Merge branch 'for-linus' of git://git.selinuxproject.org/~jmorris/linux-security
[deliverable/linux.git] / sound / soc / omap / zoom2.c
CommitLineData
df205936
LCM
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>
df205936
LCM
27
28#include <asm/mach-types.h>
29#include <mach/hardware.h>
30#include <mach/gpio.h>
f0fba2ad 31#include <mach/board-zoom.h>
ce491cf8 32#include <plat/mcbsp.h>
df205936 33
f0fba2ad 34/* Register descriptions for twl4030 codec part */
57fe7251 35#include <linux/mfd/twl4030-audio.h>
f0fba2ad 36
df205936
LCM
37#include "omap-mcbsp.h"
38#include "omap-pcm.h"
df205936 39
1b6ebdd7 40#define ZOOM2_HEADSET_MUX_GPIO (OMAP_MAX_GPIO_LINES + 15)
df205936
LCM
41
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;
f0fba2ad 46 struct snd_soc_dai *codec_dai = rtd->codec_dai;
df205936
LCM
47 int ret;
48
df205936
LCM
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
60static struct snd_soc_ops zoom2_ops = {
61 .hw_params = zoom2_hw_params,
62};
63
df205936
LCM
64/* Zoom2 machine DAPM */
65static 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
73static 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
f0fba2ad 97static int zoom2_twl4030_init(struct snd_soc_pcm_runtime *rtd)
df205936 98{
f0fba2ad 99 struct snd_soc_codec *codec = rtd->codec;
ce6120cc 100 struct snd_soc_dapm_context *dapm = &codec->dapm;
df205936 101
df205936 102 /* TWL4030 not connected pins */
ce6120cc
LG
103 snd_soc_dapm_nc_pin(dapm, "CARKITMIC");
104 snd_soc_dapm_nc_pin(dapm, "DIGIMIC0");
105 snd_soc_dapm_nc_pin(dapm, "DIGIMIC1");
106 snd_soc_dapm_nc_pin(dapm, "EARPIECE");
107 snd_soc_dapm_nc_pin(dapm, "PREDRIVEL");
108 snd_soc_dapm_nc_pin(dapm, "PREDRIVER");
109 snd_soc_dapm_nc_pin(dapm, "CARKITL");
110 snd_soc_dapm_nc_pin(dapm, "CARKITR");
111
cb424877 112 return 0;
df205936
LCM
113}
114
f0fba2ad 115static int zoom2_twl4030_voice_init(struct snd_soc_pcm_runtime *rtd)
df205936 116{
f0fba2ad 117 struct snd_soc_codec *codec = rtd->codec;
df205936
LCM
118 unsigned short reg;
119
120 /* Enable voice interface */
f0fba2ad 121 reg = codec->driver->read(codec, TWL4030_REG_VOICE_IF);
df205936 122 reg |= TWL4030_VIF_DIN_EN | TWL4030_VIF_DOUT_EN | TWL4030_VIF_EN;
f0fba2ad 123 codec->driver->write(codec, TWL4030_REG_VOICE_IF, reg);
df205936
LCM
124
125 return 0;
126}
127
128/* Digital audio interface glue - connects codec <--> CPU */
129static struct snd_soc_dai_link zoom2_dai[] = {
130 {
131 .name = "TWL4030 I2S",
132 .stream_name = "TWL4030 Audio",
f0fba2ad
LG
133 .cpu_dai_name = "omap-mcbsp-dai.1",
134 .codec_dai_name = "twl4030-hifi",
135 .platform_name = "omap-pcm-audio",
136 .codec_name = "twl4030-codec",
cf9feff2
JN
137 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
138 SND_SOC_DAIFMT_CBM_CFM,
df205936
LCM
139 .init = zoom2_twl4030_init,
140 .ops = &zoom2_ops,
141 },
142 {
143 .name = "TWL4030 PCM",
144 .stream_name = "TWL4030 Voice",
f0fba2ad
LG
145 .cpu_dai_name = "omap-mcbsp-dai.2",
146 .codec_dai_name = "twl4030-voice",
147 .platform_name = "omap-pcm-audio",
148 .codec_name = "twl4030-codec",
cf9feff2
JN
149 .dai_fmt = SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_IB_NF |
150 SND_SOC_DAIFMT_CBM_CFM,
df205936 151 .init = zoom2_twl4030_voice_init,
a3c6dac2 152 .ops = &zoom2_ops,
df205936
LCM
153 },
154};
155
156/* Audio machine driver */
157static struct snd_soc_card snd_soc_zoom2 = {
158 .name = "Zoom2",
df205936
LCM
159 .dai_link = zoom2_dai,
160 .num_links = ARRAY_SIZE(zoom2_dai),
1083dbd1
PU
161
162 .dapm_widgets = zoom2_twl4030_dapm_widgets,
163 .num_dapm_widgets = ARRAY_SIZE(zoom2_twl4030_dapm_widgets),
164 .dapm_routes = audio_map,
165 .num_dapm_routes = ARRAY_SIZE(audio_map),
df205936
LCM
166};
167
df205936
LCM
168static struct platform_device *zoom2_snd_device;
169
170static int __init zoom2_soc_init(void)
171{
172 int ret;
173
ec588ae6 174 if (!machine_is_omap_zoom2())
df205936 175 return -ENODEV;
df205936
LCM
176 printk(KERN_INFO "Zoom2 SoC init\n");
177
178 zoom2_snd_device = platform_device_alloc("soc-audio", -1);
179 if (!zoom2_snd_device) {
180 printk(KERN_ERR "Platform device allocation failed\n");
181 return -ENOMEM;
182 }
183
f0fba2ad 184 platform_set_drvdata(zoom2_snd_device, &snd_soc_zoom2);
df205936
LCM
185 ret = platform_device_add(zoom2_snd_device);
186 if (ret)
187 goto err1;
188
189 BUG_ON(gpio_request(ZOOM2_HEADSET_MUX_GPIO, "hs_mux") < 0);
190 gpio_direction_output(ZOOM2_HEADSET_MUX_GPIO, 0);
191
1b6ebdd7
CVJ
192 BUG_ON(gpio_request(ZOOM2_HEADSET_EXTMUTE_GPIO, "ext_mute") < 0);
193 gpio_direction_output(ZOOM2_HEADSET_EXTMUTE_GPIO, 0);
194
df205936
LCM
195 return 0;
196
197err1:
198 printk(KERN_ERR "Unable to add platform device\n");
199 platform_device_put(zoom2_snd_device);
200
201 return ret;
202}
203module_init(zoom2_soc_init);
204
205static void __exit zoom2_soc_exit(void)
206{
207 gpio_free(ZOOM2_HEADSET_MUX_GPIO);
1b6ebdd7 208 gpio_free(ZOOM2_HEADSET_EXTMUTE_GPIO);
df205936
LCM
209
210 platform_device_unregister(zoom2_snd_device);
211}
212module_exit(zoom2_soc_exit);
213
214MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>");
215MODULE_DESCRIPTION("ALSA SoC Zoom2");
216MODULE_LICENSE("GPL");
217
This page took 0.470524 seconds and 5 git commands to generate.