Changeset 08f747e in mainline for uspace/lib/usb
- Timestamp:
- 2010-11-26T21:49:30Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8e423a2d, dac43be
- Parents:
- e4dbfda (diff), da55d5b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- uspace/lib/usb
- Files:
-
- 2 edited
-
include/usb/classes/hub.h (modified) (2 diffs)
-
src/hcdhubd.c (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usb/include/usb/classes/hub.h
re4dbfda r08f747e 36 36 #define LIBUSB_HUB_H_ 37 37 38 /** Hub class request. */ 39 typedef enum { 40 USB_HUB_REQUEST_GET_STATUS = 0, 41 USB_HUB_REQUEST_CLEAR_FEATURE = 1, 42 USB_HUB_REQUEST_GET_STATE = 2, 43 USB_HUB_REQUEST_SET_FEATURE = 3, 44 USB_HUB_REQUEST_GET_DESCRIPTOR = 6, 45 USB_HUB_REQUEST_SET_DESCRIPTOR = 7, 46 /* USB_HUB_REQUEST_ = , */ 47 } usb_hub_class_request_t; 38 #include <sys/types.h> 39 #include <usb/hcdhubd.h> 40 48 41 49 42 /** Hub class feature selector. … … 69 62 } usb_hub_class_feature_t; 70 63 64 65 /** 66 * @brief usb hub descriptor 67 * 68 * For more information see Universal Serial Bus Specification Revision 1.1 chapter 11.16.2 69 */ 70 typedef struct hub_descriptor_type{ 71 /** Number of bytes in this descriptor, including this byte */ 72 //uint8_t bDescLength; 73 74 /** Descriptor Type, value: 29H for hub descriptor */ 75 //uint8_t bDescriptorType; 76 77 /** Number of downstream ports that this hub supports */ 78 uint8_t ports_count; 79 80 /** 81 D1...D0: Logical Power Switching Mode 82 00: Ganged power switching (all ports’ power at 83 once) 84 01: Individual port power switching 85 1X: Reserved. Used only on 1.0 compliant hubs 86 that implement no power switching. 87 D2: Identifies a Compound Device 88 0: Hub is not part of a compound device 89 1: Hub is part of a compound device 90 D4...D3: Over-current Protection Mode 91 00: Global Over-current Protection. The hub 92 reports over-current as a summation of all 93 ports’ current draw, without a breakdown of 94 individual port over-current status. 95 01: Individual Port Over-current Protection. The 96 hub reports over-current on a per-port basis. 97 Each port has an over-current indicator. 98 1X: No Over-current Protection. This option is 99 allowed only for bus-powered hubs that do not 100 implement over-current protection. 101 D15...D5: 102 Reserved 103 */ 104 uint16_t hub_characteristics; 105 106 /** 107 Time (in 2ms intervals) from the time the power-on 108 sequence begins on a port until power is good on that 109 port. The USB System Software uses this value to 110 determine how long to wait before accessing a 111 powered-on port. 112 */ 113 uint8_t pwr_on_2_good_time; 114 115 /** 116 Maximum current requirements of the Hub Controller 117 electronics in mA. 118 */ 119 uint8_t current_requirement; 120 121 /** 122 Indicates if a port has a removable device attached. 123 This field is reported on byte-granularity. Within a 124 byte, if no port exists for a given location, the field 125 representing the port characteristics returns 0. 126 Bit value definition: 127 0B - Device is removable 128 1B - Device is non-removable 129 This is a bitmap corresponding to the individual ports 130 on the hub: 131 Bit 0: Reserved for future use 132 Bit 1: Port 1 133 Bit 2: Port 2 134 .... 135 Bit n: Port n (implementation-dependent, up to a 136 maximum of 255 ports). 137 */ 138 uint8_t * devices_removable; 139 140 /** 141 This field exists for reasons of compatibility with 142 software written for 1.0 compliant devices. All bits in 143 this field should be set to 1B. This field has one bit for 144 each port on the hub with additional pad bits, if 145 necessary, to make the number of bits in the field an 146 integer multiple of 8. 147 */ 148 //uint8_t * port_pwr_ctrl_mask; 149 } usb_hub_descriptor_t; 150 151 152 153 /** @brief usb hub specific request types. 154 * 155 * For more information see Universal Serial Bus Specification Revision 1.1 chapter 11.16.2 156 */ 157 typedef enum { 158 /** This request resets a value reported in the hub status. */ 159 USB_HUB_REQ_TYPE_CLEAR_HUB_FEATURE = 0x20, 160 /** This request resets a value reported in the port status. */ 161 USB_HUB_REQ_TYPE_CLEAR_PORT_FEATURE = 0x23, 162 /** This is an optional per-port diagnostic request that returns the bus state value, as sampled at the last EOF2 point. */ 163 USB_HUB_REQ_TYPE_GET_STATE = 0xA3, 164 /** This request returns the hub descriptor. */ 165 USB_HUB_REQ_TYPE_GET_DESCRIPTOR = 0xA0, 166 /** This request returns the current hub status and the states that have changed since the previous acknowledgment. */ 167 USB_HUB_REQ_TYPE_GET_HUB_STATUS = 0xA0, 168 /** This request returns the current port status and the current value of the port status change bits. */ 169 USB_HUB_REQ_TYPE_GET_PORT_STATUS = 0xA3, 170 /** This request overwrites the hub descriptor. */ 171 USB_HUB_REQ_TYPE_SET_DESCRIPTOR = 0x20, 172 /** This request sets a value reported in the hub status. */ 173 USB_HUB_REQ_TYPE_SET_HUB_FEATURE = 0x20, 174 /** This request sets a value reported in the port status. */ 175 USB_HUB_REQ_TYPE_SET_PORT_FEATURE = 0x23 176 } usb_hub_bm_request_type_t; 177 178 /** @brief hub class request codes*/ 179 typedef enum { 180 /** */ 181 USB_HUB_REQUEST_GET_STATUS = 0, 182 /** */ 183 USB_HUB_REQUEST_CLEAR_FEATURE = 1, 184 /** */ 185 USB_HUB_REQUEST_GET_STATE = 2, 186 /** */ 187 USB_HUB_REQUEST_SET_FEATURE = 3, 188 /** */ 189 USB_HUB_REQUEST_GET_DESCRIPTOR = 6, 190 /** */ 191 USB_HUB_REQUEST_SET_DESCRIPTOR = 7 192 } usb_hub_request_t; 193 194 /** 195 * Maximum size of usb hub descriptor in bytes 196 */ 197 extern size_t USB_HUB_MAX_DESCRIPTOR_SIZE; 198 199 /** 200 * @brief create uint8_t array with serialized descriptor 201 * 202 * @param descriptor 203 */ 204 void * usb_serialize_hub_descriptor(usb_hub_descriptor_t * descriptor); 205 206 /** 207 * @brief create deserialized desriptor structure out of serialized descriptor 208 * 209 * The serialized descriptor must be proper usb hub descriptor, otherwise an eerror might occur. 210 * 211 * @param sdescriptor serialized descriptor 212 */ 213 usb_hub_descriptor_t * usb_deserialize_hub_desriptor(void * sdescriptor); 214 215 /** 216 * @brief create hub structure instance 217 * 218 * @param device 219 * @return 220 */ 221 usb_hcd_hub_info_t * usb_create_hub_info(device_t * device); 222 223 224 225 226 71 227 #endif 72 228 /** -
uspace/lib/usb/src/hcdhubd.c
re4dbfda r08f747e 36 36 #include <usb/devreq.h> 37 37 #include <usbhc_iface.h> 38 #include <usb/descriptor.h> 38 39 #include <driver.h> 39 40 #include <bool.h> 40 41 #include <errno.h> 42 #include <usb/classes/hub.h> 41 43 42 44 #define USB_HUB_DEVICE_NAME "usbhub" 45 46 #define USB_KBD_DEVICE_NAME "hid" 47 48 49 43 50 44 51 /** List of handled host controllers. */ … … 57 64 }; 58 65 66 size_t USB_HUB_MAX_DESCRIPTOR_SIZE = 71; 67 68 uint8_t USB_HUB_DESCRIPTOR_TYPE = 0x29; 69 70 //********************************************* 71 // 72 // various utils 73 // 74 //********************************************* 75 76 void * usb_serialize_hub_descriptor(usb_hub_descriptor_t * descriptor) { 77 //base size 78 size_t size = 7; 79 //variable size according to port count 80 size_t var_size = descriptor->ports_count / 8 + ((descriptor->ports_count % 8 > 0) ? 1 : 0); 81 size += 2 * var_size; 82 uint8_t * result = (uint8_t*) malloc(size); 83 //size 84 result[0] = size; 85 //descriptor type 86 result[1] = USB_DESCTYPE_HUB; 87 result[2] = descriptor->ports_count; 88 /// @fixme handling of endianness?? 89 result[3] = descriptor->hub_characteristics / 256; 90 result[4] = descriptor->hub_characteristics % 256; 91 result[5] = descriptor->pwr_on_2_good_time; 92 result[6] = descriptor->current_requirement; 93 94 size_t i; 95 for (i = 0; i < var_size; ++i) { 96 result[7 + i] = descriptor->devices_removable[i]; 97 } 98 for (i = 0; i < var_size; ++i) { 99 result[7 + var_size + i] = 255; 100 } 101 return result; 102 } 103 104 usb_hub_descriptor_t * usb_deserialize_hub_desriptor(void * serialized_descriptor) { 105 uint8_t * sdescriptor = (uint8_t*) serialized_descriptor; 106 if (sdescriptor[1] != USB_DESCTYPE_HUB) return NULL; 107 usb_hub_descriptor_t * result = (usb_hub_descriptor_t*) malloc(sizeof (usb_hub_descriptor_t)); 108 //uint8_t size = sdescriptor[0]; 109 result->ports_count = sdescriptor[2]; 110 /// @fixme handling of endianness?? 111 result->hub_characteristics = sdescriptor[4] + 256 * sdescriptor[3]; 112 result->pwr_on_2_good_time = sdescriptor[5]; 113 result->current_requirement = sdescriptor[6]; 114 size_t var_size = result->ports_count / 8 + ((result->ports_count % 8 > 0) ? 1 : 0); 115 result->devices_removable = (uint8_t*) malloc(var_size); 116 117 size_t i; 118 for (i = 0; i < var_size; ++i) { 119 result->devices_removable[i] = sdescriptor[7 + i]; 120 } 121 return result; 122 } 123 124 125 //********************************************* 126 // 127 // hub driver code 128 // 129 //********************************************* 130 59 131 static void set_hub_address(usb_hc_device_t *hc, usb_address_t address); 60 132 133 usb_hcd_hub_info_t * usb_create_hub_info(device_t * device) { 134 usb_hcd_hub_info_t* result = (usb_hcd_hub_info_t*) malloc(sizeof (usb_hcd_hub_info_t)); 135 //get parent device 136 /// @TODO this code is not correct 137 device_t * my_hcd = device; 138 while (my_hcd->parent) 139 my_hcd = my_hcd->parent; 140 //dev-> 141 printf("%s: owner hcd found: %s\n", hc_driver->name, my_hcd->name); 142 //we add the hub into the first hc 143 //link_t *link_hc = hc_list.next; 144 //usb_hc_device_t *hc = list_get_instance(link_hc, 145 // usb_hc_device_t, link); 146 //must get generic device info 147 148 149 return result; 150 } 151 61 152 /** Callback when new device is detected and must be handled by this driver. 62 153 * 63 154 * @param dev New device. 64 * @return Error code. 65 */ 66 static int add_device(device_t *dev) 67 { 155 * @return Error code.hub added, hurrah!\n" 156 */ 157 static int add_device(device_t *dev) { 68 158 /* 69 159 * FIXME: use some magic to determine whether hub or another HC … … 77 167 * We are the HC itself. 78 168 */ 79 usb_hc_device_t *hc_dev = malloc(sizeof (usb_hc_device_t));169 usb_hc_device_t *hc_dev = malloc(sizeof (usb_hc_device_t)); 80 170 list_initialize(&hc_dev->link); 81 171 hc_dev->transfer_ops = NULL; … … 99 189 list_append(&hc_dev->link, &hc_list); 100 190 191 //add keyboard 192 /// @TODO this is not correct code 193 194 /* 195 * Announce presence of child device. 196 */ 197 device_t *kbd = NULL; 198 match_id_t *match_id = NULL; 199 200 kbd = create_device(); 201 if (kbd == NULL) { 202 printf("ERROR: enomem\n"); 203 } 204 kbd->name = USB_KBD_DEVICE_NAME; 205 206 match_id = create_match_id(); 207 if (match_id == NULL) { 208 printf("ERROR: enomem\n"); 209 } 210 211 char *id; 212 rc = asprintf(&id, USB_KBD_DEVICE_NAME); 213 if (rc <= 0) { 214 printf("ERROR: enomem\n"); 215 return rc; 216 } 217 218 match_id->id = id; 219 match_id->score = 30; 220 221 add_match_id(&kbd->match_ids, match_id); 222 223 rc = child_device_register(kbd, dev); 224 if (rc != EOK) { 225 printf("ERROR: cannot register kbd\n"); 226 return rc; 227 } 228 229 printf("%s: registered root hub\n", dev->name); 101 230 return EOK; 231 232 233 102 234 } else { 103 235 usb_hc_device_t *hc = list_get_instance(hc_list.next, usb_hc_device_t, link); … … 109 241 * connected devices. 110 242 */ 111 112 return ENOTSUP; 243 //insert hub into list 244 //find owner hcd 245 device_t * my_hcd = dev; 246 while (my_hcd->parent) 247 my_hcd = my_hcd->parent; 248 //dev-> 249 printf("%s: owner hcd found: %s\n", hc_driver->name, my_hcd->name); 250 my_hcd = dev; 251 while (my_hcd->parent) 252 my_hcd = my_hcd->parent; 253 //dev-> 254 255 printf("%s: owner hcd found: %s\n", hc_driver->name, my_hcd->name); 256 257 //create the hub structure 258 usb_hcd_hub_info_t * hub_info = usb_create_hub_info(dev); 259 260 261 //append into the list 262 //we add the hub into the first hc 263 list_append(&hub_info->link, &hc->hubs); 264 265 266 267 return EOK; 268 //return ENOTSUP; 113 269 } 114 270 } … … 123 279 * @param address New hub address. 124 280 */ 125 static void set_hub_address(usb_hc_device_t *hc, usb_address_t address) 126 { 281 static void set_hub_address(usb_hc_device_t *hc, usb_address_t address) { 127 282 printf("%s: setting hub address to %d\n", hc->generic->name, address); 128 283 usb_target_t target = {0, 0}; … … 139 294 140 295 rc = usb_hc_async_control_write_setup(hc, target, 141 &setup_packet, sizeof(setup_packet), &handle);296 &setup_packet, sizeof (setup_packet), &handle); 142 297 if (rc != EOK) { 143 298 return; … … 164 319 /** Check changes on all known hubs. 165 320 */ 166 static void check_hub_changes(void) 167 { 321 static void check_hub_changes(void) { 168 322 /* 169 323 * Iterate through all HCs. … … 171 325 link_t *link_hc; 172 326 for (link_hc = hc_list.next; 173 link_hc != &hc_list;174 link_hc = link_hc->next) {327 link_hc != &hc_list; 328 link_hc = link_hc->next) { 175 329 usb_hc_device_t *hc = list_get_instance(link_hc, 176 usb_hc_device_t, link);330 usb_hc_device_t, link); 177 331 /* 178 332 * Iterate through all their hubs. … … 180 334 link_t *link_hub; 181 335 for (link_hub = hc->hubs.next; 182 link_hub != &hc->hubs;183 link_hub = link_hub->next) {336 link_hub != &hc->hubs; 337 link_hub = link_hub->next) { 184 338 usb_hcd_hub_info_t *hub = list_get_instance(link_hub, 185 usb_hcd_hub_info_t, link);339 usb_hcd_hub_info_t, link); 186 340 187 341 /* … … 205 359 */ 206 360 usb_hc_async_interrupt_in(hc, target, 207 change_bitmap, byte_length, &actual_size,208 &handle);361 change_bitmap, byte_length, &actual_size, 362 &handle); 209 363 210 364 usb_hc_async_wait_for(handle); … … 234 388 * @return Error code. 235 389 */ 236 int usb_hcd_main(usb_hc_driver_t *hc) 237 { 390 int usb_hcd_main(usb_hc_driver_t *hc) { 238 391 hc_driver = hc; 239 392 hc_driver_generic.name = hc->name;
Note:
See TracChangeset
for help on using the changeset viewer.
