[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 |
|
---|
[b7d8fd9] | 125 | /** Register endpoint attributes at host controller.
|
---|
| 126 | * This is used to reserve portion of USB bandwidth.
|
---|
[1998bcd] | 127 | * When speed is invalid, speed of the device is used.
|
---|
[b7d8fd9] | 128 | * Parameters:
|
---|
[1998bcd] | 129 | * - USB address + endpoint number
|
---|
| 130 | * - packed as ADDR << 16 + EP
|
---|
| 131 | * - speed + transfer type + direction
|
---|
| 132 | * - packed as ( SPEED << 8 + TYPE ) << 8 + DIR
|
---|
| 133 | * - maximum packet size + interval (in milliseconds)
|
---|
| 134 | * - packed as MPS << 16 + INT
|
---|
[b7d8fd9] | 135 | * Answer:
|
---|
| 136 | * - EOK - reservation successful
|
---|
| 137 | * - ELIMIT - not enough bandwidth to satisfy the request
|
---|
| 138 | */
|
---|
| 139 | IPC_M_USBHC_REGISTER_ENDPOINT,
|
---|
| 140 |
|
---|
| 141 | /** Revert endpoint registration.
|
---|
| 142 | * Parameters:
|
---|
| 143 | * - USB address
|
---|
| 144 | * - endpoint number
|
---|
| 145 | * - data direction
|
---|
| 146 | * Answer:
|
---|
| 147 | * - EOK - endpoint unregistered
|
---|
| 148 | * - ENOENT - unknown endpoint
|
---|
| 149 | */
|
---|
[ffe3fe1] | 150 | IPC_M_USBHC_UNREGISTER_ENDPOINT,
|
---|
| 151 |
|
---|
[1e647c7d] | 152 | /** Get data from device.
|
---|
| 153 | * See explanation at usb_iface_funcs_t (IN transaction).
|
---|
| 154 | */
|
---|
[bbce2c2] | 155 | IPC_M_USBHC_READ,
|
---|
[ffe3fe1] | 156 |
|
---|
[1e647c7d] | 157 | /** Send data to device.
|
---|
| 158 | * See explanation at usb_iface_funcs_t (OUT transaction).
|
---|
| 159 | */
|
---|
[bbce2c2] | 160 | IPC_M_USBHC_WRITE,
|
---|
[cb59f787] | 161 | } usbhc_iface_funcs_t;
|
---|
[91db50ac] | 162 |
|
---|
| 163 | /** Callback for outgoing transfer. */
|
---|
[bbce2c2] | 164 | typedef void (*usbhc_iface_transfer_out_callback_t)(ddf_fun_t *, int, void *);
|
---|
[91db50ac] | 165 |
|
---|
| 166 | /** Callback for incoming transfer. */
|
---|
[eb1a2f4] | 167 | typedef void (*usbhc_iface_transfer_in_callback_t)(ddf_fun_t *,
|
---|
[daec5e04] | 168 | int, size_t, void *);
|
---|
[91db50ac] | 169 |
|
---|
[6edd494] | 170 | /** USB host controller communication interface. */
|
---|
[91db50ac] | 171 | typedef struct {
|
---|
[67f55e7b] | 172 | int (*request_address)(ddf_fun_t *, usb_address_t *, bool, usb_speed_t);
|
---|
[eb1a2f4] | 173 | int (*bind_address)(ddf_fun_t *, usb_address_t, devman_handle_t);
|
---|
[eb2f7dd] | 174 | int (*find_by_address)(ddf_fun_t *, usb_address_t, devman_handle_t *);
|
---|
[eb1a2f4] | 175 | int (*release_address)(ddf_fun_t *, usb_address_t);
|
---|
[6f04905] | 176 |
|
---|
[1998bcd] | 177 | int (*register_endpoint)(ddf_fun_t *,
|
---|
[27736cf] | 178 | usb_address_t, usb_endpoint_t,
|
---|
[b7d8fd9] | 179 | usb_transfer_type_t, usb_direction_t, size_t, unsigned int);
|
---|
| 180 | int (*unregister_endpoint)(ddf_fun_t *, usb_address_t, usb_endpoint_t,
|
---|
| 181 | usb_direction_t);
|
---|
| 182 |
|
---|
[ffe3fe1] | 183 | int (*read)(ddf_fun_t *, usb_target_t, uint64_t, uint8_t *, size_t,
|
---|
| 184 | usbhc_iface_transfer_in_callback_t, void *);
|
---|
| 185 |
|
---|
| 186 | int (*write)(ddf_fun_t *, usb_target_t, uint64_t, const uint8_t *,
|
---|
| 187 | size_t, usbhc_iface_transfer_out_callback_t, void *);
|
---|
[cb59f787] | 188 | } usbhc_iface_t;
|
---|
[91db50ac] | 189 |
|
---|
| 190 |
|
---|
| 191 | #endif
|
---|
| 192 | /**
|
---|
| 193 | * @}
|
---|
| 194 | */
|
---|