ASoC: SOF: ipc4-topology: Move the kcontrol module_id update to helper
authorPeter Ujfalusi <peter.ujfalusi@linux.intel.com>
Thu, 16 Mar 2023 15:11:32 +0000 (17:11 +0200)
committerMark Brown <broonie@kernel.org>
Fri, 17 Mar 2023 13:05:55 +0000 (13:05 +0000)
Introduce a helper function to update the message template for a kcontrol
associated with a widget.

In this way the helper can be re-used by other components later.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Reviewed-by: Jaska Uimonen <jaska.uimonen@linux.intel.com>
Reviewed-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Link: https://lore.kernel.org/r/20230316151137.7598-2-peter.ujfalusi@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/sof/ipc4-topology.c

index e7b3bdc..c00df39 100644 (file)
@@ -320,6 +320,24 @@ static int sof_ipc4_widget_setup_msg(struct snd_sof_widget *swidget, struct sof_
        return 0;
 }
 
+static void sof_ipc4_widget_update_kcontrol_module_id(struct snd_sof_widget *swidget)
+{
+       struct snd_soc_component *scomp = swidget->scomp;
+       struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
+       struct sof_ipc4_fw_module *fw_module = swidget->module_info;
+       struct snd_sof_control *scontrol;
+
+       /* update module ID for all kcontrols for this widget */
+       list_for_each_entry(scontrol, &sdev->kcontrol_list, list) {
+               if (scontrol->comp_id == swidget->comp_id) {
+                       struct sof_ipc4_control_data *cdata = scontrol->ipc_control_data;
+                       struct sof_ipc4_msg *msg = &cdata->msg;
+
+                       msg->primary |= fw_module->man4_module_entry.id;
+               }
+       }
+}
+
 static int sof_ipc4_widget_setup_pcm(struct snd_sof_widget *swidget)
 {
        struct sof_ipc4_available_audio_format *available_fmt;
@@ -627,9 +645,6 @@ err:
 static int sof_ipc4_widget_setup_comp_pga(struct snd_sof_widget *swidget)
 {
        struct snd_soc_component *scomp = swidget->scomp;
-       struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
-       struct sof_ipc4_fw_module *fw_module;
-       struct snd_sof_control *scontrol;
        struct sof_ipc4_gain *gain;
        int ret;
 
@@ -662,16 +677,7 @@ static int sof_ipc4_widget_setup_comp_pga(struct snd_sof_widget *swidget)
        if (ret)
                goto err;
 
-       fw_module = swidget->module_info;
-
-       /* update module ID for all kcontrols for this widget */
-       list_for_each_entry(scontrol, &sdev->kcontrol_list, list)
-               if (scontrol->comp_id == swidget->comp_id) {
-                       struct sof_ipc4_control_data *cdata = scontrol->ipc_control_data;
-                       struct sof_ipc4_msg *msg = &cdata->msg;
-
-                       msg->primary |= fw_module->man4_module_entry.id;
-               }
+       sof_ipc4_widget_update_kcontrol_module_id(swidget);
 
        return 0;
 err: