Skip to content

Commit a666874

Browse files
ranj063broonie
authored andcommitted
ASoC: SOF: Add switch get/put IPC3 ops
Add the switch_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-8-ranjani.sridharan@linux.intel.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 838d04f commit a666874

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
@@ -127,49 +127,34 @@ int snd_sof_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info
127127
int snd_sof_switch_get(struct snd_kcontrol *kcontrol,
128128
struct snd_ctl_elem_value *ucontrol)
129129
{
130-
struct soc_mixer_control *sm =
131-
(struct soc_mixer_control *)kcontrol->private_value;
130+
struct soc_mixer_control *sm = (struct soc_mixer_control *)kcontrol->private_value;
132131
struct snd_sof_control *scontrol = sm->dobj.private;
133-
struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
134-
unsigned int i, channels = scontrol->num_channels;
135-
136-
snd_sof_refresh_control(scontrol);
132+
struct snd_soc_component *scomp = scontrol->scomp;
133+
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
134+
const struct sof_ipc_tplg_ops *tplg_ops = sdev->ipc->ops->tplg;
137135

138-
/* read back each channel */
139-
for (i = 0; i < channels; i++)
140-
ucontrol->value.integer.value[i] = cdata->chanv[i].value;
136+
if (tplg_ops->control->switch_get)
137+
return tplg_ops->control->switch_get(scontrol, ucontrol);
141138

142139
return 0;
143140
}
144141

145142
int snd_sof_switch_put(struct snd_kcontrol *kcontrol,
146143
struct snd_ctl_elem_value *ucontrol)
147144
{
148-
struct soc_mixer_control *sm =
149-
(struct soc_mixer_control *)kcontrol->private_value;
145+
struct soc_mixer_control *sm = (struct soc_mixer_control *)kcontrol->private_value;
150146
struct snd_sof_control *scontrol = sm->dobj.private;
151147
struct snd_soc_component *scomp = scontrol->scomp;
152-
struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
153-
unsigned int i, channels = scontrol->num_channels;
154-
bool change = false;
155-
u32 value;
156-
157-
/* update each channel */
158-
for (i = 0; i < channels; i++) {
159-
value = ucontrol->value.integer.value[i];
160-
change = change || (value != cdata->chanv[i].value);
161-
cdata->chanv[i].channel = i;
162-
cdata->chanv[i].value = value;
163-
}
148+
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
149+
const struct sof_ipc_tplg_ops *tplg_ops = sdev->ipc->ops->tplg;
164150

165151
if (scontrol->led_ctl.use_led)
166152
update_mute_led(scontrol, kcontrol, ucontrol);
167153

168-
/* notify DSP of mixer updates */
169-
if (pm_runtime_active(scomp->dev))
170-
snd_sof_ipc_set_get_comp_data(scontrol, true);
154+
if (tplg_ops->control->switch_put)
155+
return tplg_ops->control->switch_put(scontrol, ucontrol);
171156

172-
return change;
157+
return false;
173158
}
174159

175160
int snd_sof_enum_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
@@ -109,6 +109,54 @@ static bool sof_ipc3_volume_put(struct snd_sof_control *scontrol,
109109
return change;
110110
}
111111

112+
static int sof_ipc3_switch_get(struct snd_sof_control *scontrol,
113+
struct snd_ctl_elem_value *ucontrol)
114+
{
115+
struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
116+
unsigned int channels = scontrol->num_channels;
117+
unsigned int i;
118+
119+
snd_sof_refresh_control(scontrol);
120+
121+
/* read back each channel */
122+
for (i = 0; i < channels; i++)
123+
ucontrol->value.integer.value[i] = cdata->chanv[i].value;
124+
125+
return 0;
126+
}
127+
128+
static bool sof_ipc3_switch_put(struct snd_sof_control *scontrol,
129+
struct snd_ctl_elem_value *ucontrol)
130+
{
131+
struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
132+
struct snd_soc_component *scomp = scontrol->scomp;
133+
unsigned int channels = scontrol->num_channels;
134+
unsigned int i;
135+
bool change = false;
136+
u32 value;
137+
138+
/* update each channel */
139+
for (i = 0; i < channels; i++) {
140+
value = ucontrol->value.integer.value[i];
141+
change = change || (value != cdata->chanv[i].value);
142+
cdata->chanv[i].channel = i;
143+
cdata->chanv[i].value = value;
144+
}
145+
146+
/* notify DSP of mixer updates */
147+
if (pm_runtime_active(scomp->dev)) {
148+
int ret = snd_sof_ipc_set_get_comp_data(scontrol, true);
149+
150+
if (ret < 0) {
151+
dev_err(scomp->dev, "Failed to set mixer updates for %s\n",
152+
scontrol->name);
153+
return false;
154+
}
155+
}
156+
157+
return change;
158+
}
159+
112160
static void snd_sof_update_control(struct snd_sof_control *scontrol,
113161
struct sof_ipc_ctrl_data *cdata)
114162
{
@@ -252,5 +300,7 @@ static void sof_ipc3_control_update(struct snd_sof_dev *sdev, void *ipc_control_
252300
const struct sof_ipc_tplg_control_ops tplg_ipc3_control_ops = {
253301
.volume_put = sof_ipc3_volume_put,
254302
.volume_get = sof_ipc3_volume_get,
303+
.switch_put = sof_ipc3_switch_put,
304+
.switch_get = sof_ipc3_switch_get,
255305
.update = sof_ipc3_control_update,
256306
};

0 commit comments

Comments
 (0)