x86/xen: resume timer irqs early
[linux/fpc-iii.git] / drivers / staging / octeon-usb / cvmx-usb.h
blob8bf36966ef15d77ae15f70e01b854975ccedde14
1 /***********************license start***************
2 * Copyright (c) 2003-2010 Cavium Networks (support@cavium.com). All rights
3 * reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
18 * * Neither the name of Cavium Networks nor the names of
19 * its contributors may be used to endorse or promote products
20 * derived from this software without specific prior written
21 * permission.
23 * This Software, including technical data, may be subject to U.S. export control
24 * laws, including the U.S. Export Administration Act and its associated
25 * regulations, and may be subject to export or import regulations in other
26 * countries.
28 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
29 * AND WITH ALL FAULTS AND CAVIUM NETWORKS MAKES NO PROMISES, REPRESENTATIONS OR
30 * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO
31 * THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR
32 * DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM
33 * SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE,
34 * MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF
35 * VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR
36 * CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK ARISING OUT OF USE OR
37 * PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
38 ***********************license end**************************************/
41 /**
42 * "cvmx-usb.h" defines a set of low level USB functions to help
43 * developers create Octeon USB drivers for various operating
44 * systems. These functions provide a generic API to the Octeon
45 * USB blocks, hiding the internal hardware specific
46 * operations.
48 * At a high level the device driver needs to:
50 * - Call cvmx_usb_get_num_ports() to get the number of
51 * supported ports.
52 * - Call cvmx_usb_initialize() for each Octeon USB port.
53 * - Enable the port using cvmx_usb_enable().
54 * - Either periodically, or in an interrupt handler, call
55 * cvmx_usb_poll() to service USB events.
56 * - Manage pipes using cvmx_usb_open_pipe() and
57 * cvmx_usb_close_pipe().
58 * - Manage transfers using cvmx_usb_submit_*() and
59 * cvmx_usb_cancel*().
60 * - Shutdown USB on unload using cvmx_usb_shutdown().
62 * To monitor USB status changes, the device driver must use
63 * cvmx_usb_register_callback() to register for events that it
64 * is interested in. Below are a few hints on successfully
65 * implementing a driver on top of this API.
67 * == Initialization ==
69 * When a driver is first loaded, it is normally not necessary
70 * to bring up the USB port completely. Most operating systems
71 * expect to initialize and enable the port in two independent
72 * steps. Normally an operating system will probe hardware,
73 * initialize anything found, and then enable the hardware.
75 * In the probe phase you should:
76 * - Use cvmx_usb_get_num_ports() to determine the number of
77 * USB port to be supported.
78 * - Allocate space for a struct cvmx_usb_state for each
79 * port.
80 * - Tell the operating system about each port
82 * In the initialization phase you should:
83 * - Use cvmx_usb_initialize() on each port.
84 * - Do not call cvmx_usb_enable(). This leaves the USB port in
85 * the disabled state until the operating system is ready.
87 * Finally, in the enable phase you should:
88 * - Call cvmx_usb_enable() on the appropriate port.
89 * - Note that some operating system use a RESET instead of an
90 * enable call. To implement RESET, you should call
91 * cvmx_usb_disable() followed by cvmx_usb_enable().
93 * == Locking ==
95 * All of the functions in the cvmx-usb API assume exclusive
96 * access to the USB hardware and internal data structures. This
97 * means that the driver must provide locking as necessary.
99 * In the single CPU state it is normally enough to disable
100 * interrupts before every call to cvmx_usb*() and enable them
101 * again after the call is complete. Keep in mind that it is
102 * very common for the callback handlers to make additional
103 * calls into cvmx-usb, so the disable/enable must be protected
104 * against recursion. As an example, the Linux kernel
105 * local_irq_save() and local_irq_restore() are perfect for this
106 * in the non SMP case.
108 * In the SMP case, locking is more complicated. For SMP you not
109 * only need to disable interrupts on the local core, but also
110 * take a lock to make sure that another core cannot call
111 * cvmx-usb.
113 * == Port callback ==
115 * The port callback prototype needs to look as follows:
117 * void port_callback(struct cvmx_usb_state *usb,
118 * enum cvmx_usb_callback reason,
119 * enum cvmx_usb_complete status,
120 * int pipe_handle,
121 * int submit_handle,
122 * int bytes_transferred,
123 * void *user_data);
124 * - "usb" is the struct cvmx_usb_state for the port.
125 * - "reason" will always be CVMX_USB_CALLBACK_PORT_CHANGED.
126 * - "status" will always be CVMX_USB_COMPLETE_SUCCESS.
127 * - "pipe_handle" will always be -1.
128 * - "submit_handle" will always be -1.
129 * - "bytes_transferred" will always be 0.
130 * - "user_data" is the void pointer originally passed along
131 * with the callback. Use this for any state information you
132 * need.
134 * The port callback will be called whenever the user plugs /
135 * unplugs a device from the port. It will not be called when a
136 * device is plugged / unplugged from a hub connected to the
137 * root port. Normally all the callback needs to do is tell the
138 * operating system to poll the root hub for status. Under
139 * Linux, this is performed by calling usb_hcd_poll_rh_status().
140 * In the Linux driver we use "user_data". to pass around the
141 * Linux "hcd" structure. Once the port callback completes,
142 * Linux automatically calls octeon_usb_hub_status_data() which
143 * uses cvmx_usb_get_status() to determine the root port status.
145 * == Complete callback ==
147 * The completion callback prototype needs to look as follows:
149 * void complete_callback(struct cvmx_usb_state *usb,
150 * enum cvmx_usb_callback reason,
151 * enum cvmx_usb_complete status,
152 * int pipe_handle,
153 * int submit_handle,
154 * int bytes_transferred,
155 * void *user_data);
156 * - "usb" is the struct cvmx_usb_state for the port.
157 * - "reason" will always be CVMX_USB_CALLBACK_TRANSFER_COMPLETE.
158 * - "status" will be one of the cvmx_usb_complete enumerations.
159 * - "pipe_handle" is the handle to the pipe the transaction
160 * was originally submitted on.
161 * - "submit_handle" is the handle returned by the original
162 * cvmx_usb_submit_* call.
163 * - "bytes_transferred" is the number of bytes successfully
164 * transferred in the transaction. This will be zero on most
165 * error conditions.
166 * - "user_data" is the void pointer originally passed along
167 * with the callback. Use this for any state information you
168 * need. For example, the Linux "urb" is stored in here in the
169 * Linux driver.
171 * In general your callback handler should use "status" and
172 * "bytes_transferred" to tell the operating system the how the
173 * transaction completed. Normally the pipe is not changed in
174 * this callback.
176 * == Canceling transactions ==
178 * When a transaction is cancelled using cvmx_usb_cancel*(), the
179 * actual length of time until the complete callback is called
180 * can vary greatly. It may be called before cvmx_usb_cancel*()
181 * returns, or it may be called a number of usb frames in the
182 * future once the hardware frees the transaction. In either of
183 * these cases, the complete handler will receive
184 * CVMX_USB_COMPLETE_CANCEL.
186 * == Handling pipes ==
188 * USB "pipes" is a software construct created by this API to
189 * enable the ordering of usb transactions to a device endpoint.
190 * Octeon's underlying hardware doesn't have any concept
191 * equivalent to "pipes". The hardware instead has eight
192 * channels that can be used simultaneously to have up to eight
193 * transaction in process at the same time. In order to maintain
194 * ordering in a pipe, the transactions for a pipe will only be
195 * active in one hardware channel at a time. From an API user's
196 * perspective, this doesn't matter but it can be helpful to
197 * keep this in mind when you are probing hardware while
198 * debugging.
200 * Also keep in mind that usb transactions contain state
201 * information about the previous transaction to the same
202 * endpoint. Each transaction has a PID toggle that changes 0/1
203 * between each sub packet. This is maintained in the pipe data
204 * structures. For this reason, you generally cannot create and
205 * destroy a pipe for every transaction. A sequence of
206 * transaction to the same endpoint must use the same pipe.
208 * == Root Hub ==
210 * Some operating systems view the usb root port as a normal usb
211 * hub. These systems attempt to control the root hub with
212 * messages similar to the usb 2.0 spec for hub control and
213 * status. For these systems it may be necessary to write
214 * function to decode standard usb control messages into
215 * equivalent cvmx-usb API calls.
217 * == Interrupts ==
219 * If you plan on using usb interrupts, cvmx_usb_poll() must be
220 * called on every usb interrupt. It will read the usb state,
221 * call any needed callbacks, and schedule transactions as
222 * needed. Your device driver needs only to hookup an interrupt
223 * handler and call cvmx_usb_poll(). Octeon's usb port 0 causes
224 * CIU bit CIU_INT*_SUM0[USB] to be set (bit 56). For port 1,
225 * CIU bit CIU_INT_SUM1[USB1] is set (bit 17). How these bits
226 * are turned into interrupt numbers is operating system
227 * specific. For Linux, there are the convenient defines
228 * OCTEON_IRQ_USB0 and OCTEON_IRQ_USB1 for the IRQ numbers.
230 * If you aren't using interrupts, simple call cvmx_usb_poll()
231 * in your main processing loop.
234 #ifndef __CVMX_USB_H__
235 #define __CVMX_USB_H__
238 * enum cvmx_usb_speed - the possible USB device speeds
240 * @CVMX_USB_SPEED_HIGH: Device is operation at 480Mbps
241 * @CVMX_USB_SPEED_FULL: Device is operation at 12Mbps
242 * @CVMX_USB_SPEED_LOW: Device is operation at 1.5Mbps
244 enum cvmx_usb_speed {
245 CVMX_USB_SPEED_HIGH = 0,
246 CVMX_USB_SPEED_FULL = 1,
247 CVMX_USB_SPEED_LOW = 2,
251 * enum cvmx_usb_transfer - the possible USB transfer types
253 * @CVMX_USB_TRANSFER_CONTROL: USB transfer type control for hub and status
254 * transfers
255 * @CVMX_USB_TRANSFER_ISOCHRONOUS: USB transfer type isochronous for low
256 * priority periodic transfers
257 * @CVMX_USB_TRANSFER_BULK: USB transfer type bulk for large low priority
258 * transfers
259 * @CVMX_USB_TRANSFER_INTERRUPT: USB transfer type interrupt for high priority
260 * periodic transfers
262 enum cvmx_usb_transfer {
263 CVMX_USB_TRANSFER_CONTROL = 0,
264 CVMX_USB_TRANSFER_ISOCHRONOUS = 1,
265 CVMX_USB_TRANSFER_BULK = 2,
266 CVMX_USB_TRANSFER_INTERRUPT = 3,
270 * enum cvmx_usb_direction - the transfer directions
272 * @CVMX_USB_DIRECTION_OUT: Data is transferring from Octeon to the device/host
273 * @CVMX_USB_DIRECTION_IN: Data is transferring from the device/host to Octeon
275 enum cvmx_usb_direction {
276 CVMX_USB_DIRECTION_OUT,
277 CVMX_USB_DIRECTION_IN,
281 * enum cvmx_usb_complete - possible callback function status codes
283 * @CVMX_USB_COMPLETE_SUCCESS: The transaction / operation finished without
284 * any errors
285 * @CVMX_USB_COMPLETE_SHORT: FIXME: This is currently not implemented
286 * @CVMX_USB_COMPLETE_CANCEL: The transaction was canceled while in flight by
287 * a user call to cvmx_usb_cancel
288 * @CVMX_USB_COMPLETE_ERROR: The transaction aborted with an unexpected
289 * error status
290 * @CVMX_USB_COMPLETE_STALL: The transaction received a USB STALL response
291 * from the device
292 * @CVMX_USB_COMPLETE_XACTERR: The transaction failed with an error from the
293 * device even after a number of retries
294 * @CVMX_USB_COMPLETE_DATATGLERR: The transaction failed with a data toggle
295 * error even after a number of retries
296 * @CVMX_USB_COMPLETE_BABBLEERR: The transaction failed with a babble error
297 * @CVMX_USB_COMPLETE_FRAMEERR: The transaction failed with a frame error
298 * even after a number of retries
300 enum cvmx_usb_complete {
301 CVMX_USB_COMPLETE_SUCCESS,
302 CVMX_USB_COMPLETE_SHORT,
303 CVMX_USB_COMPLETE_CANCEL,
304 CVMX_USB_COMPLETE_ERROR,
305 CVMX_USB_COMPLETE_STALL,
306 CVMX_USB_COMPLETE_XACTERR,
307 CVMX_USB_COMPLETE_DATATGLERR,
308 CVMX_USB_COMPLETE_BABBLEERR,
309 CVMX_USB_COMPLETE_FRAMEERR,
313 * struct cvmx_usb_port_status - the USB port status information
315 * @port_enabled: 1 = Usb port is enabled, 0 = disabled
316 * @port_over_current: 1 = Over current detected, 0 = Over current not
317 * detected. Octeon doesn't support over current detection.
318 * @port_powered: 1 = Port power is being supplied to the device, 0 =
319 * power is off. Octeon doesn't support turning port power
320 * off.
321 * @port_speed: Current port speed.
322 * @connected: 1 = A device is connected to the port, 0 = No device is
323 * connected.
324 * @connect_change: 1 = Device connected state changed since the last set
325 * status call.
327 struct cvmx_usb_port_status {
328 uint32_t reserved : 25;
329 uint32_t port_enabled : 1;
330 uint32_t port_over_current : 1;
331 uint32_t port_powered : 1;
332 enum cvmx_usb_speed port_speed : 2;
333 uint32_t connected : 1;
334 uint32_t connect_change : 1;
338 * union cvmx_usb_control_header - the structure of a Control packet header
340 * @s.request_type: Bit 7 tells the direction: 1=IN, 0=OUT
341 * @s.request The standard usb request to make
342 * @s.value Value parameter for the request in little endian format
343 * @s.index Index for the request in little endian format
344 * @s.length Length of the data associated with this request in
345 * little endian format
347 union cvmx_usb_control_header {
348 uint64_t u64;
349 struct {
350 uint64_t request_type : 8;
351 uint64_t request : 8;
352 uint64_t value : 16;
353 uint64_t index : 16;
354 uint64_t length : 16;
355 } s;
359 * struct cvmx_usb_iso_packet - descriptor for Isochronous packets
361 * @offset: This is the offset in bytes into the main buffer where this data
362 * is stored.
363 * @length: This is the length in bytes of the data.
364 * @status: This is the status of this individual packet transfer.
366 struct cvmx_usb_iso_packet {
367 int offset;
368 int length;
369 enum cvmx_usb_complete status;
373 * enum cvmx_usb_callback - possible callback reasons for the USB API
375 * @CVMX_USB_CALLBACK_TRANSFER_COMPLETE: A callback of this type is called when
376 * a submitted transfer completes. The
377 * completion callback will be called even
378 * if the transfer fails or is canceled.
379 * The status parameter will contain
380 * details of why he callback was called.
381 * @CVMX_USB_CALLBACK_PORT_CHANGED: The status of the port changed. For
382 * example, someone may have plugged a
383 * device in. The status parameter
384 * contains CVMX_USB_COMPLETE_SUCCESS. Use
385 * cvmx_usb_get_status() to get the new
386 * port status.
387 * @__CVMX_USB_CALLBACK_END: Do not use. Used internally for array
388 * bounds.
390 enum cvmx_usb_callback {
391 CVMX_USB_CALLBACK_TRANSFER_COMPLETE,
392 CVMX_USB_CALLBACK_PORT_CHANGED,
393 __CVMX_USB_CALLBACK_END
397 * USB state internal data. The contents of this structure
398 * may change in future SDKs. No data in it should be referenced
399 * by user's of this API.
401 struct cvmx_usb_state {
402 char data[65536];
406 * USB callback functions are always of the following type.
407 * The parameters are as follows:
408 * - state = USB device state populated by
409 * cvmx_usb_initialize().
410 * - reason = The enum cvmx_usb_callback used to register
411 * the callback.
412 * - status = The enum cvmx_usb_complete representing the
413 * status code of a transaction.
414 * - pipe_handle = The Pipe that caused this callback, or
415 * -1 if this callback wasn't associated with a pipe.
416 * - submit_handle = Transfer submit handle causing this
417 * callback, or -1 if this callback wasn't associated
418 * with a transfer.
419 * - Actual number of bytes transfer.
420 * - user_data = The user pointer supplied to the
421 * function cvmx_usb_submit() or
422 * cvmx_usb_register_callback() */
423 typedef void (*cvmx_usb_callback_func_t)(struct cvmx_usb_state *state,
424 enum cvmx_usb_callback reason,
425 enum cvmx_usb_complete status,
426 int pipe_handle, int submit_handle,
427 int bytes_transferred, void *user_data);
430 * enum cvmx_usb_initialize_flags - flags to pass the initialization function
432 * @CVMX_USB_INITIALIZE_FLAGS_CLOCK_XO_XI: The USB port uses a 12MHz crystal
433 * as clock source at USB_XO and
434 * USB_XI.
435 * @CVMX_USB_INITIALIZE_FLAGS_CLOCK_XO_GND: The USB port uses 12/24/48MHz 2.5V
436 * board clock source at USB_XO.
437 * USB_XI should be tied to GND.
438 * @CVMX_USB_INITIALIZE_FLAGS_CLOCK_AUTO: Automatically determine clock type
439 * based on function in
440 * cvmx-helper-board.c.
441 * @CVMX_USB_INITIALIZE_FLAGS_CLOCK_MHZ_MASK: Mask for clock speed field
442 * @CVMX_USB_INITIALIZE_FLAGS_CLOCK_12MHZ: Speed of reference clock or
443 * crystal
444 * @CVMX_USB_INITIALIZE_FLAGS_CLOCK_24MHZ: Speed of reference clock
445 * @CVMX_USB_INITIALIZE_FLAGS_CLOCK_48MHZ: Speed of reference clock
446 * @CVMX_USB_INITIALIZE_FLAGS_NO_DMA: Disable DMA and used polled IO for
447 * data transfer use for the USB
449 enum cvmx_usb_initialize_flags {
450 CVMX_USB_INITIALIZE_FLAGS_CLOCK_XO_XI = 1 << 0,
451 CVMX_USB_INITIALIZE_FLAGS_CLOCK_XO_GND = 1 << 1,
452 CVMX_USB_INITIALIZE_FLAGS_CLOCK_AUTO = 0,
453 CVMX_USB_INITIALIZE_FLAGS_CLOCK_MHZ_MASK = 3 << 3,
454 CVMX_USB_INITIALIZE_FLAGS_CLOCK_12MHZ = 1 << 3,
455 CVMX_USB_INITIALIZE_FLAGS_CLOCK_24MHZ = 2 << 3,
456 CVMX_USB_INITIALIZE_FLAGS_CLOCK_48MHZ = 3 << 3,
457 /* Bits 3-4 used to encode the clock frequency */
458 CVMX_USB_INITIALIZE_FLAGS_NO_DMA = 1 << 5,
462 * enum cvmx_usb_pipe_flags - flags for passing when a pipe is created.
463 * Currently no flags need to be passed.
465 * @__CVMX_USB_PIPE_FLAGS_OPEN: Used internally to determine if a pipe is
466 * open. Do not use.
467 * @__CVMX_USB_PIPE_FLAGS_SCHEDULED: Used internally to determine if a pipe is
468 * actively using hardware. Do not use.
469 * @__CVMX_USB_PIPE_FLAGS_NEED_PING: Used internally to determine if a high
470 * speed pipe is in the ping state. Do not
471 * use.
473 enum cvmx_usb_pipe_flags {
474 __CVMX_USB_PIPE_FLAGS_OPEN = 1 << 16,
475 __CVMX_USB_PIPE_FLAGS_SCHEDULED = 1 << 17,
476 __CVMX_USB_PIPE_FLAGS_NEED_PING = 1 << 18,
479 extern int cvmx_usb_get_num_ports(void);
480 extern int cvmx_usb_initialize(struct cvmx_usb_state *state, int usb_port_number,
481 enum cvmx_usb_initialize_flags flags);
482 extern int cvmx_usb_shutdown(struct cvmx_usb_state *state);
483 extern int cvmx_usb_enable(struct cvmx_usb_state *state);
484 extern int cvmx_usb_disable(struct cvmx_usb_state *state);
485 extern struct cvmx_usb_port_status cvmx_usb_get_status(struct cvmx_usb_state *state);
486 extern void cvmx_usb_set_status(struct cvmx_usb_state *state, struct cvmx_usb_port_status port_status);
487 extern int cvmx_usb_open_pipe(struct cvmx_usb_state *state,
488 enum cvmx_usb_pipe_flags flags,
489 int device_addr, int endpoint_num,
490 enum cvmx_usb_speed device_speed, int max_packet,
491 enum cvmx_usb_transfer transfer_type,
492 enum cvmx_usb_direction transfer_dir, int interval,
493 int multi_count, int hub_device_addr,
494 int hub_port);
495 extern int cvmx_usb_submit_bulk(struct cvmx_usb_state *state, int pipe_handle,
496 uint64_t buffer, int buffer_length,
497 cvmx_usb_callback_func_t callback,
498 void *user_data);
499 extern int cvmx_usb_submit_interrupt(struct cvmx_usb_state *state, int pipe_handle,
500 uint64_t buffer, int buffer_length,
501 cvmx_usb_callback_func_t callback,
502 void *user_data);
503 extern int cvmx_usb_submit_control(struct cvmx_usb_state *state, int pipe_handle,
504 uint64_t control_header,
505 uint64_t buffer, int buffer_length,
506 cvmx_usb_callback_func_t callback,
507 void *user_data);
510 * enum cvmx_usb_isochronous_flags - flags to pass the
511 * cvmx_usb_submit_isochronous() function.
513 * @CVMX_USB_ISOCHRONOUS_FLAGS_ALLOW_SHORT: Do not return an error if a transfer
514 * is less than the maximum packet size
515 * of the device.
516 * @CVMX_USB_ISOCHRONOUS_FLAGS_ASAP: Schedule the transaction as soon as
517 * possible.
519 enum cvmx_usb_isochronous_flags {
520 CVMX_USB_ISOCHRONOUS_FLAGS_ALLOW_SHORT = 1 << 0,
521 CVMX_USB_ISOCHRONOUS_FLAGS_ASAP = 1 << 1,
524 extern int cvmx_usb_submit_isochronous(struct cvmx_usb_state *state, int pipe_handle,
525 int start_frame, int flags,
526 int number_packets,
527 struct cvmx_usb_iso_packet packets[],
528 uint64_t buffer, int buffer_length,
529 cvmx_usb_callback_func_t callback,
530 void *user_data);
531 extern int cvmx_usb_cancel(struct cvmx_usb_state *state, int pipe_handle,
532 int submit_handle);
533 extern int cvmx_usb_cancel_all(struct cvmx_usb_state *state, int pipe_handle);
534 extern int cvmx_usb_close_pipe(struct cvmx_usb_state *state, int pipe_handle);
535 extern int cvmx_usb_register_callback(struct cvmx_usb_state *state,
536 enum cvmx_usb_callback reason,
537 cvmx_usb_callback_func_t callback,
538 void *user_data);
539 extern int cvmx_usb_get_frame_number(struct cvmx_usb_state *state);
540 extern int cvmx_usb_poll(struct cvmx_usb_state *state);
542 #endif /* __CVMX_USB_H__ */