From: Takashi Iwai <tiwai@suse.de>
To: alsa-devel@alsa-project.org
Subject: [PATCH 5/7] ALSA: hda: Allocate resources with device-managed APIs
Date: Thu, 20 Sep 2018 17:55:00 +0200 [thread overview]
Message-ID: <20180920155502.7534-6-tiwai@suse.de> (raw)
In-Reply-To: <20180920155502.7534-1-tiwai@suse.de>
This patch is an attempt to slightly simplify the resource management
in HD-audio code, by using some device-managed APIs. A few resources
like PCI enablement, PCI resources and the card object are managed via
devres now. But most of codes dealing with HD-audio core stuff
couldn't be changed so much, hence the changes in this patch are
pretty small in the end.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
sound/pci/hda/hda_controller.h | 1 -
sound/pci/hda/hda_intel.c | 43 ++++++++--------------------------
2 files changed, 10 insertions(+), 34 deletions(-)
diff --git a/sound/pci/hda/hda_controller.h b/sound/pci/hda/hda_controller.h
index c95097bb5a0c..16f2285847b3 100644
--- a/sound/pci/hda/hda_controller.h
+++ b/sound/pci/hda/hda_controller.h
@@ -156,7 +156,6 @@ struct azx {
unsigned int snoop:1;
unsigned int uc_buffer:1; /* non-cached pages for stream buffers */
unsigned int align_buffer_size:1;
- unsigned int region_requested:1;
unsigned int disabled:1; /* disabled by vga_switcheroo */
/* GTS present */
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index 4e64595b381b..7a697db7a6a0 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -1318,18 +1318,11 @@ static int azx_free(struct azx *chip)
if (bus->irq >= 0)
free_irq(bus->irq, (void*)chip);
- if (chip->msi)
- pci_disable_msi(chip->pci);
- iounmap(bus->remap_addr);
azx_free_stream_pages(chip);
azx_free_streams(chip);
snd_hdac_bus_exit(bus);
- if (chip->region_requested)
- pci_release_regions(chip->pci);
-
- pci_disable_device(chip->pci);
#ifdef CONFIG_SND_HDA_PATCH_LOADER
release_firmware(chip->fw);
#endif
@@ -1657,15 +1650,13 @@ static int azx_create(struct snd_card *card, struct pci_dev *pci,
*rchip = NULL;
- err = pci_enable_device(pci);
+ err = pcim_enable_device(pci);
if (err < 0)
return err;
hda = kzalloc(sizeof(*hda), GFP_KERNEL);
- if (!hda) {
- pci_disable_device(pci);
+ if (!hda)
return -ENOMEM;
- }
chip = &hda->chip;
mutex_init(&chip->open_mutex);
@@ -1707,7 +1698,6 @@ static int azx_create(struct snd_card *card, struct pci_dev *pci,
err = azx_bus_init(chip, model[dev], &pci_hda_io_ops);
if (err < 0) {
kfree(hda);
- pci_disable_device(pci);
return err;
}
@@ -1751,17 +1741,12 @@ static int azx_first_init(struct azx *chip)
}
#endif
- err = pci_request_regions(pci, "ICH HD audio");
+ err = pcim_iomap_regions(pci, 1 << 0, "ICH HD audio");
if (err < 0)
return err;
- chip->region_requested = 1;
bus->addr = pci_resource_start(pci, 0);
- bus->remap_addr = pci_ioremap_bar(pci, 0);
- if (bus->remap_addr == NULL) {
- dev_err(card->dev, "ioremap error\n");
- return -ENXIO;
- }
+ bus->remap_addr = pcim_iomap_table(pci)[0];
if (chip->driver_type == AZX_DRIVER_SKL)
snd_hdac_bus_parse_capabilities(bus);
@@ -2057,16 +2042,14 @@ static int azx_probe(struct pci_dev *pci,
return -ENOENT;
}
- err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
- 0, &card);
- if (err < 0) {
- dev_err(&pci->dev, "Error creating card!\n");
+ err = snd_devm_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, 0,
+ &card);
+ if (err < 0)
return err;
- }
err = azx_create(card, pci, dev, pci_id->driver_data, &chip);
if (err < 0)
- goto out_free;
+ return err;
card->private_data = chip;
hda = container_of(chip, struct hda_intel, chip);
@@ -2075,7 +2058,7 @@ static int azx_probe(struct pci_dev *pci,
err = register_vga_switcheroo(chip);
if (err < 0) {
dev_err(card->dev, "Error registering vga_switcheroo client\n");
- goto out_free;
+ return err;
}
if (check_hdmi_disabled(pci)) {
@@ -2094,7 +2077,7 @@ static int azx_probe(struct pci_dev *pci,
&pci->dev, GFP_KERNEL, card,
azx_firmware_cb);
if (err < 0)
- goto out_free;
+ return err;
schedule_probe = false; /* continued in azx_firmware_cb() */
}
#endif /* CONFIG_SND_HDA_PATCH_LOADER */
@@ -2111,10 +2094,6 @@ static int azx_probe(struct pci_dev *pci,
if (chip->disabled)
complete_all(&hda->probe_wait);
return 0;
-
-out_free:
- snd_card_free(card);
- return err;
}
#ifdef CONFIG_PM
@@ -2304,8 +2283,6 @@ static void azx_remove(struct pci_dev *pci)
device_unlock(&pci->dev);
cancel_work_sync(&hda->probe_work);
device_lock(&pci->dev);
-
- snd_card_free(card);
}
}
--
2.18.0
next prev parent reply other threads:[~2018-09-20 15:55 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-20 15:54 [PATCH 0/7] Add devres support to card resources Takashi Iwai
2018-09-20 15:54 ` [PATCH 1/7] ALSA: core: Add device-managed page allocator helper Takashi Iwai
2018-09-20 15:54 ` [PATCH 2/7] ALSA: core: Add managed card creation Takashi Iwai
2018-09-21 3:01 ` Takashi Sakamoto
2018-09-21 6:32 ` Takashi Iwai
2018-09-23 8:08 ` Takashi Sakamoto
2018-10-02 16:30 ` Takashi Iwai
2018-10-03 4:05 ` Takashi Sakamoto
2018-10-03 8:12 ` Takashi Sakamoto
2018-10-03 10:30 ` Takashi Iwai
2018-10-03 13:14 ` Takashi Sakamoto
2018-10-03 15:02 ` Takashi Sakamoto
2018-10-03 15:37 ` Takashi Iwai
2018-10-04 5:33 ` Takashi Sakamoto
2018-10-03 15:32 ` Takashi Iwai
2018-09-20 15:54 ` [PATCH 3/7] ALSA: intel8x0: Allocate resources with device-managed APIs Takashi Iwai
2018-09-20 15:54 ` [PATCH 4/7] ALSA: atiixp: " Takashi Iwai
2018-09-20 15:55 ` Takashi Iwai [this message]
2018-09-20 15:55 ` [PATCH 6/7] ALSA: doc: Brush up the old writing-an-alsa-driver Takashi Iwai
2018-09-20 15:55 ` [PATCH 7/7] ALSA: doc: Add device-managed resource section 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=20180920155502.7534-6-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).