All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: alsa-devel@alsa-project.org
Subject: [PATCH 15/51] ALSA: ens137x: Allocate resources with device-managed APIs
Date: Tue, 13 Jul 2021 16:28:21 +0200	[thread overview]
Message-ID: <20210713142857.19654-16-tiwai@suse.de> (raw)
In-Reply-To: <20210713142857.19654-1-tiwai@suse.de>

This patch converts the resource management in PCI esn137x drivers
with devres as a clean up.  Each manual resource management is
converted with the corresponding devres helper, the devres helper is
used for the DMA buffer page allocations, 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.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/pci/ens1370.c | 115 +++++++++++---------------------------------
 1 file changed, 27 insertions(+), 88 deletions(-)

diff --git a/sound/pci/ens1370.c b/sound/pci/ens1370.c
index 728b69dad21b..2651f0c64c06 100644
--- a/sound/pci/ens1370.c
+++ b/sound/pci/ens1370.c
@@ -414,7 +414,7 @@ struct ensoniq {
 	unsigned int spdif_stream;
 
 #ifdef CHIP1370
-	struct snd_dma_buffer dma_bug;
+	struct snd_dma_buffer *dma_bug;
 #endif
 
 #ifdef SUPPORT_JOYSTICK
@@ -1872,11 +1872,11 @@ static void snd_ensoniq_proc_init(struct ensoniq *ensoniq)
 
  */
 
-static int snd_ensoniq_free(struct ensoniq *ensoniq)
+static void snd_ensoniq_free(struct snd_card *card)
 {
+	struct ensoniq *ensoniq = card->private_data;
+
 	snd_ensoniq_free_gameport(ensoniq);
-	if (ensoniq->irq < 0)
-		goto __hw_end;
 #ifdef CHIP1370
 	outl(ES_1370_SERR_DISABLE, ES_REG(ensoniq, CONTROL));	/* switch everything off */
 	outl(0, ES_REG(ensoniq, SERIAL));	/* clear serial interface */
@@ -1884,24 +1884,6 @@ static int snd_ensoniq_free(struct ensoniq *ensoniq)
 	outl(0, ES_REG(ensoniq, CONTROL));	/* switch everything off */
 	outl(0, ES_REG(ensoniq, SERIAL));	/* clear serial interface */
 #endif
-	pci_set_power_state(ensoniq->pci, PCI_D3hot);
-      __hw_end:
-#ifdef CHIP1370
-	if (ensoniq->dma_bug.area)
-		snd_dma_free_pages(&ensoniq->dma_bug);
-#endif
-	if (ensoniq->irq >= 0)
-		free_irq(ensoniq->irq, ensoniq);
-	pci_release_regions(ensoniq->pci);
-	pci_disable_device(ensoniq->pci);
-	kfree(ensoniq);
-	return 0;
-}
-
-static int snd_ensoniq_dev_free(struct snd_device *device)
-{
-	struct ensoniq *ensoniq = device->device_data;
-	return snd_ensoniq_free(ensoniq);
 }
 
 #ifdef CHIP1371
@@ -1935,7 +1917,7 @@ static void snd_ensoniq_chip_init(struct ensoniq *ensoniq)
 	outl(ensoniq->ctrl, ES_REG(ensoniq, CONTROL));
 	outl(ensoniq->sctrl, ES_REG(ensoniq, SERIAL));
 	outl(ES_MEM_PAGEO(ES_PAGE_ADC), ES_REG(ensoniq, MEM_PAGE));
-	outl(ensoniq->dma_bug.addr, ES_REG(ensoniq, PHANTOM_FRAME));
+	outl(ensoniq->dma_bug->addr, ES_REG(ensoniq, PHANTOM_FRAME));
 	outl(0, ES_REG(ensoniq, PHANTOM_COUNT));
 #else
 	outl(ensoniq->ctrl, ES_REG(ensoniq, CONTROL));
@@ -2032,51 +2014,35 @@ static SIMPLE_DEV_PM_OPS(snd_ensoniq_pm, snd_ensoniq_suspend, snd_ensoniq_resume
 #endif /* CONFIG_PM_SLEEP */
 
 static int snd_ensoniq_create(struct snd_card *card,
-			      struct pci_dev *pci,
-			      struct ensoniq **rensoniq)
+			      struct pci_dev *pci)
 {
-	struct ensoniq *ensoniq;
+	struct ensoniq *ensoniq = card->private_data;
 	int err;
-	static const struct snd_device_ops ops = {
-		.dev_free =	snd_ensoniq_dev_free,
-	};
 
-	*rensoniq = NULL;
-	err = pci_enable_device(pci);
+	err = pcim_enable_device(pci);
 	if (err < 0)
 		return err;
-	ensoniq = kzalloc(sizeof(*ensoniq), GFP_KERNEL);
-	if (ensoniq == NULL) {
-		pci_disable_device(pci);
-		return -ENOMEM;
-	}
 	spin_lock_init(&ensoniq->reg_lock);
 	mutex_init(&ensoniq->src_mutex);
 	ensoniq->card = card;
 	ensoniq->pci = pci;
 	ensoniq->irq = -1;
 	err = pci_request_regions(pci, "Ensoniq AudioPCI");
-	if (err < 0) {
-		kfree(ensoniq);
-		pci_disable_device(pci);
+	if (err < 0)
 		return err;
-	}
 	ensoniq->port = pci_resource_start(pci, 0);
-	if (request_irq(pci->irq, snd_audiopci_interrupt, IRQF_SHARED,
-			KBUILD_MODNAME, ensoniq)) {
+	if (devm_request_irq(&pci->dev, pci->irq, snd_audiopci_interrupt,
+			     IRQF_SHARED, KBUILD_MODNAME, ensoniq)) {
 		dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
-		snd_ensoniq_free(ensoniq);
 		return -EBUSY;
 	}
 	ensoniq->irq = pci->irq;
 	card->sync_irq = ensoniq->irq;
 #ifdef CHIP1370
-	if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &pci->dev,
-				16, &ensoniq->dma_bug) < 0) {
-		dev_err(card->dev, "unable to allocate space for phantom area - dma_bug\n");
-		snd_ensoniq_free(ensoniq);
-		return -EBUSY;
-	}
+	ensoniq->dma_bug =
+		snd_devm_alloc_pages(&pci->dev, SNDRV_DMA_TYPE_DEV, 16);
+	if (!ensoniq->dma_bug)
+		return -ENOMEM;
 #endif
 	pci_set_master(pci);
 	ensoniq->rev = pci->revision;
@@ -2099,17 +2065,10 @@ static int snd_ensoniq_create(struct snd_card *card,
 		ensoniq->cssr |= ES_1371_ST_AC97_RST;
 #endif
 
+	card->private_free = snd_ensoniq_free;
 	snd_ensoniq_chip_init(ensoniq);
 
-	err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, ensoniq, &ops);
-	if (err < 0) {
-		snd_ensoniq_free(ensoniq);
-		return err;
-	}
-
 	snd_ensoniq_proc_init(ensoniq);
-
-	*rensoniq = ensoniq;
 	return 0;
 }
 
