diff mbox series

[2/2] spi: spi-mtk-nor: support 36bit dma addressing to mediatek spi-nor

Message ID 20200910041101.1695195-3-ikjn@chromium.org (mailing list archive)
State New, archived
Headers show
Series Add 36bit dma support to mediatek spi-nor controller. | expand

Commit Message

Ikjoon Jang Sept. 10, 2020, 4:11 a.m. UTC
This patch enables direct mappings over 32bit range to spi-mtk-nor.

Signed-off-by: Ikjoon Jang <ikjn@chromium.org>

---

 drivers/spi/spi-mtk-nor.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

Comments

kernel test robot Sept. 10, 2020, 9:52 a.m. UTC | #1
Hi Ikjoon,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on spi/for-next]
[also build test WARNING on next-20200909]
[cannot apply to robh/for-next v5.9-rc4]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Ikjoon-Jang/Add-36bit-dma-support-to-mediatek-spi-nor-controller/20200910-121600
base:   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next
config: sh-allmodconfig (attached as .config)
compiler: sh4-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=sh 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   In file included from include/linux/scatterlist.h:9,
                    from include/linux/dma-mapping.h:11,
                    from drivers/spi/spi-mtk-nor.c:10:
   drivers/spi/spi-mtk-nor.c: In function 'mtk_nor_read_dma':
>> drivers/spi/spi-mtk-nor.c:286:19: warning: right shift count >= width of type [-Wshift-count-overflow]
     286 |   writel(dma_addr >> 32, sp->base + MTK_NOR_REG_DMA_DADR_HB);
         |                   ^~
   arch/sh/include/asm/io.h:31:77: note: in definition of macro '__raw_writel'
      31 | #define __raw_writel(v,a) (__chk_io_ptr(a), *(volatile u32 __force *)(a) = (v))
         |                                                                             ^
   arch/sh/include/asm/io.h:46:62: note: in expansion of macro 'ioswabl'
      46 | #define writel_relaxed(v,c) ((void)__raw_writel((__force u32)ioswabl(v),c))
         |                                                              ^~~~~~~
   arch/sh/include/asm/io.h:56:32: note: in expansion of macro 'writel_relaxed'
      56 | #define writel(v,a)  ({ wmb(); writel_relaxed((v),(a)); })
         |                                ^~~~~~~~~~~~~~
   drivers/spi/spi-mtk-nor.c:286:3: note: in expansion of macro 'writel'
     286 |   writel(dma_addr >> 32, sp->base + MTK_NOR_REG_DMA_DADR_HB);
         |   ^~~~~~
   drivers/spi/spi-mtk-nor.c:287:30: warning: right shift count >= width of type [-Wshift-count-overflow]
     287 |   writel((dma_addr + length) >> 32, sp->base + MTK_NOR_REG_DMA_END_DADR_HB);
         |                              ^~
   arch/sh/include/asm/io.h:31:77: note: in definition of macro '__raw_writel'
      31 | #define __raw_writel(v,a) (__chk_io_ptr(a), *(volatile u32 __force *)(a) = (v))
         |                                                                             ^
   arch/sh/include/asm/io.h:46:62: note: in expansion of macro 'ioswabl'
      46 | #define writel_relaxed(v,c) ((void)__raw_writel((__force u32)ioswabl(v),c))
         |                                                              ^~~~~~~
   arch/sh/include/asm/io.h:56:32: note: in expansion of macro 'writel_relaxed'
      56 | #define writel(v,a)  ({ wmb(); writel_relaxed((v),(a)); })
         |                                ^~~~~~~~~~~~~~
   drivers/spi/spi-mtk-nor.c:287:3: note: in expansion of macro 'writel'
     287 |   writel((dma_addr + length) >> 32, sp->base + MTK_NOR_REG_DMA_END_DADR_HB);
         |   ^~~~~~

