Lines Matching +full:dsp +full:- +full:aif1

1 // SPDX-License-Identifier: GPL-2.0-only
3 * rt5514.c -- RT5514 ALSA SoC audio codec driver
24 #include <sound/soc-dapm.h>
31 #include "rt5514-spi.h"
120 regmap_write(rt5514->i2c_regmap, 0x18002000, 0x000010ec); in rt5514_enable_dsp_prepare()
122 regmap_write(rt5514->i2c_regmap, 0x18002200, 0x00028604); in rt5514_enable_dsp_prepare()
124 regmap_write(rt5514->i2c_regmap, 0xfafafafa, 0x00000001); in rt5514_enable_dsp_prepare()
125 /* mini-core reset */ in rt5514_enable_dsp_prepare()
126 regmap_write(rt5514->i2c_regmap, 0x18002f00, 0x0005514b); in rt5514_enable_dsp_prepare()
127 regmap_write(rt5514->i2c_regmap, 0x18002f00, 0x00055149); in rt5514_enable_dsp_prepare()
129 regmap_write(rt5514->i2c_regmap, 0xfafafafa, 0x00000000); in rt5514_enable_dsp_prepare()
131 regmap_write(rt5514->i2c_regmap, 0x18002070, 0x00000040); in rt5514_enable_dsp_prepare()
133 regmap_write(rt5514->i2c_regmap, 0x18002240, 0x0000000a); in rt5514_enable_dsp_prepare()
135 regmap_write(rt5514->i2c_regmap, 0x18002100, 0x0000000b); in rt5514_enable_dsp_prepare()
137 regmap_write(rt5514->i2c_regmap, 0x18002004, 0x00808b81); in rt5514_enable_dsp_prepare()
138 /* DSP clk source = pll3, ENABLE DSP clk */ in rt5514_enable_dsp_prepare()
139 regmap_write(rt5514->i2c_regmap, 0x18002f08, 0x00000005); in rt5514_enable_dsp_prepare()
140 /* Enable DSP clk auto switch */ in rt5514_enable_dsp_prepare()
141 regmap_write(rt5514->i2c_regmap, 0x18001114, 0x00000001); in rt5514_enable_dsp_prepare()
142 /* Reduce DSP power */ in rt5514_enable_dsp_prepare()
143 regmap_write(rt5514->i2c_regmap, 0x18001118, 0x00000001); in rt5514_enable_dsp_prepare()
273 /* {-3, 0, +3, +4.5, +7.5, +9.5, +12, +14, +17} dB */
275 0, 2, TLV_DB_SCALE_ITEM(-300, 300, 0),
284 static const DECLARE_TLV_DB_SCALE(adc_vol_tlv, -1725, 75, 0);
292 ucontrol->value.integer.value[0] = rt5514->dsp_enabled; in rt5514_dsp_voice_wake_up_get()
300 regmap_write(rt5514->regmap, RT5514_ANA_CTRL_PLL3, 0x0000000a); in rt5514_calibration()
301 regmap_update_bits(rt5514->regmap, RT5514_PLL_SOURCE_CTRL, 0xf, in rt5514_calibration()
303 regmap_update_bits(rt5514->regmap, RT5514_PWR_ANA1, 0x301, in rt5514_calibration()
305 regmap_write(rt5514->regmap, RT5514_PLL3_CALIB_CTRL4, in rt5514_calibration()
306 0x80000000 | rt5514->pll3_cal_value); in rt5514_calibration()
307 regmap_write(rt5514->regmap, RT5514_PLL3_CALIB_CTRL1, in rt5514_calibration()
309 regmap_update_bits(rt5514->regmap, RT5514_PLL3_CALIB_CTRL5, in rt5514_calibration()
311 regmap_update_bits(rt5514->regmap, RT5514_PLL3_CALIB_CTRL5, in rt5514_calibration()
314 regmap_update_bits(rt5514->regmap, RT5514_PLL3_CALIB_CTRL5, in rt5514_calibration()
316 regmap_update_bits(rt5514->regmap, RT5514_PWR_ANA1, 0x301, 0); in rt5514_calibration()
317 regmap_update_bits(rt5514->regmap, RT5514_PLL_SOURCE_CTRL, 0xf, in rt5514_calibration()
332 if (ucontrol->value.integer.value[0] == rt5514->dsp_enabled) in rt5514_dsp_voice_wake_up_put()
336 rt5514->dsp_enabled = ucontrol->value.integer.value[0]; in rt5514_dsp_voice_wake_up_put()
338 if (rt5514->dsp_enabled) { in rt5514_dsp_voice_wake_up_put()
339 if (rt5514->pdata.dsp_calib_clk_name && in rt5514_dsp_voice_wake_up_put()
340 !IS_ERR(rt5514->dsp_calib_clk)) { in rt5514_dsp_voice_wake_up_put()
341 if (clk_set_rate(rt5514->dsp_calib_clk, in rt5514_dsp_voice_wake_up_put()
342 rt5514->pdata.dsp_calib_clk_rate)) in rt5514_dsp_voice_wake_up_put()
343 dev_err(component->dev, in rt5514_dsp_voice_wake_up_put()
346 if (clk_prepare_enable(rt5514->dsp_calib_clk)) in rt5514_dsp_voice_wake_up_put()
347 dev_err(component->dev, in rt5514_dsp_voice_wake_up_put()
357 dev_err(component->dev, "There is no SPI driver for" in rt5514_dsp_voice_wake_up_put()
361 rt5514->pll3_cal_value = buf[0] | buf[1] << 8 | in rt5514_dsp_voice_wake_up_put()
365 clk_disable_unprepare(rt5514->dsp_calib_clk); in rt5514_dsp_voice_wake_up_put()
370 request_firmware(&fw, RT5514_FIRMWARE1, component->dev); in rt5514_dsp_voice_wake_up_put()
373 rt5514_spi_burst_write(0x4ff60000, fw->data, in rt5514_dsp_voice_wake_up_put()
374 ((fw->size/8)+1)*8); in rt5514_dsp_voice_wake_up_put()
376 dev_err(component->dev, "There is no SPI driver for" in rt5514_dsp_voice_wake_up_put()
383 request_firmware(&fw, RT5514_FIRMWARE2, component->dev); in rt5514_dsp_voice_wake_up_put()
386 rt5514_spi_burst_write(0x4ffc0000, fw->data, in rt5514_dsp_voice_wake_up_put()
387 ((fw->size/8)+1)*8); in rt5514_dsp_voice_wake_up_put()
389 dev_err(component->dev, "There is no SPI driver for" in rt5514_dsp_voice_wake_up_put()
396 /* DSP run */ in rt5514_dsp_voice_wake_up_put()
397 regmap_write(rt5514->i2c_regmap, 0x18002f00, in rt5514_dsp_voice_wake_up_put()
400 if (rt5514->pdata.dsp_calib_clk_name && in rt5514_dsp_voice_wake_up_put()
401 !IS_ERR(rt5514->dsp_calib_clk)) { in rt5514_dsp_voice_wake_up_put()
404 regmap_write(rt5514->i2c_regmap, 0x1800211c, in rt5514_dsp_voice_wake_up_put()
405 rt5514->pll3_cal_value); in rt5514_dsp_voice_wake_up_put()
406 regmap_write(rt5514->i2c_regmap, 0x18002124, in rt5514_dsp_voice_wake_up_put()
408 regmap_write(rt5514->i2c_regmap, 0x18002124, in rt5514_dsp_voice_wake_up_put()
410 regmap_write(rt5514->i2c_regmap, 0x18002124, in rt5514_dsp_voice_wake_up_put()
414 regmap_multi_reg_write(rt5514->i2c_regmap, in rt5514_dsp_voice_wake_up_put()
416 regcache_mark_dirty(rt5514->regmap); in rt5514_dsp_voice_wake_up_put()
417 regcache_sync(rt5514->regmap); in rt5514_dsp_voice_wake_up_put()
433 SOC_SINGLE_EXT("DSP Voice Wake Up", SND_SOC_NOPM, 0, 1, 0,
486 * rt5514_calc_dmic_clk - Calculate the frequency divider parameter of dmic.
492 * 1MHz - 3MHz range.
501 return -EINVAL; in rt5514_calc_dmic_clk()
510 dev_warn(component->dev, "Base clock rate %d is too high\n", rate); in rt5514_calc_dmic_clk()
511 return -EINVAL; in rt5514_calc_dmic_clk()
517 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in rt5514_set_dmic_clk()
521 idx = rt5514_calc_dmic_clk(component, rt5514->sysclk); in rt5514_set_dmic_clk()
523 dev_err(component->dev, "Failed to set DMIC clock\n"); in rt5514_set_dmic_clk()
525 regmap_update_bits(rt5514->regmap, RT5514_CLK_CTRL1, in rt5514_set_dmic_clk()
529 if (rt5514->pdata.dmic_init_delay) in rt5514_set_dmic_clk()
530 msleep(rt5514->pdata.dmic_init_delay); in rt5514_set_dmic_clk()
538 struct snd_soc_component *component = snd_soc_dapm_to_component(source->dapm); in rt5514_is_sys_clk_from_pll()
541 if (rt5514->sysclk_src == RT5514_SCLK_S_PLL1) in rt5514_is_sys_clk_from_pll()
550 struct snd_soc_component *component = snd_soc_dapm_to_component(source->dapm); in rt5514_i2s_use_asrc()
553 return (rt5514->sysclk > rt5514->lrck * 384); in rt5514_i2s_use_asrc()
666 SND_SOC_DAPM_AIF_OUT("AIF1TX", "AIF1 Capture", 0, SND_SOC_NOPM, 0, 0),
753 struct snd_soc_component *component = dai->component; in rt5514_hw_params()
758 rt5514->lrck = params_rate(params); in rt5514_hw_params()
759 pre_div = rl6231_get_clk_info(rt5514->sysclk, rt5514->lrck); in rt5514_hw_params()
761 dev_err(component->dev, "Unsupported clock setting\n"); in rt5514_hw_params()
762 return -EINVAL; in rt5514_hw_params()
767 dev_err(component->dev, "Unsupported frame size: %d\n", frame_size); in rt5514_hw_params()
768 return -EINVAL; in rt5514_hw_params()
772 rt5514->bclk = rt5514->lrck * (32 << bclk_ms); in rt5514_hw_params()
774 dev_dbg(dai->dev, "bclk is %dHz and lrck is %dHz\n", in rt5514_hw_params()
775 rt5514->bclk, rt5514->lrck); in rt5514_hw_params()
776 dev_dbg(dai->dev, "bclk_ms is %d and pre_div is %d for iis %d\n", in rt5514_hw_params()
777 bclk_ms, pre_div, dai->id); in rt5514_hw_params()
792 return -EINVAL; in rt5514_hw_params()
795 regmap_update_bits(rt5514->regmap, RT5514_I2S_CTRL1, RT5514_I2S_DL_MASK, in rt5514_hw_params()
797 regmap_update_bits(rt5514->regmap, RT5514_CLK_CTRL1, in rt5514_hw_params()
800 regmap_update_bits(rt5514->regmap, RT5514_CLK_CTRL2, in rt5514_hw_params()
810 struct snd_soc_component *component = dai->component; in rt5514_set_dai_fmt()
831 return -EINVAL; in rt5514_set_dai_fmt()
851 return -EINVAL; in rt5514_set_dai_fmt()
854 regmap_update_bits(rt5514->regmap, RT5514_I2S_CTRL1, in rt5514_set_dai_fmt()
864 struct snd_soc_component *component = dai->component; in rt5514_set_dai_sysclk()
868 if (freq == rt5514->sysclk && clk_id == rt5514->sysclk_src) in rt5514_set_dai_sysclk()
881 dev_err(component->dev, "Invalid clock id (%d)\n", clk_id); in rt5514_set_dai_sysclk()
882 return -EINVAL; in rt5514_set_dai_sysclk()
885 regmap_update_bits(rt5514->regmap, RT5514_CLK_CTRL2, in rt5514_set_dai_sysclk()
888 rt5514->sysclk = freq; in rt5514_set_dai_sysclk()
889 rt5514->sysclk_src = clk_id; in rt5514_set_dai_sysclk()
891 dev_dbg(dai->dev, "Sysclk is %dHz and clock id is %d\n", freq, clk_id); in rt5514_set_dai_sysclk()
899 struct snd_soc_component *component = dai->component; in rt5514_set_dai_pll()
905 dev_dbg(component->dev, "PLL disabled\n"); in rt5514_set_dai_pll()
907 rt5514->pll_in = 0; in rt5514_set_dai_pll()
908 rt5514->pll_out = 0; in rt5514_set_dai_pll()
909 regmap_update_bits(rt5514->regmap, RT5514_CLK_CTRL2, in rt5514_set_dai_pll()
916 if (source == rt5514->pll_src && freq_in == rt5514->pll_in && in rt5514_set_dai_pll()
917 freq_out == rt5514->pll_out) in rt5514_set_dai_pll()
922 regmap_update_bits(rt5514->regmap, RT5514_PLL_SOURCE_CTRL, in rt5514_set_dai_pll()
927 regmap_update_bits(rt5514->regmap, RT5514_PLL_SOURCE_CTRL, in rt5514_set_dai_pll()
932 dev_err(component->dev, "Unknown PLL source %d\n", source); in rt5514_set_dai_pll()
933 return -EINVAL; in rt5514_set_dai_pll()
938 dev_err(component->dev, "Unsupported input clock %d\n", freq_in); in rt5514_set_dai_pll()
942 dev_dbg(component->dev, "bypass=%d m=%d n=%d k=%d\n", in rt5514_set_dai_pll()
946 regmap_write(rt5514->regmap, RT5514_ANA_CTRL_PLL1_1, in rt5514_set_dai_pll()
950 regmap_update_bits(rt5514->regmap, RT5514_ANA_CTRL_PLL1_2, in rt5514_set_dai_pll()
953 rt5514->pll_in = freq_in; in rt5514_set_dai_pll()
954 rt5514->pll_out = freq_out; in rt5514_set_dai_pll()
955 rt5514->pll_src = source; in rt5514_set_dai_pll()
963 struct snd_soc_component *component = dai->component; in rt5514_set_tdm_slot()
1037 regmap_update_bits(rt5514->regmap, RT5514_I2S_CTRL1, RT5514_TDM_MODE | in rt5514_set_tdm_slot()
1042 regmap_update_bits(rt5514->regmap, RT5514_I2S_CTRL2, in rt5514_set_tdm_slot()
1058 clk_disable_unprepare(rt5514->mclk); in rt5514_set_bias_level()
1060 ret = clk_prepare_enable(rt5514->mclk); in rt5514_set_bias_level()
1069 * If the DSP is enabled in start of recording, the DSP in rt5514_set_bias_level()
1073 if (rt5514->dsp_enabled) { in rt5514_set_bias_level()
1074 rt5514->dsp_enabled = 0; in rt5514_set_bias_level()
1075 regmap_multi_reg_write(rt5514->i2c_regmap, in rt5514_set_bias_level()
1078 regcache_mark_dirty(rt5514->regmap); in rt5514_set_bias_level()
1079 regcache_sync(rt5514->regmap); in rt5514_set_bias_level()
1094 struct platform_device *pdev = container_of(component->dev, in rt5514_probe()
1097 rt5514->mclk = devm_clk_get_optional(component->dev, "mclk"); in rt5514_probe()
1098 if (IS_ERR(rt5514->mclk)) in rt5514_probe()
1099 return PTR_ERR(rt5514->mclk); in rt5514_probe()
1101 if (rt5514->pdata.dsp_calib_clk_name) { in rt5514_probe()
1102 rt5514->dsp_calib_clk = devm_clk_get(&pdev->dev, in rt5514_probe()
1103 rt5514->pdata.dsp_calib_clk_name); in rt5514_probe()
1104 if (PTR_ERR(rt5514->dsp_calib_clk) == -EPROBE_DEFER) in rt5514_probe()
1105 return -EPROBE_DEFER; in rt5514_probe()
1108 rt5514->component = component; in rt5514_probe()
1109 rt5514->pll3_cal_value = 0x0078b000; in rt5514_probe()
1119 regmap_read(rt5514->i2c_regmap, reg | RT5514_DSP_MAPPING, val); in rt5514_i2c_read()
1129 regmap_write(rt5514->i2c_regmap, reg | RT5514_DSP_MAPPING, val); in rt5514_i2c_write()
1148 .name = "rt5514-aif1",
1151 .stream_name = "AIF1 Capture",
1225 device_property_read_u32(dev, "realtek,dmic-init-delay-ms", in rt5514_parse_dp()
1226 &rt5514->pdata.dmic_init_delay); in rt5514_parse_dp()
1227 device_property_read_string(dev, "realtek,dsp-calib-clk-name", in rt5514_parse_dp()
1228 &rt5514->pdata.dsp_calib_clk_name); in rt5514_parse_dp()
1229 device_property_read_u32(dev, "realtek,dsp-calib-clk-rate", in rt5514_parse_dp()
1230 &rt5514->pdata.dsp_calib_clk_rate); in rt5514_parse_dp()
1245 regmap_read(rt5514->regmap, RT5514_VENDOR_ID2, &val); in rt5514_i2c_resume()
1252 struct rt5514_platform_data *pdata = dev_get_platdata(&i2c->dev); in rt5514_i2c_probe()
1257 rt5514 = devm_kzalloc(&i2c->dev, sizeof(struct rt5514_priv), in rt5514_i2c_probe()
1260 return -ENOMEM; in rt5514_i2c_probe()
1265 rt5514->pdata = *pdata; in rt5514_i2c_probe()
1267 rt5514_parse_dp(rt5514, &i2c->dev); in rt5514_i2c_probe()
1269 rt5514->i2c_regmap = devm_regmap_init_i2c(i2c, &rt5514_i2c_regmap); in rt5514_i2c_probe()
1270 if (IS_ERR(rt5514->i2c_regmap)) { in rt5514_i2c_probe()
1271 ret = PTR_ERR(rt5514->i2c_regmap); in rt5514_i2c_probe()
1272 dev_err(&i2c->dev, "Failed to allocate register map: %d\n", in rt5514_i2c_probe()
1277 rt5514->regmap = devm_regmap_init(&i2c->dev, NULL, i2c, &rt5514_regmap); in rt5514_i2c_probe()
1278 if (IS_ERR(rt5514->regmap)) { in rt5514_i2c_probe()
1279 ret = PTR_ERR(rt5514->regmap); in rt5514_i2c_probe()
1280 dev_err(&i2c->dev, "Failed to allocate register map: %d\n", in rt5514_i2c_probe()
1291 ret = regmap_read(rt5514->regmap, RT5514_VENDOR_ID2, &val); in rt5514_i2c_probe()
1293 ret = regmap_read(rt5514->regmap, RT5514_VENDOR_ID2, &val); in rt5514_i2c_probe()
1295 dev_err(&i2c->dev, in rt5514_i2c_probe()
1297 return -ENODEV; in rt5514_i2c_probe()
1300 ret = regmap_multi_reg_write(rt5514->i2c_regmap, rt5514_i2c_patch, in rt5514_i2c_probe()
1303 dev_warn(&i2c->dev, "Failed to apply i2c_regmap patch: %d\n", in rt5514_i2c_probe()
1306 ret = regmap_register_patch(rt5514->regmap, rt5514_patch, in rt5514_i2c_probe()
1309 dev_warn(&i2c->dev, "Failed to apply regmap patch: %d\n", ret); in rt5514_i2c_probe()
1311 return devm_snd_soc_register_component(&i2c->dev, in rt5514_i2c_probe()