ASoC: topology: Allow bespoke configuration post widget creation
authorLiam Girdwood <liam.r.girdwood@linux.intel.com>
Fri, 9 Jun 2017 14:43:23 +0000 (15:43 +0100)
committerMark Brown <broonie@kernel.org>
Fri, 9 Jun 2017 17:46:08 +0000 (18:46 +0100)
Current topology only allows for widget configuration before the widget
is registered. This patch also allows further configuration and usage
after registration is complete.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
include/sound/soc-topology.h
sound/soc/soc-topology.c

index b8da221..f552c3f 100644 (file)
@@ -118,6 +118,9 @@ struct snd_soc_tplg_ops {
        int (*widget_load)(struct snd_soc_component *,
                struct snd_soc_dapm_widget *,
                struct snd_soc_tplg_dapm_widget *);
+       int (*widget_ready)(struct snd_soc_component *,
+               struct snd_soc_dapm_widget *,
+               struct snd_soc_tplg_dapm_widget *);
        int (*widget_unload)(struct snd_soc_component *,
                struct snd_soc_dobj *);
 
index f4ec236..12e1897 100644 (file)
@@ -344,6 +344,17 @@ static int soc_tplg_widget_load(struct soc_tplg *tplg,
        return 0;
 }
 
+/* optionally pass new dynamic widget to component driver. This is mainly for
+ * external widgets where we can assign private data/ops */
+static int soc_tplg_widget_ready(struct soc_tplg *tplg,
+       struct snd_soc_dapm_widget *w, struct snd_soc_tplg_dapm_widget *tplg_w)
+{
+       if (tplg->comp && tplg->ops && tplg->ops->widget_ready)
+               return tplg->ops->widget_ready(tplg->comp, w, tplg_w);
+
+       return 0;
+}
+
 /* pass DAI configurations to component driver for extra initialization */
 static int soc_tplg_dai_load(struct soc_tplg *tplg,
        struct snd_soc_dai_driver *dai_drv)
@@ -1579,8 +1590,16 @@ widget:
        widget->dobj.ops = tplg->ops;
        widget->dobj.index = tplg->index;
        list_add(&widget->dobj.list, &tplg->comp->dobj_list);
+
+       ret = soc_tplg_widget_ready(tplg, widget, w);
+       if (ret < 0)
+               goto ready_err;
+
        return 0;
 
+ready_err:
+       snd_soc_tplg_widget_remove(widget);
+       snd_soc_dapm_free_widget(widget);
 hdr_err:
        kfree(template.sname);
 err: