[b5ec347] | 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 |
|
---|
[281ebae] | 29 | /** @addtogroup drvusbhub
|
---|
[b5ec347] | 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
[f40a1e2] | 33 | * @brief Hub driver private definitions
|
---|
[b5ec347] | 34 | */
|
---|
| 35 |
|
---|
| 36 | #ifndef USBHUB_PRIVATE_H
|
---|
| 37 | #define USBHUB_PRIVATE_H
|
---|
| 38 |
|
---|
| 39 | #include "usbhub.h"
|
---|
[e080332] | 40 | #include "usblist.h"
|
---|
| 41 |
|
---|
[b5ec347] | 42 | #include <adt/list.h>
|
---|
| 43 | #include <bool.h>
|
---|
[eb1a2f4] | 44 | #include <ddf/driver.h>
|
---|
[ba5ab09] | 45 | #include <fibril_synch.h>
|
---|
[5097bed4] | 46 |
|
---|
[6bb83c7] | 47 | #include <usb/classes/hub.h>
|
---|
[b5ec347] | 48 | #include <usb/usb.h>
|
---|
[e080332] | 49 | #include <usb/debug.h>
|
---|
[0f21c0c] | 50 | #include <usb/request.h>
|
---|
[b5ec347] | 51 |
|
---|
| 52 | //************
|
---|
| 53 | //
|
---|
| 54 | // convenience define for malloc
|
---|
| 55 | //
|
---|
| 56 | //************
|
---|
| 57 | #define usb_new(type) (type*)malloc(sizeof(type))
|
---|
| 58 |
|
---|
| 59 |
|
---|
| 60 | //************
|
---|
| 61 | //
|
---|
[103a3626] | 62 | // convenience debug printf for usb hub
|
---|
[b5ec347] | 63 | //
|
---|
| 64 | //************
|
---|
[e080332] | 65 | #define dprintf(level, format, ...) \
|
---|
[6f8f808] | 66 | usb_log_printf((level), format "\n", ##__VA_ARGS__)
|
---|
[b5ec347] | 67 |
|
---|
[103a3626] | 68 |
|
---|
[b5ec347] | 69 | /**
|
---|
[f40a1e2] | 70 | * Create hub structure instance
|
---|
[b5ec347] | 71 | *
|
---|
[98d06b8] | 72 | * Set the address and port count information most importantly.
|
---|
| 73 | *
|
---|
[b5ec347] | 74 | * @param device
|
---|
[98d06b8] | 75 | * @param hc host controller phone
|
---|
[b5ec347] | 76 | * @return
|
---|
| 77 | */
|
---|
[eb1a2f4] | 78 | usb_hub_info_t * usb_create_hub_info(ddf_dev_t * device);
|
---|
[b5ec347] | 79 |
|
---|
[f40a1e2] | 80 | /** List of hubs maanged by this driver */
|
---|
[b5ec347] | 81 | extern usb_general_list_t usb_hub_list;
|
---|
| 82 |
|
---|
[f40a1e2] | 83 | /** Lock for hub list*/
|
---|
[ba5ab09] | 84 | extern fibril_mutex_t usb_hub_list_lock;
|
---|
[5097bed4] | 85 |
|
---|
[b5ec347] | 86 |
|
---|
| 87 | /**
|
---|
[f40a1e2] | 88 | * Perform complete control read transaction
|
---|
[b5ec347] | 89 | *
|
---|
[f40a1e2] | 90 | * Manages all three steps of transaction: setup, read and finalize
|
---|
[b5ec347] | 91 | * @param phone
|
---|
| 92 | * @param target
|
---|
[f40a1e2] | 93 | * @param request Request packet
|
---|
| 94 | * @param rcvd_buffer Received data
|
---|
[b5ec347] | 95 | * @param rcvd_size
|
---|
[f40a1e2] | 96 | * @param actual_size Actual size of received data
|
---|
[b5ec347] | 97 | * @return error code
|
---|
| 98 | */
|
---|
[d81ef61c] | 99 | /*
|
---|
[b5ec347] | 100 | int usb_drv_sync_control_read(
|
---|
[d81ef61c] | 101 | usb_endpoint_pipe_t *pipe,
|
---|
[b5ec347] | 102 | usb_device_request_setup_packet_t * request,
|
---|
| 103 | void * rcvd_buffer, size_t rcvd_size, size_t * actual_size
|
---|
[d81ef61c] | 104 | );*/
|
---|
[b5ec347] | 105 |
|
---|
| 106 | /**
|
---|
[f40a1e2] | 107 | * Perform complete control write transaction
|
---|
[b5ec347] | 108 | *
|
---|
[f40a1e2] | 109 | * Manages all three steps of transaction: setup, write and finalize
|
---|
[b5ec347] | 110 | * @param phone
|
---|
| 111 | * @param target
|
---|
[f40a1e2] | 112 | * @param request Request packet to send data
|
---|
[b5ec347] | 113 | * @param sent_buffer
|
---|
| 114 | * @param sent_size
|
---|
| 115 | * @return error code
|
---|
| 116 | */
|
---|
[d81ef61c] | 117 | /*int usb_drv_sync_control_write(
|
---|
| 118 | usb_endpoint_pipe_t *pipe,
|
---|
[b5ec347] | 119 | usb_device_request_setup_packet_t * request,
|
---|
| 120 | void * sent_buffer, size_t sent_size
|
---|
[d81ef61c] | 121 | );*/
|
---|
[b5ec347] | 122 |
|
---|
[98d06b8] | 123 | /**
|
---|
[f40a1e2] | 124 | * Set the device request to be a get hub descriptor request.
|
---|
[98d06b8] | 125 | * @warning the size is allways set to USB_HUB_MAX_DESCRIPTOR_SIZE
|
---|
| 126 | * @param request
|
---|
| 127 | * @param addr
|
---|
| 128 | */
|
---|
[10096231] | 129 | static inline void usb_hub_set_descriptor_request(
|
---|
[98d06b8] | 130 | usb_device_request_setup_packet_t * request
|
---|
| 131 | ){
|
---|
| 132 | request->index = 0;
|
---|
| 133 | request->request_type = USB_HUB_REQ_TYPE_GET_DESCRIPTOR;
|
---|
| 134 | request->request = USB_HUB_REQUEST_GET_DESCRIPTOR;
|
---|
[10096231] | 135 | request->value_high = USB_DESCTYPE_HUB;
|
---|
| 136 | request->value_low = 0;
|
---|
[98d06b8] | 137 | request->length = USB_HUB_MAX_DESCRIPTOR_SIZE;
|
---|
| 138 | }
|
---|
| 139 |
|
---|
[f40a1e2] | 140 | /**
|
---|
| 141 | * Clear feature on hub port.
|
---|
| 142 | *
|
---|
| 143 | * @param hc Host controller telephone
|
---|
| 144 | * @param address Hub address
|
---|
| 145 | * @param port_index Port
|
---|
| 146 | * @param feature Feature selector
|
---|
| 147 | * @return Operation result
|
---|
| 148 | */
|
---|
[d81ef61c] | 149 | static inline int usb_hub_clear_port_feature(usb_endpoint_pipe_t *pipe,
|
---|
[f9a0cef] | 150 | int port_index,
|
---|
| 151 | usb_hub_class_feature_t feature) {
|
---|
[d81ef61c] | 152 |
|
---|
[f9a0cef] | 153 | usb_device_request_setup_packet_t clear_request = {
|
---|
| 154 | .request_type = USB_HUB_REQ_TYPE_CLEAR_PORT_FEATURE,
|
---|
| 155 | .request = USB_DEVREQ_CLEAR_FEATURE,
|
---|
| 156 | .length = 0,
|
---|
| 157 | .index = port_index
|
---|
| 158 | };
|
---|
| 159 | clear_request.value = feature;
|
---|
[d81ef61c] | 160 | return usb_endpoint_pipe_control_write(pipe, &clear_request,
|
---|
[f9a0cef] | 161 | sizeof(clear_request), NULL, 0);
|
---|
| 162 | }
|
---|
| 163 |
|
---|
[d493ac17] | 164 | /**
|
---|
| 165 | * @brief create uint8_t array with serialized descriptor
|
---|
| 166 | *
|
---|
| 167 | * @param descriptor
|
---|
| 168 | * @return newly created serializd descriptor pointer
|
---|
| 169 | */
|
---|
| 170 | void * usb_serialize_hub_descriptor(usb_hub_descriptor_t * descriptor);
|
---|
| 171 |
|
---|
| 172 | /**
|
---|
| 173 | * @brief create deserialized desriptor structure out of serialized descriptor
|
---|
| 174 | *
|
---|
| 175 | * The serialized descriptor must be proper usb hub descriptor,
|
---|
| 176 | * otherwise an eerror might occur.
|
---|
| 177 | *
|
---|
| 178 | * @param sdescriptor serialized descriptor
|
---|
| 179 | * @return newly created deserialized descriptor pointer
|
---|
| 180 | */
|
---|
| 181 | usb_hub_descriptor_t * usb_deserialize_hub_desriptor(void * sdescriptor);
|
---|
[98d06b8] | 182 |
|
---|
[b5ec347] | 183 |
|
---|
| 184 | #endif /* USBHUB_PRIVATE_H */
|
---|
| 185 |
|
---|
| 186 | /**
|
---|
| 187 | * @}
|
---|
| 188 | */
|
---|