diff mbox series

[07/21] ASoC: amd: acp70: add acp pdm platform driver

Message ID 20241219054857.2070420-8-Vijendar.Mukunda@amd.com
State New
Headers show
Series ASoC: amd: acp70: add soundwire and acp pdm support | expand

Commit Message

Vijendar Mukunda Dec. 19, 2024, 5:48 a.m. UTC
PDM platform driver binds to the platform device created by
ACP7.0 PCI device. PDM driver registers ALSA DMA and CPU DAI
components with ASoC framework.

Signed-off-by: Vijendar Mukunda <Vijendar.Mukunda@amd.com>
---
 sound/soc/amd/acp70/Makefile        |  2 +
 sound/soc/amd/acp70/acp70-pdm-dma.c | 87 +++++++++++++++++++++++++++++
 sound/soc/amd/acp70/acp70.h         |  7 +++
 3 files changed, 96 insertions(+)
 create mode 100644 sound/soc/amd/acp70/acp70-pdm-dma.c
diff mbox series

Patch

diff --git a/sound/soc/amd/acp70/Makefile b/sound/soc/amd/acp70/Makefile
index 5e553de6c772..778bdf268731 100644
--- a/sound/soc/amd/acp70/Makefile
+++ b/sound/soc/amd/acp70/Makefile
@@ -1,5 +1,7 @@ 
 # SPDX-License-Identifier: GPL-2.0-only
 # ACP 7.0 platform Support
 snd-pci-acp70-y := pci-acp70.o
+snd-acp70-pdm-dma-y := acp70-pdm-dma.o
 
 obj-$(CONFIG_SND_SOC_AMD_ACP70) += snd-pci-acp70.o
+obj-$(CONFIG_SND_SOC_AMD_ACP70) += snd-acp70-pdm-dma.o
diff --git a/sound/soc/amd/acp70/acp70-pdm-dma.c b/sound/soc/amd/acp70/acp70-pdm-dma.c
new file mode 100644
index 000000000000..fd31e31a02a6
--- /dev/null
+++ b/sound/soc/amd/acp70/acp70-pdm-dma.c
@@ -0,0 +1,87 @@ 
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * AMD ALSA SoC ACP 7.0 PDM Driver
+ *
+ * Copyright 2024 Advanced Micro Devices, Inc.
+ */
+
+#include <linux/bitfield.h>
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <sound/pcm_params.h>
+#include <sound/soc.h>
+#include <sound/soc-dai.h>
+
+#include "acp70.h"
+
+#define DRV_NAME "acp70_pdm_dma"
+
+static struct snd_soc_dai_driver acp70_pdm_dai_driver = {
+	.name = "acp_acp70_pdm_dma.0",
+	.capture = {
+		.rates = SNDRV_PCM_RATE_48000,
+		.formats = SNDRV_PCM_FMTBIT_S32_LE,
+		.channels_min = 2,
+		.channels_max = 2,
+		.rate_min = 48000,
+		.rate_max = 48000,
+	},
+};
+
+static const struct snd_soc_component_driver acp70_pdm_component = {
+	.name		= DRV_NAME,
+};
+
+static int acp70_pdm_audio_probe(struct platform_device *pdev)
+{
+	struct resource *res;
+	struct pdm_dev_data *adata;
+	struct acp70_dev_data *acp_data;
+	struct device *parent;
+	int status;
+
+	parent = pdev->dev.parent;
+	acp_data = dev_get_drvdata(parent);
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res) {
+		dev_err(&pdev->dev, "IORESOURCE_MEM FAILED\n");
+		return -ENODEV;
+	}
+
+	adata = devm_kzalloc(&pdev->dev, sizeof(*adata), GFP_KERNEL);
+	if (!adata)
+		return -ENOMEM;
+
+	adata->acp70_base = devm_ioremap(&pdev->dev, res->start, resource_size(res));
+	if (!adata->acp70_base)
+		return -ENOMEM;
+
+	adata->capture_stream = NULL;
+	adata->acp_lock = &acp_data->acp_lock;
+	dev_set_drvdata(&pdev->dev, adata);
+	status = devm_snd_soc_register_component(&pdev->dev,
+						 &acp70_pdm_component,
+						 &acp70_pdm_dai_driver, 1);
+	if (status) {
+		dev_err(&pdev->dev, "Fail to register acp pdm dai\n");
+
+		return -ENODEV;
+	}
+	return 0;
+}
+
+static struct platform_driver acp70_pdm_dma_driver = {
+	.probe = acp70_pdm_audio_probe,
+	.driver = {
+		.name = "acp70_pdm_dma",
+	},
+};
+
+module_platform_driver(acp70_pdm_dma_driver);
+
+MODULE_AUTHOR("Vijendar.Mukunda@amd.com");
+MODULE_DESCRIPTION("AMD ACP 7.0 PDM Driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:" DRV_NAME);
diff --git a/sound/soc/amd/acp70/acp70.h b/sound/soc/amd/acp70/acp70.h
index 68035fbf23d1..c7cabb98cc1a 100644
--- a/sound/soc/amd/acp70/acp70.h
+++ b/sound/soc/amd/acp70/acp70.h
@@ -58,6 +58,13 @@  enum acp_config {
 	ACP_CONFIG_20,
 };
 
+struct pdm_dev_data {
+	u32 pdm_irq;
+	void __iomem *acp70_base;
+	struct mutex *acp_lock; /* mutex to protect acp common register access */
+	struct snd_pcm_substream *capture_stream;
+};
+
 /**
  * struct acp70_dev_data - acp pci driver context
  * @acp70_base: acp mmio base