]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - sound/soc/omap/zoom2.c
Merge branch 'for-3.1' into for-3.2
[mirror_ubuntu-bionic-kernel.git] / sound / soc / omap / zoom2.c
1 /*
2 * zoom2.c -- SoC audio for Zoom2
3 *
4 * Author: Misael Lopez Cruz <x0052729@ti.com>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18 * 02110-1301 USA
19 *
20 */
21
22 #include <linux/clk.h>
23 #include <linux/platform_device.h>
24 #include <sound/core.h>
25 #include <sound/pcm.h>
26 #include <sound/soc.h>
27
28 #include <asm/mach-types.h>
29 #include <mach/hardware.h>
30 #include <mach/gpio.h>
31 #include <mach/board-zoom.h>
32 #include <plat/mcbsp.h>
33
34 /* Register descriptions for twl4030 codec part */
35 #include <linux/mfd/twl4030-audio.h>
36
37 #include "omap-mcbsp.h"
38 #include "omap-pcm.h"
39
40 #define ZOOM2_HEADSET_MUX_GPIO (OMAP_MAX_GPIO_LINES + 15)
41
42 static int zoom2_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->codec_dai;
47 int ret;
48
49 /* Set the codec system clock for DAC and ADC */
50 ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
51 SND_SOC_CLOCK_IN);
52 if (ret < 0) {
53 printk(KERN_ERR "can't set codec system clock\n");
54 return ret;
55 }
56
57 return 0;
58 }
59
60 static struct snd_soc_ops zoom2_ops = {
61 .hw_params = zoom2_hw_params,
62 };
63
64 /* Zoom2 machine DAPM */
65 static const struct snd_soc_dapm_widget zoom2_twl4030_dapm_widgets[] = {
66 SND_SOC_DAPM_MIC("Ext Mic", NULL),
67 SND_SOC_DAPM_SPK("Ext Spk", NULL),
68 SND_SOC_DAPM_MIC("Headset Mic", NULL),
69 SND_SOC_DAPM_HP("Headset Stereophone", NULL),
70 SND_SOC_DAPM_LINE("Aux In", NULL),
71 };
72
73 static const struct snd_soc_dapm_route audio_map[] = {
74 /* External Mics: MAINMIC, SUBMIC with bias*/
75 {"MAINMIC", NULL, "Mic Bias 1"},
76 {"SUBMIC", NULL, "Mic Bias 2"},
77 {"Mic Bias 1", NULL, "Ext Mic"},
78 {"Mic Bias 2", NULL, "Ext Mic"},
79
80 /* External Speakers: HFL, HFR */
81 {"Ext Spk", NULL, "HFL"},
82 {"Ext Spk", NULL, "HFR"},
83
84 /* Headset Stereophone: HSOL, HSOR */
85 {"Headset Stereophone", NULL, "HSOL"},
86 {"Headset Stereophone", NULL, "HSOR"},
87
88 /* Headset Mic: HSMIC with bias */
89 {"HSMIC", NULL, "Headset Mic Bias"},
90 {"Headset Mic Bias", NULL, "Headset Mic"},
91
92 /* Aux In: AUXL, AUXR */
93 {"Aux In", NULL, "AUXL"},
94 {"Aux In", NULL, "AUXR"},
95 };
96
97 static int zoom2_twl4030_init(struct snd_soc_pcm_runtime *rtd)
98 {
99 struct snd_soc_codec *codec = rtd->codec;
100 struct snd_soc_dapm_context *dapm = &codec->dapm;
101 int ret;
102
103 /* Add Zoom2 specific widgets */
104 ret = snd_soc_dapm_new_controls(dapm, zoom2_twl4030_dapm_widgets,
105 ARRAY_SIZE(zoom2_twl4030_dapm_widgets));
106 if (ret)
107 return ret;
108
109 /* Set up Zoom2 specific audio path audio_map */
110 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
111
112 /* Zoom2 connected pins */
113 snd_soc_dapm_enable_pin(dapm, "Ext Mic");
114 snd_soc_dapm_enable_pin(dapm, "Ext Spk");
115 snd_soc_dapm_enable_pin(dapm, "Headset Mic");
116 snd_soc_dapm_enable_pin(dapm, "Headset Stereophone");
117 snd_soc_dapm_enable_pin(dapm, "Aux In");
118
119 /* TWL4030 not connected pins */
120 snd_soc_dapm_nc_pin(dapm, "CARKITMIC");
121 snd_soc_dapm_nc_pin(dapm, "DIGIMIC0");
122 snd_soc_dapm_nc_pin(dapm, "DIGIMIC1");
123 snd_soc_dapm_nc_pin(dapm, "EARPIECE");
124 snd_soc_dapm_nc_pin(dapm, "PREDRIVEL");
125 snd_soc_dapm_nc_pin(dapm, "PREDRIVER");
126 snd_soc_dapm_nc_pin(dapm, "CARKITL");
127 snd_soc_dapm_nc_pin(dapm, "CARKITR");
128
129 ret = snd_soc_dapm_sync(dapm);
130
131 return ret;
132 }
133
134 static int zoom2_twl4030_voice_init(struct snd_soc_pcm_runtime *rtd)
135 {
136 struct snd_soc_codec *codec = rtd->codec;
137 unsigned short reg;
138
139 /* Enable voice interface */
140 reg = codec->driver->read(codec, TWL4030_REG_VOICE_IF);
141 reg |= TWL4030_VIF_DIN_EN | TWL4030_VIF_DOUT_EN | TWL4030_VIF_EN;
142 codec->driver->write(codec, TWL4030_REG_VOICE_IF, reg);
143
144 return 0;
145 }
146
147 /* Digital audio interface glue - connects codec <--> CPU */
148 static struct snd_soc_dai_link zoom2_dai[] = {
149 {
150 .name = "TWL4030 I2S",
151 .stream_name = "TWL4030 Audio",
152 .cpu_dai_name = "omap-mcbsp-dai.1",
153 .codec_dai_name = "twl4030-hifi",
154 .platform_name = "omap-pcm-audio",
155 .codec_name = "twl4030-codec",
156 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
157 SND_SOC_DAIFMT_CBM_CFM,
158 .init = zoom2_twl4030_init,
159 .ops = &zoom2_ops,
160 },
161 {
162 .name = "TWL4030 PCM",
163 .stream_name = "TWL4030 Voice",
164 .cpu_dai_name = "omap-mcbsp-dai.2",
165 .codec_dai_name = "twl4030-voice",
166 .platform_name = "omap-pcm-audio",
167 .codec_name = "twl4030-codec",
168 .dai_fmt = SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_IB_NF |
169 SND_SOC_DAIFMT_CBM_CFM,
170 .init = zoom2_twl4030_voice_init,
171 .ops = &zoom2_ops,
172 },
173 };
174
175 /* Audio machine driver */
176 static struct snd_soc_card snd_soc_zoom2 = {
177 .name = "Zoom2",
178 .dai_link = zoom2_dai,
179 .num_links = ARRAY_SIZE(zoom2_dai),
180 };
181
182 static struct platform_device *zoom2_snd_device;
183
184 static int __init zoom2_soc_init(void)
185 {
186 int ret;
187
188 if (!machine_is_omap_zoom2())
189 return -ENODEV;
190 printk(KERN_INFO "Zoom2 SoC init\n");
191
192 zoom2_snd_device = platform_device_alloc("soc-audio", -1);
193 if (!zoom2_snd_device) {
194 printk(KERN_ERR "Platform device allocation failed\n");
195 return -ENOMEM;
196 }
197
198 platform_set_drvdata(zoom2_snd_device, &snd_soc_zoom2);
199 ret = platform_device_add(zoom2_snd_device);
200 if (ret)
201 goto err1;
202
203 BUG_ON(gpio_request(ZOOM2_HEADSET_MUX_GPIO, "hs_mux") < 0);
204 gpio_direction_output(ZOOM2_HEADSET_MUX_GPIO, 0);
205
206 BUG_ON(gpio_request(ZOOM2_HEADSET_EXTMUTE_GPIO, "ext_mute") < 0);
207 gpio_direction_output(ZOOM2_HEADSET_EXTMUTE_GPIO, 0);
208
209 return 0;
210
211 err1:
212 printk(KERN_ERR "Unable to add platform device\n");
213 platform_device_put(zoom2_snd_device);
214
215 return ret;
216 }
217 module_init(zoom2_soc_init);
218
219 static void __exit zoom2_soc_exit(void)
220 {
221 gpio_free(ZOOM2_HEADSET_MUX_GPIO);
222 gpio_free(ZOOM2_HEADSET_EXTMUTE_GPIO);
223
224 platform_device_unregister(zoom2_snd_device);
225 }
226 module_exit(zoom2_soc_exit);
227
228 MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>");
229 MODULE_DESCRIPTION("ALSA SoC Zoom2");
230 MODULE_LICENSE("GPL");
231