Skip to content

Commit 8bf95cb

Browse files
ranj063plbossart
authored andcommitted
ASoC: SOF: Add a new op to set up volume table
Add a new op set_up_volume_table for control IPC ops. Define and set the op for IPC3. Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
1 parent 04c5359 commit 8bf95cb

3 files changed

Lines changed: 35 additions & 15 deletions

File tree

‎sound/soc/sof/ipc3-control.c‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,23 @@ static int sof_ipc3_widget_kcontrol_setup(struct snd_sof_dev *sdev,
694694
return0;
695695
}
696696

697+
staticint
698+
sof_ipc3_set_up_volume_table(structsnd_sof_control*scontrol, inttlv[SOF_TLV_ITEMS], intsize)
699+
{
700+
inti;
701+
702+
/* init the volume table */
703+
scontrol->volume_table=kcalloc(size, sizeof(u32), GFP_KERNEL);
704+
if (!scontrol->volume_table)
705+
return-ENOMEM;
706+
707+
/* populate the volume table */
708+
for (i=0; i<size ; i++)
709+
scontrol->volume_table[i] =vol_compute_gain(i, tlv);
710+
711+
return0;
712+
}
713+
697714
conststructipc_tplg_control_opstplg_ipc3_control_ops= {
698715
.volume_put=sof_ipc3_volume_put,
699716
.volume_get=sof_ipc3_volume_get,
@@ -708,4 +725,5 @@ const struct ipc_tplg_control_ops tplg_ipc3_control_ops = {
708725
.bytes_ext_volatile_get=sof_ipc3_bytes_ext_volatile_get,
709726
.update=sof_ipc3_control_update,
710727
.widget_kcontrol_setup=sof_ipc3_widget_kcontrol_setup,
728+
.set_up_volume_table=sof_ipc3_set_up_volume_table,
711729
};

‎sound/soc/sof/sof-audio.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
*/
4040
#defineVOLUME_FWL 16
4141

42+
#defineSOF_TLV_ITEMS 3
43+
4244
structsnd_sof_widget;
4345
structsnd_sof_route;
4446
structsnd_sof_control;
@@ -88,6 +90,9 @@ struct ipc_tplg_control_ops {
8890
void (*update)(structsnd_sof_dev*sdev, void*ipc_control_message);
8991
/* Optional callback to setup kcontrols associated with an swidget */
9092
int (*widget_kcontrol_setup)(structsnd_sof_dev*sdev, structsnd_sof_widget*swidget);
93+
/* mandatory callback to set up volume table for volume kcontrols */
94+
int (*set_up_volume_table)(structsnd_sof_control*scontrol, inttlv[SOF_TLV_ITEMS],
95+
intsize);
9196
};
9297

9398
/**
@@ -465,4 +470,5 @@ int sof_update_ipc_object(struct snd_soc_component *scomp, void *object, enum so
465470
size_tobject_size, inttoken_instance_num);
466471
intsof_pcm_setup_connected_widgets(structsnd_sof_dev*sdev, structsnd_soc_pcm_runtime*rtd,
467472
structsnd_sof_pcm*spcm, intdir);
473+
u32vol_compute_gain(u32value, int*tlv);
468474
#endif

‎sound/soc/sof/topology.c‎

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#defineVOL_HALF_DB_STEP 50
3333

3434
/* TLV data items */
35-
#defineTLV_ITEMS 3
3635
#defineTLV_MIN 0
3736
#defineTLV_STEP 1
3837
#defineTLV_MUTE 2
@@ -133,7 +132,7 @@ int sof_update_ipc_object(struct snd_soc_component *scomp, void *object, enum so
133132
return0;
134133
}
135134

136-
staticinlineintget_tlv_data(constint*p, inttlv[TLV_ITEMS])
135+
staticinlineintget_tlv_data(constint*p, inttlv[SOF_TLV_ITEMS])
137136
{
138137
/* we only support dB scale TLV type at the moment */
139138
if ((int)p[SNDRV_CTL_TLVO_TYPE] !=SNDRV_CTL_TLVT_DB_SCALE)
@@ -223,7 +222,7 @@ static u32 vol_pow32(u32 a, int exp, u32 fwl)
223222
* Function to calculate volume gain from TLV data.
224223
* This function can only handle gain steps that are multiples of 0.5 dB
225224
*/
226-
staticu32vol_compute_gain(u32value, int*tlv)
225+
u32vol_compute_gain(u32value, int*tlv)
227226
{
228227
intdB_gain;
229228
u32linear_gain;
@@ -262,20 +261,17 @@ static u32 vol_compute_gain(u32 value, int *tlv)
262261
* "size" specifies the number of entries in the table
263262
*/
264263
staticintset_up_volume_table(structsnd_sof_control*scontrol,
265-
inttlv[TLV_ITEMS], intsize)
264+
inttlv[SOF_TLV_ITEMS], intsize)
266265
{
267-
intj;
268-
269-
/* init the volume table */
270-
scontrol->volume_table=kcalloc(size, sizeof(u32), GFP_KERNEL);
271-
if (!scontrol->volume_table)
272-
return-ENOMEM;
266+
structsnd_soc_component*scomp=scontrol->scomp;
267+
structsnd_sof_dev*sdev=snd_soc_component_get_drvdata(scomp);
268+
conststructipc_tplg_ops*tplg_ops=sdev->ipc->ops->tplg;
273269

274-
/* populate the volume table */
275-
for (j=0; j<size ; j++)
276-
scontrol->volume_table[j] =vol_compute_gain(j, tlv);
270+
if (tplg_ops->control->set_up_volume_table)
271+
returntplg_ops->control->set_up_volume_table(scontrol, tlv, size);
277272

278-
return0;
273+
dev_err(scomp->dev, "Mandatory op %s not set\n", __func__);
274+
return-EINVAL;
279275
}
280276

281277
structsof_dai_types {
@@ -771,7 +767,7 @@ static int sof_control_load_volume(struct snd_soc_component *scomp,
771767
structsnd_sof_dev*sdev=snd_soc_component_get_drvdata(scomp);
772768
structsnd_soc_tplg_mixer_control*mc=
773769
container_of(hdr, structsnd_soc_tplg_mixer_control, hdr);
774-
inttlv[TLV_ITEMS];
770+
inttlv[SOF_TLV_ITEMS];
775771
intret;
776772

777773
/* validate topology data */

0 commit comments

Comments
 (0)