6e7049a796a4eaff8021684b794180f4eb3e541a
[pandora-kernel.git] / arch / arm / mach-ep93xx / include / mach / dma.h
1 /**
2  * DOC: EP93xx DMA M2P memory to peripheral and peripheral to memory engine
3  *
4  * The EP93xx DMA M2P subsystem handles DMA transfers between memory and
5  * peripherals. DMA M2P channels are available for audio, UARTs and IrDA.
6  * See chapter 10 of the EP93xx users guide for full details on the DMA M2P
7  * engine.
8  *
9  * See sound/soc/ep93xx/ep93xx-pcm.c for an example use of the DMA M2P code.
10  *
11  */
12
13 #ifndef __ASM_ARCH_DMA_H
14 #define __ASM_ARCH_DMA_H
15
16 #include <linux/list.h>
17 #include <linux/types.h>
18 #include <linux/dmaengine.h>
19 #include <linux/dma-mapping.h>
20
21 /**
22  * struct ep93xx_dma_buffer - Information about a buffer to be transferred
23  * using the DMA M2P engine
24  *
25  * @list: Entry in DMA buffer list
26  * @bus_addr: Physical address of the buffer
27  * @size: Size of the buffer in bytes
28  */
29 struct ep93xx_dma_buffer {
30         struct list_head        list;
31         u32                     bus_addr;
32         u16                     size;
33 };
34
35 /**
36  * struct ep93xx_dma_m2p_client - Information about a DMA M2P client
37  *
38  * @name: Unique name for this client
39  * @flags: Client flags
40  * @cookie: User data to pass to callback functions
41  * @buffer_started: Non NULL function to call when a transfer is started.
42  *                      The arguments are the user data cookie and the DMA
43  *                      buffer which is starting.
44  * @buffer_finished: Non NULL function to call when a transfer is completed.
45  *                      The arguments are the user data cookie, the DMA buffer
46  *                      which has completed, and a boolean flag indicating if
47  *                      the transfer had an error.
48  */
49 struct ep93xx_dma_m2p_client {
50         char                    *name;
51         u8                      flags;
52         void                    *cookie;
53         void                    (*buffer_started)(void *cookie,
54                                         struct ep93xx_dma_buffer *buf);
55         void                    (*buffer_finished)(void *cookie,
56                                         struct ep93xx_dma_buffer *buf,
57                                         int bytes, int error);
58
59         /* private: Internal use only */
60         void                    *channel;
61 };
62
63 /* DMA M2P ports */
64 #define EP93XX_DMA_M2P_PORT_I2S1        0x00
65 #define EP93XX_DMA_M2P_PORT_I2S2        0x01
66 #define EP93XX_DMA_M2P_PORT_AAC1        0x02
67 #define EP93XX_DMA_M2P_PORT_AAC2        0x03
68 #define EP93XX_DMA_M2P_PORT_AAC3        0x04
69 #define EP93XX_DMA_M2P_PORT_I2S3        0x05
70 #define EP93XX_DMA_M2P_PORT_UART1       0x06
71 #define EP93XX_DMA_M2P_PORT_UART2       0x07
72 #define EP93XX_DMA_M2P_PORT_UART3       0x08
73 #define EP93XX_DMA_M2P_PORT_IRDA        0x09
74 #define EP93XX_DMA_M2P_PORT_MASK        0x0f
75
76 /* DMA M2P client flags */
77 #define EP93XX_DMA_M2P_TX               0x00    /* Memory to peripheral */
78 #define EP93XX_DMA_M2P_RX               0x10    /* Peripheral to memory */
79
80 /*
81  * DMA M2P client error handling flags. See the EP93xx users guide
82  * documentation on the DMA M2P CONTROL register for more details
83  */
84 #define EP93XX_DMA_M2P_ABORT_ON_ERROR   0x20    /* Abort on peripheral error */
85 #define EP93XX_DMA_M2P_IGNORE_ERROR     0x40    /* Ignore peripheral errors */
86 #define EP93XX_DMA_M2P_ERROR_MASK       0x60    /* Mask of error bits */
87
88 /**
89  * ep93xx_dma_m2p_client_register - Register a client with the DMA M2P
90  * subsystem
91  *
92  * @m2p: Client information to register
93  * returns 0 on success
94  *
95  * The DMA M2P subsystem allocates a channel and an interrupt line for the DMA
96  * client
97  */
98 int ep93xx_dma_m2p_client_register(struct ep93xx_dma_m2p_client *m2p);
99
100 /**
101  * ep93xx_dma_m2p_client_unregister - Unregister a client from the DMA M2P
102  * subsystem
103  *
104  * @m2p: Client to unregister
105  *
106  * Any transfers currently in progress will be completed in hardware, but
107  * ignored in software.
108  */
109 void ep93xx_dma_m2p_client_unregister(struct ep93xx_dma_m2p_client *m2p);
110
111 /**
112  * ep93xx_dma_m2p_submit - Submit a DMA M2P transfer
113  *
114  * @m2p: DMA Client to submit the transfer on
115  * @buf: DMA Buffer to submit
116  *
117  * If the current or next transfer positions are free on the M2P client then
118  * the transfer is started immediately. If not, the transfer is added to the
119  * list of pending transfers. This function must not be called from the
120  * buffer_finished callback for an M2P channel.
121  *
122  */
123 void ep93xx_dma_m2p_submit(struct ep93xx_dma_m2p_client *m2p,
124                            struct ep93xx_dma_buffer *buf);
125
126 /**
127  * ep93xx_dma_m2p_submit_recursive - Put a DMA transfer on the pending list
128  * for an M2P channel
129  *
130  * @m2p: DMA Client to submit the transfer on
131  * @buf: DMA Buffer to submit
132  *
133  * This function must only be called from the buffer_finished callback for an
134  * M2P channel. It is commonly used to add the next transfer in a chained list
135  * of DMA transfers.
136  */
137 void ep93xx_dma_m2p_submit_recursive(struct ep93xx_dma_m2p_client *m2p,
138                                      struct ep93xx_dma_buffer *buf);
139
140 /**
141  * ep93xx_dma_m2p_flush - Flush all pending transfers on a DMA M2P client
142  *
143  * @m2p: DMA client to flush transfers on
144  *
145  * Any transfers currently in progress will be completed in hardware, but
146  * ignored in software.
147  *
148  */
149 void ep93xx_dma_m2p_flush(struct ep93xx_dma_m2p_client *m2p);
150
151 /*
152  * M2P channels.
153  *
154  * Note that these values are also directly used for setting the PPALLOC
155  * register.
156  */
157 #define EP93XX_DMA_I2S1         0
158 #define EP93XX_DMA_I2S2         1
159 #define EP93XX_DMA_AAC1         2
160 #define EP93XX_DMA_AAC2         3
161 #define EP93XX_DMA_AAC3         4
162 #define EP93XX_DMA_I2S3         5
163 #define EP93XX_DMA_UART1        6
164 #define EP93XX_DMA_UART2        7
165 #define EP93XX_DMA_UART3        8
166 #define EP93XX_DMA_IRDA         9
167 /* M2M channels */
168 #define EP93XX_DMA_SSP          10
169 #define EP93XX_DMA_IDE          11
170
171 /**
172  * struct ep93xx_dma_data - configuration data for the EP93xx dmaengine
173  * @port: peripheral which is requesting the channel
174  * @direction: TX/RX channel
175  * @name: optional name for the channel, this is displayed in /proc/interrupts
176  *
177  * This information is passed as private channel parameter in a filter
178  * function. Note that this is only needed for slave/cyclic channels.  For
179  * memcpy channels %NULL data should be passed.
180  */
181 struct ep93xx_dma_data {
182         int                             port;
183         enum dma_data_direction         direction;
184         const char                      *name;
185 };
186
187 /**
188  * struct ep93xx_dma_chan_data - platform specific data for a DMA channel
189  * @name: name of the channel, used for getting the right clock for the channel
190  * @base: mapped registers
191  * @irq: interrupt number used by this channel
192  */
193 struct ep93xx_dma_chan_data {
194         const char                      *name;
195         void __iomem                    *base;
196         int                             irq;
197 };
198
199 /**
200  * struct ep93xx_dma_platform_data - platform data for the dmaengine driver
201  * @channels: array of channels which are passed to the driver
202  * @num_channels: number of channels in the array
203  *
204  * This structure is passed to the DMA engine driver via platform data. For
205  * M2P channels, contract is that even channels are for TX and odd for RX.
206  * There is no requirement for the M2M channels.
207  */
208 struct ep93xx_dma_platform_data {
209         struct ep93xx_dma_chan_data     *channels;
210         size_t                          num_channels;
211 };
212
213 static inline bool ep93xx_dma_chan_is_m2p(struct dma_chan *chan)
214 {
215         return !strcmp(dev_name(chan->device->dev), "ep93xx-dma-m2p");
216 }
217
218 /**
219  * ep93xx_dma_chan_direction - returns direction the channel can be used
220  * @chan: channel
221  *
222  * This function can be used in filter functions to find out whether the
223  * channel supports given DMA direction. Only M2P channels have such
224  * limitation, for M2M channels the direction is configurable.
225  */
226 static inline enum dma_data_direction
227 ep93xx_dma_chan_direction(struct dma_chan *chan)
228 {
229         if (!ep93xx_dma_chan_is_m2p(chan))
230                 return DMA_NONE;
231
232         /* even channels are for TX, odd for RX */
233         return (chan->chan_id % 2 == 0) ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
234 }
235
236 #endif /* __ASM_ARCH_DMA_H */