Lines Matching +full:fsync +full:- +full:active +full:- +full:low

1 // SPDX-License-Identifier: GPL-2.0-only
3 * cs42l42.c -- CS42L42 ALSA SoC audio driver
29 #include <sound/soc-dapm.h>
32 #include <dt-bindings/sound/cs42l42.h>
400 static DECLARE_TLV_DB_SCALE(adc_tlv, -9700, 100, true);
401 static DECLARE_TLV_DB_SCALE(mixer_tlv, -6300, 100, true);
410 switch (ucontrol->value.integer.value[0]) { in cs42l42_slow_start_put()
418 return -EINVAL; in cs42l42_slow_start_put()
452 SOC_SINGLE_S8_TLV("ADC Volume", CS42L42_ADC_VOLUME, -97, 12, adc_tlv),
479 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in cs42l42_hp_adc_ev()
484 cs42l42->hp_adc_up_pending = true; in cs42l42_hp_adc_ev()
487 /* Only need one delay if HP and ADC are both powering-up */ in cs42l42_hp_adc_ev()
488 if (cs42l42->hp_adc_up_pending) { in cs42l42_hp_adc_ev()
491 cs42l42->hp_adc_up_pending = false; in cs42l42_hp_adc_ev()
568 mutex_lock(&cs42l42->irq_lock); in cs42l42_set_jack()
569 cs42l42->jack = jk; in cs42l42_set_jack()
572 switch (cs42l42->hs_type) { in cs42l42_set_jack()
584 mutex_unlock(&cs42l42->irq_lock); in cs42l42_set_jack()
634 * Table 4-5 from the Datasheet
671 if (cs42l42->stream_use) { in cs42l42_pll_config()
672 if (pll_ratio_table[cs42l42->pll_config].sclk == clk) in cs42l42_pll_config()
675 return -EBUSY; in cs42l42_pll_config()
684 cs42l42->pll_config = i; in cs42l42_pll_config()
700 /* Configure PLL per table 4-5 */ in cs42l42_pll_config()
749 return -EINVAL; in cs42l42_pll_config()
759 if (cs42l42->stream_use) in cs42l42_src_config()
790 u32 fsync = sclk / sample_rate; in cs42l42_asp_config() local
793 if (((fsync * sample_rate) != sclk) || ((fsync % 2) != 0)) { in cs42l42_asp_config()
794 dev_err(component->dev, in cs42l42_asp_config()
798 return -EINVAL; in cs42l42_asp_config()
804 CS42L42_FRAC0_VAL(fsync - 1) << in cs42l42_asp_config()
809 CS42L42_FRAC1_VAL(fsync - 1) << in cs42l42_asp_config()
812 fsync = fsync / 2; in cs42l42_asp_config()
816 CS42L42_FRAC0_VAL(fsync - 1) << in cs42l42_asp_config()
821 CS42L42_FRAC1_VAL(fsync - 1) << in cs42l42_asp_config()
829 struct snd_soc_component *component = codec_dai->component; in cs42l42_set_dai_fmt()
842 return -EINVAL; in cs42l42_set_dai_fmt()
862 return -EINVAL; in cs42l42_set_dai_fmt()
891 struct snd_soc_component *component = dai->component; in cs42l42_dai_startup()
895 * Sample rates < 44.1 kHz would produce an out-of-range SCLK with in cs42l42_dai_startup()
899 if (cs42l42->sclk) in cs42l42_dai_startup()
903 return snd_pcm_hw_constraint_minmax(substream->runtime, in cs42l42_dai_startup()
912 struct snd_soc_component *component = dai->component; in cs42l42_pcm_hw_params()
915 unsigned int width = (params_width(params) / 8) - 1; in cs42l42_pcm_hw_params()
922 if (cs42l42->bclk_ratio) { in cs42l42_pcm_hw_params()
923 /* machine driver has set the BCLK/samp-rate ratio */ in cs42l42_pcm_hw_params()
924 bclk = cs42l42->bclk_ratio * params_rate(params); in cs42l42_pcm_hw_params()
925 } else if (cs42l42->sclk) { in cs42l42_pcm_hw_params()
927 bclk = cs42l42->sclk; in cs42l42_pcm_hw_params()
930 * Assume 24-bit samples are in 32-bit slots, to prevent SCLK being in cs42l42_pcm_hw_params()
940 switch (substream->stream) { in cs42l42_pcm_hw_params()
953 /* channel 1 on low LRCLK */ in cs42l42_pcm_hw_params()
963 /* Channel B comes from the last active channel */ in cs42l42_pcm_hw_params()
966 (channels - 1) << CS42L42_SP_RX_CHB_SEL_SHIFT); in cs42l42_pcm_hw_params()
994 struct snd_soc_component *component = dai->component; in cs42l42_set_sysclk()
999 cs42l42->sclk = 0; in cs42l42_set_sysclk()
1005 cs42l42->sclk = freq; in cs42l42_set_sysclk()
1010 dev_err(component->dev, "SCLK %u not supported\n", freq); in cs42l42_set_sysclk()
1012 return -EINVAL; in cs42l42_set_sysclk()
1018 struct snd_soc_component *component = dai->component; in cs42l42_set_bclk_ratio()
1021 cs42l42->bclk_ratio = bclk_ratio; in cs42l42_set_bclk_ratio()
1028 struct snd_soc_component *component = dai->component; in cs42l42_mute_stream()
1042 cs42l42->stream_use &= ~(1 << stream); in cs42l42_mute_stream()
1043 if (!cs42l42->stream_use) { in cs42l42_mute_stream()
1049 regmap_multi_reg_write(cs42l42->regmap, cs42l42_to_osc_seq, in cs42l42_mute_stream()
1063 if (!cs42l42->stream_use) { in cs42l42_mute_stream()
1068 * DAPM widgets power-up before stream unmute so at least in cs42l42_mute_stream()
1070 * powered-up. in cs42l42_mute_stream()
1072 if (pll_ratio_table[cs42l42->pll_config].mclk_src_sel) { in cs42l42_mute_stream()
1076 if (pll_ratio_table[cs42l42->pll_config].n > 1) { in cs42l42_mute_stream()
1079 regval = pll_ratio_table[cs42l42->pll_config].pll_divout; in cs42l42_mute_stream()
1086 ret = regmap_read_poll_timeout(cs42l42->regmap, in cs42l42_mute_stream()
1093 dev_warn(component->dev, "PLL failed to lock: %d\n", ret); in cs42l42_mute_stream()
1103 regmap_multi_reg_write(cs42l42->regmap, cs42l42_to_sclk_seq, in cs42l42_mute_stream()
1106 cs42l42->stream_use |= 1 << stream; in cs42l42_mute_stream()
1109 /* Un-mute the headphone */ in cs42l42_mute_stream()
1163 /* Set hs detect to manual, active mode */ in cs42l42_manual_hs_type_detect()
1164 regmap_update_bits(cs42l42->regmap, in cs42l42_manual_hs_type_detect()
1176 regmap_update_bits(cs42l42->regmap, in cs42l42_manual_hs_type_detect()
1184 regmap_write(cs42l42->regmap, CS42L42_HS_SWITCH_CTL, CS42L42_HSDET_SW_COMP1); in cs42l42_manual_hs_type_detect()
1188 regmap_read(cs42l42->regmap, CS42L42_HS_DET_STATUS, &hs_det_status); in cs42l42_manual_hs_type_detect()
1196 regmap_write(cs42l42->regmap, CS42L42_HS_SWITCH_CTL, CS42L42_HSDET_SW_COMP2); in cs42l42_manual_hs_type_detect()
1200 regmap_read(cs42l42->regmap, CS42L42_HS_DET_STATUS, &hs_det_status); in cs42l42_manual_hs_type_detect()
1210 cs42l42->hs_type = CS42L42_PLUG_CTIA; in cs42l42_manual_hs_type_detect()
1214 cs42l42->hs_type = CS42L42_PLUG_OMTP; in cs42l42_manual_hs_type_detect()
1221 cs42l42->hs_type = CS42L42_PLUG_CTIA; in cs42l42_manual_hs_type_detect()
1225 cs42l42->hs_type = CS42L42_PLUG_OMTP; in cs42l42_manual_hs_type_detect()
1230 cs42l42->hs_type = CS42L42_PLUG_HEADPHONE; in cs42l42_manual_hs_type_detect()
1237 regmap_write(cs42l42->regmap, CS42L42_HS_SWITCH_CTL, hs_det_sw); in cs42l42_manual_hs_type_detect()
1240 regmap_update_bits(cs42l42->regmap, in cs42l42_manual_hs_type_detect()
1252 regmap_update_bits(cs42l42->regmap, in cs42l42_manual_hs_type_detect()
1266 regmap_read(cs42l42->regmap, CS42L42_HS_DET_STATUS, &hs_det_status); in cs42l42_process_hs_type_detect()
1269 regmap_update_bits(cs42l42->regmap, in cs42l42_process_hs_type_detect()
1277 cs42l42->hs_type = (hs_det_status & CS42L42_HSDET_TYPE_MASK) >> in cs42l42_process_hs_type_detect()
1281 regmap_update_bits(cs42l42->regmap, in cs42l42_process_hs_type_detect()
1293 * We Re-Run with Manual Detection if the original detection was invalid or headphones, in cs42l42_process_hs_type_detect()
1296 if (cs42l42->hs_type == CS42L42_PLUG_INVALID || in cs42l42_process_hs_type_detect()
1297 cs42l42->hs_type == CS42L42_PLUG_HEADPHONE) { in cs42l42_process_hs_type_detect()
1298 dev_dbg(cs42l42->dev, "Running Manual Detection Fallback\n"); in cs42l42_process_hs_type_detect()
1303 if ((cs42l42->hs_type == CS42L42_PLUG_CTIA) || in cs42l42_process_hs_type_detect()
1304 (cs42l42->hs_type == CS42L42_PLUG_OMTP)) { in cs42l42_process_hs_type_detect()
1306 regmap_update_bits(cs42l42->regmap, in cs42l42_process_hs_type_detect()
1318 regmap_update_bits(cs42l42->regmap, in cs42l42_process_hs_type_detect()
1325 (cs42l42->bias_thresholds[0] << in cs42l42_process_hs_type_detect()
1329 regmap_update_bits(cs42l42->regmap, in cs42l42_process_hs_type_detect()
1335 (cs42l42->hs_bias_sense_en << CS42L42_HSBIAS_SENSE_EN_SHIFT) | in cs42l42_process_hs_type_detect()
1341 regmap_update_bits(cs42l42->regmap, in cs42l42_process_hs_type_detect()
1348 msleep(cs42l42->btn_det_init_dbnce); in cs42l42_process_hs_type_detect()
1351 regmap_read(cs42l42->regmap, CS42L42_DET_INT_STATUS2, in cs42l42_process_hs_type_detect()
1355 regmap_update_bits(cs42l42->regmap, in cs42l42_process_hs_type_detect()
1369 regmap_update_bits(cs42l42->regmap, in cs42l42_process_hs_type_detect()
1377 regmap_update_bits(cs42l42->regmap, in cs42l42_process_hs_type_detect()
1391 regmap_update_bits(cs42l42->regmap, in cs42l42_process_hs_type_detect()
1402 regmap_update_bits(cs42l42->regmap, in cs42l42_init_hs_type_detect()
1410 regmap_update_bits(cs42l42->regmap, in cs42l42_init_hs_type_detect()
1418 regmap_update_bits(cs42l42->regmap, in cs42l42_init_hs_type_detect()
1430 regmap_update_bits(cs42l42->regmap, in cs42l42_init_hs_type_detect()
1441 regmap_update_bits(cs42l42->regmap, in cs42l42_init_hs_type_detect()
1455 regmap_update_bits(cs42l42->regmap, in cs42l42_init_hs_type_detect()
1463 msleep(cs42l42->hs_bias_ramp_time); in cs42l42_init_hs_type_detect()
1466 regmap_update_bits(cs42l42->regmap, in cs42l42_init_hs_type_detect()
1474 regmap_update_bits(cs42l42->regmap, in cs42l42_init_hs_type_detect()
1489 regmap_update_bits(cs42l42->regmap, in cs42l42_cancel_hs_type_detect()
1503 regmap_update_bits(cs42l42->regmap, in cs42l42_cancel_hs_type_detect()
1511 regmap_update_bits(cs42l42->regmap, in cs42l42_cancel_hs_type_detect()
1523 regmap_update_bits(cs42l42->regmap, in cs42l42_cancel_hs_type_detect()
1541 regmap_update_bits(cs42l42->regmap, in cs42l42_handle_button_press()
1554 usleep_range(cs42l42->btn_det_event_dbnce * 1000, in cs42l42_handle_button_press()
1555 cs42l42->btn_det_event_dbnce * 2000); in cs42l42_handle_button_press()
1561 regmap_update_bits(cs42l42->regmap, in cs42l42_handle_button_press()
1568 (cs42l42->bias_thresholds[bias_level] << in cs42l42_handle_button_press()
1571 regmap_read(cs42l42->regmap, CS42L42_DET_STATUS2, in cs42l42_handle_button_press()
1579 dev_dbg(cs42l42->dev, "Function C button press\n"); in cs42l42_handle_button_press()
1583 dev_dbg(cs42l42->dev, "Function B button press\n"); in cs42l42_handle_button_press()
1587 dev_dbg(cs42l42->dev, "Function D button press\n"); in cs42l42_handle_button_press()
1591 dev_dbg(cs42l42->dev, "Function A button press\n"); in cs42l42_handle_button_press()
1599 regmap_update_bits(cs42l42->regmap, in cs42l42_handle_button_press()
1606 (cs42l42->bias_thresholds[0] << CS42L42_HS_DET_LEVEL_SHIFT)); in cs42l42_handle_button_press()
1609 regmap_read(cs42l42->regmap, CS42L42_DET_INT_STATUS2, in cs42l42_handle_button_press()
1613 regmap_update_bits(cs42l42->regmap, in cs42l42_handle_button_press()
1671 pm_runtime_get_sync(cs42l42->dev); in cs42l42_irq_thread()
1672 mutex_lock(&cs42l42->irq_lock); in cs42l42_irq_thread()
1673 if (cs42l42->suspended || !cs42l42->init_done) { in cs42l42_irq_thread()
1674 mutex_unlock(&cs42l42->irq_lock); in cs42l42_irq_thread()
1675 pm_runtime_put_autosuspend(cs42l42->dev); in cs42l42_irq_thread()
1681 regmap_read(cs42l42->regmap, irq_params_table[i].status_addr, in cs42l42_irq_thread()
1683 regmap_read(cs42l42->regmap, irq_params_table[i].mask_addr, in cs42l42_irq_thread()
1701 * Check auto-detect status. Don't assume a previous unplug event has in cs42l42_irq_thread()
1708 switch (cs42l42->hs_type) { in cs42l42_irq_thread()
1711 snd_soc_jack_report(cs42l42->jack, SND_JACK_HEADSET, in cs42l42_irq_thread()
1717 snd_soc_jack_report(cs42l42->jack, SND_JACK_HEADPHONE, in cs42l42_irq_thread()
1725 dev_dbg(cs42l42->dev, "Auto detect done (%d)\n", cs42l42->hs_type); in cs42l42_irq_thread()
1733 if (cs42l42->plug_state != CS42L42_TS_PLUG) { in cs42l42_irq_thread()
1734 cs42l42->plug_state = CS42L42_TS_PLUG; in cs42l42_irq_thread()
1740 if (cs42l42->plug_state != CS42L42_TS_UNPLUG) { in cs42l42_irq_thread()
1741 cs42l42->plug_state = CS42L42_TS_UNPLUG; in cs42l42_irq_thread()
1744 snd_soc_jack_report(cs42l42->jack, 0, in cs42l42_irq_thread()
1749 dev_dbg(cs42l42->dev, "Unplug event\n"); in cs42l42_irq_thread()
1754 cs42l42->plug_state = CS42L42_TS_TRANS; in cs42l42_irq_thread()
1759 if (cs42l42->plug_state == CS42L42_TS_PLUG && ((~masks[7]) & irq_params_table[7].mask)) { in cs42l42_irq_thread()
1764 dev_dbg(cs42l42->dev, "Button released\n"); in cs42l42_irq_thread()
1765 snd_soc_jack_report(cs42l42->jack, 0, in cs42l42_irq_thread()
1769 snd_soc_jack_report(cs42l42->jack, in cs42l42_irq_thread()
1777 mutex_unlock(&cs42l42->irq_lock); in cs42l42_irq_thread()
1778 pm_runtime_mark_last_busy(cs42l42->dev); in cs42l42_irq_thread()
1779 pm_runtime_put_autosuspend(cs42l42->dev); in cs42l42_irq_thread()
1787 regmap_update_bits(cs42l42->regmap, CS42L42_ADC_OVFL_INT_MASK, in cs42l42_set_interrupt_masks()
1791 regmap_update_bits(cs42l42->regmap, CS42L42_MIXER_INT_MASK, in cs42l42_set_interrupt_masks()
1801 regmap_update_bits(cs42l42->regmap, CS42L42_SRC_INT_MASK, in cs42l42_set_interrupt_masks()
1811 regmap_update_bits(cs42l42->regmap, CS42L42_ASP_RX_INT_MASK, in cs42l42_set_interrupt_masks()
1823 regmap_update_bits(cs42l42->regmap, CS42L42_ASP_TX_INT_MASK, in cs42l42_set_interrupt_masks()
1833 regmap_update_bits(cs42l42->regmap, CS42L42_CODEC_INT_MASK, in cs42l42_set_interrupt_masks()
1839 regmap_update_bits(cs42l42->regmap, CS42L42_SRCPL_INT_MASK, in cs42l42_set_interrupt_masks()
1849 regmap_update_bits(cs42l42->regmap, CS42L42_DET_INT1_MASK, in cs42l42_set_interrupt_masks()
1857 regmap_update_bits(cs42l42->regmap, CS42L42_DET_INT2_MASK, in cs42l42_set_interrupt_masks()
1869 regmap_update_bits(cs42l42->regmap, CS42L42_VPMON_INT_MASK, in cs42l42_set_interrupt_masks()
1873 regmap_update_bits(cs42l42->regmap, CS42L42_PLL_LOCK_INT_MASK, in cs42l42_set_interrupt_masks()
1877 regmap_update_bits(cs42l42->regmap, CS42L42_TSRS_PLUG_INT_MASK, in cs42l42_set_interrupt_masks()
1892 cs42l42->hs_type = CS42L42_PLUG_INVALID; in cs42l42_setup_hs_type_detect()
1898 regmap_update_bits(cs42l42->regmap, CS42L42_MISC_DET_CTL, in cs42l42_setup_hs_type_detect()
1902 regmap_update_bits(cs42l42->regmap, CS42L42_MIC_DET_CTL1, in cs42l42_setup_hs_type_detect()
1908 (cs42l42->bias_thresholds[0] << in cs42l42_setup_hs_type_detect()
1911 /* Remove ground noise-suppression clamps */ in cs42l42_setup_hs_type_detect()
1912 regmap_update_bits(cs42l42->regmap, in cs42l42_setup_hs_type_detect()
1918 regmap_update_bits(cs42l42->regmap, CS42L42_TSENSE_CTL, in cs42l42_setup_hs_type_detect()
1921 regmap_update_bits(cs42l42->regmap, CS42L42_TIPSENSE_CTL, in cs42l42_setup_hs_type_detect()
1926 (!cs42l42->ts_inv << CS42L42_TIP_SENSE_INV_SHIFT) | in cs42l42_setup_hs_type_detect()
1930 regmap_read(cs42l42->regmap, in cs42l42_setup_hs_type_detect()
1933 cs42l42->plug_state = (((char) reg) & in cs42l42_setup_hs_type_detect()
1953 ret = device_property_read_u32(dev, "cirrus,ts-inv", &val); in cs42l42_handle_device_data()
1958 cs42l42->ts_inv = val; in cs42l42_handle_device_data()
1962 "Wrong cirrus,ts-inv DT value %d\n", in cs42l42_handle_device_data()
1964 cs42l42->ts_inv = CS42L42_TS_INV_DIS; in cs42l42_handle_device_data()
1967 cs42l42->ts_inv = CS42L42_TS_INV_DIS; in cs42l42_handle_device_data()
1970 ret = device_property_read_u32(dev, "cirrus,ts-dbnc-rise", &val); in cs42l42_handle_device_data()
1981 cs42l42->ts_dbnc_rise = val; in cs42l42_handle_device_data()
1985 "Wrong cirrus,ts-dbnc-rise DT value %d\n", in cs42l42_handle_device_data()
1987 cs42l42->ts_dbnc_rise = CS42L42_TS_DBNCE_1000; in cs42l42_handle_device_data()
1990 cs42l42->ts_dbnc_rise = CS42L42_TS_DBNCE_1000; in cs42l42_handle_device_data()
1993 regmap_update_bits(cs42l42->regmap, CS42L42_TSENSE_CTL, in cs42l42_handle_device_data()
1995 (cs42l42->ts_dbnc_rise << in cs42l42_handle_device_data()
1998 ret = device_property_read_u32(dev, "cirrus,ts-dbnc-fall", &val); in cs42l42_handle_device_data()
2009 cs42l42->ts_dbnc_fall = val; in cs42l42_handle_device_data()
2013 "Wrong cirrus,ts-dbnc-fall DT value %d\n", in cs42l42_handle_device_data()
2015 cs42l42->ts_dbnc_fall = CS42L42_TS_DBNCE_0; in cs42l42_handle_device_data()
2018 cs42l42->ts_dbnc_fall = CS42L42_TS_DBNCE_0; in cs42l42_handle_device_data()
2021 regmap_update_bits(cs42l42->regmap, CS42L42_TSENSE_CTL, in cs42l42_handle_device_data()
2023 (cs42l42->ts_dbnc_fall << in cs42l42_handle_device_data()
2026 ret = device_property_read_u32(dev, "cirrus,btn-det-init-dbnce", &val); in cs42l42_handle_device_data()
2029 cs42l42->btn_det_init_dbnce = val; in cs42l42_handle_device_data()
2032 "Wrong cirrus,btn-det-init-dbnce DT value %d\n", in cs42l42_handle_device_data()
2034 cs42l42->btn_det_init_dbnce = in cs42l42_handle_device_data()
2038 cs42l42->btn_det_init_dbnce = in cs42l42_handle_device_data()
2042 ret = device_property_read_u32(dev, "cirrus,btn-det-event-dbnce", &val); in cs42l42_handle_device_data()
2045 cs42l42->btn_det_event_dbnce = val; in cs42l42_handle_device_data()
2048 "Wrong cirrus,btn-det-event-dbnce DT value %d\n", val); in cs42l42_handle_device_data()
2049 cs42l42->btn_det_event_dbnce = in cs42l42_handle_device_data()
2053 cs42l42->btn_det_event_dbnce = in cs42l42_handle_device_data()
2057 ret = device_property_read_u32_array(dev, "cirrus,bias-lvls", in cs42l42_handle_device_data()
2062 cs42l42->bias_thresholds[i] = thresholds[i]; in cs42l42_handle_device_data()
2065 "Wrong cirrus,bias-lvls[%d] DT value %d\n", i, in cs42l42_handle_device_data()
2067 cs42l42->bias_thresholds[i] = threshold_defaults[i]; in cs42l42_handle_device_data()
2072 cs42l42->bias_thresholds[i] = threshold_defaults[i]; in cs42l42_handle_device_data()
2075 ret = device_property_read_u32(dev, "cirrus,hs-bias-ramp-rate", &val); in cs42l42_handle_device_data()
2079 cs42l42->hs_bias_ramp_rate = val; in cs42l42_handle_device_data()
2080 cs42l42->hs_bias_ramp_time = CS42L42_HSBIAS_RAMP_TIME0; in cs42l42_handle_device_data()
2083 cs42l42->hs_bias_ramp_rate = val; in cs42l42_handle_device_data()
2084 cs42l42->hs_bias_ramp_time = CS42L42_HSBIAS_RAMP_TIME1; in cs42l42_handle_device_data()
2087 cs42l42->hs_bias_ramp_rate = val; in cs42l42_handle_device_data()
2088 cs42l42->hs_bias_ramp_time = CS42L42_HSBIAS_RAMP_TIME2; in cs42l42_handle_device_data()
2091 cs42l42->hs_bias_ramp_rate = val; in cs42l42_handle_device_data()
2092 cs42l42->hs_bias_ramp_time = CS42L42_HSBIAS_RAMP_TIME3; in cs42l42_handle_device_data()
2096 "Wrong cirrus,hs-bias-ramp-rate DT value %d\n", in cs42l42_handle_device_data()
2098 cs42l42->hs_bias_ramp_rate = CS42L42_HSBIAS_RAMP_SLOW; in cs42l42_handle_device_data()
2099 cs42l42->hs_bias_ramp_time = CS42L42_HSBIAS_RAMP_TIME2; in cs42l42_handle_device_data()
2102 cs42l42->hs_bias_ramp_rate = CS42L42_HSBIAS_RAMP_SLOW; in cs42l42_handle_device_data()
2103 cs42l42->hs_bias_ramp_time = CS42L42_HSBIAS_RAMP_TIME2; in cs42l42_handle_device_data()
2106 regmap_update_bits(cs42l42->regmap, CS42L42_HS_BIAS_CTL, in cs42l42_handle_device_data()
2108 (cs42l42->hs_bias_ramp_rate << in cs42l42_handle_device_data()
2111 if (device_property_read_bool(dev, "cirrus,hs-bias-sense-disable")) in cs42l42_handle_device_data()
2112 cs42l42->hs_bias_sense_en = 0; in cs42l42_handle_device_data()
2114 cs42l42->hs_bias_sense_en = 1; in cs42l42_handle_device_data()
2159 if (!cs42l42->init_done) in cs42l42_suspend()
2167 mutex_lock(&cs42l42->irq_lock); in cs42l42_suspend()
2168 cs42l42->suspended = true; in cs42l42_suspend()
2172 regmap_read(cs42l42->regmap, cs42l42_shutdown_seq[i].reg, &reg); in cs42l42_suspend()
2177 regmap_multi_reg_write(cs42l42->regmap, in cs42l42_suspend()
2182 mutex_unlock(&cs42l42->irq_lock); in cs42l42_suspend()
2184 /* Wait for power-down complete */ in cs42l42_suspend()
2186 ret = regmap_read_poll_timeout(cs42l42->regmap, in cs42l42_suspend()
2195 regmap_update_bits(cs42l42->regmap, CS42L42_PWR_CTL2, in cs42l42_suspend()
2198 regcache_cache_only(cs42l42->regmap, true); in cs42l42_suspend()
2199 gpiod_set_value_cansleep(cs42l42->reset_gpio, 0); in cs42l42_suspend()
2200 regulator_bulk_disable(ARRAY_SIZE(cs42l42->supplies), cs42l42->supplies); in cs42l42_suspend()
2204 regmap_write(cs42l42->regmap, cs42l42_shutdown_seq[i].reg, save_regs[i]); in cs42l42_suspend()
2207 regcache_drop_region(cs42l42->regmap, CS42L42_PAGE_REGISTER, CS42L42_PAGE_REGISTER); in cs42l42_suspend()
2221 if (!cs42l42->init_done) in cs42l42_resume()
2225 * If jack was unplugged and re-plugged during suspend it could in cs42l42_resume()
2226 * have changed type but the tip-sense state hasn't changed. in cs42l42_resume()
2227 * Force a plugged state to be re-evaluated. in cs42l42_resume()
2229 if (cs42l42->plug_state != CS42L42_TS_UNPLUG) in cs42l42_resume()
2230 cs42l42->plug_state = CS42L42_TS_TRANS; in cs42l42_resume()
2232 ret = regulator_bulk_enable(ARRAY_SIZE(cs42l42->supplies), cs42l42->supplies); in cs42l42_resume()
2238 gpiod_set_value_cansleep(cs42l42->reset_gpio, 1); in cs42l42_resume()
2251 regcache_cache_only(cs42l42->regmap, false); in cs42l42_resume_restore()
2252 regcache_mark_dirty(cs42l42->regmap); in cs42l42_resume_restore()
2254 mutex_lock(&cs42l42->irq_lock); in cs42l42_resume_restore()
2256 regcache_sync_region(cs42l42->regmap, CS42L42_MIC_DET_CTL1, CS42L42_MIC_DET_CTL1); in cs42l42_resume_restore()
2257 regcache_sync(cs42l42->regmap); in cs42l42_resume_restore()
2259 cs42l42->suspended = false; in cs42l42_resume_restore()
2260 mutex_unlock(&cs42l42->irq_lock); in cs42l42_resume_restore()
2285 dev_set_drvdata(cs42l42->dev, cs42l42); in cs42l42_common_probe()
2286 mutex_init(&cs42l42->irq_lock); in cs42l42_common_probe()
2288 BUILD_BUG_ON(ARRAY_SIZE(cs42l42_supply_names) != ARRAY_SIZE(cs42l42->supplies)); in cs42l42_common_probe()
2289 for (i = 0; i < ARRAY_SIZE(cs42l42->supplies); i++) in cs42l42_common_probe()
2290 cs42l42->supplies[i].supply = cs42l42_supply_names[i]; in cs42l42_common_probe()
2292 ret = devm_regulator_bulk_get(cs42l42->dev, in cs42l42_common_probe()
2293 ARRAY_SIZE(cs42l42->supplies), in cs42l42_common_probe()
2294 cs42l42->supplies); in cs42l42_common_probe()
2296 dev_err(cs42l42->dev, in cs42l42_common_probe()
2301 ret = regulator_bulk_enable(ARRAY_SIZE(cs42l42->supplies), in cs42l42_common_probe()
2302 cs42l42->supplies); in cs42l42_common_probe()
2304 dev_err(cs42l42->dev, in cs42l42_common_probe()
2310 cs42l42->reset_gpio = devm_gpiod_get_optional(cs42l42->dev, in cs42l42_common_probe()
2312 if (IS_ERR(cs42l42->reset_gpio)) { in cs42l42_common_probe()
2313 ret = PTR_ERR(cs42l42->reset_gpio); in cs42l42_common_probe()
2317 if (cs42l42->reset_gpio) { in cs42l42_common_probe()
2318 dev_dbg(cs42l42->dev, "Found reset GPIO\n"); in cs42l42_common_probe()
2322 * so ensure that we start with RESET low. in cs42l42_common_probe()
2324 gpiod_set_value_cansleep(cs42l42->reset_gpio, 0); in cs42l42_common_probe()
2335 if (cs42l42->sdw_peripheral) in cs42l42_common_probe()
2336 cs42l42->sdw_waiting_first_unattach = true; in cs42l42_common_probe()
2338 gpiod_set_value_cansleep(cs42l42->reset_gpio, 1); in cs42l42_common_probe()
2343 if (cs42l42->irq) { in cs42l42_common_probe()
2344 ret = request_threaded_irq(cs42l42->irq, in cs42l42_common_probe()
2349 dev_err_probe(cs42l42->dev, ret, in cs42l42_common_probe()
2356 ret = devm_snd_soc_register_component(cs42l42->dev, component_drv, dai, 1); in cs42l42_common_probe()
2363 if (cs42l42->irq) in cs42l42_common_probe()
2364 free_irq(cs42l42->irq, cs42l42); in cs42l42_common_probe()
2367 gpiod_set_value_cansleep(cs42l42->reset_gpio, 0); in cs42l42_common_probe()
2369 regulator_bulk_disable(ARRAY_SIZE(cs42l42->supplies), cs42l42->supplies); in cs42l42_common_probe()
2381 devid = cirrus_read_device_id(cs42l42->regmap, CS42L42_DEVID_AB); in cs42l42_init()
2384 dev_err(cs42l42->dev, "Failed to read device ID: %d\n", ret); in cs42l42_init()
2388 if (devid != cs42l42->devid) { in cs42l42_init()
2389 ret = -ENODEV; in cs42l42_init()
2390 dev_err(cs42l42->dev, in cs42l42_init()
2392 cs42l42->devid & 0xff, devid, cs42l42->devid); in cs42l42_init()
2396 ret = regmap_read(cs42l42->regmap, CS42L42_REVID, &reg); in cs42l42_init()
2398 dev_err(cs42l42->dev, "Get Revision ID failed\n"); in cs42l42_init()
2402 dev_info(cs42l42->dev, in cs42l42_init()
2404 cs42l42->devid & 0xff, reg & 0xFF); in cs42l42_init()
2407 regmap_update_bits(cs42l42->regmap, CS42L42_PWR_CTL1, in cs42l42_init()
2423 ret = cs42l42_handle_device_data(cs42l42->dev, cs42l42); in cs42l42_init()
2431 if (cs42l42->sdw_peripheral) { in cs42l42_init()
2432 regmap_update_bits(cs42l42->regmap, CS42L42_PWR_CTL2, in cs42l42_init()
2446 cs42l42->init_done = true; in cs42l42_init()
2454 regmap_write(cs42l42->regmap, CS42L42_CODEC_INT_MASK, 0xff); in cs42l42_init()
2455 regmap_write(cs42l42->regmap, CS42L42_TSRS_PLUG_INT_MASK, 0xff); in cs42l42_init()
2456 regmap_write(cs42l42->regmap, CS42L42_PWR_CTL1, 0xff); in cs42l42_init()
2459 if (cs42l42->irq) in cs42l42_init()
2460 free_irq(cs42l42->irq, cs42l42); in cs42l42_init()
2462 gpiod_set_value_cansleep(cs42l42->reset_gpio, 0); in cs42l42_init()
2463 regulator_bulk_disable(ARRAY_SIZE(cs42l42->supplies), in cs42l42_init()
2464 cs42l42->supplies); in cs42l42_init()
2471 if (cs42l42->irq) in cs42l42_common_remove()
2472 free_irq(cs42l42->irq, cs42l42); in cs42l42_common_remove()
2478 if (cs42l42->init_done) { in cs42l42_common_remove()
2479 regmap_write(cs42l42->regmap, CS42L42_CODEC_INT_MASK, 0xff); in cs42l42_common_remove()
2480 regmap_write(cs42l42->regmap, CS42L42_TSRS_PLUG_INT_MASK, 0xff); in cs42l42_common_remove()
2481 regmap_write(cs42l42->regmap, CS42L42_PWR_CTL1, 0xff); in cs42l42_common_remove()
2484 gpiod_set_value_cansleep(cs42l42->reset_gpio, 0); in cs42l42_common_remove()
2485 regulator_bulk_disable(ARRAY_SIZE(cs42l42->supplies), cs42l42->supplies); in cs42l42_common_remove()