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