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> | |
ebeb53e1 | 27 | #include <linux/i2c/twl.h> |
4451582f MLC |
28 | #include <sound/core.h> |
29 | #include <sound/pcm.h> | |
30 | #include <sound/soc.h> | |
de0b9888 | 31 | #include <sound/jack.h> |
4451582f MLC |
32 | |
33 | #include <asm/mach-types.h> | |
4b25408f | 34 | #include <linux/platform_data/gpio-omap.h> |
2203747c | 35 | #include <linux/platform_data/asoc-ti-mcbsp.h> |
4451582f | 36 | |
f0fba2ad | 37 | /* Register descriptions for twl4030 codec part */ |
57fe7251 | 38 | #include <linux/mfd/twl4030-audio.h> |
da155d5b | 39 | #include <linux/module.h> |
f0fba2ad | 40 | |
4451582f MLC |
41 | #include "omap-mcbsp.h" |
42 | #include "omap-pcm.h" | |
4451582f | 43 | |
30cd0c4a CVJ |
44 | /* 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) | |
c5910a70 | 48 | |
77dd7e17 LCM |
49 | static struct snd_soc_card snd_soc_sdp3430; |
50 | ||
4451582f MLC |
51 | static 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; | |
f0fba2ad | 55 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
4451582f MLC |
56 | int ret; |
57 | ||
4451582f MLC |
58 | /* 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 | ||
69 | static struct snd_soc_ops sdp3430_ops = { | |
70 | .hw_params = sdp3430_hw_params, | |
71 | }; | |
72 | ||
77dd7e17 LCM |
73 | /* Headset jack */ |
74 | static struct snd_soc_jack hs_jack; | |
75 | ||
76 | /* Headset jack detection DAPM pins */ | |
77 | static struct snd_soc_jack_pin hs_jack_pins[] = { | |
78 | { | |
63208774 LCM |
79 | .pin = "Headset Mic", |
80 | .mask = SND_JACK_MICROPHONE, | |
81 | }, | |
82 | { | |
83 | .pin = "Headset Stereophone", | |
84 | .mask = SND_JACK_HEADPHONE, | |
77dd7e17 LCM |
85 | }, |
86 | }; | |
87 | ||
88 | /* Headset jack detection gpios */ | |
89 | static 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 | ||
979c036e LCM |
98 | /* SDP3430 machine DAPM */ |
99 | static 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), | |
63208774 LCM |
102 | SND_SOC_DAPM_MIC("Headset Mic", NULL), |
103 | SND_SOC_DAPM_HP("Headset Stereophone", NULL), | |
979c036e LCM |
104 | }; |
105 | ||
106 | static 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 | ||
63208774 | 117 | /* Headset Mic: HSMIC with bias */ |
979c036e | 118 | {"HSMIC", NULL, "Headset Mic Bias"}, |
63208774 LCM |
119 | {"Headset Mic Bias", NULL, "Headset Mic"}, |
120 | ||
121 | /* Headset Stereophone (Headphone): HSOL, HSOR */ | |
122 | {"Headset Stereophone", NULL, "HSOL"}, | |
123 | {"Headset Stereophone", NULL, "HSOR"}, | |
979c036e LCM |
124 | }; |
125 | ||
f0fba2ad | 126 | static int sdp3430_twl4030_init(struct snd_soc_pcm_runtime *rtd) |
979c036e | 127 | { |
f0fba2ad | 128 | struct snd_soc_codec *codec = rtd->codec; |
ce6120cc | 129 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
979c036e LCM |
130 | int ret; |
131 | ||
979c036e | 132 | /* SDP3430 connected pins */ |
ce6120cc LG |
133 | snd_soc_dapm_enable_pin(dapm, "Ext Mic"); |
134 | snd_soc_dapm_enable_pin(dapm, "Ext Spk"); | |
135 | snd_soc_dapm_disable_pin(dapm, "Headset Mic"); | |
136 | snd_soc_dapm_disable_pin(dapm, "Headset Stereophone"); | |
979c036e LCM |
137 | |
138 | /* TWL4030 not connected pins */ | |
ce6120cc LG |
139 | snd_soc_dapm_nc_pin(dapm, "AUXL"); |
140 | snd_soc_dapm_nc_pin(dapm, "AUXR"); | |
141 | snd_soc_dapm_nc_pin(dapm, "CARKITMIC"); | |
142 | snd_soc_dapm_nc_pin(dapm, "DIGIMIC0"); | |
143 | snd_soc_dapm_nc_pin(dapm, "DIGIMIC1"); | |
144 | ||
145 | snd_soc_dapm_nc_pin(dapm, "OUTL"); | |
146 | snd_soc_dapm_nc_pin(dapm, "OUTR"); | |
147 | snd_soc_dapm_nc_pin(dapm, "EARPIECE"); | |
148 | snd_soc_dapm_nc_pin(dapm, "PREDRIVEL"); | |
149 | snd_soc_dapm_nc_pin(dapm, "PREDRIVER"); | |
150 | snd_soc_dapm_nc_pin(dapm, "CARKITL"); | |
151 | snd_soc_dapm_nc_pin(dapm, "CARKITR"); | |
152 | ||
77dd7e17 | 153 | /* Headset jack detection */ |
f0fba2ad | 154 | ret = snd_soc_jack_new(codec, "Headset Jack", |
77dd7e17 LCM |
155 | SND_JACK_HEADSET, &hs_jack); |
156 | if (ret) | |
157 | return ret; | |
979c036e | 158 | |
77dd7e17 LCM |
159 | ret = snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins), |
160 | hs_jack_pins); | |
161 | if (ret) | |
162 | return ret; | |
de0b9888 | 163 | |
77dd7e17 LCM |
164 | ret = snd_soc_jack_add_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios), |
165 | hs_jack_gpios); | |
de0b9888 | 166 | |
77dd7e17 LCM |
167 | return ret; |
168 | } | |
de0b9888 | 169 | |
f0fba2ad | 170 | static int sdp3430_twl4030_voice_init(struct snd_soc_pcm_runtime *rtd) |
11a72811 | 171 | { |
f0fba2ad | 172 | struct snd_soc_codec *codec = rtd->codec; |
11a72811 LCM |
173 | unsigned short reg; |
174 | ||
175 | /* Enable voice interface */ | |
f0fba2ad | 176 | reg = codec->driver->read(codec, TWL4030_REG_VOICE_IF); |
11a72811 | 177 | reg |= TWL4030_VIF_DIN_EN | TWL4030_VIF_DOUT_EN | TWL4030_VIF_EN; |
f0fba2ad | 178 | codec->driver->write(codec, TWL4030_REG_VOICE_IF, reg); |
11a72811 LCM |
179 | |
180 | return 0; | |
181 | } | |
182 | ||
183 | ||
4451582f | 184 | /* Digital audio interface glue - connects codec <--> CPU */ |
11a72811 LCM |
185 | static struct snd_soc_dai_link sdp3430_dai[] = { |
186 | { | |
187 | .name = "TWL4030 I2S", | |
188 | .stream_name = "TWL4030 Audio", | |
45656b44 | 189 | .cpu_dai_name = "omap-mcbsp.2", |
f0fba2ad LG |
190 | .codec_dai_name = "twl4030-hifi", |
191 | .platform_name = "omap-pcm-audio", | |
192 | .codec_name = "twl4030-codec", | |
cf9feff2 JN |
193 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | |
194 | SND_SOC_DAIFMT_CBM_CFM, | |
11a72811 LCM |
195 | .init = sdp3430_twl4030_init, |
196 | .ops = &sdp3430_ops, | |
197 | }, | |
198 | { | |
199 | .name = "TWL4030 PCM", | |
200 | .stream_name = "TWL4030 Voice", | |
45656b44 | 201 | .cpu_dai_name = "omap-mcbsp.3", |
f0fba2ad LG |
202 | .codec_dai_name = "twl4030-voice", |
203 | .platform_name = "omap-pcm-audio", | |
204 | .codec_name = "twl4030-codec", | |
cf9feff2 JN |
205 | .dai_fmt = SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_IB_NF | |
206 | SND_SOC_DAIFMT_CBM_CFM, | |
11a72811 | 207 | .init = sdp3430_twl4030_voice_init, |
a3c6dac2 | 208 | .ops = &sdp3430_ops, |
11a72811 | 209 | }, |
4451582f MLC |
210 | }; |
211 | ||
212 | /* Audio machine driver */ | |
272edb00 | 213 | static struct snd_soc_card snd_soc_sdp3430 = { |
4451582f | 214 | .name = "SDP3430", |
b425b884 | 215 | .owner = THIS_MODULE, |
11a72811 LCM |
216 | .dai_link = sdp3430_dai, |
217 | .num_links = ARRAY_SIZE(sdp3430_dai), | |
f8cf149f PU |
218 | |
219 | .dapm_widgets = sdp3430_twl4030_dapm_widgets, | |
220 | .num_dapm_widgets = ARRAY_SIZE(sdp3430_twl4030_dapm_widgets), | |
221 | .dapm_routes = audio_map, | |
222 | .num_dapm_routes = ARRAY_SIZE(audio_map), | |
4451582f MLC |
223 | }; |
224 | ||
4451582f MLC |
225 | static struct platform_device *sdp3430_snd_device; |
226 | ||
227 | static int __init sdp3430_soc_init(void) | |
228 | { | |
229 | int ret; | |
30cd0c4a | 230 | u8 pin_mux; |
4451582f | 231 | |
ec588ae6 | 232 | if (!machine_is_omap_3430sdp()) |
4451582f | 233 | return -ENODEV; |
4451582f MLC |
234 | printk(KERN_INFO "SDP3430 SoC init\n"); |
235 | ||
236 | sdp3430_snd_device = platform_device_alloc("soc-audio", -1); | |
237 | if (!sdp3430_snd_device) { | |
238 | printk(KERN_ERR "Platform device allocation failed\n"); | |
239 | return -ENOMEM; | |
240 | } | |
241 | ||
f0fba2ad | 242 | platform_set_drvdata(sdp3430_snd_device, &snd_soc_sdp3430); |
4451582f | 243 | |
c5910a70 | 244 | /* Set TWL4030 GPIO6 as EXTMUTE signal */ |
ebeb53e1 | 245 | twl_i2c_read_u8(TWL4030_MODULE_INTBR, &pin_mux, |
30cd0c4a CVJ |
246 | TWL4030_INTBR_PMBR1); |
247 | pin_mux &= ~TWL4030_GPIO6_PWM0_MUTE(0x03); | |
248 | pin_mux |= TWL4030_GPIO6_PWM0_MUTE(0x02); | |
ebeb53e1 | 249 | twl_i2c_write_u8(TWL4030_MODULE_INTBR, pin_mux, |
30cd0c4a | 250 | TWL4030_INTBR_PMBR1); |
c5910a70 | 251 | |
4451582f MLC |
252 | ret = platform_device_add(sdp3430_snd_device); |
253 | if (ret) | |
254 | goto err1; | |
255 | ||
77dd7e17 | 256 | return 0; |
4451582f MLC |
257 | |
258 | err1: | |
259 | printk(KERN_ERR "Unable to add platform device\n"); | |
260 | platform_device_put(sdp3430_snd_device); | |
261 | ||
262 | return ret; | |
263 | } | |
264 | module_init(sdp3430_soc_init); | |
265 | ||
266 | static void __exit sdp3430_soc_exit(void) | |
267 | { | |
de0b9888 LCM |
268 | snd_soc_jack_free_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios), |
269 | hs_jack_gpios); | |
270 | ||
4451582f MLC |
271 | platform_device_unregister(sdp3430_snd_device); |
272 | } | |
273 | module_exit(sdp3430_soc_exit); | |
274 | ||
275 | MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>"); | |
276 | MODULE_DESCRIPTION("ALSA SoC SDP3430"); | |
277 | MODULE_LICENSE("GPL"); | |
278 |