Commit 08e9d3ab authored by Takashi Iwai's avatar Takashi Iwai

ALSA: es1938: Allocate resources with device-managed APIs

This patch converts the resource management in PCI es1938 driver with
devres as a clean up.  Each manual resource management is converted
with the corresponding devres helper, and the card object release is
managed now via card->private_free instead of a lowlevel snd_device.

This should give no user-visible functional changes.

Link: https://lore.kernel.org/r/20210715075941.23332-18-tiwai@suse.deSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 10ed6eaf
...@@ -1521,8 +1521,10 @@ static inline int snd_es1938_create_gameport(struct es1938 *chip) { return -ENOS ...@@ -1521,8 +1521,10 @@ static inline int snd_es1938_create_gameport(struct es1938 *chip) { return -ENOS
static inline void snd_es1938_free_gameport(struct es1938 *chip) { } static inline void snd_es1938_free_gameport(struct es1938 *chip) { }
#endif /* SUPPORT_JOYSTICK */ #endif /* SUPPORT_JOYSTICK */
static int snd_es1938_free(struct es1938 *chip) static void snd_es1938_free(struct snd_card *card)
{ {
struct es1938 *chip = card->private_data;
/* disable irqs */ /* disable irqs */
outb(0x00, SLIO_REG(chip, IRQCONTROL)); outb(0x00, SLIO_REG(chip, IRQCONTROL));
if (chip->rmidi) if (chip->rmidi)
...@@ -1532,71 +1534,47 @@ static int snd_es1938_free(struct es1938 *chip) ...@@ -1532,71 +1534,47 @@ static int snd_es1938_free(struct es1938 *chip)
if (chip->irq >= 0) if (chip->irq >= 0)
free_irq(chip->irq, chip); free_irq(chip->irq, chip);
pci_release_regions(chip->pci);
pci_disable_device(chip->pci);
kfree(chip);
return 0;
}
static int snd_es1938_dev_free(struct snd_device *device)
{
struct es1938 *chip = device->device_data;
return snd_es1938_free(chip);
} }
static int snd_es1938_create(struct snd_card *card, static int snd_es1938_create(struct snd_card *card,
struct pci_dev *pci, struct pci_dev *pci)
struct es1938 **rchip)
{ {
struct es1938 *chip; struct es1938 *chip = card->private_data;
int err; int err;
static const struct snd_device_ops ops = {
.dev_free = snd_es1938_dev_free,
};
*rchip = NULL;
/* enable PCI device */ /* enable PCI device */
err = pci_enable_device(pci); err = pcim_enable_device(pci);
if (err < 0) if (err < 0)
return err; return err;
/* check, if we can restrict PCI DMA transfers to 24 bits */ /* check, if we can restrict PCI DMA transfers to 24 bits */
if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(24))) { if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(24))) {
dev_err(card->dev, dev_err(card->dev,
"architecture does not support 24bit PCI busmaster DMA\n"); "architecture does not support 24bit PCI busmaster DMA\n");
pci_disable_device(pci);
return -ENXIO; return -ENXIO;
} }
chip = kzalloc(sizeof(*chip), GFP_KERNEL);
if (chip == NULL) {
pci_disable_device(pci);
return -ENOMEM;
}
spin_lock_init(&chip->reg_lock); spin_lock_init(&chip->reg_lock);
spin_lock_init(&chip->mixer_lock); spin_lock_init(&chip->mixer_lock);
chip->card = card; chip->card = card;
chip->pci = pci; chip->pci = pci;
chip->irq = -1; chip->irq = -1;
err = pci_request_regions(pci, "ESS Solo-1"); err = pci_request_regions(pci, "ESS Solo-1");
if (err < 0) { if (err < 0)
kfree(chip);
pci_disable_device(pci);
return err; return err;
}
chip->io_port = pci_resource_start(pci, 0); chip->io_port = pci_resource_start(pci, 0);
chip->sb_port = pci_resource_start(pci, 1); chip->sb_port = pci_resource_start(pci, 1);
chip->vc_port = pci_resource_start(pci, 2); chip->vc_port = pci_resource_start(pci, 2);
chip->mpu_port = pci_resource_start(pci, 3); chip->mpu_port = pci_resource_start(pci, 3);
chip->game_port = pci_resource_start(pci, 4); chip->game_port = pci_resource_start(pci, 4);
/* still use non-managed irq handler as it's re-acquired at PM resume */
if (request_irq(pci->irq, snd_es1938_interrupt, IRQF_SHARED, if (request_irq(pci->irq, snd_es1938_interrupt, IRQF_SHARED,
KBUILD_MODNAME, chip)) { KBUILD_MODNAME, chip)) {
dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq); dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
snd_es1938_free(chip);
return -EBUSY; return -EBUSY;
} }
chip->irq = pci->irq; chip->irq = pci->irq;
card->sync_irq = chip->irq; card->sync_irq = chip->irq;
card->private_free = snd_es1938_free;
dev_dbg(card->dev, dev_dbg(card->dev,
"create: io: 0x%lx, sb: 0x%lx, vc: 0x%lx, mpu: 0x%lx, game: 0x%lx\n", "create: io: 0x%lx, sb: 0x%lx, vc: 0x%lx, mpu: 0x%lx, game: 0x%lx\n",
chip->io_port, chip->sb_port, chip->vc_port, chip->mpu_port, chip->game_port); chip->io_port, chip->sb_port, chip->vc_port, chip->mpu_port, chip->game_port);
...@@ -1604,14 +1582,6 @@ static int snd_es1938_create(struct snd_card *card, ...@@ -1604,14 +1582,6 @@ static int snd_es1938_create(struct snd_card *card,
chip->ddma_port = chip->vc_port + 0x00; /* fix from Thomas Sailer */ chip->ddma_port = chip->vc_port + 0x00; /* fix from Thomas Sailer */
snd_es1938_chip_init(chip); snd_es1938_chip_init(chip);
err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
if (err < 0) {
snd_es1938_free(chip);
return err;
}
*rchip = chip;
return 0; return 0;
} }
...@@ -1762,23 +1732,20 @@ static int snd_es1938_probe(struct pci_dev *pci, ...@@ -1762,23 +1732,20 @@ static int snd_es1938_probe(struct pci_dev *pci,
return -ENOENT; return -ENOENT;
} }
err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, err = snd_devm_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
0, &card); sizeof(*chip), &card);
if (err < 0) if (err < 0)
return err; return err;
for (idx = 0; idx < 5; idx++) { chip = card->private_data;
for (idx = 0; idx < 5; idx++)
if (pci_resource_start(pci, idx) == 0 || if (pci_resource_start(pci, idx) == 0 ||
!(pci_resource_flags(pci, idx) & IORESOURCE_IO)) { !(pci_resource_flags(pci, idx) & IORESOURCE_IO))
snd_card_free(card); return -ENODEV;
return -ENODEV;
} err = snd_es1938_create(card, pci);
} if (err < 0)
err = snd_es1938_create(card, pci, &chip);
if (err < 0) {
snd_card_free(card);
return err; return err;
}
card->private_data = chip;
strcpy(card->driver, "ES1938"); strcpy(card->driver, "ES1938");
strcpy(card->shortname, "ESS ES1938 (Solo-1)"); strcpy(card->shortname, "ESS ES1938 (Solo-1)");
...@@ -1788,15 +1755,11 @@ static int snd_es1938_probe(struct pci_dev *pci, ...@@ -1788,15 +1755,11 @@ static int snd_es1938_probe(struct pci_dev *pci,
chip->irq); chip->irq);
err = snd_es1938_new_pcm(chip, 0); err = snd_es1938_new_pcm(chip, 0);
if (err < 0) { if (err < 0)
snd_card_free(card);
return err; return err;
}
err = snd_es1938_mixer(chip); err = snd_es1938_mixer(chip);
if (err < 0) { if (err < 0)
snd_card_free(card);
return err; return err;
}
if (snd_opl3_create(card, if (snd_opl3_create(card,
SLSB_REG(chip, FMLOWADDR), SLSB_REG(chip, FMLOWADDR),
SLSB_REG(chip, FMHIGHADDR), SLSB_REG(chip, FMHIGHADDR),
...@@ -1805,15 +1768,11 @@ static int snd_es1938_probe(struct pci_dev *pci, ...@@ -1805,15 +1768,11 @@ static int snd_es1938_probe(struct pci_dev *pci,
SLSB_REG(chip, FMLOWADDR)); SLSB_REG(chip, FMLOWADDR));
} else { } else {
err = snd_opl3_timer_new(opl3, 0, 1); err = snd_opl3_timer_new(opl3, 0, 1);
if (err < 0) { if (err < 0)
snd_card_free(card);
return err; return err;
}
err = snd_opl3_hwdep_new(opl3, 0, 1, NULL); err = snd_opl3_hwdep_new(opl3, 0, 1, NULL);
if (err < 0) { if (err < 0)
snd_card_free(card);
return err; return err;
}
} }
if (snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, if (snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
chip->mpu_port, chip->mpu_port,
...@@ -1829,26 +1788,18 @@ static int snd_es1938_probe(struct pci_dev *pci, ...@@ -1829,26 +1788,18 @@ static int snd_es1938_probe(struct pci_dev *pci,
snd_es1938_create_gameport(chip); snd_es1938_create_gameport(chip);
err = snd_card_register(card); err = snd_card_register(card);
if (err < 0) { if (err < 0)
snd_card_free(card);
return err; return err;
}
pci_set_drvdata(pci, card); pci_set_drvdata(pci, card);
dev++; dev++;
return 0; return 0;
} }
static void snd_es1938_remove(struct pci_dev *pci)
{
snd_card_free(pci_get_drvdata(pci));
}
static struct pci_driver es1938_driver = { static struct pci_driver es1938_driver = {
.name = KBUILD_MODNAME, .name = KBUILD_MODNAME,
.id_table = snd_es1938_ids, .id_table = snd_es1938_ids,
.probe = snd_es1938_probe, .probe = snd_es1938_probe,
.remove = snd_es1938_remove,
.driver = { .driver = {
.pm = ES1938_PM_OPS, .pm = ES1938_PM_OPS,
}, },
......
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