Lines Matching refs:nau8824
39 static int nau8824_config_sysclk(struct nau8824 *nau8824,
41 static bool nau8824_is_jack_inserted(struct nau8824 *nau8824);
206 static int nau8824_sema_acquire(struct nau8824 *nau8824, long timeout) in nau8824_sema_acquire() argument
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()
223 static inline void nau8824_sema_release(struct nau8824 *nau8824) in nau8824_sema_release() argument
225 up(&nau8824->jd_sem); in nau8824_sema_release()
432 struct nau8824 *nau8824 = snd_soc_component_get_drvdata(component); in nau8824_output_dac_event() local
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()
455 struct nau8824 *nau8824 = snd_soc_component_get_drvdata(component); in nau8824_spk_event() local
459 regmap_update_bits(nau8824->regmap, in nau8824_spk_event()
464 regmap_update_bits(nau8824->regmap, in nau8824_spk_event()
479 struct nau8824 *nau8824 = snd_soc_component_get_drvdata(component); in nau8824_pump_event() local
485 regmap_update_bits(nau8824->regmap, in nau8824_pump_event()
490 regmap_update_bits(nau8824->regmap, in nau8824_pump_event()
505 struct nau8824 *nau8824 = snd_soc_component_get_drvdata(component); in system_clock_control() local
506 struct regmap *regmap = nau8824->regmap; in system_clock_control()
512 dev_dbg(nau8824->dev, "system clock control : POWER OFF\n"); in system_clock_control()
518 if (nau8824_is_jack_inserted(nau8824)) { in system_clock_control()
519 nau8824_config_sysclk(nau8824, in system_clock_control()
522 nau8824_config_sysclk(nau8824, NAU8824_CLK_DIS, 0); in system_clock_control()
525 clk_disable_unprepare(nau8824->mclk); in system_clock_control()
527 dev_dbg(nau8824->dev, "system clock control : POWER ON\n"); in system_clock_control()
529 ret = clk_prepare_enable(nau8824->mclk); in system_clock_control()
559 nau8824_config_sysclk(nau8824, in system_clock_control()
572 struct nau8824 *nau8824 = snd_soc_component_get_drvdata(component); in dmic_clock_control() local
576 freq = clk_get_rate(nau8824->mclk); in dmic_clock_control()
578 freq = nau8824->fs * 256; in dmic_clock_control()
588 dev_dbg(nau8824->dev, "dmic src %d for mclk %d\n", src, freq); in dmic_clock_control()
589 regmap_update_bits(nau8824->regmap, NAU8824_REG_CLK_DIVIDER, in dmic_clock_control()
825 static bool nau8824_is_jack_inserted(struct nau8824 *nau8824) in nau8824_is_jack_inserted() argument
827 struct snd_soc_jack *jack = nau8824->jack; in nau8824_is_jack_inserted()
830 if (nau8824->irq && jack) in nau8824_is_jack_inserted()
852 static void nau8824_eject_jack(struct nau8824 *nau8824) in nau8824_eject_jack() argument
854 struct snd_soc_dapm_context *dapm = nau8824->dapm; in nau8824_eject_jack()
855 struct regmap *regmap = nau8824->regmap; in nau8824_eject_jack()
880 nau8824_config_sysclk(nau8824, NAU8824_CLK_DIS, 0); in nau8824_eject_jack()
885 struct nau8824 *nau8824 = container_of( in nau8824_jdet_work() local
886 work, struct nau8824, jdet_work); in nau8824_jdet_work()
887 struct snd_soc_dapm_context *dapm = nau8824->dapm; in nau8824_jdet_work()
888 struct regmap *regmap = nau8824->regmap; in nau8824_jdet_work()
899 dev_dbg(nau8824->dev, "SAR ADC data 0x%02x\n", adc_value); in nau8824_jdet_work()
910 snd_soc_jack_report(nau8824->jack, event, event_mask); in nau8824_jdet_work()
917 if (nau8824->resume_lock) { in nau8824_jdet_work()
918 nau8824_sema_release(nau8824); in nau8824_jdet_work()
919 nau8824->resume_lock = false; in nau8824_jdet_work()
923 static void nau8824_setup_auto_irq(struct nau8824 *nau8824) in nau8824_setup_auto_irq() argument
925 struct regmap *regmap = nau8824->regmap; in nau8824_setup_auto_irq()
934 if (nau8824->dapm->bias_level < SND_SOC_BIAS_PREPARE) in nau8824_setup_auto_irq()
935 nau8824_config_sysclk(nau8824, NAU8824_CLK_INTERNAL, 0); in nau8824_setup_auto_irq()
968 struct nau8824 *nau8824 = (struct nau8824 *)data; in nau8824_interrupt() local
969 struct regmap *regmap = nau8824->regmap; in nau8824_interrupt()
973 dev_err(nau8824->dev, "failed to read irq status\n"); in nau8824_interrupt()
976 dev_dbg(nau8824->dev, "IRQ %x\n", active_irq); in nau8824_interrupt()
979 nau8824_eject_jack(nau8824); in nau8824_interrupt()
985 if (nau8824->resume_lock) { in nau8824_interrupt()
986 nau8824_sema_release(nau8824); in nau8824_interrupt()
987 nau8824->resume_lock = false; in nau8824_interrupt()
989 cancel_work_sync(&nau8824->jdet_work); in nau8824_interrupt()
1000 dev_dbg(nau8824->dev, "button %x pressed\n", event); in nau8824_interrupt()
1016 cancel_work_sync(&nau8824->jdet_work); in nau8824_interrupt()
1017 schedule_work(&nau8824->jdet_work); in nau8824_interrupt()
1022 nau8824_setup_auto_irq(nau8824); in nau8824_interrupt()
1031 snd_soc_jack_report(nau8824->jack, event, event_mask); in nau8824_interrupt()
1037 nau8824_get_osr(struct nau8824 *nau8824, int stream) in nau8824_get_osr() argument
1042 regmap_read(nau8824->regmap, in nau8824_get_osr()
1049 regmap_read(nau8824->regmap, in nau8824_get_osr()
1062 struct nau8824 *nau8824 = snd_soc_component_get_drvdata(component); in nau8824_dai_startup() local
1065 osr = nau8824_get_osr(nau8824, substream->stream); in nau8824_dai_startup()
1078 struct nau8824 *nau8824 = snd_soc_component_get_drvdata(component); in nau8824_hw_params() local
1083 nau8824_sema_acquire(nau8824, HZ); in nau8824_hw_params()
1091 nau8824->fs = params_rate(params); in nau8824_hw_params()
1092 osr = nau8824_get_osr(nau8824, substream->stream); in nau8824_hw_params()
1095 if (nau8824->fs * osr->osr > CLK_DA_AD_MAX) in nau8824_hw_params()
1098 regmap_update_bits(nau8824->regmap, NAU8824_REG_CLK_DIVIDER, in nau8824_hw_params()
1102 regmap_update_bits(nau8824->regmap, NAU8824_REG_CLK_DIVIDER, in nau8824_hw_params()
1107 regmap_read(nau8824->regmap, in nau8824_hw_params()
1111 bclk_fs = snd_soc_params_to_bclk(params) / nau8824->fs; in nau8824_hw_params()
1122 regmap_update_bits(nau8824->regmap, in nau8824_hw_params()
1145 regmap_update_bits(nau8824->regmap, NAU8824_REG_PORT0_I2S_PCM_CTRL_1, in nau8824_hw_params()
1150 nau8824_sema_release(nau8824); in nau8824_hw_params()
1158 struct nau8824 *nau8824 = snd_soc_component_get_drvdata(component); in nau8824_set_fmt() local
1202 nau8824_sema_acquire(nau8824, HZ); in nau8824_set_fmt()
1204 regmap_update_bits(nau8824->regmap, NAU8824_REG_PORT0_I2S_PCM_CTRL_1, in nau8824_set_fmt()
1207 regmap_update_bits(nau8824->regmap, NAU8824_REG_PORT0_I2S_PCM_CTRL_2, in nau8824_set_fmt()
1210 nau8824_sema_release(nau8824); in nau8824_set_fmt()
1235 struct nau8824 *nau8824 = snd_soc_component_get_drvdata(component); in nau8824_set_tdm_slot() local
1256 regmap_update_bits(nau8824->regmap, NAU8824_REG_TDM_CTRL, in nau8824_set_tdm_slot()
1260 regmap_update_bits(nau8824->regmap, NAU8824_REG_PORT0_LEFT_TIME_SLOT, in nau8824_set_tdm_slot()
1376 struct nau8824 *nau8824 = snd_soc_component_get_drvdata(component); in nau8824_set_pll() local
1383 dev_err(nau8824->dev, "Unsupported input clock %d\n", freq_in); in nau8824_set_pll()
1386 dev_dbg(nau8824->dev, "mclk_src=%x ratio=%x fll_frac=%x fll_int=%x clk_ref_div=%x\n", in nau8824_set_pll()
1390 nau8824_fll_apply(nau8824->regmap, &fll_param); in nau8824_set_pll()
1392 regmap_update_bits(nau8824->regmap, NAU8824_REG_CLK_DIVIDER, in nau8824_set_pll()
1398 static int nau8824_config_sysclk(struct nau8824 *nau8824, in nau8824_config_sysclk() argument
1401 struct regmap *regmap = nau8824->regmap; in nau8824_config_sysclk()
1412 nau8824_sema_acquire(nau8824, HZ); in nau8824_config_sysclk()
1417 nau8824_sema_release(nau8824); in nau8824_config_sysclk()
1428 nau8824_sema_acquire(nau8824, HZ); in nau8824_config_sysclk()
1431 nau8824_sema_release(nau8824); in nau8824_config_sysclk()
1435 nau8824_sema_acquire(nau8824, HZ); in nau8824_config_sysclk()
1438 nau8824_sema_release(nau8824); in nau8824_config_sysclk()
1442 nau8824_sema_acquire(nau8824, HZ); in nau8824_config_sysclk()
1445 nau8824_sema_release(nau8824); in nau8824_config_sysclk()
1449 dev_err(nau8824->dev, "Invalid clock id (%d)\n", clk_id); in nau8824_config_sysclk()
1453 dev_dbg(nau8824->dev, "Sysclk is %dHz and clock id is %d\n", freq, in nau8824_config_sysclk()
1462 struct nau8824 *nau8824 = snd_soc_component_get_drvdata(component); in nau8824_set_sysclk() local
1464 return nau8824_config_sysclk(nau8824, clk_id, freq); in nau8824_set_sysclk()
1467 static void nau8824_resume_setup(struct nau8824 *nau8824) in nau8824_resume_setup() argument
1469 nau8824_config_sysclk(nau8824, NAU8824_CLK_DIS, 0); in nau8824_resume_setup()
1470 if (nau8824->irq) { in nau8824_resume_setup()
1472 nau8824_int_status_clear_all(nau8824->regmap); in nau8824_resume_setup()
1476 regmap_update_bits(nau8824->regmap, NAU8824_REG_ENA_CTRL, in nau8824_resume_setup()
1478 regmap_update_bits(nau8824->regmap, in nau8824_resume_setup()
1482 regmap_update_bits(nau8824->regmap, in nau8824_resume_setup()
1491 struct nau8824 *nau8824 = snd_soc_component_get_drvdata(component); in nau8824_set_bias_level() local
1503 nau8824_resume_setup(nau8824); in nau8824_set_bias_level()
1508 regmap_update_bits(nau8824->regmap, in nau8824_set_bias_level()
1510 regmap_update_bits(nau8824->regmap, in nau8824_set_bias_level()
1521 struct nau8824 *nau8824 = snd_soc_component_get_drvdata(component); in nau8824_component_probe() local
1524 nau8824->dapm = dapm; in nau8824_component_probe()
1531 struct nau8824 *nau8824 = snd_soc_component_get_drvdata(component); in nau8824_suspend() local
1533 if (nau8824->irq) { in nau8824_suspend()
1534 disable_irq(nau8824->irq); in nau8824_suspend()
1537 regcache_cache_only(nau8824->regmap, true); in nau8824_suspend()
1538 regcache_mark_dirty(nau8824->regmap); in nau8824_suspend()
1545 struct nau8824 *nau8824 = snd_soc_component_get_drvdata(component); in nau8824_resume() local
1548 regcache_cache_only(nau8824->regmap, false); in nau8824_resume()
1549 regcache_sync(nau8824->regmap); in nau8824_resume()
1550 if (nau8824->irq) { in nau8824_resume()
1554 nau8824->resume_lock = true; in nau8824_resume()
1555 ret = nau8824_sema_acquire(nau8824, 0); in nau8824_resume()
1557 nau8824->resume_lock = false; in nau8824_resume()
1558 enable_irq(nau8824->irq); in nau8824_resume()
1640 struct nau8824 *nau8824 = snd_soc_component_get_drvdata(component); in nau8824_enable_jack_detect() local
1643 nau8824->jack = jack; in nau8824_enable_jack_detect()
1645 INIT_WORK(&nau8824->jdet_work, nau8824_jdet_work); in nau8824_enable_jack_detect()
1646 ret = devm_request_threaded_irq(nau8824->dev, nau8824->irq, NULL, in nau8824_enable_jack_detect()
1648 "nau8824", nau8824); in nau8824_enable_jack_detect()
1650 dev_err(nau8824->dev, "Cannot request irq %d (%d)\n", in nau8824_enable_jack_detect()
1651 nau8824->irq, ret); in nau8824_enable_jack_detect()
1664 static void nau8824_setup_buttons(struct nau8824 *nau8824) in nau8824_setup_buttons() argument
1666 struct regmap *regmap = nau8824->regmap; in nau8824_setup_buttons()
1670 nau8824->sar_voltage << NAU8824_SAR_TRACKING_GAIN_SFT); in nau8824_setup_buttons()
1673 nau8824->sar_compare_time << NAU8824_SAR_COMPARE_TIME_SFT); in nau8824_setup_buttons()
1676 nau8824->sar_sampling_time << NAU8824_SAR_SAMPLING_TIME_SFT); in nau8824_setup_buttons()
1680 (nau8824->sar_threshold_num - 1) << NAU8824_LEVELS_NR_SFT); in nau8824_setup_buttons()
1683 nau8824->sar_hysteresis << NAU8824_HYSTERESIS_SFT); in nau8824_setup_buttons()
1686 nau8824->key_debounce << NAU8824_SHORTKEY_DEBOUNCE_SFT); in nau8824_setup_buttons()
1689 (nau8824->sar_threshold[0] << 8) | nau8824->sar_threshold[1]); in nau8824_setup_buttons()
1691 (nau8824->sar_threshold[2] << 8) | nau8824->sar_threshold[3]); in nau8824_setup_buttons()
1693 (nau8824->sar_threshold[4] << 8) | nau8824->sar_threshold[5]); in nau8824_setup_buttons()
1695 (nau8824->sar_threshold[6] << 8) | nau8824->sar_threshold[7]); in nau8824_setup_buttons()
1698 static void nau8824_init_regs(struct nau8824 *nau8824) in nau8824_init_regs() argument
1700 struct regmap *regmap = nau8824->regmap; in nau8824_init_regs()
1705 (nau8824->vref_impedance << NAU8824_VMID_SEL_SFT)); in nau8824_init_regs()
1710 NAU8824_MICBIAS_VOLTAGE_MASK, nau8824->micbias_voltage); in nau8824_init_regs()
1790 nau8824->jkdet_polarity ? 0 : NAU8824_JACK_LOGIC); in nau8824_init_regs()
1793 (nau8824->jack_eject_debounce << NAU8824_JACK_EJECT_DT_SFT)); in nau8824_init_regs()
1794 if (nau8824->sar_threshold_num) in nau8824_init_regs()
1795 nau8824_setup_buttons(nau8824); in nau8824_init_regs()
1798 static int nau8824_setup_irq(struct nau8824 *nau8824) in nau8824_setup_irq() argument
1801 regmap_update_bits(nau8824->regmap, NAU8824_REG_ENA_CTRL, in nau8824_setup_irq()
1803 regmap_update_bits(nau8824->regmap, in nau8824_setup_irq()
1805 regmap_update_bits(nau8824->regmap, NAU8824_REG_INTERRUPT_SETTING_1, in nau8824_setup_irq()
1811 static void nau8824_print_device_properties(struct nau8824 *nau8824) in nau8824_print_device_properties() argument
1813 struct device *dev = nau8824->dev; in nau8824_print_device_properties()
1816 dev_dbg(dev, "jkdet-polarity: %d\n", nau8824->jkdet_polarity); in nau8824_print_device_properties()
1817 dev_dbg(dev, "micbias-voltage: %d\n", nau8824->micbias_voltage); in nau8824_print_device_properties()
1818 dev_dbg(dev, "vref-impedance: %d\n", nau8824->vref_impedance); in nau8824_print_device_properties()
1820 dev_dbg(dev, "sar-threshold-num: %d\n", nau8824->sar_threshold_num); in nau8824_print_device_properties()
1821 for (i = 0; i < nau8824->sar_threshold_num; i++) in nau8824_print_device_properties()
1823 nau8824->sar_threshold[i]); in nau8824_print_device_properties()
1825 dev_dbg(dev, "sar-hysteresis: %d\n", nau8824->sar_hysteresis); in nau8824_print_device_properties()
1826 dev_dbg(dev, "sar-voltage: %d\n", nau8824->sar_voltage); in nau8824_print_device_properties()
1827 dev_dbg(dev, "sar-compare-time: %d\n", nau8824->sar_compare_time); in nau8824_print_device_properties()
1828 dev_dbg(dev, "sar-sampling-time: %d\n", nau8824->sar_sampling_time); in nau8824_print_device_properties()
1829 dev_dbg(dev, "short-key-debounce: %d\n", nau8824->key_debounce); in nau8824_print_device_properties()
1831 nau8824->jack_eject_debounce); in nau8824_print_device_properties()
1835 struct nau8824 *nau8824) { in nau8824_read_device_properties() argument
1839 &nau8824->jkdet_polarity); in nau8824_read_device_properties()
1841 nau8824->jkdet_polarity = 1; in nau8824_read_device_properties()
1843 &nau8824->micbias_voltage); in nau8824_read_device_properties()
1845 nau8824->micbias_voltage = 6; in nau8824_read_device_properties()
1847 &nau8824->vref_impedance); in nau8824_read_device_properties()
1849 nau8824->vref_impedance = 2; in nau8824_read_device_properties()
1851 &nau8824->sar_threshold_num); in nau8824_read_device_properties()
1853 nau8824->sar_threshold_num = 4; in nau8824_read_device_properties()
1855 nau8824->sar_threshold, nau8824->sar_threshold_num); in nau8824_read_device_properties()
1857 nau8824->sar_threshold[0] = 0x0a; in nau8824_read_device_properties()
1858 nau8824->sar_threshold[1] = 0x14; in nau8824_read_device_properties()
1859 nau8824->sar_threshold[2] = 0x26; in nau8824_read_device_properties()
1860 nau8824->sar_threshold[3] = 0x73; in nau8824_read_device_properties()
1863 &nau8824->sar_hysteresis); in nau8824_read_device_properties()
1865 nau8824->sar_hysteresis = 0; in nau8824_read_device_properties()
1867 &nau8824->sar_voltage); in nau8824_read_device_properties()
1869 nau8824->sar_voltage = 6; in nau8824_read_device_properties()
1871 &nau8824->sar_compare_time); in nau8824_read_device_properties()
1873 nau8824->sar_compare_time = 1; in nau8824_read_device_properties()
1875 &nau8824->sar_sampling_time); in nau8824_read_device_properties()
1877 nau8824->sar_sampling_time = 1; in nau8824_read_device_properties()
1879 &nau8824->key_debounce); in nau8824_read_device_properties()
1881 nau8824->key_debounce = 0; in nau8824_read_device_properties()
1883 &nau8824->jack_eject_debounce); in nau8824_read_device_properties()
1885 nau8824->jack_eject_debounce = 1; in nau8824_read_device_properties()
1887 nau8824->mclk = devm_clk_get_optional(dev, "mclk"); in nau8824_read_device_properties()
1888 if (IS_ERR(nau8824->mclk)) in nau8824_read_device_properties()
1889 return PTR_ERR(nau8824->mclk); in nau8824_read_device_properties()
1978 struct nau8824 *nau8824 = dev_get_platdata(dev); in nau8824_i2c_probe() local
1981 if (!nau8824) { in nau8824_i2c_probe()
1982 nau8824 = devm_kzalloc(dev, sizeof(*nau8824), GFP_KERNEL); in nau8824_i2c_probe()
1983 if (!nau8824) in nau8824_i2c_probe()
1985 ret = nau8824_read_device_properties(dev, nau8824); in nau8824_i2c_probe()
1989 i2c_set_clientdata(i2c, nau8824); in nau8824_i2c_probe()
1991 nau8824->regmap = devm_regmap_init_i2c(i2c, &nau8824_regmap_config); in nau8824_i2c_probe()
1992 if (IS_ERR(nau8824->regmap)) in nau8824_i2c_probe()
1993 return PTR_ERR(nau8824->regmap); in nau8824_i2c_probe()
1994 nau8824->resume_lock = false; in nau8824_i2c_probe()
1995 nau8824->dev = dev; in nau8824_i2c_probe()
1996 nau8824->irq = i2c->irq; in nau8824_i2c_probe()
1997 sema_init(&nau8824->jd_sem, 1); in nau8824_i2c_probe()
2002 nau8824->jkdet_polarity = 0; in nau8824_i2c_probe()
2004 nau8824_print_device_properties(nau8824); in nau8824_i2c_probe()
2006 ret = regmap_read(nau8824->regmap, NAU8824_REG_I2C_DEVICE_ID, &value); in nau8824_i2c_probe()
2012 nau8824_reset_chip(nau8824->regmap); in nau8824_i2c_probe()
2013 nau8824_init_regs(nau8824); in nau8824_i2c_probe()
2016 nau8824_setup_irq(nau8824); in nau8824_i2c_probe()