Lines Matching +full:out +full:- +full:mono
1 // SPDX-License-Identifier: GPL-2.0-only
3 * rt5659.c -- RT5659/RT5658 ALSA SoC audio codec driver
26 #include <sound/soc-dapm.h>
1137 static const DECLARE_TLV_DB_SCALE(hp_vol_tlv, -2325, 75, 0);
1138 static const DECLARE_TLV_DB_SCALE(out_vol_tlv, -4650, 150, 0);
1139 static const DECLARE_TLV_DB_SCALE(dac_vol_tlv, -65625, 375, 0);
1140 static const DECLARE_TLV_DB_SCALE(in_vol_tlv, -3450, 150, 0);
1141 static const DECLARE_TLV_DB_SCALE(adc_vol_tlv, -17625, 375, 0);
1143 static const DECLARE_TLV_DB_SCALE(in_bst_tlv, -1200, 75, 0);
1250 * rt5659_headset_detect - Detect headset.
1297 rt5659->jack_type = SND_JACK_HEADSET; in rt5659_headset_detect()
1302 rt5659->jack_type = SND_JACK_HEADPHONE; in rt5659_headset_detect()
1310 if (rt5659->jack_type == SND_JACK_HEADSET) in rt5659_headset_detect()
1312 rt5659->jack_type = 0; in rt5659_headset_detect()
1315 dev_dbg(component->dev, "jack_type = %d\n", rt5659->jack_type); in rt5659_headset_detect()
1316 return rt5659->jack_type; in rt5659_headset_detect()
1335 &rt5659->jack_detect_work, msecs_to_jiffies(250)); in rt5659_irq()
1345 rt5659->hs_jack = hs_jack; in rt5659_set_jack_detect()
1359 if (!rt5659->component) in rt5659_jack_detect_work()
1362 val = snd_soc_component_read(rt5659->component, RT5659_INT_ST_1) & 0x0080; in rt5659_jack_detect_work()
1365 if (rt5659->jack_type == 0) { in rt5659_jack_detect_work()
1366 /* jack was out, report jack type */ in rt5659_jack_detect_work()
1367 report = rt5659_headset_detect(rt5659->component, 1); in rt5659_jack_detect_work()
1371 btn_type = rt5659_button_detect(rt5659->component); in rt5659_jack_detect_work()
1404 dev_err(rt5659->component->dev, in rt5659_jack_detect_work()
1412 report = rt5659->jack_type; in rt5659_jack_detect_work()
1415 /* jack out */ in rt5659_jack_detect_work()
1416 report = rt5659_headset_detect(rt5659->component, 0); in rt5659_jack_detect_work()
1419 snd_soc_jack_report(rt5659->hs_jack, report, SND_JACK_HEADSET | in rt5659_jack_detect_work()
1431 if (!rt5659->hs_jack) in rt5659_jack_detect_intel_hd_header()
1435 regmap_read(rt5659->regmap, RT5659_GPIO_STA, &value); in rt5659_jack_detect_intel_hd_header()
1438 if (hp_flag != rt5659->hda_hp_plugged) { in rt5659_jack_detect_intel_hd_header()
1439 rt5659->hda_hp_plugged = hp_flag; in rt5659_jack_detect_intel_hd_header()
1442 regmap_update_bits(rt5659->regmap, RT5659_IRQ_CTRL_1, in rt5659_jack_detect_intel_hd_header()
1444 rt5659->jack_type |= SND_JACK_HEADPHONE; in rt5659_jack_detect_intel_hd_header()
1446 regmap_update_bits(rt5659->regmap, RT5659_IRQ_CTRL_1, in rt5659_jack_detect_intel_hd_header()
1448 rt5659->jack_type = rt5659->jack_type & in rt5659_jack_detect_intel_hd_header()
1452 snd_soc_jack_report(rt5659->hs_jack, rt5659->jack_type, in rt5659_jack_detect_intel_hd_header()
1457 regmap_read(rt5659->regmap, RT5659_4BTN_IL_CMD_1, &value); in rt5659_jack_detect_intel_hd_header()
1458 regmap_write(rt5659->regmap, RT5659_4BTN_IL_CMD_1, value); in rt5659_jack_detect_intel_hd_header()
1461 if (mic_flag != rt5659->hda_mic_plugged) { in rt5659_jack_detect_intel_hd_header()
1462 rt5659->hda_mic_plugged = mic_flag; in rt5659_jack_detect_intel_hd_header()
1464 regmap_update_bits(rt5659->regmap, RT5659_IRQ_CTRL_2, in rt5659_jack_detect_intel_hd_header()
1466 rt5659->jack_type |= SND_JACK_MICROPHONE; in rt5659_jack_detect_intel_hd_header()
1468 regmap_update_bits(rt5659->regmap, RT5659_IRQ_CTRL_2, in rt5659_jack_detect_intel_hd_header()
1470 rt5659->jack_type = rt5659->jack_type in rt5659_jack_detect_intel_hd_header()
1474 snd_soc_jack_report(rt5659->hs_jack, rt5659->jack_type, in rt5659_jack_detect_intel_hd_header()
1489 /* Mono Output Volume */
1490 SOC_SINGLE_TLV("Mono Playback Volume", RT5659_MONO_OUT,
1494 SOC_DOUBLE_TLV("OUT Playback Volume", RT5659_LOUT,
1527 SOC_DOUBLE("Mono ADC Capture Switch", RT5659_MONO_ADC_DIG_VOL,
1529 SOC_DOUBLE_TLV("Mono ADC Capture Volume", RT5659_MONO_ADC_DIG_VOL,
1541 SOC_DOUBLE_TLV("Mono ADC Boost Gain Volume", RT5659_MONO_BOOST,
1556 * set_dmic_clk - Set parameter of dmic.
1568 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in set_dmic_clk()
1572 pd = rl6231_get_pre_div(rt5659->regmap, in set_dmic_clk()
1574 idx = rl6231_calc_dmic_clk(rt5659->sysclk / pd); in set_dmic_clk()
1577 dev_err(component->dev, "Failed to set DMIC clock\n"); in set_dmic_clk()
1588 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in set_adc1_clk()
1614 snd_soc_dapm_to_component(w->dapm); in set_adc2_clk()
1639 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in rt5659_charge_pump_event()
1660 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in is_sys_clk_from_pll()
1674 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in is_using_asrc()
1676 switch (w->shift) { in is_using_asrc()
1969 /*MX-1B [6:4], MX-1B [2:0]*/
1971 "IF1 DAC2", "IF2 DAC", "IF3 DAC", "Mono ADC MIX"
1990 /* MX-26 [13] */
2003 /* MX-26 [12] */
2016 /* MX-26 [11] */
2029 /* MX-26 [8] */
2042 /* MONO ADC L2 Source */
2043 /* MX-27 [12] */
2045 "Mono DAC MIXL", "DMIC"
2053 SOC_DAPM_ENUM("Mono ADC L2 Source", rt5659_mono_adc_l2_enum);
2056 /* MONO ADC L1 Source */
2057 /* MX-27 [11] */
2059 "Mono DAC MIXL", "ADC"
2067 SOC_DAPM_ENUM("Mono ADC L1 Source", rt5659_mono_adc_l1_enum);
2069 /* MONO ADC L Source, MONO ADC R Source*/
2070 /* MX-27 [10:9], MX-27 [2:1] */
2080 SOC_DAPM_ENUM("Mono ADC L Source", rt5659_mono_adc_l_enum);
2087 SOC_DAPM_ENUM("Mono ADC R Source", rt5659_mono_adcr_enum);
2089 /* MONO DMIC L Source */
2090 /* MX-27 [8] */
2100 SOC_DAPM_ENUM("Mono DMIC L Source", rt5659_mono_dmic_l_enum);
2102 /* MONO ADC R2 Source */
2103 /* MX-27 [4] */
2105 "Mono DAC MIXR", "DMIC"
2113 SOC_DAPM_ENUM("Mono ADC R2 Source", rt5659_mono_adc_r2_enum);
2115 /* MONO ADC R1 Source */
2116 /* MX-27 [3] */
2118 "Mono DAC MIXR", "ADC"
2126 SOC_DAPM_ENUM("Mono ADC R1 Source", rt5659_mono_adc_r1_enum);
2128 /* MONO DMIC R Source */
2129 /* MX-27 [0] */
2139 SOC_DAPM_ENUM("Mono DMIC R Source", rt5659_mono_dmic_r_enum);
2143 /* MX-29 [11:10], MX-29 [9:8]*/
2163 /* MX-2C [6], MX-2C [4]*/
2165 "Stereo DAC Mixer", "Mono DAC Mixer"
2183 /* MX-2D [3], MX-2D [2]*/
2203 /* MX-2D [1], MX-2D [0]*/
2205 "Stereo DAC Mixer", "Mono DAC Mixer"
2223 /* MX-2F [13:12] */
2236 /* MX-2F [1:0] */
2249 /* MX-31 [15] [13] */
2251 "Mono DAC", "Stereo DAC"
2269 /* MX-36 [1:0] */
2282 /* MX-78[4:0] */
2301 /* Out Volume Switch */
2317 /* Out Switch */
2347 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in rt5659_spk_event()
2379 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in rt5659_mono_event()
2401 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in rt5659_hp_event()
2448 SND_SOC_DAPM_SUPPLY("Mono Vref", RT5659_PWR_ANLG_1,
2460 SND_SOC_DAPM_SUPPLY_S("DAC Mono L ASRC", 1, RT5659_ASRC_1,
2462 SND_SOC_DAPM_SUPPLY_S("DAC Mono R ASRC", 1, RT5659_ASRC_1,
2466 SND_SOC_DAPM_SUPPLY_S("ADC Mono L ASRC", 1, RT5659_ASRC_1,
2468 SND_SOC_DAPM_SUPPLY_S("ADC Mono R ASRC", 1, RT5659_ASRC_1,
2573 SND_SOC_DAPM_MUX("Mono ADC L2 Mux", SND_SOC_NOPM, 0, 0,
2575 SND_SOC_DAPM_MUX("Mono ADC R2 Mux", SND_SOC_NOPM, 0, 0,
2577 SND_SOC_DAPM_MUX("Mono ADC L1 Mux", SND_SOC_NOPM, 0, 0,
2579 SND_SOC_DAPM_MUX("Mono ADC R1 Mux", SND_SOC_NOPM, 0, 0,
2581 SND_SOC_DAPM_MUX("Mono DMIC L Mux", SND_SOC_NOPM, 0, 0,
2583 SND_SOC_DAPM_MUX("Mono DMIC R Mux", SND_SOC_NOPM, 0, 0,
2585 SND_SOC_DAPM_MUX("Mono ADC L Mux", SND_SOC_NOPM, 0, 0,
2587 SND_SOC_DAPM_MUX("Mono ADC R Mux", SND_SOC_NOPM, 0, 0,
2600 SND_SOC_DAPM_SUPPLY("ADC Mono Left Filter", RT5659_PWR_DIG_2,
2602 SND_SOC_DAPM_MIXER("Mono ADC MIXL", RT5659_MONO_ADC_DIG_VOL,
2605 SND_SOC_DAPM_SUPPLY("ADC Mono Right Filter", RT5659_PWR_DIG_2,
2607 SND_SOC_DAPM_MIXER("Mono ADC MIXR", RT5659_MONO_ADC_DIG_VOL,
2714 SND_SOC_DAPM_SUPPLY("DAC Mono Left Filter", RT5659_PWR_DIG_2,
2716 SND_SOC_DAPM_SUPPLY("DAC Mono Right Filter", RT5659_PWR_DIG_2,
2722 SND_SOC_DAPM_MIXER("Mono DAC MIXL", SND_SOC_NOPM, 0, 0,
2724 SND_SOC_DAPM_MIXER("Mono DAC MIXR", SND_SOC_NOPM, 0, 0,
2747 /* OUT Mixer */
2754 SND_SOC_DAPM_MIXER("OUT MIXL", RT5659_PWR_MIXER, RT5659_PWR_OM_L_BIT,
2756 SND_SOC_DAPM_MIXER("OUT MIXR", RT5659_PWR_MIXER, RT5659_PWR_OM_R_BIT,
2771 /* SPO/MONO/HPO/LOUT */
2776 SND_SOC_DAPM_MIXER("Mono MIX", SND_SOC_NOPM, 0, 0, rt5659_mono_mix,
2786 SND_SOC_DAPM_PGA_S("Mono Amp", 1, RT5659_PWR_ANLG_1, RT5659_PWR_MA_BIT,
2799 SND_SOC_DAPM_SWITCH("Mono Playback", SND_SOC_NOPM, 0, 0,
2845 { "ADC Mono Left Filter", NULL, "PLL", is_sys_clk_from_pll },
2846 { "ADC Mono Right Filter", NULL, "PLL", is_sys_clk_from_pll },
2848 { "DAC Mono Left Filter", NULL, "PLL", is_sys_clk_from_pll },
2849 { "DAC Mono Right Filter", NULL, "PLL", is_sys_clk_from_pll },
2853 { "ADC Mono Left Filter", NULL, "ADC Mono L ASRC", is_using_asrc },
2854 { "ADC Mono Right Filter", NULL, "ADC Mono R ASRC", is_using_asrc },
2855 { "DAC Mono Left Filter", NULL, "DAC Mono L ASRC", is_using_asrc },
2856 { "DAC Mono Right Filter", NULL, "DAC Mono R ASRC", is_using_asrc },
2943 { "Mono DMIC L Mux", "DMIC1 L", "DMIC L1" },
2944 { "Mono DMIC L Mux", "DMIC2 L", "DMIC L2" },
2946 { "Mono DMIC R Mux", "DMIC1 R", "DMIC R1" },
2947 { "Mono DMIC R Mux", "DMIC2 R", "DMIC R2" },
2964 { "Mono ADC L Mux", "ADC1 L", "ADC1 L" },
2965 { "Mono ADC L Mux", "ADC1 R", "ADC1 R" },
2966 { "Mono ADC L Mux", "ADC2 L", "ADC2 L" },
2967 { "Mono ADC L Mux", "ADC2 R", "ADC2 R" },
2969 { "Mono ADC R Mux", "ADC1 L", "ADC1 L" },
2970 { "Mono ADC R Mux", "ADC1 R", "ADC1 R" },
2971 { "Mono ADC R Mux", "ADC2 L", "ADC2 L" },
2972 { "Mono ADC R Mux", "ADC2 R", "ADC2 R" },
2974 { "Mono ADC L2 Mux", "DMIC", "Mono DMIC L Mux" },
2975 { "Mono ADC L2 Mux", "Mono DAC MIXL", "Mono DAC MIXL" },
2976 { "Mono ADC L1 Mux", "Mono DAC MIXL", "Mono DAC MIXL" },
2977 { "Mono ADC L1 Mux", "ADC", "Mono ADC L Mux" },
2979 { "Mono ADC R1 Mux", "Mono DAC MIXR", "Mono DAC MIXR" },
2980 { "Mono ADC R1 Mux", "ADC", "Mono ADC R Mux" },
2981 { "Mono ADC R2 Mux", "DMIC", "Mono DMIC R Mux" },
2982 { "Mono ADC R2 Mux", "Mono DAC MIXR", "Mono DAC MIXR" },
2992 { "Mono ADC MIXL", "ADC1 Switch", "Mono ADC L1 Mux" },
2993 { "Mono ADC MIXL", "ADC2 Switch", "Mono ADC L2 Mux" },
2994 { "Mono ADC MIXL", NULL, "ADC Mono Left Filter" },
2996 { "Mono ADC MIXR", "ADC1 Switch", "Mono ADC R1 Mux" },
2997 { "Mono ADC MIXR", "ADC2 Switch", "Mono ADC R2 Mux" },
2998 { "Mono ADC MIXR", NULL, "ADC Mono Right Filter" },
3005 { "IF_ADC2", NULL, "Mono ADC MIXL" },
3006 { "IF_ADC2", NULL, "Mono ADC MIXR" },
3133 { "DAC L2 Mux", "Mono ADC MIX", "Mono ADC MIXL" },
3134 { "DAC L2 Mux", NULL, "DAC Mono Left Filter" },
3139 { "DAC R2 Mux", "Mono ADC MIX", "Mono ADC MIXR" },
3140 { "DAC R2 Mux", NULL, "DAC Mono Right Filter" },
3152 { "Mono DAC MIXL", "DAC L1 Switch", "DAC1 MIXL" },
3153 { "Mono DAC MIXL", "DAC R1 Switch", "DAC1 MIXR" },
3154 { "Mono DAC MIXL", "DAC L2 Switch", "DAC L2 Mux" },
3155 { "Mono DAC MIXL", "DAC R2 Switch", "DAC R2 Mux" },
3156 { "Mono DAC MIXR", "DAC L1 Switch", "DAC1 MIXL" },
3157 { "Mono DAC MIXR", "DAC R1 Switch", "DAC1 MIXR" },
3158 { "Mono DAC MIXR", "DAC R2 Switch", "DAC R2 Mux" },
3159 { "Mono DAC MIXR", "DAC L2 Switch", "DAC L2 Mux" },
3162 { "DAC MIXL", "Mono DAC Mixer", "Mono DAC MIXL" },
3164 { "DAC MIXR", "Mono DAC Mixer", "Mono DAC MIXR" },
3173 { "DAC L2 Source", "Mono DAC Mixer", "Mono DAC MIXL" },
3176 { "DAC R2 Source", "Mono DAC Mixer", "Mono DAC MIXR" },
3201 { "OUT MIXL", "DAC L2 Switch", "DAC L2" },
3202 { "OUT MIXL", "INL Switch", "INL VOL" },
3203 { "OUT MIXL", "BST1 Switch", "BST1" },
3204 { "OUT MIXL", "BST2 Switch", "BST2" },
3205 { "OUT MIXL", "BST3 Switch", "BST3" },
3206 { "OUT MIXR", "DAC R2 Switch", "DAC R2" },
3207 { "OUT MIXR", "INR Switch", "INR VOL" },
3208 { "OUT MIXR", "BST2 Switch", "BST2" },
3209 { "OUT MIXR", "BST3 Switch", "BST3" },
3210 { "OUT MIXR", "BST4 Switch", "BST4" },
3226 { "Mono MIX", "DAC L2 Switch", "DAC L2" },
3227 { "Mono MIX", "MONOVOL Switch", "MONOVOL" },
3228 { "Mono Amp", NULL, "Mono MIX" },
3229 { "Mono Amp", NULL, "Mono Vref" },
3230 { "Mono Amp", NULL, "SYS CLK DET" },
3231 { "Mono Playback", "Switch", "Mono Amp" },
3232 { "MONOOUT", NULL, "Mono Playback" },
3243 { "OUTVOL L", "Switch", "OUT MIXL" },
3244 { "OUTVOL R", "Switch", "OUT MIXR" },
3258 { "PDM L Mux", "Mono DAC", "Mono DAC MIXL" },
3261 { "PDM R Mux", "Mono DAC", "Mono DAC MIXR" },
3279 struct snd_soc_component *component = dai->component; in rt5659_hw_params()
3284 rt5659->lrck[dai->id] = params_rate(params); in rt5659_hw_params()
3285 pre_div = rl6231_get_clk_info(rt5659->sysclk, rt5659->lrck[dai->id]); in rt5659_hw_params()
3287 dev_err(component->dev, "Unsupported clock setting %d for DAI %d\n", in rt5659_hw_params()
3288 rt5659->lrck[dai->id], dai->id); in rt5659_hw_params()
3289 return -EINVAL; in rt5659_hw_params()
3293 dev_err(component->dev, "Unsupported frame size: %d\n", frame_size); in rt5659_hw_params()
3294 return -EINVAL; in rt5659_hw_params()
3297 dev_dbg(dai->dev, "lrck is %dHz and pre_div is %d for iis %d\n", in rt5659_hw_params()
3298 rt5659->lrck[dai->id], pre_div, dai->id); in rt5659_hw_params()
3313 return -EINVAL; in rt5659_hw_params()
3316 switch (dai->id) { in rt5659_hw_params()
3336 dev_err(component->dev, "Invalid dai->id: %d\n", dai->id); in rt5659_hw_params()
3337 return -EINVAL; in rt5659_hw_params()
3342 switch (rt5659->lrck[dai->id]) { in rt5659_hw_params()
3362 struct snd_soc_component *component = dai->component; in rt5659_set_dai_fmt()
3368 rt5659->master[dai->id] = 1; in rt5659_set_dai_fmt()
3372 rt5659->master[dai->id] = 0; in rt5659_set_dai_fmt()
3375 return -EINVAL; in rt5659_set_dai_fmt()
3385 return -EINVAL; in rt5659_set_dai_fmt()
3401 return -EINVAL; in rt5659_set_dai_fmt()
3404 switch (dai->id) { in rt5659_set_dai_fmt()
3421 dev_err(component->dev, "Invalid dai->id: %d\n", dai->id); in rt5659_set_dai_fmt()
3422 return -EINVAL; in rt5659_set_dai_fmt()
3434 if (freq == rt5659->sysclk && clk_id == rt5659->sysclk_src) in rt5659_set_component_sysclk()
3439 ret = clk_set_rate(rt5659->mclk, freq); in rt5659_set_component_sysclk()
3452 dev_err(component->dev, "Invalid clock id (%d)\n", clk_id); in rt5659_set_component_sysclk()
3453 return -EINVAL; in rt5659_set_component_sysclk()
3457 rt5659->sysclk = freq; in rt5659_set_component_sysclk()
3458 rt5659->sysclk_src = clk_id; in rt5659_set_component_sysclk()
3460 dev_dbg(component->dev, "Sysclk is %dHz and clock id is %d\n", in rt5659_set_component_sysclk()
3474 if (source == rt5659->pll_src && freq_in == rt5659->pll_in && in rt5659_set_component_pll()
3475 freq_out == rt5659->pll_out) in rt5659_set_component_pll()
3479 dev_dbg(component->dev, "PLL disabled\n"); in rt5659_set_component_pll()
3481 rt5659->pll_in = 0; in rt5659_set_component_pll()
3482 rt5659->pll_out = 0; in rt5659_set_component_pll()
3506 dev_err(component->dev, "Unknown PLL source %d\n", source); in rt5659_set_component_pll()
3507 return -EINVAL; in rt5659_set_component_pll()
3512 dev_err(component->dev, "Unsupported input clock %d\n", freq_in); in rt5659_set_component_pll()
3516 dev_dbg(component->dev, "bypass=%d m=%d n=%d k=%d\n", in rt5659_set_component_pll()
3526 rt5659->pll_in = freq_in; in rt5659_set_component_pll()
3527 rt5659->pll_out = freq_out; in rt5659_set_component_pll()
3528 rt5659->pll_src = source; in rt5659_set_component_pll()
3536 struct snd_soc_component *component = dai->component; in rt5659_set_tdm_slot()
3558 return -EINVAL; in rt5659_set_tdm_slot()
3577 return -EINVAL; in rt5659_set_tdm_slot()
3587 struct snd_soc_component *component = dai->component; in rt5659_set_bclk_ratio()
3590 dev_dbg(component->dev, "%s ratio=%d\n", __func__, ratio); in rt5659_set_bclk_ratio()
3592 rt5659->bclk[dai->id] = ratio; in rt5659_set_bclk_ratio()
3595 switch (dai->id) { in rt5659_set_bclk_ratio()
3621 regmap_update_bits(rt5659->regmap, RT5659_DIG_MISC, in rt5659_set_bias_level()
3623 regmap_update_bits(rt5659->regmap, RT5659_PWR_DIG_1, in rt5659_set_bias_level()
3625 regmap_update_bits(rt5659->regmap, RT5659_PWR_ANLG_1, in rt5659_set_bias_level()
3629 regmap_update_bits(rt5659->regmap, RT5659_PWR_ANLG_1, in rt5659_set_bias_level()
3635 if (dapm->bias_level == SND_SOC_BIAS_OFF) { in rt5659_set_bias_level()
3636 ret = clk_prepare_enable(rt5659->mclk); in rt5659_set_bias_level()
3638 dev_err(component->dev, in rt5659_set_bias_level()
3646 regmap_update_bits(rt5659->regmap, RT5659_PWR_DIG_1, in rt5659_set_bias_level()
3648 regmap_update_bits(rt5659->regmap, RT5659_PWR_ANLG_1, in rt5659_set_bias_level()
3652 regmap_update_bits(rt5659->regmap, RT5659_DIG_MISC, in rt5659_set_bias_level()
3654 clk_disable_unprepare(rt5659->mclk); in rt5659_set_bias_level()
3670 rt5659->component = component; in rt5659_probe()
3672 switch (rt5659->pdata.jd_src) { in rt5659_probe()
3690 regmap_write(rt5659->regmap, RT5659_RESET, 0); in rt5659_remove()
3698 regcache_cache_only(rt5659->regmap, true); in rt5659_suspend()
3699 regcache_mark_dirty(rt5659->regmap); in rt5659_suspend()
3707 regcache_cache_only(rt5659->regmap, false); in rt5659_resume()
3708 regcache_sync(rt5659->regmap); in rt5659_resume()
3730 .name = "rt5659-aif1",
3749 .name = "rt5659-aif2",
3768 .name = "rt5659-aif3",
3827 rt5659->pdata.in1_diff = device_property_read_bool(dev, in rt5659_parse_dt()
3828 "realtek,in1-differential"); in rt5659_parse_dt()
3829 rt5659->pdata.in3_diff = device_property_read_bool(dev, in rt5659_parse_dt()
3830 "realtek,in3-differential"); in rt5659_parse_dt()
3831 rt5659->pdata.in4_diff = device_property_read_bool(dev, in rt5659_parse_dt()
3832 "realtek,in4-differential"); in rt5659_parse_dt()
3835 device_property_read_u32(dev, "realtek,dmic1-data-pin", in rt5659_parse_dt()
3836 &rt5659->pdata.dmic1_data_pin); in rt5659_parse_dt()
3837 device_property_read_u32(dev, "realtek,dmic2-data-pin", in rt5659_parse_dt()
3838 &rt5659->pdata.dmic2_data_pin); in rt5659_parse_dt()
3839 device_property_read_u32(dev, "realtek,jd-src", in rt5659_parse_dt()
3840 &rt5659->pdata.jd_src); in rt5659_parse_dt()
3851 regmap_write(rt5659->regmap, RT5659_BIAS_CUR_CTRL_8, 0xa502); in rt5659_calibrate()
3852 regmap_write(rt5659->regmap, RT5659_CHOP_DAC, 0x3030); in rt5659_calibrate()
3854 regmap_write(rt5659->regmap, RT5659_PRE_DIV_1, 0xef00); in rt5659_calibrate()
3855 regmap_write(rt5659->regmap, RT5659_PRE_DIV_2, 0xeffc); in rt5659_calibrate()
3856 regmap_write(rt5659->regmap, RT5659_MICBIAS_2, 0x0280); in rt5659_calibrate()
3857 regmap_write(rt5659->regmap, RT5659_DIG_MISC, 0x0001); in rt5659_calibrate()
3858 regmap_write(rt5659->regmap, RT5659_GLB_CLK, 0x8000); in rt5659_calibrate()
3860 regmap_write(rt5659->regmap, RT5659_PWR_ANLG_1, 0xaa7e); in rt5659_calibrate()
3862 regmap_write(rt5659->regmap, RT5659_PWR_ANLG_1, 0xfe7e); in rt5659_calibrate()
3864 regmap_write(rt5659->regmap, RT5659_PWR_ANLG_3, 0x0004); in rt5659_calibrate()
3865 regmap_write(rt5659->regmap, RT5659_PWR_DIG_2, 0x0400); in rt5659_calibrate()
3867 regmap_write(rt5659->regmap, RT5659_PWR_DIG_1, 0x0080); in rt5659_calibrate()
3869 regmap_write(rt5659->regmap, RT5659_DEPOP_1, 0x0009); in rt5659_calibrate()
3871 regmap_write(rt5659->regmap, RT5659_PWR_DIG_1, 0x0f80); in rt5659_calibrate()
3873 regmap_write(rt5659->regmap, RT5659_HP_CHARGE_PUMP_1, 0x0e16); in rt5659_calibrate()
3877 regmap_write(rt5659->regmap, RT5659_CAL_REC, 0x0505); in rt5659_calibrate()
3879 regmap_write(rt5659->regmap, RT5659_PWR_ANLG_3, 0x0184); in rt5659_calibrate()
3880 regmap_write(rt5659->regmap, RT5659_CALIB_ADC_CTRL, 0x3c05); in rt5659_calibrate()
3881 regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_2, 0x20c1); in rt5659_calibrate()
3884 regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_2, 0x2cc1); in rt5659_calibrate()
3885 regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_1, 0x5100); in rt5659_calibrate()
3886 regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_7, 0x0014); in rt5659_calibrate()
3887 regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_1, 0xd100); in rt5659_calibrate()
3891 regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_2, 0x2cc1); in rt5659_calibrate()
3892 regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_1, 0x4900); in rt5659_calibrate()
3893 regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_7, 0x0016); in rt5659_calibrate()
3894 regmap_update_bits(rt5659->regmap, RT5659_HP_CALIB_CTRL_1, in rt5659_calibrate()
3899 regmap_read(rt5659->regmap, RT5659_HP_CALIB_CTRL_1, &value); in rt5659_calibrate()
3906 dev_err(rt5659->component->dev, in rt5659_calibrate()
3915 regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_2, 0x2cc1); in rt5659_calibrate()
3916 regmap_write(rt5659->regmap, RT5659_HP_VOL, 0x0000); in rt5659_calibrate()
3917 regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_1, 0x4500); in rt5659_calibrate()
3918 regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_7, 0x001f); in rt5659_calibrate()
3919 regmap_update_bits(rt5659->regmap, RT5659_HP_CALIB_CTRL_1, in rt5659_calibrate()
3924 regmap_read(rt5659->regmap, RT5659_HP_CALIB_CTRL_1, &value); in rt5659_calibrate()
3931 dev_err(rt5659->component->dev, in rt5659_calibrate()
3939 regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_7, 0x0000); in rt5659_calibrate()
3940 regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_2, 0x20c0); in rt5659_calibrate()
3944 regmap_write(rt5659->regmap, RT5659_CLASSD_0, 0x2021); in rt5659_calibrate()
3945 regmap_write(rt5659->regmap, RT5659_CLASSD_CTRL_1, 0x0260); in rt5659_calibrate()
3946 regmap_write(rt5659->regmap, RT5659_PWR_MIXER, 0x3000); in rt5659_calibrate()
3947 regmap_write(rt5659->regmap, RT5659_PWR_VOL, 0xc000); in rt5659_calibrate()
3948 regmap_write(rt5659->regmap, RT5659_A_DAC_MUX, 0x000c); in rt5659_calibrate()
3949 regmap_write(rt5659->regmap, RT5659_DIG_MISC, 0x8000); in rt5659_calibrate()
3950 regmap_write(rt5659->regmap, RT5659_SPO_VOL, 0x0808); in rt5659_calibrate()
3951 regmap_write(rt5659->regmap, RT5659_SPK_L_MIXER, 0x001e); in rt5659_calibrate()
3952 regmap_write(rt5659->regmap, RT5659_SPK_R_MIXER, 0x001e); in rt5659_calibrate()
3953 regmap_write(rt5659->regmap, RT5659_CLASSD_1, 0x0803); in rt5659_calibrate()
3954 regmap_write(rt5659->regmap, RT5659_CLASSD_2, 0x0554); in rt5659_calibrate()
3955 regmap_write(rt5659->regmap, RT5659_SPO_AMP_GAIN, 0x1103); in rt5659_calibrate()
3958 regmap_write(rt5659->regmap, RT5659_CAL_REC, 0x0909); in rt5659_calibrate()
3959 regmap_update_bits(rt5659->regmap, RT5659_HP_CALIB_CTRL_2, 0x0001, in rt5659_calibrate()
3963 regmap_write(rt5659->regmap, RT5659_SPK_DC_CAILB_CTRL_3, 0x0000); in rt5659_calibrate()
3964 regmap_write(rt5659->regmap, RT5659_CLASSD_0, 0x0021); in rt5659_calibrate()
3965 regmap_write(rt5659->regmap, RT5659_SPK_DC_CAILB_CTRL_1, 0x3e80); in rt5659_calibrate()
3966 regmap_update_bits(rt5659->regmap, RT5659_SPK_DC_CAILB_CTRL_1, in rt5659_calibrate()
3971 regmap_read(rt5659->regmap, in rt5659_calibrate()
3979 dev_err(rt5659->component->dev, in rt5659_calibrate()
3988 /* Calibrate MONO Start */ in rt5659_calibrate()
3989 regmap_write(rt5659->regmap, RT5659_DIG_MISC, 0x0000); in rt5659_calibrate()
3990 regmap_write(rt5659->regmap, RT5659_MONOMIX_IN_GAIN, 0x021f); in rt5659_calibrate()
3991 regmap_write(rt5659->regmap, RT5659_MONO_OUT, 0x480a); in rt5659_calibrate()
3992 /* MONO NG2 GAIN 5dB */ in rt5659_calibrate()
3993 regmap_write(rt5659->regmap, RT5659_MONO_GAIN, 0x0003); in rt5659_calibrate()
3994 regmap_write(rt5659->regmap, RT5659_MONO_NG2_CTRL_5, 0x0009); in rt5659_calibrate()
3997 regmap_write(rt5659->regmap, RT5659_SPK_DC_CAILB_CTRL_3, 0x000f); in rt5659_calibrate()
3998 regmap_write(rt5659->regmap, RT5659_MONO_AMP_CALIB_CTRL_1, 0x1e00); in rt5659_calibrate()
3999 regmap_update_bits(rt5659->regmap, RT5659_MONO_AMP_CALIB_CTRL_1, in rt5659_calibrate()
4004 regmap_read(rt5659->regmap, RT5659_MONO_AMP_CALIB_CTRL_1, in rt5659_calibrate()
4012 dev_err(rt5659->component->dev, in rt5659_calibrate()
4013 "Mono Calibration Failure\n"); in rt5659_calibrate()
4020 regmap_write(rt5659->regmap, RT5659_SPK_DC_CAILB_CTRL_3, 0x0003); in rt5659_calibrate()
4021 /* Calibrate MONO End */ in rt5659_calibrate()
4024 regmap_write(rt5659->regmap, RT5659_CAL_REC, 0x0808); in rt5659_calibrate()
4025 regmap_write(rt5659->regmap, RT5659_PWR_ANLG_3, 0x0000); in rt5659_calibrate()
4026 regmap_write(rt5659->regmap, RT5659_CALIB_ADC_CTRL, 0x2005); in rt5659_calibrate()
4027 regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_2, 0x20c0); in rt5659_calibrate()
4028 regmap_write(rt5659->regmap, RT5659_DEPOP_1, 0x0000); in rt5659_calibrate()
4029 regmap_write(rt5659->regmap, RT5659_CLASSD_1, 0x0011); in rt5659_calibrate()
4030 regmap_write(rt5659->regmap, RT5659_CLASSD_2, 0x0150); in rt5659_calibrate()
4031 regmap_write(rt5659->regmap, RT5659_PWR_ANLG_1, 0xfe3e); in rt5659_calibrate()
4032 regmap_write(rt5659->regmap, RT5659_MONO_OUT, 0xc80a); in rt5659_calibrate()
4033 regmap_write(rt5659->regmap, RT5659_MONO_AMP_CALIB_CTRL_1, 0x1e04); in rt5659_calibrate()
4034 regmap_write(rt5659->regmap, RT5659_PWR_MIXER, 0x0000); in rt5659_calibrate()
4035 regmap_write(rt5659->regmap, RT5659_PWR_VOL, 0x0000); in rt5659_calibrate()
4036 regmap_write(rt5659->regmap, RT5659_PWR_DIG_1, 0x0000); in rt5659_calibrate()
4037 regmap_write(rt5659->regmap, RT5659_PWR_DIG_2, 0x0000); in rt5659_calibrate()
4038 regmap_write(rt5659->regmap, RT5659_PWR_ANLG_1, 0x003e); in rt5659_calibrate()
4039 regmap_write(rt5659->regmap, RT5659_CLASSD_CTRL_1, 0x0060); in rt5659_calibrate()
4040 regmap_write(rt5659->regmap, RT5659_CLASSD_0, 0x2021); in rt5659_calibrate()
4041 regmap_write(rt5659->regmap, RT5659_GLB_CLK, 0x0000); in rt5659_calibrate()
4042 regmap_write(rt5659->regmap, RT5659_MICBIAS_2, 0x0080); in rt5659_calibrate()
4043 regmap_write(rt5659->regmap, RT5659_HP_VOL, 0x8080); in rt5659_calibrate()
4044 regmap_write(rt5659->regmap, RT5659_HP_CHARGE_PUMP_1, 0x0c16); in rt5659_calibrate()
4051 regmap_read(rt5659->regmap, RT5659_GPIO_STA, &value); in rt5659_intel_hd_header_probe_setup()
4053 rt5659->hda_hp_plugged = true; in rt5659_intel_hd_header_probe_setup()
4054 regmap_update_bits(rt5659->regmap, RT5659_IRQ_CTRL_1, in rt5659_intel_hd_header_probe_setup()
4057 regmap_update_bits(rt5659->regmap, RT5659_IRQ_CTRL_1, in rt5659_intel_hd_header_probe_setup()
4061 regmap_update_bits(rt5659->regmap, RT5659_PWR_ANLG_1, in rt5659_intel_hd_header_probe_setup()
4065 regmap_update_bits(rt5659->regmap, RT5659_PWR_ANLG_1, in rt5659_intel_hd_header_probe_setup()
4068 regmap_update_bits(rt5659->regmap, RT5659_PWR_ANLG_3, RT5659_PWR_LDO2, in rt5659_intel_hd_header_probe_setup()
4070 regmap_update_bits(rt5659->regmap, RT5659_PWR_ANLG_2, RT5659_PWR_MB1, in rt5659_intel_hd_header_probe_setup()
4072 regmap_update_bits(rt5659->regmap, RT5659_PWR_VOL, RT5659_PWR_MIC_DET, in rt5659_intel_hd_header_probe_setup()
4076 regmap_update_bits(rt5659->regmap, RT5659_4BTN_IL_CMD_2, in rt5659_intel_hd_header_probe_setup()
4078 regmap_read(rt5659->regmap, RT5659_4BTN_IL_CMD_1, &value); in rt5659_intel_hd_header_probe_setup()
4079 regmap_write(rt5659->regmap, RT5659_4BTN_IL_CMD_1, value); in rt5659_intel_hd_header_probe_setup()
4080 regmap_read(rt5659->regmap, RT5659_4BTN_IL_CMD_1, &value); in rt5659_intel_hd_header_probe_setup()
4083 rt5659->hda_mic_plugged = true; in rt5659_intel_hd_header_probe_setup()
4084 regmap_update_bits(rt5659->regmap, RT5659_IRQ_CTRL_2, in rt5659_intel_hd_header_probe_setup()
4087 regmap_update_bits(rt5659->regmap, RT5659_IRQ_CTRL_2, in rt5659_intel_hd_header_probe_setup()
4091 regmap_update_bits(rt5659->regmap, RT5659_IRQ_CTRL_2, in rt5659_intel_hd_header_probe_setup()
4097 struct rt5659_platform_data *pdata = dev_get_platdata(&i2c->dev); in rt5659_i2c_probe()
4102 rt5659 = devm_kzalloc(&i2c->dev, sizeof(struct rt5659_priv), in rt5659_i2c_probe()
4106 return -ENOMEM; in rt5659_i2c_probe()
4111 rt5659->pdata = *pdata; in rt5659_i2c_probe()
4113 rt5659_parse_dt(rt5659, &i2c->dev); in rt5659_i2c_probe()
4115 rt5659->gpiod_ldo1_en = devm_gpiod_get_optional(&i2c->dev, "ldo1-en", in rt5659_i2c_probe()
4117 if (IS_ERR(rt5659->gpiod_ldo1_en)) in rt5659_i2c_probe()
4118 dev_warn(&i2c->dev, "Request ldo1-en GPIO failed\n"); in rt5659_i2c_probe()
4120 rt5659->gpiod_reset = devm_gpiod_get_optional(&i2c->dev, "reset", in rt5659_i2c_probe()
4126 rt5659->regmap = devm_regmap_init_i2c(i2c, &rt5659_regmap); in rt5659_i2c_probe()
4127 if (IS_ERR(rt5659->regmap)) { in rt5659_i2c_probe()
4128 ret = PTR_ERR(rt5659->regmap); in rt5659_i2c_probe()
4129 dev_err(&i2c->dev, "Failed to allocate register map: %d\n", in rt5659_i2c_probe()
4134 regmap_read(rt5659->regmap, RT5659_DEVICE_ID, &val); in rt5659_i2c_probe()
4136 dev_err(&i2c->dev, in rt5659_i2c_probe()
4138 return -ENODEV; in rt5659_i2c_probe()
4141 regmap_write(rt5659->regmap, RT5659_RESET, 0); in rt5659_i2c_probe()
4144 rt5659->mclk = devm_clk_get(&i2c->dev, "mclk"); in rt5659_i2c_probe()
4145 if (IS_ERR(rt5659->mclk)) { in rt5659_i2c_probe()
4146 if (PTR_ERR(rt5659->mclk) != -ENOENT) in rt5659_i2c_probe()
4147 return PTR_ERR(rt5659->mclk); in rt5659_i2c_probe()
4149 rt5659->mclk = NULL; in rt5659_i2c_probe()
4155 if (rt5659->pdata.in1_diff) in rt5659_i2c_probe()
4156 regmap_update_bits(rt5659->regmap, RT5659_IN1_IN2, in rt5659_i2c_probe()
4158 if (rt5659->pdata.in3_diff) in rt5659_i2c_probe()
4159 regmap_update_bits(rt5659->regmap, RT5659_IN3_IN4, in rt5659_i2c_probe()
4161 if (rt5659->pdata.in4_diff) in rt5659_i2c_probe()
4162 regmap_update_bits(rt5659->regmap, RT5659_IN3_IN4, in rt5659_i2c_probe()
4166 if (rt5659->pdata.dmic1_data_pin != RT5659_DMIC1_NULL || in rt5659_i2c_probe()
4167 rt5659->pdata.dmic2_data_pin != RT5659_DMIC2_NULL) { in rt5659_i2c_probe()
4168 regmap_update_bits(rt5659->regmap, RT5659_GPIO_CTRL_1, in rt5659_i2c_probe()
4171 switch (rt5659->pdata.dmic1_data_pin) { in rt5659_i2c_probe()
4173 regmap_update_bits(rt5659->regmap, RT5659_DMIC_CTRL_1, in rt5659_i2c_probe()
4178 regmap_update_bits(rt5659->regmap, in rt5659_i2c_probe()
4182 regmap_update_bits(rt5659->regmap, RT5659_DMIC_CTRL_1, in rt5659_i2c_probe()
4184 regmap_update_bits(rt5659->regmap, RT5659_GPIO_CTRL_1, in rt5659_i2c_probe()
4189 regmap_update_bits(rt5659->regmap, RT5659_DMIC_CTRL_1, in rt5659_i2c_probe()
4191 regmap_update_bits(rt5659->regmap, RT5659_GPIO_CTRL_1, in rt5659_i2c_probe()
4196 regmap_update_bits(rt5659->regmap, RT5659_DMIC_CTRL_1, in rt5659_i2c_probe()
4198 regmap_update_bits(rt5659->regmap, RT5659_GPIO_CTRL_1, in rt5659_i2c_probe()
4204 dev_dbg(&i2c->dev, "no DMIC1\n"); in rt5659_i2c_probe()
4208 switch (rt5659->pdata.dmic2_data_pin) { in rt5659_i2c_probe()
4210 regmap_update_bits(rt5659->regmap, in rt5659_i2c_probe()
4217 regmap_update_bits(rt5659->regmap, in rt5659_i2c_probe()
4221 regmap_update_bits(rt5659->regmap, in rt5659_i2c_probe()
4228 regmap_update_bits(rt5659->regmap, in rt5659_i2c_probe()
4232 regmap_update_bits(rt5659->regmap, in rt5659_i2c_probe()
4239 regmap_update_bits(rt5659->regmap, in rt5659_i2c_probe()
4243 regmap_update_bits(rt5659->regmap, in rt5659_i2c_probe()
4250 dev_dbg(&i2c->dev, "no DMIC2\n"); in rt5659_i2c_probe()
4255 regmap_update_bits(rt5659->regmap, RT5659_GPIO_CTRL_1, in rt5659_i2c_probe()
4264 regmap_update_bits(rt5659->regmap, RT5659_DMIC_CTRL_1, in rt5659_i2c_probe()
4269 switch (rt5659->pdata.jd_src) { in rt5659_i2c_probe()
4271 regmap_write(rt5659->regmap, RT5659_EJD_CTRL_1, 0xa880); in rt5659_i2c_probe()
4272 regmap_write(rt5659->regmap, RT5659_RC_CLK_CTRL, 0x9000); in rt5659_i2c_probe()
4273 regmap_write(rt5659->regmap, RT5659_GPIO_CTRL_1, 0xc800); in rt5659_i2c_probe()
4274 regmap_update_bits(rt5659->regmap, RT5659_PWR_ANLG_1, in rt5659_i2c_probe()
4276 regmap_write(rt5659->regmap, RT5659_PWR_ANLG_2, 0x0001); in rt5659_i2c_probe()
4277 regmap_write(rt5659->regmap, RT5659_IRQ_CTRL_2, 0x0040); in rt5659_i2c_probe()
4278 INIT_DELAYED_WORK(&rt5659->jack_detect_work, in rt5659_i2c_probe()
4282 regmap_write(rt5659->regmap, RT5659_GPIO_CTRL_3, 0x8000); in rt5659_i2c_probe()
4283 regmap_write(rt5659->regmap, RT5659_RC_CLK_CTRL, 0x0900); in rt5659_i2c_probe()
4284 regmap_write(rt5659->regmap, RT5659_EJD_CTRL_1, 0x70c0); in rt5659_i2c_probe()
4285 regmap_write(rt5659->regmap, RT5659_JD_CTRL_1, 0x2000); in rt5659_i2c_probe()
4286 regmap_write(rt5659->regmap, RT5659_IRQ_CTRL_1, 0x0040); in rt5659_i2c_probe()
4287 INIT_DELAYED_WORK(&rt5659->jack_detect_work, in rt5659_i2c_probe()
4295 if (i2c->irq) { in rt5659_i2c_probe()
4296 ret = devm_request_threaded_irq(&i2c->dev, i2c->irq, NULL, in rt5659_i2c_probe()
4300 dev_err(&i2c->dev, "Failed to reguest IRQ: %d\n", ret); in rt5659_i2c_probe()
4303 regmap_update_bits(rt5659->regmap, RT5659_GPIO_CTRL_1, in rt5659_i2c_probe()
4307 return devm_snd_soc_register_component(&i2c->dev, in rt5659_i2c_probe()
4316 regmap_write(rt5659->regmap, RT5659_RESET, 0); in rt5659_i2c_shutdown()