2 * omap3pandora.c -- SoC audio for Pandora Handheld Console
4 * Author: GraÅžvydas Ignotas <notasas@gmail.com>
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.
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.
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
22 #include <linux/clk.h>
23 #include <linux/platform_device.h>
24 #include <linux/gpio.h>
25 #include <linux/delay.h>
26 #include <linux/regulator/consumer.h>
28 #include <sound/core.h>
29 #include <sound/pcm.h>
30 #include <sound/soc.h>
31 #include <sound/soc-dapm.h>
33 #include <asm/mach-types.h>
35 #include "omap-mcbsp.h"
37 #include "../codecs/twl4030.h"
39 #define OMAP3_PANDORA_DAC_POWER_GPIO 118
40 #define OMAP3_PANDORA_AMP_POWER_GPIO 14
42 #define PREFIX "ASoC omap3pandora: "
44 static struct regulator
*omap3pandora_dac_reg
;
46 static int omap3pandora_cmn_hw_params(struct snd_pcm_substream
*substream
,
47 struct snd_pcm_hw_params
*params
, unsigned int fmt
)
49 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
50 struct snd_soc_dai
*codec_dai
= rtd
->dai
->codec_dai
;
51 struct snd_soc_dai
*cpu_dai
= rtd
->dai
->cpu_dai
;
54 /* Set codec DAI configuration */
55 ret
= snd_soc_dai_set_fmt(codec_dai
, fmt
);
57 pr_err(PREFIX
"can't set codec DAI configuration\n");
61 /* Set cpu DAI configuration */
62 ret
= snd_soc_dai_set_fmt(cpu_dai
, fmt
);
64 pr_err(PREFIX
"can't set cpu DAI configuration\n");
68 /* Set the codec system clock for DAC and ADC */
69 ret
= snd_soc_dai_set_sysclk(codec_dai
, 0, 26000000,
72 pr_err(PREFIX
"can't set codec system clock\n");
76 /* Set McBSP clock to external */
77 ret
= snd_soc_dai_set_sysclk(cpu_dai
, OMAP_MCBSP_SYSCLK_CLKS_EXT
,
78 256 * params_rate(params
),
81 pr_err(PREFIX
"can't set cpu system clock\n");
85 ret
= snd_soc_dai_set_clkdiv(cpu_dai
, OMAP_MCBSP_CLKGDV
, 8);
87 pr_err(PREFIX
"can't set SRG clock divider\n");
94 static int omap3pandora_out_hw_params(struct snd_pcm_substream
*substream
,
95 struct snd_pcm_hw_params
*params
)
97 return omap3pandora_cmn_hw_params(substream
, params
,
99 SND_SOC_DAIFMT_IB_NF
|
100 SND_SOC_DAIFMT_CBS_CFS
);
103 static int omap3pandora_in_hw_params(struct snd_pcm_substream
*substream
,
104 struct snd_pcm_hw_params
*params
)
106 return omap3pandora_cmn_hw_params(substream
, params
,
108 SND_SOC_DAIFMT_NB_NF
|
109 SND_SOC_DAIFMT_CBS_CFS
);
112 static int omap3pandora_dac_event(struct snd_soc_dapm_widget
*w
,
113 struct snd_kcontrol
*k
, int event
)
116 * The PCM1773 DAC datasheet requires 1ms delay between switching
117 * VCC power on/off and /PD pin high/low
119 if (SND_SOC_DAPM_EVENT_ON(event
)) {
120 regulator_enable(omap3pandora_dac_reg
);
122 gpio_set_value(OMAP3_PANDORA_DAC_POWER_GPIO
, 1);
124 gpio_set_value(OMAP3_PANDORA_DAC_POWER_GPIO
, 0);
126 regulator_disable(omap3pandora_dac_reg
);
132 static int omap3pandora_hp_event(struct snd_soc_dapm_widget
*w
,
133 struct snd_kcontrol
*k
, int event
)
135 if (SND_SOC_DAPM_EVENT_ON(event
))
136 gpio_set_value(OMAP3_PANDORA_AMP_POWER_GPIO
, 1);
138 gpio_set_value(OMAP3_PANDORA_AMP_POWER_GPIO
, 0);
144 * Audio paths on Pandora board:
146 * |O| ---> PCM DAC +-> AMP -> Headphone Jack
147 * |M| A +--------> Line Out
149 * |P| <--- TWL4030 <--------- Line In and MICs
151 static const struct snd_soc_dapm_widget omap3pandora_out_dapm_widgets
[] = {
152 SND_SOC_DAPM_DAC_E("PCM DAC", "HiFi Playback", SND_SOC_NOPM
,
153 0, 0, omap3pandora_dac_event
,
154 SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_PRE_PMD
),
155 SND_SOC_DAPM_PGA_E("Headphone Amplifier", SND_SOC_NOPM
,
156 0, 0, NULL
, 0, omap3pandora_hp_event
,
157 SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_PRE_PMD
),
158 SND_SOC_DAPM_HP("Headphone Jack", NULL
),
159 SND_SOC_DAPM_LINE("Line Out", NULL
),
162 static const struct snd_soc_dapm_widget omap3pandora_in_dapm_widgets
[] = {
163 SND_SOC_DAPM_MIC("Mic (internal)", NULL
),
164 SND_SOC_DAPM_MIC("Mic (external)", NULL
),
165 SND_SOC_DAPM_LINE("Line In", NULL
),
168 static const struct snd_soc_dapm_route omap3pandora_out_map
[] = {
169 {"PCM DAC", NULL
, "APLL Enable"},
170 {"Headphone Amplifier", NULL
, "PCM DAC"},
171 {"Line Out", NULL
, "PCM DAC"},
172 {"Headphone Jack", NULL
, "Headphone Amplifier"},
175 static const struct snd_soc_dapm_route omap3pandora_in_map
[] = {
176 {"AUXL", NULL
, "Line In"},
177 {"AUXR", NULL
, "Line In"},
179 {"MAINMIC", NULL
, "Mic Bias 1"},
180 {"Mic Bias 1", NULL
, "Mic (internal)"},
182 {"SUBMIC", NULL
, "Mic Bias 2"},
183 {"Mic Bias 2", NULL
, "Mic (external)"},
186 static int omap3pandora_out_init(struct snd_soc_codec
*codec
)
190 /* All TWL4030 output pins are floating */
191 snd_soc_dapm_nc_pin(codec
, "EARPIECE");
192 snd_soc_dapm_nc_pin(codec
, "PREDRIVEL");
193 snd_soc_dapm_nc_pin(codec
, "PREDRIVER");
194 snd_soc_dapm_nc_pin(codec
, "HSOL");
195 snd_soc_dapm_nc_pin(codec
, "HSOR");
196 snd_soc_dapm_nc_pin(codec
, "CARKITL");
197 snd_soc_dapm_nc_pin(codec
, "CARKITR");
198 snd_soc_dapm_nc_pin(codec
, "HFL");
199 snd_soc_dapm_nc_pin(codec
, "HFR");
200 snd_soc_dapm_nc_pin(codec
, "VIBRA");
202 ret
= snd_soc_dapm_new_controls(codec
, omap3pandora_out_dapm_widgets
,
203 ARRAY_SIZE(omap3pandora_out_dapm_widgets
));
207 snd_soc_dapm_add_routes(codec
, omap3pandora_out_map
,
208 ARRAY_SIZE(omap3pandora_out_map
));
210 return snd_soc_dapm_sync(codec
);
213 static int omap3pandora_in_init(struct snd_soc_codec
*codec
)
218 snd_soc_dapm_nc_pin(codec
, "HSMIC");
219 snd_soc_dapm_nc_pin(codec
, "CARKITMIC");
220 snd_soc_dapm_nc_pin(codec
, "DIGIMIC0");
221 snd_soc_dapm_nc_pin(codec
, "DIGIMIC1");
223 ret
= snd_soc_dapm_new_controls(codec
, omap3pandora_in_dapm_widgets
,
224 ARRAY_SIZE(omap3pandora_in_dapm_widgets
));
228 snd_soc_dapm_add_routes(codec
, omap3pandora_in_map
,
229 ARRAY_SIZE(omap3pandora_in_map
));
231 return snd_soc_dapm_sync(codec
);
234 static struct snd_soc_ops omap3pandora_out_ops
= {
235 .hw_params
= omap3pandora_out_hw_params
,
238 static struct snd_soc_ops omap3pandora_in_ops
= {
239 .hw_params
= omap3pandora_in_hw_params
,
242 /* Digital audio interface glue - connects codec <--> CPU */
243 static struct snd_soc_dai_link omap3pandora_dai
[] = {
246 .stream_name
= "HiFi Out",
247 .cpu_dai
= &omap_mcbsp_dai
[0],
248 .codec_dai
= &twl4030_dai
[TWL4030_DAI_HIFI
],
249 .ops
= &omap3pandora_out_ops
,
250 .init
= omap3pandora_out_init
,
253 .stream_name
= "Line/Mic In",
254 .cpu_dai
= &omap_mcbsp_dai
[1],
255 .codec_dai
= &twl4030_dai
[TWL4030_DAI_HIFI
],
256 .ops
= &omap3pandora_in_ops
,
257 .init
= omap3pandora_in_init
,
262 static struct snd_soc_card snd_soc_card_omap3pandora
= {
263 .name
= "omap3pandora",
264 .platform
= &omap_soc_platform
,
265 .dai_link
= omap3pandora_dai
,
266 .num_links
= ARRAY_SIZE(omap3pandora_dai
),
269 /* Audio subsystem */
270 static struct snd_soc_device omap3pandora_snd_data
= {
271 .card
= &snd_soc_card_omap3pandora
,
272 .codec_dev
= &soc_codec_dev_twl4030
,
275 static struct platform_device
*omap3pandora_snd_device
;
277 static int __init
omap3pandora_soc_init(void)
281 if (!machine_is_omap3_pandora())
284 pr_info("OMAP3 Pandora SoC init\n");
286 ret
= gpio_request(OMAP3_PANDORA_DAC_POWER_GPIO
, "dac_power");
288 pr_err(PREFIX
"Failed to get DAC power GPIO\n");
292 ret
= gpio_direction_output(OMAP3_PANDORA_DAC_POWER_GPIO
, 0);
294 pr_err(PREFIX
"Failed to set DAC power GPIO direction\n");
298 ret
= gpio_request(OMAP3_PANDORA_AMP_POWER_GPIO
, "amp_power");
300 pr_err(PREFIX
"Failed to get amp power GPIO\n");
304 ret
= gpio_direction_output(OMAP3_PANDORA_AMP_POWER_GPIO
, 0);
306 pr_err(PREFIX
"Failed to set amp power GPIO direction\n");
310 omap3pandora_snd_device
= platform_device_alloc("soc-audio", -1);
311 if (omap3pandora_snd_device
== NULL
) {
312 pr_err(PREFIX
"Platform device allocation failed\n");
317 platform_set_drvdata(omap3pandora_snd_device
, &omap3pandora_snd_data
);
318 omap3pandora_snd_data
.dev
= &omap3pandora_snd_device
->dev
;
319 *(unsigned int *)omap_mcbsp_dai
[0].private_data
= 1; /* McBSP2 */
320 *(unsigned int *)omap_mcbsp_dai
[1].private_data
= 3; /* McBSP4 */
322 ret
= platform_device_add(omap3pandora_snd_device
);
324 pr_err(PREFIX
"Unable to add platform device\n");
328 omap3pandora_dac_reg
= regulator_get(&omap3pandora_snd_device
->dev
, "vcc");
329 if (IS_ERR(omap3pandora_dac_reg
)) {
330 pr_err(PREFIX
"Failed to get DAC regulator from %s: %ld\n",
331 dev_name(&omap3pandora_snd_device
->dev
),
332 PTR_ERR(omap3pandora_dac_reg
));
339 platform_device_del(omap3pandora_snd_device
);
341 platform_device_put(omap3pandora_snd_device
);
343 gpio_free(OMAP3_PANDORA_AMP_POWER_GPIO
);
345 gpio_free(OMAP3_PANDORA_DAC_POWER_GPIO
);
348 module_init(omap3pandora_soc_init
);
350 static void __exit
omap3pandora_soc_exit(void)
352 regulator_put(omap3pandora_dac_reg
);
353 platform_device_unregister(omap3pandora_snd_device
);
354 gpio_free(OMAP3_PANDORA_AMP_POWER_GPIO
);
355 gpio_free(OMAP3_PANDORA_DAC_POWER_GPIO
);
357 module_exit(omap3pandora_soc_exit
);
359 MODULE_AUTHOR("Grazvydas Ignotas <notasas@gmail.com>");
360 MODULE_DESCRIPTION("ALSA SoC OMAP3 Pandora");
361 MODULE_LICENSE("GPL");