blob: 78e14198aa1140a6a790c1d5da1f34f685a67664 [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>
Tony Lindgren4b254082012-08-30 15:37:24 -070037#include <linux/platform_data/gpio-omap.h>
Misael Lopez Cruz44515822008-11-24 22:21:23 -060038
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000039/* Register descriptions for twl4030 codec part */
Peter Ujfalusi57fe7252011-05-31 12:02:49 +030040#include <linux/mfd/twl4030-audio.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040041#include <linux/module.h>
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000042
Misael Lopez Cruz44515822008-11-24 22:21:23 -060043#include "omap-mcbsp.h"
44#include "omap-pcm.h"
Misael Lopez Cruz44515822008-11-24 22:21:23 -060045
Candelaria Villareal, Jorge30cd0c42009-08-25 10:13:25 -050046/* TWL4030 PMBR1 Register */
47#define TWL4030_INTBR_PMBR1 0x0D
48/* TWL4030 PMBR1 Register GPIO6 mux bit */
49#define TWL4030_GPIO6_PWM0_MUTE(value) (value << 2)
Candelaria Villareal, Jorgec5910a72009-07-14 20:04:08 -050050
Lopez Cruz, Misael77dd7e12009-03-12 21:45:27 -050051static struct snd_soc_card snd_soc_sdp3430;
52
Misael Lopez Cruz44515822008-11-24 22:21:23 -060053static int sdp3430_hw_params(struct snd_pcm_substream *substream,
54 struct snd_pcm_hw_params *params)
55{
56 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000057 struct snd_soc_dai *codec_dai = rtd->codec_dai;
Misael Lopez Cruz44515822008-11-24 22:21:23 -060058 int ret;
59
Misael Lopez Cruz44515822008-11-24 22:21:23 -060060 /* Set the codec system clock for DAC and ADC */
61 ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
62 SND_SOC_CLOCK_IN);
63 if (ret < 0) {
64 printk(KERN_ERR "can't set codec system clock\n");
65 return ret;
66 }
67
68 return 0;
69}
70
71static struct snd_soc_ops sdp3430_ops = {
72 .hw_params = sdp3430_hw_params,
73};
74
Lopez Cruz, Misael77dd7e12009-03-12 21:45:27 -050075/* Headset jack */
76static struct snd_soc_jack hs_jack;
77
78/* Headset jack detection DAPM pins */
79static struct snd_soc_jack_pin hs_jack_pins[] = {
80 {
Lopez Cruz, Misael63208772009-03-19 01:07:34 -050081 .pin = "Headset Mic",
82 .mask = SND_JACK_MICROPHONE,
83 },
84 {
85 .pin = "Headset Stereophone",
86 .mask = SND_JACK_HEADPHONE,
Lopez Cruz, Misael77dd7e12009-03-12 21:45:27 -050087 },
88};
89
90/* Headset jack detection gpios */
91static struct snd_soc_jack_gpio hs_jack_gpios[] = {
92 {
93 .gpio = (OMAP_MAX_GPIO_LINES + 2),
94 .name = "hsdet-gpio",
95 .report = SND_JACK_HEADSET,
96 .debounce_time = 200,
97 },
98};
99
Lopez Cruz, Misael979c0362009-03-04 11:39:07 -0600100/* SDP3430 machine DAPM */
101static const struct snd_soc_dapm_widget sdp3430_twl4030_dapm_widgets[] = {
102 SND_SOC_DAPM_MIC("Ext Mic", NULL),
103 SND_SOC_DAPM_SPK("Ext Spk", NULL),
Lopez Cruz, Misael63208772009-03-19 01:07:34 -0500104 SND_SOC_DAPM_MIC("Headset Mic", NULL),
105 SND_SOC_DAPM_HP("Headset Stereophone", NULL),
Lopez Cruz, Misael979c0362009-03-04 11:39:07 -0600106};
107
108static const struct snd_soc_dapm_route audio_map[] = {
109 /* External Mics: MAINMIC, SUBMIC with bias*/
110 {"MAINMIC", NULL, "Mic Bias 1"},
111 {"SUBMIC", NULL, "Mic Bias 2"},
112 {"Mic Bias 1", NULL, "Ext Mic"},
113 {"Mic Bias 2", NULL, "Ext Mic"},
114
115 /* External Speakers: HFL, HFR */
116 {"Ext Spk", NULL, "HFL"},
117 {"Ext Spk", NULL, "HFR"},
118
Lopez Cruz, Misael63208772009-03-19 01:07:34 -0500119 /* Headset Mic: HSMIC with bias */
Lopez Cruz, Misael979c0362009-03-04 11:39:07 -0600120 {"HSMIC", NULL, "Headset Mic Bias"},
Lopez Cruz, Misael63208772009-03-19 01:07:34 -0500121 {"Headset Mic Bias", NULL, "Headset Mic"},
122
123 /* Headset Stereophone (Headphone): HSOL, HSOR */
124 {"Headset Stereophone", NULL, "HSOL"},
125 {"Headset Stereophone", NULL, "HSOR"},
Lopez Cruz, Misael979c0362009-03-04 11:39:07 -0600126};
127
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000128static int sdp3430_twl4030_init(struct snd_soc_pcm_runtime *rtd)
Lopez Cruz, Misael979c0362009-03-04 11:39:07 -0600129{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000130 struct snd_soc_codec *codec = rtd->codec;
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200131 struct snd_soc_dapm_context *dapm = &codec->dapm;
Lopez Cruz, Misael979c0362009-03-04 11:39:07 -0600132 int ret;
133
Lopez Cruz, Misael979c0362009-03-04 11:39:07 -0600134 /* SDP3430 connected pins */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200135 snd_soc_dapm_enable_pin(dapm, "Ext Mic");
136 snd_soc_dapm_enable_pin(dapm, "Ext Spk");
137 snd_soc_dapm_disable_pin(dapm, "Headset Mic");
138 snd_soc_dapm_disable_pin(dapm, "Headset Stereophone");
Lopez Cruz, Misael979c0362009-03-04 11:39:07 -0600139
140 /* TWL4030 not connected pins */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200141 snd_soc_dapm_nc_pin(dapm, "AUXL");
142 snd_soc_dapm_nc_pin(dapm, "AUXR");
143 snd_soc_dapm_nc_pin(dapm, "CARKITMIC");
144 snd_soc_dapm_nc_pin(dapm, "DIGIMIC0");
145 snd_soc_dapm_nc_pin(dapm, "DIGIMIC1");
Lopez Cruz, Misael979c0362009-03-04 11:39:07 -0600146
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200147 snd_soc_dapm_nc_pin(dapm, "OUTL");
148 snd_soc_dapm_nc_pin(dapm, "OUTR");
149 snd_soc_dapm_nc_pin(dapm, "EARPIECE");
150 snd_soc_dapm_nc_pin(dapm, "PREDRIVEL");
151 snd_soc_dapm_nc_pin(dapm, "PREDRIVER");
152 snd_soc_dapm_nc_pin(dapm, "CARKITL");
153 snd_soc_dapm_nc_pin(dapm, "CARKITR");
Lopez Cruz, Misael979c0362009-03-04 11:39:07 -0600154
Lopez Cruz, Misael77dd7e12009-03-12 21:45:27 -0500155 /* Headset jack detection */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000156 ret = snd_soc_jack_new(codec, "Headset Jack",
Lopez Cruz, Misael77dd7e12009-03-12 21:45:27 -0500157 SND_JACK_HEADSET, &hs_jack);
158 if (ret)
159 return ret;
160
161 ret = snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins),
162 hs_jack_pins);
163 if (ret)
164 return ret;
165
166 ret = snd_soc_jack_add_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios),
167 hs_jack_gpios);
Lopez Cruz, Misael979c0362009-03-04 11:39:07 -0600168
169 return ret;
170}
171
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000172static int sdp3430_twl4030_voice_init(struct snd_soc_pcm_runtime *rtd)
Lopez Cruz, Misael11a72812009-05-18 11:53:04 -0500173{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000174 struct snd_soc_codec *codec = rtd->codec;
Lopez Cruz, Misael11a72812009-05-18 11:53:04 -0500175 unsigned short reg;
176
177 /* Enable voice interface */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000178 reg = codec->driver->read(codec, TWL4030_REG_VOICE_IF);
Lopez Cruz, Misael11a72812009-05-18 11:53:04 -0500179 reg |= TWL4030_VIF_DIN_EN | TWL4030_VIF_DOUT_EN | TWL4030_VIF_EN;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000180 codec->driver->write(codec, TWL4030_REG_VOICE_IF, reg);
Lopez Cruz, Misael11a72812009-05-18 11:53:04 -0500181
182 return 0;
183}
184
185
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600186/* Digital audio interface glue - connects codec <--> CPU */
Lopez Cruz, Misael11a72812009-05-18 11:53:04 -0500187static struct snd_soc_dai_link sdp3430_dai[] = {
188 {
189 .name = "TWL4030 I2S",
190 .stream_name = "TWL4030 Audio",
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200191 .cpu_dai_name = "omap-mcbsp.2",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000192 .codec_dai_name = "twl4030-hifi",
193 .platform_name = "omap-pcm-audio",
194 .codec_name = "twl4030-codec",
Jarkko Nikulacf9feff2011-09-30 16:07:45 +0300195 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
196 SND_SOC_DAIFMT_CBM_CFM,
Lopez Cruz, Misael11a72812009-05-18 11:53:04 -0500197 .init = sdp3430_twl4030_init,
198 .ops = &sdp3430_ops,
199 },
200 {
201 .name = "TWL4030 PCM",
202 .stream_name = "TWL4030 Voice",
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200203 .cpu_dai_name = "omap-mcbsp.3",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000204 .codec_dai_name = "twl4030-voice",
205 .platform_name = "omap-pcm-audio",
206 .codec_name = "twl4030-codec",
Jarkko Nikulacf9feff2011-09-30 16:07:45 +0300207 .dai_fmt = SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_IB_NF |
208 SND_SOC_DAIFMT_CBM_CFM,
Lopez Cruz, Misael11a72812009-05-18 11:53:04 -0500209 .init = sdp3430_twl4030_voice_init,
Jarkko Nikulaa3c6dac2011-09-30 16:07:46 +0300210 .ops = &sdp3430_ops,
Lopez Cruz, Misael11a72812009-05-18 11:53:04 -0500211 },
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600212};
213
214/* Audio machine driver */
Lopez Cruz, Misael272edb02009-02-10 02:05:07 -0600215static struct snd_soc_card snd_soc_sdp3430 = {
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600216 .name = "SDP3430",
Axel Linb425b882011-12-22 11:08:59 +0800217 .owner = THIS_MODULE,
Lopez Cruz, Misael11a72812009-05-18 11:53:04 -0500218 .dai_link = sdp3430_dai,
219 .num_links = ARRAY_SIZE(sdp3430_dai),
Peter Ujfalusif8cf1492011-10-10 15:34:12 +0300220
221 .dapm_widgets = sdp3430_twl4030_dapm_widgets,
222 .num_dapm_widgets = ARRAY_SIZE(sdp3430_twl4030_dapm_widgets),
223 .dapm_routes = audio_map,
224 .num_dapm_routes = ARRAY_SIZE(audio_map),
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600225};
226
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600227static struct platform_device *sdp3430_snd_device;
228
229static int __init sdp3430_soc_init(void)
230{
231 int ret;
Candelaria Villareal, Jorge30cd0c42009-08-25 10:13:25 -0500232 u8 pin_mux;
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600233
Jarkko Nikulaec588ae2010-10-06 16:47:26 +0300234 if (!machine_is_omap_3430sdp())
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600235 return -ENODEV;
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600236 printk(KERN_INFO "SDP3430 SoC init\n");
237
238 sdp3430_snd_device = platform_device_alloc("soc-audio", -1);
239 if (!sdp3430_snd_device) {
240 printk(KERN_ERR "Platform device allocation failed\n");
241 return -ENOMEM;
242 }
243
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000244 platform_set_drvdata(sdp3430_snd_device, &snd_soc_sdp3430);
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600245
Candelaria Villareal, Jorgec5910a72009-07-14 20:04:08 -0500246 /* Set TWL4030 GPIO6 as EXTMUTE signal */
Balaji T Kebeb53e2009-12-15 20:09:02 +0530247 twl_i2c_read_u8(TWL4030_MODULE_INTBR, &pin_mux,
Candelaria Villareal, Jorge30cd0c42009-08-25 10:13:25 -0500248 TWL4030_INTBR_PMBR1);
249 pin_mux &= ~TWL4030_GPIO6_PWM0_MUTE(0x03);
250 pin_mux |= TWL4030_GPIO6_PWM0_MUTE(0x02);
Balaji T Kebeb53e2009-12-15 20:09:02 +0530251 twl_i2c_write_u8(TWL4030_MODULE_INTBR, pin_mux,
Candelaria Villareal, Jorge30cd0c42009-08-25 10:13:25 -0500252 TWL4030_INTBR_PMBR1);
Candelaria Villareal, Jorgec5910a72009-07-14 20:04:08 -0500253
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600254 ret = platform_device_add(sdp3430_snd_device);
255 if (ret)
256 goto err1;
257
Lopez Cruz, Misael77dd7e12009-03-12 21:45:27 -0500258 return 0;
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600259
260err1:
261 printk(KERN_ERR "Unable to add platform device\n");
262 platform_device_put(sdp3430_snd_device);
263
264 return ret;
265}
266module_init(sdp3430_soc_init);
267
268static void __exit sdp3430_soc_exit(void)
269{
Lopez Cruz, Misaelde0b9882009-03-05 11:32:31 -0600270 snd_soc_jack_free_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios),
271 hs_jack_gpios);
272
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600273 platform_device_unregister(sdp3430_snd_device);
274}
275module_exit(sdp3430_soc_exit);
276
277MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>");
278MODULE_DESCRIPTION("ALSA SoC SDP3430");
279MODULE_LICENSE("GPL");
280