blob: c1245623e6d3c0fe649e40b01c0d37ca891ab119 [file] [log] [blame]
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -05001/*
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>
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -050027
28#include <asm/mach-types.h>
29#include <mach/hardware.h>
30#include <mach/gpio.h>
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000031#include <mach/board-zoom.h>
Tony Lindgrence491cf2009-10-20 09:40:47 -070032#include <plat/mcbsp.h>
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -050033
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000034/* Register descriptions for twl4030 codec part */
Peter Ujfalusi57fe7252011-05-31 12:02:49 +030035#include <linux/mfd/twl4030-audio.h>
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000036
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -050037#include "omap-mcbsp.h"
38#include "omap-pcm.h"
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -050039
Candelaria Villareal, Jorge1b6ebdd2009-07-02 19:04:07 -050040#define ZOOM2_HEADSET_MUX_GPIO (OMAP_MAX_GPIO_LINES + 15)
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -050041
42static 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;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000046 struct snd_soc_dai *codec_dai = rtd->codec_dai;
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -050047 int ret;
48
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -050049 /* 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
60static struct snd_soc_ops zoom2_ops = {
61 .hw_params = zoom2_hw_params,
62};
63
64static int zoom2_hw_voice_params(struct snd_pcm_substream *substream,
65 struct snd_pcm_hw_params *params)
66{
67 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000068 struct snd_soc_dai *codec_dai = rtd->codec_dai;
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -050069 int ret;
70
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -050071 /* Set the codec system clock for DAC and ADC */
72 ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
73 SND_SOC_CLOCK_IN);
74 if (ret < 0) {
75 printk(KERN_ERR "can't set codec system clock\n");
76 return ret;
77 }
78
79 return 0;
80}
81
82static struct snd_soc_ops zoom2_voice_ops = {
83 .hw_params = zoom2_hw_voice_params,
84};
85
86/* Zoom2 machine DAPM */
87static const struct snd_soc_dapm_widget zoom2_twl4030_dapm_widgets[] = {
88 SND_SOC_DAPM_MIC("Ext Mic", NULL),
89 SND_SOC_DAPM_SPK("Ext Spk", NULL),
90 SND_SOC_DAPM_MIC("Headset Mic", NULL),
91 SND_SOC_DAPM_HP("Headset Stereophone", NULL),
92 SND_SOC_DAPM_LINE("Aux In", NULL),
93};
94
95static const struct snd_soc_dapm_route audio_map[] = {
96 /* External Mics: MAINMIC, SUBMIC with bias*/
97 {"MAINMIC", NULL, "Mic Bias 1"},
98 {"SUBMIC", NULL, "Mic Bias 2"},
99 {"Mic Bias 1", NULL, "Ext Mic"},
100 {"Mic Bias 2", NULL, "Ext Mic"},
101
102 /* External Speakers: HFL, HFR */
103 {"Ext Spk", NULL, "HFL"},
104 {"Ext Spk", NULL, "HFR"},
105
106 /* Headset Stereophone: HSOL, HSOR */
107 {"Headset Stereophone", NULL, "HSOL"},
108 {"Headset Stereophone", NULL, "HSOR"},
109
110 /* Headset Mic: HSMIC with bias */
111 {"HSMIC", NULL, "Headset Mic Bias"},
112 {"Headset Mic Bias", NULL, "Headset Mic"},
113
114 /* Aux In: AUXL, AUXR */
115 {"Aux In", NULL, "AUXL"},
116 {"Aux In", NULL, "AUXR"},
117};
118
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000119static int zoom2_twl4030_init(struct snd_soc_pcm_runtime *rtd)
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -0500120{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000121 struct snd_soc_codec *codec = rtd->codec;
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200122 struct snd_soc_dapm_context *dapm = &codec->dapm;
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -0500123 int ret;
124
125 /* Add Zoom2 specific widgets */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200126 ret = snd_soc_dapm_new_controls(dapm, zoom2_twl4030_dapm_widgets,
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -0500127 ARRAY_SIZE(zoom2_twl4030_dapm_widgets));
128 if (ret)
129 return ret;
130
131 /* Set up Zoom2 specific audio path audio_map */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200132 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -0500133
134 /* Zoom2 connected pins */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200135 snd_soc_dapm_enable_pin(dapm, "Ext Mic");
136 snd_soc_dapm_enable_pin(dapm, "Ext Spk");
137 snd_soc_dapm_enable_pin(dapm, "Headset Mic");
138 snd_soc_dapm_enable_pin(dapm, "Headset Stereophone");
139 snd_soc_dapm_enable_pin(dapm, "Aux In");
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -0500140
141 /* TWL4030 not connected pins */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200142 snd_soc_dapm_nc_pin(dapm, "CARKITMIC");
143 snd_soc_dapm_nc_pin(dapm, "DIGIMIC0");
144 snd_soc_dapm_nc_pin(dapm, "DIGIMIC1");
145 snd_soc_dapm_nc_pin(dapm, "EARPIECE");
146 snd_soc_dapm_nc_pin(dapm, "PREDRIVEL");
147 snd_soc_dapm_nc_pin(dapm, "PREDRIVER");
148 snd_soc_dapm_nc_pin(dapm, "CARKITL");
149 snd_soc_dapm_nc_pin(dapm, "CARKITR");
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -0500150
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200151 ret = snd_soc_dapm_sync(dapm);
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -0500152
153 return ret;
154}
155
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000156static int zoom2_twl4030_voice_init(struct snd_soc_pcm_runtime *rtd)
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -0500157{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000158 struct snd_soc_codec *codec = rtd->codec;
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -0500159 unsigned short reg;
160
161 /* Enable voice interface */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000162 reg = codec->driver->read(codec, TWL4030_REG_VOICE_IF);
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -0500163 reg |= TWL4030_VIF_DIN_EN | TWL4030_VIF_DOUT_EN | TWL4030_VIF_EN;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000164 codec->driver->write(codec, TWL4030_REG_VOICE_IF, reg);
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -0500165
166 return 0;
167}
168
169/* Digital audio interface glue - connects codec <--> CPU */
170static struct snd_soc_dai_link zoom2_dai[] = {
171 {
172 .name = "TWL4030 I2S",
173 .stream_name = "TWL4030 Audio",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000174 .cpu_dai_name = "omap-mcbsp-dai.1",
175 .codec_dai_name = "twl4030-hifi",
176 .platform_name = "omap-pcm-audio",
177 .codec_name = "twl4030-codec",
Jarkko Nikulacf9feff2011-09-30 16:07:45 +0300178 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
179 SND_SOC_DAIFMT_CBM_CFM,
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -0500180 .init = zoom2_twl4030_init,
181 .ops = &zoom2_ops,
182 },
183 {
184 .name = "TWL4030 PCM",
185 .stream_name = "TWL4030 Voice",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000186 .cpu_dai_name = "omap-mcbsp-dai.2",
187 .codec_dai_name = "twl4030-voice",
188 .platform_name = "omap-pcm-audio",
189 .codec_name = "twl4030-codec",
Jarkko Nikulacf9feff2011-09-30 16:07:45 +0300190 .dai_fmt = SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_IB_NF |
191 SND_SOC_DAIFMT_CBM_CFM,
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -0500192 .init = zoom2_twl4030_voice_init,
193 .ops = &zoom2_voice_ops,
194 },
195};
196
197/* Audio machine driver */
198static struct snd_soc_card snd_soc_zoom2 = {
199 .name = "Zoom2",
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -0500200 .dai_link = zoom2_dai,
201 .num_links = ARRAY_SIZE(zoom2_dai),
202};
203
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -0500204static struct platform_device *zoom2_snd_device;
205
206static int __init zoom2_soc_init(void)
207{
208 int ret;
209
Jarkko Nikulaec588ae2010-10-06 16:47:26 +0300210 if (!machine_is_omap_zoom2())
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -0500211 return -ENODEV;
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -0500212 printk(KERN_INFO "Zoom2 SoC init\n");
213
214 zoom2_snd_device = platform_device_alloc("soc-audio", -1);
215 if (!zoom2_snd_device) {
216 printk(KERN_ERR "Platform device allocation failed\n");
217 return -ENOMEM;
218 }
219
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000220 platform_set_drvdata(zoom2_snd_device, &snd_soc_zoom2);
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -0500221 ret = platform_device_add(zoom2_snd_device);
222 if (ret)
223 goto err1;
224
225 BUG_ON(gpio_request(ZOOM2_HEADSET_MUX_GPIO, "hs_mux") < 0);
226 gpio_direction_output(ZOOM2_HEADSET_MUX_GPIO, 0);
227
Candelaria Villareal, Jorge1b6ebdd2009-07-02 19:04:07 -0500228 BUG_ON(gpio_request(ZOOM2_HEADSET_EXTMUTE_GPIO, "ext_mute") < 0);
229 gpio_direction_output(ZOOM2_HEADSET_EXTMUTE_GPIO, 0);
230
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -0500231 return 0;
232
233err1:
234 printk(KERN_ERR "Unable to add platform device\n");
235 platform_device_put(zoom2_snd_device);
236
237 return ret;
238}
239module_init(zoom2_soc_init);
240
241static void __exit zoom2_soc_exit(void)
242{
243 gpio_free(ZOOM2_HEADSET_MUX_GPIO);
Candelaria Villareal, Jorge1b6ebdd2009-07-02 19:04:07 -0500244 gpio_free(ZOOM2_HEADSET_EXTMUTE_GPIO);
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -0500245
246 platform_device_unregister(zoom2_snd_device);
247}
248module_exit(zoom2_soc_exit);
249
250MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>");
251MODULE_DESCRIPTION("ALSA SoC Zoom2");
252MODULE_LICENSE("GPL");
253