[PATCH v1 6/7] ALSA: hda/cs35l41: Store filenames of successfully loaded firmware and tunings
From: Stefan Binding
Date: Fri Nov 20 2026 - 11:12:30 EST
When the CS35L41 HDA driver loads firmware, it typically loops through
possible filenames, requesting each and stopping when it finds a valid
file.
Since firmware is sometimes reloaded - such as during system resume,
it loops through the possible filenames each time. However, since the
filename will never change, we can store the filename when we
successfully load the firmware for the first time, and reuse it later.
This ensures that the only firmware files requested by the driver in
system resume are the same as the ones cached during suspend, since
only successfully requested firmware files are cached. This prevents
unnecessary file access during resume - if a cached firmware is
requested, the cached file is used, eliminating any potential blocking
calls to the filesystem.
Signed-off-by: Stefan Binding <sbinding@xxxxxxxxxxxxxxxxxxxxx>
---
sound/hda/codecs/side-codecs/cs35l41_hda.c | 47 +++++++++++++++++-----
sound/hda/codecs/side-codecs/cs35l41_hda.h | 3 ++
2 files changed, 40 insertions(+), 10 deletions(-)
diff --git a/sound/hda/codecs/side-codecs/cs35l41_hda.c b/sound/hda/codecs/side-codecs/cs35l41_hda.c
index a0e2e0c5addf..6f4b2088c5fe 100644
--- a/sound/hda/codecs/side-codecs/cs35l41_hda.c
+++ b/sound/hda/codecs/side-codecs/cs35l41_hda.c
@@ -142,6 +142,7 @@ static int cs35l41_request_tuning_param_file(struct cs35l41_hda *cs35l41, char *
dev_dbg(cs35l41->dev, "Failed to request '%s'\n", *filename);
kfree(*filename);
*filename = NULL;
+ cs35l41->skip_tuning_params = true;
}
return ret;
@@ -308,6 +309,7 @@ static int cs35l41_fallback_firmware_file(struct cs35l41_hda *cs35l41,
if (ret) {
release_firmware(*wmfw_firmware);
kfree(*wmfw_filename);
+ *wmfw_filename = NULL;
goto err;
}
return 0;
@@ -325,6 +327,25 @@ static int cs35l41_request_firmware_files(struct cs35l41_hda *cs35l41,
{
int ret;
+ if (*wmfw_filename) {
+ ret = firmware_request_nowarn(wmfw_firmware, *wmfw_filename, cs35l41->dev);
+ if (ret != 0) {
+ dev_err(cs35l41->dev, "Failed to request known file '%s'\n",
+ *wmfw_filename);
+ return ret;
+ }
+ if (*coeff_filename) {
+ ret = firmware_request_nowarn(coeff_firmware, *coeff_filename,
+ cs35l41->dev);
+ if (ret != 0) {
+ dev_err(cs35l41->dev, "Failed to request known file '%s'\n",
+ *coeff_filename);
+ return ret;
+ }
+ }
+ return 0;
+ }
+
if (cs35l41->speaker_id > -1) {
ret = cs35l41_request_firmware_files_spkid(cs35l41, wmfw_firmware, wmfw_filename,
coeff_firmware, coeff_filename);
@@ -374,6 +395,7 @@ static int cs35l41_request_firmware_files(struct cs35l41_hda *cs35l41,
coeff_err:
release_firmware(*wmfw_firmware);
kfree(*wmfw_filename);
+ *wmfw_filename = NULL;
fallback:
return cs35l41_fallback_firmware_file(cs35l41, wmfw_firmware, wmfw_filename,
coeff_firmware, coeff_filename);
@@ -514,6 +536,9 @@ static int cs35l41_load_tuning_params(struct cs35l41_hda *cs35l41, char *tuning_
char *tuning_param_filename __free(kfree) = NULL;
int ret;
+ if (cs35l41->skip_tuning_params)
+ return 0;
+
ret = cs35l41_request_tuning_param_file(cs35l41, tuning_filename, &tuning_param_file,
&tuning_param_filename, cs35l41->acpi_subsystem_id);
if (ret) {
@@ -538,8 +563,6 @@ static int cs35l41_init_dsp(struct cs35l41_hda *cs35l41)
const struct firmware *coeff_firmware __free(firmware) = NULL;
const struct firmware *wmfw_firmware __free(firmware) = NULL;
struct cs_dsp *dsp = &cs35l41->cs_dsp;
- char *coeff_filename __free(kfree) = NULL;
- char *wmfw_filename __free(kfree) = NULL;
int ret;
if (!cs35l41->halo_initialized) {
@@ -554,23 +577,23 @@ static int cs35l41_init_dsp(struct cs35l41_hda *cs35l41)
cs35l41_set_default_tuning_params(cs35l41);
- ret = cs35l41_request_firmware_files(cs35l41, &wmfw_firmware, &wmfw_filename,
- &coeff_firmware, &coeff_filename);
+ ret = cs35l41_request_firmware_files(cs35l41, &wmfw_firmware, &cs35l41->wmfw_filename,
+ &coeff_firmware, &cs35l41->coeff_filename);
if (ret < 0)
return ret;
- dev_dbg(cs35l41->dev, "Loading WMFW Firmware: %s\n", wmfw_filename);
- if (coeff_filename) {
- dev_dbg(cs35l41->dev, "Loading Coefficient File: %s\n", coeff_filename);
- ret = cs35l41_load_tuning_params(cs35l41, coeff_filename);
+ dev_dbg(cs35l41->dev, "Loading WMFW Firmware: %s\n", cs35l41->wmfw_filename);
+ if (cs35l41->coeff_filename) {
+ dev_dbg(cs35l41->dev, "Loading Coefficient File: %s\n", cs35l41->coeff_filename);
+ ret = cs35l41_load_tuning_params(cs35l41, cs35l41->coeff_filename);
if (ret)
dev_warn(cs35l41->dev, "Unable to load Tuning Parameters: %d\n", ret);
} else {
dev_warn(cs35l41->dev, "No Coefficient File available.\n");
}
- ret = cs_dsp_power_up(dsp, wmfw_firmware, wmfw_filename, coeff_firmware, coeff_filename,
- CS35L41_HDA_FW_ID);
+ ret = cs_dsp_power_up(dsp, wmfw_firmware, cs35l41->wmfw_filename, coeff_firmware,
+ cs35l41->coeff_filename, CS35L41_HDA_FW_ID);
if (ret) {
cs35l41_set_default_tuning_params(cs35l41);
return ret;
@@ -600,6 +623,10 @@ static void cs35l41_remove_dsp(struct cs35l41_hda *cs35l41)
cs35l41_shutdown_dsp(cs35l41);
cs_dsp_remove(dsp);
cs35l41->halo_initialized = false;
+ kfree(cs35l41->wmfw_filename);
+ kfree(cs35l41->coeff_filename);
+ cs35l41->wmfw_filename = NULL;
+ cs35l41->coeff_filename = NULL;
}
/* Protection release cycle to get the speaker out of Safe-Mode */
diff --git a/sound/hda/codecs/side-codecs/cs35l41_hda.h b/sound/hda/codecs/side-codecs/cs35l41_hda.h
index 6fea4b2ad0ac..64ee70c31a43 100644
--- a/sound/hda/codecs/side-codecs/cs35l41_hda.h
+++ b/sound/hda/codecs/side-codecs/cs35l41_hda.h
@@ -93,7 +93,10 @@ struct cs35l41_hda {
unsigned int tuning_gain;
struct cirrus_amp_cal_data cal_data;
bool cal_data_valid;
+ bool skip_tuning_params;
+ char *coeff_filename;
+ char *wmfw_filename;
};
enum halo_state {
--
2.43.0