ASoC: SOF: pcm: Extend the optionality of IPC ops to IPC as well
authorPeter Ujfalusi <peter.ujfalusi@linux.intel.com>
Wed, 21 Dec 2022 10:23:21 +0000 (12:23 +0200)
committerMark Brown <broonie@kernel.org>
Sun, 25 Dec 2022 23:32:32 +0000 (23:32 +0000)
The IPC ops are optional, but they require that the ops struct is to be
allocated with all callbacks set to NULL.

Update the code to extend the optionality to:
sdev->ipc == NULL
sdev->ipc->ops == NULL
sdev->ipc->ops->[pcm] == NULL
sdev->ipc->ops->[pcm]->ops == NULL (treated optional currently)

Signed-off-by: Peter 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>
Reviewed-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Reviewed-by: Rander Wang <rander.wang@intel.com>
Link: https://lore.kernel.org/r/20221221102328.9635-5-peter.ujfalusi@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/sof/pcm.c

index 14571b8..952fc69 100644 (file)
@@ -125,8 +125,8 @@ static int sof_pcm_hw_params(struct snd_soc_component *component,
 {
        struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
        struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
+       const struct sof_ipc_pcm_ops *pcm_ops = sof_ipc_get_ops(sdev, pcm);
        struct snd_sof_platform_stream_params platform_params = { 0 };
-       const struct sof_ipc_pcm_ops *pcm_ops = sdev->ipc->ops->pcm;
        struct snd_pcm_runtime *runtime = substream->runtime;
        struct snd_sof_pcm *spcm;
        int ret;
@@ -143,7 +143,7 @@ static int sof_pcm_hw_params(struct snd_soc_component *component,
         * Handle repeated calls to hw_params() without free_pcm() in
         * between. At least ALSA OSS emulation depends on this.
         */
-       if (pcm_ops->hw_free && spcm->prepared[substream->stream]) {
+       if (pcm_ops && pcm_ops->hw_free && spcm->prepared[substream->stream]) {
                ret = pcm_ops->hw_free(component, substream);
                if (ret < 0)
                        return ret;
@@ -177,7 +177,7 @@ static int sof_pcm_hw_params(struct snd_soc_component *component,
                        return ret;
        }
 
-       if (pcm_ops->hw_params) {
+       if (pcm_ops && pcm_ops->hw_params) {
                ret = pcm_ops->hw_params(component, substream, params, &platform_params);
                if (ret < 0)
                        return ret;
@@ -196,7 +196,7 @@ static int sof_pcm_hw_free(struct snd_soc_component *component,
 {
        struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
        struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
-       const struct sof_ipc_pcm_ops *pcm_ops = sdev->ipc->ops->pcm;
+       const struct sof_ipc_pcm_ops *pcm_ops = sof_ipc_get_ops(sdev, pcm);
        struct snd_sof_pcm *spcm;
        int ret, err = 0;
 
@@ -212,7 +212,7 @@ static int sof_pcm_hw_free(struct snd_soc_component *component,
                spcm->pcm.pcm_id, substream->stream);
 
        /* free PCM in the DSP */
-       if (pcm_ops->hw_free && spcm->prepared[substream->stream]) {
+       if (pcm_ops && pcm_ops->hw_free && spcm->prepared[substream->stream]) {
                ret = pcm_ops->hw_free(component, substream);
                if (ret < 0)
                        err = ret;
@@ -279,7 +279,7 @@ static int sof_pcm_trigger(struct snd_soc_component *component,
 {
        struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
        struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
-       const struct sof_ipc_pcm_ops *pcm_ops = sdev->ipc->ops->pcm;
+       const struct sof_ipc_pcm_ops *pcm_ops = sof_ipc_get_ops(sdev, pcm);
        struct snd_sof_pcm *spcm;
        bool reset_hw_params = false;
        bool free_widget_list = false;
@@ -344,7 +344,7 @@ static int sof_pcm_trigger(struct snd_soc_component *component,
        if (!ipc_first)
                snd_sof_pcm_platform_trigger(sdev, substream, cmd);
 
-       if (pcm_ops->trigger)
+       if (pcm_ops && pcm_ops->trigger)
                ret = pcm_ops->trigger(component, substream, cmd);
 
        /* need to STOP DMA even if trigger IPC failed */
@@ -569,7 +569,7 @@ int sof_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_pa
        struct snd_sof_dai *dai =
                snd_sof_find_dai(component, (char *)rtd->dai_link->name);
        struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
-       const struct sof_ipc_pcm_ops *pcm_ops = sdev->ipc->ops->pcm;
+       const struct sof_ipc_pcm_ops *pcm_ops = sof_ipc_get_ops(sdev, pcm);
 
        /* no topology exists for this BE, try a common configuration */
        if (!dai) {
@@ -590,7 +590,7 @@ int sof_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_pa
                return 0;
        }
 
-       if (pcm_ops->dai_link_fixup)
+       if (pcm_ops && pcm_ops->dai_link_fixup)
                return pcm_ops->dai_link_fixup(rtd, params);
 
        return 0;