Lines Matching +full:spk +full:- +full:shutdown
1 // SPDX-License-Identifier: GPL-2.0
3 * rt1011.c -- rt1011 ALSA SoC amplifier component driver
25 #include <sound/soc-dapm.h>
683 regmap_multi_reg_write(rt1011->regmap, in rt1011_reg_init()
1042 ucontrol->value.integer.value[0] = rt1011->recv_spk_mode; in rt1011_recv_spk_mode_get()
1055 if (ucontrol->value.integer.value[0] == rt1011->recv_spk_mode) in rt1011_recv_spk_mode_put()
1059 rt1011->recv_spk_mode = ucontrol->value.integer.value[0]; in rt1011_recv_spk_mode_put()
1061 if (rt1011->recv_spk_mode) { in rt1011_recv_spk_mode_put()
1119 (struct rt1011_bq_drc_params *)ucontrol->value.integer.value; in rt1011_bq_drc_coeff_get()
1122 if (strstr(ucontrol->id.name, "AdvanceMode Initial Set")) in rt1011_bq_drc_coeff_get()
1124 else if (strstr(ucontrol->id.name, "AdvanceMode SEP BQ Coeff")) in rt1011_bq_drc_coeff_get()
1126 else if (strstr(ucontrol->id.name, "AdvanceMode EQ BQ Coeff")) in rt1011_bq_drc_coeff_get()
1128 else if (strstr(ucontrol->id.name, "AdvanceMode BQ UI Coeff")) in rt1011_bq_drc_coeff_get()
1130 else if (strstr(ucontrol->id.name, "AdvanceMode SmartBoost Coeff")) in rt1011_bq_drc_coeff_get()
1133 return -EINVAL; in rt1011_bq_drc_coeff_get()
1136 ucontrol->id.name, mode_idx); in rt1011_bq_drc_coeff_get()
1137 bq_drc_info = rt1011->bq_drc_params[mode_idx]; in rt1011_bq_drc_coeff_get()
1156 (struct rt1011_bq_drc_params *)ucontrol->value.integer.value; in rt1011_bq_drc_coeff_put()
1159 if (strstr(ucontrol->id.name, "AdvanceMode Initial Set")) in rt1011_bq_drc_coeff_put()
1161 else if (strstr(ucontrol->id.name, "AdvanceMode SEP BQ Coeff")) in rt1011_bq_drc_coeff_put()
1163 else if (strstr(ucontrol->id.name, "AdvanceMode EQ BQ Coeff")) in rt1011_bq_drc_coeff_put()
1165 else if (strstr(ucontrol->id.name, "AdvanceMode BQ UI Coeff")) in rt1011_bq_drc_coeff_put()
1167 else if (strstr(ucontrol->id.name, "AdvanceMode SmartBoost Coeff")) in rt1011_bq_drc_coeff_put()
1170 return -EINVAL; in rt1011_bq_drc_coeff_put()
1172 bq_drc_info = rt1011->bq_drc_params[mode_idx]; in rt1011_bq_drc_coeff_put()
1177 ucontrol->id.name, mode_idx); in rt1011_bq_drc_coeff_put()
1198 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; in rt1011_bq_drc_info()
1199 uinfo->count = 128; in rt1011_bq_drc_info()
1200 uinfo->value.integer.max = 0x17ffffff; in rt1011_bq_drc_info()
1218 ucontrol->value.integer.value[0] = rt1011->cali_done; in rt1011_r0_cali_get()
1229 rt1011->cali_done = 0; in rt1011_r0_cali_put()
1231 ucontrol->value.integer.value[0]) in rt1011_r0_cali_put()
1239 if (!rt1011->r0_reg) in rt1011_r0_load()
1240 return -EINVAL; in rt1011_r0_load()
1243 regmap_write(rt1011->regmap, RT1011_INIT_RECIPROCAL_REG_24_16, in rt1011_r0_load()
1244 ((rt1011->r0_reg>>16) & 0x1ff)); in rt1011_r0_load()
1245 regmap_write(rt1011->regmap, RT1011_INIT_RECIPROCAL_REG_15_0, in rt1011_r0_load()
1246 (rt1011->r0_reg & 0xffff)); in rt1011_r0_load()
1247 regmap_write(rt1011->regmap, RT1011_SPK_TEMP_PROTECT_4, 0x4080); in rt1011_r0_load()
1258 ucontrol->value.integer.value[0] = rt1011->r0_reg; in rt1011_r0_load_mode_get()
1271 if (ucontrol->value.integer.value[0] == rt1011->r0_reg) in rt1011_r0_load_mode_put()
1274 if (ucontrol->value.integer.value[0] == 0) in rt1011_r0_load_mode_put()
1275 return -EINVAL; in rt1011_r0_load_mode_put()
1277 dev = regmap_get_device(rt1011->regmap); in rt1011_r0_load_mode_put()
1279 rt1011->r0_reg = ucontrol->value.integer.value[0]; in rt1011_r0_load_mode_put()
1282 r0_integer = format / rt1011->r0_reg / 128; in rt1011_r0_load_mode_put()
1283 r0_factor = ((format / rt1011->r0_reg * 100) / 128) in rt1011_r0_load_mode_put()
1284 - (r0_integer * 100); in rt1011_r0_load_mode_put()
1286 r0_integer, r0_factor, rt1011->r0_reg); in rt1011_r0_load_mode_put()
1288 if (rt1011->r0_reg) in rt1011_r0_load_mode_put()
1298 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; in rt1011_r0_load_info()
1299 uinfo->count = 1; in rt1011_r0_load_info()
1300 uinfo->value.integer.max = 0x1ffffff; in rt1011_r0_load_info()
1327 rt1011->i2s_ref = ucontrol->value.enumerated.item[0]; in rt1011_i2s_ref_put()
1328 switch (rt1011->i2s_ref) { in rt1011_i2s_ref_put()
1330 regmap_write(rt1011->regmap, RT1011_TDM_TOTAL_SET, 0x0240); in rt1011_i2s_ref_put()
1331 regmap_write(rt1011->regmap, RT1011_TDM1_SET_2, 0x8); in rt1011_i2s_ref_put()
1332 regmap_write(rt1011->regmap, RT1011_TDM1_SET_1, 0x1022); in rt1011_i2s_ref_put()
1333 regmap_write(rt1011->regmap, RT1011_ADCDAT_OUT_SOURCE, 0x4); in rt1011_i2s_ref_put()
1336 regmap_write(rt1011->regmap, RT1011_TDM_TOTAL_SET, 0x0240); in rt1011_i2s_ref_put()
1337 regmap_write(rt1011->regmap, RT1011_TDM1_SET_2, 0x8); in rt1011_i2s_ref_put()
1338 regmap_write(rt1011->regmap, RT1011_TDM1_SET_1, 0x10a2); in rt1011_i2s_ref_put()
1339 regmap_write(rt1011->regmap, RT1011_ADCDAT_OUT_SOURCE, 0x4); in rt1011_i2s_ref_put()
1342 dev_info(component->dev, "I2S Reference: Do nothing\n"); in rt1011_i2s_ref_put()
1356 ucontrol->value.enumerated.item[0] = rt1011->i2s_ref; in rt1011_i2s_ref_get()
1381 SOC_SINGLE_EXT("RECV SPK Mode", SND_SOC_NOPM, 0, 1, 0,
1408 snd_soc_dapm_to_component(source->dapm); in rt1011_is_sys_clk_from_pll()
1411 if (rt1011->sysclk_src == RT1011_FS_SYS_PRE_S_PLL1) in rt1011_is_sys_clk_from_pll()
1421 snd_soc_dapm_to_component(w->dapm); in rt1011_dac_event()
1459 SND_SOC_DAPM_SUPPLY("ISENSE SPK", RT1011_POWER_1,
1461 SND_SOC_DAPM_SUPPLY("VSENSE SPK", RT1011_POWER_1,
1526 { "DAC", NULL, "ISENSE SPK" },
1527 { "DAC", NULL, "VSENSE SPK" },
1562 return -EINVAL; in rt1011_get_clk_info()
1569 return -EINVAL; in rt1011_get_clk_info()
1575 struct snd_soc_component *component = dai->component; in rt1011_hw_params()
1580 rt1011->lrck = params_rate(params); in rt1011_hw_params()
1581 pre_div = rt1011_get_clk_info(rt1011->sysclk, rt1011->lrck); in rt1011_hw_params()
1583 dev_warn(component->dev, "Force using PLL "); in rt1011_hw_params()
1585 rt1011->lrck * 64, rt1011->lrck * 256); in rt1011_hw_params()
1587 rt1011->lrck * 256, SND_SOC_CLOCK_IN); in rt1011_hw_params()
1592 dev_err(component->dev, "Unsupported frame size: %d\n", in rt1011_hw_params()
1594 return -EINVAL; in rt1011_hw_params()
1598 rt1011->bclk = rt1011->lrck * (32 << bclk_ms); in rt1011_hw_params()
1600 dev_dbg(component->dev, "bclk_ms is %d and pre_div is %d for iis %d\n", in rt1011_hw_params()
1601 bclk_ms, pre_div, dai->id); in rt1011_hw_params()
1603 dev_dbg(component->dev, "lrck is %dHz and pre_div is %d for iis %d\n", in rt1011_hw_params()
1604 rt1011->lrck, pre_div, dai->id); in rt1011_hw_params()
1638 return -EINVAL; in rt1011_hw_params()
1641 switch (dai->id) { in rt1011_hw_params()
1654 dev_err(component->dev, "Invalid dai->id: %d\n", dai->id); in rt1011_hw_params()
1655 return -EINVAL; in rt1011_hw_params()
1666 struct snd_soc_component *component = dai->component; in rt1011_set_dai_fmt()
1678 ret = -EINVAL; in rt1011_set_dai_fmt()
1689 ret = -EINVAL; in rt1011_set_dai_fmt()
1706 ret = -EINVAL; in rt1011_set_dai_fmt()
1710 switch (dai->id) { in rt1011_set_dai_fmt()
1721 dev_err(component->dev, "Invalid dai->id: %d\n", dai->id); in rt1011_set_dai_fmt()
1722 ret = -EINVAL; in rt1011_set_dai_fmt()
1736 if (freq == rt1011->sysclk && clk_id == rt1011->sysclk_src) in rt1011_set_component_sysclk()
1759 dev_err(component->dev, "Invalid clock id (%d)\n", clk_id); in rt1011_set_component_sysclk()
1760 return -EINVAL; in rt1011_set_component_sysclk()
1764 rt1011->sysclk = freq; in rt1011_set_component_sysclk()
1765 rt1011->sysclk_src = clk_id; in rt1011_set_component_sysclk()
1767 dev_dbg(component->dev, "Sysclk is %dHz and clock id is %d\n", in rt1011_set_component_sysclk()
1781 if (source == rt1011->pll_src && freq_in == rt1011->pll_in && in rt1011_set_component_pll()
1782 freq_out == rt1011->pll_out) in rt1011_set_component_pll()
1786 dev_dbg(component->dev, "PLL disabled\n"); in rt1011_set_component_pll()
1788 rt1011->pll_in = 0; in rt1011_set_component_pll()
1789 rt1011->pll_out = 0; in rt1011_set_component_pll()
1815 dev_err(component->dev, "Unknown PLL Source %d\n", source); in rt1011_set_component_pll()
1816 return -EINVAL; in rt1011_set_component_pll()
1821 dev_err(component->dev, "Unsupported input clock %d\n", in rt1011_set_component_pll()
1826 dev_dbg(component->dev, "bypass=%d m=%d n=%d k=%d\n", in rt1011_set_component_pll()
1837 rt1011->pll_in = freq_in; in rt1011_set_component_pll()
1838 rt1011->pll_out = freq_out; in rt1011_set_component_pll()
1839 rt1011->pll_src = source; in rt1011_set_component_pll()
1847 struct snd_soc_component *component = dai->component; in rt1011_set_tdm_slot()
1873 ret = -EINVAL; in rt1011_set_tdm_slot()
1893 ret = -EINVAL; in rt1011_set_tdm_slot()
1900 ret = -EINVAL; in rt1011_set_tdm_slot()
1901 dev_err(component->dev, "too many rx slots or zero slot\n"); in rt1011_set_tdm_slot()
1932 ((first_bit-1) << RT1011_TDM_I2S_TX_L_DAC1_1_SFT) | in rt1011_set_tdm_slot()
1936 ret = -EINVAL; in rt1011_set_tdm_slot()
1943 ret = -EINVAL; in rt1011_set_tdm_slot()
1944 dev_err(component->dev, "too many tx slots or zero slot\n"); in rt1011_set_tdm_slot()
1950 if (last_bit - first_bit > 1) { in rt1011_set_tdm_slot()
1951 ret = -EINVAL; in rt1011_set_tdm_slot()
1952 dev_err(component->dev, "tx slot location error\n"); in rt1011_set_tdm_slot()
2006 ret = -EINVAL; in rt1011_set_tdm_slot()
2007 dev_dbg(component->dev, in rt1011_set_tdm_slot()
2024 ret = -EINVAL; in rt1011_set_tdm_slot()
2025 dev_dbg(component->dev, in rt1011_set_tdm_slot()
2056 rt1011->component = component; in rt1011_probe()
2058 schedule_work(&rt1011->cali_work); in rt1011_probe()
2060 rt1011->i2s_ref = 0; in rt1011_probe()
2061 rt1011->bq_drc_params = devm_kcalloc(component->dev, in rt1011_probe()
2064 if (!rt1011->bq_drc_params) in rt1011_probe()
2065 return -ENOMEM; in rt1011_probe()
2068 rt1011->bq_drc_params[i] = devm_kcalloc(component->dev, in rt1011_probe()
2071 if (!rt1011->bq_drc_params[i]) in rt1011_probe()
2072 return -ENOMEM; in rt1011_probe()
2082 cancel_work_sync(&rt1011->cali_work); in rt1011_remove()
2083 rt1011_reset(rt1011->regmap); in rt1011_remove()
2091 regcache_cache_only(rt1011->regmap, true); in rt1011_suspend()
2092 regcache_mark_dirty(rt1011->regmap); in rt1011_suspend()
2101 regcache_cache_only(rt1011->regmap, false); in rt1011_resume()
2102 regcache_sync(rt1011->regmap); in rt1011_resume()
2149 .name = "rt1011-aif",
2220 struct device *dev = regmap_get_device(rt1011->regmap); in rt1011_calibrate()
2222 snd_soc_component_get_dapm(rt1011->component); in rt1011_calibrate()
2226 regcache_cache_bypass(rt1011->regmap, true); in rt1011_calibrate()
2228 regmap_write(rt1011->regmap, RT1011_RESET, 0x0000); in rt1011_calibrate()
2229 regmap_write(rt1011->regmap, RT1011_SYSTEM_RESET_3, 0x740f); in rt1011_calibrate()
2230 regmap_write(rt1011->regmap, RT1011_SYSTEM_RESET_3, 0x770f); in rt1011_calibrate()
2233 regmap_write(rt1011->regmap, RT1011_CLK_2, 0x9400); in rt1011_calibrate()
2234 regmap_write(rt1011->regmap, RT1011_PLL_1, 0x0800); in rt1011_calibrate()
2235 regmap_write(rt1011->regmap, RT1011_PLL_2, 0x0020); in rt1011_calibrate()
2236 regmap_write(rt1011->regmap, RT1011_CLK_DET, 0x0800); in rt1011_calibrate()
2239 regmap_write(rt1011->regmap, RT1011_ADC_SET_5, 0x0a20); in rt1011_calibrate()
2240 regmap_write(rt1011->regmap, RT1011_DAC_SET_2, 0xe232); in rt1011_calibrate()
2241 regmap_write(rt1011->regmap, RT1011_ADC_SET_4, 0xc000); in rt1011_calibrate()
2244 regmap_write(rt1011->regmap, RT1011_SPK_PRO_DC_DET_1, 0xb00c); in rt1011_calibrate()
2245 regmap_write(rt1011->regmap, RT1011_SPK_PRO_DC_DET_2, 0xcccc); in rt1011_calibrate()
2248 regmap_write(rt1011->regmap, RT1011_POWER_1, 0xe0e0); in rt1011_calibrate()
2249 regmap_write(rt1011->regmap, RT1011_POWER_3, 0x5003); in rt1011_calibrate()
2250 regmap_write(rt1011->regmap, RT1011_POWER_9, 0xa860); in rt1011_calibrate()
2251 regmap_write(rt1011->regmap, RT1011_DAC_SET_2, 0xa032); in rt1011_calibrate()
2254 regmap_write(rt1011->regmap, RT1011_POWER_2, 0x0007); in rt1011_calibrate()
2255 regmap_write(rt1011->regmap, RT1011_POWER_3, 0x5ff7); in rt1011_calibrate()
2256 regmap_write(rt1011->regmap, RT1011_A_TEMP_SEN, 0x7f44); in rt1011_calibrate()
2257 regmap_write(rt1011->regmap, RT1011_A_TIMING_1, 0x4054); in rt1011_calibrate()
2258 regmap_write(rt1011->regmap, RT1011_BAT_GAIN_1, 0x309c); in rt1011_calibrate()
2261 regmap_write(rt1011->regmap, RT1011_DC_CALIB_CLASSD_3, 0xcb00); in rt1011_calibrate()
2262 regmap_write(rt1011->regmap, RT1011_BOOST_CON_1, 0xe080); in rt1011_calibrate()
2263 regmap_write(rt1011->regmap, RT1011_POWER_4, 0x16f2); in rt1011_calibrate()
2264 regmap_write(rt1011->regmap, RT1011_POWER_6, 0x36ad); in rt1011_calibrate()
2267 regmap_write(rt1011->regmap, RT1011_MIXER_1, 0x3f1d); in rt1011_calibrate()
2270 regmap_write(rt1011->regmap, RT1011_EFUSE_CONTROL_1, 0x0d0a); in rt1011_calibrate()
2273 regmap_read(rt1011->regmap, RT1011_EFUSE_ADC_OFFSET_18_16, &value); in rt1011_calibrate()
2275 regmap_read(rt1011->regmap, RT1011_EFUSE_ADC_OFFSET_15_0, &value); in rt1011_calibrate()
2278 regmap_read(rt1011->regmap, RT1011_EFUSE_DAC_OFFSET_G0_20_16, &value); in rt1011_calibrate()
2280 regmap_read(rt1011->regmap, RT1011_EFUSE_DAC_OFFSET_G0_15_0, &value); in rt1011_calibrate()
2283 regmap_read(rt1011->regmap, RT1011_EFUSE_DAC_OFFSET_G1_20_16, &value); in rt1011_calibrate()
2285 regmap_read(rt1011->regmap, RT1011_EFUSE_DAC_OFFSET_G1_15_0, &value); in rt1011_calibrate()
2291 regmap_write(rt1011->regmap, RT1011_ADC_SET_1, 0x2925); in rt1011_calibrate()
2293 regmap_write(rt1011->regmap, RT1011_CLASS_D_POS, 0x010e); in rt1011_calibrate()
2294 regmap_write(rt1011->regmap, in rt1011_calibrate()
2298 regmap_write(rt1011->regmap, RT1011_SPK_TEMP_PROTECT_0, 0x8000); in rt1011_calibrate()
2299 regmap_write(rt1011->regmap, RT1011_SPK_TEMP_PROTECT_7, 0xf000); in rt1011_calibrate()
2300 regmap_write(rt1011->regmap, RT1011_SPK_TEMP_PROTECT_4, 0x4040); in rt1011_calibrate()
2301 regmap_write(rt1011->regmap, RT1011_SPK_TEMP_PROTECT_0, 0xc000); in rt1011_calibrate()
2302 regmap_write(rt1011->regmap, RT1011_SPK_TEMP_PROTECT_6, 0x07c2); in rt1011_calibrate()
2307 regmap_read(rt1011->regmap, in rt1011_calibrate()
2310 regmap_read(rt1011->regmap, in rt1011_calibrate()
2324 ret = -EAGAIN; in rt1011_calibrate()
2329 - (r0_integer * 100); in rt1011_calibrate()
2330 rt1011->r0_reg = r0[0]; in rt1011_calibrate()
2331 rt1011->cali_done = 1; in rt1011_calibrate()
2338 regmap_write(rt1011->regmap, RT1011_SPK_TEMP_PROTECT_0, 0x0000); in rt1011_calibrate()
2340 regmap_write(rt1011->regmap, RT1011_POWER_9, 0xa840); in rt1011_calibrate()
2341 regmap_write(rt1011->regmap, RT1011_SPK_TEMP_PROTECT_6, 0x0702); in rt1011_calibrate()
2342 regmap_write(rt1011->regmap, RT1011_MIXER_1, 0xffdd); in rt1011_calibrate()
2343 regmap_write(rt1011->regmap, RT1011_CLASSD_INTERNAL_SET_1, 0x0701); in rt1011_calibrate()
2344 regmap_write(rt1011->regmap, RT1011_DAC_SET_3, 0xe004); in rt1011_calibrate()
2345 regmap_write(rt1011->regmap, RT1011_A_TEMP_SEN, 0x7f40); in rt1011_calibrate()
2346 regmap_write(rt1011->regmap, RT1011_POWER_1, 0x0000); in rt1011_calibrate()
2347 regmap_write(rt1011->regmap, RT1011_POWER_2, 0x0000); in rt1011_calibrate()
2348 regmap_write(rt1011->regmap, RT1011_POWER_3, 0x0002); in rt1011_calibrate()
2349 regmap_write(rt1011->regmap, RT1011_POWER_4, 0x00f2); in rt1011_calibrate()
2351 regmap_write(rt1011->regmap, RT1011_RESET, 0x0000); in rt1011_calibrate()
2355 regmap_write(rt1011->regmap, in rt1011_calibrate()
2358 regmap_write(rt1011->regmap, in rt1011_calibrate()
2361 regmap_write(rt1011->regmap, in rt1011_calibrate()
2366 regcache_cache_bypass(rt1011->regmap, false); in rt1011_calibrate()
2367 regcache_mark_dirty(rt1011->regmap); in rt1011_calibrate()
2368 regcache_sync(rt1011->regmap); in rt1011_calibrate()
2378 struct snd_soc_component *component = rt1011->component; in rt1011_calibration_work()
2381 if (rt1011->r0_calib) in rt1011_calibration_work()
2391 rt1011->cali_done = 0; in rt1011_calibration_work()
2397 if (rt1011->temperature_calib <= 0xff && in rt1011_calibration_work()
2398 rt1011->temperature_calib > 0) { in rt1011_calibration_work()
2401 (rt1011->temperature_calib << 2)); in rt1011_calibration_work()
2404 if (rt1011->r0_calib) { in rt1011_calibration_work()
2405 rt1011->r0_reg = rt1011->r0_calib; in rt1011_calibration_work()
2408 r0_integer = format / rt1011->r0_reg / 128; in rt1011_calibration_work()
2409 r0_factor = ((format / rt1011->r0_reg * 100) / 128) in rt1011_calibration_work()
2410 - (r0_integer * 100); in rt1011_calibration_work()
2411 dev_info(component->dev, "DP r0 resistance about %d.%02d ohm, reg=0x%X\n", in rt1011_calibration_work()
2412 r0_integer, r0_factor, rt1011->r0_reg); in rt1011_calibration_work()
2423 &rt1011->temperature_calib); in rt1011_parse_dp()
2425 &rt1011->r0_calib); in rt1011_parse_dp()
2428 __func__, rt1011->r0_calib, rt1011->temperature_calib); in rt1011_parse_dp()
2439 rt1011 = devm_kzalloc(&i2c->dev, sizeof(struct rt1011_priv), in rt1011_i2c_probe()
2442 return -ENOMEM; in rt1011_i2c_probe()
2446 rt1011_parse_dp(rt1011, &i2c->dev); in rt1011_i2c_probe()
2448 rt1011->regmap = devm_regmap_init_i2c(i2c, &rt1011_regmap); in rt1011_i2c_probe()
2449 if (IS_ERR(rt1011->regmap)) { in rt1011_i2c_probe()
2450 ret = PTR_ERR(rt1011->regmap); in rt1011_i2c_probe()
2451 dev_err(&i2c->dev, "Failed to allocate register map: %d\n", in rt1011_i2c_probe()
2456 regmap_read(rt1011->regmap, RT1011_DEVICE_ID, &val); in rt1011_i2c_probe()
2458 dev_err(&i2c->dev, in rt1011_i2c_probe()
2460 return -ENODEV; in rt1011_i2c_probe()
2463 INIT_WORK(&rt1011->cali_work, rt1011_calibration_work); in rt1011_i2c_probe()
2465 return devm_snd_soc_register_component(&i2c->dev, in rt1011_i2c_probe()
2475 rt1011_reset(rt1011->regmap); in rt1011_i2c_shutdown()
2485 .shutdown = rt1011_i2c_shutdown,