dmaengine: sh: rz-dmac: Fix destination and source data size setting
authorHien Huynh <hien.huynh.px@renesas.com>
Thu, 6 Jul 2023 11:21:50 +0000 (12:21 +0100)
committerVinod Koul <vkoul@kernel.org>
Wed, 12 Jul 2023 16:54:00 +0000 (22:24 +0530)
Before setting DDS and SDS values, we need to clear its value first
otherwise, we get incorrect results when we change/update the DMA bus
width several times due to the 'OR' expression.

Fixes: 5000d37042a6 ("dmaengine: sh: Add DMAC driver for RZ/G2L SoC")
Cc: stable@kernel.org
Signed-off-by: Hien Huynh <hien.huynh.px@renesas.com>
Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Link: https://lore.kernel.org/r/20230706112150.198941-3-biju.das.jz@bp.renesas.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
drivers/dma/sh/rz-dmac.c

index 229f642..f777add 100644 (file)
@@ -9,6 +9,7 @@
  * Copyright 2012 Javier Martin, Vista Silicon <javier.martin@vista-silicon.com>
  */
 
+#include <linux/bitfield.h>
 #include <linux/dma-mapping.h>
 #include <linux/dmaengine.h>
 #include <linux/interrupt.h>
@@ -145,8 +146,8 @@ struct rz_dmac {
 #define CHCFG_REQD                     BIT(3)
 #define CHCFG_SEL(bits)                        ((bits) & 0x07)
 #define CHCFG_MEM_COPY                 (0x80400008)
-#define CHCFG_FILL_DDS(a)              (((a) << 16) & GENMASK(19, 16))
-#define CHCFG_FILL_SDS(a)              (((a) << 12) & GENMASK(15, 12))
+#define CHCFG_FILL_DDS_MASK            GENMASK(19, 16)
+#define CHCFG_FILL_SDS_MASK            GENMASK(15, 12)
 #define CHCFG_FILL_TM(a)               (((a) & BIT(5)) << 22)
 #define CHCFG_FILL_AM(a)               (((a) & GENMASK(4, 2)) << 6)
 #define CHCFG_FILL_LVL(a)              (((a) & BIT(1)) << 5)
@@ -607,13 +608,15 @@ static int rz_dmac_config(struct dma_chan *chan,
        if (val == CHCFG_DS_INVALID)
                return -EINVAL;
 
-       channel->chcfg |= CHCFG_FILL_DDS(val);
+       channel->chcfg &= ~CHCFG_FILL_DDS_MASK;
+       channel->chcfg |= FIELD_PREP(CHCFG_FILL_DDS_MASK, val);
 
        val = rz_dmac_ds_to_val_mapping(config->src_addr_width);
        if (val == CHCFG_DS_INVALID)
                return -EINVAL;
 
-       channel->chcfg |= CHCFG_FILL_SDS(val);
+       channel->chcfg &= ~CHCFG_FILL_SDS_MASK;
+       channel->chcfg |= FIELD_PREP(CHCFG_FILL_SDS_MASK, val);
 
        return 0;
 }