2 * linux/arch/arm/omap/dma.c
4 * Copyright (C) 2003 Nokia Corporation
5 * Author: Juha Yrjölä <juha.yrjola@nokia.com>
6 * DMA channel linking for 1610 by Samuel Ortiz <samuel.ortiz@nokia.com>
7 * Graphics DMA and LCD DMA graphics tranformations
8 * by Imre Deak <imre.deak@nokia.com>
9 * Some functions based on earlier dma-omap.c Copyright (C) 2001 RidgeRun, Inc.
11 * Support functions for the OMAP internal DMA channels.
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License version 2 as
15 * published by the Free Software Foundation.
19 #include <linux/module.h>
20 #include <linux/init.h>
21 #include <linux/sched.h>
22 #include <linux/spinlock.h>
23 #include <linux/errno.h>
24 #include <linux/interrupt.h>
26 #include <asm/system.h>
28 #include <asm/hardware.h>
32 #include <asm/arch/tc.h>
34 #define OMAP_DMA_ACTIVE 0x01
36 #define OMAP_DMA_CCR_EN (1 << 7)
38 #define OMAP_FUNC_MUX_ARM_BASE (0xfffe1000 + 0xec)
40 static int enable_1510_mode
= 0;
48 void (* callback
)(int lch
, u16 ch_status
, void *data
);
53 static int dma_chan_count
;
55 static spinlock_t dma_chan_lock
;
56 static struct omap_dma_lch dma_chan
[OMAP_LOGICAL_DMA_CH_COUNT
];
58 const static u8 dma_irq
[OMAP_LOGICAL_DMA_CH_COUNT
] = {
59 INT_DMA_CH0_6
, INT_DMA_CH1_7
, INT_DMA_CH2_8
, INT_DMA_CH3
,
60 INT_DMA_CH4
, INT_DMA_CH5
, INT_1610_DMA_CH6
, INT_1610_DMA_CH7
,
61 INT_1610_DMA_CH8
, INT_1610_DMA_CH9
, INT_1610_DMA_CH10
,
62 INT_1610_DMA_CH11
, INT_1610_DMA_CH12
, INT_1610_DMA_CH13
,
63 INT_1610_DMA_CH14
, INT_1610_DMA_CH15
, INT_DMA_LCD
66 static inline int get_gdma_dev(int req
)
68 u32 reg
= OMAP_FUNC_MUX_ARM_BASE
+ ((req
- 1) / 5) * 4;
69 int shift
= ((req
- 1) % 5) * 6;
71 return ((omap_readl(reg
) >> shift
) & 0x3f) + 1;
74 static inline void set_gdma_dev(int req
, int dev
)
76 u32 reg
= OMAP_FUNC_MUX_ARM_BASE
+ ((req
- 1) / 5) * 4;
77 int shift
= ((req
- 1) % 5) * 6;
81 l
&= ~(0x3f << shift
);
82 l
|= (dev
- 1) << shift
;
86 static void clear_lch_regs(int lch
)
89 u32 lch_base
= OMAP_DMA_BASE
+ lch
* 0x40;
91 for (i
= 0; i
< 0x2c; i
+= 2)
92 omap_writew(0, lch_base
+ i
);
95 void omap_set_dma_priority(int dst_port
, int priority
)
101 case OMAP_DMA_PORT_OCP_T1
: /* FFFECC00 */
102 reg
= OMAP_TC_OCPT1_PRIOR
;
104 case OMAP_DMA_PORT_OCP_T2
: /* FFFECCD0 */
105 reg
= OMAP_TC_OCPT2_PRIOR
;
107 case OMAP_DMA_PORT_EMIFF
: /* FFFECC08 */
108 reg
= OMAP_TC_EMIFF_PRIOR
;
110 case OMAP_DMA_PORT_EMIFS
: /* FFFECC04 */
111 reg
= OMAP_TC_EMIFS_PRIOR
;
119 l
|= (priority
& 0xf) << 8;
123 void omap_set_dma_transfer_params(int lch
, int data_type
, int elem_count
,
124 int frame_count
, int sync_mode
)
128 w
= omap_readw(OMAP_DMA_CSDP(lch
));
131 omap_writew(w
, OMAP_DMA_CSDP(lch
));
133 w
= omap_readw(OMAP_DMA_CCR(lch
));
135 if (sync_mode
== OMAP_DMA_SYNC_FRAME
)
137 omap_writew(w
, OMAP_DMA_CCR(lch
));
139 w
= omap_readw(OMAP_DMA_CCR2(lch
));
141 if (sync_mode
== OMAP_DMA_SYNC_BLOCK
)
143 omap_writew(w
, OMAP_DMA_CCR2(lch
));
145 omap_writew(elem_count
, OMAP_DMA_CEN(lch
));
146 omap_writew(frame_count
, OMAP_DMA_CFN(lch
));
149 void omap_set_dma_color_mode(int lch
, enum omap_dma_color_mode mode
, u32 color
)
153 BUG_ON(omap_dma_in_1510_mode());
155 w
= omap_readw(OMAP_DMA_CCR2(lch
)) & ~0x03;
157 case OMAP_DMA_CONSTANT_FILL
:
160 case OMAP_DMA_TRANSPARENT_COPY
:
163 case OMAP_DMA_COLOR_DIS
:
168 omap_writew(w
, OMAP_DMA_CCR2(lch
));
170 w
= omap_readw(OMAP_DMA_LCH_CTRL(lch
)) & ~0x0f;
171 /* Default is channel type 2D */
173 omap_writew((u16
)color
, OMAP_DMA_COLOR_L(lch
));
174 omap_writew((u16
)(color
>> 16), OMAP_DMA_COLOR_U(lch
));
175 w
|= 1; /* Channel type G */
177 omap_writew(w
, OMAP_DMA_LCH_CTRL(lch
));
181 void omap_set_dma_src_params(int lch
, int src_port
, int src_amode
,
182 unsigned long src_start
)
186 w
= omap_readw(OMAP_DMA_CSDP(lch
));
189 omap_writew(w
, OMAP_DMA_CSDP(lch
));
191 w
= omap_readw(OMAP_DMA_CCR(lch
));
193 w
|= src_amode
<< 12;
194 omap_writew(w
, OMAP_DMA_CCR(lch
));
196 omap_writew(src_start
>> 16, OMAP_DMA_CSSA_U(lch
));
197 omap_writew(src_start
, OMAP_DMA_CSSA_L(lch
));
200 void omap_set_dma_src_index(int lch
, int eidx
, int fidx
)
202 omap_writew(eidx
, OMAP_DMA_CSEI(lch
));
203 omap_writew(fidx
, OMAP_DMA_CSFI(lch
));
206 void omap_set_dma_src_data_pack(int lch
, int enable
)
210 w
= omap_readw(OMAP_DMA_CSDP(lch
)) & ~(1 << 6);
211 w
|= enable
? (1 << 6) : 0;
212 omap_writew(w
, OMAP_DMA_CSDP(lch
));
215 void omap_set_dma_src_burst_mode(int lch
, enum omap_dma_burst_mode burst_mode
)
219 w
= omap_readw(OMAP_DMA_CSDP(lch
)) & ~(0x03 << 7);
220 switch (burst_mode
) {
221 case OMAP_DMA_DATA_BURST_DIS
:
223 case OMAP_DMA_DATA_BURST_4
:
226 case OMAP_DMA_DATA_BURST_8
:
227 /* not supported by current hardware
234 omap_writew(w
, OMAP_DMA_CSDP(lch
));
237 void omap_set_dma_dest_params(int lch
, int dest_port
, int dest_amode
,
238 unsigned long dest_start
)
242 w
= omap_readw(OMAP_DMA_CSDP(lch
));
245 omap_writew(w
, OMAP_DMA_CSDP(lch
));
247 w
= omap_readw(OMAP_DMA_CCR(lch
));
249 w
|= dest_amode
<< 14;
250 omap_writew(w
, OMAP_DMA_CCR(lch
));
252 omap_writew(dest_start
>> 16, OMAP_DMA_CDSA_U(lch
));
253 omap_writew(dest_start
, OMAP_DMA_CDSA_L(lch
));
256 void omap_set_dma_dest_index(int lch
, int eidx
, int fidx
)
258 omap_writew(eidx
, OMAP_DMA_CDEI(lch
));
259 omap_writew(fidx
, OMAP_DMA_CDFI(lch
));
262 void omap_set_dma_dest_data_pack(int lch
, int enable
)
266 w
= omap_readw(OMAP_DMA_CSDP(lch
)) & ~(1 << 13);
267 w
|= enable
? (1 << 13) : 0;
268 omap_writew(w
, OMAP_DMA_CSDP(lch
));
271 void omap_set_dma_dest_burst_mode(int lch
, enum omap_dma_burst_mode burst_mode
)
275 w
= omap_readw(OMAP_DMA_CSDP(lch
)) & ~(0x03 << 14);
276 switch (burst_mode
) {
277 case OMAP_DMA_DATA_BURST_DIS
:
279 case OMAP_DMA_DATA_BURST_4
:
282 case OMAP_DMA_DATA_BURST_8
:
286 printk(KERN_ERR
"Invalid DMA burst mode\n");
290 omap_writew(w
, OMAP_DMA_CSDP(lch
));
293 static inline void init_intr(int lch
)
297 /* Read CSR to make sure it's cleared. */
298 w
= omap_readw(OMAP_DMA_CSR(lch
));
299 /* Enable some nice interrupts. */
300 omap_writew(dma_chan
[lch
].enabled_irqs
, OMAP_DMA_CICR(lch
));
301 dma_chan
[lch
].flags
|= OMAP_DMA_ACTIVE
;
304 static inline void enable_lnk(int lch
)
308 /* Clear the STOP_LNK bits */
309 w
= omap_readw(OMAP_DMA_CLNK_CTRL(lch
));
311 omap_writew(w
, OMAP_DMA_CLNK_CTRL(lch
));
313 /* And set the ENABLE_LNK bits */
314 if (dma_chan
[lch
].next_lch
!= -1)
315 omap_writew(dma_chan
[lch
].next_lch
| (1 << 15),
316 OMAP_DMA_CLNK_CTRL(lch
));
319 static inline void disable_lnk(int lch
)
323 /* Disable interrupts */
324 omap_writew(0, OMAP_DMA_CICR(lch
));
326 /* Set the STOP_LNK bit */
327 w
= omap_readw(OMAP_DMA_CLNK_CTRL(lch
));
329 w
= omap_writew(w
, OMAP_DMA_CLNK_CTRL(lch
));
331 dma_chan
[lch
].flags
&= ~OMAP_DMA_ACTIVE
;
334 void omap_start_dma(int lch
)
338 if (!omap_dma_in_1510_mode() && dma_chan
[lch
].next_lch
!= -1) {
339 int next_lch
, cur_lch
;
340 char dma_chan_link_map
[OMAP_LOGICAL_DMA_CH_COUNT
];
342 dma_chan_link_map
[lch
] = 1;
343 /* Set the link register of the first channel */
346 memset(dma_chan_link_map
, 0, sizeof(dma_chan_link_map
));
347 cur_lch
= dma_chan
[lch
].next_lch
;
349 next_lch
= dma_chan
[cur_lch
].next_lch
;
351 /* The loop case: we've been here already */
352 if (dma_chan_link_map
[cur_lch
])
354 /* Mark the current channel */
355 dma_chan_link_map
[cur_lch
] = 1;
361 } while (next_lch
!= -1);
366 w
= omap_readw(OMAP_DMA_CCR(lch
));
367 w
|= OMAP_DMA_CCR_EN
;
368 omap_writew(w
, OMAP_DMA_CCR(lch
));
369 dma_chan
[lch
].flags
|= OMAP_DMA_ACTIVE
;
372 void omap_stop_dma(int lch
)
376 if (!omap_dma_in_1510_mode() && dma_chan
[lch
].next_lch
!= -1) {
377 int next_lch
, cur_lch
= lch
;
378 char dma_chan_link_map
[OMAP_LOGICAL_DMA_CH_COUNT
];
380 memset(dma_chan_link_map
, 0, sizeof(dma_chan_link_map
));
382 /* The loop case: we've been here already */
383 if (dma_chan_link_map
[cur_lch
])
385 /* Mark the current channel */
386 dma_chan_link_map
[cur_lch
] = 1;
388 disable_lnk(cur_lch
);
390 next_lch
= dma_chan
[cur_lch
].next_lch
;
392 } while (next_lch
!= -1);
396 /* Disable all interrupts on the channel */
397 omap_writew(0, OMAP_DMA_CICR(lch
));
399 w
= omap_readw(OMAP_DMA_CCR(lch
));
400 w
&= ~OMAP_DMA_CCR_EN
;
401 omap_writew(w
, OMAP_DMA_CCR(lch
));
402 dma_chan
[lch
].flags
&= ~OMAP_DMA_ACTIVE
;
405 void omap_enable_dma_irq(int lch
, u16 bits
)
407 dma_chan
[lch
].enabled_irqs
|= bits
;
410 void omap_disable_dma_irq(int lch
, u16 bits
)
412 dma_chan
[lch
].enabled_irqs
&= ~bits
;
415 static int dma_handle_ch(int ch
)
419 if (enable_1510_mode
&& ch
>= 6) {
420 csr
= dma_chan
[ch
].saved_csr
;
421 dma_chan
[ch
].saved_csr
= 0;
423 csr
= omap_readw(OMAP_DMA_CSR(ch
));
424 if (enable_1510_mode
&& ch
<= 2 && (csr
>> 7) != 0) {
425 dma_chan
[ch
+ 6].saved_csr
= csr
>> 7;
430 if (unlikely(dma_chan
[ch
].dev_id
== -1)) {
431 printk(KERN_WARNING
"Spurious interrupt from DMA channel %d (CSR %04x)\n",
435 if (unlikely(csr
& OMAP_DMA_TOUT_IRQ
))
436 printk(KERN_WARNING
"DMA timeout with device %d\n", dma_chan
[ch
].dev_id
);
437 if (unlikely(csr
& OMAP_DMA_DROP_IRQ
))
438 printk(KERN_WARNING
"DMA synchronization event drop occurred with device %d\n",
439 dma_chan
[ch
].dev_id
);
440 if (likely(csr
& OMAP_DMA_BLOCK_IRQ
))
441 dma_chan
[ch
].flags
&= ~OMAP_DMA_ACTIVE
;
442 if (likely(dma_chan
[ch
].callback
!= NULL
))
443 dma_chan
[ch
].callback(ch
, csr
, dma_chan
[ch
].data
);
447 static irqreturn_t
dma_irq_handler(int irq
, void *dev_id
, struct pt_regs
*regs
)
449 int ch
= ((int) dev_id
) - 1;
455 handled_now
+= dma_handle_ch(ch
);
456 if (enable_1510_mode
&& dma_chan
[ch
+ 6].saved_csr
)
457 handled_now
+= dma_handle_ch(ch
+ 6);
460 handled
+= handled_now
;
463 return handled
? IRQ_HANDLED
: IRQ_NONE
;
466 int omap_request_dma(int dev_id
, const char *dev_name
,
467 void (* callback
)(int lch
, u16 ch_status
, void *data
),
468 void *data
, int *dma_ch_out
)
470 int ch
, free_ch
= -1;
472 struct omap_dma_lch
*chan
;
474 spin_lock_irqsave(&dma_chan_lock
, flags
);
475 for (ch
= 0; ch
< dma_chan_count
; ch
++) {
476 if (free_ch
== -1 && dma_chan
[ch
].dev_id
== -1) {
483 spin_unlock_irqrestore(&dma_chan_lock
, flags
);
486 chan
= dma_chan
+ free_ch
;
487 chan
->dev_id
= dev_id
;
488 clear_lch_regs(free_ch
);
489 spin_unlock_irqrestore(&dma_chan_lock
, flags
);
491 chan
->dev_id
= dev_id
;
492 chan
->dev_name
= dev_name
;
493 chan
->callback
= callback
;
495 chan
->enabled_irqs
= OMAP_DMA_TOUT_IRQ
| OMAP_DMA_DROP_IRQ
| OMAP_DMA_BLOCK_IRQ
;
497 if (cpu_is_omap16xx()) {
498 /* If the sync device is set, configure it dynamically. */
500 set_gdma_dev(free_ch
+ 1, dev_id
);
501 dev_id
= free_ch
+ 1;
503 /* Disable the 1510 compatibility mode and set the sync device
505 omap_writew(dev_id
| (1 << 10), OMAP_DMA_CCR(free_ch
));
507 omap_writew(dev_id
, OMAP_DMA_CCR(free_ch
));
509 *dma_ch_out
= free_ch
;
514 void omap_free_dma(int ch
)
518 spin_lock_irqsave(&dma_chan_lock
, flags
);
519 if (dma_chan
[ch
].dev_id
== -1) {
520 printk("omap_dma: trying to free nonallocated DMA channel %d\n", ch
);
521 spin_unlock_irqrestore(&dma_chan_lock
, flags
);
524 dma_chan
[ch
].dev_id
= -1;
525 spin_unlock_irqrestore(&dma_chan_lock
, flags
);
527 /* Disable all DMA interrupts for the channel. */
528 omap_writew(0, OMAP_DMA_CICR(ch
));
529 /* Make sure the DMA transfer is stopped. */
530 omap_writew(0, OMAP_DMA_CCR(ch
));
533 int omap_dma_in_1510_mode(void)
535 return enable_1510_mode
;
539 * lch_queue DMA will start right after lch_head one is finished.
540 * For this DMA link to start, you still need to start (see omap_start_dma)
541 * the first one. That will fire up the entire queue.
543 void omap_dma_link_lch (int lch_head
, int lch_queue
)
545 if (omap_dma_in_1510_mode()) {
546 printk(KERN_ERR
"DMA linking is not supported in 1510 mode\n");
551 if ((dma_chan
[lch_head
].dev_id
== -1) ||
552 (dma_chan
[lch_queue
].dev_id
== -1)) {
553 printk(KERN_ERR
"omap_dma: trying to link non requested channels\n");
557 dma_chan
[lch_head
].next_lch
= lch_queue
;
561 * Once the DMA queue is stopped, we can destroy it.
563 void omap_dma_unlink_lch (int lch_head
, int lch_queue
)
565 if (omap_dma_in_1510_mode()) {
566 printk(KERN_ERR
"DMA linking is not supported in 1510 mode\n");
571 if (dma_chan
[lch_head
].next_lch
!= lch_queue
||
572 dma_chan
[lch_head
].next_lch
== -1) {
573 printk(KERN_ERR
"omap_dma: trying to unlink non linked channels\n");
578 if ((dma_chan
[lch_head
].flags
& OMAP_DMA_ACTIVE
) ||
579 (dma_chan
[lch_head
].flags
& OMAP_DMA_ACTIVE
)) {
580 printk(KERN_ERR
"omap_dma: You need to stop the DMA channels before unlinking\n");
584 dma_chan
[lch_head
].next_lch
= -1;
588 static struct lcd_dma_info
{
591 void (* callback
)(u16 status
, void *data
);
595 unsigned long addr
, size
;
596 int rotate
, data_type
, xres
, yres
;
605 void omap_set_lcd_dma_b1(unsigned long addr
, u16 fb_xres
, u16 fb_yres
,
609 lcd_dma
.data_type
= data_type
;
610 lcd_dma
.xres
= fb_xres
;
611 lcd_dma
.yres
= fb_yres
;
614 void omap_set_lcd_dma_src_port(int port
)
616 lcd_dma
.src_port
= port
;
619 void omap_set_lcd_dma_ext_controller(int external
)
621 lcd_dma
.ext_ctrl
= external
;
624 void omap_set_lcd_dma_single_transfer(int single
)
626 lcd_dma
.single_transfer
= single
;
630 void omap_set_lcd_dma_b1_rotation(int rotate
)
632 if (omap_dma_in_1510_mode()) {
633 printk(KERN_ERR
"DMA rotation is not supported in 1510 mode\n");
637 lcd_dma
.rotate
= rotate
;
640 void omap_set_lcd_dma_b1_mirror(int mirror
)
642 if (omap_dma_in_1510_mode()) {
643 printk(KERN_ERR
"DMA mirror is not supported in 1510 mode\n");
646 lcd_dma
.mirror
= mirror
;
649 void omap_set_lcd_dma_b1_vxres(unsigned long vxres
)
651 if (omap_dma_in_1510_mode()) {
652 printk(KERN_ERR
"DMA virtual resulotion is not supported "
656 lcd_dma
.vxres
= vxres
;
659 void omap_set_lcd_dma_b1_scale(unsigned int xscale
, unsigned int yscale
)
661 if (omap_dma_in_1510_mode()) {
662 printk(KERN_ERR
"DMA scale is not supported in 1510 mode\n");
665 lcd_dma
.xscale
= xscale
;
666 lcd_dma
.yscale
= yscale
;
669 static void set_b1_regs(void)
671 unsigned long top
, bottom
;
674 unsigned long en
, fn
;
677 unsigned int xscale
, yscale
;
679 switch (lcd_dma
.data_type
) {
680 case OMAP_DMA_DATA_TYPE_S8
:
683 case OMAP_DMA_DATA_TYPE_S16
:
686 case OMAP_DMA_DATA_TYPE_S32
:
694 vxres
= lcd_dma
.vxres
? lcd_dma
.vxres
: lcd_dma
.xres
;
695 xscale
= lcd_dma
.xscale
? lcd_dma
.xscale
: 1;
696 yscale
= lcd_dma
.yscale
? lcd_dma
.yscale
: 1;
697 BUG_ON(vxres
< lcd_dma
.xres
);
698 #define PIXADDR(x,y) (lcd_dma.addr + ((y) * vxres * yscale + (x) * xscale) * es)
699 #define PIXSTEP(sx, sy, dx, dy) (PIXADDR(dx, dy) - PIXADDR(sx, sy) - es + 1)
700 switch (lcd_dma
.rotate
) {
702 if (!lcd_dma
.mirror
) {
704 bottom
= PIXADDR(lcd_dma
.xres
- 1, lcd_dma
.yres
- 1);
705 /* 1510 DMA requires the bottom address to be 2 more
706 * than the actual last memory access location. */
707 if (omap_dma_in_1510_mode() &&
708 lcd_dma
.data_type
== OMAP_DMA_DATA_TYPE_S32
)
710 ei
= PIXSTEP(0, 0, 1, 0);
711 fi
= PIXSTEP(lcd_dma
.xres
- 1, 0, 0, 1);
713 top
= PIXADDR(lcd_dma
.xres
- 1, 0);
714 bottom
= PIXADDR(0, lcd_dma
.yres
- 1);
715 ei
= PIXSTEP(1, 0, 0, 0);
716 fi
= PIXSTEP(0, 0, lcd_dma
.xres
- 1, 1);
722 if (!lcd_dma
.mirror
) {
723 top
= PIXADDR(0, lcd_dma
.yres
- 1);
724 bottom
= PIXADDR(lcd_dma
.xres
- 1, 0);
725 ei
= PIXSTEP(0, 1, 0, 0);
726 fi
= PIXSTEP(0, 0, 1, lcd_dma
.yres
- 1);
728 top
= PIXADDR(lcd_dma
.xres
- 1, lcd_dma
.yres
- 1);
729 bottom
= PIXADDR(0, 0);
730 ei
= PIXSTEP(0, 1, 0, 0);
731 fi
= PIXSTEP(1, 0, 0, lcd_dma
.yres
- 1);
737 if (!lcd_dma
.mirror
) {
738 top
= PIXADDR(lcd_dma
.xres
- 1, lcd_dma
.yres
- 1);
739 bottom
= PIXADDR(0, 0);
740 ei
= PIXSTEP(1, 0, 0, 0);
741 fi
= PIXSTEP(0, 1, lcd_dma
.xres
- 1, 0);
743 top
= PIXADDR(0, lcd_dma
.yres
- 1);
744 bottom
= PIXADDR(lcd_dma
.xres
- 1, 0);
745 ei
= PIXSTEP(0, 0, 1, 0);
746 fi
= PIXSTEP(lcd_dma
.xres
- 1, 1, 0, 0);
752 if (!lcd_dma
.mirror
) {
753 top
= PIXADDR(lcd_dma
.xres
- 1, 0);
754 bottom
= PIXADDR(0, lcd_dma
.yres
- 1);
755 ei
= PIXSTEP(0, 0, 0, 1);
756 fi
= PIXSTEP(1, lcd_dma
.yres
- 1, 0, 0);
759 bottom
= PIXADDR(lcd_dma
.xres
- 1, lcd_dma
.yres
- 1);
760 ei
= PIXSTEP(0, 0, 0, 1);
761 fi
= PIXSTEP(0, lcd_dma
.yres
- 1, 1, 0);
768 return; /* Supress warning about uninitialized vars */
771 if (omap_dma_in_1510_mode()) {
772 omap_writew(top
>> 16, OMAP1510_DMA_LCD_TOP_F1_U
);
773 omap_writew(top
, OMAP1510_DMA_LCD_TOP_F1_L
);
774 omap_writew(bottom
>> 16, OMAP1510_DMA_LCD_BOT_F1_U
);
775 omap_writew(bottom
, OMAP1510_DMA_LCD_BOT_F1_L
);
781 omap_writew(top
>> 16, OMAP1610_DMA_LCD_TOP_B1_U
);
782 omap_writew(top
, OMAP1610_DMA_LCD_TOP_B1_L
);
783 omap_writew(bottom
>> 16, OMAP1610_DMA_LCD_BOT_B1_U
);
784 omap_writew(bottom
, OMAP1610_DMA_LCD_BOT_B1_L
);
786 omap_writew(en
, OMAP1610_DMA_LCD_SRC_EN_B1
);
787 omap_writew(fn
, OMAP1610_DMA_LCD_SRC_FN_B1
);
789 w
= omap_readw(OMAP1610_DMA_LCD_CSDP
);
791 w
|= lcd_dma
.data_type
;
792 omap_writew(w
, OMAP1610_DMA_LCD_CSDP
);
794 w
= omap_readw(OMAP1610_DMA_LCD_CTRL
);
795 /* Always set the source port as SDRAM for now*/
797 if (lcd_dma
.ext_ctrl
)
801 if (lcd_dma
.callback
!= NULL
)
802 w
|= 1 << 1; /* Block interrupt enable */
805 omap_writew(w
, OMAP1610_DMA_LCD_CTRL
);
807 if (!(lcd_dma
.rotate
|| lcd_dma
.mirror
||
808 lcd_dma
.vxres
|| lcd_dma
.xscale
|| lcd_dma
.yscale
))
811 w
= omap_readw(OMAP1610_DMA_LCD_CCR
);
812 /* Set the double-indexed addressing mode */
814 omap_writew(w
, OMAP1610_DMA_LCD_CCR
);
816 omap_writew(ei
, OMAP1610_DMA_LCD_SRC_EI_B1
);
817 omap_writew(fi
>> 16, OMAP1610_DMA_LCD_SRC_FI_B1_U
);
818 omap_writew(fi
, OMAP1610_DMA_LCD_SRC_FI_B1_L
);
821 static irqreturn_t
lcd_dma_irq_handler(int irq
, void *dev_id
, struct pt_regs
*regs
)
825 w
= omap_readw(OMAP1610_DMA_LCD_CTRL
);
826 if (unlikely(!(w
& (1 << 3)))) {
827 printk(KERN_WARNING
"Spurious LCD DMA IRQ\n");
832 omap_writew(w
, OMAP1610_DMA_LCD_CTRL
);
834 if (lcd_dma
.callback
!= NULL
)
835 lcd_dma
.callback(w
, lcd_dma
.cb_data
);
840 int omap_request_lcd_dma(void (* callback
)(u16 status
, void *data
),
843 spin_lock_irq(&lcd_dma
.lock
);
844 if (lcd_dma
.reserved
) {
845 spin_unlock_irq(&lcd_dma
.lock
);
846 printk(KERN_ERR
"LCD DMA channel already reserved\n");
850 lcd_dma
.reserved
= 1;
851 spin_unlock_irq(&lcd_dma
.lock
);
852 lcd_dma
.callback
= callback
;
853 lcd_dma
.cb_data
= data
;
855 lcd_dma
.single_transfer
= 0;
861 lcd_dma
.ext_ctrl
= 0;
862 lcd_dma
.src_port
= 0;
867 void omap_free_lcd_dma(void)
869 spin_lock(&lcd_dma
.lock
);
870 if (!lcd_dma
.reserved
) {
871 spin_unlock(&lcd_dma
.lock
);
872 printk(KERN_ERR
"LCD DMA is not reserved\n");
876 if (!enable_1510_mode
)
877 omap_writew(omap_readw(OMAP1610_DMA_LCD_CCR
) & ~1, OMAP1610_DMA_LCD_CCR
);
878 lcd_dma
.reserved
= 0;
879 spin_unlock(&lcd_dma
.lock
);
882 void omap_enable_lcd_dma(void)
886 /* Set the Enable bit only if an external controller is
887 * connected. Otherwise the OMAP internal controller will
888 * start the transfer when it gets enabled.
890 if (enable_1510_mode
|| !lcd_dma
.ext_ctrl
)
892 w
= omap_readw(OMAP1610_DMA_LCD_CCR
);
894 omap_writew(w
, OMAP1610_DMA_LCD_CCR
);
898 void omap_setup_lcd_dma(void)
900 BUG_ON(lcd_dma
.active
);
901 if (!enable_1510_mode
) {
902 /* Set some reasonable defaults */
903 omap_writew(0x5440, OMAP1610_DMA_LCD_CCR
);
904 omap_writew(0x9102, OMAP1610_DMA_LCD_CSDP
);
905 omap_writew(0x0004, OMAP1610_DMA_LCD_LCH_CTRL
);
908 if (!enable_1510_mode
) {
911 w
= omap_readw(OMAP1610_DMA_LCD_CCR
);
912 /* If DMA was already active set the end_prog bit to have
913 * the programmed register set loaded into the active
916 w
|= 1 << 11; /* End_prog */
917 if (!lcd_dma
.single_transfer
)
918 w
|= (3 << 8); /* Auto_init, repeat */
919 omap_writew(w
, OMAP1610_DMA_LCD_CCR
);
923 void omap_stop_lcd_dma(void)
926 if (!enable_1510_mode
&& lcd_dma
.ext_ctrl
)
927 omap_writew(omap_readw(OMAP1610_DMA_LCD_CCR
) & ~(1 << 7),
928 OMAP1610_DMA_LCD_CCR
);
932 * Clears any DMA state so the DMA engine is ready to restart with new buffers
933 * through omap_start_dma(). Any buffers in flight are discarded.
935 void omap_clear_dma(int lch
)
940 local_irq_save(flags
);
941 omap_writew(omap_readw(OMAP_DMA_CCR(lch
)) & ~OMAP_DMA_CCR_EN
,
943 status
= OMAP_DMA_CSR(lch
); /* clear pending interrupts */
944 local_irq_restore(flags
);
948 * Returns current physical source address for the given DMA channel.
949 * If the channel is running the caller must disable interrupts prior calling
950 * this function and process the returned value before re-enabling interrupt to
951 * prevent races with the interrupt handler. Note that in continuous mode there
952 * is a chance for CSSA_L register overflow inbetween the two reads resulting
953 * in incorrect return value.
955 dma_addr_t
omap_get_dma_src_pos(int lch
)
957 return (dma_addr_t
) (OMAP_DMA_CSSA_L(lch
) |
958 (OMAP_DMA_CSSA_U(lch
) << 16));
962 * Returns current physical destination address for the given DMA channel.
963 * If the channel is running the caller must disable interrupts prior calling
964 * this function and process the returned value before re-enabling interrupt to
965 * prevent races with the interrupt handler. Note that in continuous mode there
966 * is a chance for CDSA_L register overflow inbetween the two reads resulting
967 * in incorrect return value.
969 dma_addr_t
omap_get_dma_dst_pos(int lch
)
971 return (dma_addr_t
) (OMAP_DMA_CDSA_L(lch
) |
972 (OMAP_DMA_CDSA_U(lch
) << 16));
975 static int __init
omap_init_dma(void)
979 if (cpu_is_omap1510()) {
980 printk(KERN_INFO
"DMA support for OMAP1510 initialized\n");
982 enable_1510_mode
= 1;
983 } else if (cpu_is_omap16xx() || cpu_is_omap730()) {
984 printk(KERN_INFO
"OMAP DMA hardware version %d\n",
985 omap_readw(OMAP_DMA_HW_ID
));
986 printk(KERN_INFO
"DMA capabilities: %08x:%08x:%04x:%04x:%04x\n",
987 (omap_readw(OMAP_DMA_CAPS_0_U
) << 16) | omap_readw(OMAP_DMA_CAPS_0_L
),
988 (omap_readw(OMAP_DMA_CAPS_1_U
) << 16) | omap_readw(OMAP_DMA_CAPS_1_L
),
989 omap_readw(OMAP_DMA_CAPS_2
), omap_readw(OMAP_DMA_CAPS_3
),
990 omap_readw(OMAP_DMA_CAPS_4
));
991 if (!enable_1510_mode
) {
994 /* Disable OMAP 3.0/3.1 compatibility mode. */
995 w
= omap_readw(OMAP_DMA_GSCR
);
997 omap_writew(w
, OMAP_DMA_GSCR
);
1006 memset(&lcd_dma
, 0, sizeof(lcd_dma
));
1007 spin_lock_init(&lcd_dma
.lock
);
1008 spin_lock_init(&dma_chan_lock
);
1009 memset(&dma_chan
, 0, sizeof(dma_chan
));
1011 for (ch
= 0; ch
< dma_chan_count
; ch
++) {
1012 dma_chan
[ch
].dev_id
= -1;
1013 dma_chan
[ch
].next_lch
= -1;
1015 if (ch
>= 6 && enable_1510_mode
)
1018 /* request_irq() doesn't like dev_id (ie. ch) being zero,
1019 * so we have to kludge around this. */
1020 r
= request_irq(dma_irq
[ch
], dma_irq_handler
, 0, "DMA",
1025 printk(KERN_ERR
"unable to request IRQ %d for DMA (error %d)\n",
1027 for (i
= 0; i
< ch
; i
++)
1028 free_irq(dma_irq
[i
], (void *) (i
+ 1));
1032 r
= request_irq(INT_DMA_LCD
, lcd_dma_irq_handler
, 0, "LCD DMA", NULL
);
1036 printk(KERN_ERR
"unable to request IRQ for LCD DMA (error %d)\n", r
);
1037 for (i
= 0; i
< dma_chan_count
; i
++)
1038 free_irq(dma_irq
[i
], (void *) (i
+ 1));
1044 arch_initcall(omap_init_dma
);
1047 EXPORT_SYMBOL(omap_get_dma_src_pos
);
1048 EXPORT_SYMBOL(omap_get_dma_dst_pos
);
1049 EXPORT_SYMBOL(omap_clear_dma
);
1050 EXPORT_SYMBOL(omap_set_dma_priority
);
1051 EXPORT_SYMBOL(omap_request_dma
);
1052 EXPORT_SYMBOL(omap_free_dma
);
1053 EXPORT_SYMBOL(omap_start_dma
);
1054 EXPORT_SYMBOL(omap_stop_dma
);
1055 EXPORT_SYMBOL(omap_enable_dma_irq
);
1056 EXPORT_SYMBOL(omap_disable_dma_irq
);
1058 EXPORT_SYMBOL(omap_set_dma_transfer_params
);
1059 EXPORT_SYMBOL(omap_set_dma_color_mode
);
1061 EXPORT_SYMBOL(omap_set_dma_src_params
);
1062 EXPORT_SYMBOL(omap_set_dma_src_index
);
1063 EXPORT_SYMBOL(omap_set_dma_src_data_pack
);
1064 EXPORT_SYMBOL(omap_set_dma_src_burst_mode
);
1066 EXPORT_SYMBOL(omap_set_dma_dest_params
);
1067 EXPORT_SYMBOL(omap_set_dma_dest_index
);
1068 EXPORT_SYMBOL(omap_set_dma_dest_data_pack
);
1069 EXPORT_SYMBOL(omap_set_dma_dest_burst_mode
);
1071 EXPORT_SYMBOL(omap_dma_link_lch
);
1072 EXPORT_SYMBOL(omap_dma_unlink_lch
);
1074 EXPORT_SYMBOL(omap_request_lcd_dma
);
1075 EXPORT_SYMBOL(omap_free_lcd_dma
);
1076 EXPORT_SYMBOL(omap_enable_lcd_dma
);
1077 EXPORT_SYMBOL(omap_setup_lcd_dma
);
1078 EXPORT_SYMBOL(omap_stop_lcd_dma
);
1079 EXPORT_SYMBOL(omap_set_lcd_dma_b1
);
1080 EXPORT_SYMBOL(omap_set_lcd_dma_single_transfer
);
1081 EXPORT_SYMBOL(omap_set_lcd_dma_ext_controller
);
1082 EXPORT_SYMBOL(omap_set_lcd_dma_b1_rotation
);
1083 EXPORT_SYMBOL(omap_set_lcd_dma_b1_vxres
);
1084 EXPORT_SYMBOL(omap_set_lcd_dma_b1_scale
);
1085 EXPORT_SYMBOL(omap_set_lcd_dma_b1_mirror
);