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

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

define default speed in one place

  • Property mode set to 100644
File size: 5.7 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
44#define DEFAULT_SPEED FULL_SPEED
45
46/*----------------------------------------------------------------------------*/
47static int reserve_default_address(ddf_fun_t *fun, usb_speed_t speed)
48{
49 assert(fun);
50 uhci_t *hc = fun_to_uhci(fun);
51 assert(hc);
52 usb_address_keeping_reserve_default(&hc->address_manager);
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_address_keeping_release_default(&hc->address_manager);
62 return EOK;
63}
64/*----------------------------------------------------------------------------*/
65static int request_address(ddf_fun_t *fun, usb_speed_t speed,
66 usb_address_t *address)
67{
68 assert(fun);
69 uhci_t *hc = fun_to_uhci(fun);
70 assert(hc);
71 *address = usb_address_keeping_request(&hc->address_manager);
72 if (*address <= 0)
73 return *address;
74 return EOK;
75}
76/*----------------------------------------------------------------------------*/
77static int bind_address(
78 ddf_fun_t *fun, usb_address_t address, devman_handle_t handle)
79{
80 assert(fun);
81 uhci_t *hc = fun_to_uhci(fun);
82 assert(hc);
83 usb_address_keeping_devman_bind(&hc->address_manager, address, handle);
84 return EOK;
85}
86/*----------------------------------------------------------------------------*/
87static int release_address(ddf_fun_t *fun, usb_address_t address)
88{
89 assert(fun);
90 uhci_t *hc = fun_to_uhci(fun);
91 assert(hc);
92 usb_address_keeping_release_default(&hc->address_manager);
93 return EOK;
94}
95/*----------------------------------------------------------------------------*/
96static int interrupt_out(ddf_fun_t *fun, usb_target_t target,
97 size_t max_packet_size,
98 void *data, size_t size,
99 usbhc_iface_transfer_out_callback_t callback, void *arg)
100{
101 dev_speed_t speed = DEFAULT_SPEED;
102
103 batch_t *batch = batch_get(fun, target, USB_TRANSFER_INTERRUPT,
104 max_packet_size, speed, data, size, NULL, 0, NULL, callback, arg);
105 if (!batch)
106 return ENOMEM;
107 batch_interrupt_out(batch);
108 return EOK;
109}
110/*----------------------------------------------------------------------------*/
111static int interrupt_in(ddf_fun_t *fun, usb_target_t target,
112 size_t max_packet_size,
113 void *data, size_t size,
114 usbhc_iface_transfer_in_callback_t callback, void *arg)
115{
116 dev_speed_t speed = DEFAULT_SPEED;
117
118 batch_t *batch = batch_get(fun, target, USB_TRANSFER_INTERRUPT,
119 max_packet_size, speed, data, size, NULL, 0, callback, NULL, arg);
120 if (!batch)
121 return ENOMEM;
122 batch_interrupt_in(batch);
123 return EOK;
124}
125/*----------------------------------------------------------------------------*/
126static int control_write(ddf_fun_t *fun, usb_target_t target,
127 size_t max_packet_size,
128 void *setup_data, size_t setup_size, void *data, size_t size,
129 usbhc_iface_transfer_out_callback_t callback, void *arg)
130{
131 dev_speed_t speed = DEFAULT_SPEED;
132
133 batch_t *batch = batch_get(fun, target, USB_TRANSFER_CONTROL,
134 max_packet_size, speed, data, size, setup_data, setup_size,
135 NULL, callback, arg);
136 if (!batch)
137 return ENOMEM;
138 batch_control_write(batch);
139 return EOK;
140}
141/*----------------------------------------------------------------------------*/
142static int control_read(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_in_callback_t callback, void *arg)
146{
147 dev_speed_t speed = DEFAULT_SPEED;
148
149 batch_t *batch = batch_get(fun, target, USB_TRANSFER_CONTROL,
150 max_packet_size, speed, data, size, setup_data, setup_size, callback,
151 NULL, arg);
152 if (!batch)
153 return ENOMEM;
154 batch_control_read(batch);
155 return EOK;
156}
157
158
159/*----------------------------------------------------------------------------*/
160usbhc_iface_t uhci_iface = {
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,
166
167 .interrupt_out = interrupt_out,
168 .interrupt_in = interrupt_in,
169
170 .control_read = control_read,
171 .control_write = control_write,
172};
173/**
174 * @}
175 */
Note: See TracBrowser for help on using the repository browser.