[alsa-devel] [PATCH 1/4 v2] ASoC: sh: fsi: add fsi-common-codec card support

Kuninori Morimoto kuninori.morimoto.gx at renesas.com
Wed Apr 4 07:06:48 CEST 2012


Current Linux Kernel is using fsi-xxx card driver for SuperH sound card.
But the differences between these were only value/strings of setting.
In order to reduce duplicate driver, this patch adds fsi-common-codec.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx at renesas.com>
---
v1 -> v2

- fsi-codec -> fsi-common-codec
- add .fmt for CPU/CODEC common audio format

 include/sound/sh_fsi.h          |   25 +++++++++
 sound/soc/sh/Kconfig            |    4 ++
 sound/soc/sh/Makefile           |    2 +
 sound/soc/sh/fsi-common-codec.c |  107 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 138 insertions(+), 0 deletions(-)
 create mode 100644 sound/soc/sh/fsi-common-codec.c

diff --git a/include/sound/sh_fsi.h b/include/sound/sh_fsi.h
index b457e87..5f125b0 100644
--- a/include/sound/sh_fsi.h
+++ b/include/sound/sh_fsi.h
@@ -96,4 +96,29 @@ struct fsi_ak4642_info {
 	int id;
 };
 
+/*
+ * for fsi-common-codec
+ */
+#define fsi_link_to_info(p)	\
+	container_of(p, struct fsi_common_codec_info, snd_link)
+#define fsi_card_to_info(p)	\
+	container_of(p, struct fsi_common_codec_info, snd_card)
+
+struct fsi_common_codec_info {
+	const char *name;
+	const char *card;
+	const char *cpu_dai;
+	const char *codec;
+	const char *platform;
+	const char *codec_dai;
+	unsigned int fmt;
+	unsigned int cpu_daifmt;
+	unsigned int codec_daifmt;
+	unsigned int sysclk;
+
+	/* used in fsi-common-codec.c */
+	struct snd_soc_dai_link snd_link;
+	struct snd_soc_card snd_card;
+};
+
 #endif /* __SOUND_FSI_H */
diff --git a/sound/soc/sh/Kconfig b/sound/soc/sh/Kconfig
index d8e06a6..00d9e09 100644
--- a/sound/soc/sh/Kconfig
+++ b/sound/soc/sh/Kconfig
@@ -22,6 +22,7 @@ config SND_SOC_SH4_SSI
 
 config SND_SOC_SH4_FSI
 	tristate "SH4 FSI support"
+	select SND_FSI_COMMON_CODEC
 	help
 	  This option enables FSI sound support
 
@@ -46,6 +47,9 @@ config SND_SH7760_AC97
 	  This option enables generic sound support for the first
 	  AC97 unit of the SH7760.
 
+config SND_FSI_COMMON_CODEC
+	tristate
+
 config SND_FSI_AK4642
 	tristate "FSI-AK4642 sound support"
 	depends on SND_SOC_SH4_FSI && I2C
diff --git a/sound/soc/sh/Makefile b/sound/soc/sh/Makefile
index 94476d4..11e9a56 100644
--- a/sound/soc/sh/Makefile
+++ b/sound/soc/sh/Makefile
@@ -17,10 +17,12 @@ snd-soc-sh7760-ac97-objs	:= sh7760-ac97.o
 snd-soc-fsi-ak4642-objs		:= fsi-ak4642.o
 snd-soc-fsi-da7210-objs		:= fsi-da7210.o
 snd-soc-fsi-hdmi-objs		:= fsi-hdmi.o
+snd-soc-fsi-common-codec-objs	:= fsi-common-codec.o
 snd-soc-migor-objs		:= migor.o
 
 obj-$(CONFIG_SND_SH7760_AC97)	+= snd-soc-sh7760-ac97.o
 obj-$(CONFIG_SND_FSI_AK4642)	+= snd-soc-fsi-ak4642.o
 obj-$(CONFIG_SND_FSI_DA7210)	+= snd-soc-fsi-da7210.o
 obj-$(CONFIG_SND_FSI_HDMI)	+= snd-soc-fsi-hdmi.o
+obj-$(CONFIG_SND_FSI_COMMON_CODEC)	+= snd-soc-fsi-common-codec.o
 obj-$(CONFIG_SND_SIU_MIGOR)	+= snd-soc-migor.o
