aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sound/soc/sh/Kconfig8
-rw-r--r--sound/soc/sh/Makefile2
-rw-r--r--sound/soc/sh/migor.c222
3 files changed, 232 insertions, 0 deletions
diff --git a/sound/soc/sh/Kconfig b/sound/soc/sh/Kconfig
index 3f1cd550334..a86696bbe17 100644
--- a/sound/soc/sh/Kconfig
+++ b/sound/soc/sh/Kconfig
@@ -61,4 +61,12 @@ config SND_FSI_DA7210
61 This option enables generic sound support for the 61 This option enables generic sound support for the
62 FSI - DA7210 unit 62 FSI - DA7210 unit
63 63
64config SND_SIU_MIGOR
65 tristate "SIU sound support on Migo-R"
66 depends on SH_MIGOR
67 select SND_SOC_SH4_SIU
68 select SND_SOC_WM8978
69 help
70 This option enables sound support for the SH7722 Migo-R board
71
64endmenu 72endmenu
diff --git a/sound/soc/sh/Makefile b/sound/soc/sh/Makefile
index 5a97d2539d8..8a5a19293bd 100644
--- a/sound/soc/sh/Makefile
+++ b/sound/soc/sh/Makefile
@@ -16,7 +16,9 @@ obj-$(CONFIG_SND_SOC_SH4_SIU) += snd-soc-siu.o
16snd-soc-sh7760-ac97-objs := sh7760-ac97.o 16snd-soc-sh7760-ac97-objs := sh7760-ac97.o
17snd-soc-fsi-ak4642-objs := fsi-ak4642.o 17snd-soc-fsi-ak4642-objs := fsi-ak4642.o
18snd-soc-fsi-da7210-objs := fsi-da7210.o 18snd-soc-fsi-da7210-objs := fsi-da7210.o
19snd-soc-migor-objs := migor.o
19 20
20obj-$(CONFIG_SND_SH7760_AC97) += snd-soc-sh7760-ac97.o 21obj-$(CONFIG_SND_SH7760_AC97) += snd-soc-sh7760-ac97.o
21obj-$(CONFIG_SND_FSI_AK4642) += snd-soc-fsi-ak4642.o 22obj-$(CONFIG_SND_FSI_AK4642) += snd-soc-fsi-ak4642.o
22obj-$(CONFIG_SND_FSI_DA7210) += snd-soc-fsi-da7210.o 23obj-$(CONFIG_SND_FSI_DA7210) += snd-soc-fsi-da7210.o
24obj-$(CONFIG_SND_SIU_MIGOR) += snd-soc-migor.o
diff --git a/sound/soc/sh/migor.c b/sound/soc/sh/migor.c
new file mode 100644
index 00000000000..3ccd9b39331
--- /dev/null
+++ b/sound/soc/sh/migor.c
@@ -0,0 +1,222 @@
1/*
2 * ALSA SoC driver for Migo-R
3 *
4 * Copyright (C) 2009-2010 Guennadi Liakhovetski <g.liakhovetski@gmx.de>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#include <linux/device.h>
12#include <linux/firmware.h>
13#include <linux/module.h>
14
15#include <asm/clock.h>
16
17#include <cpu/sh7722.h>
18
19#include <sound/core.h>
20#include <sound/pcm.h>
21#include <sound/soc.h>
22#include <sound/soc-dapm.h>
23
24#include "../codecs/wm8978.h"
25#include "siu.h"
26
27/* Default 8000Hz sampling frequency */
28static unsigned long codec_freq = 8000 * 512;
29
30static unsigned int use_count;
31
32/* External clock, sourced from the codec at the SIUMCKB pin */
33static unsigned long siumckb_recalc(struct clk *clk)
34{
35 return codec_freq;
36}
37
38static struct clk_ops siumckb_clk_ops = {
39 .recalc = siumckb_recalc,
40};
41
42static struct clk siumckb_clk = {
43 .name = "siumckb_clk",
44 .id = -1,
45 .ops = &siumckb_clk_ops,
46 .rate = 0, /* initialised at run-time */
47};
48
49static int migor_hw_params(struct snd_pcm_substream *substream,
50 struct snd_pcm_hw_params *params)
51{
52 struct snd_soc_pcm_runtime *rtd = substream->private_data;
53 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
54 int ret;
55 unsigned int rate = params_rate(params);
56
57 ret = snd_soc_dai_set_sysclk(codec_dai, WM8978_PLL, 13000000,
58 SND_SOC_CLOCK_IN);
59 if (ret < 0)
60 return ret;
61
62 ret = snd_soc_dai_set_clkdiv(codec_dai, WM8978_DACCLK, 8);
63 if (ret < 0)
64 return ret;
65
66 ret = snd_soc_dai_set_clkdiv(codec_dai, WM8978_OPCLKRATE, rate * 512);
67 if (ret < 0)
68 return ret;
69
70 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_NB_IF |
71 SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS);
72 if (ret < 0)
73 return ret;
74
75 ret = snd_soc_dai_set_fmt(rtd->dai->cpu_dai, SND_SOC_DAIFMT_NB_IF |
76 SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS);
77 if (ret < 0)
78 return ret;
79
80 codec_freq = rate * 512;
81 /*
82 * This propagates the parent frequency change to children and
83 * recalculates the frequency table
84 */
85 clk_set_rate(&siumckb_clk, codec_freq);
86 dev_dbg(codec_dai->dev, "%s: configure %luHz\n", __func__, codec_freq);
87
88 ret = snd_soc_dai_set_sysclk(rtd->dai->cpu_dai, SIU_CLKB_EXT,
89 codec_freq / 2, SND_SOC_CLOCK_IN);
90
91 if (!ret)
92 use_count++;
93
94 return ret;
95}
96
97static int migor_hw_free(struct snd_pcm_substream *substream)
98{
99 struct snd_soc_pcm_runtime *rtd = substream->private_data;
100 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
101
102 if (use_count) {
103 use_count--;
104
105 if (!use_count)
106 snd_soc_dai_set_sysclk(codec_dai, WM8978_PLL, 0,
107 SND_SOC_CLOCK_IN);
108 } else {
109 dev_dbg(codec_dai->dev, "Unbalanced hw_free!\n");
110 }
111
112 return 0;
113}
114
115static struct snd_soc_ops migor_dai_ops = {
116 .hw_params = migor_hw_params,
117 .hw_free = migor_hw_free,
118};
119
120static const struct snd_soc_dapm_widget migor_dapm_widgets[] = {
121 SND_SOC_DAPM_HP("Headphone", NULL),
122 SND_SOC_DAPM_MIC("Onboard Microphone", NULL),
123 SND_SOC_DAPM_MIC("External Microphone", NULL),
124};
125
126static const struct snd_soc_dapm_route audio_map[] = {
127 /* Headphone output connected to LHP/RHP, enable OUT4 for VMID */
128 { "Headphone", NULL, "OUT4 VMID" },
129 { "OUT4 VMID", NULL, "LHP" },
130 { "OUT4 VMID", NULL, "RHP" },
131
132 /* On-board microphone */
133 { "RMICN", NULL, "Mic Bias" },
134 { "RMICP", NULL, "Mic Bias" },
135 { "Mic Bias", NULL, "Onboard Microphone" },
136
137 /* External microphone */
138 { "LMICN", NULL, "Mic Bias" },
139 { "LMICP", NULL, "Mic Bias" },
140 { "Mic Bias", NULL, "External Microphone" },
141};
142
143static int migor_dai_init(struct snd_soc_codec *codec)
144{
145 snd_soc_dapm_new_controls(codec, migor_dapm_widgets,
146 ARRAY_SIZE(migor_dapm_widgets));
147
148 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
149
150 return 0;
151}
152
153/* migor digital audio interface glue - connects codec <--> CPU */
154static struct snd_soc_dai_link migor_dai = {
155 .name = "wm8978",
156 .stream_name = "WM8978",
157 .cpu_dai = &siu_i2s_dai,
158 .codec_dai = &wm8978_dai,
159 .ops = &migor_dai_ops,
160 .init = migor_dai_init,
161};
162
163/* migor audio machine driver */
164static struct snd_soc_card snd_soc_migor = {
165 .name = "Migo-R",
166 .platform = &siu_platform,
167 .dai_link = &migor_dai,
168 .num_links = 1,
169};
170
171/* migor audio subsystem */
172static struct snd_soc_device migor_snd_devdata = {
173 .card = &snd_soc_migor,
174 .codec_dev = &soc_codec_dev_wm8978,
175};
176
177static struct platform_device *migor_snd_device;
178
179static int __init migor_init(void)
180{
181 int ret;
182
183 ret = clk_register(&siumckb_clk);
184 if (ret < 0)
185 return ret;
186
187 /* Port number used on this machine: port B */
188 migor_snd_device = platform_device_alloc("soc-audio", 1);
189 if (!migor_snd_device) {
190 ret = -ENOMEM;
191 goto epdevalloc;
192 }
193
194 platform_set_drvdata(migor_snd_device, &migor_snd_devdata);
195
196 migor_snd_devdata.dev = &migor_snd_device->dev;
197
198 ret = platform_device_add(migor_snd_device);
199 if (ret)
200 goto epdevadd;
201
202 return 0;
203
204epdevadd:
205 platform_device_put(migor_snd_device);
206epdevalloc:
207 clk_unregister(&siumckb_clk);
208 return ret;
209}
210
211static void __exit migor_exit(void)
212{
213 clk_unregister(&siumckb_clk);
214 platform_device_unregister(migor_snd_device);
215}
216
217module_init(migor_init);
218module_exit(migor_exit);
219
220MODULE_AUTHOR("Guennadi Liakhovetski <g.liakhovetski@gmx.de>");
221MODULE_DESCRIPTION("ALSA SoC Migor");
222MODULE_LICENSE("GPL v2");