[91db50ac] | 1 | /*
|
---|
| 2 | * Copyright (c) 2010 Vojtech Horky
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
[3b77628] | 29 | /** @addtogroup libdrv
|
---|
| 30 | * @addtogroup usb
|
---|
[91db50ac] | 31 | * @{
|
---|
| 32 | */
|
---|
| 33 | /** @file
|
---|
[6edd494] | 34 | * @brief USB host controller interface definition.
|
---|
[91db50ac] | 35 | */
|
---|
| 36 |
|
---|
[cb59f787] | 37 | #ifndef LIBDRV_USBHC_IFACE_H_
|
---|
| 38 | #define LIBDRV_USBHC_IFACE_H_
|
---|
[91db50ac] | 39 |
|
---|
[eb1a2f4] | 40 | #include "ddf/driver.h"
|
---|
[91db50ac] | 41 | #include <usb/usb.h>
|
---|
[6427cf67] | 42 | #include <bool.h>
|
---|
[91db50ac] | 43 |
|
---|
| 44 |
|
---|
| 45 | /** IPC methods for communication with HC through DDF interface.
|
---|
| 46 | *
|
---|
| 47 | * Notes for async methods:
|
---|
| 48 | *
|
---|
| 49 | * Methods for sending data to device (OUT transactions)
|
---|
[cb59f787] | 50 | * - e.g. IPC_M_USBHC_INTERRUPT_OUT -
|
---|
[91db50ac] | 51 | * always use the same semantics:
|
---|
| 52 | * - first, IPC call with given method is made
|
---|
| 53 | * - argument #1 is target address
|
---|
| 54 | * - argument #2 is target endpoint
|
---|
[228f251] | 55 | * - argument #3 is max packet size of the endpoint
|
---|
[91db50ac] | 56 | * - this call is immediately followed by IPC data write (from caller)
|
---|
| 57 | * - the initial call (and the whole transaction) is answer after the
|
---|
| 58 | * transaction is scheduled by the HC and acknowledged by the device
|
---|
| 59 | * or immediately after error is detected
|
---|
| 60 | * - the answer carries only the error code
|
---|
| 61 | *
|
---|
| 62 | * Methods for retrieving data from device (IN transactions)
|
---|
[cb59f787] | 63 | * - e.g. IPC_M_USBHC_INTERRUPT_IN -
|
---|
[91db50ac] | 64 | * also use the same semantics:
|
---|
| 65 | * - first, IPC call with given method is made
|
---|
| 66 | * - argument #1 is target address
|
---|
| 67 | * - argument #2 is target endpoint
|
---|
[1e64b250] | 68 | * - this call is immediately followed by IPC data read (async version)
|
---|
[91db50ac] | 69 | * - the call is not answered until the device returns some data (or until
|
---|
| 70 | * error occurs)
|
---|
| 71 | *
|
---|
| 72 | * Some special methods (NO-DATA transactions) do not send any data. These
|
---|
| 73 | * might behave as both OUT or IN transactions because communication parts
|
---|
| 74 | * where actual buffers are exchanged are omitted.
|
---|
[1e64b250] | 75 | **
|
---|
[91db50ac] | 76 | * For all these methods, wrap functions exists. Important rule: functions
|
---|
| 77 | * for IN transactions have (as parameters) buffers where retrieved data
|
---|
| 78 | * will be stored. These buffers must be already allocated and shall not be
|
---|
| 79 | * touch until the transaction is completed
|
---|
| 80 | * (e.g. not before calling usb_wait_for() with appropriate handle).
|
---|
| 81 | * OUT transactions buffers can be freed immediately after call is dispatched
|
---|
| 82 | * (i.e. after return from wrapping function).
|
---|
| 83 | *
|
---|
| 84 | */
|
---|
| 85 | typedef enum {
|
---|
[6f04905] | 86 | /** Asks for address assignment by host controller.
|
---|
| 87 | * Answer:
|
---|
| 88 | * - ELIMIT - host controller run out of address
|
---|
| 89 | * - EOK - address assigned
|
---|
| 90 | * Answer arguments:
|
---|
| 91 | * - assigned address
|
---|
| 92 | *
|
---|
| 93 | * The address must be released by via IPC_M_USBHC_RELEASE_ADDRESS.
|
---|
| 94 | */
|
---|
| 95 | IPC_M_USBHC_REQUEST_ADDRESS,
|
---|
| 96 |
|
---|
[4689d40] | 97 | /** Bind USB address with devman handle.
|
---|
| 98 | * Parameters:
|
---|
| 99 | * - USB address
|
---|
| 100 | * - devman handle
|
---|
| 101 | * Answer:
|
---|
| 102 | * - EOK - address binded
|
---|
| 103 | * - ENOENT - address is not in use
|
---|
| 104 | */
|
---|
| 105 | IPC_M_USBHC_BIND_ADDRESS,
|
---|
| 106 |
|
---|
[eb2f7dd] | 107 | /** Get handle binded with given USB address.
|
---|
| 108 | * Parameters
|
---|
| 109 | * - USB address
|
---|
| 110 | * Answer:
|
---|
| 111 | * - EOK - address binded, first parameter is the devman handle
|
---|
| 112 | * - ENOENT - address is not in use at the moment
|
---|
| 113 | */
|
---|
| 114 | IPC_M_USBHC_GET_HANDLE_BY_ADDRESS,
|
---|
| 115 |
|
---|
[6f04905] | 116 | /** Release address in use.
|
---|
| 117 | * Arguments:
|
---|
| 118 | * - address to be released
|
---|
| 119 | * Answer:
|
---|
| 120 | * - ENOENT - address not in use
|
---|
| 121 | * - EPERM - trying to release default USB address
|
---|
| 122 | */
|
---|
| 123 | IPC_M_USBHC_RELEASE_ADDRESS,
|
---|
| 124 |
|
---|
| 125 |
|
---|
[91db50ac] | 126 | /** Send interrupt data to device.
|
---|
[1b22bd4] | 127 | * See explanation at usb_iface_funcs_t (OUT transaction).
|
---|
[91db50ac] | 128 | */
|
---|
[cb59f787] | 129 | IPC_M_USBHC_INTERRUPT_OUT,
|
---|
[91db50ac] | 130 |
|
---|
| 131 | /** Get interrupt data from device.
|
---|
[1b22bd4] | 132 | * See explanation at usb_iface_funcs_t (IN transaction).
|
---|
[91db50ac] | 133 | */
|
---|
[cb59f787] | 134 | IPC_M_USBHC_INTERRUPT_IN,
|
---|
[91db50ac] | 135 |
|
---|
[0a46c41e] | 136 | /** Send bulk data to device.
|
---|
| 137 | * See explanation at usb_iface_funcs_t (OUT transaction).
|
---|
| 138 | */
|
---|
| 139 | IPC_M_USBHC_BULK_OUT,
|
---|
| 140 |
|
---|
| 141 | /** Get bulk data from device.
|
---|
| 142 | * See explanation at usb_iface_funcs_t (IN transaction).
|
---|
| 143 | */
|
---|
| 144 | IPC_M_USBHC_BULK_IN,
|
---|
| 145 |
|
---|
[9753220] | 146 | /** Issue control WRITE transfer.
|
---|
| 147 | * See explanation at usb_iface_funcs_t (OUT transaction) for
|
---|
| 148 | * call parameters.
|
---|
| 149 | * This call is immediately followed by two IPC data writes
|
---|
| 150 | * from the caller (setup packet and actual data).
|
---|
| 151 | */
|
---|
| 152 | IPC_M_USBHC_CONTROL_WRITE,
|
---|
| 153 |
|
---|
[228f251] | 154 | /** Issue control READ transfer.
|
---|
[9753220] | 155 | * See explanation at usb_iface_funcs_t (IN transaction) for
|
---|
| 156 | * call parameters.
|
---|
[228f251] | 157 | * This call is immediately followed by IPC data write from the caller
|
---|
| 158 | * (setup packet) and IPC data read (buffer that was read).
|
---|
[9753220] | 159 | */
|
---|
| 160 | IPC_M_USBHC_CONTROL_READ,
|
---|
[91db50ac] | 161 |
|
---|
[b7d8fd9] | 162 | /** Register endpoint attributes at host controller.
|
---|
| 163 | * This is used to reserve portion of USB bandwidth.
|
---|
[1998bcd] | 164 | * When speed is invalid, speed of the device is used.
|
---|
[b7d8fd9] | 165 | * Parameters:
|
---|
[1998bcd] | 166 | * - USB address + endpoint number
|
---|
| 167 | * - packed as ADDR << 16 + EP
|
---|
| 168 | * - speed + transfer type + direction
|
---|
| 169 | * - packed as ( SPEED << 8 + TYPE ) << 8 + DIR
|
---|
| 170 | * - maximum packet size + interval (in milliseconds)
|
---|
| 171 | * - packed as MPS << 16 + INT
|
---|
[b7d8fd9] | 172 | * Answer:
|
---|
| 173 | * - EOK - reservation successful
|
---|
| 174 | * - ELIMIT - not enough bandwidth to satisfy the request
|
---|
| 175 | */
|
---|
| 176 | IPC_M_USBHC_REGISTER_ENDPOINT,
|
---|
| 177 |
|
---|
| 178 | /** Revert endpoint registration.
|
---|
| 179 | * Parameters:
|
---|
| 180 | * - USB address
|
---|
| 181 | * - endpoint number
|
---|
| 182 | * - data direction
|
---|
| 183 | * Answer:
|
---|
| 184 | * - EOK - endpoint unregistered
|
---|
| 185 | * - ENOENT - unknown endpoint
|
---|
| 186 | */
|
---|
| 187 | IPC_M_USBHC_UNREGISTER_ENDPOINT
|
---|
[cb59f787] | 188 | } usbhc_iface_funcs_t;
|
---|
[91db50ac] | 189 |
|
---|
| 190 | /** Callback for outgoing transfer. */
|
---|
[eb1a2f4] | 191 | typedef void (*usbhc_iface_transfer_out_callback_t)(ddf_fun_t *,
|
---|
[daec5e04] | 192 | int, void *);
|
---|
[91db50ac] | 193 |
|
---|
| 194 | /** Callback for incoming transfer. */
|
---|
[eb1a2f4] | 195 | typedef void (*usbhc_iface_transfer_in_callback_t)(ddf_fun_t *,
|
---|
[daec5e04] | 196 | int, size_t, void *);
|
---|
[91db50ac] | 197 |
|
---|
[fb1dca09] | 198 |
|
---|
| 199 | /** Out transfer processing function prototype. */
|
---|
[7dfc06fa] | 200 | typedef int (*usbhc_iface_transfer_out_t)(ddf_fun_t *, usb_target_t,
|
---|
[fb1dca09] | 201 | void *, size_t,
|
---|
| 202 | usbhc_iface_transfer_out_callback_t, void *);
|
---|
| 203 |
|
---|
[ec59693] | 204 | /** Setup transfer processing function prototype. @deprecated */
|
---|
[fb1dca09] | 205 | typedef usbhc_iface_transfer_out_t usbhc_iface_transfer_setup_t;
|
---|
| 206 |
|
---|
| 207 | /** In transfer processing function prototype. */
|
---|
[7dfc06fa] | 208 | typedef int (*usbhc_iface_transfer_in_t)(ddf_fun_t *, usb_target_t,
|
---|
[fb1dca09] | 209 | void *, size_t,
|
---|
| 210 | usbhc_iface_transfer_in_callback_t, void *);
|
---|
| 211 |
|
---|
[6edd494] | 212 | /** USB host controller communication interface. */
|
---|
[91db50ac] | 213 | typedef struct {
|
---|
[eb1a2f4] | 214 | int (*reserve_default_address)(ddf_fun_t *, usb_speed_t);
|
---|
| 215 | int (*release_default_address)(ddf_fun_t *);
|
---|
| 216 | int (*request_address)(ddf_fun_t *, usb_speed_t, usb_address_t *);
|
---|
| 217 | int (*bind_address)(ddf_fun_t *, usb_address_t, devman_handle_t);
|
---|
[eb2f7dd] | 218 | int (*find_by_address)(ddf_fun_t *, usb_address_t, devman_handle_t *);
|
---|
[eb1a2f4] | 219 | int (*release_address)(ddf_fun_t *, usb_address_t);
|
---|
[6f04905] | 220 |
|
---|
[1998bcd] | 221 | int (*register_endpoint)(ddf_fun_t *,
|
---|
| 222 | usb_address_t, usb_speed_t, usb_endpoint_t,
|
---|
[b7d8fd9] | 223 | usb_transfer_type_t, usb_direction_t, size_t, unsigned int);
|
---|
| 224 | int (*unregister_endpoint)(ddf_fun_t *, usb_address_t, usb_endpoint_t,
|
---|
| 225 | usb_direction_t);
|
---|
| 226 |
|
---|
[fb1dca09] | 227 | usbhc_iface_transfer_out_t interrupt_out;
|
---|
| 228 | usbhc_iface_transfer_in_t interrupt_in;
|
---|
[a3dfb2e] | 229 |
|
---|
[0a46c41e] | 230 | usbhc_iface_transfer_out_t bulk_out;
|
---|
| 231 | usbhc_iface_transfer_in_t bulk_in;
|
---|
| 232 |
|
---|
[eb1a2f4] | 233 | int (*control_write)(ddf_fun_t *, usb_target_t,
|
---|
[9753220] | 234 | void *, size_t, void *, size_t,
|
---|
| 235 | usbhc_iface_transfer_out_callback_t, void *);
|
---|
| 236 |
|
---|
[eb1a2f4] | 237 | int (*control_read)(ddf_fun_t *, usb_target_t,
|
---|
[9753220] | 238 | void *, size_t, void *, size_t,
|
---|
| 239 | usbhc_iface_transfer_in_callback_t, void *);
|
---|
[cb59f787] | 240 | } usbhc_iface_t;
|
---|
[91db50ac] | 241 |
|
---|
| 242 |
|
---|
| 243 | #endif
|
---|
| 244 | /**
|
---|
| 245 | * @}
|
---|
| 246 | */
|
---|