Lines Matching +full:mic +full:- +full:max +full:- +full:freq
1 // SPDX-License-Identifier: GPL-2.0
2 // tscs42xx.c -- TSCS42xx ALSA SoC Audio driver
19 #include <sound/soc-dapm.h>
108 dev_err(component->dev, in plls_locked()
115 } while (count--); in plls_locked()
135 return -EINVAL; in sample_rate_to_pll_freq_out()
153 dev_err(component->dev, in write_coeff_ram()
162 ret = -EIO; in write_coeff_ram()
163 dev_err(component->dev, in write_coeff_ram()
168 ret = regmap_write(tscs42xx->regmap, R_DACCRADDR, addr); in write_coeff_ram()
170 dev_err(component->dev, in write_coeff_ram()
175 ret = regmap_bulk_write(tscs42xx->regmap, R_DACCRWRL, in write_coeff_ram()
179 dev_err(component->dev, in write_coeff_ram()
196 freq_out = sample_rate_to_pll_freq_out(tscs42xx->samplerate); in power_up_audio_plls()
207 ret = -EINVAL; in power_up_audio_plls()
208 dev_err(component->dev, in power_up_audio_plls()
209 "Unrecognized PLL output freq (%d)\n", ret); in power_up_audio_plls()
213 mutex_lock(&tscs42xx->pll_lock); in power_up_audio_plls()
217 dev_err(component->dev, "Failed to turn PLL on (%d)\n", ret); in power_up_audio_plls()
222 dev_err(component->dev, "Failed to lock plls\n"); in power_up_audio_plls()
223 ret = -ENOMSG; in power_up_audio_plls()
229 mutex_unlock(&tscs42xx->pll_lock); in power_up_audio_plls()
239 mutex_lock(&tscs42xx->pll_lock); in power_down_audio_plls()
245 dev_err(component->dev, "Failed to turn PLL off (%d)\n", ret); in power_down_audio_plls()
252 dev_err(component->dev, "Failed to turn PLL off (%d)\n", ret); in power_down_audio_plls()
258 mutex_unlock(&tscs42xx->pll_lock); in power_down_audio_plls()
270 (struct coeff_ram_ctl *)kcontrol->private_value; in coeff_ram_get()
271 struct soc_bytes_ext *params = &ctl->bytes_ext; in coeff_ram_get()
273 mutex_lock(&tscs42xx->coeff_ram_lock); in coeff_ram_get()
275 memcpy(ucontrol->value.bytes.data, in coeff_ram_get()
276 &tscs42xx->coeff_ram[ctl->addr * COEFF_SIZE], params->max); in coeff_ram_get()
278 mutex_unlock(&tscs42xx->coeff_ram_lock); in coeff_ram_get()
290 (struct coeff_ram_ctl *)kcontrol->private_value; in coeff_ram_put()
291 struct soc_bytes_ext *params = &ctl->bytes_ext; in coeff_ram_put()
292 unsigned int coeff_cnt = params->max / COEFF_SIZE; in coeff_ram_put()
295 mutex_lock(&tscs42xx->coeff_ram_lock); in coeff_ram_put()
297 tscs42xx->coeff_ram_synced = false; in coeff_ram_put()
299 memcpy(&tscs42xx->coeff_ram[ctl->addr * COEFF_SIZE], in coeff_ram_put()
300 ucontrol->value.bytes.data, params->max); in coeff_ram_put()
302 mutex_lock(&tscs42xx->pll_lock); in coeff_ram_put()
305 ret = write_coeff_ram(component, tscs42xx->coeff_ram, in coeff_ram_put()
306 ctl->addr, coeff_cnt); in coeff_ram_put()
308 dev_err(component->dev, in coeff_ram_put()
312 tscs42xx->coeff_ram_synced = true; in coeff_ram_put()
317 mutex_unlock(&tscs42xx->pll_lock); in coeff_ram_put()
319 mutex_unlock(&tscs42xx->coeff_ram_lock); in coeff_ram_put()
371 snd_soc_dapm_to_component(w->dapm); in pll_event()
386 snd_soc_dapm_to_component(w->dapm); in dac_event()
390 mutex_lock(&tscs42xx->coeff_ram_lock); in dac_event()
392 if (!tscs42xx->coeff_ram_synced) { in dac_event()
393 ret = write_coeff_ram(component, tscs42xx->coeff_ram, 0x00, in dac_event()
397 tscs42xx->coeff_ram_synced = true; in dac_event()
402 mutex_unlock(&tscs42xx->coeff_ram_lock); in dac_event()
449 /* Digital Mic */
450 SND_SOC_DAPM_SUPPLY_S("Digital Mic Enable", 2, R_DMICCTL,
454 /* Analog Mic */
455 SND_SOC_DAPM_SUPPLY_S("Mic Bias", 2, R_PWRM1, FB_PWRM1_MICB,
485 {"Mic Bias", NULL, "Vref"},
536 static DECLARE_TLV_DB_SCALE(hpvol_scale, -8850, 75, 0);
537 static DECLARE_TLV_DB_SCALE(spkvol_scale, -7725, 75, 0);
538 static DECLARE_TLV_DB_SCALE(dacvol_scale, -9563, 38, 0);
539 static DECLARE_TLV_DB_SCALE(adcvol_scale, -7125, 38, 0);
540 static DECLARE_TLV_DB_SCALE(invol_scale, -1725, 75, 0);
543 static DECLARE_TLV_DB_MINMAX(compth_scale, -9562, 0);
607 (struct coeff_ram_ctl *)kcontrol->private_value; in bytes_info_ext()
608 struct soc_bytes_ext *params = &ctl->bytes_ext; in bytes_info_ext()
610 ucontrol->type = SNDRV_CTL_ELEM_TYPE_BYTES; in bytes_info_ext()
611 ucontrol->count = params->max; in bytes_info_ext()
622 .bytes_ext = {.max = xcount, }, \
640 SOC_DOUBLE_R_TLV("Mic Boost Volume", R_INSELL, R_INSELR,
647 /* Mic Bias */
648 SOC_SINGLE("Mic Bias Boost Switch", 0x71, 0x07, 1, 0),
745 SOC_SINGLE_TLV("CLE Make-Up Gain Volume",
778 SOC_SINGLE_TLV("DAC MBC1 Make-Up Gain Volume",
790 SOC_SINGLE_TLV("DAC MBC2 Make-Up Gain Volume",
802 SOC_SINGLE_TLV("DAC MBC3 Make-Up Gain Volume",
833 ret = -EINVAL; in setup_sample_format()
834 dev_err(component->dev, "Unsupported format width (%d)\n", ret); in setup_sample_format()
840 dev_err(component->dev, in setup_sample_format()
897 dev_err(component->dev, "Unsupported sample rate %d\n", rate); in setup_sample_rate()
898 return -EINVAL; in setup_sample_rate()
905 dev_err(component->dev, in setup_sample_rate()
912 dev_err(component->dev, in setup_sample_rate()
919 dev_err(component->dev, in setup_sample_rate()
926 dev_err(component->dev, in setup_sample_rate()
931 mutex_lock(&tscs42xx->audio_params_lock); in setup_sample_rate()
933 tscs42xx->samplerate = rate; in setup_sample_rate()
935 mutex_unlock(&tscs42xx->audio_params_lock); in setup_sample_rate()
1068 ret = -EINVAL; in set_pll_ctl_from_input_freq()
1069 dev_err(component->dev, "No PLL input entry for %d (%d)\n", in set_pll_ctl_from_input_freq()
1076 pll_ctl->settings[i].addr, in set_pll_ctl_from_input_freq()
1077 pll_ctl->settings[i].mask, in set_pll_ctl_from_input_freq()
1078 pll_ctl->settings[i].val); in set_pll_ctl_from_input_freq()
1080 dev_err(component->dev, "Failed to set pll ctl (%d)\n", in set_pll_ctl_from_input_freq()
1093 struct snd_soc_component *component = codec_dai->component; in tscs42xx_hw_params()
1098 dev_err(component->dev, "Failed to setup sample format (%d)\n", in tscs42xx_hw_params()
1105 dev_err(component->dev, in tscs42xx_hw_params()
1121 dev_err(component->dev, "Failed to mute DAC (%d)\n", in dac_mute()
1137 dev_err(component->dev, "Failed to unmute DAC (%d)\n", in dac_unmute()
1152 dev_err(component->dev, "Failed to mute ADC (%d)\n", in adc_mute()
1167 dev_err(component->dev, "Failed to unmute ADC (%d)\n", in adc_unmute()
1177 struct snd_soc_component *component = dai->component; in tscs42xx_mute_stream()
1197 struct snd_soc_component *component = codec_dai->component; in tscs42xx_set_dai_fmt()
1200 /* Consumer mode not supported since it needs always-on frame clock */ in tscs42xx_set_dai_fmt()
1206 dev_err(component->dev, in tscs42xx_set_dai_fmt()
1212 ret = -EINVAL; in tscs42xx_set_dai_fmt()
1213 dev_err(component->dev, "Unsupported format (%d)\n", ret); in tscs42xx_set_dai_fmt()
1223 struct snd_soc_component *component = codec_dai->component; in tscs42xx_set_dai_bclk_ratio()
1239 dev_err(component->dev, "Unsupported bclk ratio (%d)\n", ret); in tscs42xx_set_dai_bclk_ratio()
1240 return -EINVAL; in tscs42xx_set_dai_bclk_ratio()
1246 dev_err(component->dev, in tscs42xx_set_dai_bclk_ratio()
1253 dev_err(component->dev, in tscs42xx_set_dai_bclk_ratio()
1258 mutex_lock(&tscs42xx->audio_params_lock); in tscs42xx_set_dai_bclk_ratio()
1260 tscs42xx->bclk_ratio = ratio; in tscs42xx_set_dai_bclk_ratio()
1262 mutex_unlock(&tscs42xx->audio_params_lock); in tscs42xx_set_dai_bclk_ratio()
1280 ret = regmap_read(tscs42xx->regmap, R_DEVIDH, ®); in part_is_valid()
1285 ret = regmap_read(tscs42xx->regmap, R_DEVIDL, ®); in part_is_valid()
1303 unsigned long freq; in set_sysclk() local
1306 switch (tscs42xx->sysclk_src_id) { in set_sysclk()
1313 dev_err(component->dev, in set_sysclk()
1324 dev_err(component->dev, in set_sysclk()
1330 dev_err(component->dev, "pll src is unsupported\n"); in set_sysclk()
1331 return -EINVAL; in set_sysclk()
1334 freq = clk_get_rate(tscs42xx->sysclk); in set_sysclk()
1335 ret = set_pll_ctl_from_input_freq(component, freq); in set_sysclk()
1337 dev_err(component->dev, in set_sysclk()
1338 "Failed to setup PLL input freq (%d)\n", ret); in set_sysclk()
1372 u8 *coeff_ram = tscs42xx->coeff_ram; in init_coeff_ram_cache()
1376 coeff_ram[((norm_addrs[i] + 1) * COEFF_SIZE) - 1] = 0x40; in init_coeff_ram_cache()
1385 .name = "tscs42xx-HiFi",
1417 tscs42xx = devm_kzalloc(&i2c->dev, sizeof(*tscs42xx), GFP_KERNEL); in tscs42xx_i2c_probe()
1419 ret = -ENOMEM; in tscs42xx_i2c_probe()
1420 dev_err(&i2c->dev, in tscs42xx_i2c_probe()
1427 tscs42xx->sysclk = devm_clk_get(&i2c->dev, src_names[src]); in tscs42xx_i2c_probe()
1428 if (!IS_ERR(tscs42xx->sysclk)) { in tscs42xx_i2c_probe()
1430 } else if (PTR_ERR(tscs42xx->sysclk) != -ENOENT) { in tscs42xx_i2c_probe()
1431 ret = PTR_ERR(tscs42xx->sysclk); in tscs42xx_i2c_probe()
1432 dev_err(&i2c->dev, "Failed to get sysclk (%d)\n", ret); in tscs42xx_i2c_probe()
1437 ret = -EINVAL; in tscs42xx_i2c_probe()
1438 dev_err(&i2c->dev, "Failed to get a valid clock name (%d)\n", in tscs42xx_i2c_probe()
1442 tscs42xx->sysclk_src_id = src; in tscs42xx_i2c_probe()
1444 tscs42xx->regmap = devm_regmap_init_i2c(i2c, &tscs42xx_regmap); in tscs42xx_i2c_probe()
1445 if (IS_ERR(tscs42xx->regmap)) { in tscs42xx_i2c_probe()
1446 ret = PTR_ERR(tscs42xx->regmap); in tscs42xx_i2c_probe()
1447 dev_err(&i2c->dev, "Failed to allocate regmap (%d)\n", ret); in tscs42xx_i2c_probe()
1455 dev_err(&i2c->dev, "No valid part (%d)\n", ret); in tscs42xx_i2c_probe()
1456 ret = -ENODEV; in tscs42xx_i2c_probe()
1460 ret = regmap_write(tscs42xx->regmap, R_RESET, RV_RESET_ENABLE); in tscs42xx_i2c_probe()
1462 dev_err(&i2c->dev, "Failed to reset device (%d)\n", ret); in tscs42xx_i2c_probe()
1466 ret = regmap_register_patch(tscs42xx->regmap, tscs42xx_patch, in tscs42xx_i2c_probe()
1469 dev_err(&i2c->dev, "Failed to apply patch (%d)\n", ret); in tscs42xx_i2c_probe()
1473 mutex_init(&tscs42xx->audio_params_lock); in tscs42xx_i2c_probe()
1474 mutex_init(&tscs42xx->coeff_ram_lock); in tscs42xx_i2c_probe()
1475 mutex_init(&tscs42xx->pll_lock); in tscs42xx_i2c_probe()
1477 ret = devm_snd_soc_register_component(&i2c->dev, in tscs42xx_i2c_probe()
1480 dev_err(&i2c->dev, "Failed to register codec (%d)\n", ret); in tscs42xx_i2c_probe()