Skip to content

Commit 544ac88

Browse files
ranj063broonie
authored andcommitted
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>
1 parent 049307a commit 544ac88

2 files changed

Lines changed: 77 additions & 54 deletions

File tree

sound/soc/sof/control.c

Lines changed: 10 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -190,73 +190,29 @@ int snd_sof_enum_put(struct snd_kcontrol *kcontrol,
190190
int snd_sof_bytes_get(struct snd_kcontrol *kcontrol,
191191
struct snd_ctl_elem_value *ucontrol)
192192
{
193-
struct soc_bytes_ext *be =
194-
(struct soc_bytes_ext *)kcontrol->private_value;
193+
struct soc_bytes_ext *be = (struct soc_bytes_ext *)kcontrol->private_value;
195194
struct snd_sof_control *scontrol = be->dobj.private;
196195
struct snd_soc_component *scomp = scontrol->scomp;
197-
struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
198-
struct sof_abi_hdr *data = cdata->data;
199-
size_t size;
200-
201-
snd_sof_refresh_control(scontrol);
202-
203-
if (be->max > sizeof(ucontrol->value.bytes.data)) {
204-
dev_err_ratelimited(scomp->dev,
205-
"error: data max %d exceeds ucontrol data array size\n",
206-
be->max);
207-
return -EINVAL;
208-
}
209-
210-
/* be->max has been verified to be >= sizeof(struct sof_abi_hdr) */
211-
if (data->size > be->max - sizeof(*data)) {
212-
dev_err_ratelimited(scomp->dev,
213-
"error: %u bytes of control data is invalid, max is %zu\n",
214-
data->size, be->max - sizeof(*data));
215-
return -EINVAL;
216-
}
217-
218-
size = data->size + sizeof(*data);
196+
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
197+
const struct sof_ipc_tplg_ops *tplg_ops = sdev->ipc->ops->tplg;
219198

220-
/* copy back to kcontrol */
221-
memcpy(ucontrol->value.bytes.data, data, size);
199+
if (tplg_ops->control->bytes_get)
200+
return tplg_ops->control->bytes_get(scontrol, ucontrol);
222201

223202
return 0;
224203
}
225204

226205
int snd_sof_bytes_put(struct snd_kcontrol *kcontrol,
227206
struct snd_ctl_elem_value *ucontrol)
228207
{
229-
struct soc_bytes_ext *be =
230-
(struct soc_bytes_ext *)kcontrol->private_value;
208+
struct soc_bytes_ext *be = (struct soc_bytes_ext *)kcontrol->private_value;
231209
struct snd_sof_control *scontrol = be->dobj.private;
232210
struct snd_soc_component *scomp = scontrol->scomp;
233-
struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
234-
struct sof_abi_hdr *data = cdata->data;
235-
size_t size;
236-
237-
if (be->max > sizeof(ucontrol->value.bytes.data)) {
238-
dev_err_ratelimited(scomp->dev,
239-
"error: data max %d exceeds ucontrol data array size\n",
240-
be->max);
241-
return -EINVAL;
242-
}
243-
244-
/* be->max has been verified to be >= sizeof(struct sof_abi_hdr) */
245-
if (data->size > be->max - sizeof(*data)) {
246-
dev_err_ratelimited(scomp->dev,
247-
"error: data size too big %u bytes max is %zu\n",
248-
data->size, be->max - sizeof(*data));
249-
return -EINVAL;
250-
}
251-
252-
size = data->size + sizeof(*data);
253-
254-
/* copy from kcontrol */
255-
memcpy(data, ucontrol->value.bytes.data, size);
211+
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
212+
const struct sof_ipc_tplg_ops *tplg_ops = sdev->ipc->ops->tplg;
256213

257-
/* notify DSP of byte control updates */
258-
if (pm_runtime_active(scomp->dev))
259-
snd_sof_ipc_set_get_comp_data(scontrol, true);
214+
if (tplg_ops->control->bytes_put)
215+
return tplg_ops->control->bytes_put(scontrol, ucontrol);
260216

261217
return 0;
262218
}

sound/soc/sof/ipc3-control.c

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,71 @@ static bool sof_ipc3_enum_put(struct snd_sof_control *scontrol,
205205
return change;
206206
}
207207

208+
static int sof_ipc3_bytes_get(struct snd_sof_control *scontrol,
209+
struct snd_ctl_elem_value *ucontrol)
210+
{
211+
struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
212+
struct snd_soc_component *scomp = scontrol->scomp;
213+
struct sof_abi_hdr *data = cdata->data;
214+
size_t size;
215+
216+
snd_sof_refresh_control(scontrol);
217+
218+
if (scontrol->max_size > sizeof(ucontrol->value.bytes.data)) {
219+
dev_err_ratelimited(scomp->dev, "data max %zu exceeds ucontrol data array size\n",
220+
scontrol->max_size);
221+
return -EINVAL;
222+
}
223+
224+
/* be->max has been verified to be >= sizeof(struct sof_abi_hdr) */
225+
if (data->size > scontrol->max_size - sizeof(*data)) {
226+
dev_err_ratelimited(scomp->dev,
227+
"%u bytes of control data is invalid, max is %zu\n",
228+
data->size, scontrol->max_size - sizeof(*data));
229+
return -EINVAL;
230+
}
231+
232+
size = data->size + sizeof(*data);
233+
234+
/* copy back to kcontrol */
235+
memcpy(ucontrol->value.bytes.data, data, size);
236+
237+
return 0;
238+
}
239+
240+
static int sof_ipc3_bytes_put(struct snd_sof_control *scontrol,
241+
struct snd_ctl_elem_value *ucontrol)
242+
{
243+
struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
244+
struct snd_soc_component *scomp = scontrol->scomp;
245+
struct sof_abi_hdr *data = cdata->data;
246+
size_t size;
247+
248+
if (scontrol->max_size > sizeof(ucontrol->value.bytes.data)) {
249+
dev_err_ratelimited(scomp->dev, "data max %zu exceeds ucontrol data array size\n",
250+
scontrol->max_size);
251+
return -EINVAL;
252+
}
253+
254+
/* scontrol->max_size has been verified to be >= sizeof(struct sof_abi_hdr) */
255+
if (data->size > scontrol->max_size - sizeof(*data)) {
256+
dev_err_ratelimited(scomp->dev, "data size too big %u bytes max is %zu\n",
257+
data->size, scontrol->max_size - sizeof(*data));
258+
return -EINVAL;
259+
}
260+
261+
size = data->size + sizeof(*data);
262+
263+
/* copy from kcontrol */
264+
memcpy(data, ucontrol->value.bytes.data, size);
265+
266+
/* notify DSP of byte control updates */
267+
if (pm_runtime_active(scomp->dev))
268+
return snd_sof_ipc_set_get_comp_data(scontrol, true);
269+
270+
return 0;
271+
}
272+
208273
static void snd_sof_update_control(struct snd_sof_control *scontrol,
209274
struct sof_ipc_ctrl_data *cdata)
210275
{
@@ -352,5 +417,7 @@ const struct sof_ipc_tplg_control_ops tplg_ipc3_control_ops = {
352417
.switch_get = sof_ipc3_switch_get,
353418
.enum_put = sof_ipc3_enum_put,
354419
.enum_get = sof_ipc3_enum_get,
420+
.bytes_put = sof_ipc3_bytes_put,
421+
.bytes_get = sof_ipc3_bytes_get,
355422
.update = sof_ipc3_control_update,
356423
};

0 commit comments

Comments
 (0)