tools: plugin: Add index for kcontrols

Add an index field for kcontrols. This will be useful in differenciating
kcontrols of the same type in a widget. Modify the signature of the
control callback function to pass the index as an argument when creating
kcontrols. Pass 0 for ipc3 kcontrol builds as it will be unused in this
case anyway.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
This commit is contained in:
Ranjani Sridharan 2024-09-13 14:45:24 -07:00 committed by Liam Girdwood
parent dfd74b1765
commit ce385cf32a
7 changed files with 15 additions and 6 deletions

View File

@ -64,6 +64,6 @@ int plug_parse_topology(snd_sof_plug_t *plug);
int plug_set_up_pipelines(snd_sof_plug_t *plug, int dir);
int plug_free_pipelines(snd_sof_plug_t *plug, struct tplg_pipeline_list *pipeline_list, int dir);
void plug_free_topology(snd_sof_plug_t *plug);
int plug_kcontrol_cb_new(struct snd_soc_tplg_ctl_hdr *tplg_ctl, void *_comp, void *arg);
int plug_kcontrol_cb_new(struct snd_soc_tplg_ctl_hdr *tplg_ctl, void *_comp, void *arg, int index);
#endif

View File

@ -141,7 +141,7 @@ static uint32_t vol_compute_gain(uint32_t value, struct snd_soc_tplg_tlv_dbscale
}
/* helper function to add new kcontrols to the list of kcontrols in the global context */
int plug_kcontrol_cb_new(struct snd_soc_tplg_ctl_hdr *tplg_ctl, void *_comp, void *arg)
int plug_kcontrol_cb_new(struct snd_soc_tplg_ctl_hdr *tplg_ctl, void *_comp, void *arg, int index)
{
snd_sof_plug_t *plug = arg;
struct plug_shm_glb_state *glb = plug->glb_ctx.addr;
@ -169,6 +169,7 @@ int plug_kcontrol_cb_new(struct snd_soc_tplg_ctl_hdr *tplg_ctl, void *_comp, voi
ctl->module_id = comp_info->module_id;
ctl->instance_id = comp_info->instance_id;
ctl->mixer_ctl = *tplg_mixer;
ctl->index = index;
tlv = &tplg_ctl->tlv;
scale = &tlv->scale;

View File

@ -66,6 +66,7 @@ struct plug_shm_ctl {
unsigned int instance_id;
unsigned int type;
unsigned int volume_table[MAX_VOLUME_SIZE];
unsigned int index;
union {
struct snd_soc_tplg_mixer_control mixer_ctl;
struct snd_soc_tplg_enum_control enum_ctl;

View File

@ -91,6 +91,10 @@ int tplg_create_controls(struct tplg_context *ctx, int num_kcontrols,
struct snd_soc_tplg_mixer_control *mixer_ctl;
struct snd_soc_tplg_enum_control *enum_ctl;
struct snd_soc_tplg_bytes_control *bytes_ctl;
int num_mixers = 0;
int num_enums = 0;
int num_byte_controls = 0;
int index;
int j, ret = 0;
for (j = 0; j < num_kcontrols; j++) {
@ -105,6 +109,7 @@ int tplg_create_controls(struct tplg_context *ctx, int num_kcontrols,
case SND_SOC_TPLG_CTL_VOLSW_XR_SX:
case SND_SOC_TPLG_CTL_RANGE:
case SND_SOC_TPLG_DAPM_CTL_VOLSW:
index = num_mixers++;
/* load mixer type control */
mixer_ctl = (struct snd_soc_tplg_mixer_control *)ctl_hdr;
/* ctl is after private data */
@ -116,6 +121,7 @@ int tplg_create_controls(struct tplg_context *ctx, int num_kcontrols,
case SND_SOC_TPLG_DAPM_CTL_ENUM_DOUBLE:
case SND_SOC_TPLG_DAPM_CTL_ENUM_VIRT:
case SND_SOC_TPLG_DAPM_CTL_ENUM_VALUE:
index = num_enums++;
/* load enum_ctl type control */
enum_ctl = (struct snd_soc_tplg_enum_control *)ctl_hdr;
/* ctl is after private data */
@ -123,6 +129,7 @@ int tplg_create_controls(struct tplg_context *ctx, int num_kcontrols,
break;
case SND_SOC_TPLG_CTL_BYTES:
index = num_byte_controls++;
/* load bytes_ctl type control */
bytes_ctl = (struct snd_soc_tplg_bytes_control *)ctl_hdr;
/* ctl is after private data */
@ -135,7 +142,7 @@ int tplg_create_controls(struct tplg_context *ctx, int num_kcontrols,
}
if (ctx->ctl_cb && object)
ctx->ctl_cb(ctl_hdr, object, ctx->ctl_arg);
ctx->ctl_cb(ctl_hdr, object, ctx->ctl_arg, index);
}
if (rctl && ctl_hdr) {

View File

@ -181,7 +181,7 @@ struct tplg_context {
/* kcontrol creation */
void *ctl_arg;
int (*ctl_cb)(struct snd_soc_tplg_ctl_hdr *tplg_ctl,
void *comp, void *arg);
void *comp, void *arg, int index);
};
#define tplg_get(ctx) ((void *)(ctx->tplg_base + ctx->tplg_offset))

View File

@ -73,7 +73,7 @@ static int pga_ipc3_build(struct tplg_context *ctx, void *_pga)
/* call ctl creation callback if needed */
if (ctx->ctl_cb)
ctx->ctl_cb(ctl, volume, ctx->ctl_arg);
ctx->ctl_cb(ctl, volume, ctx->ctl_arg, 0);
/* we only care about the volume ctl - ignore others atm */
if (ctl->ops.get != 256)

View File

@ -225,7 +225,7 @@ int tplg_new_process(struct tplg_context *ctx, void *process, size_t process_siz
/* call ctl creation callback if needed */
if (ctx->ctl_cb)
ctx->ctl_cb(ctl, process, ctx->ctl_arg);
ctx->ctl_cb(ctl, process, ctx->ctl_arg, 0);
/* Merge process and priv_data into process_ipc */
if (!priv_data)