Lines Matching +full:sense +full:- +full:freq

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, -9600, 100, false);
404 static DECLARE_TLV_DB_SCALE(mixer_tlv, -6200, 100, false);
448 SOC_ENUM("HPF Corner Freq", cs42l42_hpf_freq_enum),
449 SOC_ENUM("WNF 3dB Freq", cs42l42_wnf3_freq_enum),
450 SOC_ENUM("WNF 05dB Freq", cs42l42_wnf05_freq_enum),
467 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in cs42l42_hpdrv_evt()
493 dev_err(component->dev, "Invalid event 0x%x\n", event); in cs42l42_hpdrv_evt()
527 regcache_cache_only(cs42l42->regmap, false); in cs42l42_set_bias_level()
528 regcache_sync(cs42l42->regmap); in cs42l42_set_bias_level()
530 ARRAY_SIZE(cs42l42->supplies), in cs42l42_set_bias_level()
531 cs42l42->supplies); in cs42l42_set_bias_level()
533 dev_err(component->dev, in cs42l42_set_bias_level()
542 regcache_cache_only(cs42l42->regmap, true); in cs42l42_set_bias_level()
543 regulator_bulk_disable(ARRAY_SIZE(cs42l42->supplies), in cs42l42_set_bias_level()
544 cs42l42->supplies); in cs42l42_set_bias_level()
556 cs42l42->component = component; in cs42l42_component_probe()
590 * Table 4-5 from the Datasheet
617 if (pll_ratio_table[i].sclk == cs42l42->sclk) { in cs42l42_pll_config()
637 fsync = cs42l42->sclk / cs42l42->srate; in cs42l42_pll_config()
638 if (((fsync * cs42l42->srate) != cs42l42->sclk) in cs42l42_pll_config()
640 dev_err(component->dev, in cs42l42_pll_config()
642 cs42l42->sclk, in cs42l42_pll_config()
643 cs42l42->srate); in cs42l42_pll_config()
644 return -EINVAL; in cs42l42_pll_config()
650 CS42L42_FRAC0_VAL(fsync - 1) << in cs42l42_pll_config()
655 CS42L42_FRAC1_VAL(fsync - 1) << in cs42l42_pll_config()
662 CS42L42_FRAC0_VAL(fsync - 1) << in cs42l42_pll_config()
667 CS42L42_FRAC1_VAL(fsync - 1) << in cs42l42_pll_config()
718 /* Configure PLL per table 4-5 */ in cs42l42_pll_config()
767 return -EINVAL; in cs42l42_pll_config()
772 struct snd_soc_component *component = codec_dai->component; in cs42l42_set_dai_fmt()
785 return -EINVAL; in cs42l42_set_dai_fmt()
794 return -EINVAL; in cs42l42_set_dai_fmt()
829 struct snd_soc_component *component = dai->component; in cs42l42_pcm_hw_params()
833 cs42l42->srate = params_rate(params); in cs42l42_pcm_hw_params()
834 cs42l42->swidth = params_width(params); in cs42l42_pcm_hw_params()
842 int clk_id, unsigned int freq, int dir) in cs42l42_set_sysclk() argument
844 struct snd_soc_component *component = dai->component; in cs42l42_set_sysclk()
847 cs42l42->sclk = freq; in cs42l42_set_sysclk()
854 struct snd_soc_component *component = dai->component; in cs42l42_mute()
888 /* Un-mute the headphone, set the full scale volume flag */ in cs42l42_mute()
941 regmap_update_bits(cs42l42->regmap, in cs42l42_process_hs_type_detect()
949 regmap_update_bits(cs42l42->regmap, in cs42l42_process_hs_type_detect()
961 regmap_read(cs42l42->regmap, CS42L42_HS_DET_STATUS, &hs_det_status); in cs42l42_process_hs_type_detect()
963 cs42l42->hs_type = (hs_det_status & CS42L42_HSDET_TYPE_MASK) >> in cs42l42_process_hs_type_detect()
967 if ((cs42l42->hs_type == CS42L42_PLUG_CTIA) || in cs42l42_process_hs_type_detect()
968 (cs42l42->hs_type == CS42L42_PLUG_OMTP)) { in cs42l42_process_hs_type_detect()
970 regmap_update_bits(cs42l42->regmap, in cs42l42_process_hs_type_detect()
982 regmap_update_bits(cs42l42->regmap, in cs42l42_process_hs_type_detect()
989 (cs42l42->bias_thresholds[0] << in cs42l42_process_hs_type_detect()
993 regmap_update_bits(cs42l42->regmap, in cs42l42_process_hs_type_detect()
1005 regmap_update_bits(cs42l42->regmap, in cs42l42_process_hs_type_detect()
1014 msleep(cs42l42->btn_det_init_dbnce); in cs42l42_process_hs_type_detect()
1017 regmap_read(cs42l42->regmap, CS42L42_DET_INT_STATUS2, in cs42l42_process_hs_type_detect()
1021 regmap_update_bits(cs42l42->regmap, in cs42l42_process_hs_type_detect()
1035 regmap_update_bits(cs42l42->regmap, in cs42l42_process_hs_type_detect()
1045 regmap_update_bits(cs42l42->regmap, in cs42l42_process_hs_type_detect()
1058 /* Unmask tip sense interrupts */ in cs42l42_process_hs_type_detect()
1059 regmap_update_bits(cs42l42->regmap, in cs42l42_process_hs_type_detect()
1073 /* Mask tip sense interrupts */ in cs42l42_init_hs_type_detect()
1074 regmap_update_bits(cs42l42->regmap, in cs42l42_init_hs_type_detect()
1086 regmap_update_bits(cs42l42->regmap, in cs42l42_init_hs_type_detect()
1096 regmap_update_bits(cs42l42->regmap, in cs42l42_init_hs_type_detect()
1108 regmap_update_bits(cs42l42->regmap, in cs42l42_init_hs_type_detect()
1119 regmap_update_bits(cs42l42->regmap, in cs42l42_init_hs_type_detect()
1133 regmap_update_bits(cs42l42->regmap, in cs42l42_init_hs_type_detect()
1143 msleep(cs42l42->hs_bias_ramp_time); in cs42l42_init_hs_type_detect()
1146 regmap_update_bits(cs42l42->regmap, in cs42l42_init_hs_type_detect()
1154 regmap_update_bits(cs42l42->regmap, in cs42l42_init_hs_type_detect()
1169 regmap_update_bits(cs42l42->regmap, in cs42l42_cancel_hs_type_detect()
1183 regmap_update_bits(cs42l42->regmap, in cs42l42_cancel_hs_type_detect()
1193 regmap_update_bits(cs42l42->regmap, in cs42l42_cancel_hs_type_detect()
1205 regmap_update_bits(cs42l42->regmap, in cs42l42_cancel_hs_type_detect()
1223 regmap_update_bits(cs42l42->regmap, in cs42l42_handle_button_press()
1236 usleep_range(cs42l42->btn_det_event_dbnce * 1000, in cs42l42_handle_button_press()
1237 cs42l42->btn_det_event_dbnce * 2000); in cs42l42_handle_button_press()
1243 regmap_update_bits(cs42l42->regmap, in cs42l42_handle_button_press()
1250 (cs42l42->bias_thresholds[bias_level] << in cs42l42_handle_button_press()
1253 regmap_read(cs42l42->regmap, CS42L42_DET_STATUS2, in cs42l42_handle_button_press()
1260 dev_dbg(cs42l42->component->dev, "Function C button press\n"); in cs42l42_handle_button_press()
1263 dev_dbg(cs42l42->component->dev, "Function B button press\n"); in cs42l42_handle_button_press()
1266 dev_dbg(cs42l42->component->dev, "Function D button press\n"); in cs42l42_handle_button_press()
1269 dev_dbg(cs42l42->component->dev, "Function A button press\n"); in cs42l42_handle_button_press()
1274 regmap_update_bits(cs42l42->regmap, in cs42l42_handle_button_press()
1281 (cs42l42->bias_thresholds[0] << CS42L42_HS_DET_LEVEL_SHIFT)); in cs42l42_handle_button_press()
1284 regmap_read(cs42l42->regmap, CS42L42_DET_INT_STATUS2, in cs42l42_handle_button_press()
1288 regmap_update_bits(cs42l42->regmap, in cs42l42_handle_button_press()
1338 struct snd_soc_component *component = cs42l42->component; in cs42l42_irq_thread()
1347 regmap_read(cs42l42->regmap, irq_params_table[i].status_addr, in cs42l42_irq_thread()
1349 regmap_read(cs42l42->regmap, irq_params_table[i].mask_addr, in cs42l42_irq_thread()
1355 /* Read tip sense status before handling type detect */ in cs42l42_irq_thread()
1360 /* Read button sense status */ in cs42l42_irq_thread()
1366 /* Check auto-detect status */ in cs42l42_irq_thread()
1370 dev_dbg(component->dev, in cs42l42_irq_thread()
1372 cs42l42->hs_type); in cs42l42_irq_thread()
1376 /* Check tip sense status */ in cs42l42_irq_thread()
1380 if (cs42l42->plug_state != CS42L42_TS_PLUG) { in cs42l42_irq_thread()
1381 cs42l42->plug_state = CS42L42_TS_PLUG; in cs42l42_irq_thread()
1387 if (cs42l42->plug_state != CS42L42_TS_UNPLUG) { in cs42l42_irq_thread()
1388 cs42l42->plug_state = CS42L42_TS_UNPLUG; in cs42l42_irq_thread()
1390 dev_dbg(component->dev, in cs42l42_irq_thread()
1396 if (cs42l42->plug_state != CS42L42_TS_TRANS) in cs42l42_irq_thread()
1397 cs42l42->plug_state = CS42L42_TS_TRANS; in cs42l42_irq_thread()
1408 dev_dbg(component->dev, in cs42l42_irq_thread()
1422 regmap_update_bits(cs42l42->regmap, CS42L42_ADC_OVFL_INT_MASK, in cs42l42_set_interrupt_masks()
1426 regmap_update_bits(cs42l42->regmap, CS42L42_MIXER_INT_MASK, in cs42l42_set_interrupt_masks()
1436 regmap_update_bits(cs42l42->regmap, CS42L42_SRC_INT_MASK, in cs42l42_set_interrupt_masks()
1446 regmap_update_bits(cs42l42->regmap, CS42L42_ASP_RX_INT_MASK, in cs42l42_set_interrupt_masks()
1458 regmap_update_bits(cs42l42->regmap, CS42L42_ASP_TX_INT_MASK, in cs42l42_set_interrupt_masks()
1468 regmap_update_bits(cs42l42->regmap, CS42L42_CODEC_INT_MASK, in cs42l42_set_interrupt_masks()
1474 regmap_update_bits(cs42l42->regmap, CS42L42_SRCPL_INT_MASK, in cs42l42_set_interrupt_masks()
1484 regmap_update_bits(cs42l42->regmap, CS42L42_DET_INT1_MASK, in cs42l42_set_interrupt_masks()
1492 regmap_update_bits(cs42l42->regmap, CS42L42_DET_INT2_MASK, in cs42l42_set_interrupt_masks()
1504 regmap_update_bits(cs42l42->regmap, CS42L42_VPMON_INT_MASK, in cs42l42_set_interrupt_masks()
1508 regmap_update_bits(cs42l42->regmap, CS42L42_PLL_LOCK_INT_MASK, in cs42l42_set_interrupt_masks()
1512 regmap_update_bits(cs42l42->regmap, CS42L42_TSRS_PLUG_INT_MASK, in cs42l42_set_interrupt_masks()
1527 cs42l42->hs_type = CS42L42_PLUG_INVALID; in cs42l42_setup_hs_type_detect()
1530 regmap_update_bits(cs42l42->regmap, CS42L42_MIC_DET_CTL1, in cs42l42_setup_hs_type_detect()
1536 (cs42l42->bias_thresholds[0] << in cs42l42_setup_hs_type_detect()
1539 /* Remove ground noise-suppression clamps */ in cs42l42_setup_hs_type_detect()
1540 regmap_update_bits(cs42l42->regmap, in cs42l42_setup_hs_type_detect()
1545 /* Enable the tip sense circuit */ in cs42l42_setup_hs_type_detect()
1546 regmap_update_bits(cs42l42->regmap, CS42L42_TIPSENSE_CTL, in cs42l42_setup_hs_type_detect()
1554 /* Save the initial status of the tip sense */ in cs42l42_setup_hs_type_detect()
1555 regmap_read(cs42l42->regmap, in cs42l42_setup_hs_type_detect()
1558 cs42l42->plug_state = (((char) reg) & in cs42l42_setup_hs_type_detect()
1573 struct device_node *np = i2c_client->dev.of_node; in cs42l42_handle_device_data()
1579 ret = of_property_read_u32(np, "cirrus,ts-inv", &val); in cs42l42_handle_device_data()
1585 cs42l42->ts_inv = val; in cs42l42_handle_device_data()
1588 dev_err(&i2c_client->dev, in cs42l42_handle_device_data()
1589 "Wrong cirrus,ts-inv DT value %d\n", in cs42l42_handle_device_data()
1591 cs42l42->ts_inv = CS42L42_TS_INV_DIS; in cs42l42_handle_device_data()
1594 cs42l42->ts_inv = CS42L42_TS_INV_DIS; in cs42l42_handle_device_data()
1597 regmap_update_bits(cs42l42->regmap, CS42L42_TSENSE_CTL, in cs42l42_handle_device_data()
1599 (cs42l42->ts_inv << CS42L42_TS_INV_SHIFT)); in cs42l42_handle_device_data()
1601 ret = of_property_read_u32(np, "cirrus,ts-dbnc-rise", &val); in cs42l42_handle_device_data()
1613 cs42l42->ts_dbnc_rise = val; in cs42l42_handle_device_data()
1616 dev_err(&i2c_client->dev, in cs42l42_handle_device_data()
1617 "Wrong cirrus,ts-dbnc-rise DT value %d\n", in cs42l42_handle_device_data()
1619 cs42l42->ts_dbnc_rise = CS42L42_TS_DBNCE_1000; in cs42l42_handle_device_data()
1622 cs42l42->ts_dbnc_rise = CS42L42_TS_DBNCE_1000; in cs42l42_handle_device_data()
1625 regmap_update_bits(cs42l42->regmap, CS42L42_TSENSE_CTL, in cs42l42_handle_device_data()
1627 (cs42l42->ts_dbnc_rise << in cs42l42_handle_device_data()
1630 ret = of_property_read_u32(np, "cirrus,ts-dbnc-fall", &val); in cs42l42_handle_device_data()
1642 cs42l42->ts_dbnc_fall = val; in cs42l42_handle_device_data()
1645 dev_err(&i2c_client->dev, in cs42l42_handle_device_data()
1646 "Wrong cirrus,ts-dbnc-fall DT value %d\n", in cs42l42_handle_device_data()
1648 cs42l42->ts_dbnc_fall = CS42L42_TS_DBNCE_0; in cs42l42_handle_device_data()
1651 cs42l42->ts_dbnc_fall = CS42L42_TS_DBNCE_0; in cs42l42_handle_device_data()
1654 regmap_update_bits(cs42l42->regmap, CS42L42_TSENSE_CTL, in cs42l42_handle_device_data()
1656 (cs42l42->ts_dbnc_fall << in cs42l42_handle_device_data()
1659 ret = of_property_read_u32(np, "cirrus,btn-det-init-dbnce", &val); in cs42l42_handle_device_data()
1663 cs42l42->btn_det_init_dbnce = val; in cs42l42_handle_device_data()
1665 dev_err(&i2c_client->dev, in cs42l42_handle_device_data()
1666 "Wrong cirrus,btn-det-init-dbnce DT value %d\n", in cs42l42_handle_device_data()
1668 cs42l42->btn_det_init_dbnce = in cs42l42_handle_device_data()
1672 cs42l42->btn_det_init_dbnce = in cs42l42_handle_device_data()
1676 ret = of_property_read_u32(np, "cirrus,btn-det-event-dbnce", &val); in cs42l42_handle_device_data()
1680 cs42l42->btn_det_event_dbnce = val; in cs42l42_handle_device_data()
1682 dev_err(&i2c_client->dev, in cs42l42_handle_device_data()
1683 "Wrong cirrus,btn-det-event-dbnce DT value %d\n", val); in cs42l42_handle_device_data()
1684 cs42l42->btn_det_event_dbnce = in cs42l42_handle_device_data()
1688 cs42l42->btn_det_event_dbnce = in cs42l42_handle_device_data()
1692 ret = of_property_read_u32_array(np, "cirrus,bias-lvls", in cs42l42_handle_device_data()
1698 cs42l42->bias_thresholds[i] = thresholds[i]; in cs42l42_handle_device_data()
1700 dev_err(&i2c_client->dev, in cs42l42_handle_device_data()
1701 "Wrong cirrus,bias-lvls[%d] DT value %d\n", i, in cs42l42_handle_device_data()
1703 cs42l42->bias_thresholds[i] = in cs42l42_handle_device_data()
1709 cs42l42->bias_thresholds[i] = threshold_defaults[i]; in cs42l42_handle_device_data()
1712 ret = of_property_read_u32(np, "cirrus,hs-bias-ramp-rate", &val); in cs42l42_handle_device_data()
1717 cs42l42->hs_bias_ramp_rate = val; in cs42l42_handle_device_data()
1718 cs42l42->hs_bias_ramp_time = CS42L42_HSBIAS_RAMP_TIME0; in cs42l42_handle_device_data()
1721 cs42l42->hs_bias_ramp_rate = val; in cs42l42_handle_device_data()
1722 cs42l42->hs_bias_ramp_time = CS42L42_HSBIAS_RAMP_TIME1; in cs42l42_handle_device_data()
1725 cs42l42->hs_bias_ramp_rate = val; in cs42l42_handle_device_data()
1726 cs42l42->hs_bias_ramp_time = CS42L42_HSBIAS_RAMP_TIME2; in cs42l42_handle_device_data()
1729 cs42l42->hs_bias_ramp_rate = val; in cs42l42_handle_device_data()
1730 cs42l42->hs_bias_ramp_time = CS42L42_HSBIAS_RAMP_TIME3; in cs42l42_handle_device_data()
1733 dev_err(&i2c_client->dev, in cs42l42_handle_device_data()
1734 "Wrong cirrus,hs-bias-ramp-rate DT value %d\n", in cs42l42_handle_device_data()
1736 cs42l42->hs_bias_ramp_rate = CS42L42_HSBIAS_RAMP_SLOW; in cs42l42_handle_device_data()
1737 cs42l42->hs_bias_ramp_time = CS42L42_HSBIAS_RAMP_TIME2; in cs42l42_handle_device_data()
1740 cs42l42->hs_bias_ramp_rate = CS42L42_HSBIAS_RAMP_SLOW; in cs42l42_handle_device_data()
1741 cs42l42->hs_bias_ramp_time = CS42L42_HSBIAS_RAMP_TIME2; in cs42l42_handle_device_data()
1744 regmap_update_bits(cs42l42->regmap, CS42L42_HS_BIAS_CTL, in cs42l42_handle_device_data()
1746 (cs42l42->hs_bias_ramp_rate << in cs42l42_handle_device_data()
1760 cs42l42 = devm_kzalloc(&i2c_client->dev, sizeof(struct cs42l42_private), in cs42l42_i2c_probe()
1763 return -ENOMEM; in cs42l42_i2c_probe()
1767 cs42l42->regmap = devm_regmap_init_i2c(i2c_client, &cs42l42_regmap); in cs42l42_i2c_probe()
1768 if (IS_ERR(cs42l42->regmap)) { in cs42l42_i2c_probe()
1769 ret = PTR_ERR(cs42l42->regmap); in cs42l42_i2c_probe()
1770 dev_err(&i2c_client->dev, "regmap_init() failed: %d\n", ret); in cs42l42_i2c_probe()
1774 for (i = 0; i < ARRAY_SIZE(cs42l42->supplies); i++) in cs42l42_i2c_probe()
1775 cs42l42->supplies[i].supply = cs42l42_supply_names[i]; in cs42l42_i2c_probe()
1777 ret = devm_regulator_bulk_get(&i2c_client->dev, in cs42l42_i2c_probe()
1778 ARRAY_SIZE(cs42l42->supplies), in cs42l42_i2c_probe()
1779 cs42l42->supplies); in cs42l42_i2c_probe()
1781 dev_err(&i2c_client->dev, in cs42l42_i2c_probe()
1786 ret = regulator_bulk_enable(ARRAY_SIZE(cs42l42->supplies), in cs42l42_i2c_probe()
1787 cs42l42->supplies); in cs42l42_i2c_probe()
1789 dev_err(&i2c_client->dev, in cs42l42_i2c_probe()
1795 cs42l42->reset_gpio = devm_gpiod_get_optional(&i2c_client->dev, in cs42l42_i2c_probe()
1797 if (IS_ERR(cs42l42->reset_gpio)) in cs42l42_i2c_probe()
1798 return PTR_ERR(cs42l42->reset_gpio); in cs42l42_i2c_probe()
1800 if (cs42l42->reset_gpio) { in cs42l42_i2c_probe()
1801 dev_dbg(&i2c_client->dev, "Found reset GPIO\n"); in cs42l42_i2c_probe()
1802 gpiod_set_value_cansleep(cs42l42->reset_gpio, 1); in cs42l42_i2c_probe()
1807 ret = devm_request_threaded_irq(&i2c_client->dev, in cs42l42_i2c_probe()
1808 i2c_client->irq, in cs42l42_i2c_probe()
1814 dev_err(&i2c_client->dev, in cs42l42_i2c_probe()
1818 ret = regmap_read(cs42l42->regmap, CS42L42_DEVID_AB, &reg); in cs42l42_i2c_probe()
1821 ret = regmap_read(cs42l42->regmap, CS42L42_DEVID_CD, &reg); in cs42l42_i2c_probe()
1824 ret = regmap_read(cs42l42->regmap, CS42L42_DEVID_E, &reg); in cs42l42_i2c_probe()
1828 ret = -ENODEV; in cs42l42_i2c_probe()
1829 dev_err(&i2c_client->dev, in cs42l42_i2c_probe()
1835 ret = regmap_read(cs42l42->regmap, CS42L42_REVID, &reg); in cs42l42_i2c_probe()
1837 dev_err(&i2c_client->dev, "Get Revision ID failed\n"); in cs42l42_i2c_probe()
1841 dev_info(&i2c_client->dev, in cs42l42_i2c_probe()
1845 regmap_update_bits(cs42l42->regmap, CS42L42_PWR_CTL1, in cs42l42_i2c_probe()
1861 if (i2c_client->dev.of_node) { in cs42l42_i2c_probe()
1874 ret = devm_snd_soc_register_component(&i2c_client->dev, in cs42l42_i2c_probe()
1881 regulator_bulk_disable(ARRAY_SIZE(cs42l42->supplies), in cs42l42_i2c_probe()
1882 cs42l42->supplies); in cs42l42_i2c_probe()
1891 gpiod_set_value_cansleep(cs42l42->reset_gpio, 0); in cs42l42_i2c_remove()
1901 regcache_cache_only(cs42l42->regmap, true); in cs42l42_runtime_suspend()
1902 regcache_mark_dirty(cs42l42->regmap); in cs42l42_runtime_suspend()
1905 gpiod_set_value_cansleep(cs42l42->reset_gpio, 0); in cs42l42_runtime_suspend()
1908 regulator_bulk_disable(ARRAY_SIZE(cs42l42->supplies), in cs42l42_runtime_suspend()
1909 cs42l42->supplies); in cs42l42_runtime_suspend()
1920 ret = regulator_bulk_enable(ARRAY_SIZE(cs42l42->supplies), in cs42l42_runtime_resume()
1921 cs42l42->supplies); in cs42l42_runtime_resume()
1928 gpiod_set_value_cansleep(cs42l42->reset_gpio, 1); in cs42l42_runtime_resume()
1930 regcache_cache_only(cs42l42->regmap, false); in cs42l42_runtime_resume()
1931 regcache_sync(cs42l42->regmap); in cs42l42_runtime_resume()