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

1 // SPDX-License-Identifier: GPL-2.0-only
3 * rt5640.c -- RT5640/RT5639 ALSA SoC audio codec driver
27 #include <sound/soc-dapm.h>
340 static const DECLARE_TLV_DB_SCALE(out_vol_tlv, -4650, 150, 0);
341 static const DECLARE_TLV_DB_MINMAX(dac_vol_tlv, -6562, 0);
342 static const DECLARE_TLV_DB_SCALE(in_vol_tlv, -3450, 150, 0);
343 static const DECLARE_TLV_DB_MINMAX(adc_vol_tlv, -1762, 3000);
451 * set_dmic_clk - Set parameter of dmic.
461 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in set_dmic_clk()
465 rate = rt5640->sysclk / rl6231_get_pre_div(rt5640->regmap, in set_dmic_clk()
469 dev_err(component->dev, "Failed to set DMIC clock\n"); in set_dmic_clk()
479 struct snd_soc_component *component = snd_soc_dapm_to_component(source->dapm); in is_using_asrc()
482 if (!rt5640->asrc_en) in is_using_asrc()
921 regmap_update_bits(rt5640->regmap, RT5640_PR_BASE + in hp_amp_power_on()
923 regmap_update_bits(rt5640->regmap, RT5640_DEPOP_M2, in hp_amp_power_on()
925 regmap_update_bits(rt5640->regmap, RT5640_DEPOP_M1, in hp_amp_power_on()
928 regmap_write(rt5640->regmap, RT5640_PR_BASE + RT5640_HP_DCC_INT1, in hp_amp_power_on()
931 regmap_update_bits(rt5640->regmap, RT5640_PWR_ANLG1, in hp_amp_power_on()
933 regmap_update_bits(rt5640->regmap, RT5640_PWR_ANLG1, in hp_amp_power_on()
937 regmap_update_bits(rt5640->regmap, RT5640_PWR_ANLG1, in hp_amp_power_on()
946 regmap_update_bits(rt5640->regmap, RT5640_DEPOP_M2, in rt5640_pmu_depop()
949 regmap_update_bits(rt5640->regmap, RT5640_CHARGE_PUMP, in rt5640_pmu_depop()
952 regmap_update_bits(rt5640->regmap, RT5640_DEPOP_M3, in rt5640_pmu_depop()
958 regmap_write(rt5640->regmap, RT5640_PR_BASE + in rt5640_pmu_depop()
960 regmap_update_bits(rt5640->regmap, RT5640_DEPOP_M1, in rt5640_pmu_depop()
963 regmap_update_bits(rt5640->regmap, RT5640_PR_BASE + in rt5640_pmu_depop()
970 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in rt5640_hp_event()
976 rt5640->hp_mute = false; in rt5640_hp_event()
980 rt5640->hp_mute = true; in rt5640_hp_event()
994 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in rt5640_lout_event()
1023 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in rt5640_hp_power_event()
1039 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in rt5640_hp_post_event()
1044 if (!rt5640->hp_mute) in rt5640_hp_post_event()
1182 SND_SOC_DAPM_AIF_IN("AIF2RX", "AIF2 Playback", 0, SND_SOC_NOPM, 0, 0),
1183 SND_SOC_DAPM_AIF_OUT("AIF2TX", "AIF2 Capture", 0, SND_SOC_NOPM, 0, 0),
1276 /* Audio DSP */
1277 SND_SOC_DAPM_PGA("Audio DSP", SND_SOC_NOPM, 0, 0, NULL, 0),
1575 {"Audio DSP", NULL, "DAC MIXL"},
1576 {"Audio DSP", NULL, "DAC MIXR"},
1579 {"DAC L2 Mux", "Base L/R", "Audio DSP"},
1651 return -EINVAL; in get_sdp_info()
1689 ret = -EINVAL; in get_sdp_info()
1699 struct snd_soc_component *component = dai->component; in rt5640_hw_params()
1704 rt5640->lrck[dai->id] = params_rate(params); in rt5640_hw_params()
1705 pre_div = rl6231_get_clk_info(rt5640->sysclk, rt5640->lrck[dai->id]); in rt5640_hw_params()
1707 dev_err(component->dev, "Unsupported clock setting %d for DAI %d\n", in rt5640_hw_params()
1708 rt5640->lrck[dai->id], dai->id); in rt5640_hw_params()
1709 return -EINVAL; in rt5640_hw_params()
1713 dev_err(component->dev, "Unsupported frame size: %d\n", frame_size); in rt5640_hw_params()
1720 rt5640->bclk[dai->id] = rt5640->lrck[dai->id] * (32 << bclk_ms); in rt5640_hw_params()
1722 dev_dbg(dai->dev, "bclk is %dHz and lrck is %dHz\n", in rt5640_hw_params()
1723 rt5640->bclk[dai->id], rt5640->lrck[dai->id]); in rt5640_hw_params()
1724 dev_dbg(dai->dev, "bclk_ms is %d and pre_div is %d for iis %d\n", in rt5640_hw_params()
1725 bclk_ms, pre_div, dai->id); in rt5640_hw_params()
1740 return -EINVAL; in rt5640_hw_params()
1743 dai_sel = get_sdp_info(component, dai->id); in rt5640_hw_params()
1745 dev_err(component->dev, "Failed to get sdp info: %d\n", dai_sel); in rt5640_hw_params()
1746 return -EINVAL; in rt5640_hw_params()
1770 struct snd_soc_component *component = dai->component; in rt5640_set_dai_fmt()
1777 rt5640->master[dai->id] = 1; in rt5640_set_dai_fmt()
1781 rt5640->master[dai->id] = 0; in rt5640_set_dai_fmt()
1784 return -EINVAL; in rt5640_set_dai_fmt()
1794 return -EINVAL; in rt5640_set_dai_fmt()
1810 return -EINVAL; in rt5640_set_dai_fmt()
1813 dai_sel = get_sdp_info(component, dai->id); in rt5640_set_dai_fmt()
1815 dev_err(component->dev, "Failed to get sdp info: %d\n", dai_sel); in rt5640_set_dai_fmt()
1816 return -EINVAL; in rt5640_set_dai_fmt()
1835 struct snd_soc_component *component = dai->component; in rt5640_set_dai_sysclk()
1843 ret = clk_set_rate(rt5640->mclk, freq); in rt5640_set_dai_sysclk()
1857 dev_err(component->dev, "Invalid clock id (%d)\n", clk_id); in rt5640_set_dai_sysclk()
1858 return -EINVAL; in rt5640_set_dai_sysclk()
1864 rt5640->sysclk = freq; in rt5640_set_dai_sysclk()
1865 rt5640->sysclk_src = clk_id; in rt5640_set_dai_sysclk()
1867 dev_dbg(dai->dev, "Sysclk is %dHz and clock id is %d\n", freq, clk_id); in rt5640_set_dai_sysclk()
1874 struct snd_soc_component *component = dai->component; in rt5640_set_dai_pll()
1879 if (source == rt5640->pll_src && freq_in == rt5640->pll_in && in rt5640_set_dai_pll()
1880 freq_out == rt5640->pll_out) in rt5640_set_dai_pll()
1884 dev_dbg(component->dev, "PLL disabled\n"); in rt5640_set_dai_pll()
1886 rt5640->pll_in = 0; in rt5640_set_dai_pll()
1887 rt5640->pll_out = 0; in rt5640_set_dai_pll()
1907 dev_err(component->dev, "Unknown PLL source %d\n", source); in rt5640_set_dai_pll()
1908 return -EINVAL; in rt5640_set_dai_pll()
1913 dev_err(component->dev, "Unsupported input clock %d\n", freq_in); in rt5640_set_dai_pll()
1917 dev_dbg(component->dev, "bypass=%d m=%d n=%d k=%d\n", in rt5640_set_dai_pll()
1927 rt5640->pll_in = freq_in; in rt5640_set_dai_pll()
1928 rt5640->pll_out = freq_out; in rt5640_set_dai_pll()
1929 rt5640->pll_src = source; in rt5640_set_dai_pll()
1953 clk_disable_unprepare(rt5640->mclk); in rt5640_set_bias_level()
1955 ret = clk_prepare_enable(rt5640->mclk); in rt5640_set_bias_level()
1987 if (rt5640->jd_src == RT5640_JD_SRC_HDA_HEADER) in rt5640_set_bias_level()
2008 regmap_update_bits(rt5640->regmap, RT5640_GPIO_CTRL1, in rt5640_dmic_enable()
2012 regmap_update_bits(rt5640->regmap, RT5640_DMIC, in rt5640_dmic_enable()
2014 regmap_update_bits(rt5640->regmap, RT5640_GPIO_CTRL1, in rt5640_dmic_enable()
2019 regmap_update_bits(rt5640->regmap, RT5640_DMIC, in rt5640_dmic_enable()
2021 regmap_update_bits(rt5640->regmap, RT5640_GPIO_CTRL1, in rt5640_dmic_enable()
2042 return -EINVAL; in rt5640_sel_asrc_clk_src()
2046 return -EINVAL; in rt5640_sel_asrc_clk_src()
2088 rt5640->asrc_en = true; in rt5640_sel_asrc_clk_src()
2091 rt5640->asrc_en = false; in rt5640_sel_asrc_clk_src()
2107 /* OVCD is unreliable when used with RCCLK as sysclk-source */ in rt5640_enable_micbias1_for_ovcd()
2108 if (rt5640->use_platform_clock) in rt5640_enable_micbias1_for_ovcd()
2121 if (rt5640->use_platform_clock) in rt5640_disable_micbias1_for_ovcd()
2136 rt5640->ovcd_irq_enabled = true; in rt5640_enable_micbias1_ovcd_irq()
2145 rt5640->ovcd_irq_enabled = false; in rt5640_disable_micbias1_ovcd_irq()
2159 dev_dbg(component->dev, "irq ctrl2 %#04x\n", val); in rt5640_micbias1_ovcd()
2169 if (rt5640->jd_gpio) in rt5640_jack_inserted()
2170 val = gpiod_get_value(rt5640->jd_gpio) ? RT5640_JD_STATUS : 0; in rt5640_jack_inserted()
2174 dev_dbg(component->dev, "irq status %#04x\n", val); in rt5640_jack_inserted()
2176 if (rt5640->jd_inverted) in rt5640_jack_inserted()
2182 /* Jack detect and button-press timings */
2195 rt5640->poll_count = 0; in rt5640_start_button_press_work()
2196 rt5640->press_count = 0; in rt5640_start_button_press_work()
2197 rt5640->release_count = 0; in rt5640_start_button_press_work()
2198 rt5640->pressed = false; in rt5640_start_button_press_work()
2199 rt5640->press_reported = false; in rt5640_start_button_press_work()
2201 schedule_delayed_work(&rt5640->bp_work, msecs_to_jiffies(BP_POLL_TIME)); in rt5640_start_button_press_work()
2208 struct snd_soc_component *component = rt5640->component; in rt5640_button_press_work()
2215 rt5640->release_count = 0; in rt5640_button_press_work()
2216 rt5640->press_count++; in rt5640_button_press_work()
2218 if (rt5640->press_count >= BP_THRESHOLD) in rt5640_button_press_work()
2219 rt5640->pressed = true; in rt5640_button_press_work()
2222 rt5640->press_count = 0; in rt5640_button_press_work()
2223 rt5640->release_count++; in rt5640_button_press_work()
2228 * at least JACK_UNPLUG_TIME milli-seconds before reporting a press. in rt5640_button_press_work()
2230 rt5640->poll_count++; in rt5640_button_press_work()
2231 if (rt5640->poll_count < (JACK_UNPLUG_TIME / BP_POLL_TIME)) { in rt5640_button_press_work()
2232 schedule_delayed_work(&rt5640->bp_work, in rt5640_button_press_work()
2237 if (rt5640->pressed && !rt5640->press_reported) { in rt5640_button_press_work()
2238 dev_dbg(component->dev, "headset button press\n"); in rt5640_button_press_work()
2239 snd_soc_jack_report(rt5640->jack, SND_JACK_BTN_0, in rt5640_button_press_work()
2241 rt5640->press_reported = true; in rt5640_button_press_work()
2244 if (rt5640->release_count >= BP_THRESHOLD) { in rt5640_button_press_work()
2245 if (rt5640->press_reported) { in rt5640_button_press_work()
2246 dev_dbg(component->dev, "headset button release\n"); in rt5640_button_press_work()
2247 snd_soc_jack_report(rt5640->jack, 0, SND_JACK_BTN_0); in rt5640_button_press_work()
2249 /* Re-enable OVCD IRQ to detect next press */ in rt5640_button_press_work()
2254 schedule_delayed_work(&rt5640->bp_work, msecs_to_jiffies(BP_POLL_TIME)); in rt5640_button_press_work()
2269 /* Clear any previous over-current status flag */ in rt5640_detect_headset()
2289 dev_dbg(component->dev, "jack mic-gnd shorted\n"); in rt5640_detect_headset()
2295 dev_dbg(component->dev, "jack mic-gnd open\n"); in rt5640_detect_headset()
2303 …dev_err(component->dev, "Error detecting headset vs headphones, bad contact?, assuming headphones\… in rt5640_detect_headset()
2312 struct snd_soc_component *component = rt5640->component; in rt5640_jack_work()
2315 if (rt5640->jd_src == RT5640_JD_SRC_HDA_HEADER) { in rt5640_jack_work()
2321 dev_dbg(component->dev, "mic jack status %d\n", in rt5640_jack_work()
2333 dev_dbg(component->dev, "headphone jack status %d\n", in rt5640_jack_work()
2342 snd_soc_jack_report(rt5640->jack, jack_type, SND_JACK_HEADSET); in rt5640_jack_work()
2349 if (rt5640->jack->status & SND_JACK_HEADPHONE) { in rt5640_jack_work()
2350 if (rt5640->jack->status & SND_JACK_MICROPHONE) { in rt5640_jack_work()
2351 cancel_delayed_work_sync(&rt5640->bp_work); in rt5640_jack_work()
2355 snd_soc_jack_report(rt5640->jack, 0, in rt5640_jack_work()
2357 dev_dbg(component->dev, "jack unplugged\n"); in rt5640_jack_work()
2359 } else if (!(rt5640->jack->status & SND_JACK_HEADPHONE)) { in rt5640_jack_work()
2361 WARN_ON(rt5640->ovcd_irq_enabled); in rt5640_jack_work()
2371 dev_dbg(component->dev, "detect status %#02x\n", status); in rt5640_jack_work()
2372 snd_soc_jack_report(rt5640->jack, status, SND_JACK_HEADSET); in rt5640_jack_work()
2373 } else if (rt5640->ovcd_irq_enabled && rt5640_micbias1_ovcd(component)) { in rt5640_jack_work()
2374 dev_dbg(component->dev, "OVCD IRQ\n"); in rt5640_jack_work()
2389 * If the jack-detect IRQ flag goes high (unplug) after our in rt5640_jack_work()
2392 * we react to edges, we miss the unplug event -> recheck. in rt5640_jack_work()
2394 queue_delayed_work(system_long_wq, &rt5640->jack_work, 0); in rt5640_jack_work()
2403 if (rt5640->jd_src == RT5640_JD_SRC_HDA_HEADER) in rt5640_irq()
2406 if (rt5640->jack) in rt5640_irq()
2407 mod_delayed_work(system_long_wq, &rt5640->jack_work, delay); in rt5640_irq()
2416 queue_delayed_work(system_long_wq, &rt5640->jack_work, in rt5640_jd_gpio_irq()
2426 if (rt5640->jd_gpio_irq_requested) { in rt5640_disable_irq_and_cancel_work()
2427 free_irq(rt5640->jd_gpio_irq, rt5640); in rt5640_disable_irq_and_cancel_work()
2428 rt5640->jd_gpio_irq_requested = false; in rt5640_disable_irq_and_cancel_work()
2431 if (rt5640->irq_requested) { in rt5640_disable_irq_and_cancel_work()
2432 free_irq(rt5640->irq, rt5640); in rt5640_disable_irq_and_cancel_work()
2433 rt5640->irq_requested = false; in rt5640_disable_irq_and_cancel_work()
2436 cancel_delayed_work_sync(&rt5640->jack_work); in rt5640_disable_irq_and_cancel_work()
2437 cancel_delayed_work_sync(&rt5640->bp_work); in rt5640_disable_irq_and_cancel_work()
2445 0xa800 | rt5640->ovcd_sf); in rt5640_set_ovcd_params()
2449 rt5640->ovcd_th | RT5640_MIC1_OVCD_EN); in rt5640_set_ovcd_params()
2452 * The over-current-detect is only reliable in detecting the absence in rt5640_set_ovcd_params()
2453 * of over-current, when the mic-contact in the jack is short-circuited, in rt5640_set_ovcd_params()
2454 * the hardware periodically retries if it can apply the bias-current in rt5640_set_ovcd_params()
2455 * leading to the ovcd status flip-flopping 1-0-1 with it being 0 about in rt5640_set_ovcd_params()
2470 * soc_remove_component() force-disables jack and thus rt5640->jack in rt5640_disable_jack_detect()
2473 if (!rt5640->jack) in rt5640_disable_jack_detect()
2478 if (rt5640->jack->status & SND_JACK_MICROPHONE) { in rt5640_disable_jack_detect()
2481 snd_soc_jack_report(rt5640->jack, 0, SND_JACK_BTN_0); in rt5640_disable_jack_detect()
2484 rt5640->jd_gpio = NULL; in rt5640_disable_jack_detect()
2485 rt5640->jack = NULL; in rt5640_disable_jack_detect()
2495 /* Select JD-source */ in rt5640_enable_jack_detect()
2497 RT5640_JD_MASK, rt5640->jd_src << RT5640_JD_SFT); in rt5640_enable_jack_detect()
2512 * All IRQs get or-ed together, so we need the jack IRQ to report 0 in rt5640_enable_jack_detect()
2517 if (rt5640->jd_inverted) { in rt5640_enable_jack_detect()
2518 if (rt5640->jd_src == RT5640_JD_SRC_JD1_IN4P) in rt5640_enable_jack_detect()
2521 else if (rt5640->jd_src == RT5640_JD_SRC_JD2_IN4N) in rt5640_enable_jack_detect()
2526 if (rt5640->jd_src == RT5640_JD_SRC_JD1_IN4P) in rt5640_enable_jack_detect()
2529 else if (rt5640->jd_src == RT5640_JD_SRC_JD2_IN4N) in rt5640_enable_jack_detect()
2537 rt5640->jack = jack; in rt5640_enable_jack_detect()
2538 if (rt5640->jack->status & SND_JACK_MICROPHONE) { in rt5640_enable_jack_detect()
2543 if (jack_data && jack_data->codec_irq_override) in rt5640_enable_jack_detect()
2544 rt5640->irq = jack_data->codec_irq_override; in rt5640_enable_jack_detect()
2546 if (jack_data && jack_data->jd_gpio) { in rt5640_enable_jack_detect()
2547 rt5640->jd_gpio = jack_data->jd_gpio; in rt5640_enable_jack_detect()
2548 rt5640->jd_gpio_irq = gpiod_to_irq(rt5640->jd_gpio); in rt5640_enable_jack_detect()
2550 ret = request_irq(rt5640->jd_gpio_irq, rt5640_jd_gpio_irq, in rt5640_enable_jack_detect()
2552 "rt5640-jd-gpio", rt5640); in rt5640_enable_jack_detect()
2554 dev_warn(component->dev, "Failed to request jd GPIO IRQ %d: %d\n", in rt5640_enable_jack_detect()
2555 rt5640->jd_gpio_irq, ret); in rt5640_enable_jack_detect()
2559 rt5640->jd_gpio_irq_requested = true; in rt5640_enable_jack_detect()
2562 if (jack_data && jack_data->use_platform_clock) in rt5640_enable_jack_detect()
2563 rt5640->use_platform_clock = jack_data->use_platform_clock; in rt5640_enable_jack_detect()
2565 ret = request_irq(rt5640->irq, rt5640_irq, in rt5640_enable_jack_detect()
2569 dev_warn(component->dev, "Failed to request IRQ %d: %d\n", rt5640->irq, ret); in rt5640_enable_jack_detect()
2573 rt5640->irq_requested = true; in rt5640_enable_jack_detect()
2576 queue_delayed_work(system_long_wq, &rt5640->jack_work, 0); in rt5640_enable_jack_detect()
2618 rt5640->jack = jack; in rt5640_enable_hda_jack_detect()
2620 ret = request_irq(rt5640->irq, rt5640_irq, in rt5640_enable_hda_jack_detect()
2623 dev_warn(component->dev, "Failed to request IRQ %d: %d\n", rt5640->irq, ret); in rt5640_enable_hda_jack_detect()
2624 rt5640->jack = NULL; in rt5640_enable_hda_jack_detect()
2627 rt5640->irq_requested = true; in rt5640_enable_hda_jack_detect()
2630 queue_delayed_work(system_long_wq, &rt5640->jack_work, 0); in rt5640_enable_hda_jack_detect()
2642 if (rt5640->jd_src == RT5640_JD_SRC_HDA_HEADER) in rt5640_set_jack()
2663 rt5640->mclk = devm_clk_get_optional(component->dev, "mclk"); in rt5640_probe()
2664 if (IS_ERR(rt5640->mclk)) in rt5640_probe()
2665 return PTR_ERR(rt5640->mclk); in rt5640_probe()
2667 rt5640->component = component; in rt5640_probe()
2697 dev_err(component->dev, in rt5640_probe()
2699 return -ENODEV; in rt5640_probe()
2703 * Note on some platforms the platform code may need to add device-props in rt5640_probe()
2706 * rt5640_i2c_probe(), so that the platform-code can attach extra in rt5640_probe()
2709 if (device_property_read_bool(component->dev, "realtek,in1-differential")) in rt5640_probe()
2713 if (device_property_read_bool(component->dev, "realtek,in2-differential")) in rt5640_probe()
2717 if (device_property_read_bool(component->dev, "realtek,in3-differential")) in rt5640_probe()
2721 if (device_property_read_bool(component->dev, "realtek,lout-differential")) in rt5640_probe()
2725 if (device_property_read_u32(component->dev, "realtek,dmic1-data-pin", in rt5640_probe()
2727 dmic1_data_pin = val - 1; in rt5640_probe()
2731 if (device_property_read_u32(component->dev, "realtek,dmic2-data-pin", in rt5640_probe()
2733 dmic2_data_pin = val - 1; in rt5640_probe()
2740 if (device_property_read_u32(component->dev, in rt5640_probe()
2741 "realtek,jack-detect-source", &val) == 0) { in rt5640_probe()
2743 rt5640->jd_src = val; in rt5640_probe()
2745 …dev_warn(component->dev, "Warning: Invalid jack-detect-source value: %d, leaving jack-detect disab… in rt5640_probe()
2749 if (!device_property_read_bool(component->dev, "realtek,jack-detect-not-inverted")) in rt5640_probe()
2750 rt5640->jd_inverted = true; in rt5640_probe()
2754 * threshold and scale-factor are 2000µA and 0.75. For an effective in rt5640_probe()
2757 rt5640->ovcd_th = RT5640_MIC1_OVTH_2000UA; in rt5640_probe()
2758 rt5640->ovcd_sf = RT5640_MIC_OVCD_SF_0P75; in rt5640_probe()
2760 if (device_property_read_u32(component->dev, in rt5640_probe()
2761 "realtek,over-current-threshold-microamp", &val) == 0) { in rt5640_probe()
2764 rt5640->ovcd_th = RT5640_MIC1_OVTH_600UA; in rt5640_probe()
2767 rt5640->ovcd_th = RT5640_MIC1_OVTH_1500UA; in rt5640_probe()
2770 rt5640->ovcd_th = RT5640_MIC1_OVTH_2000UA; in rt5640_probe()
2773 …dev_warn(component->dev, "Warning: Invalid over-current-threshold-microamp value: %d, defaulting t… in rt5640_probe()
2778 if (device_property_read_u32(component->dev, in rt5640_probe()
2779 "realtek,over-current-scale-factor", &val) == 0) { in rt5640_probe()
2781 rt5640->ovcd_sf = val << RT5640_MIC_OVCD_SF_SFT; in rt5640_probe()
2783 …dev_warn(component->dev, "Warning: Invalid over-current-scale-factor value: %d, defaulting to 0.75… in rt5640_probe()
2800 if (rt5640->jack) { in rt5640_suspend()
2802 disable_irq(rt5640->irq); in rt5640_suspend()
2803 cancel_delayed_work_sync(&rt5640->jack_work); in rt5640_suspend()
2804 cancel_delayed_work_sync(&rt5640->bp_work); in rt5640_suspend()
2809 regcache_cache_only(rt5640->regmap, true); in rt5640_suspend()
2810 regcache_mark_dirty(rt5640->regmap); in rt5640_suspend()
2811 if (rt5640->ldo1_en) in rt5640_suspend()
2812 gpiod_set_value_cansleep(rt5640->ldo1_en, 0); in rt5640_suspend()
2821 if (rt5640->ldo1_en) { in rt5640_resume()
2822 gpiod_set_value_cansleep(rt5640->ldo1_en, 1); in rt5640_resume()
2826 regcache_cache_only(rt5640->regmap, false); in rt5640_resume()
2827 regcache_sync(rt5640->regmap); in rt5640_resume()
2829 if (rt5640->jack) { in rt5640_resume()
2830 if (rt5640->jd_src == RT5640_JD_SRC_HDA_HEADER) { in rt5640_resume()
2834 if (rt5640->jd_inverted) { in rt5640_resume()
2835 if (rt5640->jd_src == RT5640_JD_SRC_JD2_IN4N) in rt5640_resume()
2844 if (rt5640->jd_src == RT5640_JD_SRC_JD2_IN4N) in rt5640_resume()
2856 enable_irq(rt5640->irq); in rt5640_resume()
2857 queue_delayed_work(system_long_wq, &rt5640->jack_work, 0); in rt5640_resume()
2880 .name = "rt5640-aif1",
2899 .name = "rt5640-aif2",
2902 .stream_name = "AIF2 Playback",
2909 .stream_name = "AIF2 Capture",
2989 rt5640 = devm_kzalloc(&i2c->dev, in rt5640_i2c_probe()
2993 return -ENOMEM; in rt5640_i2c_probe()
2996 rt5640->ldo1_en = devm_gpiod_get_optional(&i2c->dev, in rt5640_i2c_probe()
2997 "realtek,ldo1-en", in rt5640_i2c_probe()
2999 if (IS_ERR(rt5640->ldo1_en)) in rt5640_i2c_probe()
3000 return PTR_ERR(rt5640->ldo1_en); in rt5640_i2c_probe()
3002 if (rt5640->ldo1_en) { in rt5640_i2c_probe()
3003 gpiod_set_consumer_name(rt5640->ldo1_en, "RT5640 LDO1_EN"); in rt5640_i2c_probe()
3007 rt5640->regmap = devm_regmap_init_i2c(i2c, &rt5640_regmap); in rt5640_i2c_probe()
3008 if (IS_ERR(rt5640->regmap)) { in rt5640_i2c_probe()
3009 ret = PTR_ERR(rt5640->regmap); in rt5640_i2c_probe()
3010 dev_err(&i2c->dev, "Failed to allocate register map: %d\n", in rt5640_i2c_probe()
3015 regmap_read(rt5640->regmap, RT5640_VENDOR_ID2, &val); in rt5640_i2c_probe()
3017 dev_err(&i2c->dev, in rt5640_i2c_probe()
3019 return -ENODEV; in rt5640_i2c_probe()
3022 regmap_write(rt5640->regmap, RT5640_RESET, 0); in rt5640_i2c_probe()
3024 ret = regmap_register_patch(rt5640->regmap, init_list, in rt5640_i2c_probe()
3027 dev_warn(&i2c->dev, "Failed to apply regmap patch: %d\n", ret); in rt5640_i2c_probe()
3029 regmap_update_bits(rt5640->regmap, RT5640_DUMMY1, in rt5640_i2c_probe()
3032 rt5640->hp_mute = true; in rt5640_i2c_probe()
3033 rt5640->irq = i2c->irq; in rt5640_i2c_probe()
3034 INIT_DELAYED_WORK(&rt5640->bp_work, rt5640_button_press_work); in rt5640_i2c_probe()
3035 INIT_DELAYED_WORK(&rt5640->jack_work, rt5640_jack_work); in rt5640_i2c_probe()
3037 /* Make sure work is stopped on probe-error / remove */ in rt5640_i2c_probe()
3038 ret = devm_add_action_or_reset(&i2c->dev, rt5640_disable_irq_and_cancel_work, rt5640); in rt5640_i2c_probe()
3042 return devm_snd_soc_register_component(&i2c->dev, in rt5640_i2c_probe()