ASoC: wm_adsp: Refactor firmware status reading
authorCharles Keepax <ckeepax@opensource.cirrus.com>
Tue, 19 Mar 2019 11:52:10 +0000 (11:52 +0000)
committerMark Brown <broonie@kernel.org>
Tue, 19 Mar 2019 12:40:11 +0000 (12:40 +0000)
In preparation for further additions refactor the reading of the
firmware status.

Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/codecs/wm_adsp.c

index 8800ffcc4f8c074e0664cfa6ed3d11f23d96acba..fb252762f23ce789fca8fbb99e8b66a617e91332 100644 (file)
@@ -788,49 +788,42 @@ static unsigned int wm_adsp_region_to_reg(struct wm_adsp_region const *mem,
        }
 }
 
-static void wm_adsp2_show_fw_status(struct wm_adsp *dsp)
+static void wm_adsp_read_fw_status(struct wm_adsp *dsp,
+                                  int noffs, unsigned int *offs)
 {
-       unsigned int scratch[4];
-       unsigned int addr = dsp->base + ADSP2_SCRATCH0;
        unsigned int i;
        int ret;
 
-       for (i = 0; i < ARRAY_SIZE(scratch); ++i) {
-               ret = regmap_read(dsp->regmap, addr + i, &scratch[i]);
+       for (i = 0; i < noffs; ++i) {
+               ret = regmap_read(dsp->regmap, dsp->base + offs[i], &offs[i]);
                if (ret) {
                        adsp_err(dsp, "Failed to read SCRATCH%u: %d\n", i, ret);
                        return;
                }
        }
+}
+
+static void wm_adsp2_show_fw_status(struct wm_adsp *dsp)
+{
+       unsigned int offs[] = {
+               ADSP2_SCRATCH0, ADSP2_SCRATCH1, ADSP2_SCRATCH2, ADSP2_SCRATCH3,
+       };
+
+       wm_adsp_read_fw_status(dsp, ARRAY_SIZE(offs), offs);
 
        adsp_dbg(dsp, "FW SCRATCH 0:0x%x 1:0x%x 2:0x%x 3:0x%x\n",
-                scratch[0], scratch[1], scratch[2], scratch[3]);
+                offs[0], offs[1], offs[2], offs[3]);
 }
 
 static void wm_adsp2v2_show_fw_status(struct wm_adsp *dsp)
 {
-       unsigned int scratch[2];
-       int ret;
+       unsigned int offs[] = { ADSP2V2_SCRATCH0_1, ADSP2V2_SCRATCH2_3 };
 
-       ret = regmap_read(dsp->regmap, dsp->base + ADSP2V2_SCRATCH0_1,
-                         &scratch[0]);
-       if (ret) {
-               adsp_err(dsp, "Failed to read SCRATCH0_1: %d\n", ret);
-               return;
-       }
-
-       ret = regmap_read(dsp->regmap, dsp->base + ADSP2V2_SCRATCH2_3,
-                         &scratch[1]);
-       if (ret) {
-               adsp_err(dsp, "Failed to read SCRATCH2_3: %d\n", ret);
-               return;
-       }
+       wm_adsp_read_fw_status(dsp, ARRAY_SIZE(offs), offs);
 
        adsp_dbg(dsp, "FW SCRATCH 0:0x%x 1:0x%x 2:0x%x 3:0x%x\n",
-                scratch[0] & 0xFFFF,
-                scratch[0] >> 16,
-                scratch[1] & 0xFFFF,
-                scratch[1] >> 16);
+                offs[0] & 0xFFFF, offs[0] >> 16,
+                offs[1] & 0xFFFF, offs[1] >> 16);
 }
 
 static inline struct wm_coeff_ctl *bytes_ext_to_ctl(struct soc_bytes_ext *ext)