ASoC: SOF: fix an Oops, caused by invalid topology
[sfrench/cifs-2.6.git] / sound / soc / sof / pcm.c
index 2b876d4974476bd359d4f530cabfeb92776b3164..29435ba2d32927ea6cd4fd2154d5ac59d6eb3483 100644 (file)
 #include <sound/pcm_params.h>
 #include <sound/sof.h>
 #include "sof-priv.h"
+#include "sof-audio.h"
 #include "ops.h"
 
-#define DRV_NAME       "sof-audio-component"
-
 /* Create DMA buffer page table for DSP */
-static int create_page_table(struct snd_pcm_substream *substream,
+static int create_page_table(struct snd_soc_component *component,
+                            struct snd_pcm_substream *substream,
                             unsigned char *dma_area, size_t size)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_component *component =
-               snd_soc_rtdcom_lookup(rtd, DRV_NAME);
-       struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
        struct snd_sof_pcm *spcm;
        struct snd_dma_buffer *dmab = snd_pcm_get_dma_buf(substream);
        int stream = substream->stream;
 
-       spcm = snd_sof_find_spcm_dai(sdev, rtd);
+       spcm = snd_sof_find_spcm_dai(component, rtd);
        if (!spcm)
                return -EINVAL;
 
-       return snd_sof_create_page_table(sdev, dmab,
+       return snd_sof_create_page_table(component->dev, dmab,
                spcm->stream[stream].page_table.area, size);
 }
 
 static int sof_pcm_dsp_params(struct snd_sof_pcm *spcm, struct snd_pcm_substream *substream,
                              const struct sof_ipc_pcm_params_reply *reply)
 {
-       struct snd_sof_dev *sdev = spcm->sdev;
+       struct snd_soc_component *scomp = spcm->scomp;
+       struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
+
        /* validate offset */
        int ret = snd_sof_ipc_pcm_params(sdev, substream, reply);
 
        if (ret < 0)
-               dev_err(sdev->dev, "error: got wrong reply for PCM %d\n",
+               dev_err(scomp->dev, "error: got wrong reply for PCM %d\n",
                        spcm->pcm.pcm_id);
 
        return ret;
@@ -71,13 +70,12 @@ void snd_sof_pcm_period_elapsed(struct snd_pcm_substream *substream)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_component *component =
-               snd_soc_rtdcom_lookup(rtd, DRV_NAME);
-       struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
+               snd_soc_rtdcom_lookup(rtd, SOF_AUDIO_PCM_DRV_NAME);
        struct snd_sof_pcm *spcm;
 
-       spcm = snd_sof_find_spcm_dai(sdev, rtd);
+       spcm = snd_sof_find_spcm_dai(component, rtd);
        if (!spcm) {
-               dev_err(sdev->dev,
+               dev_err(component->dev,
                        "error: period elapsed for unknown stream!\n");
                return;
        }
@@ -94,14 +92,33 @@ void snd_sof_pcm_period_elapsed(struct snd_pcm_substream *substream)
 }
 EXPORT_SYMBOL(snd_sof_pcm_period_elapsed);
 
-/* this may get called several times by oss emulation */
-static int sof_pcm_hw_params(struct snd_pcm_substream *substream,
+static int sof_pcm_dsp_pcm_free(struct snd_pcm_substream *substream,
+                               struct snd_sof_dev *sdev,
+                               struct snd_sof_pcm *spcm)
+{
+       struct sof_ipc_stream stream;
+       struct sof_ipc_reply reply;
+       int ret;
+
+       stream.hdr.size = sizeof(stream);
+       stream.hdr.cmd = SOF_IPC_GLB_STREAM_MSG | SOF_IPC_STREAM_PCM_FREE;
+       stream.comp_id = spcm->stream[substream->stream].comp_id;
+
+       /* send IPC to the DSP */
+       ret = sof_ipc_tx_message(sdev->ipc, stream.hdr.cmd, &stream,
+                                sizeof(stream), &reply, sizeof(reply));
+       if (!ret)
+               spcm->prepared[substream->stream] = false;
+
+       return ret;
+}
+
+static int sof_pcm_hw_params(struct snd_soc_component *component,
+                            struct snd_pcm_substream *substream,
                             struct snd_pcm_hw_params *params)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_pcm_runtime *runtime = substream->runtime;
-       struct snd_soc_component *component =
-               snd_soc_rtdcom_lookup(rtd, DRV_NAME);
        struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
        struct snd_sof_pcm *spcm;
        struct sof_ipc_pcm_params pcm;
@@ -112,30 +129,28 @@ static int sof_pcm_hw_params(struct snd_pcm_substream *substream,
        if (rtd->dai_link->no_pcm)
                return 0;
 
-       spcm = snd_sof_find_spcm_dai(sdev, rtd);
+       spcm = snd_sof_find_spcm_dai(component, rtd);
        if (!spcm)
                return -EINVAL;
 
-       dev_dbg(sdev->dev, "pcm: hw params stream %d dir %d\n",
+       /*
+        * Handle repeated calls to hw_params() without free_pcm() in
+        * between. At least ALSA OSS emulation depends on this.
+        */
+       if (spcm->prepared[substream->stream]) {
+               ret = sof_pcm_dsp_pcm_free(substream, sdev, spcm);
+               if (ret < 0)
+                       return ret;
+       }
+
+       dev_dbg(component->dev, "pcm: hw params stream %d dir %d\n",
                spcm->pcm.pcm_id, substream->stream);
 
        memset(&pcm, 0, sizeof(pcm));
 
-       /* allocate audio buffer pages */
-       ret = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params));
-       if (ret < 0) {
-               dev_err(sdev->dev, "error: could not allocate %d bytes for PCM %d\n",
-                       params_buffer_bytes(params), spcm->pcm.pcm_id);
-               return ret;
-       }
-       if (ret) {
-               /*
-                * ret == 1 means the buffer is changed
-                * create compressed page table for audio firmware
-                * ret == 0 means the buffer is not changed
-                * so no need to regenerate the page table
-                */
-               ret = create_page_table(substream, runtime->dma_area,
+       /* create compressed page table for audio firmware */
+       if (runtime->buffer_changed) {
+               ret = create_page_table(component, substream, runtime->dma_area,
                                        runtime->dma_bytes);
                if (ret < 0)
                        return ret;
@@ -189,17 +204,17 @@ static int sof_pcm_hw_params(struct snd_pcm_substream *substream,
                                             params,
                                             &pcm.params);
        if (ret < 0) {
-               dev_err(sdev->dev, "error: platform hw params failed\n");
+               dev_err(component->dev, "error: platform hw params failed\n");
                return ret;
        }
 
-       dev_dbg(sdev->dev, "stream_tag %d", pcm.params.stream_tag);
+       dev_dbg(component->dev, "stream_tag %d", pcm.params.stream_tag);
 
        /* send IPC to the DSP */
        ret = sof_ipc_tx_message(sdev->ipc, pcm.hdr.cmd, &pcm, sizeof(pcm),
                                 &ipc_params_reply, sizeof(ipc_params_reply));
        if (ret < 0) {
-               dev_err(sdev->dev, "error: hw params ipc failed for stream %d\n",
+               dev_err(component->dev, "error: hw params ipc failed for stream %d\n",
                        pcm.params.stream_tag);
                return ret;
        }
@@ -216,32 +231,10 @@ static int sof_pcm_hw_params(struct snd_pcm_substream *substream,
        return ret;
 }
 
-static int sof_pcm_dsp_pcm_free(struct snd_pcm_substream *substream,
-                               struct snd_sof_dev *sdev,
-                               struct snd_sof_pcm *spcm)
-{
-       struct sof_ipc_stream stream;
-       struct sof_ipc_reply reply;
-       int ret;
-
-       stream.hdr.size = sizeof(stream);
-       stream.hdr.cmd = SOF_IPC_GLB_STREAM_MSG | SOF_IPC_STREAM_PCM_FREE;
-       stream.comp_id = spcm->stream[substream->stream].comp_id;
-
-       /* send IPC to the DSP */
-       ret = sof_ipc_tx_message(sdev->ipc, stream.hdr.cmd, &stream,
-                                sizeof(stream), &reply, sizeof(reply));
-       if (!ret)
-               spcm->prepared[substream->stream] = false;
-
-       return ret;
-}
-
-static int sof_pcm_hw_free(struct snd_pcm_substream *substream)
+static int sof_pcm_hw_free(struct snd_soc_component *component,
+                          struct snd_pcm_substream *substream)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_component *component =
-               snd_soc_rtdcom_lookup(rtd, DRV_NAME);
        struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
        struct snd_sof_pcm *spcm;
        int ret, err = 0;
@@ -250,12 +243,12 @@ static int sof_pcm_hw_free(struct snd_pcm_substream *substream)
        if (rtd->dai_link->no_pcm)
                return 0;
 
-       spcm = snd_sof_find_spcm_dai(sdev, rtd);
+       spcm = snd_sof_find_spcm_dai(component, rtd);
        if (!spcm)
                return -EINVAL;
 
-       dev_dbg(sdev->dev, "pcm: free stream %d dir %d\n", spcm->pcm.pcm_id,
-               substream->stream);
+       dev_dbg(component->dev, "pcm: free stream %d dir %d\n",
+               spcm->pcm.pcm_id, substream->stream);
 
        if (spcm->prepared[substream->stream]) {
                ret = sof_pcm_dsp_pcm_free(substream, sdev, spcm);
@@ -263,25 +256,21 @@ static int sof_pcm_hw_free(struct snd_pcm_substream *substream)
                        err = ret;
        }
 
-       snd_pcm_lib_free_pages(substream);
-
        cancel_work_sync(&spcm->stream[substream->stream].period_elapsed_work);
 
        ret = snd_sof_pcm_platform_hw_free(sdev, substream);
        if (ret < 0) {
-               dev_err(sdev->dev, "error: platform hw free failed\n");
+               dev_err(component->dev, "error: platform hw free failed\n");
                err = ret;
        }
 
        return err;
 }
 
-static int sof_pcm_prepare(struct snd_pcm_substream *substream)
+static int sof_pcm_prepare(struct snd_soc_component *component,
+                          struct snd_pcm_substream *substream)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_component *component =
-               snd_soc_rtdcom_lookup(rtd, DRV_NAME);
-       struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
        struct snd_sof_pcm *spcm;
        int ret;
 
@@ -289,20 +278,22 @@ static int sof_pcm_prepare(struct snd_pcm_substream *substream)
        if (rtd->dai_link->no_pcm)
                return 0;
 
-       spcm = snd_sof_find_spcm_dai(sdev, rtd);
+       spcm = snd_sof_find_spcm_dai(component, rtd);
        if (!spcm)
                return -EINVAL;
 
        if (spcm->prepared[substream->stream])
                return 0;
 
-       dev_dbg(sdev->dev, "pcm: prepare stream %d dir %d\n", spcm->pcm.pcm_id,
-               substream->stream);
+       dev_dbg(component->dev, "pcm: prepare stream %d dir %d\n",
+               spcm->pcm.pcm_id, substream->stream);
 
        /* set hw_params */
-       ret = sof_pcm_hw_params(substream, &spcm->params[substream->stream]);
+       ret = sof_pcm_hw_params(component,
+                               substream, &spcm->params[substream->stream]);
        if (ret < 0) {
-               dev_err(sdev->dev, "error: set pcm hw_params after resume\n");
+               dev_err(component->dev,
+                       "error: set pcm hw_params after resume\n");
                return ret;
        }
 
@@ -313,11 +304,10 @@ static int sof_pcm_prepare(struct snd_pcm_substream *substream)
  * FE dai link trigger actions are always executed in non-atomic context because
  * they involve IPC's.
  */
-static int sof_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
+static int sof_pcm_trigger(struct snd_soc_component *component,
+                          struct snd_pcm_substream *substream, int cmd)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_component *component =
-               snd_soc_rtdcom_lookup(rtd, DRV_NAME);
        struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
        struct snd_sof_pcm *spcm;
        struct sof_ipc_stream stream;
@@ -330,11 +320,11 @@ static int sof_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
        if (rtd->dai_link->no_pcm)
                return 0;
 
-       spcm = snd_sof_find_spcm_dai(sdev, rtd);
+       spcm = snd_sof_find_spcm_dai(component, rtd);
        if (!spcm)
                return -EINVAL;
 
-       dev_dbg(sdev->dev, "pcm: trigger stream %d dir %d cmd %d\n",
+       dev_dbg(component->dev, "pcm: trigger stream %d dir %d cmd %d\n",
                spcm->pcm.pcm_id, substream->stream, cmd);
 
        stream.hdr.size = sizeof(stream);
@@ -350,26 +340,58 @@ static int sof_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
                stream.hdr.cmd |= SOF_IPC_STREAM_TRIG_RELEASE;
                break;
        case SNDRV_PCM_TRIGGER_RESUME:
+               if (spcm->stream[substream->stream].suspend_ignored) {
+                       /*
+                        * this case will be triggered when INFO_RESUME is
+                        * supported, no need to resume streams that remained
+                        * enabled in D0ix.
+                        */
+                       spcm->stream[substream->stream].suspend_ignored = false;
+                       return 0;
+               }
+
                /* set up hw_params */
-               ret = sof_pcm_prepare(substream);
+               ret = sof_pcm_prepare(component, substream);
                if (ret < 0) {
-                       dev_err(sdev->dev,
+                       dev_err(component->dev,
                                "error: failed to set up hw_params upon resume\n");
                        return ret;
                }
 
                /* fallthrough */
        case SNDRV_PCM_TRIGGER_START:
+               if (spcm->stream[substream->stream].suspend_ignored) {
+                       /*
+                        * This case will be triggered when INFO_RESUME is
+                        * not supported, no need to re-start streams that
+                        * remained enabled in D0ix.
+                        */
+                       spcm->stream[substream->stream].suspend_ignored = false;
+                       return 0;
+               }
                stream.hdr.cmd |= SOF_IPC_STREAM_TRIG_START;
                break;
        case SNDRV_PCM_TRIGGER_SUSPEND:
+               if (sdev->s0_suspend &&
+                   spcm->stream[substream->stream].d0i3_compatible) {
+                       /*
+                        * trap the event, not sending trigger stop to
+                        * prevent the FW pipelines from being stopped,
+                        * and mark the flag to ignore the upcoming DAPM
+                        * PM events.
+                        */
+                       spcm->stream[substream->stream].suspend_ignored = true;
+                       return 0;
+               }
+               /* fallthrough */
        case SNDRV_PCM_TRIGGER_STOP:
                stream.hdr.cmd |= SOF_IPC_STREAM_TRIG_STOP;
                ipc_first = true;
                reset_hw_params = true;
                break;
        default:
-               dev_err(sdev->dev, "error: unhandled trigger cmd %d\n", cmd);
+               dev_err(component->dev, "error: unhandled trigger cmd %d\n",
+                       cmd);
                return -EINVAL;
        }
 
@@ -395,11 +417,10 @@ static int sof_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
        return ret;
 }
 
-static snd_pcm_uframes_t sof_pcm_pointer(struct snd_pcm_substream *substream)
+static snd_pcm_uframes_t sof_pcm_pointer(struct snd_soc_component *component,
+                                        struct snd_pcm_substream *substream)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_component *component =
-               snd_soc_rtdcom_lookup(rtd, DRV_NAME);
        struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
        struct snd_sof_pcm *spcm;
        snd_pcm_uframes_t host, dai;
@@ -412,7 +433,7 @@ static snd_pcm_uframes_t sof_pcm_pointer(struct snd_pcm_substream *substream)
        if (sof_ops(sdev)->pcm_pointer)
                return sof_ops(sdev)->pcm_pointer(sdev, substream);
 
-       spcm = snd_sof_find_spcm_dai(sdev, rtd);
+       spcm = snd_sof_find_spcm_dai(component, rtd);
        if (!spcm)
                return -EINVAL;
 
@@ -422,19 +443,20 @@ static snd_pcm_uframes_t sof_pcm_pointer(struct snd_pcm_substream *substream)
        dai = bytes_to_frames(substream->runtime,
                              spcm->stream[substream->stream].posn.dai_posn);
 
-       dev_dbg(sdev->dev, "PCM: stream %d dir %d DMA position %lu DAI position %lu\n",
+       dev_dbg(component->dev,
+               "PCM: stream %d dir %d DMA position %lu DAI position %lu\n",
                spcm->pcm.pcm_id, substream->stream, host, dai);
 
        return host;
 }
 
-static int sof_pcm_open(struct snd_pcm_substream *substream)
+static int sof_pcm_open(struct snd_soc_component *component,
+                       struct snd_pcm_substream *substream)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_pcm_runtime *runtime = substream->runtime;
-       struct snd_soc_component *component =
-               snd_soc_rtdcom_lookup(rtd, DRV_NAME);
        struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
+       const struct snd_sof_dsp_ops *ops = sof_ops(sdev);
        struct snd_sof_pcm *spcm;
        struct snd_soc_tplg_stream_caps *caps;
        int ret;
@@ -443,12 +465,12 @@ static int sof_pcm_open(struct snd_pcm_substream *substream)
        if (rtd->dai_link->no_pcm)
                return 0;
 
-       spcm = snd_sof_find_spcm_dai(sdev, rtd);
+       spcm = snd_sof_find_spcm_dai(component, rtd);
        if (!spcm)
                return -EINVAL;
 
-       dev_dbg(sdev->dev, "pcm: open stream %d dir %d\n", spcm->pcm.pcm_id,
-               substream->stream);
+       dev_dbg(component->dev, "pcm: open stream %d dir %d\n",
+               spcm->pcm.pcm_id, substream->stream);
 
        INIT_WORK(&spcm->stream[substream->stream].period_elapsed_work,
                  sof_pcm_period_elapsed_work);
@@ -464,11 +486,8 @@ static int sof_pcm_open(struct snd_pcm_substream *substream)
                                   le32_to_cpu(caps->period_size_min));
 
        /* set runtime config */
-       runtime->hw.info = SNDRV_PCM_INFO_MMAP |
-                         SNDRV_PCM_INFO_MMAP_VALID |
-                         SNDRV_PCM_INFO_INTERLEAVED |
-                         SNDRV_PCM_INFO_PAUSE |
-                         SNDRV_PCM_INFO_NO_PERIOD_WAKEUP;
+       runtime->hw.info = ops->hw_info; /* platform-specific */
+
        runtime->hw.formats = le64_to_cpu(caps->formats);
        runtime->hw.period_bytes_min = le32_to_cpu(caps->period_size_min);
        runtime->hw.period_bytes_max = le32_to_cpu(caps->period_size_max);
@@ -481,13 +500,13 @@ static int sof_pcm_open(struct snd_pcm_substream *substream)
         */
        runtime->hw.buffer_bytes_max = le32_to_cpu(caps->buffer_size_max);
 
-       dev_dbg(sdev->dev, "period min %zd max %zd bytes\n",
+       dev_dbg(component->dev, "period min %zd max %zd bytes\n",
                runtime->hw.period_bytes_min,
                runtime->hw.period_bytes_max);
-       dev_dbg(sdev->dev, "period count %d max %d\n",
+       dev_dbg(component->dev, "period count %d max %d\n",
                runtime->hw.periods_min,
                runtime->hw.periods_max);
-       dev_dbg(sdev->dev, "buffer max %zd bytes\n",
+       dev_dbg(component->dev, "buffer max %zd bytes\n",
                runtime->hw.buffer_bytes_max);
 
        /* set wait time - TODO: come from topology */
@@ -500,16 +519,15 @@ static int sof_pcm_open(struct snd_pcm_substream *substream)
 
        ret = snd_sof_pcm_platform_open(sdev, substream);
        if (ret < 0)
-               dev_err(sdev->dev, "error: pcm open failed %d\n", ret);
+               dev_err(component->dev, "error: pcm open failed %d\n", ret);
 
        return ret;
 }
 
-static int sof_pcm_close(struct snd_pcm_substream *substream)
+static int sof_pcm_close(struct snd_soc_component *component,
+                        struct snd_pcm_substream *substream)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_component *component =
-               snd_soc_rtdcom_lookup(rtd, DRV_NAME);
        struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
        struct snd_sof_pcm *spcm;
        int err;
@@ -518,16 +536,16 @@ static int sof_pcm_close(struct snd_pcm_substream *substream)
        if (rtd->dai_link->no_pcm)
                return 0;
 
-       spcm = snd_sof_find_spcm_dai(sdev, rtd);
+       spcm = snd_sof_find_spcm_dai(component, rtd);
        if (!spcm)
                return -EINVAL;
 
-       dev_dbg(sdev->dev, "pcm: close stream %d dir %d\n", spcm->pcm.pcm_id,
-               substream->stream);
+       dev_dbg(component->dev, "pcm: close stream %d dir %d\n",
+               spcm->pcm.pcm_id, substream->stream);
 
        err = snd_sof_pcm_platform_close(sdev, substream);
        if (err < 0) {
-               dev_err(sdev->dev, "error: pcm close failed %d\n",
+               dev_err(component->dev, "error: pcm close failed %d\n",
                        err);
                /*
                 * keep going, no point in preventing the close
@@ -538,27 +556,14 @@ static int sof_pcm_close(struct snd_pcm_substream *substream)
        return 0;
 }
 
-static struct snd_pcm_ops sof_pcm_ops = {
-       .open           = sof_pcm_open,
-       .close          = sof_pcm_close,
-       .ioctl          = snd_pcm_lib_ioctl,
-       .hw_params      = sof_pcm_hw_params,
-       .prepare        = sof_pcm_prepare,
-       .hw_free        = sof_pcm_hw_free,
-       .trigger        = sof_pcm_trigger,
-       .pointer        = sof_pcm_pointer,
-       .page           = snd_pcm_sgbuf_ops_page,
-};
-
 /*
  * Pre-allocate playback/capture audio buffer pages.
  * no need to explicitly release memory preallocated by sof_pcm_new in pcm_free
  * snd_pcm_lib_preallocate_free_for_all() is called by the core.
  */
-static int sof_pcm_new(struct snd_soc_pcm_runtime *rtd)
+static int sof_pcm_new(struct snd_soc_component *component,
+                      struct snd_soc_pcm_runtime *rtd)
 {
-       struct snd_soc_component *component =
-               snd_soc_rtdcom_lookup(rtd, DRV_NAME);
        struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
        struct snd_sof_pcm *spcm;
        struct snd_pcm *pcm = rtd->pcm;
@@ -566,14 +571,14 @@ static int sof_pcm_new(struct snd_soc_pcm_runtime *rtd)
        int stream = SNDRV_PCM_STREAM_PLAYBACK;
 
        /* find SOF PCM for this RTD */
-       spcm = snd_sof_find_spcm_dai(sdev, rtd);
+       spcm = snd_sof_find_spcm_dai(component, rtd);
        if (!spcm) {
-               dev_warn(sdev->dev, "warn: can't find PCM with DAI ID %d\n",
+               dev_warn(component->dev, "warn: can't find PCM with DAI ID %d\n",
                         rtd->dai_link->id);
                return 0;
        }
 
-       dev_dbg(sdev->dev, "creating new PCM %s\n", spcm->pcm.pcm_name);
+       dev_dbg(component->dev, "creating new PCM %s\n", spcm->pcm.pcm_name);
 
        /* do we need to pre-allocate playback audio buffer pages */
        if (!spcm->pcm.playback)
@@ -582,13 +587,19 @@ static int sof_pcm_new(struct snd_soc_pcm_runtime *rtd)
        caps = &spcm->pcm.caps[stream];
 
        /* pre-allocate playback audio buffer pages */
-       dev_dbg(sdev->dev, "spcm: allocate %s playback DMA buffer size 0x%x max 0x%x\n",
+       dev_dbg(component->dev,
+               "spcm: allocate %s playback DMA buffer size 0x%x max 0x%x\n",
                caps->name, caps->buffer_size_min, caps->buffer_size_max);
 
-       snd_pcm_lib_preallocate_pages(pcm->streams[stream].substream,
-                                     SNDRV_DMA_TYPE_DEV_SG, sdev->dev,
-                                     le32_to_cpu(caps->buffer_size_min),
-                                     le32_to_cpu(caps->buffer_size_max));
+       if (!pcm->streams[stream].substream) {
+               dev_err(component->dev, "error: NULL playback substream!\n");
+               return -EINVAL;
+       }
+
+       snd_pcm_set_managed_buffer(pcm->streams[stream].substream,
+                                  SNDRV_DMA_TYPE_DEV_SG, sdev->dev,
+                                  le32_to_cpu(caps->buffer_size_min),
+                                  le32_to_cpu(caps->buffer_size_max));
 capture:
        stream = SNDRV_PCM_STREAM_CAPTURE;
 
@@ -599,13 +610,19 @@ capture:
        caps = &spcm->pcm.caps[stream];
 
        /* pre-allocate capture audio buffer pages */
-       dev_dbg(sdev->dev, "spcm: allocate %s capture DMA buffer size 0x%x max 0x%x\n",
+       dev_dbg(component->dev,
+               "spcm: allocate %s capture DMA buffer size 0x%x max 0x%x\n",
                caps->name, caps->buffer_size_min, caps->buffer_size_max);
 
-       snd_pcm_lib_preallocate_pages(pcm->streams[stream].substream,
-                                     SNDRV_DMA_TYPE_DEV_SG, sdev->dev,
-                                     le32_to_cpu(caps->buffer_size_min),
-                                     le32_to_cpu(caps->buffer_size_max));
+       if (!pcm->streams[stream].substream) {
+               dev_err(component->dev, "error: NULL capture substream!\n");
+               return -EINVAL;
+       }
+
+       snd_pcm_set_managed_buffer(pcm->streams[stream].substream,
+                                  SNDRV_DMA_TYPE_DEV_SG, sdev->dev,
+                                  le32_to_cpu(caps->buffer_size_min),
+                                  le32_to_cpu(caps->buffer_size_max));
 
        return 0;
 }
@@ -620,14 +637,14 @@ static int sof_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd,
                                                SNDRV_PCM_HW_PARAM_CHANNELS);
        struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
        struct snd_soc_component *component =
-               snd_soc_rtdcom_lookup(rtd, DRV_NAME);
-       struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
+               snd_soc_rtdcom_lookup(rtd, SOF_AUDIO_PCM_DRV_NAME);
        struct snd_sof_dai *dai =
-               snd_sof_find_dai(sdev, (char *)rtd->dai_link->name);
+               snd_sof_find_dai(component, (char *)rtd->dai_link->name);
 
        /* no topology exists for this BE, try a common configuration */
        if (!dai) {
-               dev_warn(sdev->dev, "warning: no topology found for BE DAI %s config\n",
+               dev_warn(component->dev,
+                        "warning: no topology found for BE DAI %s config\n",
                         rtd->dai_link->name);
 
                /*  set 48k, stereo, 16bits by default */
@@ -657,7 +674,7 @@ static int sof_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd,
                snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S32_LE);
                break;
        default:
-               dev_err(sdev->dev, "error: No available DAI format!\n");
+               dev_err(component->dev, "error: No available DAI format!\n");
                return -EINVAL;
        }
 
@@ -669,9 +686,9 @@ static int sof_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd,
                channels->min = dai->dai_config->ssp.tdm_slots;
                channels->max = dai->dai_config->ssp.tdm_slots;
 
-               dev_dbg(sdev->dev,
+               dev_dbg(component->dev,
                        "rate_min: %d rate_max: %d\n", rate->min, rate->max);
-               dev_dbg(sdev->dev,
+               dev_dbg(component->dev,
                        "channels_min: %d channels_max: %d\n",
                        channels->min, channels->max);
 
@@ -679,7 +696,7 @@ static int sof_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd,
        case SOF_DAI_INTEL_DMIC:
                /* DMIC only supports 16 or 32 bit formats */
                if (dai->comp_dai.config.frame_fmt == SOF_IPC_FRAME_S24_4LE) {
-                       dev_err(sdev->dev,
+                       dev_err(component->dev,
                                "error: invalid fmt %d for DAI type %d\n",
                                dai->comp_dai.config.frame_fmt,
                                dai->dai_config->type);
@@ -691,8 +708,24 @@ static int sof_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd,
        case SOF_DAI_INTEL_ALH:
                /* do nothing for ALH dai_link */
                break;
+       case SOF_DAI_IMX_ESAI:
+               channels->min = dai->dai_config->esai.tdm_slots;
+               channels->max = dai->dai_config->esai.tdm_slots;
+
+               dev_dbg(component->dev,
+                       "channels_min: %d channels_max: %d\n",
+                       channels->min, channels->max);
+               break;
+       case SOF_DAI_IMX_SAI:
+               channels->min = dai->dai_config->sai.tdm_slots;
+               channels->max = dai->dai_config->sai.tdm_slots;
+
+               dev_dbg(component->dev,
+                       "channels_min: %d channels_max: %d\n",
+                       channels->min, channels->max);
+               break;
        default:
-               dev_err(sdev->dev, "error: invalid DAI type %d\n",
+               dev_err(component->dev, "error: invalid DAI type %d\n",
                        dai->dai_config->type);
                break;
        }
@@ -717,21 +750,13 @@ static int sof_pcm_probe(struct snd_soc_component *component)
        if (!tplg_filename)
                return -ENOMEM;
 
-       ret = snd_sof_load_topology(sdev, tplg_filename);
+       ret = snd_sof_load_topology(component, tplg_filename);
        if (ret < 0) {
-               dev_err(sdev->dev, "error: failed to load DSP topology %d\n",
+               dev_err(component->dev, "error: failed to load DSP topology %d\n",
                        ret);
                return ret;
        }
 
-       /*
-        * Some platforms in SOF, ex: BYT, may not have their platform PM
-        * callbacks set. Increment the usage count so as to
-        * prevent the device from entering runtime suspend.
-        */
-       if (!sof_ops(sdev)->runtime_suspend || !sof_ops(sdev)->runtime_resume)
-               pm_runtime_get_noresume(sdev->dev);
-
        return ret;
 }
 
@@ -752,11 +777,18 @@ void snd_sof_new_platform_drv(struct snd_sof_dev *sdev)
        pd->name = "sof-audio-component";
        pd->probe = sof_pcm_probe;
        pd->remove = sof_pcm_remove;
-       pd->ops = &sof_pcm_ops;
+       pd->open = sof_pcm_open;
+       pd->close = sof_pcm_close;
+       pd->hw_params = sof_pcm_hw_params;
+       pd->prepare = sof_pcm_prepare;
+       pd->hw_free = sof_pcm_hw_free;
+       pd->trigger = sof_pcm_trigger;
+       pd->pointer = sof_pcm_pointer;
+
 #if IS_ENABLED(CONFIG_SND_SOC_SOF_COMPRESS)
        pd->compr_ops = &sof_compressed_ops;
 #endif
-       pd->pcm_new = sof_pcm_new;
+       pd->pcm_construct = sof_pcm_new;
        pd->ignore_machine = drv_name;
        pd->be_hw_params_fixup = sof_pcm_dai_link_fixup;
        pd->be_pcm_base = SOF_BE_PCM_BASE;