OMAP: DSS2: DSI: Increase HS TX timeout
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / sound / soc / omap / rx51.c
blob47d831ef2dbbff0fd01ba0f9b18810db37d9d118
1 /*
2 * rx51.c -- SoC audio for Nokia RX-51
4 * Copyright (C) 2008 - 2009 Nokia Corporation
6 * Contact: Peter Ujfalusi <peter.ujfalusi@nokia.com>
7 * Eduardo Valentin <eduardo.valentin@nokia.com>
8 * Jarkko Nikula <jhnikula@gmail.com>
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * version 2 as published by the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22 * 02110-1301 USA
26 #include <linux/delay.h>
27 #include <linux/gpio.h>
28 #include <linux/platform_device.h>
29 #include <sound/core.h>
30 #include <sound/pcm.h>
31 #include <sound/soc.h>
32 #include <sound/soc-dapm.h>
34 #include <asm/mach-types.h>
36 #include "omap-mcbsp.h"
37 #include "omap-pcm.h"
38 #include "../codecs/tlv320aic3x.h"
41 * REVISIT: TWL4030 GPIO base in RX-51. Now statically defined to 192. This
42 * gpio is reserved in arch/arm/mach-omap2/board-rx51-peripherals.c
44 #define RX51_SPEAKER_AMP_TWL_GPIO (192 + 7)
46 static int rx51_spk_func;
47 static int rx51_dmic_func;
49 static void rx51_ext_control(struct snd_soc_codec *codec)
51 if (rx51_spk_func)
52 snd_soc_dapm_enable_pin(codec, "Ext Spk");
53 else
54 snd_soc_dapm_disable_pin(codec, "Ext Spk");
55 if (rx51_dmic_func)
56 snd_soc_dapm_enable_pin(codec, "DMic");
57 else
58 snd_soc_dapm_disable_pin(codec, "DMic");
60 snd_soc_dapm_sync(codec);
63 static int rx51_startup(struct snd_pcm_substream *substream)
65 struct snd_pcm_runtime *runtime = substream->runtime;
66 struct snd_soc_pcm_runtime *rtd = substream->private_data;
67 struct snd_soc_codec *codec = rtd->socdev->card->codec;
69 snd_pcm_hw_constraint_minmax(runtime,
70 SNDRV_PCM_HW_PARAM_CHANNELS, 2, 2);
71 rx51_ext_control(codec);
73 return 0;
76 static int rx51_hw_params(struct snd_pcm_substream *substream,
77 struct snd_pcm_hw_params *params)
79 struct snd_soc_pcm_runtime *rtd = substream->private_data;
80 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
81 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
82 int err;
84 /* Set codec DAI configuration */
85 err = snd_soc_dai_set_fmt(codec_dai,
86 SND_SOC_DAIFMT_DSP_A |
87 SND_SOC_DAIFMT_IB_NF |
88 SND_SOC_DAIFMT_CBM_CFM);
89 if (err < 0)
90 return err;
92 /* Set cpu DAI configuration */
93 err = snd_soc_dai_set_fmt(cpu_dai,
94 SND_SOC_DAIFMT_DSP_A |
95 SND_SOC_DAIFMT_IB_NF |
96 SND_SOC_DAIFMT_CBM_CFM);
97 if (err < 0)
98 return err;
100 /* Set the codec system clock for DAC and ADC */
101 return snd_soc_dai_set_sysclk(codec_dai, 0, 19200000,
102 SND_SOC_CLOCK_IN);
105 static struct snd_soc_ops rx51_ops = {
106 .startup = rx51_startup,
107 .hw_params = rx51_hw_params,
110 static int rx51_get_spk(struct snd_kcontrol *kcontrol,
111 struct snd_ctl_elem_value *ucontrol)
113 ucontrol->value.integer.value[0] = rx51_spk_func;
115 return 0;
118 static int rx51_set_spk(struct snd_kcontrol *kcontrol,
119 struct snd_ctl_elem_value *ucontrol)
121 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
123 if (rx51_spk_func == ucontrol->value.integer.value[0])
124 return 0;
126 rx51_spk_func = ucontrol->value.integer.value[0];
127 rx51_ext_control(codec);
129 return 1;
132 static int rx51_spk_event(struct snd_soc_dapm_widget *w,
133 struct snd_kcontrol *k, int event)
135 if (SND_SOC_DAPM_EVENT_ON(event))
136 gpio_set_value(RX51_SPEAKER_AMP_TWL_GPIO, 1);
137 else
138 gpio_set_value(RX51_SPEAKER_AMP_TWL_GPIO, 0);
140 return 0;
143 static int rx51_get_input(struct snd_kcontrol *kcontrol,
144 struct snd_ctl_elem_value *ucontrol)
146 ucontrol->value.integer.value[0] = rx51_dmic_func;
148 return 0;
151 static int rx51_set_input(struct snd_kcontrol *kcontrol,
152 struct snd_ctl_elem_value *ucontrol)
154 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
156 if (rx51_dmic_func == ucontrol->value.integer.value[0])
157 return 0;
159 rx51_dmic_func = ucontrol->value.integer.value[0];
160 rx51_ext_control(codec);
162 return 1;
165 static const struct snd_soc_dapm_widget aic34_dapm_widgets[] = {
166 SND_SOC_DAPM_SPK("Ext Spk", rx51_spk_event),
167 SND_SOC_DAPM_MIC("DMic", NULL),
170 static const struct snd_soc_dapm_route audio_map[] = {
171 {"Ext Spk", NULL, "HPLOUT"},
172 {"Ext Spk", NULL, "HPROUT"},
174 {"DMic Rate 64", NULL, "Mic Bias 2V"},
175 {"Mic Bias 2V", NULL, "DMic"},
178 static const char *spk_function[] = {"Off", "On"};
179 static const char *input_function[] = {"ADC", "Digital Mic"};
181 static const struct soc_enum rx51_enum[] = {
182 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(spk_function), spk_function),
183 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(input_function), input_function),
186 static const struct snd_kcontrol_new aic34_rx51_controls[] = {
187 SOC_ENUM_EXT("Speaker Function", rx51_enum[0],
188 rx51_get_spk, rx51_set_spk),
189 SOC_ENUM_EXT("Input Select", rx51_enum[1],
190 rx51_get_input, rx51_set_input),
193 static int rx51_aic34_init(struct snd_soc_codec *codec)
195 int err;
197 /* Set up NC codec pins */
198 snd_soc_dapm_nc_pin(codec, "MIC3L");
199 snd_soc_dapm_nc_pin(codec, "MIC3R");
200 snd_soc_dapm_nc_pin(codec, "LINE1R");
202 /* Add RX-51 specific controls */
203 err = snd_soc_add_controls(codec, aic34_rx51_controls,
204 ARRAY_SIZE(aic34_rx51_controls));
205 if (err < 0)
206 return err;
208 /* Add RX-51 specific widgets */
209 snd_soc_dapm_new_controls(codec, aic34_dapm_widgets,
210 ARRAY_SIZE(aic34_dapm_widgets));
212 /* Set up RX-51 specific audio path audio_map */
213 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
215 snd_soc_dapm_sync(codec);
217 return 0;
220 /* Digital audio interface glue - connects codec <--> CPU */
221 static struct snd_soc_dai_link rx51_dai[] = {
223 .name = "TLV320AIC34",
224 .stream_name = "AIC34",
225 .cpu_dai = &omap_mcbsp_dai[0],
226 .codec_dai = &aic3x_dai,
227 .init = rx51_aic34_init,
228 .ops = &rx51_ops,
232 /* Audio private data */
233 static struct aic3x_setup_data rx51_aic34_setup = {
234 .gpio_func[0] = AIC3X_GPIO1_FUNC_DISABLED,
235 .gpio_func[1] = AIC3X_GPIO2_FUNC_DIGITAL_MIC_INPUT,
238 /* Audio card */
239 static struct snd_soc_card rx51_sound_card = {
240 .name = "RX-51",
241 .dai_link = rx51_dai,
242 .num_links = ARRAY_SIZE(rx51_dai),
243 .platform = &omap_soc_platform,
246 /* Audio subsystem */
247 static struct snd_soc_device rx51_snd_devdata = {
248 .card = &rx51_sound_card,
249 .codec_dev = &soc_codec_dev_aic3x,
250 .codec_data = &rx51_aic34_setup,
253 static struct platform_device *rx51_snd_device;
255 static int __init rx51_soc_init(void)
257 int err;
259 if (!machine_is_nokia_rx51())
260 return -ENODEV;
262 rx51_snd_device = platform_device_alloc("soc-audio", -1);
263 if (!rx51_snd_device) {
264 err = -ENOMEM;
265 goto err1;
268 platform_set_drvdata(rx51_snd_device, &rx51_snd_devdata);
269 rx51_snd_devdata.dev = &rx51_snd_device->dev;
270 *(unsigned int *)rx51_dai[0].cpu_dai->private_data = 1; /* McBSP2 */
272 err = platform_device_add(rx51_snd_device);
273 if (err)
274 goto err2;
276 return 0;
277 err2:
278 platform_device_put(rx51_snd_device);
279 err1:
281 return err;
284 static void __exit rx51_soc_exit(void)
286 platform_device_unregister(rx51_snd_device);
289 module_init(rx51_soc_init);
290 module_exit(rx51_soc_exit);
292 MODULE_AUTHOR("Nokia Corporation");
293 MODULE_DESCRIPTION("ALSA SoC Nokia RX-51");
294 MODULE_LICENSE("GPL");