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