From ec6c5ae353fd9b1141da67094e125e75d031d740 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Thu, 17 Nov 2005 14:41:45 +0100 Subject: [ALSA] Remove xxx_t typedefs: ISA OPL3SA2 Modules: OPL3SA2 driver Remove xxx_t typedefs from the ISA OPL3SA2 driver. Signed-off-by: Takashi Iwai --- sound/isa/opl3sa2.c | 100 +++++++++++++++++++++++++--------------------------- 1 file changed, 49 insertions(+), 51 deletions(-) (limited to 'sound/isa/opl3sa2.c') diff --git a/sound/isa/opl3sa2.c b/sound/isa/opl3sa2.c index 47cabda792b6..a343af70f519 100644 --- a/sound/isa/opl3sa2.c +++ b/sound/isa/opl3sa2.c @@ -115,33 +115,31 @@ MODULE_PARM_DESC(opl3sa3_ymode, "Speaker size selection for 3D Enhancement mode: #define OPL3SA2_PM_D0 0x00 #define OPL3SA2_PM_D3 (OPL3SA2_PM_ADOWN|OPL3SA2_PM_PSV|OPL3SA2_PM_PDN|OPL3SA2_PM_PDX) -typedef struct snd_opl3sa2 opl3sa2_t; - struct snd_opl3sa2 { - snd_card_t *card; + struct snd_card *card; int version; /* 2 or 3 */ unsigned long port; /* control port */ struct resource *res_port; /* control port resource */ int irq; int single_dma; spinlock_t reg_lock; - snd_hwdep_t *synth; - snd_rawmidi_t *rmidi; - cs4231_t *cs4231; + struct snd_hwdep *synth; + struct snd_rawmidi *rmidi; + struct snd_cs4231 *cs4231; #ifdef CONFIG_PNP struct pnp_dev *dev; #endif unsigned char ctlregs[0x20]; int ymode; /* SL added */ - snd_kcontrol_t *master_switch; - snd_kcontrol_t *master_volume; + struct snd_kcontrol *master_switch; + struct snd_kcontrol *master_volume; #ifdef CONFIG_PM - void (*cs4231_suspend)(cs4231_t *); - void (*cs4231_resume)(cs4231_t *); + void (*cs4231_suspend)(struct snd_cs4231 *); + void (*cs4231_resume)(struct snd_cs4231 *); #endif }; -static snd_card_t *snd_opl3sa2_legacy[SNDRV_CARDS] = SNDRV_DEFAULT_PTR; +static struct snd_card *snd_opl3sa2_legacy[SNDRV_CARDS] = SNDRV_DEFAULT_PTR; #define PFX "opl3sa2: " @@ -176,7 +174,7 @@ MODULE_DEVICE_TABLE(pnp_card, snd_opl3sa2_pnpids); /* read control port (w/o spinlock) */ -static unsigned char __snd_opl3sa2_read(opl3sa2_t *chip, unsigned char reg) +static unsigned char __snd_opl3sa2_read(struct snd_opl3sa2 *chip, unsigned char reg) { unsigned char result; #if 0 @@ -192,7 +190,7 @@ static unsigned char __snd_opl3sa2_read(opl3sa2_t *chip, unsigned char reg) } /* read control port (with spinlock) */ -static unsigned char snd_opl3sa2_read(opl3sa2_t *chip, unsigned char reg) +static unsigned char snd_opl3sa2_read(struct snd_opl3sa2 *chip, unsigned char reg) { unsigned long flags; unsigned char result; @@ -204,7 +202,7 @@ static unsigned char snd_opl3sa2_read(opl3sa2_t *chip, unsigned char reg) } /* write control port (w/o spinlock) */ -static void __snd_opl3sa2_write(opl3sa2_t *chip, unsigned char reg, unsigned char value) +static void __snd_opl3sa2_write(struct snd_opl3sa2 *chip, unsigned char reg, unsigned char value) { #if 0 outb(0x1d, port); /* password */ @@ -215,7 +213,7 @@ static void __snd_opl3sa2_write(opl3sa2_t *chip, unsigned char reg, unsigned cha } /* write control port (with spinlock) */ -static void snd_opl3sa2_write(opl3sa2_t *chip, unsigned char reg, unsigned char value) +static void snd_opl3sa2_write(struct snd_opl3sa2 *chip, unsigned char reg, unsigned char value) { unsigned long flags; spin_lock_irqsave(&chip->reg_lock, flags); @@ -223,9 +221,9 @@ static void snd_opl3sa2_write(opl3sa2_t *chip, unsigned char reg, unsigned char spin_unlock_irqrestore(&chip->reg_lock, flags); } -static int __init snd_opl3sa2_detect(opl3sa2_t *chip) +static int __init snd_opl3sa2_detect(struct snd_opl3sa2 *chip) { - snd_card_t *card; + struct snd_card *card; unsigned long port; unsigned char tmp, tmp1; char str[2]; @@ -298,7 +296,7 @@ static int __init snd_opl3sa2_detect(opl3sa2_t *chip) static irqreturn_t snd_opl3sa2_interrupt(int irq, void *dev_id, struct pt_regs *regs) { unsigned short status; - opl3sa2_t *chip = dev_id; + struct snd_opl3sa2 *chip = dev_id; int handled = 0; if (chip == NULL || chip->card == NULL) @@ -340,7 +338,7 @@ static irqreturn_t snd_opl3sa2_interrupt(int irq, void *dev_id, struct pt_regs * .get = snd_opl3sa2_get_single, .put = snd_opl3sa2_put_single, \ .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) } -static int snd_opl3sa2_info_single(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) +static int snd_opl3sa2_info_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { int mask = (kcontrol->private_value >> 16) & 0xff; @@ -351,9 +349,9 @@ static int snd_opl3sa2_info_single(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t return 0; } -static int snd_opl3sa2_get_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) +static int snd_opl3sa2_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - opl3sa2_t *chip = snd_kcontrol_chip(kcontrol); + struct snd_opl3sa2 *chip = snd_kcontrol_chip(kcontrol); unsigned long flags; int reg = kcontrol->private_value & 0xff; int shift = (kcontrol->private_value >> 8) & 0xff; @@ -368,9 +366,9 @@ static int snd_opl3sa2_get_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_ return 0; } -static int snd_opl3sa2_put_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) +static int snd_opl3sa2_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - opl3sa2_t *chip = snd_kcontrol_chip(kcontrol); + struct snd_opl3sa2 *chip = snd_kcontrol_chip(kcontrol); unsigned long flags; int reg = kcontrol->private_value & 0xff; int shift = (kcontrol->private_value >> 8) & 0xff; @@ -398,7 +396,7 @@ static int snd_opl3sa2_put_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_ .get = snd_opl3sa2_get_double, .put = snd_opl3sa2_put_double, \ .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) } -static int snd_opl3sa2_info_double(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) +static int snd_opl3sa2_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { int mask = (kcontrol->private_value >> 24) & 0xff; @@ -409,9 +407,9 @@ static int snd_opl3sa2_info_double(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t return 0; } -static int snd_opl3sa2_get_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) +static int snd_opl3sa2_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - opl3sa2_t *chip = snd_kcontrol_chip(kcontrol); + struct snd_opl3sa2 *chip = snd_kcontrol_chip(kcontrol); unsigned long flags; int left_reg = kcontrol->private_value & 0xff; int right_reg = (kcontrol->private_value >> 8) & 0xff; @@ -431,9 +429,9 @@ static int snd_opl3sa2_get_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_ return 0; } -static int snd_opl3sa2_put_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) +static int snd_opl3sa2_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - opl3sa2_t *chip = snd_kcontrol_chip(kcontrol); + struct snd_opl3sa2 *chip = snd_kcontrol_chip(kcontrol); unsigned long flags; int left_reg = kcontrol->private_value & 0xff; int right_reg = (kcontrol->private_value >> 8) & 0xff; @@ -471,31 +469,31 @@ static int snd_opl3sa2_put_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_ return change; } -static snd_kcontrol_new_t snd_opl3sa2_controls[] = { +static struct snd_kcontrol_new snd_opl3sa2_controls[] = { OPL3SA2_DOUBLE("Master Playback Switch", 0, 0x07, 0x08, 7, 7, 1, 1), OPL3SA2_DOUBLE("Master Playback Volume", 0, 0x07, 0x08, 0, 0, 15, 1), OPL3SA2_SINGLE("Mic Playback Switch", 0, 0x09, 7, 1, 1), OPL3SA2_SINGLE("Mic Playback Volume", 0, 0x09, 0, 31, 1) }; -static snd_kcontrol_new_t snd_opl3sa2_tone_controls[] = { +static struct snd_kcontrol_new snd_opl3sa2_tone_controls[] = { OPL3SA2_DOUBLE("3D Control - Wide", 0, 0x14, 0x14, 4, 0, 7, 0), OPL3SA2_DOUBLE("Tone Control - Bass", 0, 0x15, 0x15, 4, 0, 7, 0), OPL3SA2_DOUBLE("Tone Control - Treble", 0, 0x16, 0x16, 4, 0, 7, 0) }; -static void snd_opl3sa2_master_free(snd_kcontrol_t *kcontrol) +static void snd_opl3sa2_master_free(struct snd_kcontrol *kcontrol) { - opl3sa2_t *chip = snd_kcontrol_chip(kcontrol); + struct snd_opl3sa2 *chip = snd_kcontrol_chip(kcontrol); chip->master_switch = NULL; chip->master_volume = NULL; } -static int __init snd_opl3sa2_mixer(opl3sa2_t *chip) +static int __init snd_opl3sa2_mixer(struct snd_opl3sa2 *chip) { - snd_card_t *card = chip->card; - snd_ctl_elem_id_t id1, id2; - snd_kcontrol_t *kctl; + struct snd_card *card = chip->card; + struct snd_ctl_elem_id id1, id2; + struct snd_kcontrol *kctl; unsigned int idx; int err; @@ -539,9 +537,9 @@ static int __init snd_opl3sa2_mixer(opl3sa2_t *chip) /* Power Management support functions */ #ifdef CONFIG_PM -static int snd_opl3sa2_suspend(snd_card_t *card, pm_message_t state) +static int snd_opl3sa2_suspend(struct snd_card *card, pm_message_t state) { - opl3sa2_t *chip = card->pm_private_data; + struct snd_opl3sa2 *chip = card->pm_private_data; snd_pcm_suspend_all(chip->cs4231->pcm); /* stop before saving regs */ chip->cs4231_suspend(chip->cs4231); @@ -552,9 +550,9 @@ static int snd_opl3sa2_suspend(snd_card_t *card, pm_message_t state) return 0; } -static int snd_opl3sa2_resume(snd_card_t *card) +static int snd_opl3sa2_resume(struct snd_card *card) { - opl3sa2_t *chip = card->pm_private_data; + struct snd_opl3sa2 *chip = card->pm_private_data; int i; /* power up */ @@ -577,7 +575,7 @@ static int snd_opl3sa2_resume(snd_card_t *card) #endif /* CONFIG_PM */ #ifdef CONFIG_PNP -static int __init snd_opl3sa2_pnp(int dev, opl3sa2_t *chip, +static int __init snd_opl3sa2_pnp(int dev, struct snd_opl3sa2 *chip, struct pnp_dev *pdev, int isapnp) { @@ -634,7 +632,7 @@ static int __init snd_opl3sa2_pnp(int dev, opl3sa2_t *chip, return 0; } -static int __init snd_opl3sa2_cpnp(int dev, opl3sa2_t *chip, +static int __init snd_opl3sa2_cpnp(int dev, struct snd_opl3sa2 *chip, struct pnp_card_link *card, const struct pnp_card_device_id *id) { @@ -652,7 +650,7 @@ static int __init snd_opl3sa2_cpnp(int dev, opl3sa2_t *chip, } #endif /* CONFIG_PNP */ -static int snd_opl3sa2_free(opl3sa2_t *chip) +static int snd_opl3sa2_free(struct snd_opl3sa2 *chip) { if (chip->irq >= 0) free_irq(chip->irq, (void *)chip); @@ -661,9 +659,9 @@ static int snd_opl3sa2_free(opl3sa2_t *chip) return 0; } -static int snd_opl3sa2_dev_free(snd_device_t *device) +static int snd_opl3sa2_dev_free(struct snd_device *device) { - opl3sa2_t *chip = device->device_data; + struct snd_opl3sa2 *chip = device->device_data; return snd_opl3sa2_free(chip); } @@ -679,11 +677,11 @@ static int __devinit snd_opl3sa2_probe(int dev, const struct pnp_card_device_id *pid) { int xirq, xdma1, xdma2; - snd_card_t *card; + struct snd_card *card; struct snd_opl3sa2 *chip; - cs4231_t *cs4231; - opl3_t *opl3; - static snd_device_ops_t ops = { + struct snd_cs4231 *cs4231; + struct snd_opl3 *opl3; + static struct snd_device_ops ops = { .dev_free = snd_opl3sa2_dev_free, }; int err; @@ -837,7 +835,7 @@ static int __devinit snd_opl3sa2_pnp_detect(struct pnp_dev *pdev, static void __devexit snd_opl3sa2_pnp_remove(struct pnp_dev * pdev) { - snd_card_t *card = (snd_card_t *) pnp_get_drvdata(pdev); + struct snd_card *card = (struct snd_card *) pnp_get_drvdata(pdev); snd_card_disconnect(card); snd_card_free_in_thread(card); @@ -872,7 +870,7 @@ static int __devinit snd_opl3sa2_pnp_cdetect(struct pnp_card_link *card, static void __devexit snd_opl3sa2_pnp_cremove(struct pnp_card_link * pcard) { - snd_card_t *card = (snd_card_t *) pnp_get_card_drvdata(pcard); + struct snd_card *card = (struct snd_card *) pnp_get_card_drvdata(pcard); snd_card_disconnect(card); snd_card_free_in_thread(card); -- cgit v1.2.3 From 704e05204c623136ea12411dc4286d1caea6cd7c Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Thu, 17 Nov 2005 17:11:53 +0100 Subject: [ALSA] opl3sa2 - Use platform_device Modules: OPL3SA2 driver Rewrite the probe/remove with platform_device. Signed-off-by: Takashi Iwai --- sound/isa/opl3sa2.c | 428 ++++++++++++++++++++++++++++------------------------ 1 file changed, 228 insertions(+), 200 deletions(-) (limited to 'sound/isa/opl3sa2.c') diff --git a/sound/isa/opl3sa2.c b/sound/isa/opl3sa2.c index a343af70f519..b923de9b321d 100644 --- a/sound/isa/opl3sa2.c +++ b/sound/isa/opl3sa2.c @@ -21,6 +21,8 @@ #include #include +#include +#include #include #include #include @@ -126,21 +128,12 @@ struct snd_opl3sa2 { struct snd_hwdep *synth; struct snd_rawmidi *rmidi; struct snd_cs4231 *cs4231; -#ifdef CONFIG_PNP - struct pnp_dev *dev; -#endif unsigned char ctlregs[0x20]; int ymode; /* SL added */ struct snd_kcontrol *master_switch; struct snd_kcontrol *master_volume; -#ifdef CONFIG_PM - void (*cs4231_suspend)(struct snd_cs4231 *); - void (*cs4231_resume)(struct snd_cs4231 *); -#endif }; -static struct snd_card *snd_opl3sa2_legacy[SNDRV_CARDS] = SNDRV_DEFAULT_PTR; - #define PFX "opl3sa2: " #ifdef CONFIG_PNP @@ -539,11 +532,10 @@ static int __init snd_opl3sa2_mixer(struct snd_opl3sa2 *chip) #ifdef CONFIG_PM static int snd_opl3sa2_suspend(struct snd_card *card, pm_message_t state) { - struct snd_opl3sa2 *chip = card->pm_private_data; - - snd_pcm_suspend_all(chip->cs4231->pcm); /* stop before saving regs */ - chip->cs4231_suspend(chip->cs4231); + struct snd_opl3sa2 *chip = card->private_data; + snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); + chip->cs4231->suspend(chip->cs4231); /* power down */ snd_opl3sa2_write(chip, OPL3SA2_PM_CTRL, OPL3SA2_PM_D3); @@ -552,7 +544,7 @@ static int snd_opl3sa2_suspend(struct snd_card *card, pm_message_t state) static int snd_opl3sa2_resume(struct snd_card *card) { - struct snd_opl3sa2 *chip = card->pm_private_data; + struct snd_opl3sa2 *chip = card->private_data; int i; /* power up */ @@ -568,23 +560,20 @@ static int snd_opl3sa2_resume(struct snd_card *card) snd_opl3sa2_write(chip, i, chip->ctlregs[i]); } /* restore cs4231 */ - chip->cs4231_resume(chip->cs4231); + chip->cs4231->resume(chip->cs4231); + snd_power_change_state(card, SNDRV_CTL_POWER_D0); return 0; } #endif /* CONFIG_PM */ #ifdef CONFIG_PNP static int __init snd_opl3sa2_pnp(int dev, struct snd_opl3sa2 *chip, - struct pnp_dev *pdev, - int isapnp) + struct pnp_dev *pdev) { struct pnp_resource_table * cfg; int err; - if (!isapnp && pnp_device_is_isapnp(pdev)) - return -ENOENT; /* we have another procedure - card */ - cfg = kmalloc(sizeof(struct pnp_resource_table), GFP_KERNEL); if (!cfg) return -ENOMEM; @@ -607,7 +596,7 @@ static int __init snd_opl3sa2_pnp(int dev, struct snd_opl3sa2 *chip, if (irq[dev] != SNDRV_AUTO_IRQ) pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1); err = pnp_manual_config_dev(pdev, cfg, 0); - if (err < 0 && isapnp) + if (err < 0) snd_printk(KERN_ERR "PnP manual resources are invalid, using auto config\n"); err = pnp_activate_dev(pdev); if (err < 0) { @@ -628,111 +617,47 @@ static int __init snd_opl3sa2_pnp(int dev, struct snd_opl3sa2 *chip, snd_printdd("%sPnP OPL3-SA: control port=0x%lx, dma1=%i, dma2=%i, irq=%i\n", pnp_device_is_pnpbios(pdev) ? "BIOS" : "ISA", port[dev], dma1[dev], dma2[dev], irq[dev]); kfree(cfg); - chip->dev = pdev; return 0; } - -static int __init snd_opl3sa2_cpnp(int dev, struct snd_opl3sa2 *chip, - struct pnp_card_link *card, - const struct pnp_card_device_id *id) -{ - struct pnp_dev *pdev; - struct pnp_resource_table * cfg = kmalloc(sizeof(struct pnp_resource_table), GFP_KERNEL); - - if (!cfg) - return -ENOMEM; - pdev = pnp_request_card_device(card, id->devs[0].id, NULL); - if (pdev == NULL) { - kfree(cfg); - return -EBUSY; - } - return snd_opl3sa2_pnp(dev, chip, pdev, 1); -} #endif /* CONFIG_PNP */ -static int snd_opl3sa2_free(struct snd_opl3sa2 *chip) +static void snd_opl3sa2_free(struct snd_card *card) { + struct snd_opl3sa2 *chip = card->private_data; if (chip->irq >= 0) free_irq(chip->irq, (void *)chip); release_and_free_resource(chip->res_port); - kfree(chip); - return 0; } -static int snd_opl3sa2_dev_free(struct snd_device *device) +static struct snd_card *snd_opl3sa2_card_new(int dev) { - struct snd_opl3sa2 *chip = device->device_data; - return snd_opl3sa2_free(chip); -} - -#ifdef CONFIG_PNP -#define is_isapnp_selected(dev) isapnp[dev] -#else -#define is_isapnp_selected(dev) 0 -#endif - -static int __devinit snd_opl3sa2_probe(int dev, - struct pnp_dev *pdev, - struct pnp_card_link *pcard, - const struct pnp_card_device_id *pid) -{ - int xirq, xdma1, xdma2; struct snd_card *card; struct snd_opl3sa2 *chip; - struct snd_cs4231 *cs4231; - struct snd_opl3 *opl3; - static struct snd_device_ops ops = { - .dev_free = snd_opl3sa2_dev_free, - }; - int err; - if (! is_isapnp_selected(dev)) { - if (port[dev] == SNDRV_AUTO_PORT) { - snd_printk(KERN_ERR PFX "specify port\n"); - return -EINVAL; - } - if (wss_port[dev] == SNDRV_AUTO_PORT) { - snd_printk(KERN_ERR PFX "specify wss_port\n"); - return -EINVAL; - } - if (fm_port[dev] == SNDRV_AUTO_PORT) { - snd_printk(KERN_ERR PFX "specify fm_port\n"); - return -EINVAL; - } - if (midi_port[dev] == SNDRV_AUTO_PORT) { - snd_printk(KERN_ERR PFX "specify midi_port\n"); - return -EINVAL; - } - } - - card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); + card = snd_card_new(index[dev], id[dev], THIS_MODULE, sizeof(struct snd_opl3sa2)); if (card == NULL) - return -ENOMEM; + return NULL; strcpy(card->driver, "OPL3SA2"); strcpy(card->shortname, "Yamaha OPL3-SA2"); - chip = kzalloc(sizeof(*chip), GFP_KERNEL); - if (chip == NULL) { - err = -ENOMEM; - goto __error; - } + chip = card->private_data; spin_lock_init(&chip->reg_lock); chip->irq = -1; - if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) - goto __error; -#ifdef CONFIG_PNP - if (pdev) { - if ((err = snd_opl3sa2_pnp(dev, chip, pdev, 0)) < 0) - goto __error; - snd_card_set_dev(card, &pdev->dev); - } - if (pcard) { - if ((err = snd_opl3sa2_cpnp(dev, chip, pcard, pid)) < 0) - goto __error; - snd_card_set_dev(card, &pcard->card->dev); - } -#endif - chip->ymode = opl3sa3_ymode[dev] & 0x03 ; /* initialise this card from supplied (or default) parameter*/ chip->card = card; + card->private_free = snd_opl3sa2_free; + return card; +} + +static int __devinit snd_opl3sa2_probe(struct snd_card *card, int dev) +{ + int xirq, xdma1, xdma2; + struct snd_opl3sa2 *chip; + struct snd_cs4231 *cs4231; + struct snd_opl3 *opl3; + int err; + + /* initialise this card from supplied (or default) parameter*/ + chip = card->private_data; + chip->ymode = opl3sa3_ymode[dev] & 0x03 ; chip->port = port[dev]; xirq = irq[dev]; xdma1 = dma1[dev]; @@ -740,11 +665,10 @@ static int __devinit snd_opl3sa2_probe(int dev, if (xdma2 < 0) chip->single_dma = 1; if ((err = snd_opl3sa2_detect(chip)) < 0) - goto __error; - if (request_irq(xirq, snd_opl3sa2_interrupt, SA_INTERRUPT, "OPL3-SA2", (void *)chip)) { + return err; + if (request_irq(xirq, snd_opl3sa2_interrupt, SA_INTERRUPT, "OPL3-SA2", chip)) { snd_printk(KERN_ERR PFX "can't grab IRQ %d\n", xirq); - err = -ENODEV; - goto __error; + return -ENODEV; } chip->irq = xirq; if ((err = snd_cs4231_create(card, @@ -754,163 +678,273 @@ static int __devinit snd_opl3sa2_probe(int dev, CS4231_HWSHARE_IRQ, &cs4231)) < 0) { snd_printd("Oops, WSS not detected at 0x%lx\n", wss_port[dev] + 4); - goto __error; + return err; } chip->cs4231 = cs4231; if ((err = snd_cs4231_pcm(cs4231, 0, NULL)) < 0) - goto __error; + return err; if ((err = snd_cs4231_mixer(cs4231)) < 0) - goto __error; + return err; if ((err = snd_opl3sa2_mixer(chip)) < 0) - goto __error; + return err; if ((err = snd_cs4231_timer(cs4231, 0, NULL)) < 0) - goto __error; + return err; if (fm_port[dev] >= 0x340 && fm_port[dev] < 0x400) { if ((err = snd_opl3_create(card, fm_port[dev], fm_port[dev] + 2, OPL3_HW_OPL3, 0, &opl3)) < 0) - goto __error; + return err; if ((err = snd_opl3_timer_new(opl3, 1, 2)) < 0) - goto __error; + return err; if ((err = snd_opl3_hwdep_new(opl3, 0, 1, &chip->synth)) < 0) - goto __error; + return err; } if (midi_port[dev] >= 0x300 && midi_port[dev] < 0x340) { if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_OPL3SA2, midi_port[dev], 0, xirq, 0, &chip->rmidi)) < 0) - goto __error; + return err; } -#ifdef CONFIG_PM - chip->cs4231_suspend = chip->cs4231->suspend; - chip->cs4231_resume = chip->cs4231->resume; - /* now clear callbacks for cs4231 */ - chip->cs4231->suspend = NULL; - chip->cs4231->resume = NULL; - snd_card_set_isa_pm_callback(card, snd_opl3sa2_suspend, snd_opl3sa2_resume, chip); -#endif - sprintf(card->longname, "%s at 0x%lx, irq %d, dma %d", card->shortname, chip->port, xirq, xdma1); if (dma2 >= 0) sprintf(card->longname + strlen(card->longname), "&%d", xdma2); - if ((err = snd_card_set_generic_dev(card)) < 0) - goto __error; - - if ((err = snd_card_register(card)) < 0) - goto __error; - - if (pdev) - pnp_set_drvdata(pdev, card); - else if (pcard) - pnp_set_card_drvdata(pcard, card); - else - snd_opl3sa2_legacy[dev] = card; - return 0; - - __error: - snd_card_free(card); - return err; + return snd_card_register(card); } #ifdef CONFIG_PNP static int __devinit snd_opl3sa2_pnp_detect(struct pnp_dev *pdev, const struct pnp_device_id *id) { - static int dev; - int res; + 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; - for ( ; dev < SNDRV_CARDS; dev++) { - if (!enable[dev] || !isapnp[dev]) - continue; - res = snd_opl3sa2_probe(dev, pdev, NULL, NULL); - if (res < 0) - return res; - dev++; - return 0; - } - return -ENODEV; + card = snd_opl3sa2_card_new(dev); + if (! card) + return -ENOMEM; + if ((err = snd_opl3sa2_pnp(dev, card->private_data, pdev)) < 0) { + snd_card_free(card); + return err; + } + snd_card_set_dev(card, &pdev->dev); + if ((err = snd_opl3sa2_probe(card, dev)) < 0) { + snd_card_free(card); + return err; + } + pnp_set_drvdata(pdev, card); + dev++; + return 0; } static void __devexit snd_opl3sa2_pnp_remove(struct pnp_dev * pdev) { - struct snd_card *card = (struct snd_card *) pnp_get_drvdata(pdev); - - snd_card_disconnect(card); - snd_card_free_in_thread(card); + snd_card_free(pnp_get_drvdata(pdev)); + pnp_set_drvdata(pdev, NULL); } +#ifdef CONFIG_PM +static int snd_opl3sa2_pnp_suspend(struct pnp_dev *pdev, pm_message_t state) +{ + return snd_opl3sa2_suspend(pnp_get_drvdata(pdev), state); +} +static int snd_opl3sa2_pnp_resume(struct pnp_dev *pdev) +{ + return snd_opl3sa2_resume(pnp_get_drvdata(pdev)); +} +#endif + static struct pnp_driver opl3sa2_pnp_driver = { .name = "opl3sa2-pnpbios", .id_table = snd_opl3sa2_pnpbiosids, .probe = snd_opl3sa2_pnp_detect, .remove = __devexit_p(snd_opl3sa2_pnp_remove), +#ifdef CONFIG_PM + .suspend = snd_opl3sa2_pnp_suspend, + .resume = snd_opl3sa2_pnp_resume, +#endif }; -static int __devinit snd_opl3sa2_pnp_cdetect(struct pnp_card_link *card, +static int __devinit snd_opl3sa2_pnp_cdetect(struct pnp_card_link *pcard, const struct pnp_card_device_id *id) { - static int dev; - int res; + static int dev; + struct pnp_dev *pdev; + int err; + struct snd_card *card; - for ( ; dev < SNDRV_CARDS; dev++) { - if (!enable[dev]) - continue; - if (is_isapnp_selected(dev)) - continue; - res = snd_opl3sa2_probe(dev, NULL, card, id); - if (res < 0) - return res; - dev++; - return 0; - } - return -ENODEV; + pdev = pnp_request_card_device(pcard, id->devs[0].id, NULL); + if (pdev == NULL) + return -EBUSY; + for (; dev < SNDRV_CARDS; dev++) { + if (enable[dev] && isapnp[dev]) + break; + } + if (dev >= SNDRV_CARDS) + return -ENODEV; + + card = snd_opl3sa2_card_new(dev); + if (! card) + return -ENOMEM; + if ((err = snd_opl3sa2_pnp(dev, card->private_data, pdev)) < 0) { + snd_card_free(card); + return err; + } + snd_card_set_dev(card, &pdev->dev); + if ((err = snd_opl3sa2_probe(card, dev)) < 0) { + snd_card_free(card); + return err; + } + pnp_set_card_drvdata(pcard, card); + dev++; + return 0; } static void __devexit snd_opl3sa2_pnp_cremove(struct pnp_card_link * pcard) { - struct snd_card *card = (struct snd_card *) pnp_get_card_drvdata(pcard); - - snd_card_disconnect(card); - snd_card_free_in_thread(card); + snd_card_free(pnp_get_card_drvdata(pcard)); + pnp_set_card_drvdata(pcard, NULL); } +#ifdef CONFIG_PM +static int snd_opl3sa2_pnp_csuspend(struct pnp_card_link *pcard, pm_message_t state) +{ + return snd_opl3sa2_suspend(pnp_get_card_drvdata(pcard), state); +} +static int snd_opl3sa2_pnp_cresume(struct pnp_card_link *pcard) +{ + return snd_opl3sa2_resume(pnp_get_card_drvdata(pcard)); +} +#endif + static struct pnp_card_driver opl3sa2_pnpc_driver = { .flags = PNP_DRIVER_RES_DISABLE, .name = "opl3sa2", .id_table = snd_opl3sa2_pnpids, .probe = snd_opl3sa2_pnp_cdetect, .remove = __devexit_p(snd_opl3sa2_pnp_cremove), +#ifdef CONFIG_PM + .suspend = snd_opl3sa2_pnp_csuspend, + .resume = snd_opl3sa2_pnp_cresume, +#endif }; #endif /* CONFIG_PNP */ +static int __init snd_opl3sa2_nonpnp_probe(struct platform_device *pdev) +{ + struct snd_card *card; + int err; + int dev = pdev->id; + + if (port[dev] == SNDRV_AUTO_PORT) { + snd_printk(KERN_ERR PFX "specify port\n"); + return -EINVAL; + } + if (wss_port[dev] == SNDRV_AUTO_PORT) { + snd_printk(KERN_ERR PFX "specify wss_port\n"); + return -EINVAL; + } + if (fm_port[dev] == SNDRV_AUTO_PORT) { + snd_printk(KERN_ERR PFX "specify fm_port\n"); + return -EINVAL; + } + if (midi_port[dev] == SNDRV_AUTO_PORT) { + snd_printk(KERN_ERR PFX "specify midi_port\n"); + return -EINVAL; + } + + card = snd_opl3sa2_card_new(dev); + if (! card) + return -ENOMEM; + snd_card_set_dev(card, &pdev->dev); + if ((err = snd_opl3sa2_probe(card, dev)) < 0) { + snd_card_free(card); + return err; + } + platform_set_drvdata(pdev, card); + return 0; +} + +static int snd_opl3sa2_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_opl3sa2_nonpnp_suspend(struct platform_device *dev, pm_message_t state) +{ + return snd_opl3sa2_suspend(platform_get_drvdata(dev), state); +} + +static int snd_opl3sa2_nonpnp_resume(struct platform_device *dev) +{ + return snd_opl3sa2_resume(platform_get_drvdata(dev)); +} +#endif + +#define OPL3SA2_DRIVER "snd_opl3sa2" + +static struct platform_driver snd_opl3sa2_nonpnp_driver = { + .probe = snd_opl3sa2_nonpnp_probe, + .remove = snd_opl3sa2_nonpnp_remove, +#ifdef CONFIG_PM + .suspend = snd_opl3sa2_nonpnp_suspend, + .resume = snd_opl3sa2_nonpnp_resume, +#endif + .driver = { + .name = OPL3SA2_DRIVER + }, +}; + static int __init alsa_card_opl3sa2_init(void) { - int dev, cards = 0; + int i, err, cards = 0; - for (dev = 0; dev < SNDRV_CARDS; dev++) { - if (!enable[dev]) - continue; + if ((err = platform_driver_register(&snd_opl3sa2_nonpnp_driver)) < 0) + return err; + + for (i = 0; i < SNDRV_CARDS && enable[i]; i++) { + struct platform_device *device; #ifdef CONFIG_PNP - if (isapnp[dev]) + if (isapnp[i]) continue; #endif - if (snd_opl3sa2_probe(dev, NULL, NULL, NULL) >= 0) - cards++; + device = platform_device_register_simple(OPL3SA2_DRIVER, + i, NULL, 0); + if (IS_ERR(device)) { + err = PTR_ERR(device); + platform_driver_unregister(&snd_opl3sa2_nonpnp_driver); + return err; + } + cards++; } -#ifdef CONFIG_PNP - cards += pnp_register_driver(&opl3sa2_pnp_driver); - cards += pnp_register_card_driver(&opl3sa2_pnpc_driver); -#endif + + err = pnp_register_driver(&opl3sa2_pnp_driver); + if (err > 0) + cards += err; + err = pnp_register_card_driver(&opl3sa2_pnpc_driver); + if (err > 0) + cards += err; + if (!cards) { #ifdef MODULE snd_printk(KERN_ERR "Yamaha OPL3-SA soundcard not found or device busy\n"); #endif -#ifdef CONFIG_PNP pnp_unregister_card_driver(&opl3sa2_pnpc_driver); pnp_unregister_driver(&opl3sa2_pnp_driver); -#endif + platform_driver_unregister(&snd_opl3sa2_nonpnp_driver); return -ENODEV; } return 0; @@ -918,15 +952,9 @@ static int __init alsa_card_opl3sa2_init(void) static void __exit alsa_card_opl3sa2_exit(void) { - int idx; - -#ifdef CONFIG_PNP - /* PnP cards first */ pnp_unregister_card_driver(&opl3sa2_pnpc_driver); pnp_unregister_driver(&opl3sa2_pnp_driver); -#endif - for (idx = 0; idx < SNDRV_CARDS; idx++) - snd_card_free(snd_opl3sa2_legacy[idx]); + platform_driver_unregister(&snd_opl3sa2_nonpnp_driver); } module_init(alsa_card_opl3sa2_init) -- cgit v1.2.3 From 73e77ba0235532bd7523ba90883d325f6e095acf Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Thu, 17 Nov 2005 17:44:01 +0100 Subject: [ALSA] Add error messages Add error messages in the critial error path to be more verbose. Signed-off-by: Takashi Iwai --- sound/core/control.c | 8 ++++++-- sound/core/device.c | 5 ++++- sound/core/hwdep.c | 7 ++++--- sound/core/pcm.c | 16 +++++++++++----- sound/core/rawmidi.c | 18 ++++++++++++++---- sound/core/timer.c | 4 +++- sound/drivers/mpu401/mpu401_uart.c | 1 + sound/drivers/opl3/opl3_lib.c | 4 +++- sound/isa/opl3sa2.c | 27 ++++++++++++++++++++------- 9 files changed, 66 insertions(+), 24 deletions(-) (limited to 'sound/isa/opl3sa2.c') diff --git a/sound/core/control.c b/sound/core/control.c index 03ae9bb7d38e..f8f98cc52417 100644 --- a/sound/core/control.c +++ b/sound/core/control.c @@ -195,8 +195,10 @@ struct snd_kcontrol *snd_ctl_new(struct snd_kcontrol *control, unsigned int acce snd_assert(control != NULL, return NULL); snd_assert(control->count > 0, return NULL); kctl = kzalloc(sizeof(*kctl) + sizeof(struct snd_kcontrol_volatile) * control->count, GFP_KERNEL); - if (kctl == NULL) + if (kctl == NULL) { + snd_printk(KERN_ERR "Cannot allocate control instance\n"); return NULL; + } *kctl = *control; for (idx = 0; idx < kctl->count; idx++) kctl->vd[idx].access = access; @@ -309,7 +311,9 @@ int snd_ctl_add(struct snd_card *card, struct snd_kcontrol *kcontrol) struct snd_ctl_elem_id id; unsigned int idx; - snd_assert(card != NULL && kcontrol != NULL, return -EINVAL); + snd_assert(card != NULL, return -EINVAL); + if (! kcontrol) + return -EINVAL; snd_assert(kcontrol->info != NULL, return -EINVAL); id = kcontrol->id; down_write(&card->controls_rwsem); diff --git a/sound/core/device.c b/sound/core/device.c index afa8cc7fb05e..b1cf6ec56784 100644 --- a/sound/core/device.c +++ b/sound/core/device.c @@ -50,8 +50,10 @@ int snd_device_new(struct snd_card *card, snd_device_type_t type, snd_assert(device_data != NULL, return -ENXIO); snd_assert(ops != NULL, return -ENXIO); dev = kzalloc(sizeof(*dev), GFP_KERNEL); - if (dev == NULL) + if (dev == NULL) { + snd_printk(KERN_ERR "Cannot allocate device\n"); return -ENOMEM; + } dev->card = card; dev->type = type; dev->state = SNDRV_DEV_BUILD; @@ -173,6 +175,7 @@ int snd_device_register(struct snd_card *card, void *device_data) dev->state = SNDRV_DEV_REGISTERED; return 0; } + snd_printd("snd_device_register busy\n"); return -EBUSY; } snd_BUG(); diff --git a/sound/core/hwdep.c b/sound/core/hwdep.c index da0fb9f08413..444e266e7c48 100644 --- a/sound/core/hwdep.c +++ b/sound/core/hwdep.c @@ -364,13 +364,14 @@ int snd_hwdep_new(struct snd_card *card, char *id, int device, *rhwdep = NULL; snd_assert(card != NULL, return -ENXIO); hwdep = kzalloc(sizeof(*hwdep), GFP_KERNEL); - if (hwdep == NULL) + if (hwdep == NULL) { + snd_printk(KERN_ERR "hwdep: cannot allocate\n"); return -ENOMEM; + } hwdep->card = card; hwdep->device = device; - if (id) { + if (id) strlcpy(hwdep->id, id, sizeof(hwdep->id)); - } #ifdef CONFIG_SND_OSSEMUL hwdep->oss_type = -1; #endif diff --git a/sound/core/pcm.c b/sound/core/pcm.c index 59c995bbf15b..9305ac357a3e 100644 --- a/sound/core/pcm.c +++ b/sound/core/pcm.c @@ -600,14 +600,18 @@ int snd_pcm_new_stream(struct snd_pcm *pcm, int stream, int substream_count) pstr->reg = &snd_pcm_reg[stream]; if (substream_count > 0) { err = snd_pcm_stream_proc_init(pstr); - if (err < 0) + if (err < 0) { + snd_printk(KERN_ERR "Error in snd_pcm_stream_proc_init\n"); return err; + } } prev = NULL; for (idx = 0, prev = NULL; idx < substream_count; idx++) { substream = kzalloc(sizeof(*substream), GFP_KERNEL); - if (substream == NULL) + if (substream == NULL) { + snd_printk(KERN_ERR "Cannot allocate PCM substream\n"); return -ENOMEM; + } substream->pcm = pcm; substream->pstr = pstr; substream->number = idx; @@ -620,6 +624,7 @@ int snd_pcm_new_stream(struct snd_pcm *pcm, int stream, int substream_count) prev->next = substream; err = snd_pcm_substream_proc_init(substream); if (err < 0) { + snd_printk(KERN_ERR "Error in snd_pcm_stream_proc_init\n"); kfree(substream); return err; } @@ -666,13 +671,14 @@ int snd_pcm_new(struct snd_card *card, char *id, int device, *rpcm = NULL; snd_assert(card != NULL, return -ENXIO); pcm = kzalloc(sizeof(*pcm), GFP_KERNEL); - if (pcm == NULL) + if (pcm == NULL) { + snd_printk(KERN_ERR "Cannot allocate PCM\n"); return -ENOMEM; + } pcm->card = card; pcm->device = device; - if (id) { + if (id) strlcpy(pcm->id, id, sizeof(pcm->id)); - } if ((err = snd_pcm_new_stream(pcm, SNDRV_PCM_STREAM_PLAYBACK, playback_count)) < 0) { snd_pcm_free(pcm); return err; diff --git a/sound/core/rawmidi.c b/sound/core/rawmidi.c index ede0a6083d29..7a86a9a08a15 100644 --- a/sound/core/rawmidi.c +++ b/sound/core/rawmidi.c @@ -1382,8 +1382,10 @@ static int snd_rawmidi_alloc_substreams(struct snd_rawmidi *rmidi, INIT_LIST_HEAD(&stream->substreams); for (idx = 0; idx < count; idx++) { substream = kzalloc(sizeof(*substream), GFP_KERNEL); - if (substream == NULL) + if (substream == NULL) { + snd_printk(KERN_ERR "rawmidi: cannot allocate substream\n"); return -ENOMEM; + } substream->stream = direction; substream->number = idx; substream->rmidi = rmidi; @@ -1425,19 +1427,27 @@ int snd_rawmidi_new(struct snd_card *card, char *id, int device, *rrawmidi = NULL; snd_assert(card != NULL, return -ENXIO); rmidi = kzalloc(sizeof(*rmidi), GFP_KERNEL); - if (rmidi == NULL) + if (rmidi == NULL) { + snd_printk(KERN_ERR "rawmidi: cannot allocate\n"); return -ENOMEM; + } rmidi->card = card; rmidi->device = device; init_MUTEX(&rmidi->open_mutex); init_waitqueue_head(&rmidi->open_wait); if (id != NULL) strlcpy(rmidi->id, id, sizeof(rmidi->id)); - if ((err = snd_rawmidi_alloc_substreams(rmidi, &rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT], SNDRV_RAWMIDI_STREAM_INPUT, input_count)) < 0) { + if ((err = snd_rawmidi_alloc_substreams(rmidi, + &rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT], + SNDRV_RAWMIDI_STREAM_INPUT, + input_count)) < 0) { snd_rawmidi_free(rmidi); return err; } - if ((err = snd_rawmidi_alloc_substreams(rmidi, &rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT], SNDRV_RAWMIDI_STREAM_OUTPUT, output_count)) < 0) { + if ((err = snd_rawmidi_alloc_substreams(rmidi, + &rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT], + SNDRV_RAWMIDI_STREAM_OUTPUT, + output_count)) < 0) { snd_rawmidi_free(rmidi); return err; } diff --git a/sound/core/timer.c b/sound/core/timer.c index 18d43a037850..74637cef6d2c 100644 --- a/sound/core/timer.c +++ b/sound/core/timer.c @@ -777,8 +777,10 @@ int snd_timer_new(struct snd_card *card, char *id, struct snd_timer_id *tid, snd_assert(rtimer != NULL, return -EINVAL); *rtimer = NULL; timer = kzalloc(sizeof(*timer), GFP_KERNEL); - if (timer == NULL) + if (timer == NULL) { + snd_printk(KERN_ERR "timer: cannot allocate\n"); return -ENOMEM; + } timer->tmr_class = tid->dev_class; timer->card = card; timer->tmr_device = tid->device; diff --git a/sound/drivers/mpu401/mpu401_uart.c b/sound/drivers/mpu401/mpu401_uart.c index 16e87f31788c..ee67b522d259 100644 --- a/sound/drivers/mpu401/mpu401_uart.c +++ b/sound/drivers/mpu401/mpu401_uart.c @@ -462,6 +462,7 @@ int snd_mpu401_uart_new(struct snd_card *card, int device, return err; mpu = kzalloc(sizeof(*mpu), GFP_KERNEL); if (mpu == NULL) { + snd_printk(KERN_ERR "mpu401_uart: cannot allocate\n"); snd_device_free(card, rmidi); return -ENOMEM; } diff --git a/sound/drivers/opl3/opl3_lib.c b/sound/drivers/opl3/opl3_lib.c index cbd37e919601..650f3b8e60e0 100644 --- a/sound/drivers/opl3/opl3_lib.c +++ b/sound/drivers/opl3/opl3_lib.c @@ -349,8 +349,10 @@ int snd_opl3_new(struct snd_card *card, *ropl3 = NULL; opl3 = kzalloc(sizeof(*opl3), GFP_KERNEL); - if (opl3 == NULL) + if (opl3 == NULL) { + snd_printk(KERN_ERR "opl3: cannot allocate\n"); return -ENOMEM; + } opl3->card = card; opl3->hardware = hardware; diff --git a/sound/isa/opl3sa2.c b/sound/isa/opl3sa2.c index b923de9b321d..aafe5565b6e5 100644 --- a/sound/isa/opl3sa2.c +++ b/sound/isa/opl3sa2.c @@ -496,21 +496,29 @@ static int __init snd_opl3sa2_mixer(struct snd_opl3sa2 *chip) /* reassign AUX0 to CD */ strcpy(id1.name, "Aux Playback Switch"); strcpy(id2.name, "CD Playback Switch"); - if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0) + if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0) { + snd_printk(KERN_ERR "Cannot rename opl3sa2 control\n"); return err; + } strcpy(id1.name, "Aux Playback Volume"); strcpy(id2.name, "CD Playback Volume"); - if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0) + if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0) { + snd_printk(KERN_ERR "Cannot rename opl3sa2 control\n"); return err; + } /* reassign AUX1 to FM */ strcpy(id1.name, "Aux Playback Switch"); id1.index = 1; strcpy(id2.name, "FM Playback Switch"); - if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0) + if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0) { + snd_printk(KERN_ERR "Cannot rename opl3sa2 control\n"); return err; + } strcpy(id1.name, "Aux Playback Volume"); strcpy(id2.name, "FM Playback Volume"); - if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0) + if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0) { + snd_printk(KERN_ERR "Cannot rename opl3sa2 control\n"); return err; + } /* add OPL3SA2 controls */ for (idx = 0; idx < ARRAY_SIZE(snd_opl3sa2_controls); idx++) { if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_opl3sa2_controls[idx], chip))) < 0) @@ -575,8 +583,10 @@ static int __init snd_opl3sa2_pnp(int dev, struct snd_opl3sa2 *chip, int err; cfg = kmalloc(sizeof(struct pnp_resource_table), GFP_KERNEL); - if (!cfg) + if (!cfg) { + snd_printk(KERN_ERR PFX "cannot allocate pnp cfg\n"); return -ENOMEM; + } /* PnP initialization */ pnp_init_resource_table(cfg); if (sb_port[dev] != SNDRV_AUTO_PORT) @@ -597,7 +607,7 @@ static int __init snd_opl3sa2_pnp(int dev, struct snd_opl3sa2 *chip, pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1); err = pnp_manual_config_dev(pdev, cfg, 0); if (err < 0) - snd_printk(KERN_ERR "PnP manual resources are invalid, using auto config\n"); + snd_printk(KERN_WARNING "PnP manual resources are invalid, using auto config\n"); err = pnp_activate_dev(pdev); if (err < 0) { kfree(cfg); @@ -784,8 +794,11 @@ static int __devinit snd_opl3sa2_pnp_cdetect(struct pnp_card_link *pcard, struct snd_card *card; pdev = pnp_request_card_device(pcard, id->devs[0].id, NULL); - if (pdev == NULL) + if (pdev == NULL) { + snd_printk(KERN_ERR PFX "can't get pnp device from id '%s'\n", + id->devs[0].id); return -EBUSY; + } for (; dev < SNDRV_CARDS; dev++) { if (enable[dev] && isapnp[dev]) break; -- cgit v1.2.3 From f7a9275d949cb0bf1f259a1546e52a0bf518151c Mon Sep 17 00:00:00 2001 From: Clemens Ladisch Date: Wed, 7 Dec 2005 09:13:42 +0100 Subject: [ALSA] unregister platform devices Call platform_device_unregister() for all platform devices that we've registered. Signed-off-by: Clemens Ladisch --- sound/arm/sa11xx-uda1341.c | 6 +++-- sound/drivers/dummy.c | 16 ++++++++++-- sound/drivers/mpu401/mpu401.c | 21 +++++++++++----- sound/drivers/mtpav.c | 4 ++- sound/drivers/serial-u16550.c | 16 ++++++++++-- sound/drivers/virmidi.c | 16 ++++++++++-- sound/isa/ad1848/ad1848.c | 16 ++++++++++-- sound/isa/cmi8330.c | 34 +++++++++++++++++++------ sound/isa/cs423x/cs4231.c | 16 ++++++++++-- sound/isa/cs423x/cs4236.c | 51 +++++++++++++++++++++++++++----------- sound/isa/es1688/es1688.c | 16 ++++++++++-- sound/isa/es18xx.c | 34 +++++++++++++++++++------ sound/isa/gus/gusclassic.c | 16 ++++++++++-- sound/isa/gus/gusextreme.c | 16 ++++++++++-- sound/isa/gus/gusmax.c | 16 ++++++++++-- sound/isa/gus/interwave.c | 34 +++++++++++++++++++------ sound/isa/opl3sa2.c | 43 ++++++++++++++++++++++++-------- sound/isa/opti9xx/opti92x-ad1848.c | 9 +++++-- sound/isa/sb/sb16.c | 42 ++++++++++++++++++++++--------- sound/isa/sb/sb8.c | 16 ++++++++++-- sound/isa/sgalaxy.c | 16 ++++++++++-- sound/isa/sscape.c | 33 ++++++++++++++++++------ sound/isa/wavefront/wavefront.c | 35 ++++++++++++++++++++------ sound/ppc/powermac.c | 4 ++- 24 files changed, 415 insertions(+), 111 deletions(-) (limited to 'sound/isa/opl3sa2.c') diff --git a/sound/arm/sa11xx-uda1341.c b/sound/arm/sa11xx-uda1341.c index 3c342c1a7c80..13057d92f08a 100644 --- a/sound/arm/sa11xx-uda1341.c +++ b/sound/arm/sa11xx-uda1341.c @@ -21,7 +21,7 @@ * merged HAL layer (patches from Brian) */ -/* $Id: sa11xx-uda1341.c,v 1.26 2005/11/17 17:19:50 tiwai Exp $ */ +/* $Id: sa11xx-uda1341.c,v 1.27 2005/12/07 09:13:42 cladisch Exp $ */ /*************************************************************************************************** * @@ -155,6 +155,8 @@ static struct snd_pcm_hw_constraint_list hw_constraints_rates = { .mask = 0, }; +static struct platform_device *device; + /* }}} */ /* {{{ Clock and sample rate stuff */ @@ -976,7 +978,6 @@ static struct platform_driver sa11xx_uda1341_driver = { static int __init sa11xx_uda1341_init(void) { int err; - struct platform_device *device; if (!machine_is_h3xxx()) return -ENODEV; @@ -992,6 +993,7 @@ static int __init sa11xx_uda1341_init(void) static void __exit sa11xx_uda1341_exit(void) { + platform_device_unregister(device); platform_driver_unregister(&sa11xx_uda1341_driver); } diff --git a/sound/drivers/dummy.c b/sound/drivers/dummy.c index 186117571745..96d207051628 100644 --- a/sound/drivers/dummy.c +++ b/sound/drivers/dummy.c @@ -144,6 +144,8 @@ MODULE_PARM_DESC(pcm_substreams, "PCM substreams # (1-16) for dummy driver."); //module_param_array(midi_devs, int, NULL, 0444); //MODULE_PARM_DESC(midi_devs, "MIDI devices # (0-2) for dummy driver."); +static struct platform_device *devices[SNDRV_CARDS]; + #define MIXER_ADDR_MASTER 0 #define MIXER_ADDR_LINE 1 #define MIXER_ADDR_MIC 2 @@ -634,6 +636,15 @@ static struct platform_driver snd_dummy_driver = { }, }; +static void __init_or_module snd_dummy_unregister_all(void) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(devices); ++i) + platform_device_unregister(devices[i]); + platform_driver_unregister(&snd_dummy_driver); +} + static int __init alsa_card_dummy_init(void) { int i, cards, err; @@ -650,6 +661,7 @@ static int __init alsa_card_dummy_init(void) err = PTR_ERR(device); goto errout; } + devices[i] = device; cards++; } if (!cards) { @@ -662,13 +674,13 @@ static int __init alsa_card_dummy_init(void) return 0; errout: - platform_driver_unregister(&snd_dummy_driver); + snd_dummy_unregister_all(); return err; } static void __exit alsa_card_dummy_exit(void) { - platform_driver_unregister(&snd_dummy_driver); + snd_dummy_unregister_all(); } module_init(alsa_card_dummy_init) diff --git a/sound/drivers/mpu401/mpu401.c b/sound/drivers/mpu401/mpu401.c index ec817a86d3dd..915589a402ab 100644 --- a/sound/drivers/mpu401/mpu401.c +++ b/sound/drivers/mpu401/mpu401.c @@ -58,6 +58,7 @@ MODULE_PARM_DESC(port, "Port # for MPU-401 device."); module_param_array(irq, int, NULL, 0444); MODULE_PARM_DESC(irq, "IRQ # for MPU-401 device."); +static struct platform_device *platform_devices[SNDRV_CARDS]; static int pnp_registered = 0; static int snd_mpu401_create(int dev, struct snd_card **rcard) @@ -220,6 +221,17 @@ static struct pnp_driver snd_mpu401_pnp_driver = { static struct pnp_driver snd_mpu401_pnp_driver; #endif +static void __init_or_module snd_mpu401_unregister_all(void) +{ + int i; + + if (pnp_registered) + pnp_unregister_driver(&snd_mpu401_pnp_driver); + for (i = 0; i < ARRAY_SIZE(platform_devices); ++i) + platform_device_unregister(platform_devices[i]); + platform_driver_unregister(&snd_mpu401_driver); +} + static int __init alsa_card_mpu401_init(void) { int i, err, devices; @@ -240,6 +252,7 @@ static int __init alsa_card_mpu401_init(void) err = PTR_ERR(device); goto errout; } + platform_devices[i] = device; devices++; } if ((err = pnp_register_driver(&snd_mpu401_pnp_driver)) >= 0) { @@ -257,17 +270,13 @@ static int __init alsa_card_mpu401_init(void) return 0; errout: - if (pnp_registered) - pnp_unregister_driver(&snd_mpu401_pnp_driver); - platform_driver_unregister(&snd_mpu401_driver); + snd_mpu401_unregister_all(); return err; } static void __exit alsa_card_mpu401_exit(void) { - if (pnp_registered) - pnp_unregister_driver(&snd_mpu401_pnp_driver); - platform_driver_unregister(&snd_mpu401_driver); + snd_mpu401_unregister_all(); } module_init(alsa_card_mpu401_init) diff --git a/sound/drivers/mtpav.c b/sound/drivers/mtpav.c index d9c4e224fa5f..b7a0b42813e1 100644 --- a/sound/drivers/mtpav.c +++ b/sound/drivers/mtpav.c @@ -95,6 +95,8 @@ MODULE_PARM_DESC(irq, "Parallel IRQ # for MotuMTPAV MIDI."); module_param(hwports, int, 0444); MODULE_PARM_DESC(hwports, "Hardware ports # for MotuMTPAV MIDI."); +static struct platform_device *device; + /* * defines */ @@ -763,7 +765,6 @@ static struct platform_driver snd_mtpav_driver = { static int __init alsa_card_mtpav_init(void) { int err; - struct platform_device *device; if ((err = platform_driver_register(&snd_mtpav_driver)) < 0) return err; @@ -778,6 +779,7 @@ static int __init alsa_card_mtpav_init(void) static void __exit alsa_card_mtpav_exit(void) { + platform_device_unregister(device); platform_driver_unregister(&snd_mtpav_driver); } diff --git a/sound/drivers/serial-u16550.c b/sound/drivers/serial-u16550.c index 3381a43c592e..29676d800cae 100644 --- a/sound/drivers/serial-u16550.c +++ b/sound/drivers/serial-u16550.c @@ -168,6 +168,8 @@ typedef struct _snd_uart16550 { } snd_uart16550_t; +static struct platform_device *devices[SNDRV_CARDS]; + static inline void snd_uart16550_add_timer(snd_uart16550_t *uart) { if (! uart->timer_running) { @@ -970,6 +972,15 @@ static struct platform_driver snd_serial_driver = { }, }; +static void __init_or_module snd_serial_unregister_all(void) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(devices); ++i) + platform_device_unregister(devices[i]); + platform_driver_unregister(&snd_serial_driver); +} + static int __init alsa_card_serial_init(void) { int i, cards, err; @@ -986,6 +997,7 @@ static int __init alsa_card_serial_init(void) err = PTR_ERR(device); goto errout; } + devices[i] = device; cards++; } if (! cards) { @@ -998,13 +1010,13 @@ static int __init alsa_card_serial_init(void) return 0; errout: - platform_driver_unregister(&snd_serial_driver); + snd_serial_unregister_all(); return err; } static void __exit alsa_card_serial_exit(void) { - platform_driver_unregister(&snd_serial_driver); + snd_serial_unregister_all(); } module_init(alsa_card_serial_init) diff --git a/sound/drivers/virmidi.c b/sound/drivers/virmidi.c index 9f36a6472478..4258723de2ab 100644 --- a/sound/drivers/virmidi.c +++ b/sound/drivers/virmidi.c @@ -82,6 +82,8 @@ struct snd_card_virmidi { struct snd_rawmidi *midi[MAX_MIDI_DEVICES]; }; +static struct platform_device *devices[SNDRV_CARDS]; + static int __init snd_virmidi_probe(struct platform_device *devptr) { @@ -144,6 +146,15 @@ static struct platform_driver snd_virmidi_driver = { }, }; +static void __init_or_module snd_virmidi_unregister_all(void) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(devices); ++i) + platform_device_unregister(devices[i]); + platform_driver_unregister(&snd_virmidi_driver); +} + static int __init alsa_card_virmidi_init(void) { int i, cards, err; @@ -160,6 +171,7 @@ static int __init alsa_card_virmidi_init(void) err = PTR_ERR(device); goto errout; } + devices[i] = device; cards++; } if (!cards) { @@ -172,13 +184,13 @@ static int __init alsa_card_virmidi_init(void) return 0; errout: - platform_driver_unregister(&snd_virmidi_driver); + snd_virmidi_unregister_all(); return err; } static void __exit alsa_card_virmidi_exit(void) { - platform_driver_unregister(&snd_virmidi_driver); + snd_virmidi_unregister_all(); } module_init(alsa_card_virmidi_init) diff --git a/sound/isa/ad1848/ad1848.c b/sound/isa/ad1848/ad1848.c index 1019e9fdff53..e091bbeffd2a 100644 --- a/sound/isa/ad1848/ad1848.c +++ b/sound/isa/ad1848/ad1848.c @@ -62,6 +62,8 @@ MODULE_PARM_DESC(dma1, "DMA1 # for AD1848 driver."); module_param_array(thinkpad, bool, NULL, 0444); MODULE_PARM_DESC(thinkpad, "Enable only for the onboard CS4248 of IBM Thinkpad 360/750/755 series."); +static struct platform_device *devices[SNDRV_CARDS]; + static int __init snd_ad1848_probe(struct platform_device *pdev) { @@ -167,6 +169,15 @@ static struct platform_driver snd_ad1848_driver = { }, }; +static void __init_or_module snd_ad1848_unregister_all(void) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(devices); ++i) + platform_device_unregister(devices[i]); + platform_driver_unregister(&snd_ad1848_driver); +} + static int __init alsa_card_ad1848_init(void) { int i, cards, err; @@ -184,6 +195,7 @@ static int __init alsa_card_ad1848_init(void) err = PTR_ERR(device); goto errout; } + devices[i] = device; cards++; } if (!cards) { @@ -196,13 +208,13 @@ static int __init alsa_card_ad1848_init(void) return 0; errout: - platform_driver_unregister(&snd_ad1848_driver); + snd_ad1848_unregister_all(); return err; } static void __exit alsa_card_ad1848_exit(void) { - platform_driver_unregister(&snd_ad1848_driver); + snd_ad1848_unregister_all(); } module_init(alsa_card_ad1848_init) diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c index ba0114ebafde..bd8e23818460 100644 --- a/sound/isa/cmi8330.c +++ b/sound/isa/cmi8330.c @@ -108,6 +108,9 @@ MODULE_PARM_DESC(wssirq, "IRQ # for CMI8330 WSS driver."); module_param_array(wssdma, int, NULL, 0444); MODULE_PARM_DESC(wssdma, "DMA for CMI8330 WSS driver."); +static struct platform_device *platform_devices[SNDRV_CARDS]; +static int pnp_registered; + #define CMI8330_RMUX3D 16 #define CMI8330_MUTEMUX 17 #define CMI8330_OUTPUTVOL 18 @@ -665,6 +668,17 @@ static struct pnp_card_driver cmi8330_pnpc_driver = { }; #endif /* CONFIG_PNP */ +static void __init_or_module snd_cmi8330_unregister_all(void) +{ + int i; + + if (pnp_registered) + pnp_unregister_card_driver(&cmi8330_pnpc_driver); + for (i = 0; i < ARRAY_SIZE(platform_devices); ++i) + platform_device_unregister(platform_devices[i]); + platform_driver_unregister(&snd_cmi8330_driver); +} + static int __init alsa_card_cmi8330_init(void) { int i, err, cards = 0; @@ -680,31 +694,35 @@ static int __init alsa_card_cmi8330_init(void) i, NULL, 0); if (IS_ERR(device)) { err = PTR_ERR(device); - platform_driver_unregister(&snd_cmi8330_driver); - return err; + goto errout; } + platform_devices[i] = device; cards++; } err = pnp_register_card_driver(&cmi8330_pnpc_driver); - if (err > 0) + if (err >= 0) { + pnp_registered = 1; cards += err; + } if (!cards) { - pnp_unregister_card_driver(&cmi8330_pnpc_driver); - platform_driver_unregister(&snd_cmi8330_driver); #ifdef MODULE snd_printk(KERN_ERR "CMI8330 not found or device busy\n"); #endif - return -ENODEV; + err = -ENODEV; + goto errout; } return 0; + + errout: + snd_cmi8330_unregister_all(); + return err; } static void __exit alsa_card_cmi8330_exit(void) { - pnp_unregister_card_driver(&cmi8330_pnpc_driver); - platform_driver_unregister(&snd_cmi8330_driver); + snd_cmi8330_unregister_all(); } module_init(alsa_card_cmi8330_init) diff --git a/sound/isa/cs423x/cs4231.c b/sound/isa/cs423x/cs4231.c index b5252a5d7412..ab67b5c2590d 100644 --- a/sound/isa/cs423x/cs4231.c +++ b/sound/isa/cs423x/cs4231.c @@ -66,6 +66,8 @@ MODULE_PARM_DESC(dma1, "DMA1 # for CS4231 driver."); module_param_array(dma2, int, NULL, 0444); MODULE_PARM_DESC(dma2, "DMA2 # for CS4231 driver."); +static struct platform_device *devices[SNDRV_CARDS]; + static int __init snd_cs4231_probe(struct platform_device *pdev) { @@ -183,6 +185,15 @@ static struct platform_driver snd_cs4231_driver = { }, }; +static void __init_or_module snd_cs4231_unregister_all(void) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(devices); ++i) + platform_device_unregister(devices[i]); + platform_driver_unregister(&snd_cs4231_driver); +} + static int __init alsa_card_cs4231_init(void) { int i, cards, err; @@ -200,6 +211,7 @@ static int __init alsa_card_cs4231_init(void) err = PTR_ERR(device); goto errout; } + devices[i] = device; cards++; } if (!cards) { @@ -212,13 +224,13 @@ static int __init alsa_card_cs4231_init(void) return 0; errout: - platform_driver_unregister(&snd_cs4231_driver); + snd_cs4231_unregister_all(); return err; } static void __exit alsa_card_cs4231_exit(void) { - platform_driver_unregister(&snd_cs4231_driver); + snd_cs4231_unregister_all(); } module_init(alsa_card_cs4231_init) diff --git a/sound/isa/cs423x/cs4236.c b/sound/isa/cs423x/cs4236.c index 9e399b6e6ed9..e1683337e6cd 100644 --- a/sound/isa/cs423x/cs4236.c +++ b/sound/isa/cs423x/cs4236.c @@ -124,6 +124,12 @@ MODULE_PARM_DESC(dma1, "DMA1 # for " IDENT " driver."); module_param_array(dma2, int, NULL, 0444); MODULE_PARM_DESC(dma2, "DMA2 # for " IDENT " driver."); +static struct platform_device *platform_devices[SNDRV_CARDS]; +static int pnpc_registered; +#ifdef CS4232 +static int pnp_registered; +#endif + struct snd_card_cs4236 { struct snd_cs4231 *chip; struct resource *res_sb_port; @@ -737,6 +743,21 @@ static struct pnp_card_driver cs423x_pnpc_driver = { }; #endif /* CONFIG_PNP */ +static void __init_or_module snd_cs423x_unregister_all(void) +{ + int i; + + if (pnpc_registered) + pnp_unregister_card_driver(&cs423x_pnpc_driver); +#ifdef CS4232 + if (pnp_registered) + pnp_unregister_driver(&cs4232_pnp_driver); +#endif + 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 i, err, cards = 0; @@ -752,40 +773,40 @@ static int __init alsa_card_cs423x_init(void) i, NULL, 0); if (IS_ERR(device)) { err = PTR_ERR(device); - platform_driver_unregister(&cs423x_nonpnp_driver); - return err; + goto errout; } + platform_devices[i] = device; cards++; } #ifdef CS4232 i = pnp_register_driver(&cs4232_pnp_driver); - if (i > 0) + if (i >= 0) { + pnp_registered = 1; cards += i; + } #endif i = pnp_register_card_driver(&cs423x_pnpc_driver); - if (i > 0) + if (i >= 0) { + pnpc_registered = 1; cards += i; + } if (!cards) { -#ifdef CS4232 - pnp_unregister_driver(&cs4232_pnp_driver); -#endif - pnp_unregister_card_driver(&cs423x_pnpc_driver); - platform_driver_unregister(&cs423x_nonpnp_driver); #ifdef MODULE printk(KERN_ERR IDENT " soundcard not found or device busy\n"); #endif - return -ENODEV; + err = -ENODEV; + goto errout; } return 0; + + errout: + snd_cs423x_unregister_all(); + return err; } static void __exit alsa_card_cs423x_exit(void) { -#ifdef CS4232 - pnp_unregister_driver(&cs4232_pnp_driver); -#endif - pnp_unregister_card_driver(&cs423x_pnpc_driver); - platform_driver_unregister(&cs423x_nonpnp_driver); + snd_cs423x_unregister_all(); } module_init(alsa_card_cs423x_init) diff --git a/sound/isa/es1688/es1688.c b/sound/isa/es1688/es1688.c index 68bd40a76f01..50d23cf3d7cc 100644 --- a/sound/isa/es1688/es1688.c +++ b/sound/isa/es1688/es1688.c @@ -69,6 +69,8 @@ MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for ESx688 driver."); module_param_array(dma8, int, NULL, 0444); MODULE_PARM_DESC(dma8, "8-bit DMA # for ESx688 driver."); +static struct platform_device *devices[SNDRV_CARDS]; + #define PFX "es1688: " static int __init snd_es1688_probe(struct platform_device *pdev) @@ -187,6 +189,15 @@ static struct platform_driver snd_es1688_driver = { }, }; +static void __init_or_module snd_es1688_unregister_all(void) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(devices); ++i) + platform_device_unregister(devices[i]); + platform_driver_unregister(&snd_es1688_driver); +} + static int __init alsa_card_es1688_init(void) { int i, cards, err; @@ -204,6 +215,7 @@ static int __init alsa_card_es1688_init(void) err = PTR_ERR(device); goto errout; } + devices[i] = device; cards++; } if (!cards) { @@ -216,13 +228,13 @@ static int __init alsa_card_es1688_init(void) return 0; errout: - platform_driver_unregister(&snd_es1688_driver); + snd_es1688_unregister_all(); return err; } static void __exit alsa_card_es1688_exit(void) { - platform_driver_unregister(&snd_es1688_driver); + snd_es1688_unregister_all(); } module_init(alsa_card_es1688_init) diff --git a/sound/isa/es18xx.c b/sound/isa/es18xx.c index 34d47132f082..bf5de0782eb0 100644 --- a/sound/isa/es18xx.c +++ b/sound/isa/es18xx.c @@ -1877,6 +1877,9 @@ MODULE_PARM_DESC(dma1, "DMA 1 # for ES18xx driver."); module_param_array(dma2, int, NULL, 0444); MODULE_PARM_DESC(dma2, "DMA 2 # for ES18xx driver."); +static struct platform_device *platform_devices[SNDRV_CARDS]; +static int pnp_registered; + #ifdef CONFIG_PNP static struct pnp_card_device_id snd_audiodrive_pnpids[] = { @@ -2202,6 +2205,17 @@ static struct pnp_card_driver es18xx_pnpc_driver = { }; #endif /* CONFIG_PNP */ +static void __init_or_module snd_es18xx_unregister_all(void) +{ + int i; + + if (pnp_registered) + pnp_unregister_card_driver(&es18xx_pnpc_driver); + for (i = 0; i < ARRAY_SIZE(platform_devices); ++i) + platform_device_unregister(platform_devices[i]); + platform_driver_unregister(&snd_es18xx_nonpnp_driver); +} + static int __init alsa_card_es18xx_init(void) { int i, err, cards = 0; @@ -2217,31 +2231,35 @@ static int __init alsa_card_es18xx_init(void) i, NULL, 0); if (IS_ERR(device)) { err = PTR_ERR(device); - platform_driver_unregister(&snd_es18xx_nonpnp_driver); - return err; + goto errout; } + platform_devices[i] = device; cards++; } i = pnp_register_card_driver(&es18xx_pnpc_driver); - if (i > 0) + if (i >= 0) { + pnp_registered = 1; cards += i; + } if(!cards) { - pnp_unregister_card_driver(&es18xx_pnpc_driver); - platform_driver_unregister(&snd_es18xx_nonpnp_driver); #ifdef MODULE snd_printk(KERN_ERR "ESS AudioDrive ES18xx soundcard not found or device busy\n"); #endif - return -ENODEV; + err = -ENODEV; + goto errout; } return 0; + + errout: + snd_es18xx_unregister_all(); + return err; } static void __exit alsa_card_es18xx_exit(void) { - pnp_unregister_card_driver(&es18xx_pnpc_driver); - platform_driver_unregister(&snd_es18xx_nonpnp_driver); + snd_es18xx_unregister_all(); } module_init(alsa_card_es18xx_init) diff --git a/sound/isa/gus/gusclassic.c b/sound/isa/gus/gusclassic.c index 57beb74f5b9d..d1165b96fa3f 100644 --- a/sound/isa/gus/gusclassic.c +++ b/sound/isa/gus/gusclassic.c @@ -71,6 +71,8 @@ MODULE_PARM_DESC(channels, "GF1 channels for GUS Classic driver."); module_param_array(pcm_channels, int, NULL, 0444); MODULE_PARM_DESC(pcm_channels, "Reserved PCM channels for GUS Classic driver."); +static struct platform_device *devices[SNDRV_CARDS]; + #define PFX "gusclassic: " @@ -227,6 +229,15 @@ static struct platform_driver snd_gusclassic_driver = { }, }; +static void __init_or_module snd_gusclassic_unregister_all(void) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(devices); ++i) + platform_device_unregister(devices[i]); + platform_driver_unregister(&snd_gusclassic_driver); +} + static int __init alsa_card_gusclassic_init(void) { int i, cards, err; @@ -244,6 +255,7 @@ static int __init alsa_card_gusclassic_init(void) err = PTR_ERR(device); goto errout; } + devices[i] = device; cards++; } if (!cards) { @@ -256,13 +268,13 @@ static int __init alsa_card_gusclassic_init(void) return 0; errout: - platform_driver_unregister(&snd_gusclassic_driver); + snd_gusclassic_unregister_all(); return err; } static void __exit alsa_card_gusclassic_exit(void) { - platform_driver_unregister(&snd_gusclassic_driver); + snd_gusclassic_unregister_all(); } module_init(alsa_card_gusclassic_init) diff --git a/sound/isa/gus/gusextreme.c b/sound/isa/gus/gusextreme.c index 6fad9734a853..239f16e6b9ee 100644 --- a/sound/isa/gus/gusextreme.c +++ b/sound/isa/gus/gusextreme.c @@ -87,6 +87,8 @@ MODULE_PARM_DESC(channels, "GF1 channels for GUS Extreme driver."); module_param_array(pcm_channels, int, NULL, 0444); MODULE_PARM_DESC(pcm_channels, "Reserved PCM channels for GUS Extreme driver."); +struct platform_device *devices[SNDRV_CARDS]; + #define PFX "gusextreme: " @@ -337,6 +339,15 @@ static struct platform_driver snd_gusextreme_driver = { }, }; +static void __init_or_module snd_gusextreme_unregister_all(void) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(devices); ++i) + platform_device_unregister(devices[i]); + platform_driver_unregister(&snd_gusextreme_driver); +} + static int __init alsa_card_gusextreme_init(void) { int i, cards, err; @@ -354,6 +365,7 @@ static int __init alsa_card_gusextreme_init(void) err = PTR_ERR(device); goto errout; } + devices[i] = device; cards++; } if (!cards) { @@ -366,13 +378,13 @@ static int __init alsa_card_gusextreme_init(void) return 0; errout: - platform_driver_unregister(&snd_gusextreme_driver); + snd_gusextreme_unregister_all(); return err; } static void __exit alsa_card_gusextreme_exit(void) { - platform_driver_unregister(&snd_gusextreme_driver); + snd_gusextreme_unregister_all(); } module_init(alsa_card_gusextreme_init) diff --git a/sound/isa/gus/gusmax.c b/sound/isa/gus/gusmax.c index d1b70ee9b039..d4d2b2a517d5 100644 --- a/sound/isa/gus/gusmax.c +++ b/sound/isa/gus/gusmax.c @@ -72,6 +72,8 @@ MODULE_PARM_DESC(channels, "Used GF1 channels for GUS MAX driver."); module_param_array(pcm_channels, int, NULL, 0444); MODULE_PARM_DESC(pcm_channels, "Reserved PCM channels for GUS MAX driver."); +static struct platform_device *devices[SNDRV_CARDS]; + struct snd_gusmax { int irq; struct snd_card *card; @@ -364,6 +366,15 @@ static struct platform_driver snd_gusmax_driver = { }, }; +static void __init_or_module snd_gusmax_unregister_all(void) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(devices); ++i) + platform_device_unregister(devices[i]); + platform_driver_unregister(&snd_gusmax_driver); +} + static int __init alsa_card_gusmax_init(void) { int i, cards, err; @@ -381,6 +392,7 @@ static int __init alsa_card_gusmax_init(void) err = PTR_ERR(device); goto errout; } + devices[i] = device; cards++; } if (!cards) { @@ -393,13 +405,13 @@ static int __init alsa_card_gusmax_init(void) return 0; errout: - platform_driver_unregister(&snd_gusmax_driver); + snd_gusmax_unregister_all(); return err; } static void __exit alsa_card_gusmax_exit(void) { - platform_driver_unregister(&snd_gusmax_driver); + snd_gusmax_unregister_all(); } module_init(alsa_card_gusmax_init) diff --git a/sound/isa/gus/interwave.c b/sound/isa/gus/interwave.c index 67a5f7402453..9838d992b101 100644 --- a/sound/isa/gus/interwave.c +++ b/sound/isa/gus/interwave.c @@ -115,6 +115,9 @@ MODULE_PARM_DESC(pcm_channels, "Reserved PCM channels for InterWave driver."); module_param_array(effect, int, NULL, 0444); MODULE_PARM_DESC(effect, "Effects enable for InterWave driver."); +static struct platform_device *platform_devices[SNDRV_CARDS]; +static int pnp_registered; + struct snd_interwave { int irq; struct snd_card *card; @@ -914,6 +917,17 @@ static struct pnp_card_driver interwave_pnpc_driver = { #endif /* CONFIG_PNP */ +static void __init_or_module snd_interwave_unregister_all(void) +{ + int i; + + if (pnp_registered) + pnp_unregister_card_driver(&interwave_pnpc_driver); + for (i = 0; i < ARRAY_SIZE(platform_devices); ++i) + platform_device_unregister(platform_devices[i]); + platform_driver_unregister(&snd_interwave_driver); +} + static int __init alsa_card_interwave_init(void) { int i, err, cards = 0; @@ -931,32 +945,36 @@ static int __init alsa_card_interwave_init(void) i, NULL, 0); if (IS_ERR(device)) { err = PTR_ERR(device); - platform_driver_unregister(&snd_interwave_driver); - return err; + goto errout; } + platform_devices[i] = device; cards++; } /* ISA PnP cards */ i = pnp_register_card_driver(&interwave_pnpc_driver); - if (i > 0) + if (i >= 0) { + pnp_registered = 1; cards += i; + } if (!cards) { - pnp_unregister_card_driver(&interwave_pnpc_driver); - platform_driver_unregister(&snd_interwave_driver); #ifdef MODULE printk(KERN_ERR "InterWave soundcard not found or device busy\n"); #endif - return -ENODEV; + err = -ENODEV; + goto errout; } return 0; + + errout: + snd_interwave_unregister_all(); + return err; } static void __exit alsa_card_interwave_exit(void) { - pnp_unregister_card_driver(&interwave_pnpc_driver); - platform_driver_unregister(&snd_interwave_driver); + snd_interwave_unregister_all(); } module_init(alsa_card_interwave_init) diff --git a/sound/isa/opl3sa2.c b/sound/isa/opl3sa2.c index aafe5565b6e5..ca359e0c674b 100644 --- a/sound/isa/opl3sa2.c +++ b/sound/isa/opl3sa2.c @@ -90,6 +90,10 @@ MODULE_PARM_DESC(dma2, "DMA2 # for OPL3-SA driver."); module_param_array(opl3sa3_ymode, int, NULL, 0444); MODULE_PARM_DESC(opl3sa3_ymode, "Speaker size selection for 3D Enhancement mode: Desktop/Large Notebook/Small Notebook/HiFi."); +static struct platform_device *platform_devices[SNDRV_CARDS]; +static int pnp_registered; +static int pnpc_registered; + /* control ports */ #define OPL3SA2_PM_CTRL 0x01 #define OPL3SA2_SYS_CTRL 0x02 @@ -921,6 +925,19 @@ static struct platform_driver snd_opl3sa2_nonpnp_driver = { }, }; +static void __init_or_module snd_opl3sa2_unregister_all(void) +{ + int i; + + if (pnpc_registered) + pnp_unregister_card_driver(&opl3sa2_pnpc_driver); + if (pnp_registered) + pnp_unregister_driver(&opl3sa2_pnp_driver); + for (i = 0; i < ARRAY_SIZE(platform_devices); ++i) + platform_device_unregister(platform_devices[i]); + platform_driver_unregister(&snd_opl3sa2_nonpnp_driver); +} + static int __init alsa_card_opl3sa2_init(void) { int i, err, cards = 0; @@ -938,36 +955,40 @@ static int __init alsa_card_opl3sa2_init(void) i, NULL, 0); if (IS_ERR(device)) { err = PTR_ERR(device); - platform_driver_unregister(&snd_opl3sa2_nonpnp_driver); - return err; + goto errout; } + platform_devices[i] = device; cards++; } err = pnp_register_driver(&opl3sa2_pnp_driver); - if (err > 0) + if (err >= 0) { + pnp_registered = 1; cards += err; + } err = pnp_register_card_driver(&opl3sa2_pnpc_driver); - if (err > 0) + if (err >= 0) { + pnpc_registered = 1; cards += err; + } if (!cards) { #ifdef MODULE snd_printk(KERN_ERR "Yamaha OPL3-SA soundcard not found or device busy\n"); #endif - pnp_unregister_card_driver(&opl3sa2_pnpc_driver); - pnp_unregister_driver(&opl3sa2_pnp_driver); - platform_driver_unregister(&snd_opl3sa2_nonpnp_driver); - return -ENODEV; + err = -ENODEV; + goto errout; } return 0; + + errout: + snd_opl3sa2_unregister_all(); + return err; } static void __exit alsa_card_opl3sa2_exit(void) { - pnp_unregister_card_driver(&opl3sa2_pnpc_driver); - pnp_unregister_driver(&opl3sa2_pnp_driver); - platform_driver_unregister(&snd_opl3sa2_nonpnp_driver); + snd_opl3sa2_unregister_all(); } module_init(alsa_card_opl3sa2_init) diff --git a/sound/isa/opti9xx/opti92x-ad1848.c b/sound/isa/opti9xx/opti92x-ad1848.c index 39211e58cd68..1ea3944ef7ab 100644 --- a/sound/isa/opti9xx/opti92x-ad1848.c +++ b/sound/isa/opti9xx/opti92x-ad1848.c @@ -259,6 +259,7 @@ struct snd_opti9xx { }; static int snd_opti9xx_pnp_is_probed; +static struct platform_device *snd_opti9xx_platform_device; #ifdef CONFIG_PNP @@ -2095,8 +2096,10 @@ static int __init alsa_card_opti9xx_init(void) if (error < 0) return error; device = platform_device_register_simple(DRIVER_NAME, -1, NULL, 0); - if (! IS_ERR(device)) + if (!IS_ERR(device)) { + snd_opti9xx_platform_device = device; return 0; + } platform_driver_unregister(&snd_opti9xx_driver); } pnp_unregister_card_driver(&opti9xx_pnpc_driver); @@ -2108,8 +2111,10 @@ static int __init alsa_card_opti9xx_init(void) static void __exit alsa_card_opti9xx_exit(void) { - if (! snd_opti9xx_pnp_is_probed) + if (!snd_opti9xx_pnp_is_probed) { + platform_device_unregister(snd_opti9xx_platform_device); platform_driver_unregister(&snd_opti9xx_driver); + } pnp_unregister_card_driver(&opti9xx_pnpc_driver); } diff --git a/sound/isa/sb/sb16.c b/sound/isa/sb/sb16.c index 05816c5d829a..c0be7a5a3425 100644 --- a/sound/isa/sb/sb16.c +++ b/sound/isa/sb/sb16.c @@ -128,6 +128,11 @@ module_param_array(seq_ports, int, NULL, 0444); MODULE_PARM_DESC(seq_ports, "Number of sequencer ports for WaveTable synth."); #endif +static struct platform_device *platform_devices[SNDRV_CARDS]; +#ifdef CONFIG_PNP +static int pnp_registered; +#endif + struct snd_card_sb16 { struct resource *fm_res; /* used to block FM i/o region for legacy cards */ struct snd_sb *chip; @@ -687,6 +692,19 @@ static struct pnp_card_driver sb16_pnpc_driver = { #endif /* CONFIG_PNP */ +static void __init_or_module snd_sb16_unregister_all(void) +{ + int i; + +#ifdef CONFIG_PNP + if (pnp_registered) + pnp_unregister_card_driver(&sb16_pnpc_driver); +#endif + for (i = 0; i < ARRAY_SIZE(platform_devices); ++i) + platform_device_unregister(platform_devices[i]); + platform_driver_unregister(&snd_sb16_nonpnp_driver); +} + static int __init alsa_card_sb16_init(void) { int i, err, cards = 0; @@ -702,23 +720,21 @@ static int __init alsa_card_sb16_init(void) i, NULL, 0); if (IS_ERR(device)) { err = PTR_ERR(device); - platform_driver_unregister(&snd_sb16_nonpnp_driver); - return err; + goto errout; } + platform_devices[i] = device; cards++; } #ifdef CONFIG_PNP /* PnP cards at last */ i = pnp_register_card_driver(&sb16_pnpc_driver); - if (i > 0) + if (i >= 0) { + pnp_registered = 1; cards += i; + } #endif if (!cards) { -#ifdef CONFIG_PNP - pnp_unregister_card_driver(&sb16_pnpc_driver); -#endif - platform_driver_unregister(&snd_sb16_nonpnp_driver); #ifdef MODULE snd_printk(KERN_ERR "Sound Blaster 16 soundcard not found or device busy\n"); #ifdef SNDRV_SBAWE_EMU8000 @@ -727,17 +743,19 @@ static int __init alsa_card_sb16_init(void) snd_printk(KERN_ERR "In case, if you have AWE card, try snd-sbawe module\n"); #endif #endif - return -ENODEV; + err = -ENODEV; + goto errout; } return 0; + + errout: + snd_sb16_unregister_all(); + return err; } static void __exit alsa_card_sb16_exit(void) { -#ifdef CONFIG_PNP - pnp_unregister_card_driver(&sb16_pnpc_driver); -#endif - platform_driver_unregister(&snd_sb16_nonpnp_driver); + snd_sb16_unregister_all(); } module_init(alsa_card_sb16_init) diff --git a/sound/isa/sb/sb8.c b/sound/isa/sb/sb8.c index 0a3d55d639a9..60ee79cd14a3 100644 --- a/sound/isa/sb/sb8.c +++ b/sound/isa/sb/sb8.c @@ -56,6 +56,8 @@ MODULE_PARM_DESC(irq, "IRQ # for SB8 driver."); module_param_array(dma8, int, NULL, 0444); MODULE_PARM_DESC(dma8, "8-bit DMA # for SB8 driver."); +static struct platform_device *devices[SNDRV_CARDS]; + struct snd_sb8 { struct resource *fm_res; /* used to block FM i/o region for legacy cards */ struct snd_sb *chip; @@ -238,6 +240,15 @@ static struct platform_driver snd_sb8_driver = { }, }; +static void __init_or_module snd_sb8_unregister_all(void) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(devices); ++i) + platform_device_unregister(devices[i]); + platform_driver_unregister(&snd_sb8_driver); +} + static int __init alsa_card_sb8_init(void) { int i, cards, err; @@ -255,6 +266,7 @@ static int __init alsa_card_sb8_init(void) err = PTR_ERR(device); goto errout; } + devices[i] = device; cards++; } if (!cards) { @@ -267,13 +279,13 @@ static int __init alsa_card_sb8_init(void) return 0; errout: - platform_driver_unregister(&snd_sb8_driver); + snd_sb8_unregister_all(); return err; } static void __exit alsa_card_sb8_exit(void) { - platform_driver_unregister(&snd_sb8_driver); + snd_sb8_unregister_all(); } module_init(alsa_card_sb8_init) diff --git a/sound/isa/sgalaxy.c b/sound/isa/sgalaxy.c index 2e1d4677fe12..0dbbb35b242c 100644 --- a/sound/isa/sgalaxy.c +++ b/sound/isa/sgalaxy.c @@ -64,6 +64,8 @@ MODULE_PARM_DESC(irq, "IRQ # for Sound Galaxy driver."); module_param_array(dma1, int, NULL, 0444); MODULE_PARM_DESC(dma1, "DMA1 # for Sound Galaxy driver."); +static struct platform_device *devices[SNDRV_CARDS]; + #define SGALAXY_AUXC_LEFT 18 #define SGALAXY_AUXC_RIGHT 19 @@ -340,6 +342,15 @@ static struct platform_driver snd_sgalaxy_driver = { }, }; +static void __init_or_module snd_sgalaxy_unregister_all(void) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(devices); ++i) + platform_device_unregister(devices[i]); + platform_driver_unregister(&snd_sgalaxy_driver); +} + static int __init alsa_card_sgalaxy_init(void) { int i, cards, err; @@ -357,6 +368,7 @@ static int __init alsa_card_sgalaxy_init(void) err = PTR_ERR(device); goto errout; } + devices[i] = device; cards++; } if (!cards) { @@ -369,13 +381,13 @@ static int __init alsa_card_sgalaxy_init(void) return 0; errout: - platform_driver_unregister(&snd_sgalaxy_driver); + snd_sgalaxy_unregister_all(); return err; } static void __exit alsa_card_sgalaxy_exit(void) { - platform_driver_unregister(&snd_sgalaxy_driver); + snd_sgalaxy_unregister_all(); } module_init(alsa_card_sgalaxy_init) diff --git a/sound/isa/sscape.c b/sound/isa/sscape.c index 6271efe689df..5fb981c0a281 100644 --- a/sound/isa/sscape.c +++ b/sound/isa/sscape.c @@ -67,6 +67,9 @@ MODULE_PARM_DESC(mpu_irq, "MPU401 IRQ # for SoundScape driver."); module_param_array(dma, int, NULL, 0444); MODULE_PARM_DESC(dma, "DMA # for SoundScape driver."); + +static struct platform_device *platform_devices[SNDRV_CARDS]; +static int pnp_registered; #ifdef CONFIG_PNP static struct pnp_card_device_id sscape_pnpids[] = { @@ -1384,6 +1387,17 @@ static struct pnp_card_driver sscape_pnpc_driver = { #endif /* CONFIG_PNP */ +static void __init_or_module sscape_unregister_all(void) +{ + int i; + + if (pnp_registered) + pnp_unregister_card_driver(&sscape_pnpc_driver); + for (i = 0; i < ARRAY_SIZE(platform_devices); ++i) + platform_device_unregister(platform_devices[i]); + platform_driver_unregister(&snd_sscape_driver); +} + static int __init sscape_manual_probe(void) { struct platform_device *device; @@ -1411,8 +1425,8 @@ static int __init sscape_manual_probe(void) dma[i] == SNDRV_AUTO_DMA) { printk(KERN_INFO "sscape: insufficient parameters, need IO, IRQ, MPU-IRQ and DMA\n"); - platform_driver_unregister(&snd_sscape_driver); - return -ENXIO; + ret = -ENXIO; + goto errout; } /* @@ -1421,17 +1435,21 @@ static int __init sscape_manual_probe(void) device = platform_device_register_simple(SSCAPE_DRIVER, i, NULL, 0); if (IS_ERR(device)) { - platform_driver_unregister(&snd_sscape_driver); - return PTR_ERR(device); + ret = PTR_ERR(device); + goto errout; } + platform_devices[i] = device; } return 0; + + errout: + sscape_unregister_all(); + return ret; } static void sscape_exit(void) { - pnp_unregister_card_driver(&sscape_pnpc_driver); - platform_driver_unregister(&snd_sscape_driver); + sscape_unregister_all(); } @@ -1448,7 +1466,8 @@ static int __init sscape_init(void) ret = sscape_manual_probe(); if (ret < 0) return ret; - pnp_register_card_driver(&sscape_pnpc_driver); + if (pnp_register_card_driver(&sscape_pnpc_driver) >= 0) + pnp_registered = 1; return 0; } diff --git a/sound/isa/wavefront/wavefront.c b/sound/isa/wavefront/wavefront.c index 77a3012e5510..a6dcb2f970ca 100644 --- a/sound/isa/wavefront/wavefront.c +++ b/sound/isa/wavefront/wavefront.c @@ -83,6 +83,9 @@ MODULE_PARM_DESC(fm_port, "FM port #."); module_param_array(use_cs4232_midi, bool, NULL, 0444); MODULE_PARM_DESC(use_cs4232_midi, "Use CS4232 MPU-401 interface (inaccessibly located inside your computer)"); +static struct platform_device *platform_devices[SNDRV_CARDS]; +static int pnp_registered; + #ifdef CONFIG_PNP @@ -688,6 +691,17 @@ static struct pnp_card_driver wavefront_pnpc_driver = { #endif /* CONFIG_PNP */ +static void __init_or_module snd_wavefront_unregister_all(void) +{ + int i; + + if (pnp_registered) + pnp_unregister_card_driver(&wavefront_pnpc_driver); + for (i = 0; i < ARRAY_SIZE(platform_devices); ++i) + platform_device_unregister(platform_devices[i]); + platform_driver_unregister(&snd_wavefront_driver); +} + static int __init alsa_card_wavefront_init(void) { int i, err, cards = 0; @@ -704,31 +718,36 @@ static int __init alsa_card_wavefront_init(void) device = platform_device_register_simple(WAVEFRONT_DRIVER, i, NULL, 0); if (IS_ERR(device)) { - platform_driver_unregister(&snd_wavefront_driver); - return PTR_ERR(device); + err = PTR_ERR(device); + goto errout; } + platform_devices[i] = device; cards++; } i = pnp_register_card_driver(&wavefront_pnpc_driver); - if (i > 0) + if (i >= 0) { + pnp_registered = 1; cards += i; + } if (!cards) { - pnp_unregister_card_driver(&wavefront_pnpc_driver); - platform_driver_unregister(&snd_wavefront_driver); #ifdef MODULE printk (KERN_ERR "No WaveFront cards found or devices busy\n"); #endif - return -ENODEV; + err = -ENODEV; + goto errout; } return 0; + + errout: + snd_wavefront_unregister_all(); + return err; } static void __exit alsa_card_wavefront_exit(void) { - pnp_unregister_card_driver(&wavefront_pnpc_driver); - platform_driver_unregister(&snd_wavefront_driver); + snd_wavefront_unregister_all(); } module_init(alsa_card_wavefront_init) diff --git a/sound/ppc/powermac.c b/sound/ppc/powermac.c index efa06fe5f01b..f4902a219e50 100644 --- a/sound/ppc/powermac.c +++ b/sound/ppc/powermac.c @@ -46,6 +46,8 @@ MODULE_PARM_DESC(id, "ID string for " CHIP_NAME " soundchip."); module_param(enable_beep, bool, 0444); MODULE_PARM_DESC(enable_beep, "Enable beep using PCM."); +static struct platform_device *device; + /* */ @@ -182,7 +184,6 @@ static struct platform_driver snd_pmac_driver = { static int __init alsa_card_pmac_init(void) { int err; - struct platform_device *device; if ((err = platform_driver_register(&snd_pmac_driver)) < 0) return err; @@ -197,6 +198,7 @@ static int __init alsa_card_pmac_init(void) static void __exit alsa_card_pmac_exit(void) { + platform_device_unregister(device); platform_driver_unregister(&snd_pmac_driver); } -- cgit v1.2.3