diff mbox series

[4/6] ASoC: amd: acp: move get_acp63_cpu_pin_id() to common file

Message ID 20241113115223.3274868-5-Vijendar.Mukunda@amd.com (mailing list archive)
State New
Headers show
Series Add generic AMD Soundwire machine driver for Legacy(No | expand

Commit Message

Vijendar Mukunda Nov. 13, 2024, 11:52 a.m. UTC
get_acp63_cpu_pin_id() is the common SoundWire machine driver
helper function will be used for AMD Legacy(No DSP) generic
SoundWire machine driver as well.
Move get_acp63_cpu_pin_id() function to common place holder.

Signed-off-by: Vijendar Mukunda <Vijendar.Mukunda@amd.com>
---
 sound/soc/amd/acp/Kconfig               |  7 +++
 sound/soc/amd/acp/Makefile              |  2 +
 sound/soc/amd/acp/acp-sdw-mach-common.c | 64 +++++++++++++++++++++++++
 sound/soc/amd/acp/acp-sdw-sof-mach.c    | 49 +------------------
 sound/soc/amd/acp/soc_amd_sdw_common.h  |  2 +
 5 files changed, 76 insertions(+), 48 deletions(-)
 create mode 100644 sound/soc/amd/acp/acp-sdw-mach-common.c
diff mbox series

Patch

diff --git a/sound/soc/amd/acp/Kconfig b/sound/soc/amd/acp/Kconfig
index 88391e4c17e3..acd047d558bd 100644
--- a/sound/soc/amd/acp/Kconfig
+++ b/sound/soc/amd/acp/Kconfig
@@ -119,10 +119,17 @@  config SND_SOC_AMD_SOF_MACH
 	help
 	  This option enables SOF sound card support for ACP audio.
 
+config SND_SOC_AMD_SDW_MACH_COMMON
+	tristate
+	help
+	  This option enables common SoundWire Machine driver module for
+	  AMD platforms.
+
 config SND_SOC_AMD_SOF_SDW_MACH
 	tristate "AMD SOF Soundwire Machine Driver Support"
 	depends on X86 && PCI && ACPI
 	depends on SOUNDWIRE
+	select SND_SOC_AMD_SDW_MACH_COMMON
 	select SND_SOC_SDW_UTILS
 	select SND_SOC_DMIC
 	select SND_SOC_RT711_SDW
diff --git a/sound/soc/amd/acp/Makefile b/sound/soc/amd/acp/Makefile
index 82cf5d180b3a..0e6c4022e7a2 100644
--- a/sound/soc/amd/acp/Makefile
+++ b/sound/soc/amd/acp/Makefile
@@ -23,6 +23,7 @@  snd-acp-mach-y     := acp-mach-common.o
 snd-acp-legacy-mach-y     := acp-legacy-mach.o acp3x-es83xx/acp3x-es83xx.o
 snd-acp-sof-mach-y     := acp-sof-mach.o
 snd-soc-acpi-amd-match-y := amd-acp63-acpi-match.o
+snd-acp-sdw-mach-y     := acp-sdw-mach-common.o
 snd-acp-sdw-sof-mach-y += acp-sdw-sof-mach.o
 
 obj-$(CONFIG_SND_SOC_AMD_ACP_PCM) += snd-acp-pcm.o
@@ -41,4 +42,5 @@  obj-$(CONFIG_SND_SOC_AMD_MACH_COMMON) += snd-acp-mach.o
 obj-$(CONFIG_SND_SOC_AMD_LEGACY_MACH) += snd-acp-legacy-mach.o
 obj-$(CONFIG_SND_SOC_AMD_SOF_MACH) += snd-acp-sof-mach.o
 obj-$(CONFIG_SND_SOC_ACPI_AMD_MATCH) += snd-soc-acpi-amd-match.o
+obj-$(CONFIG_SND_SOC_AMD_SDW_MACH_COMMON) += snd-acp-sdw-mach.o
 obj-$(CONFIG_SND_SOC_AMD_SOF_SDW_MACH) += snd-acp-sdw-sof-mach.o
diff --git a/sound/soc/amd/acp/acp-sdw-mach-common.c b/sound/soc/amd/acp/acp-sdw-mach-common.c
new file mode 100644
index 000000000000..d9393cc4a302
--- /dev/null
+++ b/sound/soc/amd/acp/acp-sdw-mach-common.c
@@ -0,0 +1,64 @@ 
+// SPDX-License-Identifier: GPL-2.0-only
+// Copyright(c) 2024 Advanced Micro Devices, Inc.
+
+/*
+ *  acp-sdw-mach-common - Common machine driver helper functions for
+ *  legacy(No DSP) stack and SOF stack.
+ */
+
+#include <linux/device.h>
+#include <linux/module.h>
+#include "soc_amd_sdw_common.h"
+
+int get_acp63_cpu_pin_id(u32 sdw_link_id, int be_id, int *cpu_pin_id, struct device *dev)
+{
+	switch (sdw_link_id) {
+	case AMD_SDW0:
+		switch (be_id) {
+		case SOC_SDW_JACK_OUT_DAI_ID:
+			*cpu_pin_id = ACP63_SW0_AUDIO0_TX;
+			break;
+		case SOC_SDW_JACK_IN_DAI_ID:
+			*cpu_pin_id = ACP63_SW0_AUDIO0_RX;
+			break;
+		case SOC_SDW_AMP_OUT_DAI_ID:
+			*cpu_pin_id = ACP63_SW0_AUDIO1_TX;
+			break;
+		case SOC_SDW_AMP_IN_DAI_ID:
+			*cpu_pin_id = ACP63_SW0_AUDIO1_RX;
+			break;
+		case SOC_SDW_DMIC_DAI_ID:
+			*cpu_pin_id = ACP63_SW0_AUDIO2_RX;
+			break;
+		default:
+			dev_err(dev, "Invalid be id:%d\n", be_id);
+			return -EINVAL;
+		}
+		break;
+	case AMD_SDW1:
+		switch (be_id) {
+		case SOC_SDW_JACK_OUT_DAI_ID:
+		case SOC_SDW_AMP_OUT_DAI_ID:
+			*cpu_pin_id = ACP63_SW1_AUDIO0_TX;
+			break;
+		case SOC_SDW_JACK_IN_DAI_ID:
+		case SOC_SDW_AMP_IN_DAI_ID:
+		case SOC_SDW_DMIC_DAI_ID:
+			*cpu_pin_id = ACP63_SW1_AUDIO0_RX;
+			break;
+		default:
+			dev_err(dev, "invalid be_id:%d\n", be_id);
+			return -EINVAL;
+		}
+		break;
+	default:
+		dev_err(dev, "Invalid link id:%d\n", sdw_link_id);
+		return -EINVAL;
+	}
+	return 0;
+}
+EXPORT_SYMBOL_NS_GPL(get_acp63_cpu_pin_id, SND_SOC_AMD_SDW_MACH);
+
+MODULE_DESCRIPTION("AMD SoundWire Common Machine driver");
+MODULE_AUTHOR("Vijendar Mukunda <Vijendar.Mukunda@amd.com>");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/amd/acp/acp-sdw-sof-mach.c b/sound/soc/amd/acp/acp-sdw-sof-mach.c
index 8fce8cb957c9..0d256c0749c9 100644
--- a/sound/soc/amd/acp/acp-sdw-sof-mach.c
+++ b/sound/soc/amd/acp/acp-sdw-sof-mach.c
@@ -64,54 +64,6 @@  static const struct snd_soc_ops sdw_ops = {
 	.shutdown = asoc_sdw_shutdown,
 };
 
-static int get_acp63_cpu_pin_id(u32 sdw_link_id, int be_id, int *cpu_pin_id, struct device *dev)
-{
-	switch (sdw_link_id) {
-	case AMD_SDW0:
-		switch (be_id) {
-		case SOC_SDW_JACK_OUT_DAI_ID:
-			*cpu_pin_id = ACP63_SW0_AUDIO0_TX;
-			break;
-		case SOC_SDW_JACK_IN_DAI_ID:
-			*cpu_pin_id = ACP63_SW0_AUDIO0_RX;
-			break;
-		case SOC_SDW_AMP_OUT_DAI_ID:
-			*cpu_pin_id = ACP63_SW0_AUDIO1_TX;
-			break;
-		case SOC_SDW_AMP_IN_DAI_ID:
-			*cpu_pin_id = ACP63_SW0_AUDIO1_RX;
-			break;
-		case SOC_SDW_DMIC_DAI_ID:
-			*cpu_pin_id = ACP63_SW0_AUDIO2_RX;
-			break;
-		default:
-			dev_err(dev, "Invalid be id:%d\n", be_id);
-			return -EINVAL;
-		}
-		break;
-	case AMD_SDW1:
-		switch (be_id) {
-		case SOC_SDW_JACK_OUT_DAI_ID:
-		case SOC_SDW_AMP_OUT_DAI_ID:
-			*cpu_pin_id = ACP63_SW1_AUDIO0_TX;
-			break;
-		case SOC_SDW_JACK_IN_DAI_ID:
-		case SOC_SDW_AMP_IN_DAI_ID:
-		case SOC_SDW_DMIC_DAI_ID:
-			*cpu_pin_id = ACP63_SW1_AUDIO0_RX;
-			break;
-		default:
-			dev_err(dev, "invalid be_id:%d\n", be_id);
-			return -EINVAL;
-		}
-		break;
-	default:
-		dev_err(dev, "Invalid link id:%d\n", sdw_link_id);
-		return -EINVAL;
-	}
-	return 0;
-}
-
 static const char * const type_strings[] = {"SimpleJack", "SmartAmp", "SmartMic"};
 
 static int create_sdw_dailink(struct snd_soc_card *card,
@@ -491,3 +443,4 @@  MODULE_DESCRIPTION("ASoC AMD SoundWire Generic Machine driver");
 MODULE_AUTHOR("Vijendar Mukunda <Vijendar.Mukunda@amd.com");
 MODULE_LICENSE("GPL");
 MODULE_IMPORT_NS(SND_SOC_SDW_UTILS);
+MODULE_IMPORT_NS(SND_SOC_AMD_SDW_MACH);
diff --git a/sound/soc/amd/acp/soc_amd_sdw_common.h b/sound/soc/amd/acp/soc_amd_sdw_common.h
index f1bd5a7afc8e..eba92cd004d4 100644
--- a/sound/soc/amd/acp/soc_amd_sdw_common.h
+++ b/sound/soc/amd/acp/soc_amd_sdw_common.h
@@ -41,4 +41,6 @@  struct amd_mc_ctx {
 	unsigned int max_sdw_links;
 };
 
+int get_acp63_cpu_pin_id(u32 sdw_link_id, int be_id, int *cpu_pin_id, struct device *dev);
+
 #endif