source: mainline/uspace/drv/bus/usb/usbhub/utils.h@ 75eb6735

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

usbhub: Rename usbhub_private.h ⇒ utils.h.

Add error checks, comments, and slight refactoring.

  • Property mode set to 100644
File size: 5.1 KB
Line 
1/*
2 * Copyright (c) 2010 Matus Dekanek
3 * Copyright (c) 2011 Jan Vesely
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30/** @addtogroup drvusbhub
31 * @{
32 */
33/** @file
34 * @brief Hub driver private definitions
35 */
36
37#ifndef USBHUB_UTILS_H
38#define USBHUB_UTILS_H
39
40#include <adt/list.h>
41#include <bool.h>
42#include <ddf/driver.h>
43#include <fibril_synch.h>
44
45#include <usb/classes/hub.h>
46#include <usb/usb.h>
47#include <usb/debug.h>
48#include <usb/dev/request.h>
49
50#include "usbhub.h"
51
52//************
53//
54// convenience define for malloc
55//
56//************
57
58
59usb_hub_info_t * usb_create_hub_info(ddf_dev_t * device);
60
61/**
62 * Set the device request to be a get hub descriptor request.
63 * @warning the size is allways set to USB_HUB_MAX_DESCRIPTOR_SIZE
64 * @param request
65 * @param addr
66 */
67static inline void usb_hub_set_descriptor_request(
68 usb_device_request_setup_packet_t *request )
69{
70 request->index = 0;
71 request->request_type = USB_HUB_REQ_TYPE_GET_DESCRIPTOR;
72 request->request = USB_HUB_REQUEST_GET_DESCRIPTOR;
73 request->value_high = USB_DESCTYPE_HUB;
74 request->value_low = 0;
75 request->length = USB_HUB_MAX_DESCRIPTOR_SIZE;
76}
77
78/**
79 * Clear feature on hub port.
80 *
81 * @param hc Host controller telephone
82 * @param address Hub address
83 * @param port_index Port
84 * @param feature Feature selector
85 * @return Operation result
86 */
87static inline int usb_hub_clear_port_feature(usb_pipe_t *pipe,
88 int port_index, usb_hub_class_feature_t feature)
89{
90
91 usb_device_request_setup_packet_t clear_request = {
92 .request_type = USB_HUB_REQ_TYPE_CLEAR_PORT_FEATURE,
93 .request = USB_DEVREQ_CLEAR_FEATURE,
94 .length = 0,
95 .index = port_index
96 };
97 clear_request.value = feature;
98 return usb_pipe_control_write(pipe, &clear_request,
99 sizeof (clear_request), NULL, 0);
100}
101
102/**
103 * Clear feature on hub port.
104 *
105 * @param hc Host controller telephone
106 * @param address Hub address
107 * @param port_index Port
108 * @param feature Feature selector
109 * @return Operation result
110 */
111static inline int usb_hub_set_port_feature(usb_pipe_t *pipe,
112 int port_index, usb_hub_class_feature_t feature)
113{
114
115 usb_device_request_setup_packet_t clear_request = {
116 .request_type = USB_HUB_REQ_TYPE_SET_PORT_FEATURE,
117 .request = USB_DEVREQ_SET_FEATURE,
118 .length = 0,
119 .index = port_index
120 };
121 clear_request.value = feature;
122 return usb_pipe_control_write(pipe, &clear_request,
123 sizeof (clear_request), NULL, 0);
124}
125
126/**
127 * Clear feature on hub port.
128 *
129 * @param pipe pipe to hub control endpoint
130 * @param feature Feature selector
131 * @return Operation result
132 */
133static inline int usb_hub_clear_feature(usb_pipe_t *pipe,
134 usb_hub_class_feature_t feature) {
135
136 usb_device_request_setup_packet_t clear_request = {
137 .request_type = USB_HUB_REQ_TYPE_CLEAR_HUB_FEATURE,
138 .request = USB_DEVREQ_CLEAR_FEATURE,
139 .length = 0,
140 .index = 0
141 };
142 clear_request.value = feature;
143 return usb_pipe_control_write(pipe, &clear_request,
144 sizeof (clear_request), NULL, 0);
145}
146
147/**
148 * Clear feature on hub port.
149 *
150 * @param pipe pipe to hub control endpoint
151 * @param feature Feature selector
152 * @return Operation result
153 */
154static inline int usb_hub_set_feature(usb_pipe_t *pipe,
155 usb_hub_class_feature_t feature)
156{
157
158 usb_device_request_setup_packet_t clear_request = {
159 .request_type = USB_HUB_REQ_TYPE_CLEAR_HUB_FEATURE,
160 .request = USB_DEVREQ_SET_FEATURE,
161 .length = 0,
162 .index = 0
163 };
164 clear_request.value = feature;
165 return usb_pipe_control_write(pipe, &clear_request,
166 sizeof (clear_request), NULL, 0);
167}
168
169void * usb_create_serialized_hub_descriptor(usb_hub_descriptor_t *descriptor);
170
171void usb_serialize_hub_descriptor(usb_hub_descriptor_t *descriptor,
172 void *serialized_descriptor);
173
174int usb_deserialize_hub_desriptor(
175 void *serialized_descriptor, size_t size, usb_hub_descriptor_t *descriptor);
176
177#endif
178/**
179 * @}
180 */
Note: See TracBrowser for help on using the repository browser.