ASoC: omap: Convert bunch of machine drivers to use init time DAI format
[deliverable/linux.git] / sound / soc / omap / sdp3430.c
... / ...
CommitLineData
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 <linux/i2c/twl.h>
28#include <sound/core.h>
29#include <sound/pcm.h>
30#include <sound/soc.h>
31#include <sound/jack.h>
32
33#include <asm/mach-types.h>
34#include <mach/hardware.h>
35#include <mach/gpio.h>
36#include <plat/mcbsp.h>
37
38/* Register descriptions for twl4030 codec part */
39#include <linux/mfd/twl4030-audio.h>
40
41#include "omap-mcbsp.h"
42#include "omap-pcm.h"
43
44/* TWL4030 PMBR1 Register */
45#define TWL4030_INTBR_PMBR1 0x0D
46/* TWL4030 PMBR1 Register GPIO6 mux bit */
47#define TWL4030_GPIO6_PWM0_MUTE(value) (value << 2)
48
49static struct snd_soc_card snd_soc_sdp3430;
50
51static int sdp3430_hw_params(struct snd_pcm_substream *substream,
52 struct snd_pcm_hw_params *params)
53{
54 struct snd_soc_pcm_runtime *rtd = substream->private_data;
55 struct snd_soc_dai *codec_dai = rtd->codec_dai;
56 int ret;
57
58 /* Set the codec system clock for DAC and ADC */
59 ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
60 SND_SOC_CLOCK_IN);
61 if (ret < 0) {
62 printk(KERN_ERR "can't set codec system clock\n");
63 return ret;
64 }
65
66 return 0;
67}
68
69static struct snd_soc_ops sdp3430_ops = {
70 .hw_params = sdp3430_hw_params,
71};
72
73static int sdp3430_hw_voice_params(struct snd_pcm_substream *substream,
74 struct snd_pcm_hw_params *params)
75{
76 struct snd_soc_pcm_runtime *rtd = substream->private_data;
77 struct snd_soc_dai *codec_dai = rtd->codec_dai;
78 int ret;
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_voice_ops = {
92 .hw_params = sdp3430_hw_voice_params,
93};
94
95/* Headset jack */
96static struct snd_soc_jack hs_jack;
97
98/* Headset jack detection DAPM pins */
99static struct snd_soc_jack_pin hs_jack_pins[] = {
100 {
101 .pin = "Headset Mic",
102 .mask = SND_JACK_MICROPHONE,
103 },
104 {
105 .pin = "Headset Stereophone",
106 .mask = SND_JACK_HEADPHONE,
107 },
108};
109
110/* Headset jack detection gpios */
111static struct snd_soc_jack_gpio hs_jack_gpios[] = {
112 {
113 .gpio = (OMAP_MAX_GPIO_LINES + 2),
114 .name = "hsdet-gpio",
115 .report = SND_JACK_HEADSET,
116 .debounce_time = 200,
117 },
118};
119
120/* SDP3430 machine DAPM */
121static const struct snd_soc_dapm_widget sdp3430_twl4030_dapm_widgets[] = {
122 SND_SOC_DAPM_MIC("Ext Mic", NULL),
123 SND_SOC_DAPM_SPK("Ext Spk", NULL),
124 SND_SOC_DAPM_MIC("Headset Mic", NULL),
125 SND_SOC_DAPM_HP("Headset Stereophone", NULL),
126};
127
128static const struct snd_soc_dapm_route audio_map[] = {
129 /* External Mics: MAINMIC, SUBMIC with bias*/
130 {"MAINMIC", NULL, "Mic Bias 1"},
131 {"SUBMIC", NULL, "Mic Bias 2"},
132 {"Mic Bias 1", NULL, "Ext Mic"},
133 {"Mic Bias 2", NULL, "Ext Mic"},
134
135 /* External Speakers: HFL, HFR */
136 {"Ext Spk", NULL, "HFL"},
137 {"Ext Spk", NULL, "HFR"},
138
139 /* Headset Mic: HSMIC with bias */
140 {"HSMIC", NULL, "Headset Mic Bias"},
141 {"Headset Mic Bias", NULL, "Headset Mic"},
142
143 /* Headset Stereophone (Headphone): HSOL, HSOR */
144 {"Headset Stereophone", NULL, "HSOL"},
145 {"Headset Stereophone", NULL, "HSOR"},
146};
147
148static int sdp3430_twl4030_init(struct snd_soc_pcm_runtime *rtd)
149{
150 struct snd_soc_codec *codec = rtd->codec;
151 struct snd_soc_dapm_context *dapm = &codec->dapm;
152 int ret;
153
154 /* Add SDP3430 specific widgets */
155 ret = snd_soc_dapm_new_controls(dapm, sdp3430_twl4030_dapm_widgets,
156 ARRAY_SIZE(sdp3430_twl4030_dapm_widgets));
157 if (ret)
158 return ret;
159
160 /* Set up SDP3430 specific audio path audio_map */
161 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
162
163 /* SDP3430 connected pins */
164 snd_soc_dapm_enable_pin(dapm, "Ext Mic");
165 snd_soc_dapm_enable_pin(dapm, "Ext Spk");
166 snd_soc_dapm_disable_pin(dapm, "Headset Mic");
167 snd_soc_dapm_disable_pin(dapm, "Headset Stereophone");
168
169 /* TWL4030 not connected pins */
170 snd_soc_dapm_nc_pin(dapm, "AUXL");
171 snd_soc_dapm_nc_pin(dapm, "AUXR");
172 snd_soc_dapm_nc_pin(dapm, "CARKITMIC");
173 snd_soc_dapm_nc_pin(dapm, "DIGIMIC0");
174 snd_soc_dapm_nc_pin(dapm, "DIGIMIC1");
175
176 snd_soc_dapm_nc_pin(dapm, "OUTL");
177 snd_soc_dapm_nc_pin(dapm, "OUTR");
178 snd_soc_dapm_nc_pin(dapm, "EARPIECE");
179 snd_soc_dapm_nc_pin(dapm, "PREDRIVEL");
180 snd_soc_dapm_nc_pin(dapm, "PREDRIVER");
181 snd_soc_dapm_nc_pin(dapm, "CARKITL");
182 snd_soc_dapm_nc_pin(dapm, "CARKITR");
183
184 ret = snd_soc_dapm_sync(dapm);
185 if (ret)
186 return ret;
187
188 /* Headset jack detection */
189 ret = snd_soc_jack_new(codec, "Headset Jack",
190 SND_JACK_HEADSET, &hs_jack);
191 if (ret)
192 return ret;
193
194 ret = snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins),
195 hs_jack_pins);
196 if (ret)
197 return ret;
198
199 ret = snd_soc_jack_add_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios),
200 hs_jack_gpios);
201
202 return ret;
203}
204
205static int sdp3430_twl4030_voice_init(struct snd_soc_pcm_runtime *rtd)
206{
207 struct snd_soc_codec *codec = rtd->codec;
208 unsigned short reg;
209
210 /* Enable voice interface */
211 reg = codec->driver->read(codec, TWL4030_REG_VOICE_IF);
212 reg |= TWL4030_VIF_DIN_EN | TWL4030_VIF_DOUT_EN | TWL4030_VIF_EN;
213 codec->driver->write(codec, TWL4030_REG_VOICE_IF, reg);
214
215 return 0;
216}
217
218
219/* Digital audio interface glue - connects codec <--> CPU */
220static struct snd_soc_dai_link sdp3430_dai[] = {
221 {
222 .name = "TWL4030 I2S",
223 .stream_name = "TWL4030 Audio",
224 .cpu_dai_name = "omap-mcbsp-dai.1",
225 .codec_dai_name = "twl4030-hifi",
226 .platform_name = "omap-pcm-audio",
227 .codec_name = "twl4030-codec",
228 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
229 SND_SOC_DAIFMT_CBM_CFM,
230 .init = sdp3430_twl4030_init,
231 .ops = &sdp3430_ops,
232 },
233 {
234 .name = "TWL4030 PCM",
235 .stream_name = "TWL4030 Voice",
236 .cpu_dai_name = "omap-mcbsp-dai.2",
237 .codec_dai_name = "twl4030-voice",
238 .platform_name = "omap-pcm-audio",
239 .codec_name = "twl4030-codec",
240 .dai_fmt = SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_IB_NF |
241 SND_SOC_DAIFMT_CBM_CFM,
242 .init = sdp3430_twl4030_voice_init,
243 .ops = &sdp3430_voice_ops,
244 },
245};
246
247/* Audio machine driver */
248static struct snd_soc_card snd_soc_sdp3430 = {
249 .name = "SDP3430",
250 .dai_link = sdp3430_dai,
251 .num_links = ARRAY_SIZE(sdp3430_dai),
252};
253
254static struct platform_device *sdp3430_snd_device;
255
256static int __init sdp3430_soc_init(void)
257{
258 int ret;
259 u8 pin_mux;
260
261 if (!machine_is_omap_3430sdp())
262 return -ENODEV;
263 printk(KERN_INFO "SDP3430 SoC init\n");
264
265 sdp3430_snd_device = platform_device_alloc("soc-audio", -1);
266 if (!sdp3430_snd_device) {
267 printk(KERN_ERR "Platform device allocation failed\n");
268 return -ENOMEM;
269 }
270
271 platform_set_drvdata(sdp3430_snd_device, &snd_soc_sdp3430);
272
273 /* Set TWL4030 GPIO6 as EXTMUTE signal */
274 twl_i2c_read_u8(TWL4030_MODULE_INTBR, &pin_mux,
275 TWL4030_INTBR_PMBR1);
276 pin_mux &= ~TWL4030_GPIO6_PWM0_MUTE(0x03);
277 pin_mux |= TWL4030_GPIO6_PWM0_MUTE(0x02);
278 twl_i2c_write_u8(TWL4030_MODULE_INTBR, pin_mux,
279 TWL4030_INTBR_PMBR1);
280
281 ret = platform_device_add(sdp3430_snd_device);
282 if (ret)
283 goto err1;
284
285 return 0;
286
287err1:
288 printk(KERN_ERR "Unable to add platform device\n");
289 platform_device_put(sdp3430_snd_device);
290
291 return ret;
292}
293module_init(sdp3430_soc_init);
294
295static void __exit sdp3430_soc_exit(void)
296{
297 snd_soc_jack_free_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios),
298 hs_jack_gpios);
299
300 platform_device_unregister(sdp3430_snd_device);
301}
302module_exit(sdp3430_soc_exit);
303
304MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>");
305MODULE_DESCRIPTION("ALSA SoC SDP3430");
306MODULE_LICENSE("GPL");
307
This page took 0.028948 seconds and 5 git commands to generate.