summaryrefslogtreecommitdiff
path: root/sound
diff options
context:
space:
mode:
authorRanjani Sridharan <ranjani.sridharan@linux.intel.com>2022-03-17 10:50:34 -0700
committerMark Brown <broonie@kernel.org>2022-03-18 16:04:43 +0000
commit544ac8858f249950b4d99c68e538cdc07300528f (patch)
treea4b8d7042bf3c6a9b263805a18d34e20c731d8bc /sound
parent049307aad2a355f7b44736eeb5795d6d4499fd12 (diff)
ASoC: SOF: Add bytes_get/put control IPC ops for IPC3
Define and set the bytes_get/put IPC control ops for IPC3. Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com> Reviewed-by: Péter Ujfalusi <peter.ujfalusi@linux.intel.com> Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com> Link: https://lore.kernel.org/r/20220317175044.1752400-10-ranjani.sridharan@linux.intel.com Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'sound')
-rw-r--r--sound/soc/sof/control.c64
-rw-r--r--sound/soc/sof/ipc3-control.c67
2 files changed, 77 insertions, 54 deletions
diff --git a/sound/soc/sof/control.c b/sound/soc/sof/control.c
index 499d426c5d38..2a4997e1cd1e 100644
--- a/sound/soc/sof/control.c
+++ b/sound/soc/sof/control.c
@@ -190,35 +190,14 @@ int snd_sof_enum_put(struct snd_kcontrol *kcontrol,
int snd_sof_bytes_get(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
- struct soc_bytes_ext *be =
- (struct soc_bytes_ext *)kcontrol->private_value;
+ struct soc_bytes_ext *be = (struct soc_bytes_ext *)kcontrol->private_value;
struct snd_sof_control *scontrol = be->dobj.private;
struct snd_soc_component *scomp = scontrol->scomp;
- struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
- struct sof_abi_hdr *data = cdata->data;
- size_t size;
-
- snd_sof_refresh_control(scontrol);
-
- if (be->max > sizeof(ucontrol->value.bytes.data)) {
- dev_err_ratelimited(scomp->dev,
- "error: data max %d exceeds ucontrol data array size\n",
- be->max);
- return -EINVAL;
- }
-
- /* be->max has been verified to be >= sizeof(struct sof_abi_hdr) */
- if (data->size > be->max - sizeof(*data)) {
- dev_err_ratelimited(scomp->dev,
- "error: %u bytes of control data is invalid, max is %zu\n",
- data->size, be->max - sizeof(*data));
- return -EINVAL;
- }
-
- size = data->size + sizeof(*data);
+ struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
+ const struct sof_ipc_tplg_ops *tplg_ops = sdev->ipc->ops->tplg;
- /* copy back to kcontrol */
- memcpy(ucontrol->value.bytes.data, data, size);
+ if (tplg_ops->control->bytes_get)
+ return tplg_ops->control->bytes_get(scontrol, ucontrol);
return 0;
}
@@ -226,37 +205,14 @@ int snd_sof_bytes_get(struct snd_kcontrol *kcontrol,
int snd_sof_bytes_put(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
- struct soc_bytes_ext *be =
- (struct soc_bytes_ext *)kcontrol->private_value;
+ struct soc_bytes_ext *be = (struct soc_bytes_ext *)kcontrol->private_value;
struct snd_sof_control *scontrol = be->dobj.private;
struct snd_soc_component *scomp = scontrol->scomp;
- struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
- struct sof_abi_hdr *data = cdata->data;
- size_t size;
-
- if (be->max > sizeof(ucontrol->value.bytes.data)) {
- dev_err_ratelimited(scomp->dev,
- "error: data max %d exceeds ucontrol data array size\n",
- be->max);
- return -EINVAL;
- }
-
- /* be->max has been verified to be >= sizeof(struct sof_abi_hdr) */
- if (data->size > be->max - sizeof(*data)) {
- dev_err_ratelimited(scomp->dev,
- "error: data size too big %u bytes max is %zu\n",
- data->size, be->max - sizeof(*data));
- return -EINVAL;
- }
-
- size = data->size + sizeof(*data);
-
- /* copy from kcontrol */
- memcpy(data, ucontrol->value.bytes.data, size);
+ struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
+ const struct sof_ipc_tplg_ops *tplg_ops = sdev->ipc->ops->tplg;
- /* notify DSP of byte control updates */
- if (pm_runtime_active(scomp->dev))
- snd_sof_ipc_set_get_comp_data(scontrol, true);
+ if (tplg_ops->control->bytes_put)
+ return tplg_ops->control->bytes_put(scontrol, ucontrol);
return 0;
}
diff --git a/sound/soc/sof/ipc3-control.c b/sound/soc/sof/ipc3-control.c
index 03948f8f7eb0..df8e4df9663d 100644
--- a/sound/soc/sof/ipc3-control.c
+++ b/sound/soc/sof/ipc3-control.c
@@ -205,6 +205,71 @@ static bool sof_ipc3_enum_put(struct snd_sof_control *scontrol,
return change;
}
+static int sof_ipc3_bytes_get(struct snd_sof_control *scontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
+ struct snd_soc_component *scomp = scontrol->scomp;
+ struct sof_abi_hdr *data = cdata->data;
+ size_t size;
+
+ snd_sof_refresh_control(scontrol);
+
+ if (scontrol->max_size > sizeof(ucontrol->value.bytes.data)) {
+ dev_err_ratelimited(scomp->dev, "data max %zu exceeds ucontrol data array size\n",
+ scontrol->max_size);
+ return -EINVAL;
+ }
+
+ /* be->max has been verified to be >= sizeof(struct sof_abi_hdr) */
+ if (data->size > scontrol->max_size - sizeof(*data)) {
+ dev_err_ratelimited(scomp->dev,
+ "%u bytes of control data is invalid, max is %zu\n",
+ data->size, scontrol->max_size - sizeof(*data));
+ return -EINVAL;
+ }
+
+ size = data->size + sizeof(*data);
+
+ /* copy back to kcontrol */
+ memcpy(ucontrol->value.bytes.data, data, size);
+
+ return 0;
+}
+
+static int sof_ipc3_bytes_put(struct snd_sof_control *scontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
+ struct snd_soc_component *scomp = scontrol->scomp;
+ struct sof_abi_hdr *data = cdata->data;
+ size_t size;
+
+ if (scontrol->max_size > sizeof(ucontrol->value.bytes.data)) {
+ dev_err_ratelimited(scomp->dev, "data max %zu exceeds ucontrol data array size\n",
+ scontrol->max_size);
+ return -EINVAL;
+ }
+
+ /* scontrol->max_size has been verified to be >= sizeof(struct sof_abi_hdr) */
+ if (data->size > scontrol->max_size - sizeof(*data)) {
+ dev_err_ratelimited(scomp->dev, "data size too big %u bytes max is %zu\n",
+ data->size, scontrol->max_size - sizeof(*data));
+ return -EINVAL;
+ }
+
+ size = data->size + sizeof(*data);
+
+ /* copy from kcontrol */
+ memcpy(data, ucontrol->value.bytes.data, size);
+
+ /* notify DSP of byte control updates */
+ if (pm_runtime_active(scomp->dev))
+ return snd_sof_ipc_set_get_comp_data(scontrol, true);
+
+ return 0;
+}
+
static void snd_sof_update_control(struct snd_sof_control *scontrol,
struct sof_ipc_ctrl_data *cdata)
{
@@ -352,5 +417,7 @@ const struct sof_ipc_tplg_control_ops tplg_ipc3_control_ops = {
.switch_get = sof_ipc3_switch_get,
.enum_put = sof_ipc3_enum_put,
.enum_get = sof_ipc3_enum_get,
+ .bytes_put = sof_ipc3_bytes_put,
+ .bytes_get = sof_ipc3_bytes_get,
.update = sof_ipc3_control_update,
};