3 * Copyright 2000,2001,2002 MontaVista Software Inc.
5 * MontaVista Software, Inc.
6 * currently maintained by Armin Kuster akuster@mvista.com
9 * MontaVista Software, Inc.
10 * ppopov@mvista.com or source@mvista.com
13 * Module name: ppc4xx_dma.h
16 * Data structures specific to the IBM PPC4xx on-chip DMA controller
19 * version 1.1: 02/02 - Armin
20 * added stb03xxx suppor
22 * version 1.2: 02/28/02 - armin
23 * changed config_405gp to a more generic config
25 * version 1.3: 07/18/02 - armin
26 * moved scatter/gather inline code to ppc4xx_sgdma.c
27 * added three new extern proto types for the STBxxxx API's
29 * version 1.4: 08/26/02 - Armin
30 * added in_use field for when a channel is claimed
31 * added new return code *_NOTFREE
36 #ifndef __ASMPPC_PPC4xx_DMA_H
37 #define __ASMPPC_PPC4xx_DMA_H
39 #include <linux/config.h>
40 #include <linux/types.h>
42 #include <asm/ibm4xx.h>
46 #define MAX_PPC4xx_DMA_CHANNELS 4
49 * Function return status codes
50 * These values are used to indicate whether or not the function
51 * call was successful, or a bad/invalid parameter was passed.
53 #define DMA_STATUS_GOOD 0
54 #define DMA_STATUS_BAD_CHANNEL 1
55 #define DMA_STATUS_BAD_HANDLE 2
56 #define DMA_STATUS_BAD_MODE 3
57 #define DMA_STATUS_NULL_POINTER 4
58 #define DMA_STATUS_OUT_OF_MEMORY 5
59 #define DMA_STATUS_SGL_LIST_EMPTY 6
60 #define DMA_STATUS_GENERAL_ERROR 7
61 #define DMA_STATUS_CHANNEL_NOTFREE 8
63 #define DMA_CHANNEL_BUSY 0x80000000
66 * These indicate status as returned from the DMA Status Register.
68 #define DMA_STATUS_NO_ERROR 0
69 #define DMA_STATUS_CS 1 /* Count Status */
70 #define DMA_STATUS_TS 2 /* Transfer Status */
71 #define DMA_STATUS_DMA_ERROR 3 /* DMA Error Occurred */
72 #define DMA_STATUS_DMA_BUSY 4 /* The channel is busy */
76 * DMA Channel Control Registers
80 #define DMA_CR_OFFSET 1
82 #define DMA_CR_OFFSET 0
85 #define DMA_CE_ENABLE (1<<31) /* DMA Channel Enable */
86 #define SET_DMA_CE_ENABLE(x) (((x)&0x1)<<31)
87 #define GET_DMA_CE_ENABLE(x) (((x)&DMA_CE_ENABLE)>>31)
89 #define DMA_CIE_ENABLE (1<<30) /* DMA Channel Interrupt Enable */
90 #define SET_DMA_CIE_ENABLE(x) (((x)&0x1)<<30)
91 #define GET_DMA_CIE_ENABLE(x) (((x)&DMA_CIE_ENABLE)>>30)
93 #define DMA_TD (1<<29)
94 #define SET_DMA_TD(x) (((x)&0x1)<<29)
95 #define GET_DMA_TD(x) (((x)&DMA_TD)>>29)
97 #define DMA_PL (1<<28) /* Peripheral Location */
98 #define SET_DMA_PL(x) (((x)&0x1)<<28)
99 #define GET_DMA_PL(x) (((x)&DMA_PL)>>28)
101 #define EXTERNAL_PERIPHERAL 0
102 #define INTERNAL_PERIPHERAL 1
104 #define SET_DMA_PW(x) (((x)&0x3)<<(26-DMA_CR_OFFSET)) /* Peripheral Width */
105 #define DMA_PW_MASK SET_DMA_PW(3)
110 /* FIXME: Add PW_128 support for 440GP DMA block */
111 #define GET_DMA_PW(x) (((x)&DMA_PW_MASK)>>(26-DMA_CR_OFFSET))
113 #define DMA_DAI (1<<(25-DMA_CR_OFFSET)) /* Destination Address Increment */
114 #define SET_DMA_DAI(x) (((x)&0x1)<<(25-DMA_CR_OFFSET))
116 #define DMA_SAI (1<<(24-DMA_CR_OFFSET)) /* Source Address Increment */
117 #define SET_DMA_SAI(x) (((x)&0x1)<<(24-DMA_CR_OFFSET))
119 #define DMA_BEN (1<<(23-DMA_CR_OFFSET)) /* Buffer Enable */
120 #define SET_DMA_BEN(x) (((x)&0x1)<<(23-DMA_CR_OFFSET))
122 #define SET_DMA_TM(x) (((x)&0x3)<<(21-DMA_CR_OFFSET)) /* Transfer Mode */
123 #define DMA_TM_MASK SET_DMA_TM(3)
124 #define TM_PERIPHERAL 0 /* Peripheral */
125 #define TM_RESERVED 1 /* Reserved */
126 #define TM_S_MM 2 /* Memory to Memory */
127 #define TM_D_MM 3 /* Device Paced Memory to Memory */
128 #define GET_DMA_TM(x) (((x)&DMA_TM_MASK)>>(21-DMA_CR_OFFSET))
130 #define SET_DMA_PSC(x) (((x)&0x3)<<(19-DMA_CR_OFFSET)) /* Peripheral Setup Cycles */
131 #define DMA_PSC_MASK SET_DMA_PSC(3)
132 #define GET_DMA_PSC(x) (((x)&DMA_PSC_MASK)>>(19-DMA_CR_OFFSET))
134 #define SET_DMA_PWC(x) (((x)&0x3F)<<(13-DMA_CR_OFFSET)) /* Peripheral Wait Cycles */
135 #define DMA_PWC_MASK SET_DMA_PWC(0x3F)
136 #define GET_DMA_PWC(x) (((x)&DMA_PWC_MASK)>>(13-DMA_CR_OFFSET))
138 #define SET_DMA_PHC(x) (((x)&0x7)<<(10-DMA_CR_OFFSET)) /* Peripheral Hold Cycles */
139 #define DMA_PHC_MASK SET_DMA_PHC(0x7)
140 #define GET_DMA_PHC(x) (((x)&DMA_PHC_MASK)>>(10-DMA_CR_OFFSET))
142 #define DMA_ETD_OUTPUT (1<<(9-DMA_CR_OFFSET)) /* EOT pin is a TC output */
143 #define SET_DMA_ETD(x) (((x)&0x1)<<(9-DMA_CR_OFFSET))
145 #define DMA_TCE_ENABLE (1<<(8-DMA_CR_OFFSET))
146 #define SET_DMA_TCE(x) (((x)&0x1)<<(8-DMA_CR_OFFSET))
148 #define DMA_DEC (1<<(2) /* Address Decrement */
149 #define SET_DMA_DEC(x) (((x)&0x1)<<2)
150 #define GET_DMA_DEC(x) (((x)&DMA_DEC)>>2)
154 * These modes are defined in a way that makes it possible to
155 * simply "or" in the value in the control register.
158 #define DMA_MODE_MM (SET_DMA_TM(TM_S_MM)) /* memory to memory */
160 /* Device-paced memory to memory, */
161 /* device is at source address */
162 #define DMA_MODE_MM_DEVATSRC (DMA_TD | SET_DMA_TM(TM_D_MM))
164 /* Device-paced memory to memory, */
165 /* device is at destination address */
166 #define DMA_MODE_MM_DEVATDST (SET_DMA_TM(TM_D_MM))
169 #define SET_DMA_PREFETCH(x) (((x)&0x3)<<(4-DMA_CR_OFFSET)) /* Memory Read Prefetch */
170 #define DMA_PREFETCH_MASK SET_DMA_PREFETCH(3)
171 #define PREFETCH_1 0 /* Prefetch 1 Double Word */
174 #define GET_DMA_PREFETCH(x) (((x)&DMA_PREFETCH_MASK)>>(4-DMA_CR_OFFSET))
176 #define DMA_PCE (1<<(3-DMA_CR_OFFSET)) /* Parity Check Enable */
177 #define SET_DMA_PCE(x) (((x)&0x1)<<(3-DMA_CR_OFFSET))
178 #define GET_DMA_PCE(x) (((x)&DMA_PCE)>>(3-DMA_CR_OFFSET))
182 #define DMA_ECE_ENABLE (1<<5)
183 #define SET_DMA_ECE(x) (((x)&0x1)<<5)
184 #define GET_DMA_ECE(x) (((x)&DMA_ECE_ENABLE)>>5)
186 #define DMA_TCD_DISABLE (1<<4)
187 #define SET_DMA_TCD(x) (((x)&0x1)<<4)
188 #define GET_DMA_TCD(x) (((x)&DMA_TCD_DISABLE)>>4)
190 typedef uint32_t sgl_handle_t;
192 #ifdef CONFIG_PPC4xx_EDMA
194 #define SGL_LIST_SIZE 4096
195 #define DMA_PPC4xx_SIZE SGL_LIST_SIZE
197 #define SET_DMA_PRIORITY(x) (((x)&0x3)<<(6-DMA_CR_OFFSET)) /* DMA Channel Priority */
198 #define DMA_PRIORITY_MASK SET_DMA_PRIORITY(3)
199 #define PRIORITY_LOW 0
200 #define PRIORITY_MID_LOW 1
201 #define PRIORITY_MID_HIGH 2
202 #define PRIORITY_HIGH 3
203 #define GET_DMA_PRIORITY(x) (((x)&DMA_PRIORITY_MASK)>>(6-DMA_CR_OFFSET))
206 * DMA Polarity Configuration Register
209 #define DMAReq0_ActiveLow (1<<31)
210 #define DMAAck0_ActiveLow (1<<30)
211 #define EOT0_ActiveLow (1<<29) /* End of Transfer */
213 #define DMAReq1_ActiveLow (1<<28)
214 #define DMAAck1_ActiveLow (1<<27)
215 #define EOT1_ActiveLow (1<<26)
217 #define DMAReq2_ActiveLow (1<<25)
218 #define DMAAck2_ActiveLow (1<<24)
219 #define EOT2_ActiveLow (1<<23)
221 #define DMAReq3_ActiveLow (1<<22)
222 #define DMAAck3_ActiveLow (1<<21)
223 #define EOT3_ActiveLow (1<<20)
226 * DMA Sleep Mode Register
228 #define SLEEP_MODE_ENABLE (1<<21)
231 * DMA Status Register
233 #define DMA_CS0 (1<<31) /* Terminal Count has been reached */
234 #define DMA_CS1 (1<<30)
235 #define DMA_CS2 (1<<29)
236 #define DMA_CS3 (1<<28)
238 #define DMA_TS0 (1<<27) /* End of Transfer has been requested */
239 #define DMA_TS1 (1<<26)
240 #define DMA_TS2 (1<<25)
241 #define DMA_TS3 (1<<24)
243 #define DMA_CH0_ERR (1<<23) /* DMA Chanel 0 Error */
244 #define DMA_CH1_ERR (1<<22)
245 #define DMA_CH2_ERR (1<<21)
246 #define DMA_CH3_ERR (1<<20)
248 #define DMA_IN_DMA_REQ0 (1<<19) /* Internal DMA Request is pending */
249 #define DMA_IN_DMA_REQ1 (1<<18)
250 #define DMA_IN_DMA_REQ2 (1<<17)
251 #define DMA_IN_DMA_REQ3 (1<<16)
253 #define DMA_EXT_DMA_REQ0 (1<<15) /* External DMA Request is pending */
254 #define DMA_EXT_DMA_REQ1 (1<<14)
255 #define DMA_EXT_DMA_REQ2 (1<<13)
256 #define DMA_EXT_DMA_REQ3 (1<<12)
258 #define DMA_CH0_BUSY (1<<11) /* DMA Channel 0 Busy */
259 #define DMA_CH1_BUSY (1<<10)
260 #define DMA_CH2_BUSY (1<<9)
261 #define DMA_CH3_BUSY (1<<8)
263 #define DMA_SG0 (1<<7) /* DMA Channel 0 Scatter/Gather in progress */
264 #define DMA_SG1 (1<<6)
265 #define DMA_SG2 (1<<5)
266 #define DMA_SG3 (1<<4)
269 * DMA SG Command Register
271 #define SSG0_ENABLE (1<<31) /* Start Scatter Gather */
272 #define SSG1_ENABLE (1<<30)
273 #define SSG2_ENABLE (1<<29)
274 #define SSG3_ENABLE (1<<28)
275 #define SSG0_MASK_ENABLE (1<<15) /* Enable writing to SSG0 bit */
276 #define SSG1_MASK_ENABLE (1<<14)
277 #define SSG2_MASK_ENABLE (1<<13)
278 #define SSG3_MASK_ENABLE (1<<12)
281 * DMA Scatter/Gather Descriptor Bit fields
283 #define SG_LINK (1<<31) /* Link */
284 #define SG_TCI_ENABLE (1<<29) /* Enable Terminal Count Interrupt */
285 #define SG_ETI_ENABLE (1<<28) /* Enable End of Transfer Interrupt */
286 #define SG_ERI_ENABLE (1<<27) /* Enable Error Interrupt */
287 #define SG_COUNT_MASK 0xFFFF /* Count Field */
289 #define SET_DMA_CONTROL \
290 (SET_DMA_CIE_ENABLE(p_init->int_enable) | /* interrupt enable */ \
291 SET_DMA_BEN(p_init->buffer_enable) | /* buffer enable */\
292 SET_DMA_ETD(p_init->etd_output) | /* end of transfer pin */ \
293 SET_DMA_TCE(p_init->tce_enable) | /* terminal count enable */ \
294 SET_DMA_PL(p_init->pl) | /* peripheral location */ \
295 SET_DMA_DAI(p_init->dai) | /* dest addr increment */ \
296 SET_DMA_SAI(p_init->sai) | /* src addr increment */ \
297 SET_DMA_PRIORITY(p_init->cp) | /* channel priority */ \
298 SET_DMA_PW(p_init->pwidth) | /* peripheral/bus width */ \
299 SET_DMA_PSC(p_init->psc) | /* peripheral setup cycles */ \
300 SET_DMA_PWC(p_init->pwc) | /* peripheral wait cycles */ \
301 SET_DMA_PHC(p_init->phc) | /* peripheral hold cycles */ \
302 SET_DMA_PREFETCH(p_init->pf) /* read prefetch */)
304 #define GET_DMA_POLARITY(chan) (DMAReq##chan##_ActiveLow | DMAAck##chan##_ActiveLow | EOT##chan##_ActiveLow)
306 #elif defined(CONFIG_STBXXX_DMA) /* stb03xxx */
308 #define DMA_PPC4xx_SIZE 4096
311 * DMA Status Register
314 #define SET_DMA_PRIORITY(x) (((x)&0x00800001)) /* DMA Channel Priority */
315 #define DMA_PRIORITY_MASK 0x00800001
316 #define PRIORITY_LOW 0x00000000
317 #define PRIORITY_MID_LOW 0x00000001
318 #define PRIORITY_MID_HIGH 0x00800000
319 #define PRIORITY_HIGH 0x00800001
320 #define GET_DMA_PRIORITY(x) (((((x)&DMA_PRIORITY_MASK) &0x00800000) >> 22 ) | (((x)&DMA_PRIORITY_MASK) &0x00000001))
322 #define DMA_CS0 (1<<31) /* Terminal Count has been reached */
323 #define DMA_CS1 (1<<30)
324 #define DMA_CS2 (1<<29)
325 #define DMA_CS3 (1<<28)
327 #define DMA_TS0 (1<<27) /* End of Transfer has been requested */
328 #define DMA_TS1 (1<<26)
329 #define DMA_TS2 (1<<25)
330 #define DMA_TS3 (1<<24)
332 #define DMA_CH0_ERR (1<<23) /* DMA Chanel 0 Error */
333 #define DMA_CH1_ERR (1<<22)
334 #define DMA_CH2_ERR (1<<21)
335 #define DMA_CH3_ERR (1<<20)
337 #define DMA_CT0 (1<<19) /* Chained transfere */
339 #define DMA_IN_DMA_REQ0 (1<<18) /* Internal DMA Request is pending */
340 #define DMA_IN_DMA_REQ1 (1<<17)
341 #define DMA_IN_DMA_REQ2 (1<<16)
342 #define DMA_IN_DMA_REQ3 (1<<15)
344 #define DMA_EXT_DMA_REQ0 (1<<14) /* External DMA Request is pending */
345 #define DMA_EXT_DMA_REQ1 (1<<13)
346 #define DMA_EXT_DMA_REQ2 (1<<12)
347 #define DMA_EXT_DMA_REQ3 (1<<11)
349 #define DMA_CH0_BUSY (1<<10) /* DMA Channel 0 Busy */
350 #define DMA_CH1_BUSY (1<<9)
351 #define DMA_CH2_BUSY (1<<8)
352 #define DMA_CH3_BUSY (1<<7)
354 #define DMA_CT1 (1<<6) /* Chained transfere */
355 #define DMA_CT2 (1<<5)
356 #define DMA_CT3 (1<<4)
358 #define DMA_CH_ENABLE (1<<7)
359 #define SET_DMA_CH(x) (((x)&0x1)<<7)
360 #define GET_DMA_CH(x) (((x)&DMA_CH_ENABLE)>>7)
362 /* STBx25xxx dma unique */
363 /* enable device port on a dma channel
364 * example ext 0 on dma 1
374 #define SERIAL2_XMIT 7
375 #define SERIAL2_RECV 6
378 #define SERIAL1_XMIT 3
379 #define SERIAL1_RECV 2
380 #define SERIAL0_XMIT 1
381 #define SERIAL0_RECV 0
391 * Bit 30 must be one for Redwoods, otherwise transfers may receive errors.
394 #define DMA_CR_MBO 0x2
396 #define SET_DMA_CONTROL \
397 (SET_DMA_CIE_ENABLE(p_init->int_enable) | /* interrupt enable */ \
398 SET_DMA_ETD(p_init->etd_output) | /* end of transfer pin */ \
399 SET_DMA_TCE(p_init->tce_enable) | /* terminal count enable */ \
400 SET_DMA_PL(p_init->pl) | /* peripheral location */ \
401 SET_DMA_DAI(p_init->dai) | /* dest addr increment */ \
402 SET_DMA_SAI(p_init->sai) | /* src addr increment */ \
403 SET_DMA_PRIORITY(p_init->cp) | /* channel priority */ \
404 SET_DMA_PW(p_init->pwidth) | /* peripheral/bus width */ \
405 SET_DMA_PSC(p_init->psc) | /* peripheral setup cycles */ \
406 SET_DMA_PWC(p_init->pwc) | /* peripheral wait cycles */ \
407 SET_DMA_PHC(p_init->phc) | /* peripheral hold cycles */ \
408 SET_DMA_TCD(p_init->tcd_disable) | /* TC chain mode disable */ \
409 SET_DMA_ECE(p_init->ece_enable) | /* ECE chanin mode enable */ \
410 SET_DMA_CH(p_init->ch_enable) | /* Chain enable */ \
411 DMA_CR_MBO /* must be one */)
413 #define GET_DMA_POLARITY(chan) chan
418 unsigned short in_use; /* set when channel is being used, clr when
422 * Valid polarity settings:
439 unsigned int polarity;
441 char buffer_enable; /* Boolean: buffer enable */
442 char tce_enable; /* Boolean: terminal count enable */
443 char etd_output; /* Boolean: eot pin is a tc output */
444 char pce; /* Boolean: parity check enable */
447 * Peripheral location:
448 * INTERNAL_PERIPHERAL (UART0 on the 405GP)
449 * EXTERNAL_PERIPHERAL
451 char pl; /* internal/external peripheral */
454 * Valid pwidth settings:
462 char dai; /* Boolean: dst address increment */
463 char sai; /* Boolean: src address increment */
466 * Valid psc settings: 0-3
468 unsigned int psc; /* Peripheral Setup Cycles */
471 * Valid pwc settings:
474 unsigned int pwc; /* Peripheral Wait Cycles */
477 * Valid phc settings:
480 unsigned int phc; /* Peripheral Hold Cycles */
483 * Valid cp (channel priority) settings:
489 unsigned int cp; /* channel priority */
492 * Valid pf (memory read prefetch) settings:
498 unsigned int pf; /* memory read prefetch */
501 * Boolean: channel interrupt enable
502 * NOTE: for sgl transfers, only the last descriptor will be setup to
507 char shift; /* easy access to byte_count shift, based on */
508 /* the width of the channel */
510 uint32_t control; /* channel control word */
512 /* These variabled are used ONLY in single dma transfers */
513 unsigned int mode; /* transfer mode */
515 char ce; /* channel enable */
516 #ifdef CONFIG_STB03xxx
520 char td; /* transfer direction */
527 phys_addr_t src_addr;
528 phys_addr_t dst_addr;
529 uint32_t control_count;
535 uint32_t control; /* channel ctrl word; loaded from each descrptr */
536 uint32_t sgl_control; /* LK, TCI, ETI, and ERI bits in sgl descriptor */
537 dma_addr_t dma_addr; /* dma (physical) address of this list */
544 phys_addr_t *src_addr;
545 phys_addr_t *dst_addr;
546 phys_addr_t dma_src_addr;
547 phys_addr_t dma_dst_addr;
550 extern ppc_dma_ch_t dma_channels[];
553 * The DMA API are in ppc4xx_dma.c and ppc4xx_sgdma.c
555 extern int hw_init_dma_channel(unsigned int, ppc_dma_ch_t *);
556 extern int get_channel_config(unsigned int, ppc_dma_ch_t *);
557 extern int set_channel_priority(unsigned int, unsigned int);
558 extern unsigned int get_peripheral_width(unsigned int);
559 extern int alloc_dma_handle(sgl_handle_t *, unsigned int, unsigned int);
560 extern void free_dma_handle(sgl_handle_t);
561 extern int get_dma_status(void);
562 extern void set_src_addr(int dmanr, phys_addr_t src_addr);
563 extern void set_dst_addr(int dmanr, phys_addr_t dst_addr);
564 extern int enable_dma(unsigned int dmanr);
565 extern void disable_dma(unsigned int dmanr);
566 extern int set_dma_mode(unsigned int dmanr, unsigned int mode);
567 extern void set_dma_count(unsigned int dmanr, unsigned int count);
568 extern int get_dma_residue(unsigned int dmanr);
569 extern void set_dma_addr(unsigned int dmanr, phys_addr_t addr);
570 extern void set_dma_addr2(unsigned int dmanr, phys_addr_t src_dma_addr,
571 phys_addr_t dst_dma_addr);
572 extern int enable_dma_interrupt(unsigned int dmanr);
573 extern int disable_dma_interrupt(unsigned int dmanr);
574 extern int clr_dma_status(unsigned int dmanr);
575 extern int map_dma_port(unsigned int dmanr, unsigned int ocp_dma,short dma_chan);
576 extern int disable_dma_port(unsigned int dmanr, unsigned int ocp_dma,short dma_chan);
579 #endif /* __KERNEL__ */