[ARM] 5466/1: Freescale STMP platform support [5/10]
[pandora-kernel.git] / arch / arm / plat-stmp3xxx / include / mach / dma.h
1 /*
2  * Freescale STMP37XX/STMP378X DMA helper interface
3  *
4  * Embedded Alley Solutions, Inc <source@embeddedalley.com>
5  *
6  * Copyright 2008 Freescale Semiconductor, Inc. All Rights Reserved.
7  * Copyright 2008 Embedded Alley Solutions, Inc All Rights Reserved.
8  */
9
10 /*
11  * The code contained herein is licensed under the GNU General Public
12  * License. You may obtain a copy of the GNU General Public License
13  * Version 2 or later at the following locations:
14  *
15  * http://www.opensource.org/licenses/gpl-license.html
16  * http://www.gnu.org/copyleft/gpl.html
17  */
18 #ifndef __ASM_PLAT_STMP3XXX_DMA_H
19 #define __ASM_PLAT_STMP3XXX_DMA_H
20
21 #include <linux/platform_device.h>
22 #include <linux/dmapool.h>
23
24 #if !defined(MAX_PIO_WORDS)
25 #define MAX_PIO_WORDS   (15)
26 #endif
27
28 #define STMP3XXX_BUS_APBH       0
29 #define STMP3XXX_BUS_APBX       1
30 #define STMP3XXX_DMA_MAX_CHANNEL        16
31
32
33 #define STMP3xxx_DMA(channel, bus)  ((bus) * 16 + (channel))
34
35 #define MAX_DMA_ADDRESS         0xffffffff
36
37 #define MAX_DMA_CHANNELS        32
38
39 struct stmp3xxx_dma_command {
40         u32 next;
41         u32 cmd;
42         union {
43                 u32 buf_ptr;
44                 u32 alternate;
45         };
46         u32 pio_words[MAX_PIO_WORDS];
47 };
48
49 struct stmp3xxx_dma_descriptor {
50         struct stmp3xxx_dma_command *command;
51         dma_addr_t handle;
52
53         /* The virtual address of the buffer pointer */
54         void *virtual_buf_ptr;
55         /* The next descriptor in a the DMA chain (optional) */
56         struct stmp3xxx_dma_descriptor *next_descr;
57 };
58
59 struct stmp37xx_circ_dma_chain {
60         unsigned total_count;
61         struct stmp3xxx_dma_descriptor *chain;
62
63         unsigned free_index;
64         unsigned free_count;
65         unsigned active_index;
66         unsigned active_count;
67         unsigned cooked_index;
68         unsigned cooked_count;
69
70         int bus;
71         unsigned channel;
72 };
73
74 static inline struct stmp3xxx_dma_descriptor
75     *stmp3xxx_dma_circ_get_free_head(struct stmp37xx_circ_dma_chain *chain)
76 {
77         return &(chain->chain[chain->free_index]);
78 }
79
80 static inline struct stmp3xxx_dma_descriptor
81     *stmp3xxx_dma_circ_get_cooked_head(struct stmp37xx_circ_dma_chain *chain)
82 {
83         return &(chain->chain[chain->cooked_index]);
84 }
85
86 int stmp3xxx_dma_request(int ch, struct device *dev, const char *name);
87 int stmp3xxx_dma_release(int ch);
88 int stmp3xxx_dma_allocate_command(int ch,
89                                   struct stmp3xxx_dma_descriptor *descriptor);
90 int stmp3xxx_dma_free_command(int ch,
91                               struct stmp3xxx_dma_descriptor *descriptor);
92 void stmp3xxx_dma_continue(int channel, u32 semaphore);
93 void stmp3xxx_dma_go(int ch, struct stmp3xxx_dma_descriptor *head,
94                      u32 semaphore);
95 int stmp3xxx_dma_running(int ch);
96 int stmp3xxx_dma_make_chain(int ch, struct stmp37xx_circ_dma_chain *chain,
97                             struct stmp3xxx_dma_descriptor descriptors[],
98                             unsigned items);
99 void stmp3xxx_dma_free_chain(struct stmp37xx_circ_dma_chain *chain);
100 void stmp37xx_circ_clear_chain(struct stmp37xx_circ_dma_chain *chain);
101 void stmp37xx_circ_advance_free(struct stmp37xx_circ_dma_chain *chain,
102                 unsigned count);
103 void stmp37xx_circ_advance_active(struct stmp37xx_circ_dma_chain *chain,
104                 unsigned count);
105 unsigned stmp37xx_circ_advance_cooked(struct stmp37xx_circ_dma_chain *chain);
106 int stmp3xxx_dma_read_semaphore(int ch);
107 void stmp3xxx_dma_init(void);
108 void stmp3xxx_dma_set_alt_target(int ch, int target);
109 void stmp3xxx_dma_suspend(void);
110 void stmp3xxx_dma_resume(void);
111
112 /*
113  * STMP37xx and STMP378x have different DMA control
114  * registers layout
115  */
116
117 void stmp3xxx_arch_dma_freeze(int ch);
118 void stmp3xxx_arch_dma_unfreeze(int ch);
119 void stmp3xxx_arch_dma_reset_channel(int ch);
120 void stmp3xxx_arch_dma_enable_interrupt(int ch);
121 void stmp3xxx_arch_dma_clear_interrupt(int ch);
122 int stmp3xxx_arch_dma_is_interrupt(int ch);
123
124 static inline void stmp3xxx_dma_reset_channel(int ch)
125 {
126         stmp3xxx_arch_dma_reset_channel(ch);
127 }
128
129
130 static inline void stmp3xxx_dma_freeze(int ch)
131 {
132         stmp3xxx_arch_dma_freeze(ch);
133 }
134
135 static inline void stmp3xxx_dma_unfreeze(int ch)
136 {
137         stmp3xxx_arch_dma_unfreeze(ch);
138 }
139
140 static inline void stmp3xxx_dma_enable_interrupt(int ch)
141 {
142         stmp3xxx_arch_dma_enable_interrupt(ch);
143 }
144
145 static inline void stmp3xxx_dma_clear_interrupt(int ch)
146 {
147         stmp3xxx_arch_dma_clear_interrupt(ch);
148 }
149
150 static inline int stmp3xxx_dma_is_interrupt(int ch)
151 {
152         return stmp3xxx_arch_dma_is_interrupt(ch);
153 }
154
155 #endif /* __ASM_PLAT_STMP3XXX_DMA_H */