[41b96b4] | 1 | /*
|
---|
[6bec59b] | 2 | * Copyright (c) 2011 Vojtech Horky, Jan Vesely
|
---|
[41b96b4] | 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
|
---|
[6bec59b] | 32 | * @brief OHCI driver hc interface implementation
|
---|
[41b96b4] | 33 | */
|
---|
| 34 | #include <ddf/driver.h>
|
---|
| 35 | #include <errno.h>
|
---|
| 36 |
|
---|
| 37 | #include <usb/debug.h>
|
---|
[6bec59b] | 38 | #include <usb/host/endpoint.h>
|
---|
[41b96b4] | 39 |
|
---|
| 40 | #include "iface.h"
|
---|
[bab71635] | 41 | #include "hc.h"
|
---|
[41b96b4] | 42 |
|
---|
[6bec59b] | 43 | static inline int setup_batch(
|
---|
| 44 | ddf_fun_t *fun, usb_target_t target, usb_direction_t direction,
|
---|
| 45 | void *data, size_t size, void * setup_data, size_t setup_size,
|
---|
| 46 | usbhc_iface_transfer_in_callback_t in,
|
---|
| 47 | usbhc_iface_transfer_out_callback_t out, void *arg, const char* name,
|
---|
| 48 | hc_t **hc, usb_transfer_batch_t **batch)
|
---|
| 49 | {
|
---|
| 50 | assert(hc);
|
---|
| 51 | assert(batch);
|
---|
| 52 | assert(fun);
|
---|
| 53 | *hc = fun_to_hc(fun);
|
---|
| 54 | assert(*hc);
|
---|
[41b96b4] | 55 |
|
---|
[6bec59b] | 56 | size_t res_bw;
|
---|
| 57 | endpoint_t *ep = usb_endpoint_manager_get_ep(&(*hc)->ep_manager,
|
---|
| 58 | target.address, target.endpoint, direction, &res_bw);
|
---|
| 59 | if (ep == NULL) {
|
---|
| 60 | usb_log_error("Endpoint(%d:%d) not registered for %s.\n",
|
---|
| 61 | target.address, target.endpoint, name);
|
---|
| 62 | return ENOENT;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | const size_t bw = bandwidth_count_usb11(
|
---|
| 66 | ep->speed, ep->transfer_type, size, ep->max_packet_size);
|
---|
| 67 | if (res_bw < bw) {
|
---|
| 68 | usb_log_error("Endpoint(%d:%d) %s needs %zu bw "
|
---|
| 69 | "but only %zu is reserved.\n",
|
---|
| 70 | name, target.address, target.endpoint, bw, res_bw);
|
---|
| 71 | return ENOSPC;
|
---|
| 72 | }
|
---|
| 73 | usb_log_debug("%s %d:%d %zu(%zu).\n",
|
---|
| 74 | name, target.address, target.endpoint, size, ep->max_packet_size);
|
---|
| 75 |
|
---|
| 76 | assert(ep->speed ==
|
---|
| 77 | usb_device_keeper_get_speed(&(*hc)->manager, target.address));
|
---|
| 78 | // assert(ep->max_packet_size == max_packet_size);
|
---|
| 79 | // assert(ep->transfer_type == USB_TRANSFER_CONTROL);
|
---|
| 80 |
|
---|
| 81 | *batch =
|
---|
| 82 | batch_get(fun, ep, data, size, setup_data, setup_size,
|
---|
| 83 | in, out, arg);
|
---|
| 84 | if (!batch)
|
---|
| 85 | return ENOMEM;
|
---|
| 86 | return EOK;
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 |
|
---|
| 90 | /** Reserve default address interface function
|
---|
[41b96b4] | 91 | *
|
---|
[6bec59b] | 92 | * @param[in] fun DDF function that was called.
|
---|
| 93 | * @param[in] speed Speed to associate with the new default address.
|
---|
[41b96b4] | 94 | * @return Error code.
|
---|
| 95 | */
|
---|
| 96 | static int reserve_default_address(ddf_fun_t *fun, usb_speed_t speed)
|
---|
| 97 | {
|
---|
[1c6a45f] | 98 | assert(fun);
|
---|
| 99 | hc_t *hc = fun_to_hc(fun);
|
---|
| 100 | assert(hc);
|
---|
| 101 | usb_log_debug("Default address request with speed %d.\n", speed);
|
---|
| 102 | usb_device_keeper_reserve_default_address(&hc->manager, speed);
|
---|
| 103 | return EOK;
|
---|
[6bec59b] | 104 | #if 0
|
---|
| 105 | endpoint_t *ep = malloc(sizeof(endpoint_t));
|
---|
| 106 | if (ep == NULL)
|
---|
| 107 | return ENOMEM;
|
---|
| 108 | const size_t max_packet_size = speed == USB_SPEED_LOW ? 8 : 64;
|
---|
| 109 | endpoint_init(ep, USB_TRANSFER_CONTROL, speed, max_packet_size);
|
---|
| 110 | int ret;
|
---|
| 111 | try_retgister:
|
---|
| 112 | ret = usb_endpoint_manager_register_ep(&hc->ep_manager,
|
---|
| 113 | USB_ADDRESS_DEFAULT, 0, USB_DIRECTION_BOTH, ep, endpoint_destroy, 0);
|
---|
| 114 | if (ret == EEXISTS) {
|
---|
| 115 | async_usleep(1000);
|
---|
| 116 | goto try_retgister;
|
---|
| 117 | }
|
---|
| 118 | if (ret != EOK) {
|
---|
| 119 | endpoint_destroy(ep);
|
---|
| 120 | }
|
---|
| 121 | return ret;
|
---|
| 122 | #endif
|
---|
[41b96b4] | 123 | }
|
---|
[b0beee82] | 124 | /*----------------------------------------------------------------------------*/
|
---|
[6bec59b] | 125 | /** Release default address interface function
|
---|
[41b96b4] | 126 | *
|
---|
[6bec59b] | 127 | * @param[in] fun DDF function that was called.
|
---|
[41b96b4] | 128 | * @return Error code.
|
---|
| 129 | */
|
---|
| 130 | static int release_default_address(ddf_fun_t *fun)
|
---|
| 131 | {
|
---|
[1c6a45f] | 132 | assert(fun);
|
---|
| 133 | hc_t *hc = fun_to_hc(fun);
|
---|
| 134 | assert(hc);
|
---|
| 135 | usb_log_debug("Default address release.\n");
|
---|
[6bec59b] | 136 | // return usb_endpoint_manager_unregister_ep(&hc->ep_manager,
|
---|
| 137 | // USB_ADDRESS_DEFAULT, 0, USB_DIRECTION_BOTH);
|
---|
[1c6a45f] | 138 | usb_device_keeper_release_default_address(&hc->manager);
|
---|
| 139 | return EOK;
|
---|
[41b96b4] | 140 | }
|
---|
[b0beee82] | 141 | /*----------------------------------------------------------------------------*/
|
---|
[6bec59b] | 142 | /** Request address interface function
|
---|
[41b96b4] | 143 | *
|
---|
[6bec59b] | 144 | * @param[in] fun DDF function that was called.
|
---|
| 145 | * @param[in] speed Speed to associate with the new default address.
|
---|
| 146 | * @param[out] address Place to write a new address.
|
---|
[41b96b4] | 147 | * @return Error code.
|
---|
| 148 | */
|
---|
[b9fa0a9] | 149 | static int request_address(
|
---|
| 150 | ddf_fun_t *fun, usb_speed_t speed, usb_address_t *address)
|
---|
[41b96b4] | 151 | {
|
---|
[1c6a45f] | 152 | assert(fun);
|
---|
| 153 | hc_t *hc = fun_to_hc(fun);
|
---|
| 154 | assert(hc);
|
---|
| 155 | assert(address);
|
---|
[41b96b4] | 156 |
|
---|
[1c6a45f] | 157 | usb_log_debug("Address request with speed %d.\n", speed);
|
---|
| 158 | *address = device_keeper_get_free_address(&hc->manager, speed);
|
---|
| 159 | usb_log_debug("Address request with result: %d.\n", *address);
|
---|
| 160 | if (*address <= 0)
|
---|
| 161 | return *address;
|
---|
| 162 | return EOK;
|
---|
[41b96b4] | 163 | }
|
---|
[b0beee82] | 164 | /*----------------------------------------------------------------------------*/
|
---|
[6bec59b] | 165 | /** Bind address interface function
|
---|
[41b96b4] | 166 | *
|
---|
[6bec59b] | 167 | * @param[in] fun DDF function that was called.
|
---|
| 168 | * @param[in] address Address of the device
|
---|
| 169 | * @param[in] handle Devman handle of the device driver.
|
---|
[41b96b4] | 170 | * @return Error code.
|
---|
| 171 | */
|
---|
[b9fa0a9] | 172 | static int bind_address(
|
---|
[6bec59b] | 173 | ddf_fun_t *fun, usb_address_t address, devman_handle_t handle)
|
---|
[41b96b4] | 174 | {
|
---|
[1c6a45f] | 175 | assert(fun);
|
---|
| 176 | hc_t *hc = fun_to_hc(fun);
|
---|
| 177 | assert(hc);
|
---|
| 178 | usb_log_debug("Address bind %d-%d.\n", address, handle);
|
---|
| 179 | usb_device_keeper_bind(&hc->manager, address, handle);
|
---|
| 180 | return EOK;
|
---|
[41b96b4] | 181 | }
|
---|
[b0beee82] | 182 | /*----------------------------------------------------------------------------*/
|
---|
[6bec59b] | 183 | /** Release address interface function
|
---|
[41b96b4] | 184 | *
|
---|
[6bec59b] | 185 | * @param[in] fun DDF function that was called.
|
---|
[41b96b4] | 186 | * @param[in] address USB address to be released.
|
---|
| 187 | * @return Error code.
|
---|
| 188 | */
|
---|
| 189 | static int release_address(ddf_fun_t *fun, usb_address_t address)
|
---|
| 190 | {
|
---|
[1c6a45f] | 191 | assert(fun);
|
---|
| 192 | hc_t *hc = fun_to_hc(fun);
|
---|
| 193 | assert(hc);
|
---|
| 194 | usb_log_debug("Address release %d.\n", address);
|
---|
| 195 | usb_device_keeper_release(&hc->manager, address);
|
---|
| 196 | return EOK;
|
---|
[41b96b4] | 197 | }
|
---|
[1c6a45f] | 198 | /*----------------------------------------------------------------------------*/
|
---|
[b9fa0a9] | 199 | static int register_endpoint(
|
---|
| 200 | ddf_fun_t *fun, usb_address_t address, usb_endpoint_t endpoint,
|
---|
[41b96b4] | 201 | usb_transfer_type_t transfer_type, usb_direction_t direction,
|
---|
| 202 | size_t max_packet_size, unsigned int interval)
|
---|
| 203 | {
|
---|
[c2be0e5] | 204 | hc_t *hc = fun_to_hc(fun);
|
---|
| 205 | assert(hc);
|
---|
| 206 | const usb_speed_t speed =
|
---|
[6bec59b] | 207 | usb_device_keeper_get_speed(&hc->manager, address);
|
---|
| 208 | const size_t size =
|
---|
| 209 | (transfer_type == USB_TRANSFER_INTERRUPT
|
---|
| 210 | || transfer_type == USB_TRANSFER_ISOCHRONOUS) ?
|
---|
| 211 | max_packet_size : 0;
|
---|
| 212 | int ret;
|
---|
| 213 |
|
---|
| 214 | endpoint_t *ep = malloc(sizeof(endpoint_t));
|
---|
| 215 | if (ep == NULL)
|
---|
| 216 | return ENOMEM;
|
---|
| 217 | ret = endpoint_init(ep, address, endpoint, direction,
|
---|
| 218 | transfer_type, speed, max_packet_size);
|
---|
| 219 | if (ret != EOK) {
|
---|
| 220 | free(ep);
|
---|
| 221 | return ret;
|
---|
| 222 | }
|
---|
| 223 |
|
---|
[c2be0e5] | 224 | usb_log_debug("Register endpoint %d:%d %s %s(%d) %zu(%zu) %u.\n",
|
---|
| 225 | address, endpoint, usb_str_transfer_type(transfer_type),
|
---|
| 226 | usb_str_speed(speed), direction, size, max_packet_size, interval);
|
---|
[6bec59b] | 227 |
|
---|
| 228 | ret = usb_endpoint_manager_register_ep(&hc->ep_manager, ep, size);
|
---|
| 229 | if (ret != EOK) {
|
---|
| 230 | endpoint_destroy(ep);
|
---|
| 231 | } else {
|
---|
| 232 | usb_device_keeper_add_ep(&hc->manager, address, ep);
|
---|
| 233 | }
|
---|
| 234 | return ret;
|
---|
[41b96b4] | 235 | }
|
---|
[1c6a45f] | 236 | /*----------------------------------------------------------------------------*/
|
---|
[b9fa0a9] | 237 | static int unregister_endpoint(
|
---|
| 238 | ddf_fun_t *fun, usb_address_t address,
|
---|
[41b96b4] | 239 | usb_endpoint_t endpoint, usb_direction_t direction)
|
---|
| 240 | {
|
---|
[c2be0e5] | 241 | hc_t *hc = fun_to_hc(fun);
|
---|
| 242 | assert(hc);
|
---|
| 243 | usb_log_debug("Unregister endpoint %d:%d %d.\n",
|
---|
| 244 | address, endpoint, direction);
|
---|
[5876d36] | 245 | return usb_endpoint_manager_unregister_ep(&hc->ep_manager, address,
|
---|
| 246 | endpoint, direction);
|
---|
[41b96b4] | 247 | }
|
---|
[be7950e8] | 248 | /*----------------------------------------------------------------------------*/
|
---|
[6bec59b] | 249 | /** Interrupt out transaction interface function
|
---|
[41b96b4] | 250 | *
|
---|
[6bec59b] | 251 | * @param[in] fun DDF function that was called.
|
---|
| 252 | * @param[in] target USB device to write to.
|
---|
| 253 | * @param[in] max_packet_size maximum size of data packet the device accepts
|
---|
| 254 | * @param[in] data Source of data.
|
---|
| 255 | * @param[in] size Size of data source.
|
---|
| 256 | * @param[in] callback Function to call on transaction completion
|
---|
| 257 | * @param[in] arg Additional for callback function.
|
---|
[41b96b4] | 258 | * @return Error code.
|
---|
| 259 | */
|
---|
[b9fa0a9] | 260 | static int interrupt_out(
|
---|
| 261 | ddf_fun_t *fun, usb_target_t target, size_t max_packet_size, void *data,
|
---|
| 262 | size_t size, usbhc_iface_transfer_out_callback_t callback, void *arg)
|
---|
[41b96b4] | 263 | {
|
---|
[6bec59b] | 264 | usb_transfer_batch_t *batch = NULL;
|
---|
| 265 | hc_t *hc = NULL;
|
---|
| 266 | int ret = setup_batch(fun, target, USB_DIRECTION_OUT, data, size,
|
---|
| 267 | NULL, 0, NULL, callback, arg, "Interrupt OUT", &hc, &batch);
|
---|
| 268 | if (ret != EOK)
|
---|
| 269 | return ret;
|
---|
[1c6a45f] | 270 | batch_interrupt_out(batch);
|
---|
[6bec59b] | 271 | ret = hc_schedule(hc, batch);
|
---|
[1c6a45f] | 272 | if (ret != EOK) {
|
---|
| 273 | batch_dispose(batch);
|
---|
| 274 | }
|
---|
[b9fa0a9] | 275 | return ret;
|
---|
[be7950e8] | 276 | }
|
---|
| 277 | /*----------------------------------------------------------------------------*/
|
---|
[6bec59b] | 278 | /** Interrupt in transaction interface function
|
---|
[41b96b4] | 279 | *
|
---|
[6bec59b] | 280 | * @param[in] fun DDF function that was called.
|
---|
| 281 | * @param[in] target USB device to write to.
|
---|
| 282 | * @param[in] max_packet_size maximum size of data packet the device accepts
|
---|
| 283 | * @param[out] data Data destination.
|
---|
| 284 | * @param[in] size Size of data source.
|
---|
| 285 | * @param[in] callback Function to call on transaction completion
|
---|
| 286 | * @param[in] arg Additional for callback function.
|
---|
[41b96b4] | 287 | * @return Error code.
|
---|
| 288 | */
|
---|
[b9fa0a9] | 289 | static int interrupt_in(
|
---|
| 290 | ddf_fun_t *fun, usb_target_t target, size_t max_packet_size, void *data,
|
---|
| 291 | size_t size, usbhc_iface_transfer_in_callback_t callback, void *arg)
|
---|
[41b96b4] | 292 | {
|
---|
[6bec59b] | 293 | usb_transfer_batch_t *batch = NULL;
|
---|
| 294 | hc_t *hc = NULL;
|
---|
| 295 | int ret = setup_batch(fun, target, USB_DIRECTION_IN, data, size,
|
---|
| 296 | NULL, 0, callback, NULL, arg, "Interrupt IN", &hc, &batch);
|
---|
| 297 | if (ret != EOK)
|
---|
| 298 | return ret;
|
---|
[1c6a45f] | 299 | batch_interrupt_in(batch);
|
---|
[6bec59b] | 300 | ret = hc_schedule(hc, batch);
|
---|
[1c6a45f] | 301 | if (ret != EOK) {
|
---|
| 302 | batch_dispose(batch);
|
---|
| 303 | }
|
---|
[b9fa0a9] | 304 | return ret;
|
---|
[41b96b4] | 305 | }
|
---|
[be7950e8] | 306 | /*----------------------------------------------------------------------------*/
|
---|
[6bec59b] | 307 | /** Bulk out transaction interface function
|
---|
[41b96b4] | 308 | *
|
---|
[6bec59b] | 309 | * @param[in] fun DDF function that was called.
|
---|
| 310 | * @param[in] target USB device to write to.
|
---|
| 311 | * @param[in] max_packet_size maximum size of data packet the device accepts
|
---|
| 312 | * @param[in] data Source of data.
|
---|
| 313 | * @param[in] size Size of data source.
|
---|
| 314 | * @param[in] callback Function to call on transaction completion
|
---|
| 315 | * @param[in] arg Additional for callback function.
|
---|
[41b96b4] | 316 | * @return Error code.
|
---|
| 317 | */
|
---|
[b9fa0a9] | 318 | static int bulk_out(
|
---|
| 319 | ddf_fun_t *fun, usb_target_t target, size_t max_packet_size, void *data,
|
---|
| 320 | size_t size, usbhc_iface_transfer_out_callback_t callback, void *arg)
|
---|
[41b96b4] | 321 | {
|
---|
[6bec59b] | 322 | usb_transfer_batch_t *batch = NULL;
|
---|
| 323 | hc_t *hc = NULL;
|
---|
| 324 | int ret = setup_batch(fun, target, USB_DIRECTION_OUT, data, size,
|
---|
| 325 | NULL, 0, NULL, callback, arg, "Bulk OUT", &hc, &batch);
|
---|
| 326 | if (ret != EOK)
|
---|
| 327 | return ret;
|
---|
[1c6a45f] | 328 | batch_bulk_out(batch);
|
---|
[6bec59b] | 329 | ret = hc_schedule(hc, batch);
|
---|
[1c6a45f] | 330 | if (ret != EOK) {
|
---|
| 331 | batch_dispose(batch);
|
---|
| 332 | }
|
---|
[b9fa0a9] | 333 | return ret;
|
---|
[be7950e8] | 334 | }
|
---|
| 335 | /*----------------------------------------------------------------------------*/
|
---|
[6bec59b] | 336 | /** Bulk in transaction interface function
|
---|
[41b96b4] | 337 | *
|
---|
[6bec59b] | 338 | * @param[in] fun DDF function that was called.
|
---|
| 339 | * @param[in] target USB device to write to.
|
---|
| 340 | * @param[in] max_packet_size maximum size of data packet the device accepts
|
---|
| 341 | * @param[out] data Data destination.
|
---|
| 342 | * @param[in] size Size of data source.
|
---|
| 343 | * @param[in] callback Function to call on transaction completion
|
---|
| 344 | * @param[in] arg Additional for callback function.
|
---|
[41b96b4] | 345 | * @return Error code.
|
---|
| 346 | */
|
---|
[b9fa0a9] | 347 | static int bulk_in(
|
---|
| 348 | ddf_fun_t *fun, usb_target_t target, size_t max_packet_size, void *data,
|
---|
| 349 | size_t size, usbhc_iface_transfer_in_callback_t callback, void *arg)
|
---|
[41b96b4] | 350 | {
|
---|
[6bec59b] | 351 | usb_transfer_batch_t *batch = NULL;
|
---|
| 352 | hc_t *hc = NULL;
|
---|
| 353 | int ret = setup_batch(fun, target, USB_DIRECTION_IN, data, size,
|
---|
| 354 | NULL, 0, callback, NULL, arg, "Bulk IN", &hc, &batch);
|
---|
| 355 | if (ret != EOK)
|
---|
| 356 | return ret;
|
---|
[1c6a45f] | 357 | batch_bulk_in(batch);
|
---|
[6bec59b] | 358 | ret = hc_schedule(hc, batch);
|
---|
[1c6a45f] | 359 | if (ret != EOK) {
|
---|
| 360 | batch_dispose(batch);
|
---|
| 361 | }
|
---|
[b9fa0a9] | 362 | return ret;
|
---|
[41b96b4] | 363 | }
|
---|
[be7950e8] | 364 | /*----------------------------------------------------------------------------*/
|
---|
[6bec59b] | 365 | /** Control write transaction interface function
|
---|
[41b96b4] | 366 | *
|
---|
[6bec59b] | 367 | * @param[in] fun DDF function that was called.
|
---|
| 368 | * @param[in] target USB device to write to.
|
---|
| 369 | * @param[in] max_packet_size maximum size of data packet the device accepts.
|
---|
| 370 | * @param[in] setup_data Data to send with SETUP transfer.
|
---|
| 371 | * @param[in] setup_size Size of data to send with SETUP transfer (always 8B).
|
---|
| 372 | * @param[in] data Source of data.
|
---|
| 373 | * @param[in] size Size of data source.
|
---|
| 374 | * @param[in] callback Function to call on transaction completion.
|
---|
| 375 | * @param[in] arg Additional for callback function.
|
---|
[41b96b4] | 376 | * @return Error code.
|
---|
| 377 | */
|
---|
[b9fa0a9] | 378 | static int control_write(
|
---|
| 379 | ddf_fun_t *fun, usb_target_t target, size_t max_packet_size,
|
---|
[1c6a45f] | 380 | void *setup_data, size_t setup_size, void *data, size_t size,
|
---|
[41b96b4] | 381 | usbhc_iface_transfer_out_callback_t callback, void *arg)
|
---|
| 382 | {
|
---|
[6bec59b] | 383 | usb_transfer_batch_t *batch = NULL;
|
---|
| 384 | hc_t *hc = NULL;
|
---|
| 385 | int ret = setup_batch(fun, target, USB_DIRECTION_BOTH, data, size,
|
---|
| 386 | setup_data, setup_size, NULL, callback, arg, "Control WRITE",
|
---|
| 387 | &hc, &batch);
|
---|
| 388 | if (ret != EOK)
|
---|
| 389 | return ret;
|
---|
[1c6a45f] | 390 | usb_device_keeper_reset_if_need(&hc->manager, target, setup_data);
|
---|
| 391 | batch_control_write(batch);
|
---|
[6bec59b] | 392 | ret = hc_schedule(hc, batch);
|
---|
[1c6a45f] | 393 | if (ret != EOK) {
|
---|
| 394 | batch_dispose(batch);
|
---|
| 395 | }
|
---|
[b9fa0a9] | 396 | return ret;
|
---|
[be7950e8] | 397 | }
|
---|
| 398 | /*----------------------------------------------------------------------------*/
|
---|
[6bec59b] | 399 | /** Control read transaction interface function
|
---|
[41b96b4] | 400 | *
|
---|
[6bec59b] | 401 | * @param[in] fun DDF function that was called.
|
---|
| 402 | * @param[in] target USB device to write to.
|
---|
| 403 | * @param[in] max_packet_size maximum size of data packet the device accepts.
|
---|
| 404 | * @param[in] setup_data Data to send with SETUP packet.
|
---|
| 405 | * @param[in] setup_size Size of data to send with SETUP packet (should be 8B).
|
---|
| 406 | * @param[out] data Source of data.
|
---|
| 407 | * @param[in] size Size of data source.
|
---|
| 408 | * @param[in] callback Function to call on transaction completion.
|
---|
| 409 | * @param[in] arg Additional for callback function.
|
---|
[41b96b4] | 410 | * @return Error code.
|
---|
| 411 | */
|
---|
[b9fa0a9] | 412 | static int control_read(
|
---|
| 413 | ddf_fun_t *fun, usb_target_t target, size_t max_packet_size,
|
---|
[1c6a45f] | 414 | void *setup_data, size_t setup_size, void *data, size_t size,
|
---|
[41b96b4] | 415 | usbhc_iface_transfer_in_callback_t callback, void *arg)
|
---|
| 416 | {
|
---|
[6bec59b] | 417 | usb_transfer_batch_t *batch = NULL;
|
---|
| 418 | hc_t *hc = NULL;
|
---|
| 419 | int ret = setup_batch(fun, target, USB_DIRECTION_BOTH, data, size,
|
---|
| 420 | setup_data, setup_size, callback, NULL, arg, "Control READ",
|
---|
| 421 | &hc, &batch);
|
---|
| 422 | if (ret != EOK)
|
---|
| 423 | return ret;
|
---|
[1c6a45f] | 424 | batch_control_read(batch);
|
---|
[6bec59b] | 425 | ret = hc_schedule(hc, batch);
|
---|
[1c6a45f] | 426 | if (ret != EOK) {
|
---|
| 427 | batch_dispose(batch);
|
---|
| 428 | }
|
---|
[b9fa0a9] | 429 | return ret;
|
---|
[41b96b4] | 430 | }
|
---|
[be7950e8] | 431 | /*----------------------------------------------------------------------------*/
|
---|
[bab71635] | 432 | usbhc_iface_t hc_iface = {
|
---|
[41b96b4] | 433 | .reserve_default_address = reserve_default_address,
|
---|
| 434 | .release_default_address = release_default_address,
|
---|
| 435 | .request_address = request_address,
|
---|
| 436 | .bind_address = bind_address,
|
---|
| 437 | .release_address = release_address,
|
---|
| 438 |
|
---|
| 439 | .register_endpoint = register_endpoint,
|
---|
| 440 | .unregister_endpoint = unregister_endpoint,
|
---|
| 441 |
|
---|
| 442 | .interrupt_out = interrupt_out,
|
---|
| 443 | .interrupt_in = interrupt_in,
|
---|
| 444 |
|
---|
| 445 | .bulk_out = bulk_out,
|
---|
| 446 | .bulk_in = bulk_in,
|
---|
| 447 |
|
---|
| 448 | .control_write = control_write,
|
---|
[1c6a45f] | 449 | .control_read = control_read,
|
---|
[41b96b4] | 450 | };
|
---|
| 451 | /**
|
---|
| 452 | * @}
|
---|
| 453 | */
|
---|