Commit eb65ccdb authored by Li Xu's avatar Li Xu Committed by Mark Brown

ASoC: wm_adsp: Expose mixer control API

Expose mixer control API for reading and writing controls from the kernel.
This API can be used by ALSA kernel drivers with ADSP support to
read and write firmware-defined memory regions.
Signed-off-by: default avatarLi Xu <li.xu@cirrus.com>
Signed-off-by: default avatarDavid Rhodes <david.rhodes@cirrus.com>
Acked-by: default avatarCharles Keepax <ckeepax@opensource.cirrus.com>
Link: https://lore.kernel.org/r/1573847653-17094-2-git-send-email-david.rhodes@cirrus.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent e48fdb53
...@@ -599,6 +599,9 @@ struct wm_coeff_ctl_ops { ...@@ -599,6 +599,9 @@ struct wm_coeff_ctl_ops {
struct wm_coeff_ctl { struct wm_coeff_ctl {
const char *name; const char *name;
const char *fw_name; const char *fw_name;
/* Subname is needed to match with firmware */
const char *subname;
unsigned int subname_len;
struct wm_adsp_alg_region alg_region; struct wm_adsp_alg_region alg_region;
struct wm_coeff_ctl_ops ops; struct wm_coeff_ctl_ops ops;
struct wm_adsp *dsp; struct wm_adsp *dsp;
...@@ -1399,6 +1402,7 @@ static void wm_adsp_free_ctl_blk(struct wm_coeff_ctl *ctl) ...@@ -1399,6 +1402,7 @@ static void wm_adsp_free_ctl_blk(struct wm_coeff_ctl *ctl)
{ {
kfree(ctl->cache); kfree(ctl->cache);
kfree(ctl->name); kfree(ctl->name);
kfree(ctl->subname);
kfree(ctl); kfree(ctl);
} }
...@@ -1472,6 +1476,15 @@ static int wm_adsp_create_control(struct wm_adsp *dsp, ...@@ -1472,6 +1476,15 @@ static int wm_adsp_create_control(struct wm_adsp *dsp,
ret = -ENOMEM; ret = -ENOMEM;
goto err_ctl; goto err_ctl;
} }
if (subname) {
ctl->subname_len = subname_len;
ctl->subname = kmemdup(subname,
strlen(subname) + 1, GFP_KERNEL);
if (!ctl->subname) {
ret = -ENOMEM;
goto err_ctl_name;
}
}
ctl->enabled = 1; ctl->enabled = 1;
ctl->set = 0; ctl->set = 0;
ctl->ops.xget = wm_coeff_get; ctl->ops.xget = wm_coeff_get;
...@@ -1485,7 +1498,7 @@ static int wm_adsp_create_control(struct wm_adsp *dsp, ...@@ -1485,7 +1498,7 @@ static int wm_adsp_create_control(struct wm_adsp *dsp,
ctl->cache = kzalloc(ctl->len, GFP_KERNEL); ctl->cache = kzalloc(ctl->len, GFP_KERNEL);
if (!ctl->cache) { if (!ctl->cache) {
ret = -ENOMEM; ret = -ENOMEM;
goto err_ctl_name; goto err_ctl_subname;
} }
list_add(&ctl->list, &dsp->ctl_list); list_add(&ctl->list, &dsp->ctl_list);
...@@ -1508,6 +1521,8 @@ static int wm_adsp_create_control(struct wm_adsp *dsp, ...@@ -1508,6 +1521,8 @@ static int wm_adsp_create_control(struct wm_adsp *dsp,
err_ctl_cache: err_ctl_cache:
kfree(ctl->cache); kfree(ctl->cache);
err_ctl_subname:
kfree(ctl->subname);
err_ctl_name: err_ctl_name:
kfree(ctl->name); kfree(ctl->name);
err_ctl: err_ctl:
...@@ -1995,6 +2010,70 @@ static int wm_adsp_load(struct wm_adsp *dsp) ...@@ -1995,6 +2010,70 @@ static int wm_adsp_load(struct wm_adsp *dsp)
return ret; return ret;
} }
/*
* Find wm_coeff_ctl with input name as its subname
* If not found, return NULL
*/
static struct wm_coeff_ctl *wm_adsp_get_ctl(struct wm_adsp *dsp,
const char *name, int type,
unsigned int alg)
{
struct wm_coeff_ctl *pos, *rslt = NULL;
list_for_each_entry(pos, &dsp->ctl_list, list) {
if (!pos->subname)
continue;
if (strncmp(pos->subname, name, pos->subname_len) == 0 &&
pos->alg_region.alg == alg &&
pos->alg_region.type == type) {
rslt = pos;
break;
}
}
return rslt;
}
int wm_adsp_write_ctl(struct wm_adsp *dsp, const char *name, int type,
unsigned int alg, void *buf, size_t len)
{
struct wm_coeff_ctl *ctl;
struct snd_kcontrol *kcontrol;
int ret;
ctl = wm_adsp_get_ctl(dsp, name, type, alg);
if (!ctl)
return -EINVAL;
if (len > ctl->len)
return -EINVAL;
ret = wm_coeff_write_control(ctl, buf, len);
kcontrol = snd_soc_card_get_kcontrol(dsp->component->card, ctl->name);
snd_ctl_notify(dsp->component->card->snd_card,
SNDRV_CTL_EVENT_MASK_VALUE, &kcontrol->id);
return ret;
}
EXPORT_SYMBOL_GPL(wm_adsp_write_ctl);
int wm_adsp_read_ctl(struct wm_adsp *dsp, const char *name, int type,
unsigned int alg, void *buf, size_t len)
{
struct wm_coeff_ctl *ctl;
ctl = wm_adsp_get_ctl(dsp, name, type, alg);
if (!ctl)
return -EINVAL;
if (len > ctl->len)
return -EINVAL;
return wm_coeff_read_control(ctl, buf, len);
}
EXPORT_SYMBOL_GPL(wm_adsp_read_ctl);
static void wm_adsp_ctl_fixup_base(struct wm_adsp *dsp, static void wm_adsp_ctl_fixup_base(struct wm_adsp *dsp,
const struct wm_adsp_alg_region *alg_region) const struct wm_adsp_alg_region *alg_region)
{ {
......
...@@ -201,5 +201,9 @@ int wm_adsp_compr_pointer(struct snd_compr_stream *stream, ...@@ -201,5 +201,9 @@ int wm_adsp_compr_pointer(struct snd_compr_stream *stream,
struct snd_compr_tstamp *tstamp); struct snd_compr_tstamp *tstamp);
int wm_adsp_compr_copy(struct snd_compr_stream *stream, int wm_adsp_compr_copy(struct snd_compr_stream *stream,
char __user *buf, size_t count); char __user *buf, size_t count);
int wm_adsp_write_ctl(struct wm_adsp *dsp, const char *name, int type,
unsigned int alg, void *buf, size_t len);
int wm_adsp_read_ctl(struct wm_adsp *dsp, const char *name, int type,
unsigned int alg, void *buf, size_t len);
#endif #endif
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