From: Charles Keepax <ckeepax@opensource.cirrus.com>
To: broonie@kernel.org
Cc: stuarth@opensource.cirrus.com, patches@opensource.cirrus.com,
alsa-devel@alsa-project.org, lgirdwood@gmail.com
Subject: [PATCH 3/5] ASoC: wm_adsp: Refactor compress stream initialisation
Date: Fri, 22 Feb 2019 10:04:19 +0000 [thread overview]
Message-ID: <20190222100421.894-3-ckeepax@opensource.cirrus.com> (raw)
In-Reply-To: <20190222100421.894-1-ckeepax@opensource.cirrus.com>
Make the code slightly clearer and prepare things for the addition of
multiple compressed streams on a single DSP core.
Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
---
sound/soc/codecs/wm_adsp.c | 139 ++++++++++++++++++++++++---------------------
1 file changed, 74 insertions(+), 65 deletions(-)
diff --git a/sound/soc/codecs/wm_adsp.c b/sound/soc/codecs/wm_adsp.c
index d556ea7204167..d5b0d969dddf7 100644
--- a/sound/soc/codecs/wm_adsp.c
+++ b/sound/soc/codecs/wm_adsp.c
@@ -3253,6 +3253,11 @@ static int wm_adsp_buffer_populate(struct wm_adsp_compr_buf *buf)
u32 offset = 0;
int i, ret;
+ buf->regions = kcalloc(caps->num_regions, sizeof(*buf->regions),
+ GFP_KERNEL);
+ if (!buf->regions)
+ return -ENOMEM;
+
for (i = 0; i < caps->num_regions; ++i) {
region = &buf->regions[i];
@@ -3287,13 +3292,34 @@ static void wm_adsp_buffer_clear(struct wm_adsp_compr_buf *buf)
buf->avail = 0;
}
-static int wm_adsp_legacy_host_buf_addr(struct wm_adsp_compr_buf *buf)
+static struct wm_adsp_compr_buf *wm_adsp_buffer_alloc(struct wm_adsp *dsp)
+{
+ struct wm_adsp_compr_buf *buf;
+
+ buf = kzalloc(sizeof(*buf), GFP_KERNEL);
+ if (!buf)
+ return NULL;
+
+ buf->dsp = dsp;
+
+ wm_adsp_buffer_clear(buf);
+
+ dsp->buffer = buf;
+
+ return buf;
+}
+
+static int wm_adsp_buffer_parse_legacy(struct wm_adsp *dsp)
{
struct wm_adsp_alg_region *alg_region;
- struct wm_adsp *dsp = buf->dsp;
+ struct wm_adsp_compr_buf *buf;
u32 xmalg, addr, magic;
int i, ret;
+ buf = wm_adsp_buffer_alloc(dsp);
+ if (!buf)
+ return -ENOMEM;
+
alg_region = wm_adsp_find_alg_region(dsp, WMFW_ADSP2_XM, dsp->fw_id);
xmalg = sizeof(struct wm_adsp_system_config_xm_hdr) / sizeof(__be32);
@@ -3303,7 +3329,7 @@ static int wm_adsp_legacy_host_buf_addr(struct wm_adsp_compr_buf *buf)
return ret;
if (magic != WM_ADSP_ALG_XM_STRUCT_MAGIC)
- return -EINVAL;
+ return -ENODEV;
addr = alg_region->base + xmalg + ALG_XM_FIELD(host_buf_ptr);
for (i = 0; i < 5; ++i) {
@@ -3323,49 +3349,27 @@ static int wm_adsp_legacy_host_buf_addr(struct wm_adsp_compr_buf *buf)
buf->host_buf_mem_type = WMFW_ADSP2_XM;
- adsp_dbg(dsp, "host_buf_ptr=%x\n", buf->host_buf_ptr);
-
- return 0;
-}
-
-static struct wm_coeff_ctl *
-wm_adsp_find_host_buffer_ctrl(struct wm_adsp_compr_buf *buf)
-{
- struct wm_adsp *dsp = buf->dsp;
- struct wm_coeff_ctl *ctl;
-
- list_for_each_entry(ctl, &dsp->ctl_list, list) {
- if (ctl->type != WMFW_CTL_TYPE_HOST_BUFFER)
- continue;
-
- if (!ctl->enabled)
- continue;
+ ret = wm_adsp_buffer_populate(buf);
+ if (ret < 0)
+ return ret;
- buf->host_buf_mem_type = ctl->alg_region.type;
- return ctl;
- }
+ adsp_dbg(dsp, "legacy host_buf_ptr=%x\n", buf->host_buf_ptr);
- return NULL;
+ return 0;
}
-static int wm_adsp_buffer_locate(struct wm_adsp_compr_buf *buf)
+static int wm_adsp_buffer_parse_coeff(struct wm_coeff_ctl *ctl)
{
- struct wm_adsp *dsp = buf->dsp;
- struct wm_coeff_ctl *ctl;
- unsigned int reg;
- u32 val;
- int i, ret;
-
- ctl = wm_adsp_find_host_buffer_ctrl(buf);
- if (!ctl)
- return wm_adsp_legacy_host_buf_addr(buf);
+ struct wm_adsp_compr_buf *buf;
+ unsigned int val, reg;
+ int ret, i;
ret = wm_coeff_base_reg(ctl, ®);
if (ret)
return ret;
for (i = 0; i < 5; ++i) {
- ret = regmap_raw_read(dsp->regmap, reg, &val, sizeof(val));
+ ret = regmap_raw_read(ctl->dsp->regmap, reg, &val, sizeof(val));
if (ret < 0)
return ret;
@@ -3375,56 +3379,61 @@ static int wm_adsp_buffer_locate(struct wm_adsp_compr_buf *buf)
usleep_range(1000, 2000);
}
- if (!val)
+ if (!val) {
+ adsp_err(ctl->dsp, "Failed to acquire host buffer\n");
return -EIO;
+ }
+
+ buf = wm_adsp_buffer_alloc(ctl->dsp);
+ if (!buf)
+ return -ENOMEM;
+ buf->host_buf_mem_type = ctl->alg_region.type;
buf->host_buf_ptr = be32_to_cpu(val);
- adsp_dbg(dsp, "host_buf_ptr=%x\n", buf->host_buf_ptr);
+
+ ret = wm_adsp_buffer_populate(buf);
+ if (ret < 0)
+ return ret;
+
+ adsp_dbg(ctl->dsp, "host_buf_ptr=%x\n", buf->host_buf_ptr);
return 0;
}
-
static int wm_adsp_buffer_init(struct wm_adsp *dsp)
{
- struct wm_adsp_compr_buf *buf;
+ struct wm_coeff_ctl *ctl;
int ret;
- buf = kzalloc(sizeof(*buf), GFP_KERNEL);
- if (!buf)
- return -ENOMEM;
-
- buf->dsp = dsp;
+ list_for_each_entry(ctl, &dsp->ctl_list, list) {
+ if (ctl->type != WMFW_CTL_TYPE_HOST_BUFFER)
+ continue;
- wm_adsp_buffer_clear(buf);
+ if (!ctl->enabled)
+ continue;
- ret = wm_adsp_buffer_locate(buf);
- if (ret < 0) {
- adsp_err(dsp, "Failed to acquire host buffer: %d\n", ret);
- goto err_buffer;
- }
+ ret = wm_adsp_buffer_parse_coeff(ctl);
+ if (ret < 0) {
+ adsp_err(dsp, "Failed to parse coeff: %d\n", ret);
+ goto error;
+ }
- buf->regions = kcalloc(wm_adsp_fw[dsp->fw].caps->num_regions,
- sizeof(*buf->regions), GFP_KERNEL);
- if (!buf->regions) {
- ret = -ENOMEM;
- goto err_buffer;
+ return 0;
}
- ret = wm_adsp_buffer_populate(buf);
- if (ret < 0) {
- adsp_err(dsp, "Failed to populate host buffer: %d\n", ret);
- goto err_regions;
+ if (!dsp->buffer) {
+ /* Fall back to legacy support */
+ ret = wm_adsp_buffer_parse_legacy(dsp);
+ if (ret) {
+ adsp_err(dsp, "Failed to parse legacy: %d\n", ret);
+ goto error;
+ }
}
- dsp->buffer = buf;
-
return 0;
-err_regions:
- kfree(buf->regions);
-err_buffer:
- kfree(buf);
+error:
+ wm_adsp_buffer_free(dsp);
return ret;
}
--
2.11.0
next prev parent reply other threads:[~2019-02-22 10:04 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-22 10:04 [PATCH 1/5] ASoC: wm_adsp: Factor out stripping padding from ADSP data Charles Keepax
2019-02-22 10:04 ` [PATCH 2/5] ASoC: wm_adsp: Reorder some functions for improved clarity Charles Keepax
2019-02-26 12:06 ` Applied "ASoC: wm_adsp: Reorder some functions for improved clarity" to the asoc tree Mark Brown
2019-02-22 10:04 ` Charles Keepax [this message]
2019-02-26 12:06 ` Applied "ASoC: wm_adsp: Refactor compress stream initialisation" " Mark Brown
2019-02-22 10:04 ` [PATCH 4/5] ASoC: wm_adsp: Add support for multiple compressed buffers Charles Keepax
2019-02-26 12:06 ` Applied "ASoC: wm_adsp: Add support for multiple compressed buffers" to the asoc tree Mark Brown
2019-02-22 10:04 ` [PATCH 5/5] ASoC: wm_adsp: Improve logging messages Charles Keepax
2019-02-26 12:06 ` Applied "ASoC: wm_adsp: Factor out stripping padding from ADSP data" to the asoc tree Mark Brown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190222100421.894-3-ckeepax@opensource.cirrus.com \
--to=ckeepax@opensource.cirrus.com \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=patches@opensource.cirrus.com \
--cc=stuarth@opensource.cirrus.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).