1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Driver for the TXx9 SoC DMA Controller
5 * Copyright (C) 2009 Atsushi Nemoto
10 #include <linux/dmaengine.h>
11 #include <asm/txx9/dmac.h>
16 * This DMAC have four channels and one FIFO buffer. Each channel can
17 * be configured for memory-memory or device-memory transfer, but only
18 * one channel can do alignment-free memory-memory transfer at a time
19 * while the channel should occupy the FIFO buffer for effective
22 * Instead of dynamically assign the FIFO buffer to channels, I chose
23 * make one dedicated channel for memory-memory transfer. The
24 * dedicated channel is public. Other channels are private and used
25 * for slave transfer. Some devices in the SoC are wired to certain
29 #ifdef CONFIG_MACH_TX49XX
30 static inline bool txx9_dma_have_SMPCHN(void)
34 #define TXX9_DMA_USE_SIMPLE_CHAIN
36 static inline bool txx9_dma_have_SMPCHN(void)
42 #ifdef __LITTLE_ENDIAN
43 #ifdef CONFIG_MACH_TX49XX
44 #define CCR_LE TXX9_DMA_CCR_LE
48 #define MCR_LE TXX9_DMA_MCR_LE
56 * Redefine this macro to handle differences between 32- and 64-bit
57 * addressing, big vs. little endian, etc.
60 #define TXX9_DMA_REG32(name) u32 __pad_##name; u32 name
62 #define TXX9_DMA_REG32(name) u32 name; u32 __pad_##name
65 /* Hardware register definitions. */
66 struct txx9dmac_cregs
{
67 #if defined(CONFIG_32BIT) && !defined(CONFIG_PHYS_ADDR_T_64BIT)
68 TXX9_DMA_REG32(CHAR
); /* Chain Address Register */
70 u64 CHAR
; /* Chain Address Register */
72 u64 SAR
; /* Source Address Register */
73 u64 DAR
; /* Destination Address Register */
74 TXX9_DMA_REG32(CNTR
); /* Count Register */
75 TXX9_DMA_REG32(SAIR
); /* Source Address Increment Register */
76 TXX9_DMA_REG32(DAIR
); /* Destination Address Increment Register */
77 TXX9_DMA_REG32(CCR
); /* Channel Control Register */
78 TXX9_DMA_REG32(CSR
); /* Channel Status Register */
80 struct txx9dmac_cregs32
{
91 struct txx9dmac_regs
{
92 /* per-channel registers */
93 struct txx9dmac_cregs CHAN
[TXX9_DMA_MAX_NR_CHANNELS
];
95 u64 MFDR
; /* Memory Fill Data Register */
96 TXX9_DMA_REG32(MCR
); /* Master Control Register */
98 struct txx9dmac_regs32
{
99 struct txx9dmac_cregs32 CHAN
[TXX9_DMA_MAX_NR_CHANNELS
];
106 #define TXX9_DMA_MCR_EIS(ch) (0x10000000<<(ch))
107 #define TXX9_DMA_MCR_DIS(ch) (0x01000000<<(ch))
108 #define TXX9_DMA_MCR_RSFIF 0x00000080
109 #define TXX9_DMA_MCR_FIFUM(ch) (0x00000008<<(ch))
110 #define TXX9_DMA_MCR_LE 0x00000004
111 #define TXX9_DMA_MCR_RPRT 0x00000002
112 #define TXX9_DMA_MCR_MSTEN 0x00000001
115 #define TXX9_DMA_CCR_IMMCHN 0x20000000
116 #define TXX9_DMA_CCR_USEXFSZ 0x10000000
117 #define TXX9_DMA_CCR_LE 0x08000000
118 #define TXX9_DMA_CCR_DBINH 0x04000000
119 #define TXX9_DMA_CCR_SBINH 0x02000000
120 #define TXX9_DMA_CCR_CHRST 0x01000000
121 #define TXX9_DMA_CCR_RVBYTE 0x00800000
122 #define TXX9_DMA_CCR_ACKPOL 0x00400000
123 #define TXX9_DMA_CCR_REQPL 0x00200000
124 #define TXX9_DMA_CCR_EGREQ 0x00100000
125 #define TXX9_DMA_CCR_CHDN 0x00080000
126 #define TXX9_DMA_CCR_DNCTL 0x00060000
127 #define TXX9_DMA_CCR_EXTRQ 0x00010000
128 #define TXX9_DMA_CCR_INTRQD 0x0000e000
129 #define TXX9_DMA_CCR_INTENE 0x00001000
130 #define TXX9_DMA_CCR_INTENC 0x00000800
131 #define TXX9_DMA_CCR_INTENT 0x00000400
132 #define TXX9_DMA_CCR_CHNEN 0x00000200
133 #define TXX9_DMA_CCR_XFACT 0x00000100
134 #define TXX9_DMA_CCR_SMPCHN 0x00000020
135 #define TXX9_DMA_CCR_XFSZ(order) (((order) << 2) & 0x0000001c)
136 #define TXX9_DMA_CCR_XFSZ_1 TXX9_DMA_CCR_XFSZ(0)
137 #define TXX9_DMA_CCR_XFSZ_2 TXX9_DMA_CCR_XFSZ(1)
138 #define TXX9_DMA_CCR_XFSZ_4 TXX9_DMA_CCR_XFSZ(2)
139 #define TXX9_DMA_CCR_XFSZ_8 TXX9_DMA_CCR_XFSZ(3)
140 #define TXX9_DMA_CCR_XFSZ_X4 TXX9_DMA_CCR_XFSZ(4)
141 #define TXX9_DMA_CCR_XFSZ_X8 TXX9_DMA_CCR_XFSZ(5)
142 #define TXX9_DMA_CCR_XFSZ_X16 TXX9_DMA_CCR_XFSZ(6)
143 #define TXX9_DMA_CCR_XFSZ_X32 TXX9_DMA_CCR_XFSZ(7)
144 #define TXX9_DMA_CCR_MEMIO 0x00000002
145 #define TXX9_DMA_CCR_SNGAD 0x00000001
148 #define TXX9_DMA_CSR_CHNEN 0x00000400
149 #define TXX9_DMA_CSR_STLXFER 0x00000200
150 #define TXX9_DMA_CSR_XFACT 0x00000100
151 #define TXX9_DMA_CSR_ABCHC 0x00000080
152 #define TXX9_DMA_CSR_NCHNC 0x00000040
153 #define TXX9_DMA_CSR_NTRNFC 0x00000020
154 #define TXX9_DMA_CSR_EXTDN 0x00000010
155 #define TXX9_DMA_CSR_CFERR 0x00000008
156 #define TXX9_DMA_CSR_CHERR 0x00000004
157 #define TXX9_DMA_CSR_DESERR 0x00000002
158 #define TXX9_DMA_CSR_SORERR 0x00000001
160 struct txx9dmac_chan
{
161 struct dma_chan chan
;
162 struct dma_device dma
;
163 struct txx9dmac_dev
*ddev
;
164 void __iomem
*ch_regs
;
165 struct tasklet_struct tasklet
;
171 /* these other elements are all protected by lock */
172 struct list_head active_list
;
173 struct list_head queue
;
174 struct list_head free_list
;
176 unsigned int descs_allocated
;
179 struct txx9dmac_dev
{
181 struct tasklet_struct tasklet
;
183 struct txx9dmac_chan
*chan
[TXX9_DMA_MAX_NR_CHANNELS
];
184 bool have_64bit_regs
;
185 unsigned int descsize
;
188 static inline bool __is_dmac64(const struct txx9dmac_dev
*ddev
)
190 return ddev
->have_64bit_regs
;
193 static inline bool is_dmac64(const struct txx9dmac_chan
*dc
)
195 return __is_dmac64(dc
->ddev
);
198 #ifdef TXX9_DMA_USE_SIMPLE_CHAIN
199 /* Hardware descriptor definition. (for simple-chain) */
200 struct txx9dmac_hwdesc
{
201 #if defined(CONFIG_32BIT) && !defined(CONFIG_PHYS_ADDR_T_64BIT)
202 TXX9_DMA_REG32(CHAR
);
208 TXX9_DMA_REG32(CNTR
);
210 struct txx9dmac_hwdesc32
{
217 #define txx9dmac_hwdesc txx9dmac_cregs
218 #define txx9dmac_hwdesc32 txx9dmac_cregs32
221 struct txx9dmac_desc
{
222 /* FIRST values the hardware uses */
224 struct txx9dmac_hwdesc hwdesc
;
225 struct txx9dmac_hwdesc32 hwdesc32
;
228 /* THEN values for driver housekeeping */
229 struct list_head desc_node ____cacheline_aligned
;
230 struct list_head tx_list
;
231 struct dma_async_tx_descriptor txd
;
235 #ifdef TXX9_DMA_USE_SIMPLE_CHAIN
237 static inline bool txx9dmac_chan_INTENT(struct txx9dmac_chan
*dc
)
239 return (dc
->ccr
& TXX9_DMA_CCR_INTENT
) != 0;
242 static inline void txx9dmac_chan_set_INTENT(struct txx9dmac_chan
*dc
)
244 dc
->ccr
|= TXX9_DMA_CCR_INTENT
;
247 static inline void txx9dmac_desc_set_INTENT(struct txx9dmac_dev
*ddev
,
248 struct txx9dmac_desc
*desc
)
252 static inline void txx9dmac_chan_set_SMPCHN(struct txx9dmac_chan
*dc
)
254 dc
->ccr
|= TXX9_DMA_CCR_SMPCHN
;
257 static inline void txx9dmac_desc_set_nosimple(struct txx9dmac_dev
*ddev
,
258 struct txx9dmac_desc
*desc
,
259 u32 sair
, u32 dair
, u32 ccr
)
263 #else /* TXX9_DMA_USE_SIMPLE_CHAIN */
265 static inline bool txx9dmac_chan_INTENT(struct txx9dmac_chan
*dc
)
270 static void txx9dmac_chan_set_INTENT(struct txx9dmac_chan
*dc
)
274 static inline void txx9dmac_desc_set_INTENT(struct txx9dmac_dev
*ddev
,
275 struct txx9dmac_desc
*desc
)
277 if (__is_dmac64(ddev
))
278 desc
->hwdesc
.CCR
|= TXX9_DMA_CCR_INTENT
;
280 desc
->hwdesc32
.CCR
|= TXX9_DMA_CCR_INTENT
;
283 static inline void txx9dmac_chan_set_SMPCHN(struct txx9dmac_chan
*dc
)
287 static inline void txx9dmac_desc_set_nosimple(struct txx9dmac_dev
*ddev
,
288 struct txx9dmac_desc
*desc
,
289 u32 sai
, u32 dai
, u32 ccr
)
291 if (__is_dmac64(ddev
)) {
292 desc
->hwdesc
.SAIR
= sai
;
293 desc
->hwdesc
.DAIR
= dai
;
294 desc
->hwdesc
.CCR
= ccr
;
296 desc
->hwdesc32
.SAIR
= sai
;
297 desc
->hwdesc32
.DAIR
= dai
;
298 desc
->hwdesc32
.CCR
= ccr
;
302 #endif /* TXX9_DMA_USE_SIMPLE_CHAIN */
304 #endif /* TXX9DMAC_H */