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>
27 #include <sound/core.h>
28 #include <sound/pcm.h>
29 #include <sound/soc.h>
30 #include <sound/soc-dapm.h>
32 #include <asm/mach-types.h>
34 #include "omap-mcbsp.h"
36 #include "../codecs/twl4030.h"
38 #define OMAP3_PANDORA_DAC_POWER_GPIO 118
39 #define OMAP3_PANDORA_AMP_POWER_GPIO 14
41 #define PREFIX "ASoC omap3pandora: "
43 static int omap3pandora_cmn_hw_params(struct snd_soc_dai
*codec_dai
,
44 struct snd_soc_dai
*cpu_dai
, unsigned int fmt
)
48 /* Set codec DAI configuration */
49 ret
= snd_soc_dai_set_fmt(codec_dai
, fmt
);
51 pr_err(PREFIX
"can't set codec DAI configuration\n");
55 /* Set cpu DAI configuration */
56 ret
= snd_soc_dai_set_fmt(cpu_dai
, fmt
);
58 pr_err(PREFIX
"can't set cpu DAI configuration\n");
62 /* Set the codec system clock for DAC and ADC */
63 ret
= snd_soc_dai_set_sysclk(codec_dai
, 0, 26000000,
66 pr_err(PREFIX
"can't set codec system clock\n");
70 /* Set McBSP clock to external */
71 ret
= snd_soc_dai_set_sysclk(cpu_dai
, OMAP_MCBSP_SYSCLK_CLKS_EXT
, 0,
74 pr_err(PREFIX
"can't set cpu system clock\n");
78 ret
= snd_soc_dai_set_clkdiv(cpu_dai
, OMAP_MCBSP_CLKGDV
, 8);
80 pr_err(PREFIX
"can't set SRG clock divider\n");
87 static int omap3pandora_out_hw_params(struct snd_pcm_substream
*substream
,
88 struct snd_pcm_hw_params
*params
)
90 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
91 struct snd_soc_dai
*codec_dai
= rtd
->dai
->codec_dai
;
92 struct snd_soc_dai
*cpu_dai
= rtd
->dai
->cpu_dai
;
94 return omap3pandora_cmn_hw_params(codec_dai
, cpu_dai
,
96 SND_SOC_DAIFMT_IB_NF
|
97 SND_SOC_DAIFMT_CBS_CFS
);
100 static int omap3pandora_in_hw_params(struct snd_pcm_substream
*substream
,
101 struct snd_pcm_hw_params
*params
)
103 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
104 struct snd_soc_dai
*codec_dai
= rtd
->dai
->codec_dai
;
105 struct snd_soc_dai
*cpu_dai
= rtd
->dai
->cpu_dai
;
107 return omap3pandora_cmn_hw_params(codec_dai
, cpu_dai
,
109 SND_SOC_DAIFMT_NB_NF
|
110 SND_SOC_DAIFMT_CBS_CFS
);
113 static int omap3pandora_hp_event(struct snd_soc_dapm_widget
*w
,
114 struct snd_kcontrol
*k
, int event
)
116 if (SND_SOC_DAPM_EVENT_ON(event
)) {
117 gpio_set_value(OMAP3_PANDORA_DAC_POWER_GPIO
, 1);
118 gpio_set_value(OMAP3_PANDORA_AMP_POWER_GPIO
, 1);
120 gpio_set_value(OMAP3_PANDORA_AMP_POWER_GPIO
, 0);
122 gpio_set_value(OMAP3_PANDORA_DAC_POWER_GPIO
, 0);
129 * Audio paths on Pandora board:
131 * |O| ---> PCM DAC +-> AMP -> Headphone Jack
132 * |M| A +--------> Line Out
134 * |P| <--- TWL4030 <--------- Line In and MICs
136 static const struct snd_soc_dapm_widget omap3pandora_out_dapm_widgets
[] = {
137 SND_SOC_DAPM_DAC("PCM DAC", "Playback", SND_SOC_NOPM
, 0, 0),
138 SND_SOC_DAPM_PGA_E("Headphone Amplifier", SND_SOC_NOPM
,
139 0, 0, NULL
, 0, omap3pandora_hp_event
,
140 SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_PRE_PMD
),
141 SND_SOC_DAPM_HP("Headphone Jack", NULL
),
142 SND_SOC_DAPM_LINE("Line Out", NULL
),
145 static const struct snd_soc_dapm_widget omap3pandora_in_dapm_widgets
[] = {
146 SND_SOC_DAPM_MIC("Mic (Internal)", NULL
),
147 SND_SOC_DAPM_MIC("Mic (external)", NULL
),
148 SND_SOC_DAPM_LINE("Line In", NULL
),
151 static const struct snd_soc_dapm_route omap3pandora_out_map
[] = {
152 {"Headphone Amplifier", NULL
, "PCM DAC"},
153 {"Line Out", NULL
, "PCM DAC"},
154 {"Headphone Jack", NULL
, "Headphone Amplifier"},
157 static const struct snd_soc_dapm_route omap3pandora_in_map
[] = {
158 {"INL", NULL
, "Line In"},
159 {"INR", NULL
, "Line In"},
160 {"INL", NULL
, "Mic (Internal)"},
161 {"INR", NULL
, "Mic (external)"},
164 static int omap3pandora_out_init(struct snd_soc_codec
*codec
)
168 ret
= snd_soc_dapm_new_controls(codec
, omap3pandora_out_dapm_widgets
,
169 ARRAY_SIZE(omap3pandora_out_dapm_widgets
));
173 snd_soc_dapm_add_routes(codec
, omap3pandora_out_map
,
174 ARRAY_SIZE(omap3pandora_out_map
));
176 return snd_soc_dapm_sync(codec
);
179 static int omap3pandora_in_init(struct snd_soc_codec
*codec
)
183 /* All TWL4030 output pins are floating */
184 snd_soc_dapm_nc_pin(codec
, "OUTL"),
185 snd_soc_dapm_nc_pin(codec
, "OUTR"),
186 snd_soc_dapm_nc_pin(codec
, "EARPIECE"),
187 snd_soc_dapm_nc_pin(codec
, "PREDRIVEL"),
188 snd_soc_dapm_nc_pin(codec
, "PREDRIVER"),
189 snd_soc_dapm_nc_pin(codec
, "HSOL"),
190 snd_soc_dapm_nc_pin(codec
, "HSOR"),
191 snd_soc_dapm_nc_pin(codec
, "CARKITL"),
192 snd_soc_dapm_nc_pin(codec
, "CARKITR"),
193 snd_soc_dapm_nc_pin(codec
, "HFL"),
194 snd_soc_dapm_nc_pin(codec
, "HFR"),
196 ret
= snd_soc_dapm_new_controls(codec
, omap3pandora_in_dapm_widgets
,
197 ARRAY_SIZE(omap3pandora_in_dapm_widgets
));
201 snd_soc_dapm_add_routes(codec
, omap3pandora_in_map
,
202 ARRAY_SIZE(omap3pandora_in_map
));
204 return snd_soc_dapm_sync(codec
);
207 static struct snd_soc_ops omap3pandora_out_ops
= {
208 .hw_params
= omap3pandora_out_hw_params
,
211 static struct snd_soc_ops omap3pandora_in_ops
= {
212 .hw_params
= omap3pandora_in_hw_params
,
215 /* Digital audio interface glue - connects codec <--> CPU */
216 static struct snd_soc_dai_link omap3pandora_dai
[] = {
219 .stream_name
= "HiFi Out",
220 .cpu_dai
= &omap_mcbsp_dai
[0],
221 .codec_dai
= &twl4030_dai
,
222 .ops
= &omap3pandora_out_ops
,
223 .init
= omap3pandora_out_init
,
226 .stream_name
= "Line/Mic In",
227 .cpu_dai
= &omap_mcbsp_dai
[1],
228 .codec_dai
= &twl4030_dai
,
229 .ops
= &omap3pandora_in_ops
,
230 .init
= omap3pandora_in_init
,
235 static struct snd_soc_card snd_soc_card_omap3pandora
= {
236 .name
= "omap3pandora",
237 .platform
= &omap_soc_platform
,
238 .dai_link
= omap3pandora_dai
,
239 .num_links
= ARRAY_SIZE(omap3pandora_dai
),
242 /* Audio subsystem */
243 static struct snd_soc_device omap3pandora_snd_data
= {
244 .card
= &snd_soc_card_omap3pandora
,
245 .codec_dev
= &soc_codec_dev_twl4030
,
248 static struct platform_device
*omap3pandora_snd_device
;
250 static int __init
omap3pandora_soc_init(void)
254 if (!machine_is_omap3_pandora()) {
255 pr_debug(PREFIX
"Not OMAP3 Pandora\n");
258 pr_info("OMAP3 Pandora SoC init\n");
260 ret
= gpio_request(OMAP3_PANDORA_DAC_POWER_GPIO
, "dac_power");
262 pr_err(PREFIX
"Failed to get DAC power GPIO\n");
266 ret
= gpio_direction_output(OMAP3_PANDORA_DAC_POWER_GPIO
, 0);
268 pr_err(PREFIX
"Failed to set DAC power GPIO direction\n");
272 ret
= gpio_request(OMAP3_PANDORA_AMP_POWER_GPIO
, "amp_power");
274 pr_err(PREFIX
"Failed to get amp power GPIO\n");
278 ret
= gpio_direction_output(OMAP3_PANDORA_AMP_POWER_GPIO
, 0);
280 pr_err(PREFIX
"Failed to set amp power GPIO direction\n");
284 omap3pandora_snd_device
= platform_device_alloc("soc-audio", -1);
285 if (omap3pandora_snd_device
== NULL
) {
286 pr_err(PREFIX
"Platform device allocation failed\n");
291 platform_set_drvdata(omap3pandora_snd_device
, &omap3pandora_snd_data
);
292 omap3pandora_snd_data
.dev
= &omap3pandora_snd_device
->dev
;
293 *(unsigned int *)omap_mcbsp_dai
[0].private_data
= 1; /* McBSP2 */
294 *(unsigned int *)omap_mcbsp_dai
[1].private_data
= 3; /* McBSP4 */
296 ret
= platform_device_add(omap3pandora_snd_device
);
298 pr_err(PREFIX
"Unable to add platform device\n");
305 platform_device_put(omap3pandora_snd_device
);
307 gpio_free(OMAP3_PANDORA_AMP_POWER_GPIO
);
309 gpio_free(OMAP3_PANDORA_DAC_POWER_GPIO
);
312 module_init(omap3pandora_soc_init
);
314 static void __exit
omap3pandora_soc_exit(void)
316 platform_device_unregister(omap3pandora_snd_device
);
317 gpio_free(OMAP3_PANDORA_AMP_POWER_GPIO
);
318 gpio_free(OMAP3_PANDORA_DAC_POWER_GPIO
);
320 module_exit(omap3pandora_soc_exit
);
322 MODULE_AUTHOR("Grazvydas Ignotas <notasas@gmail.com>");
323 MODULE_DESCRIPTION("ALSA SoC OMAP3 Pandora");
324 MODULE_LICENSE("GPL");