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>
27 #include <linux/module.h>
29 #include <sound/core.h>
30 #include <sound/pcm.h>
31 #include <sound/soc.h>
33 #include <asm/mach-types.h>
34 #include <linux/platform_data/asoc-ti-mcbsp.h>
36 #include "omap-mcbsp.h"
38 #define OMAP3_PANDORA_DAC_POWER_GPIO 118
39 #define OMAP3_PANDORA_AMP_POWER_GPIO 14
41 #define PREFIX "ASoC omap3pandora: "
43 static struct regulator *omap3pandora_dac_reg;
45 static int omap3pandora_hw_params(struct snd_pcm_substream *substream,
46 struct snd_pcm_hw_params *params)
48 struct snd_soc_pcm_runtime *rtd = substream->private_data;
49 struct snd_soc_dai *codec_dai = rtd->codec_dai;
50 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
53 /* Set the codec system clock for DAC and ADC */
54 ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
57 pr_err(PREFIX "can't set codec system clock\n");
61 /* Set McBSP clock to external */
62 ret = snd_soc_dai_set_sysclk(cpu_dai, OMAP_MCBSP_SYSCLK_CLKS_EXT,
63 256 * params_rate(params),
66 pr_err(PREFIX "can't set cpu system clock\n");
70 ret = snd_soc_dai_set_clkdiv(cpu_dai, OMAP_MCBSP_CLKGDV, 8);
72 pr_err(PREFIX "can't set SRG clock divider\n");
79 static int omap3pandora_dac_event(struct snd_soc_dapm_widget *w,
80 struct snd_kcontrol *k, int event)
85 * The PCM1773 DAC datasheet requires 1ms delay between switching
86 * VCC power on/off and /PD pin high/low
88 if (SND_SOC_DAPM_EVENT_ON(event)) {
89 ret = regulator_enable(omap3pandora_dac_reg);
91 dev_err(w->dapm->dev, "Failed to power DAC: %d\n", ret);
95 gpio_set_value(OMAP3_PANDORA_DAC_POWER_GPIO, 1);
97 gpio_set_value(OMAP3_PANDORA_DAC_POWER_GPIO, 0);
99 regulator_disable(omap3pandora_dac_reg);
105 static int omap3pandora_hp_event(struct snd_soc_dapm_widget *w,
106 struct snd_kcontrol *k, int event)
108 if (SND_SOC_DAPM_EVENT_ON(event))
109 gpio_set_value(OMAP3_PANDORA_AMP_POWER_GPIO, 1);
111 gpio_set_value(OMAP3_PANDORA_AMP_POWER_GPIO, 0);
117 * Audio paths on Pandora board:
119 * |O| ---> PCM DAC +-> AMP -> Headphone Jack
120 * |M| A +--------> Line Out
122 * |P| <--- TWL4030 <--------- Line In and MICs
124 static const struct snd_soc_dapm_widget omap3pandora_dapm_widgets[] = {
125 SND_SOC_DAPM_DAC_E("PCM DAC", "HiFi Playback", SND_SOC_NOPM,
126 0, 0, omap3pandora_dac_event,
127 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
128 SND_SOC_DAPM_PGA_E("Headphone Amplifier", SND_SOC_NOPM,
129 0, 0, NULL, 0, omap3pandora_hp_event,
130 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
131 SND_SOC_DAPM_HP("Headphone Jack", NULL),
132 SND_SOC_DAPM_LINE("Line Out", NULL),
134 SND_SOC_DAPM_MIC("Mic (internal)", NULL),
135 SND_SOC_DAPM_MIC("Mic (external)", NULL),
136 SND_SOC_DAPM_LINE("Line In", NULL),
139 static const struct snd_soc_dapm_route omap3pandora_map[] = {
140 {"PCM DAC", NULL, "APLL Enable"},
141 {"Headphone Amplifier", NULL, "PCM DAC"},
142 {"Line Out", NULL, "PCM DAC"},
143 {"Headphone Jack", NULL, "Headphone Amplifier"},
145 {"AUXL", NULL, "Line In"},
146 {"AUXR", NULL, "Line In"},
148 {"MAINMIC", NULL, "Mic (internal)"},
149 {"Mic (internal)", NULL, "Mic Bias 1"},
151 {"SUBMIC", NULL, "Mic (external)"},
152 {"Mic (external)", NULL, "Mic Bias 2"},
155 static int omap3pandora_out_init(struct snd_soc_pcm_runtime *rtd)
157 struct snd_soc_codec *codec = rtd->codec;
158 struct snd_soc_dapm_context *dapm = &codec->dapm;
160 /* All TWL4030 output pins are floating */
161 snd_soc_dapm_nc_pin(dapm, "EARPIECE");
162 snd_soc_dapm_nc_pin(dapm, "PREDRIVEL");
163 snd_soc_dapm_nc_pin(dapm, "PREDRIVER");
164 snd_soc_dapm_nc_pin(dapm, "HSOL");
165 snd_soc_dapm_nc_pin(dapm, "HSOR");
166 snd_soc_dapm_nc_pin(dapm, "CARKITL");
167 snd_soc_dapm_nc_pin(dapm, "CARKITR");
168 snd_soc_dapm_nc_pin(dapm, "HFL");
169 snd_soc_dapm_nc_pin(dapm, "HFR");
170 snd_soc_dapm_nc_pin(dapm, "VIBRA");
175 static int omap3pandora_in_init(struct snd_soc_pcm_runtime *rtd)
177 struct snd_soc_codec *codec = rtd->codec;
178 struct snd_soc_dapm_context *dapm = &codec->dapm;
181 snd_soc_dapm_nc_pin(dapm, "HSMIC");
182 snd_soc_dapm_nc_pin(dapm, "CARKITMIC");
183 snd_soc_dapm_nc_pin(dapm, "DIGIMIC0");
184 snd_soc_dapm_nc_pin(dapm, "DIGIMIC1");
189 static struct snd_soc_ops omap3pandora_ops = {
190 .hw_params = omap3pandora_hw_params,
193 /* Digital audio interface glue - connects codec <--> CPU */
194 static struct snd_soc_dai_link omap3pandora_dai[] = {
197 .stream_name = "HiFi Out",
198 .cpu_dai_name = "omap-mcbsp.2",
199 .codec_dai_name = "twl4030-hifi",
200 .platform_name = "omap-mcbsp.2",
201 .codec_name = "twl4030-codec",
202 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
203 SND_SOC_DAIFMT_CBS_CFS,
204 .ops = &omap3pandora_ops,
205 .init = omap3pandora_out_init,
208 .stream_name = "Line/Mic In",
209 .cpu_dai_name = "omap-mcbsp.4",
210 .codec_dai_name = "twl4030-hifi",
211 .platform_name = "omap-mcbsp.4",
212 .codec_name = "twl4030-codec",
213 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
214 SND_SOC_DAIFMT_CBS_CFS,
215 .ops = &omap3pandora_ops,
216 .init = omap3pandora_in_init,
221 static struct snd_soc_card snd_soc_card_omap3pandora = {
222 .name = "omap3pandora",
223 .owner = THIS_MODULE,
224 .dai_link = omap3pandora_dai,
225 .num_links = ARRAY_SIZE(omap3pandora_dai),
227 .dapm_widgets = omap3pandora_dapm_widgets,
228 .num_dapm_widgets = ARRAY_SIZE(omap3pandora_dapm_widgets),
229 .dapm_routes = omap3pandora_map,
230 .num_dapm_routes = ARRAY_SIZE(omap3pandora_map),
233 static struct platform_device *omap3pandora_snd_device;
235 static int __init omap3pandora_soc_init(void)
239 if (!machine_is_omap3_pandora())
242 pr_info("OMAP3 Pandora SoC init\n");
244 ret = gpio_request(OMAP3_PANDORA_DAC_POWER_GPIO, "dac_power");
246 pr_err(PREFIX "Failed to get DAC power GPIO\n");
250 ret = gpio_direction_output(OMAP3_PANDORA_DAC_POWER_GPIO, 0);
252 pr_err(PREFIX "Failed to set DAC power GPIO direction\n");
256 ret = gpio_request(OMAP3_PANDORA_AMP_POWER_GPIO, "amp_power");
258 pr_err(PREFIX "Failed to get amp power GPIO\n");
262 ret = gpio_direction_output(OMAP3_PANDORA_AMP_POWER_GPIO, 0);
264 pr_err(PREFIX "Failed to set amp power GPIO direction\n");
268 omap3pandora_snd_device = platform_device_alloc("soc-audio", -1);
269 if (omap3pandora_snd_device == NULL) {
270 pr_err(PREFIX "Platform device allocation failed\n");
275 platform_set_drvdata(omap3pandora_snd_device, &snd_soc_card_omap3pandora);
277 ret = platform_device_add(omap3pandora_snd_device);
279 pr_err(PREFIX "Unable to add platform device\n");
283 omap3pandora_dac_reg = regulator_get(&omap3pandora_snd_device->dev, "vcc");
284 if (IS_ERR(omap3pandora_dac_reg)) {
285 pr_err(PREFIX "Failed to get DAC regulator from %s: %ld\n",
286 dev_name(&omap3pandora_snd_device->dev),
287 PTR_ERR(omap3pandora_dac_reg));
288 ret = PTR_ERR(omap3pandora_dac_reg);
295 platform_device_del(omap3pandora_snd_device);
297 platform_device_put(omap3pandora_snd_device);
299 gpio_free(OMAP3_PANDORA_AMP_POWER_GPIO);
301 gpio_free(OMAP3_PANDORA_DAC_POWER_GPIO);
304 module_init(omap3pandora_soc_init);
306 static void __exit omap3pandora_soc_exit(void)
308 regulator_put(omap3pandora_dac_reg);
309 platform_device_unregister(omap3pandora_snd_device);
310 gpio_free(OMAP3_PANDORA_AMP_POWER_GPIO);
311 gpio_free(OMAP3_PANDORA_DAC_POWER_GPIO);
313 module_exit(omap3pandora_soc_exit);
315 MODULE_AUTHOR("Grazvydas Ignotas <notasas@gmail.com>");
316 MODULE_DESCRIPTION("ALSA SoC OMAP3 Pandora");
317 MODULE_LICENSE("GPL");