Commit d9d20e17 authored by Charles Keepax's avatar Charles Keepax Committed by Mark Brown

ASoC: wm_adsp: Factor out creation of alg_regions

Tidy up the code a little by factoring out the creation of the algorithm
regions.
Signed-off-by: default avatarCharles Keepax <ckeepax@opensource.wolfsonmicro.com>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent c9f8dd71
...@@ -913,6 +913,25 @@ static void *wm_adsp_read_algs(struct wm_adsp *dsp, size_t n_algs, ...@@ -913,6 +913,25 @@ static void *wm_adsp_read_algs(struct wm_adsp *dsp, size_t n_algs,
return alg; return alg;
} }
static struct wm_adsp_alg_region *wm_adsp_create_region(struct wm_adsp *dsp,
int type, __be32 id,
__be32 base)
{
struct wm_adsp_alg_region *alg_region;
alg_region = kzalloc(sizeof(*alg_region), GFP_KERNEL);
if (!alg_region)
return ERR_PTR(-ENOMEM);
alg_region->type = type;
alg_region->alg = be32_to_cpu(id);
alg_region->base = be32_to_cpu(base);
list_add_tail(&alg_region->list, &dsp->alg_regions);
return alg_region;
}
static int wm_adsp1_setup_algs(struct wm_adsp *dsp) static int wm_adsp1_setup_algs(struct wm_adsp *dsp)
{ {
struct wmfw_adsp1_id_hdr adsp1_id; struct wmfw_adsp1_id_hdr adsp1_id;
...@@ -944,21 +963,15 @@ static int wm_adsp1_setup_algs(struct wm_adsp *dsp) ...@@ -944,21 +963,15 @@ static int wm_adsp1_setup_algs(struct wm_adsp *dsp)
be32_to_cpu(adsp1_id.fw.ver) & 0xff, be32_to_cpu(adsp1_id.fw.ver) & 0xff,
n_algs); n_algs);
alg_region = kzalloc(sizeof(*alg_region), GFP_KERNEL); alg_region = wm_adsp_create_region(dsp, WMFW_ADSP1_ZM,
if (!alg_region) adsp1_id.fw.id, adsp1_id.zm);
return -ENOMEM; if (IS_ERR(alg_region))
alg_region->type = WMFW_ADSP1_ZM; return PTR_ERR(alg_region);
alg_region->alg = be32_to_cpu(adsp1_id.fw.id);
alg_region->base = be32_to_cpu(adsp1_id.zm);
list_add_tail(&alg_region->list, &dsp->alg_regions);
alg_region = kzalloc(sizeof(*alg_region), GFP_KERNEL); alg_region = wm_adsp_create_region(dsp, WMFW_ADSP1_DM,
if (!alg_region) adsp1_id.fw.id, adsp1_id.dm);
return -ENOMEM; if (IS_ERR(alg_region))
alg_region->type = WMFW_ADSP1_DM; return PTR_ERR(alg_region);
alg_region->alg = be32_to_cpu(adsp1_id.fw.id);
alg_region->base = be32_to_cpu(adsp1_id.dm);
list_add_tail(&alg_region->list, &dsp->alg_regions);
pos = sizeof(adsp1_id) / 2; pos = sizeof(adsp1_id) / 2;
len = (sizeof(*adsp1_alg) * n_algs) / 2; len = (sizeof(*adsp1_alg) * n_algs) / 2;
...@@ -976,15 +989,13 @@ static int wm_adsp1_setup_algs(struct wm_adsp *dsp) ...@@ -976,15 +989,13 @@ static int wm_adsp1_setup_algs(struct wm_adsp *dsp)
be32_to_cpu(adsp1_alg[i].dm), be32_to_cpu(adsp1_alg[i].dm),
be32_to_cpu(adsp1_alg[i].zm)); be32_to_cpu(adsp1_alg[i].zm));
alg_region = kzalloc(sizeof(*alg_region), GFP_KERNEL); alg_region = wm_adsp_create_region(dsp, WMFW_ADSP1_DM,
if (!alg_region) { adsp1_alg[i].alg.id,
ret = -ENOMEM; adsp1_alg[i].dm);
if (IS_ERR(alg_region)) {
ret = PTR_ERR(alg_region);
goto out; goto out;
} }
alg_region->type = WMFW_ADSP1_DM;
alg_region->alg = be32_to_cpu(adsp1_alg[i].alg.id);
alg_region->base = be32_to_cpu(adsp1_alg[i].dm);
list_add_tail(&alg_region->list, &dsp->alg_regions);
if (i + 1 < n_algs) { if (i + 1 < n_algs) {
len = be32_to_cpu(adsp1_alg[i + 1].dm); len = be32_to_cpu(adsp1_alg[i + 1].dm);
len -= be32_to_cpu(adsp1_alg[i].dm); len -= be32_to_cpu(adsp1_alg[i].dm);
...@@ -995,15 +1006,13 @@ static int wm_adsp1_setup_algs(struct wm_adsp *dsp) ...@@ -995,15 +1006,13 @@ static int wm_adsp1_setup_algs(struct wm_adsp *dsp)
be32_to_cpu(adsp1_alg[i].alg.id)); be32_to_cpu(adsp1_alg[i].alg.id));
} }
alg_region = kzalloc(sizeof(*alg_region), GFP_KERNEL); alg_region = wm_adsp_create_region(dsp, WMFW_ADSP1_ZM,
if (!alg_region) { adsp1_alg[i].alg.id,
ret = -ENOMEM; adsp1_alg[i].zm);
if (IS_ERR(alg_region)) {
ret = PTR_ERR(alg_region);
goto out; goto out;
} }
alg_region->type = WMFW_ADSP1_ZM;
alg_region->alg = be32_to_cpu(adsp1_alg[i].alg.id);
alg_region->base = be32_to_cpu(adsp1_alg[i].zm);
list_add_tail(&alg_region->list, &dsp->alg_regions);
if (i + 1 < n_algs) { if (i + 1 < n_algs) {
len = be32_to_cpu(adsp1_alg[i + 1].zm); len = be32_to_cpu(adsp1_alg[i + 1].zm);
len -= be32_to_cpu(adsp1_alg[i].zm); len -= be32_to_cpu(adsp1_alg[i].zm);
...@@ -1051,29 +1060,20 @@ static int wm_adsp2_setup_algs(struct wm_adsp *dsp) ...@@ -1051,29 +1060,20 @@ static int wm_adsp2_setup_algs(struct wm_adsp *dsp)
be32_to_cpu(adsp2_id.fw.ver) & 0xff, be32_to_cpu(adsp2_id.fw.ver) & 0xff,
n_algs); n_algs);
alg_region = kzalloc(sizeof(*alg_region), GFP_KERNEL); alg_region = wm_adsp_create_region(dsp, WMFW_ADSP2_XM,
if (!alg_region) adsp2_id.fw.id, adsp2_id.xm);
return -ENOMEM; if (IS_ERR(alg_region))
alg_region->type = WMFW_ADSP2_XM; return PTR_ERR(alg_region);
alg_region->alg = be32_to_cpu(adsp2_id.fw.id);
alg_region->base = be32_to_cpu(adsp2_id.xm);
list_add_tail(&alg_region->list, &dsp->alg_regions);
alg_region = kzalloc(sizeof(*alg_region), GFP_KERNEL); alg_region = wm_adsp_create_region(dsp, WMFW_ADSP2_YM,
if (!alg_region) adsp2_id.fw.id, adsp2_id.ym);
return -ENOMEM; if (IS_ERR(alg_region))
alg_region->type = WMFW_ADSP2_YM; return PTR_ERR(alg_region);
alg_region->alg = be32_to_cpu(adsp2_id.fw.id);
alg_region->base = be32_to_cpu(adsp2_id.ym);
list_add_tail(&alg_region->list, &dsp->alg_regions);
alg_region = kzalloc(sizeof(*alg_region), GFP_KERNEL); alg_region = wm_adsp_create_region(dsp, WMFW_ADSP2_ZM,
if (!alg_region) adsp2_id.fw.id, adsp2_id.zm);
return -ENOMEM; if (IS_ERR(alg_region))
alg_region->type = WMFW_ADSP2_ZM; return PTR_ERR(alg_region);
alg_region->alg = be32_to_cpu(adsp2_id.fw.id);
alg_region->base = be32_to_cpu(adsp2_id.zm);
list_add_tail(&alg_region->list, &dsp->alg_regions);
pos = sizeof(adsp2_id) / 2; pos = sizeof(adsp2_id) / 2;
len = (sizeof(*adsp2_alg) * n_algs) / 2; len = (sizeof(*adsp2_alg) * n_algs) / 2;
...@@ -1093,15 +1093,13 @@ static int wm_adsp2_setup_algs(struct wm_adsp *dsp) ...@@ -1093,15 +1093,13 @@ static int wm_adsp2_setup_algs(struct wm_adsp *dsp)
be32_to_cpu(adsp2_alg[i].ym), be32_to_cpu(adsp2_alg[i].ym),
be32_to_cpu(adsp2_alg[i].zm)); be32_to_cpu(adsp2_alg[i].zm));
alg_region = kzalloc(sizeof(*alg_region), GFP_KERNEL); alg_region = wm_adsp_create_region(dsp, WMFW_ADSP2_XM,
if (!alg_region) { adsp2_alg[i].alg.id,
ret = -ENOMEM; adsp2_alg[i].xm);
if (IS_ERR(alg_region)) {
ret = PTR_ERR(alg_region);
goto out; goto out;
} }
alg_region->type = WMFW_ADSP2_XM;
alg_region->alg = be32_to_cpu(adsp2_alg[i].alg.id);
alg_region->base = be32_to_cpu(adsp2_alg[i].xm);
list_add_tail(&alg_region->list, &dsp->alg_regions);
if (i + 1 < n_algs) { if (i + 1 < n_algs) {
len = be32_to_cpu(adsp2_alg[i + 1].xm); len = be32_to_cpu(adsp2_alg[i + 1].xm);
len -= be32_to_cpu(adsp2_alg[i].xm); len -= be32_to_cpu(adsp2_alg[i].xm);
...@@ -1112,15 +1110,13 @@ static int wm_adsp2_setup_algs(struct wm_adsp *dsp) ...@@ -1112,15 +1110,13 @@ static int wm_adsp2_setup_algs(struct wm_adsp *dsp)
be32_to_cpu(adsp2_alg[i].alg.id)); be32_to_cpu(adsp2_alg[i].alg.id));
} }
alg_region = kzalloc(sizeof(*alg_region), GFP_KERNEL); alg_region = wm_adsp_create_region(dsp, WMFW_ADSP2_YM,
if (!alg_region) { adsp2_alg[i].alg.id,
ret = -ENOMEM; adsp2_alg[i].ym);
if (IS_ERR(alg_region)) {
ret = PTR_ERR(alg_region);
goto out; goto out;
} }
alg_region->type = WMFW_ADSP2_YM;
alg_region->alg = be32_to_cpu(adsp2_alg[i].alg.id);
alg_region->base = be32_to_cpu(adsp2_alg[i].ym);
list_add_tail(&alg_region->list, &dsp->alg_regions);
if (i + 1 < n_algs) { if (i + 1 < n_algs) {
len = be32_to_cpu(adsp2_alg[i + 1].ym); len = be32_to_cpu(adsp2_alg[i + 1].ym);
len -= be32_to_cpu(adsp2_alg[i].ym); len -= be32_to_cpu(adsp2_alg[i].ym);
...@@ -1131,15 +1127,13 @@ static int wm_adsp2_setup_algs(struct wm_adsp *dsp) ...@@ -1131,15 +1127,13 @@ static int wm_adsp2_setup_algs(struct wm_adsp *dsp)
be32_to_cpu(adsp2_alg[i].alg.id)); be32_to_cpu(adsp2_alg[i].alg.id));
} }
alg_region = kzalloc(sizeof(*alg_region), GFP_KERNEL); alg_region = wm_adsp_create_region(dsp, WMFW_ADSP2_ZM,
if (!alg_region) { adsp2_alg[i].alg.id,
ret = -ENOMEM; adsp2_alg[i].zm);
if (IS_ERR(alg_region)) {
ret = PTR_ERR(alg_region);
goto out; goto out;
} }
alg_region->type = WMFW_ADSP2_ZM;
alg_region->alg = be32_to_cpu(adsp2_alg[i].alg.id);
alg_region->base = be32_to_cpu(adsp2_alg[i].zm);
list_add_tail(&alg_region->list, &dsp->alg_regions);
if (i + 1 < n_algs) { if (i + 1 < n_algs) {
len = be32_to_cpu(adsp2_alg[i + 1].zm); len = be32_to_cpu(adsp2_alg[i + 1].zm);
len -= be32_to_cpu(adsp2_alg[i].zm); len -= be32_to_cpu(adsp2_alg[i].zm);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment