2 * n810.c -- SoC audio for Nokia RX51
4 * Copyright (C) 2008 Nokia Corporation
6 * Contact: Jarkko Nikula <jarkko.nikula@nokia.com>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
24 #include <linux/clk.h>
25 #include <linux/delay.h>
26 #include <linux/platform_device.h>
27 #include <linux/i2c/tpa6130a2.h>
28 #include <sound/core.h>
29 #include <sound/pcm.h>
30 #include <sound/soc.h>
31 #include <sound/soc-dapm.h>
32 #include <sound/jack.h>
33 #include <sound/tlv.h>
35 #include <linux/i2c/twl4030.h>
36 #include <asm/mach-types.h>
37 #include <mach/hardware.h>
38 #include <linux/gpio.h>
39 #include <mach/mcbsp.h>
41 #include "omap-mcbsp.h"
43 #include "../codecs/tlv320aic3x.h"
44 #include "aic34b_dummy.h"
46 #define RX51_CODEC_RESET_GPIO 60
47 #define RX51_TVOUT_SEL_GPIO 40
48 #define RX51_ECI_SWITCH_1_GPIO 178
49 #define RX51_ECI_SWITCH_2_GPIO 182
50 /* REVISIT: TWL4030 GPIO base in RX51. Now statically defined to 192 */
51 #define RX51_SPEAKER_AMP_TWL_GPIO (192 + 7)
55 RX51_JACK_HP, /* headphone: stereo output, no mic */
56 RX51_JACK_HS, /* headset: stereo output with mic */
57 RX51_JACK_MIC, /* mic input only */
58 RX51_JACK_ECI, /* ECI headset */
59 RX51_JACK_TVOUT, /* stereo output with tv-out */
62 static int hp_lim = 63;
63 module_param(hp_lim, int, 0);
65 static int rx51_new_hw_audio;
66 static int rx51_spk_func;
67 static int rx51_jack_func;
68 static int rx51_fmtx_func;
69 static int rx51_dmic_func;
70 static int rx51_ear_func;
71 static struct snd_jack *rx51_jack;
73 static DEFINE_MUTEX(eci_mutex);
74 static int rx51_eci_mode = 1;
75 static int rx51_dapm_jack_bias;
76 static int tpa6130_volume = -1;
77 static int tpa6130_enable;
78 static int aic34b_volume;
80 static void rx51_set_eci_switches(int mode)
83 case 0: /* Bias off */
84 case 1: /* Bias according to rx51_dapm_jack_bias */
86 /* Codec connected to mic/bias line */
87 gpio_set_value(RX51_ECI_SWITCH_1_GPIO, 0);
88 gpio_set_value(RX51_ECI_SWITCH_2_GPIO, 1);
91 /* ECI INT#2 detect connected to mic/bias line */
92 gpio_set_value(RX51_ECI_SWITCH_1_GPIO, 0);
93 gpio_set_value(RX51_ECI_SWITCH_2_GPIO, 0);
96 /* ECI RX/TX connected to mic/bias line */
97 gpio_set_value(RX51_ECI_SWITCH_1_GPIO, 1);
98 gpio_set_value(RX51_ECI_SWITCH_2_GPIO, 0);
103 static void rx51_set_jack_bias(void)
107 mutex_lock(&eci_mutex);
108 if ((rx51_eci_mode == 1 && rx51_dapm_jack_bias) || rx51_eci_mode == 4)
110 else if (rx51_eci_mode == 1 && rx51_jack_func == RX51_JACK_ECI)
112 mutex_unlock(&eci_mutex);
114 aic34b_set_mic_bias(2); /* 2.5 V */
116 aic34b_set_mic_bias(0);
119 static void rx51_set_jack_bias_handler(struct work_struct *unused)
121 rx51_set_jack_bias();
123 DECLARE_WORK(rx51_jack_bias_work, rx51_set_jack_bias_handler);
125 static void rx51_ext_control(struct snd_soc_codec *codec)
127 int hp = 0, mic = 0, tvout = 0;
129 switch (rx51_jack_func) {
139 case RX51_JACK_TVOUT:
145 gpio_set_value(RX51_TVOUT_SEL_GPIO, tvout);
148 snd_soc_dapm_enable_pin(codec, "Ext Spk");
150 snd_soc_dapm_disable_pin(codec, "Ext Spk");
152 snd_soc_dapm_enable_pin(codec, "Headphone Jack");
154 snd_soc_dapm_disable_pin(codec, "Headphone Jack");
156 snd_soc_dapm_enable_pin(codec, "Mic Jack");
158 snd_soc_dapm_disable_pin(codec, "Mic Jack");
160 snd_soc_dapm_enable_pin(codec, "FM Transmitter");
162 snd_soc_dapm_disable_pin(codec, "FM Transmitter");
164 snd_soc_dapm_enable_pin(codec, "DMic");
166 snd_soc_dapm_disable_pin(codec, "DMic");
168 snd_soc_dapm_enable_pin(codec, "Earphone");
170 snd_soc_dapm_disable_pin(codec, "Earphone");
172 snd_soc_dapm_sync(codec);
175 int rx51_set_eci_mode(int mode)
177 if (mode < 0 || mode > 4)
180 mutex_lock(&eci_mutex);
181 if (rx51_eci_mode == mode) {
182 mutex_unlock(&eci_mutex);
186 rx51_eci_mode = mode;
187 rx51_set_eci_switches(rx51_eci_mode);
188 mutex_unlock(&eci_mutex);
190 rx51_set_jack_bias();
194 EXPORT_SYMBOL(rx51_set_eci_mode);
196 static ssize_t eci_mode_show(struct device *dev, struct device_attribute *attr,
199 return sprintf(buf, "%d\n", rx51_eci_mode);
202 static ssize_t eci_mode_store(struct device *dev,
203 struct device_attribute *attr,
204 const char *buf, size_t count)
207 if (sscanf(buf, "%d", &mode) != 1)
209 retval = rx51_set_eci_mode(mode);
211 return (retval < 0) ? retval : count;
214 static DEVICE_ATTR(eci_mode, S_IRUGO | S_IWUSR,
215 eci_mode_show, eci_mode_store);
217 void rx51_jack_report(int status)
219 snd_jack_report(rx51_jack, status);
221 EXPORT_SYMBOL(rx51_jack_report);
223 static int rx51_startup(struct snd_pcm_substream *substream)
225 struct snd_pcm_runtime *runtime = substream->runtime;
226 struct snd_soc_pcm_runtime *rtd = substream->private_data;
227 struct snd_soc_codec *codec = rtd->socdev->codec;
229 snd_pcm_hw_constraint_minmax(runtime,
230 SNDRV_PCM_HW_PARAM_CHANNELS, 2, 2);
232 rx51_ext_control(codec);
237 static void rx51_shutdown(struct snd_pcm_substream *substream)
241 static int pre_events;
243 static int rx51_hw_params(struct snd_pcm_substream *substream,
244 struct snd_pcm_hw_params *params)
246 struct snd_soc_pcm_runtime *rtd = substream->private_data;
247 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
248 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
251 if (rx51_new_hw_audio) {
254 err = twl4030_enable_regulator(RES_VMMC2);
260 /* Set codec DAI configuration */
261 err = snd_soc_dai_set_fmt(codec_dai,
262 SND_SOC_DAIFMT_DSP_A |
263 SND_SOC_DAIFMT_IB_NF |
264 SND_SOC_DAIFMT_CBM_CFM);
268 /* Set cpu DAI configuration */
269 err = snd_soc_dai_set_fmt(cpu_dai,
270 SND_SOC_DAIFMT_DSP_A |
271 SND_SOC_DAIFMT_IB_NF |
272 SND_SOC_DAIFMT_CBM_CFM);
276 /* Set the codec system clock for DAC and ADC */
277 return snd_soc_dai_set_sysclk(codec_dai, 0, 19200000,
281 static int rx51_bt_hw_params(struct snd_pcm_substream *substream,
282 struct snd_pcm_hw_params *params)
284 struct snd_soc_pcm_runtime *rtd = substream->private_data;
285 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
287 /* Set cpu DAI configuration */
288 return cpu_dai->dai_ops.set_fmt(cpu_dai,
289 SND_SOC_DAIFMT_DSP_A |
290 SND_SOC_DAIFMT_IB_NF |
291 SND_SOC_DAIFMT_CBM_CFM);
294 static struct snd_soc_ops rx51_bt_ops = {
295 .hw_params = rx51_bt_hw_params,
298 static struct snd_soc_ops rx51_ops = {
299 .startup = rx51_startup,
300 .hw_params = rx51_hw_params,
301 .shutdown = rx51_shutdown,
304 static int rx51_get_spk(struct snd_kcontrol *kcontrol,
305 struct snd_ctl_elem_value *ucontrol)
307 ucontrol->value.integer.value[0] = rx51_spk_func;
312 static int rx51_set_spk(struct snd_kcontrol *kcontrol,
313 struct snd_ctl_elem_value *ucontrol)
315 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
317 if (rx51_spk_func == ucontrol->value.integer.value[0])
320 rx51_spk_func = ucontrol->value.integer.value[0];
321 rx51_ext_control(codec);
326 static int rx51_spk_event(struct snd_soc_dapm_widget *w,
327 struct snd_kcontrol *k, int event)
329 if (SND_SOC_DAPM_EVENT_ON(event))
330 gpio_set_value(RX51_SPEAKER_AMP_TWL_GPIO, 1);
332 gpio_set_value(RX51_SPEAKER_AMP_TWL_GPIO, 0);
337 static int rx51_get_jack(struct snd_kcontrol *kcontrol,
338 struct snd_ctl_elem_value *ucontrol)
340 ucontrol->value.integer.value[0] = rx51_jack_func;
345 static int rx51_set_jack(struct snd_kcontrol *kcontrol,
346 struct snd_ctl_elem_value *ucontrol)
348 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
350 if (rx51_jack_func == ucontrol->value.integer.value[0])
353 rx51_jack_func = ucontrol->value.integer.value[0];
355 mutex_lock(&eci_mutex);
356 if (rx51_jack_func == RX51_JACK_ECI) {
357 /* Set ECI switches according to ECI mode */
358 rx51_set_eci_switches(rx51_eci_mode);
359 schedule_work(&rx51_jack_bias_work);
362 * Let the codec always be connected to mic/bias line when
363 * jack is in non-ECI function
365 rx51_set_eci_switches(1);
366 schedule_work(&rx51_jack_bias_work);
368 mutex_unlock(&eci_mutex);
370 rx51_ext_control(codec);
375 static int rx51_jack_hp_event(struct snd_soc_dapm_widget *w,
376 struct snd_kcontrol *k, int event)
379 * Note: HP amp and fmtx must not be enabled at the same
380 * time. We keep a shadow copy of the desired tpa_enable value but
381 * keep the hpamp really disabled whenever fmtx is enabled. If
382 * hpamp is requested on but fmtx is enabled, hpamp is kept
383 * disabled and enabled later from rx51_set_fmtx function when
384 * user disables fmtx.
386 if (SND_SOC_DAPM_EVENT_ON(event)) {
388 tpa6130a2_set_enabled(1);
391 tpa6130a2_set_enabled(0);
398 static int rx51_jack_mic_event(struct snd_soc_dapm_widget *w,
399 struct snd_kcontrol *k, int event)
401 if (SND_SOC_DAPM_EVENT_ON(event))
402 rx51_dapm_jack_bias = 1;
404 rx51_dapm_jack_bias = 0;
405 schedule_work(&rx51_jack_bias_work);
410 static int rx51_get_fmtx(struct snd_kcontrol *kcontrol,
411 struct snd_ctl_elem_value *ucontrol)
413 ucontrol->value.integer.value[0] = rx51_fmtx_func;
418 static int rx51_set_fmtx(struct snd_kcontrol *kcontrol,
419 struct snd_ctl_elem_value *ucontrol)
421 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
423 if (rx51_fmtx_func == ucontrol->value.integer.value[0])
426 rx51_fmtx_func = ucontrol->value.integer.value[0];
427 rx51_ext_control(codec);
429 /* fmtx and tpa must not be enabled at the same time */
430 if (rx51_fmtx_func && tpa6130_enable)
431 tpa6130a2_set_enabled(0);
432 if (!rx51_fmtx_func && tpa6130_enable)
433 tpa6130a2_set_enabled(1);
438 static int rx51_get_input(struct snd_kcontrol *kcontrol,
439 struct snd_ctl_elem_value *ucontrol)
441 ucontrol->value.integer.value[0] = rx51_dmic_func;
446 static int rx51_set_input(struct snd_kcontrol *kcontrol,
447 struct snd_ctl_elem_value *ucontrol)
449 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
451 if (rx51_dmic_func == ucontrol->value.integer.value[0])
454 rx51_dmic_func = ucontrol->value.integer.value[0];
455 rx51_ext_control(codec);
460 static int rx51_get_ear(struct snd_kcontrol *kcontrol,
461 struct snd_ctl_elem_value *ucontrol)
463 ucontrol->value.integer.value[0] = rx51_ear_func;
468 static int rx51_set_ear(struct snd_kcontrol *kcontrol,
469 struct snd_ctl_elem_value *ucontrol)
471 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
473 if (rx51_ear_func == ucontrol->value.integer.value[0])
476 rx51_ear_func = ucontrol->value.integer.value[0];
477 rx51_ext_control(codec);
482 static int rx51_ear_event(struct snd_soc_dapm_widget *w,
483 struct snd_kcontrol *k, int event)
485 if (SND_SOC_DAPM_EVENT_ON(event))
486 aic34b_ear_enable(1);
488 aic34b_ear_enable(0);
493 static int rx51_pre_spk_event(struct snd_soc_dapm_widget *w,
494 struct snd_kcontrol *k, int event)
496 if (!rx51_new_hw_audio)
499 if (SND_SOC_DAPM_EVENT_ON(event))
500 return twl4030_enable_regulator(RES_VMMC2);
505 static int rx51_post_spk_event(struct snd_soc_dapm_widget *w,
506 struct snd_kcontrol *k, int event)
508 if (!rx51_new_hw_audio)
511 if (!SND_SOC_DAPM_EVENT_ON(event))
512 return twl4030_disable_regulator(RES_VMMC2);
517 static int rx51_pre_event(struct snd_soc_dapm_widget *w,
518 struct snd_kcontrol *k, int event)
520 if (!rx51_new_hw_audio)
523 if (SND_SOC_DAPM_EVENT_ON(event)) {
526 return twl4030_enable_regulator(RES_VMMC2);
533 static int rx51_post_event(struct snd_soc_dapm_widget *w,
534 struct snd_kcontrol *k, int event)
536 if (!rx51_new_hw_audio)
539 if (!SND_SOC_DAPM_EVENT_ON(event)) {
540 if (pre_events && !w->codec->active) {
542 return twl4030_disable_regulator(RES_VMMC2);
550 RX51_EXT_API_TPA6130,
553 #define SOC_RX51_EXT_SINGLE_TLV(xname, ext_api, max, tlv_array) \
555 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
557 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
558 SNDRV_CTL_ELEM_ACCESS_READWRITE, \
559 .tlv.p = (tlv_array), \
560 .info = rx51_ext_info_volsw, \
561 .get = rx51_ext_get_volsw, \
562 .put = rx51_ext_put_volsw, \
563 .private_value = (ext_api) << 26 | (max) << 16, \
566 static int rx51_ext_info_volsw(struct snd_kcontrol *kcontrol,
567 struct snd_ctl_elem_info *uinfo)
569 int ext_api = (kcontrol->private_value >> 26) & 0x0f;
570 int max = (kcontrol->private_value >> 16) & 0xff;
572 if (ext_api == RX51_EXT_API_TPA6130)
573 if (hp_lim != max && hp_lim >= 2 && hp_lim <= 63) {
574 kcontrol->private_value &= ~(0xff << 16);
575 kcontrol->private_value |= (hp_lim << 16);
580 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
582 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
585 uinfo->value.integer.min = 0;
586 uinfo->value.integer.max = max;
591 static int rx51_ext_get_volsw(struct snd_kcontrol *kcontrol,
592 struct snd_ctl_elem_value *ucontrol)
594 int ext_api = (kcontrol->private_value >> 26) & 0x0f;
597 case RX51_EXT_API_TPA6130:
598 if (tpa6130_volume < 0)
599 tpa6130_volume = tpa6130a2_get_volume();
600 ucontrol->value.integer.value[0] = tpa6130_volume;
602 case RX51_EXT_API_AIC34B:
603 ucontrol->value.integer.value[0] = aic34b_volume;
612 static int rx51_ext_put_volsw(struct snd_kcontrol *kcontrol,
613 struct snd_ctl_elem_value *ucontrol)
615 int ext_api = (kcontrol->private_value >> 26) & 0x0f;
619 case RX51_EXT_API_TPA6130:
620 change = (tpa6130_volume != ucontrol->value.integer.value[0]);
621 tpa6130_volume = ucontrol->value.integer.value[0];
622 tpa6130a2_set_volume(tpa6130_volume);
624 case RX51_EXT_API_AIC34B:
625 change = (aic34b_volume != ucontrol->value.integer.value[0]);
626 aic34b_volume = ucontrol->value.integer.value[0];
627 aic34b_set_volume(aic34b_volume);
636 #define SOC_RX51_SINGLE_JACK_BIAS(xname) \
638 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
640 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
641 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
642 .info = rx51_info_jack_bias, \
643 .get = rx51_get_jack_bias, \
644 .put = rx51_put_jack_bias, \
647 static int rx51_info_jack_bias(struct snd_kcontrol *kcontrol,
648 struct snd_ctl_elem_info *uinfo)
650 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
652 uinfo->value.integer.min = 0;
653 uinfo->value.integer.max = 1;
658 static int rx51_get_jack_bias(struct snd_kcontrol *kcontrol,
659 struct snd_ctl_elem_value *ucontrol)
661 ucontrol->value.integer.value[0] = (aic34b_get_mic_bias() != 0);
666 static int rx51_put_jack_bias(struct snd_kcontrol *kcontrol,
667 struct snd_ctl_elem_value *ucontrol)
669 int change, new_value;
671 new_value = ucontrol->value.integer.value[0];
672 change = (new_value != aic34b_get_mic_bias());
675 switch (rx51_jack_func) {
679 aic34b_set_mic_bias(new_value * 2); /* 2.5 V */
689 static const struct snd_soc_dapm_widget aic34_dapm_widgets[] = {
690 SND_SOC_DAPM_POST("Post event", rx51_post_event),
691 SND_SOC_DAPM_SPK("Post spk", rx51_post_spk_event),
692 SND_SOC_DAPM_SPK("Ext Spk", rx51_spk_event),
693 SND_SOC_DAPM_SPK("Headphone Jack", rx51_jack_hp_event),
694 SND_SOC_DAPM_MIC("Mic Jack", rx51_jack_mic_event),
695 SND_SOC_DAPM_OUTPUT("FM Transmitter"),
696 SND_SOC_DAPM_MIC("DMic", NULL),
697 SND_SOC_DAPM_SPK("Earphone", rx51_ear_event),
698 SND_SOC_DAPM_SPK("Pre spk", rx51_pre_spk_event),
699 SND_SOC_DAPM_PRE("Pre event", rx51_pre_event),
702 static const struct snd_soc_dapm_route audio_map[] = {
703 {"Post spk", NULL, "LLOUT"},
704 {"Post spk", NULL, "RLOUT"},
706 {"Ext Spk", NULL, "HPLOUT"},
707 {"Ext Spk", NULL, "HPROUT"},
709 {"Headphone Jack", NULL, "LLOUT"},
710 {"Headphone Jack", NULL, "RLOUT"},
711 {"LINE1L", NULL, "Mic Jack"},
713 {"FM Transmitter", NULL, "LLOUT"},
714 {"FM Transmitter", NULL, "RLOUT"},
716 {"Earphone", NULL, "MONO_LOUT"},
718 {"DMic Rate 64", NULL, "Mic Bias 2V"},
719 {"Mic Bias 2V", NULL, "DMic"},
721 {"Pre spk", NULL, "LLOUT"},
722 {"Pre spk", NULL, "RLOUT"},
725 static const char *spk_function[] = {"Off", "On"};
726 static const char *jack_function[] = {"Off", "Headphone", "Headset",
727 "Mic", "ECI Headset", "TV-OUT"};
728 static const char *fmtx_function[] = {"Off", "On"};
729 static const char *input_function[] = {"ADC", "Digital Mic"};
730 static const char *ear_function[] = {"Off", "On"};
732 static const struct soc_enum rx51_enum[] = {
733 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(spk_function), spk_function),
734 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(jack_function), jack_function),
735 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(fmtx_function), fmtx_function),
736 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(input_function), input_function),
737 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(ear_function), ear_function),
741 * TPA6130 volume. From -59.5 to 4 dB with increasing step size when going
742 * down in gain. Justify scale so that it is quite correct from -20 dB and
743 * up. This setting shows -30 dB at minimum, -12.95 dB at 49 % (actual
744 * is -10.3 dB) and 4.65 dB at maximum (actual is 4 dB).
746 static const unsigned int tpa6130_tlv[] = {
747 TLV_DB_RANGE_HEAD(10),
748 0, 1, TLV_DB_SCALE_ITEM(-5950, 600, 0),
749 2, 3, TLV_DB_SCALE_ITEM(-5000, 250, 0),
750 4, 5, TLV_DB_SCALE_ITEM(-4550, 160, 0),
751 6, 7, TLV_DB_SCALE_ITEM(-4140, 190, 0),
752 8, 9, TLV_DB_SCALE_ITEM(-3650, 120, 0),
753 10, 11, TLV_DB_SCALE_ITEM(-3330, 160, 0),
754 12, 13, TLV_DB_SCALE_ITEM(-3040, 180, 0),
755 14, 20, TLV_DB_SCALE_ITEM(-2710, 110, 0),
756 21, 37, TLV_DB_SCALE_ITEM(-1960, 74, 0),
757 38, 63, TLV_DB_SCALE_ITEM(-720, 45, 0),
761 * TLV320AIC3x output stage volumes. From -78.3 to 0 dB. Muted below -78.3 dB.
762 * Step size is approximately 0.5 dB over most of the scale but increasing
763 * near the very low levels.
764 * Define dB scale so that it is mostly correct for range about -55 to 0 dB
765 * but having increasing dB difference below that (and where it doesn't count
766 * so much). This setting shows -50 dB (actual is -50.3 dB) for register
767 * value 100 and -58.5 dB (actual is -78.3 dB) for register value 117.
769 static DECLARE_TLV_DB_SCALE(aic3x_output_stage_tlv, -5900, 50, 1);
771 static const struct snd_kcontrol_new aic34_rx51_controls[] = {
772 SOC_ENUM_EXT("Speaker Function", rx51_enum[0],
773 rx51_get_spk, rx51_set_spk),
774 SOC_ENUM_EXT("Jack Function", rx51_enum[1],
775 rx51_get_jack, rx51_set_jack),
776 SOC_ENUM_EXT("FMTX Function", rx51_enum[2],
777 rx51_get_fmtx, rx51_set_fmtx),
778 SOC_ENUM_EXT("Input Select", rx51_enum[3],
779 rx51_get_input, rx51_set_input),
780 SOC_ENUM_EXT("Earphone Function", rx51_enum[4],
781 rx51_get_ear, rx51_set_ear),
782 SOC_RX51_EXT_SINGLE_TLV("Headphone Playback Volume",
783 RX51_EXT_API_TPA6130, 63,
785 SOC_RX51_EXT_SINGLE_TLV("Earphone Playback Volume",
786 RX51_EXT_API_AIC34B, 118,
787 aic3x_output_stage_tlv),
788 SOC_RX51_SINGLE_JACK_BIAS("Jack Bias Switch"),
791 static int rx51_aic34_init(struct snd_soc_codec *codec)
795 /* set up NC codec pins */
796 snd_soc_dapm_nc_pin(codec, "MIC3L");
797 snd_soc_dapm_nc_pin(codec, "MIC3R");
798 snd_soc_dapm_nc_pin(codec, "LINE1R");
800 /* Create jack for accessory reporting */
801 err = snd_jack_new(codec->card, "Jack", SND_JACK_MECHANICAL |
802 SND_JACK_HEADSET | SND_JACK_AVOUT, &rx51_jack);
806 /* Add RX51 specific controls */
807 for (i = 0; i < ARRAY_SIZE(aic34_rx51_controls); i++) {
808 err = snd_ctl_add(codec->card,
809 snd_soc_cnew(&aic34_rx51_controls[i], codec, NULL));
814 /* Add RX51 specific widgets */
815 snd_soc_dapm_new_controls(codec, aic34_dapm_widgets,
816 ARRAY_SIZE(aic34_dapm_widgets));
818 /* Set up RX51 specific audio path audio_map */
819 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
821 snd_soc_dapm_enable_pin(codec, "Earphone");
823 snd_soc_dapm_sync(codec);
828 /* Since all codec control is done by Bluetooth hardware
829 only some constrains need to be set for it */
830 struct snd_soc_dai btcodec_dai = {
831 .name = "Bluetooth codec",
833 .stream_name = "BT Playback",
836 .rates = SNDRV_PCM_RATE_8000,
837 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
839 .stream_name = "BT Capture",
842 .rates = SNDRV_PCM_RATE_8000,
843 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
846 /* Digital audio interface glue - connects codec <--> CPU */
847 static struct snd_soc_dai_link rx51_dai[] = {
849 .name = "TLV320AIC34",
850 .stream_name = "AIC34",
851 .cpu_dai = &omap_mcbsp_dai[0],
852 .codec_dai = &aic3x_dai,
853 .init = rx51_aic34_init,
856 .name = "Bluetooth PCM",
857 .stream_name = "Bluetooth",
858 .cpu_dai = &omap_mcbsp_dai[1],
859 .codec_dai = &btcodec_dai,
864 /* Audio machine driver */
865 static struct snd_soc_machine snd_soc_machine_rx51 = {
867 .dai_link = rx51_dai,
868 .num_links = ARRAY_SIZE(rx51_dai),
871 /* Audio private data */
872 static struct aic3x_setup_data rx51_aic34_setup = {
875 .gpio_func[0] = AIC3X_GPIO1_FUNC_DISABLED,
876 .gpio_func[1] = AIC3X_GPIO2_FUNC_DIGITAL_MIC_INPUT,
879 /* Audio subsystem */
880 static struct snd_soc_device rx51_snd_devdata = {
881 .machine = &snd_soc_machine_rx51,
882 .platform = &omap_soc_platform,
883 .codec_dev = &soc_codec_dev_aic3x,
884 .codec_data = &rx51_aic34_setup,
887 static struct platform_device *rx51_snd_device;
889 #define REMAP_OFFSET 2
890 #define DEDICATED_OFFSET 3
891 #define VMMC2_DEV_GRP 0x2B
892 #define VMMC2_285V 0x0a
894 static int __init rx51_soc_init(void)
899 if (!machine_is_nokia_rx51())
902 if ((system_rev >= 0x08 && system_rev <= 0x13) || /* Macros */
903 system_rev >= 0x1901) {
904 rx51_new_hw_audio = 1;
905 err = twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
907 VMMC2_DEV_GRP + DEDICATED_OFFSET);
908 err |= twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0xee,
909 VMMC2_DEV_GRP + REMAP_OFFSET);
911 printk(KERN_ERR "%s rx51 audio failed!\n", __func__);
916 if (gpio_request(RX51_CODEC_RESET_GPIO, NULL) < 0)
918 if (gpio_request(RX51_TVOUT_SEL_GPIO, "tvout_sel") < 0)
920 if (gpio_request(RX51_ECI_SWITCH_1_GPIO, "ECI switch 1") < 0)
922 if (gpio_request(RX51_ECI_SWITCH_2_GPIO, "ECI switch 2") < 0)
924 gpio_direction_output(RX51_CODEC_RESET_GPIO, 0);
925 gpio_direction_output(RX51_TVOUT_SEL_GPIO, 0);
926 gpio_direction_output(RX51_ECI_SWITCH_1_GPIO, 0);
927 gpio_direction_output(RX51_ECI_SWITCH_2_GPIO, 1);
929 gpio_set_value(RX51_CODEC_RESET_GPIO, 0);
931 gpio_set_value(RX51_CODEC_RESET_GPIO, 1);
934 if (gpio_request(RX51_SPEAKER_AMP_TWL_GPIO, NULL) < 0)
936 gpio_direction_output(RX51_SPEAKER_AMP_TWL_GPIO, 0);
938 rx51_snd_device = platform_device_alloc("soc-audio", -1);
939 if (!rx51_snd_device)
942 platform_set_drvdata(rx51_snd_device, &rx51_snd_devdata);
943 rx51_snd_devdata.dev = &rx51_snd_device->dev;
944 err = platform_device_add(rx51_snd_device);
948 dev = &rx51_snd_device->dev;
950 *(unsigned int *)rx51_dai[0].cpu_dai->private_data = 1;
951 *(unsigned int *)rx51_dai[1].cpu_dai->private_data = 2;
953 err = device_create_file(dev, &dev_attr_eci_mode);
959 platform_device_del(rx51_snd_device);
961 platform_device_put(rx51_snd_device);
967 static void __exit rx51_soc_exit(void)
969 platform_device_unregister(rx51_snd_device);
972 module_init(rx51_soc_init);
973 module_exit(rx51_soc_exit);
975 MODULE_AUTHOR("Jarkko Nikula <jarkko.nikula@nokia.com>");
976 MODULE_DESCRIPTION("ALSA SoC Nokia RX51");
977 MODULE_LICENSE("GPL");