--- Begin Message ---
- To: <broonie@xxxxxxxxxx>
- Subject: [PATCH 6/6] ASoC: SOF: amd: refactor dmic codec platform device creation
- From: Vijendar Mukunda <Vijendar.Mukunda@xxxxxxx>
- Date: Mon, 3 Apr 2023 12:46:46 +0530
- Cc: alsa-devel@xxxxxxxxxxxxxxxx, Basavaraj.Hiregoudar@xxxxxxx, Sunil-kumar.Dommati@xxxxxxx, Vijendar Mukunda <Vijendar.Mukunda@xxxxxxx>, Pierre-Louis Bossart <pierre-louis.bossart@xxxxxxxxxxxxxxx>, Liam Girdwood <lgirdwood@xxxxxxxxx>, Peter Ujfalusi <peter.ujfalusi@xxxxxxxxxxxxxxx>, Bard Liao <yung-chuan.liao@xxxxxxxxxxxxxxx>, Ranjani Sridharan <ranjani.sridharan@xxxxxxxxxxxxxxx>, Kai Vehmanen <kai.vehmanen@xxxxxxxxxxxxxxx>, Daniel Baluta <daniel.baluta@xxxxxxx>, Takashi Iwai <tiwai@xxxxxxxx>, V sujith kumar Reddy <Vsujithkumar.Reddy@xxxxxxx>, Ajit Kumar Pandey <AjitKumar.Pandey@xxxxxxx>, Ajye Huang <ajye_huang@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>, Rander Wang <rander.wang@xxxxxxxxx>, Zheng Bin <zhengbin13@xxxxxxxxxx>, "moderated list:SOUND - SOUND OPEN FIRMWARE (SOF) DRIVERS" <sound-open-firmware@xxxxxxxxxxxxxxxx>, open list <linux-kernel@xxxxxxxxxxxxxxx>
- In-reply-to: <20230403071651.919027-1-Vijendar.Mukunda@amd.com>
- References: <20230403071651.919027-1-Vijendar.Mukunda@amd.com>
Under snd_sof_dev device scope, create platform device for dmic
codec.
Signed-off-by: Vijendar Mukunda <Vijendar.Mukunda@xxxxxxx>
---
sound/soc/sof/amd/acp.c | 17 +++++++++++++++--
sound/soc/sof/amd/acp.h | 2 ++
sound/soc/sof/amd/pci-rmb.c | 19 +------------------
sound/soc/sof/amd/pci-rn.c | 19 +------------------
4 files changed, 19 insertions(+), 38 deletions(-)
diff --git a/sound/soc/sof/amd/acp.c b/sound/soc/sof/amd/acp.c
index dbf9ee6d79ed..2ae76bcd3590 100644
--- a/sound/soc/sof/amd/acp.c
+++ b/sound/soc/sof/amd/acp.c
@@ -481,11 +481,18 @@ int amd_sof_acp_probe(struct snd_sof_dev *sdev)
return -ENOMEM;
adata->dev = sdev;
+ adata->dmic_dev = platform_device_register_data(sdev->dev, "dmic-codec",
+ PLATFORM_DEVID_NONE, NULL, 0);
+ if (IS_ERR(adata->dmic_dev)) {
+ dev_err(sdev->dev, "failed to register platform for dmic codec\n");
+ return PTR_ERR(adata->dmic_dev);
+ }
addr = pci_resource_start(pci, ACP_DSP_BAR);
sdev->bar[ACP_DSP_BAR] = devm_ioremap(sdev->dev, addr, pci_resource_len(pci, ACP_DSP_BAR));
if (!sdev->bar[ACP_DSP_BAR]) {
dev_err(sdev->dev, "ioremap error\n");
- return -ENXIO;
+ ret = -ENXIO;
+ goto unregister_dev;
}
pci_set_master(pci);
@@ -494,7 +501,8 @@ int amd_sof_acp_probe(struct snd_sof_dev *sdev)
adata->smn_dev = pci_get_device(PCI_VENDOR_ID_AMD, chip->host_bridge_id, NULL);
if (!adata->smn_dev) {
dev_err(sdev->dev, "Failed to get host bridge device\n");
- return -ENODEV;
+ ret = -ENODEV;
+ goto unregister_dev;
}
sdev->ipc_irq = pci->irq;
@@ -529,6 +537,8 @@ int amd_sof_acp_probe(struct snd_sof_dev *sdev)
free_irq(sdev->ipc_irq, sdev);
free_smn_dev:
pci_dev_put(adata->smn_dev);
+unregister_dev:
+ platform_device_unregister(adata->dmic_dev);
return ret;
}
EXPORT_SYMBOL_NS(amd_sof_acp_probe, SND_SOC_SOF_AMD_COMMON);
@@ -543,6 +553,9 @@ int amd_sof_acp_remove(struct snd_sof_dev *sdev)
if (sdev->ipc_irq)
free_irq(sdev->ipc_irq, sdev);
+ if (adata->dmic_dev)
+ platform_device_unregister(adata->dmic_dev);
+
return acp_reset(sdev);
}
EXPORT_SYMBOL_NS(amd_sof_acp_remove, SND_SOC_SOF_AMD_COMMON);
diff --git a/sound/soc/sof/amd/acp.h b/sound/soc/sof/amd/acp.h
index fd04e5ae7303..1c535cc6c3a9 100644
--- a/sound/soc/sof/amd/acp.h
+++ b/sound/soc/sof/amd/acp.h
@@ -170,6 +170,8 @@ struct sof_amd_acp_desc {
/* Common device data struct for ACP devices */
struct acp_dev_data {
struct snd_sof_dev *dev;
+ /* DMIC device */
+ struct platform_device *dmic_dev;
unsigned int fw_bin_size;
unsigned int fw_data_bin_size;
u32 fw_bin_page_count;
diff --git a/sound/soc/sof/amd/pci-rmb.c b/sound/soc/sof/amd/pci-rmb.c
index 2b84f95072d3..eaf70ea6e556 100644
--- a/sound/soc/sof/amd/pci-rmb.c
+++ b/sound/soc/sof/amd/pci-rmb.c
@@ -26,8 +26,6 @@
#define ACP6x_REG_START 0x1240000
#define ACP6x_REG_END 0x125C000
-static struct platform_device *dmic_dev;
-
static const struct sof_amd_acp_desc rembrandt_chip_info = {
.rev = 6,
.host_bridge_id = HOST_BRIDGE_RMB,
@@ -65,32 +63,17 @@ static const struct sof_dev_desc rembrandt_desc = {
static int acp_pci_rmb_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
{
- struct device *dev = &pci->dev;
unsigned int flag;
- int ret;
flag = snd_amd_acp_find_config(pci);
if (flag != FLAG_AMD_SOF && flag != FLAG_AMD_SOF_ONLY_DMIC)
return -ENODEV;
- ret = sof_pci_probe(pci, pci_id);
- if (ret != 0)
- return ret;
-
- dmic_dev = platform_device_register_data(dev, "dmic-codec", PLATFORM_DEVID_NONE, NULL, 0);
- if (IS_ERR(dmic_dev)) {
- dev_err(dev, "failed to create DMIC device\n");
- sof_pci_remove(pci);
- return PTR_ERR(dmic_dev);
- }
- return ret;
+ return sof_pci_probe(pci, pci_id);
};
static void acp_pci_rmb_remove(struct pci_dev *pci)
{
- if (dmic_dev)
- platform_device_unregister(dmic_dev);
-
sof_pci_remove(pci);
}
diff --git a/sound/soc/sof/amd/pci-rn.c b/sound/soc/sof/amd/pci-rn.c
index a17b15552a7d..4809cb644152 100644
--- a/sound/soc/sof/amd/pci-rn.c
+++ b/sound/soc/sof/amd/pci-rn.c
@@ -26,8 +26,6 @@
#define ACP3x_REG_START 0x1240000
#define ACP3x_REG_END 0x125C000
-static struct platform_device *dmic_dev;
-
static const struct sof_amd_acp_desc renoir_chip_info = {
.rev = 3,
.host_bridge_id = HOST_BRIDGE_CZN,
@@ -65,32 +63,17 @@ static const struct sof_dev_desc renoir_desc = {
static int acp_pci_rn_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
{
- struct device *dev = &pci->dev;
unsigned int flag;
- int ret;
flag = snd_amd_acp_find_config(pci);
if (flag != FLAG_AMD_SOF && flag != FLAG_AMD_SOF_ONLY_DMIC)
return -ENODEV;
- ret = sof_pci_probe(pci, pci_id);
- if (ret != 0)
- return ret;
-
- dmic_dev = platform_device_register_data(dev, "dmic-codec", PLATFORM_DEVID_NONE, NULL, 0);
- if (IS_ERR(dmic_dev)) {
- dev_err(dev, "failed to create DMIC device\n");
- sof_pci_remove(pci);
- return PTR_ERR(dmic_dev);
- }
- return ret;
+ return sof_pci_probe(pci, pci_id);
};
static void acp_pci_rn_remove(struct pci_dev *pci)
{
- if (dmic_dev)
- platform_device_unregister(dmic_dev);
-
return sof_pci_remove(pci);
}
--
2.34.1
--- End Message ---