X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sound%2Fisa%2Fcs423x%2Fcs4236.c;h=07ffd5c22e81918eeb0c7647f3e19428f7832c99;hb=97bf2856c6014879bd04983a3e9dfcdac1e7fe85;hp=d9dd5ebffac7b373592846248737c5dd6e001046;hpb=5273a3df6485dc2ad6aa7ddd441b9a21970f003b;p=linux-2.6.git diff --git a/sound/isa/cs423x/cs4236.c b/sound/isa/cs423x/cs4236.c index d9dd5ebff..07ffd5c22 100644 --- a/sound/isa/cs423x/cs4236.c +++ b/sound/isa/cs423x/cs4236.c @@ -21,23 +21,22 @@ #include #include +#include +#include #include #include +#include #include #include #include #include -#define SNDRV_GET_ID #include -#define chip_t cs4231_t - MODULE_AUTHOR("Jaroslav Kysela "); MODULE_LICENSE("GPL"); -MODULE_CLASSES("{sound}"); #ifdef CS4232 MODULE_DESCRIPTION("Cirrus Logic CS4232"); -MODULE_DEVICES("{{Turtle Beach,TBS-2000}," +MODULE_SUPPORTED_DEVICE("{{Turtle Beach,TBS-2000}," "{Turtle Beach,Tropez Plus}," "{SIC CrystalWave 32}," "{Hewlett Packard,Omnibook 5500}," @@ -45,7 +44,7 @@ MODULE_DEVICES("{{Turtle Beach,TBS-2000}," "{Philips,PCA70PS}}"); #else MODULE_DESCRIPTION("Cirrus Logic CS4235-9"); -MODULE_DEVICES("{{Crystal Semiconductors,CS4235}," +MODULE_SUPPORTED_DEVICE("{{Crystal Semiconductors,CS4235}," "{Crystal Semiconductors,CS4236}," "{Crystal Semiconductors,CS4237}," "{Crystal Semiconductors,CS4238}," @@ -76,8 +75,10 @@ MODULE_DEVICES("{{Crystal Semiconductors,CS4235}," #ifdef CS4232 #define IDENT "CS4232" +#define CS423X_DRIVER "snd_cs4232" #else #define IDENT "CS4236+" +#define CS423X_DRIVER "snd_cs4236" #endif static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ @@ -96,49 +97,46 @@ static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 9,11,12,15 */ static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */ static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */ -MODULE_PARM(index, "1-" __MODULE_STRING(SNDRV_CARDS) "i"); +module_param_array(index, int, NULL, 0444); MODULE_PARM_DESC(index, "Index value for " IDENT " soundcard."); -MODULE_PARM_SYNTAX(index, SNDRV_INDEX_DESC); -MODULE_PARM(id, "1-" __MODULE_STRING(SNDRV_CARDS) "s"); +module_param_array(id, charp, NULL, 0444); MODULE_PARM_DESC(id, "ID string for " IDENT " soundcard."); -MODULE_PARM_SYNTAX(id, SNDRV_ID_DESC); -MODULE_PARM(enable, "1-" __MODULE_STRING(SNDRV_CARDS) "i"); +module_param_array(enable, bool, NULL, 0444); MODULE_PARM_DESC(enable, "Enable " IDENT " soundcard."); -MODULE_PARM_SYNTAX(enable, SNDRV_ENABLE_DESC); #ifdef CONFIG_PNP -MODULE_PARM(isapnp, "1-" __MODULE_STRING(SNDRV_CARDS) "i"); +module_param_array(isapnp, bool, NULL, 0444); MODULE_PARM_DESC(isapnp, "ISA PnP detection for specified soundcard."); -MODULE_PARM_SYNTAX(isapnp, SNDRV_ISAPNP_DESC); #endif -MODULE_PARM(port, "1-" __MODULE_STRING(SNDRV_CARDS) "l"); +module_param_array(port, long, NULL, 0444); MODULE_PARM_DESC(port, "Port # for " IDENT " driver."); -MODULE_PARM_SYNTAX(port, SNDRV_PORT12_DESC); -MODULE_PARM(cport, "1-" __MODULE_STRING(SNDRV_CARDS) "l"); +module_param_array(cport, long, NULL, 0444); MODULE_PARM_DESC(cport, "Control port # for " IDENT " driver."); -MODULE_PARM_SYNTAX(cport, SNDRV_PORT12_DESC); -MODULE_PARM(mpu_port, "1-" __MODULE_STRING(SNDRV_CARDS) "l"); +module_param_array(mpu_port, long, NULL, 0444); MODULE_PARM_DESC(mpu_port, "MPU-401 port # for " IDENT " driver."); -MODULE_PARM_SYNTAX(mpu_port, SNDRV_PORT12_DESC); -MODULE_PARM(fm_port, "1-" __MODULE_STRING(SNDRV_CARDS) "l"); +module_param_array(fm_port, long, NULL, 0444); MODULE_PARM_DESC(fm_port, "FM port # for " IDENT " driver."); -MODULE_PARM_SYNTAX(fm_port, SNDRV_PORT12_DESC); -MODULE_PARM(sb_port, "1-" __MODULE_STRING(SNDRV_CARDS) "l"); +module_param_array(sb_port, long, NULL, 0444); MODULE_PARM_DESC(sb_port, "SB port # for " IDENT " driver (optional)."); -MODULE_PARM_SYNTAX(sb_port, SNDRV_PORT12_DESC); -MODULE_PARM(irq, "1-" __MODULE_STRING(SNDRV_CARDS) "i"); +module_param_array(irq, int, NULL, 0444); MODULE_PARM_DESC(irq, "IRQ # for " IDENT " driver."); -MODULE_PARM_SYNTAX(irq, SNDRV_IRQ_DESC); -MODULE_PARM(mpu_irq, "1-" __MODULE_STRING(SNDRV_CARDS) "i"); +module_param_array(mpu_irq, int, NULL, 0444); MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for " IDENT " driver."); -MODULE_PARM_SYNTAX(mpu_irq, SNDRV_IRQ_DESC); -MODULE_PARM(dma1, "1-" __MODULE_STRING(SNDRV_CARDS) "i"); +module_param_array(dma1, int, NULL, 0444); MODULE_PARM_DESC(dma1, "DMA1 # for " IDENT " driver."); -MODULE_PARM_SYNTAX(dma1, SNDRV_DMA_DESC); -MODULE_PARM(dma2, "1-" __MODULE_STRING(SNDRV_CARDS) "i"); +module_param_array(dma2, int, NULL, 0444); MODULE_PARM_DESC(dma2, "DMA2 # for " IDENT " driver."); -MODULE_PARM_SYNTAX(dma2, SNDRV_DMA_DESC); + +static struct platform_device *platform_devices[SNDRV_CARDS]; +#ifdef CONFIG_PNP +static int pnpc_registered; +#ifdef CS4232 +static int pnp_registered; +#endif +#endif /* CONFIG_PNP */ +static unsigned int snd_cs423x_devices; struct snd_card_cs4236 { + struct snd_cs4231 *chip; struct resource *res_sb_port; #ifdef CONFIG_PNP struct pnp_dev *wss; @@ -147,33 +145,25 @@ struct snd_card_cs4236 { #endif }; -static snd_card_t *snd_cs4236_legacy[SNDRV_CARDS] = SNDRV_DEFAULT_PTR; - #ifdef CONFIG_PNP -#define ISAPNP_CS4232(_va, _vb, _vc, _device, _wss, _ctrl, _mpu401) \ - { \ - ISAPNP_CARD_ID(_va, _vb, _vc, _device), \ - .devs = { ISAPNP_DEVICE_ID(_va, _vb, _vc, _wss), \ - ISAPNP_DEVICE_ID(_va, _vb, _vc, _ctrl), \ - ISAPNP_DEVICE_ID(_va, _vb, _vc, _mpu401) } \ - } -#define ISAPNP_CS4232_1(_va, _vb, _vc, _device, _wss, _ctrl, _mpu401) \ - { \ - ISAPNP_CARD_ID(_va, _vb, _vc, _device), \ - .devs = { ISAPNP_DEVICE_ID(_va, _vb, _vc, _wss), \ - ISAPNP_DEVICE_ID(_va, _vb, _vc, _ctrl), \ - ISAPNP_DEVICE_ID('P', 'N', 'P', _mpu401) } \ - } -#define ISAPNP_CS4232_WOMPU(_va, _vb, _vc, _device, _wss, _ctrl) \ - { \ - ISAPNP_CARD_ID(_va, _vb, _vc, _device), \ - .devs = { ISAPNP_DEVICE_ID(_va, _vb, _vc, _wss), \ - ISAPNP_DEVICE_ID(_va, _vb, _vc, _ctrl) } \ - } - +#ifdef CS4232 +/* + * PNP BIOS + */ +static const struct pnp_device_id snd_cs4232_pnpbiosids[] = { + { .id = "CSC0100" }, + { .id = "CSC0000" }, + /* Guillemot Turtlebeach something appears to be cs4232 compatible + * (untested) */ + { .id = "GIM0100" }, + { .id = "" } +}; +MODULE_DEVICE_TABLE(pnp, snd_cs4232_pnpbiosids); +#endif /* CS4232 */ #ifdef CS4232 +#define CS423X_ISAPNP_DRIVER "cs4232_isapnp" static struct pnp_card_device_id snd_cs423x_pnpids[] = { /* Philips PCA70PS */ { .id = "CSC0d32", .devs = { { "CSC0000" }, { "CSC0010" }, { "PNPb006" } } }, @@ -189,15 +179,20 @@ static struct pnp_card_device_id snd_cs423x_pnpids[] = { { .id = "CSC7632", .devs = { { "CSC0000" }, { "CSC0010" }, { "PNPb006" } } }, /* SIC CrystalWave 32 (CS4232) */ { .id = "CSCf032", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, + /* Netfinity 3000 on-board soundcard */ + { .id = "CSCe825", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC010f" } } }, /* --- */ { .id = "" } /* end */ }; #else /* CS4236 */ +#define CS423X_ISAPNP_DRIVER "cs4236_isapnp" static struct pnp_card_device_id snd_cs423x_pnpids[] = { /* Intel Marlin Spike Motherboard - CS4235 */ { .id = "CSC0225", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, /* Intel Marlin Spike Motherboard (#2) - CS4235 */ { .id = "CSC0225", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } }, + /* Unknown Intel mainboard - CS4235 */ + { .id = "CSC0225", .devs = { { "CSC0100" }, { "CSC0110" } } }, /* Genius Sound Maker 3DJ - CS4237B */ { .id = "CSC0437", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, /* Digital PC 5000 Onboard - CS4236B */ @@ -256,6 +251,8 @@ static struct pnp_card_device_id snd_cs423x_pnpids[] = { { .id = "CSCd937", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, /* CS4235 without MPU401 */ { .id = "CSCe825", .devs = { { "CSC0100" }, { "CSC0110" } } }, + /* Unknown SiS530 - CS4235 */ + { .id = "CSC4825", .devs = { { "CSC0100" }, { "CSC0110" } } }, /* IBM IntelliStation M Pro 6898 11U - CS4236B */ { .id = "CSCe835", .devs = { { "CSC0000" }, { "CSC0010" } } }, /* IBM PC 300PL Onboard - CS4236B */ @@ -273,37 +270,12 @@ static struct pnp_card_device_id snd_cs423x_pnpids[] = { MODULE_DEVICE_TABLE(pnp_card, snd_cs423x_pnpids); -static int __devinit snd_card_cs4236_pnp(int dev, struct snd_card_cs4236 *acard, - struct pnp_card_link *card, - const struct pnp_card_device_id *id) +/* WSS initialization */ +static int __devinit snd_cs423x_pnp_init_wss(int dev, struct pnp_dev *pdev, + struct pnp_resource_table *cfg) { - struct pnp_dev *pdev; - struct pnp_resource_table * cfg = kmalloc(sizeof(struct pnp_resource_table), GFP_KERNEL); int err; - if (!cfg) - return -ENOMEM; - - acard->wss = pnp_request_card_device(card, id->devs[0].id, NULL); - if (acard->wss == NULL) { - kfree(cfg); - return -EBUSY; - } - acard->ctrl = pnp_request_card_device(card, id->devs[1].id, NULL); - if (acard->ctrl == NULL) { - kfree(cfg); - return -EBUSY; - } - if (id->devs[2].id[0]) { - acard->mpu = pnp_request_card_device(card, id->devs[2].id, NULL); - if (acard->mpu == NULL) { - kfree(cfg); - return -EBUSY; - } - } - - /* WSS initialization */ - pdev = acard->wss; pnp_init_resource_table(cfg); if (port[dev] != SNDRV_AUTO_PORT) pnp_resource_change(&cfg->port_resource[0], port[dev], 4); @@ -322,7 +294,6 @@ static int __devinit snd_card_cs4236_pnp(int dev, struct snd_card_cs4236 *acard, snd_printk(KERN_ERR IDENT " WSS PnP manual resources are invalid, using auto config\n"); err = pnp_activate_dev(pdev); if (err < 0) { - kfree(cfg); printk(KERN_ERR IDENT " WSS PnP configure failed for WSS (out of resources?)\n"); return -EBUSY; } @@ -337,114 +308,163 @@ static int __devinit snd_card_cs4236_pnp(int dev, struct snd_card_cs4236 *acard, port[dev], fm_port[dev], sb_port[dev]); snd_printdd("isapnp WSS: irq=%i, dma1=%i, dma2=%i\n", irq[dev], dma1[dev], dma2[dev]); + return 0; +} + +/* CTRL initialization */ +static int __devinit snd_cs423x_pnp_init_ctrl(int dev, struct pnp_dev *pdev, + struct pnp_resource_table *cfg) +{ + int err; + + pnp_init_resource_table(cfg); + if (cport[dev] != SNDRV_AUTO_PORT) + pnp_resource_change(&cfg->port_resource[0], cport[dev], 8); + err = pnp_manual_config_dev(pdev, cfg, 0); + if (err < 0) + snd_printk(KERN_ERR IDENT " CTRL PnP manual resources are invalid, using auto config\n"); + err = pnp_activate_dev(pdev); + if (err < 0) { + printk(KERN_ERR IDENT " CTRL PnP configure failed for WSS (out of resources?)\n"); + return -EBUSY; + } + cport[dev] = pnp_port_start(pdev, 0); + snd_printdd("isapnp CTRL: control port=0x%lx\n", cport[dev]); + return 0; +} + +/* MPU initialization */ +static int __devinit snd_cs423x_pnp_init_mpu(int dev, struct pnp_dev *pdev, + struct pnp_resource_table *cfg) +{ + int err; + + pnp_init_resource_table(cfg); + if (mpu_port[dev] != SNDRV_AUTO_PORT) + pnp_resource_change(&cfg->port_resource[0], mpu_port[dev], 2); + if (mpu_irq[dev] != SNDRV_AUTO_IRQ && mpu_irq[dev] >= 0) + pnp_resource_change(&cfg->irq_resource[0], mpu_irq[dev], 1); + err = pnp_manual_config_dev(pdev, cfg, 0); + if (err < 0) + snd_printk(KERN_ERR IDENT " MPU401 PnP manual resources are invalid, using auto config\n"); + err = pnp_activate_dev(pdev); + if (err < 0) { + printk(KERN_ERR IDENT " MPU401 PnP configure failed for WSS (out of resources?)\n"); + mpu_port[dev] = SNDRV_AUTO_PORT; + mpu_irq[dev] = SNDRV_AUTO_IRQ; + } else { + mpu_port[dev] = pnp_port_start(pdev, 0); + if (mpu_irq[dev] >= 0 && + pnp_irq_valid(pdev, 0) && pnp_irq(pdev, 0) >= 0) { + mpu_irq[dev] = pnp_irq(pdev, 0); + } else { + mpu_irq[dev] = -1; /* disable interrupt */ + } + } + snd_printdd("isapnp MPU: port=0x%lx, irq=%i\n", mpu_port[dev], mpu_irq[dev]); + return 0; +} + +#ifdef CS4232 +static int __devinit snd_card_cs4232_pnp(int dev, struct snd_card_cs4236 *acard, + struct pnp_dev *pdev) +{ + struct pnp_resource_table *cfg = kmalloc(sizeof(*cfg), GFP_KERNEL); + + if (!cfg) + return -ENOMEM; + if (snd_cs423x_pnp_init_wss(dev, acard->wss, cfg) < 0) { + kfree(cfg); + return -EBUSY; + } + kfree(cfg); + cport[dev] = -1; + return 0; +} +#endif + +static int __devinit snd_card_cs423x_pnpc(int dev, struct snd_card_cs4236 *acard, + struct pnp_card_link *card, + const struct pnp_card_device_id *id) +{ + struct pnp_resource_table *cfg = kmalloc(sizeof(*cfg), GFP_KERNEL); + + if (!cfg) + return -ENOMEM; + + acard->wss = pnp_request_card_device(card, id->devs[0].id, NULL); + if (acard->wss == NULL) + goto error; + acard->ctrl = pnp_request_card_device(card, id->devs[1].id, NULL); + if (acard->ctrl == NULL) + goto error; + if (id->devs[2].id[0]) { + acard->mpu = pnp_request_card_device(card, id->devs[2].id, NULL); + if (acard->mpu == NULL) + goto error; + } + + /* WSS initialization */ + if (snd_cs423x_pnp_init_wss(dev, acard->wss, cfg) < 0) + goto error; + /* CTRL initialization */ if (acard->ctrl && cport[dev] > 0) { - pdev = acard->ctrl; - pnp_init_resource_table(cfg); - if (cport[dev] != SNDRV_AUTO_PORT) - pnp_resource_change(&cfg->port_resource[0], cport[dev], 8); - err = pnp_manual_config_dev(pdev, cfg, 0); - if (err < 0) - snd_printk(KERN_ERR IDENT " CTRL PnP manual resources are invalid, using auto config\n"); - err = pnp_activate_dev(pdev); - if (err < 0) { - kfree(cfg); - printk(KERN_ERR IDENT " CTRL PnP configure failed for WSS (out of resources?)\n"); - return -EBUSY; - } - cport[dev] = pnp_port_start(pdev, 0); - snd_printdd("isapnp CTRL: control port=0x%lx\n", cport[dev]); + if (snd_cs423x_pnp_init_ctrl(dev, acard->ctrl, cfg) < 0) + goto error; } /* MPU initialization */ if (acard->mpu && mpu_port[dev] > 0) { - pdev = acard->mpu; - pnp_init_resource_table(cfg); - if (mpu_port[dev] != SNDRV_AUTO_PORT) - pnp_resource_change(&cfg->port_resource[0], mpu_port[dev], 2); - if (mpu_irq[dev] != SNDRV_AUTO_IRQ && mpu_irq[dev] >= 0 && - pnp_irq_valid(pdev, 0)) - pnp_resource_change(&cfg->irq_resource[0], mpu_irq[dev], 1); - err = pnp_manual_config_dev(pdev, cfg, 0); - if (err < 0) - snd_printk(KERN_ERR IDENT " MPU401 PnP manual resources are invalid, using auto config\n"); - err = pnp_activate_dev(pdev); - if (err < 0) { - printk(KERN_ERR IDENT " MPU401 PnP configure failed for WSS (out of resources?)\n"); - mpu_port[dev] = SNDRV_AUTO_PORT; - mpu_irq[dev] = SNDRV_AUTO_IRQ; - } else { - mpu_port[dev] = pnp_port_start(pdev, 0); - if (mpu_irq[dev] >= 0 && - pnp_irq_valid(pdev, 0) && pnp_irq(pdev, 0) >= 0) { - mpu_irq[dev] = pnp_irq(pdev, 0); - } else { - mpu_irq[dev] = -1; /* disable interrupt */ - } - } - snd_printdd("isapnp MPU: port=0x%lx, irq=%i\n", mpu_port[dev], mpu_irq[dev]); + if (snd_cs423x_pnp_init_mpu(dev, acard->mpu, cfg) < 0) + goto error; } kfree(cfg); return 0; + + error: + kfree(cfg); + return -EBUSY; } #endif /* CONFIG_PNP */ -static void snd_card_cs4236_free(snd_card_t *card) +#ifdef CONFIG_PNP +#define is_isapnp_selected(dev) isapnp[dev] +#else +#define is_isapnp_selected(dev) 0 +#endif + +static void snd_card_cs4236_free(struct snd_card *card) { - struct snd_card_cs4236 *acard = (struct snd_card_cs4236 *)card->private_data; + struct snd_card_cs4236 *acard = card->private_data; - if (acard) { - if (acard->res_sb_port) { - release_resource(acard->res_sb_port); - kfree_nocheck(acard->res_sb_port); - } - } + release_and_free_resource(acard->res_sb_port); } -static int __devinit snd_card_cs423x_probe(int dev, struct pnp_card_link *pcard, - const struct pnp_card_device_id *pid) +static struct snd_card *snd_cs423x_card_new(int dev) { - snd_card_t *card; - struct snd_card_cs4236 *acard; - snd_pcm_t *pcm = NULL; - cs4231_t *chip; - opl3_t *opl3; - int err; + struct snd_card *card; -#ifdef CONFIG_PNP - if (!isapnp[dev]) { -#endif - if (port[dev] == SNDRV_AUTO_PORT) { - snd_printk("specify port\n"); - return -EINVAL; - } - if (cport[dev] == SNDRV_AUTO_PORT) { - snd_printk("specify cport\n"); - return -EINVAL; - } -#ifdef CONFIG_PNP - } -#endif card = snd_card_new(index[dev], id[dev], THIS_MODULE, sizeof(struct snd_card_cs4236)); if (card == NULL) - return -ENOMEM; - acard = (struct snd_card_cs4236 *)card->private_data; + return NULL; card->private_free = snd_card_cs4236_free; -#ifdef CONFIG_PNP - if (isapnp[dev]) { - if ((err = snd_card_cs4236_pnp(dev, acard, pcard, pid))<0) { - printk(KERN_ERR "isapnp detection failed and probing for " IDENT " is not supported\n"); - snd_card_free(card); - return -ENXIO; - } - snd_card_set_dev(card, &pcard->card->dev); - } -#endif + return card; +} + +static int __devinit snd_cs423x_probe(struct snd_card *card, int dev) +{ + struct snd_card_cs4236 *acard; + struct snd_pcm *pcm; + struct snd_cs4231 *chip; + struct snd_opl3 *opl3; + int err; + + acard = card->private_data; if (sb_port[dev] > 0 && sb_port[dev] != SNDRV_AUTO_PORT) if ((acard->res_sb_port = request_region(sb_port[dev], 16, IDENT " SB")) == NULL) { printk(KERN_ERR IDENT ": unable to register SB port at 0x%lx\n", sb_port[dev]); - snd_card_free(card); - return -ENOMEM; + return -EBUSY; } #ifdef CS4232 @@ -456,18 +476,15 @@ static int __devinit snd_card_cs423x_probe(int dev, struct pnp_card_link *pcard, dma2[dev], CS4231_HW_DETECT, 0, - &chip)) < 0) { - snd_card_free(card); + &chip)) < 0) return err; - } - if ((err = snd_cs4231_pcm(chip, 0, &pcm)) < 0) { - snd_card_free(card); + acard->chip = chip; + + if ((err = snd_cs4231_pcm(chip, 0, &pcm)) < 0) return err; - } - if ((err = snd_cs4231_mixer(chip)) < 0) { - snd_card_free(card); + + if ((err = snd_cs4231_mixer(chip)) < 0) return err; - } #else /* CS4236 */ if ((err = snd_cs4236_create(card, @@ -478,18 +495,15 @@ static int __devinit snd_card_cs423x_probe(int dev, struct pnp_card_link *pcard, dma2[dev], CS4231_HW_DETECT, 0, - &chip)) < 0) { - snd_card_free(card); + &chip)) < 0) return err; - } - if ((err = snd_cs4236_pcm(chip, 0, &pcm)) < 0) { - snd_card_free(card); + acard->chip = chip; + + if ((err = snd_cs4236_pcm(chip, 0, &pcm)) < 0) return err; - } - if ((err = snd_cs4236_mixer(chip)) < 0) { - snd_card_free(card); + + if ((err = snd_cs4236_mixer(chip)) < 0) return err; - } #endif strcpy(card->driver, pcm->name); strcpy(card->shortname, pcm->name); @@ -501,21 +515,17 @@ static int __devinit snd_card_cs423x_probe(int dev, struct pnp_card_link *pcard, if (dma2[dev] >= 0) sprintf(card->longname + strlen(card->longname), "&%d", dma2[dev]); - if ((err = snd_cs4231_timer(chip, 0, NULL)) < 0) { - snd_card_free(card); + if ((err = snd_cs4231_timer(chip, 0, NULL)) < 0) return err; - } if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) { if (snd_opl3_create(card, fm_port[dev], fm_port[dev] + 2, OPL3_HW_OPL3_CS, 0, &opl3) < 0) { - printk(KERN_ERR IDENT ": OPL3 not detected\n"); + printk(KERN_WARNING IDENT ": OPL3 not detected\n"); } else { - if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) { - snd_card_free(card); + if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) return err; - } } } @@ -525,80 +535,276 @@ static int __devinit snd_card_cs423x_probe(int dev, struct pnp_card_link *pcard, if (snd_mpu401_uart_new(card, 0, MPU401_HW_CS4232, mpu_port[dev], 0, mpu_irq[dev], - mpu_irq[dev] >= 0 ? SA_INTERRUPT : 0, NULL) < 0) - printk(KERN_ERR IDENT ": MPU401 not detected\n"); + mpu_irq[dev] >= 0 ? IRQF_DISABLED : 0, NULL) < 0) + printk(KERN_WARNING IDENT ": MPU401 not detected\n"); + } + + return snd_card_register(card); +} + +static int __init snd_cs423x_nonpnp_probe(struct platform_device *pdev) +{ + int dev = pdev->id; + struct snd_card *card; + int err; + + if (port[dev] == SNDRV_AUTO_PORT) { + snd_printk(KERN_ERR "specify port\n"); + return -EINVAL; } - if ((err = snd_card_register(card)) < 0) { + if (cport[dev] == SNDRV_AUTO_PORT) { + snd_printk(KERN_ERR "specify cport\n"); + return -EINVAL; + } + + card = snd_cs423x_card_new(dev); + if (! card) + return -ENOMEM; + snd_card_set_dev(card, &pdev->dev); + if ((err = snd_cs423x_probe(card, dev)) < 0) { snd_card_free(card); return err; } - if (pcard) - pnp_set_card_drvdata(pcard, card); - else - snd_cs4236_legacy[dev] = card; + + platform_set_drvdata(pdev, card); + return 0; +} + +static int __devexit snd_cs423x_nonpnp_remove(struct platform_device *devptr) +{ + snd_card_free(platform_get_drvdata(devptr)); + platform_set_drvdata(devptr, NULL); + return 0; +} + +#ifdef CONFIG_PM +static int snd_cs423x_suspend(struct snd_card *card) +{ + struct snd_card_cs4236 *acard = card->private_data; + snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); + acard->chip->suspend(acard->chip); + return 0; +} + +static int snd_cs423x_resume(struct snd_card *card) +{ + struct snd_card_cs4236 *acard = card->private_data; + acard->chip->resume(acard->chip); + snd_power_change_state(card, SNDRV_CTL_POWER_D0); return 0; } +static int snd_cs423x_nonpnp_suspend(struct platform_device *dev, pm_message_t state) +{ + return snd_cs423x_suspend(platform_get_drvdata(dev)); +} + +static int snd_cs423x_nonpnp_resume(struct platform_device *dev) +{ + return snd_cs423x_resume(platform_get_drvdata(dev)); +} +#endif + +static struct platform_driver cs423x_nonpnp_driver = { + .probe = snd_cs423x_nonpnp_probe, + .remove = __devexit_p(snd_cs423x_nonpnp_remove), +#ifdef CONFIG_PM + .suspend = snd_cs423x_nonpnp_suspend, + .resume = snd_cs423x_nonpnp_resume, +#endif + .driver = { + .name = CS423X_DRIVER + }, +}; + + #ifdef CONFIG_PNP -static int __devinit snd_cs423x_pnp_detect(struct pnp_card_link *card, - const struct pnp_card_device_id *id) +#ifdef CS4232 +static int __devinit snd_cs4232_pnpbios_detect(struct pnp_dev *pdev, + const struct pnp_device_id *id) +{ + static int dev; + int err; + struct snd_card *card; + + if (pnp_device_is_isapnp(pdev)) + return -ENOENT; /* we have another procedure - card */ + for (; dev < SNDRV_CARDS; dev++) { + if (enable[dev] && isapnp[dev]) + break; + } + if (dev >= SNDRV_CARDS) + return -ENODEV; + + card = snd_cs423x_card_new(dev); + if (! card) + return -ENOMEM; + if ((err = snd_card_cs4232_pnp(dev, card->private_data, pdev)) < 0) { + printk(KERN_ERR "PnP BIOS detection failed for " IDENT "\n"); + snd_card_free(card); + return err; + } + snd_card_set_dev(card, &pdev->dev); + if ((err = snd_cs423x_probe(card, dev)) < 0) { + snd_card_free(card); + return err; + } + pnp_set_drvdata(pdev, card); + dev++; + snd_cs423x_devices++; + return 0; +} + +static void __devexit snd_cs4232_pnp_remove(struct pnp_dev * pdev) +{ + snd_card_free(pnp_get_drvdata(pdev)); + pnp_set_drvdata(pdev, NULL); +} + +#ifdef CONFIG_PM +static int snd_cs4232_pnp_suspend(struct pnp_dev *pdev, pm_message_t state) +{ + return snd_cs423x_suspend(pnp_get_drvdata(pdev)); +} + +static int snd_cs4232_pnp_resume(struct pnp_dev *pdev) +{ + return snd_cs423x_resume(pnp_get_drvdata(pdev)); +} +#endif + +static struct pnp_driver cs4232_pnp_driver = { + .name = "cs4232-pnpbios", + .id_table = snd_cs4232_pnpbiosids, + .probe = snd_cs4232_pnpbios_detect, + .remove = __devexit_p(snd_cs4232_pnp_remove), +#ifdef CONFIG_PM + .suspend = snd_cs4232_pnp_suspend, + .resume = snd_cs4232_pnp_resume, +#endif +}; +#endif /* CS4232 */ + +static int __devinit snd_cs423x_pnpc_detect(struct pnp_card_link *pcard, + const struct pnp_card_device_id *pid) { static int dev; + struct snd_card *card; int res; for ( ; dev < SNDRV_CARDS; dev++) { - if (!enable[dev] || !isapnp[dev]) - continue; - res = snd_card_cs423x_probe(dev, card, id); - if (res < 0) - return res; - dev++; - return 0; + if (enable[dev] && isapnp[dev]) + break; + } + if (dev >= SNDRV_CARDS) + return -ENODEV; + + card = snd_cs423x_card_new(dev); + if (! card) + return -ENOMEM; + if ((res = snd_card_cs423x_pnpc(dev, card->private_data, pcard, pid)) < 0) { + printk(KERN_ERR "isapnp detection failed and probing for " IDENT + " is not supported\n"); + snd_card_free(card); + return res; } - return -ENODEV; + snd_card_set_dev(card, &pcard->card->dev); + if ((res = snd_cs423x_probe(card, dev)) < 0) { + snd_card_free(card); + return res; + } + pnp_set_card_drvdata(pcard, card); + dev++; + snd_cs423x_devices++; + return 0; +} + +static void __devexit snd_cs423x_pnpc_remove(struct pnp_card_link * pcard) +{ + snd_card_free(pnp_get_card_drvdata(pcard)); + pnp_set_card_drvdata(pcard, NULL); +} + +#ifdef CONFIG_PM +static int snd_cs423x_pnpc_suspend(struct pnp_card_link *pcard, pm_message_t state) +{ + return snd_cs423x_suspend(pnp_get_card_drvdata(pcard)); } -static void __devexit snd_cs423x_pnp_remove(struct pnp_card_link * pcard) +static int snd_cs423x_pnpc_resume(struct pnp_card_link *pcard) { - snd_card_t *card = (snd_card_t *) pnp_get_card_drvdata(pcard); - - snd_card_disconnect(card); - snd_card_free_in_thread(card); + return snd_cs423x_resume(pnp_get_card_drvdata(pcard)); } - +#endif + static struct pnp_card_driver cs423x_pnpc_driver = { .flags = PNP_DRIVER_RES_DISABLE, - .name = "cs423x", + .name = CS423X_ISAPNP_DRIVER, .id_table = snd_cs423x_pnpids, - .probe = snd_cs423x_pnp_detect, - .remove = __devexit_p(snd_cs423x_pnp_remove), + .probe = snd_cs423x_pnpc_detect, + .remove = __devexit_p(snd_cs423x_pnpc_remove), +#ifdef CONFIG_PM + .suspend = snd_cs423x_pnpc_suspend, + .resume = snd_cs423x_pnpc_resume, +#endif }; #endif /* CONFIG_PNP */ +static void __init_or_module snd_cs423x_unregister_all(void) +{ + int i; + +#ifdef CONFIG_PNP + if (pnpc_registered) + pnp_unregister_card_driver(&cs423x_pnpc_driver); +#ifdef CS4232 + if (pnp_registered) + pnp_unregister_driver(&cs4232_pnp_driver); +#endif +#endif /* CONFIG_PNP */ + for (i = 0; i < ARRAY_SIZE(platform_devices); ++i) + platform_device_unregister(platform_devices[i]); + platform_driver_unregister(&cs423x_nonpnp_driver); +} + static int __init alsa_card_cs423x_init(void) { - int dev, cards = 0; + int i, err; + + if ((err = platform_driver_register(&cs423x_nonpnp_driver)) < 0) + return err; - for (dev = 0; dev < SNDRV_CARDS; dev++) { - if (!enable[dev]) + for (i = 0; i < SNDRV_CARDS; i++) { + struct platform_device *device; + if (! enable[i] || is_isapnp_selected(i)) continue; -#ifdef CONFIG_PNP - if (isapnp[dev]) + device = platform_device_register_simple(CS423X_DRIVER, + i, NULL, 0); + if (IS_ERR(device)) continue; -#endif - if (snd_card_cs423x_probe(dev, NULL, NULL) >= 0) - cards++; + if (!platform_get_drvdata(device)) { + platform_device_unregister(device); + continue; + } + platform_devices[i] = device; + snd_cs423x_devices++; } #ifdef CONFIG_PNP - cards += pnp_register_card_driver(&cs423x_pnpc_driver); -#endif - if (!cards) { -#ifdef CONFIG_PNP - pnp_unregister_card_driver(&cs423x_pnpc_driver); +#ifdef CS4232 + err = pnp_register_driver(&cs4232_pnp_driver); + if (!err) + pnp_registered = 1; #endif + err = pnp_register_card_driver(&cs423x_pnpc_driver); + if (!err) + pnpc_registered = 1; +#endif /* CONFIG_PNP */ + + if (!snd_cs423x_devices) { #ifdef MODULE printk(KERN_ERR IDENT " soundcard not found or device busy\n"); #endif + snd_cs423x_unregister_all(); return -ENODEV; } return 0; @@ -606,60 +812,8 @@ static int __init alsa_card_cs423x_init(void) static void __exit alsa_card_cs423x_exit(void) { - int idx; - -#ifdef CONFIG_PNP - /* PnP cards first */ - pnp_unregister_card_driver(&cs423x_pnpc_driver); -#endif - for (idx = 0; idx < SNDRV_CARDS; idx++) - snd_card_free(snd_cs4236_legacy[idx]); + snd_cs423x_unregister_all(); } module_init(alsa_card_cs423x_init) module_exit(alsa_card_cs423x_exit) - -#ifndef MODULE - -/* format is: snd-cs4232=enable,index,id,isapnp,port, - cport,mpu_port,fm_port,sb_port, - irq,mpu_irq,dma1,dma2 */ -/* format is: snd-cs4236=enable,index,id,isapnp,port, - cport,mpu_port,fm_port,sb_port, - irq,mpu_irq,dma1,dma2 */ - -static int __init alsa_card_cs423x_setup(char *str) -{ - static unsigned __initdata nr_dev = 0; - int __attribute__ ((__unused__)) pnp = INT_MAX; - - if (nr_dev >= SNDRV_CARDS) - return 0; - (void)(get_option(&str,&enable[nr_dev]) == 2 && - get_option(&str,&index[nr_dev]) == 2 && - get_id(&str,&id[nr_dev]) == 2 && - get_option(&str,&pnp) == 2 && - get_option_long(&str,&port[nr_dev]) == 2 && - get_option_long(&str,&cport[nr_dev]) == 2 && - get_option_long(&str,&mpu_port[nr_dev]) == 2 && - get_option_long(&str,&fm_port[nr_dev]) == 2 && - get_option_long(&str,&sb_port[nr_dev]) == 2 && - get_option(&str,&irq[nr_dev]) == 2 && - get_option(&str,&mpu_irq[nr_dev]) == 2 && - get_option(&str,&dma1[nr_dev]) == 2 && - get_option(&str,&dma2[nr_dev]) == 2); -#ifdef CONFIG_PNP - if (pnp != INT_MAX) - isapnp[nr_dev] = pnp; -#endif - nr_dev++; - return 1; -} - -#ifdef CS4232 -__setup("snd-cs4232=", alsa_card_cs423x_setup); -#else /* CS4236 */ -__setup("snd-cs4236=", alsa_card_cs423x_setup); -#endif - -#endif /* ifndef MODULE */