Lines Matching +full:sprvdd +full:- +full:supply

1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright (C) 2014-2017 Texas Instruments Incorporated - https://www.ti.com/
10 * The TLV320AIC31xx series of audio codecs are low-power, highly integrated
12 * and mono/stereo Class-D speaker driver.
36 #include <dt-bindings/sound/tlv320aic31xx.h>
148 "SPRVDD",
180 u8 ocmv; /* output common-mode voltage */
311 static const DECLARE_TLV_DB_SCALE(dac_vol_tlv, -6350, 50, 0);
313 static const DECLARE_TLV_DB_SCALE(adc_cgain_tlv, -2000, 50, 0);
317 static const DECLARE_TLV_DB_SCALE(hp_vol_tlv, -6350, 50, 0);
318 static const DECLARE_TLV_DB_SCALE(sp_vol_tlv, -6350, 50, 0);
325 AIC31XX_RDACVOL, 0, -127, 48, 7, 0, dac_vol_tlv),
335 /* HP de-pop control: apply power not immediately but via ramp
340 SOC_ENUM("HP Output Driver Power-On time", hp_poweron_time_enum),
341 SOC_ENUM("HP Output Driver Ramp-up step", hp_rampup_step_enum),
352 0, -24, 40, 6, 0, adc_cgain_tlv),
390 int ret = regmap_read(aic31xx->regmap, reg, &bits); in aic31xx_wait_bits()
394 ret = regmap_read(aic31xx->regmap, reg, &bits); in aic31xx_wait_bits()
395 counter--; in aic31xx_wait_bits()
398 dev_err(aic31xx->dev, in aic31xx_wait_bits()
401 (count - counter) * sleep); in aic31xx_wait_bits()
402 ret = -1; in aic31xx_wait_bits()
412 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in aic31xx_dapm_power_event()
418 switch (WIDGET_BIT(w->reg, w->shift)) { in aic31xx_dapm_power_event()
446 dev_err(component->dev, "Unknown widget '%s' calling %s\n", in aic31xx_dapm_power_event()
447 w->name, __func__); in aic31xx_dapm_power_event()
448 return -EINVAL; in aic31xx_dapm_power_event()
459 dev_dbg(component->dev, in aic31xx_dapm_power_event()
461 event, w->name); in aic31xx_dapm_power_event()
489 SOC_DAPM_ENUM("MIC1LP P-Terminal", mic1lp_p_enum);
492 SOC_DAPM_ENUM("MIC1RP P-Terminal", mic1rp_p_enum);
495 SOC_DAPM_ENUM("MIC1LM P-Terminal", mic1lm_p_enum);
498 SOC_DAPM_ENUM("MIC1LM M-Terminal", mic1lm_m_enum);
515 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in mic_bias_event()
523 aic31xx->micbias_vg << in mic_bias_event()
525 dev_dbg(component->dev, "%s: turned on\n", __func__); in mic_bias_event()
531 dev_dbg(component->dev, "%s: turned off\n", __func__); in mic_bias_event()
601 SND_SOC_DAPM_MUX("MIC1LP P-Terminal", SND_SOC_NOPM, 0, 0,
603 SND_SOC_DAPM_MUX("MIC1RP P-Terminal", SND_SOC_NOPM, 0, 0,
605 SND_SOC_DAPM_MUX("MIC1LM P-Terminal", SND_SOC_NOPM, 0, 0,
613 SND_SOC_DAPM_MUX("MIC1LM M-Terminal", SND_SOC_NOPM, 0, 0,
632 /* AIC3111 and AIC3110 have stereo class-D amplifier */
647 /* AIC3100 and AIC3120 have only mono class-D amplifier */
695 {"MIC1LP P-Terminal", "FFR 10 Ohm", "MIC1LP"},
696 {"MIC1LP P-Terminal", "FFR 20 Ohm", "MIC1LP"},
697 {"MIC1LP P-Terminal", "FFR 40 Ohm", "MIC1LP"},
698 {"MIC1RP P-Terminal", "FFR 10 Ohm", "MIC1RP"},
699 {"MIC1RP P-Terminal", "FFR 20 Ohm", "MIC1RP"},
700 {"MIC1RP P-Terminal", "FFR 40 Ohm", "MIC1RP"},
701 {"MIC1LM P-Terminal", "FFR 10 Ohm", "MIC1LM"},
702 {"MIC1LM P-Terminal", "FFR 20 Ohm", "MIC1LM"},
703 {"MIC1LM P-Terminal", "FFR 40 Ohm", "MIC1LM"},
705 {"MIC1LM M-Terminal", "FFR 10 Ohm", "MIC1LM"},
706 {"MIC1LM M-Terminal", "FFR 20 Ohm", "MIC1LM"},
707 {"MIC1LM M-Terminal", "FFR 40 Ohm", "MIC1LM"},
709 {"MIC_GAIN_CTL", NULL, "MIC1LP P-Terminal"},
710 {"MIC_GAIN_CTL", NULL, "MIC1RP P-Terminal"},
711 {"MIC_GAIN_CTL", NULL, "MIC1LM P-Terminal"},
712 {"MIC_GAIN_CTL", NULL, "MIC1LM M-Terminal"},
781 if (!(aic31xx->codec_type & DAC31XX_BIT)) in aic31xx_add_controls()
788 if (aic31xx->codec_type & AIC31XX_STEREO_CLASS_D_BIT) in aic31xx_add_controls()
806 if (aic31xx->codec_type & DAC31XX_BIT) { in aic31xx_add_widgets()
830 if (aic31xx->codec_type & AIC31XX_STEREO_CLASS_D_BIT) { in aic31xx_add_widgets()
864 int match = -1; in aic31xx_setup_pll()
867 if (!aic31xx->sysclk || !aic31xx->p_div) { in aic31xx_setup_pll()
868 dev_err(component->dev, "Master clock not supplied\n"); in aic31xx_setup_pll()
869 return -EINVAL; in aic31xx_setup_pll()
871 mclk_p = aic31xx->sysclk / aic31xx->p_div; in aic31xx_setup_pll()
894 if (match == -1) { in aic31xx_setup_pll()
895 dev_err(component->dev, in aic31xx_setup_pll()
899 return -EINVAL; in aic31xx_setup_pll()
902 dev_warn(component->dev, "Can not produce exact bitclock"); in aic31xx_setup_pll()
915 (aic31xx->p_div << 4) | aic31xx_divs[i].pll_r); in aic31xx_setup_pll()
944 aic31xx->rate_div_line = i; in aic31xx_setup_pll()
946 dev_dbg(component->dev, in aic31xx_setup_pll()
950 aic31xx->p_div, in aic31xx_setup_pll()
967 struct snd_soc_component *component = dai->component; in aic31xx_hw_params()
971 dev_dbg(component->dev, "## %s: width %d rate %d\n", in aic31xx_hw_params()
991 dev_err(component->dev, "%s: Unsupported width %d\n", in aic31xx_hw_params()
993 return -EINVAL; in aic31xx_hw_params()
1004 if (aic31xx->sysclk_id == AIC31XX_PLL_CLKIN_BCLK) { in aic31xx_hw_params()
1005 aic31xx->sysclk = params_rate(params) * params_width(params) * in aic31xx_hw_params()
1007 aic31xx->p_div = 1; in aic31xx_hw_params()
1016 struct snd_soc_component *component = codec_dai->component; in aic31xx_dac_mute()
1039 aic31xx->master_dapm_route_applied) { in aic31xx_clock_master_routes()
1046 if (!ret && !(aic31xx->codec_type & DAC31XX_BIT)) in aic31xx_clock_master_routes()
1054 aic31xx->master_dapm_route_applied = false; in aic31xx_clock_master_routes()
1056 !aic31xx->master_dapm_route_applied) { in aic31xx_clock_master_routes()
1063 if (!ret && !(aic31xx->codec_type & DAC31XX_BIT)) in aic31xx_clock_master_routes()
1071 aic31xx->master_dapm_route_applied = true; in aic31xx_clock_master_routes()
1080 struct snd_soc_component *component = codec_dai->component; in aic31xx_set_dai_fmt()
1085 dev_dbg(component->dev, "## %s: fmt = 0x%x\n", __func__, fmt); in aic31xx_set_dai_fmt()
1100 dev_err(component->dev, "Invalid DAI clock provider\n"); in aic31xx_set_dai_fmt()
1101 return -EINVAL; in aic31xx_set_dai_fmt()
1112 dev_err(component->dev, "Invalid DAI clock signal polarity\n"); in aic31xx_set_dai_fmt()
1113 return -EINVAL; in aic31xx_set_dai_fmt()
1142 dev_err(component->dev, "Invalid DAI interface format\n"); in aic31xx_set_dai_fmt()
1143 return -EINVAL; in aic31xx_set_dai_fmt()
1163 struct snd_soc_component *component = codec_dai->component; in aic31xx_set_dai_sysclk()
1167 dev_dbg(component->dev, "## %s: clk_id = %d, freq = %d, dir = %d\n", in aic31xx_set_dai_sysclk()
1174 dev_err(aic31xx->dev, "%s: Too high mclk frequency %u\n", in aic31xx_set_dai_sysclk()
1176 return -EINVAL; in aic31xx_set_dai_sysclk()
1178 aic31xx->p_div = i; in aic31xx_set_dai_sysclk()
1181 if (aic31xx_divs[i].mclk_p == freq / aic31xx->p_div) in aic31xx_set_dai_sysclk()
1184 dev_err(aic31xx->dev, "%s: Unsupported frequency %d\n", in aic31xx_set_dai_sysclk()
1186 return -EINVAL; in aic31xx_set_dai_sysclk()
1193 aic31xx->sysclk_id = clk_id; in aic31xx_set_dai_sysclk()
1194 aic31xx->sysclk = freq; in aic31xx_set_dai_sysclk()
1204 struct aic31xx_priv *aic31xx = disable_nb->aic31xx; in aic31xx_regulator_event()
1211 if (aic31xx->gpio_reset) in aic31xx_regulator_event()
1212 gpiod_set_value_cansleep(aic31xx->gpio_reset, 1); in aic31xx_regulator_event()
1214 regcache_mark_dirty(aic31xx->regmap); in aic31xx_regulator_event()
1215 dev_dbg(aic31xx->dev, "## %s: DISABLE received\n", __func__); in aic31xx_regulator_event()
1225 if (aic31xx->gpio_reset) { in aic31xx_reset()
1226 gpiod_set_value_cansleep(aic31xx->gpio_reset, 1); in aic31xx_reset()
1228 gpiod_set_value_cansleep(aic31xx->gpio_reset, 0); in aic31xx_reset()
1230 ret = regmap_write(aic31xx->regmap, AIC31XX_RESET, 1); in aic31xx_reset()
1243 dev_dbg(component->dev, "codec clock -> on (rate %d)\n", in aic31xx_clk_on()
1244 aic31xx_divs[aic31xx->rate_div_line].rate); in aic31xx_clk_on()
1249 if (aic31xx_divs[aic31xx->rate_div_line].nadc) in aic31xx_clk_on()
1251 if (aic31xx_divs[aic31xx->rate_div_line].madc) in aic31xx_clk_on()
1261 dev_dbg(component->dev, "codec clock -> off\n"); in aic31xx_clk_off()
1275 ret = regulator_bulk_enable(ARRAY_SIZE(aic31xx->supplies), in aic31xx_power_on()
1276 aic31xx->supplies); in aic31xx_power_on()
1280 regcache_cache_only(aic31xx->regmap, false); in aic31xx_power_on()
1282 /* Reset device registers for a consistent power-on like state */ in aic31xx_power_on()
1285 dev_err(aic31xx->dev, "Could not reset device: %d\n", ret); in aic31xx_power_on()
1287 ret = regcache_sync(aic31xx->regmap); in aic31xx_power_on()
1289 dev_err(component->dev, in aic31xx_power_on()
1291 regcache_cache_only(aic31xx->regmap, true); in aic31xx_power_on()
1292 regulator_bulk_disable(ARRAY_SIZE(aic31xx->supplies), in aic31xx_power_on()
1293 aic31xx->supplies); in aic31xx_power_on()
1302 aic31xx_set_jack(component, aic31xx->jack, NULL); in aic31xx_power_on()
1311 regcache_cache_only(aic31xx->regmap, true); in aic31xx_power_off()
1312 regulator_bulk_disable(ARRAY_SIZE(aic31xx->supplies), in aic31xx_power_off()
1313 aic31xx->supplies); in aic31xx_power_off()
1319 dev_dbg(component->dev, "## %s: %d -> %d\n", __func__, in aic31xx_set_bias_level()
1355 aic31xx->jack = jack; in aic31xx_set_jack()
1358 regmap_write(aic31xx->regmap, AIC31XX_HSDETECT, in aic31xx_set_jack()
1369 dev_dbg(aic31xx->dev, "## %s\n", __func__); in aic31xx_codec_probe()
1371 aic31xx->component = component; in aic31xx_codec_probe()
1373 for (i = 0; i < ARRAY_SIZE(aic31xx->supplies); i++) { in aic31xx_codec_probe()
1374 aic31xx->disable_nb[i].nb.notifier_call = in aic31xx_codec_probe()
1376 aic31xx->disable_nb[i].aic31xx = aic31xx; in aic31xx_codec_probe()
1378 aic31xx->supplies[i].consumer, in aic31xx_codec_probe()
1379 &aic31xx->disable_nb[i].nb); in aic31xx_codec_probe()
1381 dev_err(component->dev, in aic31xx_codec_probe()
1388 regcache_cache_only(aic31xx->regmap, true); in aic31xx_codec_probe()
1389 regcache_mark_dirty(aic31xx->regmap); in aic31xx_codec_probe()
1399 /* set output common-mode voltage */ in aic31xx_codec_probe()
1402 aic31xx->ocmv << AIC31XX_HPD_OCMV_SHIFT); in aic31xx_codec_probe()
1433 .name = "tlv320dac31xx-hifi",
1448 .name = "tlv320aic31xx-hifi",
1494 struct device *dev = aic31xx->dev; in aic31xx_irq()
1499 ret = regmap_read(aic31xx->regmap, AIC31XX_INTRDACFLAG, &value); in aic31xx_irq()
1518 ret = regmap_read(aic31xx->regmap, AIC31XX_INTRDACFLAG2, in aic31xx_irq()
1529 ret = regmap_read(aic31xx->regmap, AIC31XX_HSDETECT, &val); in aic31xx_irq()
1547 if (aic31xx->jack) in aic31xx_irq()
1548 snd_soc_jack_report(aic31xx->jack, status, in aic31xx_irq()
1558 ret = regmap_read(aic31xx->regmap, AIC31XX_OFFLAG, &value); in aic31xx_irq()
1570 dev_warn(dev, "Left-channel DAC overflow has occurred\n"); in aic31xx_irq()
1572 dev_warn(dev, "Right-channel DAC overflow has occurred\n"); in aic31xx_irq()
1595 struct device *dev = priv->dev; in aic31xx_configure_ocmv()
1599 if (dev->fwnode && in aic31xx_configure_ocmv()
1600 fwnode_property_read_u32(dev->fwnode, "ai31xx-ocmv", &value)) { in aic31xx_configure_ocmv()
1603 priv->ocmv = value; in aic31xx_configure_ocmv()
1608 avdd = regulator_get_voltage(priv->supplies[3].consumer); in aic31xx_configure_ocmv()
1609 dvdd = regulator_get_voltage(priv->supplies[5].consumer); in aic31xx_configure_ocmv()
1613 "Too high supply voltage(s) AVDD: %d, DVDD: %d\n", in aic31xx_configure_ocmv()
1616 priv->ocmv = AIC31XX_HPD_OCMV_1_8V; in aic31xx_configure_ocmv()
1618 priv->ocmv = AIC31XX_HPD_OCMV_1_65V; in aic31xx_configure_ocmv()
1620 priv->ocmv = AIC31XX_HPD_OCMV_1_5V; in aic31xx_configure_ocmv()
1622 priv->ocmv = AIC31XX_HPD_OCMV_1_35V; in aic31xx_configure_ocmv()
1625 "Invalid supply voltage(s) AVDD: %d, DVDD: %d\n", in aic31xx_configure_ocmv()
1650 * Coefficients firmware binary structure. Multi-byte values are big-endian. in tlv320dac3100_fw_load()
1655 * @5, 62 16-bit values: Page 8 buffer A DAC programmable filter coefficients in tlv320dac3100_fw_load()
1656 * @129, 12 16-bit values: Page 9 Buffer A DAC programmable filter coefficients in tlv320dac3100_fw_load()
1659 * ranging from -32 768 to 32 767. For more details on filter coefficients, in tlv320dac3100_fw_load()
1660 * please refer to the TLV320DAC3100 datasheet, tables 6-120 and 6-123. in tlv320dac3100_fw_load()
1664 dev_err(aic31xx->dev, "firmware size is %zu, expected 153 bytes\n", size); in tlv320dac3100_fw_load()
1665 return -EINVAL; in tlv320dac3100_fw_load()
1671 dev_err(aic31xx->dev, "fw magic is 0x%04x expected 0xb30c\n", val16); in tlv320dac3100_fw_load()
1672 return -EINVAL; in tlv320dac3100_fw_load()
1679 dev_err(aic31xx->dev, "invalid firmware version 0x%04x! expected 1", val16); in tlv320dac3100_fw_load()
1680 return -EINVAL; in tlv320dac3100_fw_load()
1684 ret = regmap_write(aic31xx->regmap, AIC31XX_DACPRB, *data); in tlv320dac3100_fw_load()
1686 dev_err(aic31xx->dev, "failed to write PRB index: err %d\n", ret); in tlv320dac3100_fw_load()
1693 ret = regmap_write(aic31xx->regmap, AIC31XX_REG(8, reg), *data); in tlv320dac3100_fw_load()
1695 dev_err(aic31xx->dev, in tlv320dac3100_fw_load()
1704 ret = regmap_write(aic31xx->regmap, AIC31XX_REG(9, reg), *data); in tlv320dac3100_fw_load()
1706 dev_err(aic31xx->dev, in tlv320dac3100_fw_load()
1713 dev_info(aic31xx->dev, "done loading DAC filter coefficients\n"); in tlv320dac3100_fw_load()
1724 ret = request_firmware(&fw, fw_name, aic31xx->dev); in tlv320dac3100_load_coeffs()
1728 ret = tlv320dac3100_fw_load(aic31xx, fw->data, fw->size); in tlv320dac3100_load_coeffs()
1742 dev_dbg(&i2c->dev, "## %s: %s codec_type = %d\n", __func__, in aic31xx_i2c_probe()
1743 id->name, (int)id->driver_data); in aic31xx_i2c_probe()
1745 aic31xx = devm_kzalloc(&i2c->dev, sizeof(*aic31xx), GFP_KERNEL); in aic31xx_i2c_probe()
1747 return -ENOMEM; in aic31xx_i2c_probe()
1749 aic31xx->regmap = devm_regmap_init_i2c(i2c, &aic31xx_i2c_regmap); in aic31xx_i2c_probe()
1750 if (IS_ERR(aic31xx->regmap)) { in aic31xx_i2c_probe()
1751 ret = PTR_ERR(aic31xx->regmap); in aic31xx_i2c_probe()
1752 dev_err(&i2c->dev, "Failed to allocate register map: %d\n", in aic31xx_i2c_probe()
1756 regcache_cache_only(aic31xx->regmap, true); in aic31xx_i2c_probe()
1758 aic31xx->dev = &i2c->dev; in aic31xx_i2c_probe()
1759 aic31xx->irq = i2c->irq; in aic31xx_i2c_probe()
1761 aic31xx->codec_type = id->driver_data; in aic31xx_i2c_probe()
1763 dev_set_drvdata(aic31xx->dev, aic31xx); in aic31xx_i2c_probe()
1765 fwnode_property_read_u32(aic31xx->dev->fwnode, "ai31xx-micbias-vg", in aic31xx_i2c_probe()
1771 aic31xx->micbias_vg = micbias_value; in aic31xx_i2c_probe()
1774 dev_err(aic31xx->dev, "Bad ai31xx-micbias-vg value %d\n", in aic31xx_i2c_probe()
1776 aic31xx->micbias_vg = MICBIAS_2_0V; in aic31xx_i2c_probe()
1779 if (dev_get_platdata(aic31xx->dev)) { in aic31xx_i2c_probe()
1780 memcpy(&aic31xx->pdata, dev_get_platdata(aic31xx->dev), sizeof(aic31xx->pdata)); in aic31xx_i2c_probe()
1781 aic31xx->codec_type = aic31xx->pdata.codec_type; in aic31xx_i2c_probe()
1782 aic31xx->micbias_vg = aic31xx->pdata.micbias_vg; in aic31xx_i2c_probe()
1785 aic31xx->gpio_reset = devm_gpiod_get_optional(aic31xx->dev, "reset", in aic31xx_i2c_probe()
1787 if (IS_ERR(aic31xx->gpio_reset)) in aic31xx_i2c_probe()
1788 return dev_err_probe(aic31xx->dev, PTR_ERR(aic31xx->gpio_reset), in aic31xx_i2c_probe()
1791 for (i = 0; i < ARRAY_SIZE(aic31xx->supplies); i++) in aic31xx_i2c_probe()
1792 aic31xx->supplies[i].supply = aic31xx_supply_names[i]; in aic31xx_i2c_probe()
1794 ret = devm_regulator_bulk_get(aic31xx->dev, in aic31xx_i2c_probe()
1795 ARRAY_SIZE(aic31xx->supplies), in aic31xx_i2c_probe()
1796 aic31xx->supplies); in aic31xx_i2c_probe()
1798 return dev_err_probe(aic31xx->dev, ret, "Failed to request supplies\n"); in aic31xx_i2c_probe()
1802 if (aic31xx->irq > 0) { in aic31xx_i2c_probe()
1803 regmap_update_bits(aic31xx->regmap, AIC31XX_GPIO1, in aic31xx_i2c_probe()
1808 regmap_write(aic31xx->regmap, AIC31XX_INT1CTRL, in aic31xx_i2c_probe()
1814 ret = devm_request_threaded_irq(aic31xx->dev, aic31xx->irq, in aic31xx_i2c_probe()
1816 IRQF_ONESHOT, "aic31xx-irq", in aic31xx_i2c_probe()
1819 dev_err(aic31xx->dev, "Unable to request IRQ\n"); in aic31xx_i2c_probe()
1824 if (aic31xx->codec_type == DAC3100) { in aic31xx_i2c_probe()
1825 ret = tlv320dac3100_load_coeffs(aic31xx, "tlv320dac3100-coeffs.bin"); in aic31xx_i2c_probe()
1827 dev_warn(aic31xx->dev, "Did not load any filter coefficients\n"); in aic31xx_i2c_probe()
1830 if (aic31xx->codec_type & DAC31XX_BIT) in aic31xx_i2c_probe()
1831 return devm_snd_soc_register_component(&i2c->dev, in aic31xx_i2c_probe()
1836 return devm_snd_soc_register_component(&i2c->dev, in aic31xx_i2c_probe()
1844 .name = "tlv320aic31xx-codec",