[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 | {
|
---|
[5944244] | 108 | assert(dev);
|
---|
| 109 | uhci_t *hc = dev_to_uhci(dev);
|
---|
| 110 | assert(hc);
|
---|
| 111 | return uhci_transfer(hc, dev, target, USB_TRANSFER_INTERRUPT, 0, USB_PID_OUT,
|
---|
[d93ff502] | 112 | data, size, callback, NULL, arg);
|
---|
[4317827] | 113 | }
|
---|
[3515533] | 114 | /*----------------------------------------------------------------------------*/
|
---|
[4317827] | 115 | static int interrupt_in(device_t *dev, usb_target_t target,
|
---|
| 116 | void *data, size_t size,
|
---|
| 117 | usbhc_iface_transfer_in_callback_t callback, void *arg)
|
---|
| 118 | {
|
---|
[5944244] | 119 | assert(dev);
|
---|
| 120 | uhci_t *hc = dev_to_uhci(dev);
|
---|
| 121 | assert(hc);
|
---|
| 122 | return uhci_transfer(hc, dev, target, USB_TRANSFER_INTERRUPT, 0, USB_PID_IN,
|
---|
[d93ff502] | 123 | data, size, NULL, callback, arg);
|
---|
[4317827] | 124 | }
|
---|
[3515533] | 125 | /*----------------------------------------------------------------------------*/
|
---|
[4317827] | 126 | static int control_write_setup(device_t *dev, usb_target_t target,
|
---|
| 127 | void *data, size_t size,
|
---|
| 128 | usbhc_iface_transfer_out_callback_t callback, void *arg)
|
---|
| 129 | {
|
---|
[5944244] | 130 | assert(dev);
|
---|
| 131 | uhci_t *hc = dev_to_uhci(dev);
|
---|
| 132 | assert(hc);
|
---|
| 133 | return uhci_transfer(hc, dev, target, USB_TRANSFER_CONTROL, 0, USB_PID_SETUP,
|
---|
[d93ff502] | 134 | data, size, callback, NULL, arg);
|
---|
[4317827] | 135 | }
|
---|
[3515533] | 136 | /*----------------------------------------------------------------------------*/
|
---|
[4317827] | 137 | static int control_write_data(device_t *dev, usb_target_t target,
|
---|
| 138 | void *data, size_t size,
|
---|
| 139 | usbhc_iface_transfer_out_callback_t callback, void *arg)
|
---|
| 140 | {
|
---|
[5944244] | 141 | assert(dev);
|
---|
| 142 | uhci_t *hc = dev_to_uhci(dev);
|
---|
| 143 | assert(hc);
|
---|
| 144 | return uhci_transfer(hc, dev, target, USB_TRANSFER_CONTROL, 1, USB_PID_OUT,
|
---|
[d93ff502] | 145 | data, size, callback, NULL, arg);
|
---|
[4317827] | 146 | }
|
---|
[3515533] | 147 | /*----------------------------------------------------------------------------*/
|
---|
[4317827] | 148 | static int control_write_status(device_t *dev, usb_target_t target,
|
---|
| 149 | usbhc_iface_transfer_in_callback_t callback, void *arg)
|
---|
| 150 | {
|
---|
[5944244] | 151 | assert(dev);
|
---|
| 152 | uhci_t *hc = dev_to_uhci(dev);
|
---|
| 153 | assert(hc);
|
---|
| 154 | return uhci_transfer(hc, dev, target, USB_TRANSFER_CONTROL, 0, USB_PID_IN,
|
---|
[d93ff502] | 155 | NULL, 0, NULL, callback, arg);
|
---|
[4317827] | 156 | }
|
---|
[3515533] | 157 | /*----------------------------------------------------------------------------*/
|
---|
[4317827] | 158 | static int control_read_setup(device_t *dev, usb_target_t target,
|
---|
| 159 | void *data, size_t size,
|
---|
| 160 | usbhc_iface_transfer_out_callback_t callback, void *arg)
|
---|
| 161 | {
|
---|
[5944244] | 162 | assert(dev);
|
---|
| 163 | uhci_t *hc = dev_to_uhci(dev);
|
---|
| 164 | assert(hc);
|
---|
| 165 | return uhci_transfer(hc, dev, target, USB_TRANSFER_CONTROL, 0, USB_PID_SETUP,
|
---|
[d93ff502] | 166 | data, size, callback, NULL, arg);
|
---|
[4317827] | 167 | }
|
---|
[3515533] | 168 | /*----------------------------------------------------------------------------*/
|
---|
[4317827] | 169 | static int control_read_data(device_t *dev, usb_target_t target,
|
---|
| 170 | void *data, size_t size,
|
---|
| 171 | usbhc_iface_transfer_in_callback_t callback, void *arg)
|
---|
| 172 | {
|
---|
[5944244] | 173 | assert(dev);
|
---|
| 174 | uhci_t *hc = dev_to_uhci(dev);
|
---|
| 175 | assert(hc);
|
---|
| 176 | return uhci_transfer(hc, dev, target, USB_TRANSFER_CONTROL, 1, USB_PID_IN,
|
---|
[d93ff502] | 177 | data, size, NULL, callback, arg);
|
---|
[4317827] | 178 | }
|
---|
[3515533] | 179 | /*----------------------------------------------------------------------------*/
|
---|
[4317827] | 180 | static int control_read_status(device_t *dev, usb_target_t target,
|
---|
| 181 | usbhc_iface_transfer_out_callback_t callback, void *arg)
|
---|
| 182 | {
|
---|
[5944244] | 183 | assert(dev);
|
---|
| 184 | uhci_t *hc = dev_to_uhci(dev);
|
---|
| 185 | assert(hc);
|
---|
| 186 | return uhci_transfer(hc, dev, target, USB_TRANSFER_CONTROL, 0, USB_PID_OUT,
|
---|
[d93ff502] | 187 | NULL, 0, callback, NULL, arg);
|
---|
[4317827] | 188 | }
|
---|
| 189 |
|
---|
| 190 |
|
---|
| 191 | usbhc_iface_t uhci_iface = {
|
---|
| 192 | .tell_address = get_address,
|
---|
[3515533] | 193 |
|
---|
[86b39f7e] | 194 | .reserve_default_address = reserve_default_address,
|
---|
| 195 | .release_default_address = release_default_address,
|
---|
| 196 | .request_address = request_address,
|
---|
| 197 | .bind_address = bind_address,
|
---|
| 198 | .release_address = release_address,
|
---|
[3515533] | 199 |
|
---|
[4317827] | 200 | .interrupt_out = interrupt_out,
|
---|
| 201 | .interrupt_in = interrupt_in,
|
---|
[3515533] | 202 |
|
---|
[4317827] | 203 | .control_write_setup = control_write_setup,
|
---|
| 204 | .control_write_data = control_write_data,
|
---|
| 205 | .control_write_status = control_write_status,
|
---|
[3515533] | 206 |
|
---|
[4317827] | 207 | .control_read_setup = control_read_setup,
|
---|
| 208 | .control_read_data = control_read_data,
|
---|
| 209 | .control_read_status = control_read_status
|
---|
| 210 | };
|
---|
[c56dbe0] | 211 | /**
|
---|
| 212 | * @}
|
---|
| 213 | */
|
---|