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

File tree

3 files changed

+35
-15
lines changed

3 files changed

+35
-15
lines changed

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
return 0;
695695
}
696696

697+
static int
698+
sof_ipc3_set_up_volume_table(struct snd_sof_control *scontrol, int tlv[SOF_TLV_ITEMS], int size)
699+
{
700+
int i;
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+
return 0;
712+
}
713+
697714
const struct ipc_tplg_control_ops tplg_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
#define VOLUME_FWL 16
4141

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

9398
/**
@@ -465,4 +470,5 @@ int sof_update_ipc_object(struct snd_soc_component *scomp, void *object, enum so
465470
size_t object_size, int token_instance_num);
466471
int sof_pcm_setup_connected_widgets(struct snd_sof_dev *sdev, struct snd_soc_pcm_runtime *rtd,
467472
struct snd_sof_pcm *spcm, int dir);
473+
u32 vol_compute_gain(u32 value, 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
#define VOL_HALF_DB_STEP 50
3333

3434
/* TLV data items */
35-
#define TLV_ITEMS 3
3635
#define TLV_MIN 0
3736
#define TLV_STEP 1
3837
#define TLV_MUTE 2
@@ -133,7 +132,7 @@ int sof_update_ipc_object(struct snd_soc_component *scomp, void *object, enum so
133132
return 0;
134133
}
135134

136-
static inline int get_tlv_data(const int *p, int tlv[TLV_ITEMS])
135+
static inline int get_tlv_data(const int *p, int tlv[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-
static u32 vol_compute_gain(u32 value, int *tlv)
225+
u32 vol_compute_gain(u32 value, int *tlv)
227226
{
228227
int dB_gain;
229228
u32 linear_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
static int set_up_volume_table(struct snd_sof_control *scontrol,
265-
int tlv[TLV_ITEMS], int size)
264+
int tlv[SOF_TLV_ITEMS], int size)
266265
{
267-
int j;
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+
struct snd_soc_component *scomp = scontrol->scomp;
267+
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
268+
const struct ipc_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+
return tplg_ops->control->set_up_volume_table(scontrol, tlv, size);
277272

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

281277
struct sof_dai_types {
@@ -771,7 +767,7 @@ static int sof_control_load_volume(struct snd_soc_component *scomp,
771767
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
772768
struct snd_soc_tplg_mixer_control *mc =
773769
container_of(hdr, struct snd_soc_tplg_mixer_control, hdr);
774-
int tlv[TLV_ITEMS];
770+
int tlv[SOF_TLV_ITEMS];
775771
int ret;
776772

777773
/* validate topology data */

0 commit comments

Comments
 (0)