| 1 | /*
|
|---|
| 2 | * Copyright (c) 2011 Vojtech Horky, Jan Vesely
|
|---|
| 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 usb
|
|---|
| 29 | * @{
|
|---|
| 30 | */
|
|---|
| 31 | /** @file
|
|---|
| 32 | * @brief UHCI driver
|
|---|
| 33 | */
|
|---|
| 34 | #include <ddf/driver.h>
|
|---|
| 35 | #include <remote_usbhc.h>
|
|---|
| 36 |
|
|---|
| 37 | #include <usb/debug.h>
|
|---|
| 38 |
|
|---|
| 39 | #include <errno.h>
|
|---|
| 40 |
|
|---|
| 41 | #include "iface.h"
|
|---|
| 42 | #include "uhci.h"
|
|---|
| 43 |
|
|---|
| 44 | /*----------------------------------------------------------------------------*/
|
|---|
| 45 | static int reserve_default_address(ddf_fun_t *fun, usb_speed_t speed)
|
|---|
| 46 | {
|
|---|
| 47 | assert(fun);
|
|---|
| 48 | uhci_t *hc = fun_to_uhci(fun);
|
|---|
| 49 | assert(hc);
|
|---|
| 50 | usb_address_keeping_reserve_default(&hc->address_manager);
|
|---|
| 51 | return EOK;
|
|---|
| 52 | }
|
|---|
| 53 | /*----------------------------------------------------------------------------*/
|
|---|
| 54 | static int release_default_address(ddf_fun_t *fun)
|
|---|
| 55 | {
|
|---|
| 56 | assert(fun);
|
|---|
| 57 | uhci_t *hc = fun_to_uhci(fun);
|
|---|
| 58 | assert(hc);
|
|---|
| 59 | usb_address_keeping_release_default(&hc->address_manager);
|
|---|
| 60 | return EOK;
|
|---|
| 61 | }
|
|---|
| 62 | /*----------------------------------------------------------------------------*/
|
|---|
| 63 | static int request_address(ddf_fun_t *fun, usb_speed_t speed,
|
|---|
| 64 | usb_address_t *address)
|
|---|
| 65 | {
|
|---|
| 66 | assert(fun);
|
|---|
| 67 | uhci_t *hc = fun_to_uhci(fun);
|
|---|
| 68 | assert(hc);
|
|---|
| 69 | *address = usb_address_keeping_request(&hc->address_manager);
|
|---|
| 70 | if (*address <= 0)
|
|---|
| 71 | return *address;
|
|---|
| 72 | return EOK;
|
|---|
| 73 | }
|
|---|
| 74 | /*----------------------------------------------------------------------------*/
|
|---|
| 75 | static int bind_address(
|
|---|
| 76 | ddf_fun_t *fun, usb_address_t address, devman_handle_t handle)
|
|---|
| 77 | {
|
|---|
| 78 | assert(fun);
|
|---|
| 79 | uhci_t *hc = fun_to_uhci(fun);
|
|---|
| 80 | assert(hc);
|
|---|
| 81 | usb_address_keeping_devman_bind(&hc->address_manager, address, handle);
|
|---|
| 82 | return EOK;
|
|---|
| 83 | }
|
|---|
| 84 | /*----------------------------------------------------------------------------*/
|
|---|
| 85 | static int release_address(ddf_fun_t *fun, usb_address_t address)
|
|---|
| 86 | {
|
|---|
| 87 | assert(fun);
|
|---|
| 88 | uhci_t *hc = fun_to_uhci(fun);
|
|---|
| 89 | assert(hc);
|
|---|
| 90 | usb_address_keeping_release_default(&hc->address_manager);
|
|---|
| 91 | return EOK;
|
|---|
| 92 | }
|
|---|
| 93 | /*----------------------------------------------------------------------------*/
|
|---|
| 94 | static int interrupt_out(ddf_fun_t *fun, usb_target_t target,
|
|---|
| 95 | size_t max_packet_size,
|
|---|
| 96 | void *data, size_t size,
|
|---|
| 97 | usbhc_iface_transfer_out_callback_t callback, void *arg)
|
|---|
| 98 | {
|
|---|
| 99 | dev_speed_t speed = FULL_SPEED;
|
|---|
| 100 |
|
|---|
| 101 | batch_t *batch = batch_get(fun, target, USB_TRANSFER_INTERRUPT,
|
|---|
| 102 | max_packet_size, speed, data, size, NULL, 0, NULL, callback, arg);
|
|---|
| 103 | if (!batch)
|
|---|
| 104 | return ENOMEM;
|
|---|
| 105 | batch_interrupt_out(batch);
|
|---|
| 106 | return EOK;
|
|---|
| 107 | }
|
|---|
| 108 | /*----------------------------------------------------------------------------*/
|
|---|
| 109 | static int interrupt_in(ddf_fun_t *fun, usb_target_t target,
|
|---|
| 110 | size_t max_packet_size,
|
|---|
| 111 | void *data, size_t size,
|
|---|
| 112 | usbhc_iface_transfer_in_callback_t callback, void *arg)
|
|---|
| 113 | {
|
|---|
| 114 | dev_speed_t speed = FULL_SPEED;
|
|---|
| 115 |
|
|---|
| 116 | batch_t *batch = batch_get(fun, target, USB_TRANSFER_INTERRUPT,
|
|---|
| 117 | max_packet_size, speed, data, size, NULL, 0, callback, NULL, arg);
|
|---|
| 118 | if (!batch)
|
|---|
| 119 | return ENOMEM;
|
|---|
| 120 | batch_interrupt_in(batch);
|
|---|
| 121 | return EOK;
|
|---|
| 122 | }
|
|---|
| 123 | /*----------------------------------------------------------------------------*/
|
|---|
| 124 | static int control_write(ddf_fun_t *fun, usb_target_t target,
|
|---|
| 125 | size_t max_packet_size,
|
|---|
| 126 | void *setup_data, size_t setup_size, void *data, size_t size,
|
|---|
| 127 | usbhc_iface_transfer_out_callback_t callback, void *arg)
|
|---|
| 128 | {
|
|---|
| 129 | dev_speed_t speed = FULL_SPEED;
|
|---|
| 130 |
|
|---|
| 131 | batch_t *batch = batch_get(fun, target, USB_TRANSFER_CONTROL,
|
|---|
| 132 | max_packet_size, speed, data, size, setup_data, setup_size,
|
|---|
| 133 | NULL, callback, arg);
|
|---|
| 134 | if (!batch)
|
|---|
| 135 | return ENOMEM;
|
|---|
| 136 | batch_control_write(batch);
|
|---|
| 137 | return EOK;
|
|---|
| 138 | }
|
|---|
| 139 | /*----------------------------------------------------------------------------*/
|
|---|
| 140 | static int control_read(ddf_fun_t *fun, usb_target_t target,
|
|---|
| 141 | size_t max_packet_size,
|
|---|
| 142 | void *setup_data, size_t setup_size, void *data, size_t size,
|
|---|
| 143 | usbhc_iface_transfer_in_callback_t callback, void *arg)
|
|---|
| 144 | {
|
|---|
| 145 | dev_speed_t speed = FULL_SPEED;
|
|---|
| 146 |
|
|---|
| 147 | batch_t *batch = batch_get(fun, target, USB_TRANSFER_CONTROL,
|
|---|
| 148 | max_packet_size, speed, data, size, setup_data, setup_size, callback,
|
|---|
| 149 | NULL, arg);
|
|---|
| 150 | if (!batch)
|
|---|
| 151 | return ENOMEM;
|
|---|
| 152 | batch_control_read(batch);
|
|---|
| 153 | return EOK;
|
|---|
| 154 | }
|
|---|
| 155 |
|
|---|
| 156 |
|
|---|
| 157 | /*----------------------------------------------------------------------------*/
|
|---|
| 158 | usbhc_iface_t uhci_iface = {
|
|---|
| 159 | .reserve_default_address = reserve_default_address,
|
|---|
| 160 | .release_default_address = release_default_address,
|
|---|
| 161 | .request_address = request_address,
|
|---|
| 162 | .bind_address = bind_address,
|
|---|
| 163 | .release_address = release_address,
|
|---|
| 164 |
|
|---|
| 165 | .interrupt_out = interrupt_out,
|
|---|
| 166 | .interrupt_in = interrupt_in,
|
|---|
| 167 |
|
|---|
| 168 | .control_read = control_read,
|
|---|
| 169 | .control_write = control_write,
|
|---|
| 170 | };
|
|---|
| 171 | /**
|
|---|
| 172 | * @}
|
|---|
| 173 | */
|
|---|