dmaengine: add support mmp-pdma
v2 cover dmaengine: add support mmp-pdma
v1->v2
Sync with Arnd and Haojoan, change compatible name to "marvell,pdma-1.0" Used platfroms: pxa25x, pxa27x, pxa3xx, pxa93x, pxa168, pxa910, pxa688. Use IP name rather than platform name
v0->v1
Update dt member and desc according to Arnd's suggestion
Use dma_slave_config.slave_id to transfer drcmr followed Vinod's suggestion
Patch 4 is upload as example
mtd: pxa3xx-nand: replace pxa_request_dma with dmaengine We would like hold this patch currently
since pdma will grab irq and disable pxa_init_dma.
mmp-pdma is added under dmaengine framework. The final purpose is replacing arch/arm/plat-pxa/dma.c
Test on pxa910 with pxa3xx-nand and dmatest.ko
Zhangfei Gao (4):
dmaengine: mmp-pdma support
dmaengine: mmp_tdma: add dt support
dmatest: add dmaengine_slave_config for DMA_MEMCPY
mtd: pxa3xx-nand: replace pxa_request_dma with dmaengine
Documentation/devicetree/bindings/dma/mmp-dma.txt | 75 ++ drivers/dma/Kconfig | 7 + drivers/dma/Makefile | 1 + drivers/dma/dmatest.c | 4 + drivers/dma/mmp_pdma.c | 872 +++++++++++++++++++++ drivers/dma/mmp_tdma.c | 51 +- drivers/mtd/nand/pxa3xx_nand.c | 113 ++-- include/linux/platform_data/mmp_dma.h | 19 + 8 files changed, 1072 insertions(+), 70 deletions(-) create mode 100644 Documentation/devicetree/bindings/dma/mmp-dma.txt create mode 100644 drivers/dma/mmp_pdma.c create mode 100644 include/linux/platform_data/mmp_dma.h
PATCH v2 1/4 dmaengine: mmp-pdma support
1. virtual channel vs. physical channel
Virtual channel is managed by dmaengine
Physical channel handling resource, such as irq
Physical channel is alloced dynamically as descending priority, freed immediately when irq done.
The availble highest priority physically channel will alwayes be alloced
Issue pending list -> alloc highest dma physically channel available -> dma done -> free physically channel
2. list: running list & pending list
submit: desc list -> pending listissue_pending_list: if (IDLE) pending list -> running list; free pending list (RUN)
irq: free running list (IDLE)
check pendlist -> pending list -> running list; free pending list (RUN)
3. irq:
Each list generate one irq, calling callback
One list may contain several desc chain, in such case, make sure only the last desc list generate irq.
4. async
Submit will add desc chain to pending list, which can be multi-called If multi desc chain is submitted, only the last desc would generate irq -> call back If IDLE, issue_pending_list start pending_list, transforming pendlist to running list If RUN, irq will start pending list
5. test
5.1 pxa3xx_nand on pxa910
5.2 insmod dmatest.ko (threads_per_chan=y)
By default drivers/dma/dmatest.c test every channel and test memcpy with 1 threads per channel
--- Documentation/devicetree/bindings/dma/mmp-dma.txt | 45 ++ drivers/dma/Kconfig | 7 + drivers/dma/Makefile | 1 + drivers/dma/mmp_pdma.c | 873 +++++++++++++++++++++ include/linux/platform_data/mmp_dma.h | 19 + 5 files changed, 945 insertions(+), 0 deletions(-) create mode 100644 Documentation/devicetree/bindings/dma/mmp-dma.txt create mode 100644 drivers/dma/mmp_pdma.c create mode 100644 include/linux/platform_data/mmp_dma.h
Documentation/devicetree/bindings/dma/mmp-dma.txt new file +45 -0
@@ -0,0 +1,45 @@ +* MARVELL MMP DMA controller + +Marvell Peripheral DMA Controller +Used platfroms: pxa688, pxa910, pxa3xx, etc + +Required properties: +- compatible: Should be "marvell,pdma-1.0" +- reg: Should contain DMA registers location and length. +- interrupts: Either contain all of the per-channel DMA interrupts + or one irq for pdma device +- dma-channels: Number of DMA channels supported by the controller. + +"marvell,pdma-1.0" +Used platfroms: pxa25x, pxa27x, pxa3xx, pxa93x, pxa168, pxa910, pxa688. + +Examples: + +/* + * Each channel has specific irq + * ICU parse out irq channel from ICU register, + * while DMA controller may not able to distinguish the irq channel + * Using this method, interrupt-parent is required as demuxer + * For example, pxa688 icu register 0x128, bit 0~15 is PDMA channel irq, + * 18~21 is ADMA irq + */ +pdma: dma-controller at d4000000 { + compatible = "marvell,pdma-1.0"; + reg = <0xd4000000 0x10000>; + interrupts = <0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15>; + interrupt-parent = <&intcmux32>; + dma-channels = <16>; + }; + +/* + * One irq for all channels + * Dmaengine driver (DMA controller) distinguish irq channel via + * parsing internal register + */ +pdma: dma-controller at d4000000 { + compatible = "marvell,pdma-1.0"; + reg = <0xd4000000 0x10000>; + interrupts = <47>; + dma-channels = <16>; + }; +
drivers/dma/Kconfig +7 -0
@@ -292,6 +292,13 @@ config MMP_TDMA Say Y here if you enabled MMP ADMA, otherwise say N. +config MMP_PDMA + bool "MMP PDMA support" + depends on (ARCH_MMP || ARCH_PXA) + select DMA_ENGINE + help + Support the MMP PDMA engine for PXA and MMP platfrom. + config DMA_ENGINE bool
drivers/dma/Makefile +1 -0
@@ -32,3 +32,4 @@ obj-$(CONFIG_EP93XX_DMA) += ep93xx_dma.o obj-$(CONFIG_DMA_SA11X0) += sa11x0-dma.o obj-$(CONFIG_DMA_OMAP) += omap-dma.o obj-$(CONFIG_MMP_TDMA) += mmp_tdma.o +obj-$(CONFIG_MMP_PDMA) += mmp_pdma.o
drivers/dma/mmp_pdma.c new file +873 -0
873 lines not on this page · raw message
include/linux/platform_data/mmp_dma.h new file +19 -0
@@ -0,0 +1,19 @@ +/* +* MMP Platform DMA Management +* +* Copyright (c) 2011 Marvell Semiconductors Inc. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +*/ + +#ifndef MMP_DMA_H +#define MMP_DMA_H + +struct mmp_dma_platdata { +int dma_channels; +}; + +#endif /* MMP_DMA_H */
Signature · 1 line
1.7.1
PATCH v2 1/4 dmaengine: mmp-pdma support
Quoted 25 lines · Zhangfei Gao
1. virtual channel vs. physical channel
Virtual channel is managed by dmaengine
Physical channel handling resource, such as irq
Physical channel is alloced dynamically as descending priority, freed immediately when irq done.
The availble highest priority physically channel will alwayes be allocedIssue pending list -> alloc highest dma physically channel available -> dma done -> free physically channel
2. list: running list & pending list
submit: desc list -> pending listissue_pending_list: if (IDLE) pending list -> running list; free pending list (RUN)
irq: free running list (IDLE)check pendlist -> pending list -> running list; free pending list (RUN)3. irq:
Each list generate one irq, calling callback
One list may contain several desc chain, in such case, make sure only the last desc list generate irq.4. async
Submit will add desc chain to pending list, which can be multi-called If multi desc chain is submitted, only the last desc would generate irq -> call back If IDLE,issue_pending_liststartpending_list, transforming pendlist to running list If RUN, irq will start pending list
Quoted 6 lines
5. test
5.1pxa3xx_nandon pxa910
5.2 insmod dmatest.ko (threads_per_chan=y)
By defaultdrivers/dma/dmatest.ctest every channel and test memcpy with 1 threads per channelSigned-off-by Zhangfei Gao <[email protected]>
Looks all good to, the entire series, except one very small point:
Documentation/devicetree/bindings/dma/mmp-dma.txt line 11
Quoted 6 lines
Documentation/devicetree/bindings/dma/mmp-dma.txt new file +6
-0+Required properties: +- compatible: Should be "marvell,pdma-1.0" +- reg: Should contain DMA registers location and length. +- interrupts: Either contain all of the per-channel DMA interrupts + or one irq for pdma device +- dma-channels: Number of DMA channels supported by the controller.
I think the last one should be "#dma-channels", not "dma-channels", since it's counting the channels. I think we use the "#" version in the preliminary binding for the generic dma channel assignment in DT.
Arnd
PATCH v2 1/4 dmaengine: mmp-pdma support
Quoted 8 lines
Documentation/devicetree/bindings/dma/mmp-dma.txt line 11
Quoted 7 lines
Documentation/devicetree/bindings/dma/mmp-dma.txt new file +6
-0+Required properties: +- compatible: Should be "marvell,pdma-1.0" +- reg: Should contain DMA registers location and length. +- interrupts: Either contain all of the per-channel DMA interrupts + or one irq for pdma device +- dma-channels: Number of DMA channels supported by the controller.
Quoted 6 lines
I think the last one should be "#dma-channels", not "dma-channels", since it's counting the channels. I think we use the "#" version in the preliminary binding for the generic dma channel assignment in DT.
Arnd
Thanks Arnd for careful review, will update with "#dma-channels" in v3.
Quoted 4 lines
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v2 2/4 dmaengine: mmp_tdma: add dt support
In reply to Zhangfei Gao--- Documentation/devicetree/bindings/dma/mmp-dma.txt | 30 ++++++++++++ drivers/dma/mmp_tdma.c | 51 +++++++++++++-------- 2 files changed, 61 insertions(+), 20 deletions(-)
Documentation/devicetree/bindings/dma/mmp-dma.txt +30 -0
@@ -43,3 +43,33 @@ pdma: dma-controller at d4000000 { dma-channels = <16>; }; + +Marvell Two Channel DMA Controller used specifically for audio +Used platfroms: pxa688, pxa910 + +Required properties: +- compatible: Should be "marvell,adma-1.0" or "marvell,pxa910-squ" +- reg: Should contain DMA registers location and length. +- interrupts: Either contain all of the per-channel DMA interrupts + or one irq for dma device + +"marvell,adma-1.0" used on pxa688 +"marvell,pxa910-squ" used on pxa910 + +Examples: + +/* each channel has specific irq */ +adma0: dma-controller at d42a0800 { + compatible = "marvell,adma-1.0"; + reg = <0xd42a0800 0x100>; + interrupts = <18 19>; + interrupt-parent = <&intcmux32>; + }; + +/* One irq for all channels */ +squ: dma-controller at d42a0800 { + compatible = "marvell,pxa910-squ"; + reg = <0xd42a0800 0x100>; + interrupts = <46>; + }; +
drivers/dma/mmp_tdma.c +31 -20
116 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH v2 3/4 dmatest: add dmaengine_slave_config for DMA_MEMCPY
In reply to Zhangfei GaoSet direction to DMA_MEM_TO_MEM
DMA driver may require such configure info
--- drivers/dma/dmatest.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
drivers/dma/dmatest.c +4 -0
@@ -261,6 +261,9 @@ static int dmatest_func(void *data)int src_cnt;int dst_cnt;int i; +struct dma_slave_config conf = { + .direction =DMA_MEM_TO_MEM , + }; thread_name = current->comm;set_freezable ();
@@ -361,6 +364,7 @@ static int dmatest_func(void *data) DMA_BIDIRECTIONAL); } +dmaengine_slave_config (chan, &conf);if (thread->type ==DMA_MEMCPY ) tx = dev->device_prep_dma_memcpy(chan,
Signature · 1 line
1.7.1
PATCH v2 4/4 mtd: pxa3xx-nand: replace pxa_request_dma with dmaengine
In reply to Zhangfei Gao--- drivers/mtd/nand/pxa3xx_nand.c | 113 ++++++++++++++++++++++------------------ 1 files changed, 63 insertions(+), 50 deletions(-)
drivers/mtd/nand/pxa3xx_nand.c +63 -50
@@ -22,8 +22,8 @@#include <linux/io.h> #include <linux/irq.h> #include <linux/slab.h> +#include <linux/dmaengine.h> -#include <mach/dma.h> #include <plat/pxa3xx_nand.h> #define CHIP_DELAY_TIMEOUT (2 * HZ/10)
@@ -162,8 +162,7 @@ struct pxa3xx_nand_info {unsigned char *data_buff;unsigned char *oob_buff;dma_addr_t data_buff_phys; -int data_dma_ch; -struct pxa_dma_desc *data_desc; +struct dma_chan *data_dma_ch;dma_addr_t data_desc_addr;struct pxa3xx_nand_host *host[NUM_CHIP_SELECT ];
@@ -332,14 +331,6 @@ static void pxa3xx_nand_stop(struct pxa3xx_nand_info *info)nand_writel (info,NDSR ,NDSR_MASK ); } -static void enable_int (struct pxa3xx_nand_info *info,uint32_t int_mask) -{ -uint32_t ndcr; - - ndcr =nand_readl (info,NDCR ); -nand_writel (info,NDCR , ndcr & ~int_mask); -} -static void disable_int (struct pxa3xx_nand_info *info,uint32_t int_mask) {uint32_t ndcr;
@@ -372,24 +363,38 @@ static void handle_data_pio(struct pxa3xx_nand_info *info) } } +static void dma_complete_func (void *data) +{ +struct pxa3xx_nand_info *info = data; + + info->state =STATE_DMA_DONE ; +} +static void start_data_dma (struct pxa3xx_nand_info *info) { -struct pxa_dma_desc *desc = info->data_desc; +struct dma_device *dma_dev; +struct dma_async_tx_descriptor *tx =NULL ; +dma_addr_t dma_src_addr, dma_dst_addr; +dma_cookie_t cookie;int dma_len =ALIGN (info->data_size + info->oob_size,32 ); +struct dma_slave_config conf; - desc->ddadr =DDADR_STOP ; - desc->dcmd =DCMD_ENDIRQEN |DCMD_WIDTH4 |DCMD_BURST32 | dma_len; + dma_dev = info->data_dma_ch->device;switch (info->state) {case STATE_DMA_WRITING : - desc->dsadr = info->data_buff_phys; - desc->dtadr = info->mmio_phys +NDDB ; - desc->dcmd |=DCMD_INCSRCADDR |DCMD_FLOWTRG ; + dma_src_addr = info->data_buff_phys; + dma_dst_addr = info->mmio_phys +NDDB ; + conf.direction =DMA_MEM_TO_DEV ; + conf.dst_maxburst =32 ; + conf.dst_addr_width =DMA_SLAVE_BUSWIDTH_4_BYTES ;break ;case STATE_DMA_READING : - desc->dtadr = info->data_buff_phys; - desc->dsadr = info->mmio_phys +NDDB ; - desc->dcmd |=DCMD_INCTRGADDR |DCMD_FLOWSRC ; + dma_src_addr = info->mmio_phys +NDDB ; + dma_dst_addr = info->data_buff_phys; + conf.direction =DMA_DEV_TO_MEM ; + conf.src_maxburst =32 ; + conf.src_addr_width =DMA_SLAVE_BUSWIDTH_4_BYTES ;break ;default : dev_err(&info->pdev->dev, "%s: invalid state %d\n", __func__,
@@ -397,26 +402,27 @@ static void start_data_dma(struct pxa3xx_nand_info *info)BUG (); } -DRCMR (info->drcmr_dat) =DRCMR_MAPVLD | info->data_dma_ch; -DDADR (info->data_dma_ch) = info->data_desc_addr; -DCSR (info->data_dma_ch) |=DCSR_RUN ; -} - -static void pxa3xx_nand_data_dma_irq (int channel,void *data) -{ -struct pxa3xx_nand_info *info = data; -uint32_t dcsr; + conf.slave_id = info->drcmr_dat; +dmaengine_slave_config (info->data_dma_ch, &conf); + tx = dma_dev->device_prep_dma_memcpy (info->data_dma_ch, dma_dst_addr, + dma_src_addr, dma_len,0 ); +if (!tx) { +dev_err (&info->pdev->dev,"Failed to prepare DMA memcpy\n" ); +return ; + } - dcsr =DCSR (channel); -DCSR (channel) = dcsr; + tx->callback = dma_complete_func; + tx->callback_param = info; -if (dcsr &DCSR_BUSERR ) { - info->retcode =ERR_DMABUSERR ; + cookie = tx->tx_submit (tx); +if (dma_submit_error (cookie)) { +dev_err (&info->pdev->dev,"Failed to do DMA tx_submit\n" ); +return ; } - info->state =STATE_DMA_DONE ; -enable_int (info,NDCR_INT_MASK ); -nand_writel (info,NDSR ,NDSR_WRDREQ |NDSR_RDDREQ ); +dma_async_issue_pending (info->data_dma_ch); + +return ; }static irqreturn_t pxa3xx_nand_irq (int irq,void *devid)
@@ -434,6 +440,7 @@ static irqreturn_t pxa3xx_nand_irq(int irq, void *devid) } status =nand_readl (info,NDSR ); +nand_writel (info,NDSR , status);if (status &NDSR_DBERR ) info->retcode =ERR_DBERR ;
@@ -442,7 +449,6 @@ static irqreturn_t pxa3xx_nand_irq(int irq, void *devid)if (status & (NDSR_RDDREQ |NDSR_WRDREQ )) {/* whether use dma to transfer data */ if (info->use_dma) { -disable_int (info,NDCR_INT_MASK ); info->state = (status &NDSR_RDDREQ ) ?STATE_DMA_READING :STATE_DMA_WRITING ;start_data_dma (info);
@@ -757,6 +763,9 @@ static void pxa3xx_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)struct pxa3xx_nand_info *info = host->info_data;int real_len =min_t (size_t, len, info->buf_count - info->buf_start); +if (len > mtd->oobsize) + info->use_dma = use_dma; +memcpy (buf, info->data_buff + info->buf_start, real_len); info->buf_start += real_len; }
@@ -768,6 +777,9 @@ static void pxa3xx_nand_write_buf(struct mtd_info *mtd,struct pxa3xx_nand_info *info = host->info_data;int real_len =min_t (size_t, len, info->buf_count - info->buf_start); +if (len > mtd->oobsize) + info->use_dma = use_dma; +memcpy (info->data_buff + info->buf_start, buf, real_len); info->buf_start += real_len; }
@@ -886,7 +898,7 @@ static int pxa3xx_nand_detect_config(struct pxa3xx_nand_info *info)static int pxa3xx_nand_init_buff (struct pxa3xx_nand_info *info) {struct platform_device *pdev = info->pdev; -int data_desc_offset =MAX_BUFF_SIZE -sizeof (struct pxa_dma_desc ); +dma_cap_mask_t mask;if (use_dma ==0 ) { info->data_buff =kmalloc (MAX_BUFF_SIZE ,GFP_KERNEL );
@@ -902,19 +914,20 @@ static int pxa3xx_nand_init_buff(struct pxa3xx_nand_info *info)return -ENOMEM ; } - info->data_desc = (void *)info->data_buff + data_desc_offset; - info->data_desc_addr = info->data_buff_phys + data_desc_offset; - info->data_dma_ch =pxa_request_dma ("nand-data" ,DMA_PRIO_LOW , - pxa3xx_nand_data_dma_irq, info); -if (info->data_dma_ch <0 ) { -dev_err (&pdev->dev,"failed to request data dma\n" ); -dma_free_coherent (&pdev->dev,MAX_BUFF_SIZE , - info->data_buff, info->data_buff_phys); -return info->data_dma_ch; +dma_cap_zero (mask); +dma_cap_set (DMA_MEMCPY , mask); + info->data_dma_ch =dma_request_channel (mask,NULL ,NULL ); +if (!info->data_dma_ch) { +dev_info (&pdev->dev,"Failed to request DMA channel\n" ); + goto dma_request_fail; } -return 0 ; + +dma_request_fail: +dma_free_coherent (&pdev->dev,MAX_BUFF_SIZE , + info->data_buff, info->data_buff_phys); +return -EAGAIN ; }static int pxa3xx_nand_sensing (struct pxa3xx_nand_info *info)
@@ -1149,7 +1162,7 @@ static int alloc_nand_resource(struct platform_device *pdev) fail_free_buf:free_irq (irq, info);if (use_dma) { -pxa_free_dma (info->data_dma_ch); +dma_release_channel (info->data_dma_ch);dma_free_coherent (&pdev->dev,MAX_BUFF_SIZE , info->data_buff, info->data_buff_phys); }else
@@ -1183,7 +1196,7 @@ static int pxa3xx_nand_remove(struct platform_device *pdev)if (irq >=0 )free_irq (irq, info);if (use_dma) { -pxa_free_dma (info->data_dma_ch); +dma_release_channel (info->data_dma_ch);dma_free_writecombine (&pdev->dev,MAX_BUFF_SIZE , info->data_buff, info->data_buff_phys); }else
Signature · 1 line
1.7.1