Lines Matching +full:power +full:- +full:supplies
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Codec driver for ST STA32x 2.1-channel high-efficiency digital audio system
34 #include <sound/soc-dapm.h>
54 /* Power-up register defaults */
128 /* regulator power supply names */
132 "Vcc" /* power amp spply, 10V - 36V */
139 struct regulator_bulk_data supplies[ARRAY_SIZE(sta32x_supply_names)]; member
153 static const DECLARE_TLV_DB_SCALE(mvol_tlv, -12700, 50, 1);
154 static const DECLARE_TLV_DB_SCALE(chvol_tlv, -7950, 50, 1);
155 static const DECLARE_TLV_DB_SCALE(tone_tlv, -120, 200, 0);
158 "Anti-Clipping", "Dynamic Range Compression" };
169 "Hard", "Party", "Vocal", "Hip-Hop", "Dialog", "Bass-boost #1",
170 "Bass-boost #2", "Bass-boost #3", "Loudness 1", "Loudness 2",
185 0, 7, TLV_DB_SCALE_ITEM(-1200, 200, 0),
191 1, 1, TLV_DB_SCALE_ITEM(-2900, 0, 0),
192 2, 2, TLV_DB_SCALE_ITEM(-2000, 0, 0),
193 3, 8, TLV_DB_SCALE_ITEM(-1400, 200, 0),
194 8, 16, TLV_DB_SCALE_ITEM(-700, 100, 0),
198 0, 7, TLV_DB_SCALE_ITEM(-3100, 200, 0),
199 8, 13, TLV_DB_SCALE_ITEM(-1600, 100, 0),
200 14, 16, TLV_DB_SCALE_ITEM(-1000, 300, 0),
205 1, 2, TLV_DB_SCALE_ITEM(-3800, 200, 0),
206 3, 4, TLV_DB_SCALE_ITEM(-3300, 200, 0),
207 5, 12, TLV_DB_SCALE_ITEM(-3000, 200, 0),
208 13, 16, TLV_DB_SCALE_ITEM(-1500, 300, 0),
258 int numcoef = kcontrol->private_value >> 16; in sta32x_coefficient_info()
259 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES; in sta32x_coefficient_info()
260 uinfo->count = 3 * numcoef; in sta32x_coefficient_info()
269 int numcoef = kcontrol->private_value >> 16; in sta32x_coefficient_get()
270 int index = kcontrol->private_value & 0xffff; in sta32x_coefficient_get()
274 mutex_lock(&sta32x->coeff_lock); in sta32x_coefficient_get()
277 regmap_read(sta32x->regmap, STA32X_CFUD, &cfud); in sta32x_coefficient_get()
283 regmap_write(sta32x->regmap, STA32X_CFUD, cfud); in sta32x_coefficient_get()
285 regmap_write(sta32x->regmap, STA32X_CFADDR2, index); in sta32x_coefficient_get()
287 regmap_write(sta32x->regmap, STA32X_CFUD, cfud | 0x04); in sta32x_coefficient_get()
289 regmap_write(sta32x->regmap, STA32X_CFUD, cfud | 0x08); in sta32x_coefficient_get()
291 ret = -EINVAL; in sta32x_coefficient_get()
296 regmap_read(sta32x->regmap, STA32X_B1CF1 + i, &val); in sta32x_coefficient_get()
297 ucontrol->value.bytes.data[i] = val; in sta32x_coefficient_get()
301 mutex_unlock(&sta32x->coeff_lock); in sta32x_coefficient_get()
311 int numcoef = kcontrol->private_value >> 16; in sta32x_coefficient_put()
312 int index = kcontrol->private_value & 0xffff; in sta32x_coefficient_put()
317 regmap_read(sta32x->regmap, STA32X_CFUD, &cfud); in sta32x_coefficient_put()
323 regmap_write(sta32x->regmap, STA32X_CFUD, cfud); in sta32x_coefficient_put()
325 regmap_write(sta32x->regmap, STA32X_CFADDR2, index); in sta32x_coefficient_put()
327 sta32x->coef_shadow[index + i] = in sta32x_coefficient_put()
328 (ucontrol->value.bytes.data[3 * i] << 16) in sta32x_coefficient_put()
329 | (ucontrol->value.bytes.data[3 * i + 1] << 8) in sta32x_coefficient_put()
330 | (ucontrol->value.bytes.data[3 * i + 2]); in sta32x_coefficient_put()
332 regmap_write(sta32x->regmap, STA32X_B1CF1 + i, in sta32x_coefficient_put()
333 ucontrol->value.bytes.data[i]); in sta32x_coefficient_put()
335 regmap_write(sta32x->regmap, STA32X_CFUD, cfud | 0x01); in sta32x_coefficient_put()
337 regmap_write(sta32x->regmap, STA32X_CFUD, cfud | 0x02); in sta32x_coefficient_put()
339 return -EINVAL; in sta32x_coefficient_put()
351 regmap_read(sta32x->regmap, STA32X_CFUD, &cfud); in sta32x_sync_coef_shadow()
355 regmap_write(sta32x->regmap, STA32X_CFADDR2, i); in sta32x_sync_coef_shadow()
356 regmap_write(sta32x->regmap, STA32X_B1CF1, in sta32x_sync_coef_shadow()
357 (sta32x->coef_shadow[i] >> 16) & 0xff); in sta32x_sync_coef_shadow()
358 regmap_write(sta32x->regmap, STA32X_B1CF2, in sta32x_sync_coef_shadow()
359 (sta32x->coef_shadow[i] >> 8) & 0xff); in sta32x_sync_coef_shadow()
360 regmap_write(sta32x->regmap, STA32X_B1CF3, in sta32x_sync_coef_shadow()
361 (sta32x->coef_shadow[i]) & 0xff); in sta32x_sync_coef_shadow()
364 * self-clearing, so do it explicitly in sta32x_sync_coef_shadow()
366 regmap_write(sta32x->regmap, STA32X_CFUD, cfud); in sta32x_sync_coef_shadow()
367 regmap_write(sta32x->regmap, STA32X_CFUD, cfud | 0x01); in sta32x_sync_coef_shadow()
379 regmap_read(sta32x->regmap, STA32X_MMUTE, &mute); in sta32x_cache_sync()
380 regmap_write(sta32x->regmap, STA32X_MMUTE, mute | STA32X_MMUTE_MMUTE); in sta32x_cache_sync()
382 rc = regcache_sync(sta32x->regmap); in sta32x_cache_sync()
383 regmap_write(sta32x->regmap, STA32X_MMUTE, mute); in sta32x_cache_sync()
392 struct snd_soc_component *component = sta32x->component; in sta32x_watchdog()
397 regcache_cache_bypass(sta32x->regmap, true); in sta32x_watchdog()
399 regcache_cache_bypass(sta32x->regmap, false); in sta32x_watchdog()
401 regcache_mark_dirty(sta32x->regmap); in sta32x_watchdog()
405 if (!sta32x->shutdown) in sta32x_watchdog()
407 &sta32x->watchdog_work, in sta32x_watchdog()
413 if (sta32x->pdata->needs_esd_watchdog) { in sta32x_watchdog_start()
414 sta32x->shutdown = 0; in sta32x_watchdog_start()
416 &sta32x->watchdog_work, in sta32x_watchdog_start()
423 if (sta32x->pdata->needs_esd_watchdog) { in sta32x_watchdog_stop()
424 sta32x->shutdown = 1; in sta32x_watchdog_stop()
425 cancel_delayed_work_sync(&sta32x->watchdog_work); in sta32x_watchdog_stop()
452 SOC_SINGLE("De-emphasis Filter Switch", STA32X_CONFD, STA32X_CONFD_DEMP_SHIFT, 1, 0),
457 SOC_SINGLE("Auto-Mute Switch", STA32X_CONFF, STA32X_CONFF_IDE_SHIFT, 1, 0),
499 BIQUAD_COEFS("Ch1 - Biquad 1", 0),
500 BIQUAD_COEFS("Ch1 - Biquad 2", 5),
501 BIQUAD_COEFS("Ch1 - Biquad 3", 10),
502 BIQUAD_COEFS("Ch1 - Biquad 4", 15),
503 BIQUAD_COEFS("Ch2 - Biquad 1", 20),
504 BIQUAD_COEFS("Ch2 - Biquad 2", 25),
505 BIQUAD_COEFS("Ch2 - Biquad 3", 30),
506 BIQUAD_COEFS("Ch2 - Biquad 4", 35),
507 BIQUAD_COEFS("High-pass", 40),
508 BIQUAD_COEFS("Low-pass", 45),
509 SINGLE_COEF("Ch1 - Prescale", 50),
510 SINGLE_COEF("Ch2 - Prescale", 51),
511 SINGLE_COEF("Ch1 - Postscale", 52),
512 SINGLE_COEF("Ch2 - Postscale", 53),
513 SINGLE_COEF("Ch3 - Postscale", 54),
514 SINGLE_COEF("Thermal warning - Postscale", 55),
515 SINGLE_COEF("Ch1 - Mix 1", 56),
516 SINGLE_COEF("Ch1 - Mix 2", 57),
517 SINGLE_COEF("Ch2 - Mix 1", 58),
518 SINGLE_COEF("Ch2 - Mix 2", 59),
519 SINGLE_COEF("Ch3 - Mix 1", 60),
520 SINGLE_COEF("Ch3 - Mix 2", 61),
558 * sta32x_set_dai_sysclk - configure MCLK
579 struct snd_soc_component *component = codec_dai->component; in sta32x_set_dai_sysclk()
582 dev_dbg(component->dev, "mclk=%u\n", freq); in sta32x_set_dai_sysclk()
583 sta32x->mclk = freq; in sta32x_set_dai_sysclk()
589 * sta32x_set_dai_fmt - configure the codec for the selected audio format
599 struct snd_soc_component *component = codec_dai->component; in sta32x_set_dai_fmt()
607 return -EINVAL; in sta32x_set_dai_fmt()
614 sta32x->format = fmt & SND_SOC_DAIFMT_FORMAT_MASK; in sta32x_set_dai_fmt()
617 return -EINVAL; in sta32x_set_dai_fmt()
628 return -EINVAL; in sta32x_set_dai_fmt()
631 return regmap_update_bits(sta32x->regmap, STA32X_CONFB, in sta32x_set_dai_fmt()
636 * sta32x_hw_params - program the STA32X with the given hardware parameters.
648 struct snd_soc_component *component = dai->component; in sta32x_hw_params()
650 int i, mcs = -EINVAL, ir = -EINVAL; in sta32x_hw_params()
655 if (!sta32x->mclk) { in sta32x_hw_params()
656 dev_err(component->dev, in sta32x_hw_params()
657 "sta32x->mclk is unset. Unable to determine ratio\n"); in sta32x_hw_params()
658 return -EIO; in sta32x_hw_params()
662 ratio = sta32x->mclk / rate; in sta32x_hw_params()
663 dev_dbg(component->dev, "rate: %u, ratio: %u\n", rate, ratio); in sta32x_hw_params()
673 dev_err(component->dev, "Unsupported samplerate: %u\n", rate); in sta32x_hw_params()
674 return -EINVAL; in sta32x_hw_params()
685 dev_err(component->dev, "Unresolvable ratio: %u\n", ratio); in sta32x_hw_params()
686 return -EINVAL; in sta32x_hw_params()
695 dev_dbg(component->dev, "24bit\n"); in sta32x_hw_params()
698 dev_dbg(component->dev, "24bit or 32bit\n"); in sta32x_hw_params()
699 switch (sta32x->format) { in sta32x_hw_params()
713 dev_dbg(component->dev, "20bit\n"); in sta32x_hw_params()
714 switch (sta32x->format) { in sta32x_hw_params()
728 dev_dbg(component->dev, "18bit\n"); in sta32x_hw_params()
729 switch (sta32x->format) { in sta32x_hw_params()
743 dev_dbg(component->dev, "16bit\n"); in sta32x_hw_params()
744 switch (sta32x->format) { in sta32x_hw_params()
758 return -EINVAL; in sta32x_hw_params()
761 ret = regmap_update_bits(sta32x->regmap, STA32X_CONFA, in sta32x_hw_params()
767 ret = regmap_update_bits(sta32x->regmap, STA32X_CONFB, in sta32x_hw_params()
778 if (sta32x->gpiod_nreset) { in sta32x_startup_sequence()
779 gpiod_set_value(sta32x->gpiod_nreset, 0); in sta32x_startup_sequence()
781 gpiod_set_value(sta32x->gpiod_nreset, 1); in sta32x_startup_sequence()
789 * sta32x_set_bias_level - DAPM callback
791 * @level: DAPM power level
793 * This is called by ALSA to put the component into low power mode
795 * all registers must be restored after power on.
803 dev_dbg(component->dev, "level = %d\n", level); in sta32x_set_bias_level()
809 /* Full power on */ in sta32x_set_bias_level()
810 regmap_update_bits(sta32x->regmap, STA32X_CONFF, in sta32x_set_bias_level()
817 ret = regulator_bulk_enable(ARRAY_SIZE(sta32x->supplies), in sta32x_set_bias_level()
818 sta32x->supplies); in sta32x_set_bias_level()
820 dev_err(component->dev, in sta32x_set_bias_level()
821 "Failed to enable supplies: %d\n", ret); in sta32x_set_bias_level()
830 /* Power down */ in sta32x_set_bias_level()
831 regmap_update_bits(sta32x->regmap, STA32X_CONFF, in sta32x_set_bias_level()
838 /* The chip runs through the power down sequence for us. */ in sta32x_set_bias_level()
839 regmap_update_bits(sta32x->regmap, STA32X_CONFF, in sta32x_set_bias_level()
844 gpiod_set_value(sta32x->gpiod_nreset, 0); in sta32x_set_bias_level()
846 regulator_bulk_disable(ARRAY_SIZE(sta32x->supplies), in sta32x_set_bias_level()
847 sta32x->supplies); in sta32x_set_bias_level()
860 .name = "sta32x-hifi",
874 struct sta32x_platform_data *pdata = sta32x->pdata; in sta32x_probe()
877 sta32x->component = component; in sta32x_probe()
879 if (sta32x->xti_clk) { in sta32x_probe()
880 ret = clk_prepare_enable(sta32x->xti_clk); in sta32x_probe()
882 dev_err(component->dev, in sta32x_probe()
888 ret = regulator_bulk_enable(ARRAY_SIZE(sta32x->supplies), in sta32x_probe()
889 sta32x->supplies); in sta32x_probe()
891 dev_err(component->dev, "Failed to enable supplies: %d\n", ret); in sta32x_probe()
897 dev_err(component->dev, "Failed to startup device\n"); in sta32x_probe()
902 if (!pdata->thermal_warning_recovery) in sta32x_probe()
904 if (!pdata->thermal_warning_adjustment) in sta32x_probe()
906 if (!pdata->fault_detect_recovery) in sta32x_probe()
908 regmap_update_bits(sta32x->regmap, STA32X_CONFA, in sta32x_probe()
914 regmap_update_bits(sta32x->regmap, STA32X_CONFC, in sta32x_probe()
916 pdata->drop_compensation_ns in sta32x_probe()
920 regmap_update_bits(sta32x->regmap, STA32X_CONFE, in sta32x_probe()
922 pdata->max_power_use_mpcc ? in sta32x_probe()
924 regmap_update_bits(sta32x->regmap, STA32X_CONFE, in sta32x_probe()
926 pdata->max_power_correction ? in sta32x_probe()
928 regmap_update_bits(sta32x->regmap, STA32X_CONFE, in sta32x_probe()
930 pdata->am_reduction_mode ? in sta32x_probe()
932 regmap_update_bits(sta32x->regmap, STA32X_CONFE, in sta32x_probe()
934 pdata->odd_pwm_speed_mode ? in sta32x_probe()
938 regmap_update_bits(sta32x->regmap, STA32X_CONFF, in sta32x_probe()
940 pdata->invalid_input_detect_mute ? in sta32x_probe()
944 regmap_update_bits(sta32x->regmap, STA32X_CONFF, in sta32x_probe()
946 pdata->output_conf in sta32x_probe()
950 regmap_update_bits(sta32x->regmap, STA32X_C1CFG, in sta32x_probe()
952 pdata->ch1_output_mapping in sta32x_probe()
954 regmap_update_bits(sta32x->regmap, STA32X_C2CFG, in sta32x_probe()
956 pdata->ch2_output_mapping in sta32x_probe()
958 regmap_update_bits(sta32x->regmap, STA32X_C3CFG, in sta32x_probe()
960 pdata->ch3_output_mapping in sta32x_probe()
965 sta32x->coef_shadow[i] = 0x400000; in sta32x_probe()
967 sta32x->coef_shadow[i] = 0x7fffff; in sta32x_probe()
968 sta32x->coef_shadow[55] = 0x5a9df7; in sta32x_probe()
969 sta32x->coef_shadow[56] = 0x7fffff; in sta32x_probe()
970 sta32x->coef_shadow[59] = 0x7fffff; in sta32x_probe()
971 sta32x->coef_shadow[60] = 0x400000; in sta32x_probe()
972 sta32x->coef_shadow[61] = 0x400000; in sta32x_probe()
974 if (sta32x->pdata->needs_esd_watchdog) in sta32x_probe()
975 INIT_DELAYED_WORK(&sta32x->watchdog_work, sta32x_watchdog); in sta32x_probe()
979 regulator_bulk_disable(ARRAY_SIZE(sta32x->supplies), sta32x->supplies); in sta32x_probe()
984 regulator_bulk_disable(ARRAY_SIZE(sta32x->supplies), sta32x->supplies); in sta32x_probe()
986 if (sta32x->xti_clk) in sta32x_probe()
987 clk_disable_unprepare(sta32x->xti_clk); in sta32x_probe()
996 regulator_bulk_disable(ARRAY_SIZE(sta32x->supplies), sta32x->supplies); in sta32x_remove()
998 if (sta32x->xti_clk) in sta32x_remove()
999 clk_disable_unprepare(sta32x->xti_clk); in sta32x_remove()
1039 struct device_node *np = dev->of_node; in sta32x_probe_dt()
1045 return -ENOMEM; in sta32x_probe_dt()
1047 of_property_read_u8(np, "st,output-conf", in sta32x_probe_dt()
1048 &pdata->output_conf); in sta32x_probe_dt()
1049 of_property_read_u8(np, "st,ch1-output-mapping", in sta32x_probe_dt()
1050 &pdata->ch1_output_mapping); in sta32x_probe_dt()
1051 of_property_read_u8(np, "st,ch2-output-mapping", in sta32x_probe_dt()
1052 &pdata->ch2_output_mapping); in sta32x_probe_dt()
1053 of_property_read_u8(np, "st,ch3-output-mapping", in sta32x_probe_dt()
1054 &pdata->ch3_output_mapping); in sta32x_probe_dt()
1056 pdata->fault_detect_recovery = in sta32x_probe_dt()
1057 of_property_read_bool(np, "st,fault-detect-recovery"); in sta32x_probe_dt()
1058 pdata->thermal_warning_recovery = in sta32x_probe_dt()
1059 of_property_read_bool(np, "st,thermal-warning-recovery"); in sta32x_probe_dt()
1060 pdata->thermal_warning_adjustment = in sta32x_probe_dt()
1061 of_property_read_bool(np, "st,thermal-warning-adjustment"); in sta32x_probe_dt()
1062 pdata->needs_esd_watchdog = in sta32x_probe_dt()
1066 of_property_read_u16(np, "st,drop-compensation-ns", &tmp); in sta32x_probe_dt()
1067 pdata->drop_compensation_ns = clamp_t(u16, tmp, 0, 300) / 20; in sta32x_probe_dt()
1070 pdata->max_power_use_mpcc = in sta32x_probe_dt()
1071 of_property_read_bool(np, "st,max-power-use-mpcc"); in sta32x_probe_dt()
1072 pdata->max_power_correction = in sta32x_probe_dt()
1073 of_property_read_bool(np, "st,max-power-correction"); in sta32x_probe_dt()
1074 pdata->am_reduction_mode = in sta32x_probe_dt()
1075 of_property_read_bool(np, "st,am-reduction-mode"); in sta32x_probe_dt()
1076 pdata->odd_pwm_speed_mode = in sta32x_probe_dt()
1077 of_property_read_bool(np, "st,odd-pwm-speed-mode"); in sta32x_probe_dt()
1080 pdata->invalid_input_detect_mute = in sta32x_probe_dt()
1081 of_property_read_bool(np, "st,invalid-input-detect-mute"); in sta32x_probe_dt()
1083 sta32x->pdata = pdata; in sta32x_probe_dt()
1091 struct device *dev = &i2c->dev; in sta32x_i2c_probe()
1095 sta32x = devm_kzalloc(&i2c->dev, sizeof(struct sta32x_priv), in sta32x_i2c_probe()
1098 return -ENOMEM; in sta32x_i2c_probe()
1100 mutex_init(&sta32x->coeff_lock); in sta32x_i2c_probe()
1101 sta32x->pdata = dev_get_platdata(dev); in sta32x_i2c_probe()
1104 if (dev->of_node) { in sta32x_i2c_probe()
1112 sta32x->xti_clk = devm_clk_get(dev, "xti"); in sta32x_i2c_probe()
1113 if (IS_ERR(sta32x->xti_clk)) { in sta32x_i2c_probe()
1114 ret = PTR_ERR(sta32x->xti_clk); in sta32x_i2c_probe()
1116 if (ret == -EPROBE_DEFER) in sta32x_i2c_probe()
1119 sta32x->xti_clk = NULL; in sta32x_i2c_probe()
1123 sta32x->gpiod_nreset = devm_gpiod_get_optional(dev, "reset", in sta32x_i2c_probe()
1125 if (IS_ERR(sta32x->gpiod_nreset)) in sta32x_i2c_probe()
1126 return PTR_ERR(sta32x->gpiod_nreset); in sta32x_i2c_probe()
1129 for (i = 0; i < ARRAY_SIZE(sta32x->supplies); i++) in sta32x_i2c_probe()
1130 sta32x->supplies[i].supply = sta32x_supply_names[i]; in sta32x_i2c_probe()
1132 ret = devm_regulator_bulk_get(&i2c->dev, ARRAY_SIZE(sta32x->supplies), in sta32x_i2c_probe()
1133 sta32x->supplies); in sta32x_i2c_probe()
1135 dev_err(&i2c->dev, "Failed to request supplies: %d\n", ret); in sta32x_i2c_probe()
1139 sta32x->regmap = devm_regmap_init_i2c(i2c, &sta32x_regmap); in sta32x_i2c_probe()
1140 if (IS_ERR(sta32x->regmap)) { in sta32x_i2c_probe()
1141 ret = PTR_ERR(sta32x->regmap); in sta32x_i2c_probe()