[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 |
|
---|
| 40 | #include "driver.h"
|
---|
| 41 | #include <usb/usb.h>
|
---|
| 42 |
|
---|
| 43 |
|
---|
| 44 | /** IPC methods for communication with HC through DDF interface.
|
---|
| 45 | *
|
---|
| 46 | * Notes for async methods:
|
---|
| 47 | *
|
---|
| 48 | * Methods for sending data to device (OUT transactions)
|
---|
[cb59f787] | 49 | * - e.g. IPC_M_USBHC_INTERRUPT_OUT -
|
---|
[91db50ac] | 50 | * always use the same semantics:
|
---|
| 51 | * - first, IPC call with given method is made
|
---|
| 52 | * - argument #1 is target address
|
---|
| 53 | * - argument #2 is target endpoint
|
---|
| 54 | * - argument #3 is buffer size
|
---|
| 55 | * - this call is immediately followed by IPC data write (from caller)
|
---|
| 56 | * - the initial call (and the whole transaction) is answer after the
|
---|
| 57 | * transaction is scheduled by the HC and acknowledged by the device
|
---|
| 58 | * or immediately after error is detected
|
---|
| 59 | * - the answer carries only the error code
|
---|
| 60 | *
|
---|
| 61 | * Methods for retrieving data from device (IN transactions)
|
---|
[cb59f787] | 62 | * - e.g. IPC_M_USBHC_INTERRUPT_IN -
|
---|
[91db50ac] | 63 | * also use the same semantics:
|
---|
| 64 | * - first, IPC call with given method is made
|
---|
| 65 | * - argument #1 is target address
|
---|
| 66 | * - argument #2 is target endpoint
|
---|
| 67 | * - argument #3 is buffer size
|
---|
| 68 | * - the call is not answered until the device returns some data (or until
|
---|
| 69 | * error occurs)
|
---|
| 70 | * - if the call is answered with EOK, first argument of the answer is buffer
|
---|
| 71 | * hash that could be used to retrieve the actual data
|
---|
| 72 | *
|
---|
| 73 | * Some special methods (NO-DATA transactions) do not send any data. These
|
---|
| 74 | * might behave as both OUT or IN transactions because communication parts
|
---|
| 75 | * where actual buffers are exchanged are omitted.
|
---|
| 76 | *
|
---|
| 77 | * The mentioned data retrieval can be done any time after receiving EOK
|
---|
| 78 | * answer to IN method.
|
---|
[cb59f787] | 79 | * This retrieval is done using the IPC_M_USBHC_GET_BUFFER where
|
---|
[91db50ac] | 80 | * the first argument is buffer hash from call answer.
|
---|
| 81 | * This call must be immediately followed by data read-in and after the
|
---|
[cb59f787] | 82 | * data are transferred, the initial call (IPC_M_USBHC_GET_BUFFER)
|
---|
[91db50ac] | 83 | * is answered. Each buffer can be retrieved only once.
|
---|
| 84 | *
|
---|
| 85 | * For all these methods, wrap functions exists. Important rule: functions
|
---|
| 86 | * for IN transactions have (as parameters) buffers where retrieved data
|
---|
| 87 | * will be stored. These buffers must be already allocated and shall not be
|
---|
| 88 | * touch until the transaction is completed
|
---|
| 89 | * (e.g. not before calling usb_wait_for() with appropriate handle).
|
---|
| 90 | * OUT transactions buffers can be freed immediately after call is dispatched
|
---|
| 91 | * (i.e. after return from wrapping function).
|
---|
| 92 | *
|
---|
| 93 | */
|
---|
| 94 | typedef enum {
|
---|
[aae339e9] | 95 | /** Tell USB address assigned to device.
|
---|
| 96 | * Parameters:
|
---|
| 97 | * - devman handle id
|
---|
| 98 | * Answer:
|
---|
| 99 | * - EINVAL - unknown handle or handle not managed by this driver
|
---|
| 100 | * - ENOTSUP - operation not supported by HC (shall not happen)
|
---|
| 101 | * - arbitrary error code if returned by remote implementation
|
---|
| 102 | * - EOK - handle found, first parameter contains the USB address
|
---|
| 103 | */
|
---|
| 104 | IPC_M_USBHC_GET_ADDRESS,
|
---|
| 105 |
|
---|
[91db50ac] | 106 | /** Asks for data buffer.
|
---|
[1b22bd4] | 107 | * See explanation at usb_iface_funcs_t.
|
---|
| 108 | * This function does not have counter part in functional interface
|
---|
| 109 | * as it is handled by the remote part itself.
|
---|
[91db50ac] | 110 | */
|
---|
[cb59f787] | 111 | IPC_M_USBHC_GET_BUFFER,
|
---|
[91db50ac] | 112 |
|
---|
| 113 |
|
---|
[6f04905] | 114 | /** Reserve usage of default address.
|
---|
| 115 | * This call informs the host controller that the caller will be
|
---|
| 116 | * using default USB address. It is duty of the HC driver to ensure
|
---|
| 117 | * that only single entity will have it reserved.
|
---|
| 118 | * The address is returned via IPC_M_USBHC_RELEASE_DEFAULT_ADDRESS.
|
---|
| 119 | * The caller can start using the address after receiving EOK
|
---|
| 120 | * answer.
|
---|
| 121 | */
|
---|
| 122 | IPC_M_USBHC_RESERVE_DEFAULT_ADDRESS,
|
---|
| 123 |
|
---|
| 124 | /** Release usage of default address.
|
---|
| 125 | * @see IPC_M_USBHC_RESERVE_DEFAULT_ADDRESS
|
---|
| 126 | */
|
---|
| 127 | IPC_M_USBHC_RELEASE_DEFAULT_ADDRESS,
|
---|
| 128 |
|
---|
| 129 | /** Asks for address assignment by host controller.
|
---|
| 130 | * Answer:
|
---|
| 131 | * - ELIMIT - host controller run out of address
|
---|
| 132 | * - EOK - address assigned
|
---|
| 133 | * Answer arguments:
|
---|
| 134 | * - assigned address
|
---|
| 135 | *
|
---|
| 136 | * The address must be released by via IPC_M_USBHC_RELEASE_ADDRESS.
|
---|
| 137 | */
|
---|
| 138 | IPC_M_USBHC_REQUEST_ADDRESS,
|
---|
| 139 |
|
---|
[4689d40] | 140 | /** Bind USB address with devman handle.
|
---|
| 141 | * Parameters:
|
---|
| 142 | * - USB address
|
---|
| 143 | * - devman handle
|
---|
| 144 | * Answer:
|
---|
| 145 | * - EOK - address binded
|
---|
| 146 | * - ENOENT - address is not in use
|
---|
| 147 | */
|
---|
| 148 | IPC_M_USBHC_BIND_ADDRESS,
|
---|
| 149 |
|
---|
[6f04905] | 150 | /** Release address in use.
|
---|
| 151 | * Arguments:
|
---|
| 152 | * - address to be released
|
---|
| 153 | * Answer:
|
---|
| 154 | * - ENOENT - address not in use
|
---|
| 155 | * - EPERM - trying to release default USB address
|
---|
| 156 | */
|
---|
| 157 | IPC_M_USBHC_RELEASE_ADDRESS,
|
---|
| 158 |
|
---|
| 159 |
|
---|
[91db50ac] | 160 | /** Send interrupt data to device.
|
---|
[1b22bd4] | 161 | * See explanation at usb_iface_funcs_t (OUT transaction).
|
---|
[91db50ac] | 162 | */
|
---|
[cb59f787] | 163 | IPC_M_USBHC_INTERRUPT_OUT,
|
---|
[91db50ac] | 164 |
|
---|
| 165 | /** Get interrupt data from device.
|
---|
[1b22bd4] | 166 | * See explanation at usb_iface_funcs_t (IN transaction).
|
---|
[91db50ac] | 167 | */
|
---|
[cb59f787] | 168 | IPC_M_USBHC_INTERRUPT_IN,
|
---|
[91db50ac] | 169 |
|
---|
| 170 |
|
---|
| 171 | /** Start WRITE control transfer.
|
---|
[1b22bd4] | 172 | * See explanation at usb_iface_funcs_t (OUT transaction).
|
---|
[91db50ac] | 173 | */
|
---|
[cb59f787] | 174 | IPC_M_USBHC_CONTROL_WRITE_SETUP,
|
---|
[91db50ac] | 175 |
|
---|
| 176 | /** Send control-transfer data to device.
|
---|
[1b22bd4] | 177 | * See explanation at usb_iface_funcs_t (OUT transaction).
|
---|
[91db50ac] | 178 | */
|
---|
[cb59f787] | 179 | IPC_M_USBHC_CONTROL_WRITE_DATA,
|
---|
[91db50ac] | 180 |
|
---|
| 181 | /** Terminate WRITE control transfer.
|
---|
[1b22bd4] | 182 | * See explanation at usb_iface_funcs_t (NO-DATA transaction).
|
---|
[91db50ac] | 183 | */
|
---|
[cb59f787] | 184 | IPC_M_USBHC_CONTROL_WRITE_STATUS,
|
---|
[91db50ac] | 185 |
|
---|
| 186 |
|
---|
| 187 |
|
---|
| 188 | /** Start READ control transfer.
|
---|
[1b22bd4] | 189 | * See explanation at usb_iface_funcs_t (OUT transaction).
|
---|
[91db50ac] | 190 | */
|
---|
[cb59f787] | 191 | IPC_M_USBHC_CONTROL_READ_SETUP,
|
---|
[91db50ac] | 192 |
|
---|
| 193 | /** Get control-transfer data from device.
|
---|
[1b22bd4] | 194 | * See explanation at usb_iface_funcs_t (IN transaction).
|
---|
[91db50ac] | 195 | */
|
---|
[cb59f787] | 196 | IPC_M_USBHC_CONTROL_READ_DATA,
|
---|
[91db50ac] | 197 |
|
---|
| 198 | /** Terminate READ control transfer.
|
---|
[1b22bd4] | 199 | * See explanation at usb_iface_funcs_t (NO-DATA transaction).
|
---|
[91db50ac] | 200 | */
|
---|
[cb59f787] | 201 | IPC_M_USBHC_CONTROL_READ_STATUS,
|
---|
[91db50ac] | 202 |
|
---|
[9753220] | 203 | /** Issue control WRITE transfer.
|
---|
| 204 | * See explanation at usb_iface_funcs_t (OUT transaction) for
|
---|
| 205 | * call parameters.
|
---|
| 206 | * This call is immediately followed by two IPC data writes
|
---|
| 207 | * from the caller (setup packet and actual data).
|
---|
| 208 | */
|
---|
| 209 | IPC_M_USBHC_CONTROL_WRITE,
|
---|
| 210 |
|
---|
| 211 | /** Issue control WRITE transfer.
|
---|
| 212 | * See explanation at usb_iface_funcs_t (IN transaction) for
|
---|
| 213 | * call parameters.
|
---|
| 214 | * This call is immediately followed by IPC data read from the caller
|
---|
| 215 | * (setup packet).
|
---|
| 216 | * Actual data are retrieved through IPC_M_USBHC_GET_BUFFER.
|
---|
| 217 | */
|
---|
| 218 | IPC_M_USBHC_CONTROL_READ,
|
---|
[91db50ac] | 219 |
|
---|
| 220 | /* IPC_M_USB_ */
|
---|
[cb59f787] | 221 | } usbhc_iface_funcs_t;
|
---|
[91db50ac] | 222 |
|
---|
| 223 | /** Callback for outgoing transfer. */
|
---|
[cb59f787] | 224 | typedef void (*usbhc_iface_transfer_out_callback_t)(device_t *,
|
---|
[91db50ac] | 225 | usb_transaction_outcome_t, void *);
|
---|
| 226 |
|
---|
| 227 | /** Callback for incoming transfer. */
|
---|
[cb59f787] | 228 | typedef void (*usbhc_iface_transfer_in_callback_t)(device_t *,
|
---|
[91db50ac] | 229 | usb_transaction_outcome_t, size_t, void *);
|
---|
| 230 |
|
---|
[fb1dca09] | 231 |
|
---|
| 232 | /** Out transfer processing function prototype. */
|
---|
| 233 | typedef int (*usbhc_iface_transfer_out_t)(device_t *, usb_target_t,
|
---|
| 234 | void *, size_t,
|
---|
| 235 | usbhc_iface_transfer_out_callback_t, void *);
|
---|
| 236 |
|
---|
| 237 | /** Setup transfer processing function prototype. */
|
---|
| 238 | typedef usbhc_iface_transfer_out_t usbhc_iface_transfer_setup_t;
|
---|
| 239 |
|
---|
| 240 | /** In transfer processing function prototype. */
|
---|
| 241 | typedef int (*usbhc_iface_transfer_in_t)(device_t *, usb_target_t,
|
---|
| 242 | void *, size_t,
|
---|
| 243 | usbhc_iface_transfer_in_callback_t, void *);
|
---|
| 244 |
|
---|
[6edd494] | 245 | /** USB host controller communication interface. */
|
---|
[91db50ac] | 246 | typedef struct {
|
---|
[aae339e9] | 247 | int (*tell_address)(device_t *, devman_handle_t, usb_address_t *);
|
---|
[a3dfb2e] | 248 |
|
---|
[6f04905] | 249 | int (*reserve_default_address)(device_t *);
|
---|
| 250 | int (*release_default_address)(device_t *);
|
---|
| 251 | int (*request_address)(device_t *, usb_address_t *);
|
---|
[4689d40] | 252 | int (*bind_address)(device_t *, usb_address_t, devman_handle_t);
|
---|
[6f04905] | 253 | int (*release_address)(device_t *, usb_address_t);
|
---|
| 254 |
|
---|
[fb1dca09] | 255 | usbhc_iface_transfer_out_t interrupt_out;
|
---|
| 256 | usbhc_iface_transfer_in_t interrupt_in;
|
---|
[a3dfb2e] | 257 |
|
---|
[fb1dca09] | 258 | usbhc_iface_transfer_setup_t control_write_setup;
|
---|
| 259 | usbhc_iface_transfer_out_t control_write_data;
|
---|
[a3dfb2e] | 260 | int (*control_write_status)(device_t *, usb_target_t,
|
---|
| 261 | usbhc_iface_transfer_in_callback_t, void *);
|
---|
| 262 |
|
---|
[fb1dca09] | 263 | usbhc_iface_transfer_setup_t control_read_setup;
|
---|
| 264 | usbhc_iface_transfer_in_t control_read_data;
|
---|
[a3dfb2e] | 265 | int (*control_read_status)(device_t *, usb_target_t,
|
---|
| 266 | usbhc_iface_transfer_out_callback_t, void *);
|
---|
[9753220] | 267 |
|
---|
| 268 | int (*control_write)(device_t *, usb_target_t,
|
---|
| 269 | void *, size_t, void *, size_t,
|
---|
| 270 | usbhc_iface_transfer_out_callback_t, void *);
|
---|
| 271 |
|
---|
| 272 | int (*control_read)(device_t *, usb_target_t,
|
---|
| 273 | void *, size_t, void *, size_t,
|
---|
| 274 | usbhc_iface_transfer_in_callback_t, void *);
|
---|
[cb59f787] | 275 | } usbhc_iface_t;
|
---|
[91db50ac] | 276 |
|
---|
| 277 |
|
---|
| 278 | #endif
|
---|
| 279 | /**
|
---|
| 280 | * @}
|
---|
| 281 | */
|
---|