# https://github.com/0day-ci/linux/commit/d6ccdab2988e8bf7aa66cc57daeac5e1a7e399cc
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Ikjoon-Jang/Add-36bit-dma-support-to-mediatek-spi-nor-controller/20200910-121600
git checkout d6ccdab2988e8bf7aa66cc57daeac5e1a7e399cc
vim +286 drivers/spi/spi-mtk-nor.c

   266	
   267	static int mtk_nor_read_dma(struct mtk_nor *sp, u32 from, unsigned int length,
   268				    u8 *buffer)
   269	{
   270		int ret = 0;
   271		ulong delay;
   272		u32 reg;
   273		dma_addr_t dma_addr;
   274	
   275		dma_addr = dma_map_single(sp->dev, buffer, length, DMA_FROM_DEVICE);
   276		if (dma_mapping_error(sp->dev, dma_addr)) {
   277			dev_err(sp->dev, "failed to map dma buffer.\n");
   278			return -EINVAL;
   279		}
   280	
   281		writel(from, sp->base + MTK_NOR_REG_DMA_FADR);
   282		writel(dma_addr, sp->base + MTK_NOR_REG_DMA_DADR);
   283		writel(dma_addr + length, sp->base + MTK_NOR_REG_DMA_END_DADR);
   284	
   285		if (sp->high_dma) {
 > 286			writel(dma_addr >> 32, sp->base + MTK_NOR_REG_DMA_DADR_HB);
   287			writel((dma_addr + length) >> 32, sp->base + MTK_NOR_REG_DMA_END_DADR_HB);
   288		}
   289	
   290		if (sp->has_irq) {
   291			reinit_completion(&sp->op_done);
   292			mtk_nor_rmw(sp, MTK_NOR_REG_IRQ_EN, MTK_NOR_IRQ_DMA, 0);
   293		}
   294	
   295		mtk_nor_rmw(sp, MTK_NOR_REG_DMA_CTL, MTK_NOR_DMA_START, 0);
   296	
   297		delay = CLK_TO_US(sp, (length + 5) * BITS_PER_BYTE);
   298	
   299		if (sp->has_irq) {
   300			if (!wait_for_completion_timeout(&sp->op_done,
   301							 (delay + 1) * 100))
   302				ret = -ETIMEDOUT;
   303		} else {
   304			ret = readl_poll_timeout(sp->base + MTK_NOR_REG_DMA_CTL, reg,
   305						 !(reg & MTK_NOR_DMA_START), delay / 3,
   306						 (delay + 1) * 100);
   307		}
   308	
   309		dma_unmap_single(sp->dev, dma_addr, length, DMA_FROM_DEVICE);
   310		if (ret < 0)
   311			dev_err(sp->dev, "dma read timeout.\n");
   312	
   313		return ret;
   314	}
   315	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
