Lines Matching +full:tdm +full:- +full:data +full:- +full:align
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * da7219.c - DA7219 ALSA SoC Codec Driver
13 #include <linux/clk-provider.h>
26 #include <sound/soc-dapm.h>
33 #include "da7219-aad.h"
41 static const DECLARE_TLV_DB_SCALE(da7219_mic_gain_tlv, -600, 600, 0);
42 static const DECLARE_TLV_DB_SCALE(da7219_mixin_gain_tlv, -450, 150, 0);
43 static const DECLARE_TLV_DB_SCALE(da7219_adc_dig_gain_tlv, -8325, 75, 0);
44 static const DECLARE_TLV_DB_SCALE(da7219_alc_threshold_tlv, -9450, 150, 0);
47 static const DECLARE_TLV_DB_SCALE(da7219_sidetone_gain_tlv, -4200, 300, 0);
48 static const DECLARE_TLV_DB_SCALE(da7219_tonegen_gain_tlv, -4500, 300, 0);
51 static const DECLARE_TLV_DB_SCALE(da7219_dac_eq_band_tlv, -1050, 150, 0);
55 /* -77.25dB to 12dB */
56 0x08, 0x7f, TLV_DB_SCALE_ITEM(-7725, 75, 0)
59 static const DECLARE_TLV_DB_SCALE(da7219_dac_ng_threshold_tlv, -10200, 600, 0);
60 static const DECLARE_TLV_DB_SCALE(da7219_hp_gain_tlv, -5700, 100, 0);
184 "Sum", "SWG1", "SWG2", "SWG1_1-Cos"
261 mutex_lock(&da7219->ctrl_lock); in da7219_volsw_locked_get()
263 mutex_unlock(&da7219->ctrl_lock); in da7219_volsw_locked_get()
275 mutex_lock(&da7219->ctrl_lock); in da7219_volsw_locked_put()
277 mutex_unlock(&da7219->ctrl_lock); in da7219_volsw_locked_put()
289 mutex_lock(&da7219->ctrl_lock); in da7219_enum_locked_get()
291 mutex_unlock(&da7219->ctrl_lock); in da7219_enum_locked_get()
303 mutex_lock(&da7219->ctrl_lock); in da7219_enum_locked_put()
305 mutex_unlock(&da7219->ctrl_lock); in da7219_enum_locked_put()
352 dev_warn(component->dev, in da7219_alc_calib()
389 if ((ret == 1) && (da7219->alc_en)) in da7219_mixin_gain_put()
403 if ((ucontrol->value.integer.value[0]) && (!da7219->alc_en)) { in da7219_alc_sw_put()
405 da7219->alc_en = true; in da7219_alc_sw_put()
407 da7219->alc_en = false; in da7219_alc_sw_put()
420 (struct soc_mixer_control *) kcontrol->private_value; in da7219_tonegen_freq_get()
421 unsigned int reg = mixer_ctrl->reg; in da7219_tonegen_freq_get()
425 mutex_lock(&da7219->ctrl_lock); in da7219_tonegen_freq_get()
426 ret = regmap_raw_read(da7219->regmap, reg, &val, sizeof(val)); in da7219_tonegen_freq_get()
427 mutex_unlock(&da7219->ctrl_lock); in da7219_tonegen_freq_get()
433 * Frequency value spans two 8-bit registers, lower then upper byte. in da7219_tonegen_freq_get()
436 ucontrol->value.integer.value[0] = le16_to_cpu(val); in da7219_tonegen_freq_get()
447 (struct soc_mixer_control *) kcontrol->private_value; in da7219_tonegen_freq_put()
448 unsigned int reg = mixer_ctrl->reg; in da7219_tonegen_freq_put()
453 * Frequency value spans two 8-bit registers, lower then upper byte. in da7219_tonegen_freq_put()
454 * Therefore we need to convert to little endian here to align with in da7219_tonegen_freq_put()
457 val_new = cpu_to_le16(ucontrol->value.integer.value[0]); in da7219_tonegen_freq_put()
459 mutex_lock(&da7219->ctrl_lock); in da7219_tonegen_freq_put()
460 ret = regmap_raw_read(da7219->regmap, reg, &val_old, sizeof(val_old)); in da7219_tonegen_freq_put()
462 ret = regmap_raw_write(da7219->regmap, reg, in da7219_tonegen_freq_put()
464 mutex_unlock(&da7219->ctrl_lock); in da7219_tonegen_freq_put()
551 /* Input High-Pass Filters */
594 /* DAC High-Pass Filter */
600 /* DAC 5-Band Equaliser */
776 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in da7219_mic_pga_event()
781 if (da7219->micbias_on_event) { in da7219_mic_pga_event()
786 da7219->micbias_on_event = false; in da7219_mic_pga_event()
787 msleep(da7219->mic_pga_delay); in da7219_mic_pga_event()
800 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in da7219_dai_event()
802 struct clk *bclk = da7219->dai_clks[DA7219_DAI_BCLK_IDX]; in da7219_dai_event()
809 if (da7219->master) { in da7219_dai_event()
814 dev_err(component->dev, in da7219_dai_event()
847 dev_warn(component->dev, "SRM failed to lock\n"); in da7219_dai_event()
851 /* PC free-running */ in da7219_dai_event()
857 if (da7219->master) { in da7219_dai_event()
869 return -EINVAL; in da7219_dai_event()
891 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in da7219_mixout_event()
894 switch (w->reg) { in da7219_mixout_event()
904 return -EINVAL; in da7219_mixout_event()
929 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in da7219_gain_ramp_event()
936 da7219->gain_ramp_ctrl = in da7219_gain_ramp_event()
945 da7219->gain_ramp_ctrl); in da7219_gain_ramp_event()
1166 struct snd_soc_component *component = codec_dai->component; in da7219_set_dai_sysclk()
1170 mutex_lock(&da7219->pll_lock); in da7219_set_dai_sysclk()
1172 if ((da7219->clk_src == clk_id) && (da7219->mclk_rate == freq)) { in da7219_set_dai_sysclk()
1173 mutex_unlock(&da7219->pll_lock); in da7219_set_dai_sysclk()
1178 mutex_unlock(&da7219->pll_lock); in da7219_set_dai_sysclk()
1179 dev_err(codec_dai->dev, "Unsupported MCLK value %d\n", in da7219_set_dai_sysclk()
1181 return -EINVAL; in da7219_set_dai_sysclk()
1195 dev_err(codec_dai->dev, "Unknown clock source %d\n", clk_id); in da7219_set_dai_sysclk()
1196 mutex_unlock(&da7219->pll_lock); in da7219_set_dai_sysclk()
1197 return -EINVAL; in da7219_set_dai_sysclk()
1200 da7219->clk_src = clk_id; in da7219_set_dai_sysclk()
1202 if (da7219->mclk) { in da7219_set_dai_sysclk()
1203 freq = clk_round_rate(da7219->mclk, freq); in da7219_set_dai_sysclk()
1204 ret = clk_set_rate(da7219->mclk, freq); in da7219_set_dai_sysclk()
1206 dev_err(codec_dai->dev, "Failed to set clock rate %d\n", in da7219_set_dai_sysclk()
1208 mutex_unlock(&da7219->pll_lock); in da7219_set_dai_sysclk()
1213 da7219->mclk_rate = freq; in da7219_set_dai_sysclk()
1215 mutex_unlock(&da7219->pll_lock); in da7219_set_dai_sysclk()
1229 /* Verify 2MHz - 54MHz MCLK provided, and set input divider */ in da7219_set_pll()
1230 if (da7219->mclk_rate < 2000000) { in da7219_set_pll()
1231 dev_err(component->dev, "PLL input clock %d below valid range\n", in da7219_set_pll()
1232 da7219->mclk_rate); in da7219_set_pll()
1233 return -EINVAL; in da7219_set_pll()
1234 } else if (da7219->mclk_rate <= 4500000) { in da7219_set_pll()
1237 } else if (da7219->mclk_rate <= 9000000) { in da7219_set_pll()
1240 } else if (da7219->mclk_rate <= 18000000) { in da7219_set_pll()
1243 } else if (da7219->mclk_rate <= 36000000) { in da7219_set_pll()
1246 } else if (da7219->mclk_rate <= 54000000) { in da7219_set_pll()
1250 dev_err(component->dev, "PLL input clock %d above valid range\n", in da7219_set_pll()
1251 da7219->mclk_rate); in da7219_set_pll()
1252 return -EINVAL; in da7219_set_pll()
1254 freq_ref = (da7219->mclk_rate / indiv); in da7219_set_pll()
1272 dev_err(component->dev, "Invalid PLL config\n"); in da7219_set_pll()
1273 return -EINVAL; in da7219_set_pll()
1297 struct snd_soc_component *component = codec_dai->component; in da7219_set_dai_pll()
1301 mutex_lock(&da7219->pll_lock); in da7219_set_dai_pll()
1303 mutex_unlock(&da7219->pll_lock); in da7219_set_dai_pll()
1310 struct snd_soc_component *component = codec_dai->component; in da7219_set_dai_fmt()
1316 da7219->master = true; in da7219_set_dai_fmt()
1319 da7219->master = false; in da7219_set_dai_fmt()
1322 return -EINVAL; in da7219_set_dai_fmt()
1343 return -EINVAL; in da7219_set_dai_fmt()
1361 return -EINVAL; in da7219_set_dai_fmt()
1365 return -EINVAL; in da7219_set_dai_fmt()
1382 return -EINVAL; in da7219_set_dai_fmt()
1413 return -EINVAL; in da7219_set_bclks_per_wclk()
1427 struct snd_soc_component *component = dai->component; in da7219_set_dai_tdm_slot()
1429 struct clk *wclk = da7219->dai_clks[DA7219_DAI_WCLK_IDX]; in da7219_set_dai_tdm_slot()
1430 struct clk *bclk = da7219->dai_clks[DA7219_DAI_BCLK_IDX]; in da7219_set_dai_tdm_slot()
1439 /* No channels enabled so disable TDM */ in da7219_set_dai_tdm_slot()
1444 da7219->tdm_en = false; in da7219_set_dai_tdm_slot()
1449 slot_offset = ffs(tx_mask) - 1; in da7219_set_dai_tdm_slot()
1452 dev_err(component->dev, in da7219_set_dai_tdm_slot()
1455 return -EINVAL; in da7219_set_dai_tdm_slot()
1464 dev_err(component->dev, "Invalid frame offset %d\n", offset); in da7219_set_dai_tdm_slot()
1465 return -EINVAL; in da7219_set_dai_tdm_slot()
1472 if (da7219->master) { in da7219_set_dai_tdm_slot()
1480 dev_err(component->dev, in da7219_set_dai_tdm_slot()
1481 "Failed to set TDM BCLK rate %lu: %d\n", in da7219_set_dai_tdm_slot()
1488 dev_err(component->dev, in da7219_set_dai_tdm_slot()
1489 "Failed to set TDM BCLKs per WCLK %d: %d\n", in da7219_set_dai_tdm_slot()
1497 regmap_bulk_write(da7219->regmap, DA7219_DAI_OFFSET_LOWER, in da7219_set_dai_tdm_slot()
1506 da7219->tdm_en = true; in da7219_set_dai_tdm_slot()
1551 return -EINVAL; in da7219_set_sr()
1563 struct snd_soc_component *component = dai->component; in da7219_hw_params()
1565 struct clk *wclk = da7219->dai_clks[DA7219_DAI_WCLK_IDX]; in da7219_hw_params()
1566 struct clk *bclk = da7219->dai_clks[DA7219_DAI_BCLK_IDX]; in da7219_hw_params()
1587 return -EINVAL; in da7219_hw_params()
1592 dev_err(component->dev, in da7219_hw_params()
1595 return -EINVAL; in da7219_hw_params()
1600 if (da7219->master && wclk) { in da7219_hw_params()
1603 dev_err(component->dev, in da7219_hw_params()
1610 dev_err(component->dev, in da7219_hw_params()
1621 if (da7219->master && !da7219->tdm_en) { in da7219_hw_params()
1639 dev_err(component->dev, in da7219_hw_params()
1641 return -EINVAL; in da7219_hw_params()
1646 dev_err(component->dev, in da7219_hw_params()
1654 dev_err(component->dev, in da7219_hw_params()
1688 .name = "da7219-hifi",
1777 pdata->wakeup_source = device_property_read_bool(dev, "wakeup-source"); in da7219_fw_to_pdata()
1779 pdata->dai_clk_names[DA7219_DAI_WCLK_IDX] = "da7219-dai-wclk"; in da7219_fw_to_pdata()
1780 pdata->dai_clk_names[DA7219_DAI_BCLK_IDX] = "da7219-dai-bclk"; in da7219_fw_to_pdata()
1781 if (device_property_read_string_array(dev, "clock-output-names", in da7219_fw_to_pdata()
1782 pdata->dai_clk_names, in da7219_fw_to_pdata()
1785 pdata->dai_clk_names[DA7219_DAI_WCLK_IDX], in da7219_fw_to_pdata()
1786 pdata->dai_clk_names[DA7219_DAI_BCLK_IDX]); in da7219_fw_to_pdata()
1788 if (device_property_read_u32(dev, "dlg,micbias-lvl", &of_val32) >= 0) in da7219_fw_to_pdata()
1789 pdata->micbias_lvl = da7219_fw_micbias_lvl(dev, of_val32); in da7219_fw_to_pdata()
1791 pdata->micbias_lvl = DA7219_MICBIAS_2_2V; in da7219_fw_to_pdata()
1793 if (!device_property_read_string(dev, "dlg,mic-amp-in-sel", &of_str)) in da7219_fw_to_pdata()
1794 pdata->mic_amp_in_sel = da7219_fw_mic_amp_in_sel(dev, of_str); in da7219_fw_to_pdata()
1796 pdata->mic_amp_in_sel = DA7219_MIC_AMP_IN_SEL_DIFF; in da7219_fw_to_pdata()
1818 if (da7219->mclk) { in da7219_set_bias_level()
1819 ret = clk_prepare_enable(da7219->mclk); in da7219_set_bias_level()
1821 dev_err(component->dev, in da7219_set_bias_level()
1838 if (da7219->mclk) in da7219_set_bias_level()
1839 clk_disable_unprepare(da7219->mclk); in da7219_set_bias_level()
1843 /* Only disable master bias if we're not a wake-up source */ in da7219_set_bias_level()
1844 if (!da7219->wakeup_source) in da7219_set_bias_level()
1869 da7219->supplies[i].supply = da7219_supply_names[i]; in da7219_handle_supplies()
1871 ret = regulator_bulk_get(component->dev, DA7219_NUM_SUPPLIES, in da7219_handle_supplies()
1872 da7219->supplies); in da7219_handle_supplies()
1874 dev_err(component->dev, "Failed to get supplies"); in da7219_handle_supplies()
1882 vddio = da7219->supplies[DA7219_SUPPLY_VDDIO].consumer; in da7219_handle_supplies()
1885 dev_warn(component->dev, "Invalid VDDIO voltage\n"); in da7219_handle_supplies()
1890 ret = regulator_bulk_enable(DA7219_NUM_SUPPLIES, da7219->supplies); in da7219_handle_supplies()
1892 dev_err(component->dev, "Failed to enable supplies"); in da7219_handle_supplies()
1893 regulator_bulk_free(DA7219_NUM_SUPPLIES, da7219->supplies); in da7219_handle_supplies()
1906 struct snd_soc_component *component = da7219->component; in da7219_wclk_prepare()
1908 if (!da7219->master) in da7219_wclk_prepare()
1909 return -EINVAL; in da7219_wclk_prepare()
1923 struct snd_soc_component *component = da7219->component; in da7219_wclk_unprepare()
1925 if (!da7219->master) in da7219_wclk_unprepare()
1937 struct snd_soc_component *component = da7219->component; in da7219_wclk_is_prepared()
1940 if (!da7219->master) in da7219_wclk_is_prepared()
1941 return -EINVAL; in da7219_wclk_is_prepared()
1954 struct snd_soc_component *component = da7219->component; in da7219_wclk_recalc_rate()
1992 if (!da7219->master) in da7219_wclk_round_rate()
1993 return -EINVAL; in da7219_wclk_round_rate()
2025 struct snd_soc_component *component = da7219->component; in da7219_wclk_set_rate()
2027 if (!da7219->master) in da7219_wclk_set_rate()
2028 return -EINVAL; in da7219_wclk_set_rate()
2039 struct snd_soc_component *component = da7219->component; in da7219_bclk_recalc_rate()
2081 if (!*parent_rate || !da7219->master) in da7219_bclk_round_rate()
2082 return -EINVAL; in da7219_bclk_round_rate()
2102 struct snd_soc_component *component = da7219->component; in da7219_bclk_set_rate()
2105 if (!da7219->master) in da7219_bclk_set_rate()
2106 return -EINVAL; in da7219_bclk_set_rate()
2131 struct device *dev = component->dev; in da7219_register_dai_clks()
2132 struct device_node *np = dev->of_node; in da7219_register_dai_clks()
2134 struct da7219_pdata *pdata = da7219->pdata; in da7219_register_dai_clks()
2139 /* For DT platforms allocate onecell data for clock registration */ in da7219_register_dai_clks()
2144 return -ENOMEM; in da7219_register_dai_clks()
2146 clk_data->num = DA7219_DAI_NUM_CLKS; in da7219_register_dai_clks()
2147 da7219->clk_hw_data = clk_data; in da7219_register_dai_clks()
2153 struct clk_hw *dai_clk_hw = &da7219->dai_clks_hw[i]; in da7219_register_dai_clks()
2161 if (da7219->mclk) { in da7219_register_dai_clks()
2162 parent_name = __clk_get_name(da7219->mclk); in da7219_register_dai_clks()
2172 parent_name = __clk_get_name(da7219->dai_clks[DA7219_DAI_WCLK_IDX]); in da7219_register_dai_clks()
2178 ret = -EINVAL; in da7219_register_dai_clks()
2182 init.name = pdata->dai_clk_names[i]; in da7219_register_dai_clks()
2185 dai_clk_hw->init = &init; in da7219_register_dai_clks()
2193 da7219->dai_clks[i] = dai_clk_hw->clk; in da7219_register_dai_clks()
2195 /* For DT setup onecell data, otherwise create lookup */ in da7219_register_dai_clks()
2197 da7219->clk_hw_data->hws[i] = dai_clk_hw; in da7219_register_dai_clks()
2203 ret = -ENOMEM; in da7219_register_dai_clks()
2206 da7219->dai_clks_lookup[i] = dai_clk_lookup; in da7219_register_dai_clks()
2213 ret = of_clk_add_hw_provider(dev->of_node, of_clk_hw_onecell_get, in da7219_register_dai_clks()
2214 da7219->clk_hw_data); in da7219_register_dai_clks()
2224 while (--i >= 0) { in da7219_register_dai_clks()
2225 if (da7219->dai_clks_lookup[i]) in da7219_register_dai_clks()
2226 clkdev_drop(da7219->dai_clks_lookup[i]); in da7219_register_dai_clks()
2228 clk_hw_unregister(&da7219->dai_clks_hw[i]); in da7219_register_dai_clks()
2232 kfree(da7219->clk_hw_data); in da7219_register_dai_clks()
2240 struct device_node *np = component->dev->of_node; in da7219_free_dai_clks()
2246 for (i = DA7219_DAI_NUM_CLKS - 1; i >= 0; --i) { in da7219_free_dai_clks()
2247 if (da7219->dai_clks_lookup[i]) in da7219_free_dai_clks()
2248 clkdev_drop(da7219->dai_clks_lookup[i]); in da7219_free_dai_clks()
2250 clk_hw_unregister(&da7219->dai_clks_hw[i]); in da7219_free_dai_clks()
2254 kfree(da7219->clk_hw_data); in da7219_free_dai_clks()
2268 struct da7219_pdata *pdata = da7219->pdata; in da7219_handle_pdata()
2273 da7219->wakeup_source = pdata->wakeup_source; in da7219_handle_pdata()
2276 switch (pdata->micbias_lvl) { in da7219_handle_pdata()
2283 micbias_lvl |= (pdata->micbias_lvl << in da7219_handle_pdata()
2294 da7219->mic_pga_delay = DA7219_MIC_PGA_BASE_DELAY + in da7219_handle_pdata()
2295 (pdata->micbias_lvl * in da7219_handle_pdata()
2299 switch (pdata->mic_amp_in_sel) { in da7219_handle_pdata()
2304 pdata->mic_amp_in_sel); in da7219_handle_pdata()
2457 da7219->component = component; in da7219_probe()
2458 mutex_init(&da7219->ctrl_lock); in da7219_probe()
2459 mutex_init(&da7219->pll_lock); in da7219_probe()
2466 regcache_cache_bypass(da7219->regmap, true); in da7219_probe()
2469 regmap_read(da7219->regmap, DA7219_SYSTEM_ACTIVE, &system_active); in da7219_probe()
2471 regmap_write(da7219->regmap, DA7219_GAIN_RAMP_CTRL, in da7219_probe()
2473 regmap_write(da7219->regmap, DA7219_SYSTEM_MODES_INPUT, 0x00); in da7219_probe()
2474 regmap_write(da7219->regmap, DA7219_SYSTEM_MODES_OUTPUT, 0x01); in da7219_probe()
2477 regmap_read(da7219->regmap, DA7219_SYSTEM_STATUS, in da7219_probe()
2487 regmap_write_bits(da7219->regmap, DA7219_ACCDET_CONFIG_1, in da7219_probe()
2489 regmap_write_bits(da7219->regmap, DA7219_CIF_CTRL, in da7219_probe()
2492 regmap_write_bits(da7219->regmap, DA7219_SYSTEM_ACTIVE, in da7219_probe()
2494 regmap_write_bits(da7219->regmap, DA7219_SYSTEM_ACTIVE, in da7219_probe()
2497 regcache_cache_bypass(da7219->regmap, false); in da7219_probe()
2498 regmap_reinit_cache(da7219->regmap, &da7219_regmap_config); in da7219_probe()
2503 ret = regmap_read(da7219->regmap, DA7219_CHIP_REVISION, &rev); in da7219_probe()
2505 dev_err(component->dev, "Failed to read chip revision: %d\n", ret); in da7219_probe()
2511 ret = regmap_register_patch(da7219->regmap, da7219_rev_aa_patch, in da7219_probe()
2514 dev_err(component->dev, "Failed to register AA patch: %d\n", in da7219_probe()
2523 /* Handle DT/ACPI/Platform data */ in da7219_probe()
2527 da7219->mclk = clk_get(component->dev, "mclk"); in da7219_probe()
2528 if (IS_ERR(da7219->mclk)) { in da7219_probe()
2529 if (PTR_ERR(da7219->mclk) != -ENOENT) { in da7219_probe()
2530 ret = PTR_ERR(da7219->mclk); in da7219_probe()
2533 da7219->mclk = NULL; in da7219_probe()
2542 /* Default PC counter to free-running */ in da7219_probe()
2585 clk_put(da7219->mclk); in da7219_probe()
2588 regulator_bulk_disable(DA7219_NUM_SUPPLIES, da7219->supplies); in da7219_probe()
2589 regulator_bulk_free(DA7219_NUM_SUPPLIES, da7219->supplies); in da7219_probe()
2601 clk_put(da7219->mclk); in da7219_remove()
2604 regulator_bulk_disable(DA7219_NUM_SUPPLIES, da7219->supplies); in da7219_remove()
2605 regulator_bulk_free(DA7219_NUM_SUPPLIES, da7219->supplies); in da7219_remove()
2613 /* Suspend AAD if we're not a wake-up source */ in da7219_suspend()
2614 if (!da7219->wakeup_source) in da7219_suspend()
2629 if (!da7219->wakeup_source) in da7219_resume()
2640 void *data) in da7219_set_jack() argument
2672 struct device *dev = &i2c->dev; in da7219_i2c_probe()
2679 return -ENOMEM; in da7219_i2c_probe()
2683 da7219->regmap = devm_regmap_init_i2c(i2c, &da7219_regmap_config); in da7219_i2c_probe()
2684 if (IS_ERR(da7219->regmap)) { in da7219_i2c_probe()
2685 ret = PTR_ERR(da7219->regmap); in da7219_i2c_probe()
2690 /* Retrieve DT/ACPI/Platform data */ in da7219_i2c_probe()
2691 da7219->pdata = dev_get_platdata(dev); in da7219_i2c_probe()
2692 if (!da7219->pdata) in da7219_i2c_probe()
2693 da7219->pdata = da7219_fw_to_pdata(dev); in da7219_i2c_probe()