blob: 10f1c867f11d672692aef958f64750f7f691d5c3 [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, Misael77dd7e12009-03-12 21:45:27 -050087/* Headset jack */
88static struct snd_soc_jack hs_jack;
89
90/* Headset jack detection DAPM pins */
91static struct snd_soc_jack_pin hs_jack_pins[] = {
92 {
Lopez Cruz, Misael63208772009-03-19 01:07:34 -050093 .pin = "Headset Mic",
94 .mask = SND_JACK_MICROPHONE,
95 },
96 {
97 .pin = "Headset Stereophone",
98 .mask = SND_JACK_HEADPHONE,
Lopez Cruz, Misael77dd7e12009-03-12 21:45:27 -050099 },
100};
101
102/* Headset jack detection gpios */
103static struct snd_soc_jack_gpio hs_jack_gpios[] = {
104 {
105 .gpio = (OMAP_MAX_GPIO_LINES + 2),
106 .name = "hsdet-gpio",
107 .report = SND_JACK_HEADSET,
108 .debounce_time = 200,
109 },
110};
111
Lopez Cruz, Misael979c0362009-03-04 11:39:07 -0600112/* SDP3430 machine DAPM */
113static const struct snd_soc_dapm_widget sdp3430_twl4030_dapm_widgets[] = {
114 SND_SOC_DAPM_MIC("Ext Mic", NULL),
115 SND_SOC_DAPM_SPK("Ext Spk", NULL),
Lopez Cruz, Misael63208772009-03-19 01:07:34 -0500116 SND_SOC_DAPM_MIC("Headset Mic", NULL),
117 SND_SOC_DAPM_HP("Headset Stereophone", NULL),
Lopez Cruz, Misael979c0362009-03-04 11:39:07 -0600118};
119
120static const struct snd_soc_dapm_route audio_map[] = {
121 /* External Mics: MAINMIC, SUBMIC with bias*/
122 {"MAINMIC", NULL, "Mic Bias 1"},
123 {"SUBMIC", NULL, "Mic Bias 2"},
124 {"Mic Bias 1", NULL, "Ext Mic"},
125 {"Mic Bias 2", NULL, "Ext Mic"},
126
127 /* External Speakers: HFL, HFR */
128 {"Ext Spk", NULL, "HFL"},
129 {"Ext Spk", NULL, "HFR"},
130
Lopez Cruz, Misael63208772009-03-19 01:07:34 -0500131 /* Headset Mic: HSMIC with bias */
Lopez Cruz, Misael979c0362009-03-04 11:39:07 -0600132 {"HSMIC", NULL, "Headset Mic Bias"},
Lopez Cruz, Misael63208772009-03-19 01:07:34 -0500133 {"Headset Mic Bias", NULL, "Headset Mic"},
134
135 /* Headset Stereophone (Headphone): HSOL, HSOR */
136 {"Headset Stereophone", NULL, "HSOL"},
137 {"Headset Stereophone", NULL, "HSOR"},
Lopez Cruz, Misael979c0362009-03-04 11:39:07 -0600138};
139
140static int sdp3430_twl4030_init(struct snd_soc_codec *codec)
141{
142 int ret;
143
144 /* Add SDP3430 specific widgets */
145 ret = snd_soc_dapm_new_controls(codec, sdp3430_twl4030_dapm_widgets,
146 ARRAY_SIZE(sdp3430_twl4030_dapm_widgets));
147 if (ret)
148 return ret;
149
150 /* Set up SDP3430 specific audio path audio_map */
151 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
152
153 /* SDP3430 connected pins */
154 snd_soc_dapm_enable_pin(codec, "Ext Mic");
155 snd_soc_dapm_enable_pin(codec, "Ext Spk");
Lopez Cruz, Misael63208772009-03-19 01:07:34 -0500156 snd_soc_dapm_disable_pin(codec, "Headset Mic");
157 snd_soc_dapm_disable_pin(codec, "Headset Stereophone");
Lopez Cruz, Misael979c0362009-03-04 11:39:07 -0600158
159 /* TWL4030 not connected pins */
160 snd_soc_dapm_nc_pin(codec, "AUXL");
161 snd_soc_dapm_nc_pin(codec, "AUXR");
162 snd_soc_dapm_nc_pin(codec, "CARKITMIC");
163 snd_soc_dapm_nc_pin(codec, "DIGIMIC0");
164 snd_soc_dapm_nc_pin(codec, "DIGIMIC1");
165
166 snd_soc_dapm_nc_pin(codec, "OUTL");
167 snd_soc_dapm_nc_pin(codec, "OUTR");
168 snd_soc_dapm_nc_pin(codec, "EARPIECE");
169 snd_soc_dapm_nc_pin(codec, "PREDRIVEL");
170 snd_soc_dapm_nc_pin(codec, "PREDRIVER");
171 snd_soc_dapm_nc_pin(codec, "CARKITL");
172 snd_soc_dapm_nc_pin(codec, "CARKITR");
173
174 ret = snd_soc_dapm_sync(codec);
Lopez Cruz, Misael77dd7e12009-03-12 21:45:27 -0500175 if (ret)
176 return ret;
177
178 /* Headset jack detection */
179 ret = snd_soc_jack_new(&snd_soc_sdp3430, "Headset Jack",
180 SND_JACK_HEADSET, &hs_jack);
181 if (ret)
182 return ret;
183
184 ret = snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins),
185 hs_jack_pins);
186 if (ret)
187 return ret;
188
189 ret = snd_soc_jack_add_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios),
190 hs_jack_gpios);
Lopez Cruz, Misael979c0362009-03-04 11:39:07 -0600191
192 return ret;
193}
194
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600195/* Digital audio interface glue - connects codec <--> CPU */
196static struct snd_soc_dai_link sdp3430_dai = {
197 .name = "TWL4030",
198 .stream_name = "TWL4030",
199 .cpu_dai = &omap_mcbsp_dai[0],
200 .codec_dai = &twl4030_dai,
Lopez Cruz, Misael979c0362009-03-04 11:39:07 -0600201 .init = sdp3430_twl4030_init,
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600202 .ops = &sdp3430_ops,
203};
204
205/* Audio machine driver */
Lopez Cruz, Misael272edb02009-02-10 02:05:07 -0600206static struct snd_soc_card snd_soc_sdp3430 = {
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600207 .name = "SDP3430",
Mark Brown87689d52008-12-02 16:01:14 +0000208 .platform = &omap_soc_platform,
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600209 .dai_link = &sdp3430_dai,
210 .num_links = 1,
211};
212
213/* Audio subsystem */
214static struct snd_soc_device sdp3430_snd_devdata = {
Lopez Cruz, Misael272edb02009-02-10 02:05:07 -0600215 .card = &snd_soc_sdp3430,
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600216 .codec_dev = &soc_codec_dev_twl4030,
217};
218
219static struct platform_device *sdp3430_snd_device;
220
221static int __init sdp3430_soc_init(void)
222{
223 int ret;
224
225 if (!machine_is_omap_3430sdp()) {
226 pr_debug("Not SDP3430!\n");
227 return -ENODEV;
228 }
229 printk(KERN_INFO "SDP3430 SoC init\n");
230
231 sdp3430_snd_device = platform_device_alloc("soc-audio", -1);
232 if (!sdp3430_snd_device) {
233 printk(KERN_ERR "Platform device allocation failed\n");
234 return -ENOMEM;
235 }
236
237 platform_set_drvdata(sdp3430_snd_device, &sdp3430_snd_devdata);
238 sdp3430_snd_devdata.dev = &sdp3430_snd_device->dev;
239 *(unsigned int *)sdp3430_dai.cpu_dai->private_data = 1; /* McBSP2 */
240
241 ret = platform_device_add(sdp3430_snd_device);
242 if (ret)
243 goto err1;
244
Lopez Cruz, Misael77dd7e12009-03-12 21:45:27 -0500245 return 0;
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600246
247err1:
248 printk(KERN_ERR "Unable to add platform device\n");
249 platform_device_put(sdp3430_snd_device);
250
251 return ret;
252}
253module_init(sdp3430_soc_init);
254
255static void __exit sdp3430_soc_exit(void)
256{
Lopez Cruz, Misaelde0b9882009-03-05 11:32:31 -0600257 snd_soc_jack_free_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios),
258 hs_jack_gpios);
259
Misael Lopez Cruz44515822008-11-24 22:21:23 -0600260 platform_device_unregister(sdp3430_snd_device);
261}
262module_exit(sdp3430_soc_exit);
263
264MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>");
265MODULE_DESCRIPTION("ALSA SoC SDP3430");
266MODULE_LICENSE("GPL");
267