From 79033ceae4c513b837a30a72bfb297697b2fa68e Mon Sep 17 00:00:00 2001 From: Ranjani Sridharan Date: Mon, 26 Apr 2021 13:03:57 -0700 Subject: [PATCH] topology: pre-process-dapm: add support for widget control objects Add support for pre-processing mixer and byte control objects. For ex: a pga widget with a mixer control as follows: Object.pga"0" { ... mixer.0 { index 2 max 32 name "2 MasterPlaybackControl" Object.Base.channel."fl" { shift 0 } Object.Base.channel."fr" { } Object.Base.tlv."vtlv_m64s2" { Object.Base.scale."m64s2" { mute 1 } } Object.Base.ops."ctl" { info "volsw" #256 binds the mixer control to volume get/put handlers get 256 put 256 } access [ read_write tlv_read ] } } Would be converted to: SectionControlMixer.'2 Master Playback Volume' { index 2 max 32 channel { fl { reg 1 } fr { reg 1 shift 1 } } tlv "vtlv_m64s2" ops.0 { info volsw get 256 put 256 } access [ read_write tlv_read ] } and the SectionWidget for pga.2.0 would be updated to add the mixer references as follows: SectionWidget.'pga.2.0' { ... mixer [ "2 Master Playback Volume" ] } Signed-off-by: Ranjani Sridharan Signed-off-by: Jaroslav Kysela --- topology/pre-process-dapm.c | 37 +++++++++++++++++++++++++++++++++++ topology/pre-process-object.c | 13 ++++++++++++ topology/pre-processor.h | 4 ++++ 3 files changed, 54 insertions(+) diff --git a/topology/pre-process-dapm.c b/topology/pre-process-dapm.c index fa1b64c..63dd1fb 100644 --- a/topology/pre-process-dapm.c +++ b/topology/pre-process-dapm.c @@ -92,3 +92,40 @@ int tplg_build_tlv_object(struct tplg_pre_processor *tplg_pp, snd_config_t *obj_ return tplg_parent_update(tplg_pp, parent, "tlv", name); } + +static int tplg_build_control(struct tplg_pre_processor *tplg_pp, snd_config_t *obj_cfg, + snd_config_t *parent, char *type) +{ + snd_config_t *cfg, *obj; + const char *name; + int ret; + + obj = tplg_object_get_instance_config(tplg_pp, obj_cfg); + + /* get control name */ + ret = snd_config_search(obj, "name", &cfg); + if (ret < 0) + return 0; + + ret = snd_config_get_string(cfg, &name); + if (ret < 0) + return ret; + + ret = tplg_build_object_from_template(tplg_pp, obj_cfg, &cfg, NULL, false); + if (ret < 0) + return ret; + + return tplg_parent_update(tplg_pp, parent, type, name); +} + +int tplg_build_mixer_control(struct tplg_pre_processor *tplg_pp, snd_config_t *obj_cfg, + snd_config_t *parent) +{ + return tplg_build_control(tplg_pp, obj_cfg, parent, "mixer"); +} + +int tplg_build_bytes_control(struct tplg_pre_processor *tplg_pp, snd_config_t *obj_cfg, + snd_config_t *parent) +{ + return tplg_build_control(tplg_pp, obj_cfg, parent, "bytes"); +} diff --git a/topology/pre-process-object.c b/topology/pre-process-object.c index c7c23ff..8e49be8 100644 --- a/topology/pre-process-object.c +++ b/topology/pre-process-object.c @@ -858,6 +858,15 @@ static int tplg_build_generic_object(struct tplg_pre_processor *tplg_pp, snd_con return ret; } +const struct config_template_items mixer_control_config = { + .int_config_ids = {"index", "max", "invert"}, + .compound_config_ids = {"access"} +}; + +const struct config_template_items bytes_control_config = { + .int_config_ids = {"index", "base", "num_regs", "max", "mask"}, +}; + const struct config_template_items scale_config = { .int_config_ids = {"min", "step", "mute"}, }; @@ -891,6 +900,10 @@ const struct build_function_map object_build_map[] = { {"Base", "channel", "channel", &tplg_build_channel_object, &channel_config}, {"Base", "VendorToken", "SectionVendorTokens", &tplg_build_vendor_token_object, NULL}, {"Widget", "", "SectionWidget", &tplg_build_generic_object, &widget_config}, + {"Control", "mixer", "SectionControlMixer", &tplg_build_mixer_control, + &mixer_control_config}, + {"Control", "bytes", "SectionControlBytes", &tplg_build_bytes_control, + &bytes_control_config}, }; static const struct build_function_map *tplg_object_get_map(struct tplg_pre_processor *tplg_pp, diff --git a/topology/pre-processor.h b/topology/pre-processor.h index 1e1bca5..e89fad6 100644 --- a/topology/pre-processor.h +++ b/topology/pre-processor.h @@ -61,6 +61,10 @@ int tplg_build_ops_object(struct tplg_pre_processor *tplg_pp, snd_config_t *obj_ snd_config_t *parent); int tplg_build_channel_object(struct tplg_pre_processor *tplg_pp, snd_config_t *obj_cfg, snd_config_t *parent); +int tplg_build_mixer_control(struct tplg_pre_processor *tplg_pp, snd_config_t *obj_cfg, + snd_config_t *parent); +int tplg_build_bytes_control(struct tplg_pre_processor *tplg_pp, snd_config_t *obj_cfg, + snd_config_t *parent); int tplg_parent_update(struct tplg_pre_processor *tplg_pp, snd_config_t *parent, const char *section_name, const char *item_name); -- 2.47.1