@@ -2360,47 +2319,35 @@ static int snd_audiopci_probe(struct pci_dev *pci,
 		return -ENOENT;
 	}
 
-	err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
-			   0, &card);
+	err = snd_devm_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
+				sizeof(*ensoniq), &card);
 	if (err < 0)
 		return err;
+	ensoniq = card->private_data;
 
-	err = snd_ensoniq_create(card, pci, &ensoniq);
-	if (err < 0) {
-		snd_card_free(card);
+	err = snd_ensoniq_create(card, pci);
+	if (err < 0)
 		return err;
-	}
-	card->private_data = ensoniq;
 
 #ifdef CHIP1370
 	err = snd_ensoniq_1370_mixer(ensoniq);
-	if (err < 0) {
-		snd_card_free(card);
+	if (err < 0)
 		return err;
-	}
 #endif
 #ifdef CHIP1371
 	err = snd_ensoniq_1371_mixer(ensoniq, spdif[dev], lineio[dev]);
-	if (err < 0) {
-		snd_card_free(card);
+	if (err < 0)
 		return err;
-	}
 #endif
 	err = snd_ensoniq_pcm(ensoniq, 0);
-	if (err < 0) {
-		snd_card_free(card);
+	if (err < 0)
 		return err;
-	}
 	err = snd_ensoniq_pcm2(ensoniq, 1);
-	if (err < 0) {
-		snd_card_free(card);
+	if (err < 0)
 		return err;
-	}
 	err = snd_ensoniq_midi(ensoniq, 0);
-	if (err < 0) {
-		snd_card_free(card);
+	if (err < 0)
 		return err;
-	}
 
 	snd_ensoniq_create_gameport(ensoniq, dev);
 
@@ -2414,26 +2361,18 @@ static int snd_audiopci_probe(struct pci_dev *pci,
 		ensoniq->irq);
 
 	err = snd_card_register(card);
