Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 816335c in mainline for uspace/drv/bus/usb/xhci/rh.c


Ignore:
Timestamp:
2017-10-04T10:06:10Z (4 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master
Children:
c68c713c
Parents:
5c5c9407
Message:

xhci: port speed detected properly

The correct way to determine protocol supported on a port is to look at the Port Speed value in the port register, and use it as an index to the speeds defined in extended capabilities. Now we support non-contiguous ranges of ports, USB 3.1, and the detection would work even for non-USB protocols.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/xhci/rh.c

    r5c5c9407 r816335c  
    5151static usbvirt_device_ops_t ops;
    5252
    53 int xhci_rh_init(xhci_rh_t *rh, xhci_op_regs_t *op_regs)
     53int xhci_rh_init(xhci_rh_t *rh, xhci_hc_t *hc)
    5454{
    5555        assert(rh);
    56         rh->op_regs = op_regs;
     56        assert(hc);
     57
     58        rh->hc = hc;
    5759
    5860        usb_hub_descriptor_header_t *header = &rh->hub_descriptor.header;
     
    172174{
    173175        uint8_t link_state = XHCI_REG_RD(regs, XHCI_PORT_PLS);
    174         // FIXME: do we have a better way to detect if this is usb2 or usb3 device?
    175         if (xhci_is_usb3_port(&hc->rh, port_id)) {
     176        const xhci_port_speed_t *speed = xhci_get_port_speed(&hc->rh, port_id);
     177
     178        usb_log_info("Detected new %.4s%u.%u device on port %u.", speed->name, speed->major, speed->minor, port_id);
     179
     180        if (speed->major == 3) {
    176181                if(link_state == 0) {
    177182                        /* USB3 is automatically advanced to enabled. */
    178                         uint8_t port_speed = XHCI_REG_RD(regs, XHCI_PORT_PS);
    179                         usb_log_debug("Detected new device on port %u, port speed id %u.", port_id, port_speed);
    180 
    181183                        return alloc_dev(hc, port_id, 0);
    182184                }
     
    237239
    238240        return EOK;
     241}
     242
     243const xhci_port_speed_t *xhci_get_port_speed(xhci_rh_t *rh, uint8_t port)
     244{
     245        xhci_port_regs_t *port_regs = &rh->hc->op_regs->portrs[port - 1];
     246
     247        unsigned psiv = XHCI_REG_RD(port_regs, XHCI_PORT_PS);
     248        return &rh->speeds[psiv];
    239249}
    240250
     
    343353
    344354        /* The index is 1-based. */
    345         xhci_port_regs_t* regs = &hub->op_regs->portrs[setup_packet->index - 1];
     355        xhci_port_regs_t* regs = &hub->hc->op_regs->portrs[setup_packet->index - 1];
    346356
    347357        const uint32_t status = uint32_host2usb(
Note: See TracChangeset for help on using the changeset viewer.