1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * SiFive FU540 Platform DMA driver
4 * Copyright (C) 2019 SiFive
7 * - drivers/dma/fsl-edma.c
8 * - drivers/dma/dw-edma/
9 * - drivers/dma/pxa-dma.c
11 * See the following sources for further documentation:
12 * - Chapter 12 "Platform DMA Engine (PDMA)" of
13 * SiFive FU540-C000 v1.0
14 * https://static.dev.sifive.com/FU540-C000-v1.0.pdf
19 #include <linux/dmaengine.h>
20 #include <linux/dma-direction.h>
22 #include "../dmaengine.h"
23 #include "../virt-dma.h"
25 #define PDMA_MAX_NR_CH 4
27 #define PDMA_BASE_ADDR 0x3000000
28 #define PDMA_CHAN_OFFSET 0x1000
31 #define PDMA_CTRL 0x000
32 #define PDMA_XFER_TYPE 0x004
33 #define PDMA_XFER_SIZE 0x008
34 #define PDMA_DST_ADDR 0x010
35 #define PDMA_SRC_ADDR 0x018
36 #define PDMA_ACT_TYPE 0x104 /* Read-only */
37 #define PDMA_REMAINING_BYTE 0x108 /* Read-only */
38 #define PDMA_CUR_DST_ADDR 0x110 /* Read-only*/
39 #define PDMA_CUR_SRC_ADDR 0x118 /* Read-only*/
42 #define PDMA_CLEAR_CTRL 0x0
43 #define PDMA_CLAIM_MASK GENMASK(0, 0)
44 #define PDMA_RUN_MASK GENMASK(1, 1)
45 #define PDMA_ENABLE_DONE_INT_MASK GENMASK(14, 14)
46 #define PDMA_ENABLE_ERR_INT_MASK GENMASK(15, 15)
47 #define PDMA_DONE_STATUS_MASK GENMASK(30, 30)
48 #define PDMA_ERR_STATUS_MASK GENMASK(31, 31)
51 #define PDMA_FULL_SPEED 0xFF000000
52 #define PDMA_STRICT_ORDERING BIT(3)
57 #define SF_PDMA_REG_BASE(ch) (pdma->membase + (PDMA_CHAN_OFFSET * (ch)))
61 void __iomem
*ctrl
; /* 4 bytes */
63 void __iomem
*xfer_type
; /* 4 bytes */
64 void __iomem
*xfer_size
; /* 8 bytes */
65 void __iomem
*dst_addr
; /* 8 bytes */
66 void __iomem
*src_addr
; /* 8 bytes */
69 void __iomem
*act_type
; /* 4 bytes */
70 void __iomem
*residue
; /* 8 bytes */
71 void __iomem
*cur_dst_addr
; /* 8 bytes */
72 void __iomem
*cur_src_addr
; /* 8 bytes */
80 struct virt_dma_desc vdesc
;
81 struct sf_pdma_chan
*chan
;
82 enum dma_transfer_direction dirn
;
83 struct dma_async_tx_descriptor
*async_tx
;
86 enum sf_pdma_pm_state
{
92 struct virt_dma_chan vchan
;
93 enum dma_status status
;
94 enum sf_pdma_pm_state pm_state
;
97 struct sf_pdma_desc
*desc
;
98 struct dma_slave_config cfg
;
100 dma_addr_t dma_dev_addr
;
102 struct tasklet_struct done_tasklet
;
103 struct tasklet_struct err_tasklet
;
104 struct pdma_regs regs
;
105 spinlock_t lock
; /* protect chan data */
113 struct dma_device dma_dev
;
114 void __iomem
*membase
;
115 void __iomem
*mappedbase
;
118 struct sf_pdma_chan chans
[] __counted_by(n_chans
);
121 struct sf_pdma_driver_platdata
{
125 #endif /* _SF_PDMA_H */