-	if (err < 0) {
-		snd_card_free(card);
+	if (err < 0)
 		return err;
-	}
 
 	pci_set_drvdata(pci, card);
 	dev++;
 	return 0;
 }
 
-static void snd_audiopci_remove(struct pci_dev *pci)
-{
-	snd_card_free(pci_get_drvdata(pci));
-}
-
 static struct pci_driver ens137x_driver = {
 	.name = KBUILD_MODNAME,
 	.id_table = snd_audiopci_ids,
 	.probe = snd_audiopci_probe,
-	.remove = snd_audiopci_remove,
 	.driver = {
 		.pm = SND_ENSONIQ_PM_OPS,
 	},
-- 
2.26.2


  parent reply	other threads:[~2021-07-13 14:35 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-13 14:28 [PATCH resent 00/51] ALSA: More devres usages Takashi Iwai
2021-07-13 14:28 ` [PATCH 01/51] ALSA: core: Add device-managed page allocator helper Takashi Iwai
2021-07-13 14:28 ` [PATCH 02/51] ALSA: core: Add managed card creation Takashi Iwai
2021-07-13 15:23   ` Amadeusz Sławiński
2021-07-13 16:05     ` Takashi Iwai
2021-07-13 16:15       ` Takashi Iwai
2021-07-13 14:28 ` [PATCH 03/51] ALSA: intel8x0: Allocate resources with device-managed APIs Takashi Iwai
2021-07-13 14:28 ` [PATCH 04/51] ALSA: atiixp: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 05/51] ALSA: hda: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 06/51] ALSA: doc: Add device-managed resource section Takashi Iwai
2021-07-13 14:28 ` [PATCH 07/51] ALSA: ad1889: Allocate resources with device-managed APIs Takashi Iwai
2021-07-13 14:28 ` [PATCH 08/51] ALSA: als300: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 09/51] ALSA: als4000: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 10/51] ALSA: azt3328: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 11/51] ALSA: bt87x: " Takashi Iwai
2021-07-13 17:10   ` kernel test robot
2021-07-13 14:28 ` [PATCH 12/51] ALSA: cmipci: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 13/51] ALSA: cs4281: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 14/51] ALSA: cs5530: " Takashi Iwai
2021-07-13 14:28 ` Takashi Iwai [this message]
2021-07-13 15:23   ` [PATCH 15/51] ALSA: ens137x: " Amadeusz Sławiński
2021-07-13 16:07     ` Takashi Iwai
2021-07-13 14:28 ` [PATCH 16/51] ALSA: es1938: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 17/51] ALSA: es1968: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 18/51] ALSA: fm801: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 19/51] ALSA: maestro3: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 20/51] ALSA: rme32: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 21/51] ALSA: rme96: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 22/51] ALSA: sis7019: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 23/51] ALSA: sonicvibes: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 24/51] ALSA: via82xx: " Takashi Iwai
2021-07-13 18:40   ` kernel test robot
2021-07-13 14:28 ` [PATCH 25/51] ALSA: ali5451: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 26/51] ALSA: au88x0: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 27/51] ALSA: aw2: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 28/51] ALSA: ca0106: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 29/51] ALSA: cs46xx: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 30/51] ALSA: cs5535audio: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 31/51] ALSA: echoaudio: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 32/51] ALSA: emu10k1: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 33/51] ALSA: emu10k1x: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 34/51] ALSA: ice1712: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 35/51] ALSA: ice1724: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 36/51] ALSA: korg1212: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 37/51] ALSA: lola: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 38/51] ALSA: oxygen: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 39/51] ALSA: riptide: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 40/51] ALSA: hdsp: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 41/51] ALSA: hdspm: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 42/51] ALSA: rme9652: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 43/51] ALSA: trident: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 44/51] ALSA: vx: Manage vx_core object with devres Takashi Iwai
2021-07-13 14:28 ` [PATCH 45/51] ALSA: vx222: Allocate resources with device-managed APIs Takashi Iwai
2021-07-13 14:28 ` [PATCH 46/51] ALSA: ymfpci: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 47/51] ALSA: x86: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 48/51] ALSA: virmidi: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 49/51] ALSA: mtpav: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 50/51] ALSA: serial-u16550: " Takashi Iwai
2021-07-13 16:08   ` Takashi Iwai
2021-07-13 18:39   ` kernel test robot
2021-07-13 14:28 ` [PATCH 51/51] ALSA: mpu401: " Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210713142857.19654-16-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@alsa-project.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.