Lines Matching full:cs42l42
3 * cs42l42.c -- CS42L42 ALSA SoC audio driver
34 #include <dt-bindings/sound/cs42l42.h>
36 #include "cs42l42.h"
508 struct cs42l42_private *cs42l42 = snd_soc_component_get_drvdata(component); in cs42l42_set_bias_level() local
518 regcache_cache_only(cs42l42->regmap, false); in cs42l42_set_bias_level()
519 regcache_sync(cs42l42->regmap); in cs42l42_set_bias_level()
521 ARRAY_SIZE(cs42l42->supplies), in cs42l42_set_bias_level()
522 cs42l42->supplies); in cs42l42_set_bias_level()
533 regcache_cache_only(cs42l42->regmap, true); in cs42l42_set_bias_level()
534 regulator_bulk_disable(ARRAY_SIZE(cs42l42->supplies), in cs42l42_set_bias_level()
535 cs42l42->supplies); in cs42l42_set_bias_level()
544 struct cs42l42_private *cs42l42 = in cs42l42_component_probe() local
547 cs42l42->component = component; in cs42l42_component_probe()
603 struct cs42l42_private *cs42l42 = snd_soc_component_get_drvdata(component); in cs42l42_pll_config() local
608 if (pll_ratio_table[i].sclk == cs42l42->sclk) { in cs42l42_pll_config()
628 fsync = cs42l42->sclk / cs42l42->srate; in cs42l42_pll_config()
629 if (((fsync * cs42l42->srate) != cs42l42->sclk) in cs42l42_pll_config()
633 cs42l42->sclk, in cs42l42_pll_config()
634 cs42l42->srate); in cs42l42_pll_config()
801 struct cs42l42_private *cs42l42 = snd_soc_component_get_drvdata(component); in cs42l42_pcm_hw_params() local
805 cs42l42->srate = params_rate(params); in cs42l42_pcm_hw_params()
831 struct cs42l42_private *cs42l42 = snd_soc_component_get_drvdata(component); in cs42l42_set_sysclk() local
833 cs42l42->sclk = freq; in cs42l42_set_sysclk()
903 .name = "cs42l42",
921 static void cs42l42_process_hs_type_detect(struct cs42l42_private *cs42l42) in cs42l42_process_hs_type_detect() argument
927 regmap_update_bits(cs42l42->regmap, in cs42l42_process_hs_type_detect()
935 regmap_update_bits(cs42l42->regmap, in cs42l42_process_hs_type_detect()
947 regmap_read(cs42l42->regmap, CS42L42_HS_DET_STATUS, &hs_det_status); in cs42l42_process_hs_type_detect()
949 cs42l42->hs_type = (hs_det_status & CS42L42_HSDET_TYPE_MASK) >> in cs42l42_process_hs_type_detect()
953 if ((cs42l42->hs_type == CS42L42_PLUG_CTIA) || in cs42l42_process_hs_type_detect()
954 (cs42l42->hs_type == CS42L42_PLUG_OMTP)) { in cs42l42_process_hs_type_detect()
956 regmap_update_bits(cs42l42->regmap, in cs42l42_process_hs_type_detect()
968 regmap_update_bits(cs42l42->regmap, in cs42l42_process_hs_type_detect()
975 (cs42l42->bias_thresholds[0] << in cs42l42_process_hs_type_detect()
979 regmap_update_bits(cs42l42->regmap, in cs42l42_process_hs_type_detect()
991 regmap_update_bits(cs42l42->regmap, in cs42l42_process_hs_type_detect()
1000 msleep(cs42l42->btn_det_init_dbnce); in cs42l42_process_hs_type_detect()
1003 regmap_read(cs42l42->regmap, CS42L42_DET_INT_STATUS2, in cs42l42_process_hs_type_detect()
1007 regmap_update_bits(cs42l42->regmap, in cs42l42_process_hs_type_detect()
1021 regmap_update_bits(cs42l42->regmap, in cs42l42_process_hs_type_detect()
1031 regmap_update_bits(cs42l42->regmap, in cs42l42_process_hs_type_detect()
1045 regmap_update_bits(cs42l42->regmap, in cs42l42_process_hs_type_detect()
1057 static void cs42l42_init_hs_type_detect(struct cs42l42_private *cs42l42) in cs42l42_init_hs_type_detect() argument
1060 regmap_update_bits(cs42l42->regmap, in cs42l42_init_hs_type_detect()
1072 regmap_update_bits(cs42l42->regmap, in cs42l42_init_hs_type_detect()
1082 regmap_update_bits(cs42l42->regmap, in cs42l42_init_hs_type_detect()
1094 regmap_update_bits(cs42l42->regmap, in cs42l42_init_hs_type_detect()
1105 regmap_update_bits(cs42l42->regmap, in cs42l42_init_hs_type_detect()
1119 regmap_update_bits(cs42l42->regmap, in cs42l42_init_hs_type_detect()
1129 msleep(cs42l42->hs_bias_ramp_time); in cs42l42_init_hs_type_detect()
1132 regmap_update_bits(cs42l42->regmap, in cs42l42_init_hs_type_detect()
1140 regmap_update_bits(cs42l42->regmap, in cs42l42_init_hs_type_detect()
1152 static void cs42l42_cancel_hs_type_detect(struct cs42l42_private *cs42l42) in cs42l42_cancel_hs_type_detect() argument
1155 regmap_update_bits(cs42l42->regmap, in cs42l42_cancel_hs_type_detect()
1169 regmap_update_bits(cs42l42->regmap, in cs42l42_cancel_hs_type_detect()
1179 regmap_update_bits(cs42l42->regmap, in cs42l42_cancel_hs_type_detect()
1191 regmap_update_bits(cs42l42->regmap, in cs42l42_cancel_hs_type_detect()
1203 static void cs42l42_handle_button_press(struct cs42l42_private *cs42l42) in cs42l42_handle_button_press() argument
1209 regmap_update_bits(cs42l42->regmap, in cs42l42_handle_button_press()
1222 usleep_range(cs42l42->btn_det_event_dbnce * 1000, in cs42l42_handle_button_press()
1223 cs42l42->btn_det_event_dbnce * 2000); in cs42l42_handle_button_press()
1229 regmap_update_bits(cs42l42->regmap, in cs42l42_handle_button_press()
1236 (cs42l42->bias_thresholds[bias_level] << in cs42l42_handle_button_press()
1239 regmap_read(cs42l42->regmap, CS42L42_DET_STATUS2, in cs42l42_handle_button_press()
1246 dev_dbg(cs42l42->component->dev, "Function C button press\n"); in cs42l42_handle_button_press()
1249 dev_dbg(cs42l42->component->dev, "Function B button press\n"); in cs42l42_handle_button_press()
1252 dev_dbg(cs42l42->component->dev, "Function D button press\n"); in cs42l42_handle_button_press()
1255 dev_dbg(cs42l42->component->dev, "Function A button press\n"); in cs42l42_handle_button_press()
1260 regmap_update_bits(cs42l42->regmap, in cs42l42_handle_button_press()
1267 (cs42l42->bias_thresholds[0] << CS42L42_HS_DET_LEVEL_SHIFT)); in cs42l42_handle_button_press()
1270 regmap_read(cs42l42->regmap, CS42L42_DET_INT_STATUS2, in cs42l42_handle_button_press()
1274 regmap_update_bits(cs42l42->regmap, in cs42l42_handle_button_press()
1323 struct cs42l42_private *cs42l42 = (struct cs42l42_private *)data; in cs42l42_irq_thread() local
1324 struct snd_soc_component *component = cs42l42->component; in cs42l42_irq_thread()
1333 regmap_read(cs42l42->regmap, irq_params_table[i].status_addr, in cs42l42_irq_thread()
1335 regmap_read(cs42l42->regmap, irq_params_table[i].mask_addr, in cs42l42_irq_thread()
1355 cs42l42_process_hs_type_detect(cs42l42); in cs42l42_irq_thread()
1358 cs42l42->hs_type); in cs42l42_irq_thread()
1366 if (cs42l42->plug_state != CS42L42_TS_PLUG) { in cs42l42_irq_thread()
1367 cs42l42->plug_state = CS42L42_TS_PLUG; in cs42l42_irq_thread()
1368 cs42l42_init_hs_type_detect(cs42l42); in cs42l42_irq_thread()
1373 if (cs42l42->plug_state != CS42L42_TS_UNPLUG) { in cs42l42_irq_thread()
1374 cs42l42->plug_state = CS42L42_TS_UNPLUG; in cs42l42_irq_thread()
1375 cs42l42_cancel_hs_type_detect(cs42l42); in cs42l42_irq_thread()
1382 if (cs42l42->plug_state != CS42L42_TS_TRANS) in cs42l42_irq_thread()
1383 cs42l42->plug_state = CS42L42_TS_TRANS; in cs42l42_irq_thread()
1398 cs42l42_handle_button_press(cs42l42); in cs42l42_irq_thread()
1406 static void cs42l42_set_interrupt_masks(struct cs42l42_private *cs42l42) in cs42l42_set_interrupt_masks() argument
1408 regmap_update_bits(cs42l42->regmap, CS42L42_ADC_OVFL_INT_MASK, in cs42l42_set_interrupt_masks()
1412 regmap_update_bits(cs42l42->regmap, CS42L42_MIXER_INT_MASK, in cs42l42_set_interrupt_masks()
1422 regmap_update_bits(cs42l42->regmap, CS42L42_SRC_INT_MASK, in cs42l42_set_interrupt_masks()
1432 regmap_update_bits(cs42l42->regmap, CS42L42_ASP_RX_INT_MASK, in cs42l42_set_interrupt_masks()
1444 regmap_update_bits(cs42l42->regmap, CS42L42_ASP_TX_INT_MASK, in cs42l42_set_interrupt_masks()
1454 regmap_update_bits(cs42l42->regmap, CS42L42_CODEC_INT_MASK, in cs42l42_set_interrupt_masks()
1460 regmap_update_bits(cs42l42->regmap, CS42L42_SRCPL_INT_MASK, in cs42l42_set_interrupt_masks()
1470 regmap_update_bits(cs42l42->regmap, CS42L42_DET_INT1_MASK, in cs42l42_set_interrupt_masks()
1478 regmap_update_bits(cs42l42->regmap, CS42L42_DET_INT2_MASK, in cs42l42_set_interrupt_masks()
1490 regmap_update_bits(cs42l42->regmap, CS42L42_VPMON_INT_MASK, in cs42l42_set_interrupt_masks()
1494 regmap_update_bits(cs42l42->regmap, CS42L42_PLL_LOCK_INT_MASK, in cs42l42_set_interrupt_masks()
1498 regmap_update_bits(cs42l42->regmap, CS42L42_TSRS_PLUG_INT_MASK, in cs42l42_set_interrupt_masks()
1509 static void cs42l42_setup_hs_type_detect(struct cs42l42_private *cs42l42) in cs42l42_setup_hs_type_detect() argument
1513 cs42l42->hs_type = CS42L42_PLUG_INVALID; in cs42l42_setup_hs_type_detect()
1516 regmap_update_bits(cs42l42->regmap, CS42L42_MIC_DET_CTL1, in cs42l42_setup_hs_type_detect()
1522 (cs42l42->bias_thresholds[0] << in cs42l42_setup_hs_type_detect()
1526 regmap_update_bits(cs42l42->regmap, in cs42l42_setup_hs_type_detect()
1532 regmap_update_bits(cs42l42->regmap, CS42L42_TSENSE_CTL, in cs42l42_setup_hs_type_detect()
1535 regmap_update_bits(cs42l42->regmap, CS42L42_TIPSENSE_CTL, in cs42l42_setup_hs_type_detect()
1540 (!cs42l42->ts_inv << CS42L42_TIP_SENSE_INV_SHIFT) | in cs42l42_setup_hs_type_detect()
1544 regmap_read(cs42l42->regmap, in cs42l42_setup_hs_type_detect()
1547 cs42l42->plug_state = (((char) reg) & in cs42l42_setup_hs_type_detect()
1560 struct cs42l42_private *cs42l42) in cs42l42_handle_device_data() argument
1572 cs42l42->ts_inv = val; in cs42l42_handle_device_data()
1578 cs42l42->ts_inv = CS42L42_TS_INV_DIS; in cs42l42_handle_device_data()
1581 cs42l42->ts_inv = CS42L42_TS_INV_DIS; in cs42l42_handle_device_data()
1595 cs42l42->ts_dbnc_rise = val; in cs42l42_handle_device_data()
1601 cs42l42->ts_dbnc_rise = CS42L42_TS_DBNCE_1000; in cs42l42_handle_device_data()
1604 cs42l42->ts_dbnc_rise = CS42L42_TS_DBNCE_1000; in cs42l42_handle_device_data()
1607 regmap_update_bits(cs42l42->regmap, CS42L42_TSENSE_CTL, in cs42l42_handle_device_data()
1609 (cs42l42->ts_dbnc_rise << in cs42l42_handle_device_data()
1623 cs42l42->ts_dbnc_fall = val; in cs42l42_handle_device_data()
1629 cs42l42->ts_dbnc_fall = CS42L42_TS_DBNCE_0; in cs42l42_handle_device_data()
1632 cs42l42->ts_dbnc_fall = CS42L42_TS_DBNCE_0; in cs42l42_handle_device_data()
1635 regmap_update_bits(cs42l42->regmap, CS42L42_TSENSE_CTL, in cs42l42_handle_device_data()
1637 (cs42l42->ts_dbnc_fall << in cs42l42_handle_device_data()
1643 cs42l42->btn_det_init_dbnce = val; in cs42l42_handle_device_data()
1648 cs42l42->btn_det_init_dbnce = in cs42l42_handle_device_data()
1652 cs42l42->btn_det_init_dbnce = in cs42l42_handle_device_data()
1659 cs42l42->btn_det_event_dbnce = val; in cs42l42_handle_device_data()
1663 cs42l42->btn_det_event_dbnce = in cs42l42_handle_device_data()
1667 cs42l42->btn_det_event_dbnce = in cs42l42_handle_device_data()
1676 cs42l42->bias_thresholds[i] = thresholds[i]; in cs42l42_handle_device_data()
1681 cs42l42->bias_thresholds[i] = threshold_defaults[i]; in cs42l42_handle_device_data()
1686 cs42l42->bias_thresholds[i] = threshold_defaults[i]; in cs42l42_handle_device_data()
1693 cs42l42->hs_bias_ramp_rate = val; in cs42l42_handle_device_data()
1694 cs42l42->hs_bias_ramp_time = CS42L42_HSBIAS_RAMP_TIME0; in cs42l42_handle_device_data()
1697 cs42l42->hs_bias_ramp_rate = val; in cs42l42_handle_device_data()
1698 cs42l42->hs_bias_ramp_time = CS42L42_HSBIAS_RAMP_TIME1; in cs42l42_handle_device_data()
1701 cs42l42->hs_bias_ramp_rate = val; in cs42l42_handle_device_data()
1702 cs42l42->hs_bias_ramp_time = CS42L42_HSBIAS_RAMP_TIME2; in cs42l42_handle_device_data()
1705 cs42l42->hs_bias_ramp_rate = val; in cs42l42_handle_device_data()
1706 cs42l42->hs_bias_ramp_time = CS42L42_HSBIAS_RAMP_TIME3; in cs42l42_handle_device_data()
1712 cs42l42->hs_bias_ramp_rate = CS42L42_HSBIAS_RAMP_SLOW; in cs42l42_handle_device_data()
1713 cs42l42->hs_bias_ramp_time = CS42L42_HSBIAS_RAMP_TIME2; in cs42l42_handle_device_data()
1716 cs42l42->hs_bias_ramp_rate = CS42L42_HSBIAS_RAMP_SLOW; in cs42l42_handle_device_data()
1717 cs42l42->hs_bias_ramp_time = CS42L42_HSBIAS_RAMP_TIME2; in cs42l42_handle_device_data()
1720 regmap_update_bits(cs42l42->regmap, CS42L42_HS_BIAS_CTL, in cs42l42_handle_device_data()
1722 (cs42l42->hs_bias_ramp_rate << in cs42l42_handle_device_data()
1731 struct cs42l42_private *cs42l42; in cs42l42_i2c_probe() local
1736 cs42l42 = devm_kzalloc(&i2c_client->dev, sizeof(struct cs42l42_private), in cs42l42_i2c_probe()
1738 if (!cs42l42) in cs42l42_i2c_probe()
1741 i2c_set_clientdata(i2c_client, cs42l42); in cs42l42_i2c_probe()
1743 cs42l42->regmap = devm_regmap_init_i2c(i2c_client, &cs42l42_regmap); in cs42l42_i2c_probe()
1744 if (IS_ERR(cs42l42->regmap)) { in cs42l42_i2c_probe()
1745 ret = PTR_ERR(cs42l42->regmap); in cs42l42_i2c_probe()
1750 for (i = 0; i < ARRAY_SIZE(cs42l42->supplies); i++) in cs42l42_i2c_probe()
1751 cs42l42->supplies[i].supply = cs42l42_supply_names[i]; in cs42l42_i2c_probe()
1754 ARRAY_SIZE(cs42l42->supplies), in cs42l42_i2c_probe()
1755 cs42l42->supplies); in cs42l42_i2c_probe()
1762 ret = regulator_bulk_enable(ARRAY_SIZE(cs42l42->supplies), in cs42l42_i2c_probe()
1763 cs42l42->supplies); in cs42l42_i2c_probe()
1771 cs42l42->reset_gpio = devm_gpiod_get_optional(&i2c_client->dev, in cs42l42_i2c_probe()
1773 if (IS_ERR(cs42l42->reset_gpio)) { in cs42l42_i2c_probe()
1774 ret = PTR_ERR(cs42l42->reset_gpio); in cs42l42_i2c_probe()
1778 if (cs42l42->reset_gpio) { in cs42l42_i2c_probe()
1780 gpiod_set_value_cansleep(cs42l42->reset_gpio, 1); in cs42l42_i2c_probe()
1789 "cs42l42", cs42l42); in cs42l42_i2c_probe()
1797 ret = regmap_read(cs42l42->regmap, CS42L42_DEVID_AB, ®); in cs42l42_i2c_probe()
1800 ret = regmap_read(cs42l42->regmap, CS42L42_DEVID_CD, ®); in cs42l42_i2c_probe()
1803 ret = regmap_read(cs42l42->regmap, CS42L42_DEVID_E, ®); in cs42l42_i2c_probe()
1809 "CS42L42 Device ID (%X). Expected %X\n", in cs42l42_i2c_probe()
1814 ret = regmap_read(cs42l42->regmap, CS42L42_REVID, ®); in cs42l42_i2c_probe()
1821 "Cirrus Logic CS42L42, Revision: %02X\n", reg & 0xFF); in cs42l42_i2c_probe()
1824 regmap_update_bits(cs42l42->regmap, CS42L42_PWR_CTL1, in cs42l42_i2c_probe()
1840 ret = cs42l42_handle_device_data(&i2c_client->dev, cs42l42); in cs42l42_i2c_probe()
1845 cs42l42_setup_hs_type_detect(cs42l42); in cs42l42_i2c_probe()
1848 cs42l42_set_interrupt_masks(cs42l42); in cs42l42_i2c_probe()
1858 regulator_bulk_disable(ARRAY_SIZE(cs42l42->supplies), in cs42l42_i2c_probe()
1859 cs42l42->supplies); in cs42l42_i2c_probe()
1865 struct cs42l42_private *cs42l42 = i2c_get_clientdata(i2c_client); in cs42l42_i2c_remove() local
1868 gpiod_set_value_cansleep(cs42l42->reset_gpio, 0); in cs42l42_i2c_remove()
1876 struct cs42l42_private *cs42l42 = dev_get_drvdata(dev); in cs42l42_runtime_suspend() local
1878 regcache_cache_only(cs42l42->regmap, true); in cs42l42_runtime_suspend()
1879 regcache_mark_dirty(cs42l42->regmap); in cs42l42_runtime_suspend()
1882 gpiod_set_value_cansleep(cs42l42->reset_gpio, 0); in cs42l42_runtime_suspend()
1885 regulator_bulk_disable(ARRAY_SIZE(cs42l42->supplies), in cs42l42_runtime_suspend()
1886 cs42l42->supplies); in cs42l42_runtime_suspend()
1893 struct cs42l42_private *cs42l42 = dev_get_drvdata(dev); in cs42l42_runtime_resume() local
1897 ret = regulator_bulk_enable(ARRAY_SIZE(cs42l42->supplies), in cs42l42_runtime_resume()
1898 cs42l42->supplies); in cs42l42_runtime_resume()
1905 gpiod_set_value_cansleep(cs42l42->reset_gpio, 1); in cs42l42_runtime_resume()
1908 regcache_cache_only(cs42l42->regmap, false); in cs42l42_runtime_resume()
1909 regcache_sync(cs42l42->regmap); in cs42l42_runtime_resume()
1921 { .compatible = "cirrus,cs42l42", },
1928 {"cs42l42", 0},
1936 .name = "cs42l42",
1947 MODULE_DESCRIPTION("ASoC CS42L42 driver");