Changeset 0212751 in mainline for uspace/drv/bus/usb/usbhub/usbhub.c


Ignore:
Timestamp:
2011-09-23T19:06:37Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
aefa0d5
Parents:
4559d89
Message:

usbhub: IMplement some easy TODOs

Convert process_intterrupt to use usb_hub_port_t structure instead of index.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/usbhub/usbhub.c

    r4559d89 r0212751  
    170170        usb_log_debug("hub_port_changes_callback\n");
    171171        usb_hub_info_t *hub = arg;
    172 
    173         /* FIXME: check that we received enough bytes. */
     172        assert(hub);
     173
     174        /* It is an error condition if we didn't receive enough data */
    174175        if (change_bitmap_size == 0) {
    175                 goto leave;
     176                return false;
    176177        }
    177178
     
    187188                const bool change = (change_bitmap[port / 8] >> (port % 8)) & 1;
    188189                if (change) {
    189                         usb_hub_port_process_interrupt(hub, port);
     190                        usb_hub_port_process_interrupt(&hub->ports[port], hub);
    190191                }
    191192        }
    192 leave:
    193         /* FIXME: proper interval. */
    194         // TODO Interval should be handled by USB HC scheduler not here
    195         async_usleep(1000 * 250);
    196 
    197193        return true;
    198194}
     
    256252        hub_info->port_count = descriptor.port_count;
    257253
    258         // TODO Why +1 ?
     254        // TODO: +1 hack is no longer necessary
    259255        hub_info->ports =
    260256            malloc(sizeof(usb_hub_port_t) * (hub_info->port_count + 1));
     
    349345{
    350346        if (status & USB_HUB_STATUS_OVER_CURRENT) {
    351                 /* Over-current detected on one or all ports,
    352                  * switch them all off to prevent damage. */
    353                 //TODO Consider ganged power switching here.
    354                 //TODO Hub should have turned the ports off already,
    355                 //this is redundant.
    356                 size_t port;
    357                 for (port = 1; port <= hub_info->port_count; ++port) {
    358                         const int opResult = usb_hub_port_clear_feature(
    359                             &hub_info->ports[port], USB_HUB_FEATURE_PORT_POWER);
    360                         if (opResult != EOK) {
    361                                 usb_log_warning(
    362                                     "HUB OVER-CURRENT: Cannot power off port"
    363                                     " %d:  %s\n",
    364                                     port, str_error(opResult));
    365                         }
    366                 }
     347                /* Hub should remove power from all ports if it detects OC */
     348                usb_log_warning("Detected hub over-current condition, "
     349                    "all ports should be powered off.");
    367350        } else {
    368351                /* Over-current condition is gone, it is safe to turn the
     
    379362                        }
    380363                }
     364        }
     365        const int opResult = usb_request_clear_feature(
     366            &hub_info->usb_device->ctrl_pipe, USB_REQUEST_TYPE_CLASS,
     367            USB_REQUEST_RECIPIENT_DEVICE,
     368            USB_HUB_FEATURE_C_HUB_LOCAL_POWER, 0);
     369        if (opResult != EOK) {
     370                usb_log_error(
     371                    "Failed to clear hub over-current change flag: %s.\n",
     372                    str_error(opResult));
    381373        }
    382374}
Note: See TracChangeset for help on using the changeset viewer.