[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 | */
|
---|
[eb1a2f4] | 34 | #include <ddf/driver.h>
|
---|
[67a1b78] | 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 |
|
---|
[b4875e67] | 44 | #define DEFAULT_SPEED FULL_SPEED
|
---|
| 45 |
|
---|
[86b39f7e] | 46 | /*----------------------------------------------------------------------------*/
|
---|
[eb1a2f4] | 47 | static int reserve_default_address(ddf_fun_t *fun, usb_speed_t speed)
|
---|
[86b39f7e] | 48 | {
|
---|
[eb1a2f4] | 49 | assert(fun);
|
---|
| 50 | uhci_t *hc = fun_to_uhci(fun);
|
---|
[86b39f7e] | 51 | assert(hc);
|
---|
| 52 | usb_address_keeping_reserve_default(&hc->address_manager);
|
---|
| 53 | return EOK;
|
---|
| 54 | }
|
---|
| 55 | /*----------------------------------------------------------------------------*/
|
---|
[eb1a2f4] | 56 | static int release_default_address(ddf_fun_t *fun)
|
---|
[86b39f7e] | 57 | {
|
---|
[eb1a2f4] | 58 | assert(fun);
|
---|
| 59 | uhci_t *hc = fun_to_uhci(fun);
|
---|
[86b39f7e] | 60 | assert(hc);
|
---|
| 61 | usb_address_keeping_release_default(&hc->address_manager);
|
---|
| 62 | return EOK;
|
---|
| 63 | }
|
---|
| 64 | /*----------------------------------------------------------------------------*/
|
---|
[eb1a2f4] | 65 | static int request_address(ddf_fun_t *fun, usb_speed_t speed,
|
---|
[6427cf67] | 66 | usb_address_t *address)
|
---|
[86b39f7e] | 67 | {
|
---|
[eb1a2f4] | 68 | assert(fun);
|
---|
| 69 | uhci_t *hc = fun_to_uhci(fun);
|
---|
[86b39f7e] | 70 | assert(hc);
|
---|
| 71 | *address = usb_address_keeping_request(&hc->address_manager);
|
---|
| 72 | if (*address <= 0)
|
---|
| 73 | return *address;
|
---|
| 74 | return EOK;
|
---|
| 75 | }
|
---|
| 76 | /*----------------------------------------------------------------------------*/
|
---|
| 77 | static int bind_address(
|
---|
[eb1a2f4] | 78 | ddf_fun_t *fun, usb_address_t address, devman_handle_t handle)
|
---|
[86b39f7e] | 79 | {
|
---|
[eb1a2f4] | 80 | assert(fun);
|
---|
| 81 | uhci_t *hc = fun_to_uhci(fun);
|
---|
[86b39f7e] | 82 | assert(hc);
|
---|
| 83 | usb_address_keeping_devman_bind(&hc->address_manager, address, handle);
|
---|
| 84 | return EOK;
|
---|
| 85 | }
|
---|
| 86 | /*----------------------------------------------------------------------------*/
|
---|
[eb1a2f4] | 87 | static int release_address(ddf_fun_t *fun, usb_address_t address)
|
---|
[86b39f7e] | 88 | {
|
---|
[eb1a2f4] | 89 | assert(fun);
|
---|
| 90 | uhci_t *hc = fun_to_uhci(fun);
|
---|
[86b39f7e] | 91 | assert(hc);
|
---|
| 92 | usb_address_keeping_release_default(&hc->address_manager);
|
---|
| 93 | return EOK;
|
---|
[4317827] | 94 | }
|
---|
[3515533] | 95 | /*----------------------------------------------------------------------------*/
|
---|
[eb1a2f4] | 96 | static int interrupt_out(ddf_fun_t *fun, usb_target_t target,
|
---|
[ec59693] | 97 | size_t max_packet_size,
|
---|
[4317827] | 98 | void *data, size_t size,
|
---|
| 99 | usbhc_iface_transfer_out_callback_t callback, void *arg)
|
---|
| 100 | {
|
---|
[b4875e67] | 101 | dev_speed_t speed = DEFAULT_SPEED;
|
---|
[fe10e72] | 102 |
|
---|
[eb1a2f4] | 103 | batch_t *batch = batch_get(fun, target, USB_TRANSFER_INTERRUPT,
|
---|
[7dd3318] | 104 | max_packet_size, speed, data, size, NULL, 0, NULL, callback, arg);
|
---|
[83c439c] | 105 | if (!batch)
|
---|
[7e62b62] | 106 | return ENOMEM;
|
---|
[83c439c] | 107 | batch_interrupt_out(batch);
|
---|
[7e62b62] | 108 | return EOK;
|
---|
[4317827] | 109 | }
|
---|
[3515533] | 110 | /*----------------------------------------------------------------------------*/
|
---|
[eb1a2f4] | 111 | static int interrupt_in(ddf_fun_t *fun, usb_target_t target,
|
---|
[ec59693] | 112 | size_t max_packet_size,
|
---|
[4317827] | 113 | void *data, size_t size,
|
---|
| 114 | usbhc_iface_transfer_in_callback_t callback, void *arg)
|
---|
| 115 | {
|
---|
[b4875e67] | 116 | dev_speed_t speed = DEFAULT_SPEED;
|
---|
[fe10e72] | 117 |
|
---|
[eb1a2f4] | 118 | batch_t *batch = batch_get(fun, target, USB_TRANSFER_INTERRUPT,
|
---|
[7dd3318] | 119 | max_packet_size, speed, data, size, NULL, 0, callback, NULL, arg);
|
---|
[83c439c] | 120 | if (!batch)
|
---|
[7e62b62] | 121 | return ENOMEM;
|
---|
[83c439c] | 122 | batch_interrupt_in(batch);
|
---|
[7e62b62] | 123 | return EOK;
|
---|
[4317827] | 124 | }
|
---|
[3515533] | 125 | /*----------------------------------------------------------------------------*/
|
---|
[eb1a2f4] | 126 | static int control_write(ddf_fun_t *fun, usb_target_t target,
|
---|
[ec59693] | 127 | size_t max_packet_size,
|
---|
[a72620d] | 128 | void *setup_data, size_t setup_size, void *data, size_t size,
|
---|
| 129 | usbhc_iface_transfer_out_callback_t callback, void *arg)
|
---|
| 130 | {
|
---|
[b4875e67] | 131 | dev_speed_t speed = DEFAULT_SPEED;
|
---|
[f241b05b] | 132 |
|
---|
[eb1a2f4] | 133 | batch_t *batch = batch_get(fun, target, USB_TRANSFER_CONTROL,
|
---|
[7dd3318] | 134 | max_packet_size, speed, data, size, setup_data, setup_size,
|
---|
| 135 | NULL, callback, arg);
|
---|
[83c439c] | 136 | if (!batch)
|
---|
[f241b05b] | 137 | return ENOMEM;
|
---|
[83c439c] | 138 | batch_control_write(batch);
|
---|
[f241b05b] | 139 | return EOK;
|
---|
[a72620d] | 140 | }
|
---|
| 141 | /*----------------------------------------------------------------------------*/
|
---|
[eb1a2f4] | 142 | static int control_read(ddf_fun_t *fun, usb_target_t target,
|
---|
[ec59693] | 143 | size_t max_packet_size,
|
---|
[a72620d] | 144 | void *setup_data, size_t setup_size, void *data, size_t size,
|
---|
| 145 | usbhc_iface_transfer_in_callback_t callback, void *arg)
|
---|
| 146 | {
|
---|
[b4875e67] | 147 | dev_speed_t speed = DEFAULT_SPEED;
|
---|
[f241b05b] | 148 |
|
---|
[eb1a2f4] | 149 | batch_t *batch = batch_get(fun, target, USB_TRANSFER_CONTROL,
|
---|
[7dd3318] | 150 | max_packet_size, speed, data, size, setup_data, setup_size, callback,
|
---|
| 151 | NULL, arg);
|
---|
[83c439c] | 152 | if (!batch)
|
---|
[f241b05b] | 153 | return ENOMEM;
|
---|
[83c439c] | 154 | batch_control_read(batch);
|
---|
[f241b05b] | 155 | return EOK;
|
---|
[a72620d] | 156 | }
|
---|
[7dd3318] | 157 |
|
---|
| 158 |
|
---|
[9e80904] | 159 | /*----------------------------------------------------------------------------*/
|
---|
[4317827] | 160 | usbhc_iface_t uhci_iface = {
|
---|
[86b39f7e] | 161 | .reserve_default_address = reserve_default_address,
|
---|
| 162 | .release_default_address = release_default_address,
|
---|
| 163 | .request_address = request_address,
|
---|
| 164 | .bind_address = bind_address,
|
---|
| 165 | .release_address = release_address,
|
---|
[3515533] | 166 |
|
---|
[4317827] | 167 | .interrupt_out = interrupt_out,
|
---|
| 168 | .interrupt_in = interrupt_in,
|
---|
[3515533] | 169 |
|
---|
[a72620d] | 170 | .control_read = control_read,
|
---|
| 171 | .control_write = control_write,
|
---|
[4317827] | 172 | };
|
---|
[c56dbe0] | 173 | /**
|
---|
| 174 | * @}
|
---|
| 175 | */
|
---|