2 * linux/arch/arm/plat-omap/dma.c
4 * Copyright (C) 2003 - 2008 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 * OMAP2/3 support Copyright (C) 2004-2007 Texas Instruments, Inc.
10 * Merged to support both OMAP1 and OMAP2 by Tony Lindgren <tony@atomide.com>
11 * Some functions based on earlier dma-omap.c Copyright (C) 2001 RidgeRun, Inc.
13 * Copyright (C) 2009 Texas Instruments
14 * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com>
16 * Support functions for the OMAP internal DMA channels.
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License version 2 as
20 * published by the Free Software Foundation.
24 #include <linux/module.h>
25 #include <linux/init.h>
26 #include <linux/sched.h>
27 #include <linux/spinlock.h>
28 #include <linux/errno.h>
29 #include <linux/interrupt.h>
30 #include <linux/irq.h>
33 #include <asm/system.h>
34 #include <mach/hardware.h>
41 #ifndef CONFIG_ARCH_OMAP1
42 enum { DMA_CH_ALLOC_DONE
, DMA_CH_PARAMS_SET_DONE
, DMA_CH_STARTED
,
43 DMA_CH_QUEUED
, DMA_CH_NOTSTARTED
, DMA_CH_PAUSED
, DMA_CH_LINK_ENABLED
46 enum { DMA_CHAIN_STARTED
, DMA_CHAIN_NOTSTARTED
};
49 #define OMAP_DMA_ACTIVE 0x01
50 #define OMAP_DMA_CCR_EN (1 << 7)
51 #define OMAP2_DMA_CSR_CLEAR_MASK 0xffe
53 #define OMAP_FUNC_MUX_ARM_BASE (0xfffe1000 + 0xec)
55 static int enable_1510_mode
;
63 void (*callback
)(int lch
, u16 ch_status
, void *data
);
66 #ifndef CONFIG_ARCH_OMAP1
67 /* required for Dynamic chaining */
78 struct dma_link_info
{
80 int no_of_lchs_linked
;
91 static struct dma_link_info
*dma_linked_lch
;
93 #ifndef CONFIG_ARCH_OMAP1
95 /* Chain handling macros */
96 #define OMAP_DMA_CHAIN_QINIT(chain_id) \
98 dma_linked_lch[chain_id].q_head = \
99 dma_linked_lch[chain_id].q_tail = \
100 dma_linked_lch[chain_id].q_count = 0; \
102 #define OMAP_DMA_CHAIN_QFULL(chain_id) \
103 (dma_linked_lch[chain_id].no_of_lchs_linked == \
104 dma_linked_lch[chain_id].q_count)
105 #define OMAP_DMA_CHAIN_QLAST(chain_id) \
107 ((dma_linked_lch[chain_id].no_of_lchs_linked-1) == \
108 dma_linked_lch[chain_id].q_count) \
110 #define OMAP_DMA_CHAIN_QEMPTY(chain_id) \
111 (0 == dma_linked_lch[chain_id].q_count)
112 #define __OMAP_DMA_CHAIN_INCQ(end) \
113 ((end) = ((end)+1) % dma_linked_lch[chain_id].no_of_lchs_linked)
114 #define OMAP_DMA_CHAIN_INCQHEAD(chain_id) \
116 __OMAP_DMA_CHAIN_INCQ(dma_linked_lch[chain_id].q_head); \
117 dma_linked_lch[chain_id].q_count--; \
120 #define OMAP_DMA_CHAIN_INCQTAIL(chain_id) \
122 __OMAP_DMA_CHAIN_INCQ(dma_linked_lch[chain_id].q_tail); \
123 dma_linked_lch[chain_id].q_count++; \
127 static int dma_lch_count
;
128 static int dma_chan_count
;
129 static int omap_dma_reserve_channels
;
131 static spinlock_t dma_chan_lock
;
132 static struct omap_dma_lch
*dma_chan
;
133 static void __iomem
*omap_dma_base
;
135 static const u8 omap1_dma_irq
[OMAP1_LOGICAL_DMA_CH_COUNT
] = {
136 INT_DMA_CH0_6
, INT_DMA_CH1_7
, INT_DMA_CH2_8
, INT_DMA_CH3
,
137 INT_DMA_CH4
, INT_DMA_CH5
, INT_1610_DMA_CH6
, INT_1610_DMA_CH7
,
138 INT_1610_DMA_CH8
, INT_1610_DMA_CH9
, INT_1610_DMA_CH10
,
139 INT_1610_DMA_CH11
, INT_1610_DMA_CH12
, INT_1610_DMA_CH13
,
140 INT_1610_DMA_CH14
, INT_1610_DMA_CH15
, INT_DMA_LCD
143 static inline void disable_lnk(int lch
);
144 static void omap_disable_channel_irq(int lch
);
145 static inline void omap_enable_channel_irq(int lch
);
147 #define REVISIT_24XX() printk(KERN_ERR "FIXME: no %s on 24xx\n", \
150 #define dma_read(reg) \
153 if (cpu_class_is_omap1()) \
154 __val = __raw_readw(omap_dma_base + OMAP1_DMA_##reg); \
156 __val = __raw_readl(omap_dma_base + OMAP_DMA4_##reg); \
160 #define dma_write(val, reg) \
162 if (cpu_class_is_omap1()) \
163 __raw_writew((u16)(val), omap_dma_base + OMAP1_DMA_##reg); \
165 __raw_writel((val), omap_dma_base + OMAP_DMA4_##reg); \
168 #ifdef CONFIG_ARCH_OMAP15XX
169 /* Returns 1 if the DMA module is in OMAP1510-compatible mode, 0 otherwise */
170 int omap_dma_in_1510_mode(void)
172 return enable_1510_mode
;
175 #define omap_dma_in_1510_mode() 0
178 #ifdef CONFIG_ARCH_OMAP1
179 static inline int get_gdma_dev(int req
)
181 u32 reg
= OMAP_FUNC_MUX_ARM_BASE
+ ((req
- 1) / 5) * 4;
182 int shift
= ((req
- 1) % 5) * 6;
184 return ((omap_readl(reg
) >> shift
) & 0x3f) + 1;
187 static inline void set_gdma_dev(int req
, int dev
)
189 u32 reg
= OMAP_FUNC_MUX_ARM_BASE
+ ((req
- 1) / 5) * 4;
190 int shift
= ((req
- 1) % 5) * 6;
194 l
&= ~(0x3f << shift
);
195 l
|= (dev
- 1) << shift
;
199 #define set_gdma_dev(req, dev) do {} while (0)
203 static void clear_lch_regs(int lch
)
206 void __iomem
*lch_base
= omap_dma_base
+ OMAP1_DMA_CH_BASE(lch
);
208 for (i
= 0; i
< 0x2c; i
+= 2)
209 __raw_writew(0, lch_base
+ i
);
212 void omap_set_dma_priority(int lch
, int dst_port
, int priority
)
217 if (cpu_class_is_omap1()) {
219 case OMAP_DMA_PORT_OCP_T1
: /* FFFECC00 */
220 reg
= OMAP_TC_OCPT1_PRIOR
;
222 case OMAP_DMA_PORT_OCP_T2
: /* FFFECCD0 */
223 reg
= OMAP_TC_OCPT2_PRIOR
;
225 case OMAP_DMA_PORT_EMIFF
: /* FFFECC08 */
226 reg
= OMAP_TC_EMIFF_PRIOR
;
228 case OMAP_DMA_PORT_EMIFS
: /* FFFECC04 */
229 reg
= OMAP_TC_EMIFS_PRIOR
;
237 l
|= (priority
& 0xf) << 8;
241 if (cpu_class_is_omap2()) {
244 ccr
= dma_read(CCR(lch
));
249 dma_write(ccr
, CCR(lch
));
252 EXPORT_SYMBOL(omap_set_dma_priority
);
254 void omap_set_dma_transfer_params(int lch
, int data_type
, int elem_count
,
255 int frame_count
, int sync_mode
,
256 int dma_trigger
, int src_or_dst_synch
)
260 l
= dma_read(CSDP(lch
));
263 dma_write(l
, CSDP(lch
));
265 if (cpu_class_is_omap1()) {
268 ccr
= dma_read(CCR(lch
));
270 if (sync_mode
== OMAP_DMA_SYNC_FRAME
)
272 dma_write(ccr
, CCR(lch
));
274 ccr
= dma_read(CCR2(lch
));
276 if (sync_mode
== OMAP_DMA_SYNC_BLOCK
)
278 dma_write(ccr
, CCR2(lch
));
281 if (cpu_class_is_omap2() && dma_trigger
) {
284 val
= dma_read(CCR(lch
));
286 /* DMA_SYNCHRO_CONTROL_UPPER depends on the channel number */
287 val
&= ~((3 << 19) | 0x1f);
288 val
|= (dma_trigger
& ~0x1f) << 14;
289 val
|= dma_trigger
& 0x1f;
291 if (sync_mode
& OMAP_DMA_SYNC_FRAME
)
296 if (sync_mode
& OMAP_DMA_SYNC_BLOCK
)
301 if (src_or_dst_synch
)
302 val
|= 1 << 24; /* source synch */
304 val
&= ~(1 << 24); /* dest synch */
306 dma_write(val
, CCR(lch
));
309 dma_write(elem_count
, CEN(lch
));
310 dma_write(frame_count
, CFN(lch
));
312 EXPORT_SYMBOL(omap_set_dma_transfer_params
);
314 void omap_set_dma_color_mode(int lch
, enum omap_dma_color_mode mode
, u32 color
)
316 BUG_ON(omap_dma_in_1510_mode());
318 if (cpu_class_is_omap1()) {
321 w
= dma_read(CCR2(lch
));
325 case OMAP_DMA_CONSTANT_FILL
:
328 case OMAP_DMA_TRANSPARENT_COPY
:
331 case OMAP_DMA_COLOR_DIS
:
336 dma_write(w
, CCR2(lch
));
338 w
= dma_read(LCH_CTRL(lch
));
340 /* Default is channel type 2D */
342 dma_write((u16
)color
, COLOR_L(lch
));
343 dma_write((u16
)(color
>> 16), COLOR_U(lch
));
344 w
|= 1; /* Channel type G */
346 dma_write(w
, LCH_CTRL(lch
));
349 if (cpu_class_is_omap2()) {
352 val
= dma_read(CCR(lch
));
353 val
&= ~((1 << 17) | (1 << 16));
356 case OMAP_DMA_CONSTANT_FILL
:
359 case OMAP_DMA_TRANSPARENT_COPY
:
362 case OMAP_DMA_COLOR_DIS
:
367 dma_write(val
, CCR(lch
));
370 dma_write(color
, COLOR(lch
));
373 EXPORT_SYMBOL(omap_set_dma_color_mode
);
375 void omap_set_dma_write_mode(int lch
, enum omap_dma_write_mode mode
)
377 if (cpu_class_is_omap2()) {
380 csdp
= dma_read(CSDP(lch
));
381 csdp
&= ~(0x3 << 16);
382 csdp
|= (mode
<< 16);
383 dma_write(csdp
, CSDP(lch
));
386 EXPORT_SYMBOL(omap_set_dma_write_mode
);
388 void omap_set_dma_channel_mode(int lch
, enum omap_dma_channel_mode mode
)
390 if (cpu_class_is_omap1() && !cpu_is_omap15xx()) {
393 l
= dma_read(LCH_CTRL(lch
));
396 dma_write(l
, LCH_CTRL(lch
));
399 EXPORT_SYMBOL(omap_set_dma_channel_mode
);
401 /* Note that src_port is only for omap1 */
402 void omap_set_dma_src_params(int lch
, int src_port
, int src_amode
,
403 unsigned long src_start
,
404 int src_ei
, int src_fi
)
408 if (cpu_class_is_omap1()) {
411 w
= dma_read(CSDP(lch
));
414 dma_write(w
, CSDP(lch
));
417 l
= dma_read(CCR(lch
));
419 l
|= src_amode
<< 12;
420 dma_write(l
, CCR(lch
));
422 if (cpu_class_is_omap1()) {
423 dma_write(src_start
>> 16, CSSA_U(lch
));
424 dma_write((u16
)src_start
, CSSA_L(lch
));
427 if (cpu_class_is_omap2())
428 dma_write(src_start
, CSSA(lch
));
430 dma_write(src_ei
, CSEI(lch
));
431 dma_write(src_fi
, CSFI(lch
));
433 EXPORT_SYMBOL(omap_set_dma_src_params
);
435 void omap_set_dma_params(int lch
, struct omap_dma_channel_params
*params
)
437 omap_set_dma_transfer_params(lch
, params
->data_type
,
438 params
->elem_count
, params
->frame_count
,
439 params
->sync_mode
, params
->trigger
,
440 params
->src_or_dst_synch
);
441 omap_set_dma_src_params(lch
, params
->src_port
,
442 params
->src_amode
, params
->src_start
,
443 params
->src_ei
, params
->src_fi
);
445 omap_set_dma_dest_params(lch
, params
->dst_port
,
446 params
->dst_amode
, params
->dst_start
,
447 params
->dst_ei
, params
->dst_fi
);
448 if (params
->read_prio
|| params
->write_prio
)
449 omap_dma_set_prio_lch(lch
, params
->read_prio
,
452 EXPORT_SYMBOL(omap_set_dma_params
);
454 void omap_set_dma_src_index(int lch
, int eidx
, int fidx
)
456 if (cpu_class_is_omap2())
459 dma_write(eidx
, CSEI(lch
));
460 dma_write(fidx
, CSFI(lch
));
462 EXPORT_SYMBOL(omap_set_dma_src_index
);
464 void omap_set_dma_src_data_pack(int lch
, int enable
)
468 l
= dma_read(CSDP(lch
));
472 dma_write(l
, CSDP(lch
));
474 EXPORT_SYMBOL(omap_set_dma_src_data_pack
);
476 void omap_set_dma_src_burst_mode(int lch
, enum omap_dma_burst_mode burst_mode
)
478 unsigned int burst
= 0;
481 l
= dma_read(CSDP(lch
));
484 switch (burst_mode
) {
485 case OMAP_DMA_DATA_BURST_DIS
:
487 case OMAP_DMA_DATA_BURST_4
:
488 if (cpu_class_is_omap2())
493 case OMAP_DMA_DATA_BURST_8
:
494 if (cpu_class_is_omap2()) {
498 /* not supported by current hardware on OMAP1
502 case OMAP_DMA_DATA_BURST_16
:
503 if (cpu_class_is_omap2()) {
507 /* OMAP1 don't support burst 16
515 dma_write(l
, CSDP(lch
));
517 EXPORT_SYMBOL(omap_set_dma_src_burst_mode
);
519 /* Note that dest_port is only for OMAP1 */
520 void omap_set_dma_dest_params(int lch
, int dest_port
, int dest_amode
,
521 unsigned long dest_start
,
522 int dst_ei
, int dst_fi
)
526 if (cpu_class_is_omap1()) {
527 l
= dma_read(CSDP(lch
));
530 dma_write(l
, CSDP(lch
));
533 l
= dma_read(CCR(lch
));
535 l
|= dest_amode
<< 14;
536 dma_write(l
, CCR(lch
));
538 if (cpu_class_is_omap1()) {
539 dma_write(dest_start
>> 16, CDSA_U(lch
));
540 dma_write(dest_start
, CDSA_L(lch
));
543 if (cpu_class_is_omap2())
544 dma_write(dest_start
, CDSA(lch
));
546 dma_write(dst_ei
, CDEI(lch
));
547 dma_write(dst_fi
, CDFI(lch
));
549 EXPORT_SYMBOL(omap_set_dma_dest_params
);
551 void omap_set_dma_dest_index(int lch
, int eidx
, int fidx
)
553 if (cpu_class_is_omap2())
556 dma_write(eidx
, CDEI(lch
));
557 dma_write(fidx
, CDFI(lch
));
559 EXPORT_SYMBOL(omap_set_dma_dest_index
);
561 void omap_set_dma_dest_data_pack(int lch
, int enable
)
565 l
= dma_read(CSDP(lch
));
569 dma_write(l
, CSDP(lch
));
571 EXPORT_SYMBOL(omap_set_dma_dest_data_pack
);
573 void omap_set_dma_dest_burst_mode(int lch
, enum omap_dma_burst_mode burst_mode
)
575 unsigned int burst
= 0;
578 l
= dma_read(CSDP(lch
));
581 switch (burst_mode
) {
582 case OMAP_DMA_DATA_BURST_DIS
:
584 case OMAP_DMA_DATA_BURST_4
:
585 if (cpu_class_is_omap2())
590 case OMAP_DMA_DATA_BURST_8
:
591 if (cpu_class_is_omap2())
596 case OMAP_DMA_DATA_BURST_16
:
597 if (cpu_class_is_omap2()) {
601 /* OMAP1 don't support burst 16
605 printk(KERN_ERR
"Invalid DMA burst mode\n");
610 dma_write(l
, CSDP(lch
));
612 EXPORT_SYMBOL(omap_set_dma_dest_burst_mode
);
614 static inline void omap_enable_channel_irq(int lch
)
619 if (cpu_class_is_omap1())
620 status
= dma_read(CSR(lch
));
621 else if (cpu_class_is_omap2())
622 dma_write(OMAP2_DMA_CSR_CLEAR_MASK
, CSR(lch
));
624 /* Enable some nice interrupts. */
625 dma_write(dma_chan
[lch
].enabled_irqs
, CICR(lch
));
628 static void omap_disable_channel_irq(int lch
)
630 if (cpu_class_is_omap2())
631 dma_write(0, CICR(lch
));
634 void omap_enable_dma_irq(int lch
, u16 bits
)
636 dma_chan
[lch
].enabled_irqs
|= bits
;
638 EXPORT_SYMBOL(omap_enable_dma_irq
);
640 void omap_disable_dma_irq(int lch
, u16 bits
)
642 dma_chan
[lch
].enabled_irqs
&= ~bits
;
644 EXPORT_SYMBOL(omap_disable_dma_irq
);
646 static inline void enable_lnk(int lch
)
650 l
= dma_read(CLNK_CTRL(lch
));
652 if (cpu_class_is_omap1())
655 /* Set the ENABLE_LNK bits */
656 if (dma_chan
[lch
].next_lch
!= -1)
657 l
= dma_chan
[lch
].next_lch
| (1 << 15);
659 #ifndef CONFIG_ARCH_OMAP1
660 if (cpu_class_is_omap2())
661 if (dma_chan
[lch
].next_linked_ch
!= -1)
662 l
= dma_chan
[lch
].next_linked_ch
| (1 << 15);
665 dma_write(l
, CLNK_CTRL(lch
));
668 static inline void disable_lnk(int lch
)
672 l
= dma_read(CLNK_CTRL(lch
));
674 /* Disable interrupts */
675 if (cpu_class_is_omap1()) {
676 dma_write(0, CICR(lch
));
677 /* Set the STOP_LNK bit */
681 if (cpu_class_is_omap2()) {
682 omap_disable_channel_irq(lch
);
683 /* Clear the ENABLE_LNK bit */
687 dma_write(l
, CLNK_CTRL(lch
));
688 dma_chan
[lch
].flags
&= ~OMAP_DMA_ACTIVE
;
691 static inline void omap2_enable_irq_lch(int lch
)
695 if (!cpu_class_is_omap2())
698 val
= dma_read(IRQENABLE_L0
);
700 dma_write(val
, IRQENABLE_L0
);
703 int omap_request_dma(int dev_id
, const char *dev_name
,
704 void (*callback
)(int lch
, u16 ch_status
, void *data
),
705 void *data
, int *dma_ch_out
)
707 int ch
, free_ch
= -1;
709 struct omap_dma_lch
*chan
;
711 spin_lock_irqsave(&dma_chan_lock
, flags
);
712 for (ch
= 0; ch
< dma_chan_count
; ch
++) {
713 if (free_ch
== -1 && dma_chan
[ch
].dev_id
== -1) {
720 spin_unlock_irqrestore(&dma_chan_lock
, flags
);
723 chan
= dma_chan
+ free_ch
;
724 chan
->dev_id
= dev_id
;
726 if (cpu_class_is_omap1())
727 clear_lch_regs(free_ch
);
729 if (cpu_class_is_omap2())
730 omap_clear_dma(free_ch
);
732 spin_unlock_irqrestore(&dma_chan_lock
, flags
);
734 chan
->dev_name
= dev_name
;
735 chan
->callback
= callback
;
739 #ifndef CONFIG_ARCH_OMAP1
740 if (cpu_class_is_omap2()) {
742 chan
->next_linked_ch
= -1;
746 chan
->enabled_irqs
= OMAP_DMA_DROP_IRQ
| OMAP_DMA_BLOCK_IRQ
;
748 if (cpu_class_is_omap1())
749 chan
->enabled_irqs
|= OMAP1_DMA_TOUT_IRQ
;
750 else if (cpu_class_is_omap2())
751 chan
->enabled_irqs
|= OMAP2_DMA_MISALIGNED_ERR_IRQ
|
752 OMAP2_DMA_TRANS_ERR_IRQ
;
754 if (cpu_is_omap16xx()) {
755 /* If the sync device is set, configure it dynamically. */
757 set_gdma_dev(free_ch
+ 1, dev_id
);
758 dev_id
= free_ch
+ 1;
761 * Disable the 1510 compatibility mode and set the sync device
764 dma_write(dev_id
| (1 << 10), CCR(free_ch
));
765 } else if (cpu_is_omap7xx() || cpu_is_omap15xx()) {
766 dma_write(dev_id
, CCR(free_ch
));
769 if (cpu_class_is_omap2()) {
770 omap2_enable_irq_lch(free_ch
);
771 omap_enable_channel_irq(free_ch
);
772 /* Clear the CSR register and IRQ status register */
773 dma_write(OMAP2_DMA_CSR_CLEAR_MASK
, CSR(free_ch
));
774 dma_write(1 << free_ch
, IRQSTATUS_L0
);
777 *dma_ch_out
= free_ch
;
781 EXPORT_SYMBOL(omap_request_dma
);
783 void omap_free_dma(int lch
)
787 if (dma_chan
[lch
].dev_id
== -1) {
788 pr_err("omap_dma: trying to free unallocated DMA channel %d\n",
793 if (cpu_class_is_omap1()) {
794 /* Disable all DMA interrupts for the channel. */
795 dma_write(0, CICR(lch
));
796 /* Make sure the DMA transfer is stopped. */
797 dma_write(0, CCR(lch
));
800 if (cpu_class_is_omap2()) {
802 /* Disable interrupts */
803 val
= dma_read(IRQENABLE_L0
);
805 dma_write(val
, IRQENABLE_L0
);
807 /* Clear the CSR register and IRQ status register */
808 dma_write(OMAP2_DMA_CSR_CLEAR_MASK
, CSR(lch
));
809 dma_write(1 << lch
, IRQSTATUS_L0
);
811 /* Disable all DMA interrupts for the channel. */
812 dma_write(0, CICR(lch
));
814 /* Make sure the DMA transfer is stopped. */
815 dma_write(0, CCR(lch
));
819 spin_lock_irqsave(&dma_chan_lock
, flags
);
820 dma_chan
[lch
].dev_id
= -1;
821 dma_chan
[lch
].next_lch
= -1;
822 dma_chan
[lch
].callback
= NULL
;
823 spin_unlock_irqrestore(&dma_chan_lock
, flags
);
825 EXPORT_SYMBOL(omap_free_dma
);
828 * @brief omap_dma_set_global_params : Set global priority settings for dma
831 * @param max_fifo_depth
832 * @param tparams - Number of thereads to reserve : DMA_THREAD_RESERVE_NORM
833 * DMA_THREAD_RESERVE_ONET
834 * DMA_THREAD_RESERVE_TWOT
835 * DMA_THREAD_RESERVE_THREET
838 omap_dma_set_global_params(int arb_rate
, int max_fifo_depth
, int tparams
)
842 if (!cpu_class_is_omap2()) {
843 printk(KERN_ERR
"FIXME: no %s on 15xx/16xx\n", __func__
);
850 reg
= (arb_rate
& 0xff) << 16;
851 reg
|= (0xff & max_fifo_depth
);
855 EXPORT_SYMBOL(omap_dma_set_global_params
);
858 * @brief omap_dma_set_prio_lch : Set channel wise priority settings
861 * @param read_prio - Read priority
862 * @param write_prio - Write priority
863 * Both of the above can be set with one of the following values :
864 * DMA_CH_PRIO_HIGH/DMA_CH_PRIO_LOW
867 omap_dma_set_prio_lch(int lch
, unsigned char read_prio
,
868 unsigned char write_prio
)
872 if (unlikely((lch
< 0 || lch
>= dma_lch_count
))) {
873 printk(KERN_ERR
"Invalid channel id\n");
876 l
= dma_read(CCR(lch
));
877 l
&= ~((1 << 6) | (1 << 26));
878 if (cpu_is_omap2430() || cpu_is_omap34xx() || cpu_is_omap44xx())
879 l
|= ((read_prio
& 0x1) << 6) | ((write_prio
& 0x1) << 26);
881 l
|= ((read_prio
& 0x1) << 6);
883 dma_write(l
, CCR(lch
));
887 EXPORT_SYMBOL(omap_dma_set_prio_lch
);
890 * Clears any DMA state so the DMA engine is ready to restart with new buffers
891 * through omap_start_dma(). Any buffers in flight are discarded.
893 void omap_clear_dma(int lch
)
897 local_irq_save(flags
);
899 if (cpu_class_is_omap1()) {
902 l
= dma_read(CCR(lch
));
903 l
&= ~OMAP_DMA_CCR_EN
;
904 dma_write(l
, CCR(lch
));
906 /* Clear pending interrupts */
907 l
= dma_read(CSR(lch
));
910 if (cpu_class_is_omap2()) {
912 void __iomem
*lch_base
= omap_dma_base
+ OMAP_DMA4_CH_BASE(lch
);
913 for (i
= 0; i
< 0x44; i
+= 4)
914 __raw_writel(0, lch_base
+ i
);
917 local_irq_restore(flags
);
919 EXPORT_SYMBOL(omap_clear_dma
);
921 void omap_start_dma(int lch
)
925 if (!omap_dma_in_1510_mode() && dma_chan
[lch
].next_lch
!= -1) {
926 int next_lch
, cur_lch
;
927 char dma_chan_link_map
[OMAP_DMA4_LOGICAL_DMA_CH_COUNT
];
929 dma_chan_link_map
[lch
] = 1;
930 /* Set the link register of the first channel */
933 memset(dma_chan_link_map
, 0, sizeof(dma_chan_link_map
));
934 cur_lch
= dma_chan
[lch
].next_lch
;
936 next_lch
= dma_chan
[cur_lch
].next_lch
;
938 /* The loop case: we've been here already */
939 if (dma_chan_link_map
[cur_lch
])
941 /* Mark the current channel */
942 dma_chan_link_map
[cur_lch
] = 1;
945 omap_enable_channel_irq(cur_lch
);
948 } while (next_lch
!= -1);
949 } else if (cpu_is_omap242x() ||
950 (cpu_is_omap243x() && omap_type() <= OMAP2430_REV_ES1_0
)) {
952 /* Errata: Need to write lch even if not using chaining */
953 dma_write(lch
, CLNK_CTRL(lch
));
956 omap_enable_channel_irq(lch
);
958 l
= dma_read(CCR(lch
));
961 * Errata: On ES2.0 BUFFERING disable must be set.
962 * This will always fail on ES1.0
964 if (cpu_is_omap24xx())
965 l
|= OMAP_DMA_CCR_EN
;
967 l
|= OMAP_DMA_CCR_EN
;
968 dma_write(l
, CCR(lch
));
970 dma_chan
[lch
].flags
|= OMAP_DMA_ACTIVE
;
972 EXPORT_SYMBOL(omap_start_dma
);
974 void omap_stop_dma(int lch
)
978 if (!omap_dma_in_1510_mode() && dma_chan
[lch
].next_lch
!= -1) {
979 int next_lch
, cur_lch
= lch
;
980 char dma_chan_link_map
[OMAP_DMA4_LOGICAL_DMA_CH_COUNT
];
982 memset(dma_chan_link_map
, 0, sizeof(dma_chan_link_map
));
984 /* The loop case: we've been here already */
985 if (dma_chan_link_map
[cur_lch
])
987 /* Mark the current channel */
988 dma_chan_link_map
[cur_lch
] = 1;
990 disable_lnk(cur_lch
);
992 next_lch
= dma_chan
[cur_lch
].next_lch
;
994 } while (next_lch
!= -1);
999 /* Disable all interrupts on the channel */
1000 if (cpu_class_is_omap1())
1001 dma_write(0, CICR(lch
));
1003 l
= dma_read(CCR(lch
));
1004 l
&= ~OMAP_DMA_CCR_EN
;
1005 dma_write(l
, CCR(lch
));
1007 dma_chan
[lch
].flags
&= ~OMAP_DMA_ACTIVE
;
1009 EXPORT_SYMBOL(omap_stop_dma
);
1012 * Allows changing the DMA callback function or data. This may be needed if
1013 * the driver shares a single DMA channel for multiple dma triggers.
1015 int omap_set_dma_callback(int lch
,
1016 void (*callback
)(int lch
, u16 ch_status
, void *data
),
1019 unsigned long flags
;
1024 spin_lock_irqsave(&dma_chan_lock
, flags
);
1025 if (dma_chan
[lch
].dev_id
== -1) {
1026 printk(KERN_ERR
"DMA callback for not set for free channel\n");
1027 spin_unlock_irqrestore(&dma_chan_lock
, flags
);
1030 dma_chan
[lch
].callback
= callback
;
1031 dma_chan
[lch
].data
= data
;
1032 spin_unlock_irqrestore(&dma_chan_lock
, flags
);
1036 EXPORT_SYMBOL(omap_set_dma_callback
);
1039 * Returns current physical source address for the given DMA channel.
1040 * If the channel is running the caller must disable interrupts prior calling
1041 * this function and process the returned value before re-enabling interrupt to
1042 * prevent races with the interrupt handler. Note that in continuous mode there
1043 * is a chance for CSSA_L register overflow inbetween the two reads resulting
1044 * in incorrect return value.
1046 dma_addr_t
omap_get_dma_src_pos(int lch
)
1048 dma_addr_t offset
= 0;
1050 if (cpu_is_omap15xx())
1051 offset
= dma_read(CPC(lch
));
1053 offset
= dma_read(CSAC(lch
));
1056 * omap 3.2/3.3 erratum: sometimes 0 is returned if CSAC/CDAC is
1057 * read before the DMA controller finished disabling the channel.
1059 if (!cpu_is_omap15xx() && offset
== 0)
1060 offset
= dma_read(CSAC(lch
));
1062 if (cpu_class_is_omap1())
1063 offset
|= (dma_read(CSSA_U(lch
)) << 16);
1067 EXPORT_SYMBOL(omap_get_dma_src_pos
);
1070 * Returns current physical destination address for the given DMA channel.
1071 * If the channel is running the caller must disable interrupts prior calling
1072 * this function and process the returned value before re-enabling interrupt to
1073 * prevent races with the interrupt handler. Note that in continuous mode there
1074 * is a chance for CDSA_L register overflow inbetween the two reads resulting
1075 * in incorrect return value.
1077 dma_addr_t
omap_get_dma_dst_pos(int lch
)
1079 dma_addr_t offset
= 0;
1081 if (cpu_is_omap15xx())
1082 offset
= dma_read(CPC(lch
));
1084 offset
= dma_read(CDAC(lch
));
1087 * omap 3.2/3.3 erratum: sometimes 0 is returned if CSAC/CDAC is
1088 * read before the DMA controller finished disabling the channel.
1090 if (!cpu_is_omap15xx() && offset
== 0)
1091 offset
= dma_read(CDAC(lch
));
1093 if (cpu_class_is_omap1())
1094 offset
|= (dma_read(CDSA_U(lch
)) << 16);
1098 EXPORT_SYMBOL(omap_get_dma_dst_pos
);
1100 int omap_get_dma_active_status(int lch
)
1102 return (dma_read(CCR(lch
)) & OMAP_DMA_CCR_EN
) != 0;
1104 EXPORT_SYMBOL(omap_get_dma_active_status
);
1106 int omap_dma_running(void)
1110 /* Check if LCD DMA is running */
1111 if (cpu_is_omap16xx())
1112 if (omap_readw(OMAP1610_DMA_LCD_CCR
) & OMAP_DMA_CCR_EN
)
1115 for (lch
= 0; lch
< dma_chan_count
; lch
++)
1116 if (dma_read(CCR(lch
)) & OMAP_DMA_CCR_EN
)
1123 * lch_queue DMA will start right after lch_head one is finished.
1124 * For this DMA link to start, you still need to start (see omap_start_dma)
1125 * the first one. That will fire up the entire queue.
1127 void omap_dma_link_lch(int lch_head
, int lch_queue
)
1129 if (omap_dma_in_1510_mode()) {
1130 printk(KERN_ERR
"DMA linking is not supported in 1510 mode\n");
1135 if ((dma_chan
[lch_head
].dev_id
== -1) ||
1136 (dma_chan
[lch_queue
].dev_id
== -1)) {
1137 printk(KERN_ERR
"omap_dma: trying to link "
1138 "non requested channels\n");
1142 dma_chan
[lch_head
].next_lch
= lch_queue
;
1144 EXPORT_SYMBOL(omap_dma_link_lch
);
1147 * Once the DMA queue is stopped, we can destroy it.
1149 void omap_dma_unlink_lch(int lch_head
, int lch_queue
)
1151 if (omap_dma_in_1510_mode()) {
1152 printk(KERN_ERR
"DMA linking is not supported in 1510 mode\n");
1157 if (dma_chan
[lch_head
].next_lch
!= lch_queue
||
1158 dma_chan
[lch_head
].next_lch
== -1) {
1159 printk(KERN_ERR
"omap_dma: trying to unlink "
1160 "non linked channels\n");
1164 if ((dma_chan
[lch_head
].flags
& OMAP_DMA_ACTIVE
) ||
1165 (dma_chan
[lch_head
].flags
& OMAP_DMA_ACTIVE
)) {
1166 printk(KERN_ERR
"omap_dma: You need to stop the DMA channels "
1167 "before unlinking\n");
1171 dma_chan
[lch_head
].next_lch
= -1;
1173 EXPORT_SYMBOL(omap_dma_unlink_lch
);
1175 /*----------------------------------------------------------------------------*/
1177 #ifndef CONFIG_ARCH_OMAP1
1178 /* Create chain of DMA channesls */
1179 static void create_dma_lch_chain(int lch_head
, int lch_queue
)
1183 /* Check if this is the first link in chain */
1184 if (dma_chan
[lch_head
].next_linked_ch
== -1) {
1185 dma_chan
[lch_head
].next_linked_ch
= lch_queue
;
1186 dma_chan
[lch_head
].prev_linked_ch
= lch_queue
;
1187 dma_chan
[lch_queue
].next_linked_ch
= lch_head
;
1188 dma_chan
[lch_queue
].prev_linked_ch
= lch_head
;
1191 /* a link exists, link the new channel in circular chain */
1193 dma_chan
[lch_queue
].next_linked_ch
=
1194 dma_chan
[lch_head
].next_linked_ch
;
1195 dma_chan
[lch_queue
].prev_linked_ch
= lch_head
;
1196 dma_chan
[lch_head
].next_linked_ch
= lch_queue
;
1197 dma_chan
[dma_chan
[lch_queue
].next_linked_ch
].prev_linked_ch
=
1201 l
= dma_read(CLNK_CTRL(lch_head
));
1204 dma_write(l
, CLNK_CTRL(lch_head
));
1206 l
= dma_read(CLNK_CTRL(lch_queue
));
1208 l
|= (dma_chan
[lch_queue
].next_linked_ch
);
1209 dma_write(l
, CLNK_CTRL(lch_queue
));
1213 * @brief omap_request_dma_chain : Request a chain of DMA channels
1215 * @param dev_id - Device id using the dma channel
1216 * @param dev_name - Device name
1217 * @param callback - Call back function
1219 * @no_of_chans - Number of channels requested
1220 * @chain_mode - Dynamic or static chaining : OMAP_DMA_STATIC_CHAIN
1221 * OMAP_DMA_DYNAMIC_CHAIN
1222 * @params - Channel parameters
1224 * @return - Succes : 0
1225 * Failure: -EINVAL/-ENOMEM
1227 int omap_request_dma_chain(int dev_id
, const char *dev_name
,
1228 void (*callback
) (int lch
, u16 ch_status
,
1230 int *chain_id
, int no_of_chans
, int chain_mode
,
1231 struct omap_dma_channel_params params
)
1236 /* Is the chain mode valid ? */
1237 if (chain_mode
!= OMAP_DMA_STATIC_CHAIN
1238 && chain_mode
!= OMAP_DMA_DYNAMIC_CHAIN
) {
1239 printk(KERN_ERR
"Invalid chain mode requested\n");
1243 if (unlikely((no_of_chans
< 1
1244 || no_of_chans
> dma_lch_count
))) {
1245 printk(KERN_ERR
"Invalid Number of channels requested\n");
1249 /* Allocate a queue to maintain the status of the channels
1251 channels
= kmalloc(sizeof(*channels
) * no_of_chans
, GFP_KERNEL
);
1252 if (channels
== NULL
) {
1253 printk(KERN_ERR
"omap_dma: No memory for channel queue\n");
1257 /* request and reserve DMA channels for the chain */
1258 for (i
= 0; i
< no_of_chans
; i
++) {
1259 err
= omap_request_dma(dev_id
, dev_name
,
1260 callback
, NULL
, &channels
[i
]);
1263 for (j
= 0; j
< i
; j
++)
1264 omap_free_dma(channels
[j
]);
1266 printk(KERN_ERR
"omap_dma: Request failed %d\n", err
);
1269 dma_chan
[channels
[i
]].prev_linked_ch
= -1;
1270 dma_chan
[channels
[i
]].state
= DMA_CH_NOTSTARTED
;
1273 * Allowing client drivers to set common parameters now,
1274 * so that later only relevant (src_start, dest_start
1275 * and element count) can be set
1277 omap_set_dma_params(channels
[i
], ¶ms
);
1280 *chain_id
= channels
[0];
1281 dma_linked_lch
[*chain_id
].linked_dmach_q
= channels
;
1282 dma_linked_lch
[*chain_id
].chain_mode
= chain_mode
;
1283 dma_linked_lch
[*chain_id
].chain_state
= DMA_CHAIN_NOTSTARTED
;
1284 dma_linked_lch
[*chain_id
].no_of_lchs_linked
= no_of_chans
;
1286 for (i
= 0; i
< no_of_chans
; i
++)
1287 dma_chan
[channels
[i
]].chain_id
= *chain_id
;
1289 /* Reset the Queue pointers */
1290 OMAP_DMA_CHAIN_QINIT(*chain_id
);
1292 /* Set up the chain */
1293 if (no_of_chans
== 1)
1294 create_dma_lch_chain(channels
[0], channels
[0]);
1296 for (i
= 0; i
< (no_of_chans
- 1); i
++)
1297 create_dma_lch_chain(channels
[i
], channels
[i
+ 1]);
1302 EXPORT_SYMBOL(omap_request_dma_chain
);
1305 * @brief omap_modify_dma_chain_param : Modify the chain's params - Modify the
1306 * params after setting it. Dont do this while dma is running!!
1308 * @param chain_id - Chained logical channel id.
1311 * @return - Success : 0
1314 int omap_modify_dma_chain_params(int chain_id
,
1315 struct omap_dma_channel_params params
)
1320 /* Check for input params */
1321 if (unlikely((chain_id
< 0
1322 || chain_id
>= dma_lch_count
))) {
1323 printk(KERN_ERR
"Invalid chain id\n");
1327 /* Check if the chain exists */
1328 if (dma_linked_lch
[chain_id
].linked_dmach_q
== NULL
) {
1329 printk(KERN_ERR
"Chain doesn't exists\n");
1332 channels
= dma_linked_lch
[chain_id
].linked_dmach_q
;
1334 for (i
= 0; i
< dma_linked_lch
[chain_id
].no_of_lchs_linked
; i
++) {
1336 * Allowing client drivers to set common parameters now,
1337 * so that later only relevant (src_start, dest_start
1338 * and element count) can be set
1340 omap_set_dma_params(channels
[i
], ¶ms
);
1345 EXPORT_SYMBOL(omap_modify_dma_chain_params
);
1348 * @brief omap_free_dma_chain - Free all the logical channels in a chain.
1352 * @return - Success : 0
1355 int omap_free_dma_chain(int chain_id
)
1360 /* Check for input params */
1361 if (unlikely((chain_id
< 0 || chain_id
>= dma_lch_count
))) {
1362 printk(KERN_ERR
"Invalid chain id\n");
1366 /* Check if the chain exists */
1367 if (dma_linked_lch
[chain_id
].linked_dmach_q
== NULL
) {
1368 printk(KERN_ERR
"Chain doesn't exists\n");
1372 channels
= dma_linked_lch
[chain_id
].linked_dmach_q
;
1373 for (i
= 0; i
< dma_linked_lch
[chain_id
].no_of_lchs_linked
; i
++) {
1374 dma_chan
[channels
[i
]].next_linked_ch
= -1;
1375 dma_chan
[channels
[i
]].prev_linked_ch
= -1;
1376 dma_chan
[channels
[i
]].chain_id
= -1;
1377 dma_chan
[channels
[i
]].state
= DMA_CH_NOTSTARTED
;
1378 omap_free_dma(channels
[i
]);
1383 dma_linked_lch
[chain_id
].linked_dmach_q
= NULL
;
1384 dma_linked_lch
[chain_id
].chain_mode
= -1;
1385 dma_linked_lch
[chain_id
].chain_state
= -1;
1389 EXPORT_SYMBOL(omap_free_dma_chain
);
1392 * @brief omap_dma_chain_status - Check if the chain is in
1393 * active / inactive state.
1396 * @return - Success : OMAP_DMA_CHAIN_ACTIVE/OMAP_DMA_CHAIN_INACTIVE
1399 int omap_dma_chain_status(int chain_id
)
1401 /* Check for input params */
1402 if (unlikely((chain_id
< 0 || chain_id
>= dma_lch_count
))) {
1403 printk(KERN_ERR
"Invalid chain id\n");
1407 /* Check if the chain exists */
1408 if (dma_linked_lch
[chain_id
].linked_dmach_q
== NULL
) {
1409 printk(KERN_ERR
"Chain doesn't exists\n");
1412 pr_debug("CHAINID=%d, qcnt=%d\n", chain_id
,
1413 dma_linked_lch
[chain_id
].q_count
);
1415 if (OMAP_DMA_CHAIN_QEMPTY(chain_id
))
1416 return OMAP_DMA_CHAIN_INACTIVE
;
1418 return OMAP_DMA_CHAIN_ACTIVE
;
1420 EXPORT_SYMBOL(omap_dma_chain_status
);
1423 * @brief omap_dma_chain_a_transfer - Get a free channel from a chain,
1424 * set the params and start the transfer.
1427 * @param src_start - buffer start address
1428 * @param dest_start - Dest address
1430 * @param frame_count
1431 * @param callbk_data - channel callback parameter data.
1433 * @return - Success : 0
1434 * Failure: -EINVAL/-EBUSY
1436 int omap_dma_chain_a_transfer(int chain_id
, int src_start
, int dest_start
,
1437 int elem_count
, int frame_count
, void *callbk_data
)
1444 * if buffer size is less than 1 then there is
1445 * no use of starting the chain
1447 if (elem_count
< 1) {
1448 printk(KERN_ERR
"Invalid buffer size\n");
1452 /* Check for input params */
1453 if (unlikely((chain_id
< 0
1454 || chain_id
>= dma_lch_count
))) {
1455 printk(KERN_ERR
"Invalid chain id\n");
1459 /* Check if the chain exists */
1460 if (dma_linked_lch
[chain_id
].linked_dmach_q
== NULL
) {
1461 printk(KERN_ERR
"Chain doesn't exist\n");
1465 /* Check if all the channels in chain are in use */
1466 if (OMAP_DMA_CHAIN_QFULL(chain_id
))
1469 /* Frame count may be negative in case of indexed transfers */
1470 channels
= dma_linked_lch
[chain_id
].linked_dmach_q
;
1472 /* Get a free channel */
1473 lch
= channels
[dma_linked_lch
[chain_id
].q_tail
];
1475 /* Store the callback data */
1476 dma_chan
[lch
].data
= callbk_data
;
1478 /* Increment the q_tail */
1479 OMAP_DMA_CHAIN_INCQTAIL(chain_id
);
1481 /* Set the params to the free channel */
1483 dma_write(src_start
, CSSA(lch
));
1484 if (dest_start
!= 0)
1485 dma_write(dest_start
, CDSA(lch
));
1487 /* Write the buffer size */
1488 dma_write(elem_count
, CEN(lch
));
1489 dma_write(frame_count
, CFN(lch
));
1492 * If the chain is dynamically linked,
1493 * then we may have to start the chain if its not active
1495 if (dma_linked_lch
[chain_id
].chain_mode
== OMAP_DMA_DYNAMIC_CHAIN
) {
1498 * In Dynamic chain, if the chain is not started,
1501 if (dma_linked_lch
[chain_id
].chain_state
==
1502 DMA_CHAIN_NOTSTARTED
) {
1503 /* Enable the link in previous channel */
1504 if (dma_chan
[dma_chan
[lch
].prev_linked_ch
].state
==
1506 enable_lnk(dma_chan
[lch
].prev_linked_ch
);
1507 dma_chan
[lch
].state
= DMA_CH_QUEUED
;
1511 * Chain is already started, make sure its active,
1512 * if not then start the chain
1517 if (dma_chan
[dma_chan
[lch
].prev_linked_ch
].state
==
1519 enable_lnk(dma_chan
[lch
].prev_linked_ch
);
1520 dma_chan
[lch
].state
= DMA_CH_QUEUED
;
1522 if (0 == ((1 << 7) & dma_read(
1523 CCR(dma_chan
[lch
].prev_linked_ch
)))) {
1524 disable_lnk(dma_chan
[lch
].
1526 pr_debug("\n prev ch is stopped\n");
1531 else if (dma_chan
[dma_chan
[lch
].prev_linked_ch
].state
1533 enable_lnk(dma_chan
[lch
].prev_linked_ch
);
1534 dma_chan
[lch
].state
= DMA_CH_QUEUED
;
1537 omap_enable_channel_irq(lch
);
1539 l
= dma_read(CCR(lch
));
1541 if ((0 == (l
& (1 << 24))))
1545 if (start_dma
== 1) {
1546 if (0 == (l
& (1 << 7))) {
1548 dma_chan
[lch
].state
= DMA_CH_STARTED
;
1549 pr_debug("starting %d\n", lch
);
1550 dma_write(l
, CCR(lch
));
1554 if (0 == (l
& (1 << 7)))
1555 dma_write(l
, CCR(lch
));
1557 dma_chan
[lch
].flags
|= OMAP_DMA_ACTIVE
;
1563 EXPORT_SYMBOL(omap_dma_chain_a_transfer
);
1566 * @brief omap_start_dma_chain_transfers - Start the chain
1570 * @return - Success : 0
1571 * Failure : -EINVAL/-EBUSY
1573 int omap_start_dma_chain_transfers(int chain_id
)
1578 if (unlikely((chain_id
< 0 || chain_id
>= dma_lch_count
))) {
1579 printk(KERN_ERR
"Invalid chain id\n");
1583 channels
= dma_linked_lch
[chain_id
].linked_dmach_q
;
1585 if (dma_linked_lch
[channels
[0]].chain_state
== DMA_CHAIN_STARTED
) {
1586 printk(KERN_ERR
"Chain is already started\n");
1590 if (dma_linked_lch
[chain_id
].chain_mode
== OMAP_DMA_STATIC_CHAIN
) {
1591 for (i
= 0; i
< dma_linked_lch
[chain_id
].no_of_lchs_linked
;
1593 enable_lnk(channels
[i
]);
1594 omap_enable_channel_irq(channels
[i
]);
1597 omap_enable_channel_irq(channels
[0]);
1600 l
= dma_read(CCR(channels
[0]));
1602 dma_linked_lch
[chain_id
].chain_state
= DMA_CHAIN_STARTED
;
1603 dma_chan
[channels
[0]].state
= DMA_CH_STARTED
;
1605 if ((0 == (l
& (1 << 24))))
1609 dma_write(l
, CCR(channels
[0]));
1611 dma_chan
[channels
[0]].flags
|= OMAP_DMA_ACTIVE
;
1615 EXPORT_SYMBOL(omap_start_dma_chain_transfers
);
1618 * @brief omap_stop_dma_chain_transfers - Stop the dma transfer of a chain.
1622 * @return - Success : 0
1625 int omap_stop_dma_chain_transfers(int chain_id
)
1631 /* Check for input params */
1632 if (unlikely((chain_id
< 0 || chain_id
>= dma_lch_count
))) {
1633 printk(KERN_ERR
"Invalid chain id\n");
1637 /* Check if the chain exists */
1638 if (dma_linked_lch
[chain_id
].linked_dmach_q
== NULL
) {
1639 printk(KERN_ERR
"Chain doesn't exists\n");
1642 channels
= dma_linked_lch
[chain_id
].linked_dmach_q
;
1646 * Special programming model needed to disable DMA before end of block
1648 sys_cf
= dma_read(OCP_SYSCONFIG
);
1650 /* Middle mode reg set no Standby */
1651 l
&= ~((1 << 12)|(1 << 13));
1652 dma_write(l
, OCP_SYSCONFIG
);
1654 for (i
= 0; i
< dma_linked_lch
[chain_id
].no_of_lchs_linked
; i
++) {
1656 /* Stop the Channel transmission */
1657 l
= dma_read(CCR(channels
[i
]));
1659 dma_write(l
, CCR(channels
[i
]));
1661 /* Disable the link in all the channels */
1662 disable_lnk(channels
[i
]);
1663 dma_chan
[channels
[i
]].state
= DMA_CH_NOTSTARTED
;
1666 dma_linked_lch
[chain_id
].chain_state
= DMA_CHAIN_NOTSTARTED
;
1668 /* Reset the Queue pointers */
1669 OMAP_DMA_CHAIN_QINIT(chain_id
);
1671 /* Errata - put in the old value */
1672 dma_write(sys_cf
, OCP_SYSCONFIG
);
1676 EXPORT_SYMBOL(omap_stop_dma_chain_transfers
);
1678 /* Get the index of the ongoing DMA in chain */
1680 * @brief omap_get_dma_chain_index - Get the element and frame index
1681 * of the ongoing DMA in chain
1684 * @param ei - Element index
1685 * @param fi - Frame index
1687 * @return - Success : 0
1690 int omap_get_dma_chain_index(int chain_id
, int *ei
, int *fi
)
1695 /* Check for input params */
1696 if (unlikely((chain_id
< 0 || chain_id
>= dma_lch_count
))) {
1697 printk(KERN_ERR
"Invalid chain id\n");
1701 /* Check if the chain exists */
1702 if (dma_linked_lch
[chain_id
].linked_dmach_q
== NULL
) {
1703 printk(KERN_ERR
"Chain doesn't exists\n");
1709 channels
= dma_linked_lch
[chain_id
].linked_dmach_q
;
1711 /* Get the current channel */
1712 lch
= channels
[dma_linked_lch
[chain_id
].q_head
];
1714 *ei
= dma_read(CCEN(lch
));
1715 *fi
= dma_read(CCFN(lch
));
1719 EXPORT_SYMBOL(omap_get_dma_chain_index
);
1722 * @brief omap_get_dma_chain_dst_pos - Get the destination position of the
1723 * ongoing DMA in chain
1727 * @return - Success : Destination position
1730 int omap_get_dma_chain_dst_pos(int chain_id
)
1735 /* Check for input params */
1736 if (unlikely((chain_id
< 0 || chain_id
>= dma_lch_count
))) {
1737 printk(KERN_ERR
"Invalid chain id\n");
1741 /* Check if the chain exists */
1742 if (dma_linked_lch
[chain_id
].linked_dmach_q
== NULL
) {
1743 printk(KERN_ERR
"Chain doesn't exists\n");
1747 channels
= dma_linked_lch
[chain_id
].linked_dmach_q
;
1749 /* Get the current channel */
1750 lch
= channels
[dma_linked_lch
[chain_id
].q_head
];
1752 return dma_read(CDAC(lch
));
1754 EXPORT_SYMBOL(omap_get_dma_chain_dst_pos
);
1757 * @brief omap_get_dma_chain_src_pos - Get the source position
1758 * of the ongoing DMA in chain
1761 * @return - Success : Destination position
1764 int omap_get_dma_chain_src_pos(int chain_id
)
1769 /* Check for input params */
1770 if (unlikely((chain_id
< 0 || chain_id
>= dma_lch_count
))) {
1771 printk(KERN_ERR
"Invalid chain id\n");
1775 /* Check if the chain exists */
1776 if (dma_linked_lch
[chain_id
].linked_dmach_q
== NULL
) {
1777 printk(KERN_ERR
"Chain doesn't exists\n");
1781 channels
= dma_linked_lch
[chain_id
].linked_dmach_q
;
1783 /* Get the current channel */
1784 lch
= channels
[dma_linked_lch
[chain_id
].q_head
];
1786 return dma_read(CSAC(lch
));
1788 EXPORT_SYMBOL(omap_get_dma_chain_src_pos
);
1789 #endif /* ifndef CONFIG_ARCH_OMAP1 */
1791 /*----------------------------------------------------------------------------*/
1793 #ifdef CONFIG_ARCH_OMAP1
1795 static int omap1_dma_handle_ch(int ch
)
1799 if (enable_1510_mode
&& ch
>= 6) {
1800 csr
= dma_chan
[ch
].saved_csr
;
1801 dma_chan
[ch
].saved_csr
= 0;
1803 csr
= dma_read(CSR(ch
));
1804 if (enable_1510_mode
&& ch
<= 2 && (csr
>> 7) != 0) {
1805 dma_chan
[ch
+ 6].saved_csr
= csr
>> 7;
1808 if ((csr
& 0x3f) == 0)
1810 if (unlikely(dma_chan
[ch
].dev_id
== -1)) {
1811 printk(KERN_WARNING
"Spurious interrupt from DMA channel "
1812 "%d (CSR %04x)\n", ch
, csr
);
1815 if (unlikely(csr
& OMAP1_DMA_TOUT_IRQ
))
1816 printk(KERN_WARNING
"DMA timeout with device %d\n",
1817 dma_chan
[ch
].dev_id
);
1818 if (unlikely(csr
& OMAP_DMA_DROP_IRQ
))
1819 printk(KERN_WARNING
"DMA synchronization event drop occurred "
1820 "with device %d\n", dma_chan
[ch
].dev_id
);
1821 if (likely(csr
& OMAP_DMA_BLOCK_IRQ
))
1822 dma_chan
[ch
].flags
&= ~OMAP_DMA_ACTIVE
;
1823 if (likely(dma_chan
[ch
].callback
!= NULL
))
1824 dma_chan
[ch
].callback(ch
, csr
, dma_chan
[ch
].data
);
1829 static irqreturn_t
omap1_dma_irq_handler(int irq
, void *dev_id
)
1831 int ch
= ((int) dev_id
) - 1;
1835 int handled_now
= 0;
1837 handled_now
+= omap1_dma_handle_ch(ch
);
1838 if (enable_1510_mode
&& dma_chan
[ch
+ 6].saved_csr
)
1839 handled_now
+= omap1_dma_handle_ch(ch
+ 6);
1842 handled
+= handled_now
;
1845 return handled
? IRQ_HANDLED
: IRQ_NONE
;
1849 #define omap1_dma_irq_handler NULL
1852 #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3) || \
1853 defined(CONFIG_ARCH_OMAP4)
1855 static int omap2_dma_handle_ch(int ch
)
1857 u32 status
= dma_read(CSR(ch
));
1860 if (printk_ratelimit())
1861 printk(KERN_WARNING
"Spurious DMA IRQ for lch %d\n",
1863 dma_write(1 << ch
, IRQSTATUS_L0
);
1866 if (unlikely(dma_chan
[ch
].dev_id
== -1)) {
1867 if (printk_ratelimit())
1868 printk(KERN_WARNING
"IRQ %04x for non-allocated DMA"
1869 "channel %d\n", status
, ch
);
1872 if (unlikely(status
& OMAP_DMA_DROP_IRQ
))
1874 "DMA synchronization event drop occurred with device "
1875 "%d\n", dma_chan
[ch
].dev_id
);
1876 if (unlikely(status
& OMAP2_DMA_TRANS_ERR_IRQ
)) {
1877 printk(KERN_INFO
"DMA transaction error with device %d\n",
1878 dma_chan
[ch
].dev_id
);
1879 if (cpu_class_is_omap2()) {
1880 /* Errata: sDMA Channel is not disabled
1881 * after a transaction error. So we explicitely
1882 * disable the channel
1886 ccr
= dma_read(CCR(ch
));
1887 ccr
&= ~OMAP_DMA_CCR_EN
;
1888 dma_write(ccr
, CCR(ch
));
1889 dma_chan
[ch
].flags
&= ~OMAP_DMA_ACTIVE
;
1892 if (unlikely(status
& OMAP2_DMA_SECURE_ERR_IRQ
))
1893 printk(KERN_INFO
"DMA secure error with device %d\n",
1894 dma_chan
[ch
].dev_id
);
1895 if (unlikely(status
& OMAP2_DMA_MISALIGNED_ERR_IRQ
))
1896 printk(KERN_INFO
"DMA misaligned error with device %d\n",
1897 dma_chan
[ch
].dev_id
);
1899 dma_write(OMAP2_DMA_CSR_CLEAR_MASK
, CSR(ch
));
1900 dma_write(1 << ch
, IRQSTATUS_L0
);
1902 /* If the ch is not chained then chain_id will be -1 */
1903 if (dma_chan
[ch
].chain_id
!= -1) {
1904 int chain_id
= dma_chan
[ch
].chain_id
;
1905 dma_chan
[ch
].state
= DMA_CH_NOTSTARTED
;
1906 if (dma_read(CLNK_CTRL(ch
)) & (1 << 15))
1907 dma_chan
[dma_chan
[ch
].next_linked_ch
].state
=
1909 if (dma_linked_lch
[chain_id
].chain_mode
==
1910 OMAP_DMA_DYNAMIC_CHAIN
)
1913 if (!OMAP_DMA_CHAIN_QEMPTY(chain_id
))
1914 OMAP_DMA_CHAIN_INCQHEAD(chain_id
);
1916 status
= dma_read(CSR(ch
));
1919 dma_write(status
, CSR(ch
));
1921 if (likely(dma_chan
[ch
].callback
!= NULL
))
1922 dma_chan
[ch
].callback(ch
, status
, dma_chan
[ch
].data
);
1927 /* STATUS register count is from 1-32 while our is 0-31 */
1928 static irqreturn_t
omap2_dma_irq_handler(int irq
, void *dev_id
)
1930 u32 val
, enable_reg
;
1933 val
= dma_read(IRQSTATUS_L0
);
1935 if (printk_ratelimit())
1936 printk(KERN_WARNING
"Spurious DMA IRQ\n");
1939 enable_reg
= dma_read(IRQENABLE_L0
);
1940 val
&= enable_reg
; /* Dispatch only relevant interrupts */
1941 for (i
= 0; i
< dma_lch_count
&& val
!= 0; i
++) {
1943 omap2_dma_handle_ch(i
);
1950 static struct irqaction omap24xx_dma_irq
= {
1952 .handler
= omap2_dma_irq_handler
,
1953 .flags
= IRQF_DISABLED
1957 static struct irqaction omap24xx_dma_irq
;
1960 /*----------------------------------------------------------------------------*/
1962 static struct lcd_dma_info
{
1965 void (*callback
)(u16 status
, void *data
);
1969 unsigned long addr
, size
;
1970 int rotate
, data_type
, xres
, yres
;
1976 int single_transfer
;
1979 void omap_set_lcd_dma_b1(unsigned long addr
, u16 fb_xres
, u16 fb_yres
,
1982 lcd_dma
.addr
= addr
;
1983 lcd_dma
.data_type
= data_type
;
1984 lcd_dma
.xres
= fb_xres
;
1985 lcd_dma
.yres
= fb_yres
;
1987 EXPORT_SYMBOL(omap_set_lcd_dma_b1
);
1989 void omap_set_lcd_dma_src_port(int port
)
1991 lcd_dma
.src_port
= port
;
1994 void omap_set_lcd_dma_ext_controller(int external
)
1996 lcd_dma
.ext_ctrl
= external
;
1998 EXPORT_SYMBOL(omap_set_lcd_dma_ext_controller
);
2000 void omap_set_lcd_dma_single_transfer(int single
)
2002 lcd_dma
.single_transfer
= single
;
2004 EXPORT_SYMBOL(omap_set_lcd_dma_single_transfer
);
2006 void omap_set_lcd_dma_b1_rotation(int rotate
)
2008 if (omap_dma_in_1510_mode()) {
2009 printk(KERN_ERR
"DMA rotation is not supported in 1510 mode\n");
2013 lcd_dma
.rotate
= rotate
;
2015 EXPORT_SYMBOL(omap_set_lcd_dma_b1_rotation
);
2017 void omap_set_lcd_dma_b1_mirror(int mirror
)
2019 if (omap_dma_in_1510_mode()) {
2020 printk(KERN_ERR
"DMA mirror is not supported in 1510 mode\n");
2023 lcd_dma
.mirror
= mirror
;
2025 EXPORT_SYMBOL(omap_set_lcd_dma_b1_mirror
);
2027 void omap_set_lcd_dma_b1_vxres(unsigned long vxres
)
2029 if (omap_dma_in_1510_mode()) {
2030 printk(KERN_ERR
"DMA virtual resulotion is not supported "
2034 lcd_dma
.vxres
= vxres
;
2036 EXPORT_SYMBOL(omap_set_lcd_dma_b1_vxres
);
2038 void omap_set_lcd_dma_b1_scale(unsigned int xscale
, unsigned int yscale
)
2040 if (omap_dma_in_1510_mode()) {
2041 printk(KERN_ERR
"DMA scale is not supported in 1510 mode\n");
2044 lcd_dma
.xscale
= xscale
;
2045 lcd_dma
.yscale
= yscale
;
2047 EXPORT_SYMBOL(omap_set_lcd_dma_b1_scale
);
2049 static void set_b1_regs(void)
2051 unsigned long top
, bottom
;
2054 unsigned long en
, fn
;
2056 unsigned long vxres
;
2057 unsigned int xscale
, yscale
;
2059 switch (lcd_dma
.data_type
) {
2060 case OMAP_DMA_DATA_TYPE_S8
:
2063 case OMAP_DMA_DATA_TYPE_S16
:
2066 case OMAP_DMA_DATA_TYPE_S32
:
2074 vxres
= lcd_dma
.vxres
? lcd_dma
.vxres
: lcd_dma
.xres
;
2075 xscale
= lcd_dma
.xscale
? lcd_dma
.xscale
: 1;
2076 yscale
= lcd_dma
.yscale
? lcd_dma
.yscale
: 1;
2077 BUG_ON(vxres
< lcd_dma
.xres
);
2079 #define PIXADDR(x, y) (lcd_dma.addr + \
2080 ((y) * vxres * yscale + (x) * xscale) * es)
2081 #define PIXSTEP(sx, sy, dx, dy) (PIXADDR(dx, dy) - PIXADDR(sx, sy) - es + 1)
2083 switch (lcd_dma
.rotate
) {
2085 if (!lcd_dma
.mirror
) {
2086 top
= PIXADDR(0, 0);
2087 bottom
= PIXADDR(lcd_dma
.xres
- 1, lcd_dma
.yres
- 1);
2088 /* 1510 DMA requires the bottom address to be 2 more
2089 * than the actual last memory access location. */
2090 if (omap_dma_in_1510_mode() &&
2091 lcd_dma
.data_type
== OMAP_DMA_DATA_TYPE_S32
)
2093 ei
= PIXSTEP(0, 0, 1, 0);
2094 fi
= PIXSTEP(lcd_dma
.xres
- 1, 0, 0, 1);
2096 top
= PIXADDR(lcd_dma
.xres
- 1, 0);
2097 bottom
= PIXADDR(0, lcd_dma
.yres
- 1);
2098 ei
= PIXSTEP(1, 0, 0, 0);
2099 fi
= PIXSTEP(0, 0, lcd_dma
.xres
- 1, 1);
2105 if (!lcd_dma
.mirror
) {
2106 top
= PIXADDR(0, lcd_dma
.yres
- 1);
2107 bottom
= PIXADDR(lcd_dma
.xres
- 1, 0);
2108 ei
= PIXSTEP(0, 1, 0, 0);
2109 fi
= PIXSTEP(0, 0, 1, lcd_dma
.yres
- 1);
2111 top
= PIXADDR(lcd_dma
.xres
- 1, lcd_dma
.yres
- 1);
2112 bottom
= PIXADDR(0, 0);
2113 ei
= PIXSTEP(0, 1, 0, 0);
2114 fi
= PIXSTEP(1, 0, 0, lcd_dma
.yres
- 1);
2120 if (!lcd_dma
.mirror
) {
2121 top
= PIXADDR(lcd_dma
.xres
- 1, lcd_dma
.yres
- 1);
2122 bottom
= PIXADDR(0, 0);
2123 ei
= PIXSTEP(1, 0, 0, 0);
2124 fi
= PIXSTEP(0, 1, lcd_dma
.xres
- 1, 0);
2126 top
= PIXADDR(0, lcd_dma
.yres
- 1);
2127 bottom
= PIXADDR(lcd_dma
.xres
- 1, 0);
2128 ei
= PIXSTEP(0, 0, 1, 0);
2129 fi
= PIXSTEP(lcd_dma
.xres
- 1, 1, 0, 0);
2135 if (!lcd_dma
.mirror
) {
2136 top
= PIXADDR(lcd_dma
.xres
- 1, 0);
2137 bottom
= PIXADDR(0, lcd_dma
.yres
- 1);
2138 ei
= PIXSTEP(0, 0, 0, 1);
2139 fi
= PIXSTEP(1, lcd_dma
.yres
- 1, 0, 0);
2141 top
= PIXADDR(0, 0);
2142 bottom
= PIXADDR(lcd_dma
.xres
- 1, lcd_dma
.yres
- 1);
2143 ei
= PIXSTEP(0, 0, 0, 1);
2144 fi
= PIXSTEP(0, lcd_dma
.yres
- 1, 1, 0);
2151 return; /* Suppress warning about uninitialized vars */
2154 if (omap_dma_in_1510_mode()) {
2155 omap_writew(top
>> 16, OMAP1510_DMA_LCD_TOP_F1_U
);
2156 omap_writew(top
, OMAP1510_DMA_LCD_TOP_F1_L
);
2157 omap_writew(bottom
>> 16, OMAP1510_DMA_LCD_BOT_F1_U
);
2158 omap_writew(bottom
, OMAP1510_DMA_LCD_BOT_F1_L
);
2164 omap_writew(top
>> 16, OMAP1610_DMA_LCD_TOP_B1_U
);
2165 omap_writew(top
, OMAP1610_DMA_LCD_TOP_B1_L
);
2166 omap_writew(bottom
>> 16, OMAP1610_DMA_LCD_BOT_B1_U
);
2167 omap_writew(bottom
, OMAP1610_DMA_LCD_BOT_B1_L
);
2169 omap_writew(en
, OMAP1610_DMA_LCD_SRC_EN_B1
);
2170 omap_writew(fn
, OMAP1610_DMA_LCD_SRC_FN_B1
);
2172 w
= omap_readw(OMAP1610_DMA_LCD_CSDP
);
2174 w
|= lcd_dma
.data_type
;
2175 omap_writew(w
, OMAP1610_DMA_LCD_CSDP
);
2177 w
= omap_readw(OMAP1610_DMA_LCD_CTRL
);
2178 /* Always set the source port as SDRAM for now*/
2180 if (lcd_dma
.callback
!= NULL
)
2181 w
|= 1 << 1; /* Block interrupt enable */
2184 omap_writew(w
, OMAP1610_DMA_LCD_CTRL
);
2186 if (!(lcd_dma
.rotate
|| lcd_dma
.mirror
||
2187 lcd_dma
.vxres
|| lcd_dma
.xscale
|| lcd_dma
.yscale
))
2190 w
= omap_readw(OMAP1610_DMA_LCD_CCR
);
2191 /* Set the double-indexed addressing mode */
2193 omap_writew(w
, OMAP1610_DMA_LCD_CCR
);
2195 omap_writew(ei
, OMAP1610_DMA_LCD_SRC_EI_B1
);
2196 omap_writew(fi
>> 16, OMAP1610_DMA_LCD_SRC_FI_B1_U
);
2197 omap_writew(fi
, OMAP1610_DMA_LCD_SRC_FI_B1_L
);
2200 static irqreturn_t
lcd_dma_irq_handler(int irq
, void *dev_id
)
2204 w
= omap_readw(OMAP1610_DMA_LCD_CTRL
);
2205 if (unlikely(!(w
& (1 << 3)))) {
2206 printk(KERN_WARNING
"Spurious LCD DMA IRQ\n");
2211 omap_writew(w
, OMAP1610_DMA_LCD_CTRL
);
2213 if (lcd_dma
.callback
!= NULL
)
2214 lcd_dma
.callback(w
, lcd_dma
.cb_data
);
2219 int omap_request_lcd_dma(void (*callback
)(u16 status
, void *data
),
2222 spin_lock_irq(&lcd_dma
.lock
);
2223 if (lcd_dma
.reserved
) {
2224 spin_unlock_irq(&lcd_dma
.lock
);
2225 printk(KERN_ERR
"LCD DMA channel already reserved\n");
2229 lcd_dma
.reserved
= 1;
2230 spin_unlock_irq(&lcd_dma
.lock
);
2231 lcd_dma
.callback
= callback
;
2232 lcd_dma
.cb_data
= data
;
2234 lcd_dma
.single_transfer
= 0;
2240 lcd_dma
.ext_ctrl
= 0;
2241 lcd_dma
.src_port
= 0;
2245 EXPORT_SYMBOL(omap_request_lcd_dma
);
2247 void omap_free_lcd_dma(void)
2249 spin_lock(&lcd_dma
.lock
);
2250 if (!lcd_dma
.reserved
) {
2251 spin_unlock(&lcd_dma
.lock
);
2252 printk(KERN_ERR
"LCD DMA is not reserved\n");
2256 if (!enable_1510_mode
)
2257 omap_writew(omap_readw(OMAP1610_DMA_LCD_CCR
) & ~1,
2258 OMAP1610_DMA_LCD_CCR
);
2259 lcd_dma
.reserved
= 0;
2260 spin_unlock(&lcd_dma
.lock
);
2262 EXPORT_SYMBOL(omap_free_lcd_dma
);
2264 void omap_enable_lcd_dma(void)
2269 * Set the Enable bit only if an external controller is
2270 * connected. Otherwise the OMAP internal controller will
2271 * start the transfer when it gets enabled.
2273 if (enable_1510_mode
|| !lcd_dma
.ext_ctrl
)
2276 w
= omap_readw(OMAP1610_DMA_LCD_CTRL
);
2278 omap_writew(w
, OMAP1610_DMA_LCD_CTRL
);
2282 w
= omap_readw(OMAP1610_DMA_LCD_CCR
);
2284 omap_writew(w
, OMAP1610_DMA_LCD_CCR
);
2286 EXPORT_SYMBOL(omap_enable_lcd_dma
);
2288 void omap_setup_lcd_dma(void)
2290 BUG_ON(lcd_dma
.active
);
2291 if (!enable_1510_mode
) {
2292 /* Set some reasonable defaults */
2293 omap_writew(0x5440, OMAP1610_DMA_LCD_CCR
);
2294 omap_writew(0x9102, OMAP1610_DMA_LCD_CSDP
);
2295 omap_writew(0x0004, OMAP1610_DMA_LCD_LCH_CTRL
);
2298 if (!enable_1510_mode
) {
2301 w
= omap_readw(OMAP1610_DMA_LCD_CCR
);
2303 * If DMA was already active set the end_prog bit to have
2304 * the programmed register set loaded into the active
2307 w
|= 1 << 11; /* End_prog */
2308 if (!lcd_dma
.single_transfer
)
2309 w
|= (3 << 8); /* Auto_init, repeat */
2310 omap_writew(w
, OMAP1610_DMA_LCD_CCR
);
2313 EXPORT_SYMBOL(omap_setup_lcd_dma
);
2315 void omap_stop_lcd_dma(void)
2320 if (enable_1510_mode
|| !lcd_dma
.ext_ctrl
)
2323 w
= omap_readw(OMAP1610_DMA_LCD_CCR
);
2325 omap_writew(w
, OMAP1610_DMA_LCD_CCR
);
2327 w
= omap_readw(OMAP1610_DMA_LCD_CTRL
);
2329 omap_writew(w
, OMAP1610_DMA_LCD_CTRL
);
2331 EXPORT_SYMBOL(omap_stop_lcd_dma
);
2333 /*----------------------------------------------------------------------------*/
2335 static int __init
omap_init_dma(void)
2339 if (cpu_class_is_omap1()) {
2340 omap_dma_base
= IO_ADDRESS(OMAP1_DMA_BASE
);
2341 dma_lch_count
= OMAP1_LOGICAL_DMA_CH_COUNT
;
2342 } else if (cpu_is_omap24xx()) {
2343 omap_dma_base
= IO_ADDRESS(OMAP24XX_DMA4_BASE
);
2344 dma_lch_count
= OMAP_DMA4_LOGICAL_DMA_CH_COUNT
;
2345 } else if (cpu_is_omap34xx()) {
2346 omap_dma_base
= IO_ADDRESS(OMAP34XX_DMA4_BASE
);
2347 dma_lch_count
= OMAP_DMA4_LOGICAL_DMA_CH_COUNT
;
2348 } else if (cpu_is_omap44xx()) {
2349 omap_dma_base
= IO_ADDRESS(OMAP44XX_DMA4_BASE
);
2350 dma_lch_count
= OMAP_DMA4_LOGICAL_DMA_CH_COUNT
;
2352 pr_err("DMA init failed for unsupported omap\n");
2356 if (cpu_class_is_omap2() && omap_dma_reserve_channels
2357 && (omap_dma_reserve_channels
<= dma_lch_count
))
2358 dma_lch_count
= omap_dma_reserve_channels
;
2360 dma_chan
= kzalloc(sizeof(struct omap_dma_lch
) * dma_lch_count
,
2365 if (cpu_class_is_omap2()) {
2366 dma_linked_lch
= kzalloc(sizeof(struct dma_link_info
) *
2367 dma_lch_count
, GFP_KERNEL
);
2368 if (!dma_linked_lch
) {
2374 if (cpu_is_omap15xx()) {
2375 printk(KERN_INFO
"DMA support for OMAP15xx initialized\n");
2377 enable_1510_mode
= 1;
2378 } else if (cpu_is_omap16xx() || cpu_is_omap7xx()) {
2379 printk(KERN_INFO
"OMAP DMA hardware version %d\n",
2381 printk(KERN_INFO
"DMA capabilities: %08x:%08x:%04x:%04x:%04x\n",
2382 (dma_read(CAPS_0_U
) << 16) |
2384 (dma_read(CAPS_1_U
) << 16) |
2386 dma_read(CAPS_2
), dma_read(CAPS_3
),
2388 if (!enable_1510_mode
) {
2391 /* Disable OMAP 3.0/3.1 compatibility mode. */
2395 dma_chan_count
= 16;
2398 if (cpu_is_omap16xx()) {
2401 /* this would prevent OMAP sleep */
2402 w
= omap_readw(OMAP1610_DMA_LCD_CTRL
);
2404 omap_writew(w
, OMAP1610_DMA_LCD_CTRL
);
2406 } else if (cpu_class_is_omap2()) {
2407 u8 revision
= dma_read(REVISION
) & 0xff;
2408 printk(KERN_INFO
"OMAP DMA hardware revision %d.%d\n",
2409 revision
>> 4, revision
& 0xf);
2410 dma_chan_count
= dma_lch_count
;
2416 spin_lock_init(&lcd_dma
.lock
);
2417 spin_lock_init(&dma_chan_lock
);
2419 for (ch
= 0; ch
< dma_chan_count
; ch
++) {
2421 dma_chan
[ch
].dev_id
= -1;
2422 dma_chan
[ch
].next_lch
= -1;
2424 if (ch
>= 6 && enable_1510_mode
)
2427 if (cpu_class_is_omap1()) {
2429 * request_irq() doesn't like dev_id (ie. ch) being
2430 * zero, so we have to kludge around this.
2432 r
= request_irq(omap1_dma_irq
[ch
],
2433 omap1_dma_irq_handler
, 0, "DMA",
2438 printk(KERN_ERR
"unable to request IRQ %d "
2439 "for DMA (error %d)\n",
2440 omap1_dma_irq
[ch
], r
);
2441 for (i
= 0; i
< ch
; i
++)
2442 free_irq(omap1_dma_irq
[i
],
2449 if (cpu_is_omap2430() || cpu_is_omap34xx() || cpu_is_omap44xx())
2450 omap_dma_set_global_params(DMA_DEFAULT_ARB_RATE
,
2451 DMA_DEFAULT_FIFO_DEPTH
, 0);
2453 if (cpu_class_is_omap2()) {
2455 if (cpu_is_omap44xx())
2456 irq
= INT_44XX_SDMA_IRQ0
;
2458 irq
= INT_24XX_SDMA_IRQ0
;
2459 setup_irq(irq
, &omap24xx_dma_irq
);
2462 /* Enable smartidle idlemodes and autoidle */
2463 if (cpu_is_omap34xx()) {
2464 u32 v
= dma_read(OCP_SYSCONFIG
);
2465 v
&= ~(DMA_SYSCONFIG_MIDLEMODE_MASK
|
2466 DMA_SYSCONFIG_SIDLEMODE_MASK
|
2467 DMA_SYSCONFIG_AUTOIDLE
);
2468 v
|= (DMA_SYSCONFIG_MIDLEMODE(DMA_IDLEMODE_SMARTIDLE
) |
2469 DMA_SYSCONFIG_SIDLEMODE(DMA_IDLEMODE_SMARTIDLE
) |
2470 DMA_SYSCONFIG_AUTOIDLE
);
2471 dma_write(v
, OCP_SYSCONFIG
);
2475 /* FIXME: Update LCD DMA to work on 24xx */
2476 if (cpu_class_is_omap1()) {
2477 r
= request_irq(INT_DMA_LCD
, lcd_dma_irq_handler
, 0,
2482 printk(KERN_ERR
"unable to request IRQ for LCD DMA "
2484 for (i
= 0; i
< dma_chan_count
; i
++)
2485 free_irq(omap1_dma_irq
[i
], (void *) (i
+ 1));
2493 arch_initcall(omap_init_dma
);
2496 * Reserve the omap SDMA channels using cmdline bootarg
2497 * "omap_dma_reserve_ch=". The valid range is 1 to 32
2499 static int __init
omap_dma_cmdline_reserve_ch(char *str
)
2501 if (get_option(&str
, &omap_dma_reserve_channels
) != 1)
2502 omap_dma_reserve_channels
= 0;
2506 __setup("omap_dma_reserve_ch=", omap_dma_cmdline_reserve_ch
);