Skip to content

Commit 7bca3ca

Browse files
rfvirgilbroonie
authored andcommitted
ASoC: wm_adsp: Use a struct to pass around firmware struct and filename
Bundle the pointers to struct firmware and its filename into a new struct wm_adsp_fw_files. This simplifies passing these pointers around. Changes are also needed to the test cases in wm_adsp_fw_find_test.c that use this API. Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com> Link: https://patch.msgid.link/20260310141817.1871794-10-rf@opensource.cirrus.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent d8a4c96 commit 7bca3ca

3 files changed

Lines changed: 77 additions & 114 deletions

File tree

sound/soc/codecs/wm_adsp.c

Lines changed: 50 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -717,20 +717,15 @@ int wm_adsp_read_ctl(struct wm_adsp *dsp, const char *name, int type,
717717
}
718718
EXPORT_SYMBOL_GPL(wm_adsp_read_ctl);
719719

720-
VISIBLE_IF_KUNIT void wm_adsp_release_firmware_files(const struct firmware *wmfw_firmware,
721-
char *wmfw_filename,
722-
const struct firmware *coeff_firmware,
723-
char *coeff_filename)
720+
VISIBLE_IF_KUNIT void wm_adsp_release_firmware_files(struct wm_adsp_fw_files *fw)
724721
{
725-
KUNIT_STATIC_STUB_REDIRECT(wm_adsp_release_firmware_files,
726-
wmfw_firmware, wmfw_filename,
727-
coeff_firmware, coeff_filename);
722+
KUNIT_STATIC_STUB_REDIRECT(wm_adsp_release_firmware_files, fw);
728723

729-
release_firmware(wmfw_firmware);
730-
kfree(wmfw_filename);
724+
release_firmware(fw->wmfw.firmware);
725+
kfree(fw->wmfw.filename);
731726

732-
release_firmware(coeff_firmware);
733-
kfree(coeff_filename);
727+
release_firmware(fw->coeff.firmware);
728+
kfree(fw->coeff.filename);
734729
}
735730
EXPORT_SYMBOL_IF_KUNIT(wm_adsp_release_firmware_files);
736731

