Lines Matching +full:adc +full:- +full:channel +full:- +full:clk +full:- +full:src

1 // SPDX-License-Identifier: GPL-2.0
2 // tscs42xx.c -- TSCS42xx ALSA SoC Audio driver
15 #include <linux/clk.h>
19 #include <sound/soc-dapm.h>
45 struct clk *sysclk;
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()
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()
344 /* Input Channel Mapping */
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()
439 SND_SOC_DAPM_PGA("ADC Mute", R_CNVRTR0, FB_CNVRTR0_HPOR, true, NULL, 0),
440 SND_SOC_DAPM_ADC("ADC L", "HiFi Capture", R_PWRM1, FB_PWRM1_ADCL, 0),
441 SND_SOC_DAPM_ADC("ADC R", "HiFi Capture", R_PWRM1, FB_PWRM1_ADCR, 0),
498 {"ADC Mute", NULL, "Analog Boost L"},
499 {"ADC Mute", NULL, "Analog Boost R"},
500 {"ADC L", NULL, "PLL"},
501 {"ADC R", NULL, "PLL"},
502 {"ADC L", NULL, "ADC Mute"},
503 {"ADC R", NULL, "ADC Mute"},
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()
644 /* Input Channel Map */
645 SOC_ENUM("Input Channel Map", ch_map_select_enum),
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()
901 /* DAC and ADC share bit and frame clock */ 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 /* Slave 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()
1254 "Failed to set ADC BCLK ratio (%d)\n", ret); 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, &reg); in part_is_valid()
1285 ret = regmap_read(tscs42xx->regmap, R_DEVIDL, &reg); in part_is_valid()
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()
1337 dev_err(component->dev, in set_sysclk()
1373 u8 *coeff_ram = tscs42xx->coeff_ram; in init_coeff_ram_cache()
1377 coeff_ram[((norm_addrs[i] + 1) * COEFF_SIZE) - 1] = 0x40; in init_coeff_ram_cache()
1386 .name = "tscs42xx-HiFi",
1416 int src; in tscs42xx_i2c_probe() local
1419 tscs42xx = devm_kzalloc(&i2c->dev, sizeof(*tscs42xx), GFP_KERNEL); in tscs42xx_i2c_probe()
1421 ret = -ENOMEM; in tscs42xx_i2c_probe()
1422 dev_err(&i2c->dev, in tscs42xx_i2c_probe()
1428 for (src = TSCS42XX_PLL_SRC_XTAL; src < TSCS42XX_PLL_SRC_CNT; src++) { in tscs42xx_i2c_probe()
1429 tscs42xx->sysclk = devm_clk_get(&i2c->dev, src_names[src]); in tscs42xx_i2c_probe()
1430 if (!IS_ERR(tscs42xx->sysclk)) { in tscs42xx_i2c_probe()
1432 } else if (PTR_ERR(tscs42xx->sysclk) != -ENOENT) { in tscs42xx_i2c_probe()
1433 ret = PTR_ERR(tscs42xx->sysclk); in tscs42xx_i2c_probe()
1434 dev_err(&i2c->dev, "Failed to get sysclk (%d)\n", ret); in tscs42xx_i2c_probe()
1438 if (src == TSCS42XX_PLL_SRC_CNT) { in tscs42xx_i2c_probe()
1439 ret = -EINVAL; in tscs42xx_i2c_probe()
1440 dev_err(&i2c->dev, "Failed to get a valid clock name (%d)\n", in tscs42xx_i2c_probe()
1444 tscs42xx->sysclk_src_id = src; in tscs42xx_i2c_probe()
1446 tscs42xx->regmap = devm_regmap_init_i2c(i2c, &tscs42xx_regmap); in tscs42xx_i2c_probe()
1447 if (IS_ERR(tscs42xx->regmap)) { in tscs42xx_i2c_probe()
1448 ret = PTR_ERR(tscs42xx->regmap); in tscs42xx_i2c_probe()
1449 dev_err(&i2c->dev, "Failed to allocate regmap (%d)\n", ret); in tscs42xx_i2c_probe()
1457 dev_err(&i2c->dev, "No valid part (%d)\n", ret); in tscs42xx_i2c_probe()
1458 ret = -ENODEV; in tscs42xx_i2c_probe()
1462 ret = regmap_write(tscs42xx->regmap, R_RESET, RV_RESET_ENABLE); in tscs42xx_i2c_probe()
1464 dev_err(&i2c->dev, "Failed to reset device (%d)\n", ret); in tscs42xx_i2c_probe()
1468 ret = regmap_register_patch(tscs42xx->regmap, tscs42xx_patch, in tscs42xx_i2c_probe()
1471 dev_err(&i2c->dev, "Failed to apply patch (%d)\n", ret); in tscs42xx_i2c_probe()
1475 mutex_init(&tscs42xx->audio_params_lock); in tscs42xx_i2c_probe()
1476 mutex_init(&tscs42xx->coeff_ram_lock); in tscs42xx_i2c_probe()
1477 mutex_init(&tscs42xx->pll_lock); in tscs42xx_i2c_probe()
1479 ret = devm_snd_soc_register_component(&i2c->dev, in tscs42xx_i2c_probe()
1482 dev_err(&i2c->dev, "Failed to register codec (%d)\n", ret); in tscs42xx_i2c_probe()