Commit 5b88da3c authored by Takashi Iwai's avatar Takashi Iwai

ALSA: gus: Allocate resources with device-managed APIs

This patch converts the resource management in ISA gus drivers with
devres as a clean up.  Each manual resource management is converted
with the corresponding devres helper.  The remove callback became
superfluous and dropped.

This should give no user-visible functional changes.

Link: https://lore.kernel.org/r/20210715075941.23332-66-tiwai@suse.deSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 35a245ec
...@@ -87,24 +87,10 @@ static void snd_gus_init_control(struct snd_gus_card *gus) ...@@ -87,24 +87,10 @@ static void snd_gus_init_control(struct snd_gus_card *gus)
static int snd_gus_free(struct snd_gus_card *gus) static int snd_gus_free(struct snd_gus_card *gus)
{ {
if (gus->gf1.res_port2 == NULL) if (gus->gf1.res_port2) {
goto __hw_end;
snd_gf1_stop(gus); snd_gf1_stop(gus);
snd_gus_init_dma_irq(gus, 0); snd_gus_init_dma_irq(gus, 0);
__hw_end:
release_and_free_resource(gus->gf1.res_port1);
release_and_free_resource(gus->gf1.res_port2);
if (gus->gf1.irq >= 0)
free_irq(gus->gf1.irq, (void *) gus);
if (gus->gf1.dma1 >= 0) {
disable_dma(gus->gf1.dma1);
free_dma(gus->gf1.dma1);
} }
if (!gus->equal_dma && gus->gf1.dma2 >= 0) {
disable_dma(gus->gf1.dma2);
free_dma(gus->gf1.dma2);
}
kfree(gus);
return 0; return 0;
} }
...@@ -130,7 +116,7 @@ int snd_gus_create(struct snd_card *card, ...@@ -130,7 +116,7 @@ int snd_gus_create(struct snd_card *card,
}; };
*rgus = NULL; *rgus = NULL;
gus = kzalloc(sizeof(*gus), GFP_KERNEL); gus = devm_kzalloc(card->dev, sizeof(*gus), GFP_KERNEL);
if (gus == NULL) if (gus == NULL)
return -ENOMEM; return -ENOMEM;
spin_lock_init(&gus->reg_lock); spin_lock_init(&gus->reg_lock);
...@@ -156,35 +142,33 @@ int snd_gus_create(struct snd_card *card, ...@@ -156,35 +142,33 @@ int snd_gus_create(struct snd_card *card,
gus->gf1.reg_timerctrl = GUSP(gus, TIMERCNTRL); gus->gf1.reg_timerctrl = GUSP(gus, TIMERCNTRL);
gus->gf1.reg_timerdata = GUSP(gus, TIMERDATA); gus->gf1.reg_timerdata = GUSP(gus, TIMERDATA);
/* allocate resources */ /* allocate resources */
gus->gf1.res_port1 = request_region(port, 16, "GUS GF1 (Adlib/SB)"); gus->gf1.res_port1 = devm_request_region(card->dev, port, 16,
"GUS GF1 (Adlib/SB)");
if (!gus->gf1.res_port1) { if (!gus->gf1.res_port1) {
snd_printk(KERN_ERR "gus: can't grab SB port 0x%lx\n", port); snd_printk(KERN_ERR "gus: can't grab SB port 0x%lx\n", port);
snd_gus_free(gus);
return -EBUSY; return -EBUSY;
} }
gus->gf1.res_port2 = request_region(port + 0x100, 12, "GUS GF1 (Synth)"); gus->gf1.res_port2 = devm_request_region(card->dev, port + 0x100, 12,
"GUS GF1 (Synth)");
if (!gus->gf1.res_port2) { if (!gus->gf1.res_port2) {
snd_printk(KERN_ERR "gus: can't grab synth port 0x%lx\n", port + 0x100); snd_printk(KERN_ERR "gus: can't grab synth port 0x%lx\n", port + 0x100);
snd_gus_free(gus);
return -EBUSY; return -EBUSY;
} }
if (irq >= 0 && request_irq(irq, snd_gus_interrupt, 0, "GUS GF1", (void *) gus)) { if (irq >= 0 && devm_request_irq(card->dev, irq, snd_gus_interrupt, 0,
"GUS GF1", (void *) gus)) {
snd_printk(KERN_ERR "gus: can't grab irq %d\n", irq); snd_printk(KERN_ERR "gus: can't grab irq %d\n", irq);
snd_gus_free(gus);
return -EBUSY; return -EBUSY;
} }
gus->gf1.irq = irq; gus->gf1.irq = irq;
card->sync_irq = irq; card->sync_irq = irq;
if (request_dma(dma1, "GUS - 1")) { if (snd_devm_request_dma(card->dev, dma1, "GUS - 1")) {
snd_printk(KERN_ERR "gus: can't grab DMA1 %d\n", dma1); snd_printk(KERN_ERR "gus: can't grab DMA1 %d\n", dma1);
snd_gus_free(gus);
return -EBUSY; return -EBUSY;
} }
gus->gf1.dma1 = dma1; gus->gf1.dma1 = dma1;
if (dma2 >= 0 && dma1 != dma2) { if (dma2 >= 0 && dma1 != dma2) {
if (request_dma(dma2, "GUS - 2")) { if (snd_devm_request_dma(card->dev, dma2, "GUS - 2")) {
snd_printk(KERN_ERR "gus: can't grab DMA2 %d\n", dma2); snd_printk(KERN_ERR "gus: can't grab DMA2 %d\n", dma2);
snd_gus_free(gus);
return -EBUSY; return -EBUSY;
} }
gus->gf1.dma2 = dma2; gus->gf1.dma2 = dma2;
...@@ -209,10 +193,8 @@ int snd_gus_create(struct snd_card *card, ...@@ -209,10 +193,8 @@ int snd_gus_create(struct snd_card *card,
gus->gf1.volume_ramp = 25; gus->gf1.volume_ramp = 25;
gus->gf1.smooth_pan = 1; gus->gf1.smooth_pan = 1;
err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, gus, &ops); err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, gus, &ops);
if (err < 0) { if (err < 0)
snd_gus_free(gus);
return err; return err;
}
*rgus = gus; *rgus = gus;
return 0; return 0;
} }
......
...@@ -135,7 +135,7 @@ static int snd_gusclassic_probe(struct device *dev, unsigned int n) ...@@ -135,7 +135,7 @@ static int snd_gusclassic_probe(struct device *dev, unsigned int n)
struct snd_gus_card *gus; struct snd_gus_card *gus;
int error; int error;
error = snd_card_new(dev, index[n], id[n], THIS_MODULE, 0, &card); error = snd_devm_card_new(dev, index[n], id[n], THIS_MODULE, 0, &card);
if (error < 0) if (error < 0)
return error; return error;
...@@ -144,37 +144,37 @@ static int snd_gusclassic_probe(struct device *dev, unsigned int n) ...@@ -144,37 +144,37 @@ static int snd_gusclassic_probe(struct device *dev, unsigned int n)
error = snd_gusclassic_create(card, dev, n, &gus); error = snd_gusclassic_create(card, dev, n, &gus);
if (error < 0) if (error < 0)
goto out; return error;
error = snd_gusclassic_detect(gus); error = snd_gusclassic_detect(gus);
if (error < 0) if (error < 0)
goto out; return error;
gus->joystick_dac = joystick_dac[n]; gus->joystick_dac = joystick_dac[n];
error = snd_gus_initialize(gus); error = snd_gus_initialize(gus);
if (error < 0) if (error < 0)
goto out; return error;
error = -ENODEV; error = -ENODEV;
if (gus->max_flag || gus->ess_flag) { if (gus->max_flag || gus->ess_flag) {
dev_err(dev, "GUS Classic or ACE soundcard was " dev_err(dev, "GUS Classic or ACE soundcard was "
"not detected at 0x%lx\n", gus->gf1.port); "not detected at 0x%lx\n", gus->gf1.port);
goto out; return error;
} }
error = snd_gf1_new_mixer(gus); error = snd_gf1_new_mixer(gus);
if (error < 0) if (error < 0)
goto out; return error;
error = snd_gf1_pcm_new(gus, 0, 0); error = snd_gf1_pcm_new(gus, 0, 0);
if (error < 0) if (error < 0)
goto out; return error;
if (!gus->ace_flag) { if (!gus->ace_flag) {
error = snd_gf1_rawmidi_new(gus, 0); error = snd_gf1_rawmidi_new(gus, 0);
if (error < 0) if (error < 0)
goto out; return error;
} }
sprintf(card->longname + strlen(card->longname), sprintf(card->longname + strlen(card->longname),
...@@ -187,27 +187,17 @@ static int snd_gusclassic_probe(struct device *dev, unsigned int n) ...@@ -187,27 +187,17 @@ static int snd_gusclassic_probe(struct device *dev, unsigned int n)
error = snd_card_register(card); error = snd_card_register(card);
if (error < 0) if (error < 0)
goto out; return error;
dev_set_drvdata(dev, card); dev_set_drvdata(dev, card);
return 0; return 0;
out: snd_card_free(card);
return error;
}
static void snd_gusclassic_remove(struct device *dev, unsigned int n)
{
snd_card_free(dev_get_drvdata(dev));
} }
static struct isa_driver snd_gusclassic_driver = { static struct isa_driver snd_gusclassic_driver = {
.match = snd_gusclassic_match, .match = snd_gusclassic_match,
.probe = snd_gusclassic_probe, .probe = snd_gusclassic_probe,
.remove = snd_gusclassic_remove,
#if 0 /* FIXME */ #if 0 /* FIXME */
.suspend = snd_gusclassic_suspend, .suspend = snd_gusclassic_suspend,
.remove = snd_gusclassic_remove,
#endif #endif
.driver = { .driver = {
.name = DEV_NAME .name = DEV_NAME
......
...@@ -228,7 +228,7 @@ static int snd_gusextreme_probe(struct device *dev, unsigned int n) ...@@ -228,7 +228,7 @@ static int snd_gusextreme_probe(struct device *dev, unsigned int n)
struct snd_opl3 *opl3; struct snd_opl3 *opl3;
int error; int error;
error = snd_card_new(dev, index[n], id[n], THIS_MODULE, error = snd_devm_card_new(dev, index[n], id[n], THIS_MODULE,
sizeof(struct snd_es1688), &card); sizeof(struct snd_es1688), &card);
if (error < 0) if (error < 0)
return error; return error;
...@@ -243,56 +243,56 @@ static int snd_gusextreme_probe(struct device *dev, unsigned int n) ...@@ -243,56 +243,56 @@ static int snd_gusextreme_probe(struct device *dev, unsigned int n)
error = snd_gusextreme_es1688_create(card, es1688, dev, n); error = snd_gusextreme_es1688_create(card, es1688, dev, n);
if (error < 0) if (error < 0)
goto out; return error;
if (gf1_port[n] < 0) if (gf1_port[n] < 0)
gf1_port[n] = es1688->port + 0x20; gf1_port[n] = es1688->port + 0x20;
error = snd_gusextreme_gus_card_create(card, dev, n, &gus); error = snd_gusextreme_gus_card_create(card, dev, n, &gus);
if (error < 0) if (error < 0)
goto out; return error;
error = snd_gusextreme_detect(gus, es1688); error = snd_gusextreme_detect(gus, es1688);
if (error < 0) if (error < 0)
goto out; return error;
gus->joystick_dac = joystick_dac[n]; gus->joystick_dac = joystick_dac[n];
error = snd_gus_initialize(gus); error = snd_gus_initialize(gus);
if (error < 0) if (error < 0)
goto out; return error;
error = -ENODEV; error = -ENODEV;
if (!gus->ess_flag) { if (!gus->ess_flag) {
dev_err(dev, "GUS Extreme soundcard was not " dev_err(dev, "GUS Extreme soundcard was not "
"detected at 0x%lx\n", gus->gf1.port); "detected at 0x%lx\n", gus->gf1.port);
goto out; return error;
} }
gus->codec_flag = 1; gus->codec_flag = 1;
error = snd_es1688_pcm(card, es1688, 0); error = snd_es1688_pcm(card, es1688, 0);
if (error < 0) if (error < 0)
goto out; return error;
error = snd_es1688_mixer(card, es1688); error = snd_es1688_mixer(card, es1688);
if (error < 0) if (error < 0)
goto out; return error;
snd_component_add(card, "ES1688"); snd_component_add(card, "ES1688");
if (pcm_channels[n] > 0) { if (pcm_channels[n] > 0) {
error = snd_gf1_pcm_new(gus, 1, 1); error = snd_gf1_pcm_new(gus, 1, 1);
if (error < 0) if (error < 0)
goto out; return error;
} }
error = snd_gf1_new_mixer(gus); error = snd_gf1_new_mixer(gus);
if (error < 0) if (error < 0)
goto out; return error;
error = snd_gusextreme_mixer(card); error = snd_gusextreme_mixer(card);
if (error < 0) if (error < 0)
goto out; return error;
if (snd_opl3_create(card, es1688->port, es1688->port + 2, if (snd_opl3_create(card, es1688->port, es1688->port + 2,
OPL3_HW_OPL3, 0, &opl3) < 0) OPL3_HW_OPL3, 0, &opl3) < 0)
...@@ -300,14 +300,14 @@ static int snd_gusextreme_probe(struct device *dev, unsigned int n) ...@@ -300,14 +300,14 @@ static int snd_gusextreme_probe(struct device *dev, unsigned int n)
else { else {
error = snd_opl3_hwdep_new(opl3, 0, 2, NULL); error = snd_opl3_hwdep_new(opl3, 0, 2, NULL);
if (error < 0) if (error < 0)
goto out; return error;
} }
if (es1688->mpu_port >= 0x300) { if (es1688->mpu_port >= 0x300) {
error = snd_mpu401_uart_new(card, 0, MPU401_HW_ES1688, error = snd_mpu401_uart_new(card, 0, MPU401_HW_ES1688,
es1688->mpu_port, 0, mpu_irq[n], NULL); es1688->mpu_port, 0, mpu_irq[n], NULL);
if (error < 0) if (error < 0)
goto out; return error;
} }
sprintf(card->longname, "Gravis UltraSound Extreme at 0x%lx, " sprintf(card->longname, "Gravis UltraSound Extreme at 0x%lx, "
...@@ -316,24 +316,15 @@ static int snd_gusextreme_probe(struct device *dev, unsigned int n) ...@@ -316,24 +316,15 @@ static int snd_gusextreme_probe(struct device *dev, unsigned int n)
error = snd_card_register(card); error = snd_card_register(card);
if (error < 0) if (error < 0)
goto out; return error;
dev_set_drvdata(dev, card); dev_set_drvdata(dev, card);
return 0; return 0;
out: snd_card_free(card);
return error;
}
static void snd_gusextreme_remove(struct device *dev, unsigned int n)
{
snd_card_free(dev_get_drvdata(dev));
} }
static struct isa_driver snd_gusextreme_driver = { static struct isa_driver snd_gusextreme_driver = {
.match = snd_gusextreme_match, .match = snd_gusextreme_match,
.probe = snd_gusextreme_probe, .probe = snd_gusextreme_probe,
.remove = snd_gusextreme_remove,
#if 0 /* FIXME */ #if 0 /* FIXME */
.suspend = snd_gusextreme_suspend, .suspend = snd_gusextreme_suspend,
.resume = snd_gusextreme_resume, .resume = snd_gusextreme_resume,
......
...@@ -179,16 +179,6 @@ static int snd_gusmax_mixer(struct snd_wss *chip) ...@@ -179,16 +179,6 @@ static int snd_gusmax_mixer(struct snd_wss *chip)
return 0; return 0;
} }
static void snd_gusmax_free(struct snd_card *card)
{
struct snd_gusmax *maxcard = card->private_data;
if (maxcard == NULL)
return;
if (maxcard->irq >= 0)
free_irq(maxcard->irq, (void *)maxcard);
}
static int snd_gusmax_match(struct device *pdev, unsigned int dev) static int snd_gusmax_match(struct device *pdev, unsigned int dev)
{ {
return enable[dev]; return enable[dev];
...@@ -204,11 +194,10 @@ static int snd_gusmax_probe(struct device *pdev, unsigned int dev) ...@@ -204,11 +194,10 @@ static int snd_gusmax_probe(struct device *pdev, unsigned int dev)
struct snd_wss *wss; struct snd_wss *wss;
struct snd_gusmax *maxcard; struct snd_gusmax *maxcard;
err = snd_card_new(pdev, index[dev], id[dev], THIS_MODULE, err = snd_devm_card_new(pdev, index[dev], id[dev], THIS_MODULE,
sizeof(struct snd_gusmax), &card); sizeof(struct snd_gusmax), &card);
if (err < 0) if (err < 0)
return err; return err;
card->private_free = snd_gusmax_free;
maxcard = card->private_data; maxcard = card->private_data;
maxcard->card = card; maxcard->card = card;
maxcard->irq = -1; maxcard->irq = -1;
...@@ -218,8 +207,7 @@ static int snd_gusmax_probe(struct device *pdev, unsigned int dev) ...@@ -218,8 +207,7 @@ static int snd_gusmax_probe(struct device *pdev, unsigned int dev)
xirq = snd_legacy_find_free_irq(possible_irqs); xirq = snd_legacy_find_free_irq(possible_irqs);
if (xirq < 0) { if (xirq < 0) {
snd_printk(KERN_ERR PFX "unable to find a free IRQ\n"); snd_printk(KERN_ERR PFX "unable to find a free IRQ\n");
err = -EBUSY; return -EBUSY;
goto _err;
} }
} }
xdma1 = dma1[dev]; xdma1 = dma1[dev];
...@@ -227,8 +215,7 @@ static int snd_gusmax_probe(struct device *pdev, unsigned int dev) ...@@ -227,8 +215,7 @@ static int snd_gusmax_probe(struct device *pdev, unsigned int dev)
xdma1 = snd_legacy_find_free_dma(possible_dmas); xdma1 = snd_legacy_find_free_dma(possible_dmas);
if (xdma1 < 0) { if (xdma1 < 0) {
snd_printk(KERN_ERR PFX "unable to find a free DMA1\n"); snd_printk(KERN_ERR PFX "unable to find a free DMA1\n");
err = -EBUSY; return -EBUSY;
goto _err;
} }
} }
xdma2 = dma2[dev]; xdma2 = dma2[dev];
...@@ -236,8 +223,7 @@ static int snd_gusmax_probe(struct device *pdev, unsigned int dev) ...@@ -236,8 +223,7 @@ static int snd_gusmax_probe(struct device *pdev, unsigned int dev)
xdma2 = snd_legacy_find_free_dma(possible_dmas); xdma2 = snd_legacy_find_free_dma(possible_dmas);
if (xdma2 < 0) { if (xdma2 < 0) {
snd_printk(KERN_ERR PFX "unable to find a free DMA2\n"); snd_printk(KERN_ERR PFX "unable to find a free DMA2\n");
err = -EBUSY; return -EBUSY;
goto _err;
} }
} }
...@@ -267,29 +253,28 @@ static int snd_gusmax_probe(struct device *pdev, unsigned int dev) ...@@ -267,29 +253,28 @@ static int snd_gusmax_probe(struct device *pdev, unsigned int dev)
} }
} }
if (err < 0) if (err < 0)
goto _err; return err;
err = snd_gusmax_detect(gus); err = snd_gusmax_detect(gus);
if (err < 0) if (err < 0)
goto _err; return err;
maxcard->gus_status_reg = gus->gf1.reg_irqstat; maxcard->gus_status_reg = gus->gf1.reg_irqstat;
maxcard->pcm_status_reg = gus->gf1.port + 0x10c + 2; maxcard->pcm_status_reg = gus->gf1.port + 0x10c + 2;
snd_gusmax_init(dev, card, gus); snd_gusmax_init(dev, card, gus);
err = snd_gus_initialize(gus); err = snd_gus_initialize(gus);
if (err < 0) if (err < 0)
goto _err; return err;
if (!gus->max_flag) { if (!gus->max_flag) {
snd_printk(KERN_ERR PFX "GUS MAX soundcard was not detected at 0x%lx\n", gus->gf1.port); snd_printk(KERN_ERR PFX "GUS MAX soundcard was not detected at 0x%lx\n", gus->gf1.port);
err = -ENODEV; return -ENODEV;
goto _err;
} }
if (request_irq(xirq, snd_gusmax_interrupt, 0, "GUS MAX", (void *)maxcard)) { if (devm_request_irq(card->dev, xirq, snd_gusmax_interrupt, 0,
"GUS MAX", (void *)maxcard)) {
snd_printk(KERN_ERR PFX "unable to grab IRQ %d\n", xirq); snd_printk(KERN_ERR PFX "unable to grab IRQ %d\n", xirq);
err = -EBUSY; return -EBUSY;
goto _err;
} }
maxcard->irq = xirq; maxcard->irq = xirq;
card->sync_irq = maxcard->irq; card->sync_irq = maxcard->irq;
...@@ -303,32 +288,32 @@ static int snd_gusmax_probe(struct device *pdev, unsigned int dev) ...@@ -303,32 +288,32 @@ static int snd_gusmax_probe(struct device *pdev, unsigned int dev)
WSS_HWSHARE_DMA2, WSS_HWSHARE_DMA2,
&wss); &wss);
if (err < 0) if (err < 0)
goto _err; return err;
err = snd_wss_pcm(wss, 0); err = snd_wss_pcm(wss, 0);
if (err < 0) if (err < 0)
goto _err; return err;
err = snd_wss_mixer(wss); err = snd_wss_mixer(wss);
if (err < 0) if (err < 0)
goto _err; return err;
err = snd_wss_timer(wss, 2); err = snd_wss_timer(wss, 2);
if (err < 0) if (err < 0)
goto _err; return err;
if (pcm_channels[dev] > 0) { if (pcm_channels[dev] > 0) {
err = snd_gf1_pcm_new(gus, 1, 1); err = snd_gf1_pcm_new(gus, 1, 1);
if (err < 0) if (err < 0)
goto _err; return err;
} }
err = snd_gusmax_mixer(wss); err = snd_gusmax_mixer(wss);
if (err < 0) if (err < 0)
goto _err; return err;
err = snd_gf1_rawmidi_new(gus, 0); err = snd_gf1_rawmidi_new(gus, 0);
if (err < 0) if (err < 0)
goto _err; return err;
sprintf(card->longname + strlen(card->longname), " at 0x%lx, irq %i, dma %i", gus->gf1.port, xirq, xdma1); sprintf(card->longname + strlen(card->longname), " at 0x%lx, irq %i, dma %i", gus->gf1.port, xirq, xdma1);
if (xdma2 >= 0) if (xdma2 >= 0)
...@@ -336,22 +321,13 @@ static int snd_gusmax_probe(struct device *pdev, unsigned int dev) ...@@ -336,22 +321,13 @@ static int snd_gusmax_probe(struct device *pdev, unsigned int dev)
err = snd_card_register(card); err = snd_card_register(card);
if (err < 0) if (err < 0)
goto _err; return err;
maxcard->gus = gus; maxcard->gus = gus;
maxcard->wss = wss; maxcard->wss = wss;
dev_set_drvdata(pdev, card); dev_set_drvdata(pdev, card);
return 0; return 0;
_err:
snd_card_free(card);
return err;
}
static void snd_gusmax_remove(struct device *devptr, unsigned int dev)
{
snd_card_free(dev_get_drvdata(devptr));
} }
#define DEV_NAME "gusmax" #define DEV_NAME "gusmax"
...@@ -359,7 +335,6 @@ static void snd_gusmax_remove(struct device *devptr, unsigned int dev) ...@@ -359,7 +335,6 @@ static void snd_gusmax_remove(struct device *devptr, unsigned int dev)
static struct isa_driver snd_gusmax_driver = { static struct isa_driver snd_gusmax_driver = {
.match = snd_gusmax_match, .match = snd_gusmax_match,
.probe = snd_gusmax_probe, .probe = snd_gusmax_probe,
.remove = snd_gusmax_remove,
/* FIXME: suspend/resume */ /* FIXME: suspend/resume */
.driver = { .driver = {
.name = DEV_NAME .name = DEV_NAME
......
...@@ -204,13 +204,15 @@ static int snd_interwave_detect_stb(struct snd_interwave *iwcard, ...@@ -204,13 +204,15 @@ static int snd_interwave_detect_stb(struct snd_interwave *iwcard,
port = 0x360; port = 0x360;
} }
while (port <= 0x380) { while (port <= 0x380) {
iwcard->i2c_res = request_region(port, 1, "InterWave (I2C bus)"); iwcard->i2c_res = devm_request_region(card->dev, port, 1,
"InterWave (I2C bus)");
if (iwcard->i2c_res) if (iwcard->i2c_res)
break; break;
port += 0x10; port += 0x10;
} }
} else { } else {
iwcard->i2c_res = request_region(port, 1, "InterWave (I2C bus)"); iwcard->i2c_res = devm_request_region(card->dev, port, 1,
"InterWave (I2C bus)");
} }
if (iwcard->i2c_res == NULL) { if (iwcard->i2c_res == NULL) {
snd_printk(KERN_ERR "interwave: can't grab i2c bus port\n"); snd_printk(KERN_ERR "interwave: can't grab i2c bus port\n");
...@@ -598,19 +600,6 @@ static int snd_interwave_pnp(int dev, struct snd_interwave *iwcard, ...@@ -598,19 +600,6 @@ static int snd_interwave_pnp(int dev, struct snd_interwave *iwcard,
} }
#endif /* CONFIG_PNP */ #endif /* CONFIG_PNP */
static void snd_interwave_free(struct snd_card *card)
{
struct snd_interwave *iwcard = card->private_data;
if (iwcard == NULL)
return;
#ifdef SNDRV_STB
release_and_free_resource(iwcard->i2c_res);
#endif
if (iwcard->irq >= 0)
free_irq(iwcard->irq, (void *)iwcard);
}
static int snd_interwave_card_new(struct device *pdev, int dev, static int snd_interwave_card_new(struct device *pdev, int dev,
struct snd_card **cardp) struct snd_card **cardp)
{ {
...@@ -618,14 +607,13 @@ static int snd_interwave_card_new(struct device *pdev, int dev, ...@@ -618,14 +607,13 @@ static int snd_interwave_card_new(struct device *pdev, int dev,
struct snd_interwave *iwcard; struct snd_interwave *iwcard;
int err; int err;
err = snd_card_new(pdev, index[dev], id[dev], THIS_MODULE, err = snd_devm_card_new(pdev, index[dev], id[dev], THIS_MODULE,
sizeof(struct snd_interwave), &card); sizeof(struct snd_interwave), &card);
if (err < 0) if (err < 0)
return err; return err;
iwcard = card->private_data; iwcard = card->private_data;
iwcard->card = card; iwcard->card = card;
iwcard->irq = -1; iwcard->irq = -1;
card->private_free = snd_interwave_free;
*cardp = card; *cardp = card;
return 0; return 0;
} }
...@@ -671,7 +659,7 @@ static int snd_interwave_probe(struct snd_card *card, int dev) ...@@ -671,7 +659,7 @@ static int snd_interwave_probe(struct snd_card *card, int dev)
if (err < 0) if (err < 0)
return err; return err;
if (request_irq(xirq, snd_interwave_interrupt, 0, if (devm_request_irq(card->dev, xirq, snd_interwave_interrupt, 0,
"InterWave", iwcard)) { "InterWave", iwcard)) {
snd_printk(KERN_ERR PFX "unable to grab IRQ %d\n", xirq); snd_printk(KERN_ERR PFX "unable to grab IRQ %d\n", xirq);
return -EBUSY; return -EBUSY;
...@@ -779,10 +767,8 @@ static int snd_interwave_isa_probe1(int dev, struct device *devptr) ...@@ -779,10 +767,8 @@ static int snd_interwave_isa_probe1(int dev, struct device *devptr)
return err; return err;
err = snd_interwave_probe(card, dev); err = snd_interwave_probe(card, dev);
if (err < 0) { if (err < 0)
snd_card_free(card);
return err; return err;
}
dev_set_drvdata(devptr, card); dev_set_drvdata(devptr, card);
return 0; return 0;
} }
...@@ -843,15 +829,9 @@ static int snd_interwave_isa_probe(struct device *pdev, ...@@ -843,15 +829,9 @@ static int snd_interwave_isa_probe(struct device *pdev,
} }
} }
static void snd_interwave_isa_remove(struct device *devptr, unsigned int dev)
{
snd_card_free(dev_get_drvdata(devptr));
}
static struct isa_driver snd_interwave_driver = { static struct isa_driver snd_interwave_driver = {
.match = snd_interwave_isa_match, .match = snd_interwave_isa_match,
.probe = snd_interwave_isa_probe, .probe = snd_interwave_isa_probe,
.remove = snd_interwave_isa_remove,
/* FIXME: suspend,resume */ /* FIXME: suspend,resume */
.driver = { .driver = {
.name = INTERWAVE_DRIVER .name = INTERWAVE_DRIVER
...@@ -878,32 +858,21 @@ static int snd_interwave_pnp_detect(struct pnp_card_link *pcard, ...@@ -878,32 +858,21 @@ static int snd_interwave_pnp_detect(struct pnp_card_link *pcard,
return res; return res;
res = snd_interwave_pnp(dev, card->private_data, pcard, pid); res = snd_interwave_pnp(dev, card->private_data, pcard, pid);
if (res < 0) { if (res < 0)
snd_card_free(card);
return res; return res;
}
res = snd_interwave_probe(card, dev); res = snd_interwave_probe(card, dev);
if (res < 0) { if (res < 0)
snd_card_free(card);
return res; return res;
}
pnp_set_card_drvdata(pcard, card); pnp_set_card_drvdata(pcard, card);
dev++; dev++;
return 0; return 0;
} }
static void snd_interwave_pnp_remove(struct pnp_card_link *pcard)
{
snd_card_free(pnp_get_card_drvdata(pcard));
pnp_set_card_drvdata(pcard, NULL);
}
static struct pnp_card_driver interwave_pnpc_driver = { static struct pnp_card_driver interwave_pnpc_driver = {
.flags = PNP_DRIVER_RES_DISABLE, .flags = PNP_DRIVER_RES_DISABLE,
.name = INTERWAVE_PNP_DRIVER, .name = INTERWAVE_PNP_DRIVER,
.id_table = snd_interwave_pnpids, .id_table = snd_interwave_pnpids,
.probe = snd_interwave_pnp_detect, .probe = snd_interwave_pnp_detect,
.remove = snd_interwave_pnp_remove,
/* FIXME: suspend,resume */ /* FIXME: suspend,resume */
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment