aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/generic
diff options
context:
space:
mode:
authorKuninori Morimoto <kuninori.morimoto.gx@renesas.com>2012-04-09 00:17:50 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2012-04-13 06:29:25 -0400
commitf2390880ec0264a0ed26b32c23bc23435b4297da (patch)
treecf81cd48dfefb40a054765594439adfd2a273cb1 /sound/soc/generic
parentcdc04fd1e982e91936cbcf3dec59a576517d67a1 (diff)
ASoC: add generic simple-card support
Current ASoC requires card.c file to each platforms in order to specifies its CPU and Codecs pair. But the differences between these were only value/strings of setting. In order to reduce duplicate driver, this patch adds generic/simple-card. Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc/generic')
-rw-r--r--sound/soc/generic/Kconfig4
-rw-r--r--sound/soc/generic/Makefile3
-rw-r--r--sound/soc/generic/simple-card.c114
3 files changed, 121 insertions, 0 deletions
diff --git a/sound/soc/generic/Kconfig b/sound/soc/generic/Kconfig
new file mode 100644
index 000000000000..610f61251640
--- /dev/null
+++ b/sound/soc/generic/Kconfig
@@ -0,0 +1,4 @@
1config SND_SIMPLE_CARD
2 tristate "ASoC Simple sound card support"
3 help
4 This option enables generic simple sound card support
diff --git a/sound/soc/generic/Makefile b/sound/soc/generic/Makefile
new file mode 100644
index 000000000000..9c3b246792bf
--- /dev/null
+++ b/sound/soc/generic/Makefile
@@ -0,0 +1,3 @@
1snd-soc-simple-card-objs := simple-card.o
2
3obj-$(CONFIG_SND_SIMPLE_CARD) += snd-soc-simple-card.o
diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c
new file mode 100644
index 000000000000..b4b4cab30232
--- /dev/null
+++ b/sound/soc/generic/simple-card.c
@@ -0,0 +1,114 @@
1/*
2 * ASoC simple sound card support
3 *
4 * Copyright (C) 2012 Renesas Solutions Corp.
5 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/platform_device.h>
13#include <linux/module.h>
14#include <sound/simple_card.h>
15
16#define asoc_simple_get_card_info(p) \
17 container_of(p->dai_link, struct asoc_simple_card_info, snd_link)
18
19static int asoc_simple_card_dai_init(struct snd_soc_pcm_runtime *rtd)
20{
21 struct asoc_simple_card_info *cinfo = asoc_simple_get_card_info(rtd);
22 struct asoc_simple_dai_init_info *iinfo = cinfo->init;
23 struct snd_soc_dai *codec = rtd->codec_dai;
24 struct snd_soc_dai *cpu = rtd->cpu_dai;
25 unsigned int cpu_daifmt = iinfo->fmt | iinfo->cpu_daifmt;
26 unsigned int codec_daifmt = iinfo->fmt | iinfo->codec_daifmt;
27 int ret;
28
29 if (codec_daifmt) {
30 ret = snd_soc_dai_set_fmt(codec, codec_daifmt);
31 if (ret < 0)
32 return ret;
33 }
34
35 if (iinfo->sysclk) {
36 ret = snd_soc_dai_set_sysclk(codec, 0, iinfo->sysclk, 0);
37 if (ret < 0)
38 return ret;
39 }
40
41 if (cpu_daifmt) {
42 ret = snd_soc_dai_set_fmt(cpu, cpu_daifmt);
43 if (ret < 0)
44 return ret;
45 }
46
47 return 0;
48}
49
50static int asoc_simple_card_probe(struct platform_device *pdev)
51{
52 struct asoc_simple_card_info *cinfo = pdev->dev.platform_data;
53
54 if (!cinfo) {
55 dev_err(&pdev->dev, "no info for asoc-simple-card\n");
56 return -EINVAL;
57 }
58
59 if (!cinfo->name ||
60 !cinfo->card ||
61 !cinfo->cpu_dai ||
62 !cinfo->codec ||
63 !cinfo->platform ||
64 !cinfo->codec_dai) {
65 dev_err(&pdev->dev, "insufficient asoc_simple_card_info settings\n");
66 return -EINVAL;
67 }
68
69 /*
70 * init snd_soc_dai_link
71 */
72 cinfo->snd_link.name = cinfo->name;
73 cinfo->snd_link.stream_name = cinfo->name;
74 cinfo->snd_link.cpu_dai_name = cinfo->cpu_dai;
75 cinfo->snd_link.platform_name = cinfo->platform;
76 cinfo->snd_link.codec_name = cinfo->codec;
77 cinfo->snd_link.codec_dai_name = cinfo->codec_dai;
78
79 /* enable snd_link.init if cinfo has settings */
80 if (cinfo->init)
81 cinfo->snd_link.init = asoc_simple_card_dai_init;
82
83 /*
84 * init snd_soc_card
85 */
86 cinfo->snd_card.name = cinfo->card;
87 cinfo->snd_card.owner = THIS_MODULE;
88 cinfo->snd_card.dai_link = &cinfo->snd_link;
89 cinfo->snd_card.num_links = 1;
90 cinfo->snd_card.dev = &pdev->dev;
91
92 return snd_soc_register_card(&cinfo->snd_card);
93}
94
95static int asoc_simple_card_remove(struct platform_device *pdev)
96{
97 struct asoc_simple_card_info *cinfo = pdev->dev.platform_data;
98
99 return snd_soc_unregister_card(&cinfo->snd_card);
100}
101
102static struct platform_driver asoc_simple_card = {
103 .driver = {
104 .name = "asoc-simple-card",
105 },
106 .probe = asoc_simple_card_probe,
107 .remove = asoc_simple_card_remove,
108};
109
110module_platform_driver(asoc_simple_card);
111
112MODULE_LICENSE("GPL");
113MODULE_DESCRIPTION("ASoC Simple Sound Card");
114MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>");