Lines Matching full:rt5514
3 * rt5514.c -- RT5514 ALSA SoC audio codec driver
29 #include "rt5514.h"
31 #include "rt5514-spi.h"
117 static void rt5514_enable_dsp_prepare(struct rt5514_priv *rt5514) in rt5514_enable_dsp_prepare() argument
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()
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()
139 regmap_write(rt5514->i2c_regmap, 0x18002f08, 0x00000005); in rt5514_enable_dsp_prepare()
141 regmap_write(rt5514->i2c_regmap, 0x18001114, 0x00000001); in rt5514_enable_dsp_prepare()
143 regmap_write(rt5514->i2c_regmap, 0x18001118, 0x00000001); in rt5514_enable_dsp_prepare()
290 struct rt5514_priv *rt5514 = snd_soc_component_get_drvdata(component); in rt5514_dsp_voice_wake_up_get() local
292 ucontrol->value.integer.value[0] = rt5514->dsp_enabled; in rt5514_dsp_voice_wake_up_get()
297 static int rt5514_calibration(struct rt5514_priv *rt5514, bool on) in rt5514_calibration() argument
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()
328 struct rt5514_priv *rt5514 = snd_soc_component_get_drvdata(component); in rt5514_dsp_voice_wake_up_put() local
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()
346 if (clk_prepare_enable(rt5514->dsp_calib_clk)) in rt5514_dsp_voice_wake_up_put()
350 rt5514_calibration(rt5514, true); in rt5514_dsp_voice_wake_up_put()
361 rt5514->pll3_cal_value = buf[0] | buf[1] << 8 | in rt5514_dsp_voice_wake_up_put()
364 rt5514_calibration(rt5514, false); in rt5514_dsp_voice_wake_up_put()
365 clk_disable_unprepare(rt5514->dsp_calib_clk); in rt5514_dsp_voice_wake_up_put()
368 rt5514_enable_dsp_prepare(rt5514); 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()
518 struct rt5514_priv *rt5514 = snd_soc_component_get_drvdata(component); in rt5514_set_dmic_clk() local
521 idx = rt5514_calc_dmic_clk(component, rt5514->sysclk); 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()
539 struct rt5514_priv *rt5514 = snd_soc_component_get_drvdata(component); in rt5514_is_sys_clk_from_pll() local
541 if (rt5514->sysclk_src == RT5514_SCLK_S_PLL1) in rt5514_is_sys_clk_from_pll()
551 struct rt5514_priv *rt5514 = snd_soc_component_get_drvdata(component); in rt5514_i2s_use_asrc() local
553 return (rt5514->sysclk > rt5514->lrck * 384); in rt5514_i2s_use_asrc()
754 struct rt5514_priv *rt5514 = snd_soc_component_get_drvdata(component); in rt5514_hw_params() local
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()
772 rt5514->bclk = rt5514->lrck * (32 << bclk_ms); in rt5514_hw_params()
775 rt5514->bclk, rt5514->lrck); 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()
811 struct rt5514_priv *rt5514 = snd_soc_component_get_drvdata(component); in rt5514_set_dai_fmt() local
854 regmap_update_bits(rt5514->regmap, RT5514_I2S_CTRL1, in rt5514_set_dai_fmt()
865 struct rt5514_priv *rt5514 = snd_soc_component_get_drvdata(component); in rt5514_set_dai_sysclk() local
868 if (freq == rt5514->sysclk && clk_id == rt5514->sysclk_src) 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()
900 struct rt5514_priv *rt5514 = snd_soc_component_get_drvdata(component); in rt5514_set_dai_pll() local
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()
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()
964 struct rt5514_priv *rt5514 = snd_soc_component_get_drvdata(component); in rt5514_set_tdm_slot() local
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()
1052 struct rt5514_priv *rt5514 = snd_soc_component_get_drvdata(component); in rt5514_set_bias_level() local
1058 clk_disable_unprepare(rt5514->mclk); in rt5514_set_bias_level()
1060 ret = clk_prepare_enable(rt5514->mclk); 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()
1093 struct rt5514_priv *rt5514 = snd_soc_component_get_drvdata(component); in rt5514_probe() local
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()
1108 rt5514->component = component; in rt5514_probe()
1109 rt5514->pll3_cal_value = 0x0078b000; in rt5514_probe()
1117 struct rt5514_priv *rt5514 = i2c_get_clientdata(client); in rt5514_i2c_read() local
1119 regmap_read(rt5514->i2c_regmap, reg | RT5514_DSP_MAPPING, val); in rt5514_i2c_read()
1127 struct rt5514_priv *rt5514 = i2c_get_clientdata(client); in rt5514_i2c_write() local
1129 regmap_write(rt5514->i2c_regmap, reg | RT5514_DSP_MAPPING, val); in rt5514_i2c_write()
1148 .name = "rt5514-aif1",
1202 { "rt5514" },
1209 { .compatible = "realtek,rt5514", },
1223 static int rt5514_parse_dp(struct rt5514_priv *rt5514, struct device *dev) in rt5514_parse_dp() argument
1226 &rt5514->pdata.dmic_init_delay); in rt5514_parse_dp()
1228 &rt5514->pdata.dsp_calib_clk_name); in rt5514_parse_dp()
1230 &rt5514->pdata.dsp_calib_clk_rate); in rt5514_parse_dp()
1237 struct rt5514_priv *rt5514 = dev_get_drvdata(dev); in rt5514_i2c_resume() local
1241 * Add a bogus read to avoid rt5514's confusion after s2r in case it in rt5514_i2c_resume()
1245 regmap_read(rt5514->regmap, RT5514_VENDOR_ID2, &val); in rt5514_i2c_resume()
1253 struct rt5514_priv *rt5514; in rt5514_i2c_probe() local
1257 rt5514 = devm_kzalloc(&i2c->dev, sizeof(struct rt5514_priv), in rt5514_i2c_probe()
1259 if (rt5514 == NULL) in rt5514_i2c_probe()
1262 i2c_set_clientdata(i2c, rt5514); 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()
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()
1286 * The rt5514 can get confused if the i2c lines glitch together, as 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()
1296 "Device with ID register %x is not rt5514\n", val); in rt5514_i2c_probe()
1300 ret = regmap_multi_reg_write(rt5514->i2c_regmap, rt5514_i2c_patch, in rt5514_i2c_probe()
1306 ret = regmap_register_patch(rt5514->regmap, rt5514_patch, in rt5514_i2c_probe()
1322 .name = "rt5514",
1332 MODULE_DESCRIPTION("ASoC RT5514 driver");