blob: c51594d8fd13bceccdd5be877b5913abefd04ed0 [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>
27#include <sound/core.h>
28#include <sound/pcm.h>
29#include <sound/soc.h>
30#include <sound/soc-dapm.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>
36#include <mach/mcbsp.h>
37
38#include "omap-mcbsp.h"
39#include "omap-pcm.h"
40#include "../codecs/twl4030.h"
41
Lopez Cruz, Misael77dd7e12009-03-12 21:45:27 -050042static struct snd_soc_card snd_soc_sdp3430;
43
Misael Lopez Cruz44515822008-11-24 22:21:23 -060044static int sdp3430_hw_params(struct snd_pcm_substream *substream,
45 struct snd_pcm_hw_params *params)
46{
47 struct snd_soc_pcm_runtime *rtd = substream->private_data;
48 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
49 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
50 int ret;
51
52 /* Set codec DAI configuration */
53 ret = snd_soc_dai_set_fmt(codec_dai,
54 SND_SOC_DAIFMT_I2S |
55 SND_SOC_DAIFMT_NB_NF |
56 SND_SOC_DAIFMT_CBM_CFM);
57 if (ret < 0) {
58 printk(KERN_ERR "can't set codec DAI configuration\n");
59 return ret;
60 }
61
62 /* Set cpu DAI configuration */
63 ret = snd_soc_dai_set_fmt(cpu_dai,
64 SND_SOC_DAIFMT_I2S |
65 SND_SOC_DAIFMT_NB_NF |
66 SND_SOC_DAIFMT_CBM_CFM);
67 if (ret < 0) {
68 printk(KERN_ERR "can't set cpu DAI configuration\n");
69 return ret;
70 }
71
72 /* Set the codec system clock for DAC and ADC */
73 ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
74 SND_SOC_CLOCK_IN);
75 if (ret < 0) {
76 printk(KERN_ERR "can't set codec system clock\n");
77 return ret;
78 }
79
80 return 0;
81}
82
83static struct snd_soc_ops sdp3430_ops = {
84 .hw_params = sdp3430_hw_params,
85};
86
Lopez Cruz, Misael11a72812009-05-18 11:53:04 -050087static int sdp3430_hw_voice_params(struct snd_pcm_substream *substream,
88 struct snd_pcm_hw_params *params)
89{
90 struct snd_soc_pcm_runtime *rtd = substream->private_data;
91 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
92 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
93 int ret;
94
95 /* Set codec DAI configuration */
96 ret = snd_soc_dai_set_fmt(codec_dai,
97 SND_SOC_DAIFMT_DSP_A |
98 SND_SOC_DAIFMT_IB_NF |
Lopez Cruz, Misaelc2643012009-06-19 03:23:42 -050099 SND_SOC_DAIFMT_CBM_CFM);
Lopez Cruz, Misael11a72812009-05-18 11:53:04 -0500100 if (ret) {
101 printk(KERN_ERR "can't set codec DAI configuration\n");
102 return ret;
103 }
104
105 /* Set cpu DAI configuration */
106 ret = snd_soc_dai_set_fmt(cpu_dai,
107 SND_SOC_DAIFMT_DSP_A |
108 SND_SOC_DAIFMT_IB_NF |
109 SND_SOC_DAIFMT_CBM_CFM);
110 if (ret < 0) {
111 printk(KERN_ERR "can't set cpu DAI configuration\n");
112 return ret;
113 }
114
115 /* Set the codec system clock for DAC and ADC */
116 ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
117 SND_SOC_CLOCK_IN);
118 if (ret < 0) {
119 printk(KERN_ERR "can't set codec system clock\n");
120 return ret;
121 }
122
123 return 0;
124}
125
126static struct snd_soc_ops sdp3430_voice_ops = {
127 .hw_params = sdp3430_hw_voice_params,
128};
129
Lopez Cruz, Misael77dd7e12009-03-12 21:45:27 -0500130/* Headset jack */
131static struct snd_soc_jack hs_jack;
132
133/* Headset jack detection DAPM pins */
134static struct snd_soc_jack_pin hs_jack_pins[] = {
135 {
Lopez Cruz, Misael63208772009-03-19 01:07:34 -0500136 .pin = "Headset Mic",
137 .mask = SND_JACK_MICROPHONE,
138 },
139 {
140 .pin = "Headset Stereophone",
141 .mask = SND_JACK_HEADPHONE,
Lopez Cruz, Misael77dd7e12009-03-12 21:45:27 -0500142 },
143};
144
145/* Headset jack detection gpios */
146static struct snd_soc_jack_gpio hs_jack_gpios[] = {
147 {
148 .gpio = (OMAP_MAX_GPIO_LINES + 2),
149 .name = "hsdet-gpio",
150 .report = SND_JACK_HEADSET,
151 .debounce_time = 200,
152 },
153};
154
Lopez Cruz, Misael979c0362009-03-04 11:39:07 -0600155/* SDP3430 machine DAPM */
156static const struct snd_soc_dapm_widget sdp3430_twl4030_dapm_widgets[] = {
157 SND_SOC_DAPM_MIC("Ext Mic", NULL),
158 SND_SOC_DAPM_SPK("Ext Spk", NULL),
Lopez Cruz, Misael63208772009-03-19 01:07:34 -0500159 SND_SOC_DAPM_MIC("Headset Mic", NULL),
160 SND_SOC_DAPM_HP("Headset Stereophone", NULL),
Lopez Cruz, Misael979c0362009-03-04 11:39:07 -0600161};
162
163static const struct snd_soc_dapm_route audio_map[] = {
164 /* External Mics: MAINMIC, SUBMIC with bias*/
165 {"MAINMIC", NULL, "Mic Bias 1"},
166 {"SUBMIC", NULL, "Mic Bias 2"},
167 {"Mic Bias 1", NULL, "Ext Mic"},
168 {"Mic Bias 2", NULL, "Ext Mic"},
169
170 /* External Speakers: HFL, HFR */
171 {"Ext Spk", NULL, "HFL"},
172 {"Ext Spk", NULL, "HFR"},
173
Lopez Cruz, Misael63208772009-03-19 01:07:34 -0500174 /* Headset Mic: HSMIC with bias */
Lopez Cruz, Misael979c0362009-03-04 11:39:07 -0600175 {"HSMIC", NULL, "Headset Mic Bias"},
Lopez Cruz, Misael63208772009-03-19 01:07:34 -0500176 {"Headset Mic Bias", NULL, "Headset Mic"},
177
178 /* Headset Stereophone (Headphone): HSOL, HSOR */
179 {"Headset Stereophone", NULL, "HSOL"},
180 {"Headset Stereophone", NULL, "HSOR"},
Lopez Cruz, Misael979c0362009-03-04 11:39:07 -0600181};
182
183static int sdp3430_twl4030_init(struct snd_soc_codec *codec)
184{
185 int ret;
186
187 /* Add SDP3430 specific widgets */
188 ret = snd_soc_dapm_new_controls(codec, sdp3430_twl4030_dapm_widgets,
189 ARRAY_SIZE(sdp3430_twl4030_dapm_widgets));
190 if (ret)
191 return ret;
192
193 /* Set up SDP3430 specific audio path audio_map */
194 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
195
196 /* SDP3430 connected pins */
197 snd_soc_dapm_enable_pin(codec, "Ext Mic");
198 snd_soc_dapm_enable_pin(codec, "Ext Spk");
Lopez Cruz, Misael63208772009-03-19 01:07:34 -0500199 snd_soc_dapm_disable_pin(codec, "Headset Mic");
200 snd_soc_dapm_disable_pin(codec, "Headset Stereophone");
Lopez Cruz, Misael979c0362009-03-04 11:39:07 -0600201
202 /* TWL4030 not connected pins */
203 snd_soc_dapm_nc_pin(codec, "AUXL");
204 snd_soc_dapm_nc_pin(codec, "AUXR");
205 snd_soc_dapm_nc_pin(codec, "CARKITMIC");
206 snd_soc_dapm_nc_pin(codec, "DIGIMIC0");
207 snd_soc_dapm_nc_pin(codec, "DIGIMIC1");
208
209 snd_soc_dapm_nc_pin(codec, "OUTL");
210 snd_soc_dapm_nc_pin(codec, "OUTR");
211 snd_soc_dapm_nc_pin(codec, "EARPIECE");
212 snd_soc_dapm_nc_pin(codec, "PREDRIVEL");
213 snd_soc_dapm_nc_pin(codec, "PREDRIVER");
214 snd_soc_dapm_nc_pin(codec, "CARKITL");
215 snd_soc_dapm_nc_pin(codec, "CARKITR");
216
217 ret = snd_soc_dapm_sync(codec);
Lopez Cruz, Misael77dd7e12009-03-12 21:45:27 -0500218 if (ret)
219 return ret;
220
221 /* Headset jack detection */
222 ret = snd_soc_jack_new(&snd_soc_sdp3430, "Headset Jack",
223 SND_JACK_HEADSET, &hs_jack);
224 if (ret)
225 return ret;
226
227 ret = snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins),
228 hs_jack_pins);
229 if (ret)
230 return ret;
231
232 ret = snd_soc_jack_add_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios),
233 hs_jack_gpios);
Lopez Cruz, Misael979c0362009-03-04 11:39:07 -0600234
235 return ret;
236}
237
Lopez Cruz, Misael11a72812009-05-18 11:53:04 -0500238static int sdp3430_twl4030_voice_init(struct snd_soc_codec *codec)
239{
240 unsigned short reg;
241
242 /* Enable voice interface */
243 reg = codec->read(codec, TWL4030_REG_VOICE_IF);
244 reg |= TWL4030_VIF_DIN_EN | TWL4030_VIF_DOUT_EN | TWL4030_VIF_EN;
245 codec->write(codec, TWL4030_REG_VOICE_IF, reg);
246
247 return 0;
248}
249
250
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600251/* Digital audio interface glue - connects codec <--> CPU */
Lopez Cruz, Misael11a72812009-05-18 11:53:04 -0500252static struct snd_soc_dai_link sdp3430_dai[] = {
253 {
254 .name = "TWL4030 I2S",
255 .stream_name = "TWL4030 Audio",
256 .cpu_dai = &omap_mcbsp_dai[0],
257 .codec_dai = &twl4030_dai[TWL4030_DAI_HIFI],
258 .init = sdp3430_twl4030_init,
259 .ops = &sdp3430_ops,
260 },
261 {
262 .name = "TWL4030 PCM",
263 .stream_name = "TWL4030 Voice",
264 .cpu_dai = &omap_mcbsp_dai[1],
265 .codec_dai = &twl4030_dai[TWL4030_DAI_VOICE],
266 .init = sdp3430_twl4030_voice_init,
267 .ops = &sdp3430_voice_ops,
268 },
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600269};
270
271/* Audio machine driver */
Lopez Cruz, Misael272edb02009-02-10 02:05:07 -0600272static struct snd_soc_card snd_soc_sdp3430 = {
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600273 .name = "SDP3430",
Mark Brown87689d52008-12-02 16:01:14 +0000274 .platform = &omap_soc_platform,
Lopez Cruz, Misael11a72812009-05-18 11:53:04 -0500275 .dai_link = sdp3430_dai,
276 .num_links = ARRAY_SIZE(sdp3430_dai),
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600277};
278
Peter Ujfalusi7385ba42009-05-22 10:13:16 +0300279/* twl4030 setup */
280static struct twl4030_setup_data twl4030_setup = {
281 .ramp_delay_value = 3,
282 .sysclk = 26000,
283};
284
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600285/* Audio subsystem */
286static struct snd_soc_device sdp3430_snd_devdata = {
Lopez Cruz, Misael272edb02009-02-10 02:05:07 -0600287 .card = &snd_soc_sdp3430,
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600288 .codec_dev = &soc_codec_dev_twl4030,
Peter Ujfalusi7385ba42009-05-22 10:13:16 +0300289 .codec_data = &twl4030_setup,
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600290};
291
292static struct platform_device *sdp3430_snd_device;
293
294static int __init sdp3430_soc_init(void)
295{
296 int ret;
297
298 if (!machine_is_omap_3430sdp()) {
299 pr_debug("Not SDP3430!\n");
300 return -ENODEV;
301 }
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
310 platform_set_drvdata(sdp3430_snd_device, &sdp3430_snd_devdata);
311 sdp3430_snd_devdata.dev = &sdp3430_snd_device->dev;
Lopez Cruz, Misael11a72812009-05-18 11:53:04 -0500312 *(unsigned int *)sdp3430_dai[0].cpu_dai->private_data = 1; /* McBSP2 */
313 *(unsigned int *)sdp3430_dai[1].cpu_dai->private_data = 2; /* McBSP3 */
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600314
315 ret = platform_device_add(sdp3430_snd_device);
316 if (ret)
317 goto err1;
318
Lopez Cruz, Misael77dd7e12009-03-12 21:45:27 -0500319 return 0;
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600320
321err1:
322 printk(KERN_ERR "Unable to add platform device\n");
323 platform_device_put(sdp3430_snd_device);
324
325 return ret;
326}
327module_init(sdp3430_soc_init);
328
329static void __exit sdp3430_soc_exit(void)
330{
Lopez Cruz, Misaelde0b9882009-03-05 11:32:31 -0600331 snd_soc_jack_free_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios),
332 hs_jack_gpios);
333
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600334 platform_device_unregister(sdp3430_snd_device);
335}
336module_exit(sdp3430_soc_exit);
337
338MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>");
339MODULE_DESCRIPTION("ALSA SoC SDP3430");
340MODULE_LICENSE("GPL");
341