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);
236 static void rx51_shutdown(struct snd_pcm_substream *substream)
240 static int pre_events;
242 static int rx51_hw_params(struct snd_pcm_substream *substream,
243 struct snd_pcm_hw_params *params)
245 struct snd_soc_pcm_runtime *rtd = substream->private_data;
246 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
247 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
250 if (rx51_new_hw_audio) {
253 err = twl4030_enable_regulator(RES_VMMC2);
259 /* Set codec DAI configuration */
260 err = snd_soc_dai_set_fmt(codec_dai,
261 SND_SOC_DAIFMT_DSP_A |
262 SND_SOC_DAIFMT_IB_NF |
263 SND_SOC_DAIFMT_CBM_CFM);
267 /* Set cpu DAI configuration */
268 err = snd_soc_dai_set_fmt(cpu_dai,
269 SND_SOC_DAIFMT_DSP_A |
270 SND_SOC_DAIFMT_IB_NF |
271 SND_SOC_DAIFMT_CBM_CFM);
275 /* Set the codec system clock for DAC and ADC */
276 return snd_soc_dai_set_sysclk(codec_dai, 0, 19200000,
280 static int rx51_bt_hw_params(struct snd_pcm_substream *substream,
281 struct snd_pcm_hw_params *params)
283 struct snd_soc_pcm_runtime *rtd = substream->private_data;
284 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
286 /* Set cpu DAI configuration */
287 return cpu_dai->dai_ops.set_fmt(cpu_dai,
288 SND_SOC_DAIFMT_DSP_A |
289 SND_SOC_DAIFMT_IB_NF |
290 SND_SOC_DAIFMT_CBM_CFM);
293 static struct snd_soc_ops rx51_bt_ops = {
294 .hw_params = rx51_bt_hw_params,
297 static struct snd_soc_ops rx51_ops = {
298 .startup = rx51_startup,
299 .hw_params = rx51_hw_params,
300 .shutdown = rx51_shutdown,
303 static int rx51_get_spk(struct snd_kcontrol *kcontrol,
304 struct snd_ctl_elem_value *ucontrol)
306 ucontrol->value.integer.value[0] = rx51_spk_func;
311 static int rx51_set_spk(struct snd_kcontrol *kcontrol,
312 struct snd_ctl_elem_value *ucontrol)
314 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
316 if (rx51_spk_func == ucontrol->value.integer.value[0])
319 rx51_spk_func = ucontrol->value.integer.value[0];
320 rx51_ext_control(codec);
325 static int rx51_spk_event(struct snd_soc_dapm_widget *w,
326 struct snd_kcontrol *k, int event)
328 if (SND_SOC_DAPM_EVENT_ON(event)){
329 aic3x_deemph_set_state(w->codec, 1);
330 gpio_set_value(RX51_SPEAKER_AMP_TWL_GPIO, 1);
331 printk("MNZ: Speaker Amp on!\n");
333 aic3x_deemph_set_state(w->codec, 0);
334 gpio_set_value(RX51_SPEAKER_AMP_TWL_GPIO, 0);
335 printk("MNZ: Speaker Amp off!\n");
340 static int rx51_get_jack(struct snd_kcontrol *kcontrol,
341 struct snd_ctl_elem_value *ucontrol)
343 ucontrol->value.integer.value[0] = rx51_jack_func;
348 static int rx51_set_jack(struct snd_kcontrol *kcontrol,
349 struct snd_ctl_elem_value *ucontrol)
351 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
353 if (rx51_jack_func == ucontrol->value.integer.value[0])
356 rx51_jack_func = ucontrol->value.integer.value[0];
358 mutex_lock(&eci_mutex);
359 if (rx51_jack_func == RX51_JACK_ECI) {
360 /* Set ECI switches according to ECI mode */
361 rx51_set_eci_switches(rx51_eci_mode);
362 schedule_work(&rx51_jack_bias_work);
365 * Let the codec always be connected to mic/bias line when
366 * jack is in non-ECI function
368 rx51_set_eci_switches(1);
369 schedule_work(&rx51_jack_bias_work);
371 mutex_unlock(&eci_mutex);
373 rx51_ext_control(codec);
378 static int rx51_jack_hp_event(struct snd_soc_dapm_widget *w,
379 struct snd_kcontrol *k, int event)
382 * Note: HP amp and fmtx must not be enabled at the same
383 * time. We keep a shadow copy of the desired tpa_enable value but
384 * keep the hpamp really disabled whenever fmtx is enabled. If
385 * hpamp is requested on but fmtx is enabled, hpamp is kept
386 * disabled and enabled later from rx51_set_fmtx function when
387 * user disables fmtx.
389 if (SND_SOC_DAPM_EVENT_ON(event)) {
391 tpa6130a2_set_enabled(1);
394 tpa6130a2_set_enabled(0);
401 static int rx51_jack_mic_event(struct snd_soc_dapm_widget *w,
402 struct snd_kcontrol *k, int event)
404 if (SND_SOC_DAPM_EVENT_ON(event))
405 rx51_dapm_jack_bias = 1;
407 rx51_dapm_jack_bias = 0;
408 schedule_work(&rx51_jack_bias_work);
413 static int rx51_get_fmtx(struct snd_kcontrol *kcontrol,
414 struct snd_ctl_elem_value *ucontrol)
416 ucontrol->value.integer.value[0] = rx51_fmtx_func;
421 static int rx51_set_fmtx(struct snd_kcontrol *kcontrol,
422 struct snd_ctl_elem_value *ucontrol)
424 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
426 if (rx51_fmtx_func == ucontrol->value.integer.value[0])
429 rx51_fmtx_func = ucontrol->value.integer.value[0];
430 rx51_ext_control(codec);
432 /* fmtx and tpa must not be enabled at the same time */
433 if (rx51_fmtx_func && tpa6130_enable)
434 tpa6130a2_set_enabled(0);
435 if (!rx51_fmtx_func && tpa6130_enable)
436 tpa6130a2_set_enabled(1);
441 static int rx51_get_input(struct snd_kcontrol *kcontrol,
442 struct snd_ctl_elem_value *ucontrol)
444 ucontrol->value.integer.value[0] = rx51_dmic_func;
449 static int rx51_set_input(struct snd_kcontrol *kcontrol,
450 struct snd_ctl_elem_value *ucontrol)
452 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
454 if (rx51_dmic_func == ucontrol->value.integer.value[0])
457 rx51_dmic_func = ucontrol->value.integer.value[0];
458 rx51_ext_control(codec);
463 static int rx51_get_ear(struct snd_kcontrol *kcontrol,
464 struct snd_ctl_elem_value *ucontrol)
466 ucontrol->value.integer.value[0] = rx51_ear_func;
471 static int rx51_set_ear(struct snd_kcontrol *kcontrol,
472 struct snd_ctl_elem_value *ucontrol)
474 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
476 if (rx51_ear_func == ucontrol->value.integer.value[0])
479 rx51_ear_func = ucontrol->value.integer.value[0];
480 rx51_ext_control(codec);
485 static int rx51_ear_event(struct snd_soc_dapm_widget *w,
486 struct snd_kcontrol *k, int event)
488 if (SND_SOC_DAPM_EVENT_ON(event))
489 aic34b_ear_enable(1);
491 aic34b_ear_enable(0);
496 static int rx51_pre_spk_event(struct snd_soc_dapm_widget *w,
497 struct snd_kcontrol *k, int event)
499 if (!rx51_new_hw_audio)
502 if (SND_SOC_DAPM_EVENT_ON(event))
503 return twl4030_enable_regulator(RES_VMMC2);
508 static int rx51_post_spk_event(struct snd_soc_dapm_widget *w,
509 struct snd_kcontrol *k, int event)
511 if (!rx51_new_hw_audio)
514 if (!SND_SOC_DAPM_EVENT_ON(event))
515 return twl4030_disable_regulator(RES_VMMC2);
520 static int rx51_pre_event(struct snd_soc_dapm_widget *w,
521 struct snd_kcontrol *k, int event)
523 if (!rx51_new_hw_audio)
526 if (SND_SOC_DAPM_EVENT_ON(event)) {
529 return twl4030_enable_regulator(RES_VMMC2);
536 static int rx51_post_event(struct snd_soc_dapm_widget *w,
537 struct snd_kcontrol *k, int event)
539 if (!rx51_new_hw_audio)
542 if (!SND_SOC_DAPM_EVENT_ON(event)) {
543 if (pre_events && !w->codec->active) {
545 return twl4030_disable_regulator(RES_VMMC2);
553 RX51_EXT_API_TPA6130,
556 #define SOC_RX51_EXT_SINGLE_TLV(xname, ext_api, max, tlv_array) \
558 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
560 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
561 SNDRV_CTL_ELEM_ACCESS_READWRITE, \
562 .tlv.p = (tlv_array), \
563 .info = rx51_ext_info_volsw, \
564 .get = rx51_ext_get_volsw, \
565 .put = rx51_ext_put_volsw, \
566 .private_value = (ext_api) << 26 | (max) << 16, \
569 static int rx51_ext_info_volsw(struct snd_kcontrol *kcontrol,
570 struct snd_ctl_elem_info *uinfo)
572 int ext_api = (kcontrol->private_value >> 26) & 0x0f;
573 int max = (kcontrol->private_value >> 16) & 0xff;
575 if (ext_api == RX51_EXT_API_TPA6130)
576 if (hp_lim != max && hp_lim >= 2 && hp_lim <= 63) {
577 kcontrol->private_value &= ~(0xff << 16);
578 kcontrol->private_value |= (hp_lim << 16);
583 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
585 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
588 uinfo->value.integer.min = 0;
589 uinfo->value.integer.max = max;
594 static int rx51_ext_get_volsw(struct snd_kcontrol *kcontrol,
595 struct snd_ctl_elem_value *ucontrol)
597 int ext_api = (kcontrol->private_value >> 26) & 0x0f;
600 case RX51_EXT_API_TPA6130:
601 if (tpa6130_volume < 0)
602 tpa6130_volume = tpa6130a2_get_volume();
603 ucontrol->value.integer.value[0] = tpa6130_volume;
605 case RX51_EXT_API_AIC34B:
606 ucontrol->value.integer.value[0] = aic34b_volume;
615 static int rx51_ext_put_volsw(struct snd_kcontrol *kcontrol,
616 struct snd_ctl_elem_value *ucontrol)
618 int ext_api = (kcontrol->private_value >> 26) & 0x0f;
622 case RX51_EXT_API_TPA6130:
623 change = (tpa6130_volume != ucontrol->value.integer.value[0]);
624 tpa6130_volume = ucontrol->value.integer.value[0];
625 tpa6130a2_set_volume(tpa6130_volume);
627 case RX51_EXT_API_AIC34B:
628 change = (aic34b_volume != ucontrol->value.integer.value[0]);
629 aic34b_volume = ucontrol->value.integer.value[0];
630 aic34b_set_volume(aic34b_volume);
639 #define SOC_RX51_SINGLE_JACK_BIAS(xname) \
641 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
643 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
644 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
645 .info = rx51_info_jack_bias, \
646 .get = rx51_get_jack_bias, \
647 .put = rx51_put_jack_bias, \
650 static int rx51_info_jack_bias(struct snd_kcontrol *kcontrol,
651 struct snd_ctl_elem_info *uinfo)
653 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
655 uinfo->value.integer.min = 0;
656 uinfo->value.integer.max = 1;
661 static int rx51_get_jack_bias(struct snd_kcontrol *kcontrol,
662 struct snd_ctl_elem_value *ucontrol)
664 ucontrol->value.integer.value[0] = (aic34b_get_mic_bias() != 0);
669 static int rx51_put_jack_bias(struct snd_kcontrol *kcontrol,
670 struct snd_ctl_elem_value *ucontrol)
672 int change, new_value;
674 new_value = ucontrol->value.integer.value[0];
675 change = (new_value != aic34b_get_mic_bias());
678 switch (rx51_jack_func) {
682 aic34b_set_mic_bias(new_value * 2); /* 2.5 V */
692 static const struct snd_soc_dapm_widget aic34_dapm_widgets[] = {
693 SND_SOC_DAPM_POST("Post event", rx51_post_event),
694 SND_SOC_DAPM_SPK("Post spk", rx51_post_spk_event),
695 SND_SOC_DAPM_SPK("Ext Spk", rx51_spk_event),
696 SND_SOC_DAPM_SPK("Headphone Jack", rx51_jack_hp_event),
697 SND_SOC_DAPM_MIC("Mic Jack", rx51_jack_mic_event),
698 SND_SOC_DAPM_OUTPUT("FM Transmitter"),
699 SND_SOC_DAPM_MIC("DMic", NULL),
700 SND_SOC_DAPM_SPK("Earphone", rx51_ear_event),
701 SND_SOC_DAPM_SPK("Pre spk", rx51_pre_spk_event),
702 SND_SOC_DAPM_PRE("Pre event", rx51_pre_event),
705 static const struct snd_soc_dapm_route audio_map[] = {
706 {"Post spk", NULL, "LLOUT"},
707 {"Post spk", NULL, "RLOUT"},
709 {"Ext Spk", NULL, "HPLOUT"},
710 {"Ext Spk", NULL, "HPROUT"},
712 {"Headphone Jack", NULL, "LLOUT"},
713 {"Headphone Jack", NULL, "RLOUT"},
714 {"LINE1L", NULL, "Mic Jack"},
716 {"FM Transmitter", NULL, "LLOUT"},
717 {"FM Transmitter", NULL, "RLOUT"},
719 {"Earphone", NULL, "MONO_LOUT"},
721 {"DMic Rate 64", NULL, "Mic Bias 2V"},
722 {"Mic Bias 2V", NULL, "DMic"},
724 {"Pre spk", NULL, "LLOUT"},
725 {"Pre spk", NULL, "RLOUT"},
728 static const char *spk_function[] = {"Off", "On"};
729 static const char *jack_function[] = {"Off", "Headphone", "Headset",
730 "Mic", "ECI Headset", "TV-OUT"};
731 static const char *fmtx_function[] = {"Off", "On"};
732 static const char *input_function[] = {"ADC", "Digital Mic"};
733 static const char *ear_function[] = {"Off", "On"};
735 static const struct soc_enum rx51_enum[] = {
736 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(spk_function), spk_function),
737 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(jack_function), jack_function),
738 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(fmtx_function), fmtx_function),
739 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(input_function), input_function),
740 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(ear_function), ear_function),
744 * TPA6130 volume. From -59.5 to 4 dB with increasing step size when going
745 * down in gain. Justify scale so that it is quite correct from -20 dB and
746 * up. This setting shows -30 dB at minimum, -12.95 dB at 49 % (actual
747 * is -10.3 dB) and 4.65 dB at maximum (actual is 4 dB).
749 static const unsigned int tpa6130_tlv[] = {
750 TLV_DB_RANGE_HEAD(10),
751 0, 1, TLV_DB_SCALE_ITEM(-5950, 600, 0),
752 2, 3, TLV_DB_SCALE_ITEM(-5000, 250, 0),
753 4, 5, TLV_DB_SCALE_ITEM(-4550, 160, 0),
754 6, 7, TLV_DB_SCALE_ITEM(-4140, 190, 0),
755 8, 9, TLV_DB_SCALE_ITEM(-3650, 120, 0),
756 10, 11, TLV_DB_SCALE_ITEM(-3330, 160, 0),
757 12, 13, TLV_DB_SCALE_ITEM(-3040, 180, 0),
758 14, 20, TLV_DB_SCALE_ITEM(-2710, 110, 0),
759 21, 37, TLV_DB_SCALE_ITEM(-1960, 74, 0),
760 38, 63, TLV_DB_SCALE_ITEM(-720, 45, 0),
764 * TLV320AIC3x output stage volumes. From -78.3 to 0 dB. Muted below -78.3 dB.
765 * Step size is approximately 0.5 dB over most of the scale but increasing
766 * near the very low levels.
767 * Define dB scale so that it is mostly correct for range about -55 to 0 dB
768 * but having increasing dB difference below that (and where it doesn't count
769 * so much). This setting shows -50 dB (actual is -50.3 dB) for register
770 * value 100 and -58.5 dB (actual is -78.3 dB) for register value 117.
772 static DECLARE_TLV_DB_SCALE(aic3x_output_stage_tlv, -5900, 50, 1);
774 static const struct snd_kcontrol_new aic34_rx51_controls[] = {
775 SOC_ENUM_EXT("Speaker Function", rx51_enum[0],
776 rx51_get_spk, rx51_set_spk),
777 SOC_ENUM_EXT("Jack Function", rx51_enum[1],
778 rx51_get_jack, rx51_set_jack),
779 SOC_ENUM_EXT("FMTX Function", rx51_enum[2],
780 rx51_get_fmtx, rx51_set_fmtx),
781 SOC_ENUM_EXT("Input Select", rx51_enum[3],
782 rx51_get_input, rx51_set_input),
783 SOC_ENUM_EXT("Earphone Function", rx51_enum[4],
784 rx51_get_ear, rx51_set_ear),
785 SOC_RX51_EXT_SINGLE_TLV("Headphone Playback Volume",
786 RX51_EXT_API_TPA6130, 63,
788 SOC_RX51_EXT_SINGLE_TLV("Earphone Playback Volume",
789 RX51_EXT_API_AIC34B, 118,
790 aic3x_output_stage_tlv),
791 SOC_RX51_SINGLE_JACK_BIAS("Jack Bias Switch"),
794 static int rx51_aic34_init(struct snd_soc_codec *codec)
798 printk("MNZ: BEGIN rx51_aic3x_init\n");
799 /* set up NC codec pins */
800 snd_soc_dapm_nc_pin(codec, "MIC3L");
801 snd_soc_dapm_nc_pin(codec, "MIC3R");
802 snd_soc_dapm_nc_pin(codec, "LINE1R");
804 /* Create jack for accessory reporting */
805 err = snd_jack_new(codec->card, "Jack", SND_JACK_MECHANICAL |
806 SND_JACK_HEADSET | SND_JACK_AVOUT, &rx51_jack);
810 /* Add RX51 specific controls */
811 for (i = 0; i < ARRAY_SIZE(aic34_rx51_controls); i++) {
812 err = snd_ctl_add(codec->card,
813 snd_soc_cnew(&aic34_rx51_controls[i], codec, NULL));
818 /* Add RX51 specific widgets */
819 snd_soc_dapm_new_controls(codec, aic34_dapm_widgets,
820 ARRAY_SIZE(aic34_dapm_widgets));
822 /* Set up RX51 specific audio path audio_map */
823 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
825 snd_soc_dapm_enable_pin(codec, "Earphone");
827 snd_soc_dapm_sync(codec);
829 /* Default De-emphasis filter coefficients to use as a highpass for
830 * cheap speaker protection */
831 aic3x_deemph_set_coeffs(codec, 32276, -32276, 31785);
833 printk("MNZ: END rx51_aic3x_init\n");
837 /* Since all codec control is done by Bluetooth hardware
838 only some constrains need to be set for it */
839 struct snd_soc_dai btcodec_dai = {
840 .name = "Bluetooth codec",
842 .stream_name = "BT Playback",
845 .rates = SNDRV_PCM_RATE_8000,
846 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
848 .stream_name = "BT Capture",
851 .rates = SNDRV_PCM_RATE_8000,
852 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
855 /* Digital audio interface glue - connects codec <--> CPU */
856 static struct snd_soc_dai_link rx51_dai[] = {
858 .name = "TLV320AIC34",
859 .stream_name = "AIC34",
860 .cpu_dai = &omap_mcbsp_dai[0],
861 .codec_dai = &aic3x_dai,
862 .init = rx51_aic34_init,
865 .name = "Bluetooth PCM",
866 .stream_name = "Bluetooth",
867 .cpu_dai = &omap_mcbsp_dai[1],
868 .codec_dai = &btcodec_dai,
873 /* Audio machine driver */
874 static struct snd_soc_machine snd_soc_machine_rx51 = {
876 .dai_link = rx51_dai,
877 .num_links = ARRAY_SIZE(rx51_dai),
880 /* Audio private data */
881 static struct aic3x_setup_data rx51_aic34_setup = {
884 .gpio_func[0] = AIC3X_GPIO1_FUNC_DISABLED,
885 .gpio_func[1] = AIC3X_GPIO2_FUNC_DIGITAL_MIC_INPUT,
888 /* Audio subsystem */
889 static struct snd_soc_device rx51_snd_devdata = {
890 .machine = &snd_soc_machine_rx51,
891 .platform = &omap_soc_platform,
892 .codec_dev = &soc_codec_dev_aic3x,
893 .codec_data = &rx51_aic34_setup,
896 static struct platform_device *rx51_snd_device;
898 #define REMAP_OFFSET 2
899 #define DEDICATED_OFFSET 3
900 #define VMMC2_DEV_GRP 0x2B
901 #define VMMC2_285V 0x0a
903 static int __init rx51_soc_init(void)
908 if (!machine_is_nokia_rx51())
911 if ((system_rev >= 0x08 && system_rev <= 0x13) || /* Macros */
912 system_rev >= 0x1901) {
913 rx51_new_hw_audio = 1;
914 err = twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
916 VMMC2_DEV_GRP + DEDICATED_OFFSET);
917 err |= twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0xee,
918 VMMC2_DEV_GRP + REMAP_OFFSET);
920 printk(KERN_ERR "%s rx51 audio failed!\n", __func__);
925 if (gpio_request(RX51_CODEC_RESET_GPIO, NULL) < 0)
927 if (gpio_request(RX51_TVOUT_SEL_GPIO, "tvout_sel") < 0)
929 if (gpio_request(RX51_ECI_SWITCH_1_GPIO, "ECI switch 1") < 0)
931 if (gpio_request(RX51_ECI_SWITCH_2_GPIO, "ECI switch 2") < 0)
933 gpio_direction_output(RX51_CODEC_RESET_GPIO, 0);
934 gpio_direction_output(RX51_TVOUT_SEL_GPIO, 0);
935 gpio_direction_output(RX51_ECI_SWITCH_1_GPIO, 0);
936 gpio_direction_output(RX51_ECI_SWITCH_2_GPIO, 1);
938 gpio_set_value(RX51_CODEC_RESET_GPIO, 0);
940 gpio_set_value(RX51_CODEC_RESET_GPIO, 1);
943 if (gpio_request(RX51_SPEAKER_AMP_TWL_GPIO, NULL) < 0)
945 gpio_direction_output(RX51_SPEAKER_AMP_TWL_GPIO, 0);
947 rx51_snd_device = platform_device_alloc("soc-audio", -1);
948 if (!rx51_snd_device)
951 platform_set_drvdata(rx51_snd_device, &rx51_snd_devdata);
952 rx51_snd_devdata.dev = &rx51_snd_device->dev;
953 err = platform_device_add(rx51_snd_device);
957 dev = &rx51_snd_device->dev;
959 *(unsigned int *)rx51_dai[0].cpu_dai->private_data = 1;
960 *(unsigned int *)rx51_dai[1].cpu_dai->private_data = 2;
962 err = device_create_file(dev, &dev_attr_eci_mode);
968 platform_device_del(rx51_snd_device);
970 platform_device_put(rx51_snd_device);
976 static void __exit rx51_soc_exit(void)
978 platform_device_unregister(rx51_snd_device);
981 module_init(rx51_soc_init);
982 module_exit(rx51_soc_exit);
984 MODULE_AUTHOR("Jarkko Nikula <jarkko.nikula@nokia.com>");
985 MODULE_DESCRIPTION("ALSA SoC Nokia RX51");
986 MODULE_LICENSE("GPL");