blob: 76ce77b91844871f53481afbab751dc394e51bc8 [file] [log] [blame]
Misael Lopez Cruz44515822008-11-24 22:21:23 -06001/*
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>
Balaji T Kebeb53e2009-12-15 20:09:02 +053027#include <linux/i2c/twl.h>
Misael Lopez Cruz44515822008-11-24 22:21:23 -060028#include <sound/core.h>
29#include <sound/pcm.h>
30#include <sound/soc.h>
31#include <sound/soc-dapm.h>
Lopez Cruz, Misaelde0b9882009-03-05 11:32:31 -060032#include <sound/jack.h>
Misael Lopez Cruz44515822008-11-24 22:21:23 -060033
34#include <asm/mach-types.h>
35#include <mach/hardware.h>
36#include <mach/gpio.h>
Tony Lindgrence491cf2009-10-20 09:40:47 -070037#include <plat/mcbsp.h>
Misael Lopez Cruz44515822008-11-24 22:21:23 -060038
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000039/* Register descriptions for twl4030 codec part */
40#include <linux/mfd/twl4030-codec.h>
41
Misael Lopez Cruz44515822008-11-24 22:21:23 -060042#include "omap-mcbsp.h"
43#include "omap-pcm.h"
Misael Lopez Cruz44515822008-11-24 22:21:23 -060044
Candelaria Villareal, Jorge30cd0c4a2009-08-25 10:13:25 -050045/* 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)
Candelaria Villareal, Jorgec5910a72009-07-14 20:04:08 -050049
Lopez Cruz, Misael77dd7e12009-03-12 21:45:27 -050050static struct snd_soc_card snd_soc_sdp3430;
51
Misael Lopez Cruz44515822008-11-24 22:21:23 -060052static int sdp3430_hw_params(struct snd_pcm_substream *substream,
53 struct snd_pcm_hw_params *params)
54{
55 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000056 struct snd_soc_dai *codec_dai = rtd->codec_dai;
57 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Misael Lopez Cruz44515822008-11-24 22:21:23 -060058 int ret;
59
60 /* Set codec DAI configuration */
61 ret = snd_soc_dai_set_fmt(codec_dai,
62 SND_SOC_DAIFMT_I2S |
63 SND_SOC_DAIFMT_NB_NF |
64 SND_SOC_DAIFMT_CBM_CFM);
65 if (ret < 0) {
66 printk(KERN_ERR "can't set codec DAI configuration\n");
67 return ret;
68 }
69
70 /* Set cpu DAI configuration */
71 ret = snd_soc_dai_set_fmt(cpu_dai,
72 SND_SOC_DAIFMT_I2S |
73 SND_SOC_DAIFMT_NB_NF |
74 SND_SOC_DAIFMT_CBM_CFM);
75 if (ret < 0) {
76 printk(KERN_ERR "can't set cpu DAI configuration\n");
77 return ret;
78 }
79
80 /* Set the codec system clock for DAC and ADC */
81 ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
82 SND_SOC_CLOCK_IN);
83 if (ret < 0) {
84 printk(KERN_ERR "can't set codec system clock\n");
85 return ret;
86 }
87
88 return 0;
89}
90
91static struct snd_soc_ops sdp3430_ops = {
92 .hw_params = sdp3430_hw_params,
93};
94
Lopez Cruz, Misael11a72812009-05-18 11:53:04 -050095static int sdp3430_hw_voice_params(struct snd_pcm_substream *substream,
96 struct snd_pcm_hw_params *params)
97{
98 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000099 struct snd_soc_dai *codec_dai = rtd->codec_dai;
100 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Lopez Cruz, Misael11a72812009-05-18 11:53:04 -0500101 int ret;
102
103 /* Set codec DAI configuration */
104 ret = snd_soc_dai_set_fmt(codec_dai,
105 SND_SOC_DAIFMT_DSP_A |
106 SND_SOC_DAIFMT_IB_NF |
Lopez Cruz, Misaelc2643012009-06-19 03:23:42 -0500107 SND_SOC_DAIFMT_CBM_CFM);
Lopez Cruz, Misael11a72812009-05-18 11:53:04 -0500108 if (ret) {
109 printk(KERN_ERR "can't set codec DAI configuration\n");
110 return ret;
111 }
112
113 /* Set cpu DAI configuration */
114 ret = snd_soc_dai_set_fmt(cpu_dai,
115 SND_SOC_DAIFMT_DSP_A |
116 SND_SOC_DAIFMT_IB_NF |
117 SND_SOC_DAIFMT_CBM_CFM);
118 if (ret < 0) {
119 printk(KERN_ERR "can't set cpu DAI configuration\n");
120 return ret;
121 }
122
123 /* Set the codec system clock for DAC and ADC */
124 ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
125 SND_SOC_CLOCK_IN);
126 if (ret < 0) {
127 printk(KERN_ERR "can't set codec system clock\n");
128 return ret;
129 }
130
131 return 0;
132}
133
134static struct snd_soc_ops sdp3430_voice_ops = {
135 .hw_params = sdp3430_hw_voice_params,
136};
137
Lopez Cruz, Misael77dd7e12009-03-12 21:45:27 -0500138/* Headset jack */
139static struct snd_soc_jack hs_jack;
140
141/* Headset jack detection DAPM pins */
142static struct snd_soc_jack_pin hs_jack_pins[] = {
143 {
Lopez Cruz, Misael63208772009-03-19 01:07:34 -0500144 .pin = "Headset Mic",
145 .mask = SND_JACK_MICROPHONE,
146 },
147 {
148 .pin = "Headset Stereophone",
149 .mask = SND_JACK_HEADPHONE,
Lopez Cruz, Misael77dd7e12009-03-12 21:45:27 -0500150 },
151};
152
153/* Headset jack detection gpios */
154static struct snd_soc_jack_gpio hs_jack_gpios[] = {
155 {
156 .gpio = (OMAP_MAX_GPIO_LINES + 2),
157 .name = "hsdet-gpio",
158 .report = SND_JACK_HEADSET,
159 .debounce_time = 200,
160 },
161};
162
Lopez Cruz, Misael979c0362009-03-04 11:39:07 -0600163/* SDP3430 machine DAPM */
164static const struct snd_soc_dapm_widget sdp3430_twl4030_dapm_widgets[] = {
165 SND_SOC_DAPM_MIC("Ext Mic", NULL),
166 SND_SOC_DAPM_SPK("Ext Spk", NULL),
Lopez Cruz, Misael63208772009-03-19 01:07:34 -0500167 SND_SOC_DAPM_MIC("Headset Mic", NULL),
168 SND_SOC_DAPM_HP("Headset Stereophone", NULL),
Lopez Cruz, Misael979c0362009-03-04 11:39:07 -0600169};
170
171static const struct snd_soc_dapm_route audio_map[] = {
172 /* External Mics: MAINMIC, SUBMIC with bias*/
173 {"MAINMIC", NULL, "Mic Bias 1"},
174 {"SUBMIC", NULL, "Mic Bias 2"},
175 {"Mic Bias 1", NULL, "Ext Mic"},
176 {"Mic Bias 2", NULL, "Ext Mic"},
177
178 /* External Speakers: HFL, HFR */
179 {"Ext Spk", NULL, "HFL"},
180 {"Ext Spk", NULL, "HFR"},
181
Lopez Cruz, Misael63208772009-03-19 01:07:34 -0500182 /* Headset Mic: HSMIC with bias */
Lopez Cruz, Misael979c0362009-03-04 11:39:07 -0600183 {"HSMIC", NULL, "Headset Mic Bias"},
Lopez Cruz, Misael63208772009-03-19 01:07:34 -0500184 {"Headset Mic Bias", NULL, "Headset Mic"},
185
186 /* Headset Stereophone (Headphone): HSOL, HSOR */
187 {"Headset Stereophone", NULL, "HSOL"},
188 {"Headset Stereophone", NULL, "HSOR"},
Lopez Cruz, Misael979c0362009-03-04 11:39:07 -0600189};
190
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000191static int sdp3430_twl4030_init(struct snd_soc_pcm_runtime *rtd)
Lopez Cruz, Misael979c0362009-03-04 11:39:07 -0600192{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000193 struct snd_soc_codec *codec = rtd->codec;
Lopez Cruz, Misael979c0362009-03-04 11:39:07 -0600194 int ret;
195
196 /* Add SDP3430 specific widgets */
197 ret = snd_soc_dapm_new_controls(codec, sdp3430_twl4030_dapm_widgets,
198 ARRAY_SIZE(sdp3430_twl4030_dapm_widgets));
199 if (ret)
200 return ret;
201
202 /* Set up SDP3430 specific audio path audio_map */
203 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
204
205 /* SDP3430 connected pins */
206 snd_soc_dapm_enable_pin(codec, "Ext Mic");
207 snd_soc_dapm_enable_pin(codec, "Ext Spk");
Lopez Cruz, Misael63208772009-03-19 01:07:34 -0500208 snd_soc_dapm_disable_pin(codec, "Headset Mic");
209 snd_soc_dapm_disable_pin(codec, "Headset Stereophone");
Lopez Cruz, Misael979c0362009-03-04 11:39:07 -0600210
211 /* TWL4030 not connected pins */
212 snd_soc_dapm_nc_pin(codec, "AUXL");
213 snd_soc_dapm_nc_pin(codec, "AUXR");
214 snd_soc_dapm_nc_pin(codec, "CARKITMIC");
215 snd_soc_dapm_nc_pin(codec, "DIGIMIC0");
216 snd_soc_dapm_nc_pin(codec, "DIGIMIC1");
217
218 snd_soc_dapm_nc_pin(codec, "OUTL");
219 snd_soc_dapm_nc_pin(codec, "OUTR");
220 snd_soc_dapm_nc_pin(codec, "EARPIECE");
221 snd_soc_dapm_nc_pin(codec, "PREDRIVEL");
222 snd_soc_dapm_nc_pin(codec, "PREDRIVER");
223 snd_soc_dapm_nc_pin(codec, "CARKITL");
224 snd_soc_dapm_nc_pin(codec, "CARKITR");
225
226 ret = snd_soc_dapm_sync(codec);
Lopez Cruz, Misael77dd7e12009-03-12 21:45:27 -0500227 if (ret)
228 return ret;
229
230 /* Headset jack detection */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000231 ret = snd_soc_jack_new(codec, "Headset Jack",
Lopez Cruz, Misael77dd7e12009-03-12 21:45:27 -0500232 SND_JACK_HEADSET, &hs_jack);
233 if (ret)
234 return ret;
235
236 ret = snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins),
237 hs_jack_pins);
238 if (ret)
239 return ret;
240
241 ret = snd_soc_jack_add_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios),
242 hs_jack_gpios);
Lopez Cruz, Misael979c0362009-03-04 11:39:07 -0600243
244 return ret;
245}
246
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000247static int sdp3430_twl4030_voice_init(struct snd_soc_pcm_runtime *rtd)
Lopez Cruz, Misael11a72812009-05-18 11:53:04 -0500248{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000249 struct snd_soc_codec *codec = rtd->codec;
Lopez Cruz, Misael11a72812009-05-18 11:53:04 -0500250 unsigned short reg;
251
252 /* Enable voice interface */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000253 reg = codec->driver->read(codec, TWL4030_REG_VOICE_IF);
Lopez Cruz, Misael11a72812009-05-18 11:53:04 -0500254 reg |= TWL4030_VIF_DIN_EN | TWL4030_VIF_DOUT_EN | TWL4030_VIF_EN;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000255 codec->driver->write(codec, TWL4030_REG_VOICE_IF, reg);
Lopez Cruz, Misael11a72812009-05-18 11:53:04 -0500256
257 return 0;
258}
259
260
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600261/* Digital audio interface glue - connects codec <--> CPU */
Lopez Cruz, Misael11a72812009-05-18 11:53:04 -0500262static struct snd_soc_dai_link sdp3430_dai[] = {
263 {
264 .name = "TWL4030 I2S",
265 .stream_name = "TWL4030 Audio",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000266 .cpu_dai_name = "omap-mcbsp-dai.1",
267 .codec_dai_name = "twl4030-hifi",
268 .platform_name = "omap-pcm-audio",
269 .codec_name = "twl4030-codec",
Lopez Cruz, Misael11a72812009-05-18 11:53:04 -0500270 .init = sdp3430_twl4030_init,
271 .ops = &sdp3430_ops,
272 },
273 {
274 .name = "TWL4030 PCM",
275 .stream_name = "TWL4030 Voice",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000276 .cpu_dai_name = "omap-mcbsp-dai.2",
277 .codec_dai_name = "twl4030-voice",
278 .platform_name = "omap-pcm-audio",
279 .codec_name = "twl4030-codec",
Lopez Cruz, Misael11a72812009-05-18 11:53:04 -0500280 .init = sdp3430_twl4030_voice_init,
281 .ops = &sdp3430_voice_ops,
282 },
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600283};
284
285/* Audio machine driver */
Lopez Cruz, Misael272edb02009-02-10 02:05:07 -0600286static struct snd_soc_card snd_soc_sdp3430 = {
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600287 .name = "SDP3430",
Lopez Cruz, Misael11a72812009-05-18 11:53:04 -0500288 .dai_link = sdp3430_dai,
289 .num_links = ARRAY_SIZE(sdp3430_dai),
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600290};
291
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600292static struct platform_device *sdp3430_snd_device;
293
294static int __init sdp3430_soc_init(void)
295{
296 int ret;
Candelaria Villareal, Jorge30cd0c4a2009-08-25 10:13:25 -0500297 u8 pin_mux;
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600298
299 if (!machine_is_omap_3430sdp()) {
300 pr_debug("Not SDP3430!\n");
301 return -ENODEV;
302 }
303 printk(KERN_INFO "SDP3430 SoC init\n");
304
305 sdp3430_snd_device = platform_device_alloc("soc-audio", -1);
306 if (!sdp3430_snd_device) {
307 printk(KERN_ERR "Platform device allocation failed\n");
308 return -ENOMEM;
309 }
310
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000311 platform_set_drvdata(sdp3430_snd_device, &snd_soc_sdp3430);
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600312
Candelaria Villareal, Jorgec5910a72009-07-14 20:04:08 -0500313 /* Set TWL4030 GPIO6 as EXTMUTE signal */
Balaji T Kebeb53e2009-12-15 20:09:02 +0530314 twl_i2c_read_u8(TWL4030_MODULE_INTBR, &pin_mux,
Candelaria Villareal, Jorge30cd0c4a2009-08-25 10:13:25 -0500315 TWL4030_INTBR_PMBR1);
316 pin_mux &= ~TWL4030_GPIO6_PWM0_MUTE(0x03);
317 pin_mux |= TWL4030_GPIO6_PWM0_MUTE(0x02);
Balaji T Kebeb53e2009-12-15 20:09:02 +0530318 twl_i2c_write_u8(TWL4030_MODULE_INTBR, pin_mux,
Candelaria Villareal, Jorge30cd0c4a2009-08-25 10:13:25 -0500319 TWL4030_INTBR_PMBR1);
Candelaria Villareal, Jorgec5910a72009-07-14 20:04:08 -0500320
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600321 ret = platform_device_add(sdp3430_snd_device);
322 if (ret)
323 goto err1;
324
Lopez Cruz, Misael77dd7e12009-03-12 21:45:27 -0500325 return 0;
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600326
327err1:
328 printk(KERN_ERR "Unable to add platform device\n");
329 platform_device_put(sdp3430_snd_device);
330
331 return ret;
332}
333module_init(sdp3430_soc_init);
334
335static void __exit sdp3430_soc_exit(void)
336{
Lopez Cruz, Misaelde0b9882009-03-05 11:32:31 -0600337 snd_soc_jack_free_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios),
338 hs_jack_gpios);
339
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600340 platform_device_unregister(sdp3430_snd_device);
341}
342module_exit(sdp3430_soc_exit);
343
344MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>");
345MODULE_DESCRIPTION("ALSA SoC SDP3430");
346MODULE_LICENSE("GPL");
347