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 OMAP2_DMA_CSR_CLEAR_MASK 0xffe
52 #define OMAP_FUNC_MUX_ARM_BASE (0xfffe1000 + 0xec)
54 static int enable_1510_mode
;
56 static struct omap_dma_global_context_registers
{
58 u32 dma_ocp_sysconfig
;
60 } omap_dma_global_context
;
68 void (*callback
)(int lch
, u16 ch_status
, void *data
);
71 #ifndef CONFIG_ARCH_OMAP1
72 /* required for Dynamic chaining */
83 struct dma_link_info
{
85 int no_of_lchs_linked
;
96 static struct dma_link_info
*dma_linked_lch
;
98 #ifndef CONFIG_ARCH_OMAP1
100 /* Chain handling macros */
101 #define OMAP_DMA_CHAIN_QINIT(chain_id) \
103 dma_linked_lch[chain_id].q_head = \
104 dma_linked_lch[chain_id].q_tail = \
105 dma_linked_lch[chain_id].q_count = 0; \
107 #define OMAP_DMA_CHAIN_QFULL(chain_id) \
108 (dma_linked_lch[chain_id].no_of_lchs_linked == \
109 dma_linked_lch[chain_id].q_count)
110 #define OMAP_DMA_CHAIN_QLAST(chain_id) \
112 ((dma_linked_lch[chain_id].no_of_lchs_linked-1) == \
113 dma_linked_lch[chain_id].q_count) \
115 #define OMAP_DMA_CHAIN_QEMPTY(chain_id) \
116 (0 == dma_linked_lch[chain_id].q_count)
117 #define __OMAP_DMA_CHAIN_INCQ(end) \
118 ((end) = ((end)+1) % dma_linked_lch[chain_id].no_of_lchs_linked)
119 #define OMAP_DMA_CHAIN_INCQHEAD(chain_id) \
121 __OMAP_DMA_CHAIN_INCQ(dma_linked_lch[chain_id].q_head); \
122 dma_linked_lch[chain_id].q_count--; \
125 #define OMAP_DMA_CHAIN_INCQTAIL(chain_id) \
127 __OMAP_DMA_CHAIN_INCQ(dma_linked_lch[chain_id].q_tail); \
128 dma_linked_lch[chain_id].q_count++; \
132 static int dma_lch_count
;
133 static int dma_chan_count
;
134 static int omap_dma_reserve_channels
;
136 static spinlock_t dma_chan_lock
;
137 static struct omap_dma_lch
*dma_chan
;
138 static void __iomem
*omap_dma_base
;
140 static const u8 omap1_dma_irq
[OMAP1_LOGICAL_DMA_CH_COUNT
] = {
141 INT_DMA_CH0_6
, INT_DMA_CH1_7
, INT_DMA_CH2_8
, INT_DMA_CH3
,
142 INT_DMA_CH4
, INT_DMA_CH5
, INT_1610_DMA_CH6
, INT_1610_DMA_CH7
,
143 INT_1610_DMA_CH8
, INT_1610_DMA_CH9
, INT_1610_DMA_CH10
,
144 INT_1610_DMA_CH11
, INT_1610_DMA_CH12
, INT_1610_DMA_CH13
,
145 INT_1610_DMA_CH14
, INT_1610_DMA_CH15
, INT_DMA_LCD
148 static inline void disable_lnk(int lch
);
149 static void omap_disable_channel_irq(int lch
);
150 static inline void omap_enable_channel_irq(int lch
);
152 #define REVISIT_24XX() printk(KERN_ERR "FIXME: no %s on 24xx\n", \
155 #define dma_read(reg) \
158 if (cpu_class_is_omap1()) \
159 __val = __raw_readw(omap_dma_base + OMAP1_DMA_##reg); \
161 __val = __raw_readl(omap_dma_base + OMAP_DMA4_##reg); \
165 #define dma_write(val, reg) \
167 if (cpu_class_is_omap1()) \
168 __raw_writew((u16)(val), omap_dma_base + OMAP1_DMA_##reg); \
170 __raw_writel((val), omap_dma_base + OMAP_DMA4_##reg); \
173 #ifdef CONFIG_ARCH_OMAP15XX
174 /* Returns 1 if the DMA module is in OMAP1510-compatible mode, 0 otherwise */
175 int omap_dma_in_1510_mode(void)
177 return enable_1510_mode
;
180 #define omap_dma_in_1510_mode() 0
183 #ifdef CONFIG_ARCH_OMAP1
184 static inline int get_gdma_dev(int req
)
186 u32 reg
= OMAP_FUNC_MUX_ARM_BASE
+ ((req
- 1) / 5) * 4;
187 int shift
= ((req
- 1) % 5) * 6;
189 return ((omap_readl(reg
) >> shift
) & 0x3f) + 1;
192 static inline void set_gdma_dev(int req
, int dev
)
194 u32 reg
= OMAP_FUNC_MUX_ARM_BASE
+ ((req
- 1) / 5) * 4;
195 int shift
= ((req
- 1) % 5) * 6;
199 l
&= ~(0x3f << shift
);
200 l
|= (dev
- 1) << shift
;
204 #define set_gdma_dev(req, dev) do {} while (0)
208 static void clear_lch_regs(int lch
)
211 void __iomem
*lch_base
= omap_dma_base
+ OMAP1_DMA_CH_BASE(lch
);
213 for (i
= 0; i
< 0x2c; i
+= 2)
214 __raw_writew(0, lch_base
+ i
);
217 void omap_set_dma_priority(int lch
, int dst_port
, int priority
)
222 if (cpu_class_is_omap1()) {
224 case OMAP_DMA_PORT_OCP_T1
: /* FFFECC00 */
225 reg
= OMAP_TC_OCPT1_PRIOR
;
227 case OMAP_DMA_PORT_OCP_T2
: /* FFFECCD0 */
228 reg
= OMAP_TC_OCPT2_PRIOR
;
230 case OMAP_DMA_PORT_EMIFF
: /* FFFECC08 */
231 reg
= OMAP_TC_EMIFF_PRIOR
;
233 case OMAP_DMA_PORT_EMIFS
: /* FFFECC04 */
234 reg
= OMAP_TC_EMIFS_PRIOR
;
242 l
|= (priority
& 0xf) << 8;
246 if (cpu_class_is_omap2()) {
249 ccr
= dma_read(CCR(lch
));
254 dma_write(ccr
, CCR(lch
));
257 EXPORT_SYMBOL(omap_set_dma_priority
);
259 void omap_set_dma_transfer_params(int lch
, int data_type
, int elem_count
,
260 int frame_count
, int sync_mode
,
261 int dma_trigger
, int src_or_dst_synch
)
265 l
= dma_read(CSDP(lch
));
268 dma_write(l
, CSDP(lch
));
270 if (cpu_class_is_omap1()) {
273 ccr
= dma_read(CCR(lch
));
275 if (sync_mode
== OMAP_DMA_SYNC_FRAME
)
277 dma_write(ccr
, CCR(lch
));
279 ccr
= dma_read(CCR2(lch
));
281 if (sync_mode
== OMAP_DMA_SYNC_BLOCK
)
283 dma_write(ccr
, CCR2(lch
));
286 if (cpu_class_is_omap2() && dma_trigger
) {
289 val
= dma_read(CCR(lch
));
291 /* DMA_SYNCHRO_CONTROL_UPPER depends on the channel number */
292 val
&= ~((3 << 19) | 0x1f);
293 val
|= (dma_trigger
& ~0x1f) << 14;
294 val
|= dma_trigger
& 0x1f;
296 if (sync_mode
& OMAP_DMA_SYNC_FRAME
)
301 if (sync_mode
& OMAP_DMA_SYNC_BLOCK
)
306 if (src_or_dst_synch
)
307 val
|= 1 << 24; /* source synch */
309 val
&= ~(1 << 24); /* dest synch */
311 dma_write(val
, CCR(lch
));
314 dma_write(elem_count
, CEN(lch
));
315 dma_write(frame_count
, CFN(lch
));
317 EXPORT_SYMBOL(omap_set_dma_transfer_params
);
319 void omap_set_dma_color_mode(int lch
, enum omap_dma_color_mode mode
, u32 color
)
321 BUG_ON(omap_dma_in_1510_mode());
323 if (cpu_class_is_omap1()) {
326 w
= dma_read(CCR2(lch
));
330 case OMAP_DMA_CONSTANT_FILL
:
333 case OMAP_DMA_TRANSPARENT_COPY
:
336 case OMAP_DMA_COLOR_DIS
:
341 dma_write(w
, CCR2(lch
));
343 w
= dma_read(LCH_CTRL(lch
));
345 /* Default is channel type 2D */
347 dma_write((u16
)color
, COLOR_L(lch
));
348 dma_write((u16
)(color
>> 16), COLOR_U(lch
));
349 w
|= 1; /* Channel type G */
351 dma_write(w
, LCH_CTRL(lch
));
354 if (cpu_class_is_omap2()) {
357 val
= dma_read(CCR(lch
));
358 val
&= ~((1 << 17) | (1 << 16));
361 case OMAP_DMA_CONSTANT_FILL
:
364 case OMAP_DMA_TRANSPARENT_COPY
:
367 case OMAP_DMA_COLOR_DIS
:
372 dma_write(val
, CCR(lch
));
375 dma_write(color
, COLOR(lch
));
378 EXPORT_SYMBOL(omap_set_dma_color_mode
);
380 void omap_set_dma_write_mode(int lch
, enum omap_dma_write_mode mode
)
382 if (cpu_class_is_omap2()) {
385 csdp
= dma_read(CSDP(lch
));
386 csdp
&= ~(0x3 << 16);
387 csdp
|= (mode
<< 16);
388 dma_write(csdp
, CSDP(lch
));
391 EXPORT_SYMBOL(omap_set_dma_write_mode
);
393 void omap_set_dma_channel_mode(int lch
, enum omap_dma_channel_mode mode
)
395 if (cpu_class_is_omap1() && !cpu_is_omap15xx()) {
398 l
= dma_read(LCH_CTRL(lch
));
401 dma_write(l
, LCH_CTRL(lch
));
404 EXPORT_SYMBOL(omap_set_dma_channel_mode
);
406 /* Note that src_port is only for omap1 */
407 void omap_set_dma_src_params(int lch
, int src_port
, int src_amode
,
408 unsigned long src_start
,
409 int src_ei
, int src_fi
)
413 if (cpu_class_is_omap1()) {
416 w
= dma_read(CSDP(lch
));
419 dma_write(w
, CSDP(lch
));
422 l
= dma_read(CCR(lch
));
424 l
|= src_amode
<< 12;
425 dma_write(l
, CCR(lch
));
427 if (cpu_class_is_omap1()) {
428 dma_write(src_start
>> 16, CSSA_U(lch
));
429 dma_write((u16
)src_start
, CSSA_L(lch
));
432 if (cpu_class_is_omap2())
433 dma_write(src_start
, CSSA(lch
));
435 dma_write(src_ei
, CSEI(lch
));
436 dma_write(src_fi
, CSFI(lch
));
438 EXPORT_SYMBOL(omap_set_dma_src_params
);
440 void omap_set_dma_params(int lch
, struct omap_dma_channel_params
*params
)
442 omap_set_dma_transfer_params(lch
, params
->data_type
,
443 params
->elem_count
, params
->frame_count
,
444 params
->sync_mode
, params
->trigger
,
445 params
->src_or_dst_synch
);
446 omap_set_dma_src_params(lch
, params
->src_port
,
447 params
->src_amode
, params
->src_start
,
448 params
->src_ei
, params
->src_fi
);
450 omap_set_dma_dest_params(lch
, params
->dst_port
,
451 params
->dst_amode
, params
->dst_start
,
452 params
->dst_ei
, params
->dst_fi
);
453 if (params
->read_prio
|| params
->write_prio
)
454 omap_dma_set_prio_lch(lch
, params
->read_prio
,
457 EXPORT_SYMBOL(omap_set_dma_params
);
459 void omap_set_dma_src_index(int lch
, int eidx
, int fidx
)
461 if (cpu_class_is_omap2())
464 dma_write(eidx
, CSEI(lch
));
465 dma_write(fidx
, CSFI(lch
));
467 EXPORT_SYMBOL(omap_set_dma_src_index
);
469 void omap_set_dma_src_data_pack(int lch
, int enable
)
473 l
= dma_read(CSDP(lch
));
477 dma_write(l
, CSDP(lch
));
479 EXPORT_SYMBOL(omap_set_dma_src_data_pack
);
481 void omap_set_dma_src_burst_mode(int lch
, enum omap_dma_burst_mode burst_mode
)
483 unsigned int burst
= 0;
486 l
= dma_read(CSDP(lch
));
489 switch (burst_mode
) {
490 case OMAP_DMA_DATA_BURST_DIS
:
492 case OMAP_DMA_DATA_BURST_4
:
493 if (cpu_class_is_omap2())
498 case OMAP_DMA_DATA_BURST_8
:
499 if (cpu_class_is_omap2()) {
503 /* not supported by current hardware on OMAP1
507 case OMAP_DMA_DATA_BURST_16
:
508 if (cpu_class_is_omap2()) {
512 /* OMAP1 don't support burst 16
520 dma_write(l
, CSDP(lch
));
522 EXPORT_SYMBOL(omap_set_dma_src_burst_mode
);
524 /* Note that dest_port is only for OMAP1 */
525 void omap_set_dma_dest_params(int lch
, int dest_port
, int dest_amode
,
526 unsigned long dest_start
,
527 int dst_ei
, int dst_fi
)
531 if (cpu_class_is_omap1()) {
532 l
= dma_read(CSDP(lch
));
535 dma_write(l
, CSDP(lch
));
538 l
= dma_read(CCR(lch
));
540 l
|= dest_amode
<< 14;
541 dma_write(l
, CCR(lch
));
543 if (cpu_class_is_omap1()) {
544 dma_write(dest_start
>> 16, CDSA_U(lch
));
545 dma_write(dest_start
, CDSA_L(lch
));
548 if (cpu_class_is_omap2())
549 dma_write(dest_start
, CDSA(lch
));
551 dma_write(dst_ei
, CDEI(lch
));
552 dma_write(dst_fi
, CDFI(lch
));
554 EXPORT_SYMBOL(omap_set_dma_dest_params
);
556 void omap_set_dma_dest_index(int lch
, int eidx
, int fidx
)
558 if (cpu_class_is_omap2())
561 dma_write(eidx
, CDEI(lch
));
562 dma_write(fidx
, CDFI(lch
));
564 EXPORT_SYMBOL(omap_set_dma_dest_index
);
566 void omap_set_dma_dest_data_pack(int lch
, int enable
)
570 l
= dma_read(CSDP(lch
));
574 dma_write(l
, CSDP(lch
));
576 EXPORT_SYMBOL(omap_set_dma_dest_data_pack
);
578 void omap_set_dma_dest_burst_mode(int lch
, enum omap_dma_burst_mode burst_mode
)
580 unsigned int burst
= 0;
583 l
= dma_read(CSDP(lch
));
586 switch (burst_mode
) {
587 case OMAP_DMA_DATA_BURST_DIS
:
589 case OMAP_DMA_DATA_BURST_4
:
590 if (cpu_class_is_omap2())
595 case OMAP_DMA_DATA_BURST_8
:
596 if (cpu_class_is_omap2())
601 case OMAP_DMA_DATA_BURST_16
:
602 if (cpu_class_is_omap2()) {
606 /* OMAP1 don't support burst 16
610 printk(KERN_ERR
"Invalid DMA burst mode\n");
615 dma_write(l
, CSDP(lch
));
617 EXPORT_SYMBOL(omap_set_dma_dest_burst_mode
);
619 static inline void omap_enable_channel_irq(int lch
)
624 if (cpu_class_is_omap1())
625 status
= dma_read(CSR(lch
));
626 else if (cpu_class_is_omap2())
627 dma_write(OMAP2_DMA_CSR_CLEAR_MASK
, CSR(lch
));
629 /* Enable some nice interrupts. */
630 dma_write(dma_chan
[lch
].enabled_irqs
, CICR(lch
));
633 static void omap_disable_channel_irq(int lch
)
635 if (cpu_class_is_omap2())
636 dma_write(0, CICR(lch
));
639 void omap_enable_dma_irq(int lch
, u16 bits
)
641 dma_chan
[lch
].enabled_irqs
|= bits
;
643 EXPORT_SYMBOL(omap_enable_dma_irq
);
645 void omap_disable_dma_irq(int lch
, u16 bits
)
647 dma_chan
[lch
].enabled_irqs
&= ~bits
;
649 EXPORT_SYMBOL(omap_disable_dma_irq
);
651 static inline void enable_lnk(int lch
)
655 l
= dma_read(CLNK_CTRL(lch
));
657 if (cpu_class_is_omap1())
660 /* Set the ENABLE_LNK bits */
661 if (dma_chan
[lch
].next_lch
!= -1)
662 l
= dma_chan
[lch
].next_lch
| (1 << 15);
664 #ifndef CONFIG_ARCH_OMAP1
665 if (cpu_class_is_omap2())
666 if (dma_chan
[lch
].next_linked_ch
!= -1)
667 l
= dma_chan
[lch
].next_linked_ch
| (1 << 15);
670 dma_write(l
, CLNK_CTRL(lch
));
673 static inline void disable_lnk(int lch
)
677 l
= dma_read(CLNK_CTRL(lch
));
679 /* Disable interrupts */
680 if (cpu_class_is_omap1()) {
681 dma_write(0, CICR(lch
));
682 /* Set the STOP_LNK bit */
686 if (cpu_class_is_omap2()) {
687 omap_disable_channel_irq(lch
);
688 /* Clear the ENABLE_LNK bit */
692 dma_write(l
, CLNK_CTRL(lch
));
693 dma_chan
[lch
].flags
&= ~OMAP_DMA_ACTIVE
;
696 static inline void omap2_enable_irq_lch(int lch
)
701 if (!cpu_class_is_omap2())
704 spin_lock_irqsave(&dma_chan_lock
, flags
);
705 val
= dma_read(IRQENABLE_L0
);
707 dma_write(val
, IRQENABLE_L0
);
708 spin_unlock_irqrestore(&dma_chan_lock
, flags
);
711 int omap_request_dma(int dev_id
, const char *dev_name
,
712 void (*callback
)(int lch
, u16 ch_status
, void *data
),
713 void *data
, int *dma_ch_out
)
715 int ch
, free_ch
= -1;
717 struct omap_dma_lch
*chan
;
719 spin_lock_irqsave(&dma_chan_lock
, flags
);
720 for (ch
= 0; ch
< dma_chan_count
; ch
++) {
721 if (free_ch
== -1 && dma_chan
[ch
].dev_id
== -1) {
728 spin_unlock_irqrestore(&dma_chan_lock
, flags
);
731 chan
= dma_chan
+ free_ch
;
732 chan
->dev_id
= dev_id
;
734 if (cpu_class_is_omap1())
735 clear_lch_regs(free_ch
);
737 if (cpu_class_is_omap2())
738 omap_clear_dma(free_ch
);
740 spin_unlock_irqrestore(&dma_chan_lock
, flags
);
742 chan
->dev_name
= dev_name
;
743 chan
->callback
= callback
;
747 #ifndef CONFIG_ARCH_OMAP1
748 if (cpu_class_is_omap2()) {
750 chan
->next_linked_ch
= -1;
754 chan
->enabled_irqs
= OMAP_DMA_DROP_IRQ
| OMAP_DMA_BLOCK_IRQ
;
756 if (cpu_class_is_omap1())
757 chan
->enabled_irqs
|= OMAP1_DMA_TOUT_IRQ
;
758 else if (cpu_class_is_omap2())
759 chan
->enabled_irqs
|= OMAP2_DMA_MISALIGNED_ERR_IRQ
|
760 OMAP2_DMA_TRANS_ERR_IRQ
;
762 if (cpu_is_omap16xx()) {
763 /* If the sync device is set, configure it dynamically. */
765 set_gdma_dev(free_ch
+ 1, dev_id
);
766 dev_id
= free_ch
+ 1;
769 * Disable the 1510 compatibility mode and set the sync device
772 dma_write(dev_id
| (1 << 10), CCR(free_ch
));
773 } else if (cpu_is_omap7xx() || cpu_is_omap15xx()) {
774 dma_write(dev_id
, CCR(free_ch
));
777 if (cpu_class_is_omap2()) {
778 omap2_enable_irq_lch(free_ch
);
779 omap_enable_channel_irq(free_ch
);
780 /* Clear the CSR register and IRQ status register */
781 dma_write(OMAP2_DMA_CSR_CLEAR_MASK
, CSR(free_ch
));
782 dma_write(1 << free_ch
, IRQSTATUS_L0
);
785 *dma_ch_out
= free_ch
;
789 EXPORT_SYMBOL(omap_request_dma
);
791 void omap_free_dma(int lch
)
795 if (dma_chan
[lch
].dev_id
== -1) {
796 pr_err("omap_dma: trying to free unallocated DMA channel %d\n",
801 if (cpu_class_is_omap1()) {
802 /* Disable all DMA interrupts for the channel. */
803 dma_write(0, CICR(lch
));
804 /* Make sure the DMA transfer is stopped. */
805 dma_write(0, CCR(lch
));
808 if (cpu_class_is_omap2()) {
811 spin_lock_irqsave(&dma_chan_lock
, flags
);
812 /* Disable interrupts */
813 val
= dma_read(IRQENABLE_L0
);
815 dma_write(val
, IRQENABLE_L0
);
816 spin_unlock_irqrestore(&dma_chan_lock
, flags
);
818 /* Clear the CSR register and IRQ status register */
819 dma_write(OMAP2_DMA_CSR_CLEAR_MASK
, CSR(lch
));
820 dma_write(1 << lch
, IRQSTATUS_L0
);
822 /* Disable all DMA interrupts for the channel. */
823 dma_write(0, CICR(lch
));
825 /* Make sure the DMA transfer is stopped. */
826 dma_write(0, CCR(lch
));
830 spin_lock_irqsave(&dma_chan_lock
, flags
);
831 dma_chan
[lch
].dev_id
= -1;
832 dma_chan
[lch
].next_lch
= -1;
833 dma_chan
[lch
].callback
= NULL
;
834 spin_unlock_irqrestore(&dma_chan_lock
, flags
);
836 EXPORT_SYMBOL(omap_free_dma
);
839 * @brief omap_dma_set_global_params : Set global priority settings for dma
842 * @param max_fifo_depth
843 * @param tparams - Number of threads to reserve : DMA_THREAD_RESERVE_NORM
844 * DMA_THREAD_RESERVE_ONET
845 * DMA_THREAD_RESERVE_TWOT
846 * DMA_THREAD_RESERVE_THREET
849 omap_dma_set_global_params(int arb_rate
, int max_fifo_depth
, int tparams
)
853 if (!cpu_class_is_omap2()) {
854 printk(KERN_ERR
"FIXME: no %s on 15xx/16xx\n", __func__
);
858 if (max_fifo_depth
== 0)
863 reg
= 0xff & max_fifo_depth
;
864 reg
|= (0x3 & tparams
) << 12;
865 reg
|= (arb_rate
& 0xff) << 16;
869 EXPORT_SYMBOL(omap_dma_set_global_params
);
872 * @brief omap_dma_set_prio_lch : Set channel wise priority settings
875 * @param read_prio - Read priority
876 * @param write_prio - Write priority
877 * Both of the above can be set with one of the following values :
878 * DMA_CH_PRIO_HIGH/DMA_CH_PRIO_LOW
881 omap_dma_set_prio_lch(int lch
, unsigned char read_prio
,
882 unsigned char write_prio
)
886 if (unlikely((lch
< 0 || lch
>= dma_lch_count
))) {
887 printk(KERN_ERR
"Invalid channel id\n");
890 l
= dma_read(CCR(lch
));
891 l
&= ~((1 << 6) | (1 << 26));
892 if (cpu_is_omap2430() || cpu_is_omap34xx() || cpu_is_omap44xx())
893 l
|= ((read_prio
& 0x1) << 6) | ((write_prio
& 0x1) << 26);
895 l
|= ((read_prio
& 0x1) << 6);
897 dma_write(l
, CCR(lch
));
901 EXPORT_SYMBOL(omap_dma_set_prio_lch
);
904 * Clears any DMA state so the DMA engine is ready to restart with new buffers
905 * through omap_start_dma(). Any buffers in flight are discarded.
907 void omap_clear_dma(int lch
)
911 local_irq_save(flags
);
913 if (cpu_class_is_omap1()) {
916 l
= dma_read(CCR(lch
));
917 l
&= ~OMAP_DMA_CCR_EN
;
918 dma_write(l
, CCR(lch
));
920 /* Clear pending interrupts */
921 l
= dma_read(CSR(lch
));
924 if (cpu_class_is_omap2()) {
926 void __iomem
*lch_base
= omap_dma_base
+ OMAP_DMA4_CH_BASE(lch
);
927 for (i
= 0; i
< 0x44; i
+= 4)
928 __raw_writel(0, lch_base
+ i
);
931 local_irq_restore(flags
);
933 EXPORT_SYMBOL(omap_clear_dma
);
935 void omap_start_dma(int lch
)
939 if (!omap_dma_in_1510_mode() && dma_chan
[lch
].next_lch
!= -1) {
940 int next_lch
, cur_lch
;
941 char dma_chan_link_map
[OMAP_DMA4_LOGICAL_DMA_CH_COUNT
];
943 dma_chan_link_map
[lch
] = 1;
944 /* Set the link register of the first channel */
947 memset(dma_chan_link_map
, 0, sizeof(dma_chan_link_map
));
948 cur_lch
= dma_chan
[lch
].next_lch
;
950 next_lch
= dma_chan
[cur_lch
].next_lch
;
952 /* The loop case: we've been here already */
953 if (dma_chan_link_map
[cur_lch
])
955 /* Mark the current channel */
956 dma_chan_link_map
[cur_lch
] = 1;
959 omap_enable_channel_irq(cur_lch
);
962 } while (next_lch
!= -1);
963 } else if (cpu_is_omap242x() ||
964 (cpu_is_omap243x() && omap_type() <= OMAP2430_REV_ES1_0
)) {
966 /* Errata: Need to write lch even if not using chaining */
967 dma_write(lch
, CLNK_CTRL(lch
));
970 omap_enable_channel_irq(lch
);
972 l
= dma_read(CCR(lch
));
975 * Errata: On ES2.0 BUFFERING disable must be set.
976 * This will always fail on ES1.0
978 if (cpu_is_omap24xx())
979 l
|= OMAP_DMA_CCR_EN
;
981 l
|= OMAP_DMA_CCR_EN
;
982 dma_write(l
, CCR(lch
));
984 dma_chan
[lch
].flags
|= OMAP_DMA_ACTIVE
;
986 EXPORT_SYMBOL(omap_start_dma
);
988 void omap_stop_dma(int lch
)
992 /* Disable all interrupts on the channel */
993 if (cpu_class_is_omap1())
994 dma_write(0, CICR(lch
));
996 l
= dma_read(CCR(lch
));
997 l
&= ~OMAP_DMA_CCR_EN
;
998 dma_write(l
, CCR(lch
));
1000 if (!omap_dma_in_1510_mode() && dma_chan
[lch
].next_lch
!= -1) {
1001 int next_lch
, cur_lch
= lch
;
1002 char dma_chan_link_map
[OMAP_DMA4_LOGICAL_DMA_CH_COUNT
];
1004 memset(dma_chan_link_map
, 0, sizeof(dma_chan_link_map
));
1006 /* The loop case: we've been here already */
1007 if (dma_chan_link_map
[cur_lch
])
1009 /* Mark the current channel */
1010 dma_chan_link_map
[cur_lch
] = 1;
1012 disable_lnk(cur_lch
);
1014 next_lch
= dma_chan
[cur_lch
].next_lch
;
1016 } while (next_lch
!= -1);
1019 dma_chan
[lch
].flags
&= ~OMAP_DMA_ACTIVE
;
1021 EXPORT_SYMBOL(omap_stop_dma
);
1024 * Allows changing the DMA callback function or data. This may be needed if
1025 * the driver shares a single DMA channel for multiple dma triggers.
1027 int omap_set_dma_callback(int lch
,
1028 void (*callback
)(int lch
, u16 ch_status
, void *data
),
1031 unsigned long flags
;
1036 spin_lock_irqsave(&dma_chan_lock
, flags
);
1037 if (dma_chan
[lch
].dev_id
== -1) {
1038 printk(KERN_ERR
"DMA callback for not set for free channel\n");
1039 spin_unlock_irqrestore(&dma_chan_lock
, flags
);
1042 dma_chan
[lch
].callback
= callback
;
1043 dma_chan
[lch
].data
= data
;
1044 spin_unlock_irqrestore(&dma_chan_lock
, flags
);
1048 EXPORT_SYMBOL(omap_set_dma_callback
);
1051 * Returns current physical source address for the given DMA channel.
1052 * If the channel is running the caller must disable interrupts prior calling
1053 * this function and process the returned value before re-enabling interrupt to
1054 * prevent races with the interrupt handler. Note that in continuous mode there
1055 * is a chance for CSSA_L register overflow inbetween the two reads resulting
1056 * in incorrect return value.
1058 dma_addr_t
omap_get_dma_src_pos(int lch
)
1060 dma_addr_t offset
= 0;
1062 if (cpu_is_omap15xx())
1063 offset
= dma_read(CPC(lch
));
1065 offset
= dma_read(CSAC(lch
));
1068 * omap 3.2/3.3 erratum: sometimes 0 is returned if CSAC/CDAC is
1069 * read before the DMA controller finished disabling the channel.
1071 if (!cpu_is_omap15xx() && offset
== 0)
1072 offset
= dma_read(CSAC(lch
));
1074 if (cpu_class_is_omap1())
1075 offset
|= (dma_read(CSSA_U(lch
)) << 16);
1079 EXPORT_SYMBOL(omap_get_dma_src_pos
);
1082 * Returns current physical destination address for the given DMA channel.
1083 * If the channel is running the caller must disable interrupts prior calling
1084 * this function and process the returned value before re-enabling interrupt to
1085 * prevent races with the interrupt handler. Note that in continuous mode there
1086 * is a chance for CDSA_L register overflow inbetween the two reads resulting
1087 * in incorrect return value.
1089 dma_addr_t
omap_get_dma_dst_pos(int lch
)
1091 dma_addr_t offset
= 0;
1093 if (cpu_is_omap15xx())
1094 offset
= dma_read(CPC(lch
));
1096 offset
= dma_read(CDAC(lch
));
1099 * omap 3.2/3.3 erratum: sometimes 0 is returned if CSAC/CDAC is
1100 * read before the DMA controller finished disabling the channel.
1102 if (!cpu_is_omap15xx() && offset
== 0)
1103 offset
= dma_read(CDAC(lch
));
1105 if (cpu_class_is_omap1())
1106 offset
|= (dma_read(CDSA_U(lch
)) << 16);
1110 EXPORT_SYMBOL(omap_get_dma_dst_pos
);
1112 int omap_get_dma_active_status(int lch
)
1114 return (dma_read(CCR(lch
)) & OMAP_DMA_CCR_EN
) != 0;
1116 EXPORT_SYMBOL(omap_get_dma_active_status
);
1118 int omap_dma_running(void)
1122 if (cpu_class_is_omap1())
1123 if (omap_lcd_dma_running())
1126 for (lch
= 0; lch
< dma_chan_count
; lch
++)
1127 if (dma_read(CCR(lch
)) & OMAP_DMA_CCR_EN
)
1134 * lch_queue DMA will start right after lch_head one is finished.
1135 * For this DMA link to start, you still need to start (see omap_start_dma)
1136 * the first one. That will fire up the entire queue.
1138 void omap_dma_link_lch(int lch_head
, int lch_queue
)
1140 if (omap_dma_in_1510_mode()) {
1141 if (lch_head
== lch_queue
) {
1142 dma_write(dma_read(CCR(lch_head
)) | (3 << 8),
1146 printk(KERN_ERR
"DMA linking is not supported in 1510 mode\n");
1151 if ((dma_chan
[lch_head
].dev_id
== -1) ||
1152 (dma_chan
[lch_queue
].dev_id
== -1)) {
1153 printk(KERN_ERR
"omap_dma: trying to link "
1154 "non requested channels\n");
1158 dma_chan
[lch_head
].next_lch
= lch_queue
;
1160 EXPORT_SYMBOL(omap_dma_link_lch
);
1163 * Once the DMA queue is stopped, we can destroy it.
1165 void omap_dma_unlink_lch(int lch_head
, int lch_queue
)
1167 if (omap_dma_in_1510_mode()) {
1168 if (lch_head
== lch_queue
) {
1169 dma_write(dma_read(CCR(lch_head
)) & ~(3 << 8),
1173 printk(KERN_ERR
"DMA linking is not supported in 1510 mode\n");
1178 if (dma_chan
[lch_head
].next_lch
!= lch_queue
||
1179 dma_chan
[lch_head
].next_lch
== -1) {
1180 printk(KERN_ERR
"omap_dma: trying to unlink "
1181 "non linked channels\n");
1185 if ((dma_chan
[lch_head
].flags
& OMAP_DMA_ACTIVE
) ||
1186 (dma_chan
[lch_queue
].flags
& OMAP_DMA_ACTIVE
)) {
1187 printk(KERN_ERR
"omap_dma: You need to stop the DMA channels "
1188 "before unlinking\n");
1192 dma_chan
[lch_head
].next_lch
= -1;
1194 EXPORT_SYMBOL(omap_dma_unlink_lch
);
1196 /*----------------------------------------------------------------------------*/
1198 #ifndef CONFIG_ARCH_OMAP1
1199 /* Create chain of DMA channesls */
1200 static void create_dma_lch_chain(int lch_head
, int lch_queue
)
1204 /* Check if this is the first link in chain */
1205 if (dma_chan
[lch_head
].next_linked_ch
== -1) {
1206 dma_chan
[lch_head
].next_linked_ch
= lch_queue
;
1207 dma_chan
[lch_head
].prev_linked_ch
= lch_queue
;
1208 dma_chan
[lch_queue
].next_linked_ch
= lch_head
;
1209 dma_chan
[lch_queue
].prev_linked_ch
= lch_head
;
1212 /* a link exists, link the new channel in circular chain */
1214 dma_chan
[lch_queue
].next_linked_ch
=
1215 dma_chan
[lch_head
].next_linked_ch
;
1216 dma_chan
[lch_queue
].prev_linked_ch
= lch_head
;
1217 dma_chan
[lch_head
].next_linked_ch
= lch_queue
;
1218 dma_chan
[dma_chan
[lch_queue
].next_linked_ch
].prev_linked_ch
=
1222 l
= dma_read(CLNK_CTRL(lch_head
));
1225 dma_write(l
, CLNK_CTRL(lch_head
));
1227 l
= dma_read(CLNK_CTRL(lch_queue
));
1229 l
|= (dma_chan
[lch_queue
].next_linked_ch
);
1230 dma_write(l
, CLNK_CTRL(lch_queue
));
1234 * @brief omap_request_dma_chain : Request a chain of DMA channels
1236 * @param dev_id - Device id using the dma channel
1237 * @param dev_name - Device name
1238 * @param callback - Call back function
1240 * @no_of_chans - Number of channels requested
1241 * @chain_mode - Dynamic or static chaining : OMAP_DMA_STATIC_CHAIN
1242 * OMAP_DMA_DYNAMIC_CHAIN
1243 * @params - Channel parameters
1245 * @return - Success : 0
1246 * Failure: -EINVAL/-ENOMEM
1248 int omap_request_dma_chain(int dev_id
, const char *dev_name
,
1249 void (*callback
) (int lch
, u16 ch_status
,
1251 int *chain_id
, int no_of_chans
, int chain_mode
,
1252 struct omap_dma_channel_params params
)
1257 /* Is the chain mode valid ? */
1258 if (chain_mode
!= OMAP_DMA_STATIC_CHAIN
1259 && chain_mode
!= OMAP_DMA_DYNAMIC_CHAIN
) {
1260 printk(KERN_ERR
"Invalid chain mode requested\n");
1264 if (unlikely((no_of_chans
< 1
1265 || no_of_chans
> dma_lch_count
))) {
1266 printk(KERN_ERR
"Invalid Number of channels requested\n");
1270 /* Allocate a queue to maintain the status of the channels
1272 channels
= kmalloc(sizeof(*channels
) * no_of_chans
, GFP_KERNEL
);
1273 if (channels
== NULL
) {
1274 printk(KERN_ERR
"omap_dma: No memory for channel queue\n");
1278 /* request and reserve DMA channels for the chain */
1279 for (i
= 0; i
< no_of_chans
; i
++) {
1280 err
= omap_request_dma(dev_id
, dev_name
,
1281 callback
, NULL
, &channels
[i
]);
1284 for (j
= 0; j
< i
; j
++)
1285 omap_free_dma(channels
[j
]);
1287 printk(KERN_ERR
"omap_dma: Request failed %d\n", err
);
1290 dma_chan
[channels
[i
]].prev_linked_ch
= -1;
1291 dma_chan
[channels
[i
]].state
= DMA_CH_NOTSTARTED
;
1294 * Allowing client drivers to set common parameters now,
1295 * so that later only relevant (src_start, dest_start
1296 * and element count) can be set
1298 omap_set_dma_params(channels
[i
], ¶ms
);
1301 *chain_id
= channels
[0];
1302 dma_linked_lch
[*chain_id
].linked_dmach_q
= channels
;
1303 dma_linked_lch
[*chain_id
].chain_mode
= chain_mode
;
1304 dma_linked_lch
[*chain_id
].chain_state
= DMA_CHAIN_NOTSTARTED
;
1305 dma_linked_lch
[*chain_id
].no_of_lchs_linked
= no_of_chans
;
1307 for (i
= 0; i
< no_of_chans
; i
++)
1308 dma_chan
[channels
[i
]].chain_id
= *chain_id
;
1310 /* Reset the Queue pointers */
1311 OMAP_DMA_CHAIN_QINIT(*chain_id
);
1313 /* Set up the chain */
1314 if (no_of_chans
== 1)
1315 create_dma_lch_chain(channels
[0], channels
[0]);
1317 for (i
= 0; i
< (no_of_chans
- 1); i
++)
1318 create_dma_lch_chain(channels
[i
], channels
[i
+ 1]);
1323 EXPORT_SYMBOL(omap_request_dma_chain
);
1326 * @brief omap_modify_dma_chain_param : Modify the chain's params - Modify the
1327 * params after setting it. Dont do this while dma is running!!
1329 * @param chain_id - Chained logical channel id.
1332 * @return - Success : 0
1335 int omap_modify_dma_chain_params(int chain_id
,
1336 struct omap_dma_channel_params params
)
1341 /* Check for input params */
1342 if (unlikely((chain_id
< 0
1343 || chain_id
>= dma_lch_count
))) {
1344 printk(KERN_ERR
"Invalid chain id\n");
1348 /* Check if the chain exists */
1349 if (dma_linked_lch
[chain_id
].linked_dmach_q
== NULL
) {
1350 printk(KERN_ERR
"Chain doesn't exists\n");
1353 channels
= dma_linked_lch
[chain_id
].linked_dmach_q
;
1355 for (i
= 0; i
< dma_linked_lch
[chain_id
].no_of_lchs_linked
; i
++) {
1357 * Allowing client drivers to set common parameters now,
1358 * so that later only relevant (src_start, dest_start
1359 * and element count) can be set
1361 omap_set_dma_params(channels
[i
], ¶ms
);
1366 EXPORT_SYMBOL(omap_modify_dma_chain_params
);
1369 * @brief omap_free_dma_chain - Free all the logical channels in a chain.
1373 * @return - Success : 0
1376 int omap_free_dma_chain(int chain_id
)
1381 /* Check for input params */
1382 if (unlikely((chain_id
< 0 || chain_id
>= dma_lch_count
))) {
1383 printk(KERN_ERR
"Invalid chain id\n");
1387 /* Check if the chain exists */
1388 if (dma_linked_lch
[chain_id
].linked_dmach_q
== NULL
) {
1389 printk(KERN_ERR
"Chain doesn't exists\n");
1393 channels
= dma_linked_lch
[chain_id
].linked_dmach_q
;
1394 for (i
= 0; i
< dma_linked_lch
[chain_id
].no_of_lchs_linked
; i
++) {
1395 dma_chan
[channels
[i
]].next_linked_ch
= -1;
1396 dma_chan
[channels
[i
]].prev_linked_ch
= -1;
1397 dma_chan
[channels
[i
]].chain_id
= -1;
1398 dma_chan
[channels
[i
]].state
= DMA_CH_NOTSTARTED
;
1399 omap_free_dma(channels
[i
]);
1404 dma_linked_lch
[chain_id
].linked_dmach_q
= NULL
;
1405 dma_linked_lch
[chain_id
].chain_mode
= -1;
1406 dma_linked_lch
[chain_id
].chain_state
= -1;
1410 EXPORT_SYMBOL(omap_free_dma_chain
);
1413 * @brief omap_dma_chain_status - Check if the chain is in
1414 * active / inactive state.
1417 * @return - Success : OMAP_DMA_CHAIN_ACTIVE/OMAP_DMA_CHAIN_INACTIVE
1420 int omap_dma_chain_status(int chain_id
)
1422 /* Check for input params */
1423 if (unlikely((chain_id
< 0 || chain_id
>= dma_lch_count
))) {
1424 printk(KERN_ERR
"Invalid chain id\n");
1428 /* Check if the chain exists */
1429 if (dma_linked_lch
[chain_id
].linked_dmach_q
== NULL
) {
1430 printk(KERN_ERR
"Chain doesn't exists\n");
1433 pr_debug("CHAINID=%d, qcnt=%d\n", chain_id
,
1434 dma_linked_lch
[chain_id
].q_count
);
1436 if (OMAP_DMA_CHAIN_QEMPTY(chain_id
))
1437 return OMAP_DMA_CHAIN_INACTIVE
;
1439 return OMAP_DMA_CHAIN_ACTIVE
;
1441 EXPORT_SYMBOL(omap_dma_chain_status
);
1444 * @brief omap_dma_chain_a_transfer - Get a free channel from a chain,
1445 * set the params and start the transfer.
1448 * @param src_start - buffer start address
1449 * @param dest_start - Dest address
1451 * @param frame_count
1452 * @param callbk_data - channel callback parameter data.
1454 * @return - Success : 0
1455 * Failure: -EINVAL/-EBUSY
1457 int omap_dma_chain_a_transfer(int chain_id
, int src_start
, int dest_start
,
1458 int elem_count
, int frame_count
, void *callbk_data
)
1465 * if buffer size is less than 1 then there is
1466 * no use of starting the chain
1468 if (elem_count
< 1) {
1469 printk(KERN_ERR
"Invalid buffer size\n");
1473 /* Check for input params */
1474 if (unlikely((chain_id
< 0
1475 || chain_id
>= dma_lch_count
))) {
1476 printk(KERN_ERR
"Invalid chain id\n");
1480 /* Check if the chain exists */
1481 if (dma_linked_lch
[chain_id
].linked_dmach_q
== NULL
) {
1482 printk(KERN_ERR
"Chain doesn't exist\n");
1486 /* Check if all the channels in chain are in use */
1487 if (OMAP_DMA_CHAIN_QFULL(chain_id
))
1490 /* Frame count may be negative in case of indexed transfers */
1491 channels
= dma_linked_lch
[chain_id
].linked_dmach_q
;
1493 /* Get a free channel */
1494 lch
= channels
[dma_linked_lch
[chain_id
].q_tail
];
1496 /* Store the callback data */
1497 dma_chan
[lch
].data
= callbk_data
;
1499 /* Increment the q_tail */
1500 OMAP_DMA_CHAIN_INCQTAIL(chain_id
);
1502 /* Set the params to the free channel */
1504 dma_write(src_start
, CSSA(lch
));
1505 if (dest_start
!= 0)
1506 dma_write(dest_start
, CDSA(lch
));
1508 /* Write the buffer size */
1509 dma_write(elem_count
, CEN(lch
));
1510 dma_write(frame_count
, CFN(lch
));
1513 * If the chain is dynamically linked,
1514 * then we may have to start the chain if its not active
1516 if (dma_linked_lch
[chain_id
].chain_mode
== OMAP_DMA_DYNAMIC_CHAIN
) {
1519 * In Dynamic chain, if the chain is not started,
1522 if (dma_linked_lch
[chain_id
].chain_state
==
1523 DMA_CHAIN_NOTSTARTED
) {
1524 /* Enable the link in previous channel */
1525 if (dma_chan
[dma_chan
[lch
].prev_linked_ch
].state
==
1527 enable_lnk(dma_chan
[lch
].prev_linked_ch
);
1528 dma_chan
[lch
].state
= DMA_CH_QUEUED
;
1532 * Chain is already started, make sure its active,
1533 * if not then start the chain
1538 if (dma_chan
[dma_chan
[lch
].prev_linked_ch
].state
==
1540 enable_lnk(dma_chan
[lch
].prev_linked_ch
);
1541 dma_chan
[lch
].state
= DMA_CH_QUEUED
;
1543 if (0 == ((1 << 7) & dma_read(
1544 CCR(dma_chan
[lch
].prev_linked_ch
)))) {
1545 disable_lnk(dma_chan
[lch
].
1547 pr_debug("\n prev ch is stopped\n");
1552 else if (dma_chan
[dma_chan
[lch
].prev_linked_ch
].state
1554 enable_lnk(dma_chan
[lch
].prev_linked_ch
);
1555 dma_chan
[lch
].state
= DMA_CH_QUEUED
;
1558 omap_enable_channel_irq(lch
);
1560 l
= dma_read(CCR(lch
));
1562 if ((0 == (l
& (1 << 24))))
1566 if (start_dma
== 1) {
1567 if (0 == (l
& (1 << 7))) {
1569 dma_chan
[lch
].state
= DMA_CH_STARTED
;
1570 pr_debug("starting %d\n", lch
);
1571 dma_write(l
, CCR(lch
));
1575 if (0 == (l
& (1 << 7)))
1576 dma_write(l
, CCR(lch
));
1578 dma_chan
[lch
].flags
|= OMAP_DMA_ACTIVE
;
1584 EXPORT_SYMBOL(omap_dma_chain_a_transfer
);
1587 * @brief omap_start_dma_chain_transfers - Start the chain
1591 * @return - Success : 0
1592 * Failure : -EINVAL/-EBUSY
1594 int omap_start_dma_chain_transfers(int chain_id
)
1599 if (unlikely((chain_id
< 0 || chain_id
>= dma_lch_count
))) {
1600 printk(KERN_ERR
"Invalid chain id\n");
1604 channels
= dma_linked_lch
[chain_id
].linked_dmach_q
;
1606 if (dma_linked_lch
[channels
[0]].chain_state
== DMA_CHAIN_STARTED
) {
1607 printk(KERN_ERR
"Chain is already started\n");
1611 if (dma_linked_lch
[chain_id
].chain_mode
== OMAP_DMA_STATIC_CHAIN
) {
1612 for (i
= 0; i
< dma_linked_lch
[chain_id
].no_of_lchs_linked
;
1614 enable_lnk(channels
[i
]);
1615 omap_enable_channel_irq(channels
[i
]);
1618 omap_enable_channel_irq(channels
[0]);
1621 l
= dma_read(CCR(channels
[0]));
1623 dma_linked_lch
[chain_id
].chain_state
= DMA_CHAIN_STARTED
;
1624 dma_chan
[channels
[0]].state
= DMA_CH_STARTED
;
1626 if ((0 == (l
& (1 << 24))))
1630 dma_write(l
, CCR(channels
[0]));
1632 dma_chan
[channels
[0]].flags
|= OMAP_DMA_ACTIVE
;
1636 EXPORT_SYMBOL(omap_start_dma_chain_transfers
);
1639 * @brief omap_stop_dma_chain_transfers - Stop the dma transfer of a chain.
1643 * @return - Success : 0
1646 int omap_stop_dma_chain_transfers(int chain_id
)
1652 /* Check for input params */
1653 if (unlikely((chain_id
< 0 || chain_id
>= dma_lch_count
))) {
1654 printk(KERN_ERR
"Invalid chain id\n");
1658 /* Check if the chain exists */
1659 if (dma_linked_lch
[chain_id
].linked_dmach_q
== NULL
) {
1660 printk(KERN_ERR
"Chain doesn't exists\n");
1663 channels
= dma_linked_lch
[chain_id
].linked_dmach_q
;
1667 * Special programming model needed to disable DMA before end of block
1669 sys_cf
= dma_read(OCP_SYSCONFIG
);
1671 /* Middle mode reg set no Standby */
1672 l
&= ~((1 << 12)|(1 << 13));
1673 dma_write(l
, OCP_SYSCONFIG
);
1675 for (i
= 0; i
< dma_linked_lch
[chain_id
].no_of_lchs_linked
; i
++) {
1677 /* Stop the Channel transmission */
1678 l
= dma_read(CCR(channels
[i
]));
1680 dma_write(l
, CCR(channels
[i
]));
1682 /* Disable the link in all the channels */
1683 disable_lnk(channels
[i
]);
1684 dma_chan
[channels
[i
]].state
= DMA_CH_NOTSTARTED
;
1687 dma_linked_lch
[chain_id
].chain_state
= DMA_CHAIN_NOTSTARTED
;
1689 /* Reset the Queue pointers */
1690 OMAP_DMA_CHAIN_QINIT(chain_id
);
1692 /* Errata - put in the old value */
1693 dma_write(sys_cf
, OCP_SYSCONFIG
);
1697 EXPORT_SYMBOL(omap_stop_dma_chain_transfers
);
1699 /* Get the index of the ongoing DMA in chain */
1701 * @brief omap_get_dma_chain_index - Get the element and frame index
1702 * of the ongoing DMA in chain
1705 * @param ei - Element index
1706 * @param fi - Frame index
1708 * @return - Success : 0
1711 int omap_get_dma_chain_index(int chain_id
, int *ei
, int *fi
)
1716 /* Check for input params */
1717 if (unlikely((chain_id
< 0 || chain_id
>= dma_lch_count
))) {
1718 printk(KERN_ERR
"Invalid chain id\n");
1722 /* Check if the chain exists */
1723 if (dma_linked_lch
[chain_id
].linked_dmach_q
== NULL
) {
1724 printk(KERN_ERR
"Chain doesn't exists\n");
1730 channels
= dma_linked_lch
[chain_id
].linked_dmach_q
;
1732 /* Get the current channel */
1733 lch
= channels
[dma_linked_lch
[chain_id
].q_head
];
1735 *ei
= dma_read(CCEN(lch
));
1736 *fi
= dma_read(CCFN(lch
));
1740 EXPORT_SYMBOL(omap_get_dma_chain_index
);
1743 * @brief omap_get_dma_chain_dst_pos - Get the destination position of the
1744 * ongoing DMA in chain
1748 * @return - Success : Destination position
1751 int omap_get_dma_chain_dst_pos(int chain_id
)
1756 /* Check for input params */
1757 if (unlikely((chain_id
< 0 || chain_id
>= dma_lch_count
))) {
1758 printk(KERN_ERR
"Invalid chain id\n");
1762 /* Check if the chain exists */
1763 if (dma_linked_lch
[chain_id
].linked_dmach_q
== NULL
) {
1764 printk(KERN_ERR
"Chain doesn't exists\n");
1768 channels
= dma_linked_lch
[chain_id
].linked_dmach_q
;
1770 /* Get the current channel */
1771 lch
= channels
[dma_linked_lch
[chain_id
].q_head
];
1773 return dma_read(CDAC(lch
));
1775 EXPORT_SYMBOL(omap_get_dma_chain_dst_pos
);
1778 * @brief omap_get_dma_chain_src_pos - Get the source position
1779 * of the ongoing DMA in chain
1782 * @return - Success : Destination position
1785 int omap_get_dma_chain_src_pos(int chain_id
)
1790 /* Check for input params */
1791 if (unlikely((chain_id
< 0 || chain_id
>= dma_lch_count
))) {
1792 printk(KERN_ERR
"Invalid chain id\n");
1796 /* Check if the chain exists */
1797 if (dma_linked_lch
[chain_id
].linked_dmach_q
== NULL
) {
1798 printk(KERN_ERR
"Chain doesn't exists\n");
1802 channels
= dma_linked_lch
[chain_id
].linked_dmach_q
;
1804 /* Get the current channel */
1805 lch
= channels
[dma_linked_lch
[chain_id
].q_head
];
1807 return dma_read(CSAC(lch
));
1809 EXPORT_SYMBOL(omap_get_dma_chain_src_pos
);
1810 #endif /* ifndef CONFIG_ARCH_OMAP1 */
1812 /*----------------------------------------------------------------------------*/
1814 #ifdef CONFIG_ARCH_OMAP1
1816 static int omap1_dma_handle_ch(int ch
)
1820 if (enable_1510_mode
&& ch
>= 6) {
1821 csr
= dma_chan
[ch
].saved_csr
;
1822 dma_chan
[ch
].saved_csr
= 0;
1824 csr
= dma_read(CSR(ch
));
1825 if (enable_1510_mode
&& ch
<= 2 && (csr
>> 7) != 0) {
1826 dma_chan
[ch
+ 6].saved_csr
= csr
>> 7;
1829 if ((csr
& 0x3f) == 0)
1831 if (unlikely(dma_chan
[ch
].dev_id
== -1)) {
1832 printk(KERN_WARNING
"Spurious interrupt from DMA channel "
1833 "%d (CSR %04x)\n", ch
, csr
);
1836 if (unlikely(csr
& OMAP1_DMA_TOUT_IRQ
))
1837 printk(KERN_WARNING
"DMA timeout with device %d\n",
1838 dma_chan
[ch
].dev_id
);
1839 if (unlikely(csr
& OMAP_DMA_DROP_IRQ
))
1840 printk(KERN_WARNING
"DMA synchronization event drop occurred "
1841 "with device %d\n", dma_chan
[ch
].dev_id
);
1842 if (likely(csr
& OMAP_DMA_BLOCK_IRQ
))
1843 dma_chan
[ch
].flags
&= ~OMAP_DMA_ACTIVE
;
1844 if (likely(dma_chan
[ch
].callback
!= NULL
))
1845 dma_chan
[ch
].callback(ch
, csr
, dma_chan
[ch
].data
);
1850 static irqreturn_t
omap1_dma_irq_handler(int irq
, void *dev_id
)
1852 int ch
= ((int) dev_id
) - 1;
1856 int handled_now
= 0;
1858 handled_now
+= omap1_dma_handle_ch(ch
);
1859 if (enable_1510_mode
&& dma_chan
[ch
+ 6].saved_csr
)
1860 handled_now
+= omap1_dma_handle_ch(ch
+ 6);
1863 handled
+= handled_now
;
1866 return handled
? IRQ_HANDLED
: IRQ_NONE
;
1870 #define omap1_dma_irq_handler NULL
1873 #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3) || \
1874 defined(CONFIG_ARCH_OMAP4)
1876 static int omap2_dma_handle_ch(int ch
)
1878 u32 status
= dma_read(CSR(ch
));
1881 if (printk_ratelimit())
1882 printk(KERN_WARNING
"Spurious DMA IRQ for lch %d\n",
1884 dma_write(1 << ch
, IRQSTATUS_L0
);
1887 if (unlikely(dma_chan
[ch
].dev_id
== -1)) {
1888 if (printk_ratelimit())
1889 printk(KERN_WARNING
"IRQ %04x for non-allocated DMA"
1890 "channel %d\n", status
, ch
);
1893 if (unlikely(status
& OMAP_DMA_DROP_IRQ
))
1895 "DMA synchronization event drop occurred with device "
1896 "%d\n", dma_chan
[ch
].dev_id
);
1897 if (unlikely(status
& OMAP2_DMA_TRANS_ERR_IRQ
)) {
1898 printk(KERN_INFO
"DMA transaction error with device %d\n",
1899 dma_chan
[ch
].dev_id
);
1900 if (cpu_class_is_omap2()) {
1901 /* Errata: sDMA Channel is not disabled
1902 * after a transaction error. So we explicitely
1903 * disable the channel
1907 ccr
= dma_read(CCR(ch
));
1908 ccr
&= ~OMAP_DMA_CCR_EN
;
1909 dma_write(ccr
, CCR(ch
));
1910 dma_chan
[ch
].flags
&= ~OMAP_DMA_ACTIVE
;
1913 if (unlikely(status
& OMAP2_DMA_SECURE_ERR_IRQ
))
1914 printk(KERN_INFO
"DMA secure error with device %d\n",
1915 dma_chan
[ch
].dev_id
);
1916 if (unlikely(status
& OMAP2_DMA_MISALIGNED_ERR_IRQ
))
1917 printk(KERN_INFO
"DMA misaligned error with device %d\n",
1918 dma_chan
[ch
].dev_id
);
1920 dma_write(OMAP2_DMA_CSR_CLEAR_MASK
, CSR(ch
));
1921 dma_write(1 << ch
, IRQSTATUS_L0
);
1923 /* If the ch is not chained then chain_id will be -1 */
1924 if (dma_chan
[ch
].chain_id
!= -1) {
1925 int chain_id
= dma_chan
[ch
].chain_id
;
1926 dma_chan
[ch
].state
= DMA_CH_NOTSTARTED
;
1927 if (dma_read(CLNK_CTRL(ch
)) & (1 << 15))
1928 dma_chan
[dma_chan
[ch
].next_linked_ch
].state
=
1930 if (dma_linked_lch
[chain_id
].chain_mode
==
1931 OMAP_DMA_DYNAMIC_CHAIN
)
1934 if (!OMAP_DMA_CHAIN_QEMPTY(chain_id
))
1935 OMAP_DMA_CHAIN_INCQHEAD(chain_id
);
1937 status
= dma_read(CSR(ch
));
1940 dma_write(status
, CSR(ch
));
1942 if (likely(dma_chan
[ch
].callback
!= NULL
))
1943 dma_chan
[ch
].callback(ch
, status
, dma_chan
[ch
].data
);
1948 /* STATUS register count is from 1-32 while our is 0-31 */
1949 static irqreturn_t
omap2_dma_irq_handler(int irq
, void *dev_id
)
1951 u32 val
, enable_reg
;
1954 val
= dma_read(IRQSTATUS_L0
);
1956 if (printk_ratelimit())
1957 printk(KERN_WARNING
"Spurious DMA IRQ\n");
1960 enable_reg
= dma_read(IRQENABLE_L0
);
1961 val
&= enable_reg
; /* Dispatch only relevant interrupts */
1962 for (i
= 0; i
< dma_lch_count
&& val
!= 0; i
++) {
1964 omap2_dma_handle_ch(i
);
1971 static struct irqaction omap24xx_dma_irq
= {
1973 .handler
= omap2_dma_irq_handler
,
1974 .flags
= IRQF_DISABLED
1978 static struct irqaction omap24xx_dma_irq
;
1981 /*----------------------------------------------------------------------------*/
1983 void omap_dma_global_context_save(void)
1985 omap_dma_global_context
.dma_irqenable_l0
=
1986 dma_read(IRQENABLE_L0
);
1987 omap_dma_global_context
.dma_ocp_sysconfig
=
1988 dma_read(OCP_SYSCONFIG
);
1989 omap_dma_global_context
.dma_gcr
= dma_read(GCR
);
1992 void omap_dma_global_context_restore(void)
1996 dma_write(omap_dma_global_context
.dma_gcr
, GCR
);
1997 dma_write(omap_dma_global_context
.dma_ocp_sysconfig
,
1999 dma_write(omap_dma_global_context
.dma_irqenable_l0
,
2003 * A bug in ROM code leaves IRQ status for channels 0 and 1 uncleared
2004 * after secure sram context save and restore. Hence we need to
2005 * manually clear those IRQs to avoid spurious interrupts. This
2006 * affects only secure devices.
2008 if (cpu_is_omap34xx() && (omap_type() != OMAP2_DEVICE_TYPE_GP
))
2009 dma_write(0x3 , IRQSTATUS_L0
);
2011 for (ch
= 0; ch
< dma_chan_count
; ch
++)
2012 if (dma_chan
[ch
].dev_id
!= -1)
2016 /*----------------------------------------------------------------------------*/
2018 static int __init
omap_init_dma(void)
2023 if (cpu_class_is_omap1()) {
2024 base
= OMAP1_DMA_BASE
;
2025 dma_lch_count
= OMAP1_LOGICAL_DMA_CH_COUNT
;
2026 } else if (cpu_is_omap24xx()) {
2027 base
= OMAP24XX_DMA4_BASE
;
2028 dma_lch_count
= OMAP_DMA4_LOGICAL_DMA_CH_COUNT
;
2029 } else if (cpu_is_omap34xx()) {
2030 base
= OMAP34XX_DMA4_BASE
;
2031 dma_lch_count
= OMAP_DMA4_LOGICAL_DMA_CH_COUNT
;
2032 } else if (cpu_is_omap44xx()) {
2033 base
= OMAP44XX_DMA4_BASE
;
2034 dma_lch_count
= OMAP_DMA4_LOGICAL_DMA_CH_COUNT
;
2036 pr_err("DMA init failed for unsupported omap\n");
2040 omap_dma_base
= ioremap(base
, SZ_4K
);
2041 BUG_ON(!omap_dma_base
);
2043 if (cpu_class_is_omap2() && omap_dma_reserve_channels
2044 && (omap_dma_reserve_channels
<= dma_lch_count
))
2045 dma_lch_count
= omap_dma_reserve_channels
;
2047 dma_chan
= kzalloc(sizeof(struct omap_dma_lch
) * dma_lch_count
,
2054 if (cpu_class_is_omap2()) {
2055 dma_linked_lch
= kzalloc(sizeof(struct dma_link_info
) *
2056 dma_lch_count
, GFP_KERNEL
);
2057 if (!dma_linked_lch
) {
2063 if (cpu_is_omap15xx()) {
2064 printk(KERN_INFO
"DMA support for OMAP15xx initialized\n");
2066 enable_1510_mode
= 1;
2067 } else if (cpu_is_omap16xx() || cpu_is_omap7xx()) {
2068 printk(KERN_INFO
"OMAP DMA hardware version %d\n",
2070 printk(KERN_INFO
"DMA capabilities: %08x:%08x:%04x:%04x:%04x\n",
2071 (dma_read(CAPS_0_U
) << 16) |
2073 (dma_read(CAPS_1_U
) << 16) |
2075 dma_read(CAPS_2
), dma_read(CAPS_3
),
2077 if (!enable_1510_mode
) {
2080 /* Disable OMAP 3.0/3.1 compatibility mode. */
2084 dma_chan_count
= 16;
2087 } else if (cpu_class_is_omap2()) {
2088 u8 revision
= dma_read(REVISION
) & 0xff;
2089 printk(KERN_INFO
"OMAP DMA hardware revision %d.%d\n",
2090 revision
>> 4, revision
& 0xf);
2091 dma_chan_count
= dma_lch_count
;
2097 spin_lock_init(&dma_chan_lock
);
2099 for (ch
= 0; ch
< dma_chan_count
; ch
++) {
2101 dma_chan
[ch
].dev_id
= -1;
2102 dma_chan
[ch
].next_lch
= -1;
2104 if (ch
>= 6 && enable_1510_mode
)
2107 if (cpu_class_is_omap1()) {
2109 * request_irq() doesn't like dev_id (ie. ch) being
2110 * zero, so we have to kludge around this.
2112 r
= request_irq(omap1_dma_irq
[ch
],
2113 omap1_dma_irq_handler
, 0, "DMA",
2118 printk(KERN_ERR
"unable to request IRQ %d "
2119 "for DMA (error %d)\n",
2120 omap1_dma_irq
[ch
], r
);
2121 for (i
= 0; i
< ch
; i
++)
2122 free_irq(omap1_dma_irq
[i
],
2129 if (cpu_is_omap2430() || cpu_is_omap34xx() || cpu_is_omap44xx())
2130 omap_dma_set_global_params(DMA_DEFAULT_ARB_RATE
,
2131 DMA_DEFAULT_FIFO_DEPTH
, 0);
2133 if (cpu_class_is_omap2()) {
2135 if (cpu_is_omap44xx())
2136 irq
= INT_44XX_SDMA_IRQ0
;
2138 irq
= INT_24XX_SDMA_IRQ0
;
2139 setup_irq(irq
, &omap24xx_dma_irq
);
2142 if (cpu_is_omap34xx()) {
2143 /* Enable smartidle idlemodes and autoidle */
2144 u32 v
= dma_read(OCP_SYSCONFIG
);
2145 v
&= ~(DMA_SYSCONFIG_MIDLEMODE_MASK
|
2146 DMA_SYSCONFIG_SIDLEMODE_MASK
|
2147 DMA_SYSCONFIG_AUTOIDLE
);
2148 v
|= (DMA_SYSCONFIG_MIDLEMODE(DMA_IDLEMODE_SMARTIDLE
) |
2149 DMA_SYSCONFIG_SIDLEMODE(DMA_IDLEMODE_SMARTIDLE
) |
2150 DMA_SYSCONFIG_AUTOIDLE
);
2151 dma_write(v
, OCP_SYSCONFIG
);
2152 /* reserve dma channels 0 and 1 in high security devices */
2153 if (omap_type() != OMAP2_DEVICE_TYPE_GP
) {
2154 printk(KERN_INFO
"Reserving DMA channels 0 and 1 for "
2156 dma_chan
[0].dev_id
= 0;
2157 dma_chan
[1].dev_id
= 1;
2167 iounmap(omap_dma_base
);
2172 arch_initcall(omap_init_dma
);
2175 * Reserve the omap SDMA channels using cmdline bootarg
2176 * "omap_dma_reserve_ch=". The valid range is 1 to 32
2178 static int __init
omap_dma_cmdline_reserve_ch(char *str
)
2180 if (get_option(&str
, &omap_dma_reserve_channels
) != 1)
2181 omap_dma_reserve_channels
= 0;
2185 __setup("omap_dma_reserve_ch=", omap_dma_cmdline_reserve_ch
);