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 usb
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 | /** @file
|
---|
33 | * @brief Hub driver.
|
---|
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 <driver.h>
|
---|
45 | #include <usb/usb.h>
|
---|
46 | #include <usb/usbdrv.h>
|
---|
47 | #include <usb/classes/hub.h>
|
---|
48 | #include <usb/devreq.h>
|
---|
49 | #include <usb/debug.h>
|
---|
50 |
|
---|
51 | //************
|
---|
52 | //
|
---|
53 | // convenience define for malloc
|
---|
54 | //
|
---|
55 | //************
|
---|
56 | #define usb_new(type) (type*)malloc(sizeof(type))
|
---|
57 |
|
---|
58 |
|
---|
59 | //************
|
---|
60 | //
|
---|
61 | // convenience debug printf
|
---|
62 | //
|
---|
63 | //************
|
---|
64 | #define dprintf(level, format, ...) \
|
---|
65 | usb_dprintf(NAME, (level), format "\n", ##__VA_ARGS__)
|
---|
66 |
|
---|
67 | /**
|
---|
68 | * @brief create hub structure instance
|
---|
69 | *
|
---|
70 | * Set the address and port count information most importantly.
|
---|
71 | *
|
---|
72 | * @param device
|
---|
73 | * @param hc host controller phone
|
---|
74 | * @return
|
---|
75 | */
|
---|
76 | usb_hub_info_t * usb_create_hub_info(device_t * device, int hc);
|
---|
77 |
|
---|
78 | /** list of hubs maanged by this driver */
|
---|
79 | extern usb_general_list_t usb_hub_list;
|
---|
80 |
|
---|
81 |
|
---|
82 | /**
|
---|
83 | * @brief perform complete control read transaction
|
---|
84 | *
|
---|
85 | * manages all three steps of transaction: setup, read and finalize
|
---|
86 | * @param phone
|
---|
87 | * @param target
|
---|
88 | * @param request request for data
|
---|
89 | * @param rcvd_buffer received data
|
---|
90 | * @param rcvd_size
|
---|
91 | * @param actual_size actual size of received data
|
---|
92 | * @return error code
|
---|
93 | */
|
---|
94 | int usb_drv_sync_control_read(
|
---|
95 | int phone, usb_target_t target,
|
---|
96 | usb_device_request_setup_packet_t * request,
|
---|
97 | void * rcvd_buffer, size_t rcvd_size, size_t * actual_size
|
---|
98 | );
|
---|
99 |
|
---|
100 | /**
|
---|
101 | * @brief perform complete control write transaction
|
---|
102 | *
|
---|
103 | * maanges all three steps of transaction: setup, write and finalize
|
---|
104 | * @param phone
|
---|
105 | * @param target
|
---|
106 | * @param request request to send data
|
---|
107 | * @param sent_buffer
|
---|
108 | * @param sent_size
|
---|
109 | * @return error code
|
---|
110 | */
|
---|
111 | int usb_drv_sync_control_write(
|
---|
112 | int phone, usb_target_t target,
|
---|
113 | usb_device_request_setup_packet_t * request,
|
---|
114 | void * sent_buffer, size_t sent_size
|
---|
115 | );
|
---|
116 |
|
---|
117 |
|
---|
118 | /**
|
---|
119 | * set the device request to be a set address request
|
---|
120 | * @param request
|
---|
121 | * @param addr
|
---|
122 | * \TODO this will be obsolete see usb/dev_req.h
|
---|
123 | */
|
---|
124 | static inline void usb_hub_set_set_address_request(
|
---|
125 | usb_device_request_setup_packet_t * request, uint16_t addr
|
---|
126 | ){
|
---|
127 | request->index = 0;
|
---|
128 | request->request_type = 0;/// \TODO this is not very nice sollution, we ned constant
|
---|
129 | request->request = USB_DEVREQ_SET_ADDRESS;
|
---|
130 | request->value = addr;
|
---|
131 | request->length = 0;
|
---|
132 | }
|
---|
133 |
|
---|
134 | /**
|
---|
135 | * set the device request to be a get hub descriptor request.
|
---|
136 | * @warning the size is allways set to USB_HUB_MAX_DESCRIPTOR_SIZE
|
---|
137 | * @param request
|
---|
138 | * @param addr
|
---|
139 | */
|
---|
140 | static inline void usb_hub_set_descriptor_request(
|
---|
141 | usb_device_request_setup_packet_t * request
|
---|
142 | ){
|
---|
143 | request->index = 0;
|
---|
144 | request->request_type = USB_HUB_REQ_TYPE_GET_DESCRIPTOR;
|
---|
145 | request->request = USB_HUB_REQUEST_GET_DESCRIPTOR;
|
---|
146 | request->value_high = USB_DESCTYPE_HUB;
|
---|
147 | request->value_low = 0;
|
---|
148 | request->length = USB_HUB_MAX_DESCRIPTOR_SIZE;
|
---|
149 | }
|
---|
150 |
|
---|
151 | static inline int usb_hub_clear_port_feature(int hc, usb_address_t address,
|
---|
152 | int port_index,
|
---|
153 | usb_hub_class_feature_t feature) {
|
---|
154 | usb_target_t target = {
|
---|
155 | .address = address,
|
---|
156 | .endpoint = 0
|
---|
157 | };
|
---|
158 | usb_device_request_setup_packet_t clear_request = {
|
---|
159 | .request_type = USB_HUB_REQ_TYPE_CLEAR_PORT_FEATURE,
|
---|
160 | .request = USB_DEVREQ_CLEAR_FEATURE,
|
---|
161 | .length = 0,
|
---|
162 | .index = port_index
|
---|
163 | };
|
---|
164 | clear_request.value = feature;
|
---|
165 | return usb_drv_psync_control_write(hc, target, &clear_request,
|
---|
166 | sizeof(clear_request), NULL, 0);
|
---|
167 | }
|
---|
168 |
|
---|
169 |
|
---|
170 |
|
---|
171 | #endif /* USBHUB_PRIVATE_H */
|
---|
172 |
|
---|
173 | /**
|
---|
174 | * @}
|
---|
175 | */
|
---|