return 0;
 }
 
+static struct lpaif_dmactl *__lpass_get_dmactl_handle(const struct snd_pcm_substream *substream,
+                                    struct snd_soc_component *component)
+{
+       struct snd_soc_pcm_runtime *soc_runtime = asoc_substream_to_rtd(substream);
+       struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(soc_runtime, 0);
+       struct lpass_data *drvdata = snd_soc_component_get_drvdata(component);
+       struct lpaif_dmactl *dmactl = NULL;
+
+       switch (cpu_dai->driver->id) {
+       case MI2S_PRIMARY ... MI2S_QUINARY:
+               if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+                       dmactl = drvdata->rd_dmactl;
+               else
+                       dmactl = drvdata->wr_dmactl;
+               break;
+       case LPASS_DP_RX:
+               dmactl = drvdata->hdmi_rd_dmactl;
+               break;
+       }
+
+       return dmactl;
+}
+
+static int __lpass_get_id(const struct snd_pcm_substream *substream,
+                                    struct snd_soc_component *component)
+{
+       struct snd_soc_pcm_runtime *soc_runtime = asoc_substream_to_rtd(substream);
+       struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(soc_runtime, 0);
+       struct lpass_data *drvdata = snd_soc_component_get_drvdata(component);
+       struct snd_pcm_runtime *rt = substream->runtime;
+       struct lpass_pcm_data *pcm_data = rt->private_data;
+       struct lpass_variant *v = drvdata->variant;
+       int id;
+
+       switch (cpu_dai->driver->id) {
+       case MI2S_PRIMARY ... MI2S_QUINARY:
+               if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+                       id = pcm_data->dma_ch;
+               else
+                       id = pcm_data->dma_ch - v->wrdma_channel_start;
+               break;
+       case LPASS_DP_RX:
+               id = pcm_data->dma_ch;
+               break;
+       }
+
+       return id;
+}
+
+static struct regmap *__lpass_get_regmap_handle(const struct snd_pcm_substream *substream,
+                                    struct snd_soc_component *component)
+{
+       struct snd_soc_pcm_runtime *soc_runtime = asoc_substream_to_rtd(substream);
+       struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(soc_runtime, 0);
+       struct lpass_data *drvdata = snd_soc_component_get_drvdata(component);
+       struct regmap *map = NULL;
+
+       switch (cpu_dai->driver->id) {
+       case MI2S_PRIMARY ... MI2S_QUINARY:
+               map = drvdata->lpaif_map;
+               break;
+       case LPASS_DP_RX:
+               map = drvdata->hdmiif_map;
+               break;
+       }
+
+       return map;
+}
+
 static int lpass_platform_pcmops_hw_params(struct snd_soc_component *component,
                                           struct snd_pcm_substream *substream,
                                           struct snd_pcm_hw_params *params)
        unsigned int channels = params_channels(params);
        unsigned int regval;
        struct lpaif_dmactl *dmactl;
-       int id, dir = substream->stream;
+       int id;
        int bitwidth;
        int ret, dma_port = pcm_data->i2s_port + v->dmactl_audif_start;
        unsigned int dai_id = cpu_dai->driver->id;
 
-       if (dir ==  SNDRV_PCM_STREAM_PLAYBACK) {
-               id = pcm_data->dma_ch;
-               if (dai_id == LPASS_DP_RX)
-                       dmactl = drvdata->hdmi_rd_dmactl;
-               else
-                       dmactl = drvdata->rd_dmactl;
-
-       } else {
-               dmactl = drvdata->wr_dmactl;
-               id = pcm_data->dma_ch - v->wrdma_channel_start;
-       }
+       dmactl = __lpass_get_dmactl_handle(substream, component);
+       id = __lpass_get_id(substream, component);
 
        bitwidth = snd_pcm_format_width(format);
        if (bitwidth < 0) {
        struct regmap *map;
        unsigned int dai_id = cpu_dai->driver->id;
 
-       if (dai_id == LPASS_DP_RX)
-               map = drvdata->hdmiif_map;
-       else
-               map = drvdata->lpaif_map;
+       map = __lpass_get_regmap_handle(substream, component);
 
        reg = LPAIF_DMACTL_REG(v, pcm_data->dma_ch, substream->stream, dai_id);
        ret = regmap_write(map, reg, 0);
        int ret, id, ch, dir = substream->stream;
        unsigned int dai_id = cpu_dai->driver->id;
 
-
        ch = pcm_data->dma_ch;
-       if (dir ==  SNDRV_PCM_STREAM_PLAYBACK) {
-               if (dai_id == LPASS_DP_RX) {
-                       dmactl = drvdata->hdmi_rd_dmactl;
-                       map = drvdata->hdmiif_map;
-               } else {
-                       dmactl = drvdata->rd_dmactl;
-                       map = drvdata->lpaif_map;
-               }
 
-               id = pcm_data->dma_ch;
-       } else {
-               dmactl = drvdata->wr_dmactl;
-               id = pcm_data->dma_ch - v->wrdma_channel_start;
-               map = drvdata->lpaif_map;
-       }
+       dmactl = __lpass_get_dmactl_handle(substream, component);
+       id = __lpass_get_id(substream, component);
+       map = __lpass_get_regmap_handle(substream, component);
 
        ret = regmap_write(map, LPAIF_DMABASE_REG(v, ch, dir, dai_id),
                                runtime->dma_addr);
        struct lpaif_dmactl *dmactl;
        struct regmap *map;
        int ret, ch, id;
-       int dir = substream->stream;
        unsigned int reg_irqclr = 0, val_irqclr = 0;
        unsigned int  reg_irqen = 0, val_irqen = 0, val_mask = 0;
        unsigned int dai_id = cpu_dai->driver->id;
 
        ch = pcm_data->dma_ch;
-       if (dir ==  SNDRV_PCM_STREAM_PLAYBACK) {
-               id = pcm_data->dma_ch;
-               if (dai_id == LPASS_DP_RX) {
-                       dmactl = drvdata->hdmi_rd_dmactl;
-                       map = drvdata->hdmiif_map;
-               } else {
-                       dmactl = drvdata->rd_dmactl;
-                       map = drvdata->lpaif_map;
-               }
-       } else {
-               dmactl = drvdata->wr_dmactl;
-               id = pcm_data->dma_ch - v->wrdma_channel_start;
-               map = drvdata->lpaif_map;
-       }
+       dmactl = __lpass_get_dmactl_handle(substream, component);
+       id = __lpass_get_id(substream, component);
+       map = __lpass_get_regmap_handle(substream, component);
 
        switch (cmd) {
        case SNDRV_PCM_TRIGGER_START:
        struct regmap *map;
        unsigned int dai_id = cpu_dai->driver->id;
 
-       if (dai_id == LPASS_DP_RX)
-               map = drvdata->hdmiif_map;
-       else
-               map = drvdata->lpaif_map;
-
+       map = __lpass_get_regmap_handle(substream, component);
        ch = pcm_data->dma_ch;
 
        ret = regmap_read(map,