source: mainline/uspace/drv/uhci-hcd/iface.c@ 86341e2

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 86341e2 was 1ae51ae, checked in by Jan Vesely <jano.vesely@…>, 14 years ago

Refactoring

  • Property mode set to 100644
File size: 6.9 KB
Line 
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#include "utils/device_keeper.h"
44
45/*----------------------------------------------------------------------------*/
46static int reserve_default_address(ddf_fun_t *fun, usb_speed_t speed)
47{
48 assert(fun);
49 uhci_t *hc = fun_to_uhci(fun);
50 assert(hc);
51 usb_log_debug("Default address request with speed %d.\n", speed);
52 device_keeper_reserve_default(&hc->device_manager, speed);
53 return EOK;
54}
55/*----------------------------------------------------------------------------*/
56static int release_default_address(ddf_fun_t *fun)
57{
58 assert(fun);
59 uhci_t *hc = fun_to_uhci(fun);
60 assert(hc);
61 usb_log_debug("Default address release.\n");
62 device_keeper_release_default(&hc->device_manager);
63 return EOK;
64}
65/*----------------------------------------------------------------------------*/
66static int request_address(ddf_fun_t *fun, usb_speed_t speed,
67 usb_address_t *address)
68{
69 assert(fun);
70 uhci_t *hc = fun_to_uhci(fun);
71 assert(hc);
72 assert(address);
73
74 usb_log_debug("Address request with speed %d.\n", speed);
75 *address = device_keeper_request(&hc->device_manager, speed);
76 usb_log_debug("Address request with result: %d.\n", *address);
77 if (*address <= 0)
78 return *address;
79 return EOK;
80}
81/*----------------------------------------------------------------------------*/
82static int bind_address(
83 ddf_fun_t *fun, usb_address_t address, devman_handle_t handle)
84{
85 assert(fun);
86 uhci_t *hc = fun_to_uhci(fun);
87 assert(hc);
88 usb_log_debug("Address bind %d-%d.\n", address, handle);
89 device_keeper_bind(&hc->device_manager, address, handle);
90 return EOK;
91}
92/*----------------------------------------------------------------------------*/
93static int release_address(ddf_fun_t *fun, usb_address_t address)
94{
95 assert(fun);
96 uhci_t *hc = fun_to_uhci(fun);
97 assert(hc);
98 usb_log_debug("Address release %d.\n", address);
99 device_keeper_release(&hc->device_manager, address);
100 return EOK;
101}
102/*----------------------------------------------------------------------------*/
103static int interrupt_out(ddf_fun_t *fun, usb_target_t target,
104 size_t max_packet_size, void *data, size_t size,
105 usbhc_iface_transfer_out_callback_t callback, void *arg)
106{
107 assert(fun);
108 uhci_t *hc = fun_to_uhci(fun);
109 assert(hc);
110 usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address);
111
112 usb_log_debug("Interrupt OUT %d:%d %zu(%zu).\n",
113 target.address, target.endpoint, size, max_packet_size);
114
115 batch_t *batch = batch_get(fun, target, USB_TRANSFER_INTERRUPT,
116 max_packet_size, speed, data, size, NULL, 0, NULL, callback, arg);
117 if (!batch)
118 return ENOMEM;
119 batch_interrupt_out(batch);
120 return EOK;
121}
122/*----------------------------------------------------------------------------*/
123static int interrupt_in(ddf_fun_t *fun, usb_target_t target,
124 size_t max_packet_size, void *data, size_t size,
125 usbhc_iface_transfer_in_callback_t callback, void *arg)
126{
127 assert(fun);
128 uhci_t *hc = fun_to_uhci(fun);
129 assert(hc);
130 usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address);
131 usb_log_debug("Interrupt IN %d:%d %zu(%zu).\n",
132 target.address, target.endpoint, size, max_packet_size);
133
134 batch_t *batch = batch_get(fun, target, USB_TRANSFER_INTERRUPT,
135 max_packet_size, speed, data, size, NULL, 0, callback, NULL, arg);
136 if (!batch)
137 return ENOMEM;
138 batch_interrupt_in(batch);
139 return EOK;
140}
141/*----------------------------------------------------------------------------*/
142static int control_write(ddf_fun_t *fun, usb_target_t target,
143 size_t max_packet_size,
144 void *setup_data, size_t setup_size, void *data, size_t size,
145 usbhc_iface_transfer_out_callback_t callback, void *arg)
146{
147 assert(fun);
148 uhci_t *hc = fun_to_uhci(fun);
149 assert(hc);
150 usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address);
151 usb_log_debug("Control WRITE %d:%d %zu(%zu).\n",
152 target.address, target.endpoint, size, max_packet_size);
153
154 batch_t *batch = batch_get(fun, target, USB_TRANSFER_CONTROL,
155 max_packet_size, speed, data, size, setup_data, setup_size,
156 NULL, callback, arg);
157 if (!batch)
158 return ENOMEM;
159 batch_control_write(batch);
160 return EOK;
161}
162/*----------------------------------------------------------------------------*/
163static int control_read(ddf_fun_t *fun, usb_target_t target,
164 size_t max_packet_size,
165 void *setup_data, size_t setup_size, void *data, size_t size,
166 usbhc_iface_transfer_in_callback_t callback, void *arg)
167{
168 assert(fun);
169 uhci_t *hc = fun_to_uhci(fun);
170 assert(hc);
171 usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address);
172
173 usb_log_debug("Control READ %d:%d %zu(%zu).\n",
174 target.address, target.endpoint, size, max_packet_size);
175 batch_t *batch = batch_get(fun, target, USB_TRANSFER_CONTROL,
176 max_packet_size, speed, data, size, setup_data, setup_size, callback,
177 NULL, arg);
178 if (!batch)
179 return ENOMEM;
180 batch_control_read(batch);
181 return EOK;
182}
183
184
185/*----------------------------------------------------------------------------*/
186usbhc_iface_t uhci_iface = {
187 .reserve_default_address = reserve_default_address,
188 .release_default_address = release_default_address,
189 .request_address = request_address,
190 .bind_address = bind_address,
191 .release_address = release_address,
192
193 .interrupt_out = interrupt_out,
194 .interrupt_in = interrupt_in,
195
196 .control_read = control_read,
197 .control_write = control_write,
198};
199/**
200 * @}
201 */
Note: See TracBrowser for help on using the repository browser.