blob: 269aded8a6becc38231abb3362086aa51a797bd2 [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>
Lopez Cruz, Misaelde0b9882009-03-05 11:32:31 -060031#include <sound/jack.h>
Misael Lopez Cruz44515822008-11-24 22:21:23 -060032
33#include <asm/mach-types.h>
34#include <mach/hardware.h>
35#include <mach/gpio.h>
Tony Lindgrence491cf2009-10-20 09:40:47 -070036#include <plat/mcbsp.h>
Misael Lopez Cruz44515822008-11-24 22:21:23 -060037
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000038/* Register descriptions for twl4030 codec part */
Peter Ujfalusi57fe7252011-05-31 12:02:49 +030039#include <linux/mfd/twl4030-audio.h>
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000040
Misael Lopez Cruz44515822008-11-24 22:21:23 -060041#include "omap-mcbsp.h"
42#include "omap-pcm.h"
Misael Lopez Cruz44515822008-11-24 22:21:23 -060043
Candelaria Villareal, Jorge30cd0c42009-08-25 10:13:25 -050044/* TWL4030 PMBR1 Register */
45#define TWL4030_INTBR_PMBR1 0x0D
46/* TWL4030 PMBR1 Register GPIO6 mux bit */
47#define TWL4030_GPIO6_PWM0_MUTE(value) (value << 2)
Candelaria Villareal, Jorgec5910a72009-07-14 20:04:08 -050048
Lopez Cruz, Misael77dd7e12009-03-12 21:45:27 -050049static struct snd_soc_card snd_soc_sdp3430;
50
Misael Lopez Cruz44515822008-11-24 22:21:23 -060051static int sdp3430_hw_params(struct snd_pcm_substream *substream,
52 struct snd_pcm_hw_params *params)
53{
54 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000055 struct snd_soc_dai *codec_dai = rtd->codec_dai;
Misael Lopez Cruz44515822008-11-24 22:21:23 -060056 int ret;
57
Misael Lopez Cruz44515822008-11-24 22:21:23 -060058 /* Set the codec system clock for DAC and ADC */
59 ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
60 SND_SOC_CLOCK_IN);
61 if (ret < 0) {
62 printk(KERN_ERR "can't set codec system clock\n");
63 return ret;
64 }
65
66 return 0;
67}
68
69static struct snd_soc_ops sdp3430_ops = {
70 .hw_params = sdp3430_hw_params,
71};
72
Lopez Cruz, Misael77dd7e12009-03-12 21:45:27 -050073/* Headset jack */
74static struct snd_soc_jack hs_jack;
75
76/* Headset jack detection DAPM pins */
77static struct snd_soc_jack_pin hs_jack_pins[] = {
78 {
Lopez Cruz, Misael63208772009-03-19 01:07:34 -050079 .pin = "Headset Mic",
80 .mask = SND_JACK_MICROPHONE,
81 },
82 {
83 .pin = "Headset Stereophone",
84 .mask = SND_JACK_HEADPHONE,
Lopez Cruz, Misael77dd7e12009-03-12 21:45:27 -050085 },
86};
87
88/* Headset jack detection gpios */
89static struct snd_soc_jack_gpio hs_jack_gpios[] = {
90 {
91 .gpio = (OMAP_MAX_GPIO_LINES + 2),
92 .name = "hsdet-gpio",
93 .report = SND_JACK_HEADSET,
94 .debounce_time = 200,
95 },
96};
97
Lopez Cruz, Misael979c0362009-03-04 11:39:07 -060098/* SDP3430 machine DAPM */
99static const struct snd_soc_dapm_widget sdp3430_twl4030_dapm_widgets[] = {
100 SND_SOC_DAPM_MIC("Ext Mic", NULL),
101 SND_SOC_DAPM_SPK("Ext Spk", NULL),
Lopez Cruz, Misael63208772009-03-19 01:07:34 -0500102 SND_SOC_DAPM_MIC("Headset Mic", NULL),
103 SND_SOC_DAPM_HP("Headset Stereophone", NULL),
Lopez Cruz, Misael979c0362009-03-04 11:39:07 -0600104};
105
106static const struct snd_soc_dapm_route audio_map[] = {
107 /* External Mics: MAINMIC, SUBMIC with bias*/
108 {"MAINMIC", NULL, "Mic Bias 1"},
109 {"SUBMIC", NULL, "Mic Bias 2"},
110 {"Mic Bias 1", NULL, "Ext Mic"},
111 {"Mic Bias 2", NULL, "Ext Mic"},
112
113 /* External Speakers: HFL, HFR */
114 {"Ext Spk", NULL, "HFL"},
115 {"Ext Spk", NULL, "HFR"},
116
Lopez Cruz, Misael63208772009-03-19 01:07:34 -0500117 /* Headset Mic: HSMIC with bias */
Lopez Cruz, Misael979c0362009-03-04 11:39:07 -0600118 {"HSMIC", NULL, "Headset Mic Bias"},
Lopez Cruz, Misael63208772009-03-19 01:07:34 -0500119 {"Headset Mic Bias", NULL, "Headset Mic"},
120
121 /* Headset Stereophone (Headphone): HSOL, HSOR */
122 {"Headset Stereophone", NULL, "HSOL"},
123 {"Headset Stereophone", NULL, "HSOR"},
Lopez Cruz, Misael979c0362009-03-04 11:39:07 -0600124};
125
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000126static int sdp3430_twl4030_init(struct snd_soc_pcm_runtime *rtd)
Lopez Cruz, Misael979c0362009-03-04 11:39:07 -0600127{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000128 struct snd_soc_codec *codec = rtd->codec;
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200129 struct snd_soc_dapm_context *dapm = &codec->dapm;
Lopez Cruz, Misael979c0362009-03-04 11:39:07 -0600130 int ret;
131
132 /* Add SDP3430 specific widgets */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200133 ret = snd_soc_dapm_new_controls(dapm, sdp3430_twl4030_dapm_widgets,
Lopez Cruz, Misael979c0362009-03-04 11:39:07 -0600134 ARRAY_SIZE(sdp3430_twl4030_dapm_widgets));
135 if (ret)
136 return ret;
137
138 /* Set up SDP3430 specific audio path audio_map */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200139 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
Lopez Cruz, Misael979c0362009-03-04 11:39:07 -0600140
141 /* SDP3430 connected pins */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200142 snd_soc_dapm_enable_pin(dapm, "Ext Mic");
143 snd_soc_dapm_enable_pin(dapm, "Ext Spk");
144 snd_soc_dapm_disable_pin(dapm, "Headset Mic");
145 snd_soc_dapm_disable_pin(dapm, "Headset Stereophone");
Lopez Cruz, Misael979c0362009-03-04 11:39:07 -0600146
147 /* TWL4030 not connected pins */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200148 snd_soc_dapm_nc_pin(dapm, "AUXL");
149 snd_soc_dapm_nc_pin(dapm, "AUXR");
150 snd_soc_dapm_nc_pin(dapm, "CARKITMIC");
151 snd_soc_dapm_nc_pin(dapm, "DIGIMIC0");
152 snd_soc_dapm_nc_pin(dapm, "DIGIMIC1");
Lopez Cruz, Misael979c0362009-03-04 11:39:07 -0600153
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200154 snd_soc_dapm_nc_pin(dapm, "OUTL");
155 snd_soc_dapm_nc_pin(dapm, "OUTR");
156 snd_soc_dapm_nc_pin(dapm, "EARPIECE");
157 snd_soc_dapm_nc_pin(dapm, "PREDRIVEL");
158 snd_soc_dapm_nc_pin(dapm, "PREDRIVER");
159 snd_soc_dapm_nc_pin(dapm, "CARKITL");
160 snd_soc_dapm_nc_pin(dapm, "CARKITR");
Lopez Cruz, Misael979c0362009-03-04 11:39:07 -0600161
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200162 ret = snd_soc_dapm_sync(dapm);
Lopez Cruz, Misael77dd7e12009-03-12 21:45:27 -0500163 if (ret)
164 return ret;
165
166 /* Headset jack detection */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000167 ret = snd_soc_jack_new(codec, "Headset Jack",
Lopez Cruz, Misael77dd7e12009-03-12 21:45:27 -0500168 SND_JACK_HEADSET, &hs_jack);
169 if (ret)
170 return ret;
171
172 ret = snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins),
173 hs_jack_pins);
174 if (ret)
175 return ret;
176
177 ret = snd_soc_jack_add_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios),
178 hs_jack_gpios);
Lopez Cruz, Misael979c0362009-03-04 11:39:07 -0600179
180 return ret;
181}
182
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000183static int sdp3430_twl4030_voice_init(struct snd_soc_pcm_runtime *rtd)
Lopez Cruz, Misael11a72812009-05-18 11:53:04 -0500184{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000185 struct snd_soc_codec *codec = rtd->codec;
Lopez Cruz, Misael11a72812009-05-18 11:53:04 -0500186 unsigned short reg;
187
188 /* Enable voice interface */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000189 reg = codec->driver->read(codec, TWL4030_REG_VOICE_IF);
Lopez Cruz, Misael11a72812009-05-18 11:53:04 -0500190 reg |= TWL4030_VIF_DIN_EN | TWL4030_VIF_DOUT_EN | TWL4030_VIF_EN;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000191 codec->driver->write(codec, TWL4030_REG_VOICE_IF, reg);
Lopez Cruz, Misael11a72812009-05-18 11:53:04 -0500192
193 return 0;
194}
195
196
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600197/* Digital audio interface glue - connects codec <--> CPU */
Lopez Cruz, Misael11a72812009-05-18 11:53:04 -0500198static struct snd_soc_dai_link sdp3430_dai[] = {
199 {
200 .name = "TWL4030 I2S",
201 .stream_name = "TWL4030 Audio",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000202 .cpu_dai_name = "omap-mcbsp-dai.1",
203 .codec_dai_name = "twl4030-hifi",
204 .platform_name = "omap-pcm-audio",
205 .codec_name = "twl4030-codec",
Jarkko Nikulacf9feff2011-09-30 16:07:45 +0300206 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
207 SND_SOC_DAIFMT_CBM_CFM,
Lopez Cruz, Misael11a72812009-05-18 11:53:04 -0500208 .init = sdp3430_twl4030_init,
209 .ops = &sdp3430_ops,
210 },
211 {
212 .name = "TWL4030 PCM",
213 .stream_name = "TWL4030 Voice",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000214 .cpu_dai_name = "omap-mcbsp-dai.2",
215 .codec_dai_name = "twl4030-voice",
216 .platform_name = "omap-pcm-audio",
217 .codec_name = "twl4030-codec",
Jarkko Nikulacf9feff2011-09-30 16:07:45 +0300218 .dai_fmt = SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_IB_NF |
219 SND_SOC_DAIFMT_CBM_CFM,
Lopez Cruz, Misael11a72812009-05-18 11:53:04 -0500220 .init = sdp3430_twl4030_voice_init,
Jarkko Nikulaa3c6dac2011-09-30 16:07:46 +0300221 .ops = &sdp3430_ops,
Lopez Cruz, Misael11a72812009-05-18 11:53:04 -0500222 },
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600223};
224
225/* Audio machine driver */
Lopez Cruz, Misael272edb02009-02-10 02:05:07 -0600226static struct snd_soc_card snd_soc_sdp3430 = {
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600227 .name = "SDP3430",
Lopez Cruz, Misael11a72812009-05-18 11:53:04 -0500228 .dai_link = sdp3430_dai,
229 .num_links = ARRAY_SIZE(sdp3430_dai),
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600230};
231
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600232static struct platform_device *sdp3430_snd_device;
233
234static int __init sdp3430_soc_init(void)
235{
236 int ret;
Candelaria Villareal, Jorge30cd0c42009-08-25 10:13:25 -0500237 u8 pin_mux;
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600238
Jarkko Nikulaec588ae2010-10-06 16:47:26 +0300239 if (!machine_is_omap_3430sdp())
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600240 return -ENODEV;
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600241 printk(KERN_INFO "SDP3430 SoC init\n");
242
243 sdp3430_snd_device = platform_device_alloc("soc-audio", -1);
244 if (!sdp3430_snd_device) {
245 printk(KERN_ERR "Platform device allocation failed\n");
246 return -ENOMEM;
247 }
248
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000249 platform_set_drvdata(sdp3430_snd_device, &snd_soc_sdp3430);
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600250
Candelaria Villareal, Jorgec5910a72009-07-14 20:04:08 -0500251 /* Set TWL4030 GPIO6 as EXTMUTE signal */
Balaji T Kebeb53e2009-12-15 20:09:02 +0530252 twl_i2c_read_u8(TWL4030_MODULE_INTBR, &pin_mux,
Candelaria Villareal, Jorge30cd0c42009-08-25 10:13:25 -0500253 TWL4030_INTBR_PMBR1);
254 pin_mux &= ~TWL4030_GPIO6_PWM0_MUTE(0x03);
255 pin_mux |= TWL4030_GPIO6_PWM0_MUTE(0x02);
Balaji T Kebeb53e2009-12-15 20:09:02 +0530256 twl_i2c_write_u8(TWL4030_MODULE_INTBR, pin_mux,
Candelaria Villareal, Jorge30cd0c42009-08-25 10:13:25 -0500257 TWL4030_INTBR_PMBR1);
Candelaria Villareal, Jorgec5910a72009-07-14 20:04:08 -0500258
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600259 ret = platform_device_add(sdp3430_snd_device);
260 if (ret)
261 goto err1;
262
Lopez Cruz, Misael77dd7e12009-03-12 21:45:27 -0500263 return 0;
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600264
265err1:
266 printk(KERN_ERR "Unable to add platform device\n");
267 platform_device_put(sdp3430_snd_device);
268
269 return ret;
270}
271module_init(sdp3430_soc_init);
272
273static void __exit sdp3430_soc_exit(void)
274{
Lopez Cruz, Misaelde0b9882009-03-05 11:32:31 -0600275 snd_soc_jack_free_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios),
276 hs_jack_gpios);
277
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600278 platform_device_unregister(sdp3430_snd_device);
279}
280module_exit(sdp3430_soc_exit);
281
282MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>");
283MODULE_DESCRIPTION("ALSA SoC SDP3430");
284MODULE_LICENSE("GPL");
285