[alsa-devel] [PATCH 3/5] ASoC: simple-card: add asoc_simple_dai_set for initializing

Kuninori Morimoto kuninori.morimoto.gx at renesas.com
Wed Dec 26 07:52:42 CET 2012


Current simple-card supports sysclk settings but it is only for codec.
In order to abolish deviation between cpu and codec,
and in order to simplify processing,
this patch adds asoc_simple_dai_set for initializing.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx at renesas.com>
---
 arch/arm/mach-shmobile/board-ap4evb.c          |   11 +++---
 arch/arm/mach-shmobile/board-armadillo800eva.c |   10 +++---
 arch/arm/mach-shmobile/board-kzm9g.c           |    8 ++---
 arch/arm/mach-shmobile/board-mackerel.c        |   11 +++---
 arch/sh/boards/mach-ecovec24/setup.c           |    7 ++--
 arch/sh/boards/mach-se/7724/setup.c            |    9 +++--
 include/sound/simple_card.h                    |   12 ++++---
 sound/soc/generic/simple-card.c                |   44 ++++++++++++++----------
 8 files changed, 59 insertions(+), 53 deletions(-)

diff --git a/arch/arm/mach-shmobile/board-ap4evb.c b/arch/arm/mach-shmobile/board-ap4evb.c
index 4c97903..60e6be4 100644
--- a/arch/arm/mach-shmobile/board-ap4evb.c
+++ b/arch/arm/mach-shmobile/board-ap4evb.c
@@ -687,10 +687,10 @@ static struct platform_device fsi_device = {
 };
 
 static struct asoc_simple_dai_init_info fsi2_ak4643_init_info = {
-	.fmt		= SND_SOC_DAIFMT_LEFT_J,
-	.codec_daifmt	= SND_SOC_DAIFMT_CBM_CFM,
-	.cpu_daifmt	= SND_SOC_DAIFMT_CBS_CFS,
-	.sysclk		= 11289600,
+	.daifmt			= SND_SOC_DAIFMT_LEFT_J,
+	.cpu_set.daifmt		= SND_SOC_DAIFMT_CBS_CFS,
+	.codec_set.daifmt	= SND_SOC_DAIFMT_CBM_CFM,
+	.codec_set.sysclk	= 11289600,
 };
 
 static struct asoc_simple_card_info fsi2_ak4643_info = {
@@ -810,8 +810,7 @@ static struct platform_device lcdc1_device = {
 };
 
 static struct asoc_simple_dai_init_info fsi2_hdmi_init_info = {
-	.cpu_daifmt	= SND_SOC_DAIFMT_CBM_CFM |
-			  SND_SOC_DAIFMT_IB_NF,
+	.cpu_set.daifmt	= SND_SOC_DAIFMT_CBM_CFM | SND_SOC_DAIFMT_IB_NF,
 };
 
 static struct asoc_simple_card_info fsi2_hdmi_info = {
diff --git a/arch/arm/mach-shmobile/board-armadillo800eva.c b/arch/arm/mach-shmobile/board-armadillo800eva.c
index 042a21e..278324c 100644
--- a/arch/arm/mach-shmobile/board-armadillo800eva.c
+++ b/arch/arm/mach-shmobile/board-armadillo800eva.c
@@ -808,10 +808,10 @@ static struct platform_device fsi_device = {
 
 /* FSI-WM8978 */
 static struct asoc_simple_dai_init_info fsi_wm8978_init_info = {
-	.fmt		= SND_SOC_DAIFMT_I2S,
-	.codec_daifmt	= SND_SOC_DAIFMT_CBM_CFM | SND_SOC_DAIFMT_NB_NF,
-	.cpu_daifmt	= SND_SOC_DAIFMT_CBS_CFS,
-	.sysclk		= 12288000,
+	.daifmt			= SND_SOC_DAIFMT_I2S,
+	.cpu_set.daifmt		= SND_SOC_DAIFMT_CBS_CFS | SND_SOC_DAIFMT_IB_NF,
+	.codec_set.daifmt	= SND_SOC_DAIFMT_CBM_CFM | SND_SOC_DAIFMT_NB_NF,
+	.codec_set.sysclk	= 12288000,
 };
 
 static struct asoc_simple_card_info fsi_wm8978_info = {
@@ -834,7 +834,7 @@ static struct platform_device fsi_wm8978_device = {
 
 /* FSI-HDMI */
 static struct asoc_simple_dai_init_info fsi2_hdmi_init_info = {
-	.cpu_daifmt	= SND_SOC_DAIFMT_CBM_CFM,
+	.cpu_set.daifmt	= SND_SOC_DAIFMT_CBM_CFM,
 };
 
 static struct asoc_simple_card_info fsi2_hdmi_info = {
diff --git a/arch/arm/mach-shmobile/board-kzm9g.c b/arch/arm/mach-shmobile/board-kzm9g.c
index 9ca7ce5..59a6dc3 100644
--- a/arch/arm/mach-shmobile/board-kzm9g.c
+++ b/arch/arm/mach-shmobile/board-kzm9g.c
@@ -527,10 +527,10 @@ static struct platform_device fsi_device = {
 };
 
 static struct asoc_simple_dai_init_info fsi2_ak4648_init_info = {
-	.fmt		= SND_SOC_DAIFMT_LEFT_J,
-	.codec_daifmt	= SND_SOC_DAIFMT_CBM_CFM,
-	.cpu_daifmt	= SND_SOC_DAIFMT_CBS_CFS,
-	.sysclk		= 11289600,
+	.daifmt			= SND_SOC_DAIFMT_LEFT_J,
+	.cpu_set.daifmt		= SND_SOC_DAIFMT_CBS_CFS,
+	.codec_set.daifmt	= SND_SOC_DAIFMT_CBM_CFM,
+	.codec_set.sysclk	= 11289600,
 };
 
 static struct asoc_simple_card_info fsi2_ak4648_info = {
diff --git a/arch/arm/mach-shmobile/board-mackerel.c b/arch/arm/mach-shmobile/board-mackerel.c
index b5d210b..d6380be 100644
--- a/arch/arm/mach-shmobile/board-mackerel.c
+++ b/arch/arm/mach-shmobile/board-mackerel.c
@@ -503,8 +503,7 @@ static struct platform_device hdmi_lcdc_device = {
 };
 
 static struct asoc_simple_dai_init_info fsi2_hdmi_init_info = {
-	.cpu_daifmt	= SND_SOC_DAIFMT_CBM_CFM |
-			  SND_SOC_DAIFMT_IB_NF,
+	.cpu_set.daifmt	= SND_SOC_DAIFMT_CBM_CFM | SND_SOC_DAIFMT_IB_NF,
 };
 
 static struct asoc_simple_card_info fsi2_hdmi_info = {
@@ -894,10 +893,10 @@ static struct platform_device fsi_device = {
 };
 
 static struct asoc_simple_dai_init_info fsi2_ak4643_init_info = {
-	.fmt		= SND_SOC_DAIFMT_LEFT_J,
-	.codec_daifmt	= SND_SOC_DAIFMT_CBM_CFM,
-	.cpu_daifmt	= SND_SOC_DAIFMT_CBS_CFS,
-	.sysclk		= 11289600,
+	.daifmt			= SND_SOC_DAIFMT_LEFT_J,
+	.cpu_set.daifmt		= SND_SOC_DAIFMT_CBS_CFS,
+	.codec_set.daifmt	= SND_SOC_DAIFMT_CBM_CFM,
+	.codec_set.sysclk	= 11289600,
 };
 
 static struct asoc_simple_card_info fsi2_ak4643_info = {
diff --git a/arch/sh/boards/mach-ecovec24/setup.c b/arch/sh/boards/mach-ecovec24/setup.c
index 8ebe4c7..8e68d79 100644
--- a/arch/sh/boards/mach-ecovec24/setup.c
+++ b/arch/sh/boards/mach-ecovec24/setup.c
@@ -898,10 +898,9 @@ static struct platform_device fsi_device = {
 };
 
 static struct asoc_simple_dai_init_info fsi_da7210_init_info = {
-	.fmt		= SND_SOC_DAIFMT_I2S,
-	.codec_daifmt	= SND_SOC_DAIFMT_CBM_CFM,
-	.cpu_daifmt	= SND_SOC_DAIFMT_CBS_CFS |
-			  SND_SOC_DAIFMT_IB_NF,
+	.daifmt			= SND_SOC_DAIFMT_I2S,
+	.codec_set.daifmt	= SND_SOC_DAIFMT_CBM_CFM,
+	.cpu_set.daifmt		= SND_SOC_DAIFMT_CBS_CFS | SND_SOC_DAIFMT_IB_NF,
 };
 
 static struct asoc_simple_card_info fsi_da7210_info = {
diff --git a/arch/sh/boards/mach-se/7724/setup.c b/arch/sh/boards/mach-se/7724/setup.c
index 975608f..8bf853f 100644
--- a/arch/sh/boards/mach-se/7724/setup.c
+++ b/arch/sh/boards/mach-se/7724/setup.c
@@ -300,11 +300,10 @@ static struct platform_device fsi_device = {
 };
 
 static struct asoc_simple_dai_init_info fsi2_ak4642_init_info = {
-	.fmt		= SND_SOC_DAIFMT_LEFT_J,
-	.codec_daifmt	= SND_SOC_DAIFMT_CBM_CFM,
-	.cpu_daifmt	= SND_SOC_DAIFMT_CBS_CFS |
-			  SND_SOC_DAIFMT_IB_NF,
-	.sysclk		= 11289600,
+	.daifmt			= SND_SOC_DAIFMT_LEFT_J,
+	.cpu_set.daifmt		= SND_SOC_DAIFMT_CBS_CFS | SND_SOC_DAIFMT_IB_NF,
+	.codec_set.daifmt	= SND_SOC_DAIFMT_CBM_CFM,
+	.codec_set.sysclk	= 11289600,
 };
 
 static struct asoc_simple_card_info fsi_ak4642_info = {
diff --git a/include/sound/simple_card.h b/include/sound/simple_card.h
index 4b62b8d..f99b586 100644
--- a/include/sound/simple_card.h
+++ b/include/sound/simple_card.h
@@ -14,13 +14,17 @@
 
 #include <sound/soc.h>
 
-struct asoc_simple_dai_init_info {
-	unsigned int fmt;
-	unsigned int cpu_daifmt;
-	unsigned int codec_daifmt;
+struct asoc_simple_dai_set {
+	unsigned int daifmt;
 	unsigned int sysclk;
 };
 
+struct asoc_simple_dai_init_info {
+	unsigned int daifmt;
+	struct asoc_simple_dai_set cpu_set;
+	struct asoc_simple_dai_set codec_set;
+};
+
 struct asoc_simple_card_info {
 	const char *name;
 	const char *card;
diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c
index bc050ec..aba6290 100644
--- a/sound/soc/generic/simple-card.c
+++ b/sound/soc/generic/simple-card.c
@@ -16,33 +16,39 @@
 #define asoc_simple_get_card_info(p) \
 	container_of(p->dai_link, struct asoc_simple_card_info, snd_link)
 
+static int __asoc_simple_card_dai_init(struct snd_soc_dai *dai,
+				       struct asoc_simple_dai_set *set,
+				       unsigned int daifmt)
+{
+	int ret = 0;
+
+	daifmt |= set->daifmt;
+
+	if (!ret && daifmt)
+		ret = snd_soc_dai_set_fmt(dai, daifmt);
+
+	if (!ret && set->sysclk)
+		ret = snd_soc_dai_set_sysclk(dai, 0, set->sysclk, 0);
+
+	return ret;
+}
+
 static int asoc_simple_card_dai_init(struct snd_soc_pcm_runtime *rtd)
 {
 	struct asoc_simple_card_info *cinfo = asoc_simple_get_card_info(rtd);
-	struct asoc_simple_dai_init_info *iinfo = cinfo->init;
+	struct asoc_simple_dai_init_info *info = cinfo->init;
 	struct snd_soc_dai *codec = rtd->codec_dai;
 	struct snd_soc_dai *cpu = rtd->cpu_dai;
-	unsigned int cpu_daifmt = iinfo->fmt | iinfo->cpu_daifmt;
-	unsigned int codec_daifmt = iinfo->fmt | iinfo->codec_daifmt;
+	unsigned int daifmt = info->daifmt;
 	int ret;
 
-	if (codec_daifmt) {
-		ret = snd_soc_dai_set_fmt(codec, codec_daifmt);
-		if (ret < 0)
-			return ret;
-	}
+	ret = __asoc_simple_card_dai_init(codec, &info->codec_set, daifmt);
+	if (ret < 0)
+		return ret;
 
-	if (iinfo->sysclk) {
-		ret = snd_soc_dai_set_sysclk(codec, 0, iinfo->sysclk, 0);
-		if (ret < 0)
-			return ret;
-	}
-
-	if (cpu_daifmt) {
-		ret = snd_soc_dai_set_fmt(cpu, cpu_daifmt);
-		if (ret < 0)
-			return ret;
-	}
+	ret = __asoc_simple_card_dai_init(cpu, &info->cpu_set, daifmt);
+	if (ret < 0)
+		return ret;
 
 	return 0;
 }
-- 
1.7.9.5



More information about the Alsa-devel mailing list