]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - sound/soc/omap/sdp3430.c
ASoC: Decouple DAPM from CODECs
[mirror_ubuntu-bionic-kernel.git] / sound / soc / omap / sdp3430.c
CommitLineData
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>
31#include <sound/soc-dapm.h>
de0b9888 32#include <sound/jack.h>
4451582f
MLC
33
34#include <asm/mach-types.h>
35#include <mach/hardware.h>
36#include <mach/gpio.h>
ce491cf8 37#include <plat/mcbsp.h>
4451582f 38
f0fba2ad
LG
39/* Register descriptions for twl4030 codec part */
40#include <linux/mfd/twl4030-codec.h>
41
4451582f
MLC
42#include "omap-mcbsp.h"
43#include "omap-pcm.h"
4451582f 44
30cd0c4a
CVJ
45/* 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)
c5910a70 49
77dd7e17
LCM
50static struct snd_soc_card snd_soc_sdp3430;
51
4451582f
MLC
52static 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;
f0fba2ad
LG
56 struct snd_soc_dai *codec_dai = rtd->codec_dai;
57 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
4451582f
MLC
58 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
11a72811
LCM
95static 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;
f0fba2ad
LG
99 struct snd_soc_dai *codec_dai = rtd->codec_dai;
100 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
11a72811
LCM
101 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 |
c264301c 107 SND_SOC_DAIFMT_CBM_CFM);
11a72811
LCM
108 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
77dd7e17
LCM
138/* 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 {
63208774
LCM
144 .pin = "Headset Mic",
145 .mask = SND_JACK_MICROPHONE,
146 },
147 {
148 .pin = "Headset Stereophone",
149 .mask = SND_JACK_HEADPHONE,
77dd7e17
LCM
150 },
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
979c036e
LCM
163/* 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),
63208774
LCM
167 SND_SOC_DAPM_MIC("Headset Mic", NULL),
168 SND_SOC_DAPM_HP("Headset Stereophone", NULL),
979c036e
LCM
169};
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
63208774 182 /* Headset Mic: HSMIC with bias */
979c036e 183 {"HSMIC", NULL, "Headset Mic Bias"},
63208774
LCM
184 {"Headset Mic Bias", NULL, "Headset Mic"},
185
186 /* Headset Stereophone (Headphone): HSOL, HSOR */
187 {"Headset Stereophone", NULL, "HSOL"},
188 {"Headset Stereophone", NULL, "HSOR"},
979c036e
LCM
189};
190
f0fba2ad 191static int sdp3430_twl4030_init(struct snd_soc_pcm_runtime *rtd)
979c036e 192{
f0fba2ad 193 struct snd_soc_codec *codec = rtd->codec;
ce6120cc 194 struct snd_soc_dapm_context *dapm = &codec->dapm;
979c036e
LCM
195 int ret;
196
197 /* Add SDP3430 specific widgets */
ce6120cc 198 ret = snd_soc_dapm_new_controls(dapm, sdp3430_twl4030_dapm_widgets,
979c036e
LCM
199 ARRAY_SIZE(sdp3430_twl4030_dapm_widgets));
200 if (ret)
201 return ret;
202
203 /* Set up SDP3430 specific audio path audio_map */
ce6120cc 204 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
979c036e
LCM
205
206 /* SDP3430 connected pins */
ce6120cc
LG
207 snd_soc_dapm_enable_pin(dapm, "Ext Mic");
208 snd_soc_dapm_enable_pin(dapm, "Ext Spk");
209 snd_soc_dapm_disable_pin(dapm, "Headset Mic");
210 snd_soc_dapm_disable_pin(dapm, "Headset Stereophone");
979c036e
LCM
211
212 /* TWL4030 not connected pins */
ce6120cc
LG
213 snd_soc_dapm_nc_pin(dapm, "AUXL");
214 snd_soc_dapm_nc_pin(dapm, "AUXR");
215 snd_soc_dapm_nc_pin(dapm, "CARKITMIC");
216 snd_soc_dapm_nc_pin(dapm, "DIGIMIC0");
217 snd_soc_dapm_nc_pin(dapm, "DIGIMIC1");
218
219 snd_soc_dapm_nc_pin(dapm, "OUTL");
220 snd_soc_dapm_nc_pin(dapm, "OUTR");
221 snd_soc_dapm_nc_pin(dapm, "EARPIECE");
222 snd_soc_dapm_nc_pin(dapm, "PREDRIVEL");
223 snd_soc_dapm_nc_pin(dapm, "PREDRIVER");
224 snd_soc_dapm_nc_pin(dapm, "CARKITL");
225 snd_soc_dapm_nc_pin(dapm, "CARKITR");
226
227 ret = snd_soc_dapm_sync(dapm);
77dd7e17
LCM
228 if (ret)
229 return ret;
979c036e 230
77dd7e17 231 /* Headset jack detection */
f0fba2ad 232 ret = snd_soc_jack_new(codec, "Headset Jack",
77dd7e17
LCM
233 SND_JACK_HEADSET, &hs_jack);
234 if (ret)
235 return ret;
979c036e 236
77dd7e17
LCM
237 ret = snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins),
238 hs_jack_pins);
239 if (ret)
240 return ret;
de0b9888 241
77dd7e17
LCM
242 ret = snd_soc_jack_add_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios),
243 hs_jack_gpios);
de0b9888 244
77dd7e17
LCM
245 return ret;
246}
de0b9888 247
f0fba2ad 248static int sdp3430_twl4030_voice_init(struct snd_soc_pcm_runtime *rtd)
11a72811 249{
f0fba2ad 250 struct snd_soc_codec *codec = rtd->codec;
11a72811
LCM
251 unsigned short reg;
252
253 /* Enable voice interface */
f0fba2ad 254 reg = codec->driver->read(codec, TWL4030_REG_VOICE_IF);
11a72811 255 reg |= TWL4030_VIF_DIN_EN | TWL4030_VIF_DOUT_EN | TWL4030_VIF_EN;
f0fba2ad 256 codec->driver->write(codec, TWL4030_REG_VOICE_IF, reg);
11a72811
LCM
257
258 return 0;
259}
260
261
4451582f 262/* Digital audio interface glue - connects codec <--> CPU */
11a72811
LCM
263static struct snd_soc_dai_link sdp3430_dai[] = {
264 {
265 .name = "TWL4030 I2S",
266 .stream_name = "TWL4030 Audio",
f0fba2ad
LG
267 .cpu_dai_name = "omap-mcbsp-dai.1",
268 .codec_dai_name = "twl4030-hifi",
269 .platform_name = "omap-pcm-audio",
270 .codec_name = "twl4030-codec",
11a72811
LCM
271 .init = sdp3430_twl4030_init,
272 .ops = &sdp3430_ops,
273 },
274 {
275 .name = "TWL4030 PCM",
276 .stream_name = "TWL4030 Voice",
f0fba2ad
LG
277 .cpu_dai_name = "omap-mcbsp-dai.2",
278 .codec_dai_name = "twl4030-voice",
279 .platform_name = "omap-pcm-audio",
280 .codec_name = "twl4030-codec",
11a72811
LCM
281 .init = sdp3430_twl4030_voice_init,
282 .ops = &sdp3430_voice_ops,
283 },
4451582f
MLC
284};
285
286/* Audio machine driver */
272edb00 287static struct snd_soc_card snd_soc_sdp3430 = {
4451582f 288 .name = "SDP3430",
11a72811
LCM
289 .dai_link = sdp3430_dai,
290 .num_links = ARRAY_SIZE(sdp3430_dai),
4451582f
MLC
291};
292
4451582f
MLC
293static struct platform_device *sdp3430_snd_device;
294
295static int __init sdp3430_soc_init(void)
296{
297 int ret;
30cd0c4a 298 u8 pin_mux;
4451582f 299
ec588ae6 300 if (!machine_is_omap_3430sdp())
4451582f 301 return -ENODEV;
4451582f
MLC
302 printk(KERN_INFO "SDP3430 SoC init\n");
303
304 sdp3430_snd_device = platform_device_alloc("soc-audio", -1);
305 if (!sdp3430_snd_device) {
306 printk(KERN_ERR "Platform device allocation failed\n");
307 return -ENOMEM;
308 }
309
f0fba2ad 310 platform_set_drvdata(sdp3430_snd_device, &snd_soc_sdp3430);
4451582f 311
c5910a70 312 /* Set TWL4030 GPIO6 as EXTMUTE signal */
ebeb53e1 313 twl_i2c_read_u8(TWL4030_MODULE_INTBR, &pin_mux,
30cd0c4a
CVJ
314 TWL4030_INTBR_PMBR1);
315 pin_mux &= ~TWL4030_GPIO6_PWM0_MUTE(0x03);
316 pin_mux |= TWL4030_GPIO6_PWM0_MUTE(0x02);
ebeb53e1 317 twl_i2c_write_u8(TWL4030_MODULE_INTBR, pin_mux,
30cd0c4a 318 TWL4030_INTBR_PMBR1);
c5910a70 319
4451582f
MLC
320 ret = platform_device_add(sdp3430_snd_device);
321 if (ret)
322 goto err1;
323
77dd7e17 324 return 0;
4451582f
MLC
325
326err1:
327 printk(KERN_ERR "Unable to add platform device\n");
328 platform_device_put(sdp3430_snd_device);
329
330 return ret;
331}
332module_init(sdp3430_soc_init);
333
334static void __exit sdp3430_soc_exit(void)
335{
de0b9888
LCM
336 snd_soc_jack_free_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios),
337 hs_jack_gpios);
338
4451582f
MLC
339 platform_device_unregister(sdp3430_snd_device);
340}
341module_exit(sdp3430_soc_exit);
342
343MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>");
344MODULE_DESCRIPTION("ALSA SoC SDP3430");
345MODULE_LICENSE("GPL");
346