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
27 #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 while (!rt5668->component) in rt5668_jack_detect_handler()
1028 while (!rt5668->component->card->instantiated) in rt5668_jack_detect_handler()
1031 mutex_lock(&rt5668->calibrate_mutex); in rt5668_jack_detect_handler()
1033 val = snd_soc_component_read(rt5668->component, RT5668_AJD1_CTRL) in rt5668_jack_detect_handler()
1037 if (rt5668->jack_type == 0) { in rt5668_jack_detect_handler()
1039 rt5668->jack_type = in rt5668_jack_detect_handler()
1040 rt5668_headset_detect(rt5668->component, 1); in rt5668_jack_detect_handler()
1043 rt5668->jack_type = SND_JACK_HEADSET; in rt5668_jack_detect_handler()
1044 btn_type = rt5668_button_detect(rt5668->component); in rt5668_jack_detect_handler()
1056 rt5668->jack_type |= SND_JACK_BTN_0; in rt5668_jack_detect_handler()
1061 rt5668->jack_type |= SND_JACK_BTN_1; in rt5668_jack_detect_handler()
1066 rt5668->jack_type |= SND_JACK_BTN_2; in rt5668_jack_detect_handler()
1071 rt5668->jack_type |= SND_JACK_BTN_3; in rt5668_jack_detect_handler()
1077 dev_err(rt5668->component->dev, in rt5668_jack_detect_handler()
1085 rt5668->jack_type = rt5668_headset_detect(rt5668->component, 0); in rt5668_jack_detect_handler()
1088 snd_soc_jack_report(rt5668->hs_jack, rt5668->jack_type, in rt5668_jack_detect_handler()
1093 if (rt5668->jack_type & (SND_JACK_BTN_0 | SND_JACK_BTN_1 | in rt5668_jack_detect_handler()
1095 schedule_delayed_work(&rt5668->jd_check_work, 0); in rt5668_jack_detect_handler()
1097 cancel_delayed_work_sync(&rt5668->jd_check_work); in rt5668_jack_detect_handler()
1099 mutex_unlock(&rt5668->calibrate_mutex); in rt5668_jack_detect_handler()
1115 /* ADC Digital Volume Control */
1116 SOC_DOUBLE("STO1 ADC Capture Switch", RT5668_STO1_ADC_DIG_VOL,
1118 SOC_DOUBLE_TLV("STO1 ADC Capture Volume", RT5668_STO1_ADC_DIG_VOL,
1121 /* ADC Boost Volume Control */
1122 SOC_DOUBLE_TLV("STO1 ADC Boost Gain Volume", RT5668_STO1_ADC_BOOST,
1133 if (rt5668->sysclk < target) { in rt5668_div_sel()
1135 rt5668->sysclk); in rt5668_div_sel()
1139 for (i = 0; i < size - 1; i++) { in rt5668_div_sel()
1141 if (target * div[i] == rt5668->sysclk) in rt5668_div_sel()
1143 if (target * div[i + 1] > rt5668->sysclk) { in rt5668_div_sel()
1145 rt5668->sysclk); in rt5668_div_sel()
1150 if (target * div[i] < rt5668->sysclk) in rt5668_div_sel()
1152 rt5668->sysclk); in rt5668_div_sel()
1154 return size - 1; in rt5668_div_sel()
1159 * set_dmic_clk - Set parameter of dmic.
1172 snd_soc_dapm_to_component(w->dapm); in set_dmic_clk()
1174 int idx = -EINVAL; in set_dmic_clk()
1189 snd_soc_dapm_to_component(w->dapm); in set_filter_clk()
1191 int ref, val, reg, idx = -EINVAL; in set_filter_clk()
1196 if (w->shift == RT5668_PWR_ADC_S1F_BIT && in set_filter_clk()
1198 ref = 256 * rt5668->lrck[RT5668_AIF2]; in set_filter_clk()
1200 ref = 256 * rt5668->lrck[RT5668_AIF1]; in set_filter_clk()
1204 if (w->shift == RT5668_PWR_ADC_S1F_BIT) in set_filter_clk()
1220 snd_soc_dapm_to_component(w->dapm); in is_sys_clk_from_pll1()
1235 snd_soc_dapm_to_component(w->dapm); in is_using_asrc()
1237 switch (w->shift) { in is_using_asrc()
1277 SOC_DAPM_SINGLE("Stereo ADC Switch", RT5668_AD_DA_MIXER,
1284 SOC_DAPM_SINGLE("Stereo ADC Switch", RT5668_AD_DA_MIXER,
1311 /* MX-26 [13] [5] */
1313 "DAC MIX", "ADC"
1330 /* STO1 ADC Source */
1331 /* MX-26 [11:10] [3:2] */
1351 /* MX-26 [12] [4] */
1370 /* MX-79 [6:4] I2S1 ADC data location */
1387 SOC_DAPM_ENUM("IF1 ADC Slot location", rt5668_if1_adc_slot_enum);
1390 /* MX-2B [4], MX-2B [0]*/
1421 snd_soc_dapm_to_component(w->dapm); in rt5668_hp_event()
1470 snd_soc_dapm_to_component(w->dapm); in rt5655_set_verf()
1474 switch (w->shift) { in rt5655_set_verf()
1492 switch (w->shift) { in rt5655_set_verf()
1551 SND_SOC_DAPM_SUPPLY_S("ADC STO1 ASRC", 1, RT5668_PLL_TRACK_1,
1572 SND_SOC_DAPM_SUPPLY("DMIC CLK", SND_SOC_NOPM, 0, 0,
1601 /* ADC Mux */
1602 SND_SOC_DAPM_MUX("Stereo1 ADC L1 Mux", SND_SOC_NOPM, 0, 0,
1604 SND_SOC_DAPM_MUX("Stereo1 ADC R1 Mux", SND_SOC_NOPM, 0, 0,
1606 SND_SOC_DAPM_MUX("Stereo1 ADC L2 Mux", SND_SOC_NOPM, 0, 0,
1608 SND_SOC_DAPM_MUX("Stereo1 ADC R2 Mux", SND_SOC_NOPM, 0, 0,
1610 SND_SOC_DAPM_MUX("Stereo1 ADC L Mux", SND_SOC_NOPM, 0, 0,
1612 SND_SOC_DAPM_MUX("Stereo1 ADC R Mux", SND_SOC_NOPM, 0, 0,
1617 /* ADC Mixer */
1618 SND_SOC_DAPM_SUPPLY("ADC Stereo1 Filter", RT5668_PWR_DIG_2,
1621 SND_SOC_DAPM_MIXER("Stereo1 ADC MIXL", RT5668_STO1_ADC_DIG_VOL,
1624 SND_SOC_DAPM_MIXER("Stereo1 ADC MIXR", RT5668_STO1_ADC_DIG_VOL,
1628 /* ADC PGA */
1629 SND_SOC_DAPM_PGA("Stereo1 ADC MIX", SND_SOC_NOPM, 0, 0, NULL, 0),
1641 SND_SOC_DAPM_MUX("IF1 01 ADC Swap Mux", SND_SOC_NOPM, 0, 0,
1643 SND_SOC_DAPM_MUX("IF1 23 ADC Swap Mux", SND_SOC_NOPM, 0, 0,
1645 SND_SOC_DAPM_MUX("IF1 45 ADC Swap Mux", SND_SOC_NOPM, 0, 0,
1647 SND_SOC_DAPM_MUX("IF1 67 ADC Swap Mux", SND_SOC_NOPM, 0, 0,
1649 SND_SOC_DAPM_MUX("IF2 ADC Swap Mux", SND_SOC_NOPM, 0, 0,
1669 /* DAC channel Mux */
1710 /* CLK DET */
1728 {"ADC Stereo1 Filter", NULL, "PLL1", is_sys_clk_from_pll1},
1732 {"ADC Stereo1 Filter", NULL, "ADC STO1 ASRC", is_using_asrc},
1734 {"ADC STO1 ASRC", NULL, "AD ASRC"},
1758 {"DMIC L1", NULL, "DMIC CLK"},
1760 {"DMIC R1", NULL, "DMIC CLK"},
1762 {"DMIC CLK", NULL, "DMIC ASRC"},
1764 {"Stereo1 ADC L Mux", "ADC1 L", "ADC1 L"},
1765 {"Stereo1 ADC L Mux", "ADC1 R", "ADC1 R"},
1766 {"Stereo1 ADC R Mux", "ADC1 L", "ADC1 L"},
1767 {"Stereo1 ADC R Mux", "ADC1 R", "ADC1 R"},
1769 {"Stereo1 ADC L1 Mux", "ADC", "Stereo1 ADC L Mux"},
1770 {"Stereo1 ADC L1 Mux", "DAC MIX", "Stereo1 DAC MIXL"},
1771 {"Stereo1 ADC L2 Mux", "DMIC", "DMIC L1"},
1772 {"Stereo1 ADC L2 Mux", "DAC MIX", "Stereo1 DAC MIXL"},
1774 {"Stereo1 ADC R1 Mux", "ADC", "Stereo1 ADC R Mux"},
1775 {"Stereo1 ADC R1 Mux", "DAC MIX", "Stereo1 DAC MIXR"},
1776 {"Stereo1 ADC R2 Mux", "DMIC", "DMIC R1"},
1777 {"Stereo1 ADC R2 Mux", "DAC MIX", "Stereo1 DAC MIXR"},
1779 {"Stereo1 ADC MIXL", "ADC1 Switch", "Stereo1 ADC L1 Mux"},
1780 {"Stereo1 ADC MIXL", "ADC2 Switch", "Stereo1 ADC L2 Mux"},
1781 {"Stereo1 ADC MIXL", NULL, "ADC Stereo1 Filter"},
1783 {"Stereo1 ADC MIXR", "ADC1 Switch", "Stereo1 ADC R1 Mux"},
1784 {"Stereo1 ADC MIXR", "ADC2 Switch", "Stereo1 ADC R2 Mux"},
1785 {"Stereo1 ADC MIXR", NULL, "ADC Stereo1 Filter"},
1787 {"Stereo1 ADC MIX", NULL, "Stereo1 ADC MIXL"},
1788 {"Stereo1 ADC MIX", NULL, "Stereo1 ADC MIXR"},
1790 {"IF1 01 ADC Swap Mux", "L/R", "Stereo1 ADC MIX"},
1791 {"IF1 01 ADC Swap Mux", "L/L", "Stereo1 ADC MIX"},
1792 {"IF1 01 ADC Swap Mux", "R/L", "Stereo1 ADC MIX"},
1793 {"IF1 01 ADC Swap Mux", "R/R", "Stereo1 ADC MIX"},
1794 {"IF1 23 ADC Swap Mux", "L/R", "Stereo1 ADC MIX"},
1795 {"IF1 23 ADC Swap Mux", "R/L", "Stereo1 ADC MIX"},
1796 {"IF1 23 ADC Swap Mux", "L/L", "Stereo1 ADC MIX"},
1797 {"IF1 23 ADC Swap Mux", "R/R", "Stereo1 ADC MIX"},
1798 {"IF1 45 ADC Swap Mux", "L/R", "Stereo1 ADC MIX"},
1799 {"IF1 45 ADC Swap Mux", "R/L", "Stereo1 ADC MIX"},
1800 {"IF1 45 ADC Swap Mux", "L/L", "Stereo1 ADC MIX"},
1801 {"IF1 45 ADC Swap Mux", "R/R", "Stereo1 ADC MIX"},
1802 {"IF1 67 ADC Swap Mux", "L/R", "Stereo1 ADC MIX"},
1803 {"IF1 67 ADC Swap Mux", "R/L", "Stereo1 ADC MIX"},
1804 {"IF1 67 ADC Swap Mux", "L/L", "Stereo1 ADC MIX"},
1805 {"IF1 67 ADC Swap Mux", "R/R", "Stereo1 ADC MIX"},
1807 {"IF1_ADC Mux", "Slot 0", "IF1 01 ADC Swap Mux"},
1808 {"IF1_ADC Mux", "Slot 2", "IF1 23 ADC Swap Mux"},
1809 {"IF1_ADC Mux", "Slot 4", "IF1 45 ADC Swap Mux"},
1810 {"IF1_ADC Mux", "Slot 6", "IF1 67 ADC Swap Mux"},
1814 {"IF2 ADC Swap Mux", "L/R", "Stereo1 ADC MIX"},
1815 {"IF2 ADC Swap Mux", "R/L", "Stereo1 ADC MIX"},
1816 {"IF2 ADC Swap Mux", "L/L", "Stereo1 ADC MIX"},
1817 {"IF2 ADC Swap Mux", "R/R", "Stereo1 ADC MIX"},
1818 {"ADCDAT Mux", "ADCDAT2", "IF2 ADC Swap Mux"},
1828 {"DAC1 MIXL", "Stereo ADC Switch", "Stereo1 ADC MIXL"},
1830 {"DAC1 MIXR", "Stereo ADC Switch", "Stereo1 ADC MIXR"},
1868 struct snd_soc_component *component = dai->component; in rt5668_set_tdm_slot()
1887 return -EINVAL; in rt5668_set_tdm_slot()
1907 return -EINVAL; in rt5668_set_tdm_slot()
1920 struct snd_soc_component *component = dai->component; in rt5668_hw_params()
1925 rt5668->lrck[dai->id] = params_rate(params); in rt5668_hw_params()
1926 pre_div = rl6231_get_clk_info(rt5668->sysclk, rt5668->lrck[dai->id]); in rt5668_hw_params()
1930 dev_err(component->dev, "Unsupported frame size: %d\n", in rt5668_hw_params()
1932 return -EINVAL; in rt5668_hw_params()
1935 dev_dbg(dai->dev, "lrck is %dHz and pre_div is %d for iis %d\n", in rt5668_hw_params()
1936 rt5668->lrck[dai->id], pre_div, dai->id); in rt5668_hw_params()
1958 return -EINVAL; in rt5668_hw_params()
1961 switch (dai->id) { in rt5668_hw_params()
1965 if (rt5668->master[RT5668_AIF1]) { in rt5668_hw_params()
1982 if (rt5668->master[RT5668_AIF2]) { in rt5668_hw_params()
1997 dev_err(component->dev, "Invalid dai->id: %d\n", dai->id); in rt5668_hw_params()
1998 return -EINVAL; in rt5668_hw_params()
2006 struct snd_soc_component *component = dai->component; in rt5668_set_dai_fmt()
2012 rt5668->master[dai->id] = 1; in rt5668_set_dai_fmt()
2015 rt5668->master[dai->id] = 0; in rt5668_set_dai_fmt()
2018 return -EINVAL; in rt5668_set_dai_fmt()
2029 if (dai->id == RT5668_AIF1) in rt5668_set_dai_fmt()
2032 return -EINVAL; in rt5668_set_dai_fmt()
2035 if (dai->id == RT5668_AIF1) in rt5668_set_dai_fmt()
2039 return -EINVAL; in rt5668_set_dai_fmt()
2042 return -EINVAL; in rt5668_set_dai_fmt()
2061 return -EINVAL; in rt5668_set_dai_fmt()
2064 switch (dai->id) { in rt5668_set_dai_fmt()
2072 tdm_ctrl | rt5668->master[dai->id]); in rt5668_set_dai_fmt()
2075 if (rt5668->master[dai->id] == 0) in rt5668_set_dai_fmt()
2082 dev_err(component->dev, "Invalid dai->id: %d\n", dai->id); in rt5668_set_dai_fmt()
2083 return -EINVAL; in rt5668_set_dai_fmt()
2092 unsigned int reg_val = 0, src = 0; in rt5668_set_component_sysclk() local
2094 if (freq == rt5668->sysclk && clk_id == rt5668->sysclk_src) in rt5668_set_component_sysclk()
2100 src = RT5668_CLK_SRC_MCLK; in rt5668_set_component_sysclk()
2104 src = RT5668_CLK_SRC_PLL1; in rt5668_set_component_sysclk()
2108 src = RT5668_CLK_SRC_PLL2; in rt5668_set_component_sysclk()
2112 src = RT5668_CLK_SRC_RCCLK; in rt5668_set_component_sysclk()
2115 dev_err(component->dev, "Invalid clock id (%d)\n", clk_id); in rt5668_set_component_sysclk()
2116 return -EINVAL; in rt5668_set_component_sysclk()
2121 if (rt5668->master[RT5668_AIF2]) { in rt5668_set_component_sysclk()
2124 src << RT5668_I2S2_SRC_SFT); in rt5668_set_component_sysclk()
2127 rt5668->sysclk = freq; in rt5668_set_component_sysclk()
2128 rt5668->sysclk_src = clk_id; in rt5668_set_component_sysclk()
2130 dev_dbg(component->dev, "Sysclk is %dHz and clock id is %d\n", in rt5668_set_component_sysclk()
2144 if (source == rt5668->pll_src && freq_in == rt5668->pll_in && in rt5668_set_component_pll()
2145 freq_out == rt5668->pll_out) in rt5668_set_component_pll()
2149 dev_dbg(component->dev, "PLL disabled\n"); in rt5668_set_component_pll()
2151 rt5668->pll_in = 0; in rt5668_set_component_pll()
2152 rt5668->pll_out = 0; in rt5668_set_component_pll()
2168 dev_err(component->dev, "Unknown PLL Source %d\n", source); in rt5668_set_component_pll()
2169 return -EINVAL; in rt5668_set_component_pll()
2174 dev_err(component->dev, "Unsupport input clock %d\n", freq_in); in rt5668_set_component_pll()
2178 dev_dbg(component->dev, "bypass=%d m=%d n=%d k=%d\n", in rt5668_set_component_pll()
2188 rt5668->pll_in = freq_in; in rt5668_set_component_pll()
2189 rt5668->pll_out = freq_out; in rt5668_set_component_pll()
2190 rt5668->pll_src = source; in rt5668_set_component_pll()
2197 struct snd_soc_component *component = dai->component; in rt5668_set_bclk_ratio()
2200 rt5668->bclk[dai->id] = ratio; in rt5668_set_bclk_ratio()
2214 dev_err(dai->dev, "Invalid bclk ratio %d\n", ratio); in rt5668_set_bclk_ratio()
2215 return -EINVAL; in rt5668_set_bclk_ratio()
2228 regmap_update_bits(rt5668->regmap, RT5668_PWR_ANLG_1, in rt5668_set_bias_level()
2231 regmap_update_bits(rt5668->regmap, RT5668_PWR_DIG_1, in rt5668_set_bias_level()
2237 regmap_update_bits(rt5668->regmap, RT5668_PWR_ANLG_1, in rt5668_set_bias_level()
2239 regmap_update_bits(rt5668->regmap, RT5668_PWR_DIG_1, in rt5668_set_bias_level()
2243 regmap_update_bits(rt5668->regmap, RT5668_PWR_DIG_1, in rt5668_set_bias_level()
2245 regmap_update_bits(rt5668->regmap, RT5668_PWR_ANLG_1, in rt5668_set_bias_level()
2260 rt5668->component = component; in rt5668_probe()
2269 rt5668_reset(rt5668->regmap); in rt5668_remove()
2277 regcache_cache_only(rt5668->regmap, true); in rt5668_suspend()
2278 regcache_mark_dirty(rt5668->regmap); in rt5668_suspend()
2286 regcache_cache_only(rt5668->regmap, false); in rt5668_resume()
2287 regcache_sync(rt5668->regmap); in rt5668_resume()
2314 .name = "rt5668-aif1",
2333 .name = "rt5668-aif2",
2388 of_property_read_u32(dev->of_node, "realtek,dmic1-data-pin", in rt5668_parse_dt()
2389 &rt5668->pdata.dmic1_data_pin); in rt5668_parse_dt()
2390 of_property_read_u32(dev->of_node, "realtek,dmic1-clk-pin", in rt5668_parse_dt()
2391 &rt5668->pdata.dmic1_clk_pin); in rt5668_parse_dt()
2392 of_property_read_u32(dev->of_node, "realtek,jd-src", in rt5668_parse_dt()
2393 &rt5668->pdata.jd_src); in rt5668_parse_dt()
2395 rt5668->pdata.ldo1_en = of_get_named_gpio(dev->of_node, in rt5668_parse_dt()
2396 "realtek,ldo1-en-gpios", 0); in rt5668_parse_dt()
2405 mutex_lock(&rt5668->calibrate_mutex); in rt5668_calibrate()
2407 rt5668_reset(rt5668->regmap); in rt5668_calibrate()
2408 regmap_write(rt5668->regmap, RT5668_PWR_ANLG_1, 0xa2bf); in rt5668_calibrate()
2410 regmap_write(rt5668->regmap, RT5668_PWR_ANLG_1, 0xf2bf); in rt5668_calibrate()
2411 regmap_write(rt5668->regmap, RT5668_MICBIAS_2, 0x0380); in rt5668_calibrate()
2412 regmap_write(rt5668->regmap, RT5668_PWR_DIG_1, 0x8001); in rt5668_calibrate()
2413 regmap_write(rt5668->regmap, RT5668_TEST_MODE_CTRL_1, 0x0000); in rt5668_calibrate()
2414 regmap_write(rt5668->regmap, RT5668_STO1_DAC_MIXER, 0x2080); in rt5668_calibrate()
2415 regmap_write(rt5668->regmap, RT5668_STO1_ADC_MIXER, 0x4040); in rt5668_calibrate()
2416 regmap_write(rt5668->regmap, RT5668_DEPOP_1, 0x0069); in rt5668_calibrate()
2417 regmap_write(rt5668->regmap, RT5668_CHOP_DAC, 0x3000); in rt5668_calibrate()
2418 regmap_write(rt5668->regmap, RT5668_HP_CTRL_2, 0x6000); in rt5668_calibrate()
2419 regmap_write(rt5668->regmap, RT5668_HP_CHARGE_PUMP_1, 0x0f26); in rt5668_calibrate()
2420 regmap_write(rt5668->regmap, RT5668_CALIB_ADC_CTRL, 0x7f05); in rt5668_calibrate()
2421 regmap_write(rt5668->regmap, RT5668_STO1_ADC_MIXER, 0x686c); in rt5668_calibrate()
2422 regmap_write(rt5668->regmap, RT5668_CAL_REC, 0x0d0d); in rt5668_calibrate()
2423 regmap_write(rt5668->regmap, RT5668_HP_CALIB_CTRL_9, 0x000f); in rt5668_calibrate()
2424 regmap_write(rt5668->regmap, RT5668_PWR_DIG_1, 0x8d01); in rt5668_calibrate()
2425 regmap_write(rt5668->regmap, RT5668_HP_CALIB_CTRL_2, 0x0321); in rt5668_calibrate()
2426 regmap_write(rt5668->regmap, RT5668_HP_LOGIC_CTRL_2, 0x0004); in rt5668_calibrate()
2427 regmap_write(rt5668->regmap, RT5668_HP_CALIB_CTRL_1, 0x7c00); in rt5668_calibrate()
2428 regmap_write(rt5668->regmap, RT5668_HP_CALIB_CTRL_3, 0x06a1); in rt5668_calibrate()
2429 regmap_write(rt5668->regmap, RT5668_A_DAC1_MUX, 0x0311); in rt5668_calibrate()
2430 regmap_write(rt5668->regmap, RT5668_RESET_HPF_CTRL, 0x0000); in rt5668_calibrate()
2431 regmap_write(rt5668->regmap, RT5668_ADC_STO1_HP_CTRL_1, 0x3320); in rt5668_calibrate()
2433 regmap_write(rt5668->regmap, RT5668_HP_CALIB_CTRL_1, 0xfc00); in rt5668_calibrate()
2436 regmap_read(rt5668->regmap, RT5668_HP_CALIB_STA_1, &value); in rt5668_calibrate()
2447 regmap_write(rt5668->regmap, RT5668_STO1_ADC_MIXER, 0xc0c4); in rt5668_calibrate()
2448 regmap_write(rt5668->regmap, RT5668_PWR_DIG_1, 0x0000); in rt5668_calibrate()
2450 mutex_unlock(&rt5668->calibrate_mutex); in rt5668_calibrate()
2457 struct rt5668_platform_data *pdata = dev_get_platdata(&i2c->dev); in rt5668_i2c_probe()
2462 rt5668 = devm_kzalloc(&i2c->dev, sizeof(struct rt5668_priv), in rt5668_i2c_probe()
2466 return -ENOMEM; in rt5668_i2c_probe()
2471 rt5668->pdata = *pdata; in rt5668_i2c_probe()
2473 rt5668_parse_dt(rt5668, &i2c->dev); in rt5668_i2c_probe()
2475 rt5668->regmap = devm_regmap_init_i2c(i2c, &rt5668_regmap); in rt5668_i2c_probe()
2476 if (IS_ERR(rt5668->regmap)) { in rt5668_i2c_probe()
2477 ret = PTR_ERR(rt5668->regmap); in rt5668_i2c_probe()
2478 dev_err(&i2c->dev, "Failed to allocate register map: %d\n", in rt5668_i2c_probe()
2483 for (i = 0; i < ARRAY_SIZE(rt5668->supplies); i++) in rt5668_i2c_probe()
2484 rt5668->supplies[i].supply = rt5668_supply_names[i]; in rt5668_i2c_probe()
2486 ret = devm_regulator_bulk_get(&i2c->dev, ARRAY_SIZE(rt5668->supplies), in rt5668_i2c_probe()
2487 rt5668->supplies); in rt5668_i2c_probe()
2489 dev_err(&i2c->dev, "Failed to request supplies: %d\n", ret); in rt5668_i2c_probe()
2493 ret = regulator_bulk_enable(ARRAY_SIZE(rt5668->supplies), in rt5668_i2c_probe()
2494 rt5668->supplies); in rt5668_i2c_probe()
2496 dev_err(&i2c->dev, "Failed to enable supplies: %d\n", ret); in rt5668_i2c_probe()
2500 if (gpio_is_valid(rt5668->pdata.ldo1_en)) { in rt5668_i2c_probe()
2501 if (devm_gpio_request_one(&i2c->dev, rt5668->pdata.ldo1_en, in rt5668_i2c_probe()
2503 dev_err(&i2c->dev, "Fail gpio_request gpio_ldo\n"); in rt5668_i2c_probe()
2509 regmap_write(rt5668->regmap, RT5668_I2C_MODE, 0x1); in rt5668_i2c_probe()
2512 regmap_read(rt5668->regmap, RT5668_DEVICE_ID, &val); in rt5668_i2c_probe()
2515 return -ENODEV; in rt5668_i2c_probe()
2518 rt5668_reset(rt5668->regmap); in rt5668_i2c_probe()
2522 regmap_write(rt5668->regmap, RT5668_DEPOP_1, 0x0000); in rt5668_i2c_probe()
2525 if (rt5668->pdata.dmic1_data_pin != RT5668_DMIC1_NULL) { in rt5668_i2c_probe()
2526 switch (rt5668->pdata.dmic1_data_pin) { in rt5668_i2c_probe()
2528 regmap_update_bits(rt5668->regmap, RT5668_DMIC_CTRL_1, in rt5668_i2c_probe()
2530 regmap_update_bits(rt5668->regmap, RT5668_GPIO_CTRL_1, in rt5668_i2c_probe()
2535 regmap_update_bits(rt5668->regmap, RT5668_DMIC_CTRL_1, in rt5668_i2c_probe()
2537 regmap_update_bits(rt5668->regmap, RT5668_GPIO_CTRL_1, in rt5668_i2c_probe()
2542 dev_dbg(&i2c->dev, "invalid DMIC_DAT pin\n"); in rt5668_i2c_probe()
2546 switch (rt5668->pdata.dmic1_clk_pin) { in rt5668_i2c_probe()
2548 regmap_update_bits(rt5668->regmap, RT5668_GPIO_CTRL_1, in rt5668_i2c_probe()
2553 regmap_update_bits(rt5668->regmap, RT5668_GPIO_CTRL_1, in rt5668_i2c_probe()
2558 dev_dbg(&i2c->dev, "invalid DMIC_CLK pin\n"); in rt5668_i2c_probe()
2563 regmap_update_bits(rt5668->regmap, RT5668_PWR_ANLG_1, in rt5668_i2c_probe()
2566 regmap_write(rt5668->regmap, RT5668_MICBIAS_2, 0x0380); in rt5668_i2c_probe()
2567 regmap_update_bits(rt5668->regmap, RT5668_GPIO_CTRL_1, in rt5668_i2c_probe()
2570 regmap_write(rt5668->regmap, RT5668_TEST_MODE_CTRL_1, 0x0000); in rt5668_i2c_probe()
2572 INIT_DELAYED_WORK(&rt5668->jack_detect_work, in rt5668_i2c_probe()
2574 INIT_DELAYED_WORK(&rt5668->jd_check_work, in rt5668_i2c_probe()
2577 mutex_init(&rt5668->calibrate_mutex); in rt5668_i2c_probe()
2579 if (i2c->irq) { in rt5668_i2c_probe()
2580 ret = devm_request_threaded_irq(&i2c->dev, i2c->irq, NULL, in rt5668_i2c_probe()
2584 dev_err(&i2c->dev, "Failed to reguest IRQ: %d\n", ret); in rt5668_i2c_probe()
2588 return devm_snd_soc_register_component(&i2c->dev, &soc_component_dev_rt5668, in rt5668_i2c_probe()
2596 rt5668_reset(rt5668->regmap); in rt5668_i2c_shutdown()