ASoC: cs35l56: Don't overwrite a patched firmware
authorRichard Fitzgerald <rf@opensource.cirrus.com>
Tue, 15 Aug 2023 12:48:26 +0000 (13:48 +0100)
committerMark Brown <broonie@kernel.org>
Tue, 15 Aug 2023 12:56:47 +0000 (13:56 +0100)
Only attempt to download wmfw/bin files to a non-secured part if
it reports FIRMWARE_MISSING. If FIRMWARE_MISSING is false the
firmware has already been patched and overwriting the patch could
corrupt the running firmware.

For a secured part the wmfw/bin can be downloaded even if
FIRMWARE_MISSING is false, because they will only patch tunings.

Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
Link: https://lore.kernel.org/r/20230815124826.5447-3-rf@opensource.cirrus.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/codecs/cs35l56.c

index 98cfcae..3a9ec87 100644 (file)
@@ -665,8 +665,17 @@ static void cs35l56_secure_patch(struct cs35l56_private *cs35l56)
 
 static void cs35l56_patch(struct cs35l56_private *cs35l56)
 {
+       unsigned int firmware_missing;
        int ret;
 
+       ret = regmap_read(cs35l56->base.regmap, CS35L56_PROTECTION_STATUS, &firmware_missing);
+       if (ret) {
+               dev_err(cs35l56->base.dev, "Failed to read PROTECTION_STATUS: %d\n", ret);
+               return;
+       }
+
+       firmware_missing &= CS35L56_FIRMWARE_MISSING;
+
        /*
         * Disable SoundWire interrupts to prevent race with IRQ work.
         * Setting sdw_irq_no_unmask prevents the handler re-enabling
@@ -685,8 +694,12 @@ static void cs35l56_patch(struct cs35l56_private *cs35l56)
        if (ret)
                goto err;
 
-       /* Use wm_adsp to load and apply the firmware patch and coefficient files */
-       ret = wm_adsp_power_up(&cs35l56->dsp, true);
+       /*
+        * Use wm_adsp to load and apply the firmware patch and coefficient files,
+        * but only if firmware is missing. If firmware is already patched just
+        * power-up wm_adsp without downloading firmware.
+        */
+       ret = wm_adsp_power_up(&cs35l56->dsp, !!firmware_missing);
        if (ret) {
                dev_dbg(cs35l56->base.dev, "%s: wm_adsp_power_up ret %d\n", __func__, ret);
                goto err;