kernel test robot Sept. 11, 2020, 11:31 a.m. UTC | #2
Hi Ikjoon,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on spi/for-next]
[also build test WARNING on next-20200910]
[cannot apply to robh/for-next v5.9-rc4]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Ikjoon-Jang/Add-36bit-dma-support-to-mediatek-spi-nor-controller/20200910-121600
base:   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next
config: arm-randconfig-r035-20200909 (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project 0a5dc7effb191eff740e0e7ae7bd8e1f6bdb3ad9)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install arm cross compiling tool for clang build
        # apt-get install binutils-arm-linux-gnueabi
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> drivers/spi/spi-mtk-nor.c:286:19: warning: shift count >= width of type [-Wshift-count-overflow]
                   writel(dma_addr >> 32, sp->base + MTK_NOR_REG_DMA_DADR_HB);
                                   ^  ~~
   arch/arm/include/asm/io.h:307:51: note: expanded from macro 'writel'
   #define writel(v,c)             ({ __iowmb(); writel_relaxed(v,c); })
                                                                ^
   arch/arm/include/asm/io.h:299:68: note: expanded from macro 'writel_relaxed'
   #define writel_relaxed(v,c)     __raw_writel((__force u32) cpu_to_le32(v),c)
                                                                          ^
   include/uapi/linux/byteorder/little_endian.h:33:51: note: expanded from macro '__cpu_to_le32'
   #define __cpu_to_le32(x) ((__force __le32)(__u32)(x))
                                                     ^
   drivers/spi/spi-mtk-nor.c:287:30: warning: shift count >= width of type [-Wshift-count-overflow]
                   writel((dma_addr + length) >> 32, sp->base + MTK_NOR_REG_DMA_END_DADR_HB);
                                              ^  ~~
   arch/arm/include/asm/io.h:307:51: note: expanded from macro 'writel'
   #define writel(v,c)             ({ __iowmb(); writel_relaxed(v,c); })
                                                                ^
   arch/arm/include/asm/io.h:299:68: note: expanded from macro 'writel_relaxed'
   #define writel_relaxed(v,c)     __raw_writel((__force u32) cpu_to_le32(v),c)
                                                                          ^
   include/uapi/linux/byteorder/little_endian.h:33:51: note: expanded from macro '__cpu_to_le32'
   #define __cpu_to_le32(x) ((__force __le32)(__u32)(x))
                                                     ^
   2 warnings generated.

# https://github.com/0day-ci/linux/commit/d6ccdab2988e8bf7aa66cc57daeac5e1a7e399cc
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Ikjoon-Jang/Add-36bit-dma-support-to-mediatek-spi-nor-controller/20200910-121600
git checkout d6ccdab2988e8bf7aa66cc57daeac5e1a7e399cc
vim +286 drivers/spi/spi-mtk-nor.c

   266	
   267	static int mtk_nor_read_dma(struct mtk_nor *sp, u32 from, unsigned int length,
   268				    u8 *buffer)
   269	{
   270		int ret = 0;
   271		ulong delay;
   272		u32 reg;
   273		dma_addr_t dma_addr;
   274	
   275		dma_addr = dma_map_single(sp->dev, buffer, length, DMA_FROM_DEVICE);
   276		if (dma_mapping_error(sp->dev, dma_addr)) {
   277			dev_err(sp->dev, "failed to map dma buffer.\n");
   278			return -EINVAL;
   279		}
   280	
   281		writel(from, sp->base + MTK_NOR_REG_DMA_FADR);
   282		writel(dma_addr, sp->base + MTK_NOR_REG_DMA_DADR);
   283		writel(dma_addr + length, sp->base + MTK_NOR_REG_DMA_END_DADR);
   284	
   285		if (sp->high_dma) {
 > 286			writel(dma_addr >> 32, sp->base + MTK_NOR_REG_DMA_DADR_HB);
   287			writel((dma_addr + length) >> 32, sp->base + MTK_NOR_REG_DMA_END_DADR_HB);
   288		}
   289	
   290		if (sp->has_irq) {
   291			reinit_completion(&sp->op_done);
   292			mtk_nor_rmw(sp, MTK_NOR_REG_IRQ_EN, MTK_NOR_IRQ_DMA, 0);
   293		}
   294	
   295		mtk_nor_rmw(sp, MTK_NOR_REG_DMA_CTL, MTK_NOR_DMA_START, 0);
   296	
   297		delay = CLK_TO_US(sp, (length + 5) * BITS_PER_BYTE);
   298	
   299		if (sp->has_irq) {
   300			if (!wait_for_completion_timeout(&sp->op_done,
   301							 (delay + 1) * 100))
   302				ret = -ETIMEDOUT;
   303		} else {
   304			ret = readl_poll_timeout(sp->base + MTK_NOR_REG_DMA_CTL, reg,
   305						 !(reg & MTK_NOR_DMA_START), delay / 3,
   306						 (delay + 1) * 100);
   307		}
   308	
   309		dma_unmap_single(sp->dev, dma_addr, length, DMA_FROM_DEVICE);
   310		if (ret < 0)
   311			dev_err(sp->dev, "dma read timeout.\n");
   312	
   313		return ret;
   314	}
   315	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff mbox series

