GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / sound / soc / sh / migor.c
blob87e2b7fcbf176d9f429506b285dcc2f6ac05d7bc
1 /*
2 * ALSA SoC driver for Migo-R
4 * Copyright (C) 2009-2010 Guennadi Liakhovetski <g.liakhovetski@gmx.de>
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 */
11 #include <linux/device.h>
12 #include <linux/firmware.h>
13 #include <linux/module.h>
15 #include <asm/clkdev.h>
16 #include <asm/clock.h>
18 #include <cpu/sh7722.h>
20 #include <sound/core.h>
21 #include <sound/pcm.h>
22 #include <sound/soc.h>
23 #include <sound/soc-dapm.h>
25 #include "../codecs/wm8978.h"
26 #include "siu.h"
28 /* Default 8000Hz sampling frequency */
29 static unsigned long codec_freq = 8000 * 512;
31 static unsigned int use_count;
33 /* External clock, sourced from the codec at the SIUMCKB pin */
34 static unsigned long siumckb_recalc(struct clk *clk)
36 return codec_freq;
39 static struct clk_ops siumckb_clk_ops = {
40 .recalc = siumckb_recalc,
43 static struct clk siumckb_clk = {
44 .ops = &siumckb_clk_ops,
45 .rate = 0, /* initialised at run-time */
48 static struct clk_lookup *siumckb_lookup;
50 static int migor_hw_params(struct snd_pcm_substream *substream,
51 struct snd_pcm_hw_params *params)
53 struct snd_soc_pcm_runtime *rtd = substream->private_data;
54 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
55 int ret;
56 unsigned int rate = params_rate(params);
58 ret = snd_soc_dai_set_sysclk(codec_dai, WM8978_PLL, 13000000,
59 SND_SOC_CLOCK_IN);
60 if (ret < 0)
61 return ret;
63 ret = snd_soc_dai_set_clkdiv(codec_dai, WM8978_OPCLKRATE, rate * 512);
64 if (ret < 0)
65 return ret;
67 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_NB_IF |
68 SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS);
69 if (ret < 0)
70 return ret;
72 ret = snd_soc_dai_set_fmt(rtd->dai->cpu_dai, SND_SOC_DAIFMT_NB_IF |
73 SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS);
74 if (ret < 0)
75 return ret;
77 codec_freq = rate * 512;
79 * This propagates the parent frequency change to children and
80 * recalculates the frequency table
82 clk_set_rate(&siumckb_clk, codec_freq);
83 dev_dbg(codec_dai->dev, "%s: configure %luHz\n", __func__, codec_freq);
85 ret = snd_soc_dai_set_sysclk(rtd->dai->cpu_dai, SIU_CLKB_EXT,
86 codec_freq / 2, SND_SOC_CLOCK_IN);
88 if (!ret)
89 use_count++;
91 return ret;
94 static int migor_hw_free(struct snd_pcm_substream *substream)
96 struct snd_soc_pcm_runtime *rtd = substream->private_data;
97 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
99 if (use_count) {
100 use_count--;
102 if (!use_count)
103 snd_soc_dai_set_sysclk(codec_dai, WM8978_PLL, 0,
104 SND_SOC_CLOCK_IN);
105 } else {
106 dev_dbg(codec_dai->dev, "Unbalanced hw_free!\n");
109 return 0;
112 static struct snd_soc_ops migor_dai_ops = {
113 .hw_params = migor_hw_params,
114 .hw_free = migor_hw_free,
117 static const struct snd_soc_dapm_widget migor_dapm_widgets[] = {
118 SND_SOC_DAPM_HP("Headphone", NULL),
119 SND_SOC_DAPM_MIC("Onboard Microphone", NULL),
120 SND_SOC_DAPM_MIC("External Microphone", NULL),
123 static const struct snd_soc_dapm_route audio_map[] = {
124 /* Headphone output connected to LHP/RHP, enable OUT4 for VMID */
125 { "Headphone", NULL, "OUT4 VMID" },
126 { "OUT4 VMID", NULL, "LHP" },
127 { "OUT4 VMID", NULL, "RHP" },
129 /* On-board microphone */
130 { "RMICN", NULL, "Mic Bias" },
131 { "RMICP", NULL, "Mic Bias" },
132 { "Mic Bias", NULL, "Onboard Microphone" },
134 /* External microphone */
135 { "LMICN", NULL, "Mic Bias" },
136 { "LMICP", NULL, "Mic Bias" },
137 { "Mic Bias", NULL, "External Microphone" },
140 static int migor_dai_init(struct snd_soc_codec *codec)
142 snd_soc_dapm_new_controls(codec, migor_dapm_widgets,
143 ARRAY_SIZE(migor_dapm_widgets));
145 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
147 return 0;
150 /* migor digital audio interface glue - connects codec <--> CPU */
151 static struct snd_soc_dai_link migor_dai = {
152 .name = "wm8978",
153 .stream_name = "WM8978",
154 .cpu_dai = &siu_i2s_dai,
155 .codec_dai = &wm8978_dai,
156 .ops = &migor_dai_ops,
157 .init = migor_dai_init,
160 /* migor audio machine driver */
161 static struct snd_soc_card snd_soc_migor = {
162 .name = "Migo-R",
163 .platform = &siu_platform,
164 .dai_link = &migor_dai,
165 .num_links = 1,
168 /* migor audio subsystem */
169 static struct snd_soc_device migor_snd_devdata = {
170 .card = &snd_soc_migor,
171 .codec_dev = &soc_codec_dev_wm8978,
174 static struct platform_device *migor_snd_device;
176 static int __init migor_init(void)
178 int ret;
180 ret = clk_register(&siumckb_clk);
181 if (ret < 0)
182 return ret;
184 siumckb_lookup = clkdev_alloc(&siumckb_clk, "siumckb_clk", NULL);
185 if (!siumckb_lookup) {
186 ret = -ENOMEM;
187 goto eclkdevalloc;
189 clkdev_add(siumckb_lookup);
191 /* Port number used on this machine: port B */
192 migor_snd_device = platform_device_alloc("soc-audio", 1);
193 if (!migor_snd_device) {
194 ret = -ENOMEM;
195 goto epdevalloc;
198 platform_set_drvdata(migor_snd_device, &migor_snd_devdata);
200 migor_snd_devdata.dev = &migor_snd_device->dev;
202 ret = platform_device_add(migor_snd_device);
203 if (ret)
204 goto epdevadd;
206 return 0;
208 epdevadd:
209 platform_device_put(migor_snd_device);
210 epdevalloc:
211 clkdev_drop(siumckb_lookup);
212 eclkdevalloc:
213 clk_unregister(&siumckb_clk);
214 return ret;
217 static void __exit migor_exit(void)
219 clkdev_drop(siumckb_lookup);
220 clk_unregister(&siumckb_clk);
221 platform_device_unregister(migor_snd_device);
224 module_init(migor_init);
225 module_exit(migor_exit);
227 MODULE_AUTHOR("Guennadi Liakhovetski <g.liakhovetski@gmx.de>");
228 MODULE_DESCRIPTION("ALSA SoC Migor");
229 MODULE_LICENSE("GPL v2");