Lines Matching +full:tx1 +full:- +full:0
1 // SPDX-License-Identifier: GPL-2.0-only
28 #include <linux/mfd/twl4030-audio.h>
31 #define TWL4030_PMBR1_REG 0x0D
33 #define TWL4030_GPIO6_PWM0_MUTE(value) ((value & 0x03) << 2)
67 u8 ctl_cache[TWL4030_REG_PRECKR_CTL - TWL4030_REG_EAR_CTL + 1];
79 twl4030->ctl_cache[i - TWL4030_REG_EAR_CTL] = byte; in tw4030_init_ctl_cache()
86 u8 value = 0; in twl4030_read()
89 return -EIO; in twl4030_read()
98 value = twl4030->ctl_cache[reg - TWL4030_REG_EAR_CTL]; in twl4030_read()
116 if (twl4030->earpiece_enabled) in twl4030_can_write_to_chip()
120 if (twl4030->predrivel_enabled) in twl4030_can_write_to_chip()
124 if (twl4030->predriver_enabled) in twl4030_can_write_to_chip()
128 if (twl4030->carkitl_enabled) in twl4030_can_write_to_chip()
132 if (twl4030->carkitr_enabled) in twl4030_can_write_to_chip()
136 if (twl4030->hsl_enabled || twl4030->hsr_enabled) in twl4030_can_write_to_chip()
161 twl4030->ctl_cache[reg - TWL4030_REG_EAR_CTL] = value; in twl4030_write()
170 return 0; in twl4030_write()
188 if (enable == twl4030->codec_powered) in twl4030_codec_enable()
196 if (mode >= 0) in twl4030_codec_enable()
197 twl4030->codec_powered = enable; in twl4030_codec_enable()
210 of_property_read_u32(node, "ti,digimic_delay", &board_params->digimic_delay); in twl4030_get_board_param_values()
211 of_property_read_u32(node, "ti,ramp_delay_value", &board_params->ramp_delay_value); in twl4030_get_board_param_values()
212 of_property_read_u32(node, "ti,offset_cncl_path", &board_params->offset_cncl_path); in twl4030_get_board_param_values()
214 board_params->hs_extmute = value; in twl4030_get_board_param_values()
216 board_params->hs_extmute_gpio = of_get_named_gpio(node, "ti,hs_extmute_gpio", 0); in twl4030_get_board_param_values()
217 if (gpio_is_valid(board_params->hs_extmute_gpio)) in twl4030_get_board_param_values()
218 board_params->hs_extmute = 1; in twl4030_get_board_param_values()
227 twl4030_codec_node = of_get_child_by_name(component->dev->parent->of_node, in twl4030_get_board_params()
231 board_params = devm_kzalloc(component->dev, in twl4030_get_board_params()
250 int i = 0; in twl4030_init_chip()
254 if (board_params && board_params->hs_extmute) { in twl4030_init_chip()
255 if (gpio_is_valid(board_params->hs_extmute_gpio)) { in twl4030_init_chip()
258 if (!board_params->hs_extmute_gpio) in twl4030_init_chip()
259 dev_warn(component->dev, in twl4030_init_chip()
260 "Extmute GPIO is 0 is this correct?\n"); in twl4030_init_chip()
262 ret = gpio_request_one(board_params->hs_extmute_gpio, in twl4030_init_chip()
266 dev_err(component->dev, in twl4030_init_chip()
268 board_params->hs_extmute_gpio = -1; in twl4030_init_chip()
276 pin_mux &= ~TWL4030_GPIO6_PWM0_MUTE(0x03); in twl4030_init_chip()
277 pin_mux |= TWL4030_GPIO6_PWM0_MUTE(0x02); in twl4030_init_chip()
286 /* anti-pop when changing analog gain */ in twl4030_init_chip()
295 /* REG_ARXR2_APGA_CTL reset according to the TRM: 0dB, DA_EN */ in twl4030_init_chip()
296 twl4030_write(component, TWL4030_REG_ARXR2_APGA_CTL, 0x32); in twl4030_init_chip()
302 twl4030->board_params = board_params; in twl4030_init_chip()
306 reg |= (board_params->ramp_delay_value << 2); in twl4030_init_chip()
314 reg |= board_params->offset_cncl_path; in twl4030_init_chip()
334 twl4030_codec_enable(component, 0); in twl4030_init_chip()
342 twl4030->apll_enabled++; in twl4030_apll_enable()
343 if (twl4030->apll_enabled == 1) in twl4030_apll_enable()
347 twl4030->apll_enabled--; in twl4030_apll_enable()
348 if (!twl4030->apll_enabled) in twl4030_apll_enable()
356 SOC_DAPM_SINGLE("Voice", TWL4030_REG_EAR_CTL, 0, 1, 0),
357 SOC_DAPM_SINGLE("AudioL1", TWL4030_REG_EAR_CTL, 1, 1, 0),
358 SOC_DAPM_SINGLE("AudioL2", TWL4030_REG_EAR_CTL, 2, 1, 0),
359 SOC_DAPM_SINGLE("AudioR1", TWL4030_REG_EAR_CTL, 3, 1, 0),
364 SOC_DAPM_SINGLE("Voice", TWL4030_REG_PREDL_CTL, 0, 1, 0),
365 SOC_DAPM_SINGLE("AudioL1", TWL4030_REG_PREDL_CTL, 1, 1, 0),
366 SOC_DAPM_SINGLE("AudioL2", TWL4030_REG_PREDL_CTL, 2, 1, 0),
367 SOC_DAPM_SINGLE("AudioR2", TWL4030_REG_PREDL_CTL, 3, 1, 0),
372 SOC_DAPM_SINGLE("Voice", TWL4030_REG_PREDR_CTL, 0, 1, 0),
373 SOC_DAPM_SINGLE("AudioR1", TWL4030_REG_PREDR_CTL, 1, 1, 0),
374 SOC_DAPM_SINGLE("AudioR2", TWL4030_REG_PREDR_CTL, 2, 1, 0),
375 SOC_DAPM_SINGLE("AudioL2", TWL4030_REG_PREDR_CTL, 3, 1, 0),
380 SOC_DAPM_SINGLE("Voice", TWL4030_REG_HS_SEL, 0, 1, 0),
381 SOC_DAPM_SINGLE("AudioL1", TWL4030_REG_HS_SEL, 1, 1, 0),
382 SOC_DAPM_SINGLE("AudioL2", TWL4030_REG_HS_SEL, 2, 1, 0),
387 SOC_DAPM_SINGLE("Voice", TWL4030_REG_HS_SEL, 3, 1, 0),
388 SOC_DAPM_SINGLE("AudioR1", TWL4030_REG_HS_SEL, 4, 1, 0),
389 SOC_DAPM_SINGLE("AudioR2", TWL4030_REG_HS_SEL, 5, 1, 0),
394 SOC_DAPM_SINGLE("Voice", TWL4030_REG_PRECKL_CTL, 0, 1, 0),
395 SOC_DAPM_SINGLE("AudioL1", TWL4030_REG_PRECKL_CTL, 1, 1, 0),
396 SOC_DAPM_SINGLE("AudioL2", TWL4030_REG_PRECKL_CTL, 2, 1, 0),
401 SOC_DAPM_SINGLE("Voice", TWL4030_REG_PRECKR_CTL, 0, 1, 0),
402 SOC_DAPM_SINGLE("AudioR1", TWL4030_REG_PRECKR_CTL, 1, 1, 0),
403 SOC_DAPM_SINGLE("AudioR2", TWL4030_REG_PRECKR_CTL, 2, 1, 0),
411 TWL4030_REG_HFL_CTL, 0,
426 TWL4030_REG_HFR_CTL, 0,
462 TWL4030_REG_ANAMICL, 0, 1, 0),
464 TWL4030_REG_ANAMICL, 1, 1, 0),
466 TWL4030_REG_ANAMICL, 2, 1, 0),
468 TWL4030_REG_ANAMICL, 3, 1, 0),
473 SOC_DAPM_SINGLE("Sub Mic Capture Switch", TWL4030_REG_ANAMICR, 0, 1, 0),
474 SOC_DAPM_SINGLE("AUXR Capture Switch", TWL4030_REG_ANAMICR, 2, 1, 0),
477 /* TX1 L/R Analog/Digital microphone selection */
482 TWL4030_REG_ADCMICSEL, 0,
501 SOC_DAPM_SINGLE("Switch", TWL4030_REG_ARXR1_APGA_CTL, 2, 1, 0);
505 SOC_DAPM_SINGLE("Switch", TWL4030_REG_ARXL1_APGA_CTL, 2, 1, 0);
509 SOC_DAPM_SINGLE("Switch", TWL4030_REG_ARXR2_APGA_CTL, 2, 1, 0);
513 SOC_DAPM_SINGLE("Switch", TWL4030_REG_ARXL2_APGA_CTL, 2, 1, 0);
517 SOC_DAPM_SINGLE("Switch", TWL4030_REG_VDL_APGA_CTL, 2, 1, 0);
519 /* Digital bypass gain, mute instead of -30dB */
521 0, 1, TLV_DB_SCALE_ITEM(-3000, 600, 1),
522 2, 3, TLV_DB_SCALE_ITEM(-2400, 0, 0),
523 4, 7, TLV_DB_SCALE_ITEM(-1800, 600, 0)
526 /* Digital bypass left (TX1L -> RX2L) */
529 TWL4030_REG_ATX2ARXPGA, 3, 7, 0,
532 /* Digital bypass right (TX1R -> RX2R) */
535 TWL4030_REG_ATX2ARXPGA, 0, 7, 0,
540 * from -51 to -10 dB in 1 dB steps (mute instead of -51 dB)
542 static DECLARE_TLV_DB_SCALE(twl4030_dapm_dbypassv_tlv, -5100, 100, 1);
544 /* Digital bypass voice: sidetone (VUL -> VDL)*/
547 TWL4030_REG_VSTPGA, 0, 0x29, 0,
554 * On mute bypass the reg_cache and write 0 to the register
562 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); \
567 twl4030->pin_name##_enabled = 1; \
571 twl4030->pin_name##_enabled = 0; \
572 twl_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE, 0, reg); \
575 return 0; \
591 /* HF ramp-up */ in handsfree_ramp()
602 /* HF ramp-down */ in handsfree_ramp()
617 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in handsfreelpga_event()
624 handsfree_ramp(component, TWL4030_REG_HFL_CTL, 0); in handsfreelpga_event()
627 return 0; in handsfreelpga_event()
633 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in handsfreerpga_event()
640 handsfree_ramp(component, TWL4030_REG_HFR_CTL, 0); in handsfreerpga_event()
643 return 0; in handsfreerpga_event()
649 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in vibramux_event()
651 twl4030_write(component, TWL4030_REG_VIBRA_SET, 0xff); in vibramux_event()
652 return 0; in vibramux_event()
658 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in apll_event()
665 twl4030_apll_enable(component, 0); in apll_event()
668 return 0; in apll_event()
674 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in aif_event()
691 twl4030_apll_enable(component, 0); in aif_event()
694 return 0; in aif_event()
701 struct twl4030_board_params *board_params = twl4030->board_params; in headset_ramp()
702 /* Base values for ramp delay calculation: 2^19 - 2^26 */ in headset_ramp()
712 twl4030->sysclk) + 1; in headset_ramp()
715 * the pop-noise */ in headset_ramp()
716 if (board_params && board_params->hs_extmute) { in headset_ramp()
717 if (gpio_is_valid(board_params->hs_extmute_gpio)) { in headset_ramp()
718 gpio_set_value(board_params->hs_extmute_gpio, 1); in headset_ramp()
726 /* Headset ramp-up according to the TRM */ in headset_ramp()
737 /* Headset ramp-down _not_ according to in headset_ramp()
744 twl_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE, hs_gain & (~0x0f), in headset_ramp()
752 if (board_params && board_params->hs_extmute) { in headset_ramp()
753 if (gpio_is_valid(board_params->hs_extmute_gpio)) { in headset_ramp()
754 gpio_set_value(board_params->hs_extmute_gpio, 0); in headset_ramp()
765 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in headsetlpga_event()
770 /* Do the ramp-up only once */ in headsetlpga_event()
771 if (!twl4030->hsr_enabled) in headsetlpga_event()
774 twl4030->hsl_enabled = 1; in headsetlpga_event()
777 /* Do the ramp-down only if both headsetL/R is disabled */ in headsetlpga_event()
778 if (!twl4030->hsr_enabled) in headsetlpga_event()
779 headset_ramp(component, 0); in headsetlpga_event()
781 twl4030->hsl_enabled = 0; in headsetlpga_event()
784 return 0; in headsetlpga_event()
790 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in headsetrpga_event()
795 /* Do the ramp-up only once */ in headsetrpga_event()
796 if (!twl4030->hsl_enabled) in headsetrpga_event()
799 twl4030->hsr_enabled = 1; in headsetrpga_event()
802 /* Do the ramp-down only if both headsetL/R is disabled */ in headsetrpga_event()
803 if (!twl4030->hsl_enabled) in headsetrpga_event()
804 headset_ramp(component, 0); in headsetrpga_event()
806 twl4030->hsr_enabled = 0; in headsetrpga_event()
809 return 0; in headsetrpga_event()
815 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in digimic_event()
817 struct twl4030_board_params *board_params = twl4030->board_params; in digimic_event()
819 if (board_params && board_params->digimic_delay) in digimic_event()
820 twl4030_wait_ms(board_params->digimic_delay); in digimic_event()
821 return 0; in digimic_event()
827 * 0x0 : Power down (mute)
828 * 0x1 : 6dB
829 * 0x2 : 0 dB
830 * 0x3 : -6 dB
838 (struct soc_mixer_control *)kcontrol->private_value; in snd_soc_get_volsw_twl4030()
840 unsigned int reg = mc->reg; in snd_soc_get_volsw_twl4030()
841 unsigned int shift = mc->shift; in snd_soc_get_volsw_twl4030()
842 unsigned int rshift = mc->rshift; in snd_soc_get_volsw_twl4030()
843 int max = mc->max; in snd_soc_get_volsw_twl4030()
844 int mask = (1 << fls(max)) - 1; in snd_soc_get_volsw_twl4030()
846 ucontrol->value.integer.value[0] = in snd_soc_get_volsw_twl4030()
848 if (ucontrol->value.integer.value[0]) in snd_soc_get_volsw_twl4030()
849 ucontrol->value.integer.value[0] = in snd_soc_get_volsw_twl4030()
850 max + 1 - ucontrol->value.integer.value[0]; in snd_soc_get_volsw_twl4030()
853 ucontrol->value.integer.value[1] = in snd_soc_get_volsw_twl4030()
855 if (ucontrol->value.integer.value[1]) in snd_soc_get_volsw_twl4030()
856 ucontrol->value.integer.value[1] = in snd_soc_get_volsw_twl4030()
857 max + 1 - ucontrol->value.integer.value[1]; in snd_soc_get_volsw_twl4030()
860 return 0; in snd_soc_get_volsw_twl4030()
867 (struct soc_mixer_control *)kcontrol->private_value; in snd_soc_put_volsw_twl4030()
869 unsigned int reg = mc->reg; in snd_soc_put_volsw_twl4030()
870 unsigned int shift = mc->shift; in snd_soc_put_volsw_twl4030()
871 unsigned int rshift = mc->rshift; in snd_soc_put_volsw_twl4030()
872 int max = mc->max; in snd_soc_put_volsw_twl4030()
873 int mask = (1 << fls(max)) - 1; in snd_soc_put_volsw_twl4030()
876 val = (ucontrol->value.integer.value[0] & mask); in snd_soc_put_volsw_twl4030()
880 val = max + 1 - val; in snd_soc_put_volsw_twl4030()
883 val2 = (ucontrol->value.integer.value[1] & mask); in snd_soc_put_volsw_twl4030()
886 val2 = max + 1 - val2; in snd_soc_put_volsw_twl4030()
896 (struct soc_mixer_control *)kcontrol->private_value; in snd_soc_get_volsw_r2_twl4030()
898 unsigned int reg = mc->reg; in snd_soc_get_volsw_r2_twl4030()
899 unsigned int reg2 = mc->rreg; in snd_soc_get_volsw_r2_twl4030()
900 unsigned int shift = mc->shift; in snd_soc_get_volsw_r2_twl4030()
901 int max = mc->max; in snd_soc_get_volsw_r2_twl4030()
902 int mask = (1<<fls(max))-1; in snd_soc_get_volsw_r2_twl4030()
904 ucontrol->value.integer.value[0] = in snd_soc_get_volsw_r2_twl4030()
906 ucontrol->value.integer.value[1] = in snd_soc_get_volsw_r2_twl4030()
909 if (ucontrol->value.integer.value[0]) in snd_soc_get_volsw_r2_twl4030()
910 ucontrol->value.integer.value[0] = in snd_soc_get_volsw_r2_twl4030()
911 max + 1 - ucontrol->value.integer.value[0]; in snd_soc_get_volsw_r2_twl4030()
912 if (ucontrol->value.integer.value[1]) in snd_soc_get_volsw_r2_twl4030()
913 ucontrol->value.integer.value[1] = in snd_soc_get_volsw_r2_twl4030()
914 max + 1 - ucontrol->value.integer.value[1]; in snd_soc_get_volsw_r2_twl4030()
916 return 0; in snd_soc_get_volsw_r2_twl4030()
923 (struct soc_mixer_control *)kcontrol->private_value; in snd_soc_put_volsw_r2_twl4030()
925 unsigned int reg = mc->reg; in snd_soc_put_volsw_r2_twl4030()
926 unsigned int reg2 = mc->rreg; in snd_soc_put_volsw_r2_twl4030()
927 unsigned int shift = mc->shift; in snd_soc_put_volsw_r2_twl4030()
928 int max = mc->max; in snd_soc_put_volsw_r2_twl4030()
929 int mask = (1 << fls(max)) - 1; in snd_soc_put_volsw_r2_twl4030()
934 val = (ucontrol->value.integer.value[0] & mask); in snd_soc_put_volsw_r2_twl4030()
935 val2 = (ucontrol->value.integer.value[1] & mask); in snd_soc_put_volsw_r2_twl4030()
938 val = max + 1 - val; in snd_soc_put_volsw_r2_twl4030()
940 val2 = max + 1 - val2; in snd_soc_put_volsw_r2_twl4030()
946 if (err < 0) in snd_soc_put_volsw_r2_twl4030()
959 TWL4030_REG_CODEC_MODE, 0,
968 if (twl4030->configured) { in snd_soc_put_twl4030_opmode_enum_double()
969 dev_err(component->dev, in snd_soc_put_twl4030_opmode_enum_double()
970 "operation mode cannot be changed on-the-fly\n"); in snd_soc_put_twl4030_opmode_enum_double()
971 return -EBUSY; in snd_soc_put_twl4030_opmode_enum_double()
979 * from -62 to 0 dB in 1 dB steps (mute instead of -63 dB)
981 static DECLARE_TLV_DB_SCALE(digital_fine_tlv, -6300, 100, 1);
985 * 0 dB to 12 dB in 6 dB steps
988 static DECLARE_TLV_DB_SCALE(digital_coarse_tlv, 0, 600, 0);
992 * from -37 to 12 dB in 1 dB steps (mute instead of -37 dB)
994 static DECLARE_TLV_DB_SCALE(digital_voice_downlink_tlv, -3700, 100, 1);
998 * -24 dB to 12 dB in 2 dB steps
1000 static DECLARE_TLV_DB_SCALE(analog_tlv, -2400, 200, 0);
1004 * -6 dB to 6 dB in 6 dB steps (mute instead of -12)
1006 static DECLARE_TLV_DB_SCALE(output_tvl, -1200, 600, 1);
1010 * 0 dB to 12 dB in 6 dB steps (mute instead of -6)
1012 static DECLARE_TLV_DB_SCALE(output_ear_tvl, -600, 600, 1);
1016 * from 0 dB to 31 dB in 1 dB steps
1018 static DECLARE_TLV_DB_SCALE(digital_capture_tlv, 0, 100, 0);
1022 * 0 dB to 30 dB in 6 dB steps
1024 static DECLARE_TLV_DB_SCALE(input_gain_tlv, 0, 600, 0);
1045 /* Vibra H-bridge direction mode */
1047 "Vibra H-bridge direction", "Audio data MSB",
1054 /* Vibra H-bridge direction */
1069 TWL4030_REG_MISC_SET_1, 0,
1081 0, 0x3f, 0, digital_fine_tlv),
1084 0, 0x3f, 0, digital_fine_tlv),
1088 6, 0x2, 0, digital_coarse_tlv),
1091 6, 0x2, 0, digital_coarse_tlv),
1095 3, 0x12, 1, analog_tlv),
1098 3, 0x12, 1, analog_tlv),
1101 1, 1, 0),
1104 1, 1, 0),
1108 TWL4030_REG_VRXPGA, 0, 0x31, 0, digital_voice_downlink_tlv),
1111 TWL4030_REG_VDL_APGA_CTL, 3, 0x12, 1, analog_tlv),
1114 TWL4030_REG_VDL_APGA_CTL, 1, 1, 0),
1119 4, 3, 0, snd_soc_get_volsw_r2_twl4030,
1123 TWL4030_REG_HS_GAIN_SET, 0, 2, 3, 0, snd_soc_get_volsw_twl4030,
1128 4, 3, 0, snd_soc_get_volsw_r2_twl4030,
1132 TWL4030_REG_EAR_CTL, 4, 3, 0, snd_soc_get_volsw_twl4030,
1136 SOC_DOUBLE_R_TLV("TX1 Digital Capture Volume",
1138 0, 0x1f, 0, digital_capture_tlv),
1141 0, 0x1f, 0, digital_capture_tlv),
1144 0, 3, 5, 0, input_gain_tlv),
1150 SOC_ENUM("Vibra H-bridge mode", twl4030_vibradirmode_enum),
1151 SOC_ENUM("Vibra H-bridge direction", twl4030_vibradir_enum),
1187 SND_SOC_DAPM_DAC("DAC Right1", NULL, SND_SOC_NOPM, 0, 0),
1188 SND_SOC_DAPM_DAC("DAC Left1", NULL, SND_SOC_NOPM, 0, 0),
1189 SND_SOC_DAPM_DAC("DAC Right2", NULL, SND_SOC_NOPM, 0, 0),
1190 SND_SOC_DAPM_DAC("DAC Left2", NULL, SND_SOC_NOPM, 0, 0),
1191 SND_SOC_DAPM_DAC("DAC Voice", NULL, SND_SOC_NOPM, 0, 0),
1193 SND_SOC_DAPM_AIF_IN("VAIFIN", "Voice Playback", 0,
1194 TWL4030_REG_VOICE_IF, 6, 0),
1197 SND_SOC_DAPM_SWITCH("Right1 Analog Loopback", SND_SOC_NOPM, 0, 0,
1199 SND_SOC_DAPM_SWITCH("Left1 Analog Loopback", SND_SOC_NOPM, 0, 0,
1201 SND_SOC_DAPM_SWITCH("Right2 Analog Loopback", SND_SOC_NOPM, 0, 0,
1203 SND_SOC_DAPM_SWITCH("Left2 Analog Loopback", SND_SOC_NOPM, 0, 0,
1205 SND_SOC_DAPM_SWITCH("Voice Analog Loopback", SND_SOC_NOPM, 0, 0,
1209 SND_SOC_DAPM_SUPPLY("FM Loop Enable", TWL4030_REG_MISC_SET_1, 5, 0,
1210 NULL, 0),
1213 SND_SOC_DAPM_SWITCH("Left Digital Loopback", SND_SOC_NOPM, 0, 0,
1215 SND_SOC_DAPM_SWITCH("Right Digital Loopback", SND_SOC_NOPM, 0, 0,
1217 SND_SOC_DAPM_SWITCH("Voice Digital Loopback", SND_SOC_NOPM, 0, 0,
1222 TWL4030_REG_AVDAC_CTL, 0, 0, NULL, 0),
1224 TWL4030_REG_AVDAC_CTL, 1, 0, NULL, 0),
1226 TWL4030_REG_AVDAC_CTL, 2, 0, NULL, 0),
1228 TWL4030_REG_AVDAC_CTL, 3, 0, NULL, 0),
1230 TWL4030_REG_AVDAC_CTL, 4, 0, NULL, 0),
1234 TWL4030_REG_ARXR1_APGA_CTL, 0, 0, NULL, 0),
1236 TWL4030_REG_ARXL1_APGA_CTL, 0, 0, NULL, 0),
1238 TWL4030_REG_ARXR2_APGA_CTL, 0, 0, NULL, 0),
1240 TWL4030_REG_ARXL2_APGA_CTL, 0, 0, NULL, 0),
1242 TWL4030_REG_VDL_APGA_CTL, 0, 0, NULL, 0),
1244 SND_SOC_DAPM_SUPPLY("APLL Enable", SND_SOC_NOPM, 0, 0, apll_event,
1247 SND_SOC_DAPM_SUPPLY("AIF Enable", SND_SOC_NOPM, 0, 0, aif_event,
1252 SND_SOC_DAPM_MIXER("Earpiece Mixer", SND_SOC_NOPM, 0, 0,
1253 &twl4030_dapm_earpiece_controls[0],
1256 0, 0, NULL, 0, earpiecepga_event,
1259 SND_SOC_DAPM_MIXER("PredriveL Mixer", SND_SOC_NOPM, 0, 0,
1260 &twl4030_dapm_predrivel_controls[0],
1263 0, 0, NULL, 0, predrivelpga_event,
1265 SND_SOC_DAPM_MIXER("PredriveR Mixer", SND_SOC_NOPM, 0, 0,
1266 &twl4030_dapm_predriver_controls[0],
1269 0, 0, NULL, 0, predriverpga_event,
1272 SND_SOC_DAPM_MIXER("HeadsetL Mixer", SND_SOC_NOPM, 0, 0,
1273 &twl4030_dapm_hsol_controls[0],
1276 0, 0, NULL, 0, headsetlpga_event,
1278 SND_SOC_DAPM_MIXER("HeadsetR Mixer", SND_SOC_NOPM, 0, 0,
1279 &twl4030_dapm_hsor_controls[0],
1282 0, 0, NULL, 0, headsetrpga_event,
1285 SND_SOC_DAPM_MIXER("CarkitL Mixer", SND_SOC_NOPM, 0, 0,
1286 &twl4030_dapm_carkitl_controls[0],
1289 0, 0, NULL, 0, carkitlpga_event,
1291 SND_SOC_DAPM_MIXER("CarkitR Mixer", SND_SOC_NOPM, 0, 0,
1292 &twl4030_dapm_carkitr_controls[0],
1295 0, 0, NULL, 0, carkitrpga_event,
1300 SND_SOC_DAPM_MUX("HandsfreeL Mux", SND_SOC_NOPM, 0, 0,
1302 SND_SOC_DAPM_SWITCH("HandsfreeL", SND_SOC_NOPM, 0, 0,
1305 0, 0, NULL, 0, handsfreelpga_event,
1307 SND_SOC_DAPM_MUX("HandsfreeR Mux", SND_SOC_NOPM, 5, 0,
1309 SND_SOC_DAPM_SWITCH("HandsfreeR", SND_SOC_NOPM, 0, 0,
1312 0, 0, NULL, 0, handsfreerpga_event,
1315 SND_SOC_DAPM_MUX_E("Vibra Mux", TWL4030_REG_VIBRA_CTL, 0, 0,
1318 SND_SOC_DAPM_MUX("Vibra Route", SND_SOC_NOPM, 0, 0,
1323 SND_SOC_DAPM_ADC("ADC Virtual Left1", NULL, SND_SOC_NOPM, 0, 0),
1324 SND_SOC_DAPM_ADC("ADC Virtual Right1", NULL, SND_SOC_NOPM, 0, 0),
1325 SND_SOC_DAPM_ADC("ADC Virtual Left2", NULL, SND_SOC_NOPM, 0, 0),
1326 SND_SOC_DAPM_ADC("ADC Virtual Right2", NULL, SND_SOC_NOPM, 0, 0),
1328 SND_SOC_DAPM_AIF_OUT("VAIFOUT", "Voice Capture", 0,
1329 TWL4030_REG_VOICE_IF, 5, 0),
1332 TX1 Left/Right: either analog Left/Right or Digimic0
1334 SND_SOC_DAPM_MUX("TX1 Capture Route", SND_SOC_NOPM, 0, 0,
1336 SND_SOC_DAPM_MUX("TX2 Capture Route", SND_SOC_NOPM, 0, 0,
1341 TWL4030_REG_ANAMICL, 4, 0,
1342 &twl4030_dapm_analoglmic_controls[0],
1345 TWL4030_REG_ANAMICR, 4, 0,
1346 &twl4030_dapm_analogrmic_controls[0],
1350 TWL4030_REG_AVADC_CTL, 3, 0, NULL, 0),
1352 TWL4030_REG_AVADC_CTL, 1, 0, NULL, 0),
1355 TWL4030_REG_ADCMICSEL, 1, 0, NULL, 0,
1358 TWL4030_REG_ADCMICSEL, 3, 0, NULL, 0,
1361 SND_SOC_DAPM_SUPPLY("micbias1 select", TWL4030_REG_MICBIAS_CTL, 5, 0,
1362 NULL, 0),
1363 SND_SOC_DAPM_SUPPLY("micbias2 select", TWL4030_REG_MICBIAS_CTL, 6, 0,
1364 NULL, 0),
1368 TWL4030_REG_MICBIAS_CTL, 0, 0, NULL, 0),
1370 TWL4030_REG_MICBIAS_CTL, 1, 0, NULL, 0),
1372 TWL4030_REG_MICBIAS_CTL, 2, 0, NULL, 0),
1374 SND_SOC_DAPM_SUPPLY("VIF Enable", TWL4030_REG_VOICE_IF, 0, 0, NULL, 0),
1378 /* Stream -> DAC mapping */
1385 /* ADC -> Stream mapping */
1522 /* TX1 Left capture path */
1523 {"TX1 Capture Route", "Analog", "ADC Physical Left"},
1524 {"TX1 Capture Route", "Digimic0", "Digimic0 Enable"},
1525 /* TX1 Right capture path */
1526 {"TX1 Capture Route", "Analog", "ADC Physical Right"},
1527 {"TX1 Capture Route", "Digimic0", "Digimic0 Enable"},
1535 {"ADC Virtual Left1", NULL, "TX1 Capture Route"},
1536 {"ADC Virtual Right1", NULL, "TX1 Capture Route"},
1566 {"Right Digital Loopback", "Volume", "TX1 Capture Route"},
1567 {"Left Digital Loopback", "Volume", "TX1 Capture Route"},
1589 twl4030_codec_enable(component, 0); in twl4030_set_bias_level()
1593 return 0; in twl4030_set_bias_level()
1602 if (mst_substream == twl4030->master_substream) in twl4030_constraints()
1603 slv_substream = twl4030->slave_substream; in twl4030_constraints()
1604 else if (mst_substream == twl4030->slave_substream) in twl4030_constraints()
1605 slv_substream = twl4030->master_substream; in twl4030_constraints()
1610 snd_pcm_hw_constraint_single(slv_substream->runtime, in twl4030_constraints()
1612 twl4030->rate); in twl4030_constraints()
1614 snd_pcm_hw_constraint_single(slv_substream->runtime, in twl4030_constraints()
1616 twl4030->sample_bits); in twl4030_constraints()
1618 snd_pcm_hw_constraint_single(slv_substream->runtime, in twl4030_constraints()
1620 twl4030->channels); in twl4030_constraints()
1648 struct snd_soc_component *component = dai->component; in twl4030_startup()
1651 if (twl4030->master_substream) { in twl4030_startup()
1652 twl4030->slave_substream = substream; in twl4030_startup()
1656 if (twl4030->configured) in twl4030_startup()
1657 twl4030_constraints(twl4030, twl4030->master_substream); in twl4030_startup()
1664 snd_pcm_hw_constraint_single(substream->runtime, in twl4030_startup()
1668 twl4030->master_substream = substream; in twl4030_startup()
1671 return 0; in twl4030_startup()
1677 struct snd_soc_component *component = dai->component; in twl4030_shutdown()
1680 if (twl4030->master_substream == substream) in twl4030_shutdown()
1681 twl4030->master_substream = twl4030->slave_substream; in twl4030_shutdown()
1683 twl4030->slave_substream = NULL; in twl4030_shutdown()
1687 if (!twl4030->master_substream) in twl4030_shutdown()
1688 twl4030->configured = 0; in twl4030_shutdown()
1689 else if (!twl4030->master_substream->runtime->channels) in twl4030_shutdown()
1690 twl4030->configured = 0; in twl4030_shutdown()
1693 if (substream->runtime->channels == 4) in twl4030_shutdown()
1694 twl4030_tdm_enable(component, substream->stream, 0); in twl4030_shutdown()
1701 struct snd_soc_component *component = dai->component; in twl4030_hw_params()
1714 twl4030_tdm_enable(component, substream->stream, 1); in twl4030_hw_params()
1716 return -EINVAL; in twl4030_hw_params()
1719 if (twl4030->configured) in twl4030_hw_params()
1721 return 0; in twl4030_hw_params()
1760 dev_err(component->dev, "%s: unknown rate %d\n", __func__, in twl4030_hw_params()
1762 return -EINVAL; in twl4030_hw_params()
1777 dev_err(component->dev, "%s: unsupported bits/sample %d\n", in twl4030_hw_params()
1779 return -EINVAL; in twl4030_hw_params()
1783 if (twl4030->codec_powered) { in twl4030_hw_params()
1788 twl4030_codec_enable(component, 0); in twl4030_hw_params()
1800 twl4030->configured = 1; in twl4030_hw_params()
1801 twl4030->rate = params_rate(params); in twl4030_hw_params()
1802 twl4030->sample_bits = hw_param_interval(params, in twl4030_hw_params()
1803 SNDRV_PCM_HW_PARAM_SAMPLE_BITS)->min; in twl4030_hw_params()
1804 twl4030->channels = params_channels(params); in twl4030_hw_params()
1809 if (twl4030->slave_substream) in twl4030_hw_params()
1812 return 0; in twl4030_hw_params()
1818 struct snd_soc_component *component = codec_dai->component; in twl4030_set_dai_sysclk()
1827 dev_err(component->dev, "Unsupported HFCLKIN: %u\n", freq); in twl4030_set_dai_sysclk()
1828 return -EINVAL; in twl4030_set_dai_sysclk()
1831 if ((freq / 1000) != twl4030->sysclk) { in twl4030_set_dai_sysclk()
1832 dev_err(component->dev, in twl4030_set_dai_sysclk()
1834 freq, twl4030->sysclk * 1000); in twl4030_set_dai_sysclk()
1835 return -EINVAL; in twl4030_set_dai_sysclk()
1838 return 0; in twl4030_set_dai_sysclk()
1843 struct snd_soc_component *component = codec_dai->component; in twl4030_set_dai_fmt()
1861 return -EINVAL; in twl4030_set_dai_fmt()
1874 return -EINVAL; in twl4030_set_dai_fmt()
1878 if (twl4030->codec_powered) { in twl4030_set_dai_fmt()
1883 twl4030_codec_enable(component, 0); in twl4030_set_dai_fmt()
1891 return 0; in twl4030_set_dai_fmt()
1896 struct snd_soc_component *component = dai->component; in twl4030_set_tristate()
1932 struct snd_soc_component *component = dai->component; in twl4030_voice_startup()
1939 if (twl4030->sysclk != 26000) { in twl4030_voice_startup()
1940 dev_err(component->dev, in twl4030_voice_startup()
1942 __func__, twl4030->sysclk); in twl4030_voice_startup()
1943 return -EINVAL; in twl4030_voice_startup()
1953 dev_err(component->dev, "%s: the codec mode is not option2\n", in twl4030_voice_startup()
1955 return -EINVAL; in twl4030_voice_startup()
1958 return 0; in twl4030_voice_startup()
1964 struct snd_soc_component *component = dai->component; in twl4030_voice_shutdown()
1967 twl4030_voice_enable(component, substream->stream, 0); in twl4030_voice_shutdown()
1974 struct snd_soc_component *component = dai->component; in twl4030_voice_hw_params()
1979 twl4030_voice_enable(component, substream->stream, 1); in twl4030_voice_hw_params()
1994 dev_err(component->dev, "%s: unknown rate %d\n", __func__, in twl4030_voice_hw_params()
1996 return -EINVAL; in twl4030_voice_hw_params()
2000 if (twl4030->codec_powered) { in twl4030_voice_hw_params()
2005 twl4030_codec_enable(component, 0); in twl4030_voice_hw_params()
2013 return 0; in twl4030_voice_hw_params()
2019 struct snd_soc_component *component = codec_dai->component; in twl4030_voice_set_dai_sysclk()
2023 dev_err(component->dev, in twl4030_voice_set_dai_sysclk()
2026 return -EINVAL; in twl4030_voice_set_dai_sysclk()
2028 if ((freq / 1000) != twl4030->sysclk) { in twl4030_voice_set_dai_sysclk()
2029 dev_err(component->dev, in twl4030_voice_set_dai_sysclk()
2031 freq, twl4030->sysclk * 1000); in twl4030_voice_set_dai_sysclk()
2032 return -EINVAL; in twl4030_voice_set_dai_sysclk()
2034 return 0; in twl4030_voice_set_dai_sysclk()
2040 struct snd_soc_component *component = codec_dai->component; in twl4030_voice_set_dai_fmt()
2056 return -EINVAL; in twl4030_voice_set_dai_fmt()
2068 return -EINVAL; in twl4030_voice_set_dai_fmt()
2072 if (twl4030->codec_powered) { in twl4030_voice_set_dai_fmt()
2077 twl4030_codec_enable(component, 0); in twl4030_voice_set_dai_fmt()
2085 return 0; in twl4030_voice_set_dai_fmt()
2090 struct snd_soc_component *component = dai->component; in twl4030_voice_set_tristate()
2124 .name = "twl4030-hifi",
2142 .name = "twl4030-voice",
2163 twl4030 = devm_kzalloc(component->dev, sizeof(struct twl4030_priv), in twl4030_soc_probe()
2166 return -ENOMEM; in twl4030_soc_probe()
2169 twl4030->sysclk = twl4030_audio_get_mclk() / 1000; in twl4030_soc_probe()
2173 return 0; in twl4030_soc_probe()
2179 struct twl4030_board_params *board_params = twl4030->board_params; in twl4030_soc_remove()
2181 if (board_params && board_params->hs_extmute && in twl4030_soc_remove()
2182 gpio_is_valid(board_params->hs_extmute_gpio)) in twl4030_soc_remove()
2183 gpio_free(board_params->hs_extmute_gpio); in twl4030_soc_remove()
2204 return devm_snd_soc_register_component(&pdev->dev, in twl4030_codec_probe()
2209 MODULE_ALIAS("platform:twl4030-codec");
2214 .name = "twl4030-codec",