2 * sdp3430.c -- SoC audio for TI OMAP3430 SDP
4 * Author: Misael Lopez Cruz <x0052729@ti.com>
7 * Author: Steve Sakoman <steve@sakoman.com>
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2 as published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
25 #include <linux/clk.h>
26 #include <linux/platform_device.h>
27 #include <sound/core.h>
28 #include <sound/pcm.h>
29 #include <sound/soc.h>
30 #include <sound/soc-dapm.h>
31 #include <sound/jack.h>
33 #include <asm/mach-types.h>
34 #include <mach/hardware.h>
35 #include <mach/gpio.h>
36 #include <mach/mcbsp.h>
38 #include "omap-mcbsp.h"
40 #include "../codecs/twl4030.h"
42 static struct snd_soc_card snd_soc_sdp3430
;
44 static int sdp3430_hw_params(struct snd_pcm_substream
*substream
,
45 struct snd_pcm_hw_params
*params
)
47 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
48 struct snd_soc_dai
*codec_dai
= rtd
->dai
->codec_dai
;
49 struct snd_soc_dai
*cpu_dai
= rtd
->dai
->cpu_dai
;
52 /* Set codec DAI configuration */
53 ret
= snd_soc_dai_set_fmt(codec_dai
,
55 SND_SOC_DAIFMT_NB_NF
|
56 SND_SOC_DAIFMT_CBM_CFM
);
58 printk(KERN_ERR
"can't set codec DAI configuration\n");
62 /* Set cpu DAI configuration */
63 ret
= snd_soc_dai_set_fmt(cpu_dai
,
65 SND_SOC_DAIFMT_NB_NF
|
66 SND_SOC_DAIFMT_CBM_CFM
);
68 printk(KERN_ERR
"can't set cpu DAI configuration\n");
72 /* Set the codec system clock for DAC and ADC */
73 ret
= snd_soc_dai_set_sysclk(codec_dai
, 0, 26000000,
76 printk(KERN_ERR
"can't set codec system clock\n");
83 static struct snd_soc_ops sdp3430_ops
= {
84 .hw_params
= sdp3430_hw_params
,
87 static int sdp3430_hw_voice_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
;
95 /* Set codec DAI configuration */
96 ret
= snd_soc_dai_set_fmt(codec_dai
,
97 SND_SOC_DAIFMT_DSP_A
|
98 SND_SOC_DAIFMT_IB_NF
|
99 SND_SOC_DAIFMT_CBS_CFM
);
101 printk(KERN_ERR
"can't set codec DAI configuration\n");
105 /* Set cpu DAI configuration */
106 ret
= snd_soc_dai_set_fmt(cpu_dai
,
107 SND_SOC_DAIFMT_DSP_A
|
108 SND_SOC_DAIFMT_IB_NF
|
109 SND_SOC_DAIFMT_CBM_CFM
);
111 printk(KERN_ERR
"can't set cpu DAI configuration\n");
115 /* Set the codec system clock for DAC and ADC */
116 ret
= snd_soc_dai_set_sysclk(codec_dai
, 0, 26000000,
119 printk(KERN_ERR
"can't set codec system clock\n");
126 static struct snd_soc_ops sdp3430_voice_ops
= {
127 .hw_params
= sdp3430_hw_voice_params
,
131 static struct snd_soc_jack hs_jack
;
133 /* Headset jack detection DAPM pins */
134 static struct snd_soc_jack_pin hs_jack_pins
[] = {
136 .pin
= "Headset Mic",
137 .mask
= SND_JACK_MICROPHONE
,
140 .pin
= "Headset Stereophone",
141 .mask
= SND_JACK_HEADPHONE
,
145 /* Headset jack detection gpios */
146 static struct snd_soc_jack_gpio hs_jack_gpios
[] = {
148 .gpio
= (OMAP_MAX_GPIO_LINES
+ 2),
149 .name
= "hsdet-gpio",
150 .report
= SND_JACK_HEADSET
,
151 .debounce_time
= 200,
155 /* SDP3430 machine DAPM */
156 static const struct snd_soc_dapm_widget sdp3430_twl4030_dapm_widgets
[] = {
157 SND_SOC_DAPM_MIC("Ext Mic", NULL
),
158 SND_SOC_DAPM_SPK("Ext Spk", NULL
),
159 SND_SOC_DAPM_MIC("Headset Mic", NULL
),
160 SND_SOC_DAPM_HP("Headset Stereophone", NULL
),
163 static const struct snd_soc_dapm_route audio_map
[] = {
164 /* External Mics: MAINMIC, SUBMIC with bias*/
165 {"MAINMIC", NULL
, "Mic Bias 1"},
166 {"SUBMIC", NULL
, "Mic Bias 2"},
167 {"Mic Bias 1", NULL
, "Ext Mic"},
168 {"Mic Bias 2", NULL
, "Ext Mic"},
170 /* External Speakers: HFL, HFR */
171 {"Ext Spk", NULL
, "HFL"},
172 {"Ext Spk", NULL
, "HFR"},
174 /* Headset Mic: HSMIC with bias */
175 {"HSMIC", NULL
, "Headset Mic Bias"},
176 {"Headset Mic Bias", NULL
, "Headset Mic"},
178 /* Headset Stereophone (Headphone): HSOL, HSOR */
179 {"Headset Stereophone", NULL
, "HSOL"},
180 {"Headset Stereophone", NULL
, "HSOR"},
183 static int sdp3430_twl4030_init(struct snd_soc_codec
*codec
)
187 /* Add SDP3430 specific widgets */
188 ret
= snd_soc_dapm_new_controls(codec
, sdp3430_twl4030_dapm_widgets
,
189 ARRAY_SIZE(sdp3430_twl4030_dapm_widgets
));
193 /* Set up SDP3430 specific audio path audio_map */
194 snd_soc_dapm_add_routes(codec
, audio_map
, ARRAY_SIZE(audio_map
));
196 /* SDP3430 connected pins */
197 snd_soc_dapm_enable_pin(codec
, "Ext Mic");
198 snd_soc_dapm_enable_pin(codec
, "Ext Spk");
199 snd_soc_dapm_disable_pin(codec
, "Headset Mic");
200 snd_soc_dapm_disable_pin(codec
, "Headset Stereophone");
202 /* TWL4030 not connected pins */
203 snd_soc_dapm_nc_pin(codec
, "AUXL");
204 snd_soc_dapm_nc_pin(codec
, "AUXR");
205 snd_soc_dapm_nc_pin(codec
, "CARKITMIC");
206 snd_soc_dapm_nc_pin(codec
, "DIGIMIC0");
207 snd_soc_dapm_nc_pin(codec
, "DIGIMIC1");
209 snd_soc_dapm_nc_pin(codec
, "OUTL");
210 snd_soc_dapm_nc_pin(codec
, "OUTR");
211 snd_soc_dapm_nc_pin(codec
, "EARPIECE");
212 snd_soc_dapm_nc_pin(codec
, "PREDRIVEL");
213 snd_soc_dapm_nc_pin(codec
, "PREDRIVER");
214 snd_soc_dapm_nc_pin(codec
, "CARKITL");
215 snd_soc_dapm_nc_pin(codec
, "CARKITR");
217 ret
= snd_soc_dapm_sync(codec
);
221 /* Headset jack detection */
222 ret
= snd_soc_jack_new(&snd_soc_sdp3430
, "Headset Jack",
223 SND_JACK_HEADSET
, &hs_jack
);
227 ret
= snd_soc_jack_add_pins(&hs_jack
, ARRAY_SIZE(hs_jack_pins
),
232 ret
= snd_soc_jack_add_gpios(&hs_jack
, ARRAY_SIZE(hs_jack_gpios
),
238 static int sdp3430_twl4030_voice_init(struct snd_soc_codec
*codec
)
242 /* Enable voice interface */
243 reg
= codec
->read(codec
, TWL4030_REG_VOICE_IF
);
244 reg
|= TWL4030_VIF_DIN_EN
| TWL4030_VIF_DOUT_EN
| TWL4030_VIF_EN
;
245 codec
->write(codec
, TWL4030_REG_VOICE_IF
, reg
);
251 /* Digital audio interface glue - connects codec <--> CPU */
252 static struct snd_soc_dai_link sdp3430_dai
[] = {
254 .name
= "TWL4030 I2S",
255 .stream_name
= "TWL4030 Audio",
256 .cpu_dai
= &omap_mcbsp_dai
[0],
257 .codec_dai
= &twl4030_dai
[TWL4030_DAI_HIFI
],
258 .init
= sdp3430_twl4030_init
,
262 .name
= "TWL4030 PCM",
263 .stream_name
= "TWL4030 Voice",
264 .cpu_dai
= &omap_mcbsp_dai
[1],
265 .codec_dai
= &twl4030_dai
[TWL4030_DAI_VOICE
],
266 .init
= sdp3430_twl4030_voice_init
,
267 .ops
= &sdp3430_voice_ops
,
271 /* Audio machine driver */
272 static struct snd_soc_card snd_soc_sdp3430
= {
274 .platform
= &omap_soc_platform
,
275 .dai_link
= sdp3430_dai
,
276 .num_links
= ARRAY_SIZE(sdp3430_dai
),
280 static struct twl4030_setup_data twl4030_setup
= {
281 .ramp_delay_value
= 3,
285 /* Audio subsystem */
286 static struct snd_soc_device sdp3430_snd_devdata
= {
287 .card
= &snd_soc_sdp3430
,
288 .codec_dev
= &soc_codec_dev_twl4030
,
289 .codec_data
= &twl4030_setup
,
292 static struct platform_device
*sdp3430_snd_device
;
294 static int __init
sdp3430_soc_init(void)
298 if (!machine_is_omap_3430sdp()) {
299 pr_debug("Not SDP3430!\n");
302 printk(KERN_INFO
"SDP3430 SoC init\n");
304 sdp3430_snd_device
= platform_device_alloc("soc-audio", -1);
305 if (!sdp3430_snd_device
) {
306 printk(KERN_ERR
"Platform device allocation failed\n");
310 platform_set_drvdata(sdp3430_snd_device
, &sdp3430_snd_devdata
);
311 sdp3430_snd_devdata
.dev
= &sdp3430_snd_device
->dev
;
312 *(unsigned int *)sdp3430_dai
[0].cpu_dai
->private_data
= 1; /* McBSP2 */
313 *(unsigned int *)sdp3430_dai
[1].cpu_dai
->private_data
= 2; /* McBSP3 */
315 ret
= platform_device_add(sdp3430_snd_device
);
322 printk(KERN_ERR
"Unable to add platform device\n");
323 platform_device_put(sdp3430_snd_device
);
327 module_init(sdp3430_soc_init
);
329 static void __exit
sdp3430_soc_exit(void)
331 snd_soc_jack_free_gpios(&hs_jack
, ARRAY_SIZE(hs_jack_gpios
),
334 platform_device_unregister(sdp3430_snd_device
);
336 module_exit(sdp3430_soc_exit
);
338 MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>");
339 MODULE_DESCRIPTION("ALSA SoC SDP3430");
340 MODULE_LICENSE("GPL");