]>
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> | |
27 | #include <sound/core.h> | |
28 | #include <sound/pcm.h> | |
29 | #include <sound/soc.h> | |
30 | #include <sound/soc-dapm.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> | |
36 | #include <mach/mcbsp.h> | |
37 | ||
38 | #include "omap-mcbsp.h" | |
39 | #include "omap-pcm.h" | |
40 | #include "../codecs/twl4030.h" | |
41 | ||
42 | static int sdp3430_hw_params(struct snd_pcm_substream *substream, | |
43 | struct snd_pcm_hw_params *params) | |
44 | { | |
45 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | |
46 | struct snd_soc_dai *codec_dai = rtd->dai->codec_dai; | |
47 | struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai; | |
48 | int ret; | |
49 | ||
50 | /* Set codec DAI configuration */ | |
51 | ret = snd_soc_dai_set_fmt(codec_dai, | |
52 | SND_SOC_DAIFMT_I2S | | |
53 | SND_SOC_DAIFMT_NB_NF | | |
54 | SND_SOC_DAIFMT_CBM_CFM); | |
55 | if (ret < 0) { | |
56 | printk(KERN_ERR "can't set codec DAI configuration\n"); | |
57 | return ret; | |
58 | } | |
59 | ||
60 | /* Set cpu DAI configuration */ | |
61 | ret = snd_soc_dai_set_fmt(cpu_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 cpu DAI configuration\n"); | |
67 | return ret; | |
68 | } | |
69 | ||
70 | /* Set the codec system clock for DAC and ADC */ | |
71 | ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000, | |
72 | SND_SOC_CLOCK_IN); | |
73 | if (ret < 0) { | |
74 | printk(KERN_ERR "can't set codec system clock\n"); | |
75 | return ret; | |
76 | } | |
77 | ||
78 | return 0; | |
79 | } | |
80 | ||
81 | static struct snd_soc_ops sdp3430_ops = { | |
82 | .hw_params = sdp3430_hw_params, | |
83 | }; | |
84 | ||
979c036e LCM |
85 | /* SDP3430 machine DAPM */ |
86 | static const struct snd_soc_dapm_widget sdp3430_twl4030_dapm_widgets[] = { | |
87 | SND_SOC_DAPM_MIC("Ext Mic", NULL), | |
88 | SND_SOC_DAPM_SPK("Ext Spk", NULL), | |
89 | SND_SOC_DAPM_HP("Headset Jack", NULL), | |
90 | }; | |
91 | ||
92 | static const struct snd_soc_dapm_route audio_map[] = { | |
93 | /* External Mics: MAINMIC, SUBMIC with bias*/ | |
94 | {"MAINMIC", NULL, "Mic Bias 1"}, | |
95 | {"SUBMIC", NULL, "Mic Bias 2"}, | |
96 | {"Mic Bias 1", NULL, "Ext Mic"}, | |
97 | {"Mic Bias 2", NULL, "Ext Mic"}, | |
98 | ||
99 | /* External Speakers: HFL, HFR */ | |
100 | {"Ext Spk", NULL, "HFL"}, | |
101 | {"Ext Spk", NULL, "HFR"}, | |
102 | ||
103 | /* Headset: HSMIC (with bias), HSOL, HSOR */ | |
104 | {"Headset Jack", NULL, "HSOL"}, | |
105 | {"Headset Jack", NULL, "HSOR"}, | |
106 | {"HSMIC", NULL, "Headset Mic Bias"}, | |
107 | {"Headset Mic Bias", NULL, "Headset Jack"}, | |
108 | }; | |
109 | ||
110 | static int sdp3430_twl4030_init(struct snd_soc_codec *codec) | |
111 | { | |
112 | int ret; | |
113 | ||
114 | /* Add SDP3430 specific widgets */ | |
115 | ret = snd_soc_dapm_new_controls(codec, sdp3430_twl4030_dapm_widgets, | |
116 | ARRAY_SIZE(sdp3430_twl4030_dapm_widgets)); | |
117 | if (ret) | |
118 | return ret; | |
119 | ||
120 | /* Set up SDP3430 specific audio path audio_map */ | |
121 | snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); | |
122 | ||
123 | /* SDP3430 connected pins */ | |
124 | snd_soc_dapm_enable_pin(codec, "Ext Mic"); | |
125 | snd_soc_dapm_enable_pin(codec, "Ext Spk"); | |
de0b9888 | 126 | snd_soc_dapm_disable_pin(codec, "Headset Jack"); |
979c036e LCM |
127 | |
128 | /* TWL4030 not connected pins */ | |
129 | snd_soc_dapm_nc_pin(codec, "AUXL"); | |
130 | snd_soc_dapm_nc_pin(codec, "AUXR"); | |
131 | snd_soc_dapm_nc_pin(codec, "CARKITMIC"); | |
132 | snd_soc_dapm_nc_pin(codec, "DIGIMIC0"); | |
133 | snd_soc_dapm_nc_pin(codec, "DIGIMIC1"); | |
134 | ||
135 | snd_soc_dapm_nc_pin(codec, "OUTL"); | |
136 | snd_soc_dapm_nc_pin(codec, "OUTR"); | |
137 | snd_soc_dapm_nc_pin(codec, "EARPIECE"); | |
138 | snd_soc_dapm_nc_pin(codec, "PREDRIVEL"); | |
139 | snd_soc_dapm_nc_pin(codec, "PREDRIVER"); | |
140 | snd_soc_dapm_nc_pin(codec, "CARKITL"); | |
141 | snd_soc_dapm_nc_pin(codec, "CARKITR"); | |
142 | ||
143 | ret = snd_soc_dapm_sync(codec); | |
144 | ||
145 | return ret; | |
146 | } | |
147 | ||
de0b9888 LCM |
148 | /* Headset jack */ |
149 | static struct snd_soc_jack hs_jack; | |
150 | ||
151 | /* Headset jack detection DAPM pins */ | |
152 | static struct snd_soc_jack_pin hs_jack_pins[] = { | |
153 | { | |
154 | .pin = "Headset Jack", | |
155 | .mask = SND_JACK_HEADSET, | |
156 | }, | |
157 | }; | |
158 | ||
159 | /* Headset jack detection gpios */ | |
160 | static struct snd_soc_jack_gpio hs_jack_gpios[] = { | |
161 | { | |
162 | .gpio = (OMAP_MAX_GPIO_LINES + 2), | |
163 | .name = "hsdet-gpio", | |
164 | .report = SND_JACK_HEADSET, | |
165 | .debounce_time = 200, | |
166 | }, | |
167 | }; | |
168 | ||
4451582f MLC |
169 | /* Digital audio interface glue - connects codec <--> CPU */ |
170 | static struct snd_soc_dai_link sdp3430_dai = { | |
171 | .name = "TWL4030", | |
172 | .stream_name = "TWL4030", | |
173 | .cpu_dai = &omap_mcbsp_dai[0], | |
174 | .codec_dai = &twl4030_dai, | |
979c036e | 175 | .init = sdp3430_twl4030_init, |
4451582f MLC |
176 | .ops = &sdp3430_ops, |
177 | }; | |
178 | ||
179 | /* Audio machine driver */ | |
272edb00 | 180 | static struct snd_soc_card snd_soc_sdp3430 = { |
4451582f | 181 | .name = "SDP3430", |
87689d56 | 182 | .platform = &omap_soc_platform, |
4451582f MLC |
183 | .dai_link = &sdp3430_dai, |
184 | .num_links = 1, | |
185 | }; | |
186 | ||
187 | /* Audio subsystem */ | |
188 | static struct snd_soc_device sdp3430_snd_devdata = { | |
272edb00 | 189 | .card = &snd_soc_sdp3430, |
4451582f MLC |
190 | .codec_dev = &soc_codec_dev_twl4030, |
191 | }; | |
192 | ||
193 | static struct platform_device *sdp3430_snd_device; | |
194 | ||
195 | static int __init sdp3430_soc_init(void) | |
196 | { | |
197 | int ret; | |
198 | ||
199 | if (!machine_is_omap_3430sdp()) { | |
200 | pr_debug("Not SDP3430!\n"); | |
201 | return -ENODEV; | |
202 | } | |
203 | printk(KERN_INFO "SDP3430 SoC init\n"); | |
204 | ||
205 | sdp3430_snd_device = platform_device_alloc("soc-audio", -1); | |
206 | if (!sdp3430_snd_device) { | |
207 | printk(KERN_ERR "Platform device allocation failed\n"); | |
208 | return -ENOMEM; | |
209 | } | |
210 | ||
211 | platform_set_drvdata(sdp3430_snd_device, &sdp3430_snd_devdata); | |
212 | sdp3430_snd_devdata.dev = &sdp3430_snd_device->dev; | |
213 | *(unsigned int *)sdp3430_dai.cpu_dai->private_data = 1; /* McBSP2 */ | |
214 | ||
215 | ret = platform_device_add(sdp3430_snd_device); | |
216 | if (ret) | |
217 | goto err1; | |
218 | ||
de0b9888 LCM |
219 | /* Headset jack detection */ |
220 | ret = snd_soc_jack_new(&snd_soc_sdp3430, "SDP3430 headset jack", | |
221 | SND_JACK_HEADSET, &hs_jack); | |
222 | if (ret) | |
223 | return ret; | |
224 | ||
225 | ret = snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins), | |
226 | hs_jack_pins); | |
227 | if (ret) | |
228 | return ret; | |
229 | ||
230 | ret = snd_soc_jack_add_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios), | |
231 | hs_jack_gpios); | |
232 | ||
233 | return ret; | |
4451582f MLC |
234 | |
235 | err1: | |
236 | printk(KERN_ERR "Unable to add platform device\n"); | |
237 | platform_device_put(sdp3430_snd_device); | |
238 | ||
239 | return ret; | |
240 | } | |
241 | module_init(sdp3430_soc_init); | |
242 | ||
243 | static void __exit sdp3430_soc_exit(void) | |
244 | { | |
de0b9888 LCM |
245 | snd_soc_jack_free_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios), |
246 | hs_jack_gpios); | |
247 | ||
4451582f MLC |
248 | platform_device_unregister(sdp3430_snd_device); |
249 | } | |
250 | module_exit(sdp3430_soc_exit); | |
251 | ||
252 | MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>"); | |
253 | MODULE_DESCRIPTION("ALSA SoC SDP3430"); | |
254 | MODULE_LICENSE("GPL"); | |
255 |