Changeset af4e464e in mainline
- Timestamp:
- 2013-02-08T13:05:54Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 711f5fb8
- Parents:
- 4c86c7c
- Location:
- uspace/drv/bus/usb/uhci
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/uhci/uhci_rh.c
r4c86c7c raf4e464e 37 37 UHCI_RH_PORT_COUNT = 2, 38 38 /* 1 byte for hub status bit and 2 port status bits */ 39 UHCI_PORT_BYTES = 1,39 UHCI_PORT_BYTES = (1 + UHCI_RH_PORT_COUNT + 7) / 8, 40 40 }; 41 41 42 42 /** Hub descriptor. */ 43 43 static const struct { 44 /** Common hub descriptor header */ 44 45 usb_hub_descriptor_header_t header; 46 /** Port removable status bits */ 45 47 uint8_t removable[UHCI_PORT_BYTES]; 48 /** Port powered status bits */ 46 49 uint8_t powered[UHCI_PORT_BYTES]; 47 50 } __attribute__((packed)) hub_descriptor = { … … 59 62 }; 60 63 61 62 64 static usbvirt_device_ops_t ops; 63 65 66 /** Initialize uhci rh structure. 67 * @param instance Memory place to initialize. 68 * @param ports Pointer to TWO UHCI RH port registers. 69 * @param name device name, passed to virthub init 70 * @return Error code, EOK on success. 71 */ 64 72 int uhci_rh_init(uhci_rh_t *instance, ioport16_t *ports, const char *name) 65 73 { … … 73 81 } 74 82 83 /** Schedule USB batch for the root hub. 84 * 85 * @param instance UHCI rh instance 86 * @param batch USB communication batch 87 * @return EOK. 88 * 89 * The result of scheduling is always EOK. The result of communication does 90 * not have to be. 91 */ 75 92 int uhci_rh_schedule(uhci_rh_t *instance, usb_transfer_batch_t *batch) 76 93 { … … 90 107 return EOK; 91 108 } 109 110 /** UHCI port register bits */ 92 111 enum { 93 112 STATUS_CONNECTED = (1 << 0), … … 107 126 STATUS_WC_BITS = STATUS_CHANGE_BITS, 108 127 }; 128 109 129 /* HUB ROUTINES IMPLEMENTATION */ 130 110 131 static void uhci_port_reset_enable(ioport16_t *port) 111 132 { … … 146 167 usb_log_debug("%s: rh: " msg, d->name, ##__VA_ARGS__) \ 147 168 169 /** USB HUB port state request handler. 170 * @param device Virtual hub device 171 * @param setup_packet USB setup stage data. 172 * @param[out] data destination data buffer, size must be at least 173 * setup_packet->length bytes 174 * @param[out] act_size Sized of the valid response part of the buffer. 175 * @return Error code. 176 * 177 * Do not confuse with port status. Port state reports data line states, 178 * it is usefull for debuging purposes only. 179 */ 148 180 static int req_get_port_state(usbvirt_device_t *device, 149 181 const usb_device_request_setup_packet_t *setup_packet, … … 170 202 (BIT_VAL(val, bit) << feat) 171 203 204 /** Port status request handler. 205 * @param device Virtual hub device 206 * @param setup_packet USB setup stage data. 207 * @param[out] data destination data buffer, size must be at least 208 * setup_packet->length bytes 209 * @param[out] act_size Sized of the valid response part of the buffer. 210 * @return Error code. 211 * 212 * Converts status reported via ioport to USB format. 213 * @note: reset change status needs to be handled in sw. 214 */ 172 215 static int req_get_port_status(usbvirt_device_t *device, 173 216 const usb_device_request_setup_packet_t *setup_packet, … … 201 244 } 202 245 246 /** Port clear feature request handler. 247 * @param device Virtual hub device 248 * @param setup_packet USB setup stage data. 249 * @param[out] data destination data buffer, size must be at least 250 * setup_packet->length bytes 251 * @param[out] act_size Sized of the valid response part of the buffer. 252 * @return Error code. 253 */ 203 254 static int req_clear_port_feature(usbvirt_device_t *device, 204 255 const usb_device_request_setup_packet_t *setup_packet, … … 213 264 switch (feature) { 214 265 case USB_HUB_FEATURE_PORT_ENABLE: 215 RH_DEBUG(device, port, "Clear port enable (status %" PRIx16 ")\n",216 status);266 RH_DEBUG(device, port, "Clear port enable (status %" 267 PRIx16 ")\n", status); 217 268 pio_write_16(hub->ports[port], val & ~STATUS_ENABLED); 218 269 break; 219 270 case USB_HUB_FEATURE_PORT_SUSPEND: 220 RH_DEBUG(device, port, "Clear port suspend (status %" PRIx16 ")\n",221 status);271 RH_DEBUG(device, port, "Clear port suspend (status %" 272 PRIx16 ")\n", status); 222 273 pio_write_16(hub->ports[port], val & ~STATUS_SUSPEND); 223 274 // TODO we should do resume magic … … 231 282 break; 232 283 case USB_HUB_FEATURE_C_PORT_CONNECTION: 233 RH_DEBUG(device, port, "Clear port conn change (status %" PRIx16234 ")\n", status);284 RH_DEBUG(device, port, "Clear port conn change (status %" 285 PRIx16 ")\n", status); 235 286 pio_write_16(hub->ports[port], val | STATUS_CONNECTED_CHANGED); 236 287 break; 237 288 case USB_HUB_FEATURE_C_PORT_RESET: 238 RH_DEBUG(device, port, "Clear port reset change (status %" PRIx16239 ")\n", status);289 RH_DEBUG(device, port, "Clear port reset change (status %" 290 PRIx16 ")\n", status); 240 291 hub->reset_changed[port] = false; 241 292 break; 242 293 case USB_HUB_FEATURE_C_PORT_ENABLE: 243 RH_DEBUG(device, port, "Clear port enable change (status %" PRIx16244 ")\n", status);294 RH_DEBUG(device, port, "Clear port enable change (status %" 295 PRIx16 ")\n", status); 245 296 pio_write_16(hub->ports[port], status | STATUS_ENABLED_CHANGED); 246 297 break; 247 298 case USB_HUB_FEATURE_C_PORT_SUSPEND: 248 RH_DEBUG(device, port, "Clear port suspend change (status %" PRIx16249 ")\n", status);299 RH_DEBUG(device, port, "Clear port suspend change (status %" 300 PRIx16 ")\n", status); 250 301 //TODO 251 302 return ENOTSUP; 252 303 case USB_HUB_FEATURE_C_PORT_OVER_CURRENT: 253 RH_DEBUG(device, port, "Clear port OC change (status %" PRIx16254 ")\n", status);304 RH_DEBUG(device, port, "Clear port OC change (status %" 305 PRIx16 ")\n", status); 255 306 /* UHCI Does not report over current */ 307 //TODO: newer chips do, but some have broken wiring 256 308 break; 257 309 default: 258 RH_DEBUG(device, port, "Clear unknown feature %d (status %" PRIx16259 ")\n", feature, status);310 RH_DEBUG(device, port, "Clear unknown feature %d (status %" 311 PRIx16 ")\n", feature, status); 260 312 usb_log_warning("Clearing feature %d is unsupported\n", 261 313 feature); … … 265 317 } 266 318 319 /** Port set feature request handler. 320 * @param device Virtual hub device 321 * @param setup_packet USB setup stage data. 322 * @param[out] data destination data buffer, size must be at least 323 * setup_packet->length bytes 324 * @param[out] act_size Sized of the valid response part of the buffer. 325 * @return Error code. 326 */ 267 327 static int req_set_port_feature(usbvirt_device_t *device, 268 328 const usb_device_request_setup_packet_t *setup_packet, … … 295 355 /* We are always powered */ 296 356 usb_log_warning("Tried to power port %u\n", port); 357 break; 297 358 case USB_HUB_FEATURE_C_PORT_CONNECTION: 298 359 case USB_HUB_FEATURE_C_PORT_ENABLE: … … 314 375 } 315 376 377 /** UHCI root hub request handlers */ 316 378 static usbvirt_control_request_handler_t control_transfer_handlers[] = { 317 379 { … … 344 406 .name = "ClearHubFeature", 345 407 /* Hub features are overcurrent and supply good, 346 * this request may only setchanges that we never report*/408 * this request may only clear changes that we never report*/ 347 409 .callback = req_nop, 348 410 }, … … 390 452 }; 391 453 454 /** Status change handler. 455 * @param device Virtual hub device 456 * @param endpoint Enpoint number 457 * @param tr_type Transfer type 458 * @param buffer Response destination 459 * @param buffer_size BYtes available in buffer 460 * @param actual_size Size us the used part of the dest buffer. 461 * 462 * Produces status mask. Bit 0 indicates hub status change the other bits 463 * represnet port status change. Endian does not matter as UHCI root hubs 464 * only need 1 byte. 465 */ 392 466 static int req_status_change_handler(usbvirt_device_t *device, 393 467 usb_endpoint_t endpoint, usb_transfer_type_t tr_type, 394 468 void *buffer, size_t buffer_size, size_t *actual_size) 395 469 { 470 uhci_rh_t *hub = virthub_get_data(device); 471 assert(hub); 472 396 473 if (buffer_size < 1) 397 474 return ESTALL; 398 uhci_rh_t *hub = virthub_get_data(device);399 assert(hub);400 475 401 476 const uint16_t status_a = pio_read_16(hub->ports[0]); -
uspace/drv/bus/usb/uhci/uhci_rh.h
r4c86c7c raf4e464e 33 33 * @brief UHCI host controller driver structure 34 34 */ 35 #ifndef DRV_UHCI_ RHVIRT_H36 #define DRV_UHCI_ RHVIRT_H35 #ifndef DRV_UHCI_UHCI_RH_H 36 #define DRV_UHCI_UHCI_RH_H 37 37 38 38 #include <usbvirt/virthub_base.h> … … 42 42 #define HUB_STATUS_CHANGE_PIPE 1 43 43 44 44 /** Virtual to UHCI hub connector */ 45 45 typedef struct { 46 /** Virtual hub software implementation */ 46 47 virthub_base_t base; 48 /** UHCI root hub port io registers */ 47 49 ioport16_t *ports[2]; 50 /** Reset change indicator, it is not reported by regs */ 48 51 bool reset_changed[2]; 49 52 } uhci_rh_t; … … 51 54 int uhci_rh_init(uhci_rh_t *instance, ioport16_t *ports, const char *name); 52 55 int uhci_rh_schedule(uhci_rh_t *instance, usb_transfer_batch_t *batch); 56 57 /** Get UHCI rh address. 58 * 59 * @param instance UHCI rh instance. 60 * @return USB address assigned to the hub. 61 * Wrapper for virtual hub address 62 */ 53 63 static inline usb_address_t uhci_rh_get_address(uhci_rh_t *instance) 54 64 {
Note:
See TracChangeset
for help on using the changeset viewer.