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

firmware: cs_dsp: Add offset to cs_dsp read/write

Provide a mechanism to access only part of a control through the cs_dsp
interface.
Signed-off-by: default avatarCharles Keepax <ckeepax@opensource.cirrus.com>
Link: https://lore.kernel.org/r/20211117132300.1290-9-ckeepax@opensource.cirrus.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent b329b3d3
...@@ -616,7 +616,8 @@ static void cs_dsp_halo_show_fw_status(struct cs_dsp *dsp) ...@@ -616,7 +616,8 @@ static void cs_dsp_halo_show_fw_status(struct cs_dsp *dsp)
offs[0], offs[1], offs[2], offs[3]); offs[0], offs[1], offs[2], offs[3]);
} }
static int cs_dsp_coeff_base_reg(struct cs_dsp_coeff_ctl *ctl, unsigned int *reg) static int cs_dsp_coeff_base_reg(struct cs_dsp_coeff_ctl *ctl, unsigned int *reg,
unsigned int off)
{ {
const struct cs_dsp_alg_region *alg_region = &ctl->alg_region; const struct cs_dsp_alg_region *alg_region = &ctl->alg_region;
struct cs_dsp *dsp = ctl->dsp; struct cs_dsp *dsp = ctl->dsp;
...@@ -629,7 +630,7 @@ static int cs_dsp_coeff_base_reg(struct cs_dsp_coeff_ctl *ctl, unsigned int *reg ...@@ -629,7 +630,7 @@ static int cs_dsp_coeff_base_reg(struct cs_dsp_coeff_ctl *ctl, unsigned int *reg
return -EINVAL; return -EINVAL;
} }
*reg = dsp->ops->region_to_reg(mem, ctl->alg_region.base + ctl->offset); *reg = dsp->ops->region_to_reg(mem, ctl->alg_region.base + ctl->offset + off);
return 0; return 0;
} }
...@@ -658,7 +659,7 @@ int cs_dsp_coeff_write_acked_control(struct cs_dsp_coeff_ctl *ctl, unsigned int ...@@ -658,7 +659,7 @@ int cs_dsp_coeff_write_acked_control(struct cs_dsp_coeff_ctl *ctl, unsigned int
if (!dsp->running) if (!dsp->running)
return -EPERM; return -EPERM;
ret = cs_dsp_coeff_base_reg(ctl, &reg); ret = cs_dsp_coeff_base_reg(ctl, &reg, 0);
if (ret) if (ret)
return ret; return ret;
...@@ -712,14 +713,14 @@ int cs_dsp_coeff_write_acked_control(struct cs_dsp_coeff_ctl *ctl, unsigned int ...@@ -712,14 +713,14 @@ int cs_dsp_coeff_write_acked_control(struct cs_dsp_coeff_ctl *ctl, unsigned int
EXPORT_SYMBOL_GPL(cs_dsp_coeff_write_acked_control); EXPORT_SYMBOL_GPL(cs_dsp_coeff_write_acked_control);
static int cs_dsp_coeff_write_ctrl_raw(struct cs_dsp_coeff_ctl *ctl, static int cs_dsp_coeff_write_ctrl_raw(struct cs_dsp_coeff_ctl *ctl,
const void *buf, size_t len) unsigned int off, const void *buf, size_t len)
{ {
struct cs_dsp *dsp = ctl->dsp; struct cs_dsp *dsp = ctl->dsp;
void *scratch; void *scratch;
int ret; int ret;
unsigned int reg; unsigned int reg;
ret = cs_dsp_coeff_base_reg(ctl, &reg); ret = cs_dsp_coeff_base_reg(ctl, &reg, off);
if (ret) if (ret)
return ret; return ret;
...@@ -745,6 +746,7 @@ static int cs_dsp_coeff_write_ctrl_raw(struct cs_dsp_coeff_ctl *ctl, ...@@ -745,6 +746,7 @@ static int cs_dsp_coeff_write_ctrl_raw(struct cs_dsp_coeff_ctl *ctl,
/** /**
* cs_dsp_coeff_write_ctrl() - Writes the given buffer to the given coefficient control * cs_dsp_coeff_write_ctrl() - Writes the given buffer to the given coefficient control
* @ctl: pointer to coefficient control * @ctl: pointer to coefficient control
* @off: word offset at which data should be written
* @buf: the buffer to write to the given control * @buf: the buffer to write to the given control
* @len: the length of the buffer in bytes * @len: the length of the buffer in bytes
* *
...@@ -752,7 +754,8 @@ static int cs_dsp_coeff_write_ctrl_raw(struct cs_dsp_coeff_ctl *ctl, ...@@ -752,7 +754,8 @@ static int cs_dsp_coeff_write_ctrl_raw(struct cs_dsp_coeff_ctl *ctl,
* *
* Return: Zero for success, a negative number on error. * Return: Zero for success, a negative number on error.
*/ */
int cs_dsp_coeff_write_ctrl(struct cs_dsp_coeff_ctl *ctl, const void *buf, size_t len) int cs_dsp_coeff_write_ctrl(struct cs_dsp_coeff_ctl *ctl,
unsigned int off, const void *buf, size_t len)
{ {
int ret = 0; int ret = 0;
...@@ -761,27 +764,31 @@ int cs_dsp_coeff_write_ctrl(struct cs_dsp_coeff_ctl *ctl, const void *buf, size_ ...@@ -761,27 +764,31 @@ int cs_dsp_coeff_write_ctrl(struct cs_dsp_coeff_ctl *ctl, const void *buf, size_
if (!ctl) if (!ctl)
return -ENOENT; return -ENOENT;
if (len + off * sizeof(u32) > ctl->len)
return -EINVAL;
if (ctl->flags & WMFW_CTL_FLAG_VOLATILE) if (ctl->flags & WMFW_CTL_FLAG_VOLATILE)
ret = -EPERM; ret = -EPERM;
else if (buf != ctl->cache) else if (buf != ctl->cache)
memcpy(ctl->cache, buf, len); memcpy(ctl->cache + off * sizeof(u32), buf, len);
ctl->set = 1; ctl->set = 1;
if (ctl->enabled && ctl->dsp->running) if (ctl->enabled && ctl->dsp->running)
ret = cs_dsp_coeff_write_ctrl_raw(ctl, buf, len); ret = cs_dsp_coeff_write_ctrl_raw(ctl, off, buf, len);
return ret; return ret;
} }
EXPORT_SYMBOL_GPL(cs_dsp_coeff_write_ctrl); EXPORT_SYMBOL_GPL(cs_dsp_coeff_write_ctrl);
static int cs_dsp_coeff_read_ctrl_raw(struct cs_dsp_coeff_ctl *ctl, void *buf, size_t len) static int cs_dsp_coeff_read_ctrl_raw(struct cs_dsp_coeff_ctl *ctl,
unsigned int off, void *buf, size_t len)
{ {
struct cs_dsp *dsp = ctl->dsp; struct cs_dsp *dsp = ctl->dsp;
void *scratch; void *scratch;
int ret; int ret;
unsigned int reg; unsigned int reg;
ret = cs_dsp_coeff_base_reg(ctl, &reg); ret = cs_dsp_coeff_base_reg(ctl, &reg, off);
if (ret) if (ret)
return ret; return ret;
...@@ -807,6 +814,7 @@ static int cs_dsp_coeff_read_ctrl_raw(struct cs_dsp_coeff_ctl *ctl, void *buf, s ...@@ -807,6 +814,7 @@ static int cs_dsp_coeff_read_ctrl_raw(struct cs_dsp_coeff_ctl *ctl, void *buf, s
/** /**
* cs_dsp_coeff_read_ctrl() - Reads the given coefficient control into the given buffer * cs_dsp_coeff_read_ctrl() - Reads the given coefficient control into the given buffer
* @ctl: pointer to coefficient control * @ctl: pointer to coefficient control
* @off: word offset at which data should be read
* @buf: the buffer to store to the given control * @buf: the buffer to store to the given control
* @len: the length of the buffer in bytes * @len: the length of the buffer in bytes
* *
...@@ -814,7 +822,8 @@ static int cs_dsp_coeff_read_ctrl_raw(struct cs_dsp_coeff_ctl *ctl, void *buf, s ...@@ -814,7 +822,8 @@ static int cs_dsp_coeff_read_ctrl_raw(struct cs_dsp_coeff_ctl *ctl, void *buf, s
* *
* Return: Zero for success, a negative number on error. * Return: Zero for success, a negative number on error.
*/ */
int cs_dsp_coeff_read_ctrl(struct cs_dsp_coeff_ctl *ctl, void *buf, size_t len) int cs_dsp_coeff_read_ctrl(struct cs_dsp_coeff_ctl *ctl,
unsigned int off, void *buf, size_t len)
{ {
int ret = 0; int ret = 0;
...@@ -823,17 +832,20 @@ int cs_dsp_coeff_read_ctrl(struct cs_dsp_coeff_ctl *ctl, void *buf, size_t len) ...@@ -823,17 +832,20 @@ int cs_dsp_coeff_read_ctrl(struct cs_dsp_coeff_ctl *ctl, void *buf, size_t len)
if (!ctl) if (!ctl)
return -ENOENT; return -ENOENT;
if (len + off * sizeof(u32) > ctl->len)
return -EINVAL;
if (ctl->flags & WMFW_CTL_FLAG_VOLATILE) { if (ctl->flags & WMFW_CTL_FLAG_VOLATILE) {
if (ctl->enabled && ctl->dsp->running) if (ctl->enabled && ctl->dsp->running)
return cs_dsp_coeff_read_ctrl_raw(ctl, buf, len); return cs_dsp_coeff_read_ctrl_raw(ctl, off, buf, len);
else else
return -EPERM; return -EPERM;
} else { } else {
if (!ctl->flags && ctl->enabled && ctl->dsp->running) if (!ctl->flags && ctl->enabled && ctl->dsp->running)
ret = cs_dsp_coeff_read_ctrl_raw(ctl, ctl->cache, ctl->len); ret = cs_dsp_coeff_read_ctrl_raw(ctl, 0, ctl->cache, ctl->len);
if (buf != ctl->cache) if (buf != ctl->cache)
memcpy(buf, ctl->cache, len); memcpy(buf, ctl->cache + off * sizeof(u32), len);
} }
return ret; return ret;
...@@ -857,7 +869,7 @@ static int cs_dsp_coeff_init_control_caches(struct cs_dsp *dsp) ...@@ -857,7 +869,7 @@ static int cs_dsp_coeff_init_control_caches(struct cs_dsp *dsp)
* created so we don't need to do anything. * created so we don't need to do anything.
*/ */
if (!ctl->flags || (ctl->flags & WMFW_CTL_FLAG_READABLE)) { if (!ctl->flags || (ctl->flags & WMFW_CTL_FLAG_READABLE)) {
ret = cs_dsp_coeff_read_ctrl_raw(ctl, ctl->cache, ctl->len); ret = cs_dsp_coeff_read_ctrl_raw(ctl, 0, ctl->cache, ctl->len);
if (ret < 0) if (ret < 0)
return ret; return ret;
} }
...@@ -875,7 +887,7 @@ static int cs_dsp_coeff_sync_controls(struct cs_dsp *dsp) ...@@ -875,7 +887,7 @@ static int cs_dsp_coeff_sync_controls(struct cs_dsp *dsp)
if (!ctl->enabled) if (!ctl->enabled)
continue; continue;
if (ctl->set && !(ctl->flags & WMFW_CTL_FLAG_VOLATILE)) { if (ctl->set && !(ctl->flags & WMFW_CTL_FLAG_VOLATILE)) {
ret = cs_dsp_coeff_write_ctrl_raw(ctl, ctl->cache, ret = cs_dsp_coeff_write_ctrl_raw(ctl, 0, ctl->cache,
ctl->len); ctl->len);
if (ret < 0) if (ret < 0)
return ret; return ret;
......
...@@ -232,8 +232,10 @@ void cs_dsp_init_debugfs(struct cs_dsp *dsp, struct dentry *debugfs_root); ...@@ -232,8 +232,10 @@ void cs_dsp_init_debugfs(struct cs_dsp *dsp, struct dentry *debugfs_root);
void cs_dsp_cleanup_debugfs(struct cs_dsp *dsp); void cs_dsp_cleanup_debugfs(struct cs_dsp *dsp);
int cs_dsp_coeff_write_acked_control(struct cs_dsp_coeff_ctl *ctl, unsigned int event_id); int cs_dsp_coeff_write_acked_control(struct cs_dsp_coeff_ctl *ctl, unsigned int event_id);
int cs_dsp_coeff_write_ctrl(struct cs_dsp_coeff_ctl *ctl, const void *buf, size_t len); int cs_dsp_coeff_write_ctrl(struct cs_dsp_coeff_ctl *ctl, unsigned int off,
int cs_dsp_coeff_read_ctrl(struct cs_dsp_coeff_ctl *ctl, void *buf, size_t len); const void *buf, size_t len);
int cs_dsp_coeff_read_ctrl(struct cs_dsp_coeff_ctl *ctl, unsigned int off,
void *buf, size_t len);
struct cs_dsp_coeff_ctl *cs_dsp_get_ctl(struct cs_dsp *dsp, const char *name, int type, struct cs_dsp_coeff_ctl *cs_dsp_get_ctl(struct cs_dsp *dsp, const char *name, int type,
unsigned int alg); unsigned int alg);
......
...@@ -401,7 +401,7 @@ static int wm_coeff_put(struct snd_kcontrol *kctl, ...@@ -401,7 +401,7 @@ static int wm_coeff_put(struct snd_kcontrol *kctl,
int ret = 0; int ret = 0;
mutex_lock(&cs_ctl->dsp->pwr_lock); mutex_lock(&cs_ctl->dsp->pwr_lock);
ret = cs_dsp_coeff_write_ctrl(cs_ctl, p, cs_ctl->len); ret = cs_dsp_coeff_write_ctrl(cs_ctl, 0, p, cs_ctl->len);
mutex_unlock(&cs_ctl->dsp->pwr_lock); mutex_unlock(&cs_ctl->dsp->pwr_lock);
return ret; return ret;
...@@ -421,7 +421,7 @@ static int wm_coeff_tlv_put(struct snd_kcontrol *kctl, ...@@ -421,7 +421,7 @@ static int wm_coeff_tlv_put(struct snd_kcontrol *kctl,
if (copy_from_user(cs_ctl->cache, bytes, size)) if (copy_from_user(cs_ctl->cache, bytes, size))
ret = -EFAULT; ret = -EFAULT;
else else
ret = cs_dsp_coeff_write_ctrl(cs_ctl, cs_ctl->cache, size); ret = cs_dsp_coeff_write_ctrl(cs_ctl, 0, cs_ctl->cache, size);
mutex_unlock(&cs_ctl->dsp->pwr_lock); mutex_unlock(&cs_ctl->dsp->pwr_lock);
...@@ -464,7 +464,7 @@ static int wm_coeff_get(struct snd_kcontrol *kctl, ...@@ -464,7 +464,7 @@ static int wm_coeff_get(struct snd_kcontrol *kctl,
int ret; int ret;
mutex_lock(&cs_ctl->dsp->pwr_lock); mutex_lock(&cs_ctl->dsp->pwr_lock);
ret = cs_dsp_coeff_read_ctrl(cs_ctl, p, cs_ctl->len); ret = cs_dsp_coeff_read_ctrl(cs_ctl, 0, p, cs_ctl->len);
mutex_unlock(&cs_ctl->dsp->pwr_lock); mutex_unlock(&cs_ctl->dsp->pwr_lock);
return ret; return ret;
...@@ -481,7 +481,7 @@ static int wm_coeff_tlv_get(struct snd_kcontrol *kctl, ...@@ -481,7 +481,7 @@ static int wm_coeff_tlv_get(struct snd_kcontrol *kctl,
mutex_lock(&cs_ctl->dsp->pwr_lock); mutex_lock(&cs_ctl->dsp->pwr_lock);
ret = cs_dsp_coeff_read_ctrl(cs_ctl, cs_ctl->cache, size); ret = cs_dsp_coeff_read_ctrl(cs_ctl, 0, cs_ctl->cache, size);
if (!ret && copy_to_user(bytes, cs_ctl->cache, size)) if (!ret && copy_to_user(bytes, cs_ctl->cache, size))
ret = -EFAULT; ret = -EFAULT;
...@@ -684,7 +684,7 @@ int wm_adsp_write_ctl(struct wm_adsp *dsp, const char *name, int type, ...@@ -684,7 +684,7 @@ int wm_adsp_write_ctl(struct wm_adsp *dsp, const char *name, int type,
if (len > cs_ctl->len) if (len > cs_ctl->len)
return -EINVAL; return -EINVAL;
ret = cs_dsp_coeff_write_ctrl(cs_ctl, buf, len); ret = cs_dsp_coeff_write_ctrl(cs_ctl, 0, buf, len);
if (ret) if (ret)
return ret; return ret;
...@@ -723,7 +723,7 @@ int wm_adsp_read_ctl(struct wm_adsp *dsp, const char *name, int type, ...@@ -723,7 +723,7 @@ int wm_adsp_read_ctl(struct wm_adsp *dsp, const char *name, int type,
if (len > cs_ctl->len) if (len > cs_ctl->len)
return -EINVAL; return -EINVAL;
return cs_dsp_coeff_read_ctrl(cs_ctl, buf, len); return cs_dsp_coeff_read_ctrl(cs_ctl, 0, buf, len);
} }
EXPORT_SYMBOL_GPL(wm_adsp_read_ctl); EXPORT_SYMBOL_GPL(wm_adsp_read_ctl);
...@@ -1432,7 +1432,7 @@ static int wm_adsp_buffer_parse_coeff(struct cs_dsp_coeff_ctl *cs_ctl) ...@@ -1432,7 +1432,7 @@ static int wm_adsp_buffer_parse_coeff(struct cs_dsp_coeff_ctl *cs_ctl)
int ret, i; int ret, i;
for (i = 0; i < 5; ++i) { for (i = 0; i < 5; ++i) {
ret = cs_dsp_coeff_read_ctrl(cs_ctl, &coeff_v1, sizeof(coeff_v1)); ret = cs_dsp_coeff_read_ctrl(cs_ctl, 0, &coeff_v1, sizeof(coeff_v1));
if (ret < 0) if (ret < 0)
return ret; return ret;
......
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