Lines Matching +full:adc +full:- +full:freq

1 // SPDX-License-Identifier: GPL-2.0-only
13 #include <linux/mfd/twl4030-audio.h>
64 u8 ctl_cache[TWL4030_REG_PRECKR_CTL - TWL4030_REG_EAR_CTL + 1];
76 twl4030->ctl_cache[i - TWL4030_REG_EAR_CTL] = byte; in tw4030_init_ctl_cache()
86 return -EIO; in twl4030_read()
95 value = twl4030->ctl_cache[reg - TWL4030_REG_EAR_CTL]; in twl4030_read()
113 if (twl4030->earpiece_enabled) in twl4030_can_write_to_chip()
117 if (twl4030->predrivel_enabled) in twl4030_can_write_to_chip()
121 if (twl4030->predriver_enabled) in twl4030_can_write_to_chip()
125 if (twl4030->carkitl_enabled) in twl4030_can_write_to_chip()
129 if (twl4030->carkitr_enabled) in twl4030_can_write_to_chip()
133 if (twl4030->hsl_enabled || twl4030->hsr_enabled) in twl4030_can_write_to_chip()
158 twl4030->ctl_cache[reg - TWL4030_REG_EAR_CTL] = value; in twl4030_write()
185 if (enable == twl4030->codec_powered) in twl4030_codec_enable()
194 twl4030->codec_powered = enable; in twl4030_codec_enable()
207 of_property_read_u32(node, "ti,digimic_delay", &board_params->digimic_delay); in twl4030_get_board_param_values()
208 of_property_read_u32(node, "ti,ramp_delay_value", &board_params->ramp_delay_value); in twl4030_get_board_param_values()
209 of_property_read_u32(node, "ti,offset_cncl_path", &board_params->offset_cncl_path); in twl4030_get_board_param_values()
211 board_params->hs_extmute = value; in twl4030_get_board_param_values()
214 board_params->hs_extmute = 1; in twl4030_get_board_param_values()
223 twl4030_codec_node = of_get_child_by_name(component->dev->parent->of_node, in twl4030_get_board_params()
227 board_params = devm_kzalloc(component->dev, in twl4030_get_board_params()
250 if (board_params && board_params->hs_extmute) { in twl4030_init_chip()
251 board_params->hs_extmute_gpio = devm_gpiod_get_optional(component->dev, in twl4030_init_chip()
254 if (IS_ERR(board_params->hs_extmute_gpio)) in twl4030_init_chip()
255 return dev_err_probe(component->dev, PTR_ERR(board_params->hs_extmute_gpio), in twl4030_init_chip()
258 if (board_params->hs_extmute_gpio) { in twl4030_init_chip()
259 gpiod_set_consumer_name(board_params->hs_extmute_gpio, "hs_extmute"); in twl4030_init_chip()
263 dev_info(component->dev, "use TWL4030 GPIO6\n"); in twl4030_init_chip()
278 /* anti-pop when changing analog gain */ in twl4030_init_chip()
294 twl4030->board_params = board_params; in twl4030_init_chip()
298 reg |= (board_params->ramp_delay_value << 2); in twl4030_init_chip()
306 reg |= board_params->offset_cncl_path; in twl4030_init_chip()
336 twl4030->apll_enabled++; in twl4030_apll_enable()
337 if (twl4030->apll_enabled == 1) in twl4030_apll_enable()
341 twl4030->apll_enabled--; in twl4030_apll_enable()
342 if (!twl4030->apll_enabled) in twl4030_apll_enable()
513 /* Digital bypass gain, mute instead of -30dB */
515 0, 1, TLV_DB_SCALE_ITEM(-3000, 600, 1),
516 2, 3, TLV_DB_SCALE_ITEM(-2400, 0, 0),
517 4, 7, TLV_DB_SCALE_ITEM(-1800, 600, 0)
520 /* Digital bypass left (TX1L -> RX2L) */
526 /* Digital bypass right (TX1R -> RX2R) */
534 * from -51 to -10 dB in 1 dB steps (mute instead of -51 dB)
536 static DECLARE_TLV_DB_SCALE(twl4030_dapm_dbypassv_tlv, -5100, 100, 1);
538 /* Digital bypass voice: sidetone (VUL -> VDL)*/
556 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); \
561 twl4030->pin_name##_enabled = 1; \
565 twl4030->pin_name##_enabled = 0; \
585 /* HF ramp-up */ in handsfree_ramp()
596 /* HF ramp-down */ in handsfree_ramp()
611 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in handsfreelpga_event()
627 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in handsfreerpga_event()
643 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in vibramux_event()
652 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in apll_event()
668 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in aif_event()
695 struct twl4030_board_params *board_params = twl4030->board_params; in headset_ramp()
696 /* Base values for ramp delay calculation: 2^19 - 2^26 */ in headset_ramp()
706 twl4030->sysclk) + 1; in headset_ramp()
709 * the pop-noise */ in headset_ramp()
710 if (board_params && board_params->hs_extmute) { in headset_ramp()
711 if (board_params->hs_extmute_gpio) { in headset_ramp()
712 gpiod_set_value(board_params->hs_extmute_gpio, 1); in headset_ramp()
720 /* Headset ramp-up according to the TRM */ in headset_ramp()
731 /* Headset ramp-down _not_ according to in headset_ramp()
746 if (board_params && board_params->hs_extmute) { in headset_ramp()
747 if (board_params->hs_extmute_gpio) { in headset_ramp()
748 gpiod_set_value(board_params->hs_extmute_gpio, 0); in headset_ramp()
759 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in headsetlpga_event()
764 /* Do the ramp-up only once */ in headsetlpga_event()
765 if (!twl4030->hsr_enabled) in headsetlpga_event()
768 twl4030->hsl_enabled = 1; in headsetlpga_event()
771 /* Do the ramp-down only if both headsetL/R is disabled */ in headsetlpga_event()
772 if (!twl4030->hsr_enabled) in headsetlpga_event()
775 twl4030->hsl_enabled = 0; in headsetlpga_event()
784 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in headsetrpga_event()
789 /* Do the ramp-up only once */ in headsetrpga_event()
790 if (!twl4030->hsl_enabled) in headsetrpga_event()
793 twl4030->hsr_enabled = 1; in headsetrpga_event()
796 /* Do the ramp-down only if both headsetL/R is disabled */ in headsetrpga_event()
797 if (!twl4030->hsl_enabled) in headsetrpga_event()
800 twl4030->hsr_enabled = 0; in headsetrpga_event()
809 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in digimic_event()
811 struct twl4030_board_params *board_params = twl4030->board_params; in digimic_event()
813 if (board_params && board_params->digimic_delay) in digimic_event()
814 twl4030_wait_ms(board_params->digimic_delay); in digimic_event()
824 * 0x3 : -6 dB
832 (struct soc_mixer_control *)kcontrol->private_value; in snd_soc_get_volsw_twl4030()
834 unsigned int reg = mc->reg; in snd_soc_get_volsw_twl4030()
835 unsigned int shift = mc->shift; in snd_soc_get_volsw_twl4030()
836 unsigned int rshift = mc->rshift; in snd_soc_get_volsw_twl4030()
837 int max = mc->max; in snd_soc_get_volsw_twl4030()
838 int mask = (1 << fls(max)) - 1; in snd_soc_get_volsw_twl4030()
840 ucontrol->value.integer.value[0] = in snd_soc_get_volsw_twl4030()
842 if (ucontrol->value.integer.value[0]) in snd_soc_get_volsw_twl4030()
843 ucontrol->value.integer.value[0] = in snd_soc_get_volsw_twl4030()
844 max + 1 - ucontrol->value.integer.value[0]; in snd_soc_get_volsw_twl4030()
847 ucontrol->value.integer.value[1] = in snd_soc_get_volsw_twl4030()
849 if (ucontrol->value.integer.value[1]) in snd_soc_get_volsw_twl4030()
850 ucontrol->value.integer.value[1] = in snd_soc_get_volsw_twl4030()
851 max + 1 - ucontrol->value.integer.value[1]; in snd_soc_get_volsw_twl4030()
861 (struct soc_mixer_control *)kcontrol->private_value; in snd_soc_put_volsw_twl4030()
863 unsigned int reg = mc->reg; in snd_soc_put_volsw_twl4030()
864 unsigned int shift = mc->shift; in snd_soc_put_volsw_twl4030()
865 unsigned int rshift = mc->rshift; in snd_soc_put_volsw_twl4030()
866 int max = mc->max; in snd_soc_put_volsw_twl4030()
867 int mask = (1 << fls(max)) - 1; in snd_soc_put_volsw_twl4030()
870 val = (ucontrol->value.integer.value[0] & mask); in snd_soc_put_volsw_twl4030()
874 val = max + 1 - val; in snd_soc_put_volsw_twl4030()
877 val2 = (ucontrol->value.integer.value[1] & mask); in snd_soc_put_volsw_twl4030()
880 val2 = max + 1 - val2; in snd_soc_put_volsw_twl4030()
890 (struct soc_mixer_control *)kcontrol->private_value; in snd_soc_get_volsw_r2_twl4030()
892 unsigned int reg = mc->reg; in snd_soc_get_volsw_r2_twl4030()
893 unsigned int reg2 = mc->rreg; in snd_soc_get_volsw_r2_twl4030()
894 unsigned int shift = mc->shift; in snd_soc_get_volsw_r2_twl4030()
895 int max = mc->max; in snd_soc_get_volsw_r2_twl4030()
896 int mask = (1<<fls(max))-1; in snd_soc_get_volsw_r2_twl4030()
898 ucontrol->value.integer.value[0] = in snd_soc_get_volsw_r2_twl4030()
900 ucontrol->value.integer.value[1] = in snd_soc_get_volsw_r2_twl4030()
903 if (ucontrol->value.integer.value[0]) in snd_soc_get_volsw_r2_twl4030()
904 ucontrol->value.integer.value[0] = in snd_soc_get_volsw_r2_twl4030()
905 max + 1 - ucontrol->value.integer.value[0]; in snd_soc_get_volsw_r2_twl4030()
906 if (ucontrol->value.integer.value[1]) in snd_soc_get_volsw_r2_twl4030()
907 ucontrol->value.integer.value[1] = in snd_soc_get_volsw_r2_twl4030()
908 max + 1 - ucontrol->value.integer.value[1]; in snd_soc_get_volsw_r2_twl4030()
917 (struct soc_mixer_control *)kcontrol->private_value; in snd_soc_put_volsw_r2_twl4030()
919 unsigned int reg = mc->reg; in snd_soc_put_volsw_r2_twl4030()
920 unsigned int reg2 = mc->rreg; in snd_soc_put_volsw_r2_twl4030()
921 unsigned int shift = mc->shift; in snd_soc_put_volsw_r2_twl4030()
922 int max = mc->max; in snd_soc_put_volsw_r2_twl4030()
923 int mask = (1 << fls(max)) - 1; in snd_soc_put_volsw_r2_twl4030()
928 val = (ucontrol->value.integer.value[0] & mask); in snd_soc_put_volsw_r2_twl4030()
929 val2 = (ucontrol->value.integer.value[1] & mask); in snd_soc_put_volsw_r2_twl4030()
932 val = max + 1 - val; in snd_soc_put_volsw_r2_twl4030()
934 val2 = max + 1 - val2; in snd_soc_put_volsw_r2_twl4030()
962 if (twl4030->configured) { in snd_soc_put_twl4030_opmode_enum_double()
963 dev_err(component->dev, in snd_soc_put_twl4030_opmode_enum_double()
964 "operation mode cannot be changed on-the-fly\n"); in snd_soc_put_twl4030_opmode_enum_double()
965 return -EBUSY; in snd_soc_put_twl4030_opmode_enum_double()
973 * from -62 to 0 dB in 1 dB steps (mute instead of -63 dB)
975 static DECLARE_TLV_DB_SCALE(digital_fine_tlv, -6300, 100, 1);
986 * from -37 to 12 dB in 1 dB steps (mute instead of -37 dB)
988 static DECLARE_TLV_DB_SCALE(digital_voice_downlink_tlv, -3700, 100, 1);
992 * -24 dB to 12 dB in 2 dB steps
994 static DECLARE_TLV_DB_SCALE(analog_tlv, -2400, 200, 0);
998 * -6 dB to 6 dB in 6 dB steps (mute instead of -12)
1000 static DECLARE_TLV_DB_SCALE(output_tvl, -1200, 600, 1);
1004 * 0 dB to 12 dB in 6 dB steps (mute instead of -6)
1006 static DECLARE_TLV_DB_SCALE(output_ear_tvl, -600, 600, 1);
1039 /* Vibra H-bridge direction mode */
1041 "Vibra H-bridge direction", "Audio data MSB",
1048 /* Vibra H-bridge direction */
1144 SOC_ENUM("Vibra H-bridge mode", twl4030_vibradirmode_enum),
1145 SOC_ENUM("Vibra H-bridge direction", twl4030_vibradir_enum),
1315 /* Introducing four virtual ADC, since TWL4030 have four channel for
1317 SND_SOC_DAPM_ADC("ADC Virtual Left1", NULL, SND_SOC_NOPM, 0, 0),
1318 SND_SOC_DAPM_ADC("ADC Virtual Right1", NULL, SND_SOC_NOPM, 0, 0),
1319 SND_SOC_DAPM_ADC("ADC Virtual Left2", NULL, SND_SOC_NOPM, 0, 0),
1320 SND_SOC_DAPM_ADC("ADC Virtual Right2", NULL, SND_SOC_NOPM, 0, 0),
1343 SND_SOC_DAPM_PGA("ADC Physical Left",
1345 SND_SOC_DAPM_PGA("ADC Physical Right",
1372 /* Stream -> DAC mapping */
1379 /* ADC -> Stream mapping */
1380 {"HiFi Capture", NULL, "ADC Virtual Left1"},
1381 {"HiFi Capture", NULL, "ADC Virtual Right1"},
1382 {"HiFi Capture", NULL, "ADC Virtual Left2"},
1383 {"HiFi Capture", NULL, "ADC Virtual Right2"},
1384 {"VAIFOUT", NULL, "ADC Virtual Left2"},
1385 {"VAIFOUT", NULL, "ADC Virtual Right2"},
1494 {"ADC Virtual Left1", NULL, "Virtual HiFi IN"},
1495 {"ADC Virtual Right1", NULL, "Virtual HiFi IN"},
1496 {"ADC Virtual Left2", NULL, "Virtual HiFi IN"},
1497 {"ADC Virtual Right2", NULL, "Virtual HiFi IN"},
1507 {"ADC Physical Left", NULL, "Analog Left"},
1508 {"ADC Physical Right", NULL, "Analog Right"},
1517 {"TX1 Capture Route", "Analog", "ADC Physical Left"},
1520 {"TX1 Capture Route", "Analog", "ADC Physical Right"},
1523 {"TX2 Capture Route", "Analog", "ADC Physical Left"},
1526 {"TX2 Capture Route", "Analog", "ADC Physical Right"},
1529 {"ADC Virtual Left1", NULL, "TX1 Capture Route"},
1530 {"ADC Virtual Right1", NULL, "TX1 Capture Route"},
1531 {"ADC Virtual Left2", NULL, "TX2 Capture Route"},
1532 {"ADC Virtual Right2", NULL, "TX2 Capture Route"},
1534 {"ADC Virtual Left1", NULL, "AIF Enable"},
1535 {"ADC Virtual Right1", NULL, "AIF Enable"},
1536 {"ADC Virtual Left2", NULL, "AIF Enable"},
1537 {"ADC Virtual Right2", NULL, "AIF Enable"},
1596 if (mst_substream == twl4030->master_substream) in twl4030_constraints()
1597 slv_substream = twl4030->slave_substream; in twl4030_constraints()
1598 else if (mst_substream == twl4030->slave_substream) in twl4030_constraints()
1599 slv_substream = twl4030->master_substream; in twl4030_constraints()
1604 snd_pcm_hw_constraint_single(slv_substream->runtime, in twl4030_constraints()
1606 twl4030->rate); in twl4030_constraints()
1608 snd_pcm_hw_constraint_single(slv_substream->runtime, in twl4030_constraints()
1610 twl4030->sample_bits); in twl4030_constraints()
1612 snd_pcm_hw_constraint_single(slv_substream->runtime, in twl4030_constraints()
1614 twl4030->channels); in twl4030_constraints()
1642 struct snd_soc_component *component = dai->component; in twl4030_startup()
1645 if (twl4030->master_substream) { in twl4030_startup()
1646 twl4030->slave_substream = substream; in twl4030_startup()
1650 if (twl4030->configured) in twl4030_startup()
1651 twl4030_constraints(twl4030, twl4030->master_substream); in twl4030_startup()
1658 snd_pcm_hw_constraint_single(substream->runtime, in twl4030_startup()
1662 twl4030->master_substream = substream; in twl4030_startup()
1671 struct snd_soc_component *component = dai->component; in twl4030_shutdown()
1674 if (twl4030->master_substream == substream) in twl4030_shutdown()
1675 twl4030->master_substream = twl4030->slave_substream; in twl4030_shutdown()
1677 twl4030->slave_substream = NULL; in twl4030_shutdown()
1681 if (!twl4030->master_substream) in twl4030_shutdown()
1682 twl4030->configured = 0; in twl4030_shutdown()
1683 else if (!twl4030->master_substream->runtime->channels) in twl4030_shutdown()
1684 twl4030->configured = 0; in twl4030_shutdown()
1687 if (substream->runtime->channels == 4) in twl4030_shutdown()
1688 twl4030_tdm_enable(component, substream->stream, 0); in twl4030_shutdown()
1695 struct snd_soc_component *component = dai->component; in twl4030_hw_params()
1708 twl4030_tdm_enable(component, substream->stream, 1); in twl4030_hw_params()
1710 return -EINVAL; in twl4030_hw_params()
1713 if (twl4030->configured) in twl4030_hw_params()
1754 dev_err(component->dev, "%s: unknown rate %d\n", __func__, in twl4030_hw_params()
1756 return -EINVAL; in twl4030_hw_params()
1771 dev_err(component->dev, "%s: unsupported bits/sample %d\n", in twl4030_hw_params()
1773 return -EINVAL; in twl4030_hw_params()
1777 if (twl4030->codec_powered) { in twl4030_hw_params()
1794 twl4030->configured = 1; in twl4030_hw_params()
1795 twl4030->rate = params_rate(params); in twl4030_hw_params()
1796 twl4030->sample_bits = hw_param_interval(params, in twl4030_hw_params()
1797 SNDRV_PCM_HW_PARAM_SAMPLE_BITS)->min; in twl4030_hw_params()
1798 twl4030->channels = params_channels(params); in twl4030_hw_params()
1803 if (twl4030->slave_substream) in twl4030_hw_params()
1810 unsigned int freq, int dir) in twl4030_set_dai_sysclk() argument
1812 struct snd_soc_component *component = codec_dai->component; in twl4030_set_dai_sysclk()
1815 switch (freq) { in twl4030_set_dai_sysclk()
1821 dev_err(component->dev, "Unsupported HFCLKIN: %u\n", freq); in twl4030_set_dai_sysclk()
1822 return -EINVAL; in twl4030_set_dai_sysclk()
1825 if ((freq / 1000) != twl4030->sysclk) { in twl4030_set_dai_sysclk()
1826 dev_err(component->dev, in twl4030_set_dai_sysclk()
1828 freq, twl4030->sysclk * 1000); in twl4030_set_dai_sysclk()
1829 return -EINVAL; in twl4030_set_dai_sysclk()
1837 struct snd_soc_component *component = codec_dai->component; in twl4030_set_dai_fmt()
1855 return -EINVAL; in twl4030_set_dai_fmt()
1868 return -EINVAL; in twl4030_set_dai_fmt()
1872 if (twl4030->codec_powered) { in twl4030_set_dai_fmt()
1890 struct snd_soc_component *component = dai->component; in twl4030_set_tristate()
1926 struct snd_soc_component *component = dai->component; in twl4030_voice_startup()
1933 if (twl4030->sysclk != 26000) { in twl4030_voice_startup()
1934 dev_err(component->dev, in twl4030_voice_startup()
1936 __func__, twl4030->sysclk); in twl4030_voice_startup()
1937 return -EINVAL; in twl4030_voice_startup()
1947 dev_err(component->dev, "%s: the codec mode is not option2\n", in twl4030_voice_startup()
1949 return -EINVAL; in twl4030_voice_startup()
1958 struct snd_soc_component *component = dai->component; in twl4030_voice_shutdown()
1961 twl4030_voice_enable(component, substream->stream, 0); in twl4030_voice_shutdown()
1968 struct snd_soc_component *component = dai->component; in twl4030_voice_hw_params()
1973 twl4030_voice_enable(component, substream->stream, 1); in twl4030_voice_hw_params()
1988 dev_err(component->dev, "%s: unknown rate %d\n", __func__, in twl4030_voice_hw_params()
1990 return -EINVAL; in twl4030_voice_hw_params()
1994 if (twl4030->codec_powered) { in twl4030_voice_hw_params()
2011 int clk_id, unsigned int freq, int dir) in twl4030_voice_set_dai_sysclk() argument
2013 struct snd_soc_component *component = codec_dai->component; in twl4030_voice_set_dai_sysclk()
2016 if (freq != 26000000) { in twl4030_voice_set_dai_sysclk()
2017 dev_err(component->dev, in twl4030_voice_set_dai_sysclk()
2019 __func__, freq / 1000); in twl4030_voice_set_dai_sysclk()
2020 return -EINVAL; in twl4030_voice_set_dai_sysclk()
2022 if ((freq / 1000) != twl4030->sysclk) { in twl4030_voice_set_dai_sysclk()
2023 dev_err(component->dev, in twl4030_voice_set_dai_sysclk()
2025 freq, twl4030->sysclk * 1000); in twl4030_voice_set_dai_sysclk()
2026 return -EINVAL; in twl4030_voice_set_dai_sysclk()
2034 struct snd_soc_component *component = codec_dai->component; in twl4030_voice_set_dai_fmt()
2050 return -EINVAL; in twl4030_voice_set_dai_fmt()
2062 return -EINVAL; in twl4030_voice_set_dai_fmt()
2066 if (twl4030->codec_powered) { in twl4030_voice_set_dai_fmt()
2084 struct snd_soc_component *component = dai->component; in twl4030_voice_set_tristate()
2118 .name = "twl4030-hifi",
2136 .name = "twl4030-voice",
2157 twl4030 = devm_kzalloc(component->dev, sizeof(struct twl4030_priv), in twl4030_soc_probe()
2160 return -ENOMEM; in twl4030_soc_probe()
2163 twl4030->sysclk = twl4030_audio_get_mclk() / 1000; in twl4030_soc_probe()
2185 return devm_snd_soc_register_component(&pdev->dev, in twl4030_codec_probe()
2190 MODULE_ALIAS("platform:twl4030-codec");
2195 .name = "twl4030-codec",