summaryrefslogtreecommitdiff
path: root/arch/arm/plat-mxc/include/mach/dma.h
blob: d2f6091cebb3857d1b277dd4654bb88bb8ef738f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
/*
 * Copyright 2004-2009 Freescale Semiconductor, Inc. All Rights Reserved.
 */

/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

#ifndef __ASM_ARCH_MXC_DMA_H__
#define __ASM_ARCH_MXC_DMA_H__

#include <linux/scatterlist.h>

#define MXC_DMA_DYNAMIC_CHANNEL   255

#define MXC_DMA_DONE		  0x0
#define MXC_DMA_REQUEST_TIMEOUT   0x1
#define MXC_DMA_TRANSFER_ERROR    0x2

/*! This defines the list of device ID's for DMA */
typedef enum mxc_dma_device {
	MXC_DMA_UART1_RX,
	MXC_DMA_UART1_TX,
	MXC_DMA_UART2_RX,
	M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A_FIFO_MEMORY,
	MXC_DMA_DSP_PACKET_DATA0_RD,
	MXC_DMA_DSP_PACKET_DATA0_WR,
	MXC_DMA_DSP_PACKET_DATA1_RD,
	MXC_DMA_DSP_PACKET_DATA1_WR,
	MXC_DMA_DSP_LOG0_CHNL,
	MXC_DMA_DSP_LOG1_CHNL,
	MXC_DMA_DSP_LOG2_CHNL,
	MXC_DMA_DSP_LOG3_CHNL,
	MXC_DMA_CSI_RX,
	MXC_DMA_SPDIF_16BIT_TX,
	MXC_DMA_SPDIF_16BIT_RX,
	MXC_DMA_SPDIF_32BIT_TX,
	MXC_DMA_SPDIF_32BIT_RX,
	MXC_DMA_ASRC_A_RX,
	MXC_DMA_ASRC_A_TX,
	MXC_DMA_ASRC_B_RX,
	MXC_DMA_ASRC_B_TX,
	MXC_DMA_ASRC_C_RX,
	MXC_DMA_ASRC_C_TX,
	MXC_DMA_ASRCA_ESAI,
	MXC_DMA_ASRCB_ESAI,
	MXC_DMA_ASRCC_ESAI,
	MXC_DMA_ASRCA_SSI1_TX0,
	MXC_DMA_ASRCA_SSI1_TX1,
	MXC_DMA_ASRCA_SSI2_TX0,
	MXC_DMA_ASRCA_SSI2_TX1,
	MXC_DMA_ASRCB_SSI1_TX0,
	MXC_DMA_ASRCB_SSI1_TX1,
	MXC_DMA_ASRCB_SSI2_TX0,
	MXC_DMA_ASRCB_SSI2_TX1,
	MXC_DMA_ESAI_16BIT_RX,
	MXC_DMA_ESAI_16BIT_TX,
	MXC_DMA_ESAI_24BIT_RX,
	MXC_DMA_ESAI_24BIT_TX,
	MXC_DMA_TEST_RAM2D2RAM,
	MXC_DMA_TEST_RAM2RAM2D,
	MXC_DMA_TEST_RAM2D2RAM2D,
	MXC_DMA_TEST_RAM2RAM,
	MXC_DMA_TEST_HW_CHAINING,
	MXC_DMA_TEST_SW_CHAINING
} mxc_dma_device_t;

/*! This defines the prototype of callback funtion registered by the drivers */
typedef void (*mxc_dma_callback_t) (void *arg, int error_status,
				    unsigned int count);

/*! This defines the type of DMA transfer requested */
typedef enum mxc_dma_mode {
	MXC_DMA_MODE_READ,
	MXC_DMA_MODE_WRITE,
} mxc_dma_mode_t;

/*! This defines the DMA channel parameters */
typedef struct mxc_dma_channel {
	unsigned int active:1;	/*!< When there has a active tranfer, it is set to 1 */
	unsigned int lock;	/*!< Defines the channel is allocated or not */
	int curr_buf;		/*!< Current buffer */
	mxc_dma_mode_t mode;	/*!< Read or Write */
	unsigned int channel;	/*!< Channel info */
	unsigned int dynamic:1;	/*!< Channel not statically allocated when 1 */
	char *dev_name;		/*!< Device name */
	void *private;		/*!< Private structure for platform */
	mxc_dma_callback_t cb_fn;	/*!< The callback function */
	void *cb_args;		/*!< The argument of callback function */
} mxc_dma_channel_t;

/*! This structure contains the information about a dma transfer */
typedef struct mxc_dma_requestbuf {
	dma_addr_t src_addr;	/*!< source address */
	dma_addr_t dst_addr;	/*!< destination address */
	int num_of_bytes;	/*!< the length of this transfer : bytes */
} mxc_dma_requestbuf_t;

/*! This struct contains the information for asrc special*/
struct dma_channel_asrc_info {
	u32 channs;		/*!< data channels in asrc */
};

/*! This struct contains  the information for device special*/
struct dma_channel_info {
	struct dma_channel_asrc_info asrc;	/*!< asrc special information */
};

#if defined(CONFIG_ARCH_MX27) || defined(CONFIG_ARCH_MX21)
#include <mach/mx2_dma.h>
#else
#include <mach/sdma.h>
#endif

