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/jack.h>
32 #include <asm/mach-types.h>
33 #include <linux/platform_data/gpio-omap.h>
35 #include <linux/module.h>
37 #include "omap-mcbsp.h"
40 static struct snd_soc_card snd_soc_sdp3430;
42 static int sdp3430_hw_params(struct snd_pcm_substream *substream,
43 struct snd_pcm_hw_params *params)
45 struct snd_soc_pcm_runtime *rtd = substream->private_data;
46 struct snd_soc_dai *codec_dai = rtd->codec_dai;
49 /* Set the codec system clock for DAC and ADC */
50 ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
53 printk(KERN_ERR "can't set codec system clock\n");
60 static struct snd_soc_ops sdp3430_ops = {
61 .hw_params = sdp3430_hw_params,
65 static struct snd_soc_jack hs_jack;
67 /* Headset jack detection DAPM pins */
68 static struct snd_soc_jack_pin hs_jack_pins[] = {
71 .mask = SND_JACK_MICROPHONE,
74 .pin = "Headset Stereophone",
75 .mask = SND_JACK_HEADPHONE,
79 /* Headset jack detection gpios */
80 static struct snd_soc_jack_gpio hs_jack_gpios[] = {
82 .gpio = (OMAP_MAX_GPIO_LINES + 2),
84 .report = SND_JACK_HEADSET,
89 /* SDP3430 machine DAPM */
90 static const struct snd_soc_dapm_widget sdp3430_twl4030_dapm_widgets[] = {
91 SND_SOC_DAPM_MIC("Ext Mic", NULL),
92 SND_SOC_DAPM_SPK("Ext Spk", NULL),
93 SND_SOC_DAPM_MIC("Headset Mic", NULL),
94 SND_SOC_DAPM_HP("Headset Stereophone", NULL),
97 static const struct snd_soc_dapm_route audio_map[] = {
98 /* External Mics: MAINMIC, SUBMIC with bias */
99 {"MAINMIC", NULL, "Ext Mic"},
100 {"SUBMIC", NULL, "Ext Mic"},
101 {"Ext Mic", NULL, "Mic Bias 1"},
102 {"Ext Mic", NULL, "Mic Bias 2"},
104 /* External Speakers: HFL, HFR */
105 {"Ext Spk", NULL, "HFL"},
106 {"Ext Spk", NULL, "HFR"},
108 /* Headset Mic: HSMIC with bias */
109 {"HSMIC", NULL, "Headset Mic"},
110 {"Headset Mic", NULL, "Headset Mic Bias"},
112 /* Headset Stereophone (Headphone): HSOL, HSOR */
113 {"Headset Stereophone", NULL, "HSOL"},
114 {"Headset Stereophone", NULL, "HSOR"},
117 static int sdp3430_twl4030_init(struct snd_soc_pcm_runtime *rtd)
119 struct snd_soc_codec *codec = rtd->codec;
120 struct snd_soc_dapm_context *dapm = &codec->dapm;
123 /* SDP3430 connected pins */
124 snd_soc_dapm_enable_pin(dapm, "Ext Mic");
125 snd_soc_dapm_enable_pin(dapm, "Ext Spk");
126 snd_soc_dapm_disable_pin(dapm, "Headset Mic");
127 snd_soc_dapm_disable_pin(dapm, "Headset Stereophone");
129 /* TWL4030 not connected pins */
130 snd_soc_dapm_nc_pin(dapm, "AUXL");
131 snd_soc_dapm_nc_pin(dapm, "AUXR");
132 snd_soc_dapm_nc_pin(dapm, "CARKITMIC");
133 snd_soc_dapm_nc_pin(dapm, "DIGIMIC0");
134 snd_soc_dapm_nc_pin(dapm, "DIGIMIC1");
136 snd_soc_dapm_nc_pin(dapm, "OUTL");
137 snd_soc_dapm_nc_pin(dapm, "OUTR");
138 snd_soc_dapm_nc_pin(dapm, "EARPIECE");
139 snd_soc_dapm_nc_pin(dapm, "PREDRIVEL");
140 snd_soc_dapm_nc_pin(dapm, "PREDRIVER");
141 snd_soc_dapm_nc_pin(dapm, "CARKITL");
142 snd_soc_dapm_nc_pin(dapm, "CARKITR");
144 /* Headset jack detection */
145 ret = snd_soc_jack_new(codec, "Headset Jack",
146 SND_JACK_HEADSET, &hs_jack);
150 ret = snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins),
155 ret = snd_soc_jack_add_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios),
161 /* Digital audio interface glue - connects codec <--> CPU */
162 static struct snd_soc_dai_link sdp3430_dai[] = {
164 .name = "TWL4030 I2S",
165 .stream_name = "TWL4030 Audio",
166 .cpu_dai_name = "omap-mcbsp.2",
167 .codec_dai_name = "twl4030-hifi",
168 .platform_name = "omap-pcm-audio",
169 .codec_name = "twl4030-codec",
170 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
171 SND_SOC_DAIFMT_CBM_CFM,
172 .init = sdp3430_twl4030_init,
176 .name = "TWL4030 PCM",
177 .stream_name = "TWL4030 Voice",
178 .cpu_dai_name = "omap-mcbsp.3",
179 .codec_dai_name = "twl4030-voice",
180 .platform_name = "omap-pcm-audio",
181 .codec_name = "twl4030-codec",
182 .dai_fmt = SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_IB_NF |
183 SND_SOC_DAIFMT_CBM_CFM,
188 /* Audio machine driver */
189 static struct snd_soc_card snd_soc_sdp3430 = {
191 .owner = THIS_MODULE,
192 .dai_link = sdp3430_dai,
193 .num_links = ARRAY_SIZE(sdp3430_dai),
195 .dapm_widgets = sdp3430_twl4030_dapm_widgets,
196 .num_dapm_widgets = ARRAY_SIZE(sdp3430_twl4030_dapm_widgets),
197 .dapm_routes = audio_map,
198 .num_dapm_routes = ARRAY_SIZE(audio_map),
201 static struct platform_device *sdp3430_snd_device;
203 static int __init sdp3430_soc_init(void)
207 if (!machine_is_omap_3430sdp())
209 printk(KERN_INFO "SDP3430 SoC init\n");
211 sdp3430_snd_device = platform_device_alloc("soc-audio", -1);
212 if (!sdp3430_snd_device) {
213 printk(KERN_ERR "Platform device allocation failed\n");
217 platform_set_drvdata(sdp3430_snd_device, &snd_soc_sdp3430);
219 ret = platform_device_add(sdp3430_snd_device);
226 printk(KERN_ERR "Unable to add platform device\n");
227 platform_device_put(sdp3430_snd_device);
231 module_init(sdp3430_soc_init);
233 static void __exit sdp3430_soc_exit(void)
235 snd_soc_jack_free_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios),
238 platform_device_unregister(sdp3430_snd_device);
240 module_exit(sdp3430_soc_exit);
242 MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>");
243 MODULE_DESCRIPTION("ALSA SoC SDP3430");
244 MODULE_LICENSE("GPL");