ASoC: tegra: fix maxburst settings in dmaengine code
[deliverable/linux.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>
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>
ce491cf8 36#include <plat/mcbsp.h>
4451582f 37
f0fba2ad 38/* Register descriptions for twl4030 codec part */
57fe7251 39#include <linux/mfd/twl4030-audio.h>
da155d5b 40#include <linux/module.h>
f0fba2ad 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 56 struct snd_soc_dai *codec_dai = rtd->codec_dai;
4451582f
MLC
57 int ret;
58
4451582f
MLC
59 /* Set the codec system clock for DAC and ADC */
60 ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
61 SND_SOC_CLOCK_IN);
62 if (ret < 0) {
63 printk(KERN_ERR "can't set codec system clock\n");
64 return ret;
65 }
66
67 return 0;
68}
69
70static struct snd_soc_ops sdp3430_ops = {
71 .hw_params = sdp3430_hw_params,
72};
73
77dd7e17
LCM
74/* Headset jack */
75static struct snd_soc_jack hs_jack;
76
77/* Headset jack detection DAPM pins */
78static struct snd_soc_jack_pin hs_jack_pins[] = {
79 {
63208774
LCM
80 .pin = "Headset Mic",
81 .mask = SND_JACK_MICROPHONE,
82 },
83 {
84 .pin = "Headset Stereophone",
85 .mask = SND_JACK_HEADPHONE,
77dd7e17
LCM
86 },
87};
88
89/* Headset jack detection gpios */
90static struct snd_soc_jack_gpio hs_jack_gpios[] = {
91 {
92 .gpio = (OMAP_MAX_GPIO_LINES + 2),
93 .name = "hsdet-gpio",
94 .report = SND_JACK_HEADSET,
95 .debounce_time = 200,
96 },
97};
98
979c036e
LCM
99/* SDP3430 machine DAPM */
100static const struct snd_soc_dapm_widget sdp3430_twl4030_dapm_widgets[] = {
101 SND_SOC_DAPM_MIC("Ext Mic", NULL),
102 SND_SOC_DAPM_SPK("Ext Spk", NULL),
63208774
LCM
103 SND_SOC_DAPM_MIC("Headset Mic", NULL),
104 SND_SOC_DAPM_HP("Headset Stereophone", NULL),
979c036e
LCM
105};
106
107static const struct snd_soc_dapm_route audio_map[] = {
108 /* External Mics: MAINMIC, SUBMIC with bias*/
109 {"MAINMIC", NULL, "Mic Bias 1"},
110 {"SUBMIC", NULL, "Mic Bias 2"},
111 {"Mic Bias 1", NULL, "Ext Mic"},
112 {"Mic Bias 2", NULL, "Ext Mic"},
113
114 /* External Speakers: HFL, HFR */
115 {"Ext Spk", NULL, "HFL"},
116 {"Ext Spk", NULL, "HFR"},
117
63208774 118 /* Headset Mic: HSMIC with bias */
979c036e 119 {"HSMIC", NULL, "Headset Mic Bias"},
63208774
LCM
120 {"Headset Mic Bias", NULL, "Headset Mic"},
121
122 /* Headset Stereophone (Headphone): HSOL, HSOR */
123 {"Headset Stereophone", NULL, "HSOL"},
124 {"Headset Stereophone", NULL, "HSOR"},
979c036e
LCM
125};
126
f0fba2ad 127static int sdp3430_twl4030_init(struct snd_soc_pcm_runtime *rtd)
979c036e 128{
f0fba2ad 129 struct snd_soc_codec *codec = rtd->codec;
ce6120cc 130 struct snd_soc_dapm_context *dapm = &codec->dapm;
979c036e
LCM
131 int ret;
132
979c036e 133 /* SDP3430 connected pins */
ce6120cc
LG
134 snd_soc_dapm_enable_pin(dapm, "Ext Mic");
135 snd_soc_dapm_enable_pin(dapm, "Ext Spk");
136 snd_soc_dapm_disable_pin(dapm, "Headset Mic");
137 snd_soc_dapm_disable_pin(dapm, "Headset Stereophone");
979c036e
LCM
138
139 /* TWL4030 not connected pins */
ce6120cc
LG
140 snd_soc_dapm_nc_pin(dapm, "AUXL");
141 snd_soc_dapm_nc_pin(dapm, "AUXR");
142 snd_soc_dapm_nc_pin(dapm, "CARKITMIC");
143 snd_soc_dapm_nc_pin(dapm, "DIGIMIC0");
144 snd_soc_dapm_nc_pin(dapm, "DIGIMIC1");
145
146 snd_soc_dapm_nc_pin(dapm, "OUTL");
147 snd_soc_dapm_nc_pin(dapm, "OUTR");
148 snd_soc_dapm_nc_pin(dapm, "EARPIECE");
149 snd_soc_dapm_nc_pin(dapm, "PREDRIVEL");
150 snd_soc_dapm_nc_pin(dapm, "PREDRIVER");
151 snd_soc_dapm_nc_pin(dapm, "CARKITL");
152 snd_soc_dapm_nc_pin(dapm, "CARKITR");
153
77dd7e17 154 /* Headset jack detection */
f0fba2ad 155 ret = snd_soc_jack_new(codec, "Headset Jack",
77dd7e17
LCM
156 SND_JACK_HEADSET, &hs_jack);
157 if (ret)
158 return ret;
979c036e 159
77dd7e17
LCM
160 ret = snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins),
161 hs_jack_pins);
162 if (ret)
163 return ret;
de0b9888 164
77dd7e17
LCM
165 ret = snd_soc_jack_add_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios),
166 hs_jack_gpios);
de0b9888 167
77dd7e17
LCM
168 return ret;
169}
de0b9888 170
f0fba2ad 171static int sdp3430_twl4030_voice_init(struct snd_soc_pcm_runtime *rtd)
11a72811 172{
f0fba2ad 173 struct snd_soc_codec *codec = rtd->codec;
11a72811
LCM
174 unsigned short reg;
175
176 /* Enable voice interface */
f0fba2ad 177 reg = codec->driver->read(codec, TWL4030_REG_VOICE_IF);
11a72811 178 reg |= TWL4030_VIF_DIN_EN | TWL4030_VIF_DOUT_EN | TWL4030_VIF_EN;
f0fba2ad 179 codec->driver->write(codec, TWL4030_REG_VOICE_IF, reg);
11a72811
LCM
180
181 return 0;
182}
183
184
4451582f 185/* Digital audio interface glue - connects codec <--> CPU */
11a72811
LCM
186static struct snd_soc_dai_link sdp3430_dai[] = {
187 {
188 .name = "TWL4030 I2S",
189 .stream_name = "TWL4030 Audio",
45656b44 190 .cpu_dai_name = "omap-mcbsp.2",
f0fba2ad
LG
191 .codec_dai_name = "twl4030-hifi",
192 .platform_name = "omap-pcm-audio",
193 .codec_name = "twl4030-codec",
cf9feff2
JN
194 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
195 SND_SOC_DAIFMT_CBM_CFM,
11a72811
LCM
196 .init = sdp3430_twl4030_init,
197 .ops = &sdp3430_ops,
198 },
199 {
200 .name = "TWL4030 PCM",
201 .stream_name = "TWL4030 Voice",
45656b44 202 .cpu_dai_name = "omap-mcbsp.3",
f0fba2ad
LG
203 .codec_dai_name = "twl4030-voice",
204 .platform_name = "omap-pcm-audio",
205 .codec_name = "twl4030-codec",
cf9feff2
JN
206 .dai_fmt = SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_IB_NF |
207 SND_SOC_DAIFMT_CBM_CFM,
11a72811 208 .init = sdp3430_twl4030_voice_init,
a3c6dac2 209 .ops = &sdp3430_ops,
11a72811 210 },
4451582f
MLC
211};
212
213/* Audio machine driver */
272edb00 214static struct snd_soc_card snd_soc_sdp3430 = {
4451582f 215 .name = "SDP3430",
b425b884 216 .owner = THIS_MODULE,
11a72811
LCM
217 .dai_link = sdp3430_dai,
218 .num_links = ARRAY_SIZE(sdp3430_dai),
f8cf149f
PU
219
220 .dapm_widgets = sdp3430_twl4030_dapm_widgets,
221 .num_dapm_widgets = ARRAY_SIZE(sdp3430_twl4030_dapm_widgets),
222 .dapm_routes = audio_map,
223 .num_dapm_routes = ARRAY_SIZE(audio_map),
4451582f
MLC
224};
225
4451582f
MLC
226static struct platform_device *sdp3430_snd_device;
227
228static int __init sdp3430_soc_init(void)
229{
230 int ret;
30cd0c4a 231 u8 pin_mux;
4451582f 232
ec588ae6 233 if (!machine_is_omap_3430sdp())
4451582f 234 return -ENODEV;
4451582f
MLC
235 printk(KERN_INFO "SDP3430 SoC init\n");
236
237 sdp3430_snd_device = platform_device_alloc("soc-audio", -1);
238 if (!sdp3430_snd_device) {
239 printk(KERN_ERR "Platform device allocation failed\n");
240 return -ENOMEM;
241 }
242
f0fba2ad 243 platform_set_drvdata(sdp3430_snd_device, &snd_soc_sdp3430);
4451582f 244
c5910a70 245 /* Set TWL4030 GPIO6 as EXTMUTE signal */
ebeb53e1 246 twl_i2c_read_u8(TWL4030_MODULE_INTBR, &pin_mux,
30cd0c4a
CVJ
247 TWL4030_INTBR_PMBR1);
248 pin_mux &= ~TWL4030_GPIO6_PWM0_MUTE(0x03);
249 pin_mux |= TWL4030_GPIO6_PWM0_MUTE(0x02);
ebeb53e1 250 twl_i2c_write_u8(TWL4030_MODULE_INTBR, pin_mux,
30cd0c4a 251 TWL4030_INTBR_PMBR1);
c5910a70 252
4451582f
MLC
253 ret = platform_device_add(sdp3430_snd_device);
254 if (ret)
255 goto err1;
256
77dd7e17 257 return 0;
4451582f
MLC
258
259err1:
260 printk(KERN_ERR "Unable to add platform device\n");
261 platform_device_put(sdp3430_snd_device);
262
263 return ret;
264}
265module_init(sdp3430_soc_init);
266
267static void __exit sdp3430_soc_exit(void)
268{
de0b9888
LCM
269 snd_soc_jack_free_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios),
270 hs_jack_gpios);
271
4451582f
MLC
272 platform_device_unregister(sdp3430_snd_device);
273}
274module_exit(sdp3430_soc_exit);
275
276MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>");
277MODULE_DESCRIPTION("ALSA SoC SDP3430");
278MODULE_LICENSE("GPL");
279
This page took 0.175157 seconds and 5 git commands to generate.