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
,
88 static struct snd_soc_jack hs_jack
;
90 /* Headset jack detection DAPM pins */
91 static struct snd_soc_jack_pin hs_jack_pins
[] = {
93 .pin
= "Headset Jack",
94 .mask
= SND_JACK_HEADSET
,
98 /* Headset jack detection gpios */
99 static struct snd_soc_jack_gpio hs_jack_gpios
[] = {
101 .gpio
= (OMAP_MAX_GPIO_LINES
+ 2),
102 .name
= "hsdet-gpio",
103 .report
= SND_JACK_HEADSET
,
104 .debounce_time
= 200,
108 /* SDP3430 machine DAPM */
109 static const struct snd_soc_dapm_widget sdp3430_twl4030_dapm_widgets
[] = {
110 SND_SOC_DAPM_MIC("Ext Mic", NULL
),
111 SND_SOC_DAPM_SPK("Ext Spk", NULL
),
112 SND_SOC_DAPM_HP("Headset Jack", NULL
),
115 static const struct snd_soc_dapm_route audio_map
[] = {
116 /* External Mics: MAINMIC, SUBMIC with bias*/
117 {"MAINMIC", NULL
, "Mic Bias 1"},
118 {"SUBMIC", NULL
, "Mic Bias 2"},
119 {"Mic Bias 1", NULL
, "Ext Mic"},
120 {"Mic Bias 2", NULL
, "Ext Mic"},
122 /* External Speakers: HFL, HFR */
123 {"Ext Spk", NULL
, "HFL"},
124 {"Ext Spk", NULL
, "HFR"},
126 /* Headset: HSMIC (with bias), HSOL, HSOR */
127 {"Headset Jack", NULL
, "HSOL"},
128 {"Headset Jack", NULL
, "HSOR"},
129 {"HSMIC", NULL
, "Headset Mic Bias"},
130 {"Headset Mic Bias", NULL
, "Headset Jack"},
133 static int sdp3430_twl4030_init(struct snd_soc_codec
*codec
)
137 /* Add SDP3430 specific widgets */
138 ret
= snd_soc_dapm_new_controls(codec
, sdp3430_twl4030_dapm_widgets
,
139 ARRAY_SIZE(sdp3430_twl4030_dapm_widgets
));
143 /* Set up SDP3430 specific audio path audio_map */
144 snd_soc_dapm_add_routes(codec
, audio_map
, ARRAY_SIZE(audio_map
));
146 /* SDP3430 connected pins */
147 snd_soc_dapm_enable_pin(codec
, "Ext Mic");
148 snd_soc_dapm_enable_pin(codec
, "Ext Spk");
149 snd_soc_dapm_disable_pin(codec
, "Headset Jack");
151 /* TWL4030 not connected pins */
152 snd_soc_dapm_nc_pin(codec
, "AUXL");
153 snd_soc_dapm_nc_pin(codec
, "AUXR");
154 snd_soc_dapm_nc_pin(codec
, "CARKITMIC");
155 snd_soc_dapm_nc_pin(codec
, "DIGIMIC0");
156 snd_soc_dapm_nc_pin(codec
, "DIGIMIC1");
158 snd_soc_dapm_nc_pin(codec
, "OUTL");
159 snd_soc_dapm_nc_pin(codec
, "OUTR");
160 snd_soc_dapm_nc_pin(codec
, "EARPIECE");
161 snd_soc_dapm_nc_pin(codec
, "PREDRIVEL");
162 snd_soc_dapm_nc_pin(codec
, "PREDRIVER");
163 snd_soc_dapm_nc_pin(codec
, "CARKITL");
164 snd_soc_dapm_nc_pin(codec
, "CARKITR");
166 ret
= snd_soc_dapm_sync(codec
);
170 /* Headset jack detection */
171 ret
= snd_soc_jack_new(&snd_soc_sdp3430
, "Headset Jack",
172 SND_JACK_HEADSET
, &hs_jack
);
176 ret
= snd_soc_jack_add_pins(&hs_jack
, ARRAY_SIZE(hs_jack_pins
),
181 ret
= snd_soc_jack_add_gpios(&hs_jack
, ARRAY_SIZE(hs_jack_gpios
),
187 /* Digital audio interface glue - connects codec <--> CPU */
188 static struct snd_soc_dai_link sdp3430_dai
= {
190 .stream_name
= "TWL4030",
191 .cpu_dai
= &omap_mcbsp_dai
[0],
192 .codec_dai
= &twl4030_dai
,
193 .init
= sdp3430_twl4030_init
,
197 /* Audio machine driver */
198 static struct snd_soc_card snd_soc_sdp3430
= {
200 .platform
= &omap_soc_platform
,
201 .dai_link
= &sdp3430_dai
,
205 /* Audio subsystem */
206 static struct snd_soc_device sdp3430_snd_devdata
= {
207 .card
= &snd_soc_sdp3430
,
208 .codec_dev
= &soc_codec_dev_twl4030
,
211 static struct platform_device
*sdp3430_snd_device
;
213 static int __init
sdp3430_soc_init(void)
217 if (!machine_is_omap_3430sdp()) {
218 pr_debug("Not SDP3430!\n");
221 printk(KERN_INFO
"SDP3430 SoC init\n");
223 sdp3430_snd_device
= platform_device_alloc("soc-audio", -1);
224 if (!sdp3430_snd_device
) {
225 printk(KERN_ERR
"Platform device allocation failed\n");
229 platform_set_drvdata(sdp3430_snd_device
, &sdp3430_snd_devdata
);
230 sdp3430_snd_devdata
.dev
= &sdp3430_snd_device
->dev
;
231 *(unsigned int *)sdp3430_dai
.cpu_dai
->private_data
= 1; /* McBSP2 */
233 ret
= platform_device_add(sdp3430_snd_device
);
240 printk(KERN_ERR
"Unable to add platform device\n");
241 platform_device_put(sdp3430_snd_device
);
245 module_init(sdp3430_soc_init
);
247 static void __exit
sdp3430_soc_exit(void)
249 snd_soc_jack_free_gpios(&hs_jack
, ARRAY_SIZE(hs_jack_gpios
),
252 platform_device_unregister(sdp3430_snd_device
);
254 module_exit(sdp3430_soc_exit
);
256 MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>");
257 MODULE_DESCRIPTION("ALSA SoC SDP3430");
258 MODULE_LICENSE("GPL");