source: mainline/uspace/drv/uhci-hcd/iface.c@ 98807e16

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

Use toggle tracking

  • Property mode set to 100644
File size: 8.3 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, &hc->device_manager);
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, &hc->device_manager);
139 return EOK;
140}
141/*----------------------------------------------------------------------------*/
142static int bulk_out(ddf_fun_t *fun, usb_target_t target,
143 size_t max_packet_size, void *data, size_t size,
144 usbhc_iface_transfer_out_callback_t callback, void *arg)
145{
146 assert(fun);
147 uhci_t *hc = fun_to_uhci(fun);
148 assert(hc);
149 usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address);
150
151 usb_log_debug("Bulk OUT %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_BULK,
155 max_packet_size, speed, data, size, NULL, 0, NULL, callback, arg);
156 if (!batch)
157 return ENOMEM;
158 batch_bulk_out(batch, &hc->device_manager);
159 return EOK;
160}
161/*----------------------------------------------------------------------------*/
162static int bulk_in(ddf_fun_t *fun, usb_target_t target,
163 size_t max_packet_size, void *data, size_t size,
164 usbhc_iface_transfer_in_callback_t callback, void *arg)
165{
166 assert(fun);
167 uhci_t *hc = fun_to_uhci(fun);
168 assert(hc);
169 usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address);
170 usb_log_debug("Bulk IN %d:%d %zu(%zu).\n",
171 target.address, target.endpoint, size, max_packet_size);
172
173 batch_t *batch = batch_get(fun, target, USB_TRANSFER_BULK,
174 max_packet_size, speed, data, size, NULL, 0, callback, NULL, arg);
175 if (!batch)
176 return ENOMEM;
177 batch_bulk_in(batch, &hc->device_manager);
178 return EOK;
179}
180/*----------------------------------------------------------------------------*/
181static int control_write(ddf_fun_t *fun, usb_target_t target,
182 size_t max_packet_size,
183 void *setup_data, size_t setup_size, void *data, size_t size,
184 usbhc_iface_transfer_out_callback_t callback, void *arg)
185{
186 assert(fun);
187 uhci_t *hc = fun_to_uhci(fun);
188 assert(hc);
189 usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address);
190 usb_log_debug("Control WRITE %d:%d %zu(%zu).\n",
191 target.address, target.endpoint, size, max_packet_size);
192
193 batch_t *batch = batch_get(fun, target, USB_TRANSFER_CONTROL,
194 max_packet_size, speed, data, size, setup_data, setup_size,
195 NULL, callback, arg);
196 if (!batch)
197 return ENOMEM;
198 batch_control_write(batch);
199 return EOK;
200}
201/*----------------------------------------------------------------------------*/
202static int control_read(ddf_fun_t *fun, usb_target_t target,
203 size_t max_packet_size,
204 void *setup_data, size_t setup_size, void *data, size_t size,
205 usbhc_iface_transfer_in_callback_t callback, void *arg)
206{
207 assert(fun);
208 uhci_t *hc = fun_to_uhci(fun);
209 assert(hc);
210 usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address);
211
212 usb_log_debug("Control READ %d:%d %zu(%zu).\n",
213 target.address, target.endpoint, size, max_packet_size);
214 batch_t *batch = batch_get(fun, target, USB_TRANSFER_CONTROL,
215 max_packet_size, speed, data, size, setup_data, setup_size, callback,
216 NULL, arg);
217 if (!batch)
218 return ENOMEM;
219 batch_control_read(batch);
220 return EOK;
221}
222/*----------------------------------------------------------------------------*/
223usbhc_iface_t uhci_iface = {
224 .reserve_default_address = reserve_default_address,
225 .release_default_address = release_default_address,
226 .request_address = request_address,
227 .bind_address = bind_address,
228 .release_address = release_address,
229
230 .interrupt_out = interrupt_out,
231 .interrupt_in = interrupt_in,
232
233 .bulk_in = bulk_in,
234 .bulk_out = bulk_out,
235
236 .control_read = control_read,
237 .control_write = control_write,
238};
239/**
240 * @}
241 */
Note: See TracBrowser for help on using the repository browser.