summary refs log tree commit diff
path: root/sound/soc/sof
diff options
context:
space:
mode:
authorVijendar Mukunda <Vijendar.Mukunda@amd.com>2023-04-03 12:46:46 +0530
committerPrasad Prasad <venkataprasad.potturu@amd.com>2023-04-23 15:10:05 -0400
commit8801a60166d62726a1cd8d97f77e13337ff546e9 (patch)
tree190377f190d6b5c62bbc1d62a3f7719341edebb2 /sound/soc/sof
parent6e9367250331624d9324f7d7b67bce45292c6100 (diff)
downloadlinux-8801a60166d62726a1cd8d97f77e13337ff546e9.tar.gz
FROMGIT: ASoC: SOF: amd: refactor dmic codec platform device creation
Under snd_sof_dev device scope, create platform device for dmic
codec.

Signed-off-by: Vijendar Mukunda <Vijendar.Mukunda@amd.com>
Link: https://lore.kernel.org/r/168050621098.26.7486882101201297853@mailman-core.alsa-project.org
Signed-off-by: Mark Brown <broonie@kernel.org>
(cherry picked from commit dd6bdd8b4d41b8f9db4b88dff2d10c0c62dbeb1d
 https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git/ for-next)

Signed-off-by: Venkata Prasad Potturu <venkataprasad.potturu@amd.com>
Reviewed-by: V sujith kumar Reddy <Vsujithkumar.Reddy@amd.com>
Diffstat (limited to 'sound/soc/sof')
-rw-r--r--sound/soc/sof/amd/acp.c17
-rw-r--r--sound/soc/sof/amd/acp.h2
-rw-r--r--sound/soc/sof/amd/pci-rmb.c19
-rw-r--r--sound/soc/sof/amd/pci-rn.c19
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 @@ free_ipc_irq:
 	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 6fc9e8b63171..abeb19dd8fed 100644
--- a/sound/soc/sof/amd/acp.h
+++ b/sound/soc/sof/amd/acp.h
@@ -168,6 +168,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);
 }