Lines Matching +full:debounce +full:- +full:insertion +full:- +full:ms

1 // SPDX-License-Identifier: GPL-2.0-only
35 static int quirk_override = -1;
37 MODULE_PARM_DESC(quirk, "Board-specific quirk override");
211 ret = down_timeout(&nau8824->jd_sem, timeout); in nau8824_sema_acquire()
213 dev_warn(nau8824->dev, "Acquire semaphore timeout\n"); in nau8824_sema_acquire()
215 ret = down_interruptible(&nau8824->jd_sem); in nau8824_sema_acquire()
217 dev_warn(nau8824->dev, "Acquire semaphore fail\n"); in nau8824_sema_acquire()
225 up(&nau8824->jd_sem); in nau8824_sema_release()
304 "Off", "NC", "u-law", "A-law" };
359 static const DECLARE_TLV_DB_MINMAX(hp_vol_tlv, -3000, 0);
361 static const DECLARE_TLV_DB_SCALE(dmic_vol_tlv, -12800, 50, 0);
431 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in nau8824_output_dac_event()
437 regmap_update_bits(nau8824->regmap, NAU8824_REG_ENABLE_LO, in nau8824_output_dac_event()
441 regmap_update_bits(nau8824->regmap, NAU8824_REG_ENABLE_LO, in nau8824_output_dac_event()
445 return -EINVAL; in nau8824_output_dac_event()
454 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in nau8824_spk_event()
459 regmap_update_bits(nau8824->regmap, in nau8824_spk_event()
464 regmap_update_bits(nau8824->regmap, in nau8824_spk_event()
469 return -EINVAL; in nau8824_spk_event()
478 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in nau8824_pump_event()
485 regmap_update_bits(nau8824->regmap, in nau8824_pump_event()
490 regmap_update_bits(nau8824->regmap, in nau8824_pump_event()
495 return -EINVAL; in nau8824_pump_event()
504 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in system_clock_control()
506 struct regmap *regmap = nau8824->regmap; in system_clock_control()
511 dev_dbg(nau8824->dev, "system clock control : POWER OFF\n"); in system_clock_control()
524 dev_dbg(nau8824->dev, "system clock control : POWER ON\n"); in system_clock_control()
563 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in dmic_clock_control()
572 if ((0x1 << (8 - src)) * nau8824->fs <= DMIC_CLK) in dmic_clock_control()
575 dev_dbg(nau8824->dev, "dmic src %d for mclk %d\n", src, nau8824->fs * 256); in dmic_clock_control()
576 regmap_update_bits(nau8824->regmap, NAU8824_REG_CLK_DIVIDER, in dmic_clock_control()
814 struct snd_soc_jack *jack = nau8824->jack; in nau8824_is_jack_inserted()
817 if (nau8824->irq && jack) in nau8824_is_jack_inserted()
818 insert = jack->status & SND_JACK_HEADPHONE; in nau8824_is_jack_inserted()
827 /* Reset the intrruption status from rightmost bit if the corres- in nau8824_int_status_clear_all()
841 struct snd_soc_dapm_context *dapm = nau8824->dapm; in nau8824_eject_jack()
842 struct regmap *regmap = nau8824->regmap; in nau8824_eject_jack()
851 /* Enable the insertion interruption, disable the ejection in nau8824_eject_jack()
852 * interruption, and then bypass de-bounce circuit. in nau8824_eject_jack()
866 if (dapm->bias_level < SND_SOC_BIAS_PREPARE) in nau8824_eject_jack()
874 struct snd_soc_dapm_context *dapm = nau8824->dapm; in nau8824_jdet_work()
875 struct regmap *regmap = nau8824->regmap; in nau8824_jdet_work()
886 dev_dbg(nau8824->dev, "SAR ADC data 0x%02x\n", adc_value); in nau8824_jdet_work()
897 snd_soc_jack_report(nau8824->jack, event, event_mask); in nau8824_jdet_work()
904 if (nau8824->resume_lock) { in nau8824_jdet_work()
906 nau8824->resume_lock = false; in nau8824_jdet_work()
912 struct regmap *regmap = nau8824->regmap; in nau8824_setup_auto_irq()
921 if (nau8824->dapm->bias_level < SND_SOC_BIAS_PREPARE) in nau8824_setup_auto_irq()
956 struct regmap *regmap = nau8824->regmap; in nau8824_interrupt()
960 dev_err(nau8824->dev, "failed to read irq status\n"); in nau8824_interrupt()
963 dev_dbg(nau8824->dev, "IRQ %x\n", active_irq); in nau8824_interrupt()
972 if (nau8824->resume_lock) { in nau8824_interrupt()
974 nau8824->resume_lock = false; in nau8824_interrupt()
976 cancel_work_sync(&nau8824->jdet_work); in nau8824_interrupt()
987 dev_dbg(nau8824->dev, "button %x pressed\n", event); in nau8824_interrupt()
994 /* Turn off insertion interruption at manual mode */ in nau8824_interrupt()
1003 cancel_work_sync(&nau8824->jdet_work); in nau8824_interrupt()
1004 schedule_work(&nau8824->jdet_work); in nau8824_interrupt()
1018 snd_soc_jack_report(nau8824->jack, event, event_mask); in nau8824_interrupt()
1029 regmap_read(nau8824->regmap, in nau8824_get_osr()
1036 regmap_read(nau8824->regmap, in nau8824_get_osr()
1048 struct snd_soc_component *component = dai->component; in nau8824_dai_startup()
1052 osr = nau8824_get_osr(nau8824, substream->stream); in nau8824_dai_startup()
1053 if (!osr || !osr->osr) in nau8824_dai_startup()
1054 return -EINVAL; in nau8824_dai_startup()
1056 return snd_pcm_hw_constraint_minmax(substream->runtime, in nau8824_dai_startup()
1058 0, CLK_DA_AD_MAX / osr->osr); in nau8824_dai_startup()
1064 struct snd_soc_component *component = dai->component; in nau8824_hw_params()
1068 int err = -EINVAL; in nau8824_hw_params()
1078 nau8824->fs = params_rate(params); in nau8824_hw_params()
1079 osr = nau8824_get_osr(nau8824, substream->stream); in nau8824_hw_params()
1080 if (!osr || !osr->osr) in nau8824_hw_params()
1082 if (nau8824->fs * osr->osr > CLK_DA_AD_MAX) in nau8824_hw_params()
1084 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) in nau8824_hw_params()
1085 regmap_update_bits(nau8824->regmap, NAU8824_REG_CLK_DIVIDER, in nau8824_hw_params()
1087 osr->clk_src << NAU8824_CLK_DAC_SRC_SFT); in nau8824_hw_params()
1089 regmap_update_bits(nau8824->regmap, NAU8824_REG_CLK_DIVIDER, in nau8824_hw_params()
1091 osr->clk_src << NAU8824_CLK_ADC_SRC_SFT); in nau8824_hw_params()
1094 regmap_read(nau8824->regmap, in nau8824_hw_params()
1098 bclk_fs = snd_soc_params_to_bclk(params) / nau8824->fs; in nau8824_hw_params()
1109 regmap_update_bits(nau8824->regmap, in nau8824_hw_params()
1132 regmap_update_bits(nau8824->regmap, NAU8824_REG_PORT0_I2S_PCM_CTRL_1, in nau8824_hw_params()
1144 struct snd_soc_component *component = dai->component; in nau8824_set_fmt()
1155 return -EINVAL; in nau8824_set_fmt()
1165 return -EINVAL; in nau8824_set_fmt()
1186 return -EINVAL; in nau8824_set_fmt()
1191 regmap_update_bits(nau8824->regmap, NAU8824_REG_PORT0_I2S_PCM_CTRL_1, in nau8824_set_fmt()
1194 regmap_update_bits(nau8824->regmap, NAU8824_REG_PORT0_I2S_PCM_CTRL_2, in nau8824_set_fmt()
1203 * nau8824_set_tdm_slot - configure DAI TDM.
1221 struct snd_soc_component *component = dai->component; in nau8824_set_tdm_slot()
1229 return -EINVAL; in nau8824_set_tdm_slot()
1243 regmap_update_bits(nau8824->regmap, NAU8824_REG_TDM_CTRL, in nau8824_set_tdm_slot()
1247 regmap_update_bits(nau8824->regmap, NAU8824_REG_PORT0_LEFT_TIME_SLOT, in nau8824_set_tdm_slot()
1254 * nau8824_calc_fll_param - Calculate FLL parameters.
1270 * freq_in by 1, 2, 4, or 8 using FLL pre-scalar. in nau8824_calc_fll_param()
1279 return -EINVAL; in nau8824_calc_fll_param()
1280 fll_param->clk_ref_div = fll_pre_scalar[i].val; in nau8824_calc_fll_param()
1288 return -EINVAL; in nau8824_calc_fll_param()
1289 fll_param->ratio = fll_ratio[i].val; in nau8824_calc_fll_param()
1292 * FDCO must be within the 90MHz - 124MHz or the FFL cannot be in nau8824_calc_fll_param()
1307 return -EINVAL; in nau8824_calc_fll_param()
1308 fll_param->mclk_src = mclk_src_scaling[fvco_sel].val; in nau8824_calc_fll_param()
1310 /* Calculate the FLL 10-bit integer input and the FLL 16-bit fractional in nau8824_calc_fll_param()
1313 fvco = div_u64(fvco_max << 16, fref * fll_param->ratio); in nau8824_calc_fll_param()
1314 fll_param->fll_int = (fvco >> 16) & 0x3FF; in nau8824_calc_fll_param()
1315 fll_param->fll_frac = fvco & 0xFFFF; in nau8824_calc_fll_param()
1324 NAU8824_CLK_SRC_MCLK | fll_param->mclk_src); in nau8824_fll_apply()
1326 NAU8824_FLL_RATIO_MASK, fll_param->ratio); in nau8824_fll_apply()
1327 /* FLL 16-bit fractional input */ in nau8824_fll_apply()
1328 regmap_write(regmap, NAU8824_REG_FLL2, fll_param->fll_frac); in nau8824_fll_apply()
1329 /* FLL 10-bit integer input */ in nau8824_fll_apply()
1331 NAU8824_FLL_INTEGER_MASK, fll_param->fll_int); in nau8824_fll_apply()
1332 /* FLL pre-scaler */ in nau8824_fll_apply()
1335 fll_param->clk_ref_div << NAU8824_FLL_REF_DIV_SFT); in nau8824_fll_apply()
1339 /* Disable free-running mode */ in nau8824_fll_apply()
1342 if (fll_param->fll_frac) { in nau8824_fll_apply()
1370 dev_err(nau8824->dev, "Unsupported input clock %d\n", freq_in); in nau8824_set_pll()
1373 dev_dbg(nau8824->dev, "mclk_src=%x ratio=%x fll_frac=%x fll_int=%x clk_ref_div=%x\n", in nau8824_set_pll()
1377 nau8824_fll_apply(nau8824->regmap, &fll_param); in nau8824_set_pll()
1379 regmap_update_bits(nau8824->regmap, NAU8824_REG_CLK_DIVIDER, in nau8824_set_pll()
1388 struct regmap *regmap = nau8824->regmap; in nau8824_config_sysclk()
1436 dev_err(nau8824->dev, "Invalid clock id (%d)\n", clk_id); in nau8824_config_sysclk()
1437 return -EINVAL; in nau8824_config_sysclk()
1440 dev_dbg(nau8824->dev, "Sysclk is %dHz and clock id is %d\n", freq, in nau8824_config_sysclk()
1457 if (nau8824->irq) { in nau8824_resume_setup()
1459 nau8824_int_status_clear_all(nau8824->regmap); in nau8824_resume_setup()
1460 /* Enable jack detection at sleep mode, insertion detection, in nau8824_resume_setup()
1463 regmap_update_bits(nau8824->regmap, NAU8824_REG_ENA_CTRL, in nau8824_resume_setup()
1465 regmap_update_bits(nau8824->regmap, in nau8824_resume_setup()
1469 regmap_update_bits(nau8824->regmap, in nau8824_resume_setup()
1495 regmap_update_bits(nau8824->regmap, in nau8824_set_bias_level()
1497 regmap_update_bits(nau8824->regmap, in nau8824_set_bias_level()
1511 nau8824->dapm = dapm; in nau8824_component_probe()
1520 if (nau8824->irq) { in nau8824_suspend()
1521 disable_irq(nau8824->irq); in nau8824_suspend()
1524 regcache_cache_only(nau8824->regmap, true); in nau8824_suspend()
1525 regcache_mark_dirty(nau8824->regmap); in nau8824_suspend()
1535 regcache_cache_only(nau8824->regmap, false); in nau8824_resume()
1536 regcache_sync(nau8824->regmap); in nau8824_resume()
1537 if (nau8824->irq) { in nau8824_resume()
1541 nau8824->resume_lock = true; in nau8824_resume()
1544 nau8824->resume_lock = false; in nau8824_resume()
1545 enable_irq(nau8824->irq); in nau8824_resume()
1615 * nau8824_enable_jack_detect - Specify a jack for event reporting
1630 nau8824->jack = jack; in nau8824_enable_jack_detect()
1632 INIT_WORK(&nau8824->jdet_work, nau8824_jdet_work); in nau8824_enable_jack_detect()
1633 ret = devm_request_threaded_irq(nau8824->dev, nau8824->irq, NULL, in nau8824_enable_jack_detect()
1637 dev_err(nau8824->dev, "Cannot request irq %d (%d)\n", in nau8824_enable_jack_detect()
1638 nau8824->irq, ret); in nau8824_enable_jack_detect()
1653 struct regmap *regmap = nau8824->regmap; in nau8824_setup_buttons()
1657 nau8824->sar_voltage << NAU8824_SAR_TRACKING_GAIN_SFT); in nau8824_setup_buttons()
1660 nau8824->sar_compare_time << NAU8824_SAR_COMPARE_TIME_SFT); in nau8824_setup_buttons()
1663 nau8824->sar_sampling_time << NAU8824_SAR_SAMPLING_TIME_SFT); in nau8824_setup_buttons()
1667 (nau8824->sar_threshold_num - 1) << NAU8824_LEVELS_NR_SFT); in nau8824_setup_buttons()
1670 nau8824->sar_hysteresis << NAU8824_HYSTERESIS_SFT); in nau8824_setup_buttons()
1673 nau8824->key_debounce << NAU8824_SHORTKEY_DEBOUNCE_SFT); in nau8824_setup_buttons()
1676 (nau8824->sar_threshold[0] << 8) | nau8824->sar_threshold[1]); in nau8824_setup_buttons()
1678 (nau8824->sar_threshold[2] << 8) | nau8824->sar_threshold[3]); in nau8824_setup_buttons()
1680 (nau8824->sar_threshold[4] << 8) | nau8824->sar_threshold[5]); in nau8824_setup_buttons()
1682 (nau8824->sar_threshold[6] << 8) | nau8824->sar_threshold[7]); in nau8824_setup_buttons()
1687 struct regmap *regmap = nau8824->regmap; in nau8824_init_regs()
1692 (nau8824->vref_impedance << NAU8824_VMID_SEL_SFT)); in nau8824_init_regs()
1697 NAU8824_MICBIAS_VOLTAGE_MASK, nau8824->micbias_voltage); in nau8824_init_regs()
1727 /* Class G timer 64ms */ in nau8824_init_regs()
1776 /* jkdet_polarity - 1 is for active-low */ in nau8824_init_regs()
1777 nau8824->jkdet_polarity ? 0 : NAU8824_JACK_LOGIC); in nau8824_init_regs()
1780 (nau8824->jack_eject_debounce << NAU8824_JACK_EJECT_DT_SFT)); in nau8824_init_regs()
1781 if (nau8824->sar_threshold_num) in nau8824_init_regs()
1788 regmap_update_bits(nau8824->regmap, NAU8824_REG_ENA_CTRL, in nau8824_setup_irq()
1790 regmap_update_bits(nau8824->regmap, in nau8824_setup_irq()
1792 regmap_update_bits(nau8824->regmap, NAU8824_REG_INTERRUPT_SETTING_1, in nau8824_setup_irq()
1800 struct device *dev = nau8824->dev; in nau8824_print_device_properties()
1803 dev_dbg(dev, "jkdet-polarity: %d\n", nau8824->jkdet_polarity); in nau8824_print_device_properties()
1804 dev_dbg(dev, "micbias-voltage: %d\n", nau8824->micbias_voltage); in nau8824_print_device_properties()
1805 dev_dbg(dev, "vref-impedance: %d\n", nau8824->vref_impedance); in nau8824_print_device_properties()
1807 dev_dbg(dev, "sar-threshold-num: %d\n", nau8824->sar_threshold_num); in nau8824_print_device_properties()
1808 for (i = 0; i < nau8824->sar_threshold_num; i++) in nau8824_print_device_properties()
1809 dev_dbg(dev, "sar-threshold[%d]=%x\n", i, in nau8824_print_device_properties()
1810 nau8824->sar_threshold[i]); in nau8824_print_device_properties()
1812 dev_dbg(dev, "sar-hysteresis: %d\n", nau8824->sar_hysteresis); in nau8824_print_device_properties()
1813 dev_dbg(dev, "sar-voltage: %d\n", nau8824->sar_voltage); in nau8824_print_device_properties()
1814 dev_dbg(dev, "sar-compare-time: %d\n", nau8824->sar_compare_time); in nau8824_print_device_properties()
1815 dev_dbg(dev, "sar-sampling-time: %d\n", nau8824->sar_sampling_time); in nau8824_print_device_properties()
1816 dev_dbg(dev, "short-key-debounce: %d\n", nau8824->key_debounce); in nau8824_print_device_properties()
1817 dev_dbg(dev, "jack-eject-debounce: %d\n", in nau8824_print_device_properties()
1818 nau8824->jack_eject_debounce); in nau8824_print_device_properties()
1825 ret = device_property_read_u32(dev, "nuvoton,jkdet-polarity", in nau8824_read_device_properties()
1826 &nau8824->jkdet_polarity); in nau8824_read_device_properties()
1828 nau8824->jkdet_polarity = 1; in nau8824_read_device_properties()
1829 ret = device_property_read_u32(dev, "nuvoton,micbias-voltage", in nau8824_read_device_properties()
1830 &nau8824->micbias_voltage); in nau8824_read_device_properties()
1832 nau8824->micbias_voltage = 6; in nau8824_read_device_properties()
1833 ret = device_property_read_u32(dev, "nuvoton,vref-impedance", in nau8824_read_device_properties()
1834 &nau8824->vref_impedance); in nau8824_read_device_properties()
1836 nau8824->vref_impedance = 2; in nau8824_read_device_properties()
1837 ret = device_property_read_u32(dev, "nuvoton,sar-threshold-num", in nau8824_read_device_properties()
1838 &nau8824->sar_threshold_num); in nau8824_read_device_properties()
1840 nau8824->sar_threshold_num = 4; in nau8824_read_device_properties()
1841 ret = device_property_read_u32_array(dev, "nuvoton,sar-threshold", in nau8824_read_device_properties()
1842 nau8824->sar_threshold, nau8824->sar_threshold_num); in nau8824_read_device_properties()
1844 nau8824->sar_threshold[0] = 0x0a; in nau8824_read_device_properties()
1845 nau8824->sar_threshold[1] = 0x14; in nau8824_read_device_properties()
1846 nau8824->sar_threshold[2] = 0x26; in nau8824_read_device_properties()
1847 nau8824->sar_threshold[3] = 0x73; in nau8824_read_device_properties()
1849 ret = device_property_read_u32(dev, "nuvoton,sar-hysteresis", in nau8824_read_device_properties()
1850 &nau8824->sar_hysteresis); in nau8824_read_device_properties()
1852 nau8824->sar_hysteresis = 0; in nau8824_read_device_properties()
1853 ret = device_property_read_u32(dev, "nuvoton,sar-voltage", in nau8824_read_device_properties()
1854 &nau8824->sar_voltage); in nau8824_read_device_properties()
1856 nau8824->sar_voltage = 6; in nau8824_read_device_properties()
1857 ret = device_property_read_u32(dev, "nuvoton,sar-compare-time", in nau8824_read_device_properties()
1858 &nau8824->sar_compare_time); in nau8824_read_device_properties()
1860 nau8824->sar_compare_time = 1; in nau8824_read_device_properties()
1861 ret = device_property_read_u32(dev, "nuvoton,sar-sampling-time", in nau8824_read_device_properties()
1862 &nau8824->sar_sampling_time); in nau8824_read_device_properties()
1864 nau8824->sar_sampling_time = 1; in nau8824_read_device_properties()
1865 ret = device_property_read_u32(dev, "nuvoton,short-key-debounce", in nau8824_read_device_properties()
1866 &nau8824->key_debounce); in nau8824_read_device_properties()
1868 nau8824->key_debounce = 0; in nau8824_read_device_properties()
1869 ret = device_property_read_u32(dev, "nuvoton,jack-eject-debounce", in nau8824_read_device_properties()
1870 &nau8824->jack_eject_debounce); in nau8824_read_device_properties()
1872 nau8824->jack_eject_debounce = 1; in nau8824_read_device_properties()
1893 DMI_MATCH(DMI_PRODUCT_NAME, "i1-TF"),
1937 if (quirk_override != -1) { in nau8824_check_quirks()
1944 nau8824_quirk = (unsigned long)dmi_id->driver_data; in nau8824_check_quirks()
1952 return "cfg-spk:1"; in nau8824_components()
1954 return "cfg-spk:2"; in nau8824_components()
1960 struct device *dev = &i2c->dev; in nau8824_i2c_probe()
1967 return -ENOMEM; in nau8824_i2c_probe()
1974 nau8824->regmap = devm_regmap_init_i2c(i2c, &nau8824_regmap_config); in nau8824_i2c_probe()
1975 if (IS_ERR(nau8824->regmap)) in nau8824_i2c_probe()
1976 return PTR_ERR(nau8824->regmap); in nau8824_i2c_probe()
1977 nau8824->resume_lock = false; in nau8824_i2c_probe()
1978 nau8824->dev = dev; in nau8824_i2c_probe()
1979 nau8824->irq = i2c->irq; in nau8824_i2c_probe()
1980 sema_init(&nau8824->jd_sem, 1); in nau8824_i2c_probe()
1985 nau8824->jkdet_polarity = 0; in nau8824_i2c_probe()
1989 ret = regmap_read(nau8824->regmap, NAU8824_REG_I2C_DEVICE_ID, &value); in nau8824_i2c_probe()
1995 nau8824_reset_chip(nau8824->regmap); in nau8824_i2c_probe()
1998 if (i2c->irq) in nau8824_i2c_probe()