diff mbox series

[09/21] ASoC: amd: acp70: add acp soundwire dma driver

Message ID 20241219054857.2070420-10-Vijendar.Mukunda@amd.com
State New
Headers show
Series [01/21] ASoC: amd: add register header file for ACP7.0 platform | expand

Commit Message

Vijendar Mukunda Dec. 19, 2024, 5:48 a.m. UTC
SoundWire DMA platform driver binds to the platform device created by ACP
PCI device. SoundWire DMA driver registers ALSA DMA component with ASoC
framework. Add common SoundWire dma driver for ACP7.0 and ACP7.1 platforms.

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

Patch

diff --git a/sound/soc/amd/acp70/Makefile b/sound/soc/amd/acp70/Makefile
index 778bdf268731..f3e47635558b 100644
--- a/sound/soc/amd/acp70/Makefile
+++ b/sound/soc/amd/acp70/Makefile
@@ -2,6 +2,8 @@ 
 # ACP 7.0 platform Support
 snd-pci-acp70-y := pci-acp70.o
 snd-acp70-pdm-dma-y := acp70-pdm-dma.o
+snd-acp70-sdw-dma-y := acp70-sdw-dma.o
 
 obj-$(CONFIG_SND_SOC_AMD_ACP70) += snd-pci-acp70.o
 obj-$(CONFIG_SND_SOC_AMD_ACP70) += snd-acp70-pdm-dma.o
+obj-$(CONFIG_SND_SOC_AMD_ACP70) += snd-acp70-sdw-dma.o
diff --git a/sound/soc/amd/acp70/acp70-sdw-dma.c b/sound/soc/amd/acp70/acp70-sdw-dma.c
new file mode 100644
index 000000000000..6d748b295cb0
--- /dev/null
+++ b/sound/soc/amd/acp70/acp70-sdw-dma.c
@@ -0,0 +1,74 @@ 
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * AMD ALSA SoC common SoundWire DMA Driver for ACP 7.0 and
+ * ACP 7.1 platforms.
+ *
+ * Copyright 2024 Advanced Micro Devices, Inc.
+ */
+
+#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 <linux/soundwire/sdw_amd.h>
+#include "acp70.h"
+
+#define DRV_NAME "amd_acp70_sdw_dma"
+
+static const struct snd_soc_component_driver acp70_sdw_component = {
+	.name		= DRV_NAME,
+	.use_dai_pcm_id = true,
+};
+
+static int acp70_sdw_platform_probe(struct platform_device *pdev)
+{
+	struct resource *res;
+	struct sdw_dma_dev_data *sdw_data;
+	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;
+	}
+
+	sdw_data = devm_kzalloc(&pdev->dev, sizeof(*sdw_data), GFP_KERNEL);
+	if (!sdw_data)
+		return -ENOMEM;
+
+	sdw_data->acp_base = devm_ioremap(&pdev->dev, res->start, resource_size(res));
+	if (!sdw_data->acp_base)
+		return -ENOMEM;
+
+	sdw_data->acp_lock = &acp_data->acp_lock;
+	dev_set_drvdata(&pdev->dev, sdw_data);
+	status = devm_snd_soc_register_component(&pdev->dev,
+						 &acp70_sdw_component,
+						 NULL, 0);
+	if (status) {
+		dev_err(&pdev->dev, "Fail to register sdw dma component\n");
+		return status;
+	}
+	return 0;
+}
+
+static struct platform_driver acp70_sdw_dma_driver = {
+	.probe = acp70_sdw_platform_probe,
+	.driver = {
+		.name = "amd_acp70_sdw_dma",
+	},
+};
+
+module_platform_driver(acp70_sdw_dma_driver);
+
+MODULE_AUTHOR("Vijendar.Mukunda@amd.com");
+MODULE_DESCRIPTION("AMD ACP7.0 SDW DMA 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 d6c99d43ed4f..c707c10c4be4 100644
--- a/sound/soc/amd/acp70/acp70.h
+++ b/sound/soc/amd/acp70/acp70.h
@@ -97,6 +97,11 @@  struct pdm_dev_data {
 	struct snd_pcm_substream *capture_stream;
 };
 
+struct sdw_dma_dev_data {
+	void __iomem *acp_base;
+	struct mutex *acp_lock; /* used to protect acp common register access */
+};
+
 /**
  * struct acp70_dev_data - acp pci driver context
  * @acp70_base: acp mmio base