Lines Matching +full:adc +full:- +full:channel +full:- +full:clk +full:- +full:src

1 // SPDX-License-Identifier: GPL-2.0-only
3 * cs42l42.c -- CS42L42 ALSA SoC audio driver
32 #include <sound/soc-dapm.h>
35 #include <dt-bindings/sound/cs42l42.h>
403 static DECLARE_TLV_DB_SCALE(adc_tlv, -9700, 100, true);
404 static DECLARE_TLV_DB_SCALE(mixer_tlv, -6300, 100, true);
413 switch (ucontrol->value.integer.value[0]) { in cs42l42_slow_start_put()
421 return -EINVAL; in cs42l42_slow_start_put()
446 /* ADC Volume and Filter Controls */
447 SOC_SINGLE("ADC Notch Switch", CS42L42_ADC_CTL,
449 SOC_SINGLE("ADC Weak Force Switch", CS42L42_ADC_CTL,
451 SOC_SINGLE("ADC Invert Switch", CS42L42_ADC_CTL,
453 SOC_SINGLE("ADC Boost Switch", CS42L42_ADC_CTL,
455 SOC_SINGLE_S8_TLV("ADC Volume", CS42L42_ADC_VOLUME, -97, 12, adc_tlv),
456 SOC_SINGLE("ADC WNF Switch", CS42L42_ADC_WNF_HPF_CTL,
458 SOC_SINGLE("ADC HPF Switch", CS42L42_ADC_WNF_HPF_CTL,
482 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in cs42l42_hp_adc_ev()
487 cs42l42->hp_adc_up_pending = true; in cs42l42_hp_adc_ev()
490 /* Only need one delay if HP and ADC are both powering-up */ in cs42l42_hp_adc_ev()
491 if (cs42l42->hp_adc_up_pending) { in cs42l42_hp_adc_ev()
494 cs42l42->hp_adc_up_pending = false; in cs42l42_hp_adc_ev()
518 SND_SOC_DAPM_ADC_E("ADC", NULL, CS42L42_PWR_CTL1, CS42L42_ADC_PDN_SHIFT, 1,
530 /* Soundwire SRC power control */
551 {"ADC", NULL, "HS"},
552 { "SDOUT1", NULL, "ADC" },
553 { "SDOUT2", NULL, "ADC" },
571 mutex_lock(&cs42l42->irq_lock); in cs42l42_set_jack()
572 cs42l42->jack = jk; in cs42l42_set_jack()
575 switch (cs42l42->hs_type) { in cs42l42_set_jack()
587 mutex_unlock(&cs42l42->irq_lock); in cs42l42_set_jack()
637 * Table 4-5 from the Datasheet
667 int cs42l42_pll_config(struct snd_soc_component *component, unsigned int clk, in cs42l42_pll_config() argument
674 if (cs42l42->stream_use) { in cs42l42_pll_config()
675 if (pll_ratio_table[cs42l42->pll_config].sclk == clk) in cs42l42_pll_config()
678 return -EBUSY; in cs42l42_pll_config()
686 if (pll_ratio_table[i].sclk == clk) { in cs42l42_pll_config()
687 cs42l42->pll_config = i; in cs42l42_pll_config()
703 /* Configure PLL per table 4-5 */ in cs42l42_pll_config()
752 return -EINVAL; in cs42l42_pll_config()
762 if (cs42l42->stream_use) in cs42l42_src_config()
765 /* SRC MCLK must be as close as possible to 125 * sample rate */ in cs42l42_src_config()
797 dev_err(component->dev, in cs42l42_asp_config()
801 return -EINVAL; in cs42l42_asp_config()
807 CS42L42_FRAC0_VAL(fsync - 1) << in cs42l42_asp_config()
812 CS42L42_FRAC1_VAL(fsync - 1) << in cs42l42_asp_config()
819 CS42L42_FRAC0_VAL(fsync - 1) << in cs42l42_asp_config()
824 CS42L42_FRAC1_VAL(fsync - 1) << in cs42l42_asp_config()
832 struct snd_soc_component *component = codec_dai->component; in cs42l42_set_dai_fmt()
845 return -EINVAL; in cs42l42_set_dai_fmt()
865 return -EINVAL; in cs42l42_set_dai_fmt()
894 struct snd_soc_component *component = dai->component; in cs42l42_dai_startup()
898 * Sample rates < 44.1 kHz would produce an out-of-range SCLK with in cs42l42_dai_startup()
902 if (cs42l42->sclk) in cs42l42_dai_startup()
906 return snd_pcm_hw_constraint_minmax(substream->runtime, in cs42l42_dai_startup()
915 struct snd_soc_component *component = dai->component; in cs42l42_pcm_hw_params()
918 unsigned int width = (params_width(params) / 8) - 1; in cs42l42_pcm_hw_params()
925 if (cs42l42->bclk_ratio) { in cs42l42_pcm_hw_params()
926 /* machine driver has set the BCLK/samp-rate ratio */ in cs42l42_pcm_hw_params()
927 bclk = cs42l42->bclk_ratio * params_rate(params); in cs42l42_pcm_hw_params()
928 } else if (cs42l42->sclk) { in cs42l42_pcm_hw_params()
930 bclk = cs42l42->sclk; in cs42l42_pcm_hw_params()
933 * Assume 24-bit samples are in 32-bit slots, to prevent SCLK being in cs42l42_pcm_hw_params()
943 switch (substream->stream) { in cs42l42_pcm_hw_params()
945 /* channel 2 on high LRCLK */ in cs42l42_pcm_hw_params()
956 /* channel 1 on low LRCLK */ in cs42l42_pcm_hw_params()
960 /* Channel 2 on high LRCLK */ in cs42l42_pcm_hw_params()
966 /* Channel B comes from the last active channel */ in cs42l42_pcm_hw_params()
969 (channels - 1) << CS42L42_SP_RX_CHB_SEL_SHIFT); in cs42l42_pcm_hw_params()
997 struct snd_soc_component *component = dai->component; in cs42l42_set_sysclk()
1002 cs42l42->sclk = 0; in cs42l42_set_sysclk()
1008 cs42l42->sclk = freq; in cs42l42_set_sysclk()
1013 dev_err(component->dev, "SCLK %u not supported\n", freq); in cs42l42_set_sysclk()
1015 return -EINVAL; in cs42l42_set_sysclk()
1021 struct snd_soc_component *component = dai->component; in cs42l42_set_bclk_ratio()
1024 cs42l42->bclk_ratio = bclk_ratio; in cs42l42_set_bclk_ratio()
1031 struct snd_soc_component *component = dai->component; in cs42l42_mute_stream()
1045 cs42l42->stream_use &= ~(1 << stream); in cs42l42_mute_stream()
1046 if (!cs42l42->stream_use) { in cs42l42_mute_stream()
1052 regmap_multi_reg_write(cs42l42->regmap, cs42l42_to_osc_seq, in cs42l42_mute_stream()
1066 if (!cs42l42->stream_use) { in cs42l42_mute_stream()
1069 * PLL must not be started with ADC and HP both off in cs42l42_mute_stream()
1071 * DAPM widgets power-up before stream unmute so at least in cs42l42_mute_stream()
1072 * one of the "DAC" or "ADC" widgets will already have in cs42l42_mute_stream()
1073 * powered-up. in cs42l42_mute_stream()
1075 if (pll_ratio_table[cs42l42->pll_config].mclk_src_sel) { in cs42l42_mute_stream()
1079 if (pll_ratio_table[cs42l42->pll_config].n > 1) { in cs42l42_mute_stream()
1082 regval = pll_ratio_table[cs42l42->pll_config].pll_divout; in cs42l42_mute_stream()
1089 ret = regmap_read_poll_timeout(cs42l42->regmap, in cs42l42_mute_stream()
1096 dev_warn(component->dev, "PLL failed to lock: %d\n", ret); in cs42l42_mute_stream()
1106 regmap_multi_reg_write(cs42l42->regmap, cs42l42_to_sclk_seq, in cs42l42_mute_stream()
1109 cs42l42->stream_use |= 1 << stream; in cs42l42_mute_stream()
1112 /* Un-mute the headphone */ in cs42l42_mute_stream()
1167 regmap_update_bits(cs42l42->regmap, in cs42l42_manual_hs_type_detect()
1179 regmap_update_bits(cs42l42->regmap, in cs42l42_manual_hs_type_detect()
1187 regmap_write(cs42l42->regmap, CS42L42_HS_SWITCH_CTL, CS42L42_HSDET_SW_COMP1); in cs42l42_manual_hs_type_detect()
1191 regmap_read(cs42l42->regmap, CS42L42_HS_DET_STATUS, &hs_det_status); in cs42l42_manual_hs_type_detect()
1199 regmap_write(cs42l42->regmap, CS42L42_HS_SWITCH_CTL, CS42L42_HSDET_SW_COMP2); in cs42l42_manual_hs_type_detect()
1203 regmap_read(cs42l42->regmap, CS42L42_HS_DET_STATUS, &hs_det_status); in cs42l42_manual_hs_type_detect()
1213 cs42l42->hs_type = CS42L42_PLUG_CTIA; in cs42l42_manual_hs_type_detect()
1217 cs42l42->hs_type = CS42L42_PLUG_OMTP; in cs42l42_manual_hs_type_detect()
1224 cs42l42->hs_type = CS42L42_PLUG_CTIA; in cs42l42_manual_hs_type_detect()
1228 cs42l42->hs_type = CS42L42_PLUG_OMTP; in cs42l42_manual_hs_type_detect()
1233 cs42l42->hs_type = CS42L42_PLUG_HEADPHONE; in cs42l42_manual_hs_type_detect()
1240 regmap_write(cs42l42->regmap, CS42L42_HS_SWITCH_CTL, hs_det_sw); in cs42l42_manual_hs_type_detect()
1243 regmap_update_bits(cs42l42->regmap, in cs42l42_manual_hs_type_detect()
1255 regmap_update_bits(cs42l42->regmap, in cs42l42_manual_hs_type_detect()
1269 regmap_read(cs42l42->regmap, CS42L42_HS_DET_STATUS, &hs_det_status); in cs42l42_process_hs_type_detect()
1272 regmap_update_bits(cs42l42->regmap, in cs42l42_process_hs_type_detect()
1280 cs42l42->hs_type = (hs_det_status & CS42L42_HSDET_TYPE_MASK) >> in cs42l42_process_hs_type_detect()
1284 regmap_update_bits(cs42l42->regmap, in cs42l42_process_hs_type_detect()
1296 * We Re-Run with Manual Detection if the original detection was invalid or headphones, in cs42l42_process_hs_type_detect()
1299 if (cs42l42->hs_type == CS42L42_PLUG_INVALID || in cs42l42_process_hs_type_detect()
1300 cs42l42->hs_type == CS42L42_PLUG_HEADPHONE) { in cs42l42_process_hs_type_detect()
1301 dev_dbg(cs42l42->dev, "Running Manual Detection Fallback\n"); in cs42l42_process_hs_type_detect()
1306 if ((cs42l42->hs_type == CS42L42_PLUG_CTIA) || in cs42l42_process_hs_type_detect()
1307 (cs42l42->hs_type == CS42L42_PLUG_OMTP)) { in cs42l42_process_hs_type_detect()
1309 regmap_update_bits(cs42l42->regmap, in cs42l42_process_hs_type_detect()
1321 regmap_update_bits(cs42l42->regmap, in cs42l42_process_hs_type_detect()
1328 (cs42l42->bias_thresholds[0] << in cs42l42_process_hs_type_detect()
1332 regmap_update_bits(cs42l42->regmap, in cs42l42_process_hs_type_detect()
1338 (cs42l42->hs_bias_sense_en << CS42L42_HSBIAS_SENSE_EN_SHIFT) | in cs42l42_process_hs_type_detect()
1344 regmap_update_bits(cs42l42->regmap, in cs42l42_process_hs_type_detect()
1351 msleep(cs42l42->btn_det_init_dbnce); in cs42l42_process_hs_type_detect()
1354 regmap_read(cs42l42->regmap, CS42L42_DET_INT_STATUS2, in cs42l42_process_hs_type_detect()
1358 regmap_update_bits(cs42l42->regmap, in cs42l42_process_hs_type_detect()
1372 regmap_update_bits(cs42l42->regmap, in cs42l42_process_hs_type_detect()
1380 regmap_update_bits(cs42l42->regmap, in cs42l42_process_hs_type_detect()
1394 regmap_update_bits(cs42l42->regmap, in cs42l42_process_hs_type_detect()
1405 regmap_update_bits(cs42l42->regmap, in cs42l42_init_hs_type_detect()
1413 regmap_update_bits(cs42l42->regmap, in cs42l42_init_hs_type_detect()
1421 regmap_update_bits(cs42l42->regmap, in cs42l42_init_hs_type_detect()
1433 regmap_update_bits(cs42l42->regmap, in cs42l42_init_hs_type_detect()
1444 regmap_update_bits(cs42l42->regmap, in cs42l42_init_hs_type_detect()
1458 regmap_update_bits(cs42l42->regmap, in cs42l42_init_hs_type_detect()
1466 msleep(cs42l42->hs_bias_ramp_time); in cs42l42_init_hs_type_detect()
1469 regmap_update_bits(cs42l42->regmap, in cs42l42_init_hs_type_detect()
1477 regmap_update_bits(cs42l42->regmap, in cs42l42_init_hs_type_detect()
1492 regmap_update_bits(cs42l42->regmap, in cs42l42_cancel_hs_type_detect()
1506 regmap_update_bits(cs42l42->regmap, in cs42l42_cancel_hs_type_detect()
1514 regmap_update_bits(cs42l42->regmap, in cs42l42_cancel_hs_type_detect()
1526 regmap_update_bits(cs42l42->regmap, in cs42l42_cancel_hs_type_detect()
1544 regmap_update_bits(cs42l42->regmap, in cs42l42_handle_button_press()
1557 usleep_range(cs42l42->btn_det_event_dbnce * 1000, in cs42l42_handle_button_press()
1558 cs42l42->btn_det_event_dbnce * 2000); in cs42l42_handle_button_press()
1564 regmap_update_bits(cs42l42->regmap, in cs42l42_handle_button_press()
1571 (cs42l42->bias_thresholds[bias_level] << in cs42l42_handle_button_press()
1574 regmap_read(cs42l42->regmap, CS42L42_DET_STATUS2, in cs42l42_handle_button_press()
1582 dev_dbg(cs42l42->dev, "Function C button press\n"); in cs42l42_handle_button_press()
1586 dev_dbg(cs42l42->dev, "Function B button press\n"); in cs42l42_handle_button_press()
1590 dev_dbg(cs42l42->dev, "Function D button press\n"); in cs42l42_handle_button_press()
1594 dev_dbg(cs42l42->dev, "Function A button press\n"); in cs42l42_handle_button_press()
1602 regmap_update_bits(cs42l42->regmap, in cs42l42_handle_button_press()
1609 (cs42l42->bias_thresholds[0] << CS42L42_HS_DET_LEVEL_SHIFT)); in cs42l42_handle_button_press()
1612 regmap_read(cs42l42->regmap, CS42L42_DET_INT_STATUS2, in cs42l42_handle_button_press()
1616 regmap_update_bits(cs42l42->regmap, in cs42l42_handle_button_press()
1674 pm_runtime_get_sync(cs42l42->dev); in cs42l42_irq_thread()
1675 mutex_lock(&cs42l42->irq_lock); in cs42l42_irq_thread()
1676 if (cs42l42->suspended || !cs42l42->init_done) { in cs42l42_irq_thread()
1677 mutex_unlock(&cs42l42->irq_lock); in cs42l42_irq_thread()
1678 pm_runtime_put_autosuspend(cs42l42->dev); in cs42l42_irq_thread()
1684 regmap_read(cs42l42->regmap, irq_params_table[i].status_addr, in cs42l42_irq_thread()
1686 regmap_read(cs42l42->regmap, irq_params_table[i].mask_addr, in cs42l42_irq_thread()
1704 * Check auto-detect status. Don't assume a previous unplug event has in cs42l42_irq_thread()
1711 switch (cs42l42->hs_type) { in cs42l42_irq_thread()
1714 snd_soc_jack_report(cs42l42->jack, SND_JACK_HEADSET, in cs42l42_irq_thread()
1720 snd_soc_jack_report(cs42l42->jack, SND_JACK_HEADPHONE, in cs42l42_irq_thread()
1728 dev_dbg(cs42l42->dev, "Auto detect done (%d)\n", cs42l42->hs_type); in cs42l42_irq_thread()
1736 if (cs42l42->plug_state != CS42L42_TS_PLUG) { in cs42l42_irq_thread()
1737 cs42l42->plug_state = CS42L42_TS_PLUG; in cs42l42_irq_thread()
1743 if (cs42l42->plug_state != CS42L42_TS_UNPLUG) { in cs42l42_irq_thread()
1744 cs42l42->plug_state = CS42L42_TS_UNPLUG; in cs42l42_irq_thread()
1747 snd_soc_jack_report(cs42l42->jack, 0, in cs42l42_irq_thread()
1752 dev_dbg(cs42l42->dev, "Unplug event\n"); in cs42l42_irq_thread()
1757 cs42l42->plug_state = CS42L42_TS_TRANS; in cs42l42_irq_thread()
1762 if (cs42l42->plug_state == CS42L42_TS_PLUG && ((~masks[7]) & irq_params_table[7].mask)) { in cs42l42_irq_thread()
1767 dev_dbg(cs42l42->dev, "Button released\n"); in cs42l42_irq_thread()
1768 snd_soc_jack_report(cs42l42->jack, 0, in cs42l42_irq_thread()
1772 snd_soc_jack_report(cs42l42->jack, in cs42l42_irq_thread()
1780 mutex_unlock(&cs42l42->irq_lock); in cs42l42_irq_thread()
1781 pm_runtime_mark_last_busy(cs42l42->dev); in cs42l42_irq_thread()
1782 pm_runtime_put_autosuspend(cs42l42->dev); in cs42l42_irq_thread()
1790 regmap_update_bits(cs42l42->regmap, CS42L42_ADC_OVFL_INT_MASK, in cs42l42_set_interrupt_masks()
1794 regmap_update_bits(cs42l42->regmap, CS42L42_MIXER_INT_MASK, in cs42l42_set_interrupt_masks()
1804 regmap_update_bits(cs42l42->regmap, CS42L42_SRC_INT_MASK, in cs42l42_set_interrupt_masks()
1814 regmap_update_bits(cs42l42->regmap, CS42L42_ASP_RX_INT_MASK, in cs42l42_set_interrupt_masks()
1826 regmap_update_bits(cs42l42->regmap, CS42L42_ASP_TX_INT_MASK, in cs42l42_set_interrupt_masks()
1836 regmap_update_bits(cs42l42->regmap, CS42L42_CODEC_INT_MASK, in cs42l42_set_interrupt_masks()
1842 regmap_update_bits(cs42l42->regmap, CS42L42_SRCPL_INT_MASK, in cs42l42_set_interrupt_masks()
1852 regmap_update_bits(cs42l42->regmap, CS42L42_DET_INT1_MASK, in cs42l42_set_interrupt_masks()
1860 regmap_update_bits(cs42l42->regmap, CS42L42_DET_INT2_MASK, in cs42l42_set_interrupt_masks()
1872 regmap_update_bits(cs42l42->regmap, CS42L42_VPMON_INT_MASK, in cs42l42_set_interrupt_masks()
1876 regmap_update_bits(cs42l42->regmap, CS42L42_PLL_LOCK_INT_MASK, in cs42l42_set_interrupt_masks()
1880 regmap_update_bits(cs42l42->regmap, CS42L42_TSRS_PLUG_INT_MASK, in cs42l42_set_interrupt_masks()
1895 cs42l42->hs_type = CS42L42_PLUG_INVALID; in cs42l42_setup_hs_type_detect()
1898 * DETECT_MODE must always be 0 with ADC and HP both off otherwise the in cs42l42_setup_hs_type_detect()
1901 regmap_update_bits(cs42l42->regmap, CS42L42_MISC_DET_CTL, in cs42l42_setup_hs_type_detect()
1905 regmap_update_bits(cs42l42->regmap, CS42L42_MIC_DET_CTL1, in cs42l42_setup_hs_type_detect()
1911 (cs42l42->bias_thresholds[0] << in cs42l42_setup_hs_type_detect()
1914 /* Remove ground noise-suppression clamps */ in cs42l42_setup_hs_type_detect()
1915 regmap_update_bits(cs42l42->regmap, in cs42l42_setup_hs_type_detect()
1921 regmap_update_bits(cs42l42->regmap, CS42L42_TSENSE_CTL, in cs42l42_setup_hs_type_detect()
1924 regmap_update_bits(cs42l42->regmap, CS42L42_TIPSENSE_CTL, in cs42l42_setup_hs_type_detect()
1929 (!cs42l42->ts_inv << CS42L42_TIP_SENSE_INV_SHIFT) | in cs42l42_setup_hs_type_detect()
1933 regmap_read(cs42l42->regmap, in cs42l42_setup_hs_type_detect()
1936 cs42l42->plug_state = (((char) reg) & in cs42l42_setup_hs_type_detect()
1956 ret = device_property_read_u32(dev, "cirrus,ts-inv", &val); in cs42l42_handle_device_data()
1961 cs42l42->ts_inv = val; in cs42l42_handle_device_data()
1965 "Wrong cirrus,ts-inv DT value %d\n", in cs42l42_handle_device_data()
1967 cs42l42->ts_inv = CS42L42_TS_INV_DIS; in cs42l42_handle_device_data()
1970 cs42l42->ts_inv = CS42L42_TS_INV_DIS; in cs42l42_handle_device_data()
1973 ret = device_property_read_u32(dev, "cirrus,ts-dbnc-rise", &val); in cs42l42_handle_device_data()
1984 cs42l42->ts_dbnc_rise = val; in cs42l42_handle_device_data()
1988 "Wrong cirrus,ts-dbnc-rise DT value %d\n", in cs42l42_handle_device_data()
1990 cs42l42->ts_dbnc_rise = CS42L42_TS_DBNCE_1000; in cs42l42_handle_device_data()
1993 cs42l42->ts_dbnc_rise = CS42L42_TS_DBNCE_1000; in cs42l42_handle_device_data()
1996 regmap_update_bits(cs42l42->regmap, CS42L42_TSENSE_CTL, in cs42l42_handle_device_data()
1998 (cs42l42->ts_dbnc_rise << in cs42l42_handle_device_data()
2001 ret = device_property_read_u32(dev, "cirrus,ts-dbnc-fall", &val); in cs42l42_handle_device_data()
2012 cs42l42->ts_dbnc_fall = val; in cs42l42_handle_device_data()
2016 "Wrong cirrus,ts-dbnc-fall DT value %d\n", in cs42l42_handle_device_data()
2018 cs42l42->ts_dbnc_fall = CS42L42_TS_DBNCE_0; in cs42l42_handle_device_data()
2021 cs42l42->ts_dbnc_fall = CS42L42_TS_DBNCE_0; in cs42l42_handle_device_data()
2024 regmap_update_bits(cs42l42->regmap, CS42L42_TSENSE_CTL, in cs42l42_handle_device_data()
2026 (cs42l42->ts_dbnc_fall << in cs42l42_handle_device_data()
2029 ret = device_property_read_u32(dev, "cirrus,btn-det-init-dbnce", &val); in cs42l42_handle_device_data()
2032 cs42l42->btn_det_init_dbnce = val; in cs42l42_handle_device_data()
2035 "Wrong cirrus,btn-det-init-dbnce DT value %d\n", in cs42l42_handle_device_data()
2037 cs42l42->btn_det_init_dbnce = in cs42l42_handle_device_data()
2041 cs42l42->btn_det_init_dbnce = in cs42l42_handle_device_data()
2045 ret = device_property_read_u32(dev, "cirrus,btn-det-event-dbnce", &val); in cs42l42_handle_device_data()
2048 cs42l42->btn_det_event_dbnce = val; in cs42l42_handle_device_data()
2051 "Wrong cirrus,btn-det-event-dbnce DT value %d\n", val); in cs42l42_handle_device_data()
2052 cs42l42->btn_det_event_dbnce = in cs42l42_handle_device_data()
2056 cs42l42->btn_det_event_dbnce = in cs42l42_handle_device_data()
2060 ret = device_property_read_u32_array(dev, "cirrus,bias-lvls", in cs42l42_handle_device_data()
2065 cs42l42->bias_thresholds[i] = thresholds[i]; in cs42l42_handle_device_data()
2068 "Wrong cirrus,bias-lvls[%d] DT value %d\n", i, in cs42l42_handle_device_data()
2070 cs42l42->bias_thresholds[i] = threshold_defaults[i]; in cs42l42_handle_device_data()
2075 cs42l42->bias_thresholds[i] = threshold_defaults[i]; in cs42l42_handle_device_data()
2078 ret = device_property_read_u32(dev, "cirrus,hs-bias-ramp-rate", &val); in cs42l42_handle_device_data()
2082 cs42l42->hs_bias_ramp_rate = val; in cs42l42_handle_device_data()
2083 cs42l42->hs_bias_ramp_time = CS42L42_HSBIAS_RAMP_TIME0; in cs42l42_handle_device_data()
2086 cs42l42->hs_bias_ramp_rate = val; in cs42l42_handle_device_data()
2087 cs42l42->hs_bias_ramp_time = CS42L42_HSBIAS_RAMP_TIME1; in cs42l42_handle_device_data()
2090 cs42l42->hs_bias_ramp_rate = val; in cs42l42_handle_device_data()
2091 cs42l42->hs_bias_ramp_time = CS42L42_HSBIAS_RAMP_TIME2; in cs42l42_handle_device_data()
2094 cs42l42->hs_bias_ramp_rate = val; in cs42l42_handle_device_data()
2095 cs42l42->hs_bias_ramp_time = CS42L42_HSBIAS_RAMP_TIME3; in cs42l42_handle_device_data()
2099 "Wrong cirrus,hs-bias-ramp-rate DT value %d\n", in cs42l42_handle_device_data()
2101 cs42l42->hs_bias_ramp_rate = CS42L42_HSBIAS_RAMP_SLOW; in cs42l42_handle_device_data()
2102 cs42l42->hs_bias_ramp_time = CS42L42_HSBIAS_RAMP_TIME2; in cs42l42_handle_device_data()
2105 cs42l42->hs_bias_ramp_rate = CS42L42_HSBIAS_RAMP_SLOW; in cs42l42_handle_device_data()
2106 cs42l42->hs_bias_ramp_time = CS42L42_HSBIAS_RAMP_TIME2; in cs42l42_handle_device_data()
2109 regmap_update_bits(cs42l42->regmap, CS42L42_HS_BIAS_CTL, in cs42l42_handle_device_data()
2111 (cs42l42->hs_bias_ramp_rate << in cs42l42_handle_device_data()
2114 if (device_property_read_bool(dev, "cirrus,hs-bias-sense-disable")) in cs42l42_handle_device_data()
2115 cs42l42->hs_bias_sense_en = 0; in cs42l42_handle_device_data()
2117 cs42l42->hs_bias_sense_en = 1; in cs42l42_handle_device_data()
2162 if (!cs42l42->init_done) in cs42l42_suspend()
2170 mutex_lock(&cs42l42->irq_lock); in cs42l42_suspend()
2171 cs42l42->suspended = true; in cs42l42_suspend()
2175 regmap_read(cs42l42->regmap, cs42l42_shutdown_seq[i].reg, &reg); in cs42l42_suspend()
2180 regmap_multi_reg_write(cs42l42->regmap, in cs42l42_suspend()
2185 mutex_unlock(&cs42l42->irq_lock); in cs42l42_suspend()
2187 /* Wait for power-down complete */ in cs42l42_suspend()
2189 ret = regmap_read_poll_timeout(cs42l42->regmap, in cs42l42_suspend()
2198 regmap_update_bits(cs42l42->regmap, CS42L42_PWR_CTL2, in cs42l42_suspend()
2202 regcache_cache_only(cs42l42->regmap, true); in cs42l42_suspend()
2203 gpiod_set_value_cansleep(cs42l42->reset_gpio, 0); in cs42l42_suspend()
2204 regulator_bulk_disable(ARRAY_SIZE(cs42l42->supplies), cs42l42->supplies); in cs42l42_suspend()
2208 regmap_write(cs42l42->regmap, cs42l42_shutdown_seq[i].reg, save_regs[i]); in cs42l42_suspend()
2211 regcache_drop_region(cs42l42->regmap, CS42L42_PAGE_REGISTER, CS42L42_PAGE_REGISTER); in cs42l42_suspend()
2225 if (!cs42l42->init_done) in cs42l42_resume()
2229 * If jack was unplugged and re-plugged during suspend it could in cs42l42_resume()
2230 * have changed type but the tip-sense state hasn't changed. in cs42l42_resume()
2231 * Force a plugged state to be re-evaluated. in cs42l42_resume()
2233 if (cs42l42->plug_state != CS42L42_TS_UNPLUG) in cs42l42_resume()
2234 cs42l42->plug_state = CS42L42_TS_TRANS; in cs42l42_resume()
2236 ret = regulator_bulk_enable(ARRAY_SIZE(cs42l42->supplies), cs42l42->supplies); in cs42l42_resume()
2242 gpiod_set_value_cansleep(cs42l42->reset_gpio, 1); in cs42l42_resume()
2255 regcache_cache_only(cs42l42->regmap, false); in cs42l42_resume_restore()
2256 regcache_mark_dirty(cs42l42->regmap); in cs42l42_resume_restore()
2258 mutex_lock(&cs42l42->irq_lock); in cs42l42_resume_restore()
2260 regcache_sync_region(cs42l42->regmap, CS42L42_MIC_DET_CTL1, CS42L42_MIC_DET_CTL1); in cs42l42_resume_restore()
2261 regcache_sync(cs42l42->regmap); in cs42l42_resume_restore()
2263 cs42l42->suspended = false; in cs42l42_resume_restore()
2264 mutex_unlock(&cs42l42->irq_lock); in cs42l42_resume_restore()
2289 dev_set_drvdata(cs42l42->dev, cs42l42); in cs42l42_common_probe()
2290 mutex_init(&cs42l42->irq_lock); in cs42l42_common_probe()
2292 BUILD_BUG_ON(ARRAY_SIZE(cs42l42_supply_names) != ARRAY_SIZE(cs42l42->supplies)); in cs42l42_common_probe()
2293 for (i = 0; i < ARRAY_SIZE(cs42l42->supplies); i++) in cs42l42_common_probe()
2294 cs42l42->supplies[i].supply = cs42l42_supply_names[i]; in cs42l42_common_probe()
2296 ret = devm_regulator_bulk_get(cs42l42->dev, in cs42l42_common_probe()
2297 ARRAY_SIZE(cs42l42->supplies), in cs42l42_common_probe()
2298 cs42l42->supplies); in cs42l42_common_probe()
2300 dev_err(cs42l42->dev, in cs42l42_common_probe()
2305 ret = regulator_bulk_enable(ARRAY_SIZE(cs42l42->supplies), in cs42l42_common_probe()
2306 cs42l42->supplies); in cs42l42_common_probe()
2308 dev_err(cs42l42->dev, in cs42l42_common_probe()
2314 cs42l42->reset_gpio = devm_gpiod_get_optional(cs42l42->dev, in cs42l42_common_probe()
2316 if (IS_ERR(cs42l42->reset_gpio)) { in cs42l42_common_probe()
2317 ret = PTR_ERR(cs42l42->reset_gpio); in cs42l42_common_probe()
2321 if (cs42l42->reset_gpio) { in cs42l42_common_probe()
2322 dev_dbg(cs42l42->dev, "Found reset GPIO\n"); in cs42l42_common_probe()
2328 gpiod_set_value_cansleep(cs42l42->reset_gpio, 0); in cs42l42_common_probe()
2339 if (cs42l42->sdw_peripheral) in cs42l42_common_probe()
2340 cs42l42->sdw_waiting_first_unattach = true; in cs42l42_common_probe()
2342 gpiod_set_value_cansleep(cs42l42->reset_gpio, 1); in cs42l42_common_probe()
2347 if (cs42l42->irq) { in cs42l42_common_probe()
2348 ret = request_threaded_irq(cs42l42->irq, in cs42l42_common_probe()
2353 dev_err_probe(cs42l42->dev, ret, in cs42l42_common_probe()
2360 ret = devm_snd_soc_register_component(cs42l42->dev, component_drv, dai, 1); in cs42l42_common_probe()
2367 if (cs42l42->irq) in cs42l42_common_probe()
2368 free_irq(cs42l42->irq, cs42l42); in cs42l42_common_probe()
2371 gpiod_set_value_cansleep(cs42l42->reset_gpio, 0); in cs42l42_common_probe()
2373 regulator_bulk_disable(ARRAY_SIZE(cs42l42->supplies), cs42l42->supplies); in cs42l42_common_probe()
2385 devid = cirrus_read_device_id(cs42l42->regmap, CS42L42_DEVID_AB); in cs42l42_init()
2388 dev_err(cs42l42->dev, "Failed to read device ID: %d\n", ret); in cs42l42_init()
2392 if (devid != cs42l42->devid) { in cs42l42_init()
2393 ret = -ENODEV; in cs42l42_init()
2394 dev_err(cs42l42->dev, in cs42l42_init()
2396 cs42l42->devid & 0xff, devid, cs42l42->devid); in cs42l42_init()
2400 ret = regmap_read(cs42l42->regmap, CS42L42_REVID, &reg); in cs42l42_init()
2402 dev_err(cs42l42->dev, "Get Revision ID failed\n"); in cs42l42_init()
2406 dev_info(cs42l42->dev, in cs42l42_init()
2408 cs42l42->devid & 0xff, reg & 0xFF); in cs42l42_init()
2411 regmap_update_bits(cs42l42->regmap, CS42L42_PWR_CTL1, in cs42l42_init()
2427 ret = cs42l42_handle_device_data(cs42l42->dev, cs42l42); in cs42l42_init()
2432 * SRC power is linked to ASP power so doesn't work in Soundwire mode. in cs42l42_init()
2433 * Override it and use DAPM to control SRC power for Soundwire. in cs42l42_init()
2435 if (cs42l42->sdw_peripheral) { in cs42l42_init()
2436 regmap_update_bits(cs42l42->regmap, CS42L42_PWR_CTL2, in cs42l42_init()
2450 cs42l42->init_done = true; in cs42l42_init()
2458 regmap_write(cs42l42->regmap, CS42L42_CODEC_INT_MASK, 0xff); in cs42l42_init()
2459 regmap_write(cs42l42->regmap, CS42L42_TSRS_PLUG_INT_MASK, 0xff); in cs42l42_init()
2460 regmap_write(cs42l42->regmap, CS42L42_PWR_CTL1, 0xff); in cs42l42_init()
2463 if (cs42l42->irq) in cs42l42_init()
2464 free_irq(cs42l42->irq, cs42l42); in cs42l42_init()
2466 gpiod_set_value_cansleep(cs42l42->reset_gpio, 0); in cs42l42_init()
2467 regulator_bulk_disable(ARRAY_SIZE(cs42l42->supplies), in cs42l42_init()
2468 cs42l42->supplies); in cs42l42_init()
2475 if (cs42l42->irq) in cs42l42_common_remove()
2476 free_irq(cs42l42->irq, cs42l42); in cs42l42_common_remove()
2482 if (cs42l42->init_done) { in cs42l42_common_remove()
2483 regmap_write(cs42l42->regmap, CS42L42_CODEC_INT_MASK, 0xff); in cs42l42_common_remove()
2484 regmap_write(cs42l42->regmap, CS42L42_TSRS_PLUG_INT_MASK, 0xff); in cs42l42_common_remove()
2485 regmap_write(cs42l42->regmap, CS42L42_PWR_CTL1, 0xff); in cs42l42_common_remove()
2488 gpiod_set_value_cansleep(cs42l42->reset_gpio, 0); in cs42l42_common_remove()
2489 regulator_bulk_disable(ARRAY_SIZE(cs42l42->supplies), cs42l42->supplies); in cs42l42_common_remove()