ASoC: SOF: ipc4-topology: Add prepare op for DAI type widgets
authorRanjani Sridharan <ranjani.sridharan@linux.intel.com>
Thu, 9 Jun 2022 03:26:26 +0000 (20:26 -0700)
committerMark Brown <broonie@kernel.org>
Fri, 10 Jun 2022 12:31:54 +0000 (13:31 +0100)
Define the prepare op for the DAI type widgets for IPC4.
The prepare op is responsible for choosing the input/output audio
formats for these widgets based on the runtime PCM params, assigning the
instance ID and updating the total memory usage for the pipelines these
widgets belong to.

Co-developed-by: Rander Wang <rander.wang@linux.intel.com>
Signed-off-by: Rander Wang <rander.wang@linux.intel.com>
Co-developed-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Reviewed-by: Péter Ujfalusi <peter.ujfalusi@linux.intel.com>
Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Link: https://lore.kernel.org/r/20220609032643.916882-7-ranjani.sridharan@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/sof/ipc4-topology.c

index 1a73c16f1624279a3fd9038fd499a22fa13e561e..1bc5ff0154c58bb32b93bb12bd3b97a207d5cbaa 100644 (file)
@@ -706,8 +706,13 @@ static void sof_ipc4_unprepare_copier_module(struct snd_sof_widget *swidget)
        pipeline = pipe_widget->private;
        pipeline->mem_usage = 0;
 
-       if (WIDGET_IS_AIF(swidget->id))
+       if (WIDGET_IS_AIF(swidget->id)) {
                ipc4_copier = swidget->private;
+       } else if (WIDGET_IS_DAI(swidget->id)) {
+               struct snd_sof_dai *dai = swidget->private;
+
+               ipc4_copier = dai->private;
+       }
 
        if (ipc4_copier) {
                kfree(ipc4_copier->ipc_config_data);
@@ -776,6 +781,34 @@ sof_ipc4_prepare_copier_module(struct snd_sof_widget *swidget,
                ref_params = fe_params;
                break;
        }
+       case snd_soc_dapm_dai_in:
+       case snd_soc_dapm_dai_out:
+       {
+               struct snd_sof_dai *dai = swidget->private;
+
+               ipc4_copier = (struct sof_ipc4_copier *)dai->private;
+               copier_data = &ipc4_copier->data;
+               available_fmt = &ipc4_copier->available_fmt;
+               if (dir == SNDRV_PCM_STREAM_CAPTURE) {
+                       available_fmt->ref_audio_fmt = available_fmt->out_audio_fmt;
+                       ref_audio_fmt_size = sizeof(struct sof_ipc4_audio_format);
+
+                       /*
+                        * modify the input params for the dai copier as it only supports
+                        * 32-bit always
+                        */
+                       fmt = hw_param_mask(pipeline_params, SNDRV_PCM_HW_PARAM_FORMAT);
+                       snd_mask_none(fmt);
+                       snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S32_LE);
+               } else {
+                       available_fmt->ref_audio_fmt = &available_fmt->base_config->audio_fmt;
+                       ref_audio_fmt_size = sizeof(struct sof_ipc4_base_module_cfg);
+               }
+
+               ref_params = pipeline_params;
+
+               break;
+       }
        default:
                dev_err(sdev->dev, "unsupported type %d for copier %s",
                        swidget->id, swidget->widget->name);
@@ -879,9 +912,13 @@ static const struct sof_ipc_tplg_widget_ops tplg_ipc4_widget_ops[SND_SOC_DAPM_TY
                                  sof_ipc4_prepare_copier_module,
                                  sof_ipc4_unprepare_copier_module},
        [snd_soc_dapm_dai_in] = {sof_ipc4_widget_setup_comp_dai, sof_ipc4_widget_free_comp_dai,
-                                dai_token_list, ARRAY_SIZE(dai_token_list), NULL, NULL, NULL},
+                                dai_token_list, ARRAY_SIZE(dai_token_list), NULL,
+                                sof_ipc4_prepare_copier_module,
+                                sof_ipc4_unprepare_copier_module},
        [snd_soc_dapm_dai_out] = {sof_ipc4_widget_setup_comp_dai, sof_ipc4_widget_free_comp_dai,
-                                 dai_token_list, ARRAY_SIZE(dai_token_list), NULL, NULL, NULL},
+                                 dai_token_list, ARRAY_SIZE(dai_token_list), NULL,
+                                 sof_ipc4_prepare_copier_module,
+                                 sof_ipc4_unprepare_copier_module},
        [snd_soc_dapm_scheduler] = {sof_ipc4_widget_setup_comp_pipeline, sof_ipc4_widget_free_comp,
                                    pipeline_token_list, ARRAY_SIZE(pipeline_token_list), NULL,
                                    NULL, NULL},