Lines Matching +full:out +full:- +full:mono

1 // SPDX-License-Identifier: GPL-2.0-only
3 * rt5645.c -- RT5645 ALSA SoC audio codec driver
27 #include <sound/soc-dapm.h>
42 static unsigned int quirk = -1;
434 /* Some (package) variants have the headset-mic pin not-connected */
664 static const DECLARE_TLV_DB_SCALE(out_vol_tlv, -4650, 150, 0);
665 static const DECLARE_TLV_DB_SCALE(dac_vol_tlv, -6525, 75, 0);
666 static const DECLARE_TLV_DB_SCALE(in_vol_tlv, -3450, 150, 0);
667 static const DECLARE_TLV_DB_SCALE(adc_vol_tlv, -1725, 75, 0);
681 /* {-6, -4.5, -3, -1.5, 0, 0.82, 1.58, 2.28} dB */
683 0, 4, TLV_DB_SCALE_ITEM(-600, 150, 0),
692 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES; in rt5645_hweq_info()
693 uinfo->count = RT5645_HWEQ_NUM * sizeof(struct rt5645_eq_param_s); in rt5645_hweq_info()
704 (struct rt5645_eq_param_s_be16 *)ucontrol->value.bytes.data; in rt5645_hweq_get()
708 eq_param[i].reg = cpu_to_be16(rt5645->eq_param[i].reg); in rt5645_hweq_get()
709 eq_param[i].val = cpu_to_be16(rt5645->eq_param[i].val); in rt5645_hweq_get()
730 (struct rt5645_eq_param_s_be16 *)ucontrol->value.bytes.data; in rt5645_hweq_put()
734 rt5645->eq_param[i].reg = be16_to_cpu(eq_param[i].reg); in rt5645_hweq_put()
735 rt5645->eq_param[i].val = be16_to_cpu(eq_param[i].val); in rt5645_hweq_put()
739 for (i = RT5645_HWEQ_NUM - 1; i >= 0; i--) { in rt5645_hweq_put()
740 if (rt5645->eq_param[i].reg == 0) in rt5645_hweq_put()
742 else if (rt5645->eq_param[i].reg != RT5645_EQ_CTRL2) in rt5645_hweq_put()
749 if (!rt5645_validate_hweq(rt5645->eq_param[i].reg) && in rt5645_hweq_put()
750 rt5645->eq_param[i].reg != 0) in rt5645_hweq_put()
752 else if (rt5645->eq_param[i].reg == 0) in rt5645_hweq_put()
773 regmap_update_bits(rt5645->regmap, RT5645_MICBIAS, in rt5645_spk_put_volsw()
778 mod_delayed_work(system_power_efficient_wq, &rt5645->rcclock_work, in rt5645_spk_put_volsw()
811 SOC_DOUBLE("OUT Playback Switch", RT5645_LOUT1,
813 SOC_DOUBLE("OUT Channel Switch", RT5645_LOUT1,
815 SOC_DOUBLE_TLV("OUT Playback Volume", RT5645_LOUT1,
823 SOC_DOUBLE_TLV("Mono DAC Playback Volume", RT5645_DAC2_DIG_VOL,
841 SOC_DOUBLE("Mono ADC Capture Switch", RT5645_MONO_ADC_DIG_VOL,
843 SOC_DOUBLE_TLV("Mono ADC Capture Volume", RT5645_MONO_ADC_DIG_VOL,
850 SOC_DOUBLE_TLV("Mono ADC Boost Capture Volume", RT5645_ADC_BST_VOL2,
864 * set_dmic_clk - Set parameter of dmic.
874 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in set_dmic_clk()
878 rate = rt5645->sysclk / rl6231_get_pre_div(rt5645->regmap, in set_dmic_clk()
882 dev_err(component->dev, "Failed to set DMIC clock\n"); in set_dmic_clk()
892 struct snd_soc_component *component = snd_soc_dapm_to_component(source->dapm); in is_sys_clk_from_pll()
906 struct snd_soc_component *component = snd_soc_dapm_to_component(source->dapm); in is_using_asrc()
909 switch (source->shift) { in is_using_asrc()
957 if (rt5645_validate_hweq(rt5645->eq_param[i].reg)) in rt5645_enable_hweq()
958 regmap_write(rt5645->regmap, rt5645->eq_param[i].reg, in rt5645_enable_hweq()
959 rt5645->eq_param[i].val); in rt5645_enable_hweq()
968 * rt5645_sel_asrc_clk_src - select ASRC clock source for a set of filters
997 return -EINVAL; in rt5645_sel_asrc_clk_src()
1155 SOC_DAPM_SINGLE("OUT MIXL Switch", RT5645_REC_L2_MIXER,
1168 SOC_DAPM_SINGLE("OUT MIXR Switch", RT5645_REC_R2_MIXER,
1274 /*DAC1 L/R source*/ /* MX-29 [9:8] [11:10] */
1293 /*DAC2 L/R source*/ /* MX-1B [6:4] [2:0] */
1295 "IF1 DAC", "IF2 DAC", "IF3 DAC", "Mono ADC", "VAD_ADC"
1306 "IF1 DAC", "IF2 DAC", "IF3 DAC", "Mono ADC", "Haptic"
1317 /* MX-27 [12] */
1329 /* MX-27 [11] */
1341 /* MX-27 [8] */
1353 /* Mono ADC source */
1354 /* MX-28 [12] */
1356 "Mono DAC MIXL", "ADC"
1364 SOC_DAPM_ENUM("Mono ADC1 left source", rt5645_mono_adc_l1_enum);
1365 /* MX-28 [11] */
1367 "Mono DAC MIXL", "DMIC"
1375 SOC_DAPM_ENUM("Mono ADC2 left source", rt5645_mono_adc_l2_enum);
1377 /* MX-28 [8] */
1387 SOC_DAPM_ENUM("Mono DMIC left source", rt5645_mono_dmic_l_enum);
1388 /* MX-28 [1:0] */
1394 SOC_DAPM_ENUM("Mono DMIC Right source", rt5645_mono_dmic_r_enum);
1395 /* MX-28 [4] */
1397 "Mono DAC MIXR", "ADC"
1405 SOC_DAPM_ENUM("Mono ADC1 right source", rt5645_mono_adc_r1_enum);
1406 /* MX-28 [3] */
1408 "Mono DAC MIXR", "DMIC"
1416 SOC_DAPM_ENUM("Mono ADC2 right source", rt5645_mono_adc_r2_enum);
1418 /* MX-77 [9:8] */
1431 /* MX-78 [4:0] */
1469 /* MX-78 [15:14][13:12][11:10] */
1492 /* MX-77 [7:6][5:4][3:2] */
1511 /* MX-79 [14:12][10:8][6:4][2:0] */
1540 /* MX-7a [14:12][10:8][6:4][2:0] */
1565 /* MX-2d [3] [2] */
1584 /* MX-2d [1] [0] */
1586 "Stereo DAC Mixer", "Mono DAC Mixer"
1603 /* MX-2F [13:12] */
1615 /* MX-31 [15] [13] [11] [9] */
1617 "Mono DAC", "Stereo DAC"
1634 /* MX-9D [9:8] */
1636 "Sto1 ADC L", "Mono ADC L", "Mono ADC R"
1678 if (rt5645->codec_type == CODEC_TYPE_RT5650) { in hp_amp_power()
1683 regmap_write(rt5645->regmap, RT5645_PR_BASE + in hp_amp_power()
1687 regmap_read(rt5645->regmap, RT5645_PR_BASE + in hp_amp_power()
1694 regmap_write(rt5645->regmap, RT5645_PR_BASE + in hp_amp_power()
1697 regmap_write(rt5645->regmap, RT5645_PR_BASE + in hp_amp_power()
1706 regmap_write(rt5645->regmap, RT5645_PR_BASE + in hp_amp_power()
1728 regmap_write(rt5645->regmap, RT5645_PR_BASE + in hp_amp_power()
1730 regmap_write(rt5645->regmap, RT5645_PR_BASE + in hp_amp_power()
1736 hp_amp_power_count--; in hp_amp_power()
1738 if (rt5645->codec_type == CODEC_TYPE_RT5650) { in hp_amp_power()
1739 regmap_write(rt5645->regmap, RT5645_PR_BASE + in hp_amp_power()
1742 regmap_write(rt5645->regmap, RT5645_PR_BASE + in hp_amp_power()
1771 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in rt5645_hp_event()
1778 if (rt5645->codec_type == CODEC_TYPE_RT5645) { in rt5645_hp_event()
1785 regmap_write(rt5645->regmap, RT5645_PR_BASE + in rt5645_hp_event()
1805 if (rt5645->codec_type == CODEC_TYPE_RT5645) { in rt5645_hp_event()
1812 regmap_write(rt5645->regmap, RT5645_PR_BASE + in rt5645_hp_event()
1837 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in rt5645_spk_event()
1870 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in rt5645_lout_event()
1900 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in rt5645_bst2_event()
1923 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in rt5645_set_micbias1_event()
1948 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in rt5645_set_micbias2_event()
1988 SND_SOC_DAPM_SUPPLY_S("DAC MONO L ASRC", 1, RT5645_ASRC_1,
1990 SND_SOC_DAPM_SUPPLY_S("DAC MONO R ASRC", 1, RT5645_ASRC_1,
1994 SND_SOC_DAPM_SUPPLY_S("DMIC MONO L ASRC", 1, RT5645_ASRC_1,
1996 SND_SOC_DAPM_SUPPLY_S("DMIC MONO R ASRC", 1, RT5645_ASRC_1,
2000 SND_SOC_DAPM_SUPPLY_S("ADC MONO L ASRC", 1, RT5645_ASRC_1,
2002 SND_SOC_DAPM_SUPPLY_S("ADC MONO R ASRC", 1, RT5645_ASRC_1,
2070 SND_SOC_DAPM_MUX("Mono DMIC L Mux", SND_SOC_NOPM, 0, 0,
2072 SND_SOC_DAPM_MUX("Mono DMIC R Mux", SND_SOC_NOPM, 0, 0,
2074 SND_SOC_DAPM_MUX("Mono ADC L2 Mux", SND_SOC_NOPM, 0, 0,
2076 SND_SOC_DAPM_MUX("Mono ADC L1 Mux", SND_SOC_NOPM, 0, 0,
2078 SND_SOC_DAPM_MUX("Mono ADC R1 Mux", SND_SOC_NOPM, 0, 0,
2080 SND_SOC_DAPM_MUX("Mono ADC R2 Mux", SND_SOC_NOPM, 0, 0,
2092 SND_SOC_DAPM_SUPPLY_S("adc mono left filter", 1, RT5645_PWR_DIG2,
2094 SND_SOC_DAPM_MIXER_E("Mono ADC MIXL", SND_SOC_NOPM, 0, 0,
2097 SND_SOC_DAPM_SUPPLY_S("adc mono right filter", 1, RT5645_PWR_DIG2,
2099 SND_SOC_DAPM_MIXER_E("Mono ADC MIXR", SND_SOC_NOPM, 0, 0,
2167 SND_SOC_DAPM_SUPPLY_S("dac mono left filter", 1, RT5645_PWR_DIG2,
2169 SND_SOC_DAPM_SUPPLY_S("dac mono right filter", 1, RT5645_PWR_DIG2,
2175 SND_SOC_DAPM_MIXER("Mono DAC MIXL", SND_SOC_NOPM, 0, 0,
2177 SND_SOC_DAPM_MIXER("Mono DAC MIXR", SND_SOC_NOPM, 0, 0,
2193 /* OUT Mixer */
2198 SND_SOC_DAPM_MIXER("OUT MIXL", RT5645_PWR_MIXER, RT5645_PWR_OM_L_BIT,
2200 SND_SOC_DAPM_MIXER("OUT MIXR", RT5645_PWR_MIXER, RT5645_PWR_OM_R_BIT,
2221 /* HPO/LOUT/Mono Mixer */
2308 { "adc mono left filter", NULL, "ADC MONO L ASRC", is_using_asrc },
2309 { "adc mono right filter", NULL, "ADC MONO R ASRC", is_using_asrc },
2310 { "dac mono left filter", NULL, "DAC MONO L ASRC", is_using_asrc },
2311 { "dac mono right filter", NULL, "DAC MONO R ASRC", is_using_asrc },
2339 { "RECMIXL", "OUT MIXL Switch", "OUT MIXL" },
2345 { "RECMIXR", "OUT MIXR Switch", "OUT MIXR" },
2365 { "Mono DMIC L Mux", "DMIC1", "DMIC L1" },
2366 { "Mono DMIC L Mux", "DMIC2", "DMIC L2" },
2367 { "Mono DMIC L Mux", NULL, "DMIC MONO L ASRC" },
2369 { "Mono DMIC R Mux", "DMIC1", "DMIC R1" },
2370 { "Mono DMIC R Mux", "DMIC2", "DMIC R2" },
2371 { "Mono DMIC R Mux", NULL, "DMIC MONO R ASRC" },
2383 { "Mono ADC L2 Mux", "DMIC", "Mono DMIC L Mux" },
2384 { "Mono ADC L2 Mux", "Mono DAC MIXL", "Mono DAC MIXL" },
2385 { "Mono ADC L1 Mux", "Mono DAC MIXL", "Mono DAC MIXL" },
2386 { "Mono ADC L1 Mux", "ADC", "ADC L" },
2388 { "Mono ADC R1 Mux", "Mono DAC MIXR", "Mono DAC MIXR" },
2389 { "Mono ADC R1 Mux", "ADC", "ADC R" },
2390 { "Mono ADC R2 Mux", "DMIC", "Mono DMIC R Mux" },
2391 { "Mono ADC R2 Mux", "Mono DAC MIXR", "Mono DAC MIXR" },
2406 { "Mono ADC MIXL", "ADC1 Switch", "Mono ADC L1 Mux" },
2407 { "Mono ADC MIXL", "ADC2 Switch", "Mono ADC L2 Mux" },
2408 { "Mono ADC MIXL", NULL, "adc mono left filter" },
2409 { "adc mono left filter", NULL, "PLL1", is_sys_clk_from_pll },
2411 { "Mono ADC MIXR", "ADC1 Switch", "Mono ADC R1 Mux" },
2412 { "Mono ADC MIXR", "ADC2 Switch", "Mono ADC R2 Mux" },
2413 { "Mono ADC MIXR", NULL, "adc mono right filter" },
2414 { "adc mono right filter", NULL, "PLL1", is_sys_clk_from_pll },
2417 { "VAD ADC Mux", "Mono ADC L", "Mono ADC MIXL" },
2418 { "VAD ADC Mux", "Mono ADC R", "Mono ADC MIXR" },
2422 { "IF_ADC2", NULL, "Mono ADC MIXL" },
2423 { "IF_ADC2", NULL, "Mono ADC MIXR" },
2462 { "DAC L2 Mux", "Mono ADC", "Mono ADC MIXL" },
2465 { "DAC L2 Volume", NULL, "dac mono left filter" },
2468 { "DAC R2 Mux", "Mono ADC", "Mono ADC MIXR" },
2471 { "DAC R2 Volume", NULL, "dac mono right filter" },
2482 { "Mono DAC MIXL", "DAC L1 Switch", "DAC1 MIXL" },
2483 { "Mono DAC MIXL", "DAC L2 Switch", "DAC L2 Volume" },
2484 { "Mono DAC MIXL", "DAC R2 Switch", "DAC R2 Volume" },
2485 { "Mono DAC MIXL", NULL, "dac mono left filter" },
2486 { "Mono DAC MIXR", "DAC R1 Switch", "DAC1 MIXR" },
2487 { "Mono DAC MIXR", "DAC R2 Switch", "DAC R2 Volume" },
2488 { "Mono DAC MIXR", "DAC L2 Switch", "DAC L2 Volume" },
2489 { "Mono DAC MIXR", NULL, "dac mono right filter" },
2512 { "OUT MIXL", "BST1 Switch", "BST1" },
2513 { "OUT MIXL", "INL Switch", "INL VOL" },
2514 { "OUT MIXL", "DAC L2 Switch", "DAC L2" },
2515 { "OUT MIXL", "DAC L1 Switch", "DAC L1" },
2517 { "OUT MIXR", "BST2 Switch", "BST2" },
2518 { "OUT MIXR", "INR Switch", "INR VOL" },
2519 { "OUT MIXR", "DAC R2 Switch", "DAC R2" },
2520 { "OUT MIXR", "DAC R1 Switch", "DAC R1" },
2554 { "LOUT MIX", "OUTMIX L Switch", "OUT MIXL" },
2555 { "LOUT MIX", "OUTMIX R Switch", "OUT MIXR" },
2558 { "PDM1 L Mux", "Mono DAC", "Mono DAC MIXL" },
2561 { "PDM1 R Mux", "Mono DAC", "Mono DAC MIXR" },
2594 { "A DAC2 L Mux", "Mono DAC Mixer", "Mono DAC MIXL"},
2596 { "A DAC2 R Mux", "Mono DAC Mixer", "Mono DAC MIXR"},
2681 { "DAC L2", NULL, "Mono DAC MIXL" },
2682 { "DAC R2", NULL, "Mono DAC MIXR" },
2744 struct snd_soc_component *component = dai->component; in rt5645_hw_params()
2749 rt5645->lrck[dai->id] = params_rate(params); in rt5645_hw_params()
2750 pre_div = rl6231_get_clk_info(rt5645->sysclk, rt5645->lrck[dai->id]); in rt5645_hw_params()
2752 dev_err(component->dev, "Unsupported clock setting\n"); in rt5645_hw_params()
2753 return -EINVAL; in rt5645_hw_params()
2757 dev_err(component->dev, "Unsupported frame size: %d\n", frame_size); in rt5645_hw_params()
2758 return -EINVAL; in rt5645_hw_params()
2761 switch (rt5645->codec_type) { in rt5645_hw_params()
2771 rt5645->bclk[dai->id] = rt5645->lrck[dai->id] * (32 << bclk_ms); in rt5645_hw_params()
2773 dev_dbg(dai->dev, "bclk is %dHz and lrck is %dHz\n", in rt5645_hw_params()
2774 rt5645->bclk[dai->id], rt5645->lrck[dai->id]); in rt5645_hw_params()
2775 dev_dbg(dai->dev, "bclk_ms is %d and pre_div is %d for iis %d\n", in rt5645_hw_params()
2776 bclk_ms, pre_div, dai->id); in rt5645_hw_params()
2791 return -EINVAL; in rt5645_hw_params()
2794 switch (dai->id) { in rt5645_hw_params()
2811 dev_err(component->dev, "Invalid dai->id: %d\n", dai->id); in rt5645_hw_params()
2812 return -EINVAL; in rt5645_hw_params()
2820 struct snd_soc_component *component = dai->component; in rt5645_set_dai_fmt()
2824 switch (rt5645->codec_type) { in rt5645_set_dai_fmt()
2835 rt5645->master[dai->id] = 1; in rt5645_set_dai_fmt()
2839 rt5645->master[dai->id] = 0; in rt5645_set_dai_fmt()
2842 return -EINVAL; in rt5645_set_dai_fmt()
2852 return -EINVAL; in rt5645_set_dai_fmt()
2868 return -EINVAL; in rt5645_set_dai_fmt()
2870 switch (dai->id) { in rt5645_set_dai_fmt()
2882 dev_err(component->dev, "Invalid dai->id: %d\n", dai->id); in rt5645_set_dai_fmt()
2883 return -EINVAL; in rt5645_set_dai_fmt()
2891 struct snd_soc_component *component = dai->component; in rt5645_set_dai_sysclk()
2895 if (freq == rt5645->sysclk && clk_id == rt5645->sysclk_src) in rt5645_set_dai_sysclk()
2909 dev_err(component->dev, "Invalid clock id (%d)\n", clk_id); in rt5645_set_dai_sysclk()
2910 return -EINVAL; in rt5645_set_dai_sysclk()
2914 rt5645->sysclk = freq; in rt5645_set_dai_sysclk()
2915 rt5645->sysclk_src = clk_id; in rt5645_set_dai_sysclk()
2917 dev_dbg(dai->dev, "Sysclk is %dHz and clock id is %d\n", freq, clk_id); in rt5645_set_dai_sysclk()
2925 struct snd_soc_component *component = dai->component; in rt5645_set_dai_pll()
2930 if (source == rt5645->pll_src && freq_in == rt5645->pll_in && in rt5645_set_dai_pll()
2931 freq_out == rt5645->pll_out) in rt5645_set_dai_pll()
2935 dev_dbg(component->dev, "PLL disabled\n"); in rt5645_set_dai_pll()
2937 rt5645->pll_in = 0; in rt5645_set_dai_pll()
2938 rt5645->pll_out = 0; in rt5645_set_dai_pll()
2951 switch (dai->id) { in rt5645_set_dai_pll()
2961 dev_err(component->dev, "Invalid dai->id: %d\n", dai->id); in rt5645_set_dai_pll()
2962 return -EINVAL; in rt5645_set_dai_pll()
2966 dev_err(component->dev, "Unknown PLL source %d\n", source); in rt5645_set_dai_pll()
2967 return -EINVAL; in rt5645_set_dai_pll()
2972 dev_err(component->dev, "Unsupported input clock %d\n", freq_in); in rt5645_set_dai_pll()
2976 dev_dbg(component->dev, "bypass=%d m=%d n=%d k=%d\n", in rt5645_set_dai_pll()
2986 rt5645->pll_in = freq_in; in rt5645_set_dai_pll()
2987 rt5645->pll_out = freq_out; in rt5645_set_dai_pll()
2988 rt5645->pll_src = source; in rt5645_set_dai_pll()
2996 struct snd_soc_component *component = dai->component; in rt5645_set_tdm_slot()
3001 switch (rt5645->codec_type) { in rt5645_set_tdm_slot()
3019 if (rt5645->codec_type == CODEC_TYPE_RT5645) in rt5645_set_tdm_slot()
3094 if (rt5645->en_button_func) in rt5645_set_bias_level()
3096 &rt5645->jack_detect_work, in rt5645_set_bias_level()
3103 if (!rt5645->en_button_func) in rt5645_set_bias_level()
3154 regmap_write(rt5645->regmap, RT5645_CHARGE_PUMP, 0x0e06); in rt5645_jack_detect()
3160 if (!dapm->card->instantiated) { in rt5645_jack_detect()
3163 regmap_update_bits(rt5645->regmap, RT5645_PWR_ANLG1, in rt5645_jack_detect()
3166 regmap_update_bits(rt5645->regmap, RT5645_PWR_MIXER, in rt5645_jack_detect()
3168 regmap_update_bits(rt5645->regmap, RT5645_PWR_VOL, in rt5645_jack_detect()
3172 regmap_write(rt5645->regmap, RT5645_JD_CTRL3, 0x00f0); in rt5645_jack_detect()
3173 regmap_update_bits(rt5645->regmap, RT5645_IN1_CTRL2, in rt5645_jack_detect()
3175 regmap_update_bits(rt5645->regmap, RT5645_IN1_CTRL1, in rt5645_jack_detect()
3178 regmap_update_bits(rt5645->regmap, RT5645_IN1_CTRL2, in rt5645_jack_detect()
3182 regmap_read(rt5645->regmap, RT5645_IN1_CTRL3, &val); in rt5645_jack_detect()
3184 dev_dbg(component->dev, "val = %d\n", val); in rt5645_jack_detect()
3186 if ((val == 1 || val == 2) && !rt5645->pdata.no_headset_mic) { in rt5645_jack_detect()
3187 rt5645->jack_type = SND_JACK_HEADSET; in rt5645_jack_detect()
3188 if (rt5645->en_button_func) { in rt5645_jack_detect()
3194 rt5645->jack_type = SND_JACK_HEADPHONE; in rt5645_jack_detect()
3196 if (rt5645->pdata.level_trigger_irq) in rt5645_jack_detect()
3197 regmap_update_bits(rt5645->regmap, RT5645_IRQ_CTRL2, in rt5645_jack_detect()
3199 } else { /* jack out */ in rt5645_jack_detect()
3200 rt5645->jack_type = 0; in rt5645_jack_detect()
3202 regmap_update_bits(rt5645->regmap, RT5645_HP_VOL, in rt5645_jack_detect()
3205 regmap_update_bits(rt5645->regmap, RT5645_IN1_CTRL2, in rt5645_jack_detect()
3207 regmap_update_bits(rt5645->regmap, RT5645_IN1_CTRL1, in rt5645_jack_detect()
3210 if (rt5645->en_button_func) in rt5645_jack_detect()
3213 if (rt5645->pdata.jd_mode == 0) in rt5645_jack_detect()
3217 if (rt5645->pdata.level_trigger_irq) in rt5645_jack_detect()
3218 regmap_update_bits(rt5645->regmap, RT5645_IRQ_CTRL2, in rt5645_jack_detect()
3222 return rt5645->jack_type; in rt5645_jack_detect()
3245 rt5645->hp_jack = hp_jack; in rt5645_set_jack_detect()
3246 rt5645->mic_jack = mic_jack; in rt5645_set_jack_detect()
3247 rt5645->btn_jack = btn_jack; in rt5645_set_jack_detect()
3248 if (rt5645->btn_jack && rt5645->codec_type == CODEC_TYPE_RT5650) { in rt5645_set_jack_detect()
3249 rt5645->en_button_func = true; in rt5645_set_jack_detect()
3250 regmap_update_bits(rt5645->regmap, RT5645_GPIO_CTRL1, in rt5645_set_jack_detect()
3252 regmap_update_bits(rt5645->regmap, RT5645_GEN_CTRL1, in rt5645_set_jack_detect()
3267 if (!rt5645->component) in rt5645_jack_detect_work()
3270 switch (rt5645->pdata.jd_mode) { in rt5645_jack_detect_work()
3272 if (rt5645->gpiod_hp_det) { in rt5645_jack_detect_work()
3273 gpio_state = gpiod_get_value(rt5645->gpiod_hp_det); in rt5645_jack_detect_work()
3274 if (rt5645->pdata.inv_hp_pol) in rt5645_jack_detect_work()
3276 dev_dbg(rt5645->component->dev, "gpio_state = %d\n", in rt5645_jack_detect_work()
3278 report = rt5645_jack_detect(rt5645->component, gpio_state); in rt5645_jack_detect_work()
3280 snd_soc_jack_report(rt5645->hp_jack, in rt5645_jack_detect_work()
3282 snd_soc_jack_report(rt5645->mic_jack, in rt5645_jack_detect_work()
3286 val = snd_soc_component_read(rt5645->component, RT5645_A_JD_CTRL1) & 0x0020; in rt5645_jack_detect_work()
3289 val = snd_soc_component_read(rt5645->component, RT5645_INT_IRQ_ST) & 0x1000; in rt5645_jack_detect_work()
3294 if (!val && (rt5645->jack_type == 0)) { /* jack in */ in rt5645_jack_detect_work()
3295 report = rt5645_jack_detect(rt5645->component, 1); in rt5645_jack_detect_work()
3296 } else if (!val && rt5645->jack_type != 0) { in rt5645_jack_detect_work()
3297 /* for push button and jack out */ in rt5645_jack_detect_work()
3299 if (snd_soc_component_read(rt5645->component, RT5645_INT_IRQ_ST) & 0x4) { in rt5645_jack_detect_work()
3302 btn_type = rt5645_button_detect(rt5645->component); in rt5645_jack_detect_work()
3332 dev_err(rt5645->component->dev, in rt5645_jack_detect_work()
3339 report = rt5645->jack_type; in rt5645_jack_detect_work()
3341 mod_timer(&rt5645->btn_check_timer, in rt5645_jack_detect_work()
3345 /* jack out */ in rt5645_jack_detect_work()
3347 snd_soc_component_update_bits(rt5645->component, in rt5645_jack_detect_work()
3349 rt5645_jack_detect(rt5645->component, 0); in rt5645_jack_detect_work()
3352 snd_soc_jack_report(rt5645->hp_jack, report, SND_JACK_HEADPHONE); in rt5645_jack_detect_work()
3353 snd_soc_jack_report(rt5645->mic_jack, report, SND_JACK_MICROPHONE); in rt5645_jack_detect_work()
3354 if (rt5645->en_button_func) in rt5645_jack_detect_work()
3355 snd_soc_jack_report(rt5645->btn_jack, in rt5645_jack_detect_work()
3365 regmap_update_bits(rt5645->regmap, RT5645_MICBIAS, in rt5645_rcclock_work()
3374 &rt5645->jack_detect_work, msecs_to_jiffies(250)); in rt5645_irq()
3384 &rt5645->jack_detect_work, msecs_to_jiffies(5)); in rt5645_btn_check_callback()
3392 rt5645->component = component; in rt5645_probe()
3394 switch (rt5645->codec_type) { in rt5645_probe()
3402 if (rt5645->v_id < 3) { in rt5645_probe()
3421 if (rt5645->pdata.jd_mode) { in rt5645_probe()
3427 if (rt5645->pdata.long_name) in rt5645_probe()
3428 component->card->long_name = rt5645->pdata.long_name; in rt5645_probe()
3430 rt5645->eq_param = devm_kcalloc(component->dev, in rt5645_probe()
3434 if (!rt5645->eq_param) in rt5645_probe()
3435 return -ENOMEM; in rt5645_probe()
3450 regcache_cache_only(rt5645->regmap, true); in rt5645_suspend()
3451 regcache_mark_dirty(rt5645->regmap); in rt5645_suspend()
3460 regcache_cache_only(rt5645->regmap, false); in rt5645_resume()
3461 regcache_sync(rt5645->regmap); in rt5645_resume()
3484 .name = "rt5645-aif1",
3503 .name = "rt5645-aif2",
3627 .long_name = "gpd-win-pocket-rt5645",
3674 { "hp-detect-gpios", &ef20_hp_detect, 1 },
3756 .ident = "MINIX Z83-4",
3759 DMI_MATCH(DMI_PRODUCT_NAME, "Z83-4"),
3776 DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "MIIX 310-10ICR"),
3785 DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "Lenovo MIIX 320-10ICR"),
3834 if (device_property_present(dev, "realtek,in2-differential") || in rt5645_check_dp()
3835 device_property_present(dev, "realtek,dmic1-data-pin") || in rt5645_check_dp()
3836 device_property_present(dev, "realtek,dmic2-data-pin") || in rt5645_check_dp()
3837 device_property_present(dev, "realtek,jd-mode")) in rt5645_check_dp()
3845 rt5645->pdata.in2_diff = device_property_read_bool(dev, in rt5645_parse_dt()
3846 "realtek,in2-differential"); in rt5645_parse_dt()
3848 "realtek,dmic1-data-pin", &rt5645->pdata.dmic1_data_pin); in rt5645_parse_dt()
3850 "realtek,dmic2-data-pin", &rt5645->pdata.dmic2_data_pin); in rt5645_parse_dt()
3852 "realtek,jd-mode", &rt5645->pdata.jd_mode); in rt5645_parse_dt()
3866 rt5645 = devm_kzalloc(&i2c->dev, sizeof(struct rt5645_priv), in rt5645_i2c_probe()
3869 return -ENOMEM; in rt5645_i2c_probe()
3871 rt5645->i2c = i2c; in rt5645_i2c_probe()
3876 dev_info(&i2c->dev, "Detected %s platform\n", dmi_data->ident); in rt5645_i2c_probe()
3877 pdata = dmi_data->driver_data; in rt5645_i2c_probe()
3881 rt5645->pdata = *pdata; in rt5645_i2c_probe()
3882 else if (rt5645_check_dp(&i2c->dev)) in rt5645_i2c_probe()
3883 rt5645_parse_dt(rt5645, &i2c->dev); in rt5645_i2c_probe()
3885 rt5645->pdata = jd_mode3_platform_data; in rt5645_i2c_probe()
3887 if (quirk != -1) { in rt5645_i2c_probe()
3888 rt5645->pdata.in2_diff = QUIRK_IN2_DIFF(quirk); in rt5645_i2c_probe()
3889 rt5645->pdata.level_trigger_irq = QUIRK_LEVEL_IRQ(quirk); in rt5645_i2c_probe()
3890 rt5645->pdata.inv_jd1_1 = QUIRK_INV_JD1_1(quirk); in rt5645_i2c_probe()
3891 rt5645->pdata.inv_hp_pol = QUIRK_INV_HP_POL(quirk); in rt5645_i2c_probe()
3892 rt5645->pdata.jd_mode = QUIRK_JD_MODE(quirk); in rt5645_i2c_probe()
3893 rt5645->pdata.dmic1_data_pin = QUIRK_DMIC1_DATA_PIN(quirk); in rt5645_i2c_probe()
3894 rt5645->pdata.dmic2_data_pin = QUIRK_DMIC2_DATA_PIN(quirk); in rt5645_i2c_probe()
3897 if (has_acpi_companion(&i2c->dev)) { in rt5645_i2c_probe()
3899 if (devm_acpi_dev_add_driver_gpios(&i2c->dev, cht_rt5645_gpios)) in rt5645_i2c_probe()
3900 dev_dbg(&i2c->dev, "Failed to add driver gpios\n"); in rt5645_i2c_probe()
3903 /* The ALC3270 package has the headset-mic pin not-connected */ in rt5645_i2c_probe()
3904 if (acpi_dev_hid_uid_match(ACPI_COMPANION(&i2c->dev), "10EC3270", NULL)) in rt5645_i2c_probe()
3905 rt5645->pdata.no_headset_mic = true; in rt5645_i2c_probe()
3908 rt5645->gpiod_hp_det = devm_gpiod_get_optional(&i2c->dev, "hp-detect", in rt5645_i2c_probe()
3911 if (IS_ERR(rt5645->gpiod_hp_det)) { in rt5645_i2c_probe()
3912 dev_info(&i2c->dev, "failed to initialize gpiod\n"); in rt5645_i2c_probe()
3913 ret = PTR_ERR(rt5645->gpiod_hp_det); in rt5645_i2c_probe()
3916 * errors, including -EPROBE_DEFER in rt5645_i2c_probe()
3918 if (ret != -ENOENT) in rt5645_i2c_probe()
3922 for (i = 0; i < ARRAY_SIZE(rt5645->supplies); i++) in rt5645_i2c_probe()
3923 rt5645->supplies[i].supply = rt5645_supply_names[i]; in rt5645_i2c_probe()
3925 ret = devm_regulator_bulk_get(&i2c->dev, in rt5645_i2c_probe()
3926 ARRAY_SIZE(rt5645->supplies), in rt5645_i2c_probe()
3927 rt5645->supplies); in rt5645_i2c_probe()
3929 dev_err(&i2c->dev, "Failed to request supplies: %d\n", ret); in rt5645_i2c_probe()
3933 ret = regulator_bulk_enable(ARRAY_SIZE(rt5645->supplies), in rt5645_i2c_probe()
3934 rt5645->supplies); in rt5645_i2c_probe()
3936 dev_err(&i2c->dev, "Failed to enable supplies: %d\n", ret); in rt5645_i2c_probe()
3943 dev_err(&i2c->dev, "Failed to allocate temp register map: %d\n", in rt5645_i2c_probe()
3957 rt5645->regmap = devm_regmap_init_i2c(i2c, &rt5645_regmap); in rt5645_i2c_probe()
3958 rt5645->codec_type = CODEC_TYPE_RT5645; in rt5645_i2c_probe()
3961 rt5645->regmap = devm_regmap_init_i2c(i2c, &rt5650_regmap); in rt5645_i2c_probe()
3962 rt5645->codec_type = CODEC_TYPE_RT5650; in rt5645_i2c_probe()
3965 dev_err(&i2c->dev, in rt5645_i2c_probe()
3968 ret = -ENODEV; in rt5645_i2c_probe()
3972 if (IS_ERR(rt5645->regmap)) { in rt5645_i2c_probe()
3973 ret = PTR_ERR(rt5645->regmap); in rt5645_i2c_probe()
3974 dev_err(&i2c->dev, "Failed to allocate register map: %d\n", in rt5645_i2c_probe()
3979 regmap_write(rt5645->regmap, RT5645_RESET, 0); in rt5645_i2c_probe()
3982 rt5645->v_id = val & 0xff; in rt5645_i2c_probe()
3984 regmap_write(rt5645->regmap, RT5645_AD_DA_MIXER, 0x8080); in rt5645_i2c_probe()
3986 ret = regmap_register_patch(rt5645->regmap, init_list, in rt5645_i2c_probe()
3989 dev_warn(&i2c->dev, "Failed to apply regmap patch: %d\n", ret); in rt5645_i2c_probe()
3991 if (rt5645->codec_type == CODEC_TYPE_RT5650) { in rt5645_i2c_probe()
3992 ret = regmap_register_patch(rt5645->regmap, rt5650_init_list, in rt5645_i2c_probe()
3995 dev_warn(&i2c->dev, "Apply rt5650 patch failed: %d\n", in rt5645_i2c_probe()
3999 regmap_update_bits(rt5645->regmap, RT5645_CLSD_OUT_CTRL, 0xc0, 0xc0); in rt5645_i2c_probe()
4001 if (rt5645->pdata.in2_diff) in rt5645_i2c_probe()
4002 regmap_update_bits(rt5645->regmap, RT5645_IN2_CTRL, in rt5645_i2c_probe()
4005 if (rt5645->pdata.dmic1_data_pin || rt5645->pdata.dmic2_data_pin) { in rt5645_i2c_probe()
4006 regmap_update_bits(rt5645->regmap, RT5645_GPIO_CTRL1, in rt5645_i2c_probe()
4009 switch (rt5645->pdata.dmic1_data_pin) { in rt5645_i2c_probe()
4011 regmap_update_bits(rt5645->regmap, RT5645_DMIC_CTRL1, in rt5645_i2c_probe()
4016 regmap_update_bits(rt5645->regmap, RT5645_GPIO_CTRL1, in rt5645_i2c_probe()
4018 regmap_update_bits(rt5645->regmap, RT5645_DMIC_CTRL1, in rt5645_i2c_probe()
4020 regmap_update_bits(rt5645->regmap, RT5645_GPIO_CTRL1, in rt5645_i2c_probe()
4025 regmap_update_bits(rt5645->regmap, RT5645_DMIC_CTRL1, in rt5645_i2c_probe()
4027 regmap_update_bits(rt5645->regmap, RT5645_GPIO_CTRL1, in rt5645_i2c_probe()
4036 switch (rt5645->pdata.dmic2_data_pin) { in rt5645_i2c_probe()
4038 regmap_update_bits(rt5645->regmap, RT5645_DMIC_CTRL1, in rt5645_i2c_probe()
4043 regmap_update_bits(rt5645->regmap, RT5645_DMIC_CTRL1, in rt5645_i2c_probe()
4045 regmap_update_bits(rt5645->regmap, RT5645_GPIO_CTRL1, in rt5645_i2c_probe()
4050 regmap_update_bits(rt5645->regmap, RT5645_DMIC_CTRL1, in rt5645_i2c_probe()
4052 regmap_update_bits(rt5645->regmap, RT5645_GPIO_CTRL1, in rt5645_i2c_probe()
4058 regmap_update_bits(rt5645->regmap, RT5645_DMIC_CTRL1, in rt5645_i2c_probe()
4060 regmap_update_bits(rt5645->regmap, RT5645_GPIO_CTRL1, in rt5645_i2c_probe()
4069 if (rt5645->pdata.jd_mode) { in rt5645_i2c_probe()
4070 regmap_update_bits(rt5645->regmap, RT5645_GEN_CTRL3, in rt5645_i2c_probe()
4073 regmap_update_bits(rt5645->regmap, RT5645_MICBIAS, in rt5645_i2c_probe()
4075 regmap_update_bits(rt5645->regmap, RT5645_IRQ_CTRL2, in rt5645_i2c_probe()
4077 regmap_update_bits(rt5645->regmap, RT5645_GEN_CTRL3, in rt5645_i2c_probe()
4079 regmap_update_bits(rt5645->regmap, RT5645_HPO_MIXER, in rt5645_i2c_probe()
4081 regmap_update_bits(rt5645->regmap, RT5645_MICBIAS, in rt5645_i2c_probe()
4083 regmap_update_bits(rt5645->regmap, RT5645_GPIO_CTRL1, in rt5645_i2c_probe()
4085 switch (rt5645->pdata.jd_mode) { in rt5645_i2c_probe()
4087 regmap_update_bits(rt5645->regmap, RT5645_A_JD_CTRL1, in rt5645_i2c_probe()
4092 regmap_update_bits(rt5645->regmap, RT5645_A_JD_CTRL1, in rt5645_i2c_probe()
4098 regmap_update_bits(rt5645->regmap, RT5645_A_JD_CTRL1, in rt5645_i2c_probe()
4105 if (rt5645->pdata.inv_jd1_1) { in rt5645_i2c_probe()
4106 regmap_update_bits(rt5645->regmap, RT5645_IRQ_CTRL2, in rt5645_i2c_probe()
4111 regmap_update_bits(rt5645->regmap, RT5645_ADDA_CLK1, in rt5645_i2c_probe()
4114 if (rt5645->pdata.level_trigger_irq) { in rt5645_i2c_probe()
4115 regmap_update_bits(rt5645->regmap, RT5645_IRQ_CTRL2, in rt5645_i2c_probe()
4118 timer_setup(&rt5645->btn_check_timer, rt5645_btn_check_callback, 0); in rt5645_i2c_probe()
4120 INIT_DELAYED_WORK(&rt5645->jack_detect_work, rt5645_jack_detect_work); in rt5645_i2c_probe()
4121 INIT_DELAYED_WORK(&rt5645->rcclock_work, rt5645_rcclock_work); in rt5645_i2c_probe()
4123 if (rt5645->i2c->irq) { in rt5645_i2c_probe()
4124 ret = request_threaded_irq(rt5645->i2c->irq, NULL, rt5645_irq, in rt5645_i2c_probe()
4128 dev_err(&i2c->dev, "Failed to reguest IRQ: %d\n", ret); in rt5645_i2c_probe()
4133 ret = devm_snd_soc_register_component(&i2c->dev, &soc_component_dev_rt5645, in rt5645_i2c_probe()
4141 if (rt5645->i2c->irq) in rt5645_i2c_probe()
4142 free_irq(rt5645->i2c->irq, rt5645); in rt5645_i2c_probe()
4144 regulator_bulk_disable(ARRAY_SIZE(rt5645->supplies), rt5645->supplies); in rt5645_i2c_probe()
4152 if (i2c->irq) in rt5645_i2c_remove()
4153 free_irq(i2c->irq, rt5645); in rt5645_i2c_remove()
4159 del_timer_sync(&rt5645->btn_check_timer); in rt5645_i2c_remove()
4161 cancel_delayed_work_sync(&rt5645->jack_detect_work); in rt5645_i2c_remove()
4162 cancel_delayed_work_sync(&rt5645->rcclock_work); in rt5645_i2c_remove()
4164 regulator_bulk_disable(ARRAY_SIZE(rt5645->supplies), rt5645->supplies); in rt5645_i2c_remove()
4171 regmap_update_bits(rt5645->regmap, RT5645_GEN_CTRL3, in rt5645_i2c_shutdown()
4173 regmap_update_bits(rt5645->regmap, RT5645_IN1_CTRL2, RT5645_CBJ_MN_JD, in rt5645_i2c_shutdown()
4175 regmap_update_bits(rt5645->regmap, RT5645_IN1_CTRL1, RT5645_CBJ_BST1_EN, in rt5645_i2c_shutdown()
4178 regmap_write(rt5645->regmap, RT5645_RESET, 0); in rt5645_i2c_shutdown()