• Home
  • Raw
  • Download

Lines Matching +full:lrclk +full:- +full:strength

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)
182 /* When VAG powering on to get local loop from Line-In, the sleep in vag_power_on()
202 * If the event comes from HP and Line-In is selected, in vag_power_consumers()
204 * As HP_POWERUP is not set when HP muxed to line-in, in vag_power_consumers()
232 * - LINE_IN (for HP events) / HP (for DAC/ADC events) in vag_power_off()
233 * - DAC in vag_power_off()
234 * - ADC in vag_power_off()
242 /* In power down case, we need wait 400-1000 ms in vag_power_off()
261 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in mic_bias_event()
269 sgtl5000->micbias_resistor << SGTL5000_BIAS_R_SHIFT); in mic_bias_event()
293 * both headphones and line-out. in vag_and_mute_control()
304 sgtl5000->mute_state[event_source] = in vag_and_mute_control()
310 sgtl5000->mute_state[event_source]); in vag_and_mute_control()
313 sgtl5000->mute_state[event_source] = in vag_and_mute_control()
319 sgtl5000->mute_state[event_source]); in vag_and_mute_control()
336 snd_soc_dapm_to_component(w->dapm); in headphone_pga_event()
349 snd_soc_dapm_to_component(w->dapm); in adc_updown_depop()
358 snd_soc_dapm_to_component(w->dapm); in dac_updown_depop()
469 {"Capture Mux", "LINE_IN", "LINE_IN"}, /* line_in --> adc_mux */
470 {"Capture Mux", "MIC_IN", "MIC_IN"}, /* mic_in --> adc_mux */
472 {"ADC", NULL, "Capture Mux"}, /* adc_mux --> adc */
473 {"AIFOUT", NULL, "ADC"}, /* adc --> i2s_out */
475 {"DAP Mux", "ADC", "ADC"}, /* adc --> DAP mux */
476 {"DAP Mux", NULL, "AIFIN"}, /* i2s --> DAP mux */
477 {"DAP", NULL, "DAP Mux"}, /* DAP mux --> dap */
479 {"DAP MIX Mux", "ADC", "ADC"}, /* adc --> DAP MIX mux */
480 {"DAP MIX Mux", NULL, "AIFIN"}, /* i2s --> DAP MIX mux */
481 {"DAP", NULL, "DAP MIX Mux"}, /* DAP MIX mux --> dap */
483 {"Digital Input Mux", "ADC", "ADC"}, /* adc --> audio mux */
484 {"Digital Input Mux", NULL, "AIFIN"}, /* i2s --> audio mux */
485 {"Digital Input Mux", NULL, "DAP"}, /* dap --> audio mux */
486 {"DAC", NULL, "Digital Input Mux"}, /* audio mux --> dac */
488 {"Headphone Mux", "DAC", "DAC"}, /* dac --> hp_mux */
489 {"LO", NULL, "DAC"}, /* dac --> line_out */
491 {"Headphone Mux", "LINE_IN", "LINE_IN"},/* line_in --> hp_mux */
492 {"HP", NULL, "Headphone Mux"}, /* hp_mux --> hp */
502 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; in dac_info_volsw()
503 uinfo->count = 2; in dac_info_volsw()
504 uinfo->value.integer.min = 0; in dac_info_volsw()
505 uinfo->value.integer.max = 0xfc - 0x3c; in dac_info_volsw()
513 * 15-------------8-7--------------0
515 * -------------------------------
517 * PCM volume with 0.5017 dB steps from 0 to -90 dB
522 * 0x3D = -0.5 dB
523 * 0xF0 = -90 dB
528 * register value 0x3c(0dB) 0xf0(-90dB)0xfc
529 * ------------------------------
553 l = 0xfc - l; in dac_get_volsw()
554 r = 0xfc - r; in dac_get_volsw()
556 ucontrol->value.integer.value[0] = l; in dac_get_volsw()
557 ucontrol->value.integer.value[1] = r; in dac_get_volsw()
566 * 15-------------8-7--------------0
568 * -------------------------------
570 * PCM volume with 0.5017 dB steps from 0 to -90 dB
575 * 0x3D = -0.5 dB
576 * 0xF0 = -90 dB
582 * ------------------------------
583 * register value 0x3c(0dB) 0xf0(-90dB)0xfc
593 l = ucontrol->value.integer.value[0]; in dac_put_volsw()
594 r = ucontrol->value.integer.value[1]; in dac_put_volsw()
596 /* make sure userspace volume fall in (0, 0xfc-0x3c) */ in dac_put_volsw()
597 l = clamp(l, 0, 0xfc - 0x3c); in dac_put_volsw()
598 r = clamp(r, 0, 0xfc - 0x3c); in dac_put_volsw()
601 l = 0xfc - l; in dac_put_volsw()
602 r = 0xfc - r; in dac_put_volsw()
618 * dB = ( fls(register_value) - 14.347 ) * 6.02
621 * 0 to 96 we use pre-calculated values.
630 /* register value 0 => -96dB */ in avc_get_threshold()
632 ucontrol->value.integer.value[0] = 96; in avc_get_threshold()
633 ucontrol->value.integer.value[1] = 96; in avc_get_threshold()
642 ucontrol->value.integer.value[0] = db; in avc_get_threshold()
643 ucontrol->value.integer.value[1] = db; in avc_get_threshold()
654 * 0 to 96 we use pre-calculated values.
663 db = (int)ucontrol->value.integer.value[0]; in avc_put_threshold()
665 return -EINVAL; in avc_put_threshold()
672 static const DECLARE_TLV_DB_SCALE(capture_6db_attenuate, -600, 600, 0);
680 /* tlv for DAP channels, 0% - 100% - 200% */
683 /* tlv for bass bands, -11.75db to 12.0db, step .25db */
684 static const DECLARE_TLV_DB_SCALE(bass_band, -1175, 25, 0);
686 /* tlv for hp volume, -51.5db to 12.0db, step .5db */
687 static const DECLARE_TLV_DB_SCALE(headphone_volume, -5150, 50, 0);
690 static const DECLARE_TLV_DB_SCALE(lineout_volume, -1550, 50, 0);
711 SOC_SINGLE_TLV("Capture Attenuate Switch (-6dB)",
771 struct snd_soc_component *component = codec_dai->component; in sgtl5000_digital_mute()
777 * only I2S block - this can be done by powering it off in sgtl5000_digital_mute()
788 struct snd_soc_component *component = codec_dai->component; in sgtl5000_set_dai_fmt()
792 sgtl5000->master = 0; in sgtl5000_set_dai_fmt()
796 * - clock and frame slave, in sgtl5000_set_dai_fmt()
797 * - clock and frame master in sgtl5000_set_dai_fmt()
804 sgtl5000->master = 1; in sgtl5000_set_dai_fmt()
807 return -EINVAL; in sgtl5000_set_dai_fmt()
831 return -EINVAL; in sgtl5000_set_dai_fmt()
834 sgtl5000->fmt = fmt & SND_SOC_DAIFMT_FORMAT_MASK; in sgtl5000_set_dai_fmt()
844 return -EINVAL; in sgtl5000_set_dai_fmt()
856 struct snd_soc_component *component = codec_dai->component; in sgtl5000_set_dai_sysclk()
861 sgtl5000->sysclk = freq; in sgtl5000_set_dai_sysclk()
864 return -EINVAL; in sgtl5000_set_dai_sysclk()
920 return -EINVAL; in sgtl5000_set_clock()
938 dev_err(component->dev, "frame rate %d not supported\n", in sgtl5000_set_clock()
940 return -EINVAL; in sgtl5000_set_clock()
946 * of 8 MHz - 27 MHz in sgtl5000_set_clock()
948 switch (sgtl5000->sysclk / frame_rate) { in sgtl5000_set_clock()
963 if (sgtl5000->master) { in sgtl5000_set_clock()
967 dev_err(component->dev, in sgtl5000_set_clock()
969 dev_err(component->dev, "%d ratio is not supported. " in sgtl5000_set_clock()
971 sgtl5000->sysclk / frame_rate); in sgtl5000_set_clock()
972 return -EINVAL; in sgtl5000_set_clock()
983 if (sgtl5000->sysclk > 17000000) { in sgtl5000_set_clock()
985 in = sgtl5000->sysclk / 2; in sgtl5000_set_clock()
988 in = sgtl5000->sysclk; in sgtl5000_set_clock()
1042 struct snd_soc_component *component = dai->component; in sgtl5000_pcm_hw_params()
1050 if (!sgtl5000->sysclk) { in sgtl5000_pcm_hw_params()
1051 dev_err(component->dev, "%s: set sysclk first!\n", __func__); in sgtl5000_pcm_hw_params()
1052 return -EFAULT; in sgtl5000_pcm_hw_params()
1055 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) in sgtl5000_pcm_hw_params()
1064 /* set codec clock base on lrclk */ in sgtl5000_pcm_hw_params()
1072 if (sgtl5000->fmt == SND_SOC_DAIFMT_RIGHT_J) in sgtl5000_pcm_hw_params()
1073 return -EINVAL; in sgtl5000_pcm_hw_params()
1089 if (sgtl5000->fmt == SND_SOC_DAIFMT_RIGHT_J) in sgtl5000_pcm_hw_params()
1090 return -EINVAL; in sgtl5000_pcm_hw_params()
1096 return -EINVAL; in sgtl5000_pcm_hw_params()
1110 * off --> standby --> prepare --> on
1111 * standby --> prepare --> on
1114 * on --> prepare --> standby
1126 regcache_cache_only(sgtl->regmap, false); in sgtl5000_set_bias_level()
1127 ret = regcache_sync(sgtl->regmap); in sgtl5000_set_bias_level()
1129 regcache_cache_only(sgtl->regmap, true); in sgtl5000_set_bias_level()
1138 regcache_cache_only(sgtl->regmap, true); in sgtl5000_set_bias_level()
1293 vdda = regulator_get_voltage(sgtl5000->supplies[VDDA].consumer); in sgtl5000_set_power_regs()
1294 vddio = regulator_get_voltage(sgtl5000->supplies[VDDIO].consumer); in sgtl5000_set_power_regs()
1295 vddd = (sgtl5000->num_supplies > VDDD) in sgtl5000_set_power_regs()
1296 ? regulator_get_voltage(sgtl5000->supplies[VDDD].consumer) in sgtl5000_set_power_regs()
1304 dev_err(component->dev, "regulator voltage not set correctly\n"); in sgtl5000_set_power_regs()
1306 return -EINVAL; in sgtl5000_set_power_regs()
1311 dev_err(component->dev, in sgtl5000_set_power_regs()
1315 return -EINVAL; in sgtl5000_set_power_regs()
1360 vag = (vag - SGTL5000_ANA_GND_BASE) / SGTL5000_ANA_GND_STP; in sgtl5000_set_power_regs()
1373 lo_vag = (lo_vag - SGTL5000_LINE_OUT_GND_BASE) / in sgtl5000_set_power_regs()
1416 for (i = 0; i < ARRAY_SIZE(sgtl5000->supplies); i++) in sgtl5000_enable_regulators()
1417 sgtl5000->supplies[i].supply = supply_names[i]; in sgtl5000_enable_regulators()
1419 vddd = regulator_get_optional(&client->dev, "VDDD"); in sgtl5000_enable_regulators()
1422 if (PTR_ERR(vddd) == -EPROBE_DEFER) in sgtl5000_enable_regulators()
1423 return -EPROBE_DEFER; in sgtl5000_enable_regulators()
1429 sgtl5000->num_supplies = ARRAY_SIZE(sgtl5000->supplies) in sgtl5000_enable_regulators()
1430 - 1 + external_vddd; in sgtl5000_enable_regulators()
1431 ret = regulator_bulk_get(&client->dev, sgtl5000->num_supplies, in sgtl5000_enable_regulators()
1432 sgtl5000->supplies); in sgtl5000_enable_regulators()
1436 ret = regulator_bulk_enable(sgtl5000->num_supplies, in sgtl5000_enable_regulators()
1437 sgtl5000->supplies); in sgtl5000_enable_regulators()
1441 regulator_bulk_free(sgtl5000->num_supplies, in sgtl5000_enable_regulators()
1442 sgtl5000->supplies); in sgtl5000_enable_regulators()
1475 reg = ((sgtl5000->lrclk_strength) << SGTL5000_PAD_I2S_LRCLK_SHIFT | 0x5f); in sgtl5000_probe()
1483 sgtl5000->micbias_resistor << SGTL5000_BIAS_R_SHIFT); in sgtl5000_probe()
1487 sgtl5000->micbias_voltage << SGTL5000_BIAS_VOLT_SHIFT); in sgtl5000_probe()
1553 ret = regmap_write(sgtl5000->regmap, index, val); in sgtl5000_fill_defaults()
1555 dev_err(&client->dev, in sgtl5000_fill_defaults()
1566 struct device_node *np = client->dev.of_node; in sgtl5000_i2c_probe()
1570 sgtl5000 = devm_kzalloc(&client->dev, sizeof(*sgtl5000), GFP_KERNEL); in sgtl5000_i2c_probe()
1572 return -ENOMEM; in sgtl5000_i2c_probe()
1580 sgtl5000->regmap = devm_regmap_init_i2c(client, &sgtl5000_regmap); in sgtl5000_i2c_probe()
1581 if (IS_ERR(sgtl5000->regmap)) { in sgtl5000_i2c_probe()
1582 ret = PTR_ERR(sgtl5000->regmap); in sgtl5000_i2c_probe()
1583 dev_err(&client->dev, "Failed to allocate regmap: %d\n", ret); in sgtl5000_i2c_probe()
1587 sgtl5000->mclk = devm_clk_get(&client->dev, NULL); in sgtl5000_i2c_probe()
1588 if (IS_ERR(sgtl5000->mclk)) { in sgtl5000_i2c_probe()
1589 ret = PTR_ERR(sgtl5000->mclk); in sgtl5000_i2c_probe()
1591 if (ret == -ENOENT) in sgtl5000_i2c_probe()
1592 ret = -EPROBE_DEFER; in sgtl5000_i2c_probe()
1594 if (ret != -EPROBE_DEFER) in sgtl5000_i2c_probe()
1595 dev_err(&client->dev, "Failed to get mclock: %d\n", in sgtl5000_i2c_probe()
1600 ret = clk_prepare_enable(sgtl5000->mclk); in sgtl5000_i2c_probe()
1602 dev_err(&client->dev, "Error enabling clock %d\n", ret); in sgtl5000_i2c_probe()
1610 ret = regmap_read(sgtl5000->regmap, SGTL5000_CHIP_ID, &reg); in sgtl5000_i2c_probe()
1612 dev_err(&client->dev, "Error reading chip id %d\n", ret); in sgtl5000_i2c_probe()
1618 dev_err(&client->dev, in sgtl5000_i2c_probe()
1620 ret = -ENODEV; in sgtl5000_i2c_probe()
1625 dev_info(&client->dev, "sgtl5000 revision 0x%x\n", rev); in sgtl5000_i2c_probe()
1626 sgtl5000->revision = rev; in sgtl5000_i2c_probe()
1629 ret = regmap_write(sgtl5000->regmap, in sgtl5000_i2c_probe()
1633 dev_err(&client->dev, in sgtl5000_i2c_probe()
1636 /* Mute everything to avoid pop from the following power-up */ in sgtl5000_i2c_probe()
1637 ret = regmap_write(sgtl5000->regmap, SGTL5000_CHIP_ANA_CTRL, in sgtl5000_i2c_probe()
1640 dev_err(&client->dev, in sgtl5000_i2c_probe()
1646 * If VAG is powered-on (e.g. from previous boot), it would be disabled in sgtl5000_i2c_probe()
1650 * cool-down time. in sgtl5000_i2c_probe()
1652 ret = regmap_read(sgtl5000->regmap, SGTL5000_CHIP_ANA_POWER, &value); in sgtl5000_i2c_probe()
1654 dev_err(&client->dev, "Failed to read ANA_POWER: %d\n", ret); in sgtl5000_i2c_probe()
1658 ret = regmap_update_bits(sgtl5000->regmap, in sgtl5000_i2c_probe()
1663 dev_err(&client->dev, "Error %d disabling VAG\n", ret); in sgtl5000_i2c_probe()
1672 if (sgtl5000->num_supplies <= VDDD) { in sgtl5000_i2c_probe()
1674 ret = regmap_update_bits(sgtl5000->regmap, in sgtl5000_i2c_probe()
1679 dev_err(&client->dev, in sgtl5000_i2c_probe()
1683 dev_info(&client->dev, in sgtl5000_i2c_probe()
1692 dev_dbg(&client->dev, "Using external VDDD\n"); in sgtl5000_i2c_probe()
1694 ret = regmap_write(sgtl5000->regmap, SGTL5000_CHIP_ANA_POWER, ana_pwr); in sgtl5000_i2c_probe()
1696 dev_err(&client->dev, in sgtl5000_i2c_probe()
1702 "micbias-resistor-k-ohms", &value)) { in sgtl5000_i2c_probe()
1705 sgtl5000->micbias_resistor = 0; in sgtl5000_i2c_probe()
1708 sgtl5000->micbias_resistor = 1; in sgtl5000_i2c_probe()
1711 sgtl5000->micbias_resistor = 2; in sgtl5000_i2c_probe()
1714 sgtl5000->micbias_resistor = 3; in sgtl5000_i2c_probe()
1717 sgtl5000->micbias_resistor = 2; in sgtl5000_i2c_probe()
1718 dev_err(&client->dev, in sgtl5000_i2c_probe()
1723 sgtl5000->micbias_resistor = 2; in sgtl5000_i2c_probe()
1726 "micbias-voltage-m-volts", &value)) { in sgtl5000_i2c_probe()
1730 sgtl5000->micbias_voltage = (value / 250) - 5; in sgtl5000_i2c_probe()
1732 sgtl5000->micbias_voltage = 0; in sgtl5000_i2c_probe()
1733 dev_err(&client->dev, in sgtl5000_i2c_probe()
1737 sgtl5000->micbias_voltage = 0; in sgtl5000_i2c_probe()
1741 sgtl5000->lrclk_strength = I2S_LRCLK_STRENGTH_LOW; in sgtl5000_i2c_probe()
1742 if (!of_property_read_u32(np, "lrclk-strength", &value)) { in sgtl5000_i2c_probe()
1745 sgtl5000->lrclk_strength = value; in sgtl5000_i2c_probe()
1751 ret = devm_snd_soc_register_component(&client->dev, in sgtl5000_i2c_probe()
1759 clk_disable_unprepare(sgtl5000->mclk); in sgtl5000_i2c_probe()
1762 regulator_bulk_disable(sgtl5000->num_supplies, sgtl5000->supplies); in sgtl5000_i2c_probe()
1763 regulator_bulk_free(sgtl5000->num_supplies, sgtl5000->supplies); in sgtl5000_i2c_probe()
1772 clk_disable_unprepare(sgtl5000->mclk); in sgtl5000_i2c_remove()
1773 regulator_bulk_disable(sgtl5000->num_supplies, sgtl5000->supplies); in sgtl5000_i2c_remove()
1774 regulator_bulk_free(sgtl5000->num_supplies, sgtl5000->supplies); in sgtl5000_i2c_remove()