Lines Matching +full:codec +full:- +full:aif2 +full:- +full:bclk

1 // SPDX-License-Identifier: GPL-2.0-only
3 // rt5682s.c -- RT5682I-VS ALSA SoC audio component driver
25 #include <sound/soc-dapm.h>
38 .dai_clk_names[RT5682S_DAI_WCLK_IDX] = "rt5682-dai-wclk",
39 .dai_clk_names[RT5682S_DAI_BCLK_IDX] = "rt5682-dai-bclk",
46 [RT5682S_SUPPLY_LDO1_IN] = "LDO1-IN",
69 ret = regmap_multi_reg_write(rt5682s->regmap, patch_list, ARRAY_SIZE(patch_list)); in rt5682s_apply_patch_list()
624 regmap_write(rt5682s->regmap, RT5682S_RESET, 0); in rt5682s_reset()
634 dev_dbg(component->dev, "%s btn_type=%x\n", __func__, btn_type); in rt5682s_button_detect()
651 mutex_lock(&rt5682s->sar_mutex); in rt5682s_sar_power_mode()
694 dev_err(component->dev, "Invalid SAR Power mode: %d\n", mode); in rt5682s_sar_power_mode()
698 mutex_unlock(&rt5682s->sar_mutex); in rt5682s_sar_power_mode()
732 * rt5682s_headset_detect - Detect headset.
781 dev_dbg(component->dev, "%s, val=%d, count=%d\n", __func__, val, count); in rt5682s_headset_detect()
809 if (!rt5682s->wclk_enabled) { in rt5682s_headset_detect()
823 dev_dbg(component->dev, "jack_type = %d\n", jack_type); in rt5682s_headset_detect()
835 if (!rt5682s->component || in rt5682s_jack_detect_handler()
836 !snd_soc_card_is_instantiated(rt5682s->component->card)) { in rt5682s_jack_detect_handler()
839 &rt5682s->jack_detect_work, msecs_to_jiffies(15)); in rt5682s_jack_detect_handler()
843 dapm = snd_soc_component_get_dapm(rt5682s->component); in rt5682s_jack_detect_handler()
846 mutex_lock(&rt5682s->calibrate_mutex); in rt5682s_jack_detect_handler()
847 mutex_lock(&rt5682s->wclk_mutex); in rt5682s_jack_detect_handler()
849 val = snd_soc_component_read(rt5682s->component, RT5682S_AJD1_CTRL) in rt5682s_jack_detect_handler()
853 if (rt5682s->jack_type == 0) { in rt5682s_jack_detect_handler()
855 rt5682s->jack_type = rt5682s_headset_detect(rt5682s->component, 1); in rt5682s_jack_detect_handler()
856 rt5682s->irq_work_delay_time = 0; in rt5682s_jack_detect_handler()
857 } else if ((rt5682s->jack_type & SND_JACK_HEADSET) == SND_JACK_HEADSET) { in rt5682s_jack_detect_handler()
859 rt5682s->jack_type = SND_JACK_HEADSET; in rt5682s_jack_detect_handler()
860 btn_type = rt5682s_button_detect(rt5682s->component); in rt5682s_jack_detect_handler()
872 rt5682s->jack_type |= SND_JACK_BTN_0; in rt5682s_jack_detect_handler()
877 rt5682s->jack_type |= SND_JACK_BTN_1; in rt5682s_jack_detect_handler()
882 rt5682s->jack_type |= SND_JACK_BTN_2; in rt5682s_jack_detect_handler()
887 rt5682s->jack_type |= SND_JACK_BTN_3; in rt5682s_jack_detect_handler()
892 dev_err(rt5682s->component->dev, in rt5682s_jack_detect_handler()
899 rt5682s->jack_type = rt5682s_headset_detect(rt5682s->component, 0); in rt5682s_jack_detect_handler()
900 rt5682s->irq_work_delay_time = 50; in rt5682s_jack_detect_handler()
903 mutex_unlock(&rt5682s->wclk_mutex); in rt5682s_jack_detect_handler()
904 mutex_unlock(&rt5682s->calibrate_mutex); in rt5682s_jack_detect_handler()
907 snd_soc_jack_report(rt5682s->hs_jack, rt5682s->jack_type, in rt5682s_jack_detect_handler()
911 if (rt5682s->jack_type & (SND_JACK_BTN_0 | SND_JACK_BTN_1 | in rt5682s_jack_detect_handler()
913 schedule_delayed_work(&rt5682s->jd_check_work, 0); in rt5682s_jack_detect_handler()
915 cancel_delayed_work_sync(&rt5682s->jd_check_work); in rt5682s_jack_detect_handler()
923 if (snd_soc_component_read(rt5682s->component, RT5682S_AJD1_CTRL) & RT5682S_JDH_RS_MASK) { in rt5682s_jd_check_handler()
925 schedule_delayed_work(&rt5682s->jack_detect_work, 0); in rt5682s_jd_check_handler()
927 schedule_delayed_work(&rt5682s->jd_check_work, 500); in rt5682s_jd_check_handler()
935 mod_delayed_work(system_power_efficient_wq, &rt5682s->jack_detect_work, in rt5682s_irq()
936 msecs_to_jiffies(rt5682s->irq_work_delay_time)); in rt5682s_irq()
947 rt5682s->hs_jack = hs_jack; in rt5682s_set_jack_detect()
950 regmap_update_bits(rt5682s->regmap, RT5682S_IRQ_CTRL_2, in rt5682s_set_jack_detect()
952 regmap_update_bits(rt5682s->regmap, RT5682S_RC_CLK_CTRL, in rt5682s_set_jack_detect()
954 cancel_delayed_work_sync(&rt5682s->jack_detect_work); in rt5682s_set_jack_detect()
959 switch (rt5682s->pdata.jd_src) { in rt5682s_set_jack_detect()
961 regmap_update_bits(rt5682s->regmap, RT5682S_CBJ_CTRL_5, in rt5682s_set_jack_detect()
963 regmap_update_bits(rt5682s->regmap, RT5682S_CBJ_CTRL_2, in rt5682s_set_jack_detect()
965 regmap_update_bits(rt5682s->regmap, RT5682S_CBJ_CTRL_1, in rt5682s_set_jack_detect()
970 regmap_update_bits(rt5682s->regmap, RT5682S_SAR_IL_CMD_1, in rt5682s_set_jack_detect()
972 regmap_update_bits(rt5682s->regmap, RT5682S_GPIO_CTRL_1, in rt5682s_set_jack_detect()
974 regmap_update_bits(rt5682s->regmap, RT5682S_PWR_ANLG_3, in rt5682s_set_jack_detect()
976 regmap_update_bits(rt5682s->regmap, RT5682S_PWR_ANLG_2, in rt5682s_set_jack_detect()
978 regmap_update_bits(rt5682s->regmap, RT5682S_RC_CLK_CTRL, in rt5682s_set_jack_detect()
980 regmap_update_bits(rt5682s->regmap, RT5682S_IRQ_CTRL_2, in rt5682s_set_jack_detect()
983 regmap_update_bits(rt5682s->regmap, RT5682S_4BTN_IL_CMD_4, in rt5682s_set_jack_detect()
986 regmap_update_bits(rt5682s->regmap, RT5682S_4BTN_IL_CMD_5, in rt5682s_set_jack_detect()
989 regmap_update_bits(rt5682s->regmap, RT5682S_4BTN_IL_CMD_6, in rt5682s_set_jack_detect()
992 regmap_update_bits(rt5682s->regmap, RT5682S_4BTN_IL_CMD_7, in rt5682s_set_jack_detect()
997 &rt5682s->jack_detect_work, msecs_to_jiffies(250)); in rt5682s_set_jack_detect()
1001 regmap_update_bits(rt5682s->regmap, RT5682S_IRQ_CTRL_2, in rt5682s_set_jack_detect()
1003 regmap_update_bits(rt5682s->regmap, RT5682S_RC_CLK_CTRL, in rt5682s_set_jack_detect()
1008 dev_warn(component->dev, "Wrong JD source\n"); in rt5682s_set_jack_detect()
1015 static const DECLARE_TLV_DB_SCALE(dac_vol_tlv, -9562, 75, 0);
1016 static const DECLARE_TLV_DB_SCALE(adc_vol_tlv, -1725, 75, 0);
1018 static const DECLARE_TLV_DB_SCALE(cbj_bst_tlv, -1200, 150, 0);
1041 * rt5682s_sel_asrc_clk_src - select ASRC clock source for a set of filters
1050 * for codec. This function provides an API to select the clock source for a
1064 return -EINVAL; in rt5682s_sel_asrc_clk_src()
1089 if (rt5682s->sysclk < target) { in rt5682s_div_sel()
1090 dev_err(rt5682s->component->dev, in rt5682s_div_sel()
1091 "sysclk rate %d is too low\n", rt5682s->sysclk); in rt5682s_div_sel()
1095 for (i = 0; i < size - 1; i++) { in rt5682s_div_sel()
1096 dev_dbg(rt5682s->component->dev, "div[%d]=%d\n", i, div[i]); in rt5682s_div_sel()
1097 if (target * div[i] == rt5682s->sysclk) in rt5682s_div_sel()
1099 if (target * div[i + 1] > rt5682s->sysclk) { in rt5682s_div_sel()
1100 dev_dbg(rt5682s->component->dev, in rt5682s_div_sel()
1101 "can't find div for sysclk %d\n", rt5682s->sysclk); in rt5682s_div_sel()
1106 if (target * div[i] < rt5682s->sysclk) in rt5682s_div_sel()
1107 dev_err(rt5682s->component->dev, in rt5682s_div_sel()
1108 "sysclk rate %d is too high\n", rt5682s->sysclk); in rt5682s_div_sel()
1110 return size - 1; in rt5682s_div_sel()
1119 return -EINVAL; in get_clk_info()
1126 return -EINVAL; in get_clk_info()
1130 * set_dmic_clk - Set parameter of dmic.
1142 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in set_dmic_clk()
1147 if (rt5682s->pdata.dmic_clk_rate) in set_dmic_clk()
1148 dmic_clk_rate = rt5682s->pdata.dmic_clk_rate; in set_dmic_clk()
1161 struct snd_soc_component *component = rt5682s->component; in rt5682s_set_pllb_power()
1181 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in set_pllb_event()
1185 if (rt5682s->wclk_enabled) in set_pllb_event()
1198 struct snd_soc_component *component = rt5682s->component; in rt5682s_set_filter_clk()
1210 if (rt5682s->sysclk <= 12288000 * div_o[idx]) in rt5682s_set_filter_clk()
1222 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in set_filter_clk()
1229 if (w->shift == RT5682S_PWR_ADC_S1F_BIT && val == RT5682S_GP4_PIN_ADCDAT2) in set_filter_clk()
1230 ref = 256 * rt5682s->lrck[RT5682S_AIF2]; in set_filter_clk()
1232 ref = 256 * rt5682s->lrck[RT5682S_AIF1]; in set_filter_clk()
1234 if (w->shift == RT5682S_PWR_ADC_S1F_BIT) in set_filter_clk()
1247 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in set_dmic_power()
1251 if (rt5682s->pdata.dmic_delay) in set_dmic_power()
1252 delay = rt5682s->pdata.dmic_delay; in set_dmic_power()
1268 if (!rt5682s->jack_type && !rt5682s->wclk_enabled) { in set_dmic_power()
1280 struct snd_soc_component *component = rt5682s->component; in rt5682s_set_i2s()
1301 if (on && rt5682s->master[id]) { in rt5682s_set_i2s()
1302 pre_div = get_clk_info(rt5682s->sysclk, rt5682s->lrck[id]); in rt5682s_set_i2s()
1304 dev_err(component->dev, "get pre_div failed\n"); in rt5682s_set_i2s()
1308 dev_dbg(component->dev, "lrck is %dHz and pre_div is %d for iis %d master\n", in rt5682s_set_i2s()
1309 rt5682s->lrck[id], pre_div, id); in rt5682s_set_i2s()
1319 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in set_i2s_event()
1326 if (!snd_soc_dapm_widget_name_cmp(w, "I2S1") && !rt5682s->wclk_enabled) in set_i2s_event()
1337 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in is_sys_clk_from_plla()
1340 if ((rt5682s->sysclk_src == RT5682S_CLK_SRC_PLL1) || in is_sys_clk_from_plla()
1341 (rt5682s->sysclk_src == RT5682S_CLK_SRC_PLL2 && rt5682s->pll_comb == USE_PLLAB)) in is_sys_clk_from_plla()
1350 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in is_sys_clk_from_pllb()
1353 if (rt5682s->sysclk_src == RT5682S_CLK_SRC_PLL2) in is_sys_clk_from_pllb()
1363 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in is_using_asrc()
1365 switch (w->shift) { in is_using_asrc()
1391 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in rt5682s_hp_amp_event()
1436 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in rt5682s_stereo1_adc_mixl_event()
1440 if (rt5682s->pdata.amic_delay) in rt5682s_stereo1_adc_mixl_event()
1441 delay = rt5682s->pdata.amic_delay; in rt5682s_stereo1_adc_mixl_event()
1461 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in sar_power_event()
1464 if ((rt5682s->jack_type & SND_JACK_HEADSET) != SND_JACK_HEADSET) in sar_power_event()
1569 /* MX-26 [13] [5] */
1587 /* MX-26 [11:10] [3:2] */
1605 /* MX-26 [12] [4] */
1622 /* MX-79 [6:4] I2S1 ADC data location */
1639 /* MX-2B [4], MX-2B [0]*/
1799 SND_SOC_DAPM_AIF_OUT("AIF2TX", "AIF2 Capture", 0, RT5682S_I2S2_SDP,
1983 struct snd_soc_component *component = dai->component; in rt5682s_set_tdm_slot()
1997 dev_err(component->dev, "Invalid or oversized Tx slots.\n"); in rt5682s_set_tdm_slot()
1998 return -EINVAL; in rt5682s_set_tdm_slot()
2000 val |= (tx_slotnum - 1) << RT5682S_TDM_ADC_DL_SFT; in rt5682s_set_tdm_slot()
2019 return -EINVAL; in rt5682s_set_tdm_slot()
2029 return -EINVAL; in rt5682s_set_tdm_slot()
2049 return -EINVAL; in rt5682s_set_tdm_slot()
2063 struct snd_soc_component *component = dai->component; in rt5682s_hw_params()
2068 rt5682s->lrck[dai->id] = params_rate(params); in rt5682s_hw_params()
2072 dev_err(component->dev, "Unsupported frame size: %d\n", frame_size); in rt5682s_hw_params()
2073 return -EINVAL; in rt5682s_hw_params()
2096 return -EINVAL; in rt5682s_hw_params()
2099 switch (dai->id) { in rt5682s_hw_params()
2121 dev_err(component->dev, "Invalid dai->id: %d\n", dai->id); in rt5682s_hw_params()
2122 return -EINVAL; in rt5682s_hw_params()
2130 struct snd_soc_component *component = dai->component; in rt5682s_set_dai_fmt()
2136 rt5682s->master[dai->id] = 1; in rt5682s_set_dai_fmt()
2139 rt5682s->master[dai->id] = 0; in rt5682s_set_dai_fmt()
2142 return -EINVAL; in rt5682s_set_dai_fmt()
2153 if (dai->id == RT5682S_AIF1) in rt5682s_set_dai_fmt()
2156 return -EINVAL; in rt5682s_set_dai_fmt()
2159 if (dai->id == RT5682S_AIF1) in rt5682s_set_dai_fmt()
2163 return -EINVAL; in rt5682s_set_dai_fmt()
2166 return -EINVAL; in rt5682s_set_dai_fmt()
2185 return -EINVAL; in rt5682s_set_dai_fmt()
2188 switch (dai->id) { in rt5682s_set_dai_fmt()
2196 tdm_ctrl | rt5682s->master[dai->id]); in rt5682s_set_dai_fmt()
2199 if (rt5682s->master[dai->id] == 0) in rt5682s_set_dai_fmt()
2206 dev_err(component->dev, "Invalid dai->id: %d\n", dai->id); in rt5682s_set_dai_fmt()
2207 return -EINVAL; in rt5682s_set_dai_fmt()
2218 if (freq == rt5682s->sysclk && clk_id == rt5682s->sysclk_src) in rt5682s_set_component_sysclk()
2235 dev_err(component->dev, "Invalid clock id (%d)\n", clk_id); in rt5682s_set_component_sysclk()
2236 return -EINVAL; in rt5682s_set_component_sysclk()
2246 rt5682s->sysclk = freq; in rt5682s_set_component_sysclk()
2247 rt5682s->sysclk_src = clk_id; in rt5682s_set_component_sysclk()
2249 dev_dbg(component->dev, "Sysclk is %dHz and clock id is %d\n", in rt5682s_set_component_sysclk()
2313 for (i = ARRAY_SIZE(plla_table) - 1; i >= 0; i--) { in find_pll_inter_combination()
2315 for (j = ARRAY_SIZE(pllb_table) - 1; j >= 0; j--) { in find_pll_inter_combination()
2326 return -EINVAL; in find_pll_inter_combination()
2336 if (source == rt5682s->pll_src[pll_id] && freq_in == rt5682s->pll_in[pll_id] && in rt5682s_set_component_pll()
2337 freq_out == rt5682s->pll_out[pll_id]) in rt5682s_set_component_pll()
2341 dev_dbg(component->dev, "PLL disabled\n"); in rt5682s_set_component_pll()
2342 rt5682s->pll_in[pll_id] = 0; in rt5682s_set_component_pll()
2343 rt5682s->pll_out[pll_id] = 0; in rt5682s_set_component_pll()
2359 dev_err(component->dev, "Unknown PLL Source %d\n", source); in rt5682s_set_component_pll()
2360 return -EINVAL; in rt5682s_set_component_pll()
2363 rt5682s->pll_comb = find_pll_inter_combination(freq_in, freq_out, in rt5682s_set_component_pll()
2366 if ((pll_id == RT5682S_PLL1 && rt5682s->pll_comb == USE_PLLA) || in rt5682s_set_component_pll()
2367 (pll_id == RT5682S_PLL2 && (rt5682s->pll_comb == USE_PLLB || in rt5682s_set_component_pll()
2368 rt5682s->pll_comb == USE_PLLAB))) { in rt5682s_set_component_pll()
2369 dev_dbg(component->dev, in rt5682s_set_component_pll()
2370 "Supported freq conversion for PLL%d:(%d->%d): %d\n", in rt5682s_set_component_pll()
2371 pll_id + 1, freq_in, freq_out, rt5682s->pll_comb); in rt5682s_set_component_pll()
2373 dev_err(component->dev, in rt5682s_set_component_pll()
2374 "Unsupported freq conversion for PLL%d:(%d->%d): %d\n", in rt5682s_set_component_pll()
2375 pll_id + 1, freq_in, freq_out, rt5682s->pll_comb); in rt5682s_set_component_pll()
2376 return -EINVAL; in rt5682s_set_component_pll()
2379 if (rt5682s->pll_comb == USE_PLLA || rt5682s->pll_comb == USE_PLLAB) { in rt5682s_set_component_pll()
2380 dev_dbg(component->dev, in rt5682s_set_component_pll()
2395 if (rt5682s->pll_comb == USE_PLLB || rt5682s->pll_comb == USE_PLLAB) { in rt5682s_set_component_pll()
2396 dev_dbg(component->dev, in rt5682s_set_component_pll()
2415 if (rt5682s->pll_comb == USE_PLLB) in rt5682s_set_component_pll()
2419 rt5682s->pll_in[pll_id] = freq_in; in rt5682s_set_component_pll()
2420 rt5682s->pll_out[pll_id] = freq_out; in rt5682s_set_component_pll()
2421 rt5682s->pll_src[pll_id] = source; in rt5682s_set_component_pll()
2429 struct snd_soc_component *component = dai->component; in rt5682s_set_bclk1_ratio()
2432 rt5682s->bclk[dai->id] = ratio; in rt5682s_set_bclk1_ratio()
2452 dev_err(dai->dev, "Invalid bclk1 ratio %d\n", ratio); in rt5682s_set_bclk1_ratio()
2453 return -EINVAL; in rt5682s_set_bclk1_ratio()
2461 struct snd_soc_component *component = dai->component; in rt5682s_set_bclk2_ratio()
2464 rt5682s->bclk[dai->id] = ratio; in rt5682s_set_bclk2_ratio()
2476 dev_err(dai->dev, "Invalid bclk2 ratio %d\n", ratio); in rt5682s_set_bclk2_ratio()
2477 return -EINVAL; in rt5682s_set_bclk2_ratio()
2490 regmap_update_bits(rt5682s->regmap, RT5682S_PWR_DIG_1, in rt5682s_set_bias_level()
2495 regmap_update_bits(rt5682s->regmap, RT5682S_PWR_DIG_1, in rt5682s_set_bias_level()
2499 regmap_update_bits(rt5682s->regmap, RT5682S_PWR_DIG_1, RT5682S_PWR_LDO, 0); in rt5682s_set_bias_level()
2500 if (!rt5682s->wclk_enabled) in rt5682s_set_bias_level()
2501 regmap_update_bits(rt5682s->regmap, RT5682S_PWR_DIG_1, in rt5682s_set_bias_level()
2518 if (!rt5682s->master[RT5682S_AIF1]) { in rt5682s_clk_check()
2519 dev_dbg(rt5682s->component->dev, "dai clk fmt not set correctly\n"); in rt5682s_clk_check()
2529 struct snd_soc_component *component = rt5682s->component; in rt5682s_wclk_prepare()
2533 return -EINVAL; in rt5682s_wclk_prepare()
2535 mutex_lock(&rt5682s->wclk_mutex); in rt5682s_wclk_prepare()
2551 ref = 256 * rt5682s->lrck[RT5682S_AIF1]; in rt5682s_wclk_prepare()
2555 rt5682s->wclk_enabled = 1; in rt5682s_wclk_prepare()
2557 mutex_unlock(&rt5682s->wclk_mutex); in rt5682s_wclk_prepare()
2566 struct snd_soc_component *component = rt5682s->component; in rt5682s_wclk_unprepare()
2571 mutex_lock(&rt5682s->wclk_mutex); in rt5682s_wclk_unprepare()
2573 if (!rt5682s->jack_type) in rt5682s_wclk_unprepare()
2585 rt5682s->wclk_enabled = 0; in rt5682s_wclk_unprepare()
2587 mutex_unlock(&rt5682s->wclk_mutex); in rt5682s_wclk_unprepare()
2595 struct snd_soc_component *component = rt5682s->component; in rt5682s_wclk_recalc_rate()
2603 if (rt5682s->lrck[RT5682S_AIF1] != CLK_48 && in rt5682s_wclk_recalc_rate()
2604 rt5682s->lrck[RT5682S_AIF1] != CLK_44) { in rt5682s_wclk_recalc_rate()
2605 dev_warn(component->dev, "%s: clk %s only support %d or %d Hz output\n", in rt5682s_wclk_recalc_rate()
2610 return rt5682s->lrck[RT5682S_AIF1]; in rt5682s_wclk_recalc_rate()
2618 struct snd_soc_component *component = rt5682s->component; in rt5682s_wclk_round_rate()
2622 return -EINVAL; in rt5682s_wclk_round_rate()
2628 dev_warn(component->dev, "%s: clk %s only support %d or %d Hz output\n", in rt5682s_wclk_round_rate()
2641 struct snd_soc_component *component = rt5682s->component; in rt5682s_wclk_set_rate()
2647 return -EINVAL; in rt5682s_wclk_set_rate()
2654 * It will set the codec anyway by assuming mclk is 48MHz. in rt5682s_wclk_set_rate()
2656 parent_clk = clk_get_parent(hw->clk); in rt5682s_wclk_set_rate()
2658 dev_warn(component->dev, in rt5682s_wclk_set_rate()
2663 dev_warn(component->dev, "clk %s only support %d Hz input\n", in rt5682s_wclk_set_rate()
2677 rt5682s->lrck[RT5682S_AIF1] = rate; in rt5682s_wclk_set_rate()
2687 struct snd_soc_component *component = rt5682s->component; in rt5682s_bclk_recalc_rate()
2730 return -EINVAL; in rt5682s_bclk_round_rate()
2733 * BCLK rates are set as a multiplier of WCLK in HW. in rt5682s_bclk_round_rate()
2736 * and find the appropriate multiplier of BCLK to in rt5682s_bclk_round_rate()
2737 * get the rounded down BCLK value. in rt5682s_bclk_round_rate()
2749 struct snd_soc_component *component = rt5682s->component; in rt5682s_bclk_set_rate()
2754 return -EINVAL; in rt5682s_bclk_set_rate()
2759 if (dai->id == RT5682S_AIF1) in rt5682s_bclk_set_rate()
2762 dev_err(component->dev, "dai %d not found in component\n", in rt5682s_bclk_set_rate()
2764 return -ENODEV; in rt5682s_bclk_set_rate()
2784 struct device *dev = component->dev; in rt5682s_register_dai_clks()
2786 struct rt5682s_platform_data *pdata = &rt5682s->pdata; in rt5682s_register_dai_clks()
2795 dai_clk_hw = &rt5682s->dai_clks_hw[i]; in rt5682s_register_dai_clks()
2800 if (rt5682s->mclk) { in rt5682s_register_dai_clks()
2809 /* Make WCLK the parent of BCLK */ in rt5682s_register_dai_clks()
2810 parent = &rt5682s->dai_clks_hw[RT5682S_DAI_WCLK_IDX]; in rt5682s_register_dai_clks()
2816 return -EINVAL; in rt5682s_register_dai_clks()
2819 init.name = pdata->dai_clk_names[i]; in rt5682s_register_dai_clks()
2822 dai_clk_hw->init = &init; in rt5682s_register_dai_clks()
2830 if (dev->of_node) { in rt5682s_register_dai_clks()
2851 rt5682s->mclk = devm_clk_get_optional(component->dev, "mclk"); in rt5682s_dai_probe_clks()
2852 if (IS_ERR(rt5682s->mclk)) in rt5682s_dai_probe_clks()
2853 return PTR_ERR(rt5682s->mclk); in rt5682s_dai_probe_clks()
2861 rt5682s->lrck[RT5682S_AIF1] = CLK_48; in rt5682s_dai_probe_clks()
2876 rt5682s->component = component; in rt5682s_probe()
2893 if (rt5682s->irq) in rt5682s_suspend()
2894 disable_irq(rt5682s->irq); in rt5682s_suspend()
2896 cancel_delayed_work_sync(&rt5682s->jack_detect_work); in rt5682s_suspend()
2897 cancel_delayed_work_sync(&rt5682s->jd_check_work); in rt5682s_suspend()
2899 if (rt5682s->hs_jack) in rt5682s_suspend()
2900 rt5682s->jack_type = rt5682s_headset_detect(component, 0); in rt5682s_suspend()
2902 regcache_cache_only(rt5682s->regmap, true); in rt5682s_suspend()
2903 regcache_mark_dirty(rt5682s->regmap); in rt5682s_suspend()
2912 regcache_cache_only(rt5682s->regmap, false); in rt5682s_resume()
2913 regcache_sync(rt5682s->regmap); in rt5682s_resume()
2915 if (rt5682s->hs_jack) { in rt5682s_resume()
2917 &rt5682s->jack_detect_work, msecs_to_jiffies(0)); in rt5682s_resume()
2920 if (rt5682s->irq) in rt5682s_resume()
2921 enable_irq(rt5682s->irq); in rt5682s_resume()
2964 device_property_read_u32(dev, "realtek,dmic1-data-pin", in rt5682s_parse_dt()
2965 &rt5682s->pdata.dmic1_data_pin); in rt5682s_parse_dt()
2966 device_property_read_u32(dev, "realtek,dmic1-clk-pin", in rt5682s_parse_dt()
2967 &rt5682s->pdata.dmic1_clk_pin); in rt5682s_parse_dt()
2968 device_property_read_u32(dev, "realtek,jd-src", in rt5682s_parse_dt()
2969 &rt5682s->pdata.jd_src); in rt5682s_parse_dt()
2970 device_property_read_u32(dev, "realtek,dmic-clk-rate-hz", in rt5682s_parse_dt()
2971 &rt5682s->pdata.dmic_clk_rate); in rt5682s_parse_dt()
2972 device_property_read_u32(dev, "realtek,dmic-delay-ms", in rt5682s_parse_dt()
2973 &rt5682s->pdata.dmic_delay); in rt5682s_parse_dt()
2974 device_property_read_u32(dev, "realtek,amic-delay-ms", in rt5682s_parse_dt()
2975 &rt5682s->pdata.amic_delay); in rt5682s_parse_dt()
2976 device_property_read_u32(dev, "realtek,ldo-sel", in rt5682s_parse_dt()
2977 &rt5682s->pdata.ldo_dacref); in rt5682s_parse_dt()
2979 if (device_property_read_string_array(dev, "clock-output-names", in rt5682s_parse_dt()
2980 rt5682s->pdata.dai_clk_names, in rt5682s_parse_dt()
2983 rt5682s->pdata.dai_clk_names[RT5682S_DAI_WCLK_IDX], in rt5682s_parse_dt()
2984 rt5682s->pdata.dai_clk_names[RT5682S_DAI_BCLK_IDX]); in rt5682s_parse_dt()
2986 rt5682s->pdata.dmic_clk_driving_high = device_property_read_bool(dev, in rt5682s_parse_dt()
2987 "realtek,dmic-clk-driving-high"); in rt5682s_parse_dt()
2996 mutex_lock(&rt5682s->calibrate_mutex); in rt5682s_calibrate()
2998 regmap_write(rt5682s->regmap, RT5682S_PWR_ANLG_1, 0xaa80); in rt5682s_calibrate()
3000 regmap_write(rt5682s->regmap, RT5682S_PWR_ANLG_1, 0xfa80); in rt5682s_calibrate()
3001 regmap_write(rt5682s->regmap, RT5682S_PWR_DIG_1, 0x01c0); in rt5682s_calibrate()
3002 regmap_write(rt5682s->regmap, RT5682S_MICBIAS_2, 0x0380); in rt5682s_calibrate()
3003 regmap_write(rt5682s->regmap, RT5682S_GLB_CLK, 0x8000); in rt5682s_calibrate()
3004 regmap_write(rt5682s->regmap, RT5682S_ADDA_CLK_1, 0x1001); in rt5682s_calibrate()
3005 regmap_write(rt5682s->regmap, RT5682S_CHOP_DAC_2, 0x3030); in rt5682s_calibrate()
3006 regmap_write(rt5682s->regmap, RT5682S_CHOP_ADC, 0xb000); in rt5682s_calibrate()
3007 regmap_write(rt5682s->regmap, RT5682S_STO1_ADC_MIXER, 0x686c); in rt5682s_calibrate()
3008 regmap_write(rt5682s->regmap, RT5682S_CAL_REC, 0x5151); in rt5682s_calibrate()
3009 regmap_write(rt5682s->regmap, RT5682S_HP_CALIB_CTRL_2, 0x0321); in rt5682s_calibrate()
3010 regmap_write(rt5682s->regmap, RT5682S_HP_LOGIC_CTRL_2, 0x0004); in rt5682s_calibrate()
3011 regmap_write(rt5682s->regmap, RT5682S_HP_CALIB_CTRL_1, 0x7c00); in rt5682s_calibrate()
3012 regmap_write(rt5682s->regmap, RT5682S_HP_CALIB_CTRL_1, 0xfc00); in rt5682s_calibrate()
3015 regmap_read(rt5682s->regmap, RT5682S_HP_CALIB_ST_1, &value); in rt5682s_calibrate()
3023 dev_err(rt5682s->component->dev, "HP Calibration Failure\n"); in rt5682s_calibrate()
3026 regmap_write(rt5682s->regmap, RT5682S_MICBIAS_2, 0x0180); in rt5682s_calibrate()
3027 regmap_write(rt5682s->regmap, RT5682S_CAL_REC, 0x5858); in rt5682s_calibrate()
3028 regmap_write(rt5682s->regmap, RT5682S_STO1_ADC_MIXER, 0xc0c4); in rt5682s_calibrate()
3029 regmap_write(rt5682s->regmap, RT5682S_HP_CALIB_CTRL_2, 0x0320); in rt5682s_calibrate()
3030 regmap_write(rt5682s->regmap, RT5682S_PWR_DIG_1, 0x00c0); in rt5682s_calibrate()
3031 regmap_write(rt5682s->regmap, RT5682S_PWR_ANLG_1, 0x0800); in rt5682s_calibrate()
3032 regmap_write(rt5682s->regmap, RT5682S_GLB_CLK, 0x0000); in rt5682s_calibrate()
3034 mutex_unlock(&rt5682s->calibrate_mutex); in rt5682s_calibrate()
3052 .name = "rt5682s-aif1",
3071 .name = "rt5682s-aif2",
3074 .stream_name = "AIF2 Capture",
3087 struct device *dev = regmap_get_device(rt5682s->regmap); in rt5682s_i2c_disable_regulators()
3090 ret = regulator_disable(rt5682s->supplies[RT5682S_SUPPLY_AVDD].consumer); in rt5682s_i2c_disable_regulators()
3094 ret = regulator_disable(rt5682s->supplies[RT5682S_SUPPLY_DBVDD].consumer); in rt5682s_i2c_disable_regulators()
3098 ret = regulator_disable(rt5682s->supplies[RT5682S_SUPPLY_LDO1_IN].consumer); in rt5682s_i2c_disable_regulators()
3100 dev_err(dev, "Failed to disable supply LDO1-IN: %d\n", ret); in rt5682s_i2c_disable_regulators()
3104 ret = regulator_disable(rt5682s->supplies[RT5682S_SUPPLY_MICVDD].consumer); in rt5682s_i2c_disable_regulators()
3111 struct rt5682s_platform_data *pdata = dev_get_platdata(&i2c->dev); in rt5682s_i2c_probe()
3116 rt5682s = devm_kzalloc(&i2c->dev, sizeof(struct rt5682s_priv), GFP_KERNEL); in rt5682s_i2c_probe()
3118 return -ENOMEM; in rt5682s_i2c_probe()
3122 rt5682s->pdata = i2s_default_platform_data; in rt5682s_i2c_probe()
3125 rt5682s->pdata = *pdata; in rt5682s_i2c_probe()
3127 rt5682s_parse_dt(rt5682s, &i2c->dev); in rt5682s_i2c_probe()
3129 rt5682s->regmap = devm_regmap_init_i2c(i2c, &rt5682s_regmap); in rt5682s_i2c_probe()
3130 if (IS_ERR(rt5682s->regmap)) { in rt5682s_i2c_probe()
3131 ret = PTR_ERR(rt5682s->regmap); in rt5682s_i2c_probe()
3132 dev_err(&i2c->dev, "Failed to allocate register map: %d\n", ret); in rt5682s_i2c_probe()
3136 for (i = 0; i < ARRAY_SIZE(rt5682s->supplies); i++) in rt5682s_i2c_probe()
3137 rt5682s->supplies[i].supply = rt5682s_supply_names[i]; in rt5682s_i2c_probe()
3139 ret = devm_regulator_bulk_get(&i2c->dev, in rt5682s_i2c_probe()
3140 ARRAY_SIZE(rt5682s->supplies), rt5682s->supplies); in rt5682s_i2c_probe()
3142 dev_err(&i2c->dev, "Failed to request supplies: %d\n", ret); in rt5682s_i2c_probe()
3146 ret = devm_add_action_or_reset(&i2c->dev, rt5682s_i2c_disable_regulators, rt5682s); in rt5682s_i2c_probe()
3150 ret = regulator_enable(rt5682s->supplies[RT5682S_SUPPLY_MICVDD].consumer); in rt5682s_i2c_probe()
3152 dev_err(&i2c->dev, "Failed to enable supply MICVDD: %d\n", ret); in rt5682s_i2c_probe()
3157 ret = regulator_enable(rt5682s->supplies[RT5682S_SUPPLY_AVDD].consumer); in rt5682s_i2c_probe()
3159 dev_err(&i2c->dev, "Failed to enable supply AVDD: %d\n", ret); in rt5682s_i2c_probe()
3163 ret = regulator_enable(rt5682s->supplies[RT5682S_SUPPLY_DBVDD].consumer); in rt5682s_i2c_probe()
3165 dev_err(&i2c->dev, "Failed to enable supply DBVDD: %d\n", ret); in rt5682s_i2c_probe()
3169 ret = regulator_enable(rt5682s->supplies[RT5682S_SUPPLY_LDO1_IN].consumer); in rt5682s_i2c_probe()
3171 dev_err(&i2c->dev, "Failed to enable supply LDO1-IN: %d\n", ret); in rt5682s_i2c_probe()
3175 rt5682s->ldo1_en = devm_gpiod_get_optional(&i2c->dev, in rt5682s_i2c_probe()
3176 "realtek,ldo1-en", in rt5682s_i2c_probe()
3178 if (IS_ERR(rt5682s->ldo1_en)) { in rt5682s_i2c_probe()
3179 dev_err(&i2c->dev, "Fail gpio request ldo1_en\n"); in rt5682s_i2c_probe()
3180 return PTR_ERR(rt5682s->ldo1_en); in rt5682s_i2c_probe()
3186 regmap_read(rt5682s->regmap, RT5682S_DEVICE_ID, &val); in rt5682s_i2c_probe()
3188 dev_err(&i2c->dev, "Device with ID register %x is not rt5682s\n", val); in rt5682s_i2c_probe()
3189 return -ENODEV; in rt5682s_i2c_probe()
3193 rt5682s_apply_patch_list(rt5682s, &i2c->dev); in rt5682s_i2c_probe()
3195 regmap_update_bits(rt5682s->regmap, RT5682S_PWR_DIG_2, in rt5682s_i2c_probe()
3199 mutex_init(&rt5682s->calibrate_mutex); in rt5682s_i2c_probe()
3200 mutex_init(&rt5682s->sar_mutex); in rt5682s_i2c_probe()
3201 mutex_init(&rt5682s->wclk_mutex); in rt5682s_i2c_probe()
3204 regmap_update_bits(rt5682s->regmap, RT5682S_MICBIAS_2, in rt5682s_i2c_probe()
3207 regmap_update_bits(rt5682s->regmap, RT5682S_PWR_ANLG_1, in rt5682s_i2c_probe()
3209 regmap_update_bits(rt5682s->regmap, RT5682S_HP_LOGIC_CTRL_2, in rt5682s_i2c_probe()
3211 regmap_update_bits(rt5682s->regmap, RT5682S_HP_CHARGE_PUMP_2, in rt5682s_i2c_probe()
3213 regmap_update_bits(rt5682s->regmap, RT5682S_HP_AMP_DET_CTL_1, in rt5682s_i2c_probe()
3217 switch (rt5682s->pdata.dmic1_data_pin) { in rt5682s_i2c_probe()
3221 regmap_update_bits(rt5682s->regmap, RT5682S_DMIC_CTRL_1, in rt5682s_i2c_probe()
3223 regmap_update_bits(rt5682s->regmap, RT5682S_GPIO_CTRL_1, in rt5682s_i2c_probe()
3227 regmap_update_bits(rt5682s->regmap, RT5682S_DMIC_CTRL_1, in rt5682s_i2c_probe()
3229 regmap_update_bits(rt5682s->regmap, RT5682S_GPIO_CTRL_1, in rt5682s_i2c_probe()
3233 dev_warn(&i2c->dev, "invalid DMIC_DAT pin\n"); in rt5682s_i2c_probe()
3238 switch (rt5682s->pdata.dmic1_clk_pin) { in rt5682s_i2c_probe()
3242 regmap_update_bits(rt5682s->regmap, RT5682S_GPIO_CTRL_1, in rt5682s_i2c_probe()
3246 regmap_update_bits(rt5682s->regmap, RT5682S_GPIO_CTRL_1, in rt5682s_i2c_probe()
3248 if (rt5682s->pdata.dmic_clk_driving_high) in rt5682s_i2c_probe()
3249 regmap_update_bits(rt5682s->regmap, RT5682S_PAD_DRIVING_CTRL, in rt5682s_i2c_probe()
3253 dev_warn(&i2c->dev, "invalid DMIC_CLK pin\n"); in rt5682s_i2c_probe()
3258 switch (rt5682s->pdata.ldo_dacref) { in rt5682s_i2c_probe()
3262 regmap_update_bits(rt5682s->regmap, RT5682S_BIAS_CUR_CTRL_7, in rt5682s_i2c_probe()
3266 regmap_update_bits(rt5682s->regmap, RT5682S_BIAS_CUR_CTRL_7, in rt5682s_i2c_probe()
3270 regmap_update_bits(rt5682s->regmap, RT5682S_BIAS_CUR_CTRL_7, in rt5682s_i2c_probe()
3274 dev_warn(&i2c->dev, "invalid LDO output setting.\n"); in rt5682s_i2c_probe()
3278 INIT_DELAYED_WORK(&rt5682s->jack_detect_work, rt5682s_jack_detect_handler); in rt5682s_i2c_probe()
3279 INIT_DELAYED_WORK(&rt5682s->jd_check_work, rt5682s_jd_check_handler); in rt5682s_i2c_probe()
3281 if (i2c->irq) { in rt5682s_i2c_probe()
3282 ret = devm_request_threaded_irq(&i2c->dev, i2c->irq, NULL, rt5682s_irq, in rt5682s_i2c_probe()
3286 rt5682s->irq = i2c->irq; in rt5682s_i2c_probe()
3288 dev_err(&i2c->dev, "Failed to request IRQ: %d\n", ret); in rt5682s_i2c_probe()
3291 return devm_snd_soc_register_component(&i2c->dev, &rt5682s_soc_component_dev, in rt5682s_i2c_probe()
3299 disable_irq(client->irq); in rt5682s_i2c_shutdown()
3300 cancel_delayed_work_sync(&rt5682s->jack_detect_work); in rt5682s_i2c_shutdown()
3301 cancel_delayed_work_sync(&rt5682s->jd_check_work); in rt5682s_i2c_shutdown()
3343 MODULE_DESCRIPTION("ASoC RT5682I-VS driver");