Lines Matching +full:tdm +full:- +full:data +full:- +full:delay

1 // SPDX-License-Identifier: GPL-2.0
3 * ALSA SoC Texas Instruments TAS6424 Quad-Channel Audio Amplifier
5 * Copyright (C) 2016-2017 Texas Instruments Incorporated - https://www.ti.com/
17 #include <linux/delay.h>
23 #include <sound/soc-dapm.h>
32 "dvdd", /* Digital power supply. Connect to 3.3-V supply. */
34 "pvdd", /* Class-D amp output FETs supply. */
52 * DAC digital volumes. From -103.5 to 24 dB in 0.5 dB steps. Note that
53 * setting the gain below -100 dB (register value <0x7) is effectively a MUTE
56 static DECLARE_TLV_DB_SCALE(dac_tlv, -10350, 50, 0);
74 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in tas6424_dac_event()
77 dev_dbg(component->dev, "%s() event=0x%0x\n", __func__, event); in tas6424_dac_event()
80 /* Observe codec shutdown-to-active time */ in tas6424_dac_event()
84 tas6424->last_fault1 = 0; in tas6424_dac_event()
85 tas6424->last_fault2 = 0; in tas6424_dac_event()
86 tas6424->last_warn = 0; in tas6424_dac_event()
87 schedule_delayed_work(&tas6424->fault_check_work, in tas6424_dac_event()
91 cancel_delayed_work_sync(&tas6424->fault_check_work); in tas6424_dac_event()
113 struct snd_soc_component *component = dai->component; in tas6424_hw_params()
118 dev_dbg(component->dev, "%s() rate=%u width=%u\n", __func__, rate, width); in tas6424_hw_params()
131 dev_err(component->dev, "unsupported sample rate: %u\n", rate); in tas6424_hw_params()
132 return -EINVAL; in tas6424_hw_params()
142 dev_err(component->dev, "unsupported sample width: %u\n", width); in tas6424_hw_params()
143 return -EINVAL; in tas6424_hw_params()
156 struct snd_soc_component *component = dai->component; in tas6424_set_dai_fmt()
159 dev_dbg(component->dev, "%s() fmt=0x%0x\n", __func__, fmt); in tas6424_set_dai_fmt()
166 dev_err(component->dev, "Invalid DAI clocking\n"); in tas6424_set_dai_fmt()
167 return -EINVAL; in tas6424_set_dai_fmt()
175 dev_err(component->dev, "Invalid DAI clock signal polarity\n"); in tas6424_set_dai_fmt()
176 return -EINVAL; in tas6424_set_dai_fmt()
190 * LRCLK duty cycle during TDM to receive DSP_B formatted data in tas6424_set_dai_fmt()
191 * in LEFTJ mode (no delaying of the 1st data bit). in tas6424_set_dai_fmt()
199 dev_err(component->dev, "Invalid DAI interface format\n"); in tas6424_set_dai_fmt()
200 return -EINVAL; in tas6424_set_dai_fmt()
213 struct snd_soc_component *component = dai->component; in tas6424_set_dai_tdm_slot()
217 dev_dbg(component->dev, "%s() tx_mask=%d rx_mask=%d\n", __func__, in tas6424_set_dai_tdm_slot()
221 return 0; /* nothing needed to disable TDM mode */ in tas6424_set_dai_tdm_slot()
226 * TAS6424's TDM interface is not fully configurable. in tas6424_set_dai_tdm_slot()
231 if (last_slot - first_slot != 4) { in tas6424_set_dai_tdm_slot()
232 dev_err(component->dev, "tdm mask must cover 4 contiguous slots\n"); in tas6424_set_dai_tdm_slot()
233 return -EINVAL; in tas6424_set_dai_tdm_slot()
244 dev_err(component->dev, "tdm mask must start at slot 0 or 4\n"); in tas6424_set_dai_tdm_slot()
245 return -EINVAL; in tas6424_set_dai_tdm_slot()
256 struct snd_soc_component *component = dai->component; in tas6424_mute()
260 dev_dbg(component->dev, "%s() mute=%d\n", __func__, mute); in tas6424_mute()
262 if (tas6424->mute_gpio) { in tas6424_mute()
263 gpiod_set_value_cansleep(tas6424->mute_gpio, mute); in tas6424_mute()
284 regcache_cache_only(tas6424->regmap, true); in tas6424_power_off()
285 regcache_mark_dirty(tas6424->regmap); in tas6424_power_off()
287 ret = regulator_bulk_disable(ARRAY_SIZE(tas6424->supplies), in tas6424_power_off()
288 tas6424->supplies); in tas6424_power_off()
290 dev_err(component->dev, "failed to disable supplies: %d\n", ret); in tas6424_power_off()
305 if (!regmap_read(tas6424->regmap, TAS6424_DC_DIAG_CTRL1, &reg_val)) in tas6424_power_on()
308 ret = regulator_bulk_enable(ARRAY_SIZE(tas6424->supplies), in tas6424_power_on()
309 tas6424->supplies); in tas6424_power_on()
311 dev_err(component->dev, "failed to enable supplies: %d\n", ret); in tas6424_power_on()
315 regcache_cache_only(tas6424->regmap, false); in tas6424_power_on()
317 ret = regcache_sync(tas6424->regmap); in tas6424_power_on()
319 dev_err(component->dev, "failed to sync regcache: %d\n", ret); in tas6424_power_on()
323 if (tas6424->mute_gpio) { in tas6424_power_on()
324 gpiod_set_value_cansleep(tas6424->mute_gpio, 0); in tas6424_power_on()
328 * access is not necessary to un-mute the channels in tas6424_power_on()
349 dev_dbg(component->dev, "%s() level=%d\n", __func__, level); in tas6424_set_bias_level()
389 .name = "tas6424-amplifier",
405 struct device *dev = tas6424->dev; in tas6424_fault_check_work()
409 ret = regmap_read(tas6424->regmap, TAS6424_CHANNEL_FAULT, &reg); in tas6424_fault_check_work()
416 tas6424->last_cfault = reg; in tas6424_fault_check_work()
426 if ((reg & TAS6424_FAULT_OC_CH1) && !(tas6424->last_cfault & TAS6424_FAULT_OC_CH1)) in tas6424_fault_check_work()
429 if ((reg & TAS6424_FAULT_OC_CH2) && !(tas6424->last_cfault & TAS6424_FAULT_OC_CH2)) in tas6424_fault_check_work()
432 if ((reg & TAS6424_FAULT_OC_CH3) && !(tas6424->last_cfault & TAS6424_FAULT_OC_CH3)) in tas6424_fault_check_work()
435 if ((reg & TAS6424_FAULT_OC_CH4) && !(tas6424->last_cfault & TAS6424_FAULT_OC_CH4)) in tas6424_fault_check_work()
438 if ((reg & TAS6424_FAULT_DC_CH1) && !(tas6424->last_cfault & TAS6424_FAULT_DC_CH1)) in tas6424_fault_check_work()
441 if ((reg & TAS6424_FAULT_DC_CH2) && !(tas6424->last_cfault & TAS6424_FAULT_DC_CH2)) in tas6424_fault_check_work()
444 if ((reg & TAS6424_FAULT_DC_CH3) && !(tas6424->last_cfault & TAS6424_FAULT_DC_CH3)) in tas6424_fault_check_work()
447 if ((reg & TAS6424_FAULT_DC_CH4) && !(tas6424->last_cfault & TAS6424_FAULT_DC_CH4)) in tas6424_fault_check_work()
451 tas6424->last_cfault = reg; in tas6424_fault_check_work()
454 ret = regmap_read(tas6424->regmap, TAS6424_GLOB_FAULT1, &reg); in tas6424_fault_check_work()
464 * stopped to avoid any false-positives. However there are no in tas6424_fault_check_work()
473 tas6424->last_fault1 = reg; in tas6424_fault_check_work()
477 if ((reg & TAS6424_FAULT_PVDD_OV) && !(tas6424->last_fault1 & TAS6424_FAULT_PVDD_OV)) in tas6424_fault_check_work()
480 if ((reg & TAS6424_FAULT_VBAT_OV) && !(tas6424->last_fault1 & TAS6424_FAULT_VBAT_OV)) in tas6424_fault_check_work()
483 if ((reg & TAS6424_FAULT_PVDD_UV) && !(tas6424->last_fault1 & TAS6424_FAULT_PVDD_UV)) in tas6424_fault_check_work()
486 if ((reg & TAS6424_FAULT_VBAT_UV) && !(tas6424->last_fault1 & TAS6424_FAULT_VBAT_UV)) in tas6424_fault_check_work()
490 tas6424->last_fault1 = reg; in tas6424_fault_check_work()
493 ret = regmap_read(tas6424->regmap, TAS6424_GLOB_FAULT2, &reg); in tas6424_fault_check_work()
506 tas6424->last_fault2 = reg; in tas6424_fault_check_work()
510 if ((reg & TAS6424_FAULT_OTSD) && !(tas6424->last_fault2 & TAS6424_FAULT_OTSD)) in tas6424_fault_check_work()
513 if ((reg & TAS6424_FAULT_OTSD_CH1) && !(tas6424->last_fault2 & TAS6424_FAULT_OTSD_CH1)) in tas6424_fault_check_work()
516 if ((reg & TAS6424_FAULT_OTSD_CH2) && !(tas6424->last_fault2 & TAS6424_FAULT_OTSD_CH2)) in tas6424_fault_check_work()
519 if ((reg & TAS6424_FAULT_OTSD_CH3) && !(tas6424->last_fault2 & TAS6424_FAULT_OTSD_CH3)) in tas6424_fault_check_work()
522 if ((reg & TAS6424_FAULT_OTSD_CH4) && !(tas6424->last_fault2 & TAS6424_FAULT_OTSD_CH4)) in tas6424_fault_check_work()
526 tas6424->last_fault2 = reg; in tas6424_fault_check_work()
529 ret = regmap_read(tas6424->regmap, TAS6424_WARN, &reg); in tas6424_fault_check_work()
544 tas6424->last_warn = reg; in tas6424_fault_check_work()
548 if ((reg & TAS6424_WARN_VDD_UV) && !(tas6424->last_warn & TAS6424_WARN_VDD_UV)) in tas6424_fault_check_work()
551 if ((reg & TAS6424_WARN_VDD_POR) && !(tas6424->last_warn & TAS6424_WARN_VDD_POR)) in tas6424_fault_check_work()
554 if ((reg & TAS6424_WARN_VDD_OTW) && !(tas6424->last_warn & TAS6424_WARN_VDD_OTW)) in tas6424_fault_check_work()
557 if ((reg & TAS6424_WARN_VDD_OTW_CH1) && !(tas6424->last_warn & TAS6424_WARN_VDD_OTW_CH1)) in tas6424_fault_check_work()
560 if ((reg & TAS6424_WARN_VDD_OTW_CH2) && !(tas6424->last_warn & TAS6424_WARN_VDD_OTW_CH2)) in tas6424_fault_check_work()
563 if ((reg & TAS6424_WARN_VDD_OTW_CH3) && !(tas6424->last_warn & TAS6424_WARN_VDD_OTW_CH3)) in tas6424_fault_check_work()
566 if ((reg & TAS6424_WARN_VDD_OTW_CH4) && !(tas6424->last_warn & TAS6424_WARN_VDD_OTW_CH4)) in tas6424_fault_check_work()
570 tas6424->last_warn = reg; in tas6424_fault_check_work()
573 ret = regmap_write_bits(tas6424->regmap, TAS6424_MISC_CTRL3, in tas6424_fault_check_work()
578 ret = regmap_write_bits(tas6424->regmap, TAS6424_MISC_CTRL3, in tas6424_fault_check_work()
585 schedule_delayed_work(&tas6424->fault_check_work, in tas6424_fault_check_work()
685 struct device *dev = &client->dev; in tas6424_i2c_probe()
692 return -ENOMEM; in tas6424_i2c_probe()
695 tas6424->dev = dev; in tas6424_i2c_probe()
697 tas6424->regmap = devm_regmap_init_i2c(client, &tas6424_regmap_config); in tas6424_i2c_probe()
698 if (IS_ERR(tas6424->regmap)) { in tas6424_i2c_probe()
699 ret = PTR_ERR(tas6424->regmap); in tas6424_i2c_probe()
706 * out of the stand-by mode. in tas6424_i2c_probe()
710 tas6424->standby_gpio = devm_gpiod_get_optional(dev, "standby", in tas6424_i2c_probe()
712 if (IS_ERR(tas6424->standby_gpio)) { in tas6424_i2c_probe()
713 if (PTR_ERR(tas6424->standby_gpio) == -EPROBE_DEFER) in tas6424_i2c_probe()
714 return -EPROBE_DEFER; in tas6424_i2c_probe()
716 PTR_ERR(tas6424->standby_gpio)); in tas6424_i2c_probe()
717 tas6424->standby_gpio = NULL; in tas6424_i2c_probe()
726 tas6424->mute_gpio = devm_gpiod_get_optional(dev, "mute", in tas6424_i2c_probe()
728 if (IS_ERR(tas6424->mute_gpio)) { in tas6424_i2c_probe()
729 if (PTR_ERR(tas6424->mute_gpio) == -EPROBE_DEFER) in tas6424_i2c_probe()
730 return -EPROBE_DEFER; in tas6424_i2c_probe()
732 PTR_ERR(tas6424->mute_gpio)); in tas6424_i2c_probe()
733 tas6424->mute_gpio = NULL; in tas6424_i2c_probe()
736 for (i = 0; i < ARRAY_SIZE(tas6424->supplies); i++) in tas6424_i2c_probe()
737 tas6424->supplies[i].supply = tas6424_supply_names[i]; in tas6424_i2c_probe()
738 ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(tas6424->supplies), in tas6424_i2c_probe()
739 tas6424->supplies); in tas6424_i2c_probe()
745 ret = regulator_bulk_enable(ARRAY_SIZE(tas6424->supplies), in tas6424_i2c_probe()
746 tas6424->supplies); in tas6424_i2c_probe()
752 /* Reset device to establish well-defined startup state */ in tas6424_i2c_probe()
753 ret = regmap_update_bits(tas6424->regmap, TAS6424_MODE_CTRL, in tas6424_i2c_probe()
760 INIT_DELAYED_WORK(&tas6424->fault_check_work, tas6424_fault_check_work); in tas6424_i2c_probe()
772 regulator_bulk_disable(ARRAY_SIZE(tas6424->supplies), tas6424->supplies); in tas6424_i2c_probe()
778 struct device *dev = &client->dev; in tas6424_i2c_remove()
782 cancel_delayed_work_sync(&tas6424->fault_check_work); in tas6424_i2c_remove()
784 /* put the codec in stand-by */ in tas6424_i2c_remove()
785 if (tas6424->standby_gpio) in tas6424_i2c_remove()
786 gpiod_set_value_cansleep(tas6424->standby_gpio, 1); in tas6424_i2c_remove()
788 ret = regulator_bulk_disable(ARRAY_SIZE(tas6424->supplies), in tas6424_i2c_remove()
789 tas6424->supplies); in tas6424_i2c_remove()