Commit | Line | Data |
---|---|---|
4451582f MLC |
1 | /* |
2 | * sdp3430.c -- SoC audio for TI OMAP3430 SDP | |
3 | * | |
4 | * Author: Misael Lopez Cruz <x0052729@ti.com> | |
5 | * | |
6 | * Based on: | |
7 | * Author: Steve Sakoman <steve@sakoman.com> | |
8 | * | |
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. | |
12 | * | |
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. | |
17 | * | |
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 | |
21 | * 02110-1301 USA | |
22 | * | |
23 | */ | |
24 | ||
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> | |
de0b9888 | 31 | #include <sound/jack.h> |
4451582f MLC |
32 | |
33 | #include <asm/mach-types.h> | |
34 | #include <mach/hardware.h> | |
35 | #include <mach/gpio.h> | |
36 | #include <mach/mcbsp.h> | |
37 | ||
38 | #include "omap-mcbsp.h" | |
39 | #include "omap-pcm.h" | |
40 | #include "../codecs/twl4030.h" | |
41 | ||
77dd7e17 LCM |
42 | static struct snd_soc_card snd_soc_sdp3430; |
43 | ||
4451582f MLC |
44 | static int sdp3430_hw_params(struct snd_pcm_substream *substream, |
45 | struct snd_pcm_hw_params *params) | |
46 | { | |
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; | |
50 | int ret; | |
51 | ||
52 | /* Set codec DAI configuration */ | |
53 | ret = snd_soc_dai_set_fmt(codec_dai, | |
54 | SND_SOC_DAIFMT_I2S | | |
55 | SND_SOC_DAIFMT_NB_NF | | |
56 | SND_SOC_DAIFMT_CBM_CFM); | |
57 | if (ret < 0) { | |
58 | printk(KERN_ERR "can't set codec DAI configuration\n"); | |
59 | return ret; | |
60 | } | |
61 | ||
62 | /* Set cpu DAI configuration */ | |
63 | ret = snd_soc_dai_set_fmt(cpu_dai, | |
64 | SND_SOC_DAIFMT_I2S | | |
65 | SND_SOC_DAIFMT_NB_NF | | |
66 | SND_SOC_DAIFMT_CBM_CFM); | |
67 | if (ret < 0) { | |
68 | printk(KERN_ERR "can't set cpu DAI configuration\n"); | |
69 | return ret; | |
70 | } | |
71 | ||
72 | /* Set the codec system clock for DAC and ADC */ | |
73 | ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000, | |
74 | SND_SOC_CLOCK_IN); | |
75 | if (ret < 0) { | |
76 | printk(KERN_ERR "can't set codec system clock\n"); | |
77 | return ret; | |
78 | } | |
79 | ||
80 | return 0; | |
81 | } | |
82 | ||
83 | static struct snd_soc_ops sdp3430_ops = { | |
84 | .hw_params = sdp3430_hw_params, | |
85 | }; | |
86 | ||
11a72811 LCM |
87 | static int sdp3430_hw_voice_params(struct snd_pcm_substream *substream, |
88 | struct snd_pcm_hw_params *params) | |
89 | { | |
90 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | |
91 | struct snd_soc_dai *codec_dai = rtd->dai->codec_dai; | |
92 | struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai; | |
93 | int ret; | |
94 | ||
95 | /* Set codec DAI configuration */ | |
96 | ret = snd_soc_dai_set_fmt(codec_dai, | |
97 | SND_SOC_DAIFMT_DSP_A | | |
98 | SND_SOC_DAIFMT_IB_NF | | |
c264301c | 99 | SND_SOC_DAIFMT_CBM_CFM); |
11a72811 LCM |
100 | if (ret) { |
101 | printk(KERN_ERR "can't set codec DAI configuration\n"); | |
102 | return ret; | |
103 | } | |
104 | ||
105 | /* Set cpu DAI configuration */ | |
106 | ret = snd_soc_dai_set_fmt(cpu_dai, | |
107 | SND_SOC_DAIFMT_DSP_A | | |
108 | SND_SOC_DAIFMT_IB_NF | | |
109 | SND_SOC_DAIFMT_CBM_CFM); | |
110 | if (ret < 0) { | |
111 | printk(KERN_ERR "can't set cpu DAI configuration\n"); | |
112 | return ret; | |
113 | } | |
114 | ||
115 | /* Set the codec system clock for DAC and ADC */ | |
116 | ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000, | |
117 | SND_SOC_CLOCK_IN); | |
118 | if (ret < 0) { | |
119 | printk(KERN_ERR "can't set codec system clock\n"); | |
120 | return ret; | |
121 | } | |
122 | ||
123 | return 0; | |
124 | } | |
125 | ||
126 | static struct snd_soc_ops sdp3430_voice_ops = { | |
127 | .hw_params = sdp3430_hw_voice_params, | |
128 | }; | |
129 | ||
77dd7e17 LCM |
130 | /* Headset jack */ |
131 | static struct snd_soc_jack hs_jack; | |
132 | ||
133 | /* Headset jack detection DAPM pins */ | |
134 | static struct snd_soc_jack_pin hs_jack_pins[] = { | |
135 | { | |
63208774 LCM |
136 | .pin = "Headset Mic", |
137 | .mask = SND_JACK_MICROPHONE, | |
138 | }, | |
139 | { | |
140 | .pin = "Headset Stereophone", | |
141 | .mask = SND_JACK_HEADPHONE, | |
77dd7e17 LCM |
142 | }, |
143 | }; | |
144 | ||
145 | /* Headset jack detection gpios */ | |
146 | static struct snd_soc_jack_gpio hs_jack_gpios[] = { | |
147 | { | |
148 | .gpio = (OMAP_MAX_GPIO_LINES + 2), | |
149 | .name = "hsdet-gpio", | |
150 | .report = SND_JACK_HEADSET, | |
151 | .debounce_time = 200, | |
152 | }, | |
153 | }; | |
154 | ||
979c036e LCM |
155 | /* SDP3430 machine DAPM */ |
156 | static const struct snd_soc_dapm_widget sdp3430_twl4030_dapm_widgets[] = { | |
157 | SND_SOC_DAPM_MIC("Ext Mic", NULL), | |
158 | SND_SOC_DAPM_SPK("Ext Spk", NULL), | |
63208774 LCM |
159 | SND_SOC_DAPM_MIC("Headset Mic", NULL), |
160 | SND_SOC_DAPM_HP("Headset Stereophone", NULL), | |
979c036e LCM |
161 | }; |
162 | ||
163 | static const struct snd_soc_dapm_route audio_map[] = { | |
164 | /* External Mics: MAINMIC, SUBMIC with bias*/ | |
165 | {"MAINMIC", NULL, "Mic Bias 1"}, | |
166 | {"SUBMIC", NULL, "Mic Bias 2"}, | |
167 | {"Mic Bias 1", NULL, "Ext Mic"}, | |
168 | {"Mic Bias 2", NULL, "Ext Mic"}, | |
169 | ||
170 | /* External Speakers: HFL, HFR */ | |
171 | {"Ext Spk", NULL, "HFL"}, | |
172 | {"Ext Spk", NULL, "HFR"}, | |
173 | ||
63208774 | 174 | /* Headset Mic: HSMIC with bias */ |
979c036e | 175 | {"HSMIC", NULL, "Headset Mic Bias"}, |
63208774 LCM |
176 | {"Headset Mic Bias", NULL, "Headset Mic"}, |
177 | ||
178 | /* Headset Stereophone (Headphone): HSOL, HSOR */ | |
179 | {"Headset Stereophone", NULL, "HSOL"}, | |
180 | {"Headset Stereophone", NULL, "HSOR"}, | |
979c036e LCM |
181 | }; |
182 | ||
183 | static int sdp3430_twl4030_init(struct snd_soc_codec *codec) | |
184 | { | |
185 | int ret; | |
186 | ||
187 | /* Add SDP3430 specific widgets */ | |
188 | ret = snd_soc_dapm_new_controls(codec, sdp3430_twl4030_dapm_widgets, | |
189 | ARRAY_SIZE(sdp3430_twl4030_dapm_widgets)); | |
190 | if (ret) | |
191 | return ret; | |
192 | ||
193 | /* Set up SDP3430 specific audio path audio_map */ | |
194 | snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); | |
195 | ||
196 | /* SDP3430 connected pins */ | |
197 | snd_soc_dapm_enable_pin(codec, "Ext Mic"); | |
198 | snd_soc_dapm_enable_pin(codec, "Ext Spk"); | |
63208774 LCM |
199 | snd_soc_dapm_disable_pin(codec, "Headset Mic"); |
200 | snd_soc_dapm_disable_pin(codec, "Headset Stereophone"); | |
979c036e LCM |
201 | |
202 | /* TWL4030 not connected pins */ | |
203 | snd_soc_dapm_nc_pin(codec, "AUXL"); | |
204 | snd_soc_dapm_nc_pin(codec, "AUXR"); | |
205 | snd_soc_dapm_nc_pin(codec, "CARKITMIC"); | |
206 | snd_soc_dapm_nc_pin(codec, "DIGIMIC0"); | |
207 | snd_soc_dapm_nc_pin(codec, "DIGIMIC1"); | |
208 | ||
209 | snd_soc_dapm_nc_pin(codec, "OUTL"); | |
210 | snd_soc_dapm_nc_pin(codec, "OUTR"); | |
211 | snd_soc_dapm_nc_pin(codec, "EARPIECE"); | |
212 | snd_soc_dapm_nc_pin(codec, "PREDRIVEL"); | |
213 | snd_soc_dapm_nc_pin(codec, "PREDRIVER"); | |
214 | snd_soc_dapm_nc_pin(codec, "CARKITL"); | |
215 | snd_soc_dapm_nc_pin(codec, "CARKITR"); | |
216 | ||
217 | ret = snd_soc_dapm_sync(codec); | |
77dd7e17 LCM |
218 | if (ret) |
219 | return ret; | |
979c036e | 220 | |
77dd7e17 LCM |
221 | /* Headset jack detection */ |
222 | ret = snd_soc_jack_new(&snd_soc_sdp3430, "Headset Jack", | |
223 | SND_JACK_HEADSET, &hs_jack); | |
224 | if (ret) | |
225 | return ret; | |
979c036e | 226 | |
77dd7e17 LCM |
227 | ret = snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins), |
228 | hs_jack_pins); | |
229 | if (ret) | |
230 | return ret; | |
de0b9888 | 231 | |
77dd7e17 LCM |
232 | ret = snd_soc_jack_add_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios), |
233 | hs_jack_gpios); | |
de0b9888 | 234 | |
77dd7e17 LCM |
235 | return ret; |
236 | } | |
de0b9888 | 237 | |
11a72811 LCM |
238 | static int sdp3430_twl4030_voice_init(struct snd_soc_codec *codec) |
239 | { | |
240 | unsigned short reg; | |
241 | ||
242 | /* Enable voice interface */ | |
243 | reg = codec->read(codec, TWL4030_REG_VOICE_IF); | |
244 | reg |= TWL4030_VIF_DIN_EN | TWL4030_VIF_DOUT_EN | TWL4030_VIF_EN; | |
245 | codec->write(codec, TWL4030_REG_VOICE_IF, reg); | |
246 | ||
247 | return 0; | |
248 | } | |
249 | ||
250 | ||
4451582f | 251 | /* Digital audio interface glue - connects codec <--> CPU */ |
11a72811 LCM |
252 | static struct snd_soc_dai_link sdp3430_dai[] = { |
253 | { | |
254 | .name = "TWL4030 I2S", | |
255 | .stream_name = "TWL4030 Audio", | |
256 | .cpu_dai = &omap_mcbsp_dai[0], | |
257 | .codec_dai = &twl4030_dai[TWL4030_DAI_HIFI], | |
258 | .init = sdp3430_twl4030_init, | |
259 | .ops = &sdp3430_ops, | |
260 | }, | |
261 | { | |
262 | .name = "TWL4030 PCM", | |
263 | .stream_name = "TWL4030 Voice", | |
264 | .cpu_dai = &omap_mcbsp_dai[1], | |
265 | .codec_dai = &twl4030_dai[TWL4030_DAI_VOICE], | |
266 | .init = sdp3430_twl4030_voice_init, | |
267 | .ops = &sdp3430_voice_ops, | |
268 | }, | |
4451582f MLC |
269 | }; |
270 | ||
271 | /* Audio machine driver */ | |
272edb00 | 272 | static struct snd_soc_card snd_soc_sdp3430 = { |
4451582f | 273 | .name = "SDP3430", |
87689d56 | 274 | .platform = &omap_soc_platform, |
11a72811 LCM |
275 | .dai_link = sdp3430_dai, |
276 | .num_links = ARRAY_SIZE(sdp3430_dai), | |
4451582f MLC |
277 | }; |
278 | ||
7385ba44 PU |
279 | /* twl4030 setup */ |
280 | static struct twl4030_setup_data twl4030_setup = { | |
281 | .ramp_delay_value = 3, | |
282 | .sysclk = 26000, | |
283 | }; | |
284 | ||
4451582f MLC |
285 | /* Audio subsystem */ |
286 | static struct snd_soc_device sdp3430_snd_devdata = { | |
272edb00 | 287 | .card = &snd_soc_sdp3430, |
4451582f | 288 | .codec_dev = &soc_codec_dev_twl4030, |
7385ba44 | 289 | .codec_data = &twl4030_setup, |
4451582f MLC |
290 | }; |
291 | ||
292 | static struct platform_device *sdp3430_snd_device; | |
293 | ||
294 | static int __init sdp3430_soc_init(void) | |
295 | { | |
296 | int ret; | |
297 | ||
298 | if (!machine_is_omap_3430sdp()) { | |
299 | pr_debug("Not SDP3430!\n"); | |
300 | return -ENODEV; | |
301 | } | |
302 | printk(KERN_INFO "SDP3430 SoC init\n"); | |
303 | ||
304 | sdp3430_snd_device = platform_device_alloc("soc-audio", -1); | |
305 | if (!sdp3430_snd_device) { | |
306 | printk(KERN_ERR "Platform device allocation failed\n"); | |
307 | return -ENOMEM; | |
308 | } | |
309 | ||
310 | platform_set_drvdata(sdp3430_snd_device, &sdp3430_snd_devdata); | |
311 | sdp3430_snd_devdata.dev = &sdp3430_snd_device->dev; | |
11a72811 LCM |
312 | *(unsigned int *)sdp3430_dai[0].cpu_dai->private_data = 1; /* McBSP2 */ |
313 | *(unsigned int *)sdp3430_dai[1].cpu_dai->private_data = 2; /* McBSP3 */ | |
4451582f MLC |
314 | |
315 | ret = platform_device_add(sdp3430_snd_device); | |
316 | if (ret) | |
317 | goto err1; | |
318 | ||
77dd7e17 | 319 | return 0; |
4451582f MLC |
320 | |
321 | err1: | |
322 | printk(KERN_ERR "Unable to add platform device\n"); | |
323 | platform_device_put(sdp3430_snd_device); | |
324 | ||
325 | return ret; | |
326 | } | |
327 | module_init(sdp3430_soc_init); | |
328 | ||
329 | static void __exit sdp3430_soc_exit(void) | |
330 | { | |
de0b9888 LCM |
331 | snd_soc_jack_free_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios), |
332 | hs_jack_gpios); | |
333 | ||
4451582f MLC |
334 | platform_device_unregister(sdp3430_snd_device); |
335 | } | |
336 | module_exit(sdp3430_soc_exit); | |
337 | ||
338 | MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>"); | |
339 | MODULE_DESCRIPTION("ALSA SoC SDP3430"); | |
340 | MODULE_LICENSE("GPL"); | |
341 |