@@ -745,7 +740,7 @@ VISIBLE_IF_KUNIT int wm_adsp_firmware_request(const struct firmware **firmware,
745740
EXPORT_SYMBOL_IF_KUNIT(wm_adsp_firmware_request);
746741

747742
static int wm_adsp_request_firmware_file(struct wm_adsp *dsp,
748-
const struct firmware **firmware, char **filename,
743+
struct wm_adsp_fw_file *fw,
749744
const char *dir, const char *system_name,
750745
const char *asoc_component_prefix,
751746
const char *filetype)
@@ -761,25 +756,25 @@ static int wm_adsp_request_firmware_file(struct wm_adsp *dsp,
761756
fwf = dsp->cs_dsp.name;
762757

763758
if (system_name && asoc_component_prefix)
764-
*filename = kasprintf(GFP_KERNEL, "%s%s-%s-%s-%s-%s.%s", dir, dsp->part,
765-
fwf, wm_adsp_fw[dsp->fw].file, system_name,
766-
asoc_component_prefix, filetype);
759+
fw->filename = kasprintf(GFP_KERNEL, "%s%s-%s-%s-%s-%s.%s", dir, dsp->part,
760+
fwf, wm_adsp_fw[dsp->fw].file, system_name,
761+
asoc_component_prefix, filetype);
767762
else if (system_name)
768-
*filename = kasprintf(GFP_KERNEL, "%s%s-%s-%s-%s.%s", dir, dsp->part,
769-
fwf, wm_adsp_fw[dsp->fw].file, system_name,
770-
filetype);
763+
fw->filename = kasprintf(GFP_KERNEL, "%s%s-%s-%s-%s.%s", dir, dsp->part,
764+
fwf, wm_adsp_fw[dsp->fw].file, system_name,
765+
filetype);
771766
else
772-
*filename = kasprintf(GFP_KERNEL, "%s%s-%s-%s.%s", dir, dsp->part, fwf,
773-
wm_adsp_fw[dsp->fw].file, filetype);
767+
fw->filename = kasprintf(GFP_KERNEL, "%s%s-%s-%s.%s", dir, dsp->part, fwf,
768+
wm_adsp_fw[dsp->fw].file, filetype);
774769

775-
if (*filename == NULL)
770+
if (!fw->filename)
776771
return -ENOMEM;
777772

778773
/*
779774
* Make sure that filename after dir is lower-case and any non-alpha-numeric
780775
* characters except full-stop are replaced with hyphens.
781776
*/
782-
s = *filename + strlen(dir);
777+
s = fw->filename + strlen(dir);
783778
while (*s) {
784779
c = *s;
785780
if (isalnum(c))
@@ -789,26 +784,23 @@ static int wm_adsp_request_firmware_file(struct wm_adsp *dsp,
789784
s++;
790785
}
791786

792-
ret = wm_adsp_firmware_request(firmware, *filename, cs_dsp->dev);
787+
ret = wm_adsp_firmware_request(&fw->firmware, fw->filename, cs_dsp->dev);
793788
if (ret < 0) {
794-
adsp_dbg(dsp, "Failed to request '%s': %d\n", *filename, ret);
795-
kfree(*filename);
796-
*filename = NULL;
789+
adsp_dbg(dsp, "Failed to request '%s': %d\n", fw->filename, ret);
790+
kfree(fw->filename);
791+
fw->filename = NULL;
797792
if (ret != -ENOENT)
798793
return ret;
799794
} else {
800-
adsp_dbg(dsp, "Found '%s'\n", *filename);
795+
adsp_dbg(dsp, "Found '%s'\n", fw->filename);
801796
}
802797

803798
return 0;
804799
}
805800

806801
static const char * const cirrus_dir = "cirrus/";
807802
VISIBLE_IF_KUNIT int wm_adsp_request_firmware_files(struct wm_adsp *dsp,
808-
const struct firmware **wmfw_firmware,
809-
char **wmfw_filename,
810-
const struct firmware **coeff_firmware,
811-
char **coeff_filename)
803+
struct wm_adsp_fw_files *fw)
812804
{
813805
const char *system_name = dsp->system_name;
814806
const char *suffix = dsp->component->name_prefix;
@@ -818,14 +810,14 @@ VISIBLE_IF_KUNIT int wm_adsp_request_firmware_files(struct wm_adsp *dsp,
818810
suffix = dsp->fwf_suffix;
819811

820812
if (system_name && suffix) {
821-
ret = wm_adsp_request_firmware_file(dsp, wmfw_firmware, wmfw_filename,
813+
ret = wm_adsp_request_firmware_file(dsp, &fw->wmfw,
822814
cirrus_dir, system_name,
823815
suffix, "wmfw");
824816
if (ret < 0)
825817
goto err;
826818

827-
if (*wmfw_firmware) {
828-
ret = wm_adsp_request_firmware_file(dsp, coeff_firmware, coeff_filename,
819+
if (fw->wmfw.firmware) {
820+
ret = wm_adsp_request_firmware_file(dsp, &fw->coeff,
829821
cirrus_dir, system_name,
830822
suffix, "bin");
831823
if (ret < 0)
@@ -836,59 +828,57 @@ VISIBLE_IF_KUNIT int wm_adsp_request_firmware_files(struct wm_adsp *dsp,
836828
}
837829

838830
if (system_name) {
839-
ret = wm_adsp_request_firmware_file(dsp, wmfw_firmware, wmfw_filename,
831+
ret = wm_adsp_request_firmware_file(dsp, &fw->wmfw,
840832
cirrus_dir, system_name,
841833
NULL, "wmfw");
842834
if (ret < 0)
843835
goto err;
844836

845-
if (*wmfw_firmware || dsp->wmfw_optional) {
837+
if (fw->wmfw.firmware || dsp->wmfw_optional) {
846838
if (suffix) {
847839
ret = wm_adsp_request_firmware_file(dsp,
848-
coeff_firmware, coeff_filename,
840+
&fw->coeff,
849841
cirrus_dir, system_name,
850842
suffix, "bin");
851843
if (ret < 0)
852844
goto err;
853845
}
854846

855-
if (!*coeff_firmware) {
847+
if (!fw->coeff.firmware) {
856848
ret = wm_adsp_request_firmware_file(dsp,
857-
coeff_firmware, coeff_filename,
849+
&fw->coeff,
858850
cirrus_dir, system_name,
859851
NULL, "bin");
860852
if (ret < 0)
861853
goto err;
862854
}
863855

864-
if (*wmfw_firmware || (dsp->wmfw_optional && *coeff_firmware))
856+
if (fw->wmfw.firmware || (dsp->wmfw_optional && fw->coeff.firmware))
865857
return 0;
866858
}
867859
}
868860

869861
/* Check legacy location */
870-
ret = wm_adsp_request_firmware_file(dsp, wmfw_firmware, wmfw_filename,
871-
"", NULL, NULL, "wmfw");
862+
ret = wm_adsp_request_firmware_file(dsp, &fw->wmfw, "", NULL, NULL, "wmfw");
872863
if (ret < 0)
873864
goto err;
874865

875-
if (*wmfw_firmware) {
876-
ret = wm_adsp_request_firmware_file(dsp, coeff_firmware, coeff_filename,
877-
"", NULL, NULL, "bin");
866+
if (fw->wmfw.firmware) {
867+
ret = wm_adsp_request_firmware_file(dsp, &fw->coeff, "", NULL, NULL, "bin");
878868
if (ret < 0)
879869
goto err;
880870

881871
return 0;
882872
}
883873

884874
/* Fall back to generic wmfw and optional matching bin */
885-
ret = wm_adsp_request_firmware_file(dsp, wmfw_firmware, wmfw_filename,
875+
ret = wm_adsp_request_firmware_file(dsp, &fw->wmfw,
886876
cirrus_dir, NULL, NULL, "wmfw");
887877
if (ret < 0)
888878
goto err;
889879

890-
if (*wmfw_firmware || dsp->wmfw_optional) {
891-
ret = wm_adsp_request_firmware_file(dsp, coeff_firmware, coeff_filename,
880+
if (fw->wmfw.firmware || dsp->wmfw_optional) {
881+
ret = wm_adsp_request_firmware_file(dsp, &fw->coeff,
892882
cirrus_dir, NULL, NULL, "bin");
893883
if (ret < 0)
894884
goto err;
@@ -903,8 +893,7 @@ VISIBLE_IF_KUNIT int wm_adsp_request_firmware_files(struct wm_adsp *dsp,
903893

904894
ret = -ENOENT;
905895
err:
906-
wm_adsp_release_firmware_files(*wmfw_firmware, *wmfw_filename,
907-
*coeff_firmware, *coeff_filename);
896+
wm_adsp_release_firmware_files(fw);
908897

909898
return ret;
910899
}
@@ -939,29 +928,23 @@ int wm_adsp1_event(struct snd_soc_dapm_widget *w,
939928
struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
940929
struct wm_adsp *dsps = snd_soc_component_get_drvdata(component);
941930
struct wm_adsp *dsp = &dsps[w->shift];
931+
struct wm_adsp_fw_files fw = { 0 };
942932
int ret = 0;
943-
char *wmfw_filename = NULL;
944-
const struct firmware *wmfw_firmware = NULL;
945-
char *coeff_filename = NULL;
946-
const struct firmware *coeff_firmware = NULL;
947933

948934
dsp->component = component;
949935

950936
switch (event) {
951937
case SND_SOC_DAPM_POST_PMU:
952-
ret = wm_adsp_request_firmware_files(dsp,
953-
&wmfw_firmware, &wmfw_filename,
954-
&coeff_firmware, &coeff_filename);
938+
ret = wm_adsp_request_firmware_files(dsp, &fw);
955939
if (ret)
956940
break;
957941

958942
ret = cs_dsp_adsp1_power_up(&dsp->cs_dsp,
959-
wmfw_firmware, wmfw_filename,
960-
coeff_firmware, coeff_filename,
943+
fw.wmfw.firmware, fw.wmfw.filename,
944+
fw.coeff.firmware, fw.coeff.filename,
961945
wm_adsp_fw_text[dsp->fw]);
962946

963-
wm_adsp_release_firmware_files(wmfw_firmware, wmfw_filename,
964-
coeff_firmware, coeff_filename);
947+
wm_adsp_release_firmware_files(&fw);
965948
break;
966949
case SND_SOC_DAPM_PRE_PMD:
967950
cs_dsp_adsp1_power_down(&dsp->cs_dsp);
@@ -1037,33 +1020,27 @@ EXPORT_SYMBOL_GPL(wm_adsp2_preloader_put);
10371020

10381021
int wm_adsp_power_up(struct wm_adsp *dsp, bool load_firmware)
10391022
{
1023+
struct wm_adsp_fw_files fw = { 0 };
10401024
int ret = 0;
1041-
char *wmfw_filename = NULL;
1042-
const struct firmware *wmfw_firmware = NULL;
1043-
char *coeff_filename = NULL;
1044-
const struct firmware *coeff_firmware = NULL;
10451025

10461026
if (load_firmware) {
1047-
ret = wm_adsp_request_firmware_files(dsp,
1048-
&wmfw_firmware, &wmfw_filename,
1049-
&coeff_firmware, &coeff_filename);
1027+
ret = wm_adsp_request_firmware_files(dsp, &fw);
10501028
if (ret)
10511029
return ret;
10521030
}
10531031

1054-
if (dsp->bin_mandatory && !coeff_firmware) {
1032+
if (dsp->bin_mandatory && !fw.coeff.firmware) {
10551033
ret = -ENOENT;
10561034
goto err;
10571035
}
10581036

10591037
ret = cs_dsp_power_up(&dsp->cs_dsp,
1060-
wmfw_firmware, wmfw_filename,
1061-
coeff_firmware, coeff_filename,
1038+
fw.wmfw.firmware, fw.wmfw.filename,
1039+
fw.coeff.firmware, fw.coeff.filename,
10621040
wm_adsp_fw_text[dsp->fw]);
10631041

10641042
err:
1065-
wm_adsp_release_firmware_files(wmfw_firmware, wmfw_filename,
1066-
coeff_firmware, coeff_filename);
1043+
wm_adsp_release_firmware_files(&fw);
10671044

10681045
return ret;
10691046
}

sound/soc/codecs/wm_adsp.h

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ struct wm_adsp {
7979
SOC_ENUM_EXT(dspname " Firmware", wm_adsp_fw_enum[num], \
8080
wm_adsp_fw_get, wm_adsp_fw_put)
8181

82+
struct wm_adsp_fw_file {
83+
const struct firmware *firmware;
84+
char *filename;
85+
};
86+
87+
struct wm_adsp_fw_files {
88+
struct wm_adsp_fw_file wmfw;
89+
struct wm_adsp_fw_file coeff;
90+
};
91+
8292
extern const struct soc_enum wm_adsp_fw_enum[];
8393

8494
int wm_adsp1_init(struct wm_adsp *dsp);
@@ -144,18 +154,11 @@ int wm_adsp_read_ctl(struct wm_adsp *dsp, const char *name, int type,
144154

145155
#if IS_ENABLED(CONFIG_KUNIT)
146156
const char *wm_adsp_get_fwf_name_by_index(int index);
147-
void wm_adsp_release_firmware_files(const struct firmware *wmfw_firmware,
148-
char *wmfw_filename,
149-
const struct firmware *coeff_firmware,
150-
char *coeff_filename);
157+
void wm_adsp_release_firmware_files(struct wm_adsp_fw_files *fw);
151158
int wm_adsp_firmware_request(const struct firmware **firmware,
152159
const char *filename,
153160
struct device *dev);
154-
int wm_adsp_request_firmware_files(struct wm_adsp *dsp,
155-
const struct firmware **wmfw_firmware,
156-
char **wmfw_filename,
157-
const struct firmware **coeff_firmware,
158-
char **coeff_filename);
161+
int wm_adsp_request_firmware_files(struct wm_adsp *dsp, struct wm_adsp_fw_files *fw);
159162
#endif
160163

161164
#endif

0 commit comments

Comments
 (0)