[Sound-open-firmware] [PATCH 4/4] [RFC] ASoC: SOF: Introduce snd_soc_fw_mach descriptor

Daniel Baluta daniel.baluta at nxp.com
Wed Oct 30 16:42:01 CET 2019


This will unify machine driver descriptor between
OF/ACPI.

Signed-off-by: Daniel Baluta <daniel.baluta at nxp.com>
---
 include/sound/soc-of.h    | 22 ++++++++++++++++++++++
 include/sound/sof.h       | 26 ++++++++++++++++++++++++++
 sound/soc/sof/pcm.c       |  2 +-
 sound/soc/sof/sof-audio.h |  2 +-
 4 files changed, 50 insertions(+), 2 deletions(-)
 create mode 100644 include/sound/soc-of.h

diff --git a/include/sound/soc-of.h b/include/sound/soc-of.h
new file mode 100644
index 000000000000..267c92c54188
--- /dev/null
+++ b/include/sound/soc-of.h
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-2.0
+ *
+ * Copyright 2019 NXP
+ */
+
+#ifndef __LINUX_SND_SOC_OF_H
+#define __LINUX_SND_SOC_OF_H
+
+#include <linux/of.h>
+
+/**
+ * snd_soc_of_mach: DT-based machine driver descriptor
+ *
+ * @drv_name: machine driver name
+ * @of: DT node providing machine driver description
+ */
+struct snd_soc_of_mach {
+	const char *drv_name;
+	struct device_node *of;
+};
+
+#endif
diff --git a/include/sound/sof.h b/include/sound/sof.h
index 4e151abecac8..60db0a73d337 100644
--- a/include/sound/sof.h
+++ b/include/sound/sof.h
@@ -14,10 +14,36 @@
 #include <linux/pci.h>
 #include <sound/soc.h>
 #include <sound/soc-acpi.h>
+#include <sound/soc-of.h>
 
 struct snd_sof_dsp_ops;
 struct snd_sof_audio_ops;
 
+enum {
+	SND_SOC_FW_TYPE_ACPI = 0,
+	SND_SOC_FW_TYPE_OF,
+};
+
+struct snd_soc_fw_mach {
+	int type;
+	union {
+		struct snd_soc_acpi_mach *acpi;
+		struct snd_soc_of_mach *of;
+	};
+};
+
+static inline
+const char *sof_mach_get_drv_name(const struct snd_soc_fw_mach *mach)
+{
+	switch (mach->type) {
+	case SND_SOC_FW_TYPE_ACPI:
+		return mach->acpi->drv_name;
+	case SND_SOC_FW_TYPE_OF:
+		return mach->of->drv_name;
+	default:
+		return NULL;
+	}
+}
 /*
  * SOF Platform data.
  */
diff --git a/sound/soc/sof/pcm.c b/sound/soc/sof/pcm.c
index 8de566d7ee85..c0e8ecb287d7 100644
--- a/sound/soc/sof/pcm.c
+++ b/sound/soc/sof/pcm.c
@@ -795,7 +795,7 @@ void snd_sof_new_platform_drv(struct sof_audio_dev *sof_audio)
 	struct snd_soc_component_driver *pd = &sof_audio->plat_drv;
 	const char *drv_name;
 
-	drv_name = sof_audio->machine->drv_name;
+	drv_name = sof_mach_get_drv_name(sof_audio->machine);
 
 	pd->name = "sof-audio-component";
 	pd->probe = sof_pcm_probe;
diff --git a/sound/soc/sof/sof-audio.h b/sound/soc/sof/sof-audio.h
index 8b76b8b1709b..013e7e85d61d 100644
--- a/sound/soc/sof/sof-audio.h
+++ b/sound/soc/sof/sof-audio.h
@@ -160,7 +160,7 @@ struct sof_audio_dev {
 
 	/* machine */
 	struct platform_device *pdev_mach;
-	const struct snd_soc_acpi_mach *machine;
+	struct snd_soc_fw_mach *machine;
 
 	const char *tplg_filename_prefix;
 	const char *tplg_filename;
-- 
2.17.1



More information about the Sound-open-firmware mailing list