Patch

diff --git a/drivers/spi/spi-mtk-nor.c b/drivers/spi/spi-mtk-nor.c
index 6e6ca2b8e6c8..eb93ae34e670 100644
--- a/drivers/spi/spi-mtk-nor.c
+++ b/drivers/spi/spi-mtk-nor.c
@@ -78,6 +78,8 @@ 
 #define MTK_NOR_REG_DMA_FADR		0x71c
 #define MTK_NOR_REG_DMA_DADR		0x720
 #define MTK_NOR_REG_DMA_END_DADR	0x724
+#define MTK_NOR_REG_DMA_DADR_HB		0x738
+#define MTK_NOR_REG_DMA_END_DADR_HB	0x73c
 
 #define MTK_NOR_PRG_MAX_SIZE		6
 // Reading DMA src/dst addresses have to be 16-byte aligned
@@ -101,6 +103,7 @@  struct mtk_nor {
 	unsigned int spi_freq;
 	bool wbuf_en;
 	bool has_irq;
+	bool high_dma;
 	struct completion op_done;
 };
 
@@ -279,6 +282,11 @@  static int mtk_nor_read_dma(struct mtk_nor *sp, u32 from, unsigned int length,
 	writel(dma_addr, sp->base + MTK_NOR_REG_DMA_DADR);
 	writel(dma_addr + length, sp->base + MTK_NOR_REG_DMA_END_DADR);
 
+	if (sp->high_dma) {
+		writel(dma_addr >> 32, sp->base + MTK_NOR_REG_DMA_DADR_HB);
+		writel((dma_addr + length) >> 32, sp->base + MTK_NOR_REG_DMA_END_DADR_HB);
+	}
+
 	if (sp->has_irq) {
 		reinit_completion(&sp->op_done);
 		mtk_nor_rmw(sp, MTK_NOR_REG_IRQ_EN, MTK_NOR_IRQ_DMA, 0);
@@ -578,7 +586,8 @@  static const struct spi_controller_mem_ops mtk_nor_mem_ops = {
 };
 
 static const struct of_device_id mtk_nor_match[] = {
-	{ .compatible = "mediatek,mt8173-nor" },
+	{ .compatible = "mediatek,mt8192-nor", .data = (void *)36 },
+	{ .compatible = "mediatek,mt8173-nor", .data = (void *)32 },
 	{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, mtk_nor_match);
@@ -591,6 +600,7 @@  static int mtk_nor_probe(struct platform_device *pdev)
 	u8 *buffer;
 	struct clk *spi_clk, *ctlr_clk;
 	int ret, irq;
+	unsigned long dma_bits;
 
 	base = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(base))
@@ -614,6 +624,12 @@  static int mtk_nor_probe(struct platform_device *pdev)
 		buffer = (u8 *)(((ulong)buffer + MTK_NOR_DMA_ALIGN) &
 				~MTK_NOR_DMA_ALIGN_MASK);
 
+	dma_bits = (unsigned long)of_device_get_match_data(&pdev->dev);
+	if (dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(dma_bits))) {
+		dev_err(&pdev->dev, "failed to set dma mask(%lu)\n", dma_bits);
+		return -EINVAL;
+	}
+
 	ctlr = spi_alloc_master(&pdev->dev, sizeof(*sp));
 	if (!ctlr) {
 		dev_err(&pdev->dev, "failed to allocate spi controller\n");
@@ -640,6 +656,7 @@  static int mtk_nor_probe(struct platform_device *pdev)
 	sp->dev = &pdev->dev;
 	sp->spi_clk = spi_clk;
 	sp->ctlr_clk = ctlr_clk;
+	sp->high_dma = (dma_bits > 32);
 
 	irq = platform_get_irq_optional(pdev, 0);
 	if (irq < 0) {