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[] = {
94 .mask = SND_JACK_MICROPHONE,
97 .pin = "Headset Stereophone",
98 .mask = SND_JACK_HEADPHONE,
102 /* Headset jack detection gpios */
103 static struct snd_soc_jack_gpio hs_jack_gpios[] = {
105 .gpio = (OMAP_MAX_GPIO_LINES + 2),
106 .name = "hsdet-gpio",
107 .report = SND_JACK_HEADSET,
108 .debounce_time = 200,
112 /* SDP3430 machine DAPM */
113 static const struct snd_soc_dapm_widget sdp3430_twl4030_dapm_widgets[] = {
114 SND_SOC_DAPM_MIC("Ext Mic", NULL),
115 SND_SOC_DAPM_SPK("Ext Spk", NULL),
116 SND_SOC_DAPM_MIC("Headset Mic", NULL),
117 SND_SOC_DAPM_HP("Headset Stereophone", NULL),
120 static const struct snd_soc_dapm_route audio_map[] = {
121 /* External Mics: MAINMIC, SUBMIC with bias*/
122 {"MAINMIC", NULL, "Mic Bias 1"},
123 {"SUBMIC", NULL, "Mic Bias 2"},
124 {"Mic Bias 1", NULL, "Ext Mic"},
125 {"Mic Bias 2", NULL, "Ext Mic"},
127 /* External Speakers: HFL, HFR */
128 {"Ext Spk", NULL, "HFL"},
129 {"Ext Spk", NULL, "HFR"},
131 /* Headset Mic: HSMIC with bias */
132 {"HSMIC", NULL, "Headset Mic Bias"},
133 {"Headset Mic Bias", NULL, "Headset Mic"},
135 /* Headset Stereophone (Headphone): HSOL, HSOR */
136 {"Headset Stereophone", NULL, "HSOL"},
137 {"Headset Stereophone", NULL, "HSOR"},
140 static int sdp3430_twl4030_init(struct snd_soc_codec *codec)
144 /* Add SDP3430 specific widgets */
145 ret = snd_soc_dapm_new_controls(codec, sdp3430_twl4030_dapm_widgets,
146 ARRAY_SIZE(sdp3430_twl4030_dapm_widgets));
150 /* Set up SDP3430 specific audio path audio_map */
151 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
153 /* SDP3430 connected pins */
154 snd_soc_dapm_enable_pin(codec, "Ext Mic");
155 snd_soc_dapm_enable_pin(codec, "Ext Spk");
156 snd_soc_dapm_disable_pin(codec, "Headset Mic");
157 snd_soc_dapm_disable_pin(codec, "Headset Stereophone");
159 /* TWL4030 not connected pins */
160 snd_soc_dapm_nc_pin(codec, "AUXL");
161 snd_soc_dapm_nc_pin(codec, "AUXR");
162 snd_soc_dapm_nc_pin(codec, "CARKITMIC");
163 snd_soc_dapm_nc_pin(codec, "DIGIMIC0");
164 snd_soc_dapm_nc_pin(codec, "DIGIMIC1");
166 snd_soc_dapm_nc_pin(codec, "OUTL");
167 snd_soc_dapm_nc_pin(codec, "OUTR");
168 snd_soc_dapm_nc_pin(codec, "EARPIECE");
169 snd_soc_dapm_nc_pin(codec, "PREDRIVEL");
170 snd_soc_dapm_nc_pin(codec, "PREDRIVER");
171 snd_soc_dapm_nc_pin(codec, "CARKITL");
172 snd_soc_dapm_nc_pin(codec, "CARKITR");
174 ret = snd_soc_dapm_sync(codec);
178 /* Headset jack detection */
179 ret = snd_soc_jack_new(&snd_soc_sdp3430, "Headset Jack",
180 SND_JACK_HEADSET, &hs_jack);
184 ret = snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins),
189 ret = snd_soc_jack_add_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios),
195 /* Digital audio interface glue - connects codec <--> CPU */
196 static struct snd_soc_dai_link sdp3430_dai = {
198 .stream_name = "TWL4030",
199 .cpu_dai = &omap_mcbsp_dai[0],
200 .codec_dai = &twl4030_dai,
201 .init = sdp3430_twl4030_init,
205 /* Audio machine driver */
206 static struct snd_soc_card snd_soc_sdp3430 = {
208 .platform = &omap_soc_platform,
209 .dai_link = &sdp3430_dai,
213 /* Audio subsystem */
214 static struct snd_soc_device sdp3430_snd_devdata = {
215 .card = &snd_soc_sdp3430,
216 .codec_dev = &soc_codec_dev_twl4030,
219 static struct platform_device *sdp3430_snd_device;
221 static int __init sdp3430_soc_init(void)
225 if (!machine_is_omap_3430sdp()) {
226 pr_debug("Not SDP3430!\n");
229 printk(KERN_INFO "SDP3430 SoC init\n");
231 sdp3430_snd_device = platform_device_alloc("soc-audio", -1);
232 if (!sdp3430_snd_device) {
233 printk(KERN_ERR "Platform device allocation failed\n");
237 platform_set_drvdata(sdp3430_snd_device, &sdp3430_snd_devdata);
238 sdp3430_snd_devdata.dev = &sdp3430_snd_device->dev;
239 *(unsigned int *)sdp3430_dai.cpu_dai->private_data = 1; /* McBSP2 */
241 ret = platform_device_add(sdp3430_snd_device);
248 printk(KERN_ERR "Unable to add platform device\n");
249 platform_device_put(sdp3430_snd_device);
253 module_init(sdp3430_soc_init);
255 static void __exit sdp3430_soc_exit(void)
257 snd_soc_jack_free_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios),
260 platform_device_unregister(sdp3430_snd_device);
262 module_exit(sdp3430_soc_exit);
264 MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>");
265 MODULE_DESCRIPTION("ALSA SoC SDP3430");
266 MODULE_LICENSE("GPL");