Lines Matching +full:adc +full:- +full:channel +full:- +full:clk +full:- +full:src

1 // SPDX-License-Identifier: GPL-2.0-only
3 * rt5668.c -- RT5668B ALSA SoC audio component driver
26 #include <sound/soc-dapm.h>
746 static const DECLARE_TLV_DB_SCALE(hp_vol_tlv, -2250, 150, 0);
747 static const DECLARE_TLV_DB_SCALE(dac_vol_tlv, -65625, 375, 0);
748 static const DECLARE_TLV_DB_SCALE(adc_vol_tlv, -17625, 375, 0);
783 SOC_DAPM_ENUM("IF2 ADC Swap Mux", rt5668_if2_adc_enum);
786 SOC_DAPM_ENUM("IF1 01 ADC Swap Mux", rt5668_if1_01_adc_enum);
789 SOC_DAPM_ENUM("IF1 23 ADC Swap Mux", rt5668_if1_23_adc_enum);
792 SOC_DAPM_ENUM("IF1 45 ADC Swap Mux", rt5668_if1_45_adc_enum);
795 SOC_DAPM_ENUM("IF1 67 ADC Swap Mux", rt5668_if1_67_adc_enum);
803 * rt5668_sel_asrc_clk_src - select ASRC clock source for a set of filters
827 return -EINVAL; in rt5668_sel_asrc_clk_src()
887 * rt5668_headset_detect - Detect headset.
922 rt5668->jack_type = SND_JACK_HEADSET; in rt5668_headset_detect()
926 rt5668->jack_type = SND_JACK_HEADPHONE; in rt5668_headset_detect()
936 rt5668->jack_type = 0; in rt5668_headset_detect()
939 dev_dbg(component->dev, "jack_type = %d\n", rt5668->jack_type); in rt5668_headset_detect()
940 return rt5668->jack_type; in rt5668_headset_detect()
948 &rt5668->jack_detect_work, msecs_to_jiffies(250)); in rt5668_irq()
958 if (snd_soc_component_read(rt5668->component, RT5668_AJD1_CTRL) in rt5668_jd_check_handler()
961 rt5668->jack_type = rt5668_headset_detect(rt5668->component, 0); in rt5668_jd_check_handler()
963 snd_soc_jack_report(rt5668->hs_jack, rt5668->jack_type, in rt5668_jd_check_handler()
968 schedule_delayed_work(&rt5668->jd_check_work, 500); in rt5668_jd_check_handler()
977 switch (rt5668->pdata.jd_src) { in rt5668_set_jack_detect()
986 regmap_update_bits(rt5668->regmap, RT5668_GPIO_CTRL_1, in rt5668_set_jack_detect()
988 regmap_update_bits(rt5668->regmap, RT5668_RC_CLK_CTRL, in rt5668_set_jack_detect()
992 regmap_update_bits(rt5668->regmap, RT5668_PWR_ANLG_2, in rt5668_set_jack_detect()
995 regmap_update_bits(rt5668->regmap, RT5668_IRQ_CTRL_2, in rt5668_set_jack_detect()
999 &rt5668->jack_detect_work, msecs_to_jiffies(250)); in rt5668_set_jack_detect()
1003 regmap_update_bits(rt5668->regmap, RT5668_IRQ_CTRL_2, in rt5668_set_jack_detect()
1005 regmap_update_bits(rt5668->regmap, RT5668_RC_CLK_CTRL, in rt5668_set_jack_detect()
1010 dev_warn(component->dev, "Wrong JD source\n"); in rt5668_set_jack_detect()
1014 rt5668->hs_jack = hs_jack; in rt5668_set_jack_detect()
1025 if (!rt5668->component || in rt5668_jack_detect_handler()
1026 !snd_soc_card_is_instantiated(rt5668->component->card)) { in rt5668_jack_detect_handler()
1029 &rt5668->jack_detect_work, msecs_to_jiffies(15)); in rt5668_jack_detect_handler()
1033 mutex_lock(&rt5668->calibrate_mutex); in rt5668_jack_detect_handler()
1035 val = snd_soc_component_read(rt5668->component, RT5668_AJD1_CTRL) in rt5668_jack_detect_handler()
1039 if (rt5668->jack_type == 0) { in rt5668_jack_detect_handler()
1041 rt5668->jack_type = in rt5668_jack_detect_handler()
1042 rt5668_headset_detect(rt5668->component, 1); in rt5668_jack_detect_handler()
1045 rt5668->jack_type = SND_JACK_HEADSET; in rt5668_jack_detect_handler()
1046 btn_type = rt5668_button_detect(rt5668->component); in rt5668_jack_detect_handler()
1058 rt5668->jack_type |= SND_JACK_BTN_0; in rt5668_jack_detect_handler()
1063 rt5668->jack_type |= SND_JACK_BTN_1; in rt5668_jack_detect_handler()
1068 rt5668->jack_type |= SND_JACK_BTN_2; in rt5668_jack_detect_handler()
1073 rt5668->jack_type |= SND_JACK_BTN_3; in rt5668_jack_detect_handler()
1079 dev_err(rt5668->component->dev, in rt5668_jack_detect_handler()
1087 rt5668->jack_type = rt5668_headset_detect(rt5668->component, 0); in rt5668_jack_detect_handler()
1090 snd_soc_jack_report(rt5668->hs_jack, rt5668->jack_type, in rt5668_jack_detect_handler()
1095 if (rt5668->jack_type & (SND_JACK_BTN_0 | SND_JACK_BTN_1 | in rt5668_jack_detect_handler()
1097 schedule_delayed_work(&rt5668->jd_check_work, 0); in rt5668_jack_detect_handler()
1099 cancel_delayed_work_sync(&rt5668->jd_check_work); in rt5668_jack_detect_handler()
1101 mutex_unlock(&rt5668->calibrate_mutex); in rt5668_jack_detect_handler()
1117 /* ADC Digital Volume Control */
1118 SOC_DOUBLE("STO1 ADC Capture Switch", RT5668_STO1_ADC_DIG_VOL,
1120 SOC_DOUBLE_TLV("STO1 ADC Capture Volume", RT5668_STO1_ADC_DIG_VOL,
1123 /* ADC Boost Volume Control */
1124 SOC_DOUBLE_TLV("STO1 ADC Boost Gain Volume", RT5668_STO1_ADC_BOOST,
1135 if (rt5668->sysclk < target) { in rt5668_div_sel()
1137 rt5668->sysclk); in rt5668_div_sel()
1141 for (i = 0; i < size - 1; i++) { in rt5668_div_sel()
1143 if (target * div[i] == rt5668->sysclk) in rt5668_div_sel()
1145 if (target * div[i + 1] > rt5668->sysclk) { in rt5668_div_sel()
1147 rt5668->sysclk); in rt5668_div_sel()
1152 if (target * div[i] < rt5668->sysclk) in rt5668_div_sel()
1154 rt5668->sysclk); in rt5668_div_sel()
1156 return size - 1; in rt5668_div_sel()
1161 * set_dmic_clk - Set parameter of dmic.
1174 snd_soc_dapm_to_component(w->dapm); in set_dmic_clk()
1191 snd_soc_dapm_to_component(w->dapm); in set_filter_clk()
1198 if (w->shift == RT5668_PWR_ADC_S1F_BIT && in set_filter_clk()
1200 ref = 256 * rt5668->lrck[RT5668_AIF2]; in set_filter_clk()
1202 ref = 256 * rt5668->lrck[RT5668_AIF1]; in set_filter_clk()
1206 if (w->shift == RT5668_PWR_ADC_S1F_BIT) in set_filter_clk()
1222 snd_soc_dapm_to_component(w->dapm); in is_sys_clk_from_pll1()
1237 snd_soc_dapm_to_component(w->dapm); in is_using_asrc()
1239 switch (w->shift) { in is_using_asrc()
1279 SOC_DAPM_SINGLE("Stereo ADC Switch", RT5668_AD_DA_MIXER,
1286 SOC_DAPM_SINGLE("Stereo ADC Switch", RT5668_AD_DA_MIXER,
1313 /* MX-26 [13] [5] */
1315 "DAC MIX", "ADC"
1332 /* STO1 ADC Source */
1333 /* MX-26 [11:10] [3:2] */
1353 /* MX-26 [12] [4] */
1372 /* MX-79 [6:4] I2S1 ADC data location */
1389 SOC_DAPM_ENUM("IF1 ADC Slot location", rt5668_if1_adc_slot_enum);
1392 /* MX-2B [4], MX-2B [0]*/
1423 snd_soc_dapm_to_component(w->dapm); in rt5668_hp_event()
1472 snd_soc_dapm_to_component(w->dapm); in rt5655_set_verf()
1476 switch (w->shift) { in rt5655_set_verf()
1494 switch (w->shift) { in rt5655_set_verf()
1553 SND_SOC_DAPM_SUPPLY_S("ADC STO1 ASRC", 1, RT5668_PLL_TRACK_1,
1574 SND_SOC_DAPM_SUPPLY("DMIC CLK", SND_SOC_NOPM, 0, 0,
1603 /* ADC Mux */
1604 SND_SOC_DAPM_MUX("Stereo1 ADC L1 Mux", SND_SOC_NOPM, 0, 0,
1606 SND_SOC_DAPM_MUX("Stereo1 ADC R1 Mux", SND_SOC_NOPM, 0, 0,
1608 SND_SOC_DAPM_MUX("Stereo1 ADC L2 Mux", SND_SOC_NOPM, 0, 0,
1610 SND_SOC_DAPM_MUX("Stereo1 ADC R2 Mux", SND_SOC_NOPM, 0, 0,
1612 SND_SOC_DAPM_MUX("Stereo1 ADC L Mux", SND_SOC_NOPM, 0, 0,
1614 SND_SOC_DAPM_MUX("Stereo1 ADC R Mux", SND_SOC_NOPM, 0, 0,
1619 /* ADC Mixer */
1620 SND_SOC_DAPM_SUPPLY("ADC Stereo1 Filter", RT5668_PWR_DIG_2,
1623 SND_SOC_DAPM_MIXER("Stereo1 ADC MIXL", RT5668_STO1_ADC_DIG_VOL,
1626 SND_SOC_DAPM_MIXER("Stereo1 ADC MIXR", RT5668_STO1_ADC_DIG_VOL,
1630 /* ADC PGA */
1631 SND_SOC_DAPM_PGA("Stereo1 ADC MIX", SND_SOC_NOPM, 0, 0, NULL, 0),
1643 SND_SOC_DAPM_MUX("IF1 01 ADC Swap Mux", SND_SOC_NOPM, 0, 0,
1645 SND_SOC_DAPM_MUX("IF1 23 ADC Swap Mux", SND_SOC_NOPM, 0, 0,
1647 SND_SOC_DAPM_MUX("IF1 45 ADC Swap Mux", SND_SOC_NOPM, 0, 0,
1649 SND_SOC_DAPM_MUX("IF1 67 ADC Swap Mux", SND_SOC_NOPM, 0, 0,
1651 SND_SOC_DAPM_MUX("IF2 ADC Swap Mux", SND_SOC_NOPM, 0, 0,
1671 /* DAC channel Mux */
1712 /* CLK DET */
1730 {"ADC Stereo1 Filter", NULL, "PLL1", is_sys_clk_from_pll1},
1734 {"ADC Stereo1 Filter", NULL, "ADC STO1 ASRC", is_using_asrc},
1736 {"ADC STO1 ASRC", NULL, "AD ASRC"},
1760 {"DMIC L1", NULL, "DMIC CLK"},
1762 {"DMIC R1", NULL, "DMIC CLK"},
1764 {"DMIC CLK", NULL, "DMIC ASRC"},
1766 {"Stereo1 ADC L Mux", "ADC1 L", "ADC1 L"},
1767 {"Stereo1 ADC L Mux", "ADC1 R", "ADC1 R"},
1768 {"Stereo1 ADC R Mux", "ADC1 L", "ADC1 L"},
1769 {"Stereo1 ADC R Mux", "ADC1 R", "ADC1 R"},
1771 {"Stereo1 ADC L1 Mux", "ADC", "Stereo1 ADC L Mux"},
1772 {"Stereo1 ADC L1 Mux", "DAC MIX", "Stereo1 DAC MIXL"},
1773 {"Stereo1 ADC L2 Mux", "DMIC", "DMIC L1"},
1774 {"Stereo1 ADC L2 Mux", "DAC MIX", "Stereo1 DAC MIXL"},
1776 {"Stereo1 ADC R1 Mux", "ADC", "Stereo1 ADC R Mux"},
1777 {"Stereo1 ADC R1 Mux", "DAC MIX", "Stereo1 DAC MIXR"},
1778 {"Stereo1 ADC R2 Mux", "DMIC", "DMIC R1"},
1779 {"Stereo1 ADC R2 Mux", "DAC MIX", "Stereo1 DAC MIXR"},
1781 {"Stereo1 ADC MIXL", "ADC1 Switch", "Stereo1 ADC L1 Mux"},
1782 {"Stereo1 ADC MIXL", "ADC2 Switch", "Stereo1 ADC L2 Mux"},
1783 {"Stereo1 ADC MIXL", NULL, "ADC Stereo1 Filter"},
1785 {"Stereo1 ADC MIXR", "ADC1 Switch", "Stereo1 ADC R1 Mux"},
1786 {"Stereo1 ADC MIXR", "ADC2 Switch", "Stereo1 ADC R2 Mux"},
1787 {"Stereo1 ADC MIXR", NULL, "ADC Stereo1 Filter"},
1789 {"Stereo1 ADC MIX", NULL, "Stereo1 ADC MIXL"},
1790 {"Stereo1 ADC MIX", NULL, "Stereo1 ADC MIXR"},
1792 {"IF1 01 ADC Swap Mux", "L/R", "Stereo1 ADC MIX"},
1793 {"IF1 01 ADC Swap Mux", "L/L", "Stereo1 ADC MIX"},
1794 {"IF1 01 ADC Swap Mux", "R/L", "Stereo1 ADC MIX"},
1795 {"IF1 01 ADC Swap Mux", "R/R", "Stereo1 ADC MIX"},
1796 {"IF1 23 ADC Swap Mux", "L/R", "Stereo1 ADC MIX"},
1797 {"IF1 23 ADC Swap Mux", "R/L", "Stereo1 ADC MIX"},
1798 {"IF1 23 ADC Swap Mux", "L/L", "Stereo1 ADC MIX"},
1799 {"IF1 23 ADC Swap Mux", "R/R", "Stereo1 ADC MIX"},
1800 {"IF1 45 ADC Swap Mux", "L/R", "Stereo1 ADC MIX"},
1801 {"IF1 45 ADC Swap Mux", "R/L", "Stereo1 ADC MIX"},
1802 {"IF1 45 ADC Swap Mux", "L/L", "Stereo1 ADC MIX"},
1803 {"IF1 45 ADC Swap Mux", "R/R", "Stereo1 ADC MIX"},
1804 {"IF1 67 ADC Swap Mux", "L/R", "Stereo1 ADC MIX"},
1805 {"IF1 67 ADC Swap Mux", "R/L", "Stereo1 ADC MIX"},
1806 {"IF1 67 ADC Swap Mux", "L/L", "Stereo1 ADC MIX"},
1807 {"IF1 67 ADC Swap Mux", "R/R", "Stereo1 ADC MIX"},
1809 {"IF1_ADC Mux", "Slot 0", "IF1 01 ADC Swap Mux"},
1810 {"IF1_ADC Mux", "Slot 2", "IF1 23 ADC Swap Mux"},
1811 {"IF1_ADC Mux", "Slot 4", "IF1 45 ADC Swap Mux"},
1812 {"IF1_ADC Mux", "Slot 6", "IF1 67 ADC Swap Mux"},
1816 {"IF2 ADC Swap Mux", "L/R", "Stereo1 ADC MIX"},
1817 {"IF2 ADC Swap Mux", "R/L", "Stereo1 ADC MIX"},
1818 {"IF2 ADC Swap Mux", "L/L", "Stereo1 ADC MIX"},
1819 {"IF2 ADC Swap Mux", "R/R", "Stereo1 ADC MIX"},
1820 {"ADCDAT Mux", "ADCDAT2", "IF2 ADC Swap Mux"},
1830 {"DAC1 MIXL", "Stereo ADC Switch", "Stereo1 ADC MIXL"},
1832 {"DAC1 MIXR", "Stereo ADC Switch", "Stereo1 ADC MIXR"},
1870 struct snd_soc_component *component = dai->component; in rt5668_set_tdm_slot()
1889 return -EINVAL; in rt5668_set_tdm_slot()
1909 return -EINVAL; in rt5668_set_tdm_slot()
1922 struct snd_soc_component *component = dai->component; in rt5668_hw_params()
1927 rt5668->lrck[dai->id] = params_rate(params); in rt5668_hw_params()
1928 pre_div = rl6231_get_clk_info(rt5668->sysclk, rt5668->lrck[dai->id]); in rt5668_hw_params()
1932 dev_err(component->dev, "Unsupported frame size: %d\n", in rt5668_hw_params()
1934 return -EINVAL; in rt5668_hw_params()
1937 dev_dbg(dai->dev, "lrck is %dHz and pre_div is %d for iis %d\n", in rt5668_hw_params()
1938 rt5668->lrck[dai->id], pre_div, dai->id); in rt5668_hw_params()
1960 return -EINVAL; in rt5668_hw_params()
1963 switch (dai->id) { in rt5668_hw_params()
1967 if (rt5668->master[RT5668_AIF1]) { in rt5668_hw_params()
1984 if (rt5668->master[RT5668_AIF2]) { in rt5668_hw_params()
1999 dev_err(component->dev, "Invalid dai->id: %d\n", dai->id); in rt5668_hw_params()
2000 return -EINVAL; in rt5668_hw_params()
2008 struct snd_soc_component *component = dai->component; in rt5668_set_dai_fmt()
2014 rt5668->master[dai->id] = 1; in rt5668_set_dai_fmt()
2017 rt5668->master[dai->id] = 0; in rt5668_set_dai_fmt()
2020 return -EINVAL; in rt5668_set_dai_fmt()
2031 if (dai->id == RT5668_AIF1) in rt5668_set_dai_fmt()
2034 return -EINVAL; in rt5668_set_dai_fmt()
2037 if (dai->id == RT5668_AIF1) in rt5668_set_dai_fmt()
2041 return -EINVAL; in rt5668_set_dai_fmt()
2044 return -EINVAL; in rt5668_set_dai_fmt()
2063 return -EINVAL; in rt5668_set_dai_fmt()
2066 switch (dai->id) { in rt5668_set_dai_fmt()
2074 tdm_ctrl | rt5668->master[dai->id]); in rt5668_set_dai_fmt()
2077 if (rt5668->master[dai->id] == 0) in rt5668_set_dai_fmt()
2084 dev_err(component->dev, "Invalid dai->id: %d\n", dai->id); in rt5668_set_dai_fmt()
2085 return -EINVAL; in rt5668_set_dai_fmt()
2094 unsigned int reg_val = 0, src = 0; in rt5668_set_component_sysclk() local
2096 if (freq == rt5668->sysclk && clk_id == rt5668->sysclk_src) in rt5668_set_component_sysclk()
2102 src = RT5668_CLK_SRC_MCLK; in rt5668_set_component_sysclk()
2106 src = RT5668_CLK_SRC_PLL1; in rt5668_set_component_sysclk()
2110 src = RT5668_CLK_SRC_PLL2; in rt5668_set_component_sysclk()
2114 src = RT5668_CLK_SRC_RCCLK; in rt5668_set_component_sysclk()
2117 dev_err(component->dev, "Invalid clock id (%d)\n", clk_id); in rt5668_set_component_sysclk()
2118 return -EINVAL; in rt5668_set_component_sysclk()
2123 if (rt5668->master[RT5668_AIF2]) { in rt5668_set_component_sysclk()
2126 src << RT5668_I2S2_SRC_SFT); in rt5668_set_component_sysclk()
2129 rt5668->sysclk = freq; in rt5668_set_component_sysclk()
2130 rt5668->sysclk_src = clk_id; in rt5668_set_component_sysclk()
2132 dev_dbg(component->dev, "Sysclk is %dHz and clock id is %d\n", in rt5668_set_component_sysclk()
2146 if (source == rt5668->pll_src && freq_in == rt5668->pll_in && in rt5668_set_component_pll()
2147 freq_out == rt5668->pll_out) in rt5668_set_component_pll()
2151 dev_dbg(component->dev, "PLL disabled\n"); in rt5668_set_component_pll()
2153 rt5668->pll_in = 0; in rt5668_set_component_pll()
2154 rt5668->pll_out = 0; in rt5668_set_component_pll()
2170 dev_err(component->dev, "Unknown PLL Source %d\n", source); in rt5668_set_component_pll()
2171 return -EINVAL; in rt5668_set_component_pll()
2176 dev_err(component->dev, "Unsupported input clock %d\n", freq_in); in rt5668_set_component_pll()
2180 dev_dbg(component->dev, "bypass=%d m=%d n=%d k=%d\n", in rt5668_set_component_pll()
2190 rt5668->pll_in = freq_in; in rt5668_set_component_pll()
2191 rt5668->pll_out = freq_out; in rt5668_set_component_pll()
2192 rt5668->pll_src = source; in rt5668_set_component_pll()
2199 struct snd_soc_component *component = dai->component; in rt5668_set_bclk_ratio()
2202 rt5668->bclk[dai->id] = ratio; in rt5668_set_bclk_ratio()
2216 dev_err(dai->dev, "Invalid bclk ratio %d\n", ratio); in rt5668_set_bclk_ratio()
2217 return -EINVAL; in rt5668_set_bclk_ratio()
2230 regmap_update_bits(rt5668->regmap, RT5668_PWR_ANLG_1, in rt5668_set_bias_level()
2233 regmap_update_bits(rt5668->regmap, RT5668_PWR_DIG_1, in rt5668_set_bias_level()
2239 regmap_update_bits(rt5668->regmap, RT5668_PWR_ANLG_1, in rt5668_set_bias_level()
2241 regmap_update_bits(rt5668->regmap, RT5668_PWR_DIG_1, in rt5668_set_bias_level()
2245 regmap_update_bits(rt5668->regmap, RT5668_PWR_DIG_1, in rt5668_set_bias_level()
2247 regmap_update_bits(rt5668->regmap, RT5668_PWR_ANLG_1, in rt5668_set_bias_level()
2262 rt5668->component = component; in rt5668_probe()
2271 rt5668_reset(rt5668->regmap); in rt5668_remove()
2279 regcache_cache_only(rt5668->regmap, true); in rt5668_suspend()
2280 regcache_mark_dirty(rt5668->regmap); in rt5668_suspend()
2288 regcache_cache_only(rt5668->regmap, false); in rt5668_resume()
2289 regcache_sync(rt5668->regmap); in rt5668_resume()
2316 .name = "rt5668-aif1",
2335 .name = "rt5668-aif2",
2389 of_property_read_u32(dev->of_node, "realtek,dmic1-data-pin", in rt5668_parse_dt()
2390 &rt5668->pdata.dmic1_data_pin); in rt5668_parse_dt()
2391 of_property_read_u32(dev->of_node, "realtek,dmic1-clk-pin", in rt5668_parse_dt()
2392 &rt5668->pdata.dmic1_clk_pin); in rt5668_parse_dt()
2393 of_property_read_u32(dev->of_node, "realtek,jd-src", in rt5668_parse_dt()
2394 &rt5668->pdata.jd_src); in rt5668_parse_dt()
2403 mutex_lock(&rt5668->calibrate_mutex); in rt5668_calibrate()
2405 rt5668_reset(rt5668->regmap); in rt5668_calibrate()
2406 regmap_write(rt5668->regmap, RT5668_PWR_ANLG_1, 0xa2bf); in rt5668_calibrate()
2408 regmap_write(rt5668->regmap, RT5668_PWR_ANLG_1, 0xf2bf); in rt5668_calibrate()
2409 regmap_write(rt5668->regmap, RT5668_MICBIAS_2, 0x0380); in rt5668_calibrate()
2410 regmap_write(rt5668->regmap, RT5668_PWR_DIG_1, 0x8001); in rt5668_calibrate()
2411 regmap_write(rt5668->regmap, RT5668_TEST_MODE_CTRL_1, 0x0000); in rt5668_calibrate()
2412 regmap_write(rt5668->regmap, RT5668_STO1_DAC_MIXER, 0x2080); in rt5668_calibrate()
2413 regmap_write(rt5668->regmap, RT5668_STO1_ADC_MIXER, 0x4040); in rt5668_calibrate()
2414 regmap_write(rt5668->regmap, RT5668_DEPOP_1, 0x0069); in rt5668_calibrate()
2415 regmap_write(rt5668->regmap, RT5668_CHOP_DAC, 0x3000); in rt5668_calibrate()
2416 regmap_write(rt5668->regmap, RT5668_HP_CTRL_2, 0x6000); in rt5668_calibrate()
2417 regmap_write(rt5668->regmap, RT5668_HP_CHARGE_PUMP_1, 0x0f26); in rt5668_calibrate()
2418 regmap_write(rt5668->regmap, RT5668_CALIB_ADC_CTRL, 0x7f05); in rt5668_calibrate()
2419 regmap_write(rt5668->regmap, RT5668_STO1_ADC_MIXER, 0x686c); in rt5668_calibrate()
2420 regmap_write(rt5668->regmap, RT5668_CAL_REC, 0x0d0d); in rt5668_calibrate()
2421 regmap_write(rt5668->regmap, RT5668_HP_CALIB_CTRL_9, 0x000f); in rt5668_calibrate()
2422 regmap_write(rt5668->regmap, RT5668_PWR_DIG_1, 0x8d01); in rt5668_calibrate()
2423 regmap_write(rt5668->regmap, RT5668_HP_CALIB_CTRL_2, 0x0321); in rt5668_calibrate()
2424 regmap_write(rt5668->regmap, RT5668_HP_LOGIC_CTRL_2, 0x0004); in rt5668_calibrate()
2425 regmap_write(rt5668->regmap, RT5668_HP_CALIB_CTRL_1, 0x7c00); in rt5668_calibrate()
2426 regmap_write(rt5668->regmap, RT5668_HP_CALIB_CTRL_3, 0x06a1); in rt5668_calibrate()
2427 regmap_write(rt5668->regmap, RT5668_A_DAC1_MUX, 0x0311); in rt5668_calibrate()
2428 regmap_write(rt5668->regmap, RT5668_RESET_HPF_CTRL, 0x0000); in rt5668_calibrate()
2429 regmap_write(rt5668->regmap, RT5668_ADC_STO1_HP_CTRL_1, 0x3320); in rt5668_calibrate()
2431 regmap_write(rt5668->regmap, RT5668_HP_CALIB_CTRL_1, 0xfc00); in rt5668_calibrate()
2434 regmap_read(rt5668->regmap, RT5668_HP_CALIB_STA_1, &value); in rt5668_calibrate()
2445 regmap_write(rt5668->regmap, RT5668_STO1_ADC_MIXER, 0xc0c4); in rt5668_calibrate()
2446 regmap_write(rt5668->regmap, RT5668_PWR_DIG_1, 0x0000); in rt5668_calibrate()
2448 mutex_unlock(&rt5668->calibrate_mutex); in rt5668_calibrate()
2454 struct rt5668_platform_data *pdata = dev_get_platdata(&i2c->dev); in rt5668_i2c_probe()
2459 rt5668 = devm_kzalloc(&i2c->dev, sizeof(struct rt5668_priv), in rt5668_i2c_probe()
2463 return -ENOMEM; in rt5668_i2c_probe()
2468 rt5668->pdata = *pdata; in rt5668_i2c_probe()
2470 rt5668_parse_dt(rt5668, &i2c->dev); in rt5668_i2c_probe()
2472 rt5668->regmap = devm_regmap_init_i2c(i2c, &rt5668_regmap); in rt5668_i2c_probe()
2473 if (IS_ERR(rt5668->regmap)) { in rt5668_i2c_probe()
2474 ret = PTR_ERR(rt5668->regmap); in rt5668_i2c_probe()
2475 dev_err(&i2c->dev, "Failed to allocate register map: %d\n", in rt5668_i2c_probe()
2480 for (i = 0; i < ARRAY_SIZE(rt5668->supplies); i++) in rt5668_i2c_probe()
2481 rt5668->supplies[i].supply = rt5668_supply_names[i]; in rt5668_i2c_probe()
2483 ret = devm_regulator_bulk_get(&i2c->dev, ARRAY_SIZE(rt5668->supplies), in rt5668_i2c_probe()
2484 rt5668->supplies); in rt5668_i2c_probe()
2486 dev_err(&i2c->dev, "Failed to request supplies: %d\n", ret); in rt5668_i2c_probe()
2490 ret = regulator_bulk_enable(ARRAY_SIZE(rt5668->supplies), in rt5668_i2c_probe()
2491 rt5668->supplies); in rt5668_i2c_probe()
2493 dev_err(&i2c->dev, "Failed to enable supplies: %d\n", ret); in rt5668_i2c_probe()
2497 rt5668->ldo1_en = devm_gpiod_get_optional(&i2c->dev, in rt5668_i2c_probe()
2498 "realtek,ldo1-en", in rt5668_i2c_probe()
2500 if (IS_ERR(rt5668->ldo1_en)) { in rt5668_i2c_probe()
2501 dev_err(&i2c->dev, "Fail gpio request ldo1_en\n"); in rt5668_i2c_probe()
2502 return PTR_ERR(rt5668->ldo1_en); in rt5668_i2c_probe()
2508 regmap_write(rt5668->regmap, RT5668_I2C_MODE, 0x1); in rt5668_i2c_probe()
2511 regmap_read(rt5668->regmap, RT5668_DEVICE_ID, &val); in rt5668_i2c_probe()
2514 return -ENODEV; in rt5668_i2c_probe()
2517 rt5668_reset(rt5668->regmap); in rt5668_i2c_probe()
2521 regmap_write(rt5668->regmap, RT5668_DEPOP_1, 0x0000); in rt5668_i2c_probe()
2524 if (rt5668->pdata.dmic1_data_pin != RT5668_DMIC1_NULL) { in rt5668_i2c_probe()
2525 switch (rt5668->pdata.dmic1_data_pin) { in rt5668_i2c_probe()
2527 regmap_update_bits(rt5668->regmap, RT5668_DMIC_CTRL_1, in rt5668_i2c_probe()
2529 regmap_update_bits(rt5668->regmap, RT5668_GPIO_CTRL_1, in rt5668_i2c_probe()
2534 regmap_update_bits(rt5668->regmap, RT5668_DMIC_CTRL_1, in rt5668_i2c_probe()
2536 regmap_update_bits(rt5668->regmap, RT5668_GPIO_CTRL_1, in rt5668_i2c_probe()
2541 dev_dbg(&i2c->dev, "invalid DMIC_DAT pin\n"); in rt5668_i2c_probe()
2545 switch (rt5668->pdata.dmic1_clk_pin) { in rt5668_i2c_probe()
2547 regmap_update_bits(rt5668->regmap, RT5668_GPIO_CTRL_1, in rt5668_i2c_probe()
2552 regmap_update_bits(rt5668->regmap, RT5668_GPIO_CTRL_1, in rt5668_i2c_probe()
2557 dev_dbg(&i2c->dev, "invalid DMIC_CLK pin\n"); in rt5668_i2c_probe()
2562 regmap_update_bits(rt5668->regmap, RT5668_PWR_ANLG_1, in rt5668_i2c_probe()
2565 regmap_write(rt5668->regmap, RT5668_MICBIAS_2, 0x0380); in rt5668_i2c_probe()
2566 regmap_update_bits(rt5668->regmap, RT5668_GPIO_CTRL_1, in rt5668_i2c_probe()
2569 regmap_write(rt5668->regmap, RT5668_TEST_MODE_CTRL_1, 0x0000); in rt5668_i2c_probe()
2571 INIT_DELAYED_WORK(&rt5668->jack_detect_work, in rt5668_i2c_probe()
2573 INIT_DELAYED_WORK(&rt5668->jd_check_work, in rt5668_i2c_probe()
2576 mutex_init(&rt5668->calibrate_mutex); in rt5668_i2c_probe()
2578 if (i2c->irq) { in rt5668_i2c_probe()
2579 ret = devm_request_threaded_irq(&i2c->dev, i2c->irq, NULL, in rt5668_i2c_probe()
2583 dev_err(&i2c->dev, "Failed to reguest IRQ: %d\n", ret); in rt5668_i2c_probe()
2587 return devm_snd_soc_register_component(&i2c->dev, &soc_component_dev_rt5668, in rt5668_i2c_probe()
2595 rt5668_reset(rt5668->regmap); in rt5668_i2c_shutdown()