Merge branch 'trivial' of git://git.kernel.org/pub/scm/linux/kernel/git/mmarek/kbuild
[deliverable/linux.git] / sound / soc / omap / omap3pandora.c
CommitLineData
68fb7407
GI
1/*
2 * omap3pandora.c -- SoC audio for Pandora Handheld Console
3 *
4 * Author: GraÅžvydas Ignotas <notasas@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18 * 02110-1301 USA
19 *
20 */
21
22#include <linux/clk.h>
23#include <linux/platform_device.h>
24#include <linux/gpio.h>
25#include <linux/delay.h>
c50749de 26#include <linux/regulator/consumer.h>
68fb7407
GI
27
28#include <sound/core.h>
29#include <sound/pcm.h>
30#include <sound/soc.h>
68fb7407
GI
31
32#include <asm/mach-types.h>
f0fba2ad 33#include <plat/mcbsp.h>
68fb7407
GI
34
35#include "omap-mcbsp.h"
36#include "omap-pcm.h"
68fb7407
GI
37
38#define OMAP3_PANDORA_DAC_POWER_GPIO 118
39#define OMAP3_PANDORA_AMP_POWER_GPIO 14
40
41#define PREFIX "ASoC omap3pandora: "
42
c50749de
GI
43static struct regulator *omap3pandora_dac_reg;
44
4b94dba0
GI
45static int omap3pandora_hw_params(struct snd_pcm_substream *substream,
46 struct snd_pcm_hw_params *params)
68fb7407 47{
9e5d86fe 48 struct snd_soc_pcm_runtime *rtd = substream->private_data;
f0fba2ad
LG
49 struct snd_soc_dai *codec_dai = rtd->codec_dai;
50 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
68fb7407
GI
51 int ret;
52
68fb7407
GI
53 /* Set the codec system clock for DAC and ADC */
54 ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
55 SND_SOC_CLOCK_IN);
56 if (ret < 0) {
57 pr_err(PREFIX "can't set codec system clock\n");
58 return ret;
59 }
60
61 /* Set McBSP clock to external */
9e5d86fe
JN
62 ret = snd_soc_dai_set_sysclk(cpu_dai, OMAP_MCBSP_SYSCLK_CLKS_EXT,
63 256 * params_rate(params),
64 SND_SOC_CLOCK_IN);
68fb7407
GI
65 if (ret < 0) {
66 pr_err(PREFIX "can't set cpu system clock\n");
67 return ret;
68 }
69
70 ret = snd_soc_dai_set_clkdiv(cpu_dai, OMAP_MCBSP_CLKGDV, 8);
71 if (ret < 0) {
72 pr_err(PREFIX "can't set SRG clock divider\n");
73 return ret;
74 }
75
76 return 0;
77}
78
c50749de 79static int omap3pandora_dac_event(struct snd_soc_dapm_widget *w,
68fb7407
GI
80 struct snd_kcontrol *k, int event)
81{
c50749de
GI
82 /*
83 * The PCM1773 DAC datasheet requires 1ms delay between switching
84 * VCC power on/off and /PD pin high/low
85 */
68fb7407 86 if (SND_SOC_DAPM_EVENT_ON(event)) {
c50749de
GI
87 regulator_enable(omap3pandora_dac_reg);
88 mdelay(1);
68fb7407 89 gpio_set_value(OMAP3_PANDORA_DAC_POWER_GPIO, 1);
68fb7407 90 } else {
68fb7407 91 gpio_set_value(OMAP3_PANDORA_DAC_POWER_GPIO, 0);
c50749de
GI
92 mdelay(1);
93 regulator_disable(omap3pandora_dac_reg);
68fb7407
GI
94 }
95
96 return 0;
97}
98
c50749de
GI
99static int omap3pandora_hp_event(struct snd_soc_dapm_widget *w,
100 struct snd_kcontrol *k, int event)
101{
102 if (SND_SOC_DAPM_EVENT_ON(event))
103 gpio_set_value(OMAP3_PANDORA_AMP_POWER_GPIO, 1);
104 else
105 gpio_set_value(OMAP3_PANDORA_AMP_POWER_GPIO, 0);
106
107 return 0;
108}
109
68fb7407
GI
110/*
111 * Audio paths on Pandora board:
112 *
113 * |O| ---> PCM DAC +-> AMP -> Headphone Jack
114 * |M| A +--------> Line Out
115 * |A| <~~clk~~+
116 * |P| <--- TWL4030 <--------- Line In and MICs
117 */
118static const struct snd_soc_dapm_widget omap3pandora_out_dapm_widgets[] = {
c50749de
GI
119 SND_SOC_DAPM_DAC_E("PCM DAC", "HiFi Playback", SND_SOC_NOPM,
120 0, 0, omap3pandora_dac_event,
121 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
68fb7407
GI
122 SND_SOC_DAPM_PGA_E("Headphone Amplifier", SND_SOC_NOPM,
123 0, 0, NULL, 0, omap3pandora_hp_event,
124 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
125 SND_SOC_DAPM_HP("Headphone Jack", NULL),
126 SND_SOC_DAPM_LINE("Line Out", NULL),
127};
128
129static const struct snd_soc_dapm_widget omap3pandora_in_dapm_widgets[] = {
8f008062 130 SND_SOC_DAPM_MIC("Mic (internal)", NULL),
68fb7407
GI
131 SND_SOC_DAPM_MIC("Mic (external)", NULL),
132 SND_SOC_DAPM_LINE("Line In", NULL),
133};
134
135static const struct snd_soc_dapm_route omap3pandora_out_map[] = {
3b9447fb 136 {"PCM DAC", NULL, "APLL Enable"},
68fb7407
GI
137 {"Headphone Amplifier", NULL, "PCM DAC"},
138 {"Line Out", NULL, "PCM DAC"},
139 {"Headphone Jack", NULL, "Headphone Amplifier"},
140};
141
142static const struct snd_soc_dapm_route omap3pandora_in_map[] = {
8f008062
GI
143 {"AUXL", NULL, "Line In"},
144 {"AUXR", NULL, "Line In"},
145
146 {"MAINMIC", NULL, "Mic Bias 1"},
147 {"Mic Bias 1", NULL, "Mic (internal)"},
148
149 {"SUBMIC", NULL, "Mic Bias 2"},
150 {"Mic Bias 2", NULL, "Mic (external)"},
68fb7407
GI
151};
152
f0fba2ad 153static int omap3pandora_out_init(struct snd_soc_pcm_runtime *rtd)
68fb7407 154{
f0fba2ad 155 struct snd_soc_codec *codec = rtd->codec;
ce6120cc 156 struct snd_soc_dapm_context *dapm = &codec->dapm;
68fb7407
GI
157 int ret;
158
8f008062 159 /* All TWL4030 output pins are floating */
ce6120cc
LG
160 snd_soc_dapm_nc_pin(dapm, "EARPIECE");
161 snd_soc_dapm_nc_pin(dapm, "PREDRIVEL");
162 snd_soc_dapm_nc_pin(dapm, "PREDRIVER");
163 snd_soc_dapm_nc_pin(dapm, "HSOL");
164 snd_soc_dapm_nc_pin(dapm, "HSOR");
165 snd_soc_dapm_nc_pin(dapm, "CARKITL");
166 snd_soc_dapm_nc_pin(dapm, "CARKITR");
167 snd_soc_dapm_nc_pin(dapm, "HFL");
168 snd_soc_dapm_nc_pin(dapm, "HFR");
169 snd_soc_dapm_nc_pin(dapm, "VIBRA");
170
171 ret = snd_soc_dapm_new_controls(dapm, omap3pandora_out_dapm_widgets,
68fb7407
GI
172 ARRAY_SIZE(omap3pandora_out_dapm_widgets));
173 if (ret < 0)
174 return ret;
175
cb424877 176 return snd_soc_dapm_add_routes(dapm, omap3pandora_out_map,
68fb7407 177 ARRAY_SIZE(omap3pandora_out_map));
68fb7407
GI
178}
179
f0fba2ad 180static int omap3pandora_in_init(struct snd_soc_pcm_runtime *rtd)
68fb7407 181{
f0fba2ad 182 struct snd_soc_codec *codec = rtd->codec;
ce6120cc 183 struct snd_soc_dapm_context *dapm = &codec->dapm;
68fb7407
GI
184 int ret;
185
8f008062 186 /* Not comnnected */
ce6120cc
LG
187 snd_soc_dapm_nc_pin(dapm, "HSMIC");
188 snd_soc_dapm_nc_pin(dapm, "CARKITMIC");
189 snd_soc_dapm_nc_pin(dapm, "DIGIMIC0");
190 snd_soc_dapm_nc_pin(dapm, "DIGIMIC1");
7f185340 191
ce6120cc 192 ret = snd_soc_dapm_new_controls(dapm, omap3pandora_in_dapm_widgets,
68fb7407
GI
193 ARRAY_SIZE(omap3pandora_in_dapm_widgets));
194 if (ret < 0)
195 return ret;
196
cb424877 197 return snd_soc_dapm_add_routes(dapm, omap3pandora_in_map,
68fb7407 198 ARRAY_SIZE(omap3pandora_in_map));
68fb7407
GI
199}
200
4b94dba0
GI
201static struct snd_soc_ops omap3pandora_ops = {
202 .hw_params = omap3pandora_hw_params,
68fb7407
GI
203};
204
205/* Digital audio interface glue - connects codec <--> CPU */
206static struct snd_soc_dai_link omap3pandora_dai[] = {
207 {
208 .name = "PCM1773",
209 .stream_name = "HiFi Out",
f0fba2ad
LG
210 .cpu_dai_name = "omap-mcbsp-dai.1",
211 .codec_dai_name = "twl4030-hifi",
212 .platform_name = "omap-pcm-audio",
213 .codec_name = "twl4030-codec",
cf9feff2
JN
214 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
215 SND_SOC_DAIFMT_CBS_CFS,
4b94dba0 216 .ops = &omap3pandora_ops,
68fb7407
GI
217 .init = omap3pandora_out_init,
218 }, {
219 .name = "TWL4030",
220 .stream_name = "Line/Mic In",
f0fba2ad
LG
221 .cpu_dai_name = "omap-mcbsp-dai.3",
222 .codec_dai_name = "twl4030-hifi",
223 .platform_name = "omap-pcm-audio",
224 .codec_name = "twl4030-codec",
cf9feff2
JN
225 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
226 SND_SOC_DAIFMT_CBS_CFS,
4b94dba0 227 .ops = &omap3pandora_ops,
68fb7407
GI
228 .init = omap3pandora_in_init,
229 }
230};
231
232/* SoC card */
233static struct snd_soc_card snd_soc_card_omap3pandora = {
234 .name = "omap3pandora",
68fb7407
GI
235 .dai_link = omap3pandora_dai,
236 .num_links = ARRAY_SIZE(omap3pandora_dai),
237};
238
68fb7407
GI
239static struct platform_device *omap3pandora_snd_device;
240
241static int __init omap3pandora_soc_init(void)
242{
243 int ret;
244
8f008062 245 if (!machine_is_omap3_pandora())
68fb7407 246 return -ENODEV;
8f008062 247
68fb7407
GI
248 pr_info("OMAP3 Pandora SoC init\n");
249
250 ret = gpio_request(OMAP3_PANDORA_DAC_POWER_GPIO, "dac_power");
251 if (ret) {
252 pr_err(PREFIX "Failed to get DAC power GPIO\n");
253 return ret;
254 }
255
256 ret = gpio_direction_output(OMAP3_PANDORA_DAC_POWER_GPIO, 0);
257 if (ret) {
258 pr_err(PREFIX "Failed to set DAC power GPIO direction\n");
259 goto fail0;
260 }
261
262 ret = gpio_request(OMAP3_PANDORA_AMP_POWER_GPIO, "amp_power");
263 if (ret) {
264 pr_err(PREFIX "Failed to get amp power GPIO\n");
265 goto fail0;
266 }
267
268 ret = gpio_direction_output(OMAP3_PANDORA_AMP_POWER_GPIO, 0);
269 if (ret) {
270 pr_err(PREFIX "Failed to set amp power GPIO direction\n");
271 goto fail1;
272 }
273
274 omap3pandora_snd_device = platform_device_alloc("soc-audio", -1);
275 if (omap3pandora_snd_device == NULL) {
276 pr_err(PREFIX "Platform device allocation failed\n");
277 ret = -ENOMEM;
278 goto fail1;
279 }
280
f0fba2ad 281 platform_set_drvdata(omap3pandora_snd_device, &snd_soc_card_omap3pandora);
68fb7407
GI
282
283 ret = platform_device_add(omap3pandora_snd_device);
284 if (ret) {
285 pr_err(PREFIX "Unable to add platform device\n");
286 goto fail2;
287 }
288
c50749de
GI
289 omap3pandora_dac_reg = regulator_get(&omap3pandora_snd_device->dev, "vcc");
290 if (IS_ERR(omap3pandora_dac_reg)) {
291 pr_err(PREFIX "Failed to get DAC regulator from %s: %ld\n",
292 dev_name(&omap3pandora_snd_device->dev),
293 PTR_ERR(omap3pandora_dac_reg));
5c12d201 294 ret = PTR_ERR(omap3pandora_dac_reg);
c50749de
GI
295 goto fail3;
296 }
297
68fb7407
GI
298 return 0;
299
c50749de
GI
300fail3:
301 platform_device_del(omap3pandora_snd_device);
68fb7407
GI
302fail2:
303 platform_device_put(omap3pandora_snd_device);
304fail1:
305 gpio_free(OMAP3_PANDORA_AMP_POWER_GPIO);
306fail0:
307 gpio_free(OMAP3_PANDORA_DAC_POWER_GPIO);
308 return ret;
309}
310module_init(omap3pandora_soc_init);
311
312static void __exit omap3pandora_soc_exit(void)
313{
c50749de 314 regulator_put(omap3pandora_dac_reg);
68fb7407
GI
315 platform_device_unregister(omap3pandora_snd_device);
316 gpio_free(OMAP3_PANDORA_AMP_POWER_GPIO);
317 gpio_free(OMAP3_PANDORA_DAC_POWER_GPIO);
318}
319module_exit(omap3pandora_soc_exit);
320
321MODULE_AUTHOR("Grazvydas Ignotas <notasas@gmail.com>");
322MODULE_DESCRIPTION("ALSA SoC OMAP3 Pandora");
323MODULE_LICENSE("GPL");
This page took 0.160884 seconds and 5 git commands to generate.