[41b96b4] | 1 | /*
|
---|
| 2 | * Copyright (c) 2011 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 | /** @addtogroup drvusbohci
|
---|
| 29 | * @{
|
---|
| 30 | */
|
---|
| 31 | /** @file
|
---|
| 32 | * USB-HC interface implementation.
|
---|
| 33 | */
|
---|
| 34 | #include <ddf/driver.h>
|
---|
| 35 | #include <ddf/interrupt.h>
|
---|
| 36 | #include <device/hw_res.h>
|
---|
| 37 | #include <errno.h>
|
---|
| 38 | #include <str_error.h>
|
---|
| 39 |
|
---|
| 40 | #include <usb_iface.h>
|
---|
| 41 | #include <usb/ddfiface.h>
|
---|
| 42 | #include <usb/debug.h>
|
---|
| 43 |
|
---|
| 44 | #include "iface.h"
|
---|
| 45 |
|
---|
| 46 | #define UNSUPPORTED(methodname) \
|
---|
| 47 | usb_log_warning("Unsupported interface method `%s()' in %s:%d.\n", \
|
---|
| 48 | methodname, __FILE__, __LINE__)
|
---|
| 49 |
|
---|
| 50 | /** Reserve default address.
|
---|
| 51 | *
|
---|
| 52 | * This function may block the caller.
|
---|
| 53 | *
|
---|
| 54 | * @param[in] fun Device function the action was invoked on.
|
---|
| 55 | * @param[in] speed Speed of the device for which the default address is
|
---|
| 56 | * reserved.
|
---|
| 57 | * @return Error code.
|
---|
| 58 | */
|
---|
| 59 | static int reserve_default_address(ddf_fun_t *fun, usb_speed_t speed)
|
---|
| 60 | {
|
---|
| 61 | UNSUPPORTED("reserve_default_address");
|
---|
| 62 |
|
---|
| 63 | return ENOTSUP;
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | /** Release default address.
|
---|
| 67 | *
|
---|
| 68 | * @param[in] fun Device function the action was invoked on.
|
---|
| 69 | * @return Error code.
|
---|
| 70 | */
|
---|
| 71 | static int release_default_address(ddf_fun_t *fun)
|
---|
| 72 | {
|
---|
| 73 | UNSUPPORTED("release_default_address");
|
---|
| 74 |
|
---|
| 75 | return ENOTSUP;
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | /** Found free USB address.
|
---|
| 79 | *
|
---|
| 80 | * @param[in] fun Device function the action was invoked on.
|
---|
| 81 | * @param[in] speed Speed of the device that will get this address.
|
---|
| 82 | * @param[out] address Non-null pointer where to store the free address.
|
---|
| 83 | * @return Error code.
|
---|
| 84 | */
|
---|
| 85 | static int request_address(ddf_fun_t *fun, usb_speed_t speed,
|
---|
| 86 | usb_address_t *address)
|
---|
| 87 | {
|
---|
| 88 | UNSUPPORTED("request_address");
|
---|
| 89 |
|
---|
| 90 | return ENOTSUP;
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | /** Bind USB address with device devman handle.
|
---|
| 94 | *
|
---|
| 95 | * @param[in] fun Device function the action was invoked on.
|
---|
| 96 | * @param[in] address USB address of the device.
|
---|
| 97 | * @param[in] handle Devman handle of the device.
|
---|
| 98 | * @return Error code.
|
---|
| 99 | */
|
---|
| 100 | static int bind_address(ddf_fun_t *fun,
|
---|
| 101 | usb_address_t address, devman_handle_t handle)
|
---|
| 102 | {
|
---|
| 103 | UNSUPPORTED("bind_address");
|
---|
| 104 |
|
---|
| 105 | return ENOTSUP;
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | /** Release previously requested address.
|
---|
| 109 | *
|
---|
| 110 | * @param[in] fun Device function the action was invoked on.
|
---|
| 111 | * @param[in] address USB address to be released.
|
---|
| 112 | * @return Error code.
|
---|
| 113 | */
|
---|
| 114 | static int release_address(ddf_fun_t *fun, usb_address_t address)
|
---|
| 115 | {
|
---|
| 116 | UNSUPPORTED("release_address");
|
---|
| 117 |
|
---|
| 118 | return ENOTSUP;
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | /** Register endpoint for bandwidth reservation.
|
---|
| 122 | *
|
---|
| 123 | * @param[in] fun Device function the action was invoked on.
|
---|
| 124 | * @param[in] address USB address of the device.
|
---|
| 125 | * @param[in] endpoint Endpoint number.
|
---|
| 126 | * @param[in] transfer_type USB transfer type.
|
---|
| 127 | * @param[in] direction Endpoint data direction.
|
---|
| 128 | * @param[in] max_packet_size Max packet size of the endpoint.
|
---|
| 129 | * @param[in] interval Polling interval.
|
---|
| 130 | * @return Error code.
|
---|
| 131 | */
|
---|
| 132 | static int register_endpoint(ddf_fun_t *fun,
|
---|
| 133 | usb_address_t address, usb_endpoint_t endpoint,
|
---|
| 134 | usb_transfer_type_t transfer_type, usb_direction_t direction,
|
---|
| 135 | size_t max_packet_size, unsigned int interval)
|
---|
| 136 | {
|
---|
| 137 | UNSUPPORTED("register_endpoint");
|
---|
| 138 |
|
---|
| 139 | return ENOTSUP;
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | /** Unregister endpoint (free some bandwidth reservation).
|
---|
| 143 | *
|
---|
| 144 | * @param[in] fun Device function the action was invoked on.
|
---|
| 145 | * @param[in] address USB address of the device.
|
---|
| 146 | * @param[in] endpoint Endpoint number.
|
---|
| 147 | * @param[in] direction Endpoint data direction.
|
---|
| 148 | * @return Error code.
|
---|
| 149 | */
|
---|
| 150 | static int unregister_endpoint(ddf_fun_t *fun, usb_address_t address,
|
---|
| 151 | usb_endpoint_t endpoint, usb_direction_t direction)
|
---|
| 152 | {
|
---|
| 153 | UNSUPPORTED("unregister_endpoint");
|
---|
| 154 |
|
---|
| 155 | return ENOTSUP;
|
---|
| 156 | }
|
---|
| 157 |
|
---|
| 158 | /** Schedule interrupt out transfer.
|
---|
| 159 | *
|
---|
| 160 | * The callback is supposed to be called once the transfer (on the wire) is
|
---|
| 161 | * complete regardless of the outcome.
|
---|
| 162 | * However, the callback could be called only when this function returns
|
---|
| 163 | * with success status (i.e. returns EOK).
|
---|
| 164 | *
|
---|
| 165 | * @param[in] fun Device function the action was invoked on.
|
---|
| 166 | * @param[in] target Target pipe (address and endpoint number) specification.
|
---|
| 167 | * @param[in] max_packet_size Max packet size for the transfer.
|
---|
| 168 | * @param[in] data Data to be sent (in USB endianess, allocated and deallocated
|
---|
| 169 | * by the caller).
|
---|
| 170 | * @param[in] size Size of the @p data buffer in bytes.
|
---|
| 171 | * @param[in] callback Callback to be issued once the transfer is complete.
|
---|
| 172 | * @param[in] arg Pass-through argument to the callback.
|
---|
| 173 | * @return Error code.
|
---|
| 174 | */
|
---|
| 175 | static int interrupt_out(ddf_fun_t *fun, usb_target_t target,
|
---|
| 176 | size_t max_packet_size, void *data, size_t size,
|
---|
| 177 | usbhc_iface_transfer_out_callback_t callback, void *arg)
|
---|
| 178 | {
|
---|
| 179 | UNSUPPORTED("interrupt_out");
|
---|
| 180 |
|
---|
| 181 | return ENOTSUP;
|
---|
| 182 | }
|
---|
| 183 |
|
---|
| 184 | /** Schedule interrupt in transfer.
|
---|
| 185 | *
|
---|
| 186 | * The callback is supposed to be called once the transfer (on the wire) is
|
---|
| 187 | * complete regardless of the outcome.
|
---|
| 188 | * However, the callback could be called only when this function returns
|
---|
| 189 | * with success status (i.e. returns EOK).
|
---|
| 190 | *
|
---|
| 191 | * @param[in] fun Device function the action was invoked on.
|
---|
| 192 | * @param[in] target Target pipe (address and endpoint number) specification.
|
---|
| 193 | * @param[in] max_packet_size Max packet size for the transfer.
|
---|
| 194 | * @param[in] data Buffer where to store the data (in USB endianess,
|
---|
| 195 | * allocated and deallocated by the caller).
|
---|
| 196 | * @param[in] size Size of the @p data buffer in bytes.
|
---|
| 197 | * @param[in] callback Callback to be issued once the transfer is complete.
|
---|
| 198 | * @param[in] arg Pass-through argument to the callback.
|
---|
| 199 | * @return Error code.
|
---|
| 200 | */
|
---|
| 201 | static int interrupt_in(ddf_fun_t *fun, usb_target_t target,
|
---|
| 202 | size_t max_packet_size, void *data, size_t size,
|
---|
| 203 | usbhc_iface_transfer_in_callback_t callback, void *arg)
|
---|
| 204 | {
|
---|
| 205 | UNSUPPORTED("interrupt_in");
|
---|
| 206 |
|
---|
| 207 | return ENOTSUP;
|
---|
| 208 | }
|
---|
| 209 |
|
---|
| 210 | /** Schedule bulk out transfer.
|
---|
| 211 | *
|
---|
| 212 | * The callback is supposed to be called once the transfer (on the wire) is
|
---|
| 213 | * complete regardless of the outcome.
|
---|
| 214 | * However, the callback could be called only when this function returns
|
---|
| 215 | * with success status (i.e. returns EOK).
|
---|
| 216 | *
|
---|
| 217 | * @param[in] fun Device function the action was invoked on.
|
---|
| 218 | * @param[in] target Target pipe (address and endpoint number) specification.
|
---|
| 219 | * @param[in] max_packet_size Max packet size for the transfer.
|
---|
| 220 | * @param[in] data Data to be sent (in USB endianess, allocated and deallocated
|
---|
| 221 | * by the caller).
|
---|
| 222 | * @param[in] size Size of the @p data buffer in bytes.
|
---|
| 223 | * @param[in] callback Callback to be issued once the transfer is complete.
|
---|
| 224 | * @param[in] arg Pass-through argument to the callback.
|
---|
| 225 | * @return Error code.
|
---|
| 226 | */
|
---|
| 227 | static int bulk_out(ddf_fun_t *fun, usb_target_t target,
|
---|
| 228 | size_t max_packet_size, void *data, size_t size,
|
---|
| 229 | usbhc_iface_transfer_out_callback_t callback, void *arg)
|
---|
| 230 | {
|
---|
| 231 | UNSUPPORTED("bulk_out");
|
---|
| 232 |
|
---|
| 233 | return ENOTSUP;
|
---|
| 234 | }
|
---|
| 235 |
|
---|
| 236 | /** Schedule bulk in transfer.
|
---|
| 237 | *
|
---|
| 238 | * The callback is supposed to be called once the transfer (on the wire) is
|
---|
| 239 | * complete regardless of the outcome.
|
---|
| 240 | * However, the callback could be called only when this function returns
|
---|
| 241 | * with success status (i.e. returns EOK).
|
---|
| 242 | *
|
---|
| 243 | * @param[in] fun Device function the action was invoked on.
|
---|
| 244 | * @param[in] target Target pipe (address and endpoint number) specification.
|
---|
| 245 | * @param[in] max_packet_size Max packet size for the transfer.
|
---|
| 246 | * @param[in] data Buffer where to store the data (in USB endianess,
|
---|
| 247 | * allocated and deallocated by the caller).
|
---|
| 248 | * @param[in] size Size of the @p data buffer in bytes.
|
---|
| 249 | * @param[in] callback Callback to be issued once the transfer is complete.
|
---|
| 250 | * @param[in] arg Pass-through argument to the callback.
|
---|
| 251 | * @return Error code.
|
---|
| 252 | */
|
---|
| 253 | static int bulk_in(ddf_fun_t *fun, usb_target_t target,
|
---|
| 254 | size_t max_packet_size, void *data, size_t size,
|
---|
| 255 | usbhc_iface_transfer_in_callback_t callback, void *arg)
|
---|
| 256 | {
|
---|
| 257 | UNSUPPORTED("bulk_in");
|
---|
| 258 |
|
---|
| 259 | return ENOTSUP;
|
---|
| 260 | }
|
---|
| 261 |
|
---|
| 262 | /** Schedule control write transfer.
|
---|
| 263 | *
|
---|
| 264 | * The callback is supposed to be called once the transfer (on the wire) is
|
---|
| 265 | * complete regardless of the outcome.
|
---|
| 266 | * However, the callback could be called only when this function returns
|
---|
| 267 | * with success status (i.e. returns EOK).
|
---|
| 268 | *
|
---|
| 269 | * @param[in] fun Device function the action was invoked on.
|
---|
| 270 | * @param[in] target Target pipe (address and endpoint number) specification.
|
---|
| 271 | * @param[in] max_packet_size Max packet size for the transfer.
|
---|
| 272 | * @param[in] setup_packet Setup packet buffer (in USB endianess, allocated
|
---|
| 273 | * and deallocated by the caller).
|
---|
| 274 | * @param[in] setup_packet_size Size of @p setup_packet buffer in bytes.
|
---|
| 275 | * @param[in] data_buffer Data buffer (in USB endianess, allocated and
|
---|
| 276 | * deallocated by the caller).
|
---|
| 277 | * @param[in] data_buffer_size Size of @p data_buffer buffer in bytes.
|
---|
| 278 | * @param[in] callback Callback to be issued once the transfer is complete.
|
---|
| 279 | * @param[in] arg Pass-through argument to the callback.
|
---|
| 280 | * @return Error code.
|
---|
| 281 | */
|
---|
| 282 | static int control_write(ddf_fun_t *fun, usb_target_t target,
|
---|
| 283 | size_t max_packet_size,
|
---|
| 284 | void *setup_packet, size_t setup_packet_size,
|
---|
| 285 | void *data_buffer, size_t data_buffer_size,
|
---|
| 286 | usbhc_iface_transfer_out_callback_t callback, void *arg)
|
---|
| 287 | {
|
---|
| 288 | UNSUPPORTED("control_write");
|
---|
| 289 |
|
---|
| 290 | return ENOTSUP;
|
---|
| 291 | }
|
---|
| 292 |
|
---|
| 293 | /** Schedule control read transfer.
|
---|
| 294 | *
|
---|
| 295 | * The callback is supposed to be called once the transfer (on the wire) is
|
---|
| 296 | * complete regardless of the outcome.
|
---|
| 297 | * However, the callback could be called only when this function returns
|
---|
| 298 | * with success status (i.e. returns EOK).
|
---|
| 299 | *
|
---|
| 300 | * @param[in] fun Device function the action was invoked on.
|
---|
| 301 | * @param[in] target Target pipe (address and endpoint number) specification.
|
---|
| 302 | * @param[in] max_packet_size Max packet size for the transfer.
|
---|
| 303 | * @param[in] setup_packet Setup packet buffer (in USB endianess, allocated
|
---|
| 304 | * and deallocated by the caller).
|
---|
| 305 | * @param[in] setup_packet_size Size of @p setup_packet buffer in bytes.
|
---|
| 306 | * @param[in] data_buffer Buffer where to store the data (in USB endianess,
|
---|
| 307 | * allocated and deallocated by the caller).
|
---|
| 308 | * @param[in] data_buffer_size Size of @p data_buffer buffer in bytes.
|
---|
| 309 | * @param[in] callback Callback to be issued once the transfer is complete.
|
---|
| 310 | * @param[in] arg Pass-through argument to the callback.
|
---|
| 311 | * @return Error code.
|
---|
| 312 | */
|
---|
| 313 | static int control_read(ddf_fun_t *fun, usb_target_t target,
|
---|
| 314 | size_t max_packet_size,
|
---|
| 315 | void *setup_packet, size_t setup_packet_size,
|
---|
| 316 | void *data_buffer, size_t data_buffer_size,
|
---|
| 317 | usbhc_iface_transfer_in_callback_t callback, void *arg)
|
---|
| 318 | {
|
---|
| 319 | UNSUPPORTED("control_read");
|
---|
| 320 |
|
---|
| 321 | return ENOTSUP;
|
---|
| 322 | }
|
---|
| 323 |
|
---|
| 324 | /** Host controller interface implementation for EHCI. */
|
---|
| 325 | usbhc_iface_t ohci_hc_iface = {
|
---|
| 326 | .reserve_default_address = reserve_default_address,
|
---|
| 327 | .release_default_address = release_default_address,
|
---|
| 328 | .request_address = request_address,
|
---|
| 329 | .bind_address = bind_address,
|
---|
| 330 | .release_address = release_address,
|
---|
| 331 |
|
---|
| 332 | .register_endpoint = register_endpoint,
|
---|
| 333 | .unregister_endpoint = unregister_endpoint,
|
---|
| 334 |
|
---|
| 335 | .interrupt_out = interrupt_out,
|
---|
| 336 | .interrupt_in = interrupt_in,
|
---|
| 337 |
|
---|
| 338 | .bulk_out = bulk_out,
|
---|
| 339 | .bulk_in = bulk_in,
|
---|
| 340 |
|
---|
| 341 | .control_write = control_write,
|
---|
| 342 | .control_read = control_read
|
---|
| 343 | };
|
---|
| 344 |
|
---|
| 345 | /**
|
---|
| 346 | * @}
|
---|
| 347 | */
|
---|