[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 | */
|
---|
[c56dbe0] | 28 | /** @addtogroup usb
|
---|
| 29 | * @{
|
---|
| 30 | */
|
---|
| 31 | /** @file
|
---|
| 32 | * @brief UHCI driver
|
---|
| 33 | */
|
---|
[67a1b78] | 34 | #include <driver.h>
|
---|
| 35 | #include <remote_usbhc.h>
|
---|
[c56dbe0] | 36 |
|
---|
[1669a73] | 37 | #include <usb/debug.h>
|
---|
| 38 |
|
---|
[4317827] | 39 | #include <errno.h>
|
---|
| 40 |
|
---|
[3515533] | 41 | #include "iface.h"
|
---|
[4317827] | 42 | #include "uhci.h"
|
---|
| 43 |
|
---|
| 44 | static int get_address(device_t *dev, devman_handle_t handle,
|
---|
| 45 | usb_address_t *address)
|
---|
| 46 | {
|
---|
[86b39f7e] | 47 | assert(dev);
|
---|
[5944244] | 48 | uhci_t *hc = dev_to_uhci(dev);
|
---|
[86b39f7e] | 49 | assert(hc);
|
---|
| 50 | *address = usb_address_keeping_find(&hc->address_manager, handle);
|
---|
| 51 | if (*address <= 0)
|
---|
| 52 | return *address;
|
---|
| 53 | return EOK;
|
---|
| 54 | }
|
---|
| 55 | /*----------------------------------------------------------------------------*/
|
---|
| 56 | static int reserve_default_address(device_t *dev)
|
---|
| 57 | {
|
---|
| 58 | assert(dev);
|
---|
[5944244] | 59 | uhci_t *hc = dev_to_uhci(dev);
|
---|
[86b39f7e] | 60 | assert(hc);
|
---|
| 61 | usb_address_keeping_reserve_default(&hc->address_manager);
|
---|
| 62 | return EOK;
|
---|
| 63 | }
|
---|
| 64 | /*----------------------------------------------------------------------------*/
|
---|
| 65 | static int release_default_address(device_t *dev)
|
---|
| 66 | {
|
---|
| 67 | assert(dev);
|
---|
[5944244] | 68 | uhci_t *hc = dev_to_uhci(dev);
|
---|
[86b39f7e] | 69 | assert(hc);
|
---|
| 70 | usb_address_keeping_release_default(&hc->address_manager);
|
---|
| 71 | return EOK;
|
---|
| 72 | }
|
---|
| 73 | /*----------------------------------------------------------------------------*/
|
---|
| 74 | static int request_address(device_t *dev, usb_address_t *address)
|
---|
| 75 | {
|
---|
| 76 | assert(dev);
|
---|
[5944244] | 77 | uhci_t *hc = dev_to_uhci(dev);
|
---|
[86b39f7e] | 78 | assert(hc);
|
---|
| 79 | *address = usb_address_keeping_request(&hc->address_manager);
|
---|
| 80 | if (*address <= 0)
|
---|
| 81 | return *address;
|
---|
| 82 | return EOK;
|
---|
| 83 | }
|
---|
| 84 | /*----------------------------------------------------------------------------*/
|
---|
| 85 | static int bind_address(
|
---|
| 86 | device_t *dev, usb_address_t address, devman_handle_t handle)
|
---|
| 87 | {
|
---|
| 88 | assert(dev);
|
---|
[5944244] | 89 | uhci_t *hc = dev_to_uhci(dev);
|
---|
[86b39f7e] | 90 | assert(hc);
|
---|
| 91 | usb_address_keeping_devman_bind(&hc->address_manager, address, handle);
|
---|
| 92 | return EOK;
|
---|
| 93 | }
|
---|
| 94 | /*----------------------------------------------------------------------------*/
|
---|
| 95 | static int release_address(device_t *dev, usb_address_t address)
|
---|
| 96 | {
|
---|
| 97 | assert(dev);
|
---|
[5944244] | 98 | uhci_t *hc = dev_to_uhci(dev);
|
---|
[86b39f7e] | 99 | assert(hc);
|
---|
| 100 | usb_address_keeping_release_default(&hc->address_manager);
|
---|
| 101 | return EOK;
|
---|
[4317827] | 102 | }
|
---|
[3515533] | 103 | /*----------------------------------------------------------------------------*/
|
---|
[4317827] | 104 | static int interrupt_out(device_t *dev, usb_target_t target,
|
---|
| 105 | void *data, size_t size,
|
---|
| 106 | usbhc_iface_transfer_out_callback_t callback, void *arg)
|
---|
| 107 | {
|
---|
[fe10e72] | 108 | size_t max_packet_size = 8;
|
---|
| 109 | dev_speed_t speed = FULL_SPEED;
|
---|
| 110 |
|
---|
[83c439c] | 111 | batch_t *batch = batch_get(dev, target, USB_TRANSFER_INTERRUPT,
|
---|
[7dd3318] | 112 | max_packet_size, speed, data, size, NULL, 0, NULL, callback, arg);
|
---|
[83c439c] | 113 | if (!batch)
|
---|
[7e62b62] | 114 | return ENOMEM;
|
---|
[83c439c] | 115 | batch_interrupt_out(batch);
|
---|
[7e62b62] | 116 | return EOK;
|
---|
[4317827] | 117 | }
|
---|
[3515533] | 118 | /*----------------------------------------------------------------------------*/
|
---|
[4317827] | 119 | static int interrupt_in(device_t *dev, usb_target_t target,
|
---|
| 120 | void *data, size_t size,
|
---|
| 121 | usbhc_iface_transfer_in_callback_t callback, void *arg)
|
---|
| 122 | {
|
---|
[61bb85d] | 123 | size_t max_packet_size = 4;
|
---|
[fe10e72] | 124 | dev_speed_t speed = FULL_SPEED;
|
---|
| 125 |
|
---|
[83c439c] | 126 | batch_t *batch = batch_get(dev, target, USB_TRANSFER_INTERRUPT,
|
---|
[7dd3318] | 127 | max_packet_size, speed, data, size, NULL, 0, callback, NULL, arg);
|
---|
[83c439c] | 128 | if (!batch)
|
---|
[7e62b62] | 129 | return ENOMEM;
|
---|
[83c439c] | 130 | batch_interrupt_in(batch);
|
---|
[7e62b62] | 131 | return EOK;
|
---|
[4317827] | 132 | }
|
---|
[3515533] | 133 | /*----------------------------------------------------------------------------*/
|
---|
[a72620d] | 134 | static int control_write(device_t *dev, usb_target_t target,
|
---|
| 135 | void *setup_data, size_t setup_size, void *data, size_t size,
|
---|
| 136 | usbhc_iface_transfer_out_callback_t callback, void *arg)
|
---|
| 137 | {
|
---|
[2b4dbd1] | 138 | size_t max_packet_size = 8;
|
---|
[f241b05b] | 139 | dev_speed_t speed = FULL_SPEED;
|
---|
| 140 |
|
---|
[83c439c] | 141 | batch_t *batch = batch_get(dev, target, USB_TRANSFER_CONTROL,
|
---|
[7dd3318] | 142 | max_packet_size, speed, data, size, setup_data, setup_size,
|
---|
| 143 | NULL, callback, arg);
|
---|
[83c439c] | 144 | if (!batch)
|
---|
[f241b05b] | 145 | return ENOMEM;
|
---|
[83c439c] | 146 | batch_control_write(batch);
|
---|
[f241b05b] | 147 | return EOK;
|
---|
[a72620d] | 148 | }
|
---|
| 149 | /*----------------------------------------------------------------------------*/
|
---|
| 150 | static int control_read(device_t *dev, usb_target_t target,
|
---|
| 151 | void *setup_data, size_t setup_size, void *data, size_t size,
|
---|
| 152 | usbhc_iface_transfer_in_callback_t callback, void *arg)
|
---|
| 153 | {
|
---|
[2b4dbd1] | 154 | size_t max_packet_size = 8;
|
---|
[f241b05b] | 155 | dev_speed_t speed = FULL_SPEED;
|
---|
| 156 |
|
---|
[83c439c] | 157 | batch_t *batch = batch_get(dev, target, USB_TRANSFER_CONTROL,
|
---|
[7dd3318] | 158 | max_packet_size, speed, data, size, setup_data, setup_size, callback,
|
---|
| 159 | NULL, arg);
|
---|
[83c439c] | 160 | if (!batch)
|
---|
[f241b05b] | 161 | return ENOMEM;
|
---|
[83c439c] | 162 | batch_control_read(batch);
|
---|
[f241b05b] | 163 | return EOK;
|
---|
[a72620d] | 164 | }
|
---|
| 165 | /*----------------------------------------------------------------------------*/
|
---|
[4317827] | 166 | static int control_write_setup(device_t *dev, usb_target_t target,
|
---|
| 167 | void *data, size_t size,
|
---|
| 168 | usbhc_iface_transfer_out_callback_t callback, void *arg)
|
---|
| 169 | {
|
---|
[7dd3318] | 170 | size_t max_packet_size = 8;
|
---|
| 171 | dev_speed_t speed = FULL_SPEED;
|
---|
| 172 |
|
---|
[6cd7b17] | 173 | usb_log_warning("Using deprecated API %s.\n", __FUNCTION__);
|
---|
[83c439c] | 174 | batch_t *batch = batch_get(dev, target, USB_TRANSFER_CONTROL,
|
---|
[7dd3318] | 175 | max_packet_size, speed, NULL, 0, data, size, NULL, callback, arg);
|
---|
[83c439c] | 176 | if (!batch)
|
---|
[9e80904] | 177 | return ENOMEM;
|
---|
[83c439c] | 178 | batch_control_setup_old(batch);
|
---|
[9e80904] | 179 | return EOK;
|
---|
[4317827] | 180 | }
|
---|
[3515533] | 181 | /*----------------------------------------------------------------------------*/
|
---|
[4317827] | 182 | static int control_write_data(device_t *dev, usb_target_t target,
|
---|
| 183 | void *data, size_t size,
|
---|
| 184 | usbhc_iface_transfer_out_callback_t callback, void *arg)
|
---|
| 185 | {
|
---|
[7dd3318] | 186 | size_t max_packet_size = 8;
|
---|
| 187 | dev_speed_t speed = FULL_SPEED;
|
---|
| 188 |
|
---|
[6cd7b17] | 189 | usb_log_warning("Using deprecated API %s.\n", __FUNCTION__);
|
---|
[83c439c] | 190 | batch_t *batch = batch_get(dev, target, USB_TRANSFER_CONTROL,
|
---|
[7dd3318] | 191 | max_packet_size, speed, data, size, NULL, 0, NULL, callback, arg);
|
---|
[83c439c] | 192 | if (!batch)
|
---|
[9e80904] | 193 | return ENOMEM;
|
---|
[83c439c] | 194 | batch_control_write_data_old(batch);
|
---|
[9e80904] | 195 | return EOK;
|
---|
[4317827] | 196 | }
|
---|
[3515533] | 197 | /*----------------------------------------------------------------------------*/
|
---|
[4317827] | 198 | static int control_write_status(device_t *dev, usb_target_t target,
|
---|
| 199 | usbhc_iface_transfer_in_callback_t callback, void *arg)
|
---|
| 200 | {
|
---|
[7dd3318] | 201 | size_t max_packet_size = 8;
|
---|
| 202 | dev_speed_t speed = FULL_SPEED;
|
---|
| 203 |
|
---|
[6cd7b17] | 204 | usb_log_warning("Using deprecated API %s.\n", __FUNCTION__);
|
---|
[83c439c] | 205 | batch_t *batch = batch_get(dev, target, USB_TRANSFER_CONTROL,
|
---|
[7dd3318] | 206 | max_packet_size, speed, NULL, 0, NULL, 0, callback, NULL, arg);
|
---|
[83c439c] | 207 | if (!batch)
|
---|
[9e80904] | 208 | return ENOMEM;
|
---|
[83c439c] | 209 | batch_control_write_status_old(batch);
|
---|
[9e80904] | 210 | return EOK;
|
---|
[4317827] | 211 | }
|
---|
[3515533] | 212 | /*----------------------------------------------------------------------------*/
|
---|
[4317827] | 213 | static int control_read_setup(device_t *dev, usb_target_t target,
|
---|
| 214 | void *data, size_t size,
|
---|
| 215 | usbhc_iface_transfer_out_callback_t callback, void *arg)
|
---|
| 216 | {
|
---|
[7dd3318] | 217 | size_t max_packet_size = 8;
|
---|
| 218 | dev_speed_t speed = FULL_SPEED;
|
---|
| 219 |
|
---|
[6cd7b17] | 220 | usb_log_warning("Using deprecated API %s.\n", __FUNCTION__);
|
---|
[83c439c] | 221 | batch_t *batch = batch_get(dev, target, USB_TRANSFER_CONTROL,
|
---|
[7dd3318] | 222 | max_packet_size, speed, NULL, 0, data, size, NULL, callback, arg);
|
---|
[83c439c] | 223 | if (!batch)
|
---|
[9e80904] | 224 | return ENOMEM;
|
---|
[83c439c] | 225 | batch_control_setup_old(batch);
|
---|
[9e80904] | 226 | return EOK;
|
---|
[4317827] | 227 | }
|
---|
[3515533] | 228 | /*----------------------------------------------------------------------------*/
|
---|
[4317827] | 229 | static int control_read_data(device_t *dev, usb_target_t target,
|
---|
| 230 | void *data, size_t size,
|
---|
| 231 | usbhc_iface_transfer_in_callback_t callback, void *arg)
|
---|
| 232 | {
|
---|
[7dd3318] | 233 | size_t max_packet_size = 8;
|
---|
| 234 | dev_speed_t speed = FULL_SPEED;
|
---|
| 235 |
|
---|
[6cd7b17] | 236 | usb_log_warning("Using deprecated API %s.\n", __FUNCTION__);
|
---|
[83c439c] | 237 | batch_t *batch = batch_get(dev, target, USB_TRANSFER_CONTROL,
|
---|
[7dd3318] | 238 | max_packet_size, speed, data, size, NULL, 0, callback, NULL, arg);
|
---|
[83c439c] | 239 | if (!batch)
|
---|
[9e80904] | 240 | return ENOMEM;
|
---|
[83c439c] | 241 | batch_control_read_data_old(batch);
|
---|
[9e80904] | 242 | return EOK;
|
---|
[4317827] | 243 | }
|
---|
[3515533] | 244 | /*----------------------------------------------------------------------------*/
|
---|
[4317827] | 245 | static int control_read_status(device_t *dev, usb_target_t target,
|
---|
| 246 | usbhc_iface_transfer_out_callback_t callback, void *arg)
|
---|
| 247 | {
|
---|
[7dd3318] | 248 | size_t max_packet_size = 8;
|
---|
| 249 | dev_speed_t speed = FULL_SPEED;
|
---|
| 250 |
|
---|
[6cd7b17] | 251 | usb_log_warning("Using deprecated API %s.\n", __FUNCTION__);
|
---|
[83c439c] | 252 | batch_t *batch = batch_get(dev, target, USB_TRANSFER_CONTROL,
|
---|
[7dd3318] | 253 | max_packet_size, speed, NULL, 0, NULL, 0, NULL, callback, arg);
|
---|
[83c439c] | 254 | if (!batch)
|
---|
[9e80904] | 255 | return ENOMEM;
|
---|
[83c439c] | 256 | batch_control_read_status_old(batch);
|
---|
[9e80904] | 257 | return EOK;
|
---|
[4317827] | 258 | }
|
---|
[9e80904] | 259 | /*----------------------------------------------------------------------------*/
|
---|
[4317827] | 260 | usbhc_iface_t uhci_iface = {
|
---|
| 261 | .tell_address = get_address,
|
---|
[3515533] | 262 |
|
---|
[86b39f7e] | 263 | .reserve_default_address = reserve_default_address,
|
---|
| 264 | .release_default_address = release_default_address,
|
---|
| 265 | .request_address = request_address,
|
---|
| 266 | .bind_address = bind_address,
|
---|
| 267 | .release_address = release_address,
|
---|
[3515533] | 268 |
|
---|
[4317827] | 269 | .interrupt_out = interrupt_out,
|
---|
| 270 | .interrupt_in = interrupt_in,
|
---|
[3515533] | 271 |
|
---|
[a72620d] | 272 | .control_read = control_read,
|
---|
| 273 | .control_write = control_write,
|
---|
| 274 |
|
---|
[4317827] | 275 | .control_write_setup = control_write_setup,
|
---|
| 276 | .control_write_data = control_write_data,
|
---|
| 277 | .control_write_status = control_write_status,
|
---|
[3515533] | 278 |
|
---|
[4317827] | 279 | .control_read_setup = control_read_setup,
|
---|
| 280 | .control_read_data = control_read_data,
|
---|
| 281 | .control_read_status = control_read_status
|
---|
| 282 | };
|
---|
[c56dbe0] | 283 | /**
|
---|
| 284 | * @}
|
---|
| 285 | */
|
---|