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
;
57 static struct omap_dma_global_context_registers
{
59 u32 dma_ocp_sysconfig
;
61 } omap_dma_global_context
;
69 void (*callback
)(int lch
, u16 ch_status
, void *data
);
72 #ifndef CONFIG_ARCH_OMAP1
73 /* required for Dynamic chaining */
84 struct dma_link_info
{
86 int no_of_lchs_linked
;
97 static struct dma_link_info
*dma_linked_lch
;
99 #ifndef CONFIG_ARCH_OMAP1
101 /* Chain handling macros */
102 #define OMAP_DMA_CHAIN_QINIT(chain_id) \
104 dma_linked_lch[chain_id].q_head = \
105 dma_linked_lch[chain_id].q_tail = \
106 dma_linked_lch[chain_id].q_count = 0; \
108 #define OMAP_DMA_CHAIN_QFULL(chain_id) \
109 (dma_linked_lch[chain_id].no_of_lchs_linked == \
110 dma_linked_lch[chain_id].q_count)
111 #define OMAP_DMA_CHAIN_QLAST(chain_id) \
113 ((dma_linked_lch[chain_id].no_of_lchs_linked-1) == \
114 dma_linked_lch[chain_id].q_count) \
116 #define OMAP_DMA_CHAIN_QEMPTY(chain_id) \
117 (0 == dma_linked_lch[chain_id].q_count)
118 #define __OMAP_DMA_CHAIN_INCQ(end) \
119 ((end) = ((end)+1) % dma_linked_lch[chain_id].no_of_lchs_linked)
120 #define OMAP_DMA_CHAIN_INCQHEAD(chain_id) \
122 __OMAP_DMA_CHAIN_INCQ(dma_linked_lch[chain_id].q_head); \
123 dma_linked_lch[chain_id].q_count--; \
126 #define OMAP_DMA_CHAIN_INCQTAIL(chain_id) \
128 __OMAP_DMA_CHAIN_INCQ(dma_linked_lch[chain_id].q_tail); \
129 dma_linked_lch[chain_id].q_count++; \
133 static int dma_lch_count
;
134 static int dma_chan_count
;
135 static int omap_dma_reserve_channels
;
137 static spinlock_t dma_chan_lock
;
138 static struct omap_dma_lch
*dma_chan
;
139 static void __iomem
*omap_dma_base
;
141 static const u8 omap1_dma_irq
[OMAP1_LOGICAL_DMA_CH_COUNT
] = {
142 INT_DMA_CH0_6
, INT_DMA_CH1_7
, INT_DMA_CH2_8
, INT_DMA_CH3
,
143 INT_DMA_CH4
, INT_DMA_CH5
, INT_1610_DMA_CH6
, INT_1610_DMA_CH7
,
144 INT_1610_DMA_CH8
, INT_1610_DMA_CH9
, INT_1610_DMA_CH10
,
145 INT_1610_DMA_CH11
, INT_1610_DMA_CH12
, INT_1610_DMA_CH13
,
146 INT_1610_DMA_CH14
, INT_1610_DMA_CH15
, INT_DMA_LCD
149 static inline void disable_lnk(int lch
);
150 static void omap_disable_channel_irq(int lch
);
151 static inline void omap_enable_channel_irq(int lch
);
153 #define REVISIT_24XX() printk(KERN_ERR "FIXME: no %s on 24xx\n", \
156 #define dma_read(reg) \
159 if (cpu_class_is_omap1()) \
160 __val = __raw_readw(omap_dma_base + OMAP1_DMA_##reg); \
162 __val = __raw_readl(omap_dma_base + OMAP_DMA4_##reg); \
166 #define dma_write(val, reg) \
168 if (cpu_class_is_omap1()) \
169 __raw_writew((u16)(val), omap_dma_base + OMAP1_DMA_##reg); \
171 __raw_writel((val), omap_dma_base + OMAP_DMA4_##reg); \
174 #ifdef CONFIG_ARCH_OMAP15XX
175 /* Returns 1 if the DMA module is in OMAP1510-compatible mode, 0 otherwise */
176 int omap_dma_in_1510_mode(void)
178 return enable_1510_mode
;
181 #define omap_dma_in_1510_mode() 0
184 #ifdef CONFIG_ARCH_OMAP1
185 static inline int get_gdma_dev(int req
)
187 u32 reg
= OMAP_FUNC_MUX_ARM_BASE
+ ((req
- 1) / 5) * 4;
188 int shift
= ((req
- 1) % 5) * 6;
190 return ((omap_readl(reg
) >> shift
) & 0x3f) + 1;
193 static inline void set_gdma_dev(int req
, int dev
)
195 u32 reg
= OMAP_FUNC_MUX_ARM_BASE
+ ((req
- 1) / 5) * 4;
196 int shift
= ((req
- 1) % 5) * 6;
200 l
&= ~(0x3f << shift
);
201 l
|= (dev
- 1) << shift
;
205 #define set_gdma_dev(req, dev) do {} while (0)
209 static void clear_lch_regs(int lch
)
212 void __iomem
*lch_base
= omap_dma_base
+ OMAP1_DMA_CH_BASE(lch
);
214 for (i
= 0; i
< 0x2c; i
+= 2)
215 __raw_writew(0, lch_base
+ i
);
218 void omap_set_dma_priority(int lch
, int dst_port
, int priority
)
223 if (cpu_class_is_omap1()) {
225 case OMAP_DMA_PORT_OCP_T1
: /* FFFECC00 */
226 reg
= OMAP_TC_OCPT1_PRIOR
;
228 case OMAP_DMA_PORT_OCP_T2
: /* FFFECCD0 */
229 reg
= OMAP_TC_OCPT2_PRIOR
;
231 case OMAP_DMA_PORT_EMIFF
: /* FFFECC08 */
232 reg
= OMAP_TC_EMIFF_PRIOR
;
234 case OMAP_DMA_PORT_EMIFS
: /* FFFECC04 */
235 reg
= OMAP_TC_EMIFS_PRIOR
;
243 l
|= (priority
& 0xf) << 8;
247 if (cpu_class_is_omap2()) {
250 ccr
= dma_read(CCR(lch
));
255 dma_write(ccr
, CCR(lch
));
258 EXPORT_SYMBOL(omap_set_dma_priority
);
260 void omap_set_dma_transfer_params(int lch
, int data_type
, int elem_count
,
261 int frame_count
, int sync_mode
,
262 int dma_trigger
, int src_or_dst_synch
)
266 l
= dma_read(CSDP(lch
));
269 dma_write(l
, CSDP(lch
));
271 if (cpu_class_is_omap1()) {
274 ccr
= dma_read(CCR(lch
));
276 if (sync_mode
== OMAP_DMA_SYNC_FRAME
)
278 dma_write(ccr
, CCR(lch
));
280 ccr
= dma_read(CCR2(lch
));
282 if (sync_mode
== OMAP_DMA_SYNC_BLOCK
)
284 dma_write(ccr
, CCR2(lch
));
287 if (cpu_class_is_omap2() && dma_trigger
) {
290 val
= dma_read(CCR(lch
));
292 /* DMA_SYNCHRO_CONTROL_UPPER depends on the channel number */
293 val
&= ~((3 << 19) | 0x1f);
294 val
|= (dma_trigger
& ~0x1f) << 14;
295 val
|= dma_trigger
& 0x1f;
297 if (sync_mode
& OMAP_DMA_SYNC_FRAME
)
302 if (sync_mode
& OMAP_DMA_SYNC_BLOCK
)
307 if (src_or_dst_synch
)
308 val
|= 1 << 24; /* source synch */
310 val
&= ~(1 << 24); /* dest synch */
312 dma_write(val
, CCR(lch
));
315 dma_write(elem_count
, CEN(lch
));
316 dma_write(frame_count
, CFN(lch
));
318 EXPORT_SYMBOL(omap_set_dma_transfer_params
);
320 void omap_set_dma_color_mode(int lch
, enum omap_dma_color_mode mode
, u32 color
)
322 BUG_ON(omap_dma_in_1510_mode());
324 if (cpu_class_is_omap1()) {
327 w
= dma_read(CCR2(lch
));
331 case OMAP_DMA_CONSTANT_FILL
:
334 case OMAP_DMA_TRANSPARENT_COPY
:
337 case OMAP_DMA_COLOR_DIS
:
342 dma_write(w
, CCR2(lch
));
344 w
= dma_read(LCH_CTRL(lch
));
346 /* Default is channel type 2D */
348 dma_write((u16
)color
, COLOR_L(lch
));
349 dma_write((u16
)(color
>> 16), COLOR_U(lch
));
350 w
|= 1; /* Channel type G */
352 dma_write(w
, LCH_CTRL(lch
));
355 if (cpu_class_is_omap2()) {
358 val
= dma_read(CCR(lch
));
359 val
&= ~((1 << 17) | (1 << 16));
362 case OMAP_DMA_CONSTANT_FILL
:
365 case OMAP_DMA_TRANSPARENT_COPY
:
368 case OMAP_DMA_COLOR_DIS
:
373 dma_write(val
, CCR(lch
));
376 dma_write(color
, COLOR(lch
));
379 EXPORT_SYMBOL(omap_set_dma_color_mode
);
381 void omap_set_dma_write_mode(int lch
, enum omap_dma_write_mode mode
)
383 if (cpu_class_is_omap2()) {
386 csdp
= dma_read(CSDP(lch
));
387 csdp
&= ~(0x3 << 16);
388 csdp
|= (mode
<< 16);
389 dma_write(csdp
, CSDP(lch
));
392 EXPORT_SYMBOL(omap_set_dma_write_mode
);
394 void omap_set_dma_channel_mode(int lch
, enum omap_dma_channel_mode mode
)
396 if (cpu_class_is_omap1() && !cpu_is_omap15xx()) {
399 l
= dma_read(LCH_CTRL(lch
));
402 dma_write(l
, LCH_CTRL(lch
));
405 EXPORT_SYMBOL(omap_set_dma_channel_mode
);
407 /* Note that src_port is only for omap1 */
408 void omap_set_dma_src_params(int lch
, int src_port
, int src_amode
,
409 unsigned long src_start
,
410 int src_ei
, int src_fi
)
414 if (cpu_class_is_omap1()) {
417 w
= dma_read(CSDP(lch
));
420 dma_write(w
, CSDP(lch
));
423 l
= dma_read(CCR(lch
));
425 l
|= src_amode
<< 12;
426 dma_write(l
, CCR(lch
));
428 if (cpu_class_is_omap1()) {
429 dma_write(src_start
>> 16, CSSA_U(lch
));
430 dma_write((u16
)src_start
, CSSA_L(lch
));
433 if (cpu_class_is_omap2())
434 dma_write(src_start
, CSSA(lch
));
436 dma_write(src_ei
, CSEI(lch
));
437 dma_write(src_fi
, CSFI(lch
));
439 EXPORT_SYMBOL(omap_set_dma_src_params
);
441 void omap_set_dma_params(int lch
, struct omap_dma_channel_params
*params
)
443 omap_set_dma_transfer_params(lch
, params
->data_type
,
444 params
->elem_count
, params
->frame_count
,
445 params
->sync_mode
, params
->trigger
,
446 params
->src_or_dst_synch
);
447 omap_set_dma_src_params(lch
, params
->src_port
,
448 params
->src_amode
, params
->src_start
,
449 params
->src_ei
, params
->src_fi
);
451 omap_set_dma_dest_params(lch
, params
->dst_port
,
452 params
->dst_amode
, params
->dst_start
,
453 params
->dst_ei
, params
->dst_fi
);
454 if (params
->read_prio
|| params
->write_prio
)
455 omap_dma_set_prio_lch(lch
, params
->read_prio
,
458 EXPORT_SYMBOL(omap_set_dma_params
);
460 void omap_set_dma_src_index(int lch
, int eidx
, int fidx
)
462 if (cpu_class_is_omap2())
465 dma_write(eidx
, CSEI(lch
));
466 dma_write(fidx
, CSFI(lch
));
468 EXPORT_SYMBOL(omap_set_dma_src_index
);
470 void omap_set_dma_src_data_pack(int lch
, int enable
)
474 l
= dma_read(CSDP(lch
));
478 dma_write(l
, CSDP(lch
));
480 EXPORT_SYMBOL(omap_set_dma_src_data_pack
);
482 void omap_set_dma_src_burst_mode(int lch
, enum omap_dma_burst_mode burst_mode
)
484 unsigned int burst
= 0;
487 l
= dma_read(CSDP(lch
));
490 switch (burst_mode
) {
491 case OMAP_DMA_DATA_BURST_DIS
:
493 case OMAP_DMA_DATA_BURST_4
:
494 if (cpu_class_is_omap2())
499 case OMAP_DMA_DATA_BURST_8
:
500 if (cpu_class_is_omap2()) {
504 /* not supported by current hardware on OMAP1
508 case OMAP_DMA_DATA_BURST_16
:
509 if (cpu_class_is_omap2()) {
513 /* OMAP1 don't support burst 16
521 dma_write(l
, CSDP(lch
));
523 EXPORT_SYMBOL(omap_set_dma_src_burst_mode
);
525 /* Note that dest_port is only for OMAP1 */
526 void omap_set_dma_dest_params(int lch
, int dest_port
, int dest_amode
,
527 unsigned long dest_start
,
528 int dst_ei
, int dst_fi
)
532 if (cpu_class_is_omap1()) {
533 l
= dma_read(CSDP(lch
));
536 dma_write(l
, CSDP(lch
));
539 l
= dma_read(CCR(lch
));
541 l
|= dest_amode
<< 14;
542 dma_write(l
, CCR(lch
));
544 if (cpu_class_is_omap1()) {
545 dma_write(dest_start
>> 16, CDSA_U(lch
));
546 dma_write(dest_start
, CDSA_L(lch
));
549 if (cpu_class_is_omap2())
550 dma_write(dest_start
, CDSA(lch
));
552 dma_write(dst_ei
, CDEI(lch
));
553 dma_write(dst_fi
, CDFI(lch
));
555 EXPORT_SYMBOL(omap_set_dma_dest_params
);
557 void omap_set_dma_dest_index(int lch
, int eidx
, int fidx
)
559 if (cpu_class_is_omap2())
562 dma_write(eidx
, CDEI(lch
));
563 dma_write(fidx
, CDFI(lch
));
565 EXPORT_SYMBOL(omap_set_dma_dest_index
);
567 void omap_set_dma_dest_data_pack(int lch
, int enable
)
571 l
= dma_read(CSDP(lch
));
575 dma_write(l
, CSDP(lch
));
577 EXPORT_SYMBOL(omap_set_dma_dest_data_pack
);
579 void omap_set_dma_dest_burst_mode(int lch
, enum omap_dma_burst_mode burst_mode
)
581 unsigned int burst
= 0;
584 l
= dma_read(CSDP(lch
));
587 switch (burst_mode
) {
588 case OMAP_DMA_DATA_BURST_DIS
:
590 case OMAP_DMA_DATA_BURST_4
:
591 if (cpu_class_is_omap2())
596 case OMAP_DMA_DATA_BURST_8
:
597 if (cpu_class_is_omap2())
602 case OMAP_DMA_DATA_BURST_16
:
603 if (cpu_class_is_omap2()) {
607 /* OMAP1 don't support burst 16
611 printk(KERN_ERR
"Invalid DMA burst mode\n");
616 dma_write(l
, CSDP(lch
));
618 EXPORT_SYMBOL(omap_set_dma_dest_burst_mode
);
620 static inline void omap_enable_channel_irq(int lch
)
625 if (cpu_class_is_omap1())
626 status
= dma_read(CSR(lch
));
627 else if (cpu_class_is_omap2())
628 dma_write(OMAP2_DMA_CSR_CLEAR_MASK
, CSR(lch
));
630 /* Enable some nice interrupts. */
631 dma_write(dma_chan
[lch
].enabled_irqs
, CICR(lch
));
634 static void omap_disable_channel_irq(int lch
)
636 if (cpu_class_is_omap2())
637 dma_write(0, CICR(lch
));
640 void omap_enable_dma_irq(int lch
, u16 bits
)
642 dma_chan
[lch
].enabled_irqs
|= bits
;
644 EXPORT_SYMBOL(omap_enable_dma_irq
);
646 void omap_disable_dma_irq(int lch
, u16 bits
)
648 dma_chan
[lch
].enabled_irqs
&= ~bits
;
650 EXPORT_SYMBOL(omap_disable_dma_irq
);
652 static inline void enable_lnk(int lch
)
656 l
= dma_read(CLNK_CTRL(lch
));
658 if (cpu_class_is_omap1())
661 /* Set the ENABLE_LNK bits */
662 if (dma_chan
[lch
].next_lch
!= -1)
663 l
= dma_chan
[lch
].next_lch
| (1 << 15);
665 #ifndef CONFIG_ARCH_OMAP1
666 if (cpu_class_is_omap2())
667 if (dma_chan
[lch
].next_linked_ch
!= -1)
668 l
= dma_chan
[lch
].next_linked_ch
| (1 << 15);
671 dma_write(l
, CLNK_CTRL(lch
));
674 static inline void disable_lnk(int lch
)
678 l
= dma_read(CLNK_CTRL(lch
));
680 /* Disable interrupts */
681 if (cpu_class_is_omap1()) {
682 dma_write(0, CICR(lch
));
683 /* Set the STOP_LNK bit */
687 if (cpu_class_is_omap2()) {
688 omap_disable_channel_irq(lch
);
689 /* Clear the ENABLE_LNK bit */
693 dma_write(l
, CLNK_CTRL(lch
));
694 dma_chan
[lch
].flags
&= ~OMAP_DMA_ACTIVE
;
697 static inline void omap2_enable_irq_lch(int lch
)
701 if (!cpu_class_is_omap2())
704 val
= dma_read(IRQENABLE_L0
);
706 dma_write(val
, IRQENABLE_L0
);
709 int omap_request_dma(int dev_id
, const char *dev_name
,
710 void (*callback
)(int lch
, u16 ch_status
, void *data
),
711 void *data
, int *dma_ch_out
)
713 int ch
, free_ch
= -1;
715 struct omap_dma_lch
*chan
;
717 spin_lock_irqsave(&dma_chan_lock
, flags
);
718 for (ch
= 0; ch
< dma_chan_count
; ch
++) {
719 if (free_ch
== -1 && dma_chan
[ch
].dev_id
== -1) {
726 spin_unlock_irqrestore(&dma_chan_lock
, flags
);
729 chan
= dma_chan
+ free_ch
;
730 chan
->dev_id
= dev_id
;
732 if (cpu_class_is_omap1())
733 clear_lch_regs(free_ch
);
735 if (cpu_class_is_omap2())
736 omap_clear_dma(free_ch
);
738 spin_unlock_irqrestore(&dma_chan_lock
, flags
);
740 chan
->dev_name
= dev_name
;
741 chan
->callback
= callback
;
745 #ifndef CONFIG_ARCH_OMAP1
746 if (cpu_class_is_omap2()) {
748 chan
->next_linked_ch
= -1;
752 chan
->enabled_irqs
= OMAP_DMA_DROP_IRQ
| OMAP_DMA_BLOCK_IRQ
;
754 if (cpu_class_is_omap1())
755 chan
->enabled_irqs
|= OMAP1_DMA_TOUT_IRQ
;
756 else if (cpu_class_is_omap2())
757 chan
->enabled_irqs
|= OMAP2_DMA_MISALIGNED_ERR_IRQ
|
758 OMAP2_DMA_TRANS_ERR_IRQ
;
760 if (cpu_is_omap16xx()) {
761 /* If the sync device is set, configure it dynamically. */
763 set_gdma_dev(free_ch
+ 1, dev_id
);
764 dev_id
= free_ch
+ 1;
767 * Disable the 1510 compatibility mode and set the sync device
770 dma_write(dev_id
| (1 << 10), CCR(free_ch
));
771 } else if (cpu_is_omap7xx() || cpu_is_omap15xx()) {
772 dma_write(dev_id
, CCR(free_ch
));
775 if (cpu_class_is_omap2()) {
776 omap2_enable_irq_lch(free_ch
);
777 omap_enable_channel_irq(free_ch
);
778 /* Clear the CSR register and IRQ status register */
779 dma_write(OMAP2_DMA_CSR_CLEAR_MASK
, CSR(free_ch
));
780 dma_write(1 << free_ch
, IRQSTATUS_L0
);
783 *dma_ch_out
= free_ch
;
787 EXPORT_SYMBOL(omap_request_dma
);
789 void omap_free_dma(int lch
)
793 if (dma_chan
[lch
].dev_id
== -1) {
794 pr_err("omap_dma: trying to free unallocated DMA channel %d\n",
799 if (cpu_class_is_omap1()) {
800 /* Disable all DMA interrupts for the channel. */
801 dma_write(0, CICR(lch
));
802 /* Make sure the DMA transfer is stopped. */
803 dma_write(0, CCR(lch
));
806 if (cpu_class_is_omap2()) {
808 /* Disable interrupts */
809 val
= dma_read(IRQENABLE_L0
);
811 dma_write(val
, IRQENABLE_L0
);
813 /* Clear the CSR register and IRQ status register */
814 dma_write(OMAP2_DMA_CSR_CLEAR_MASK
, CSR(lch
));
815 dma_write(1 << lch
, IRQSTATUS_L0
);
817 /* Disable all DMA interrupts for the channel. */
818 dma_write(0, CICR(lch
));
820 /* Make sure the DMA transfer is stopped. */
821 dma_write(0, CCR(lch
));
825 spin_lock_irqsave(&dma_chan_lock
, flags
);
826 dma_chan
[lch
].dev_id
= -1;
827 dma_chan
[lch
].next_lch
= -1;
828 dma_chan
[lch
].callback
= NULL
;
829 spin_unlock_irqrestore(&dma_chan_lock
, flags
);
831 EXPORT_SYMBOL(omap_free_dma
);
834 * @brief omap_dma_set_global_params : Set global priority settings for dma
837 * @param max_fifo_depth
838 * @param tparams - Number of threads to reserve : DMA_THREAD_RESERVE_NORM
839 * DMA_THREAD_RESERVE_ONET
840 * DMA_THREAD_RESERVE_TWOT
841 * DMA_THREAD_RESERVE_THREET
844 omap_dma_set_global_params(int arb_rate
, int max_fifo_depth
, int tparams
)
848 if (!cpu_class_is_omap2()) {
849 printk(KERN_ERR
"FIXME: no %s on 15xx/16xx\n", __func__
);
853 if (max_fifo_depth
== 0)
858 reg
= 0xff & max_fifo_depth
;
859 reg
|= (0x3 & tparams
) << 12;
860 reg
|= (arb_rate
& 0xff) << 16;
864 EXPORT_SYMBOL(omap_dma_set_global_params
);
867 * @brief omap_dma_set_prio_lch : Set channel wise priority settings
870 * @param read_prio - Read priority
871 * @param write_prio - Write priority
872 * Both of the above can be set with one of the following values :
873 * DMA_CH_PRIO_HIGH/DMA_CH_PRIO_LOW
876 omap_dma_set_prio_lch(int lch
, unsigned char read_prio
,
877 unsigned char write_prio
)
881 if (unlikely((lch
< 0 || lch
>= dma_lch_count
))) {
882 printk(KERN_ERR
"Invalid channel id\n");
885 l
= dma_read(CCR(lch
));
886 l
&= ~((1 << 6) | (1 << 26));
887 if (cpu_is_omap2430() || cpu_is_omap34xx() || cpu_is_omap44xx())
888 l
|= ((read_prio
& 0x1) << 6) | ((write_prio
& 0x1) << 26);
890 l
|= ((read_prio
& 0x1) << 6);
892 dma_write(l
, CCR(lch
));
896 EXPORT_SYMBOL(omap_dma_set_prio_lch
);
899 * Clears any DMA state so the DMA engine is ready to restart with new buffers
900 * through omap_start_dma(). Any buffers in flight are discarded.
902 void omap_clear_dma(int lch
)
906 local_irq_save(flags
);
908 if (cpu_class_is_omap1()) {
911 l
= dma_read(CCR(lch
));
912 l
&= ~OMAP_DMA_CCR_EN
;
913 dma_write(l
, CCR(lch
));
915 /* Clear pending interrupts */
916 l
= dma_read(CSR(lch
));
919 if (cpu_class_is_omap2()) {
921 void __iomem
*lch_base
= omap_dma_base
+ OMAP_DMA4_CH_BASE(lch
);
922 for (i
= 0; i
< 0x44; i
+= 4)
923 __raw_writel(0, lch_base
+ i
);
926 local_irq_restore(flags
);
928 EXPORT_SYMBOL(omap_clear_dma
);
930 void omap_start_dma(int lch
)
934 if (!omap_dma_in_1510_mode() && dma_chan
[lch
].next_lch
!= -1) {
935 int next_lch
, cur_lch
;
936 char dma_chan_link_map
[OMAP_DMA4_LOGICAL_DMA_CH_COUNT
];
938 dma_chan_link_map
[lch
] = 1;
939 /* Set the link register of the first channel */
942 memset(dma_chan_link_map
, 0, sizeof(dma_chan_link_map
));
943 cur_lch
= dma_chan
[lch
].next_lch
;
945 next_lch
= dma_chan
[cur_lch
].next_lch
;
947 /* The loop case: we've been here already */
948 if (dma_chan_link_map
[cur_lch
])
950 /* Mark the current channel */
951 dma_chan_link_map
[cur_lch
] = 1;
954 omap_enable_channel_irq(cur_lch
);
957 } while (next_lch
!= -1);
958 } else if (cpu_is_omap242x() ||
959 (cpu_is_omap243x() && omap_type() <= OMAP2430_REV_ES1_0
)) {
961 /* Errata: Need to write lch even if not using chaining */
962 dma_write(lch
, CLNK_CTRL(lch
));
965 omap_enable_channel_irq(lch
);
967 l
= dma_read(CCR(lch
));
970 * Errata: On ES2.0 BUFFERING disable must be set.
971 * This will always fail on ES1.0
973 if (cpu_is_omap24xx())
974 l
|= OMAP_DMA_CCR_EN
;
976 l
|= OMAP_DMA_CCR_EN
;
977 dma_write(l
, CCR(lch
));
979 dma_chan
[lch
].flags
|= OMAP_DMA_ACTIVE
;
981 EXPORT_SYMBOL(omap_start_dma
);
983 void omap_stop_dma(int lch
)
987 /* Disable all interrupts on the channel */
988 if (cpu_class_is_omap1())
989 dma_write(0, CICR(lch
));
991 l
= dma_read(CCR(lch
));
992 l
&= ~OMAP_DMA_CCR_EN
;
993 dma_write(l
, CCR(lch
));
995 if (!omap_dma_in_1510_mode() && dma_chan
[lch
].next_lch
!= -1) {
996 int next_lch
, cur_lch
= lch
;
997 char dma_chan_link_map
[OMAP_DMA4_LOGICAL_DMA_CH_COUNT
];
999 memset(dma_chan_link_map
, 0, sizeof(dma_chan_link_map
));
1001 /* The loop case: we've been here already */
1002 if (dma_chan_link_map
[cur_lch
])
1004 /* Mark the current channel */
1005 dma_chan_link_map
[cur_lch
] = 1;
1007 disable_lnk(cur_lch
);
1009 next_lch
= dma_chan
[cur_lch
].next_lch
;
1011 } while (next_lch
!= -1);
1014 dma_chan
[lch
].flags
&= ~OMAP_DMA_ACTIVE
;
1016 EXPORT_SYMBOL(omap_stop_dma
);
1019 * Allows changing the DMA callback function or data. This may be needed if
1020 * the driver shares a single DMA channel for multiple dma triggers.
1022 int omap_set_dma_callback(int lch
,
1023 void (*callback
)(int lch
, u16 ch_status
, void *data
),
1026 unsigned long flags
;
1031 spin_lock_irqsave(&dma_chan_lock
, flags
);
1032 if (dma_chan
[lch
].dev_id
== -1) {
1033 printk(KERN_ERR
"DMA callback for not set for free channel\n");
1034 spin_unlock_irqrestore(&dma_chan_lock
, flags
);
1037 dma_chan
[lch
].callback
= callback
;
1038 dma_chan
[lch
].data
= data
;
1039 spin_unlock_irqrestore(&dma_chan_lock
, flags
);
1043 EXPORT_SYMBOL(omap_set_dma_callback
);
1046 * Returns current physical source address for the given DMA channel.
1047 * If the channel is running the caller must disable interrupts prior calling
1048 * this function and process the returned value before re-enabling interrupt to
1049 * prevent races with the interrupt handler. Note that in continuous mode there
1050 * is a chance for CSSA_L register overflow inbetween the two reads resulting
1051 * in incorrect return value.
1053 dma_addr_t
omap_get_dma_src_pos(int lch
)
1055 dma_addr_t offset
= 0;
1057 if (cpu_is_omap15xx())
1058 offset
= dma_read(CPC(lch
));
1060 offset
= dma_read(CSAC(lch
));
1063 * omap 3.2/3.3 erratum: sometimes 0 is returned if CSAC/CDAC is
1064 * read before the DMA controller finished disabling the channel.
1066 if (!cpu_is_omap15xx() && offset
== 0)
1067 offset
= dma_read(CSAC(lch
));
1069 if (cpu_class_is_omap1())
1070 offset
|= (dma_read(CSSA_U(lch
)) << 16);
1074 EXPORT_SYMBOL(omap_get_dma_src_pos
);
1077 * Returns current physical destination address for the given DMA channel.
1078 * If the channel is running the caller must disable interrupts prior calling
1079 * this function and process the returned value before re-enabling interrupt to
1080 * prevent races with the interrupt handler. Note that in continuous mode there
1081 * is a chance for CDSA_L register overflow inbetween the two reads resulting
1082 * in incorrect return value.
1084 dma_addr_t
omap_get_dma_dst_pos(int lch
)
1086 dma_addr_t offset
= 0;
1088 if (cpu_is_omap15xx())
1089 offset
= dma_read(CPC(lch
));
1091 offset
= dma_read(CDAC(lch
));
1094 * omap 3.2/3.3 erratum: sometimes 0 is returned if CSAC/CDAC is
1095 * read before the DMA controller finished disabling the channel.
1097 if (!cpu_is_omap15xx() && offset
== 0)
1098 offset
= dma_read(CDAC(lch
));
1100 if (cpu_class_is_omap1())
1101 offset
|= (dma_read(CDSA_U(lch
)) << 16);
1105 EXPORT_SYMBOL(omap_get_dma_dst_pos
);
1107 int omap_get_dma_active_status(int lch
)
1109 return (dma_read(CCR(lch
)) & OMAP_DMA_CCR_EN
) != 0;
1111 EXPORT_SYMBOL(omap_get_dma_active_status
);
1113 int omap_dma_running(void)
1117 /* Check if LCD DMA is running */
1118 if (cpu_is_omap16xx())
1119 if (omap_readw(OMAP1610_DMA_LCD_CCR
) & OMAP_DMA_CCR_EN
)
1122 for (lch
= 0; lch
< dma_chan_count
; lch
++)
1123 if (dma_read(CCR(lch
)) & OMAP_DMA_CCR_EN
)
1130 * lch_queue DMA will start right after lch_head one is finished.
1131 * For this DMA link to start, you still need to start (see omap_start_dma)
1132 * the first one. That will fire up the entire queue.
1134 void omap_dma_link_lch(int lch_head
, int lch_queue
)
1136 if (omap_dma_in_1510_mode()) {
1137 if (lch_head
== lch_queue
) {
1138 dma_write(dma_read(CCR(lch_head
)) | (3 << 8),
1142 printk(KERN_ERR
"DMA linking is not supported in 1510 mode\n");
1147 if ((dma_chan
[lch_head
].dev_id
== -1) ||
1148 (dma_chan
[lch_queue
].dev_id
== -1)) {
1149 printk(KERN_ERR
"omap_dma: trying to link "
1150 "non requested channels\n");
1154 dma_chan
[lch_head
].next_lch
= lch_queue
;
1156 EXPORT_SYMBOL(omap_dma_link_lch
);
1159 * Once the DMA queue is stopped, we can destroy it.
1161 void omap_dma_unlink_lch(int lch_head
, int lch_queue
)
1163 if (omap_dma_in_1510_mode()) {
1164 if (lch_head
== lch_queue
) {
1165 dma_write(dma_read(CCR(lch_head
)) & ~(3 << 8),
1169 printk(KERN_ERR
"DMA linking is not supported in 1510 mode\n");
1174 if (dma_chan
[lch_head
].next_lch
!= lch_queue
||
1175 dma_chan
[lch_head
].next_lch
== -1) {
1176 printk(KERN_ERR
"omap_dma: trying to unlink "
1177 "non linked channels\n");
1181 if ((dma_chan
[lch_head
].flags
& OMAP_DMA_ACTIVE
) ||
1182 (dma_chan
[lch_head
].flags
& OMAP_DMA_ACTIVE
)) {
1183 printk(KERN_ERR
"omap_dma: You need to stop the DMA channels "
1184 "before unlinking\n");
1188 dma_chan
[lch_head
].next_lch
= -1;
1190 EXPORT_SYMBOL(omap_dma_unlink_lch
);
1192 /*----------------------------------------------------------------------------*/
1194 #ifndef CONFIG_ARCH_OMAP1
1195 /* Create chain of DMA channesls */
1196 static void create_dma_lch_chain(int lch_head
, int lch_queue
)
1200 /* Check if this is the first link in chain */
1201 if (dma_chan
[lch_head
].next_linked_ch
== -1) {
1202 dma_chan
[lch_head
].next_linked_ch
= lch_queue
;
1203 dma_chan
[lch_head
].prev_linked_ch
= lch_queue
;
1204 dma_chan
[lch_queue
].next_linked_ch
= lch_head
;
1205 dma_chan
[lch_queue
].prev_linked_ch
= lch_head
;
1208 /* a link exists, link the new channel in circular chain */
1210 dma_chan
[lch_queue
].next_linked_ch
=
1211 dma_chan
[lch_head
].next_linked_ch
;
1212 dma_chan
[lch_queue
].prev_linked_ch
= lch_head
;
1213 dma_chan
[lch_head
].next_linked_ch
= lch_queue
;
1214 dma_chan
[dma_chan
[lch_queue
].next_linked_ch
].prev_linked_ch
=
1218 l
= dma_read(CLNK_CTRL(lch_head
));
1221 dma_write(l
, CLNK_CTRL(lch_head
));
1223 l
= dma_read(CLNK_CTRL(lch_queue
));
1225 l
|= (dma_chan
[lch_queue
].next_linked_ch
);
1226 dma_write(l
, CLNK_CTRL(lch_queue
));
1230 * @brief omap_request_dma_chain : Request a chain of DMA channels
1232 * @param dev_id - Device id using the dma channel
1233 * @param dev_name - Device name
1234 * @param callback - Call back function
1236 * @no_of_chans - Number of channels requested
1237 * @chain_mode - Dynamic or static chaining : OMAP_DMA_STATIC_CHAIN
1238 * OMAP_DMA_DYNAMIC_CHAIN
1239 * @params - Channel parameters
1241 * @return - Succes : 0
1242 * Failure: -EINVAL/-ENOMEM
1244 int omap_request_dma_chain(int dev_id
, const char *dev_name
,
1245 void (*callback
) (int lch
, u16 ch_status
,
1247 int *chain_id
, int no_of_chans
, int chain_mode
,
1248 struct omap_dma_channel_params params
)
1253 /* Is the chain mode valid ? */
1254 if (chain_mode
!= OMAP_DMA_STATIC_CHAIN
1255 && chain_mode
!= OMAP_DMA_DYNAMIC_CHAIN
) {
1256 printk(KERN_ERR
"Invalid chain mode requested\n");
1260 if (unlikely((no_of_chans
< 1
1261 || no_of_chans
> dma_lch_count
))) {
1262 printk(KERN_ERR
"Invalid Number of channels requested\n");
1266 /* Allocate a queue to maintain the status of the channels
1268 channels
= kmalloc(sizeof(*channels
) * no_of_chans
, GFP_KERNEL
);
1269 if (channels
== NULL
) {
1270 printk(KERN_ERR
"omap_dma: No memory for channel queue\n");
1274 /* request and reserve DMA channels for the chain */
1275 for (i
= 0; i
< no_of_chans
; i
++) {
1276 err
= omap_request_dma(dev_id
, dev_name
,
1277 callback
, NULL
, &channels
[i
]);
1280 for (j
= 0; j
< i
; j
++)
1281 omap_free_dma(channels
[j
]);
1283 printk(KERN_ERR
"omap_dma: Request failed %d\n", err
);
1286 dma_chan
[channels
[i
]].prev_linked_ch
= -1;
1287 dma_chan
[channels
[i
]].state
= DMA_CH_NOTSTARTED
;
1290 * Allowing client drivers to set common parameters now,
1291 * so that later only relevant (src_start, dest_start
1292 * and element count) can be set
1294 omap_set_dma_params(channels
[i
], ¶ms
);
1297 *chain_id
= channels
[0];
1298 dma_linked_lch
[*chain_id
].linked_dmach_q
= channels
;
1299 dma_linked_lch
[*chain_id
].chain_mode
= chain_mode
;
1300 dma_linked_lch
[*chain_id
].chain_state
= DMA_CHAIN_NOTSTARTED
;
1301 dma_linked_lch
[*chain_id
].no_of_lchs_linked
= no_of_chans
;
1303 for (i
= 0; i
< no_of_chans
; i
++)
1304 dma_chan
[channels
[i
]].chain_id
= *chain_id
;
1306 /* Reset the Queue pointers */
1307 OMAP_DMA_CHAIN_QINIT(*chain_id
);
1309 /* Set up the chain */
1310 if (no_of_chans
== 1)
1311 create_dma_lch_chain(channels
[0], channels
[0]);
1313 for (i
= 0; i
< (no_of_chans
- 1); i
++)
1314 create_dma_lch_chain(channels
[i
], channels
[i
+ 1]);
1319 EXPORT_SYMBOL(omap_request_dma_chain
);
1322 * @brief omap_modify_dma_chain_param : Modify the chain's params - Modify the
1323 * params after setting it. Dont do this while dma is running!!
1325 * @param chain_id - Chained logical channel id.
1328 * @return - Success : 0
1331 int omap_modify_dma_chain_params(int chain_id
,
1332 struct omap_dma_channel_params params
)
1337 /* Check for input params */
1338 if (unlikely((chain_id
< 0
1339 || chain_id
>= dma_lch_count
))) {
1340 printk(KERN_ERR
"Invalid chain id\n");
1344 /* Check if the chain exists */
1345 if (dma_linked_lch
[chain_id
].linked_dmach_q
== NULL
) {
1346 printk(KERN_ERR
"Chain doesn't exists\n");
1349 channels
= dma_linked_lch
[chain_id
].linked_dmach_q
;
1351 for (i
= 0; i
< dma_linked_lch
[chain_id
].no_of_lchs_linked
; i
++) {
1353 * Allowing client drivers to set common parameters now,
1354 * so that later only relevant (src_start, dest_start
1355 * and element count) can be set
1357 omap_set_dma_params(channels
[i
], ¶ms
);
1362 EXPORT_SYMBOL(omap_modify_dma_chain_params
);
1365 * @brief omap_free_dma_chain - Free all the logical channels in a chain.
1369 * @return - Success : 0
1372 int omap_free_dma_chain(int chain_id
)
1377 /* Check for input params */
1378 if (unlikely((chain_id
< 0 || chain_id
>= dma_lch_count
))) {
1379 printk(KERN_ERR
"Invalid chain id\n");
1383 /* Check if the chain exists */
1384 if (dma_linked_lch
[chain_id
].linked_dmach_q
== NULL
) {
1385 printk(KERN_ERR
"Chain doesn't exists\n");
1389 channels
= dma_linked_lch
[chain_id
].linked_dmach_q
;
1390 for (i
= 0; i
< dma_linked_lch
[chain_id
].no_of_lchs_linked
; i
++) {
1391 dma_chan
[channels
[i
]].next_linked_ch
= -1;
1392 dma_chan
[channels
[i
]].prev_linked_ch
= -1;
1393 dma_chan
[channels
[i
]].chain_id
= -1;
1394 dma_chan
[channels
[i
]].state
= DMA_CH_NOTSTARTED
;
1395 omap_free_dma(channels
[i
]);
1400 dma_linked_lch
[chain_id
].linked_dmach_q
= NULL
;
1401 dma_linked_lch
[chain_id
].chain_mode
= -1;
1402 dma_linked_lch
[chain_id
].chain_state
= -1;
1406 EXPORT_SYMBOL(omap_free_dma_chain
);
1409 * @brief omap_dma_chain_status - Check if the chain is in
1410 * active / inactive state.
1413 * @return - Success : OMAP_DMA_CHAIN_ACTIVE/OMAP_DMA_CHAIN_INACTIVE
1416 int omap_dma_chain_status(int chain_id
)
1418 /* Check for input params */
1419 if (unlikely((chain_id
< 0 || chain_id
>= dma_lch_count
))) {
1420 printk(KERN_ERR
"Invalid chain id\n");
1424 /* Check if the chain exists */
1425 if (dma_linked_lch
[chain_id
].linked_dmach_q
== NULL
) {
1426 printk(KERN_ERR
"Chain doesn't exists\n");
1429 pr_debug("CHAINID=%d, qcnt=%d\n", chain_id
,
1430 dma_linked_lch
[chain_id
].q_count
);
1432 if (OMAP_DMA_CHAIN_QEMPTY(chain_id
))
1433 return OMAP_DMA_CHAIN_INACTIVE
;
1435 return OMAP_DMA_CHAIN_ACTIVE
;
1437 EXPORT_SYMBOL(omap_dma_chain_status
);
1440 * @brief omap_dma_chain_a_transfer - Get a free channel from a chain,
1441 * set the params and start the transfer.
1444 * @param src_start - buffer start address
1445 * @param dest_start - Dest address
1447 * @param frame_count
1448 * @param callbk_data - channel callback parameter data.
1450 * @return - Success : 0
1451 * Failure: -EINVAL/-EBUSY
1453 int omap_dma_chain_a_transfer(int chain_id
, int src_start
, int dest_start
,
1454 int elem_count
, int frame_count
, void *callbk_data
)
1461 * if buffer size is less than 1 then there is
1462 * no use of starting the chain
1464 if (elem_count
< 1) {
1465 printk(KERN_ERR
"Invalid buffer size\n");
1469 /* Check for input params */
1470 if (unlikely((chain_id
< 0
1471 || chain_id
>= dma_lch_count
))) {
1472 printk(KERN_ERR
"Invalid chain id\n");
1476 /* Check if the chain exists */
1477 if (dma_linked_lch
[chain_id
].linked_dmach_q
== NULL
) {
1478 printk(KERN_ERR
"Chain doesn't exist\n");
1482 /* Check if all the channels in chain are in use */
1483 if (OMAP_DMA_CHAIN_QFULL(chain_id
))
1486 /* Frame count may be negative in case of indexed transfers */
1487 channels
= dma_linked_lch
[chain_id
].linked_dmach_q
;
1489 /* Get a free channel */
1490 lch
= channels
[dma_linked_lch
[chain_id
].q_tail
];
1492 /* Store the callback data */
1493 dma_chan
[lch
].data
= callbk_data
;
1495 /* Increment the q_tail */
1496 OMAP_DMA_CHAIN_INCQTAIL(chain_id
);
1498 /* Set the params to the free channel */
1500 dma_write(src_start
, CSSA(lch
));
1501 if (dest_start
!= 0)
1502 dma_write(dest_start
, CDSA(lch
));
1504 /* Write the buffer size */
1505 dma_write(elem_count
, CEN(lch
));
1506 dma_write(frame_count
, CFN(lch
));
1509 * If the chain is dynamically linked,
1510 * then we may have to start the chain if its not active
1512 if (dma_linked_lch
[chain_id
].chain_mode
== OMAP_DMA_DYNAMIC_CHAIN
) {
1515 * In Dynamic chain, if the chain is not started,
1518 if (dma_linked_lch
[chain_id
].chain_state
==
1519 DMA_CHAIN_NOTSTARTED
) {
1520 /* Enable the link in previous channel */
1521 if (dma_chan
[dma_chan
[lch
].prev_linked_ch
].state
==
1523 enable_lnk(dma_chan
[lch
].prev_linked_ch
);
1524 dma_chan
[lch
].state
= DMA_CH_QUEUED
;
1528 * Chain is already started, make sure its active,
1529 * if not then start the chain
1534 if (dma_chan
[dma_chan
[lch
].prev_linked_ch
].state
==
1536 enable_lnk(dma_chan
[lch
].prev_linked_ch
);
1537 dma_chan
[lch
].state
= DMA_CH_QUEUED
;
1539 if (0 == ((1 << 7) & dma_read(
1540 CCR(dma_chan
[lch
].prev_linked_ch
)))) {
1541 disable_lnk(dma_chan
[lch
].
1543 pr_debug("\n prev ch is stopped\n");
1548 else if (dma_chan
[dma_chan
[lch
].prev_linked_ch
].state
1550 enable_lnk(dma_chan
[lch
].prev_linked_ch
);
1551 dma_chan
[lch
].state
= DMA_CH_QUEUED
;
1554 omap_enable_channel_irq(lch
);
1556 l
= dma_read(CCR(lch
));
1558 if ((0 == (l
& (1 << 24))))
1562 if (start_dma
== 1) {
1563 if (0 == (l
& (1 << 7))) {
1565 dma_chan
[lch
].state
= DMA_CH_STARTED
;
1566 pr_debug("starting %d\n", lch
);
1567 dma_write(l
, CCR(lch
));
1571 if (0 == (l
& (1 << 7)))
1572 dma_write(l
, CCR(lch
));
1574 dma_chan
[lch
].flags
|= OMAP_DMA_ACTIVE
;
1580 EXPORT_SYMBOL(omap_dma_chain_a_transfer
);
1583 * @brief omap_start_dma_chain_transfers - Start the chain
1587 * @return - Success : 0
1588 * Failure : -EINVAL/-EBUSY
1590 int omap_start_dma_chain_transfers(int chain_id
)
1595 if (unlikely((chain_id
< 0 || chain_id
>= dma_lch_count
))) {
1596 printk(KERN_ERR
"Invalid chain id\n");
1600 channels
= dma_linked_lch
[chain_id
].linked_dmach_q
;
1602 if (dma_linked_lch
[channels
[0]].chain_state
== DMA_CHAIN_STARTED
) {
1603 printk(KERN_ERR
"Chain is already started\n");
1607 if (dma_linked_lch
[chain_id
].chain_mode
== OMAP_DMA_STATIC_CHAIN
) {
1608 for (i
= 0; i
< dma_linked_lch
[chain_id
].no_of_lchs_linked
;
1610 enable_lnk(channels
[i
]);
1611 omap_enable_channel_irq(channels
[i
]);
1614 omap_enable_channel_irq(channels
[0]);
1617 l
= dma_read(CCR(channels
[0]));
1619 dma_linked_lch
[chain_id
].chain_state
= DMA_CHAIN_STARTED
;
1620 dma_chan
[channels
[0]].state
= DMA_CH_STARTED
;
1622 if ((0 == (l
& (1 << 24))))
1626 dma_write(l
, CCR(channels
[0]));
1628 dma_chan
[channels
[0]].flags
|= OMAP_DMA_ACTIVE
;
1632 EXPORT_SYMBOL(omap_start_dma_chain_transfers
);
1635 * @brief omap_stop_dma_chain_transfers - Stop the dma transfer of a chain.
1639 * @return - Success : 0
1642 int omap_stop_dma_chain_transfers(int chain_id
)
1648 /* Check for input params */
1649 if (unlikely((chain_id
< 0 || chain_id
>= dma_lch_count
))) {
1650 printk(KERN_ERR
"Invalid chain id\n");
1654 /* Check if the chain exists */
1655 if (dma_linked_lch
[chain_id
].linked_dmach_q
== NULL
) {
1656 printk(KERN_ERR
"Chain doesn't exists\n");
1659 channels
= dma_linked_lch
[chain_id
].linked_dmach_q
;
1663 * Special programming model needed to disable DMA before end of block
1665 sys_cf
= dma_read(OCP_SYSCONFIG
);
1667 /* Middle mode reg set no Standby */
1668 l
&= ~((1 << 12)|(1 << 13));
1669 dma_write(l
, OCP_SYSCONFIG
);
1671 for (i
= 0; i
< dma_linked_lch
[chain_id
].no_of_lchs_linked
; i
++) {
1673 /* Stop the Channel transmission */
1674 l
= dma_read(CCR(channels
[i
]));
1676 dma_write(l
, CCR(channels
[i
]));
1678 /* Disable the link in all the channels */
1679 disable_lnk(channels
[i
]);
1680 dma_chan
[channels
[i
]].state
= DMA_CH_NOTSTARTED
;
1683 dma_linked_lch
[chain_id
].chain_state
= DMA_CHAIN_NOTSTARTED
;
1685 /* Reset the Queue pointers */
1686 OMAP_DMA_CHAIN_QINIT(chain_id
);
1688 /* Errata - put in the old value */
1689 dma_write(sys_cf
, OCP_SYSCONFIG
);
1693 EXPORT_SYMBOL(omap_stop_dma_chain_transfers
);
1695 /* Get the index of the ongoing DMA in chain */
1697 * @brief omap_get_dma_chain_index - Get the element and frame index
1698 * of the ongoing DMA in chain
1701 * @param ei - Element index
1702 * @param fi - Frame index
1704 * @return - Success : 0
1707 int omap_get_dma_chain_index(int chain_id
, int *ei
, int *fi
)
1712 /* Check for input params */
1713 if (unlikely((chain_id
< 0 || chain_id
>= dma_lch_count
))) {
1714 printk(KERN_ERR
"Invalid chain id\n");
1718 /* Check if the chain exists */
1719 if (dma_linked_lch
[chain_id
].linked_dmach_q
== NULL
) {
1720 printk(KERN_ERR
"Chain doesn't exists\n");
1726 channels
= dma_linked_lch
[chain_id
].linked_dmach_q
;
1728 /* Get the current channel */
1729 lch
= channels
[dma_linked_lch
[chain_id
].q_head
];
1731 *ei
= dma_read(CCEN(lch
));
1732 *fi
= dma_read(CCFN(lch
));
1736 EXPORT_SYMBOL(omap_get_dma_chain_index
);
1739 * @brief omap_get_dma_chain_dst_pos - Get the destination position of the
1740 * ongoing DMA in chain
1744 * @return - Success : Destination position
1747 int omap_get_dma_chain_dst_pos(int chain_id
)
1752 /* Check for input params */
1753 if (unlikely((chain_id
< 0 || chain_id
>= dma_lch_count
))) {
1754 printk(KERN_ERR
"Invalid chain id\n");
1758 /* Check if the chain exists */
1759 if (dma_linked_lch
[chain_id
].linked_dmach_q
== NULL
) {
1760 printk(KERN_ERR
"Chain doesn't exists\n");
1764 channels
= dma_linked_lch
[chain_id
].linked_dmach_q
;
1766 /* Get the current channel */
1767 lch
= channels
[dma_linked_lch
[chain_id
].q_head
];
1769 return dma_read(CDAC(lch
));
1771 EXPORT_SYMBOL(omap_get_dma_chain_dst_pos
);
1774 * @brief omap_get_dma_chain_src_pos - Get the source position
1775 * of the ongoing DMA in chain
1778 * @return - Success : Destination position
1781 int omap_get_dma_chain_src_pos(int chain_id
)
1786 /* Check for input params */
1787 if (unlikely((chain_id
< 0 || chain_id
>= dma_lch_count
))) {
1788 printk(KERN_ERR
"Invalid chain id\n");
1792 /* Check if the chain exists */
1793 if (dma_linked_lch
[chain_id
].linked_dmach_q
== NULL
) {
1794 printk(KERN_ERR
"Chain doesn't exists\n");
1798 channels
= dma_linked_lch
[chain_id
].linked_dmach_q
;
1800 /* Get the current channel */
1801 lch
= channels
[dma_linked_lch
[chain_id
].q_head
];
1803 return dma_read(CSAC(lch
));
1805 EXPORT_SYMBOL(omap_get_dma_chain_src_pos
);
1806 #endif /* ifndef CONFIG_ARCH_OMAP1 */
1808 /*----------------------------------------------------------------------------*/
1810 #ifdef CONFIG_ARCH_OMAP1
1812 static int omap1_dma_handle_ch(int ch
)
1816 if (enable_1510_mode
&& ch
>= 6) {
1817 csr
= dma_chan
[ch
].saved_csr
;
1818 dma_chan
[ch
].saved_csr
= 0;
1820 csr
= dma_read(CSR(ch
));
1821 if (enable_1510_mode
&& ch
<= 2 && (csr
>> 7) != 0) {
1822 dma_chan
[ch
+ 6].saved_csr
= csr
>> 7;
1825 if ((csr
& 0x3f) == 0)
1827 if (unlikely(dma_chan
[ch
].dev_id
== -1)) {
1828 printk(KERN_WARNING
"Spurious interrupt from DMA channel "
1829 "%d (CSR %04x)\n", ch
, csr
);
1832 if (unlikely(csr
& OMAP1_DMA_TOUT_IRQ
))
1833 printk(KERN_WARNING
"DMA timeout with device %d\n",
1834 dma_chan
[ch
].dev_id
);
1835 if (unlikely(csr
& OMAP_DMA_DROP_IRQ
))
1836 printk(KERN_WARNING
"DMA synchronization event drop occurred "
1837 "with device %d\n", dma_chan
[ch
].dev_id
);
1838 if (likely(csr
& OMAP_DMA_BLOCK_IRQ
))
1839 dma_chan
[ch
].flags
&= ~OMAP_DMA_ACTIVE
;
1840 if (likely(dma_chan
[ch
].callback
!= NULL
))
1841 dma_chan
[ch
].callback(ch
, csr
, dma_chan
[ch
].data
);
1846 static irqreturn_t
omap1_dma_irq_handler(int irq
, void *dev_id
)
1848 int ch
= ((int) dev_id
) - 1;
1852 int handled_now
= 0;
1854 handled_now
+= omap1_dma_handle_ch(ch
);
1855 if (enable_1510_mode
&& dma_chan
[ch
+ 6].saved_csr
)
1856 handled_now
+= omap1_dma_handle_ch(ch
+ 6);
1859 handled
+= handled_now
;
1862 return handled
? IRQ_HANDLED
: IRQ_NONE
;
1866 #define omap1_dma_irq_handler NULL
1869 #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3) || \
1870 defined(CONFIG_ARCH_OMAP4)
1872 static int omap2_dma_handle_ch(int ch
)
1874 u32 status
= dma_read(CSR(ch
));
1877 if (printk_ratelimit())
1878 printk(KERN_WARNING
"Spurious DMA IRQ for lch %d\n",
1880 dma_write(1 << ch
, IRQSTATUS_L0
);
1883 if (unlikely(dma_chan
[ch
].dev_id
== -1)) {
1884 if (printk_ratelimit())
1885 printk(KERN_WARNING
"IRQ %04x for non-allocated DMA"
1886 "channel %d\n", status
, ch
);
1889 if (unlikely(status
& OMAP_DMA_DROP_IRQ
))
1891 "DMA synchronization event drop occurred with device "
1892 "%d\n", dma_chan
[ch
].dev_id
);
1893 if (unlikely(status
& OMAP2_DMA_TRANS_ERR_IRQ
)) {
1894 printk(KERN_INFO
"DMA transaction error with device %d\n",
1895 dma_chan
[ch
].dev_id
);
1896 if (cpu_class_is_omap2()) {
1897 /* Errata: sDMA Channel is not disabled
1898 * after a transaction error. So we explicitely
1899 * disable the channel
1903 ccr
= dma_read(CCR(ch
));
1904 ccr
&= ~OMAP_DMA_CCR_EN
;
1905 dma_write(ccr
, CCR(ch
));
1906 dma_chan
[ch
].flags
&= ~OMAP_DMA_ACTIVE
;
1909 if (unlikely(status
& OMAP2_DMA_SECURE_ERR_IRQ
))
1910 printk(KERN_INFO
"DMA secure error with device %d\n",
1911 dma_chan
[ch
].dev_id
);
1912 if (unlikely(status
& OMAP2_DMA_MISALIGNED_ERR_IRQ
))
1913 printk(KERN_INFO
"DMA misaligned error with device %d\n",
1914 dma_chan
[ch
].dev_id
);
1916 dma_write(OMAP2_DMA_CSR_CLEAR_MASK
, CSR(ch
));
1917 dma_write(1 << ch
, IRQSTATUS_L0
);
1919 /* If the ch is not chained then chain_id will be -1 */
1920 if (dma_chan
[ch
].chain_id
!= -1) {
1921 int chain_id
= dma_chan
[ch
].chain_id
;
1922 dma_chan
[ch
].state
= DMA_CH_NOTSTARTED
;
1923 if (dma_read(CLNK_CTRL(ch
)) & (1 << 15))
1924 dma_chan
[dma_chan
[ch
].next_linked_ch
].state
=
1926 if (dma_linked_lch
[chain_id
].chain_mode
==
1927 OMAP_DMA_DYNAMIC_CHAIN
)
1930 if (!OMAP_DMA_CHAIN_QEMPTY(chain_id
))
1931 OMAP_DMA_CHAIN_INCQHEAD(chain_id
);
1933 status
= dma_read(CSR(ch
));
1936 dma_write(status
, CSR(ch
));
1938 if (likely(dma_chan
[ch
].callback
!= NULL
))
1939 dma_chan
[ch
].callback(ch
, status
, dma_chan
[ch
].data
);
1944 /* STATUS register count is from 1-32 while our is 0-31 */
1945 static irqreturn_t
omap2_dma_irq_handler(int irq
, void *dev_id
)
1947 u32 val
, enable_reg
;
1950 val
= dma_read(IRQSTATUS_L0
);
1952 if (printk_ratelimit())
1953 printk(KERN_WARNING
"Spurious DMA IRQ\n");
1956 enable_reg
= dma_read(IRQENABLE_L0
);
1957 val
&= enable_reg
; /* Dispatch only relevant interrupts */
1958 for (i
= 0; i
< dma_lch_count
&& val
!= 0; i
++) {
1960 omap2_dma_handle_ch(i
);
1967 static struct irqaction omap24xx_dma_irq
= {
1969 .handler
= omap2_dma_irq_handler
,
1970 .flags
= IRQF_DISABLED
1974 static struct irqaction omap24xx_dma_irq
;
1977 /*----------------------------------------------------------------------------*/
1979 static struct lcd_dma_info
{
1982 void (*callback
)(u16 status
, void *data
);
1986 unsigned long addr
, size
;
1987 int rotate
, data_type
, xres
, yres
;
1993 int single_transfer
;
1996 void omap_set_lcd_dma_b1(unsigned long addr
, u16 fb_xres
, u16 fb_yres
,
1999 lcd_dma
.addr
= addr
;
2000 lcd_dma
.data_type
= data_type
;
2001 lcd_dma
.xres
= fb_xres
;
2002 lcd_dma
.yres
= fb_yres
;
2004 EXPORT_SYMBOL(omap_set_lcd_dma_b1
);
2006 void omap_set_lcd_dma_src_port(int port
)
2008 lcd_dma
.src_port
= port
;
2011 void omap_set_lcd_dma_ext_controller(int external
)
2013 lcd_dma
.ext_ctrl
= external
;
2015 EXPORT_SYMBOL(omap_set_lcd_dma_ext_controller
);
2017 void omap_set_lcd_dma_single_transfer(int single
)
2019 lcd_dma
.single_transfer
= single
;
2021 EXPORT_SYMBOL(omap_set_lcd_dma_single_transfer
);
2023 void omap_set_lcd_dma_b1_rotation(int rotate
)
2025 if (omap_dma_in_1510_mode()) {
2026 printk(KERN_ERR
"DMA rotation is not supported in 1510 mode\n");
2030 lcd_dma
.rotate
= rotate
;
2032 EXPORT_SYMBOL(omap_set_lcd_dma_b1_rotation
);
2034 void omap_set_lcd_dma_b1_mirror(int mirror
)
2036 if (omap_dma_in_1510_mode()) {
2037 printk(KERN_ERR
"DMA mirror is not supported in 1510 mode\n");
2040 lcd_dma
.mirror
= mirror
;
2042 EXPORT_SYMBOL(omap_set_lcd_dma_b1_mirror
);
2044 void omap_set_lcd_dma_b1_vxres(unsigned long vxres
)
2046 if (omap_dma_in_1510_mode()) {
2047 printk(KERN_ERR
"DMA virtual resulotion is not supported "
2051 lcd_dma
.vxres
= vxres
;
2053 EXPORT_SYMBOL(omap_set_lcd_dma_b1_vxres
);
2055 void omap_set_lcd_dma_b1_scale(unsigned int xscale
, unsigned int yscale
)
2057 if (omap_dma_in_1510_mode()) {
2058 printk(KERN_ERR
"DMA scale is not supported in 1510 mode\n");
2061 lcd_dma
.xscale
= xscale
;
2062 lcd_dma
.yscale
= yscale
;
2064 EXPORT_SYMBOL(omap_set_lcd_dma_b1_scale
);
2066 static void set_b1_regs(void)
2068 unsigned long top
, bottom
;
2071 unsigned long en
, fn
;
2073 unsigned long vxres
;
2074 unsigned int xscale
, yscale
;
2076 switch (lcd_dma
.data_type
) {
2077 case OMAP_DMA_DATA_TYPE_S8
:
2080 case OMAP_DMA_DATA_TYPE_S16
:
2083 case OMAP_DMA_DATA_TYPE_S32
:
2091 vxres
= lcd_dma
.vxres
? lcd_dma
.vxres
: lcd_dma
.xres
;
2092 xscale
= lcd_dma
.xscale
? lcd_dma
.xscale
: 1;
2093 yscale
= lcd_dma
.yscale
? lcd_dma
.yscale
: 1;
2094 BUG_ON(vxres
< lcd_dma
.xres
);
2096 #define PIXADDR(x, y) (lcd_dma.addr + \
2097 ((y) * vxres * yscale + (x) * xscale) * es)
2098 #define PIXSTEP(sx, sy, dx, dy) (PIXADDR(dx, dy) - PIXADDR(sx, sy) - es + 1)
2100 switch (lcd_dma
.rotate
) {
2102 if (!lcd_dma
.mirror
) {
2103 top
= PIXADDR(0, 0);
2104 bottom
= PIXADDR(lcd_dma
.xres
- 1, lcd_dma
.yres
- 1);
2105 /* 1510 DMA requires the bottom address to be 2 more
2106 * than the actual last memory access location. */
2107 if (omap_dma_in_1510_mode() &&
2108 lcd_dma
.data_type
== OMAP_DMA_DATA_TYPE_S32
)
2110 ei
= PIXSTEP(0, 0, 1, 0);
2111 fi
= PIXSTEP(lcd_dma
.xres
- 1, 0, 0, 1);
2113 top
= PIXADDR(lcd_dma
.xres
- 1, 0);
2114 bottom
= PIXADDR(0, lcd_dma
.yres
- 1);
2115 ei
= PIXSTEP(1, 0, 0, 0);
2116 fi
= PIXSTEP(0, 0, lcd_dma
.xres
- 1, 1);
2122 if (!lcd_dma
.mirror
) {
2123 top
= PIXADDR(0, lcd_dma
.yres
- 1);
2124 bottom
= PIXADDR(lcd_dma
.xres
- 1, 0);
2125 ei
= PIXSTEP(0, 1, 0, 0);
2126 fi
= PIXSTEP(0, 0, 1, lcd_dma
.yres
- 1);
2128 top
= PIXADDR(lcd_dma
.xres
- 1, lcd_dma
.yres
- 1);
2129 bottom
= PIXADDR(0, 0);
2130 ei
= PIXSTEP(0, 1, 0, 0);
2131 fi
= PIXSTEP(1, 0, 0, lcd_dma
.yres
- 1);
2137 if (!lcd_dma
.mirror
) {
2138 top
= PIXADDR(lcd_dma
.xres
- 1, lcd_dma
.yres
- 1);
2139 bottom
= PIXADDR(0, 0);
2140 ei
= PIXSTEP(1, 0, 0, 0);
2141 fi
= PIXSTEP(0, 1, lcd_dma
.xres
- 1, 0);
2143 top
= PIXADDR(0, lcd_dma
.yres
- 1);
2144 bottom
= PIXADDR(lcd_dma
.xres
- 1, 0);
2145 ei
= PIXSTEP(0, 0, 1, 0);
2146 fi
= PIXSTEP(lcd_dma
.xres
- 1, 1, 0, 0);
2152 if (!lcd_dma
.mirror
) {
2153 top
= PIXADDR(lcd_dma
.xres
- 1, 0);
2154 bottom
= PIXADDR(0, lcd_dma
.yres
- 1);
2155 ei
= PIXSTEP(0, 0, 0, 1);
2156 fi
= PIXSTEP(1, lcd_dma
.yres
- 1, 0, 0);
2158 top
= PIXADDR(0, 0);
2159 bottom
= PIXADDR(lcd_dma
.xres
- 1, lcd_dma
.yres
- 1);
2160 ei
= PIXSTEP(0, 0, 0, 1);
2161 fi
= PIXSTEP(0, lcd_dma
.yres
- 1, 1, 0);
2168 return; /* Suppress warning about uninitialized vars */
2171 if (omap_dma_in_1510_mode()) {
2172 omap_writew(top
>> 16, OMAP1510_DMA_LCD_TOP_F1_U
);
2173 omap_writew(top
, OMAP1510_DMA_LCD_TOP_F1_L
);
2174 omap_writew(bottom
>> 16, OMAP1510_DMA_LCD_BOT_F1_U
);
2175 omap_writew(bottom
, OMAP1510_DMA_LCD_BOT_F1_L
);
2181 omap_writew(top
>> 16, OMAP1610_DMA_LCD_TOP_B1_U
);
2182 omap_writew(top
, OMAP1610_DMA_LCD_TOP_B1_L
);
2183 omap_writew(bottom
>> 16, OMAP1610_DMA_LCD_BOT_B1_U
);
2184 omap_writew(bottom
, OMAP1610_DMA_LCD_BOT_B1_L
);
2186 omap_writew(en
, OMAP1610_DMA_LCD_SRC_EN_B1
);
2187 omap_writew(fn
, OMAP1610_DMA_LCD_SRC_FN_B1
);
2189 w
= omap_readw(OMAP1610_DMA_LCD_CSDP
);
2191 w
|= lcd_dma
.data_type
;
2192 omap_writew(w
, OMAP1610_DMA_LCD_CSDP
);
2194 w
= omap_readw(OMAP1610_DMA_LCD_CTRL
);
2195 /* Always set the source port as SDRAM for now*/
2197 if (lcd_dma
.callback
!= NULL
)
2198 w
|= 1 << 1; /* Block interrupt enable */
2201 omap_writew(w
, OMAP1610_DMA_LCD_CTRL
);
2203 if (!(lcd_dma
.rotate
|| lcd_dma
.mirror
||
2204 lcd_dma
.vxres
|| lcd_dma
.xscale
|| lcd_dma
.yscale
))
2207 w
= omap_readw(OMAP1610_DMA_LCD_CCR
);
2208 /* Set the double-indexed addressing mode */
2210 omap_writew(w
, OMAP1610_DMA_LCD_CCR
);
2212 omap_writew(ei
, OMAP1610_DMA_LCD_SRC_EI_B1
);
2213 omap_writew(fi
>> 16, OMAP1610_DMA_LCD_SRC_FI_B1_U
);
2214 omap_writew(fi
, OMAP1610_DMA_LCD_SRC_FI_B1_L
);
2217 static irqreturn_t
lcd_dma_irq_handler(int irq
, void *dev_id
)
2221 w
= omap_readw(OMAP1610_DMA_LCD_CTRL
);
2222 if (unlikely(!(w
& (1 << 3)))) {
2223 printk(KERN_WARNING
"Spurious LCD DMA IRQ\n");
2228 omap_writew(w
, OMAP1610_DMA_LCD_CTRL
);
2230 if (lcd_dma
.callback
!= NULL
)
2231 lcd_dma
.callback(w
, lcd_dma
.cb_data
);
2236 int omap_request_lcd_dma(void (*callback
)(u16 status
, void *data
),
2239 spin_lock_irq(&lcd_dma
.lock
);
2240 if (lcd_dma
.reserved
) {
2241 spin_unlock_irq(&lcd_dma
.lock
);
2242 printk(KERN_ERR
"LCD DMA channel already reserved\n");
2246 lcd_dma
.reserved
= 1;
2247 spin_unlock_irq(&lcd_dma
.lock
);
2248 lcd_dma
.callback
= callback
;
2249 lcd_dma
.cb_data
= data
;
2251 lcd_dma
.single_transfer
= 0;
2257 lcd_dma
.ext_ctrl
= 0;
2258 lcd_dma
.src_port
= 0;
2262 EXPORT_SYMBOL(omap_request_lcd_dma
);
2264 void omap_free_lcd_dma(void)
2266 spin_lock(&lcd_dma
.lock
);
2267 if (!lcd_dma
.reserved
) {
2268 spin_unlock(&lcd_dma
.lock
);
2269 printk(KERN_ERR
"LCD DMA is not reserved\n");
2273 if (!enable_1510_mode
)
2274 omap_writew(omap_readw(OMAP1610_DMA_LCD_CCR
) & ~1,
2275 OMAP1610_DMA_LCD_CCR
);
2276 lcd_dma
.reserved
= 0;
2277 spin_unlock(&lcd_dma
.lock
);
2279 EXPORT_SYMBOL(omap_free_lcd_dma
);
2281 void omap_enable_lcd_dma(void)
2286 * Set the Enable bit only if an external controller is
2287 * connected. Otherwise the OMAP internal controller will
2288 * start the transfer when it gets enabled.
2290 if (enable_1510_mode
|| !lcd_dma
.ext_ctrl
)
2293 w
= omap_readw(OMAP1610_DMA_LCD_CTRL
);
2295 omap_writew(w
, OMAP1610_DMA_LCD_CTRL
);
2299 w
= omap_readw(OMAP1610_DMA_LCD_CCR
);
2301 omap_writew(w
, OMAP1610_DMA_LCD_CCR
);
2303 EXPORT_SYMBOL(omap_enable_lcd_dma
);
2305 void omap_setup_lcd_dma(void)
2307 BUG_ON(lcd_dma
.active
);
2308 if (!enable_1510_mode
) {
2309 /* Set some reasonable defaults */
2310 omap_writew(0x5440, OMAP1610_DMA_LCD_CCR
);
2311 omap_writew(0x9102, OMAP1610_DMA_LCD_CSDP
);
2312 omap_writew(0x0004, OMAP1610_DMA_LCD_LCH_CTRL
);
2315 if (!enable_1510_mode
) {
2318 w
= omap_readw(OMAP1610_DMA_LCD_CCR
);
2320 * If DMA was already active set the end_prog bit to have
2321 * the programmed register set loaded into the active
2324 w
|= 1 << 11; /* End_prog */
2325 if (!lcd_dma
.single_transfer
)
2326 w
|= (3 << 8); /* Auto_init, repeat */
2327 omap_writew(w
, OMAP1610_DMA_LCD_CCR
);
2330 EXPORT_SYMBOL(omap_setup_lcd_dma
);
2332 void omap_stop_lcd_dma(void)
2337 if (enable_1510_mode
|| !lcd_dma
.ext_ctrl
)
2340 w
= omap_readw(OMAP1610_DMA_LCD_CCR
);
2342 omap_writew(w
, OMAP1610_DMA_LCD_CCR
);
2344 w
= omap_readw(OMAP1610_DMA_LCD_CTRL
);
2346 omap_writew(w
, OMAP1610_DMA_LCD_CTRL
);
2348 EXPORT_SYMBOL(omap_stop_lcd_dma
);
2350 void omap_dma_global_context_save(void)
2352 omap_dma_global_context
.dma_irqenable_l0
=
2353 dma_read(IRQENABLE_L0
);
2354 omap_dma_global_context
.dma_ocp_sysconfig
=
2355 dma_read(OCP_SYSCONFIG
);
2356 omap_dma_global_context
.dma_gcr
= dma_read(GCR
);
2359 void omap_dma_global_context_restore(void)
2363 dma_write(omap_dma_global_context
.dma_gcr
, GCR
);
2364 dma_write(omap_dma_global_context
.dma_ocp_sysconfig
,
2366 dma_write(omap_dma_global_context
.dma_irqenable_l0
,
2370 * A bug in ROM code leaves IRQ status for channels 0 and 1 uncleared
2371 * after secure sram context save and restore. Hence we need to
2372 * manually clear those IRQs to avoid spurious interrupts. This
2373 * affects only secure devices.
2375 if (cpu_is_omap34xx() && (omap_type() != OMAP2_DEVICE_TYPE_GP
))
2376 dma_write(0x3 , IRQSTATUS_L0
);
2378 for (ch
= 0; ch
< dma_chan_count
; ch
++)
2379 if (dma_chan
[ch
].dev_id
!= -1)
2383 /*----------------------------------------------------------------------------*/
2385 static int __init
omap_init_dma(void)
2390 if (cpu_class_is_omap1()) {
2391 base
= OMAP1_DMA_BASE
;
2392 dma_lch_count
= OMAP1_LOGICAL_DMA_CH_COUNT
;
2393 } else if (cpu_is_omap24xx()) {
2394 base
= OMAP24XX_DMA4_BASE
;
2395 dma_lch_count
= OMAP_DMA4_LOGICAL_DMA_CH_COUNT
;
2396 } else if (cpu_is_omap34xx()) {
2397 base
= OMAP34XX_DMA4_BASE
;
2398 dma_lch_count
= OMAP_DMA4_LOGICAL_DMA_CH_COUNT
;
2399 } else if (cpu_is_omap44xx()) {
2400 base
= OMAP44XX_DMA4_BASE
;
2401 dma_lch_count
= OMAP_DMA4_LOGICAL_DMA_CH_COUNT
;
2403 pr_err("DMA init failed for unsupported omap\n");
2407 omap_dma_base
= ioremap(base
, SZ_4K
);
2408 BUG_ON(!omap_dma_base
);
2410 if (cpu_class_is_omap2() && omap_dma_reserve_channels
2411 && (omap_dma_reserve_channels
<= dma_lch_count
))
2412 dma_lch_count
= omap_dma_reserve_channels
;
2414 dma_chan
= kzalloc(sizeof(struct omap_dma_lch
) * dma_lch_count
,
2421 if (cpu_class_is_omap2()) {
2422 dma_linked_lch
= kzalloc(sizeof(struct dma_link_info
) *
2423 dma_lch_count
, GFP_KERNEL
);
2424 if (!dma_linked_lch
) {
2430 if (cpu_is_omap15xx()) {
2431 printk(KERN_INFO
"DMA support for OMAP15xx initialized\n");
2433 enable_1510_mode
= 1;
2434 } else if (cpu_is_omap16xx() || cpu_is_omap7xx()) {
2435 printk(KERN_INFO
"OMAP DMA hardware version %d\n",
2437 printk(KERN_INFO
"DMA capabilities: %08x:%08x:%04x:%04x:%04x\n",
2438 (dma_read(CAPS_0_U
) << 16) |
2440 (dma_read(CAPS_1_U
) << 16) |
2442 dma_read(CAPS_2
), dma_read(CAPS_3
),
2444 if (!enable_1510_mode
) {
2447 /* Disable OMAP 3.0/3.1 compatibility mode. */
2451 dma_chan_count
= 16;
2454 if (cpu_is_omap16xx()) {
2457 /* this would prevent OMAP sleep */
2458 w
= omap_readw(OMAP1610_DMA_LCD_CTRL
);
2460 omap_writew(w
, OMAP1610_DMA_LCD_CTRL
);
2462 } else if (cpu_class_is_omap2()) {
2463 u8 revision
= dma_read(REVISION
) & 0xff;
2464 printk(KERN_INFO
"OMAP DMA hardware revision %d.%d\n",
2465 revision
>> 4, revision
& 0xf);
2466 dma_chan_count
= dma_lch_count
;
2472 spin_lock_init(&lcd_dma
.lock
);
2473 spin_lock_init(&dma_chan_lock
);
2475 for (ch
= 0; ch
< dma_chan_count
; ch
++) {
2477 dma_chan
[ch
].dev_id
= -1;
2478 dma_chan
[ch
].next_lch
= -1;
2480 if (ch
>= 6 && enable_1510_mode
)
2483 if (cpu_class_is_omap1()) {
2485 * request_irq() doesn't like dev_id (ie. ch) being
2486 * zero, so we have to kludge around this.
2488 r
= request_irq(omap1_dma_irq
[ch
],
2489 omap1_dma_irq_handler
, 0, "DMA",
2494 printk(KERN_ERR
"unable to request IRQ %d "
2495 "for DMA (error %d)\n",
2496 omap1_dma_irq
[ch
], r
);
2497 for (i
= 0; i
< ch
; i
++)
2498 free_irq(omap1_dma_irq
[i
],
2505 if (cpu_is_omap2430() || cpu_is_omap34xx() || cpu_is_omap44xx())
2506 omap_dma_set_global_params(DMA_DEFAULT_ARB_RATE
,
2507 DMA_DEFAULT_FIFO_DEPTH
, 0);
2509 if (cpu_class_is_omap2()) {
2511 if (cpu_is_omap44xx())
2512 irq
= INT_44XX_SDMA_IRQ0
;
2514 irq
= INT_24XX_SDMA_IRQ0
;
2515 setup_irq(irq
, &omap24xx_dma_irq
);
2518 if (cpu_is_omap34xx()) {
2519 /* Enable smartidle idlemodes and autoidle */
2520 u32 v
= dma_read(OCP_SYSCONFIG
);
2521 v
&= ~(DMA_SYSCONFIG_MIDLEMODE_MASK
|
2522 DMA_SYSCONFIG_SIDLEMODE_MASK
|
2523 DMA_SYSCONFIG_AUTOIDLE
);
2524 v
|= (DMA_SYSCONFIG_MIDLEMODE(DMA_IDLEMODE_SMARTIDLE
) |
2525 DMA_SYSCONFIG_SIDLEMODE(DMA_IDLEMODE_SMARTIDLE
) |
2526 DMA_SYSCONFIG_AUTOIDLE
);
2527 dma_write(v
, OCP_SYSCONFIG
);
2528 /* reserve dma channels 0 and 1 in high security devices */
2529 if (omap_type() != OMAP2_DEVICE_TYPE_GP
) {
2530 printk(KERN_INFO
"Reserving DMA channels 0 and 1 for "
2532 dma_chan
[0].dev_id
= 0;
2533 dma_chan
[1].dev_id
= 1;
2538 /* FIXME: Update LCD DMA to work on 24xx */
2539 if (cpu_class_is_omap1()) {
2540 r
= request_irq(INT_DMA_LCD
, lcd_dma_irq_handler
, 0,
2545 printk(KERN_ERR
"unable to request IRQ for LCD DMA "
2547 for (i
= 0; i
< dma_chan_count
; i
++)
2548 free_irq(omap1_dma_irq
[i
], (void *) (i
+ 1));
2559 iounmap(omap_dma_base
);
2564 arch_initcall(omap_init_dma
);
2567 * Reserve the omap SDMA channels using cmdline bootarg
2568 * "omap_dma_reserve_ch=". The valid range is 1 to 32
2570 static int __init
omap_dma_cmdline_reserve_ch(char *str
)
2572 if (get_option(&str
, &omap_dma_reserve_channels
) != 1)
2573 omap_dma_reserve_channels
= 0;
2577 __setup("omap_dma_reserve_ch=", omap_dma_cmdline_reserve_ch
);