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/jack.h>
33 #include <asm/mach-types.h>
34 #include <mach/hardware.h>
35 #include <mach/gpio.h>
36 #include <plat/mcbsp.h>
38 /* Register descriptions for twl4030 codec part */
39 #include <linux/mfd/twl4030-audio.h>
40 #include <linux/module.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
;
59 /* Set the codec system clock for DAC and ADC */
60 ret
= snd_soc_dai_set_sysclk(codec_dai
, 0, 26000000,
63 printk(KERN_ERR
"can't set codec system clock\n");
70 static struct snd_soc_ops sdp3430_ops
= {
71 .hw_params
= sdp3430_hw_params
,
75 static struct snd_soc_jack hs_jack
;
77 /* Headset jack detection DAPM pins */
78 static struct snd_soc_jack_pin hs_jack_pins
[] = {
81 .mask
= SND_JACK_MICROPHONE
,
84 .pin
= "Headset Stereophone",
85 .mask
= SND_JACK_HEADPHONE
,
89 /* Headset jack detection gpios */
90 static struct snd_soc_jack_gpio hs_jack_gpios
[] = {
92 .gpio
= (OMAP_MAX_GPIO_LINES
+ 2),
94 .report
= SND_JACK_HEADSET
,
99 /* SDP3430 machine DAPM */
100 static const struct snd_soc_dapm_widget sdp3430_twl4030_dapm_widgets
[] = {
101 SND_SOC_DAPM_MIC("Ext Mic", NULL
),
102 SND_SOC_DAPM_SPK("Ext Spk", NULL
),
103 SND_SOC_DAPM_MIC("Headset Mic", NULL
),
104 SND_SOC_DAPM_HP("Headset Stereophone", NULL
),
107 static const struct snd_soc_dapm_route audio_map
[] = {
108 /* External Mics: MAINMIC, SUBMIC with bias*/
109 {"MAINMIC", NULL
, "Mic Bias 1"},
110 {"SUBMIC", NULL
, "Mic Bias 2"},
111 {"Mic Bias 1", NULL
, "Ext Mic"},
112 {"Mic Bias 2", NULL
, "Ext Mic"},
114 /* External Speakers: HFL, HFR */
115 {"Ext Spk", NULL
, "HFL"},
116 {"Ext Spk", NULL
, "HFR"},
118 /* Headset Mic: HSMIC with bias */
119 {"HSMIC", NULL
, "Headset Mic Bias"},
120 {"Headset Mic Bias", NULL
, "Headset Mic"},
122 /* Headset Stereophone (Headphone): HSOL, HSOR */
123 {"Headset Stereophone", NULL
, "HSOL"},
124 {"Headset Stereophone", NULL
, "HSOR"},
127 static int sdp3430_twl4030_init(struct snd_soc_pcm_runtime
*rtd
)
129 struct snd_soc_codec
*codec
= rtd
->codec
;
130 struct snd_soc_dapm_context
*dapm
= &codec
->dapm
;
133 /* SDP3430 connected pins */
134 snd_soc_dapm_enable_pin(dapm
, "Ext Mic");
135 snd_soc_dapm_enable_pin(dapm
, "Ext Spk");
136 snd_soc_dapm_disable_pin(dapm
, "Headset Mic");
137 snd_soc_dapm_disable_pin(dapm
, "Headset Stereophone");
139 /* TWL4030 not connected pins */
140 snd_soc_dapm_nc_pin(dapm
, "AUXL");
141 snd_soc_dapm_nc_pin(dapm
, "AUXR");
142 snd_soc_dapm_nc_pin(dapm
, "CARKITMIC");
143 snd_soc_dapm_nc_pin(dapm
, "DIGIMIC0");
144 snd_soc_dapm_nc_pin(dapm
, "DIGIMIC1");
146 snd_soc_dapm_nc_pin(dapm
, "OUTL");
147 snd_soc_dapm_nc_pin(dapm
, "OUTR");
148 snd_soc_dapm_nc_pin(dapm
, "EARPIECE");
149 snd_soc_dapm_nc_pin(dapm
, "PREDRIVEL");
150 snd_soc_dapm_nc_pin(dapm
, "PREDRIVER");
151 snd_soc_dapm_nc_pin(dapm
, "CARKITL");
152 snd_soc_dapm_nc_pin(dapm
, "CARKITR");
154 /* Headset jack detection */
155 ret
= snd_soc_jack_new(codec
, "Headset Jack",
156 SND_JACK_HEADSET
, &hs_jack
);
160 ret
= snd_soc_jack_add_pins(&hs_jack
, ARRAY_SIZE(hs_jack_pins
),
165 ret
= snd_soc_jack_add_gpios(&hs_jack
, ARRAY_SIZE(hs_jack_gpios
),
171 static int sdp3430_twl4030_voice_init(struct snd_soc_pcm_runtime
*rtd
)
173 struct snd_soc_codec
*codec
= rtd
->codec
;
176 /* Enable voice interface */
177 reg
= codec
->driver
->read(codec
, TWL4030_REG_VOICE_IF
);
178 reg
|= TWL4030_VIF_DIN_EN
| TWL4030_VIF_DOUT_EN
| TWL4030_VIF_EN
;
179 codec
->driver
->write(codec
, TWL4030_REG_VOICE_IF
, reg
);
185 /* Digital audio interface glue - connects codec <--> CPU */
186 static struct snd_soc_dai_link sdp3430_dai
[] = {
188 .name
= "TWL4030 I2S",
189 .stream_name
= "TWL4030 Audio",
190 .cpu_dai_name
= "omap-mcbsp.2",
191 .codec_dai_name
= "twl4030-hifi",
192 .platform_name
= "omap-pcm-audio",
193 .codec_name
= "twl4030-codec",
194 .dai_fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
|
195 SND_SOC_DAIFMT_CBM_CFM
,
196 .init
= sdp3430_twl4030_init
,
200 .name
= "TWL4030 PCM",
201 .stream_name
= "TWL4030 Voice",
202 .cpu_dai_name
= "omap-mcbsp.3",
203 .codec_dai_name
= "twl4030-voice",
204 .platform_name
= "omap-pcm-audio",
205 .codec_name
= "twl4030-codec",
206 .dai_fmt
= SND_SOC_DAIFMT_DSP_A
| SND_SOC_DAIFMT_IB_NF
|
207 SND_SOC_DAIFMT_CBM_CFM
,
208 .init
= sdp3430_twl4030_voice_init
,
213 /* Audio machine driver */
214 static struct snd_soc_card snd_soc_sdp3430
= {
216 .owner
= THIS_MODULE
,
217 .dai_link
= sdp3430_dai
,
218 .num_links
= ARRAY_SIZE(sdp3430_dai
),
220 .dapm_widgets
= sdp3430_twl4030_dapm_widgets
,
221 .num_dapm_widgets
= ARRAY_SIZE(sdp3430_twl4030_dapm_widgets
),
222 .dapm_routes
= audio_map
,
223 .num_dapm_routes
= ARRAY_SIZE(audio_map
),
226 static struct platform_device
*sdp3430_snd_device
;
228 static int __init
sdp3430_soc_init(void)
233 if (!machine_is_omap_3430sdp())
235 printk(KERN_INFO
"SDP3430 SoC init\n");
237 sdp3430_snd_device
= platform_device_alloc("soc-audio", -1);
238 if (!sdp3430_snd_device
) {
239 printk(KERN_ERR
"Platform device allocation failed\n");
243 platform_set_drvdata(sdp3430_snd_device
, &snd_soc_sdp3430
);
245 /* Set TWL4030 GPIO6 as EXTMUTE signal */
246 twl_i2c_read_u8(TWL4030_MODULE_INTBR
, &pin_mux
,
247 TWL4030_INTBR_PMBR1
);
248 pin_mux
&= ~TWL4030_GPIO6_PWM0_MUTE(0x03);
249 pin_mux
|= TWL4030_GPIO6_PWM0_MUTE(0x02);
250 twl_i2c_write_u8(TWL4030_MODULE_INTBR
, pin_mux
,
251 TWL4030_INTBR_PMBR1
);
253 ret
= platform_device_add(sdp3430_snd_device
);
260 printk(KERN_ERR
"Unable to add platform device\n");
261 platform_device_put(sdp3430_snd_device
);
265 module_init(sdp3430_soc_init
);
267 static void __exit
sdp3430_soc_exit(void)
269 snd_soc_jack_free_gpios(&hs_jack
, ARRAY_SIZE(hs_jack_gpios
),
272 platform_device_unregister(sdp3430_snd_device
);
274 module_exit(sdp3430_soc_exit
);
276 MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>");
277 MODULE_DESCRIPTION("ALSA SoC SDP3430");
278 MODULE_LICENSE("GPL");