Lines Matching +full:charge +full:- +full:vol
1 // SPDX-License-Identifier: GPL-2.0
3 // sgtl5000.c -- SGTL5000 ALSA SoC Audio driver
5 // Copyright 2010-2011 Freescale Semiconductor, Inc. All Rights Reserved.
26 #include <sound/soc-dapm.h>
80 /* AVC: Threshold dB -> register: pre-calculated values */
110 #define LINREG_VDDD ((1600 - LDO_VOLTAGE / 1000) / 50)
190 /* When VAG powering on to get local loop from Line-In, the sleep in vag_power_on()
210 * If the event comes from HP and Line-In is selected, in vag_power_consumers()
212 * As HP_POWERUP is not set when HP muxed to line-in, in vag_power_consumers()
240 * - LINE_IN (for HP events) / HP (for DAC/ADC events) in vag_power_off()
241 * - DAC in vag_power_off()
242 * - ADC in vag_power_off()
250 /* In power down case, we need wait 400-1000 ms in vag_power_off()
269 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in mic_bias_event()
277 sgtl5000->micbias_resistor << SGTL5000_BIAS_R_SHIFT); in mic_bias_event()
301 * both headphones and line-out. in vag_and_mute_control()
312 sgtl5000->mute_state[event_source] = in vag_and_mute_control()
318 sgtl5000->mute_state[event_source]); in vag_and_mute_control()
321 sgtl5000->mute_state[event_source] = in vag_and_mute_control()
327 sgtl5000->mute_state[event_source]); in vag_and_mute_control()
344 snd_soc_dapm_to_component(w->dapm); in headphone_pga_event()
357 snd_soc_dapm_to_component(w->dapm); in adc_updown_depop()
366 snd_soc_dapm_to_component(w->dapm); in dac_updown_depop()
477 {"Capture Mux", "LINE_IN", "LINE_IN"}, /* line_in --> adc_mux */
478 {"Capture Mux", "MIC_IN", "MIC_IN"}, /* mic_in --> adc_mux */
480 {"ADC", NULL, "Capture Mux"}, /* adc_mux --> adc */
481 {"AIFOUT", NULL, "ADC"}, /* adc --> i2s_out */
483 {"DAP Mux", "ADC", "ADC"}, /* adc --> DAP mux */
484 {"DAP Mux", NULL, "AIFIN"}, /* i2s --> DAP mux */
485 {"DAP", NULL, "DAP Mux"}, /* DAP mux --> dap */
487 {"DAP MIX Mux", "ADC", "ADC"}, /* adc --> DAP MIX mux */
488 {"DAP MIX Mux", NULL, "AIFIN"}, /* i2s --> DAP MIX mux */
489 {"DAP", NULL, "DAP MIX Mux"}, /* DAP MIX mux --> dap */
491 {"Digital Input Mux", "ADC", "ADC"}, /* adc --> audio mux */
492 {"Digital Input Mux", NULL, "AIFIN"}, /* i2s --> audio mux */
493 {"Digital Input Mux", NULL, "DAP"}, /* dap --> audio mux */
494 {"DAC", NULL, "Digital Input Mux"}, /* audio mux --> dac */
496 {"Headphone Mux", "DAC", "DAC"}, /* dac --> hp_mux */
497 {"LO", NULL, "DAC"}, /* dac --> line_out */
499 {"Headphone Mux", "LINE_IN", "LINE_IN"},/* line_in --> hp_mux */
500 {"HP", NULL, "Headphone Mux"}, /* hp_mux --> hp */
510 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; in dac_info_volsw()
511 uinfo->count = 2; in dac_info_volsw()
512 uinfo->value.integer.min = 0; in dac_info_volsw()
513 uinfo->value.integer.max = 0xfc - 0x3c; in dac_info_volsw()
521 * 15-------------8-7--------------0
522 * | R channel vol | L channel vol |
523 * -------------------------------
525 * PCM volume with 0.5017 dB steps from 0 to -90 dB
530 * 0x3D = -0.5 dB
531 * 0xF0 = -90 dB
536 * register value 0x3c(0dB) 0xf0(-90dB)0xfc
537 * ------------------------------
561 l = 0xfc - l; in dac_get_volsw()
562 r = 0xfc - r; in dac_get_volsw()
564 ucontrol->value.integer.value[0] = l; in dac_get_volsw()
565 ucontrol->value.integer.value[1] = r; in dac_get_volsw()
574 * 15-------------8-7--------------0
575 * | R channel vol | L channel vol |
576 * -------------------------------
578 * PCM volume with 0.5017 dB steps from 0 to -90 dB
583 * 0x3D = -0.5 dB
584 * 0xF0 = -90 dB
590 * ------------------------------
591 * register value 0x3c(0dB) 0xf0(-90dB)0xfc
601 l = ucontrol->value.integer.value[0]; in dac_put_volsw()
602 r = ucontrol->value.integer.value[1]; in dac_put_volsw()
604 /* make sure userspace volume fall in (0, 0xfc-0x3c) */ in dac_put_volsw()
605 l = clamp(l, 0, 0xfc - 0x3c); in dac_put_volsw()
606 r = clamp(r, 0, 0xfc - 0x3c); in dac_put_volsw()
609 l = 0xfc - l; in dac_put_volsw()
610 r = 0xfc - r; in dac_put_volsw()
626 * dB = ( fls(register_value) - 14.347 ) * 6.02
629 * 0 to 96 we use pre-calculated values.
638 /* register value 0 => -96dB */ in avc_get_threshold()
640 ucontrol->value.integer.value[0] = 96; in avc_get_threshold()
641 ucontrol->value.integer.value[1] = 96; in avc_get_threshold()
650 ucontrol->value.integer.value[0] = db; in avc_get_threshold()
651 ucontrol->value.integer.value[1] = db; in avc_get_threshold()
662 * 0 to 96 we use pre-calculated values.
671 db = (int)ucontrol->value.integer.value[0]; in avc_put_threshold()
673 return -EINVAL; in avc_put_threshold()
680 static const DECLARE_TLV_DB_SCALE(capture_6db_attenuate, -600, 600, 0);
688 /* tlv for DAP channels, 0% - 100% - 200% */
691 /* tlv for bass bands, -11.75db to 12.0db, step .25db */
692 static const DECLARE_TLV_DB_SCALE(bass_band, -1175, 25, 0);
694 /* tlv for hp volume, -51.5db to 12.0db, step .5db */
695 static const DECLARE_TLV_DB_SCALE(headphone_volume, -5150, 50, 0);
698 static const DECLARE_TLV_DB_SCALE(lineout_volume, -1550, 50, 0);
719 SOC_SINGLE_TLV("Capture Attenuate Switch (-6dB)",
780 struct snd_soc_component *component = codec_dai->component; in sgtl5000_mute_stream()
786 * only I2S block - this can be done by powering it off in sgtl5000_mute_stream()
797 struct snd_soc_component *component = codec_dai->component; in sgtl5000_set_dai_fmt()
801 sgtl5000->master = 0; in sgtl5000_set_dai_fmt()
805 * - clock and frame slave, in sgtl5000_set_dai_fmt()
806 * - clock and frame master in sgtl5000_set_dai_fmt()
813 sgtl5000->master = 1; in sgtl5000_set_dai_fmt()
816 return -EINVAL; in sgtl5000_set_dai_fmt()
840 return -EINVAL; in sgtl5000_set_dai_fmt()
843 sgtl5000->fmt = fmt & SND_SOC_DAIFMT_FORMAT_MASK; in sgtl5000_set_dai_fmt()
853 return -EINVAL; in sgtl5000_set_dai_fmt()
865 struct snd_soc_component *component = codec_dai->component; in sgtl5000_set_dai_sysclk()
870 sgtl5000->sysclk = freq; in sgtl5000_set_dai_sysclk()
873 return -EINVAL; in sgtl5000_set_dai_sysclk()
929 return -EINVAL; in sgtl5000_set_clock()
947 dev_err(component->dev, "frame rate %d not supported\n", in sgtl5000_set_clock()
949 return -EINVAL; in sgtl5000_set_clock()
955 * of 8 MHz - 27 MHz in sgtl5000_set_clock()
957 switch (sgtl5000->sysclk / frame_rate) { in sgtl5000_set_clock()
972 if (sgtl5000->master) { in sgtl5000_set_clock()
976 dev_err(component->dev, in sgtl5000_set_clock()
978 dev_err(component->dev, "%d ratio is not supported. " in sgtl5000_set_clock()
980 sgtl5000->sysclk / frame_rate); in sgtl5000_set_clock()
981 return -EINVAL; in sgtl5000_set_clock()
992 if (sgtl5000->sysclk > 17000000) { in sgtl5000_set_clock()
994 in = sgtl5000->sysclk / 2; in sgtl5000_set_clock()
997 in = sgtl5000->sysclk; in sgtl5000_set_clock()
1051 struct snd_soc_component *component = dai->component; in sgtl5000_pcm_hw_params()
1059 if (!sgtl5000->sysclk) { in sgtl5000_pcm_hw_params()
1060 dev_err(component->dev, "%s: set sysclk first!\n", __func__); in sgtl5000_pcm_hw_params()
1061 return -EFAULT; in sgtl5000_pcm_hw_params()
1064 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) in sgtl5000_pcm_hw_params()
1081 if (sgtl5000->fmt == SND_SOC_DAIFMT_RIGHT_J) in sgtl5000_pcm_hw_params()
1082 return -EINVAL; in sgtl5000_pcm_hw_params()
1098 if (sgtl5000->fmt == SND_SOC_DAIFMT_RIGHT_J) in sgtl5000_pcm_hw_params()
1099 return -EINVAL; in sgtl5000_pcm_hw_params()
1105 return -EINVAL; in sgtl5000_pcm_hw_params()
1119 * off --> standby --> prepare --> on
1120 * standby --> prepare --> on
1123 * on --> prepare --> standby
1135 regcache_cache_only(sgtl->regmap, false); in sgtl5000_set_bias_level()
1136 ret = regcache_sync(sgtl->regmap); in sgtl5000_set_bias_level()
1138 regcache_cache_only(sgtl->regmap, true); in sgtl5000_set_bias_level()
1147 regcache_cache_only(sgtl->regmap, true); in sgtl5000_set_bias_level()
1281 * 2. charge pump, set to different value
1303 vdda = regulator_get_voltage(sgtl5000->supplies[VDDA].consumer); in sgtl5000_set_power_regs()
1304 vddio = regulator_get_voltage(sgtl5000->supplies[VDDIO].consumer); in sgtl5000_set_power_regs()
1305 vddd = (sgtl5000->num_supplies > VDDD) in sgtl5000_set_power_regs()
1306 ? regulator_get_voltage(sgtl5000->supplies[VDDD].consumer) in sgtl5000_set_power_regs()
1314 dev_err(component->dev, "regulator voltage not set correctly\n"); in sgtl5000_set_power_regs()
1316 return -EINVAL; in sgtl5000_set_power_regs()
1321 dev_err(component->dev, in sgtl5000_set_power_regs()
1325 return -EINVAL; in sgtl5000_set_power_regs()
1336 /* enable internal oscillator used for charge pump */ in sgtl5000_set_power_regs()
1340 /* Enable VDDC charge pump */ in sgtl5000_set_power_regs()
1345 * if vddio == vdda the source of charge pump should be in sgtl5000_set_power_regs()
1348 if (regulator_is_equal(sgtl5000->supplies[VDDA].consumer, in sgtl5000_set_power_regs()
1349 sgtl5000->supplies[VDDIO].consumer)) { in sgtl5000_set_power_regs()
1371 vag = (vag - SGTL5000_ANA_GND_BASE) / SGTL5000_ANA_GND_STP; in sgtl5000_set_power_regs()
1384 lo_vag = (lo_vag - SGTL5000_LINE_OUT_GND_BASE) / in sgtl5000_set_power_regs()
1427 for (i = 0; i < ARRAY_SIZE(sgtl5000->supplies); i++) in sgtl5000_enable_regulators()
1428 sgtl5000->supplies[i].supply = supply_names[i]; in sgtl5000_enable_regulators()
1430 vddd = regulator_get_optional(&client->dev, "VDDD"); in sgtl5000_enable_regulators()
1433 if (PTR_ERR(vddd) == -EPROBE_DEFER) in sgtl5000_enable_regulators()
1434 return -EPROBE_DEFER; in sgtl5000_enable_regulators()
1440 sgtl5000->num_supplies = ARRAY_SIZE(sgtl5000->supplies) in sgtl5000_enable_regulators()
1441 - 1 + external_vddd; in sgtl5000_enable_regulators()
1442 ret = regulator_bulk_get(&client->dev, sgtl5000->num_supplies, in sgtl5000_enable_regulators()
1443 sgtl5000->supplies); in sgtl5000_enable_regulators()
1447 ret = regulator_bulk_enable(sgtl5000->num_supplies, in sgtl5000_enable_regulators()
1448 sgtl5000->supplies); in sgtl5000_enable_regulators()
1452 regulator_bulk_free(sgtl5000->num_supplies, in sgtl5000_enable_regulators()
1453 sgtl5000->supplies); in sgtl5000_enable_regulators()
1486 reg = ((sgtl5000->lrclk_strength) << SGTL5000_PAD_I2S_LRCLK_SHIFT | in sgtl5000_probe()
1487 (sgtl5000->sclk_strength) << SGTL5000_PAD_I2S_SCLK_SHIFT | in sgtl5000_probe()
1496 sgtl5000->micbias_resistor << SGTL5000_BIAS_R_SHIFT); in sgtl5000_probe()
1500 sgtl5000->micbias_voltage << SGTL5000_BIAS_VOLT_SHIFT); in sgtl5000_probe()
1573 ret = regmap_write(sgtl5000->regmap, index, val); in sgtl5000_fill_defaults()
1575 dev_err(&client->dev, in sgtl5000_fill_defaults()
1585 struct device_node *np = client->dev.of_node; in sgtl5000_i2c_probe()
1589 sgtl5000 = devm_kzalloc(&client->dev, sizeof(*sgtl5000), GFP_KERNEL); in sgtl5000_i2c_probe()
1591 return -ENOMEM; in sgtl5000_i2c_probe()
1599 sgtl5000->regmap = devm_regmap_init_i2c(client, &sgtl5000_regmap); in sgtl5000_i2c_probe()
1600 if (IS_ERR(sgtl5000->regmap)) { in sgtl5000_i2c_probe()
1601 ret = PTR_ERR(sgtl5000->regmap); in sgtl5000_i2c_probe()
1602 dev_err(&client->dev, "Failed to allocate regmap: %d\n", ret); in sgtl5000_i2c_probe()
1606 sgtl5000->mclk = devm_clk_get(&client->dev, NULL); in sgtl5000_i2c_probe()
1607 if (IS_ERR(sgtl5000->mclk)) { in sgtl5000_i2c_probe()
1608 ret = PTR_ERR(sgtl5000->mclk); in sgtl5000_i2c_probe()
1610 if (ret == -ENOENT) in sgtl5000_i2c_probe()
1611 ret = -EPROBE_DEFER; in sgtl5000_i2c_probe()
1613 dev_err_probe(&client->dev, ret, "Failed to get mclock\n"); in sgtl5000_i2c_probe()
1618 ret = clk_prepare_enable(sgtl5000->mclk); in sgtl5000_i2c_probe()
1620 dev_err(&client->dev, "Error enabling clock %d\n", ret); in sgtl5000_i2c_probe()
1628 ret = regmap_read(sgtl5000->regmap, SGTL5000_CHIP_ID, ®); in sgtl5000_i2c_probe()
1630 dev_err(&client->dev, "Error reading chip id %d\n", ret); in sgtl5000_i2c_probe()
1636 dev_err(&client->dev, in sgtl5000_i2c_probe()
1638 ret = -ENODEV; in sgtl5000_i2c_probe()
1643 dev_info(&client->dev, "sgtl5000 revision 0x%x\n", rev); in sgtl5000_i2c_probe()
1644 sgtl5000->revision = rev; in sgtl5000_i2c_probe()
1647 ret = regmap_write(sgtl5000->regmap, in sgtl5000_i2c_probe()
1651 dev_err(&client->dev, in sgtl5000_i2c_probe()
1654 /* Mute everything to avoid pop from the following power-up */ in sgtl5000_i2c_probe()
1655 ret = regmap_write(sgtl5000->regmap, SGTL5000_CHIP_ANA_CTRL, in sgtl5000_i2c_probe()
1658 dev_err(&client->dev, in sgtl5000_i2c_probe()
1664 * If VAG is powered-on (e.g. from previous boot), it would be disabled in sgtl5000_i2c_probe()
1668 * cool-down time. in sgtl5000_i2c_probe()
1670 ret = regmap_read(sgtl5000->regmap, SGTL5000_CHIP_ANA_POWER, &value); in sgtl5000_i2c_probe()
1672 dev_err(&client->dev, "Failed to read ANA_POWER: %d\n", ret); in sgtl5000_i2c_probe()
1676 ret = regmap_update_bits(sgtl5000->regmap, in sgtl5000_i2c_probe()
1681 dev_err(&client->dev, "Error %d disabling VAG\n", ret); in sgtl5000_i2c_probe()
1690 if (sgtl5000->num_supplies <= VDDD) { in sgtl5000_i2c_probe()
1692 ret = regmap_update_bits(sgtl5000->regmap, in sgtl5000_i2c_probe()
1697 dev_err(&client->dev, in sgtl5000_i2c_probe()
1701 dev_info(&client->dev, in sgtl5000_i2c_probe()
1710 dev_dbg(&client->dev, "Using external VDDD\n"); in sgtl5000_i2c_probe()
1712 ret = regmap_write(sgtl5000->regmap, SGTL5000_CHIP_ANA_POWER, ana_pwr); in sgtl5000_i2c_probe()
1714 dev_err(&client->dev, in sgtl5000_i2c_probe()
1720 "micbias-resistor-k-ohms", &value)) { in sgtl5000_i2c_probe()
1723 sgtl5000->micbias_resistor = 0; in sgtl5000_i2c_probe()
1726 sgtl5000->micbias_resistor = 1; in sgtl5000_i2c_probe()
1729 sgtl5000->micbias_resistor = 2; in sgtl5000_i2c_probe()
1732 sgtl5000->micbias_resistor = 3; in sgtl5000_i2c_probe()
1735 sgtl5000->micbias_resistor = 2; in sgtl5000_i2c_probe()
1736 dev_err(&client->dev, in sgtl5000_i2c_probe()
1741 sgtl5000->micbias_resistor = 2; in sgtl5000_i2c_probe()
1744 "micbias-voltage-m-volts", &value)) { in sgtl5000_i2c_probe()
1748 sgtl5000->micbias_voltage = (value / 250) - 5; in sgtl5000_i2c_probe()
1750 sgtl5000->micbias_voltage = 0; in sgtl5000_i2c_probe()
1751 dev_err(&client->dev, in sgtl5000_i2c_probe()
1755 sgtl5000->micbias_voltage = 0; in sgtl5000_i2c_probe()
1759 sgtl5000->lrclk_strength = I2S_LRCLK_STRENGTH_LOW; in sgtl5000_i2c_probe()
1760 if (!of_property_read_u32(np, "lrclk-strength", &value)) { in sgtl5000_i2c_probe()
1763 sgtl5000->lrclk_strength = value; in sgtl5000_i2c_probe()
1766 sgtl5000->sclk_strength = I2S_SCLK_STRENGTH_LOW; in sgtl5000_i2c_probe()
1767 if (!of_property_read_u32(np, "sclk-strength", &value)) { in sgtl5000_i2c_probe()
1770 sgtl5000->sclk_strength = value; in sgtl5000_i2c_probe()
1776 ret = devm_snd_soc_register_component(&client->dev, in sgtl5000_i2c_probe()
1784 clk_disable_unprepare(sgtl5000->mclk); in sgtl5000_i2c_probe()
1787 regulator_bulk_disable(sgtl5000->num_supplies, sgtl5000->supplies); in sgtl5000_i2c_probe()
1788 regulator_bulk_free(sgtl5000->num_supplies, sgtl5000->supplies); in sgtl5000_i2c_probe()
1797 regmap_write(sgtl5000->regmap, SGTL5000_CHIP_CLK_CTRL, SGTL5000_CHIP_CLK_CTRL_DEFAULT); in sgtl5000_i2c_remove()
1798 regmap_write(sgtl5000->regmap, SGTL5000_CHIP_DIG_POWER, SGTL5000_DIG_POWER_DEFAULT); in sgtl5000_i2c_remove()
1799 regmap_write(sgtl5000->regmap, SGTL5000_CHIP_ANA_POWER, SGTL5000_ANA_POWER_DEFAULT); in sgtl5000_i2c_remove()
1801 clk_disable_unprepare(sgtl5000->mclk); in sgtl5000_i2c_remove()
1802 regulator_bulk_disable(sgtl5000->num_supplies, sgtl5000->supplies); in sgtl5000_i2c_remove()
1803 regulator_bulk_free(sgtl5000->num_supplies, sgtl5000->supplies); in sgtl5000_i2c_remove()