Skip to content

Commit cfa43aa

Browse files
rfvirgilbroonie
authored andcommitted
ALSA: hda: cs35l56: Apply amp calibration from EFI data
If there are factory calibration settings in EFI, extract the settings and write them to the firmware calibration controls. Signed-off-by: Richard Fitzgerald <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 1326444 commit cfa43aa

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

sound/pci/hda/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ config SND_HDA_SCODEC_CS35L56_I2C
162162
select SND_HDA_SCODEC_CS35L56
163163
select SND_HDA_CIRRUS_SCODEC
164164
select SND_HDA_CS_DSP_CONTROLS
165+
select SND_SOC_CS_AMP_LIB
165166
help
166167
Say Y or M here to include CS35L56 amplifier support with
167168
I2C control.
@@ -177,6 +178,7 @@ config SND_HDA_SCODEC_CS35L56_SPI
177178
select SND_HDA_SCODEC_CS35L56
178179
select SND_HDA_CIRRUS_SCODEC
179180
select SND_HDA_CS_DSP_CONTROLS
181+
select SND_SOC_CS_AMP_LIB
180182
help
181183
Say Y or M here to include CS35L56 amplifier support with
182184
SPI control.

sound/pci/hda/cs35l56_hda.c

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <linux/regmap.h>
1515
#include <linux/slab.h>
1616
#include <sound/core.h>
17+
#include <sound/cs-amp-lib.h>
1718
#include <sound/hda_codec.h>
1819
#include <sound/tlv.h>
1920
#include "cirrus_scodec.h"
@@ -547,6 +548,22 @@ static void cs35l56_hda_add_dsp_controls(struct cs35l56_hda *cs35l56)
547548
hda_cs_dsp_add_controls(&cs35l56->cs_dsp, &info);
548549
}
549550

551+
static void cs35l56_hda_apply_calibration(struct cs35l56_hda *cs35l56)
552+
{
553+
int ret;
554+
555+
if (!cs35l56->base.cal_data_valid || cs35l56->base.secured)
556+
return;
557+
558+
ret = cs_amp_write_cal_coeffs(&cs35l56->cs_dsp,
559+
&cs35l56_calibration_controls,
560+
&cs35l56->base.cal_data);
561+
if (ret < 0)
562+
dev_warn(cs35l56->base.dev, "Failed to write calibration: %d\n", ret);
563+
else
564+
dev_info(cs35l56->base.dev, "Calibration applied\n");
565+
}
566+
550567
static int cs35l56_hda_fw_load(struct cs35l56_hda *cs35l56)
551568
{
552569
const struct firmware *coeff_firmware = NULL;
@@ -618,12 +635,8 @@ static int cs35l56_hda_fw_load(struct cs35l56_hda *cs35l56)
618635
if (coeff_filename)
619636
dev_dbg(cs35l56->base.dev, "Loaded Coefficients: %s\n", coeff_filename);
620637

621-
if (!firmware_missing) {
622-
ret = cs35l56_mbox_send(&cs35l56->base, CS35L56_MBOX_CMD_AUDIO_REINIT);
623-
if (ret)
624-
goto err_powered_up;
625-
} else if (wmfw_firmware || coeff_firmware) {
626-
/* If we downloaded firmware, reset the device and wait for it to boot */
638+
/* If we downloaded firmware, reset the device and wait for it to boot */
639+
if (firmware_missing && (wmfw_firmware || coeff_firmware)) {
627640
cs35l56_system_reset(&cs35l56->base, false);
628641
regcache_mark_dirty(cs35l56->base.regmap);
629642
ret = cs35l56_wait_for_firmware_boot(&cs35l56->base);
@@ -646,6 +659,11 @@ static int cs35l56_hda_fw_load(struct cs35l56_hda *cs35l56)
646659
if (ret)
647660
dev_dbg(cs35l56->base.dev, "%s: cs_dsp_run ret %d\n", __func__, ret);
648661

662+
cs35l56_hda_apply_calibration(cs35l56);
663+
ret = cs35l56_mbox_send(&cs35l56->base, CS35L56_MBOX_CMD_AUDIO_REINIT);
664+
if (ret)
665+
cs_dsp_stop(&cs35l56->cs_dsp);
666+
649667
err_powered_up:
650668
if (!cs35l56->base.fw_patched)
651669
cs_dsp_power_down(&cs35l56->cs_dsp);
@@ -953,6 +971,8 @@ int cs35l56_hda_common_probe(struct cs35l56_hda *cs35l56, int id)
953971
goto err;
954972
}
955973

974+
cs35l56->base.cal_index = cs35l56->index;
975+
956976
cs35l56_init_cs_dsp(&cs35l56->base, &cs35l56->cs_dsp);
957977
cs35l56->cs_dsp.client_ops = &cs35l56_hda_client_ops;
958978

@@ -990,6 +1010,10 @@ int cs35l56_hda_common_probe(struct cs35l56_hda *cs35l56, int id)
9901010
if (ret)
9911011
goto err;
9921012

1013+
ret = cs35l56_get_calibration(&cs35l56->base);
1014+
if (ret)
1015+
goto err;
1016+
9931017
ret = cs_dsp_halo_init(&cs35l56->cs_dsp);
9941018
if (ret) {
9951019
dev_err_probe(cs35l56->base.dev, ret, "cs_dsp_halo_init failed\n");
@@ -1064,10 +1088,11 @@ const struct dev_pm_ops cs35l56_hda_pm_ops = {
10641088
EXPORT_SYMBOL_NS_GPL(cs35l56_hda_pm_ops, SND_HDA_SCODEC_CS35L56);
10651089

10661090
MODULE_DESCRIPTION("CS35L56 HDA Driver");
1091+
MODULE_IMPORT_NS(FW_CS_DSP);
10671092
MODULE_IMPORT_NS(SND_HDA_CIRRUS_SCODEC);
10681093
MODULE_IMPORT_NS(SND_HDA_CS_DSP_CONTROLS);
10691094
MODULE_IMPORT_NS(SND_SOC_CS35L56_SHARED);
1095+
MODULE_IMPORT_NS(SND_SOC_CS_AMP_LIB);
10701096
MODULE_AUTHOR("Richard Fitzgerald <[email protected]>");
10711097
MODULE_AUTHOR("Simon Trimmer <[email protected]>");
10721098
MODULE_LICENSE("GPL");
1073-
MODULE_IMPORT_NS(FW_CS_DSP);

0 commit comments

Comments
 (0)