diff --git a/sound/soc/sh/fsi-common-codec.c b/sound/soc/sh/fsi-common-codec.c
new file mode 100644
index 0000000..81bbead
--- /dev/null
+++ b/sound/soc/sh/fsi-common-codec.c
@@ -0,0 +1,107 @@
+/*
+ * FSI common codec sound card support
+ *
+ * Copyright (C) 2012 Renesas Solutions Corp.
+ * Kuninori Morimoto <kuninori.morimoto.gx at renesas.com>
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ */
+
+#include <linux/platform_device.h>
+#include <linux/module.h>
+#include <sound/sh_fsi.h>
+
+static int fsi_common_codec_dai_init(struct snd_soc_pcm_runtime *rtd)
+{
+	struct fsi_common_codec_info *pinfo = fsi_link_to_info(rtd->dai_link);
+	struct snd_soc_dai *codec = rtd->codec_dai;
+	struct snd_soc_dai *cpu = rtd->cpu_dai;
+	unsigned int cpu_daifmt = pinfo->fmt | pinfo->cpu_daifmt;
+	unsigned int codec_daifmt = pinfo->fmt | pinfo->codec_daifmt;
+	int ret;
+
+	if (codec_daifmt) {
+		ret = snd_soc_dai_set_fmt(codec, codec_daifmt);
+		if (ret < 0)
+			return ret;
+	}
+
+	if (pinfo->sysclk) {
+		ret = snd_soc_dai_set_sysclk(codec, 0, pinfo->sysclk, 0);
+		if (ret < 0)
+			return ret;
+	}
+
+	if (cpu_daifmt) {
+		ret = snd_soc_dai_set_fmt(cpu, cpu_daifmt);
+		if (ret < 0)
+			return ret;
+	}
+
+	return 0;
+}
+
+static int fsi_common_codec_probe(struct platform_device *pdev)
+{
+	struct fsi_common_codec_info *pinfo = pdev->dev.platform_data;
+
+	if (!pinfo) {
+		dev_err(&pdev->dev, "no info for fsi-common-codec\n");
+		return -EINVAL;
+	}
+
+	if (!pinfo->name	||
+	    !pinfo->card	||
+	    !pinfo->cpu_dai	||
+	    !pinfo->codec	||
+	    !pinfo->platform	||
+	    !pinfo->codec_dai) {
+		dev_err(&pdev->dev, "insufficient fsi_common_codec_info settings\n");
+		return -EINVAL;
+	}
+
+	/*
+	 * init snd_soc_dai_link
+	 */
+	pinfo->snd_link.name		= pinfo->name;
+	pinfo->snd_link.stream_name	= pinfo->name;
+	pinfo->snd_link.cpu_dai_name	= pinfo->cpu_dai;
+	pinfo->snd_link.platform_name	= pinfo->platform;
+	pinfo->snd_link.codec_name	= pinfo->codec;
+	pinfo->snd_link.codec_dai_name	= pinfo->codec_dai;
+	pinfo->snd_link.init		= fsi_common_codec_dai_init;
+
+	/*
+	 * init snd_soc_card
+	 */
+	pinfo->snd_card.name		= pinfo->card;
+	pinfo->snd_card.owner		= THIS_MODULE;
+	pinfo->snd_card.dai_link	= &pinfo->snd_link;
+	pinfo->snd_card.num_links	= 1;
+	pinfo->snd_card.dev		= &pdev->dev;
+
+	return snd_soc_register_card(&pinfo->snd_card);
+}
+
+static int fsi_common_codec_remove(struct platform_device *pdev)
+{
+	struct fsi_common_codec_info *pinfo = pdev->dev.platform_data;
+
+	return snd_soc_unregister_card(&pinfo->snd_card);
+}
+
+static struct platform_driver fsi_common_codec = {
+	.driver = {
+		.name	= "fsi-common-codec-audio",
+	},
+	.probe		= fsi_common_codec_probe,
+	.remove		= fsi_common_codec_remove,
+};
+
+module_platform_driver(fsi_common_codec);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("SuperH FSI common codec sound card");
+MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx at renesas.com>");
-- 
1.7.5.4



More information about the Alsa-devel mailing list