Lines Matching +full:hs +full:- +full:bias +full:- +full:ramp +full:- +full:rate
1 // SPDX-License-Identifier: GPL-2.0-only
28 #include <linux/mfd/twl4030-audio.h>
56 unsigned int rate; member
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()
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()
188 if (enable == twl4030->codec_powered) 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()
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()
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()
286 /* anti-pop when changing analog gain */ 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()
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()
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) */
532 /* Digital bypass right (TX1R -> RX2R) */
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)*/
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; \
584 static void handsfree_ramp(struct snd_soc_component *component, int reg, int ramp) in handsfree_ramp() argument
590 if (ramp) { in handsfree_ramp()
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()
633 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in handsfreerpga_event()
649 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in vibramux_event()
658 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in apll_event()
674 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in aif_event()
697 static void headset_ramp(struct snd_soc_component *component, int ramp) in headset_ramp() argument
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()
710 twl4030->sysclk) + 1; in headset_ramp()
713 * the pop-noise */ in headset_ramp()
714 if (board_params && board_params->hs_extmute) { in headset_ramp()
715 if (gpio_is_valid(board_params->hs_extmute_gpio)) { in headset_ramp()
716 gpio_set_value(board_params->hs_extmute_gpio, 1); in headset_ramp()
723 if (ramp) { in headset_ramp()
724 /* Headset ramp-up according to the TRM */ in headset_ramp()
732 /* Wait ramp delay time + 1, so the VMID can settle */ in headset_ramp()
735 /* Headset ramp-down _not_ according to in headset_ramp()
739 /* Wait ramp delay time + 1, so the VMID can settle */ in headset_ramp()
750 if (board_params && board_params->hs_extmute) { in headset_ramp()
751 if (gpio_is_valid(board_params->hs_extmute_gpio)) { in headset_ramp()
752 gpio_set_value(board_params->hs_extmute_gpio, 0); in headset_ramp()
763 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in headsetlpga_event()
768 /* Do the ramp-up only once */ in headsetlpga_event()
769 if (!twl4030->hsr_enabled) in headsetlpga_event()
772 twl4030->hsl_enabled = 1; in headsetlpga_event()
775 /* Do the ramp-down only if both headsetL/R is disabled */ in headsetlpga_event()
776 if (!twl4030->hsr_enabled) in headsetlpga_event()
779 twl4030->hsl_enabled = 0; in headsetlpga_event()
788 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in headsetrpga_event()
793 /* Do the ramp-up only once */ in headsetrpga_event()
794 if (!twl4030->hsl_enabled) in headsetrpga_event()
797 twl4030->hsr_enabled = 1; in headsetrpga_event()
800 /* Do the ramp-down only if both headsetL/R is disabled */ in headsetrpga_event()
801 if (!twl4030->hsl_enabled) in headsetrpga_event()
804 twl4030->hsr_enabled = 0; in headsetrpga_event()
813 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in digimic_event()
815 struct twl4030_board_params *board_params = twl4030->board_params; in digimic_event()
817 if (board_params && board_params->digimic_delay) in digimic_event()
818 twl4030_wait_ms(board_params->digimic_delay); in digimic_event()
828 * 0x3 : -6 dB
836 (struct soc_mixer_control *)kcontrol->private_value; in snd_soc_get_volsw_twl4030()
838 unsigned int reg = mc->reg; in snd_soc_get_volsw_twl4030()
839 unsigned int shift = mc->shift; in snd_soc_get_volsw_twl4030()
840 unsigned int rshift = mc->rshift; in snd_soc_get_volsw_twl4030()
841 int max = mc->max; in snd_soc_get_volsw_twl4030()
842 int mask = (1 << fls(max)) - 1; in snd_soc_get_volsw_twl4030()
844 ucontrol->value.integer.value[0] = in snd_soc_get_volsw_twl4030()
846 if (ucontrol->value.integer.value[0]) in snd_soc_get_volsw_twl4030()
847 ucontrol->value.integer.value[0] = in snd_soc_get_volsw_twl4030()
848 max + 1 - ucontrol->value.integer.value[0]; in snd_soc_get_volsw_twl4030()
851 ucontrol->value.integer.value[1] = in snd_soc_get_volsw_twl4030()
853 if (ucontrol->value.integer.value[1]) in snd_soc_get_volsw_twl4030()
854 ucontrol->value.integer.value[1] = in snd_soc_get_volsw_twl4030()
855 max + 1 - ucontrol->value.integer.value[1]; in snd_soc_get_volsw_twl4030()
865 (struct soc_mixer_control *)kcontrol->private_value; in snd_soc_put_volsw_twl4030()
867 unsigned int reg = mc->reg; in snd_soc_put_volsw_twl4030()
868 unsigned int shift = mc->shift; in snd_soc_put_volsw_twl4030()
869 unsigned int rshift = mc->rshift; in snd_soc_put_volsw_twl4030()
870 int max = mc->max; in snd_soc_put_volsw_twl4030()
871 int mask = (1 << fls(max)) - 1; in snd_soc_put_volsw_twl4030()
874 val = (ucontrol->value.integer.value[0] & mask); in snd_soc_put_volsw_twl4030()
878 val = max + 1 - val; in snd_soc_put_volsw_twl4030()
881 val2 = (ucontrol->value.integer.value[1] & mask); in snd_soc_put_volsw_twl4030()
884 val2 = max + 1 - val2; in snd_soc_put_volsw_twl4030()
894 (struct soc_mixer_control *)kcontrol->private_value; in snd_soc_get_volsw_r2_twl4030()
896 unsigned int reg = mc->reg; in snd_soc_get_volsw_r2_twl4030()
897 unsigned int reg2 = mc->rreg; in snd_soc_get_volsw_r2_twl4030()
898 unsigned int shift = mc->shift; in snd_soc_get_volsw_r2_twl4030()
899 int max = mc->max; in snd_soc_get_volsw_r2_twl4030()
900 int mask = (1<<fls(max))-1; in snd_soc_get_volsw_r2_twl4030()
902 ucontrol->value.integer.value[0] = in snd_soc_get_volsw_r2_twl4030()
904 ucontrol->value.integer.value[1] = in snd_soc_get_volsw_r2_twl4030()
907 if (ucontrol->value.integer.value[0]) in snd_soc_get_volsw_r2_twl4030()
908 ucontrol->value.integer.value[0] = in snd_soc_get_volsw_r2_twl4030()
909 max + 1 - ucontrol->value.integer.value[0]; in snd_soc_get_volsw_r2_twl4030()
910 if (ucontrol->value.integer.value[1]) in snd_soc_get_volsw_r2_twl4030()
911 ucontrol->value.integer.value[1] = in snd_soc_get_volsw_r2_twl4030()
912 max + 1 - ucontrol->value.integer.value[1]; in snd_soc_get_volsw_r2_twl4030()
921 (struct soc_mixer_control *)kcontrol->private_value; in snd_soc_put_volsw_r2_twl4030()
923 unsigned int reg = mc->reg; in snd_soc_put_volsw_r2_twl4030()
924 unsigned int reg2 = mc->rreg; in snd_soc_put_volsw_r2_twl4030()
925 unsigned int shift = mc->shift; in snd_soc_put_volsw_r2_twl4030()
926 int max = mc->max; in snd_soc_put_volsw_r2_twl4030()
927 int mask = (1 << fls(max)) - 1; in snd_soc_put_volsw_r2_twl4030()
932 val = (ucontrol->value.integer.value[0] & mask); in snd_soc_put_volsw_r2_twl4030()
933 val2 = (ucontrol->value.integer.value[1] & mask); in snd_soc_put_volsw_r2_twl4030()
936 val = max + 1 - val; in snd_soc_put_volsw_r2_twl4030()
938 val2 = max + 1 - val2; in snd_soc_put_volsw_r2_twl4030()
966 if (twl4030->configured) { in snd_soc_put_twl4030_opmode_enum_double()
967 dev_err(component->dev, in snd_soc_put_twl4030_opmode_enum_double()
968 "operation mode cannot be changed on-the-fly\n"); in snd_soc_put_twl4030_opmode_enum_double()
969 return -EBUSY; in snd_soc_put_twl4030_opmode_enum_double()
977 * from -62 to 0 dB in 1 dB steps (mute instead of -63 dB)
979 static DECLARE_TLV_DB_SCALE(digital_fine_tlv, -6300, 100, 1);
990 * from -37 to 12 dB in 1 dB steps (mute instead of -37 dB)
992 static DECLARE_TLV_DB_SCALE(digital_voice_downlink_tlv, -3700, 100, 1);
996 * -24 dB to 12 dB in 2 dB steps
998 static DECLARE_TLV_DB_SCALE(analog_tlv, -2400, 200, 0);
1002 * -6 dB to 6 dB in 6 dB steps (mute instead of -12)
1004 static DECLARE_TLV_DB_SCALE(output_tvl, -1200, 600, 1);
1008 * 0 dB to 12 dB in 6 dB steps (mute instead of -6)
1010 static DECLARE_TLV_DB_SCALE(output_ear_tvl, -600, 600, 1);
1043 /* Vibra H-bridge direction mode */
1045 "Vibra H-bridge direction", "Audio data MSB",
1052 /* Vibra H-bridge direction */
1146 SOC_ENUM("HS ramp delay", twl4030_rampdelay_enum),
1148 SOC_ENUM("Vibra H-bridge mode", twl4030_vibradirmode_enum),
1149 SOC_ENUM("Vibra H-bridge direction", twl4030_vibradir_enum),
1364 /* Microphone bias */
1365 SND_SOC_DAPM_SUPPLY("Mic Bias 1",
1367 SND_SOC_DAPM_SUPPLY("Mic Bias 2",
1369 SND_SOC_DAPM_SUPPLY("Headset Mic Bias",
1376 /* Stream -> DAC mapping */
1383 /* ADC -> Stream mapping */
1600 if (mst_substream == twl4030->master_substream) in twl4030_constraints()
1601 slv_substream = twl4030->slave_substream; in twl4030_constraints()
1602 else if (mst_substream == twl4030->slave_substream) in twl4030_constraints()
1603 slv_substream = twl4030->master_substream; in twl4030_constraints()
1608 snd_pcm_hw_constraint_single(slv_substream->runtime, in twl4030_constraints()
1610 twl4030->rate); in twl4030_constraints()
1612 snd_pcm_hw_constraint_single(slv_substream->runtime, in twl4030_constraints()
1614 twl4030->sample_bits); in twl4030_constraints()
1616 snd_pcm_hw_constraint_single(slv_substream->runtime, in twl4030_constraints()
1618 twl4030->channels); in twl4030_constraints()
1646 struct snd_soc_component *component = dai->component; in twl4030_startup()
1649 if (twl4030->master_substream) { in twl4030_startup()
1650 twl4030->slave_substream = substream; in twl4030_startup()
1654 if (twl4030->configured) in twl4030_startup()
1655 twl4030_constraints(twl4030, twl4030->master_substream); in twl4030_startup()
1662 snd_pcm_hw_constraint_single(substream->runtime, in twl4030_startup()
1666 twl4030->master_substream = substream; in twl4030_startup()
1675 struct snd_soc_component *component = dai->component; in twl4030_shutdown()
1678 if (twl4030->master_substream == substream) in twl4030_shutdown()
1679 twl4030->master_substream = twl4030->slave_substream; in twl4030_shutdown()
1681 twl4030->slave_substream = NULL; in twl4030_shutdown()
1685 if (!twl4030->master_substream) in twl4030_shutdown()
1686 twl4030->configured = 0; in twl4030_shutdown()
1687 else if (!twl4030->master_substream->runtime->channels) in twl4030_shutdown()
1688 twl4030->configured = 0; in twl4030_shutdown()
1691 if (substream->runtime->channels == 4) in twl4030_shutdown()
1692 twl4030_tdm_enable(component, substream->stream, 0); in twl4030_shutdown()
1699 struct snd_soc_component *component = dai->component; in twl4030_hw_params()
1712 twl4030_tdm_enable(component, substream->stream, 1); in twl4030_hw_params()
1714 return -EINVAL; in twl4030_hw_params()
1717 if (twl4030->configured) in twl4030_hw_params()
1721 /* bit rate */ in twl4030_hw_params()
1758 dev_err(component->dev, "%s: unknown rate %d\n", __func__, in twl4030_hw_params()
1760 return -EINVAL; in twl4030_hw_params()
1775 dev_err(component->dev, "%s: unsupported bits/sample %d\n", in twl4030_hw_params()
1777 return -EINVAL; in twl4030_hw_params()
1781 if (twl4030->codec_powered) { in twl4030_hw_params()
1798 twl4030->configured = 1; in twl4030_hw_params()
1799 twl4030->rate = params_rate(params); in twl4030_hw_params()
1800 twl4030->sample_bits = hw_param_interval(params, in twl4030_hw_params()
1801 SNDRV_PCM_HW_PARAM_SAMPLE_BITS)->min; in twl4030_hw_params()
1802 twl4030->channels = params_channels(params); in twl4030_hw_params()
1807 if (twl4030->slave_substream) in twl4030_hw_params()
1816 struct snd_soc_component *component = codec_dai->component; in twl4030_set_dai_sysclk()
1825 dev_err(component->dev, "Unsupported HFCLKIN: %u\n", freq); in twl4030_set_dai_sysclk()
1826 return -EINVAL; in twl4030_set_dai_sysclk()
1829 if ((freq / 1000) != twl4030->sysclk) { in twl4030_set_dai_sysclk()
1830 dev_err(component->dev, in twl4030_set_dai_sysclk()
1832 freq, twl4030->sysclk * 1000); in twl4030_set_dai_sysclk()
1833 return -EINVAL; in twl4030_set_dai_sysclk()
1841 struct snd_soc_component *component = codec_dai->component; in twl4030_set_dai_fmt()
1859 return -EINVAL; in twl4030_set_dai_fmt()
1872 return -EINVAL; in twl4030_set_dai_fmt()
1876 if (twl4030->codec_powered) { in twl4030_set_dai_fmt()
1894 struct snd_soc_component *component = dai->component; in twl4030_set_tristate()
1930 struct snd_soc_component *component = dai->component; in twl4030_voice_startup()
1937 if (twl4030->sysclk != 26000) { in twl4030_voice_startup()
1938 dev_err(component->dev, in twl4030_voice_startup()
1940 __func__, twl4030->sysclk); in twl4030_voice_startup()
1941 return -EINVAL; in twl4030_voice_startup()
1951 dev_err(component->dev, "%s: the codec mode is not option2\n", in twl4030_voice_startup()
1953 return -EINVAL; in twl4030_voice_startup()
1962 struct snd_soc_component *component = dai->component; in twl4030_voice_shutdown()
1965 twl4030_voice_enable(component, substream->stream, 0); in twl4030_voice_shutdown()
1972 struct snd_soc_component *component = dai->component; in twl4030_voice_hw_params()
1977 twl4030_voice_enable(component, substream->stream, 1); in twl4030_voice_hw_params()
1979 /* bit rate */ in twl4030_voice_hw_params()
1992 dev_err(component->dev, "%s: unknown rate %d\n", __func__, in twl4030_voice_hw_params()
1994 return -EINVAL; in twl4030_voice_hw_params()
1998 if (twl4030->codec_powered) { in twl4030_voice_hw_params()
2017 struct snd_soc_component *component = codec_dai->component; in twl4030_voice_set_dai_sysclk()
2021 dev_err(component->dev, in twl4030_voice_set_dai_sysclk()
2024 return -EINVAL; in twl4030_voice_set_dai_sysclk()
2026 if ((freq / 1000) != twl4030->sysclk) { in twl4030_voice_set_dai_sysclk()
2027 dev_err(component->dev, in twl4030_voice_set_dai_sysclk()
2029 freq, twl4030->sysclk * 1000); in twl4030_voice_set_dai_sysclk()
2030 return -EINVAL; in twl4030_voice_set_dai_sysclk()
2038 struct snd_soc_component *component = codec_dai->component; in twl4030_voice_set_dai_fmt()
2054 return -EINVAL; in twl4030_voice_set_dai_fmt()
2066 return -EINVAL; in twl4030_voice_set_dai_fmt()
2070 if (twl4030->codec_powered) { in twl4030_voice_set_dai_fmt()
2088 struct snd_soc_component *component = dai->component; in twl4030_voice_set_tristate()
2122 .name = "twl4030-hifi",
2140 .name = "twl4030-voice",
2161 twl4030 = devm_kzalloc(component->dev, sizeof(struct twl4030_priv), in twl4030_soc_probe()
2164 return -ENOMEM; in twl4030_soc_probe()
2167 twl4030->sysclk = twl4030_audio_get_mclk() / 1000; in twl4030_soc_probe()
2177 struct twl4030_board_params *board_params = twl4030->board_params; in twl4030_soc_remove()
2179 if (board_params && board_params->hs_extmute && in twl4030_soc_remove()
2180 gpio_is_valid(board_params->hs_extmute_gpio)) in twl4030_soc_remove()
2181 gpio_free(board_params->hs_extmute_gpio); in twl4030_soc_remove()
2202 return devm_snd_soc_register_component(&pdev->dev, in twl4030_codec_probe()
2207 MODULE_ALIAS("platform:twl4030-codec");
2212 .name = "twl4030-codec",