Lines Matching +full:oversampling +full:- +full:ratio
1 // SPDX-License-Identifier: GPL-2.0-only
3 // nau8821.c -- Nuvoton NAU88L21 audio codec driver
7 // Co-author: Seven Lee <wtli@nuvoton.com>
43 int ratio; member
71 /* ratio for input clk freq */
277 struct soc_bytes_ext *params = (void *)kcontrol->private_value; in nau8821_biq_coeff_get()
279 if (!component->regmap) in nau8821_biq_coeff_get()
280 return -EINVAL; in nau8821_biq_coeff_get()
282 regmap_raw_read(component->regmap, NAU8821_R21_BIQ0_COF1, in nau8821_biq_coeff_get()
283 ucontrol->value.bytes.data, params->max); in nau8821_biq_coeff_get()
292 struct soc_bytes_ext *params = (void *)kcontrol->private_value; in nau8821_biq_coeff_put()
295 if (!component->regmap) in nau8821_biq_coeff_put()
296 return -EINVAL; in nau8821_biq_coeff_put()
298 data = kmemdup(ucontrol->value.bytes.data, in nau8821_biq_coeff_put()
299 params->max, GFP_KERNEL | GFP_DMA); in nau8821_biq_coeff_put()
301 return -ENOMEM; in nau8821_biq_coeff_put()
303 regmap_raw_write(component->regmap, NAU8821_R21_BIQ0_COF1, in nau8821_biq_coeff_put()
304 data, params->max); in nau8821_biq_coeff_put()
325 static const DECLARE_TLV_DB_MINMAX_MUTE(adc_vol_tlv, -6600, 2400);
326 static const DECLARE_TLV_DB_MINMAX_MUTE(sidetone_vol_tlv, -4200, 0);
327 static const DECLARE_TLV_DB_MINMAX(hp_vol_tlv, -900, 0);
328 static const DECLARE_TLV_DB_SCALE(playback_vol_tlv, -6600, 50, 1);
329 static const DECLARE_TLV_DB_MINMAX(fepga_gain_tlv, -100, 3600);
330 static const DECLARE_TLV_DB_MINMAX_MUTE(crosstalk_vol_tlv, -7000, 2400);
351 SOC_ENUM("DAC Oversampling Rate", nau8821_dac_oversampl_enum),
366 snd_soc_dapm_to_component(w->dapm); in dmic_clock_control()
368 int i, speed_selection = -1, clk_adc_src, clk_adc; in dmic_clock_control()
373 * less than nau8821->dmic_clk_threshold. in dmic_clock_control()
375 regmap_read(nau8821->regmap, NAU8821_R03_CLK_DIVIDER, in dmic_clock_control()
379 clk_adc = (nau8821->fs * 256) >> clk_adc_src; in dmic_clock_control()
383 nau8821->dmic_clk_threshold) { in dmic_clock_control()
388 return -EINVAL; in dmic_clock_control()
390 dev_dbg(nau8821->dev, in dmic_clock_control()
392 clk_adc, nau8821->dmic_clk_threshold, in dmic_clock_control()
394 regmap_update_bits(nau8821->regmap, NAU8821_R13_DMIC_CTRL, in dmic_clock_control()
405 snd_soc_dapm_to_component(w->dapm); in nau8821_left_adc_event()
411 regmap_update_bits(nau8821->regmap, NAU8821_R01_ENA_CTRL, in nau8821_left_adc_event()
415 regmap_update_bits(nau8821->regmap, in nau8821_left_adc_event()
419 return -EINVAL; in nau8821_left_adc_event()
429 snd_soc_dapm_to_component(w->dapm); in nau8821_right_adc_event()
435 regmap_update_bits(nau8821->regmap, NAU8821_R01_ENA_CTRL, in nau8821_right_adc_event()
439 regmap_update_bits(nau8821->regmap, in nau8821_right_adc_event()
443 return -EINVAL; in nau8821_right_adc_event()
453 snd_soc_dapm_to_component(w->dapm); in nau8821_pump_event()
461 regmap_update_bits(nau8821->regmap, NAU8821_R80_CHARGE_PUMP, in nau8821_pump_event()
465 regmap_update_bits(nau8821->regmap, NAU8821_R80_CHARGE_PUMP, in nau8821_pump_event()
469 return -EINVAL; in nau8821_pump_event()
479 snd_soc_dapm_to_component(w->dapm); in nau8821_output_dac_event()
485 regmap_update_bits(nau8821->regmap, NAU8821_R66_BIAS_ADJ, in nau8821_output_dac_event()
489 regmap_update_bits(nau8821->regmap, NAU8821_R66_BIAS_ADJ, in nau8821_output_dac_event()
493 return -EINVAL; in nau8821_output_dac_event()
503 snd_soc_dapm_to_component(w->dapm); in system_clock_control()
507 dev_dbg(nau8821->dev, "system clock control : POWER OFF\n"); in system_clock_control()
513 if (nau8821_is_jack_inserted(nau8821->regmap)) { in system_clock_control()
596 /* HPOL/R are ungrounded by disabling 16 Ohm pull-downs on playback */
679 regmap_read(nau8821->regmap, NAU8821_R2C_DAC_CTRL1, &osr); in nau8821_get_osr()
685 regmap_read(nau8821->regmap, NAU8821_R2B_ADC_RATE, &osr); in nau8821_get_osr()
696 struct snd_soc_component *component = dai->component; in nau8821_dai_startup()
700 osr = nau8821_get_osr(nau8821, substream->stream); in nau8821_dai_startup()
701 if (!osr || !osr->osr) in nau8821_dai_startup()
702 return -EINVAL; in nau8821_dai_startup()
704 return snd_pcm_hw_constraint_minmax(substream->runtime, in nau8821_dai_startup()
706 0, CLK_DA_AD_MAX / osr->osr); in nau8821_dai_startup()
712 struct snd_soc_component *component = dai->component; in nau8821_hw_params()
717 nau8821->fs = params_rate(params); in nau8821_hw_params()
724 osr = nau8821_get_osr(nau8821, substream->stream); in nau8821_hw_params()
725 if (!osr || !osr->osr) in nau8821_hw_params()
726 return -EINVAL; in nau8821_hw_params()
727 if (nau8821->fs * osr->osr > CLK_DA_AD_MAX) in nau8821_hw_params()
728 return -EINVAL; in nau8821_hw_params()
729 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) in nau8821_hw_params()
730 regmap_update_bits(nau8821->regmap, NAU8821_R03_CLK_DIVIDER, in nau8821_hw_params()
732 osr->clk_src << NAU8821_CLK_DAC_SRC_SFT); in nau8821_hw_params()
734 regmap_update_bits(nau8821->regmap, NAU8821_R03_CLK_DIVIDER, in nau8821_hw_params()
736 osr->clk_src << NAU8821_CLK_ADC_SRC_SFT); in nau8821_hw_params()
739 regmap_read(nau8821->regmap, NAU8821_R1D_I2S_PCM_CTRL2, &ctrl_val); in nau8821_hw_params()
741 /* get the bclk and fs ratio */ in nau8821_hw_params()
742 bclk_fs = snd_soc_params_to_bclk(params) / nau8821->fs; in nau8821_hw_params()
750 return -EINVAL; in nau8821_hw_params()
752 regmap_update_bits(nau8821->regmap, NAU8821_R1D_I2S_PCM_CTRL2, in nau8821_hw_params()
771 return -EINVAL; in nau8821_hw_params()
774 regmap_update_bits(nau8821->regmap, NAU8821_R1C_I2S_PCM_CTRL1, in nau8821_hw_params()
782 struct snd_soc_component *component = codec_dai->component; in nau8821_set_dai_fmt()
793 return -EINVAL; in nau8821_set_dai_fmt()
803 return -EINVAL; in nau8821_set_dai_fmt()
824 return -EINVAL; in nau8821_set_dai_fmt()
827 regmap_update_bits(nau8821->regmap, NAU8821_R1C_I2S_PCM_CTRL1, in nau8821_set_dai_fmt()
830 regmap_update_bits(nau8821->regmap, NAU8821_R1D_I2S_PCM_CTRL2, in nau8821_set_dai_fmt()
839 struct snd_soc_component *component = dai->component; in nau8821_digital_mute()
846 return regmap_update_bits(nau8821->regmap, in nau8821_digital_mute()
901 /* Reset the intrruption status from rightmost bit if the corres- in nau8821_int_status_clear_all()
915 struct snd_soc_dapm_context *dapm = nau8821->dapm; in nau8821_eject_jack()
916 struct regmap *regmap = nau8821->regmap; in nau8821_eject_jack()
931 /* Enable the insertion interruption, disable the ejection inter- in nau8821_eject_jack()
932 * ruption, and then bypass de-bounce circuit. in nau8821_eject_jack()
937 /* Mask unneeded IRQs: 1 - disable, 0 - enable */ in nau8821_eject_jack()
946 if (dapm->bias_level < SND_SOC_BIAS_PREPARE) in nau8821_eject_jack()
952 if (nau8821->key_enable) { in nau8821_eject_jack()
972 struct snd_soc_dapm_context *dapm = nau8821->dapm; in nau8821_jdet_work()
974 struct regmap *regmap = nau8821->regmap; in nau8821_jdet_work()
984 dev_dbg(nau8821->dev, "Headset connected\n"); in nau8821_jdet_work()
995 if (nau8821->key_enable) { in nau8821_jdet_work()
1005 dev_dbg(nau8821->dev, "Headphone connected\n"); in nau8821_jdet_work()
1011 snd_soc_jack_report(nau8821->jack, event, event_mask); in nau8821_jdet_work()
1017 struct regmap *regmap = nau8821->regmap; in nau8821_setup_inserted_irq()
1020 if (nau8821->dapm->bias_level < SND_SOC_BIAS_PREPARE) in nau8821_setup_inserted_irq()
1033 /* Not bypass de-bounce circuit */ in nau8821_setup_inserted_irq()
1046 struct regmap *regmap = nau8821->regmap; in nau8821_interrupt()
1050 dev_err(nau8821->dev, "failed to read irq status\n"); in nau8821_interrupt()
1054 dev_dbg(nau8821->dev, "IRQ %d\n", active_irq); in nau8821_interrupt()
1076 cancel_work_sync(&nau8821->jdet_work); in nau8821_interrupt()
1077 schedule_work(&nau8821->jdet_work); in nau8821_interrupt()
1089 dev_warn(nau8821->dev, in nau8821_interrupt()
1101 snd_soc_jack_report(nau8821->jack, event, event_mask); in nau8821_interrupt()
1126 nau8821->dapm = dapm; in nau8821_component_probe()
1132 * nau8821_calc_fll_param - Calculate FLL parameters.
1148 * dividing freq_in by 1, 2, 4, or 8 using FLL pre-scalar. in nau8821_calc_fll_param()
1157 return -EINVAL; in nau8821_calc_fll_param()
1158 fll_param->clk_ref_div = fll_pre_scalar[i].val; in nau8821_calc_fll_param()
1160 /* Choose the FLL ratio based on FREF */ in nau8821_calc_fll_param()
1166 return -EINVAL; in nau8821_calc_fll_param()
1167 fll_param->ratio = fll_ratio[i].val; in nau8821_calc_fll_param()
1170 * FDCO must be within the 90MHz - 100MHz or the FFL cannot be in nau8821_calc_fll_param()
1185 return -EINVAL; in nau8821_calc_fll_param()
1186 fll_param->mclk_src = mclk_src_scaling[fvco_sel].val; in nau8821_calc_fll_param()
1188 /* Calculate the FLL 10-bit integer input and the FLL 24-bit fractional in nau8821_calc_fll_param()
1189 * input based on FDCO, FREF and FLL ratio. in nau8821_calc_fll_param()
1191 fvco = div_u64(fvco_max << 24, fref * fll_param->ratio); in nau8821_calc_fll_param()
1192 fll_param->fll_int = (fvco >> 24) & 0x3ff; in nau8821_calc_fll_param()
1193 fll_param->fll_frac = fvco & 0xffffff; in nau8821_calc_fll_param()
1201 struct regmap *regmap = nau8821->regmap; in nau8821_fll_apply()
1205 NAU8821_CLK_SRC_MCLK | fll_param->mclk_src); in nau8821_fll_apply()
1209 fll_param->ratio | (0x6 << NAU8821_ICTRL_LATCH_SFT)); in nau8821_fll_apply()
1210 /* FLL 24-bit fractional input */ in nau8821_fll_apply()
1212 (fll_param->fll_frac >> 16) & 0xff); in nau8821_fll_apply()
1213 regmap_write(regmap, NAU8821_R0B_FLL8, fll_param->fll_frac & 0xffff); in nau8821_fll_apply()
1214 /* FLL 10-bit integer input */ in nau8821_fll_apply()
1216 NAU8821_FLL_INTEGER_MASK, fll_param->fll_int); in nau8821_fll_apply()
1217 /* FLL pre-scaler */ in nau8821_fll_apply()
1221 (fll_param->clk_ref_div << NAU8821_FLL_REF_DIV_SFT)); in nau8821_fll_apply()
1225 /* Disable free-running mode */ in nau8821_fll_apply()
1228 if (fll_param->fll_frac) { in nau8821_fll_apply()
1249 * nau8821_set_fll - FLL configuration of nau8821
1271 dev_err(nau8821->dev, in nau8821_set_fll()
1276 dev_dbg(nau8821->dev, in nau8821_set_fll()
1277 "mclk_src=%x ratio=%x fll_frac=%x fll_int=%x clk_ref_div=%x\n", in nau8821_set_fll()
1278 fll_param->mclk_src, fll_param->ratio, fll_param->fll_frac, in nau8821_set_fll()
1279 fll_param->fll_int, fll_param->clk_ref_div); in nau8821_set_fll()
1283 regmap_update_bits(nau8821->regmap, NAU8821_R03_CLK_DIVIDER, in nau8821_set_fll()
1303 struct regmap *regmap = nau8821->regmap; in nau8821_configure_sysclk()
1368 dev_err(nau8821->dev, "Invalid clock id (%d)\n", clk_id); in nau8821_configure_sysclk()
1369 return -EINVAL; in nau8821_configure_sysclk()
1371 nau8821->clk_id = clk_id; in nau8821_configure_sysclk()
1372 dev_dbg(nau8821->dev, "Sysclk is %dHz and clock id is %d\n", freq, in nau8821_configure_sysclk()
1373 nau8821->clk_id); in nau8821_configure_sysclk()
1388 struct regmap *regmap = nau8821->regmap; in nau8821_resume_setup()
1392 if (nau8821->irq) { in nau8821_resume_setup()
1397 * bypass de-bounce circuit. in nau8821_resume_setup()
1415 struct regmap *regmap = nau8821->regmap; in nau8821_set_bias_level()
1435 if (nau8821->irq) { in nau8821_set_bias_level()
1463 if (nau8821->irq) in nau8821_suspend()
1464 disable_irq(nau8821->irq); in nau8821_suspend()
1468 snd_soc_dapm_sync(nau8821->dapm); in nau8821_suspend()
1469 regcache_cache_only(nau8821->regmap, true); in nau8821_suspend()
1470 regcache_mark_dirty(nau8821->regmap); in nau8821_suspend()
1479 regcache_cache_only(nau8821->regmap, false); in nau8821_resume()
1480 regcache_sync(nau8821->regmap); in nau8821_resume()
1481 if (nau8821->irq) in nau8821_resume()
1482 enable_irq(nau8821->irq); in nau8821_resume()
1507 * nau8821_enable_jack_detect - Specify a jack for event reporting
1522 nau8821->jack = jack; in nau8821_enable_jack_detect()
1524 INIT_WORK(&nau8821->jdet_work, nau8821_jdet_work); in nau8821_enable_jack_detect()
1525 ret = devm_request_threaded_irq(nau8821->dev, nau8821->irq, NULL, in nau8821_enable_jack_detect()
1529 dev_err(nau8821->dev, "Cannot request irq %d (%d)\n", in nau8821_enable_jack_detect()
1530 nau8821->irq, ret); in nau8821_enable_jack_detect()
1546 struct device *dev = nau8821->dev; in nau8821_print_device_properties()
1548 dev_dbg(dev, "jkdet-enable: %d\n", nau8821->jkdet_enable); in nau8821_print_device_properties()
1549 dev_dbg(dev, "jkdet-pull-enable: %d\n", nau8821->jkdet_pull_enable); in nau8821_print_device_properties()
1550 dev_dbg(dev, "jkdet-pull-up: %d\n", nau8821->jkdet_pull_up); in nau8821_print_device_properties()
1551 dev_dbg(dev, "jkdet-polarity: %d\n", nau8821->jkdet_polarity); in nau8821_print_device_properties()
1552 dev_dbg(dev, "micbias-voltage: %d\n", nau8821->micbias_voltage); in nau8821_print_device_properties()
1553 dev_dbg(dev, "vref-impedance: %d\n", nau8821->vref_impedance); in nau8821_print_device_properties()
1554 dev_dbg(dev, "jack-insert-debounce: %d\n", in nau8821_print_device_properties()
1555 nau8821->jack_insert_debounce); in nau8821_print_device_properties()
1556 dev_dbg(dev, "jack-eject-debounce: %d\n", in nau8821_print_device_properties()
1557 nau8821->jack_eject_debounce); in nau8821_print_device_properties()
1558 dev_dbg(dev, "dmic-clk-threshold: %d\n", in nau8821_print_device_properties()
1559 nau8821->dmic_clk_threshold); in nau8821_print_device_properties()
1560 dev_dbg(dev, "key_enable: %d\n", nau8821->key_enable); in nau8821_print_device_properties()
1568 nau8821->jkdet_enable = device_property_read_bool(dev, in nau8821_read_device_properties()
1569 "nuvoton,jkdet-enable"); in nau8821_read_device_properties()
1570 nau8821->jkdet_pull_enable = device_property_read_bool(dev, in nau8821_read_device_properties()
1571 "nuvoton,jkdet-pull-enable"); in nau8821_read_device_properties()
1572 nau8821->jkdet_pull_up = device_property_read_bool(dev, in nau8821_read_device_properties()
1573 "nuvoton,jkdet-pull-up"); in nau8821_read_device_properties()
1574 nau8821->key_enable = device_property_read_bool(dev, in nau8821_read_device_properties()
1575 "nuvoton,key-enable"); in nau8821_read_device_properties()
1576 ret = device_property_read_u32(dev, "nuvoton,jkdet-polarity", in nau8821_read_device_properties()
1577 &nau8821->jkdet_polarity); in nau8821_read_device_properties()
1579 nau8821->jkdet_polarity = 1; in nau8821_read_device_properties()
1580 ret = device_property_read_u32(dev, "nuvoton,micbias-voltage", in nau8821_read_device_properties()
1581 &nau8821->micbias_voltage); in nau8821_read_device_properties()
1583 nau8821->micbias_voltage = 6; in nau8821_read_device_properties()
1584 ret = device_property_read_u32(dev, "nuvoton,vref-impedance", in nau8821_read_device_properties()
1585 &nau8821->vref_impedance); in nau8821_read_device_properties()
1587 nau8821->vref_impedance = 2; in nau8821_read_device_properties()
1588 ret = device_property_read_u32(dev, "nuvoton,jack-insert-debounce", in nau8821_read_device_properties()
1589 &nau8821->jack_insert_debounce); in nau8821_read_device_properties()
1591 nau8821->jack_insert_debounce = 7; in nau8821_read_device_properties()
1592 ret = device_property_read_u32(dev, "nuvoton,jack-eject-debounce", in nau8821_read_device_properties()
1593 &nau8821->jack_eject_debounce); in nau8821_read_device_properties()
1595 nau8821->jack_eject_debounce = 0; in nau8821_read_device_properties()
1596 ret = device_property_read_u32(dev, "nuvoton,dmic-clk-threshold", in nau8821_read_device_properties()
1597 &nau8821->dmic_clk_threshold); in nau8821_read_device_properties()
1599 nau8821->dmic_clk_threshold = 3072000; in nau8821_read_device_properties()
1606 struct regmap *regmap = nau8821->regmap; in nau8821_init_regs()
1620 (nau8821->vref_impedance << NAU8821_BIAS_VMID_SEL_SFT) | in nau8821_init_regs()
1651 NAU8821_MICBIAS_VOLTAGE_MASK, nau8821->micbias_voltage); in nau8821_init_regs()
1652 /* Default oversampling/decimations settings are unusable in nau8821_init_regs()
1663 struct regmap *regmap = nau8821->regmap; in nau8821_setup_irq()
1668 nau8821->jkdet_enable ? 0 : NAU8821_JKDET_OUTPUT_EN); in nau8821_setup_irq()
1671 nau8821->jkdet_pull_enable ? 0 : NAU8821_JKDET_PULL_EN); in nau8821_setup_irq()
1674 nau8821->jkdet_pull_up ? NAU8821_JKDET_PULL_UP : 0); in nau8821_setup_irq()
1677 /* jkdet_polarity - 1 is for active-low */ in nau8821_setup_irq()
1678 nau8821->jkdet_polarity ? 0 : NAU8821_JACK_POLARITY); in nau8821_setup_irq()
1681 nau8821->jack_insert_debounce << in nau8821_setup_irq()
1685 nau8821->jack_eject_debounce << in nau8821_setup_irq()
1693 /* Mask unneeded IRQs: 1 - disable, 0 - enable */ in nau8821_setup_irq()
1701 struct device *dev = &i2c->dev; in nau8821_i2c_probe()
1702 struct nau8821 *nau8821 = dev_get_platdata(&i2c->dev); in nau8821_i2c_probe()
1708 return -ENOMEM; in nau8821_i2c_probe()
1713 nau8821->regmap = devm_regmap_init_i2c(i2c, &nau8821_regmap_config); in nau8821_i2c_probe()
1714 if (IS_ERR(nau8821->regmap)) in nau8821_i2c_probe()
1715 return PTR_ERR(nau8821->regmap); in nau8821_i2c_probe()
1717 nau8821->dev = dev; in nau8821_i2c_probe()
1718 nau8821->irq = i2c->irq; in nau8821_i2c_probe()
1721 nau8821_reset_chip(nau8821->regmap); in nau8821_i2c_probe()
1722 ret = regmap_read(nau8821->regmap, NAU8821_R58_I2C_DEVICE_ID, &value); in nau8821_i2c_probe()
1729 if (i2c->irq) in nau8821_i2c_probe()
1732 ret = devm_snd_soc_register_component(&i2c->dev, in nau8821_i2c_probe()