Lines Matching +full:jd +full:- +full:invert

1 // SPDX-License-Identifier: GPL-2.0-only
3 * rt5645.c -- RT5645 ALSA SoC audio codec driver
26 #include <sound/soc-dapm.h>
41 static unsigned int quirk = -1;
427 /* Invert JD1_1 status polarity */
429 /* Invert HP detect status polarity */
438 /* Some (package) variants have the headset-mic pin not-connected */
670 static const DECLARE_TLV_DB_SCALE(out_vol_tlv, -4650, 150, 0);
671 static const DECLARE_TLV_DB_SCALE(dac_vol_tlv, -6525, 75, 0);
672 static const DECLARE_TLV_DB_SCALE(in_vol_tlv, -3450, 150, 0);
673 static const DECLARE_TLV_DB_SCALE(adc_vol_tlv, -1725, 75, 0);
687 /* {-6, -4.5, -3, -1.5, 0, 0.82, 1.58, 2.28} dB */
689 0, 4, TLV_DB_SCALE_ITEM(-600, 150, 0),
698 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES; in rt5645_hweq_info()
699 uinfo->count = RT5645_HWEQ_NUM * sizeof(struct rt5645_eq_param_s); in rt5645_hweq_info()
710 (struct rt5645_eq_param_s_be16 *)ucontrol->value.bytes.data; in rt5645_hweq_get()
714 eq_param[i].reg = cpu_to_be16(rt5645->eq_param[i].reg); in rt5645_hweq_get()
715 eq_param[i].val = cpu_to_be16(rt5645->eq_param[i].val); in rt5645_hweq_get()
736 (struct rt5645_eq_param_s_be16 *)ucontrol->value.bytes.data; in rt5645_hweq_put()
740 rt5645->eq_param[i].reg = be16_to_cpu(eq_param[i].reg); in rt5645_hweq_put()
741 rt5645->eq_param[i].val = be16_to_cpu(eq_param[i].val); in rt5645_hweq_put()
745 for (i = RT5645_HWEQ_NUM - 1; i >= 0; i--) { in rt5645_hweq_put()
746 if (rt5645->eq_param[i].reg == 0) in rt5645_hweq_put()
748 else if (rt5645->eq_param[i].reg != RT5645_EQ_CTRL2) in rt5645_hweq_put()
755 if (!rt5645_validate_hweq(rt5645->eq_param[i].reg) && in rt5645_hweq_put()
756 rt5645->eq_param[i].reg != 0) in rt5645_hweq_put()
758 else if (rt5645->eq_param[i].reg == 0) in rt5645_hweq_put()
779 regmap_update_bits(rt5645->regmap, RT5645_MICBIAS, in rt5645_spk_put_volsw()
784 mod_delayed_work(system_power_efficient_wq, &rt5645->rcclock_work, in rt5645_spk_put_volsw()
870 * set_dmic_clk - Set parameter of dmic.
880 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in set_dmic_clk()
884 rate = rt5645->sysclk / rl6231_get_pre_div(rt5645->regmap, in set_dmic_clk()
888 dev_err(component->dev, "Failed to set DMIC clock\n"); in set_dmic_clk()
898 struct snd_soc_component *component = snd_soc_dapm_to_component(source->dapm); in is_sys_clk_from_pll()
912 struct snd_soc_component *component = snd_soc_dapm_to_component(source->dapm); in is_using_asrc()
915 switch (source->shift) { in is_using_asrc()
963 if (rt5645_validate_hweq(rt5645->eq_param[i].reg)) in rt5645_enable_hweq()
964 regmap_write(rt5645->regmap, rt5645->eq_param[i].reg, in rt5645_enable_hweq()
965 rt5645->eq_param[i].val); in rt5645_enable_hweq()
974 * rt5645_sel_asrc_clk_src - select ASRC clock source for a set of filters
1003 return -EINVAL; in rt5645_sel_asrc_clk_src()
1280 /*DAC1 L/R source*/ /* MX-29 [9:8] [11:10] */
1299 /*DAC2 L/R source*/ /* MX-1B [6:4] [2:0] */
1323 /* MX-27 [12] */
1335 /* MX-27 [11] */
1347 /* MX-27 [8] */
1360 /* MX-28 [12] */
1371 /* MX-28 [11] */
1383 /* MX-28 [8] */
1394 /* MX-28 [1:0] */
1401 /* MX-28 [4] */
1412 /* MX-28 [3] */
1424 /* MX-77 [9:8] */
1437 /* MX-78 [4:0] */
1475 /* MX-78 [15:14][13:12][11:10] */
1498 /* MX-77 [7:6][5:4][3:2] */
1517 /* MX-79 [14:12][10:8][6:4][2:0] */
1546 /* MX-7a [14:12][10:8][6:4][2:0] */
1571 /* MX-2d [3] [2] */
1590 /* MX-2d [1] [0] */
1609 /* MX-2F [13:12] */
1621 /* MX-31 [15] [13] [11] [9] */
1640 /* MX-9D [9:8] */
1684 if (rt5645->codec_type == CODEC_TYPE_RT5650) { in hp_amp_power()
1689 regmap_write(rt5645->regmap, RT5645_PR_BASE + in hp_amp_power()
1693 regmap_read(rt5645->regmap, RT5645_PR_BASE + in hp_amp_power()
1700 regmap_write(rt5645->regmap, RT5645_PR_BASE + in hp_amp_power()
1703 regmap_write(rt5645->regmap, RT5645_PR_BASE + in hp_amp_power()
1715 regmap_write(rt5645->regmap, RT5645_PR_BASE + in hp_amp_power()
1737 regmap_write(rt5645->regmap, RT5645_PR_BASE + in hp_amp_power()
1739 regmap_write(rt5645->regmap, RT5645_PR_BASE + in hp_amp_power()
1745 hp_amp_power_count--; in hp_amp_power()
1747 if (rt5645->codec_type == CODEC_TYPE_RT5650) { in hp_amp_power()
1748 regmap_write(rt5645->regmap, RT5645_PR_BASE + in hp_amp_power()
1751 regmap_write(rt5645->regmap, RT5645_PR_BASE + in hp_amp_power()
1781 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in rt5645_hp_event()
1788 if (rt5645->codec_type == CODEC_TYPE_RT5645) { in rt5645_hp_event()
1795 regmap_write(rt5645->regmap, RT5645_PR_BASE + in rt5645_hp_event()
1815 if (rt5645->codec_type == CODEC_TYPE_RT5645) { in rt5645_hp_event()
1822 regmap_write(rt5645->regmap, RT5645_PR_BASE + in rt5645_hp_event()
1847 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in rt5645_spk_event()
1880 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in rt5645_lout_event()
1910 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in rt5645_bst2_event()
1933 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in rt5645_set_micbias1_event()
1958 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in rt5645_set_micbias2_event()
1986 SND_SOC_DAPM_SUPPLY("JD Power", RT5645_PWR_ANLG2,
2337 { "BST1", NULL, "JD Power" },
2575 { "HP amp", NULL, "JD Power" },
2754 struct snd_soc_component *component = dai->component; in rt5645_hw_params()
2759 rt5645->lrck[dai->id] = params_rate(params); in rt5645_hw_params()
2760 pre_div = rl6231_get_clk_info(rt5645->sysclk, rt5645->lrck[dai->id]); in rt5645_hw_params()
2762 dev_err(component->dev, "Unsupported clock setting\n"); in rt5645_hw_params()
2763 return -EINVAL; in rt5645_hw_params()
2767 dev_err(component->dev, "Unsupported frame size: %d\n", frame_size); in rt5645_hw_params()
2768 return -EINVAL; in rt5645_hw_params()
2771 switch (rt5645->codec_type) { in rt5645_hw_params()
2781 rt5645->bclk[dai->id] = rt5645->lrck[dai->id] * (32 << bclk_ms); in rt5645_hw_params()
2783 dev_dbg(dai->dev, "bclk is %dHz and lrck is %dHz\n", in rt5645_hw_params()
2784 rt5645->bclk[dai->id], rt5645->lrck[dai->id]); in rt5645_hw_params()
2785 dev_dbg(dai->dev, "bclk_ms is %d and pre_div is %d for iis %d\n", in rt5645_hw_params()
2786 bclk_ms, pre_div, dai->id); in rt5645_hw_params()
2801 return -EINVAL; in rt5645_hw_params()
2804 switch (dai->id) { in rt5645_hw_params()
2821 dev_err(component->dev, "Invalid dai->id: %d\n", dai->id); in rt5645_hw_params()
2822 return -EINVAL; in rt5645_hw_params()
2830 struct snd_soc_component *component = dai->component; in rt5645_set_dai_fmt()
2834 switch (rt5645->codec_type) { in rt5645_set_dai_fmt()
2845 rt5645->master[dai->id] = 1; in rt5645_set_dai_fmt()
2849 rt5645->master[dai->id] = 0; in rt5645_set_dai_fmt()
2852 return -EINVAL; in rt5645_set_dai_fmt()
2862 return -EINVAL; in rt5645_set_dai_fmt()
2878 return -EINVAL; in rt5645_set_dai_fmt()
2880 switch (dai->id) { in rt5645_set_dai_fmt()
2892 dev_err(component->dev, "Invalid dai->id: %d\n", dai->id); in rt5645_set_dai_fmt()
2893 return -EINVAL; in rt5645_set_dai_fmt()
2901 struct snd_soc_component *component = dai->component; in rt5645_set_dai_sysclk()
2905 if (freq == rt5645->sysclk && clk_id == rt5645->sysclk_src) in rt5645_set_dai_sysclk()
2919 dev_err(component->dev, "Invalid clock id (%d)\n", clk_id); in rt5645_set_dai_sysclk()
2920 return -EINVAL; in rt5645_set_dai_sysclk()
2924 rt5645->sysclk = freq; in rt5645_set_dai_sysclk()
2925 rt5645->sysclk_src = clk_id; in rt5645_set_dai_sysclk()
2927 dev_dbg(dai->dev, "Sysclk is %dHz and clock id is %d\n", freq, clk_id); in rt5645_set_dai_sysclk()
2935 struct snd_soc_component *component = dai->component; in rt5645_set_dai_pll()
2940 if (source == rt5645->pll_src && freq_in == rt5645->pll_in && in rt5645_set_dai_pll()
2941 freq_out == rt5645->pll_out) in rt5645_set_dai_pll()
2945 dev_dbg(component->dev, "PLL disabled\n"); in rt5645_set_dai_pll()
2947 rt5645->pll_in = 0; in rt5645_set_dai_pll()
2948 rt5645->pll_out = 0; in rt5645_set_dai_pll()
2961 switch (dai->id) { in rt5645_set_dai_pll()
2971 dev_err(component->dev, "Invalid dai->id: %d\n", dai->id); in rt5645_set_dai_pll()
2972 return -EINVAL; in rt5645_set_dai_pll()
2976 dev_err(component->dev, "Unknown PLL source %d\n", source); in rt5645_set_dai_pll()
2977 return -EINVAL; in rt5645_set_dai_pll()
2982 dev_err(component->dev, "Unsupported input clock %d\n", freq_in); in rt5645_set_dai_pll()
2986 dev_dbg(component->dev, "bypass=%d m=%d n=%d k=%d\n", in rt5645_set_dai_pll()
2996 rt5645->pll_in = freq_in; in rt5645_set_dai_pll()
2997 rt5645->pll_out = freq_out; in rt5645_set_dai_pll()
2998 rt5645->pll_src = source; in rt5645_set_dai_pll()
3006 struct snd_soc_component *component = dai->component; in rt5645_set_tdm_slot()
3011 switch (rt5645->codec_type) { in rt5645_set_tdm_slot()
3029 if (rt5645->codec_type == CODEC_TYPE_RT5645) in rt5645_set_tdm_slot()
3104 if (rt5645->en_button_func) in rt5645_set_bias_level()
3106 &rt5645->jack_detect_work, in rt5645_set_bias_level()
3113 if (!rt5645->en_button_func) in rt5645_set_bias_level()
3176 regmap_write(rt5645->regmap, RT5645_CHARGE_PUMP, 0x0206); in rt5645_jack_detect()
3182 if (!snd_soc_card_is_instantiated(dapm->card)) { in rt5645_jack_detect()
3183 /* Power up necessary bits for JD if dapm is in rt5645_jack_detect()
3185 regmap_update_bits(rt5645->regmap, RT5645_PWR_ANLG1, in rt5645_jack_detect()
3188 regmap_update_bits(rt5645->regmap, RT5645_PWR_MIXER, in rt5645_jack_detect()
3190 regmap_update_bits(rt5645->regmap, RT5645_PWR_VOL, in rt5645_jack_detect()
3194 regmap_write(rt5645->regmap, RT5645_JD_CTRL3, 0x00f0); in rt5645_jack_detect()
3195 regmap_update_bits(rt5645->regmap, RT5645_IN1_CTRL2, in rt5645_jack_detect()
3197 regmap_update_bits(rt5645->regmap, RT5645_IN1_CTRL1, in rt5645_jack_detect()
3200 regmap_update_bits(rt5645->regmap, RT5645_IN1_CTRL2, in rt5645_jack_detect()
3203 if (rt5645->gpiod_cbj_sleeve) in rt5645_jack_detect()
3204 gpiod_set_value(rt5645->gpiod_cbj_sleeve, 1); in rt5645_jack_detect()
3207 regmap_read(rt5645->regmap, RT5645_IN1_CTRL3, &val); in rt5645_jack_detect()
3209 dev_dbg(component->dev, "val = %d\n", val); in rt5645_jack_detect()
3211 if ((val == 1 || val == 2) && !rt5645->pdata.no_headset_mic) { in rt5645_jack_detect()
3212 rt5645->jack_type = SND_JACK_HEADSET; in rt5645_jack_detect()
3213 if (rt5645->en_button_func) { in rt5645_jack_detect()
3217 if (rt5645->en_button_func) in rt5645_jack_detect()
3221 rt5645->jack_type = SND_JACK_HEADPHONE; in rt5645_jack_detect()
3222 if (rt5645->gpiod_cbj_sleeve) in rt5645_jack_detect()
3223 gpiod_set_value(rt5645->gpiod_cbj_sleeve, 0); in rt5645_jack_detect()
3225 if (rt5645->pdata.level_trigger_irq) in rt5645_jack_detect()
3226 regmap_update_bits(rt5645->regmap, RT5645_IRQ_CTRL2, in rt5645_jack_detect()
3229 regmap_write(rt5645->regmap, RT5645_CHARGE_PUMP, 0x0e06); in rt5645_jack_detect()
3231 rt5645->jack_type = 0; in rt5645_jack_detect()
3233 regmap_update_bits(rt5645->regmap, RT5645_HP_VOL, in rt5645_jack_detect()
3236 regmap_update_bits(rt5645->regmap, RT5645_IN1_CTRL2, in rt5645_jack_detect()
3238 regmap_update_bits(rt5645->regmap, RT5645_IN1_CTRL1, in rt5645_jack_detect()
3241 if (rt5645->en_button_func) in rt5645_jack_detect()
3244 if (rt5645->pdata.jd_mode == 0) in rt5645_jack_detect()
3248 if (rt5645->pdata.level_trigger_irq) in rt5645_jack_detect()
3249 regmap_update_bits(rt5645->regmap, RT5645_IRQ_CTRL2, in rt5645_jack_detect()
3252 if (rt5645->gpiod_cbj_sleeve) in rt5645_jack_detect()
3253 gpiod_set_value(rt5645->gpiod_cbj_sleeve, 0); in rt5645_jack_detect()
3256 return rt5645->jack_type; in rt5645_jack_detect()
3279 rt5645->hp_jack = hp_jack; in rt5645_set_jack_detect()
3280 rt5645->mic_jack = mic_jack; in rt5645_set_jack_detect()
3281 rt5645->btn_jack = btn_jack; in rt5645_set_jack_detect()
3282 if (rt5645->btn_jack && rt5645->codec_type == CODEC_TYPE_RT5650) { in rt5645_set_jack_detect()
3283 rt5645->en_button_func = true; in rt5645_set_jack_detect()
3284 regmap_update_bits(rt5645->regmap, RT5645_GPIO_CTRL1, in rt5645_set_jack_detect()
3286 regmap_update_bits(rt5645->regmap, RT5645_GEN_CTRL1, in rt5645_set_jack_detect()
3288 regmap_update_bits(rt5645->regmap, RT5645_DEPOP_M1, in rt5645_set_jack_detect()
3323 if (!rt5645->component) in rt5645_jack_detect_work()
3326 mutex_lock(&rt5645->jd_mutex); in rt5645_jack_detect_work()
3328 switch (rt5645->pdata.jd_mode) { in rt5645_jack_detect_work()
3329 case 0: /* Not using rt5645 JD */ in rt5645_jack_detect_work()
3330 if (rt5645->gpiod_hp_det) { in rt5645_jack_detect_work()
3331 gpio_state = gpiod_get_value(rt5645->gpiod_hp_det); in rt5645_jack_detect_work()
3332 if (rt5645->pdata.inv_hp_pol) in rt5645_jack_detect_work()
3334 dev_dbg(rt5645->component->dev, "gpio_state = %d\n", in rt5645_jack_detect_work()
3336 report = rt5645_jack_detect(rt5645->component, gpio_state); in rt5645_jack_detect_work()
3338 snd_soc_jack_report(rt5645->hp_jack, in rt5645_jack_detect_work()
3340 snd_soc_jack_report(rt5645->mic_jack, in rt5645_jack_detect_work()
3342 mutex_unlock(&rt5645->jd_mutex); in rt5645_jack_detect_work()
3345 val = snd_soc_component_read(rt5645->component, RT5645_A_JD_CTRL1) & 0x0020; in rt5645_jack_detect_work()
3348 val = snd_soc_component_read(rt5645->component, RT5645_INT_IRQ_ST) & 0x1000; in rt5645_jack_detect_work()
3353 if (!val && (rt5645->jack_type == 0)) { /* jack in */ in rt5645_jack_detect_work()
3354 report = rt5645_jack_detect(rt5645->component, 1); in rt5645_jack_detect_work()
3355 } else if (!val && rt5645->jack_type == SND_JACK_HEADSET) { in rt5645_jack_detect_work()
3358 if (snd_soc_component_read(rt5645->component, RT5645_INT_IRQ_ST) & 0x4) { in rt5645_jack_detect_work()
3361 btn_type = rt5645_button_detect(rt5645->component); in rt5645_jack_detect_work()
3391 dev_err(rt5645->component->dev, in rt5645_jack_detect_work()
3398 report = rt5645->jack_type; in rt5645_jack_detect_work()
3400 mod_timer(&rt5645->btn_check_timer, in rt5645_jack_detect_work()
3406 snd_soc_component_update_bits(rt5645->component, in rt5645_jack_detect_work()
3408 rt5645_jack_detect(rt5645->component, 0); in rt5645_jack_detect_work()
3411 mutex_unlock(&rt5645->jd_mutex); in rt5645_jack_detect_work()
3413 snd_soc_jack_report(rt5645->hp_jack, report, SND_JACK_HEADPHONE); in rt5645_jack_detect_work()
3414 snd_soc_jack_report(rt5645->mic_jack, report, SND_JACK_MICROPHONE); in rt5645_jack_detect_work()
3415 if (rt5645->en_button_func) in rt5645_jack_detect_work()
3416 snd_soc_jack_report(rt5645->btn_jack, in rt5645_jack_detect_work()
3426 regmap_update_bits(rt5645->regmap, RT5645_MICBIAS, in rt5645_rcclock_work()
3435 &rt5645->jack_detect_work, msecs_to_jiffies(250)); in rt5645_irq()
3445 &rt5645->jack_detect_work, msecs_to_jiffies(5)); in rt5645_btn_check_callback()
3453 rt5645->component = component; in rt5645_probe()
3455 switch (rt5645->codec_type) { in rt5645_probe()
3463 if (rt5645->v_id < 3) { in rt5645_probe()
3481 /* for JD function */ in rt5645_probe()
3482 if (rt5645->pdata.jd_mode) { in rt5645_probe()
3483 snd_soc_dapm_force_enable_pin(dapm, "JD Power"); in rt5645_probe()
3488 if (rt5645->pdata.long_name) in rt5645_probe()
3489 component->card->long_name = rt5645->pdata.long_name; in rt5645_probe()
3491 rt5645->eq_param = devm_kcalloc(component->dev, in rt5645_probe()
3495 if (!rt5645->eq_param) in rt5645_probe()
3496 return -ENOMEM; in rt5645_probe()
3511 regcache_cache_only(rt5645->regmap, true); in rt5645_suspend()
3512 regcache_mark_dirty(rt5645->regmap); in rt5645_suspend()
3521 regcache_cache_only(rt5645->regmap, false); in rt5645_resume()
3522 regcache_sync(rt5645->regmap); in rt5645_resume()
3545 .name = "rt5645-aif1",
3564 .name = "rt5645-aif2",
3690 .long_name = "gpd-win-pocket-rt5645",
3747 { "hp-detect-gpios", &ef20_hp_detect, 1 },
3829 .ident = "MINIX Z83-4",
3832 DMI_MATCH(DMI_PRODUCT_NAME, "Z83-4"),
3849 DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "MIIX 310-10ICR"),
3858 DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "Lenovo MIIX 320-10ICR"),
3871 * DF-BI-7-S70CR100-*
3872 * DF-BI-7-S70CR110-*
3873 * DF-BI-7-S70CR200-*
3874 * LP-BS-7-S70CR700-*
3905 .ident = "Acer Switch V 10 (SW5-017)",
3908 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "SW5-017"),
3927 if (device_property_present(dev, "realtek,in2-differential") || in rt5645_check_dp()
3928 device_property_present(dev, "realtek,dmic1-data-pin") || in rt5645_check_dp()
3929 device_property_present(dev, "realtek,dmic2-data-pin") || in rt5645_check_dp()
3930 device_property_present(dev, "realtek,jd-mode")) in rt5645_check_dp()
3938 pdata->in2_diff = device_property_read_bool(dev, "realtek,in2-differential"); in rt5645_parse_dt()
3939 device_property_read_u32(dev, "realtek,dmic1-data-pin", &pdata->dmic1_data_pin); in rt5645_parse_dt()
3940 device_property_read_u32(dev, "realtek,dmic2-data-pin", &pdata->dmic2_data_pin); in rt5645_parse_dt()
3941 device_property_read_u32(dev, "realtek,jd-mode", &pdata->jd_mode); in rt5645_parse_dt()
3950 dev_info(codec_dev, "Detected %s platform\n", dmi_data->ident); in rt5645_get_pdata()
3951 *pdata = *((struct rt5645_platform_data *)dmi_data->driver_data); in rt5645_get_pdata()
3958 if (quirk != -1) { in rt5645_get_pdata()
3959 pdata->in2_diff = QUIRK_IN2_DIFF(quirk); in rt5645_get_pdata()
3960 pdata->level_trigger_irq = QUIRK_LEVEL_IRQ(quirk); in rt5645_get_pdata()
3961 pdata->inv_jd1_1 = QUIRK_INV_JD1_1(quirk); in rt5645_get_pdata()
3962 pdata->inv_hp_pol = QUIRK_INV_HP_POL(quirk); in rt5645_get_pdata()
3963 pdata->jd_mode = QUIRK_JD_MODE(quirk); in rt5645_get_pdata()
3964 pdata->dmic1_data_pin = QUIRK_DMIC1_DATA_PIN(quirk); in rt5645_get_pdata()
3965 pdata->dmic2_data_pin = QUIRK_DMIC2_DATA_PIN(quirk); in rt5645_get_pdata()
3990 snprintf(buf, sizeof(buf), "cfg-spk:%d cfg-mic:%s", spk, mic); in rt5645_components()
4003 rt5645 = devm_kzalloc(&i2c->dev, sizeof(struct rt5645_priv), in rt5645_i2c_probe()
4006 return -ENOMEM; in rt5645_i2c_probe()
4008 rt5645->i2c = i2c; in rt5645_i2c_probe()
4010 rt5645_get_pdata(&i2c->dev, &rt5645->pdata); in rt5645_i2c_probe()
4012 if (has_acpi_companion(&i2c->dev)) { in rt5645_i2c_probe()
4014 if (devm_acpi_dev_add_driver_gpios(&i2c->dev, cht_rt5645_gpios)) in rt5645_i2c_probe()
4015 dev_dbg(&i2c->dev, "Failed to add driver gpios\n"); in rt5645_i2c_probe()
4018 /* The ALC3270 package has the headset-mic pin not-connected */ in rt5645_i2c_probe()
4019 if (acpi_dev_hid_uid_match(ACPI_COMPANION(&i2c->dev), "10EC3270", NULL)) in rt5645_i2c_probe()
4020 rt5645->pdata.no_headset_mic = true; in rt5645_i2c_probe()
4023 rt5645->gpiod_hp_det = devm_gpiod_get_optional(&i2c->dev, "hp-detect", in rt5645_i2c_probe()
4026 if (IS_ERR(rt5645->gpiod_hp_det)) { in rt5645_i2c_probe()
4027 dev_info(&i2c->dev, "failed to initialize gpiod\n"); in rt5645_i2c_probe()
4028 ret = PTR_ERR(rt5645->gpiod_hp_det); in rt5645_i2c_probe()
4031 * errors, including -EPROBE_DEFER in rt5645_i2c_probe()
4033 if (ret != -ENOENT) in rt5645_i2c_probe()
4037 rt5645->gpiod_cbj_sleeve = devm_gpiod_get_optional(&i2c->dev, "cbj-sleeve", in rt5645_i2c_probe()
4040 if (IS_ERR(rt5645->gpiod_cbj_sleeve)) { in rt5645_i2c_probe()
4041 ret = PTR_ERR(rt5645->gpiod_cbj_sleeve); in rt5645_i2c_probe()
4042 dev_info(&i2c->dev, "failed to initialize gpiod, ret=%d\n", ret); in rt5645_i2c_probe()
4043 if (ret != -ENOENT) in rt5645_i2c_probe()
4047 for (i = 0; i < ARRAY_SIZE(rt5645->supplies); i++) in rt5645_i2c_probe()
4048 rt5645->supplies[i].supply = rt5645_supply_names[i]; in rt5645_i2c_probe()
4050 ret = devm_regulator_bulk_get(&i2c->dev, in rt5645_i2c_probe()
4051 ARRAY_SIZE(rt5645->supplies), in rt5645_i2c_probe()
4052 rt5645->supplies); in rt5645_i2c_probe()
4054 dev_err(&i2c->dev, "Failed to request supplies: %d\n", ret); in rt5645_i2c_probe()
4058 ret = regulator_bulk_enable(ARRAY_SIZE(rt5645->supplies), in rt5645_i2c_probe()
4059 rt5645->supplies); in rt5645_i2c_probe()
4061 dev_err(&i2c->dev, "Failed to enable supplies: %d\n", ret); in rt5645_i2c_probe()
4068 dev_err(&i2c->dev, "Failed to allocate temp register map: %d\n", in rt5645_i2c_probe()
4080 dev_err(&i2c->dev, "Failed to read: 0x%02X\n, ret = %d", RT5645_VENDOR_ID2, ret); in rt5645_i2c_probe()
4086 rt5645->regmap = devm_regmap_init_i2c(i2c, &rt5645_regmap); in rt5645_i2c_probe()
4087 rt5645->codec_type = CODEC_TYPE_RT5645; in rt5645_i2c_probe()
4090 rt5645->regmap = devm_regmap_init_i2c(i2c, &rt5650_regmap); in rt5645_i2c_probe()
4091 rt5645->codec_type = CODEC_TYPE_RT5650; in rt5645_i2c_probe()
4094 dev_err(&i2c->dev, in rt5645_i2c_probe()
4097 ret = -ENODEV; in rt5645_i2c_probe()
4101 if (IS_ERR(rt5645->regmap)) { in rt5645_i2c_probe()
4102 ret = PTR_ERR(rt5645->regmap); in rt5645_i2c_probe()
4103 dev_err(&i2c->dev, "Failed to allocate register map: %d\n", in rt5645_i2c_probe()
4108 regmap_write(rt5645->regmap, RT5645_RESET, 0); in rt5645_i2c_probe()
4111 rt5645->v_id = val & 0xff; in rt5645_i2c_probe()
4113 regmap_write(rt5645->regmap, RT5645_AD_DA_MIXER, 0x8080); in rt5645_i2c_probe()
4115 ret = regmap_multi_reg_write(rt5645->regmap, init_list, in rt5645_i2c_probe()
4118 dev_warn(&i2c->dev, "Failed to apply regmap patch: %d\n", ret); in rt5645_i2c_probe()
4120 if (rt5645->codec_type == CODEC_TYPE_RT5650) { in rt5645_i2c_probe()
4121 ret = regmap_multi_reg_write(rt5645->regmap, rt5650_init_list, in rt5645_i2c_probe()
4124 dev_warn(&i2c->dev, "Apply rt5650 patch failed: %d\n", in rt5645_i2c_probe()
4128 regmap_update_bits(rt5645->regmap, RT5645_CLSD_OUT_CTRL, 0xc0, 0xc0); in rt5645_i2c_probe()
4130 if (rt5645->pdata.in2_diff) in rt5645_i2c_probe()
4131 regmap_update_bits(rt5645->regmap, RT5645_IN2_CTRL, in rt5645_i2c_probe()
4134 if (rt5645->pdata.dmic1_data_pin || rt5645->pdata.dmic2_data_pin) { in rt5645_i2c_probe()
4135 regmap_update_bits(rt5645->regmap, RT5645_GPIO_CTRL1, in rt5645_i2c_probe()
4138 switch (rt5645->pdata.dmic1_data_pin) { in rt5645_i2c_probe()
4140 regmap_update_bits(rt5645->regmap, RT5645_DMIC_CTRL1, in rt5645_i2c_probe()
4145 regmap_update_bits(rt5645->regmap, RT5645_GPIO_CTRL1, in rt5645_i2c_probe()
4147 regmap_update_bits(rt5645->regmap, RT5645_DMIC_CTRL1, in rt5645_i2c_probe()
4149 regmap_update_bits(rt5645->regmap, RT5645_GPIO_CTRL1, in rt5645_i2c_probe()
4154 regmap_update_bits(rt5645->regmap, RT5645_DMIC_CTRL1, in rt5645_i2c_probe()
4156 regmap_update_bits(rt5645->regmap, RT5645_GPIO_CTRL1, in rt5645_i2c_probe()
4165 switch (rt5645->pdata.dmic2_data_pin) { in rt5645_i2c_probe()
4167 regmap_update_bits(rt5645->regmap, RT5645_DMIC_CTRL1, in rt5645_i2c_probe()
4172 regmap_update_bits(rt5645->regmap, RT5645_DMIC_CTRL1, in rt5645_i2c_probe()
4174 regmap_update_bits(rt5645->regmap, RT5645_GPIO_CTRL1, in rt5645_i2c_probe()
4179 regmap_update_bits(rt5645->regmap, RT5645_DMIC_CTRL1, in rt5645_i2c_probe()
4181 regmap_update_bits(rt5645->regmap, RT5645_GPIO_CTRL1, in rt5645_i2c_probe()
4187 regmap_update_bits(rt5645->regmap, RT5645_DMIC_CTRL1, in rt5645_i2c_probe()
4189 regmap_update_bits(rt5645->regmap, RT5645_GPIO_CTRL1, in rt5645_i2c_probe()
4198 if (rt5645->pdata.jd_mode) { in rt5645_i2c_probe()
4199 regmap_update_bits(rt5645->regmap, RT5645_GEN_CTRL3, in rt5645_i2c_probe()
4202 regmap_update_bits(rt5645->regmap, RT5645_MICBIAS, in rt5645_i2c_probe()
4204 regmap_update_bits(rt5645->regmap, RT5645_IRQ_CTRL2, in rt5645_i2c_probe()
4206 regmap_update_bits(rt5645->regmap, RT5645_GEN_CTRL3, in rt5645_i2c_probe()
4208 regmap_update_bits(rt5645->regmap, RT5645_HPO_MIXER, in rt5645_i2c_probe()
4210 regmap_update_bits(rt5645->regmap, RT5645_MICBIAS, in rt5645_i2c_probe()
4212 regmap_update_bits(rt5645->regmap, RT5645_GPIO_CTRL1, in rt5645_i2c_probe()
4214 switch (rt5645->pdata.jd_mode) { in rt5645_i2c_probe()
4216 regmap_update_bits(rt5645->regmap, RT5645_A_JD_CTRL1, in rt5645_i2c_probe()
4221 regmap_update_bits(rt5645->regmap, RT5645_A_JD_CTRL1, in rt5645_i2c_probe()
4227 regmap_update_bits(rt5645->regmap, RT5645_A_JD_CTRL1, in rt5645_i2c_probe()
4234 if (rt5645->pdata.inv_jd1_1) { in rt5645_i2c_probe()
4235 regmap_update_bits(rt5645->regmap, RT5645_IRQ_CTRL2, in rt5645_i2c_probe()
4240 regmap_update_bits(rt5645->regmap, RT5645_ADDA_CLK1, in rt5645_i2c_probe()
4243 if (rt5645->pdata.level_trigger_irq) { in rt5645_i2c_probe()
4244 regmap_update_bits(rt5645->regmap, RT5645_IRQ_CTRL2, in rt5645_i2c_probe()
4247 timer_setup(&rt5645->btn_check_timer, rt5645_btn_check_callback, 0); in rt5645_i2c_probe()
4249 mutex_init(&rt5645->jd_mutex); in rt5645_i2c_probe()
4250 INIT_DELAYED_WORK(&rt5645->jack_detect_work, rt5645_jack_detect_work); in rt5645_i2c_probe()
4251 INIT_DELAYED_WORK(&rt5645->rcclock_work, rt5645_rcclock_work); in rt5645_i2c_probe()
4253 if (rt5645->i2c->irq) { in rt5645_i2c_probe()
4254 ret = request_threaded_irq(rt5645->i2c->irq, NULL, rt5645_irq, in rt5645_i2c_probe()
4258 dev_err(&i2c->dev, "Failed to request IRQ: %d\n", ret); in rt5645_i2c_probe()
4263 ret = devm_snd_soc_register_component(&i2c->dev, &soc_component_dev_rt5645, in rt5645_i2c_probe()
4271 if (rt5645->i2c->irq) in rt5645_i2c_probe()
4272 free_irq(rt5645->i2c->irq, rt5645); in rt5645_i2c_probe()
4274 regulator_bulk_disable(ARRAY_SIZE(rt5645->supplies), rt5645->supplies); in rt5645_i2c_probe()
4282 if (i2c->irq) in rt5645_i2c_remove()
4283 free_irq(i2c->irq, rt5645); in rt5645_i2c_remove()
4289 del_timer_sync(&rt5645->btn_check_timer); in rt5645_i2c_remove()
4291 cancel_delayed_work_sync(&rt5645->jack_detect_work); in rt5645_i2c_remove()
4292 cancel_delayed_work_sync(&rt5645->rcclock_work); in rt5645_i2c_remove()
4294 if (rt5645->gpiod_cbj_sleeve) in rt5645_i2c_remove()
4295 gpiod_set_value(rt5645->gpiod_cbj_sleeve, 0); in rt5645_i2c_remove()
4297 regulator_bulk_disable(ARRAY_SIZE(rt5645->supplies), rt5645->supplies); in rt5645_i2c_remove()
4304 regmap_update_bits(rt5645->regmap, RT5645_GEN_CTRL3, in rt5645_i2c_shutdown()
4306 regmap_update_bits(rt5645->regmap, RT5645_IN1_CTRL2, RT5645_CBJ_MN_JD, in rt5645_i2c_shutdown()
4308 regmap_update_bits(rt5645->regmap, RT5645_IN1_CTRL1, RT5645_CBJ_BST1_EN, in rt5645_i2c_shutdown()
4311 regmap_write(rt5645->regmap, RT5645_RESET, 0); in rt5645_i2c_shutdown()
4313 if (rt5645->gpiod_cbj_sleeve) in rt5645_i2c_shutdown()
4314 gpiod_set_value(rt5645->gpiod_cbj_sleeve, 0); in rt5645_i2c_shutdown()
4321 del_timer_sync(&rt5645->btn_check_timer); in rt5645_sys_suspend()
4322 cancel_delayed_work_sync(&rt5645->jack_detect_work); in rt5645_sys_suspend()
4323 cancel_delayed_work_sync(&rt5645->rcclock_work); in rt5645_sys_suspend()
4325 regcache_cache_only(rt5645->regmap, true); in rt5645_sys_suspend()
4326 regcache_mark_dirty(rt5645->regmap); in rt5645_sys_suspend()
4334 regcache_cache_only(rt5645->regmap, false); in rt5645_sys_resume()
4335 regcache_sync(rt5645->regmap); in rt5645_sys_resume()
4337 if (rt5645->hp_jack) { in rt5645_sys_resume()
4338 rt5645->jack_type = 0; in rt5645_sys_resume()
4339 rt5645_jack_detect_work(&rt5645->jack_detect_work.work); in rt5645_sys_resume()