• Home
  • Raw
  • Download

Lines Matching +full:pga +full:- +full:gain

2  * da7219.c - DA7219 ALSA SoC Codec Driver
17 #include <linux/clk-provider.h>
30 #include <sound/soc-dapm.h>
37 #include "da7219-aad.h"
45 static const DECLARE_TLV_DB_SCALE(da7219_mic_gain_tlv, -600, 600, 0);
46 static const DECLARE_TLV_DB_SCALE(da7219_mixin_gain_tlv, -450, 150, 0);
47 static const DECLARE_TLV_DB_SCALE(da7219_adc_dig_gain_tlv, -8325, 75, 0);
48 static const DECLARE_TLV_DB_SCALE(da7219_alc_threshold_tlv, -9450, 150, 0);
51 static const DECLARE_TLV_DB_SCALE(da7219_sidetone_gain_tlv, -4200, 300, 0);
52 static const DECLARE_TLV_DB_SCALE(da7219_tonegen_gain_tlv, -4500, 300, 0);
55 static const DECLARE_TLV_DB_SCALE(da7219_dac_eq_band_tlv, -1050, 150, 0);
59 /* -77.25dB to 12dB */
60 0x08, 0x7f, TLV_DB_SCALE_ITEM(-7725, 75, 0)
63 static const DECLARE_TLV_DB_SCALE(da7219_dac_ng_threshold_tlv, -10200, 600, 0);
64 static const DECLARE_TLV_DB_SCALE(da7219_hp_gain_tlv, -5700, 100, 0);
188 "Sum", "SWG1", "SWG2", "SWG1_1-Cos"
265 mutex_lock(&da7219->ctrl_lock); in da7219_volsw_locked_get()
267 mutex_unlock(&da7219->ctrl_lock); in da7219_volsw_locked_get()
279 mutex_lock(&da7219->ctrl_lock); in da7219_volsw_locked_put()
281 mutex_unlock(&da7219->ctrl_lock); in da7219_volsw_locked_put()
293 mutex_lock(&da7219->ctrl_lock); in da7219_enum_locked_get()
295 mutex_unlock(&da7219->ctrl_lock); in da7219_enum_locked_get()
307 mutex_lock(&da7219->ctrl_lock); in da7219_enum_locked_put()
309 mutex_unlock(&da7219->ctrl_lock); in da7219_enum_locked_put()
356 dev_warn(component->dev, in da7219_alc_calib()
393 if ((ret == 1) && (da7219->alc_en)) in da7219_mixin_gain_put()
407 if ((ucontrol->value.integer.value[0]) && (!da7219->alc_en)) { in da7219_alc_sw_put()
409 da7219->alc_en = true; in da7219_alc_sw_put()
411 da7219->alc_en = false; in da7219_alc_sw_put()
424 (struct soc_mixer_control *) kcontrol->private_value; in da7219_tonegen_freq_get()
425 unsigned int reg = mixer_ctrl->reg; in da7219_tonegen_freq_get()
429 mutex_lock(&da7219->ctrl_lock); in da7219_tonegen_freq_get()
430 ret = regmap_raw_read(da7219->regmap, reg, &val, sizeof(val)); in da7219_tonegen_freq_get()
431 mutex_unlock(&da7219->ctrl_lock); in da7219_tonegen_freq_get()
437 * Frequency value spans two 8-bit registers, lower then upper byte. in da7219_tonegen_freq_get()
440 ucontrol->value.integer.value[0] = le16_to_cpu(val); in da7219_tonegen_freq_get()
451 (struct soc_mixer_control *) kcontrol->private_value; in da7219_tonegen_freq_put()
452 unsigned int reg = mixer_ctrl->reg; in da7219_tonegen_freq_put()
457 * Frequency value spans two 8-bit registers, lower then upper byte. in da7219_tonegen_freq_put()
461 val = cpu_to_le16(ucontrol->value.integer.value[0]); in da7219_tonegen_freq_put()
463 mutex_lock(&da7219->ctrl_lock); in da7219_tonegen_freq_put()
464 ret = regmap_raw_write(da7219->regmap, reg, &val, sizeof(val)); in da7219_tonegen_freq_put()
465 mutex_unlock(&da7219->ctrl_lock); in da7219_tonegen_freq_put()
493 SOC_SINGLE("Mixin Gain Ramp Switch", DA7219_MIXIN_L_CTRL,
496 SOC_SINGLE("Mixin ZC Gain Switch", DA7219_MIXIN_L_CTRL,
508 SOC_SINGLE("Capture Digital Gain Ramp Switch", DA7219_ADC_L_CTRL,
549 /* Input High-Pass Filters */
589 /* Gain ramping */
590 SOC_ENUM("Gain Ramp Rate", da7219_gain_ramp_rate),
592 /* DAC High-Pass Filter */
598 /* DAC 5-Band Equaliser */
651 SOC_DOUBLE_R("Playback Digital Gain Ramp Switch", DA7219_DAC_L_CTRL,
671 SOC_DOUBLE_R("Headphone Gain Ramp Switch", DA7219_HP_L_CTRL,
674 SOC_DOUBLE_R("Headphone ZC Gain Switch", DA7219_HP_L_CTRL,
774 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in da7219_mic_pga_event()
779 if (da7219->micbias_on_event) { in da7219_mic_pga_event()
784 da7219->micbias_on_event = false; in da7219_mic_pga_event()
785 msleep(da7219->mic_pga_delay); in da7219_mic_pga_event()
798 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in da7219_dai_event()
806 if (da7219->master) { in da7219_dai_event()
808 if (da7219->dai_clks) { in da7219_dai_event()
809 ret = clk_prepare_enable(da7219->dai_clks); in da7219_dai_event()
811 dev_err(component->dev, in da7219_dai_event()
844 dev_warn(component->dev, "SRM failed to lock\n"); in da7219_dai_event()
848 /* PC free-running */ in da7219_dai_event()
854 if (da7219->master) { in da7219_dai_event()
855 if (da7219->dai_clks) in da7219_dai_event()
856 clk_disable_unprepare(da7219->dai_clks); in da7219_dai_event()
866 return -EINVAL; in da7219_dai_event()
888 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in da7219_mixout_event()
891 switch (w->reg) { in da7219_mixout_event()
901 return -EINVAL; in da7219_mixout_event()
906 /* Enable minimum gain on HP to avoid pops */ in da7219_mixout_event()
914 /* Remove minimum gain on HP */ in da7219_mixout_event()
926 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in da7219_gain_ramp_event()
932 /* Ensure nominal gain ramping for DAPM sequence */ in da7219_gain_ramp_event()
933 da7219->gain_ramp_ctrl = in da7219_gain_ramp_event()
940 /* Restore previous gain ramp settings */ in da7219_gain_ramp_event()
942 da7219->gain_ramp_ctrl); in da7219_gain_ramp_event()
964 SND_SOC_DAPM_PGA_E("Mic PGA", DA7219_MIC_1_CTRL,
967 SND_SOC_DAPM_PGA_E("Mixin PGA", DA7219_MIXIN_L_CTRL,
1043 SND_SOC_DAPM_PGA_E("Mixout Left PGA", DA7219_MIXOUT_L_CTRL,
1047 SND_SOC_DAPM_PGA_E("Mixout Right PGA", DA7219_MIXOUT_R_CTRL,
1051 SND_SOC_DAPM_SUPPLY_S("Headphone Left PGA", 1, DA7219_HP_L_CTRL,
1055 SND_SOC_DAPM_SUPPLY_S("Headphone Right PGA", 1, DA7219_HP_R_CTRL,
1071 SND_SOC_DAPM_PRE("Pre Power Gain Ramp", da7219_gain_ramp_event),
1072 SND_SOC_DAPM_POST("Post Power Gain Ramp", da7219_gain_ramp_event),
1109 {"Mic PGA", NULL, "MIC"},
1110 {"Mixin PGA", NULL, "Mic PGA"},
1111 {"ADC", NULL, "Mixin PGA"},
1142 {"Mixout Left PGA", NULL, "DACL"},
1143 {"Mixout Right PGA", NULL, "DACR"},
1145 {"HPL", NULL, "Mixout Left PGA"},
1146 {"HPR", NULL, "Mixout Right PGA"},
1148 {"HPL", NULL, "Headphone Left PGA"},
1149 {"HPR", NULL, "Headphone Right PGA"},
1163 struct snd_soc_component *component = codec_dai->component; in da7219_set_dai_sysclk()
1167 if ((da7219->clk_src == clk_id) && (da7219->mclk_rate == freq)) in da7219_set_dai_sysclk()
1171 dev_err(codec_dai->dev, "Unsupported MCLK value %d\n", in da7219_set_dai_sysclk()
1173 return -EINVAL; in da7219_set_dai_sysclk()
1176 mutex_lock(&da7219->pll_lock); in da7219_set_dai_sysclk()
1189 dev_err(codec_dai->dev, "Unknown clock source %d\n", clk_id); in da7219_set_dai_sysclk()
1190 mutex_unlock(&da7219->pll_lock); in da7219_set_dai_sysclk()
1191 return -EINVAL; in da7219_set_dai_sysclk()
1194 da7219->clk_src = clk_id; in da7219_set_dai_sysclk()
1196 if (da7219->mclk) { in da7219_set_dai_sysclk()
1197 freq = clk_round_rate(da7219->mclk, freq); in da7219_set_dai_sysclk()
1198 ret = clk_set_rate(da7219->mclk, freq); in da7219_set_dai_sysclk()
1200 dev_err(codec_dai->dev, "Failed to set clock rate %d\n", in da7219_set_dai_sysclk()
1202 mutex_unlock(&da7219->pll_lock); in da7219_set_dai_sysclk()
1207 da7219->mclk_rate = freq; in da7219_set_dai_sysclk()
1209 mutex_unlock(&da7219->pll_lock); in da7219_set_dai_sysclk()
1223 /* Verify 2MHz - 54MHz MCLK provided, and set input divider */ in da7219_set_pll()
1224 if (da7219->mclk_rate < 2000000) { in da7219_set_pll()
1225 dev_err(component->dev, "PLL input clock %d below valid range\n", in da7219_set_pll()
1226 da7219->mclk_rate); in da7219_set_pll()
1227 return -EINVAL; in da7219_set_pll()
1228 } else if (da7219->mclk_rate <= 4500000) { in da7219_set_pll()
1231 } else if (da7219->mclk_rate <= 9000000) { in da7219_set_pll()
1234 } else if (da7219->mclk_rate <= 18000000) { in da7219_set_pll()
1237 } else if (da7219->mclk_rate <= 36000000) { in da7219_set_pll()
1240 } else if (da7219->mclk_rate <= 54000000) { in da7219_set_pll()
1244 dev_err(component->dev, "PLL input clock %d above valid range\n", in da7219_set_pll()
1245 da7219->mclk_rate); in da7219_set_pll()
1246 return -EINVAL; in da7219_set_pll()
1248 freq_ref = (da7219->mclk_rate / indiv); in da7219_set_pll()
1266 dev_err(component->dev, "Invalid PLL config\n"); in da7219_set_pll()
1267 return -EINVAL; in da7219_set_pll()
1291 struct snd_soc_component *component = codec_dai->component; in da7219_set_dai_pll()
1295 mutex_lock(&da7219->pll_lock); in da7219_set_dai_pll()
1297 mutex_unlock(&da7219->pll_lock); in da7219_set_dai_pll()
1304 struct snd_soc_component *component = codec_dai->component; in da7219_set_dai_fmt()
1310 da7219->master = true; in da7219_set_dai_fmt()
1313 da7219->master = false; in da7219_set_dai_fmt()
1316 return -EINVAL; in da7219_set_dai_fmt()
1337 return -EINVAL; in da7219_set_dai_fmt()
1355 return -EINVAL; in da7219_set_dai_fmt()
1359 return -EINVAL; in da7219_set_dai_fmt()
1376 return -EINVAL; in da7219_set_dai_fmt()
1396 struct snd_soc_component *component = dai->component; in da7219_set_dai_tdm_slot()
1402 /* No channels enabled so disable TDM, revert to 64-bit frames */ in da7219_set_dai_tdm_slot()
1415 dev_err(component->dev, "Invalid number of slots, max = %d\n", in da7219_set_dai_tdm_slot()
1417 return -EINVAL; in da7219_set_dai_tdm_slot()
1422 dev_err(component->dev, "Invalid slot offset, max = %d\n", in da7219_set_dai_tdm_slot()
1424 return -EINVAL; in da7219_set_dai_tdm_slot()
1443 dev_err(component->dev, "Invalid frame size %d\n", frame_size); in da7219_set_dai_tdm_slot()
1444 return -EINVAL; in da7219_set_dai_tdm_slot()
1452 regmap_bulk_write(da7219->regmap, DA7219_DAI_OFFSET_LOWER, in da7219_set_dai_tdm_slot()
1468 struct snd_soc_component *component = dai->component; in da7219_hw_params()
1486 return -EINVAL; in da7219_hw_params()
1491 dev_err(component->dev, in da7219_hw_params()
1494 return -EINVAL; in da7219_hw_params()
1533 return -EINVAL; in da7219_hw_params()
1557 .name = "da7219-hifi",
1634 struct device *dev = component->dev; in da7219_fw_to_pdata()
1643 pdata->wakeup_source = device_property_read_bool(dev, "wakeup-source"); in da7219_fw_to_pdata()
1645 pdata->dai_clks_name = "da7219-dai-clks"; in da7219_fw_to_pdata()
1646 if (device_property_read_string(dev, "clock-output-names", in da7219_fw_to_pdata()
1647 &pdata->dai_clks_name)) in da7219_fw_to_pdata()
1649 pdata->dai_clks_name); in da7219_fw_to_pdata()
1651 if (device_property_read_u32(dev, "dlg,micbias-lvl", &of_val32) >= 0) in da7219_fw_to_pdata()
1652 pdata->micbias_lvl = da7219_fw_micbias_lvl(dev, of_val32); in da7219_fw_to_pdata()
1654 pdata->micbias_lvl = DA7219_MICBIAS_2_2V; in da7219_fw_to_pdata()
1656 if (!device_property_read_string(dev, "dlg,mic-amp-in-sel", &of_str)) in da7219_fw_to_pdata()
1657 pdata->mic_amp_in_sel = da7219_fw_mic_amp_in_sel(dev, of_str); in da7219_fw_to_pdata()
1659 pdata->mic_amp_in_sel = DA7219_MIC_AMP_IN_SEL_DIFF; in da7219_fw_to_pdata()
1681 if (da7219->mclk) { in da7219_set_bias_level()
1682 ret = clk_prepare_enable(da7219->mclk); in da7219_set_bias_level()
1684 dev_err(component->dev, in da7219_set_bias_level()
1701 if (da7219->mclk) in da7219_set_bias_level()
1702 clk_disable_unprepare(da7219->mclk); in da7219_set_bias_level()
1706 /* Only disable master bias if we're not a wake-up source */ in da7219_set_bias_level()
1707 if (!da7219->wakeup_source) in da7219_set_bias_level()
1732 da7219->supplies[i].supply = da7219_supply_names[i]; in da7219_handle_supplies()
1734 ret = devm_regulator_bulk_get(component->dev, DA7219_NUM_SUPPLIES, in da7219_handle_supplies()
1735 da7219->supplies); in da7219_handle_supplies()
1737 dev_err(component->dev, "Failed to get supplies"); in da7219_handle_supplies()
1742 vddio = da7219->supplies[DA7219_SUPPLY_VDDIO].consumer; in da7219_handle_supplies()
1745 dev_warn(component->dev, "Invalid VDDIO voltage\n"); in da7219_handle_supplies()
1750 ret = regulator_bulk_enable(DA7219_NUM_SUPPLIES, da7219->supplies); in da7219_handle_supplies()
1752 dev_err(component->dev, "Failed to enable supplies"); in da7219_handle_supplies()
1770 struct snd_soc_component *component = da7219->aad->component; in da7219_dai_clks_prepare()
1783 struct snd_soc_component *component = da7219->aad->component; in da7219_dai_clks_unprepare()
1793 struct snd_soc_component *component = da7219->aad->component; in da7219_dai_clks_is_prepared()
1809 struct device *dev = component->dev; in da7219_register_dai_clks()
1811 struct da7219_pdata *pdata = da7219->pdata; in da7219_register_dai_clks()
1818 init.name = pdata->dai_clks_name; in da7219_register_dai_clks()
1820 da7219->dai_clks_hw.init = &init; in da7219_register_dai_clks()
1822 dai_clks = devm_clk_register(dev, &da7219->dai_clks_hw); in da7219_register_dai_clks()
1828 da7219->dai_clks = dai_clks; in da7219_register_dai_clks()
1831 if (dev->of_node) { in da7219_register_dai_clks()
1833 &da7219->dai_clks_hw); in da7219_register_dai_clks()
1835 dai_clks_lookup = clkdev_create(dai_clks, pdata->dai_clks_name, in da7219_register_dai_clks()
1840 da7219->dai_clks_lookup = dai_clks_lookup; in da7219_register_dai_clks()
1850 struct da7219_pdata *pdata = da7219->pdata; in da7219_handle_pdata()
1855 da7219->wakeup_source = pdata->wakeup_source; in da7219_handle_pdata()
1860 switch (pdata->micbias_lvl) { in da7219_handle_pdata()
1867 micbias_lvl |= (pdata->micbias_lvl << in da7219_handle_pdata()
1876 * Mic PGA, based on Mic Bias voltage. in da7219_handle_pdata()
1878 da7219->mic_pga_delay = DA7219_MIC_PGA_BASE_DELAY + in da7219_handle_pdata()
1879 (pdata->micbias_lvl * in da7219_handle_pdata()
1883 switch (pdata->mic_amp_in_sel) { in da7219_handle_pdata()
1888 pdata->mic_amp_in_sel); in da7219_handle_pdata()
1904 mutex_init(&da7219->ctrl_lock); in da7219_probe()
1905 mutex_init(&da7219->pll_lock); in da7219_probe()
1912 ret = regmap_read(da7219->regmap, DA7219_CHIP_REVISION, &rev); in da7219_probe()
1914 dev_err(component->dev, "Failed to read chip revision: %d\n", ret); in da7219_probe()
1920 ret = regmap_register_patch(da7219->regmap, da7219_rev_aa_patch, in da7219_probe()
1923 dev_err(component->dev, "Failed to register AA patch: %d\n", in da7219_probe()
1933 da7219->pdata = dev_get_platdata(component->dev); in da7219_probe()
1934 if (!da7219->pdata) in da7219_probe()
1935 da7219->pdata = da7219_fw_to_pdata(component); in da7219_probe()
1940 da7219->mclk = devm_clk_get(component->dev, "mclk"); in da7219_probe()
1941 if (IS_ERR(da7219->mclk)) { in da7219_probe()
1942 if (PTR_ERR(da7219->mclk) != -ENOENT) { in da7219_probe()
1943 ret = PTR_ERR(da7219->mclk); in da7219_probe()
1946 da7219->mclk = NULL; in da7219_probe()
1950 /* Default PC counter to free-running */ in da7219_probe()
1954 /* Default gain ramping */ in da7219_probe()
1971 /* Default minimum gain on HP to avoid pops during DAPM sequencing */ in da7219_probe()
1990 regulator_bulk_disable(DA7219_NUM_SUPPLIES, da7219->supplies); in da7219_probe()
2002 if (da7219->dai_clks_lookup) in da7219_remove()
2003 clkdev_drop(da7219->dai_clks_lookup); in da7219_remove()
2007 regulator_bulk_disable(DA7219_NUM_SUPPLIES, da7219->supplies); in da7219_remove()
2015 /* Suspend AAD if we're not a wake-up source */ in da7219_suspend()
2016 if (!da7219->wakeup_source) in da7219_suspend()
2031 if (!da7219->wakeup_source) in da7219_resume()
2207 da7219 = devm_kzalloc(&i2c->dev, sizeof(struct da7219_priv), in da7219_i2c_probe()
2210 return -ENOMEM; in da7219_i2c_probe()
2214 da7219->regmap = devm_regmap_init_i2c(i2c, &da7219_regmap_config); in da7219_i2c_probe()
2215 if (IS_ERR(da7219->regmap)) { in da7219_i2c_probe()
2216 ret = PTR_ERR(da7219->regmap); in da7219_i2c_probe()
2217 dev_err(&i2c->dev, "regmap_init() failed: %d\n", ret); in da7219_i2c_probe()
2221 regcache_cache_bypass(da7219->regmap, true); in da7219_i2c_probe()
2224 regmap_read(da7219->regmap, DA7219_SYSTEM_ACTIVE, &system_active); in da7219_i2c_probe()
2226 regmap_write(da7219->regmap, DA7219_GAIN_RAMP_CTRL, in da7219_i2c_probe()
2228 regmap_write(da7219->regmap, DA7219_SYSTEM_MODES_INPUT, 0x00); in da7219_i2c_probe()
2229 regmap_write(da7219->regmap, DA7219_SYSTEM_MODES_OUTPUT, 0x01); in da7219_i2c_probe()
2232 regmap_read(da7219->regmap, DA7219_SYSTEM_STATUS, in da7219_i2c_probe()
2242 regmap_write_bits(da7219->regmap, DA7219_ACCDET_CONFIG_1, in da7219_i2c_probe()
2244 regmap_write_bits(da7219->regmap, DA7219_CIF_CTRL, in da7219_i2c_probe()
2247 regmap_write_bits(da7219->regmap, DA7219_SYSTEM_ACTIVE, in da7219_i2c_probe()
2250 regcache_cache_bypass(da7219->regmap, false); in da7219_i2c_probe()
2252 ret = devm_snd_soc_register_component(&i2c->dev, in da7219_i2c_probe()
2256 dev_err(&i2c->dev, "Failed to register da7219 component: %d\n", in da7219_i2c_probe()