Lines Matching +full:jack +full:- +full:insert +full:- +full:debounce
1 // SPDX-License-Identifier: GPL-2.0-only
3 * rt5663.c -- RT5663 ALSA SoC audio codec driver
6 * Author: Jack Yu <jack.yu@realtek.com>
22 #include <sound/jack.h>
24 #include <sound/soc-dapm.h>
1374 static const DECLARE_TLV_DB_SCALE(rt5663_hp_vol_tlv, -2400, 150, 0);
1375 static const DECLARE_TLV_DB_SCALE(rt5663_v2_hp_vol_tlv, -2250, 150, 0);
1376 static const DECLARE_TLV_DB_SCALE(dac_vol_tlv, -6525, 75, 0);
1377 static const DECLARE_TLV_DB_SCALE(adc_vol_tlv, -1725, 75, 0);
1406 /* reset in-line command */ in rt5663_enable_push_button_irq()
1413 switch (rt5663->codec_ver) { in rt5663_enable_push_button_irq()
1425 dev_err(component->dev, "Unknown CODEC Version\n"); in rt5663_enable_push_button_irq()
1428 switch (rt5663->codec_ver) { in rt5663_enable_push_button_irq()
1440 dev_err(component->dev, "Unknown CODEC Version\n"); in rt5663_enable_push_button_irq()
1444 /* reset in-line command */ in rt5663_enable_push_button_irq()
1455 * rt5663_v2_jack_detect - Detect headset.
1457 * @jack_insert: Jack insert or not.
1459 * Detect whether is headset or not when jack inserted.
1470 dev_dbg(component->dev, "%s jack_insert:%d\n", __func__, jack_insert); in rt5663_v2_jack_detect()
1489 dev_dbg(component->dev, "%s: MX-0011 val=%x sleep %d\n", in rt5663_v2_jack_detect()
1493 dev_dbg(component->dev, "%s val = %d\n", __func__, val); in rt5663_v2_jack_detect()
1497 rt5663->jack_type = SND_JACK_HEADSET; in rt5663_v2_jack_detect()
1506 rt5663->jack_type = SND_JACK_HEADPHONE; in rt5663_v2_jack_detect()
1512 if (rt5663->jack_type == SND_JACK_HEADSET) { in rt5663_v2_jack_detect()
1520 rt5663->jack_type = 0; in rt5663_v2_jack_detect()
1523 dev_dbg(component->dev, "jack_type = %d\n", rt5663->jack_type); in rt5663_v2_jack_detect()
1524 return rt5663->jack_type; in rt5663_v2_jack_detect()
1528 * rt5663_jack_detect - Detect headset.
1530 * @jack_insert: Jack insert or not.
1532 * Detect whether is headset or not when jack inserted.
1541 dev_dbg(component->dev, "%s jack_insert:%d\n", __func__, jack_insert); in rt5663_jack_detect()
1588 regmap_read(rt5663->regmap, RT5663_INT_ST_2, &val); in rt5663_jack_detect()
1600 dev_dbg(component->dev, "%s val = %d\n", __func__, val); in rt5663_jack_detect()
1609 rt5663->jack_type = SND_JACK_HEADSET; in rt5663_jack_detect()
1612 if (rt5663->pdata.impedance_sensing_num) in rt5663_jack_detect()
1615 if (rt5663->pdata.dc_offset_l_manual_mic) { in rt5663_jack_detect()
1616 regmap_write(rt5663->regmap, RT5663_MIC_DECRO_2, in rt5663_jack_detect()
1617 rt5663->pdata.dc_offset_l_manual_mic >> in rt5663_jack_detect()
1619 regmap_write(rt5663->regmap, RT5663_MIC_DECRO_3, in rt5663_jack_detect()
1620 rt5663->pdata.dc_offset_l_manual_mic & in rt5663_jack_detect()
1624 if (rt5663->pdata.dc_offset_r_manual_mic) { in rt5663_jack_detect()
1625 regmap_write(rt5663->regmap, RT5663_MIC_DECRO_5, in rt5663_jack_detect()
1626 rt5663->pdata.dc_offset_r_manual_mic >> in rt5663_jack_detect()
1628 regmap_write(rt5663->regmap, RT5663_MIC_DECRO_6, in rt5663_jack_detect()
1629 rt5663->pdata.dc_offset_r_manual_mic & in rt5663_jack_detect()
1634 rt5663->jack_type = SND_JACK_HEADPHONE; in rt5663_jack_detect()
1639 if (rt5663->pdata.impedance_sensing_num) in rt5663_jack_detect()
1642 if (rt5663->pdata.dc_offset_l_manual) { in rt5663_jack_detect()
1643 regmap_write(rt5663->regmap, RT5663_MIC_DECRO_2, in rt5663_jack_detect()
1644 rt5663->pdata.dc_offset_l_manual >> 16); in rt5663_jack_detect()
1645 regmap_write(rt5663->regmap, RT5663_MIC_DECRO_3, in rt5663_jack_detect()
1646 rt5663->pdata.dc_offset_l_manual & in rt5663_jack_detect()
1650 if (rt5663->pdata.dc_offset_r_manual) { in rt5663_jack_detect()
1651 regmap_write(rt5663->regmap, RT5663_MIC_DECRO_5, in rt5663_jack_detect()
1652 rt5663->pdata.dc_offset_r_manual >> 16); in rt5663_jack_detect()
1653 regmap_write(rt5663->regmap, RT5663_MIC_DECRO_6, in rt5663_jack_detect()
1654 rt5663->pdata.dc_offset_r_manual & in rt5663_jack_detect()
1660 if (rt5663->jack_type == SND_JACK_HEADSET) in rt5663_jack_detect()
1662 rt5663->jack_type = 0; in rt5663_jack_detect()
1668 dev_dbg(component->dev, "jack_type = %d\n", rt5663->jack_type); in rt5663_jack_detect()
1669 return rt5663->jack_type; in rt5663_jack_detect()
1677 for (i = 0; i < rt5663->pdata.impedance_sensing_num; i++) { in rt5663_impedance_sensing()
1678 if (rt5663->imp_table[i].vol == 7) in rt5663_impedance_sensing()
1682 if (rt5663->jack_type == SND_JACK_HEADSET) { in rt5663_impedance_sensing()
1684 rt5663->imp_table[i].dc_offset_l_manual_mic >> 16); in rt5663_impedance_sensing()
1686 rt5663->imp_table[i].dc_offset_l_manual_mic & 0xffff); in rt5663_impedance_sensing()
1688 rt5663->imp_table[i].dc_offset_r_manual_mic >> 16); in rt5663_impedance_sensing()
1690 rt5663->imp_table[i].dc_offset_r_manual_mic & 0xffff); in rt5663_impedance_sensing()
1693 rt5663->imp_table[i].dc_offset_l_manual >> 16); in rt5663_impedance_sensing()
1695 rt5663->imp_table[i].dc_offset_l_manual & 0xffff); in rt5663_impedance_sensing()
1697 rt5663->imp_table[i].dc_offset_r_manual >> 16); in rt5663_impedance_sensing()
1699 rt5663->imp_table[i].dc_offset_r_manual & 0xffff); in rt5663_impedance_sensing()
1809 for (i = 0; i < rt5663->pdata.impedance_sensing_num; i++) { in rt5663_impedance_sensing()
1810 if (value >= rt5663->imp_table[i].imp_min && in rt5663_impedance_sensing()
1811 value <= rt5663->imp_table[i].imp_max) in rt5663_impedance_sensing()
1816 rt5663->imp_table[i].vol); in rt5663_impedance_sensing()
1818 rt5663->imp_table[i].vol); in rt5663_impedance_sensing()
1820 if (rt5663->jack_type == SND_JACK_HEADSET) { in rt5663_impedance_sensing()
1822 rt5663->imp_table[i].dc_offset_l_manual_mic >> 16); in rt5663_impedance_sensing()
1824 rt5663->imp_table[i].dc_offset_l_manual_mic & 0xffff); in rt5663_impedance_sensing()
1826 rt5663->imp_table[i].dc_offset_r_manual_mic >> 16); in rt5663_impedance_sensing()
1828 rt5663->imp_table[i].dc_offset_r_manual_mic & 0xffff); in rt5663_impedance_sensing()
1831 rt5663->imp_table[i].dc_offset_l_manual >> 16); in rt5663_impedance_sensing()
1833 rt5663->imp_table[i].dc_offset_l_manual & 0xffff); in rt5663_impedance_sensing()
1835 rt5663->imp_table[i].dc_offset_r_manual >> 16); in rt5663_impedance_sensing()
1837 rt5663->imp_table[i].dc_offset_r_manual & 0xffff); in rt5663_impedance_sensing()
1848 dev_dbg(component->dev, "%s: val=0x%x\n", __func__, val); in rt5663_button_detect()
1859 dev_dbg(regmap_get_device(rt5663->regmap), "%s IRQ queue work\n", in rt5663_irq()
1862 queue_delayed_work(system_wq, &rt5663->jack_detect_work, in rt5663_irq()
1873 rt5663->hs_jack = hs_jack; in rt5663_set_jack_detect()
1885 dev_dbg(component->dev, "%s val=%x\n", __func__, val); in rt5663_check_jd_status()
1888 switch (rt5663->codec_ver) { in rt5663_check_jd_status()
1894 dev_err(component->dev, "Unknown CODEC Version\n"); in rt5663_check_jd_status()
1904 struct snd_soc_component *component = rt5663->component; in rt5663_jack_detect_work()
1911 /* jack in */ in rt5663_jack_detect_work()
1912 if (rt5663->jack_type == 0) { in rt5663_jack_detect_work()
1913 /* jack was out, report jack type */ in rt5663_jack_detect_work()
1914 switch (rt5663->codec_ver) { in rt5663_jack_detect_work()
1917 rt5663->component, 1); in rt5663_jack_detect_work()
1920 report = rt5663_jack_detect(rt5663->component, 1); in rt5663_jack_detect_work()
1921 if (rt5663->pdata.impedance_sensing_num) in rt5663_jack_detect_work()
1922 rt5663_impedance_sensing(rt5663->component); in rt5663_jack_detect_work()
1925 dev_err(component->dev, "Unknown CODEC Version\n"); in rt5663_jack_detect_work()
1928 /* Delay the jack insert report to avoid pop noise */ in rt5663_jack_detect_work()
1931 /* jack is already in, report button event */ in rt5663_jack_detect_work()
1933 btn_type = rt5663_button_detect(rt5663->component); in rt5663_jack_detect_work()
1966 dev_err(rt5663->component->dev, in rt5663_jack_detect_work()
1973 report = rt5663->jack_type; in rt5663_jack_detect_work()
1975 &rt5663->jd_unplug_work); in rt5663_jack_detect_work()
1978 &rt5663->jd_unplug_work, in rt5663_jack_detect_work()
1983 /* jack out */ in rt5663_jack_detect_work()
1984 switch (rt5663->codec_ver) { in rt5663_jack_detect_work()
1986 report = rt5663_v2_jack_detect(rt5663->component, 0); in rt5663_jack_detect_work()
1989 report = rt5663_jack_detect(rt5663->component, 0); in rt5663_jack_detect_work()
1992 dev_err(component->dev, "Unknown CODEC Version\n"); in rt5663_jack_detect_work()
1995 dev_dbg(component->dev, "%s jack report: 0x%04x\n", __func__, report); in rt5663_jack_detect_work()
1996 snd_soc_jack_report(rt5663->hs_jack, report, SND_JACK_HEADSET | in rt5663_jack_detect_work()
2005 struct snd_soc_component *component = rt5663->component; in rt5663_jd_unplug_work()
2011 /* jack out */ in rt5663_jd_unplug_work()
2012 switch (rt5663->codec_ver) { in rt5663_jd_unplug_work()
2014 rt5663_v2_jack_detect(rt5663->component, 0); in rt5663_jd_unplug_work()
2017 rt5663_jack_detect(rt5663->component, 0); in rt5663_jd_unplug_work()
2020 dev_err(component->dev, "Unknown CODEC Version\n"); in rt5663_jd_unplug_work()
2023 snd_soc_jack_report(rt5663->hs_jack, 0, SND_JACK_HEADSET | in rt5663_jd_unplug_work()
2027 queue_delayed_work(system_wq, &rt5663->jd_unplug_work, in rt5663_jd_unplug_work()
2074 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in rt5663_is_sys_clk_from_pll()
2088 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in rt5663_is_using_asrc()
2091 if (rt5663->codec_ver == CODEC_VER_1) { in rt5663_is_using_asrc()
2092 switch (w->shift) { in rt5663_is_using_asrc()
2105 switch (w->shift) { in rt5663_is_using_asrc()
2130 struct snd_soc_component *component = snd_soc_dapm_to_component(source->dapm); in rt5663_i2s_use_asrc()
2136 switch (rt5663->codec_ver) { in rt5663_i2s_use_asrc()
2146 dev_err(component->dev, "Unknown CODEC Version\n"); in rt5663_i2s_use_asrc()
2151 if (rt5663->sysclk > rt5663->lrck * 384) in rt5663_i2s_use_asrc()
2154 dev_err(component->dev, "sysclk < 384 x fs, disable i2s asrc\n"); in rt5663_i2s_use_asrc()
2160 * rt5663_sel_asrc_clk_src - select ASRC clock source for a set of filters
2188 return -EINVAL; in rt5663_sel_asrc_clk_src()
2197 switch (rt5663->codec_ver) { in rt5663_sel_asrc_clk_src()
2207 dev_err(component->dev, "Unknown CODEC Version\n"); in rt5663_sel_asrc_clk_src()
2322 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in rt5663_hp_event()
2327 if (rt5663->codec_ver == CODEC_VER_1) { in rt5663_hp_event()
2355 if (rt5663->codec_ver == CODEC_VER_1) { in rt5663_hp_event()
2380 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in rt5663_charge_pump_event()
2385 if (rt5663->codec_ver == CODEC_VER_0) { in rt5663_charge_pump_event()
2394 if (rt5663->codec_ver == CODEC_VER_0) { in rt5663_charge_pump_event()
2410 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in rt5663_bst2_power()
2434 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in rt5663_pre_div_power()
2766 struct snd_soc_component *component = dai->component; in rt5663_hw_params()
2771 rt5663->lrck = params_rate(params); in rt5663_hw_params()
2773 dev_dbg(dai->dev, "bclk is %dHz and sysclk is %dHz\n", in rt5663_hw_params()
2774 rt5663->lrck, rt5663->sysclk); in rt5663_hw_params()
2776 pre_div = rl6231_get_clk_info(rt5663->sysclk, rt5663->lrck); in rt5663_hw_params()
2778 dev_err(component->dev, "Unsupported clock setting %d for DAI %d\n", in rt5663_hw_params()
2779 rt5663->lrck, dai->id); in rt5663_hw_params()
2780 return -EINVAL; in rt5663_hw_params()
2783 dev_dbg(dai->dev, "pre_div is %d for iis %d\n", pre_div, dai->id); in rt5663_hw_params()
2799 return -EINVAL; in rt5663_hw_params()
2813 struct snd_soc_component *component = dai->component; in rt5663_set_dai_fmt()
2823 return -EINVAL; in rt5663_set_dai_fmt()
2833 return -EINVAL; in rt5663_set_dai_fmt()
2849 return -EINVAL; in rt5663_set_dai_fmt()
2861 struct snd_soc_component *component = dai->component; in rt5663_set_dai_sysclk()
2865 if (freq == rt5663->sysclk && clk_id == rt5663->sysclk_src) in rt5663_set_dai_sysclk()
2879 dev_err(component->dev, "Invalid clock id (%d)\n", clk_id); in rt5663_set_dai_sysclk()
2880 return -EINVAL; in rt5663_set_dai_sysclk()
2884 rt5663->sysclk = freq; in rt5663_set_dai_sysclk()
2885 rt5663->sysclk_src = clk_id; in rt5663_set_dai_sysclk()
2887 dev_dbg(component->dev, "Sysclk is %dHz and clock id is %d\n", in rt5663_set_dai_sysclk()
2896 struct snd_soc_component *component = dai->component; in rt5663_set_dai_pll()
2902 if (source == rt5663->pll_src && freq_in == rt5663->pll_in && in rt5663_set_dai_pll()
2903 freq_out == rt5663->pll_out) in rt5663_set_dai_pll()
2907 dev_dbg(component->dev, "PLL disabled\n"); in rt5663_set_dai_pll()
2909 rt5663->pll_in = 0; in rt5663_set_dai_pll()
2910 rt5663->pll_out = 0; in rt5663_set_dai_pll()
2916 switch (rt5663->codec_ver) { in rt5663_set_dai_pll()
2926 dev_err(component->dev, "Unknown CODEC Version\n"); in rt5663_set_dai_pll()
2927 return -EINVAL; in rt5663_set_dai_pll()
2938 dev_err(component->dev, "Unknown PLL source %d\n", source); in rt5663_set_dai_pll()
2939 return -EINVAL; in rt5663_set_dai_pll()
2945 dev_err(component->dev, "Unsupported input clock %d\n", freq_in); in rt5663_set_dai_pll()
2949 dev_dbg(component->dev, "bypass=%d m=%d n=%d k=%d\n", pll_code.m_bp, in rt5663_set_dai_pll()
2959 rt5663->pll_in = freq_in; in rt5663_set_dai_pll()
2960 rt5663->pll_out = freq_out; in rt5663_set_dai_pll()
2961 rt5663->pll_src = source; in rt5663_set_dai_pll()
2969 struct snd_soc_component *component = dai->component; in rt5663_set_tdm_slot()
2992 return -EINVAL; in rt5663_set_tdm_slot()
3011 return -EINVAL; in rt5663_set_tdm_slot()
3014 switch (rt5663->codec_ver) { in rt5663_set_tdm_slot()
3022 dev_err(component->dev, "Unknown CODEC Version\n"); in rt5663_set_tdm_slot()
3023 return -EINVAL; in rt5663_set_tdm_slot()
3035 struct snd_soc_component *component = dai->component; in rt5663_set_bclk_ratio()
3039 dev_dbg(component->dev, "%s ratio = %d\n", __func__, ratio); in rt5663_set_bclk_ratio()
3041 if (rt5663->codec_ver == CODEC_VER_1) in rt5663_set_bclk_ratio()
3068 dev_err(component->dev, "Invalid ratio!\n"); in rt5663_set_bclk_ratio()
3069 return -EINVAL; in rt5663_set_bclk_ratio()
3088 if (rt5663->codec_ver == CODEC_VER_1) { in rt5663_set_bias_level()
3101 if (rt5663->codec_ver == CODEC_VER_1) in rt5663_set_bias_level()
3111 if (rt5663->codec_ver == CODEC_VER_1) { in rt5663_set_bias_level()
3121 if (rt5663->jack_type != SND_JACK_HEADSET) in rt5663_set_bias_level()
3146 rt5663->component = component; in rt5663_probe()
3148 switch (rt5663->codec_ver) { in rt5663_probe()
3169 if (!rt5663->imp_table) in rt5663_probe()
3182 regmap_write(rt5663->regmap, RT5663_RESET, 0); in rt5663_remove()
3190 if (rt5663->irq) in rt5663_suspend()
3191 disable_irq(rt5663->irq); in rt5663_suspend()
3193 cancel_delayed_work_sync(&rt5663->jack_detect_work); in rt5663_suspend()
3194 cancel_delayed_work_sync(&rt5663->jd_unplug_work); in rt5663_suspend()
3196 regcache_cache_only(rt5663->regmap, true); in rt5663_suspend()
3197 regcache_mark_dirty(rt5663->regmap); in rt5663_suspend()
3206 regcache_cache_only(rt5663->regmap, false); in rt5663_resume()
3207 regcache_sync(rt5663->regmap); in rt5663_resume()
3211 if (rt5663->irq) in rt5663_resume()
3212 enable_irq(rt5663->irq); in rt5663_resume()
3236 .name = "rt5663-aif",
3333 regmap_write(rt5663->regmap, RT5663_BIAS_CUR_8, 0xa402); in rt5663_v2_calibrate()
3334 regmap_write(rt5663->regmap, RT5663_PWR_DIG_1, 0x0100); in rt5663_v2_calibrate()
3335 regmap_write(rt5663->regmap, RT5663_RECMIX, 0x4040); in rt5663_v2_calibrate()
3336 regmap_write(rt5663->regmap, RT5663_DIG_MISC, 0x0001); in rt5663_v2_calibrate()
3337 regmap_write(rt5663->regmap, RT5663_RC_CLK, 0x0380); in rt5663_v2_calibrate()
3338 regmap_write(rt5663->regmap, RT5663_GLB_CLK, 0x8000); in rt5663_v2_calibrate()
3339 regmap_write(rt5663->regmap, RT5663_ADDA_CLK_1, 0x1000); in rt5663_v2_calibrate()
3340 regmap_write(rt5663->regmap, RT5663_CHOP_DAC_L, 0x3030); in rt5663_v2_calibrate()
3341 regmap_write(rt5663->regmap, RT5663_CALIB_ADC, 0x3c05); in rt5663_v2_calibrate()
3342 regmap_write(rt5663->regmap, RT5663_PWR_ANLG_1, 0xa23e); in rt5663_v2_calibrate()
3344 regmap_write(rt5663->regmap, RT5663_PWR_ANLG_1, 0xf23e); in rt5663_v2_calibrate()
3345 regmap_write(rt5663->regmap, RT5663_HP_CALIB_2, 0x0321); in rt5663_v2_calibrate()
3346 regmap_write(rt5663->regmap, RT5663_HP_CALIB_1, 0xfc00); in rt5663_v2_calibrate()
3354 regmap_write(rt5663->regmap, RT5663_RESET, 0x0000); in rt5663_calibrate()
3356 regmap_write(rt5663->regmap, RT5663_ANA_BIAS_CUR_4, 0x00a1); in rt5663_calibrate()
3357 regmap_write(rt5663->regmap, RT5663_RC_CLK, 0x0380); in rt5663_calibrate()
3358 regmap_write(rt5663->regmap, RT5663_GLB_CLK, 0x8000); in rt5663_calibrate()
3359 regmap_write(rt5663->regmap, RT5663_ADDA_CLK_1, 0x1000); in rt5663_calibrate()
3360 regmap_write(rt5663->regmap, RT5663_VREF_RECMIX, 0x0032); in rt5663_calibrate()
3361 regmap_write(rt5663->regmap, RT5663_HP_IMP_SEN_19, 0x000c); in rt5663_calibrate()
3362 regmap_write(rt5663->regmap, RT5663_DUMMY_1, 0x0324); in rt5663_calibrate()
3363 regmap_write(rt5663->regmap, RT5663_DIG_MISC, 0x8001); in rt5663_calibrate()
3364 regmap_write(rt5663->regmap, RT5663_VREFADJ_OP, 0x0f28); in rt5663_calibrate()
3365 regmap_write(rt5663->regmap, RT5663_PWR_ANLG_1, 0xa23b); in rt5663_calibrate()
3367 regmap_write(rt5663->regmap, RT5663_PWR_ANLG_1, 0xf23b); in rt5663_calibrate()
3368 regmap_write(rt5663->regmap, RT5663_PWR_ANLG_2, 0x8000); in rt5663_calibrate()
3369 regmap_write(rt5663->regmap, RT5663_PWR_ANLG_3, 0x0008); in rt5663_calibrate()
3370 regmap_write(rt5663->regmap, RT5663_PRE_DIV_GATING_1, 0xffff); in rt5663_calibrate()
3371 regmap_write(rt5663->regmap, RT5663_PRE_DIV_GATING_2, 0xffff); in rt5663_calibrate()
3372 regmap_write(rt5663->regmap, RT5663_CBJ_1, 0x8c10); in rt5663_calibrate()
3373 regmap_write(rt5663->regmap, RT5663_IL_CMD_2, 0x00c1); in rt5663_calibrate()
3374 regmap_write(rt5663->regmap, RT5663_EM_JACK_TYPE_1, 0xb880); in rt5663_calibrate()
3375 regmap_write(rt5663->regmap, RT5663_EM_JACK_TYPE_2, 0x4110); in rt5663_calibrate()
3376 regmap_write(rt5663->regmap, RT5663_EM_JACK_TYPE_2, 0x4118); in rt5663_calibrate()
3380 regmap_read(rt5663->regmap, RT5663_INT_ST_2, &value); in rt5663_calibrate()
3390 regmap_write(rt5663->regmap, RT5663_HP_IMP_SEN_19, 0x0000); in rt5663_calibrate()
3391 regmap_write(rt5663->regmap, RT5663_DEPOP_2, 0x3003); in rt5663_calibrate()
3392 regmap_write(rt5663->regmap, RT5663_DEPOP_1, 0x0038); in rt5663_calibrate()
3393 regmap_write(rt5663->regmap, RT5663_DEPOP_1, 0x003b); in rt5663_calibrate()
3394 regmap_write(rt5663->regmap, RT5663_PWR_DIG_2, 0x8400); in rt5663_calibrate()
3395 regmap_write(rt5663->regmap, RT5663_PWR_DIG_1, 0x8df8); in rt5663_calibrate()
3396 regmap_write(rt5663->regmap, RT5663_PWR_ANLG_2, 0x8003); in rt5663_calibrate()
3397 regmap_write(rt5663->regmap, RT5663_PWR_ANLG_3, 0x018c); in rt5663_calibrate()
3398 regmap_write(rt5663->regmap, RT5663_HP_CHARGE_PUMP_1, 0x1e32); in rt5663_calibrate()
3399 regmap_write(rt5663->regmap, RT5663_DUMMY_2, 0x8089); in rt5663_calibrate()
3400 regmap_write(rt5663->regmap, RT5663_DACREF_LDO, 0x3b0b); in rt5663_calibrate()
3402 regmap_write(rt5663->regmap, RT5663_STO_DAC_MIXER, 0x0000); in rt5663_calibrate()
3403 regmap_write(rt5663->regmap, RT5663_BYPASS_STO_DAC, 0x000c); in rt5663_calibrate()
3404 regmap_write(rt5663->regmap, RT5663_HP_BIAS, 0xafaa); in rt5663_calibrate()
3405 regmap_write(rt5663->regmap, RT5663_CHARGE_PUMP_1, 0x2224); in rt5663_calibrate()
3406 regmap_write(rt5663->regmap, RT5663_HP_OUT_EN, 0x8088); in rt5663_calibrate()
3407 regmap_write(rt5663->regmap, RT5663_STO_DRE_9, 0x0017); in rt5663_calibrate()
3408 regmap_write(rt5663->regmap, RT5663_STO_DRE_10, 0x0017); in rt5663_calibrate()
3409 regmap_write(rt5663->regmap, RT5663_STO1_ADC_MIXER, 0x4040); in rt5663_calibrate()
3410 regmap_write(rt5663->regmap, RT5663_CHOP_ADC, 0x3000); in rt5663_calibrate()
3411 regmap_write(rt5663->regmap, RT5663_RECMIX, 0x0005); in rt5663_calibrate()
3412 regmap_write(rt5663->regmap, RT5663_ADDA_RST, 0xc000); in rt5663_calibrate()
3413 regmap_write(rt5663->regmap, RT5663_STO1_HPF_ADJ1, 0x3320); in rt5663_calibrate()
3414 regmap_write(rt5663->regmap, RT5663_HP_CALIB_2, 0x00c9); in rt5663_calibrate()
3415 regmap_write(rt5663->regmap, RT5663_DUMMY_1, 0x004c); in rt5663_calibrate()
3416 regmap_write(rt5663->regmap, RT5663_ANA_BIAS_CUR_1, 0x1111); in rt5663_calibrate()
3417 regmap_write(rt5663->regmap, RT5663_BIAS_CUR_8, 0x4402); in rt5663_calibrate()
3418 regmap_write(rt5663->regmap, RT5663_CHARGE_PUMP_2, 0x3311); in rt5663_calibrate()
3419 regmap_write(rt5663->regmap, RT5663_HP_CALIB_1, 0x0069); in rt5663_calibrate()
3420 regmap_write(rt5663->regmap, RT5663_HP_CALIB_3, 0x06ce); in rt5663_calibrate()
3421 regmap_write(rt5663->regmap, RT5663_HP_CALIB_1_1, 0x6800); in rt5663_calibrate()
3422 regmap_write(rt5663->regmap, RT5663_CHARGE_PUMP_2, 0x1100); in rt5663_calibrate()
3423 regmap_write(rt5663->regmap, RT5663_HP_CALIB_7, 0x0057); in rt5663_calibrate()
3424 regmap_write(rt5663->regmap, RT5663_HP_CALIB_1_1, 0xe800); in rt5663_calibrate()
3428 regmap_read(rt5663->regmap, RT5663_HP_CALIB_1_1, &value); in rt5663_calibrate()
3439 regmap_write(rt5663->regmap, RT5663_HP_CALIB_1_1, 0x6200); in rt5663_calibrate()
3440 regmap_write(rt5663->regmap, RT5663_HP_CALIB_7, 0x0059); in rt5663_calibrate()
3441 regmap_write(rt5663->regmap, RT5663_HP_CALIB_1_1, 0xe200); in rt5663_calibrate()
3445 regmap_read(rt5663->regmap, RT5663_HP_CALIB_1_1, &value); in rt5663_calibrate()
3456 regmap_write(rt5663->regmap, RT5663_EM_JACK_TYPE_1, 0xb8e0); in rt5663_calibrate()
3458 regmap_write(rt5663->regmap, RT5663_PWR_ANLG_1, 0x003b); in rt5663_calibrate()
3460 regmap_write(rt5663->regmap, RT5663_PWR_DIG_1, 0x0000); in rt5663_calibrate()
3462 regmap_write(rt5663->regmap, RT5663_DEPOP_1, 0x000b); in rt5663_calibrate()
3464 regmap_write(rt5663->regmap, RT5663_DEPOP_1, 0x0008); in rt5663_calibrate()
3466 regmap_write(rt5663->regmap, RT5663_PWR_ANLG_2, 0x0000); in rt5663_calibrate()
3476 &rt5663->pdata.dc_offset_l_manual); in rt5663_parse_dp()
3478 &rt5663->pdata.dc_offset_r_manual); in rt5663_parse_dp()
3480 &rt5663->pdata.dc_offset_l_manual_mic); in rt5663_parse_dp()
3482 &rt5663->pdata.dc_offset_r_manual_mic); in rt5663_parse_dp()
3484 &rt5663->pdata.impedance_sensing_num); in rt5663_parse_dp()
3486 if (rt5663->pdata.impedance_sensing_num) { in rt5663_parse_dp()
3488 rt5663->pdata.impedance_sensing_num; in rt5663_parse_dp()
3489 rt5663->imp_table = devm_kzalloc(dev, table_size, GFP_KERNEL); in rt5663_parse_dp()
3490 if (!rt5663->imp_table) in rt5663_parse_dp()
3491 return -ENOMEM; in rt5663_parse_dp()
3494 (u32 *)rt5663->imp_table, table_size); in rt5663_parse_dp()
3504 struct rt5663_platform_data *pdata = dev_get_platdata(&i2c->dev); in rt5663_i2c_probe()
3510 rt5663 = devm_kzalloc(&i2c->dev, sizeof(struct rt5663_priv), in rt5663_i2c_probe()
3514 return -ENOMEM; in rt5663_i2c_probe()
3519 rt5663->pdata = *pdata; in rt5663_i2c_probe()
3521 ret = rt5663_parse_dp(rt5663, &i2c->dev); in rt5663_i2c_probe()
3526 for (i = 0; i < ARRAY_SIZE(rt5663->supplies); i++) in rt5663_i2c_probe()
3527 rt5663->supplies[i].supply = rt5663_supply_names[i]; in rt5663_i2c_probe()
3529 ret = devm_regulator_bulk_get(&i2c->dev, in rt5663_i2c_probe()
3530 ARRAY_SIZE(rt5663->supplies), in rt5663_i2c_probe()
3531 rt5663->supplies); in rt5663_i2c_probe()
3533 dev_err(&i2c->dev, "Failed to request supplies: %d\n", ret); in rt5663_i2c_probe()
3538 for (i = 0; i < ARRAY_SIZE(rt5663->supplies); i++) { in rt5663_i2c_probe()
3539 ret = regulator_set_load(rt5663->supplies[i].consumer, in rt5663_i2c_probe()
3542 dev_err(&i2c->dev, in rt5663_i2c_probe()
3544 rt5663->supplies[i].supply, ret); in rt5663_i2c_probe()
3549 ret = regulator_bulk_enable(ARRAY_SIZE(rt5663->supplies), in rt5663_i2c_probe()
3550 rt5663->supplies); in rt5663_i2c_probe()
3553 dev_err(&i2c->dev, "Failed to enable supplies: %d\n", ret); in rt5663_i2c_probe()
3561 dev_err(&i2c->dev, "Failed to allocate temp register map: %d\n", in rt5663_i2c_probe()
3568 dev_err(&i2c->dev, in rt5663_i2c_probe()
3577 rt5663->regmap = devm_regmap_init_i2c(i2c, &rt5663_v2_regmap); in rt5663_i2c_probe()
3578 rt5663->codec_ver = CODEC_VER_1; in rt5663_i2c_probe()
3581 rt5663->regmap = devm_regmap_init_i2c(i2c, &rt5663_regmap); in rt5663_i2c_probe()
3582 rt5663->codec_ver = CODEC_VER_0; in rt5663_i2c_probe()
3585 dev_err(&i2c->dev, in rt5663_i2c_probe()
3588 ret = -ENODEV; in rt5663_i2c_probe()
3592 if (IS_ERR(rt5663->regmap)) { in rt5663_i2c_probe()
3593 ret = PTR_ERR(rt5663->regmap); in rt5663_i2c_probe()
3594 dev_err(&i2c->dev, "Failed to allocate register map: %d\n", in rt5663_i2c_probe()
3600 regmap_write(rt5663->regmap, RT5663_RESET, 0); in rt5663_i2c_probe()
3601 regcache_cache_bypass(rt5663->regmap, true); in rt5663_i2c_probe()
3602 switch (rt5663->codec_ver) { in rt5663_i2c_probe()
3610 dev_err(&i2c->dev, "%s:Unknown codec type\n", __func__); in rt5663_i2c_probe()
3612 regcache_cache_bypass(rt5663->regmap, false); in rt5663_i2c_probe()
3613 regmap_write(rt5663->regmap, RT5663_RESET, 0); in rt5663_i2c_probe()
3614 dev_dbg(&i2c->dev, "calibrate done\n"); in rt5663_i2c_probe()
3616 switch (rt5663->codec_ver) { in rt5663_i2c_probe()
3620 ret = regmap_register_patch(rt5663->regmap, rt5663_patch_list, in rt5663_i2c_probe()
3623 dev_warn(&i2c->dev, in rt5663_i2c_probe()
3627 dev_err(&i2c->dev, "%s:Unknown codec type\n", __func__); in rt5663_i2c_probe()
3631 regmap_update_bits(rt5663->regmap, RT5663_GPIO_1, RT5663_GP1_PIN_MASK, in rt5663_i2c_probe()
3633 /* 4btn inline command debounce */ in rt5663_i2c_probe()
3634 regmap_update_bits(rt5663->regmap, RT5663_IL_CMD_5, in rt5663_i2c_probe()
3637 switch (rt5663->codec_ver) { in rt5663_i2c_probe()
3639 regmap_write(rt5663->regmap, RT5663_BIAS_CUR_8, 0xa402); in rt5663_i2c_probe()
3641 regmap_update_bits(rt5663->regmap, RT5663_AUTO_1MRC_CLK, in rt5663_i2c_probe()
3644 regmap_update_bits(rt5663->regmap, RT5663_PWR_ANLG_2, in rt5663_i2c_probe()
3646 regmap_update_bits(rt5663->regmap, RT5663_IRQ_1, in rt5663_i2c_probe()
3649 regmap_update_bits(rt5663->regmap, RT5663_HP_LOGIC_2, in rt5663_i2c_probe()
3651 regmap_update_bits(rt5663->regmap, RT5663_RECMIX, in rt5663_i2c_probe()
3655 /* Set GPIO4 and GPIO8 as input for combo jack */ in rt5663_i2c_probe()
3656 regmap_update_bits(rt5663->regmap, RT5663_GPIO_2, in rt5663_i2c_probe()
3658 regmap_update_bits(rt5663->regmap, RT5663_GPIO_3, in rt5663_i2c_probe()
3660 regmap_update_bits(rt5663->regmap, RT5663_PWR_ANLG_1, in rt5663_i2c_probe()
3665 regmap_update_bits(rt5663->regmap, RT5663_DIG_MISC, in rt5663_i2c_probe()
3667 regmap_update_bits(rt5663->regmap, RT5663_AUTO_1MRC_CLK, in rt5663_i2c_probe()
3669 regmap_update_bits(rt5663->regmap, RT5663_IRQ_1, in rt5663_i2c_probe()
3671 regmap_update_bits(rt5663->regmap, RT5663_GPIO_1, in rt5663_i2c_probe()
3673 regmap_write(rt5663->regmap, RT5663_VREF_RECMIX, 0x0032); in rt5663_i2c_probe()
3674 regmap_update_bits(rt5663->regmap, RT5663_GPIO_2, in rt5663_i2c_probe()
3677 regmap_update_bits(rt5663->regmap, RT5663_RECMIX, in rt5663_i2c_probe()
3679 regmap_update_bits(rt5663->regmap, RT5663_TDM_2, in rt5663_i2c_probe()
3684 dev_err(&i2c->dev, "%s:Unknown codec type\n", __func__); in rt5663_i2c_probe()
3687 INIT_DELAYED_WORK(&rt5663->jack_detect_work, rt5663_jack_detect_work); in rt5663_i2c_probe()
3688 INIT_DELAYED_WORK(&rt5663->jd_unplug_work, rt5663_jd_unplug_work); in rt5663_i2c_probe()
3690 if (i2c->irq) { in rt5663_i2c_probe()
3691 ret = request_irq(i2c->irq, rt5663_irq, in rt5663_i2c_probe()
3695 dev_err(&i2c->dev, "%s Failed to request IRQ: %d\n", in rt5663_i2c_probe()
3699 rt5663->irq = i2c->irq; in rt5663_i2c_probe()
3702 ret = devm_snd_soc_register_component(&i2c->dev, in rt5663_i2c_probe()
3717 if (i2c->irq) in rt5663_i2c_probe()
3718 free_irq(i2c->irq, rt5663); in rt5663_i2c_probe()
3720 regulator_bulk_disable(ARRAY_SIZE(rt5663->supplies), rt5663->supplies); in rt5663_i2c_probe()
3728 if (i2c->irq) in rt5663_i2c_remove()
3729 free_irq(i2c->irq, rt5663); in rt5663_i2c_remove()
3731 regulator_bulk_disable(ARRAY_SIZE(rt5663->supplies), rt5663->supplies); in rt5663_i2c_remove()
3738 regmap_write(rt5663->regmap, RT5663_RESET, 0); in rt5663_i2c_shutdown()
3755 MODULE_AUTHOR("Jack Yu <jack.yu@realtek.com>");