summaryrefslogtreecommitdiffstats
path: root/drivers/staging/westbridge/astoria/include/linux/westbridge/cyasdma.h
blob: 6efb8b80ffb7ce26c3b4a39f5427c5cb3e43cc3d (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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
/* Cypress West Bridge API header file (cyasdma.h)
## ===========================
## Copyright (C) 2010  Cypress Semiconductor
##
## This program is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License
## as published by the Free Software Foundation; either version 2
## of the License, or (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 51 Franklin Street
## Fifth Floor, Boston, MA  02110-1301, USA.
## ===========================
*/

#ifndef _INCLUDED_CYASDMA_H_
#define _INCLUDED_CYASDMA_H_

#include "cyashal.h"
#include "cyasdevice.h"

#include "cyas_cplus_start.h"


/*@@DMA Overview
	This module manages the DMA operations to/from the West Bridge
	device.  The DMA module maintains a DMA queue for each endpoint
	so multiple DMA requests may be queued and they will complete
	at some future time.

	The DMA module must be started before it can be used.  It is
	started by calling CyAsDmaStart().  This function intializes
	all of the endpoint data structures.

	In order to perform DMA on a particular endpoint, the endpoint
	must be enabled by calling CyAsDmaEnableEndPoint(). In addition
	to enabling or disabling the endpoint, this function also sets
	the direction for a given endpoint.  Direction is given in USB
	terms.  For P port to West Bridge traffic, the endpoint is a
	CyAsDirectionIn endpoint.  For West Bridge to P port traffic,
	the endpoint is a CyAsDirectionOut endpoint.

	Once DMA is started and an endpoint is enabled, DMA requests
	are issued by calling CyAsDmaQueueRequest().  This function
	queue either a DMA read or DMA write request.  The callback
	associated with the request is called once the request has been
	fulfilled.

	See Also
	* CyAsDmaStart
	* CyAsDmaEnableEndPoint
	* CyAsDmaDirection
	* CyAsDmaQueueRequest
 */

/************************
 * West Bridge Constants
 ************************/
#define CY_AS_DMA_MAX_SIZE_HW_SIZE (0xffffffff)

/************************
 * West Bridge Data Structures
 ************************/

/* Summary
   This type specifies the direction of an endpoint to the
   CyAsDmaEnableEndPoint function.

   Description
   When an endpoint is enabled, the direction of the endpoint
   can also be set. This type is used to specify the endpoint
   type.  Note that the direction is specified in USB terms.
   Therefore, if the DMA is from the P port to West Bridge,
   the direction is IN.

   See Also
   * CyAsDmaEnableEndPoint
*/
typedef enum cy_as_dma_direction {
	/* Set the endpoint to type IN (P -> West Bridge) */
	cy_as_direction_in = 0,
	/* Set the endpoint to type OUT (West Bridge -> P) */
	cy_as_direction_out = 1,
	/* Only valid for EP 0 */
	cy_as_direction_in_out = 2,
	/* Do no change the endpoint type */
	cy_as_direction_dont_change = 3
} cy_as_dma_direction;

/*********************************
 * West Bridge Functions
 *********************************/

/* Summary
   Initialize the DMA module and ready the module for receiving data

   Description
   This function initializes the DMA module by initializing all of
   the endpoint data structures associated with the device given.
   This function also register a DMA complete callback with the HAL
   DMA code.  This callback is called whenever the HAL DMA subsystem
   completes a requested DMA operation.

   Returns
   CY_AS_ERROR_SUCCESS - the module initialized sucessfully
   CY_AS_ERROR_OUT_OF_MEMORY - memory allocation failed during
		initialization
   CY_AS_ERROR_ALREADY_RUNNING - the DMA module was already running

   See Also
   * CyAsDmaStop
*/
extern cy_as_return_status_t
cy_as_dma_start(
	/* The device to start */
	cy_as_device *dev_p
	);

/* Summary
   Shutdown the DMA module

   Description
   This function shuts down the DMA module for this device by
   canceling any DMA requests associated with each endpoint and
   then freeing the resources associated with each DMA endpoint.

   Returns
   CY_AS_ERROR_SUCCESS - the module shutdown sucessfully
   CY_AS_ERROR_NOT_RUNNING - the DMA module was not running

   See Also
   * CyAsDmaStart
   * CyAsDmaCancel
*/
extern cy_as_return_status_t
cy_as_dma_stop(
	/* The device to stop */
	cy_as_device *dev_p
	);

/* Summary
   This function cancels all outstanding DMA requests on a given endpoint

   Description
   This function cancels any DMA requests outstanding on a given endpoint
   by disabling the transfer of DMA requests from the queue to the HAL
   layer and then removing any pending DMA requests from the queue. The
   callback associated with any DMA requests that are being removed is
   called with an error code of CY_AS_ERROR_CANCELED.

   Notes
   If a request has already been sent to the HAL layer it will be
   completed and not canceled. Only requests that have not been sent to
   the HAL layer will be cancelled.

   Returns
   CY_AS_ERROR_SUCCESS - the traffic on the endpoint is canceled
	sucessfully

   See Also
*/
extern cy_as_return_status_t
cy_as_dma_cancel(
	/* The device of interest */
	cy_as_device *dev_p,
	/* The endpoint to cancel */
	cy_as_end_point_number_t ep,
	cy_as_return_status_t err
	);

/* Summary
   This function enables a single endpoint for DMA operations

   Description
   In order to enable the queuing of DMA requests on a given
   endpoint, the endpoint must be enabled for DMA.  This function
   enables a given endpoint.  In addition, this function sets the
   direction of the DMA operation.

   Returns
   * CY_AS_ERROR_INVALID_ENDPOINT - invalid endpoint number
   * CY_AS_ERROR_SUCCESS - endpoint was enabled or disabled
   *	successfully

   See Also
   * CyAsDmaQueueRequest
*/
extern cy_as_return_status_t
cy_as_dma_enable_end_point(
	/* The device of interest */
	cy_as_device *dev_p,
	/* The endpoint to enable or disable */
	cy_as_end_point_number_t ep,
	/* CyTrue to enable, CyFalse to disable */
	cy_bool	enable,
	/* The direction of the endpoint */
	cy_as_dma_direction	dir
);

/* Summary
   This function queue a DMA request for a given endpoint

   Description
   When an West Bridge API module wishes to do a DMA operation,
   this function is called on the associated endpoint to queue
   a DMA request.  When the DMA request has been fulfilled, the
   callback associated with the DMA operation is called.

   Notes
   The buffer associated with the DMA request, must remain valid
   until after the callback function is calld.

   Returns
   * CY_AS_ERROR_SUCCESS - the DMA operation was queued successfully
   * CY_AS_ERROR_INVALID_ENDPOINT - the endpoint number was invalid
   * CY_AS_ERROR_ENDPOINT_DISABLED - the endpoint was disabled
   * CY_AS_ERROR_OUT_OF_MEMORY - out of memory processing the request

   See Also
   * CyAsDmaEnableEndPoint
   * CyAsDmaCancel
*/
extern cy_as_return_status_t
cy_as_dma_queue_request(
	/* The device of interest */
	cy_as_device *dev_p,
	/* The endpoint to receive a new request */
	cy_as_end_point_number_t ep,
	/* The memory buffer for the DMA request -
	 * must be valid until after the callback has been called */
	void *mem_p,
	/* The size of the DMA request in bytes */
	uint32_t size,
	/* If true and a DMA read request, return the next packet
	 * regardless of size */
	cy_bool	packet,
	/* If true, this is a read request,
	 * otherwise it is a write request */
	cy_bool	readreq,
	/* The callback to call when the DMA request is complete,
	 * either successfully or via an error */
	cy_as_dma_callback cb
	);

/* Summary
   This function waits until all DMA requests on a given endpoint
   have been processed and then return

   Description
   There are times when a module in the West Bridge API needs to
   wait until the DMA operations have been queued.  This function
   sleeps until all DMA requests have been fulfilled and only then
   returns to the caller.

   Notes
   I don't think we will need a list of sleeping clients to support
   multiple parallel client modules sleeping on a single endpoint,
   but if we do instead of having a single sleep channel in the
   endpoint, each client will have to supply a sleep channel and we
   will have to maintain a list of sleep channels to wake.

   Returns
   * CY_AS_ERROR_SUCCESS - the queue has drained sucessfully
   * CY_AS_ERROR_INVALID_ENDPOINT - the endpoint given is not valid
   * CY_AS_ERROR_NESTED_SLEEP - CyAsDmaQueueRequest() was requested
   *	on an endpoint where CyAsDmaQueueRequest was already called
*/
extern cy_as_return_status_t
cy_as_dma_drain_queue(
	/* The device of interest */
	cy_as_device *dev_p,
	/* The endpoint to drain */
	cy_as_end_point_number_t ep,
	/* If CyTrue, call kickstart to start the DMA process,
	if cy_false, west bridge will start the DMA process */
	cy_bool kickstart
	);

/* Summary
   Sets the maximum amount of data West Bridge can accept in a single
   DMA Operation for the given endpoint

   Description
   Depending on the configuration of the West Bridge device endpoint,
   the amount of data that can be accepted varies.  This function
   sets the maximum amount of data West Bridge can accept in a single
   DMA operation.  The value is stored with the endpoint and passed
   to the HAL layer in the CyAsHalDmaSetupWrite() and
   CyAsHalDmaSetupRead() functoins.

   Returns
   * CY_AS_ERROR_SUCCESS - the value was set sucessfully
   * CY_AS_ERROR_INVALID_SIZE - the size value was not valid
*/
extern cy_as_return_status_t
cy_as_dma_set_max_dma_size(
	/* The device of interest */
	cy_as_device *dev_p,
	/* The endpoint to change */
	cy_as_end_point_number_t ep,
	/* The max size of this endpoint in bytes */
	uint32_t size
	);

/* Summary
   This function starts the DMA process on a given channel.

   Description
   When transferring data from the P port processor to West
   Bridge, the DMA operation must be initiated P Port software
   for the first transfer.  Subsequent transferrs will be
   handled at the interrupt level.

   Returns
   * CY_AS_ERROR_SUCCESS
*/
extern cy_as_return_status_t
cy_as_dma_kick_start(
	/* The device of interest */
	cy_as_device *dev_p,
	/* The endpoint to change */
	cy_as_end_point_number_t ep
	);

/* Summary
   This function receives endpoint data from a request.

   Description
   For endpoint 0 and 1 the endpoint data is transferred from
   the West Bridge device to the DMA via a lowlevel
   requests (via the mailbox registers).

   Returns
   * CY_AS_ERROR_SUCCESS
*/
extern cy_as_return_status_t
cy_as_dma_received_data(
	/* The device of interest */
	cy_as_device *dev_p,
	/* The endpoint that received data */
	cy_as_end_point_number_t ep,
	/* The data size */
	uint32_t dsize,
	/* The data buffer */
	void *data
	);

/* Summary
   This function is called when the DMA operation on
   an endpoint has been completed.

   Returns
   * void
 */
extern void
cy_as_dma_completed_callback(
	/* Tag to HAL completing the DMA operation. */
	cy_as_hal_device_tag	 tag,
	/* Endpoint on which DMA has been completed. */
	cy_as_end_point_number_t ep,
	/* Length of data received. */
	uint32_t			 length,
	/* Status of DMA operation. */
	cy_as_return_status_t   status
	);

#include "cyas_cplus_end.h"

#endif		  /* _INCLUDED_CYASDMA_H_ */
OpenPOWER on IntegriCloud