/*!
 * This function is generally called by the driver at open time.
 * The DMA driver would do any initialization steps that is required
 * to get the channel ready for data transfer.
 *
 * @param channel_id   a pre-defined id. The peripheral driver would specify
 *                     the id associated with its peripheral. This would be
 *                     used by the DMA driver to identify the peripheral
 *                     requesting DMA and do the necessary setup on the
 *                     channel associated with the particular peripheral.
 *                     The DMA driver could use static or dynamic DMA channel
 *                     allocation.
 * @param dev_name     module name or device name
 * @param data         the customized parameter for special channel.
 * @return returns a negative number on error if request for a DMA channel did not
 *         succeed, returns the channel number to be used on success.
 */
extern int mxc_dma_request_ext(mxc_dma_device_t channel_id, char *dev_name,
			       struct dma_channel_info *info);

static inline int mxc_dma_request(mxc_dma_device_t channel_id, char *dev_name)
{
	return mxc_dma_request_ext(channel_id, dev_name, NULL);
}

/*!
 * This function is generally called by the driver at close time. The DMA
 * driver would do any cleanup associated with this channel.
 *
 * @param channel_num  the channel number returned at request time. This
 *                     would be used by the DMA driver to identify the calling
 *                     driver and do the necessary cleanup on the channel
 *                     associated with the particular peripheral
 * @return returns a negative number on error or 0 on success
 */
extern int mxc_dma_free(int channel_num);

/*!
 * This function would just configure the buffers specified by the user into
 * dma channel. The caller must call mxc_dma_enable to start this transfer.
 *
 * @param channel_num  the channel number returned at request time. This
 *                     would be used by the DMA driver to identify the calling
 *                     driver and do the necessary cleanup on the channel
 *                     associated with the particular peripheral
 * @param dma_buf      an array of physical addresses to the user defined
 *                     buffers. The caller must guarantee the dma_buf is
 *                     available until the transfer is completed.
 * @param num_buf      number of buffers in the array
 * @param mode         specifies whether this is READ or WRITE operation
 * @return This function returns a negative number on error if buffer could not be
 *         added with DMA for transfer. On Success, it returns 0
 */
extern int mxc_dma_config(int channel_num, mxc_dma_requestbuf_t *dma_buf,
			  int num_buf, mxc_dma_mode_t mode);

/*!
 * This function would just configure the scatterlist specified by the
 * user into dma channel. This is a slight variation of mxc_dma_config(),
 * it is provided for the convenience of drivers that have a scatterlist
 * passed into them. It is the calling driver's responsibility to have the
 * correct physical address filled in the "dma_address" field of the
 * scatterlist.
 *
 * @param channel_num  the channel number returned at request time. This
 *                     would be used by the DMA driver to identify the calling
 *                     driver and do the necessary cleanup on the channel
 *                     associated with the particular peripheral
 * @param sg           a scatterlist of buffers. The caller must guarantee
 *                     the dma_buf is available until the transfer is
 *                     completed.
 * @param num_buf      number of buffers in the array
 * @param num_of_bytes total number of bytes to transfer. If set to 0, this
 *                     would imply to use the length field of the scatterlist
 *                     for each DMA transfer. Else it would calculate the size
 *                     for each DMA transfer.
 * @param mode         specifies whether this is READ or WRITE operation
 * @return This function returns a negative number on error if buffer could not
 *         be added with DMA for transfer. On Success, it returns 0
 */
extern int mxc_dma_sg_config(int channel_num, struct scatterlist *sg,
			     int num_buf, int num_of_bytes,
			     mxc_dma_mode_t mode);

/*!
 * This function is provided if the driver would like to set/change its
 * callback function.
 *
 * @param channel_num  the channel number returned at request time. This
 *                     would be used by the DMA driver to identify the calling
 *                     driver and do the necessary cleanup on the channel
 *                     associated with the particular peripheral
 * @param callback     a callback function to provide notification on transfer
 *                     completion, user could specify NULL if he does not wish
 *                     to be notified
 * @param arg          an argument that gets passed in to the callback
 *                     function, used by the user to do any driver specific
 *                     operations.
 * @return this function returns a negative number on error if the callback
 *         could not be set for the channel or 0 on success
 */
extern int mxc_dma_callback_set(int channel_num, mxc_dma_callback_t callback,
				void *arg);

/*!
 * This stops the DMA channel and any ongoing transfers. Subsequent use of
 * mxc_dma_enable() will restart the channel and restart the transfer.
 *
 * @param channel_num  the channel number returned at request time. This
 *                     would be used by the DMA driver to identify the calling
 *                     driver and do the necessary cleanup on the channel
 *                     associated with the particular peripheral
 * @return returns a negative number on error or 0 on success
 */
extern int mxc_dma_disable(int channel_num);

/*!
 * This starts DMA transfer. Or it restarts DMA on a stopped channel
 * previously stopped with mxc_dma_disable().
 *
 * @param channel_num  the channel number returned at request time. This
 *                     would be used by the DMA driver to identify the calling
 *                     driver and do the necessary cleanup on the channel
 *                     associated with the particular peripheral
 * @return returns a negative number on error or 0 on success
 */
extern int mxc_dma_enable(int channel_num);

#endif