source: mainline/uspace/drv/usbhub/port_status.h@ 82122f3

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 82122f3 was 39c3d95d, checked in by Matus Dekanek <smekideki@…>, 15 years ago

a few fixes for usb hub driver

  • Property mode set to 100644
File size: 8.5 KB
Line 
1/*
2 * Copyright (c) 2010 Matus Dekanek
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
29#ifndef PORT_STATUS_H
30#define PORT_STATUS_H
31
32#include <bool.h>
33#include <sys/types.h>
34#include <usb/devreq.h>
35#include "usbhub_private.h"
36
37/**
38 * structure holding port status and changes flags.
39 * should not be accessed directly, use supplied getter/setter methods.
40 *
41 * For more information refer to table 11-15 in
42 * "Universal Serial Bus Specification Revision 1.1"
43 *
44 */
45typedef uint32_t usb_port_status_t;
46
47/**
48 * set values in request to be it a port status request
49 * @param request
50 * @param port
51 */
52static inline void usb_hub_set_port_status_request(
53usb_device_request_setup_packet_t * request, uint16_t port
54){
55 request->index = port;
56 request->request_type = USB_HUB_REQ_TYPE_GET_PORT_STATUS;
57 request->request = USB_HUB_REQUEST_GET_STATUS;
58 request->value = 0;
59 request->length = 4;
60}
61
62
63/**
64 * create request for usb hub port status
65 * @param port
66 * @return
67 */
68static inline usb_device_request_setup_packet_t *
69usb_hub_create_port_status_request(uint16_t port){
70 usb_device_request_setup_packet_t * result =
71 usb_new(usb_device_request_setup_packet_t);
72 usb_hub_set_port_status_request(result,port);
73 return result;
74}
75
76
77/**
78 * set the device request to be a port enable request
79 * @param request
80 * @param port
81 */
82static inline void usb_hub_set_enable_port_request(
83usb_device_request_setup_packet_t * request, uint16_t port
84){
85 request->index = port;
86 request->request_type = USB_HUB_REQ_TYPE_SET_PORT_FEATURE;
87 request->request = USB_HUB_REQUEST_SET_FEATURE;
88 request->value = USB_HUB_FEATURE_C_PORT_ENABLE;
89 request->length = 0;
90}
91
92/**
93 * enable specified port
94 * @param port
95 * @return
96 */
97static inline usb_device_request_setup_packet_t *
98usb_hub_create_enable_port_request(uint16_t port){
99 usb_device_request_setup_packet_t * result =
100 usb_new(usb_device_request_setup_packet_t);
101 usb_hub_set_enable_port_request(result,port);
102 return result;
103}
104
105/**
106 * set the device request to be a port disable request
107 * @param request
108 * @param port
109 */
110static inline void usb_hub_set_disable_port_request(
111usb_device_request_setup_packet_t * request, uint16_t port
112){
113 request->index = port;
114 request->request_type = USB_HUB_REQ_TYPE_SET_PORT_FEATURE;
115 request->request = USB_HUB_REQUEST_SET_FEATURE;
116 request->value = USB_HUB_FEATURE_C_PORT_SUSPEND;
117 request->length = 0;
118}
119
120/**
121 * disable specified port
122 * @param port
123 * @return
124 */
125static inline usb_device_request_setup_packet_t *
126usb_hub_create_disable_port_request(uint16_t port){
127 usb_device_request_setup_packet_t * result =
128 usb_new(usb_device_request_setup_packet_t);
129 usb_hub_set_disable_port_request(result,port);
130 return result;
131}
132
133/**
134 * set the device request to be a port disable request
135 * @param request
136 * @param port
137 */
138static inline void usb_hub_set_reset_port_request(
139usb_device_request_setup_packet_t * request, uint16_t port
140){
141 request->index = port;
142 request->request_type = USB_HUB_REQ_TYPE_SET_PORT_FEATURE;
143 request->request = USB_HUB_REQUEST_SET_FEATURE;
144 request->value = USB_HUB_FEATURE_PORT_RESET;
145 request->length = 0;
146}
147
148/**
149 * disable specified port
150 * @param port
151 * @return
152 */
153static inline usb_device_request_setup_packet_t *
154usb_hub_create_reset_port_request(uint16_t port){
155 usb_device_request_setup_packet_t * result =
156 usb_new(usb_device_request_setup_packet_t);
157 usb_hub_set_reset_port_request(result,port);
158 return result;
159}
160
161/**
162 * set the device request to be a port disable request
163 * @param request
164 * @param port
165 */
166static inline void usb_hub_set_power_port_request(
167usb_device_request_setup_packet_t * request, uint16_t port
168){
169 request->index = port;
170 request->request_type = USB_HUB_REQ_TYPE_SET_PORT_FEATURE;
171 request->request = USB_HUB_REQUEST_SET_FEATURE;
172 request->value = USB_HUB_FEATURE_PORT_POWER;
173 request->length = 0;
174}
175
176/** get i`th bit of port status */
177static inline bool usb_port_get_bit(usb_port_status_t * status, int idx)
178{
179 return (((*status)>>(idx))%2);
180}
181
182/** set i`th bit of port status */
183static inline void usb_port_set_bit(
184 usb_port_status_t * status, int idx, bool value)
185{
186 (*status) = value?
187 ((*status)|(1<<(idx))):
188 ((*status)&(~(1<<(idx))));
189}
190
191//device connnected on port
192static inline bool usb_port_dev_connected(usb_port_status_t * status){
193 return usb_port_get_bit(status,0);
194}
195
196static inline void usb_port_set_dev_connected(usb_port_status_t * status,bool connected){
197 usb_port_set_bit(status,0,connected);
198}
199
200//port enabled
201static inline bool usb_port_enabled(usb_port_status_t * status){
202 return usb_port_get_bit(status,1);
203}
204
205static inline void usb_port_set_enabled(usb_port_status_t * status,bool enabled){
206 usb_port_set_bit(status,1,enabled);
207}
208
209//port suspended
210static inline bool usb_port_suspended(usb_port_status_t * status){
211 return usb_port_get_bit(status,2);
212}
213
214static inline void usb_port_set_suspended(usb_port_status_t * status,bool suspended){
215 usb_port_set_bit(status,2,suspended);
216}
217
218//over currect
219static inline bool usb_port_over_current(usb_port_status_t * status){
220 return usb_port_get_bit(status,3);
221}
222
223static inline void usb_port_set_over_current(usb_port_status_t * status,bool value){
224 usb_port_set_bit(status,3,value);
225}
226
227//port reset
228static inline bool usb_port_reset(usb_port_status_t * status){
229 return usb_port_get_bit(status,4);
230}
231
232static inline void usb_port_set_reset(usb_port_status_t * status,bool value){
233 usb_port_set_bit(status,4,value);
234}
235
236//powered
237static inline bool usb_port_powered(usb_port_status_t * status){
238 return usb_port_get_bit(status,8);
239}
240
241static inline void usb_port_set_powered(usb_port_status_t * status,bool powered){
242 usb_port_set_bit(status,8,powered);
243}
244
245//low speed device attached
246static inline bool usb_port_low_speed(usb_port_status_t * status){
247 return usb_port_get_bit(status,9);
248}
249
250static inline void usb_port_set_low_speed(usb_port_status_t * status,bool low_speed){
251 usb_port_set_bit(status,9,low_speed);
252}
253
254
255//connect change
256static inline bool usb_port_connect_change(usb_port_status_t * status){
257 return usb_port_get_bit(status,16);
258}
259
260static inline void usb_port_set_connect_change(usb_port_status_t * status,bool change){
261 usb_port_set_bit(status,16,change);
262}
263
264//port enable change
265static inline bool usb_port_enabled_change(usb_port_status_t * status){
266 return usb_port_get_bit(status,17);
267}
268
269static inline void usb_port_set_enabled_change(usb_port_status_t * status,bool change){
270 usb_port_set_bit(status,17,change);
271}
272
273//suspend change
274static inline bool usb_port_suspend_change(usb_port_status_t * status){
275 return usb_port_get_bit(status,18);
276}
277
278static inline void usb_port_set_suspend_change(usb_port_status_t * status,bool change){
279 usb_port_set_bit(status,18,change);
280}
281
282//over current change
283static inline bool usb_port_overcurrent_change(usb_port_status_t * status){
284 return usb_port_get_bit(status,19);
285}
286
287static inline void usb_port_set_overcurrent_change(usb_port_status_t * status,bool change){
288 usb_port_set_bit(status,19,change);
289}
290
291//reset change
292static inline bool usb_port_reset_completed(usb_port_status_t * status){
293 return usb_port_get_bit(status,20);
294}
295
296static inline void usb_port_set_reset_completed(usb_port_status_t * status,bool completed){
297 usb_port_set_bit(status,20,completed);
298}
299
300
301
302#endif /* PORT_STATUS_H */
303
Note: See TracBrowser for help on using the repository browser.