2008-07-09 02:59:42 +08:00
|
|
|
/*
|
|
|
|
* Driver for the Synopsys DesignWare AHB DMA Controller
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005-2007 Atmel Corporation
|
2011-05-24 16:34:09 +08:00
|
|
|
* Copyright (C) 2010-2011 ST Microelectronics
|
2008-07-09 02:59:42 +08:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2013-06-05 20:26:45 +08:00
|
|
|
#include <linux/interrupt.h>
|
2013-01-10 16:53:03 +08:00
|
|
|
#include <linux/dmaengine.h>
|
2008-07-09 02:59:42 +08:00
|
|
|
|
2016-11-25 22:59:07 +08:00
|
|
|
#include "internal.h"
|
|
|
|
|
2013-02-28 05:36:03 +08:00
|
|
|
#define DW_DMA_MAX_NR_REQUESTS 16
|
2008-07-09 02:59:42 +08:00
|
|
|
|
2012-02-01 18:42:28 +08:00
|
|
|
/* flow controller */
|
|
|
|
enum dw_dma_fc {
|
|
|
|
DW_DMA_FC_D_M2M,
|
|
|
|
DW_DMA_FC_D_M2P,
|
|
|
|
DW_DMA_FC_D_P2M,
|
|
|
|
DW_DMA_FC_D_P2P,
|
|
|
|
DW_DMA_FC_P_P2M,
|
|
|
|
DW_DMA_FC_SP_P2P,
|
|
|
|
DW_DMA_FC_P_M2P,
|
|
|
|
DW_DMA_FC_DP_P2P,
|
|
|
|
};
|
|
|
|
|
2008-07-09 02:59:42 +08:00
|
|
|
/*
|
|
|
|
* Redefine this macro to handle differences between 32- and 64-bit
|
|
|
|
* addressing, big vs. little endian, etc.
|
|
|
|
*/
|
|
|
|
#define DW_REG(name) u32 name; u32 __pad_##name
|
|
|
|
|
|
|
|
/* Hardware register definitions. */
|
|
|
|
struct dw_dma_chan_regs {
|
|
|
|
DW_REG(SAR); /* Source Address Register */
|
|
|
|
DW_REG(DAR); /* Destination Address Register */
|
|
|
|
DW_REG(LLP); /* Linked List Pointer */
|
|
|
|
u32 CTL_LO; /* Control Register Low */
|
|
|
|
u32 CTL_HI; /* Control Register High */
|
|
|
|
DW_REG(SSTAT);
|
|
|
|
DW_REG(DSTAT);
|
|
|
|
DW_REG(SSTATAR);
|
|
|
|
DW_REG(DSTATAR);
|
|
|
|
u32 CFG_LO; /* Configuration Register Low */
|
|
|
|
u32 CFG_HI; /* Configuration Register High */
|
|
|
|
DW_REG(SGR);
|
|
|
|
DW_REG(DSR);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct dw_dma_irq_regs {
|
|
|
|
DW_REG(XFER);
|
|
|
|
DW_REG(BLOCK);
|
|
|
|
DW_REG(SRC_TRAN);
|
|
|
|
DW_REG(DST_TRAN);
|
|
|
|
DW_REG(ERROR);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct dw_dma_regs {
|
|
|
|
/* per-channel registers */
|
|
|
|
struct dw_dma_chan_regs CHAN[DW_DMA_MAX_NR_CHANNELS];
|
|
|
|
|
|
|
|
/* irq handling */
|
|
|
|
struct dw_dma_irq_regs RAW; /* r */
|
|
|
|
struct dw_dma_irq_regs STATUS; /* r (raw & mask) */
|
|
|
|
struct dw_dma_irq_regs MASK; /* rw (set = irq enabled) */
|
|
|
|
struct dw_dma_irq_regs CLEAR; /* w (ack, affects "raw") */
|
|
|
|
|
|
|
|
DW_REG(STATUS_INT); /* r */
|
|
|
|
|
|
|
|
/* software handshaking */
|
|
|
|
DW_REG(REQ_SRC);
|
|
|
|
DW_REG(REQ_DST);
|
|
|
|
DW_REG(SGL_REQ_SRC);
|
|
|
|
DW_REG(SGL_REQ_DST);
|
|
|
|
DW_REG(LAST_SRC);
|
|
|
|
DW_REG(LAST_DST);
|
|
|
|
|
|
|
|
/* miscellaneous */
|
|
|
|
DW_REG(CFG);
|
|
|
|
DW_REG(CH_EN);
|
|
|
|
DW_REG(ID);
|
|
|
|
DW_REG(TEST);
|
|
|
|
|
2012-09-21 20:05:45 +08:00
|
|
|
/* reserved */
|
|
|
|
DW_REG(__reserved0);
|
|
|
|
DW_REG(__reserved1);
|
|
|
|
|
2012-06-19 18:34:01 +08:00
|
|
|
/* optional encoded params, 0x3c8..0x3f7 */
|
2012-09-21 20:05:45 +08:00
|
|
|
u32 __reserved;
|
|
|
|
|
|
|
|
/* per-channel configuration registers */
|
|
|
|
u32 DWC_PARAMS[DW_DMA_MAX_NR_CHANNELS];
|
|
|
|
u32 MULTI_BLK_TYPE;
|
|
|
|
u32 MAX_BLK_SIZE;
|
|
|
|
|
|
|
|
/* top-level parameters */
|
|
|
|
u32 DW_PARAMS;
|
2008-07-09 02:59:42 +08:00
|
|
|
};
|
|
|
|
|
2013-06-12 16:09:57 +08:00
|
|
|
/*
|
|
|
|
* Big endian I/O access when reading and writing to the DMA controller
|
|
|
|
* registers. This is needed on some platforms, like the Atmel AVR32
|
|
|
|
* architecture.
|
|
|
|
*/
|
|
|
|
|
2012-10-26 04:38:05 +08:00
|
|
|
#ifdef CONFIG_DW_DMAC_BIG_ENDIAN_IO
|
|
|
|
#define dma_readl_native ioread32be
|
|
|
|
#define dma_writel_native iowrite32be
|
|
|
|
#else
|
|
|
|
#define dma_readl_native readl
|
|
|
|
#define dma_writel_native writel
|
|
|
|
#endif
|
|
|
|
|
2012-09-21 20:05:45 +08:00
|
|
|
/* Bitfields in DW_PARAMS */
|
|
|
|
#define DW_PARAMS_NR_CHAN 8 /* number of channels */
|
|
|
|
#define DW_PARAMS_NR_MASTER 11 /* number of AHB masters */
|
|
|
|
#define DW_PARAMS_DATA_WIDTH(n) (15 + 2 * (n))
|
|
|
|
#define DW_PARAMS_DATA_WIDTH1 15 /* master 1 data width */
|
|
|
|
#define DW_PARAMS_DATA_WIDTH2 17 /* master 2 data width */
|
|
|
|
#define DW_PARAMS_DATA_WIDTH3 19 /* master 3 data width */
|
|
|
|
#define DW_PARAMS_DATA_WIDTH4 21 /* master 4 data width */
|
|
|
|
#define DW_PARAMS_EN 28 /* encoded parameters */
|
|
|
|
|
|
|
|
/* Bitfields in DWC_PARAMS */
|
|
|
|
#define DWC_PARAMS_MBLK_EN 11 /* multi block transfer */
|
|
|
|
|
2014-09-23 22:18:10 +08:00
|
|
|
/* bursts size */
|
|
|
|
enum dw_dma_msize {
|
|
|
|
DW_DMA_MSIZE_1,
|
|
|
|
DW_DMA_MSIZE_4,
|
|
|
|
DW_DMA_MSIZE_8,
|
|
|
|
DW_DMA_MSIZE_16,
|
|
|
|
DW_DMA_MSIZE_32,
|
|
|
|
DW_DMA_MSIZE_64,
|
|
|
|
DW_DMA_MSIZE_128,
|
|
|
|
DW_DMA_MSIZE_256,
|
|
|
|
};
|
|
|
|
|
2016-03-18 22:24:44 +08:00
|
|
|
/* Bitfields in LLP */
|
|
|
|
#define DWC_LLP_LMS(x) ((x) & 3) /* list master select */
|
|
|
|
#define DWC_LLP_LOC(x) ((x) & ~3) /* next lli */
|
|
|
|
|
2008-07-09 02:59:42 +08:00
|
|
|
/* Bitfields in CTL_LO */
|
|
|
|
#define DWC_CTLL_INT_EN (1 << 0) /* irqs enabled? */
|
|
|
|
#define DWC_CTLL_DST_WIDTH(n) ((n)<<1) /* bytes per element */
|
|
|
|
#define DWC_CTLL_SRC_WIDTH(n) ((n)<<4)
|
|
|
|
#define DWC_CTLL_DST_INC (0<<7) /* DAR update/not */
|
|
|
|
#define DWC_CTLL_DST_DEC (1<<7)
|
|
|
|
#define DWC_CTLL_DST_FIX (2<<7)
|
2016-01-07 08:39:33 +08:00
|
|
|
#define DWC_CTLL_SRC_INC (0<<9) /* SAR update/not */
|
2008-07-09 02:59:42 +08:00
|
|
|
#define DWC_CTLL_SRC_DEC (1<<9)
|
|
|
|
#define DWC_CTLL_SRC_FIX (2<<9)
|
|
|
|
#define DWC_CTLL_DST_MSIZE(n) ((n)<<11) /* burst, #elements */
|
|
|
|
#define DWC_CTLL_SRC_MSIZE(n) ((n)<<14)
|
|
|
|
#define DWC_CTLL_S_GATH_EN (1 << 17) /* src gather, !FIX */
|
|
|
|
#define DWC_CTLL_D_SCAT_EN (1 << 18) /* dst scatter, !FIX */
|
2011-03-04 18:12:51 +08:00
|
|
|
#define DWC_CTLL_FC(n) ((n) << 20)
|
2008-07-09 02:59:42 +08:00
|
|
|
#define DWC_CTLL_FC_M2M (0 << 20) /* mem-to-mem */
|
|
|
|
#define DWC_CTLL_FC_M2P (1 << 20) /* mem-to-periph */
|
|
|
|
#define DWC_CTLL_FC_P2M (2 << 20) /* periph-to-mem */
|
|
|
|
#define DWC_CTLL_FC_P2P (3 << 20) /* periph-to-periph */
|
|
|
|
/* plus 4 transfer types for peripheral-as-flow-controller */
|
|
|
|
#define DWC_CTLL_DMS(n) ((n)<<23) /* dst master select */
|
|
|
|
#define DWC_CTLL_SMS(n) ((n)<<25) /* src master select */
|
|
|
|
#define DWC_CTLL_LLP_D_EN (1 << 27) /* dest block chain */
|
|
|
|
#define DWC_CTLL_LLP_S_EN (1 << 28) /* src block chain */
|
|
|
|
|
|
|
|
/* Bitfields in CTL_HI */
|
|
|
|
#define DWC_CTLH_DONE 0x00001000
|
|
|
|
#define DWC_CTLH_BLOCK_TS_MASK 0x00000fff
|
|
|
|
|
2014-09-23 22:18:10 +08:00
|
|
|
/* Bitfields in CFG_LO */
|
2011-03-03 18:17:22 +08:00
|
|
|
#define DWC_CFGL_CH_PRIOR_MASK (0x7 << 5) /* priority mask */
|
|
|
|
#define DWC_CFGL_CH_PRIOR(x) ((x) << 5) /* priority */
|
2008-07-09 02:59:42 +08:00
|
|
|
#define DWC_CFGL_CH_SUSP (1 << 8) /* pause xfer */
|
|
|
|
#define DWC_CFGL_FIFO_EMPTY (1 << 9) /* pause xfer */
|
|
|
|
#define DWC_CFGL_HS_DST (1 << 10) /* handshake w/dst */
|
|
|
|
#define DWC_CFGL_HS_SRC (1 << 11) /* handshake w/src */
|
2014-09-23 22:18:10 +08:00
|
|
|
#define DWC_CFGL_LOCK_CH_XFER (0 << 12) /* scope of LOCK_CH */
|
|
|
|
#define DWC_CFGL_LOCK_CH_BLOCK (1 << 12)
|
|
|
|
#define DWC_CFGL_LOCK_CH_XACT (2 << 12)
|
|
|
|
#define DWC_CFGL_LOCK_BUS_XFER (0 << 14) /* scope of LOCK_BUS */
|
|
|
|
#define DWC_CFGL_LOCK_BUS_BLOCK (1 << 14)
|
|
|
|
#define DWC_CFGL_LOCK_BUS_XACT (2 << 14)
|
|
|
|
#define DWC_CFGL_LOCK_CH (1 << 15) /* channel lockout */
|
|
|
|
#define DWC_CFGL_LOCK_BUS (1 << 16) /* busmaster lockout */
|
|
|
|
#define DWC_CFGL_HS_DST_POL (1 << 18) /* dst handshake active low */
|
|
|
|
#define DWC_CFGL_HS_SRC_POL (1 << 19) /* src handshake active low */
|
2008-07-09 02:59:42 +08:00
|
|
|
#define DWC_CFGL_MAX_BURST(x) ((x) << 20)
|
|
|
|
#define DWC_CFGL_RELOAD_SAR (1 << 30)
|
|
|
|
#define DWC_CFGL_RELOAD_DAR (1 << 31)
|
|
|
|
|
2014-09-23 22:18:10 +08:00
|
|
|
/* Bitfields in CFG_HI */
|
|
|
|
#define DWC_CFGH_FCMODE (1 << 0)
|
|
|
|
#define DWC_CFGH_FIFO_MODE (1 << 1)
|
|
|
|
#define DWC_CFGH_PROTCTL(x) ((x) << 2)
|
2008-07-09 02:59:42 +08:00
|
|
|
#define DWC_CFGH_DS_UPD_EN (1 << 5)
|
|
|
|
#define DWC_CFGH_SS_UPD_EN (1 << 6)
|
2014-09-23 22:18:10 +08:00
|
|
|
#define DWC_CFGH_SRC_PER(x) ((x) << 7)
|
|
|
|
#define DWC_CFGH_DST_PER(x) ((x) << 11)
|
2008-07-09 02:59:42 +08:00
|
|
|
|
|
|
|
/* Bitfields in SGR */
|
|
|
|
#define DWC_SGR_SGI(x) ((x) << 0)
|
|
|
|
#define DWC_SGR_SGC(x) ((x) << 20)
|
|
|
|
|
|
|
|
/* Bitfields in DSR */
|
|
|
|
#define DWC_DSR_DSI(x) ((x) << 0)
|
|
|
|
#define DWC_DSR_DSC(x) ((x) << 20)
|
|
|
|
|
|
|
|
/* Bitfields in CFG */
|
|
|
|
#define DW_CFG_DMA_EN (1 << 0)
|
|
|
|
|
2009-04-01 21:47:02 +08:00
|
|
|
enum dw_dmac_flags {
|
|
|
|
DW_DMA_IS_CYCLIC = 0,
|
2012-09-21 20:05:49 +08:00
|
|
|
DW_DMA_IS_SOFT_LLP = 1,
|
2016-03-18 22:24:51 +08:00
|
|
|
DW_DMA_IS_PAUSED = 2,
|
2016-03-18 22:24:52 +08:00
|
|
|
DW_DMA_IS_INITIALIZED = 3,
|
2009-04-01 21:47:02 +08:00
|
|
|
};
|
|
|
|
|
2008-07-09 02:59:42 +08:00
|
|
|
struct dw_dma_chan {
|
2013-01-10 16:53:03 +08:00
|
|
|
struct dma_chan chan;
|
|
|
|
void __iomem *ch_regs;
|
|
|
|
u8 mask;
|
|
|
|
u8 priority;
|
|
|
|
enum dma_transfer_direction direction;
|
2008-07-09 02:59:42 +08:00
|
|
|
|
2012-09-21 20:05:49 +08:00
|
|
|
/* software emulation of the LLP transfers */
|
|
|
|
struct list_head *tx_node_active;
|
|
|
|
|
2008-07-09 02:59:42 +08:00
|
|
|
spinlock_t lock;
|
|
|
|
|
|
|
|
/* these other elements are all protected by lock */
|
2009-04-01 21:47:02 +08:00
|
|
|
unsigned long flags;
|
2008-07-09 02:59:42 +08:00
|
|
|
struct list_head active_list;
|
|
|
|
struct list_head queue;
|
2009-04-01 21:47:02 +08:00
|
|
|
struct dw_cyclic_desc *cdesc;
|
2008-07-09 02:59:42 +08:00
|
|
|
|
|
|
|
unsigned int descs_allocated;
|
2012-02-01 18:42:26 +08:00
|
|
|
|
2012-09-21 20:05:47 +08:00
|
|
|
/* hardware configuration */
|
|
|
|
unsigned int block_size;
|
2012-09-21 20:05:49 +08:00
|
|
|
bool nollp;
|
2013-03-26 22:53:57 +08:00
|
|
|
|
|
|
|
/* custom slave configuration */
|
2016-08-18 00:20:20 +08:00
|
|
|
struct dw_dma_slave dws;
|
2012-09-21 20:05:47 +08:00
|
|
|
|
2014-12-22 22:54:14 +08:00
|
|
|
/* configuration passed via .device_config */
|
2012-02-01 18:42:26 +08:00
|
|
|
struct dma_slave_config dma_sconfig;
|
2008-07-09 02:59:42 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static inline struct dw_dma_chan_regs __iomem *
|
|
|
|
__dwc_regs(struct dw_dma_chan *dwc)
|
|
|
|
{
|
|
|
|
return dwc->ch_regs;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define channel_readl(dwc, name) \
|
2012-10-26 04:38:05 +08:00
|
|
|
dma_readl_native(&(__dwc_regs(dwc)->name))
|
2008-07-09 02:59:42 +08:00
|
|
|
#define channel_writel(dwc, name, val) \
|
2012-10-26 04:38:05 +08:00
|
|
|
dma_writel_native((val), &(__dwc_regs(dwc)->name))
|
2008-07-09 02:59:42 +08:00
|
|
|
|
|
|
|
static inline struct dw_dma_chan *to_dw_dma_chan(struct dma_chan *chan)
|
|
|
|
{
|
|
|
|
return container_of(chan, struct dw_dma_chan, chan);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct dw_dma {
|
|
|
|
struct dma_device dma;
|
|
|
|
void __iomem *regs;
|
2013-01-16 21:48:50 +08:00
|
|
|
struct dma_pool *desc_pool;
|
2008-07-09 02:59:42 +08:00
|
|
|
struct tasklet_struct tasklet;
|
|
|
|
|
2014-03-05 21:48:12 +08:00
|
|
|
/* channels */
|
|
|
|
struct dw_dma_chan *chan;
|
2008-07-09 02:59:42 +08:00
|
|
|
u8 all_chan_mask;
|
2014-09-23 22:18:14 +08:00
|
|
|
u8 in_use;
|
2008-07-09 02:59:42 +08:00
|
|
|
|
2016-04-27 19:15:39 +08:00
|
|
|
/* platform data */
|
|
|
|
struct dw_dma_platform_data *pdata;
|
2008-07-09 02:59:42 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static inline struct dw_dma_regs __iomem *__dw_regs(struct dw_dma *dw)
|
|
|
|
{
|
|
|
|
return dw->regs;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define dma_readl(dw, name) \
|
2012-10-26 04:38:05 +08:00
|
|
|
dma_readl_native(&(__dw_regs(dw)->name))
|
2008-07-09 02:59:42 +08:00
|
|
|
#define dma_writel(dw, name, val) \
|
2012-10-26 04:38:05 +08:00
|
|
|
dma_writel_native((val), &(__dw_regs(dw)->name))
|
2008-07-09 02:59:42 +08:00
|
|
|
|
|
|
|
#define channel_set_bit(dw, reg, mask) \
|
|
|
|
dma_writel(dw, reg, ((mask) << 8) | (mask))
|
|
|
|
#define channel_clear_bit(dw, reg, mask) \
|
|
|
|
dma_writel(dw, reg, ((mask) << 8) | 0)
|
|
|
|
|
|
|
|
static inline struct dw_dma *to_dw_dma(struct dma_device *ddev)
|
|
|
|
{
|
|
|
|
return container_of(ddev, struct dw_dma, dma);
|
|
|
|
}
|
|
|
|
|
2016-03-18 22:24:43 +08:00
|
|
|
#ifdef CONFIG_DW_DMAC_BIG_ENDIAN_IO
|
|
|
|
typedef __be32 __dw32;
|
|
|
|
#else
|
|
|
|
typedef __le32 __dw32;
|
|
|
|
#endif
|
|
|
|
|
2008-07-09 02:59:42 +08:00
|
|
|
/* LLI == Linked List Item; a.k.a. DMA block descriptor */
|
|
|
|
struct dw_lli {
|
|
|
|
/* values that are not changed by hardware */
|
2016-03-18 22:24:43 +08:00
|
|
|
__dw32 sar;
|
|
|
|
__dw32 dar;
|
|
|
|
__dw32 llp; /* chain to next lli */
|
|
|
|
__dw32 ctllo;
|
2008-07-09 02:59:42 +08:00
|
|
|
/* values that may get written back: */
|
2016-03-18 22:24:43 +08:00
|
|
|
__dw32 ctlhi;
|
2008-07-09 02:59:42 +08:00
|
|
|
/* sstat and dstat can snapshot peripheral register state.
|
|
|
|
* silicon config may discard either or both...
|
|
|
|
*/
|
2016-03-18 22:24:43 +08:00
|
|
|
__dw32 sstat;
|
|
|
|
__dw32 dstat;
|
2008-07-09 02:59:42 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct dw_desc {
|
|
|
|
/* FIRST values the hardware uses */
|
|
|
|
struct dw_lli lli;
|
|
|
|
|
2016-03-18 22:24:43 +08:00
|
|
|
#ifdef CONFIG_DW_DMAC_BIG_ENDIAN_IO
|
|
|
|
#define lli_set(d, reg, v) ((d)->lli.reg |= cpu_to_be32(v))
|
|
|
|
#define lli_clear(d, reg, v) ((d)->lli.reg &= ~cpu_to_be32(v))
|
|
|
|
#define lli_read(d, reg) be32_to_cpu((d)->lli.reg)
|
|
|
|
#define lli_write(d, reg, v) ((d)->lli.reg = cpu_to_be32(v))
|
|
|
|
#else
|
|
|
|
#define lli_set(d, reg, v) ((d)->lli.reg |= cpu_to_le32(v))
|
|
|
|
#define lli_clear(d, reg, v) ((d)->lli.reg &= ~cpu_to_le32(v))
|
|
|
|
#define lli_read(d, reg) le32_to_cpu((d)->lli.reg)
|
|
|
|
#define lli_write(d, reg, v) ((d)->lli.reg = cpu_to_le32(v))
|
|
|
|
#endif
|
|
|
|
|
2008-07-09 02:59:42 +08:00
|
|
|
/* THEN values for driver housekeeping */
|
|
|
|
struct list_head desc_node;
|
2009-09-09 08:53:02 +08:00
|
|
|
struct list_head tx_list;
|
2008-07-09 02:59:42 +08:00
|
|
|
struct dma_async_tx_descriptor txd;
|
|
|
|
size_t len;
|
2013-01-25 17:48:01 +08:00
|
|
|
size_t total_len;
|
2016-03-18 22:24:53 +08:00
|
|
|
u32 residue;
|
2008-07-09 02:59:42 +08:00
|
|
|
};
|
|
|
|
|
2012-10-18 22:34:12 +08:00
|
|
|
#define to_dw_desc(h) list_entry(h, struct dw_desc, desc_node)
|
|
|
|
|
2008-07-09 02:59:42 +08:00
|
|
|
static inline struct dw_desc *
|
|
|
|
txd_to_dw_desc(struct dma_async_tx_descriptor *txd)
|
|
|
|
{
|
|
|
|
return container_of(txd, struct dw_desc, txd);
|
|
|
|
}
|