| [4317827] | 1 | /*
|
|---|
| [c56dbe0] | 2 | * Copyright (c) 2011 Vojtech Horky, Jan Vesely
|
|---|
| [4317827] | 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 | */
|
|---|
| [17ceb72] | 28 | /** @addtogroup drvusbuhcihc
|
|---|
| [c56dbe0] | 29 | * @{
|
|---|
| 30 | */
|
|---|
| 31 | /** @file
|
|---|
| [17ceb72] | 32 | * @brief UHCI driver hc interface implementation
|
|---|
| [c56dbe0] | 33 | */
|
|---|
| [eb1a2f4] | 34 | #include <ddf/driver.h>
|
|---|
| [1c6a45f] | 35 | #include <errno.h>
|
|---|
| [c56dbe0] | 36 |
|
|---|
| [1669a73] | 37 | #include <usb/debug.h>
|
|---|
| [8dc762e0] | 38 | #include <usb/host/endpoint.h>
|
|---|
| [1669a73] | 39 |
|
|---|
| [3515533] | 40 | #include "iface.h"
|
|---|
| [563ead9] | 41 | #include "batch.h"
|
|---|
| [c01cd32] | 42 | #include "hc.h"
|
|---|
| [b4875e67] | 43 |
|
|---|
| [2e6bbcf] | 44 | static inline int setup_batch(
|
|---|
| 45 | ddf_fun_t *fun, usb_target_t target, usb_direction_t direction,
|
|---|
| 46 | void *data, size_t size, void * setup_data, size_t setup_size,
|
|---|
| 47 | usbhc_iface_transfer_in_callback_t in,
|
|---|
| 48 | usbhc_iface_transfer_out_callback_t out, void *arg, const char* name,
|
|---|
| 49 | hc_t **hc, usb_transfer_batch_t **batch)
|
|---|
| 50 | {
|
|---|
| 51 | assert(hc);
|
|---|
| 52 | assert(batch);
|
|---|
| 53 | assert(fun);
|
|---|
| 54 | *hc = fun_to_hc(fun);
|
|---|
| 55 | assert(*hc);
|
|---|
| 56 |
|
|---|
| 57 | size_t res_bw;
|
|---|
| 58 | endpoint_t *ep = usb_endpoint_manager_get_ep(&(*hc)->ep_manager,
|
|---|
| 59 | target.address, target.endpoint, direction, &res_bw);
|
|---|
| 60 | if (ep == NULL) {
|
|---|
| 61 | usb_log_error("Endpoint(%d:%d) not registered for %s.\n",
|
|---|
| 62 | target.address, target.endpoint, name);
|
|---|
| 63 | return ENOENT;
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| [c4fb5ecd] | 66 | usb_log_debug2("%s %d:%d %zu(%zu).\n",
|
|---|
| [0ede0c3] | 67 | name, target.address, target.endpoint, size, ep->max_packet_size);
|
|---|
| 68 |
|
|---|
| [2e6bbcf] | 69 | const size_t bw = bandwidth_count_usb11(
|
|---|
| 70 | ep->speed, ep->transfer_type, size, ep->max_packet_size);
|
|---|
| 71 | if (res_bw < bw) {
|
|---|
| 72 | usb_log_error("Endpoint(%d:%d) %s needs %zu bw "
|
|---|
| 73 | "but only %zu is reserved.\n",
|
|---|
| [86b4ee0] | 74 | target.address, target.endpoint, name, bw, res_bw);
|
|---|
| [2e6bbcf] | 75 | return ENOSPC;
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| [a19a2d7] | 78 | *batch = batch_get(
|
|---|
| 79 | fun, ep, data, size, setup_data, setup_size, in, out, arg);
|
|---|
| 80 | if (!*batch)
|
|---|
| [fb8927d] | 81 | return ENOMEM;
|
|---|
| [86b39f7e] | 82 | return EOK;
|
|---|
| 83 | }
|
|---|
| 84 | /*----------------------------------------------------------------------------*/
|
|---|
| [a7e2f0d] | 85 | /** Request address interface function
|
|---|
| 86 | *
|
|---|
| 87 | * @param[in] fun DDF function that was called.
|
|---|
| 88 | * @param[in] speed Speed to associate with the new default address.
|
|---|
| 89 | * @param[out] address Place to write a new address.
|
|---|
| 90 | * @return Error code.
|
|---|
| 91 | */
|
|---|
| [b9fa0a9] | 92 | static int request_address(
|
|---|
| 93 | ddf_fun_t *fun, usb_speed_t speed, usb_address_t *address)
|
|---|
| [86b39f7e] | 94 | {
|
|---|
| [eb1a2f4] | 95 | assert(fun);
|
|---|
| [c01cd32] | 96 | hc_t *hc = fun_to_hc(fun);
|
|---|
| [86b39f7e] | 97 | assert(hc);
|
|---|
| [1a93bb0] | 98 | assert(address);
|
|---|
| 99 |
|
|---|
| 100 | usb_log_debug("Address request with speed %d.\n", speed);
|
|---|
| [62ed5bc] | 101 | *address = device_keeper_get_free_address(&hc->manager, speed);
|
|---|
| [1a93bb0] | 102 | usb_log_debug("Address request with result: %d.\n", *address);
|
|---|
| [86b39f7e] | 103 | if (*address <= 0)
|
|---|
| [1c6a45f] | 104 | return *address;
|
|---|
| [86b39f7e] | 105 | return EOK;
|
|---|
| 106 | }
|
|---|
| 107 | /*----------------------------------------------------------------------------*/
|
|---|
| [a7e2f0d] | 108 | /** Bind address interface function
|
|---|
| 109 | *
|
|---|
| 110 | * @param[in] fun DDF function that was called.
|
|---|
| 111 | * @param[in] address Address of the device
|
|---|
| 112 | * @param[in] handle Devman handle of the device driver.
|
|---|
| 113 | * @return Error code.
|
|---|
| 114 | */
|
|---|
| [86b39f7e] | 115 | static int bind_address(
|
|---|
| [eb1a2f4] | 116 | ddf_fun_t *fun, usb_address_t address, devman_handle_t handle)
|
|---|
| [86b39f7e] | 117 | {
|
|---|
| [eb1a2f4] | 118 | assert(fun);
|
|---|
| [c01cd32] | 119 | hc_t *hc = fun_to_hc(fun);
|
|---|
| [86b39f7e] | 120 | assert(hc);
|
|---|
| [4125b7d] | 121 | usb_log_debug("Address bind %d-%" PRIun ".\n", address, handle);
|
|---|
| [62ed5bc] | 122 | usb_device_keeper_bind(&hc->manager, address, handle);
|
|---|
| [86b39f7e] | 123 | return EOK;
|
|---|
| 124 | }
|
|---|
| [563ead9] | 125 | /*----------------------------------------------------------------------------*/
|
|---|
| [df25ab6] | 126 | /** Find device handle by address interface function.
|
|---|
| 127 | *
|
|---|
| 128 | * @param[in] fun DDF function that was called.
|
|---|
| 129 | * @param[in] address Address in question.
|
|---|
| 130 | * @param[out] handle Where to store device handle if found.
|
|---|
| 131 | * @return Error code.
|
|---|
| 132 | */
|
|---|
| 133 | static int find_by_address(ddf_fun_t *fun, usb_address_t address,
|
|---|
| 134 | devman_handle_t *handle)
|
|---|
| 135 | {
|
|---|
| 136 | assert(fun);
|
|---|
| 137 | hc_t *hc = fun_to_hc(fun);
|
|---|
| 138 | assert(hc);
|
|---|
| [563ead9] | 139 | const bool found =
|
|---|
| [df25ab6] | 140 | usb_device_keeper_find_by_address(&hc->manager, address, handle);
|
|---|
| 141 | return found ? EOK : ENOENT;
|
|---|
| 142 | }
|
|---|
| [86b39f7e] | 143 | /*----------------------------------------------------------------------------*/
|
|---|
| [a7e2f0d] | 144 | /** Release address interface function
|
|---|
| 145 | *
|
|---|
| 146 | * @param[in] fun DDF function that was called.
|
|---|
| 147 | * @param[in] address USB address to be released.
|
|---|
| 148 | * @return Error code.
|
|---|
| 149 | */
|
|---|
| [eb1a2f4] | 150 | static int release_address(ddf_fun_t *fun, usb_address_t address)
|
|---|
| [86b39f7e] | 151 | {
|
|---|
| [eb1a2f4] | 152 | assert(fun);
|
|---|
| [c01cd32] | 153 | hc_t *hc = fun_to_hc(fun);
|
|---|
| [86b39f7e] | 154 | assert(hc);
|
|---|
| [1a93bb0] | 155 | usb_log_debug("Address release %d.\n", address);
|
|---|
| [62ed5bc] | 156 | usb_device_keeper_release(&hc->manager, address);
|
|---|
| [86b39f7e] | 157 | return EOK;
|
|---|
| [4317827] | 158 | }
|
|---|
| [3515533] | 159 | /*----------------------------------------------------------------------------*/
|
|---|
| [8870230] | 160 | static int register_endpoint(
|
|---|
| [1998bcd] | 161 | ddf_fun_t *fun, usb_address_t address, usb_speed_t ep_speed,
|
|---|
| 162 | usb_endpoint_t endpoint,
|
|---|
| [8870230] | 163 | usb_transfer_type_t transfer_type, usb_direction_t direction,
|
|---|
| 164 | size_t max_packet_size, unsigned int interval)
|
|---|
| 165 | {
|
|---|
| [563ead9] | 166 | assert(fun);
|
|---|
| [a1313b8c] | 167 | hc_t *hc = fun_to_hc(fun);
|
|---|
| 168 | assert(hc);
|
|---|
| [86b4ee0] | 169 | const size_t size = max_packet_size;
|
|---|
| [1998bcd] | 170 | usb_speed_t speed = usb_device_keeper_get_speed(&hc->manager, address);
|
|---|
| 171 | if (speed >= USB_SPEED_MAX) {
|
|---|
| 172 | speed = ep_speed;
|
|---|
| 173 | }
|
|---|
| [c4fb5ecd] | 174 | usb_log_debug("Register endpoint %d:%d %s-%s %s %zuB %ums.\n",
|
|---|
| [86b4ee0] | 175 | address, endpoint, usb_str_transfer_type(transfer_type),
|
|---|
| [c4fb5ecd] | 176 | usb_str_direction(direction), usb_str_speed(speed),
|
|---|
| 177 | max_packet_size, interval);
|
|---|
| [86b4ee0] | 178 |
|
|---|
| [a81736d5] | 179 | return usb_endpoint_manager_add_ep(&hc->ep_manager, address, endpoint,
|
|---|
| 180 | direction, transfer_type, speed, max_packet_size, size);
|
|---|
| [8870230] | 181 | }
|
|---|
| 182 | /*----------------------------------------------------------------------------*/
|
|---|
| 183 | static int unregister_endpoint(
|
|---|
| 184 | ddf_fun_t *fun, usb_address_t address,
|
|---|
| 185 | usb_endpoint_t endpoint, usb_direction_t direction)
|
|---|
| 186 | {
|
|---|
| [563ead9] | 187 | assert(fun);
|
|---|
| [a1313b8c] | 188 | hc_t *hc = fun_to_hc(fun);
|
|---|
| 189 | assert(hc);
|
|---|
| [c4fb5ecd] | 190 | usb_log_debug("Unregister endpoint %d:%d %s.\n",
|
|---|
| 191 | address, endpoint, usb_str_direction(direction));
|
|---|
| [6ce42e85] | 192 | return usb_endpoint_manager_unregister_ep(&hc->ep_manager, address,
|
|---|
| 193 | endpoint, direction);
|
|---|
| [8870230] | 194 | }
|
|---|
| 195 | /*----------------------------------------------------------------------------*/
|
|---|
| [a7e2f0d] | 196 | /** Interrupt out transaction interface function
|
|---|
| 197 | *
|
|---|
| 198 | * @param[in] fun DDF function that was called.
|
|---|
| 199 | * @param[in] target USB device to write to.
|
|---|
| 200 | * @param[in] data Source of data.
|
|---|
| 201 | * @param[in] size Size of data source.
|
|---|
| 202 | * @param[in] callback Function to call on transaction completion
|
|---|
| 203 | * @param[in] arg Additional for callback function.
|
|---|
| 204 | * @return Error code.
|
|---|
| 205 | */
|
|---|
| [b9fa0a9] | 206 | static int interrupt_out(
|
|---|
| [7dfc06fa] | 207 | ddf_fun_t *fun, usb_target_t target, void *data,
|
|---|
| [b9fa0a9] | 208 | size_t size, usbhc_iface_transfer_out_callback_t callback, void *arg)
|
|---|
| [4317827] | 209 | {
|
|---|
| [2e6bbcf] | 210 | usb_transfer_batch_t *batch = NULL;
|
|---|
| 211 | hc_t *hc = NULL;
|
|---|
| 212 | int ret = setup_batch(fun, target, USB_DIRECTION_OUT, data, size,
|
|---|
| 213 | NULL, 0, NULL, callback, arg, "Interrupt OUT", &hc, &batch);
|
|---|
| 214 | if (ret != EOK)
|
|---|
| 215 | return ret;
|
|---|
| [563ead9] | 216 | assert(batch);
|
|---|
| 217 | assert(hc);
|
|---|
| [5620bd4] | 218 | batch_interrupt_out(batch);
|
|---|
| [2e6bbcf] | 219 | ret = hc_schedule(hc, batch);
|
|---|
| [3bd96bb] | 220 | if (ret != EOK) {
|
|---|
| [2cc6e97] | 221 | usb_transfer_batch_dispose(batch);
|
|---|
| [3bd96bb] | 222 | }
|
|---|
| [b9fa0a9] | 223 | return ret;
|
|---|
| [4317827] | 224 | }
|
|---|
| [3515533] | 225 | /*----------------------------------------------------------------------------*/
|
|---|
| [a7e2f0d] | 226 | /** Interrupt in transaction interface function
|
|---|
| 227 | *
|
|---|
| 228 | * @param[in] fun DDF function that was called.
|
|---|
| 229 | * @param[in] target USB device to write to.
|
|---|
| 230 | * @param[out] data Data destination.
|
|---|
| 231 | * @param[in] size Size of data source.
|
|---|
| 232 | * @param[in] callback Function to call on transaction completion
|
|---|
| 233 | * @param[in] arg Additional for callback function.
|
|---|
| 234 | * @return Error code.
|
|---|
| 235 | */
|
|---|
| [b9fa0a9] | 236 | static int interrupt_in(
|
|---|
| [7dfc06fa] | 237 | ddf_fun_t *fun, usb_target_t target, void *data,
|
|---|
| [b9fa0a9] | 238 | size_t size, usbhc_iface_transfer_in_callback_t callback, void *arg)
|
|---|
| [4317827] | 239 | {
|
|---|
| [2e6bbcf] | 240 | usb_transfer_batch_t *batch = NULL;
|
|---|
| 241 | hc_t *hc = NULL;
|
|---|
| 242 | int ret = setup_batch(fun, target, USB_DIRECTION_IN, data, size,
|
|---|
| 243 | NULL, 0, callback, NULL, arg, "Interrupt IN", &hc, &batch);
|
|---|
| 244 | if (ret != EOK)
|
|---|
| 245 | return ret;
|
|---|
| [563ead9] | 246 | assert(batch);
|
|---|
| 247 | assert(hc);
|
|---|
| [5620bd4] | 248 | batch_interrupt_in(batch);
|
|---|
| [2e6bbcf] | 249 | ret = hc_schedule(hc, batch);
|
|---|
| [3bd96bb] | 250 | if (ret != EOK) {
|
|---|
| [2cc6e97] | 251 | usb_transfer_batch_dispose(batch);
|
|---|
| [3bd96bb] | 252 | }
|
|---|
| [b9fa0a9] | 253 | return ret;
|
|---|
| [4317827] | 254 | }
|
|---|
| [3515533] | 255 | /*----------------------------------------------------------------------------*/
|
|---|
| [a7e2f0d] | 256 | /** Bulk out transaction interface function
|
|---|
| 257 | *
|
|---|
| 258 | * @param[in] fun DDF function that was called.
|
|---|
| 259 | * @param[in] target USB device to write to.
|
|---|
| 260 | * @param[in] data Source of data.
|
|---|
| 261 | * @param[in] size Size of data source.
|
|---|
| 262 | * @param[in] callback Function to call on transaction completion
|
|---|
| 263 | * @param[in] arg Additional for callback function.
|
|---|
| 264 | * @return Error code.
|
|---|
| 265 | */
|
|---|
| [b9fa0a9] | 266 | static int bulk_out(
|
|---|
| [7dfc06fa] | 267 | ddf_fun_t *fun, usb_target_t target, void *data,
|
|---|
| [b9fa0a9] | 268 | size_t size, usbhc_iface_transfer_out_callback_t callback, void *arg)
|
|---|
| [0e06a14] | 269 | {
|
|---|
| [2e6bbcf] | 270 | usb_transfer_batch_t *batch = NULL;
|
|---|
| 271 | hc_t *hc = NULL;
|
|---|
| 272 | int ret = setup_batch(fun, target, USB_DIRECTION_OUT, data, size,
|
|---|
| 273 | NULL, 0, NULL, callback, arg, "Bulk OUT", &hc, &batch);
|
|---|
| 274 | if (ret != EOK)
|
|---|
| 275 | return ret;
|
|---|
| [563ead9] | 276 | assert(batch);
|
|---|
| 277 | assert(hc);
|
|---|
| [5620bd4] | 278 | batch_bulk_out(batch);
|
|---|
| [2e6bbcf] | 279 | ret = hc_schedule(hc, batch);
|
|---|
| [3bd96bb] | 280 | if (ret != EOK) {
|
|---|
| [2cc6e97] | 281 | usb_transfer_batch_dispose(batch);
|
|---|
| [3bd96bb] | 282 | }
|
|---|
| [b9fa0a9] | 283 | return ret;
|
|---|
| [0e06a14] | 284 | }
|
|---|
| 285 | /*----------------------------------------------------------------------------*/
|
|---|
| [a7e2f0d] | 286 | /** Bulk in transaction interface function
|
|---|
| 287 | *
|
|---|
| 288 | * @param[in] fun DDF function that was called.
|
|---|
| 289 | * @param[in] target USB device to write to.
|
|---|
| 290 | * @param[out] data Data destination.
|
|---|
| 291 | * @param[in] size Size of data source.
|
|---|
| 292 | * @param[in] callback Function to call on transaction completion
|
|---|
| 293 | * @param[in] arg Additional for callback function.
|
|---|
| 294 | * @return Error code.
|
|---|
| 295 | */
|
|---|
| [b9fa0a9] | 296 | static int bulk_in(
|
|---|
| [7dfc06fa] | 297 | ddf_fun_t *fun, usb_target_t target, void *data,
|
|---|
| [b9fa0a9] | 298 | size_t size, usbhc_iface_transfer_in_callback_t callback, void *arg)
|
|---|
| [0e06a14] | 299 | {
|
|---|
| [2e6bbcf] | 300 | usb_transfer_batch_t *batch = NULL;
|
|---|
| 301 | hc_t *hc = NULL;
|
|---|
| 302 | int ret = setup_batch(fun, target, USB_DIRECTION_IN, data, size,
|
|---|
| 303 | NULL, 0, callback, NULL, arg, "Bulk IN", &hc, &batch);
|
|---|
| 304 | if (ret != EOK)
|
|---|
| 305 | return ret;
|
|---|
| [563ead9] | 306 | assert(batch);
|
|---|
| 307 | assert(hc);
|
|---|
| [5620bd4] | 308 | batch_bulk_in(batch);
|
|---|
| [2e6bbcf] | 309 | ret = hc_schedule(hc, batch);
|
|---|
| [3bd96bb] | 310 | if (ret != EOK) {
|
|---|
| [2cc6e97] | 311 | usb_transfer_batch_dispose(batch);
|
|---|
| [3bd96bb] | 312 | }
|
|---|
| [b9fa0a9] | 313 | return ret;
|
|---|
| [0e06a14] | 314 | }
|
|---|
| 315 | /*----------------------------------------------------------------------------*/
|
|---|
| [a7e2f0d] | 316 | /** Control write transaction interface function
|
|---|
| 317 | *
|
|---|
| 318 | * @param[in] fun DDF function that was called.
|
|---|
| 319 | * @param[in] target USB device to write to.
|
|---|
| [c61338a] | 320 | * @param[in] setup_data Data to send with SETUP transfer.
|
|---|
| 321 | * @param[in] setup_size Size of data to send with SETUP transfer (always 8B).
|
|---|
| [a7e2f0d] | 322 | * @param[in] data Source of data.
|
|---|
| 323 | * @param[in] size Size of data source.
|
|---|
| 324 | * @param[in] callback Function to call on transaction completion.
|
|---|
| 325 | * @param[in] arg Additional for callback function.
|
|---|
| 326 | * @return Error code.
|
|---|
| 327 | */
|
|---|
| [b9fa0a9] | 328 | static int control_write(
|
|---|
| [7dfc06fa] | 329 | ddf_fun_t *fun, usb_target_t target,
|
|---|
| [a72620d] | 330 | void *setup_data, size_t setup_size, void *data, size_t size,
|
|---|
| 331 | usbhc_iface_transfer_out_callback_t callback, void *arg)
|
|---|
| 332 | {
|
|---|
| [2e6bbcf] | 333 | usb_transfer_batch_t *batch = NULL;
|
|---|
| 334 | hc_t *hc = NULL;
|
|---|
| 335 | int ret = setup_batch(fun, target, USB_DIRECTION_BOTH, data, size,
|
|---|
| 336 | setup_data, setup_size, NULL, callback, arg, "Control WRITE",
|
|---|
| 337 | &hc, &batch);
|
|---|
| 338 | if (ret != EOK)
|
|---|
| 339 | return ret;
|
|---|
| [563ead9] | 340 | assert(batch);
|
|---|
| 341 | assert(hc);
|
|---|
| [ba038f4] | 342 | usb_endpoint_manager_reset_if_need(&hc->ep_manager, target, setup_data);
|
|---|
| [83c439c] | 343 | batch_control_write(batch);
|
|---|
| [2e6bbcf] | 344 | ret = hc_schedule(hc, batch);
|
|---|
| [3bd96bb] | 345 | if (ret != EOK) {
|
|---|
| [2cc6e97] | 346 | usb_transfer_batch_dispose(batch);
|
|---|
| [3bd96bb] | 347 | }
|
|---|
| [b9fa0a9] | 348 | return ret;
|
|---|
| [a72620d] | 349 | }
|
|---|
| 350 | /*----------------------------------------------------------------------------*/
|
|---|
| [a7e2f0d] | 351 | /** Control read transaction interface function
|
|---|
| 352 | *
|
|---|
| 353 | * @param[in] fun DDF function that was called.
|
|---|
| 354 | * @param[in] target USB device to write to.
|
|---|
| 355 | * @param[in] setup_data Data to send with SETUP packet.
|
|---|
| 356 | * @param[in] setup_size Size of data to send with SETUP packet (should be 8B).
|
|---|
| 357 | * @param[out] data Source of data.
|
|---|
| 358 | * @param[in] size Size of data source.
|
|---|
| 359 | * @param[in] callback Function to call on transaction completion.
|
|---|
| 360 | * @param[in] arg Additional for callback function.
|
|---|
| 361 | * @return Error code.
|
|---|
| 362 | */
|
|---|
| [b9fa0a9] | 363 | static int control_read(
|
|---|
| [7dfc06fa] | 364 | ddf_fun_t *fun, usb_target_t target,
|
|---|
| [a72620d] | 365 | void *setup_data, size_t setup_size, void *data, size_t size,
|
|---|
| 366 | usbhc_iface_transfer_in_callback_t callback, void *arg)
|
|---|
| 367 | {
|
|---|
| [2e6bbcf] | 368 | usb_transfer_batch_t *batch = NULL;
|
|---|
| 369 | hc_t *hc = NULL;
|
|---|
| 370 | int ret = setup_batch(fun, target, USB_DIRECTION_BOTH, data, size,
|
|---|
| 371 | setup_data, setup_size, callback, NULL, arg, "Control READ",
|
|---|
| 372 | &hc, &batch);
|
|---|
| 373 | if (ret != EOK)
|
|---|
| 374 | return ret;
|
|---|
| [563ead9] | 375 | assert(batch);
|
|---|
| 376 | assert(hc);
|
|---|
| [83c439c] | 377 | batch_control_read(batch);
|
|---|
| [2e6bbcf] | 378 | ret = hc_schedule(hc, batch);
|
|---|
| [3bd96bb] | 379 | if (ret != EOK) {
|
|---|
| [2cc6e97] | 380 | usb_transfer_batch_dispose(batch);
|
|---|
| [3bd96bb] | 381 | }
|
|---|
| [b9fa0a9] | 382 | return ret;
|
|---|
| [a72620d] | 383 | }
|
|---|
| [9e80904] | 384 | /*----------------------------------------------------------------------------*/
|
|---|
| [c01cd32] | 385 | usbhc_iface_t hc_iface = {
|
|---|
| [86b39f7e] | 386 | .request_address = request_address,
|
|---|
| 387 | .bind_address = bind_address,
|
|---|
| [df25ab6] | 388 | .find_by_address = find_by_address,
|
|---|
| [86b39f7e] | 389 | .release_address = release_address,
|
|---|
| [3515533] | 390 |
|
|---|
| [8870230] | 391 | .register_endpoint = register_endpoint,
|
|---|
| 392 | .unregister_endpoint = unregister_endpoint,
|
|---|
| 393 |
|
|---|
| [4317827] | 394 | .interrupt_out = interrupt_out,
|
|---|
| 395 | .interrupt_in = interrupt_in,
|
|---|
| [3515533] | 396 |
|
|---|
| [0e06a14] | 397 | .bulk_out = bulk_out,
|
|---|
| [1c6a45f] | 398 | .bulk_in = bulk_in,
|
|---|
| [0e06a14] | 399 |
|
|---|
| [a72620d] | 400 | .control_write = control_write,
|
|---|
| [1c6a45f] | 401 | .control_read = control_read,
|
|---|
| [4317827] | 402 | };
|
|---|
| [c56dbe0] | 403 | /**
|
|---|
| 404 | * @}
|
|---|
| 405 | */
|
|---|