• Home
  • Raw
  • Download

Lines Matching full:rt5682

3 // rt5682.c  --  RT5682 ALSA SoC audio component driver
29 #include <sound/rt5682.h>
32 #include "rt5682.h"
50 void rt5682_apply_patch_list(struct rt5682_priv *rt5682, struct device *dev) in rt5682_apply_patch_list() argument
54 ret = regmap_multi_reg_write(rt5682->regmap, patch_list, in rt5682_apply_patch_list()
809 void rt5682_reset(struct rt5682_priv *rt5682) in rt5682_reset() argument
811 regmap_write(rt5682->regmap, RT5682_RESET, 0); in rt5682_reset()
812 if (!rt5682->is_sdw) in rt5682_reset()
813 regmap_write(rt5682->regmap, RT5682_I2C_MODE, 1); in rt5682_reset()
823 * The ASRC function is for asynchronous MCLK and LRCK. Also, since RT5682 can
877 struct rt5682_priv *rt5682 = snd_soc_component_get_drvdata(component); in rt5682_enable_push_button_irq() local
888 if (rt5682->is_sdw) in rt5682_enable_push_button_irq()
922 struct rt5682_priv *rt5682 = snd_soc_component_get_drvdata(component); in rt5682_headset_detect() local
958 rt5682->jack_type = SND_JACK_HEADSET; in rt5682_headset_detect()
962 rt5682->jack_type = SND_JACK_HEADPHONE; in rt5682_headset_detect()
995 rt5682->jack_type = 0; in rt5682_headset_detect()
998 dev_dbg(component->dev, "jack_type = %d\n", rt5682->jack_type); in rt5682_headset_detect()
999 return rt5682->jack_type; in rt5682_headset_detect()
1006 struct rt5682_priv *rt5682 = snd_soc_component_get_drvdata(component); in rt5682_set_jack_detect() local
1008 rt5682->hs_jack = hs_jack; in rt5682_set_jack_detect()
1011 regmap_update_bits(rt5682->regmap, RT5682_IRQ_CTRL_2, in rt5682_set_jack_detect()
1013 regmap_update_bits(rt5682->regmap, RT5682_RC_CLK_CTRL, in rt5682_set_jack_detect()
1015 cancel_delayed_work_sync(&rt5682->jack_detect_work); in rt5682_set_jack_detect()
1020 if (!rt5682->is_sdw) { in rt5682_set_jack_detect()
1021 switch (rt5682->pdata.jd_src) { in rt5682_set_jack_detect()
1034 regmap_update_bits(rt5682->regmap, RT5682_GPIO_CTRL_1, in rt5682_set_jack_detect()
1036 regmap_update_bits(rt5682->regmap, RT5682_RC_CLK_CTRL, in rt5682_set_jack_detect()
1040 regmap_update_bits(rt5682->regmap, RT5682_PWR_ANLG_2, in rt5682_set_jack_detect()
1042 regmap_update_bits(rt5682->regmap, RT5682_IRQ_CTRL_2, in rt5682_set_jack_detect()
1045 regmap_update_bits(rt5682->regmap, RT5682_4BTN_IL_CMD_4, in rt5682_set_jack_detect()
1046 0x7f7f, (rt5682->pdata.btndet_delay << 8 | in rt5682_set_jack_detect()
1047 rt5682->pdata.btndet_delay)); in rt5682_set_jack_detect()
1048 regmap_update_bits(rt5682->regmap, RT5682_4BTN_IL_CMD_5, in rt5682_set_jack_detect()
1049 0x7f7f, (rt5682->pdata.btndet_delay << 8 | in rt5682_set_jack_detect()
1050 rt5682->pdata.btndet_delay)); in rt5682_set_jack_detect()
1051 regmap_update_bits(rt5682->regmap, RT5682_4BTN_IL_CMD_6, in rt5682_set_jack_detect()
1052 0x7f7f, (rt5682->pdata.btndet_delay << 8 | in rt5682_set_jack_detect()
1053 rt5682->pdata.btndet_delay)); in rt5682_set_jack_detect()
1054 regmap_update_bits(rt5682->regmap, RT5682_4BTN_IL_CMD_7, in rt5682_set_jack_detect()
1055 0x7f7f, (rt5682->pdata.btndet_delay << 8 | in rt5682_set_jack_detect()
1056 rt5682->pdata.btndet_delay)); in rt5682_set_jack_detect()
1058 &rt5682->jack_detect_work, in rt5682_set_jack_detect()
1063 regmap_update_bits(rt5682->regmap, RT5682_IRQ_CTRL_2, in rt5682_set_jack_detect()
1065 regmap_update_bits(rt5682->regmap, RT5682_RC_CLK_CTRL, in rt5682_set_jack_detect()
1080 struct rt5682_priv *rt5682 = in rt5682_jack_detect_handler() local
1084 if (!rt5682->component || !rt5682->component->card || in rt5682_jack_detect_handler()
1085 !rt5682->component->card->instantiated) { in rt5682_jack_detect_handler()
1088 &rt5682->jack_detect_work, msecs_to_jiffies(15)); in rt5682_jack_detect_handler()
1092 mutex_lock(&rt5682->calibrate_mutex); in rt5682_jack_detect_handler()
1094 val = snd_soc_component_read(rt5682->component, RT5682_AJD1_CTRL) in rt5682_jack_detect_handler()
1098 if (rt5682->jack_type == 0) { in rt5682_jack_detect_handler()
1100 rt5682->jack_type = in rt5682_jack_detect_handler()
1101 rt5682_headset_detect(rt5682->component, 1); in rt5682_jack_detect_handler()
1102 } else if ((rt5682->jack_type & SND_JACK_HEADSET) == in rt5682_jack_detect_handler()
1105 rt5682->jack_type = SND_JACK_HEADSET; in rt5682_jack_detect_handler()
1106 btn_type = rt5682_button_detect(rt5682->component); in rt5682_jack_detect_handler()
1108 * rt5682 can report three kinds of button behavior, in rt5682_jack_detect_handler()
1118 rt5682->jack_type |= SND_JACK_BTN_0; in rt5682_jack_detect_handler()
1123 rt5682->jack_type |= SND_JACK_BTN_1; in rt5682_jack_detect_handler()
1128 rt5682->jack_type |= SND_JACK_BTN_2; in rt5682_jack_detect_handler()
1133 rt5682->jack_type |= SND_JACK_BTN_3; in rt5682_jack_detect_handler()
1138 dev_err(rt5682->component->dev, in rt5682_jack_detect_handler()
1146 rt5682->jack_type = rt5682_headset_detect(rt5682->component, 0); in rt5682_jack_detect_handler()
1149 snd_soc_jack_report(rt5682->hs_jack, rt5682->jack_type, in rt5682_jack_detect_handler()
1154 if (!rt5682->is_sdw) { in rt5682_jack_detect_handler()
1155 if (rt5682->jack_type & (SND_JACK_BTN_0 | SND_JACK_BTN_1 | in rt5682_jack_detect_handler()
1157 schedule_delayed_work(&rt5682->jd_check_work, 0); in rt5682_jack_detect_handler()
1159 cancel_delayed_work_sync(&rt5682->jd_check_work); in rt5682_jack_detect_handler()
1162 mutex_unlock(&rt5682->calibrate_mutex); in rt5682_jack_detect_handler()
1187 static int rt5682_div_sel(struct rt5682_priv *rt5682, in rt5682_div_sel() argument
1192 if (rt5682->sysclk < target) { in rt5682_div_sel()
1193 dev_err(rt5682->component->dev, in rt5682_div_sel()
1194 "sysclk rate %d is too low\n", rt5682->sysclk); in rt5682_div_sel()
1199 dev_dbg(rt5682->component->dev, "div[%d]=%d\n", i, div[i]); in rt5682_div_sel()
1200 if (target * div[i] == rt5682->sysclk) in rt5682_div_sel()
1202 if (target * div[i + 1] > rt5682->sysclk) { in rt5682_div_sel()
1203 dev_dbg(rt5682->component->dev, in rt5682_div_sel()
1205 rt5682->sysclk); in rt5682_div_sel()
1210 if (target * div[i] < rt5682->sysclk) in rt5682_div_sel()
1211 dev_err(rt5682->component->dev, in rt5682_div_sel()
1212 "sysclk rate %d is too high\n", rt5682->sysclk); in rt5682_div_sel()
1232 struct rt5682_priv *rt5682 = snd_soc_component_get_drvdata(component); in set_dmic_clk() local
1236 if (rt5682->pdata.dmic_clk_rate) in set_dmic_clk()
1237 dmic_clk_rate = rt5682->pdata.dmic_clk_rate; in set_dmic_clk()
1239 idx = rt5682_div_sel(rt5682, dmic_clk_rate, div, ARRAY_SIZE(div)); in set_dmic_clk()
1252 struct rt5682_priv *rt5682 = snd_soc_component_get_drvdata(component); in set_filter_clk() local
1257 if (rt5682->is_sdw) in set_filter_clk()
1264 ref = 256 * rt5682->lrck[RT5682_AIF2]; in set_filter_clk()
1266 ref = 256 * rt5682->lrck[RT5682_AIF1]; in set_filter_clk()
1268 idx = rt5682_div_sel(rt5682, ref, div_f, ARRAY_SIZE(div_f)); in set_filter_clk()
1280 if (rt5682->sysclk <= 12288000 * div_o[idx]) in set_filter_clk()
1543 struct rt5682_priv *rt5682 = snd_soc_component_get_drvdata(component); in set_dmic_power() local
1546 if (rt5682->pdata.dmic_delay) in set_dmic_power()
1547 delay = rt5682->pdata.dmic_delay; in set_dmic_power()
1564 if (!rt5682->jack_type) { in set_dmic_power()
2072 struct rt5682_priv *rt5682 = snd_soc_component_get_drvdata(component); in rt5682_hw_params() local
2076 rt5682->lrck[dai->id] = params_rate(params); in rt5682_hw_params()
2077 pre_div = rl6231_get_clk_info(rt5682->sysclk, rt5682->lrck[dai->id]); in rt5682_hw_params()
2087 rt5682->lrck[dai->id], pre_div, dai->id); in rt5682_hw_params()
2116 if (rt5682->master[RT5682_AIF1]) { in rt5682_hw_params()
2121 (rt5682->sysclk_src) << RT5682_I2S_CLK_SRC_SFT); in rt5682_hw_params()
2135 if (rt5682->master[RT5682_AIF2]) { in rt5682_hw_params()
2160 struct rt5682_priv *rt5682 = snd_soc_component_get_drvdata(component); in rt5682_set_dai_fmt() local
2165 rt5682->master[dai->id] = 1; in rt5682_set_dai_fmt()
2168 rt5682->master[dai->id] = 0; in rt5682_set_dai_fmt()
2225 tdm_ctrl | rt5682->master[dai->id]); in rt5682_set_dai_fmt()
2228 if (rt5682->master[dai->id] == 0) in rt5682_set_dai_fmt()
2244 struct rt5682_priv *rt5682 = snd_soc_component_get_drvdata(component); in rt5682_set_component_sysclk() local
2247 if (freq == rt5682->sysclk && clk_id == rt5682->sysclk_src) in rt5682_set_component_sysclk()
2274 if (rt5682->master[RT5682_AIF2]) { in rt5682_set_component_sysclk()
2280 rt5682->sysclk = freq; in rt5682_set_component_sysclk()
2281 rt5682->sysclk_src = clk_id; in rt5682_set_component_sysclk()
2293 struct rt5682_priv *rt5682 = snd_soc_component_get_drvdata(component); in rt5682_set_component_pll() local
2298 if (source == rt5682->pll_src[pll_id] && in rt5682_set_component_pll()
2299 freq_in == rt5682->pll_in[pll_id] && in rt5682_set_component_pll()
2300 freq_out == rt5682->pll_out[pll_id]) in rt5682_set_component_pll()
2306 rt5682->pll_in[pll_id] = 0; in rt5682_set_component_pll()
2307 rt5682->pll_out[pll_id] = 0; in rt5682_set_component_pll()
2412 rt5682->pll_in[pll_id] = freq_in; in rt5682_set_component_pll()
2413 rt5682->pll_out[pll_id] = freq_out; in rt5682_set_component_pll()
2414 rt5682->pll_src[pll_id] = source; in rt5682_set_component_pll()
2422 struct rt5682_priv *rt5682 = snd_soc_component_get_drvdata(component); in rt5682_set_bclk1_ratio() local
2424 rt5682->bclk[dai->id] = ratio; in rt5682_set_bclk1_ratio()
2454 struct rt5682_priv *rt5682 = snd_soc_component_get_drvdata(component); in rt5682_set_bclk2_ratio() local
2456 rt5682->bclk[dai->id] = ratio; in rt5682_set_bclk2_ratio()
2480 struct rt5682_priv *rt5682 = snd_soc_component_get_drvdata(component); in rt5682_set_bias_level() local
2484 regmap_update_bits(rt5682->regmap, RT5682_PWR_ANLG_1, in rt5682_set_bias_level()
2486 regmap_update_bits(rt5682->regmap, RT5682_PWR_DIG_1, in rt5682_set_bias_level()
2492 regmap_update_bits(rt5682->regmap, RT5682_PWR_DIG_1, in rt5682_set_bias_level()
2496 regmap_update_bits(rt5682->regmap, RT5682_PWR_DIG_1, in rt5682_set_bias_level()
2498 regmap_update_bits(rt5682->regmap, RT5682_PWR_ANLG_1, in rt5682_set_bias_level()
2513 static bool rt5682_clk_check(struct rt5682_priv *rt5682) in rt5682_clk_check() argument
2515 if (!rt5682->master[RT5682_AIF1]) { in rt5682_clk_check()
2516 dev_dbg(rt5682->component->dev, "sysclk/dai not set correctly\n"); in rt5682_clk_check()
2524 struct rt5682_priv *rt5682 = in rt5682_wclk_prepare() local
2527 struct snd_soc_component *component = rt5682->component; in rt5682_wclk_prepare()
2531 if (!rt5682_clk_check(rt5682)) in rt5682_wclk_prepare()
2560 struct rt5682_priv *rt5682 = in rt5682_wclk_unprepare() local
2563 struct snd_soc_component *component = rt5682->component; in rt5682_wclk_unprepare()
2567 if (!rt5682_clk_check(rt5682)) in rt5682_wclk_unprepare()
2574 if (!rt5682->jack_type) in rt5682_wclk_unprepare()
2590 struct rt5682_priv *rt5682 = in rt5682_wclk_recalc_rate() local
2593 struct snd_soc_component *component = rt5682->component; in rt5682_wclk_recalc_rate()
2596 if (!rt5682_clk_check(rt5682)) in rt5682_wclk_recalc_rate()
2601 if (rt5682->lrck[RT5682_AIF1] != CLK_48 && in rt5682_wclk_recalc_rate()
2602 rt5682->lrck[RT5682_AIF1] != CLK_44) { in rt5682_wclk_recalc_rate()
2608 return rt5682->lrck[RT5682_AIF1]; in rt5682_wclk_recalc_rate()
2614 struct rt5682_priv *rt5682 = in rt5682_wclk_round_rate() local
2617 struct snd_soc_component *component = rt5682->component; in rt5682_wclk_round_rate()
2620 if (!rt5682_clk_check(rt5682)) in rt5682_wclk_round_rate()
2638 struct rt5682_priv *rt5682 = in rt5682_wclk_set_rate() local
2641 struct snd_soc_component *component = rt5682->component; in rt5682_wclk_set_rate()
2647 if (!rt5682_clk_check(rt5682)) in rt5682_wclk_set_rate()
2678 rt5682->lrck[RT5682_AIF1] = rate; in rt5682_wclk_set_rate()
2680 pre_div = rl6231_get_clk_info(rt5682->sysclk, rate); in rt5682_wclk_set_rate()
2685 (rt5682->sysclk_src) << RT5682_I2S_CLK_SRC_SFT); in rt5682_wclk_set_rate()
2693 struct rt5682_priv *rt5682 = in rt5682_bclk_recalc_rate() local
2696 struct snd_soc_component *component = rt5682->component; in rt5682_bclk_recalc_rate()
2734 struct rt5682_priv *rt5682 = in rt5682_bclk_round_rate() local
2739 if (!*parent_rate || !rt5682_clk_check(rt5682)) in rt5682_bclk_round_rate()
2757 struct rt5682_priv *rt5682 = in rt5682_bclk_set_rate() local
2760 struct snd_soc_component *component = rt5682->component; in rt5682_bclk_set_rate()
2764 if (!rt5682_clk_check(rt5682)) in rt5682_bclk_set_rate()
2799 struct rt5682_priv *rt5682 = snd_soc_component_get_drvdata(component); in rt5682_register_dai_clks() local
2800 struct rt5682_platform_data *pdata = &rt5682->pdata; in rt5682_register_dai_clks()
2809 dai_clk_hw = &rt5682->dai_clks_hw[i]; in rt5682_register_dai_clks()
2814 if (rt5682->mclk) { in rt5682_register_dai_clks()
2824 parent = &rt5682->dai_clks_hw[RT5682_DAI_WCLK_IDX]; in rt5682_register_dai_clks()
2863 struct rt5682_priv *rt5682 = snd_soc_component_get_drvdata(component); in rt5682_probe() local
2871 rt5682->component = component; in rt5682_probe()
2873 if (rt5682->is_sdw) { in rt5682_probe()
2874 slave = rt5682->slave; in rt5682_probe()
2885 rt5682->mclk = devm_clk_get(component->dev, "mclk"); in rt5682_probe()
2886 if (IS_ERR(rt5682->mclk)) { in rt5682_probe()
2887 if (PTR_ERR(rt5682->mclk) != -ENOENT) { in rt5682_probe()
2888 ret = PTR_ERR(rt5682->mclk); in rt5682_probe()
2891 rt5682->mclk = NULL; in rt5682_probe()
2900 rt5682->lrck[RT5682_AIF1] = CLK_48; in rt5682_probe()
2912 struct rt5682_priv *rt5682 = snd_soc_component_get_drvdata(component); in rt5682_remove() local
2914 rt5682_reset(rt5682); in rt5682_remove()
2920 struct rt5682_priv *rt5682 = snd_soc_component_get_drvdata(component); in rt5682_suspend() local
2922 regcache_cache_only(rt5682->regmap, true); in rt5682_suspend()
2923 regcache_mark_dirty(rt5682->regmap); in rt5682_suspend()
2929 struct rt5682_priv *rt5682 = snd_soc_component_get_drvdata(component); in rt5682_resume() local
2931 regcache_cache_only(rt5682->regmap, false); in rt5682_resume()
2932 regcache_sync(rt5682->regmap); in rt5682_resume()
2935 &rt5682->jack_detect_work, msecs_to_jiffies(250)); in rt5682_resume()
2980 int rt5682_parse_dt(struct rt5682_priv *rt5682, struct device *dev) in rt5682_parse_dt() argument
2984 &rt5682->pdata.dmic1_data_pin); in rt5682_parse_dt()
2986 &rt5682->pdata.dmic1_clk_pin); in rt5682_parse_dt()
2988 &rt5682->pdata.jd_src); in rt5682_parse_dt()
2990 &rt5682->pdata.btndet_delay); in rt5682_parse_dt()
2992 &rt5682->pdata.dmic_clk_rate); in rt5682_parse_dt()
2994 &rt5682->pdata.dmic_delay); in rt5682_parse_dt()
2996 rt5682->pdata.ldo1_en = of_get_named_gpio(dev->of_node, in rt5682_parse_dt()
3000 rt5682->pdata.dai_clk_names, in rt5682_parse_dt()
3003 rt5682->pdata.dai_clk_names[RT5682_DAI_WCLK_IDX], in rt5682_parse_dt()
3004 rt5682->pdata.dai_clk_names[RT5682_DAI_BCLK_IDX]); in rt5682_parse_dt()
3010 void rt5682_calibrate(struct rt5682_priv *rt5682) in rt5682_calibrate() argument
3014 mutex_lock(&rt5682->calibrate_mutex); in rt5682_calibrate()
3016 rt5682_reset(rt5682); in rt5682_calibrate()
3017 regmap_write(rt5682->regmap, RT5682_I2C_CTRL, 0x000f); in rt5682_calibrate()
3018 regmap_write(rt5682->regmap, RT5682_PWR_ANLG_1, 0xa2af); in rt5682_calibrate()
3020 regmap_write(rt5682->regmap, RT5682_PWR_ANLG_1, 0xf2af); in rt5682_calibrate()
3021 regmap_write(rt5682->regmap, RT5682_MICBIAS_2, 0x0300); in rt5682_calibrate()
3022 regmap_write(rt5682->regmap, RT5682_GLB_CLK, 0x8000); in rt5682_calibrate()
3023 regmap_write(rt5682->regmap, RT5682_PWR_DIG_1, 0x0100); in rt5682_calibrate()
3024 regmap_write(rt5682->regmap, RT5682_HP_IMP_SENS_CTRL_19, 0x3800); in rt5682_calibrate()
3025 regmap_write(rt5682->regmap, RT5682_CHOP_DAC, 0x3000); in rt5682_calibrate()
3026 regmap_write(rt5682->regmap, RT5682_CALIB_ADC_CTRL, 0x7005); in rt5682_calibrate()
3027 regmap_write(rt5682->regmap, RT5682_STO1_ADC_MIXER, 0x686c); in rt5682_calibrate()
3028 regmap_write(rt5682->regmap, RT5682_CAL_REC, 0x0d0d); in rt5682_calibrate()
3029 regmap_write(rt5682->regmap, RT5682_HP_CALIB_CTRL_2, 0x0321); in rt5682_calibrate()
3030 regmap_write(rt5682->regmap, RT5682_HP_LOGIC_CTRL_2, 0x0004); in rt5682_calibrate()
3031 regmap_write(rt5682->regmap, RT5682_HP_CALIB_CTRL_1, 0x7c00); in rt5682_calibrate()
3032 regmap_write(rt5682->regmap, RT5682_HP_CALIB_CTRL_3, 0x06a1); in rt5682_calibrate()
3033 regmap_write(rt5682->regmap, RT5682_A_DAC1_MUX, 0x0311); in rt5682_calibrate()
3034 regmap_write(rt5682->regmap, RT5682_HP_CALIB_CTRL_1, 0x7c00); in rt5682_calibrate()
3036 regmap_write(rt5682->regmap, RT5682_HP_CALIB_CTRL_1, 0xfc00); in rt5682_calibrate()
3039 regmap_read(rt5682->regmap, RT5682_HP_CALIB_STA_1, &value); in rt5682_calibrate()
3047 dev_err(rt5682->component->dev, "HP Calibration Failure\n"); in rt5682_calibrate()
3050 regmap_write(rt5682->regmap, RT5682_PWR_ANLG_1, 0x002f); in rt5682_calibrate()
3051 regmap_write(rt5682->regmap, RT5682_MICBIAS_2, 0x0080); in rt5682_calibrate()
3052 regmap_write(rt5682->regmap, RT5682_GLB_CLK, 0x0000); in rt5682_calibrate()
3053 regmap_write(rt5682->regmap, RT5682_PWR_DIG_1, 0x0000); in rt5682_calibrate()
3054 regmap_write(rt5682->regmap, RT5682_CHOP_DAC, 0x2000); in rt5682_calibrate()
3055 regmap_write(rt5682->regmap, RT5682_CALIB_ADC_CTRL, 0x2005); in rt5682_calibrate()
3056 regmap_write(rt5682->regmap, RT5682_STO1_ADC_MIXER, 0xc0c4); in rt5682_calibrate()
3057 regmap_write(rt5682->regmap, RT5682_CAL_REC, 0x0c0c); in rt5682_calibrate()
3059 mutex_unlock(&rt5682->calibrate_mutex); in rt5682_calibrate()
3063 MODULE_DESCRIPTION("ASoC RT5682 driver");