Lines Matching +full:3 +full:- +full:ch1 +full:- +full:supply

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Codec driver for ST STA32x 2.1-channel high-efficiency digital audio system
35 #include <sound/soc-dapm.h>
55 /* Power-up register defaults */
129 /* regulator power supply names */
131 "Vdda", /* analog supply, 3.3VV */
132 "Vdd3", /* digital supply, 3.3V */
133 "Vcc" /* power amp spply, 10V - 36V */
154 static const DECLARE_TLV_DB_SCALE(mvol_tlv, -12700, 50, 1);
155 static const DECLARE_TLV_DB_SCALE(chvol_tlv, -7950, 50, 1);
156 static const DECLARE_TLV_DB_SCALE(tone_tlv, -120, 200, 0);
159 "Anti-Clipping", "Dynamic Range Compression" };
170 "Hard", "Party", "Vocal", "Hip-Hop", "Dialog", "Bass-boost #1",
171 "Bass-boost #2", "Bass-boost #3", "Loudness 1", "Loudness 2",
172 "Loudness 3", "Loudness 4", "Loudness 5", "Loudness 6", "Loudness 7",
186 0, 7, TLV_DB_SCALE_ITEM(-1200, 200, 0),
192 1, 1, TLV_DB_SCALE_ITEM(-2900, 0, 0),
193 2, 2, TLV_DB_SCALE_ITEM(-2000, 0, 0),
194 3, 8, TLV_DB_SCALE_ITEM(-1400, 200, 0),
195 8, 16, TLV_DB_SCALE_ITEM(-700, 100, 0),
199 0, 7, TLV_DB_SCALE_ITEM(-3100, 200, 0),
200 8, 13, TLV_DB_SCALE_ITEM(-1600, 100, 0),
201 14, 16, TLV_DB_SCALE_ITEM(-1000, 300, 0),
206 1, 2, TLV_DB_SCALE_ITEM(-3800, 200, 0),
207 3, 4, TLV_DB_SCALE_ITEM(-3300, 200, 0),
208 5, 12, TLV_DB_SCALE_ITEM(-3000, 200, 0),
209 13, 16, TLV_DB_SCALE_ITEM(-1500, 300, 0),
259 int numcoef = kcontrol->private_value >> 16; in sta32x_coefficient_info()
260 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES; in sta32x_coefficient_info()
261 uinfo->count = 3 * numcoef; in sta32x_coefficient_info()
270 int numcoef = kcontrol->private_value >> 16; in sta32x_coefficient_get()
271 int index = kcontrol->private_value & 0xffff; in sta32x_coefficient_get()
275 mutex_lock(&sta32x->coeff_lock); in sta32x_coefficient_get()
278 regmap_read(sta32x->regmap, STA32X_CFUD, &cfud); in sta32x_coefficient_get()
284 regmap_write(sta32x->regmap, STA32X_CFUD, cfud); in sta32x_coefficient_get()
286 regmap_write(sta32x->regmap, STA32X_CFADDR2, index); in sta32x_coefficient_get()
288 regmap_write(sta32x->regmap, STA32X_CFUD, cfud | 0x04); in sta32x_coefficient_get()
290 regmap_write(sta32x->regmap, STA32X_CFUD, cfud | 0x08); in sta32x_coefficient_get()
292 ret = -EINVAL; in sta32x_coefficient_get()
296 for (i = 0; i < 3 * numcoef; i++) { in sta32x_coefficient_get()
297 regmap_read(sta32x->regmap, STA32X_B1CF1 + i, &val); in sta32x_coefficient_get()
298 ucontrol->value.bytes.data[i] = val; in sta32x_coefficient_get()
302 mutex_unlock(&sta32x->coeff_lock); in sta32x_coefficient_get()
312 int numcoef = kcontrol->private_value >> 16; in sta32x_coefficient_put()
313 int index = kcontrol->private_value & 0xffff; in sta32x_coefficient_put()
318 regmap_read(sta32x->regmap, STA32X_CFUD, &cfud); in sta32x_coefficient_put()
324 regmap_write(sta32x->regmap, STA32X_CFUD, cfud); in sta32x_coefficient_put()
326 regmap_write(sta32x->regmap, STA32X_CFADDR2, index); in sta32x_coefficient_put()
328 sta32x->coef_shadow[index + i] = in sta32x_coefficient_put()
329 (ucontrol->value.bytes.data[3 * i] << 16) in sta32x_coefficient_put()
330 | (ucontrol->value.bytes.data[3 * i + 1] << 8) in sta32x_coefficient_put()
331 | (ucontrol->value.bytes.data[3 * i + 2]); in sta32x_coefficient_put()
332 for (i = 0; i < 3 * numcoef; i++) in sta32x_coefficient_put()
333 regmap_write(sta32x->regmap, STA32X_B1CF1 + i, in sta32x_coefficient_put()
334 ucontrol->value.bytes.data[i]); in sta32x_coefficient_put()
336 regmap_write(sta32x->regmap, STA32X_CFUD, cfud | 0x01); in sta32x_coefficient_put()
338 regmap_write(sta32x->regmap, STA32X_CFUD, cfud | 0x02); in sta32x_coefficient_put()
340 return -EINVAL; in sta32x_coefficient_put()
352 regmap_read(sta32x->regmap, STA32X_CFUD, &cfud); in sta32x_sync_coef_shadow()
356 regmap_write(sta32x->regmap, STA32X_CFADDR2, i); in sta32x_sync_coef_shadow()
357 regmap_write(sta32x->regmap, STA32X_B1CF1, in sta32x_sync_coef_shadow()
358 (sta32x->coef_shadow[i] >> 16) & 0xff); in sta32x_sync_coef_shadow()
359 regmap_write(sta32x->regmap, STA32X_B1CF2, in sta32x_sync_coef_shadow()
360 (sta32x->coef_shadow[i] >> 8) & 0xff); in sta32x_sync_coef_shadow()
361 regmap_write(sta32x->regmap, STA32X_B1CF3, in sta32x_sync_coef_shadow()
362 (sta32x->coef_shadow[i]) & 0xff); in sta32x_sync_coef_shadow()
365 * self-clearing, so do it explicitly in sta32x_sync_coef_shadow()
367 regmap_write(sta32x->regmap, STA32X_CFUD, cfud); in sta32x_sync_coef_shadow()
368 regmap_write(sta32x->regmap, STA32X_CFUD, cfud | 0x01); in sta32x_sync_coef_shadow()
380 regmap_read(sta32x->regmap, STA32X_MMUTE, &mute); in sta32x_cache_sync()
381 regmap_write(sta32x->regmap, STA32X_MMUTE, mute | STA32X_MMUTE_MMUTE); in sta32x_cache_sync()
383 rc = regcache_sync(sta32x->regmap); in sta32x_cache_sync()
384 regmap_write(sta32x->regmap, STA32X_MMUTE, mute); in sta32x_cache_sync()
393 struct snd_soc_component *component = sta32x->component; in sta32x_watchdog()
398 regcache_cache_bypass(sta32x->regmap, true); in sta32x_watchdog()
400 regcache_cache_bypass(sta32x->regmap, false); in sta32x_watchdog()
402 regcache_mark_dirty(sta32x->regmap); in sta32x_watchdog()
406 if (!sta32x->shutdown) in sta32x_watchdog()
408 &sta32x->watchdog_work, in sta32x_watchdog()
414 if (sta32x->pdata->needs_esd_watchdog) { in sta32x_watchdog_start()
415 sta32x->shutdown = 0; in sta32x_watchdog_start()
417 &sta32x->watchdog_work, in sta32x_watchdog_start()
424 if (sta32x->pdata->needs_esd_watchdog) { in sta32x_watchdog_stop()
425 sta32x->shutdown = 1; in sta32x_watchdog_stop()
426 cancel_delayed_work_sync(&sta32x->watchdog_work); in sta32x_watchdog_stop()
447 SOC_SINGLE("Ch1 Switch", STA32X_MMUTE, 1, 1, 1),
449 SOC_SINGLE("Ch3 Switch", STA32X_MMUTE, 3, 1, 1),
450 SOC_SINGLE_TLV("Ch1 Volume", STA32X_C1VOL, 0, 0xff, 1, chvol_tlv),
453 SOC_SINGLE("De-emphasis Filter Switch", STA32X_CONFD, STA32X_CONFD_DEMP_SHIFT, 1, 0),
458 SOC_SINGLE("Auto-Mute Switch", STA32X_CONFF, STA32X_CONFF_IDE_SHIFT, 1, 0),
463 SOC_SINGLE("Ch1 Tone Control Bypass Switch", STA32X_C1CFG, STA32X_CxCFG_TCB_SHIFT, 1, 0),
465 SOC_SINGLE("Ch1 EQ Bypass Switch", STA32X_C1CFG, STA32X_CxCFG_EQBP_SHIFT, 1, 0),
467 SOC_SINGLE("Ch1 Master Volume Bypass Switch", STA32X_C1CFG, STA32X_CxCFG_VBP_SHIFT, 1, 0),
470 SOC_ENUM("Ch1 Limiter Select", sta32x_limiter_ch1_enum),
500 BIQUAD_COEFS("Ch1 - Biquad 1", 0),
501 BIQUAD_COEFS("Ch1 - Biquad 2", 5),
502 BIQUAD_COEFS("Ch1 - Biquad 3", 10),
503 BIQUAD_COEFS("Ch1 - Biquad 4", 15),
504 BIQUAD_COEFS("Ch2 - Biquad 1", 20),
505 BIQUAD_COEFS("Ch2 - Biquad 2", 25),
506 BIQUAD_COEFS("Ch2 - Biquad 3", 30),
507 BIQUAD_COEFS("Ch2 - Biquad 4", 35),
508 BIQUAD_COEFS("High-pass", 40),
509 BIQUAD_COEFS("Low-pass", 45),
510 SINGLE_COEF("Ch1 - Prescale", 50),
511 SINGLE_COEF("Ch2 - Prescale", 51),
512 SINGLE_COEF("Ch1 - Postscale", 52),
513 SINGLE_COEF("Ch2 - Postscale", 53),
514 SINGLE_COEF("Ch3 - Postscale", 54),
515 SINGLE_COEF("Thermal warning - Postscale", 55),
516 SINGLE_COEF("Ch1 - Mix 1", 56),
517 SINGLE_COEF("Ch1 - Mix 2", 57),
518 SINGLE_COEF("Ch2 - Mix 1", 58),
519 SINGLE_COEF("Ch2 - Mix 2", 59),
520 SINGLE_COEF("Ch3 - Mix 1", 60),
521 SINGLE_COEF("Ch3 - Mix 2", 61),
552 static int mcs_ratio_table[3][7] = {
559 * sta32x_set_dai_sysclk - configure MCLK
580 struct snd_soc_component *component = codec_dai->component; in sta32x_set_dai_sysclk()
583 dev_dbg(component->dev, "mclk=%u\n", freq); in sta32x_set_dai_sysclk()
584 sta32x->mclk = freq; in sta32x_set_dai_sysclk()
590 * sta32x_set_dai_fmt - configure the codec for the selected audio format
600 struct snd_soc_component *component = codec_dai->component; in sta32x_set_dai_fmt()
608 return -EINVAL; in sta32x_set_dai_fmt()
615 sta32x->format = fmt & SND_SOC_DAIFMT_FORMAT_MASK; in sta32x_set_dai_fmt()
618 return -EINVAL; in sta32x_set_dai_fmt()
629 return -EINVAL; in sta32x_set_dai_fmt()
632 return regmap_update_bits(sta32x->regmap, STA32X_CONFB, in sta32x_set_dai_fmt()
637 * sta32x_hw_params - program the STA32X with the given hardware parameters.
649 struct snd_soc_component *component = dai->component; in sta32x_hw_params()
651 int i, mcs = -EINVAL, ir = -EINVAL; in sta32x_hw_params()
656 if (!sta32x->mclk) { in sta32x_hw_params()
657 dev_err(component->dev, in sta32x_hw_params()
658 "sta32x->mclk is unset. Unable to determine ratio\n"); in sta32x_hw_params()
659 return -EIO; in sta32x_hw_params()
663 ratio = sta32x->mclk / rate; in sta32x_hw_params()
664 dev_dbg(component->dev, "rate: %u, ratio: %u\n", rate, ratio); in sta32x_hw_params()
674 dev_err(component->dev, "Unsupported samplerate: %u\n", rate); in sta32x_hw_params()
675 return -EINVAL; in sta32x_hw_params()
686 dev_err(component->dev, "Unresolvable ratio: %u\n", ratio); in sta32x_hw_params()
687 return -EINVAL; in sta32x_hw_params()
696 dev_dbg(component->dev, "24bit\n"); in sta32x_hw_params()
699 dev_dbg(component->dev, "24bit or 32bit\n"); in sta32x_hw_params()
700 switch (sta32x->format) { in sta32x_hw_params()
714 dev_dbg(component->dev, "20bit\n"); in sta32x_hw_params()
715 switch (sta32x->format) { in sta32x_hw_params()
729 dev_dbg(component->dev, "18bit\n"); in sta32x_hw_params()
730 switch (sta32x->format) { in sta32x_hw_params()
744 dev_dbg(component->dev, "16bit\n"); in sta32x_hw_params()
745 switch (sta32x->format) { in sta32x_hw_params()
759 return -EINVAL; in sta32x_hw_params()
762 ret = regmap_update_bits(sta32x->regmap, STA32X_CONFA, in sta32x_hw_params()
768 ret = regmap_update_bits(sta32x->regmap, STA32X_CONFB, in sta32x_hw_params()
779 if (sta32x->gpiod_nreset) { in sta32x_startup_sequence()
780 gpiod_set_value(sta32x->gpiod_nreset, 0); in sta32x_startup_sequence()
782 gpiod_set_value(sta32x->gpiod_nreset, 1); in sta32x_startup_sequence()
790 * sta32x_set_bias_level - DAPM callback
804 dev_dbg(component->dev, "level = %d\n", level); in sta32x_set_bias_level()
811 regmap_update_bits(sta32x->regmap, STA32X_CONFF, in sta32x_set_bias_level()
818 ret = regulator_bulk_enable(ARRAY_SIZE(sta32x->supplies), in sta32x_set_bias_level()
819 sta32x->supplies); in sta32x_set_bias_level()
821 dev_err(component->dev, in sta32x_set_bias_level()
832 regmap_update_bits(sta32x->regmap, STA32X_CONFF, in sta32x_set_bias_level()
840 regmap_update_bits(sta32x->regmap, STA32X_CONFF, in sta32x_set_bias_level()
845 gpiod_set_value(sta32x->gpiod_nreset, 0); in sta32x_set_bias_level()
847 regulator_bulk_disable(ARRAY_SIZE(sta32x->supplies), in sta32x_set_bias_level()
848 sta32x->supplies); in sta32x_set_bias_level()
861 .name = "sta32x-hifi",
875 struct sta32x_platform_data *pdata = sta32x->pdata; in sta32x_probe()
878 sta32x->component = component; in sta32x_probe()
880 if (sta32x->xti_clk) { in sta32x_probe()
881 ret = clk_prepare_enable(sta32x->xti_clk); in sta32x_probe()
883 dev_err(component->dev, in sta32x_probe()
889 ret = regulator_bulk_enable(ARRAY_SIZE(sta32x->supplies), in sta32x_probe()
890 sta32x->supplies); in sta32x_probe()
892 dev_err(component->dev, "Failed to enable supplies: %d\n", ret); in sta32x_probe()
898 dev_err(component->dev, "Failed to startup device\n"); in sta32x_probe()
903 if (!pdata->thermal_warning_recovery) in sta32x_probe()
905 if (!pdata->thermal_warning_adjustment) in sta32x_probe()
907 if (!pdata->fault_detect_recovery) in sta32x_probe()
909 regmap_update_bits(sta32x->regmap, STA32X_CONFA, in sta32x_probe()
915 regmap_update_bits(sta32x->regmap, STA32X_CONFC, in sta32x_probe()
917 pdata->drop_compensation_ns in sta32x_probe()
921 regmap_update_bits(sta32x->regmap, STA32X_CONFE, in sta32x_probe()
923 pdata->max_power_use_mpcc ? in sta32x_probe()
925 regmap_update_bits(sta32x->regmap, STA32X_CONFE, in sta32x_probe()
927 pdata->max_power_correction ? in sta32x_probe()
929 regmap_update_bits(sta32x->regmap, STA32X_CONFE, in sta32x_probe()
931 pdata->am_reduction_mode ? in sta32x_probe()
933 regmap_update_bits(sta32x->regmap, STA32X_CONFE, in sta32x_probe()
935 pdata->odd_pwm_speed_mode ? in sta32x_probe()
939 regmap_update_bits(sta32x->regmap, STA32X_CONFF, in sta32x_probe()
941 pdata->invalid_input_detect_mute ? in sta32x_probe()
945 regmap_update_bits(sta32x->regmap, STA32X_CONFF, in sta32x_probe()
947 pdata->output_conf in sta32x_probe()
951 regmap_update_bits(sta32x->regmap, STA32X_C1CFG, in sta32x_probe()
953 pdata->ch1_output_mapping in sta32x_probe()
955 regmap_update_bits(sta32x->regmap, STA32X_C2CFG, in sta32x_probe()
957 pdata->ch2_output_mapping in sta32x_probe()
959 regmap_update_bits(sta32x->regmap, STA32X_C3CFG, in sta32x_probe()
961 pdata->ch3_output_mapping in sta32x_probe()
966 sta32x->coef_shadow[i] = 0x400000; in sta32x_probe()
968 sta32x->coef_shadow[i] = 0x7fffff; in sta32x_probe()
969 sta32x->coef_shadow[55] = 0x5a9df7; in sta32x_probe()
970 sta32x->coef_shadow[56] = 0x7fffff; in sta32x_probe()
971 sta32x->coef_shadow[59] = 0x7fffff; in sta32x_probe()
972 sta32x->coef_shadow[60] = 0x400000; in sta32x_probe()
973 sta32x->coef_shadow[61] = 0x400000; in sta32x_probe()
975 if (sta32x->pdata->needs_esd_watchdog) in sta32x_probe()
976 INIT_DELAYED_WORK(&sta32x->watchdog_work, sta32x_watchdog); in sta32x_probe()
980 regulator_bulk_disable(ARRAY_SIZE(sta32x->supplies), sta32x->supplies); in sta32x_probe()
985 regulator_bulk_disable(ARRAY_SIZE(sta32x->supplies), sta32x->supplies); in sta32x_probe()
987 if (sta32x->xti_clk) in sta32x_probe()
988 clk_disable_unprepare(sta32x->xti_clk); in sta32x_probe()
997 regulator_bulk_disable(ARRAY_SIZE(sta32x->supplies), sta32x->supplies); in sta32x_remove()
999 if (sta32x->xti_clk) in sta32x_remove()
1000 clk_disable_unprepare(sta32x->xti_clk); in sta32x_remove()
1040 struct device_node *np = dev->of_node; in sta32x_probe_dt()
1046 return -ENOMEM; in sta32x_probe_dt()
1048 of_property_read_u8(np, "st,output-conf", in sta32x_probe_dt()
1049 &pdata->output_conf); in sta32x_probe_dt()
1050 of_property_read_u8(np, "st,ch1-output-mapping", in sta32x_probe_dt()
1051 &pdata->ch1_output_mapping); in sta32x_probe_dt()
1052 of_property_read_u8(np, "st,ch2-output-mapping", in sta32x_probe_dt()
1053 &pdata->ch2_output_mapping); in sta32x_probe_dt()
1054 of_property_read_u8(np, "st,ch3-output-mapping", in sta32x_probe_dt()
1055 &pdata->ch3_output_mapping); in sta32x_probe_dt()
1057 pdata->fault_detect_recovery = in sta32x_probe_dt()
1058 of_property_read_bool(np, "st,fault-detect-recovery"); in sta32x_probe_dt()
1059 pdata->thermal_warning_recovery = in sta32x_probe_dt()
1060 of_property_read_bool(np, "st,thermal-warning-recovery"); in sta32x_probe_dt()
1061 pdata->thermal_warning_adjustment = in sta32x_probe_dt()
1062 of_property_read_bool(np, "st,thermal-warning-adjustment"); in sta32x_probe_dt()
1063 pdata->needs_esd_watchdog = in sta32x_probe_dt()
1067 of_property_read_u16(np, "st,drop-compensation-ns", &tmp); in sta32x_probe_dt()
1068 pdata->drop_compensation_ns = clamp_t(u16, tmp, 0, 300) / 20; in sta32x_probe_dt()
1071 pdata->max_power_use_mpcc = in sta32x_probe_dt()
1072 of_property_read_bool(np, "st,max-power-use-mpcc"); in sta32x_probe_dt()
1073 pdata->max_power_correction = in sta32x_probe_dt()
1074 of_property_read_bool(np, "st,max-power-correction"); in sta32x_probe_dt()
1075 pdata->am_reduction_mode = in sta32x_probe_dt()
1076 of_property_read_bool(np, "st,am-reduction-mode"); in sta32x_probe_dt()
1077 pdata->odd_pwm_speed_mode = in sta32x_probe_dt()
1078 of_property_read_bool(np, "st,odd-pwm-speed-mode"); in sta32x_probe_dt()
1081 pdata->invalid_input_detect_mute = in sta32x_probe_dt()
1082 of_property_read_bool(np, "st,invalid-input-detect-mute"); in sta32x_probe_dt()
1084 sta32x->pdata = pdata; in sta32x_probe_dt()
1092 struct device *dev = &i2c->dev; in sta32x_i2c_probe()
1096 sta32x = devm_kzalloc(&i2c->dev, sizeof(struct sta32x_priv), in sta32x_i2c_probe()
1099 return -ENOMEM; in sta32x_i2c_probe()
1101 mutex_init(&sta32x->coeff_lock); in sta32x_i2c_probe()
1102 sta32x->pdata = dev_get_platdata(dev); in sta32x_i2c_probe()
1105 if (dev->of_node) { in sta32x_i2c_probe()
1113 sta32x->xti_clk = devm_clk_get(dev, "xti"); in sta32x_i2c_probe()
1114 if (IS_ERR(sta32x->xti_clk)) { in sta32x_i2c_probe()
1115 ret = PTR_ERR(sta32x->xti_clk); in sta32x_i2c_probe()
1117 if (ret == -EPROBE_DEFER) in sta32x_i2c_probe()
1120 sta32x->xti_clk = NULL; in sta32x_i2c_probe()
1124 sta32x->gpiod_nreset = devm_gpiod_get_optional(dev, "reset", in sta32x_i2c_probe()
1126 if (IS_ERR(sta32x->gpiod_nreset)) in sta32x_i2c_probe()
1127 return PTR_ERR(sta32x->gpiod_nreset); in sta32x_i2c_probe()
1130 for (i = 0; i < ARRAY_SIZE(sta32x->supplies); i++) in sta32x_i2c_probe()
1131 sta32x->supplies[i].supply = sta32x_supply_names[i]; in sta32x_i2c_probe()
1133 ret = devm_regulator_bulk_get(&i2c->dev, ARRAY_SIZE(sta32x->supplies), in sta32x_i2c_probe()
1134 sta32x->supplies); in sta32x_i2c_probe()
1136 dev_err(&i2c->dev, "Failed to request supplies: %d\n", ret); in sta32x_i2c_probe()
1140 sta32x->regmap = devm_regmap_init_i2c(i2c, &sta32x_regmap); in sta32x_i2c_probe()
1141 if (IS_ERR(sta32x->regmap)) { in sta32x_i2c_probe()
1142 ret = PTR_ERR(sta32x->regmap); in sta32x_i2c_probe()