source: mainline/uspace/drv/usbhub/usbhub_private.h@ 9d06563

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 9d06563 was 040ab02, checked in by Matus Dekanek <smekideki@…>, 14 years ago

usb hub global over-current and power changes

  • Property mode set to 100644
File size: 5.6 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/** @addtogroup drvusbhub
30 * @{
31 */
32/** @file
33 * @brief Hub driver private definitions
34 */
35
36#ifndef USBHUB_PRIVATE_H
37#define USBHUB_PRIVATE_H
38
39#include "usbhub.h"
40#include "usblist.h"
41
42#include <adt/list.h>
43#include <bool.h>
44#include <ddf/driver.h>
45#include <fibril_synch.h>
46
47#include <usb/classes/hub.h>
48#include <usb/usb.h>
49#include <usb/debug.h>
50#include <usb/request.h>
51
52//************
53//
54// convenience define for malloc
55//
56//************
57#define usb_new(type) (type*)malloc(sizeof(type))
58
59
60/**
61 * Create hub structure instance
62 *
63 * Set the address and port count information most importantly.
64 *
65 * @param device
66 * @param hc host controller phone
67 * @return
68 */
69usb_hub_info_t * usb_create_hub_info(ddf_dev_t * device);
70
71/**
72 * Set the device request to be a get hub descriptor request.
73 * @warning the size is allways set to USB_HUB_MAX_DESCRIPTOR_SIZE
74 * @param request
75 * @param addr
76 */
77static inline void usb_hub_set_descriptor_request(
78usb_device_request_setup_packet_t * request
79){
80 request->index = 0;
81 request->request_type = USB_HUB_REQ_TYPE_GET_DESCRIPTOR;
82 request->request = USB_HUB_REQUEST_GET_DESCRIPTOR;
83 request->value_high = USB_DESCTYPE_HUB;
84 request->value_low = 0;
85 request->length = USB_HUB_MAX_DESCRIPTOR_SIZE;
86}
87
88/**
89 * Clear feature on hub port.
90 *
91 * @param hc Host controller telephone
92 * @param address Hub address
93 * @param port_index Port
94 * @param feature Feature selector
95 * @return Operation result
96 */
97static inline int usb_hub_clear_port_feature(usb_pipe_t *pipe,
98 int port_index,
99 usb_hub_class_feature_t feature) {
100
101 usb_device_request_setup_packet_t clear_request = {
102 .request_type = USB_HUB_REQ_TYPE_CLEAR_PORT_FEATURE,
103 .request = USB_DEVREQ_CLEAR_FEATURE,
104 .length = 0,
105 .index = port_index
106 };
107 clear_request.value = feature;
108 return usb_pipe_control_write(pipe, &clear_request,
109 sizeof(clear_request), NULL, 0);
110}
111
112/**
113 * Clear feature on hub port.
114 *
115 * @param hc Host controller telephone
116 * @param address Hub address
117 * @param port_index Port
118 * @param feature Feature selector
119 * @return Operation result
120 */
121static inline int usb_hub_set_port_feature(usb_pipe_t *pipe,
122 int port_index,
123 usb_hub_class_feature_t feature) {
124
125 usb_device_request_setup_packet_t clear_request = {
126 .request_type = USB_HUB_REQ_TYPE_CLEAR_PORT_FEATURE,
127 .request = USB_DEVREQ_SET_FEATURE,
128 .length = 0,
129 .index = port_index
130 };
131 clear_request.value = feature;
132 return usb_pipe_control_write(pipe, &clear_request,
133 sizeof(clear_request), NULL, 0);
134}
135
136
137/**
138 * Clear feature on hub port.
139 *
140 * @param pipe pipe to hub control endpoint
141 * @param feature Feature selector
142 * @return Operation result
143 */
144static inline int usb_hub_clear_feature(usb_pipe_t *pipe,
145 usb_hub_class_feature_t feature) {
146
147 usb_device_request_setup_packet_t clear_request = {
148 .request_type = USB_HUB_REQ_TYPE_CLEAR_HUB_FEATURE,
149 .request = USB_DEVREQ_CLEAR_FEATURE,
150 .length = 0,
151 .index = 0
152 };
153 clear_request.value = feature;
154 return usb_pipe_control_write(pipe, &clear_request,
155 sizeof(clear_request), NULL, 0);
156}
157
158/**
159 * Clear feature on hub port.
160 *
161 * @param pipe pipe to hub control endpoint
162 * @param feature Feature selector
163 * @return Operation result
164 */
165static inline int usb_hub_set_feature(usb_pipe_t *pipe,
166 usb_hub_class_feature_t feature) {
167
168 usb_device_request_setup_packet_t clear_request = {
169 .request_type = USB_HUB_REQ_TYPE_CLEAR_HUB_FEATURE,
170 .request = USB_DEVREQ_SET_FEATURE,
171 .length = 0,
172 .index = 0
173 };
174 clear_request.value = feature;
175 return usb_pipe_control_write(pipe, &clear_request,
176 sizeof(clear_request), NULL, 0);
177}
178
179/**
180 * create uint8_t array with serialized descriptor
181 *
182 * @param descriptor
183 * @return newly created serializd descriptor pointer
184 */
185void * usb_serialize_hub_descriptor(usb_hub_descriptor_t * descriptor);
186
187/**
188 * create deserialized desriptor structure out of serialized descriptor
189 *
190 * The serialized descriptor must be proper usb hub descriptor,
191 * otherwise an eerror might occur.
192 *
193 * @param sdescriptor serialized descriptor
194 * @return newly created deserialized descriptor pointer
195 */
196usb_hub_descriptor_t * usb_deserialize_hub_desriptor(void * sdescriptor);
197
198
199#endif /* USBHUB_PRIVATE_H */
200
201/**
202 * @}
203 */
Note: See TracBrowser for help on using the repository browser.