[alsa-devel] [RFC][PATCH 1/2] ASoC: add snd_soc_of_parse_daifmt()

Kuninori Morimoto kuninori.morimoto.gx at renesas.com
Thu Nov 29 05:31:44 CET 2012


ALSA SoC system is using SND_SOC_DAIFMT_xxx flags on each platform,
and its value might be updated for some reason.
This means that if platform is using Device Tree
and if it gets parameter value directly,
it is difficult to keep compatible on each platform Device Tree.
This patch adds snd_soc_of_parse_daifmt() to solve this issue.
Each platform can use [prefix]snd,soc,daifmt,xxx to set
SND_SOC_DAIFMT_XXX on Device Tree.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx at renesas.com>
---
 include/sound/soc.h  |    2 ++
 sound/soc/soc-core.c |   72 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 74 insertions(+)

diff --git a/include/sound/soc.h b/include/sound/soc.h
index 91244a0..af64632 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -1168,6 +1168,8 @@ int snd_soc_of_parse_card_name(struct snd_soc_card *card,
 			       const char *propname);
 int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
 				   const char *propname);
+int snd_soc_of_parse_daifmt(struct device_node *np,
+			    const char *prefix, unsigned int *fmt);
 
 #include <sound/soc-dai.h>
 
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 9c768bc..0142742 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -4179,6 +4179,78 @@ int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
 }
 EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_routing);
 
+static int __snd_soc_of_parse_daifmt(struct device_node *np,
+				     const char *prefix, unsigned int *fmt,
+				     const char *propname, unsigned int val)
+{
+	char str[128];
+	int ret;
+
+	snprintf(str, 128, "%ssnd,soc,daifmt,%s", prefix, propname);
+	ret = of_property_read_bool(np, str);
+	if (ret)
+		*fmt |= val;
+
+	return ret;
+}
+
+int snd_soc_of_parse_daifmt(struct device_node *np,
+			    const char *prefix, unsigned int *fmt)
+{
+	int ret = 0;
+	char pre[] = "";
+
+	if (!prefix)
+		prefix = pre;
+
+	/*
+	 * it will find "[prefix]snd,soc,daifmt,xxx" from device_node,
+	 * and set SND_SOC_DAIFMT_XXX
+	 */
+	ret |= __snd_soc_of_parse_daifmt(np, prefix, fmt,
+					 "i2s", SND_SOC_DAIFMT_I2S);
+	ret |= __snd_soc_of_parse_daifmt(np, prefix, fmt,
+					 "right_j", SND_SOC_DAIFMT_RIGHT_J);
+	ret |= __snd_soc_of_parse_daifmt(np, prefix, fmt,
+					 "left_j", SND_SOC_DAIFMT_LEFT_J);
+	ret |= __snd_soc_of_parse_daifmt(np, prefix, fmt,
+					 "dsp_a", SND_SOC_DAIFMT_DSP_A);
+	ret |= __snd_soc_of_parse_daifmt(np, prefix, fmt,
+					 "dsp_b", SND_SOC_DAIFMT_DSP_B);
+	ret |= __snd_soc_of_parse_daifmt(np, prefix, fmt,
+					 "ac97", SND_SOC_DAIFMT_AC97);
+	ret |= __snd_soc_of_parse_daifmt(np, prefix, fmt,
+					 "pdm", SND_SOC_DAIFMT_PDM);
+	ret |= __snd_soc_of_parse_daifmt(np, prefix, fmt,
+					 "msb", SND_SOC_DAIFMT_MSB);
+	ret |= __snd_soc_of_parse_daifmt(np, prefix, fmt,
+					 "lsb", SND_SOC_DAIFMT_LSB);
+	ret |= __snd_soc_of_parse_daifmt(np, prefix, fmt,
+					 "cont", SND_SOC_DAIFMT_CONT);
+	ret |= __snd_soc_of_parse_daifmt(np, prefix, fmt,
+					 "gated", SND_SOC_DAIFMT_GATED);
+	ret |= __snd_soc_of_parse_daifmt(np, prefix, fmt,
+					 "nb_nf", SND_SOC_DAIFMT_NB_NF);
+	ret |= __snd_soc_of_parse_daifmt(np, prefix, fmt,
+					 "nb_if", SND_SOC_DAIFMT_NB_IF);
+	ret |= __snd_soc_of_parse_daifmt(np, prefix, fmt,
+					 "ib_nf", SND_SOC_DAIFMT_IB_NF);
+	ret |= __snd_soc_of_parse_daifmt(np, prefix, fmt,
+					 "ib_if", SND_SOC_DAIFMT_IB_IF);
+	ret |= __snd_soc_of_parse_daifmt(np, prefix, fmt,
+					 "cbm_cfm", SND_SOC_DAIFMT_CBM_CFM);
+	ret |= __snd_soc_of_parse_daifmt(np, prefix, fmt,
+					 "cbs_cfm", SND_SOC_DAIFMT_CBS_CFM);
+	ret |= __snd_soc_of_parse_daifmt(np, prefix, fmt,
+					 "cbm_cfs", SND_SOC_DAIFMT_CBM_CFS);
+	ret |= __snd_soc_of_parse_daifmt(np, prefix, fmt,
+					 "cbs_cfs", SND_SOC_DAIFMT_CBS_CFS);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(snd_soc_of_parse_daifmt);
+
+
 static int __init snd_soc_init(void)
 {
 #ifdef CONFIG_DEBUG_FS
-- 
1.7.9.5



More information about the Alsa-devel mailing list