Skip to content

Commit 049307a

Browse files
ranj063broonie
authored andcommitted
ASoC: SOF: Add enum_get/put control ops for IPC3
Define and set the enum_get/put control IPC 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-9-ranjani.sridharan@linux.intel.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent a666874 commit 049307a

2 files changed

Lines changed: 62 additions & 27 deletions

File tree

sound/soc/sof/control.c

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -160,46 +160,31 @@ int snd_sof_switch_put(struct snd_kcontrol *kcontrol,
160160
int snd_sof_enum_get(struct snd_kcontrol *kcontrol,
161161
struct snd_ctl_elem_value *ucontrol)
162162
{
163-
struct soc_enum *se =
164-
(struct soc_enum *)kcontrol->private_value;
163+
struct soc_enum *se = (struct soc_enum *)kcontrol->private_value;
165164
struct snd_sof_control *scontrol = se->dobj.private;
166-
struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
167-
unsigned int i, channels = scontrol->num_channels;
168-
169-
snd_sof_refresh_control(scontrol);
165+
struct snd_soc_component *scomp = scontrol->scomp;
166+
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
167+
const struct sof_ipc_tplg_ops *tplg_ops = sdev->ipc->ops->tplg;
170168

171-
/* read back each channel */
172-
for (i = 0; i < channels; i++)
173-
ucontrol->value.enumerated.item[i] = cdata->chanv[i].value;
169+
if (tplg_ops->control->enum_get)
170+
return tplg_ops->control->enum_get(scontrol, ucontrol);
174171

175172
return 0;
176173
}
177174

178175
int snd_sof_enum_put(struct snd_kcontrol *kcontrol,
179176
struct snd_ctl_elem_value *ucontrol)
180177
{
181-
struct soc_enum *se =
182-
(struct soc_enum *)kcontrol->private_value;
178+
struct soc_enum *se = (struct soc_enum *)kcontrol->private_value;
183179
struct snd_sof_control *scontrol = se->dobj.private;
184180
struct snd_soc_component *scomp = scontrol->scomp;
185-
struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
186-
unsigned int i, channels = scontrol->num_channels;
187-
bool change = false;
188-
u32 value;
189-
190-
/* update each channel */
191-
for (i = 0; i < channels; i++) {
192-
value = ucontrol->value.enumerated.item[i];
193-
change = change || (value != cdata->chanv[i].value);
194-
cdata->chanv[i].channel = i;
195-
cdata->chanv[i].value = value;
196-
}
181+
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
182+
const struct sof_ipc_tplg_ops *tplg_ops = sdev->ipc->ops->tplg;
197183

198-
/* notify DSP of enum updates */
199-
if (pm_runtime_active(scomp->dev))
200-
snd_sof_ipc_set_get_comp_data(scontrol, true);
184+
if (tplg_ops->control->enum_put)
185+
return tplg_ops->control->enum_put(scontrol, ucontrol);
201186

202-
return change;
187+
return false;
203188
}
204189

205190
int snd_sof_bytes_get(struct snd_kcontrol *kcontrol,

sound/soc/sof/ipc3-control.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,54 @@ static bool sof_ipc3_switch_put(struct snd_sof_control *scontrol,
157157
return change;
158158
}
159159

160+
static int sof_ipc3_enum_get(struct snd_sof_control *scontrol,
161+
struct snd_ctl_elem_value *ucontrol)
162+
{
163+
struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
164+
unsigned int channels = scontrol->num_channels;
165+
unsigned int i;
166+
167+
snd_sof_refresh_control(scontrol);
168+
169+
/* read back each channel */
170+
for (i = 0; i < channels; i++)
171+
ucontrol->value.enumerated.item[i] = cdata->chanv[i].value;
172+
173+
return 0;
174+
}
175+
176+
static bool sof_ipc3_enum_put(struct snd_sof_control *scontrol,
177+
struct snd_ctl_elem_value *ucontrol)
178+
{
179+
struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
180+
struct snd_soc_component *scomp = scontrol->scomp;
181+
unsigned int channels = scontrol->num_channels;
182+
unsigned int i;
183+
bool change = false;
184+
u32 value;
185+
186+
/* update each channel */
187+
for (i = 0; i < channels; i++) {
188+
value = ucontrol->value.enumerated.item[i];
189+
change = change || (value != cdata->chanv[i].value);
190+
cdata->chanv[i].channel = i;
191+
cdata->chanv[i].value = value;
192+
}
193+
194+
/* notify DSP of enum updates */
195+
if (pm_runtime_active(scomp->dev)) {
196+
int ret = snd_sof_ipc_set_get_comp_data(scontrol, true);
197+
198+
if (ret < 0) {
199+
dev_err(scomp->dev, "Failed to set enum updates for %s\n",
200+
scontrol->name);
201+
return false;
202+
}
203+
}
204+
205+
return change;
206+
}
207+
160208
static void snd_sof_update_control(struct snd_sof_control *scontrol,
161209
struct sof_ipc_ctrl_data *cdata)
162210
{
@@ -302,5 +350,7 @@ const struct sof_ipc_tplg_control_ops tplg_ipc3_control_ops = {
302350
.volume_get = sof_ipc3_volume_get,
303351
.switch_put = sof_ipc3_switch_put,
304352
.switch_get = sof_ipc3_switch_get,
353+
.enum_put = sof_ipc3_enum_put,
354+
.enum_get = sof_ipc3_enum_get,
305355
.update = sof_ipc3_control_update,
306356
};

0 commit comments

Comments
 (0)