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 <linux/i2c/twl.h>
28 #include <sound/core.h>
29 #include <sound/pcm.h>
30 #include <sound/soc.h>
31 #include <sound/soc-dapm.h>
32 #include <sound/jack.h>
34 #include <asm/mach-types.h>
35 #include <mach/hardware.h>
36 #include <mach/gpio.h>
37 #include <plat/mcbsp.h>
39 /* Register descriptions for twl4030 codec part */
40 #include <linux/mfd/twl4030-codec.h>
42 #include "omap-mcbsp.h"
45 /* TWL4030 PMBR1 Register */
46 #define TWL4030_INTBR_PMBR1 0x0D
47 /* TWL4030 PMBR1 Register GPIO6 mux bit */
48 #define TWL4030_GPIO6_PWM0_MUTE(value) (value << 2)
50 static struct snd_soc_card snd_soc_sdp3430
;
52 static int sdp3430_hw_params(struct snd_pcm_substream
*substream
,
53 struct snd_pcm_hw_params
*params
)
55 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
56 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
57 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
60 /* Set codec DAI configuration */
61 ret
= snd_soc_dai_set_fmt(codec_dai
,
63 SND_SOC_DAIFMT_NB_NF
|
64 SND_SOC_DAIFMT_CBM_CFM
);
66 printk(KERN_ERR
"can't set codec DAI configuration\n");
70 /* Set cpu DAI configuration */
71 ret
= snd_soc_dai_set_fmt(cpu_dai
,
73 SND_SOC_DAIFMT_NB_NF
|
74 SND_SOC_DAIFMT_CBM_CFM
);
76 printk(KERN_ERR
"can't set cpu DAI configuration\n");
80 /* Set the codec system clock for DAC and ADC */
81 ret
= snd_soc_dai_set_sysclk(codec_dai
, 0, 26000000,
84 printk(KERN_ERR
"can't set codec system clock\n");
91 static struct snd_soc_ops sdp3430_ops
= {
92 .hw_params
= sdp3430_hw_params
,
95 static int sdp3430_hw_voice_params(struct snd_pcm_substream
*substream
,
96 struct snd_pcm_hw_params
*params
)
98 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
99 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
100 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
103 /* Set codec DAI configuration */
104 ret
= snd_soc_dai_set_fmt(codec_dai
,
105 SND_SOC_DAIFMT_DSP_A
|
106 SND_SOC_DAIFMT_IB_NF
|
107 SND_SOC_DAIFMT_CBM_CFM
);
109 printk(KERN_ERR
"can't set codec DAI configuration\n");
113 /* Set cpu DAI configuration */
114 ret
= snd_soc_dai_set_fmt(cpu_dai
,
115 SND_SOC_DAIFMT_DSP_A
|
116 SND_SOC_DAIFMT_IB_NF
|
117 SND_SOC_DAIFMT_CBM_CFM
);
119 printk(KERN_ERR
"can't set cpu DAI configuration\n");
123 /* Set the codec system clock for DAC and ADC */
124 ret
= snd_soc_dai_set_sysclk(codec_dai
, 0, 26000000,
127 printk(KERN_ERR
"can't set codec system clock\n");
134 static struct snd_soc_ops sdp3430_voice_ops
= {
135 .hw_params
= sdp3430_hw_voice_params
,
139 static struct snd_soc_jack hs_jack
;
141 /* Headset jack detection DAPM pins */
142 static struct snd_soc_jack_pin hs_jack_pins
[] = {
144 .pin
= "Headset Mic",
145 .mask
= SND_JACK_MICROPHONE
,
148 .pin
= "Headset Stereophone",
149 .mask
= SND_JACK_HEADPHONE
,
153 /* Headset jack detection gpios */
154 static struct snd_soc_jack_gpio hs_jack_gpios
[] = {
156 .gpio
= (OMAP_MAX_GPIO_LINES
+ 2),
157 .name
= "hsdet-gpio",
158 .report
= SND_JACK_HEADSET
,
159 .debounce_time
= 200,
163 /* SDP3430 machine DAPM */
164 static const struct snd_soc_dapm_widget sdp3430_twl4030_dapm_widgets
[] = {
165 SND_SOC_DAPM_MIC("Ext Mic", NULL
),
166 SND_SOC_DAPM_SPK("Ext Spk", NULL
),
167 SND_SOC_DAPM_MIC("Headset Mic", NULL
),
168 SND_SOC_DAPM_HP("Headset Stereophone", NULL
),
171 static const struct snd_soc_dapm_route audio_map
[] = {
172 /* External Mics: MAINMIC, SUBMIC with bias*/
173 {"MAINMIC", NULL
, "Mic Bias 1"},
174 {"SUBMIC", NULL
, "Mic Bias 2"},
175 {"Mic Bias 1", NULL
, "Ext Mic"},
176 {"Mic Bias 2", NULL
, "Ext Mic"},
178 /* External Speakers: HFL, HFR */
179 {"Ext Spk", NULL
, "HFL"},
180 {"Ext Spk", NULL
, "HFR"},
182 /* Headset Mic: HSMIC with bias */
183 {"HSMIC", NULL
, "Headset Mic Bias"},
184 {"Headset Mic Bias", NULL
, "Headset Mic"},
186 /* Headset Stereophone (Headphone): HSOL, HSOR */
187 {"Headset Stereophone", NULL
, "HSOL"},
188 {"Headset Stereophone", NULL
, "HSOR"},
191 static int sdp3430_twl4030_init(struct snd_soc_pcm_runtime
*rtd
)
193 struct snd_soc_codec
*codec
= rtd
->codec
;
196 /* Add SDP3430 specific widgets */
197 ret
= snd_soc_dapm_new_controls(codec
, sdp3430_twl4030_dapm_widgets
,
198 ARRAY_SIZE(sdp3430_twl4030_dapm_widgets
));
202 /* Set up SDP3430 specific audio path audio_map */
203 snd_soc_dapm_add_routes(codec
, audio_map
, ARRAY_SIZE(audio_map
));
205 /* SDP3430 connected pins */
206 snd_soc_dapm_enable_pin(codec
, "Ext Mic");
207 snd_soc_dapm_enable_pin(codec
, "Ext Spk");
208 snd_soc_dapm_disable_pin(codec
, "Headset Mic");
209 snd_soc_dapm_disable_pin(codec
, "Headset Stereophone");
211 /* TWL4030 not connected pins */
212 snd_soc_dapm_nc_pin(codec
, "AUXL");
213 snd_soc_dapm_nc_pin(codec
, "AUXR");
214 snd_soc_dapm_nc_pin(codec
, "CARKITMIC");
215 snd_soc_dapm_nc_pin(codec
, "DIGIMIC0");
216 snd_soc_dapm_nc_pin(codec
, "DIGIMIC1");
218 snd_soc_dapm_nc_pin(codec
, "OUTL");
219 snd_soc_dapm_nc_pin(codec
, "OUTR");
220 snd_soc_dapm_nc_pin(codec
, "EARPIECE");
221 snd_soc_dapm_nc_pin(codec
, "PREDRIVEL");
222 snd_soc_dapm_nc_pin(codec
, "PREDRIVER");
223 snd_soc_dapm_nc_pin(codec
, "CARKITL");
224 snd_soc_dapm_nc_pin(codec
, "CARKITR");
226 ret
= snd_soc_dapm_sync(codec
);
230 /* Headset jack detection */
231 ret
= snd_soc_jack_new(codec
, "Headset Jack",
232 SND_JACK_HEADSET
, &hs_jack
);
236 ret
= snd_soc_jack_add_pins(&hs_jack
, ARRAY_SIZE(hs_jack_pins
),
241 ret
= snd_soc_jack_add_gpios(&hs_jack
, ARRAY_SIZE(hs_jack_gpios
),
247 static int sdp3430_twl4030_voice_init(struct snd_soc_pcm_runtime
*rtd
)
249 struct snd_soc_codec
*codec
= rtd
->codec
;
252 /* Enable voice interface */
253 reg
= codec
->driver
->read(codec
, TWL4030_REG_VOICE_IF
);
254 reg
|= TWL4030_VIF_DIN_EN
| TWL4030_VIF_DOUT_EN
| TWL4030_VIF_EN
;
255 codec
->driver
->write(codec
, TWL4030_REG_VOICE_IF
, reg
);
261 /* Digital audio interface glue - connects codec <--> CPU */
262 static struct snd_soc_dai_link sdp3430_dai
[] = {
264 .name
= "TWL4030 I2S",
265 .stream_name
= "TWL4030 Audio",
266 .cpu_dai_name
= "omap-mcbsp-dai.1",
267 .codec_dai_name
= "twl4030-hifi",
268 .platform_name
= "omap-pcm-audio",
269 .codec_name
= "twl4030-codec",
270 .init
= sdp3430_twl4030_init
,
274 .name
= "TWL4030 PCM",
275 .stream_name
= "TWL4030 Voice",
276 .cpu_dai_name
= "omap-mcbsp-dai.2",
277 .codec_dai_name
= "twl4030-voice",
278 .platform_name
= "omap-pcm-audio",
279 .codec_name
= "twl4030-codec",
280 .init
= sdp3430_twl4030_voice_init
,
281 .ops
= &sdp3430_voice_ops
,
285 /* Audio machine driver */
286 static struct snd_soc_card snd_soc_sdp3430
= {
288 .dai_link
= sdp3430_dai
,
289 .num_links
= ARRAY_SIZE(sdp3430_dai
),
292 static struct platform_device
*sdp3430_snd_device
;
294 static int __init
sdp3430_soc_init(void)
299 if (!machine_is_omap_3430sdp())
301 printk(KERN_INFO
"SDP3430 SoC init\n");
303 sdp3430_snd_device
= platform_device_alloc("soc-audio", -1);
304 if (!sdp3430_snd_device
) {
305 printk(KERN_ERR
"Platform device allocation failed\n");
309 platform_set_drvdata(sdp3430_snd_device
, &snd_soc_sdp3430
);
311 /* Set TWL4030 GPIO6 as EXTMUTE signal */
312 twl_i2c_read_u8(TWL4030_MODULE_INTBR
, &pin_mux
,
313 TWL4030_INTBR_PMBR1
);
314 pin_mux
&= ~TWL4030_GPIO6_PWM0_MUTE(0x03);
315 pin_mux
|= TWL4030_GPIO6_PWM0_MUTE(0x02);
316 twl_i2c_write_u8(TWL4030_MODULE_INTBR
, pin_mux
,
317 TWL4030_INTBR_PMBR1
);
319 ret
= platform_device_add(sdp3430_snd_device
);
326 printk(KERN_ERR
"Unable to add platform device\n");
327 platform_device_put(sdp3430_snd_device
);
331 module_init(sdp3430_soc_init
);
333 static void __exit
sdp3430_soc_exit(void)
335 snd_soc_jack_free_gpios(&hs_jack
, ARRAY_SIZE(hs_jack_gpios
),
338 platform_device_unregister(sdp3430_snd_device
);
340 module_exit(sdp3430_soc_exit
);
342 MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>");
343 MODULE_DESCRIPTION("ALSA SoC SDP3430");
344 MODULE_LICENSE("GPL");