[alsa-devel] [PATCH 3/7][RFC] ASoC: soc.h: add sound dai_link connection macro

Kuninori Morimoto kuninori.morimoto.gx at renesas.com
Mon Apr 8 04:31:51 CEST 2019


Modern style dai_link requests CPU/Codec/Platform component
pointer array and its size, but it will be very verbose code.
To avoid such scene, this patch adds dai_link connection macro.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx at renesas.com>
---
 include/sound/soc.h | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)

diff --git a/include/sound/soc.h b/include/sound/soc.h
index 23463ba..fdde69a 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -1043,6 +1043,63 @@ struct snd_soc_dai_link {
 	     ((i) < link->num_codecs) && ((codec) = &link->codecs[i]);	\
 	     (i)++)
 
+/*
+ * Sample 1 : Single CPU/Codec/Platform
+ *
+ * SND_SOC_DAI_LINK_CCP(single_dsp,
+ *	SND_SOC_DAI_LINK(SDL_CPU("xxx")),
+ *	SND_SOC_DAI_LINK(SDL_CODEC("xxx", "xxx")),
+ *	SND_SOC_DAI_LINK(SDL_PLATFORM("xxx")));
+ *
+ * static struct snd_soc_dai_link xxx = {
+ *	...
+ *	SND_SOC_LINK_CCP(single_dsp),
+ *	...
+ * };
+ *
+ * Sample 2 : Multi CPU/Codec, no Platform
+ *
+ * SND_SOC_DAI_LINK_CC(multi_dsp,
+ *	SND_SOC_DAI_LINK(SDL_CPU("xxx"),
+ *			 SDL_CPU("xxx")),
+ *	SND_SOC_DAI_LINK(SDL_CODEC("xxx", "xxx"),
+ *			 SDL_CODEC("xxx", "xxx")))
+ *
+ * static struct snd_soc_dai_link xxx = {
+ *	...
+ *	SND_SOC_LINK_CC(multi_dsp),
+ *	...
+ * };
+ */
+#define SND_SOC_DAI_LINK_CC(name, cpu, codec)\
+	static struct snd_soc_dai_link_component name##_cpu[]	= cpu;\
+	static struct snd_soc_dai_link_component name##_codec[]	= codec
+
+#define SND_SOC_DAI_LINK_CCP(name, cpu, codec, platform)\
+	static struct snd_soc_dai_link_component name##_cpu[]	= cpu;\
+	static struct snd_soc_dai_link_component name##_codec[]	= codec;\
+	static struct snd_soc_dai_link_component name##_platform[] = platform
+
+#define SND_SOC_DAI_LINK(param...)	{ param }
+#define SDL_EMPTY()			{ }
+#define SDL_CPU(_dai)			{ .dai_name = _dai, }
+#define SDL_CODEC(_name, _dai)		{ .name = _name, .dai_name = _dai, }
+#define SDL_PLATFORM(_name)		{ .name = _name }
+
+#define SND_SOC_LINK_CC(name)				\
+	.cpus		= name##_cpu,			\
+	.num_cpus	= ARRAY_SIZE(name##_cpu),	\
+	.codecs		= name##_codec,			\
+	.num_codecs	= ARRAY_SIZE(name##_codec)
+
+#define SND_SOC_LINK_CCP(name)				\
+	.cpus		= name##_cpu,			\
+	.num_cpus	= ARRAY_SIZE(name##_cpu),	\
+	.codecs		= name##_codec,			\
+	.num_codecs	= ARRAY_SIZE(name##_codec),	\
+	.platforms	= name##_platform,		\
+	.num_platforms	= ARRAY_SIZE(name##_platform)
+
 struct snd_soc_codec_conf {
 	/*
 	 * specify device either by device name, or by
-- 
2.7.4



More information about the Alsa-devel mailing list