Ignore:
File:
1 edited

Legend:

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

    r49ce810 r7d521e24  
    6767    usb_hub_status_t status);
    6868
    69 static int usb_process_hub_local_power_change(usb_hub_info_t * hub_info,
     69static int usb_process_hub_power_change(usb_hub_info_t * hub_info,
    7070    usb_hub_status_t status);
    7171
     
    336336 */
    337337static int usb_hub_start_hub_fibril(usb_hub_info_t * hub_info){
    338         int rc;
     338        /*
     339         * The processing will require opened control pipe and connection
     340         * to the host controller.
     341         * It is waste of resources but let's hope there will be less
     342         * hubs than the phone limit.
     343         * FIXME: with some proper locking over pipes and session
     344         * auto destruction, this could work better.
     345         */
     346        int rc = usb_hc_connection_open(&hub_info->connection);
     347        if (rc != EOK) {
     348                //usb_pipe_end_session(hub_info->control_pipe);
     349                usb_log_error("Failed to open connection to HC: %s.\n",
     350                    str_error(rc));
     351                return rc;
     352        }
    339353
    340354        rc = usb_device_auto_poll(hub_info->usb_device, 0,
     
    372386        int opResult;
    373387        if (usb_hub_is_status(status,USB_HUB_FEATURE_HUB_OVER_CURRENT)){
    374                 //poweroff all ports
    375                 unsigned int port;
    376                 for(port = 1;port <= hub_info->port_count;++port){
    377                         opResult = usb_hub_clear_port_feature(
    378                             hub_info->control_pipe,port,
    379                             USB_HUB_FEATURE_PORT_POWER);
    380                         if (opResult != EOK) {
    381                                 usb_log_warning(
    382                                     "cannot power off port %d;  %d\n",
    383                                     port, opResult);
    384                         }
     388                opResult = usb_hub_clear_feature(hub_info->control_pipe,
     389                    USB_HUB_FEATURE_HUB_LOCAL_POWER);
     390                if (opResult != EOK) {
     391                        usb_log_error("cannot power off hub: %d\n",
     392                            opResult);
    385393                }
    386394        } else {
    387                 //power all ports
    388                 unsigned int port;
    389                 for(port = 1;port <= hub_info->port_count;++port){
    390                         opResult = usb_hub_set_port_feature(
    391                             hub_info->control_pipe,port,
    392                             USB_HUB_FEATURE_PORT_POWER);
    393                         if (opResult != EOK) {
    394                                 usb_log_warning(
    395                                     "cannot power off port %d;  %d\n",
    396                                     port, opResult);
    397                         }
     395                opResult = usb_hub_set_feature(hub_info->control_pipe,
     396                    USB_HUB_FEATURE_HUB_LOCAL_POWER);
     397                if (opResult != EOK) {
     398                        usb_log_error("cannot power on hub: %d\n",
     399                            opResult);
    398400                }
    399401        }
     
    402404
    403405/**
    404  * process hub local power change
    405  *
    406  * This change is ignored.
     406 * process hub power change
     407 *
     408 * If the power has been lost, reestablish it.
     409 * If it was reestablished, re-power all ports.
    407410 * @param hub_info hub instance
    408411 * @param status hub status bitmask
    409412 * @return error code
    410413 */
    411 static int usb_process_hub_local_power_change(usb_hub_info_t * hub_info,
     414static int usb_process_hub_power_change(usb_hub_info_t * hub_info,
    412415    usb_hub_status_t status) {
    413416        int opResult = EOK;
     417        if (!usb_hub_is_status(status,USB_HUB_FEATURE_HUB_LOCAL_POWER)) {
     418                //restart power on hub
     419                opResult = usb_hub_set_feature(hub_info->control_pipe,
     420                    USB_HUB_FEATURE_HUB_LOCAL_POWER);
     421                if (opResult != EOK) {
     422                        usb_log_error("cannot power on hub: %d\n",
     423                            opResult);
     424                }
     425        } else {//power reestablished on hub- restart ports
     426                size_t port;
     427                for (port = 1; port <= hub_info->port_count; ++port) {
     428                        opResult = usb_hub_set_port_feature(
     429                            hub_info->control_pipe,
     430                            port, USB_HUB_FEATURE_PORT_POWER);
     431                        if (opResult != EOK) {
     432                                usb_log_error("Cannot power on port %zu: %s.\n",
     433                                    port, str_error(opResult));
     434                        }
     435                }
     436        }
     437        if(opResult!=EOK){
     438                return opResult;//no feature clearing
     439        }
    414440        opResult = usb_hub_clear_feature(hub_info->control_pipe,
    415441            USB_HUB_FEATURE_C_HUB_LOCAL_POWER);
     
    426452 *
    427453 * The change can be either in the over-current condition or
    428  * local-power change.
     454 * local-power lost condition.
    429455 * @param hub_info hub instance
    430456 */
     
    461487        if (
    462488            usb_hub_is_status(status,16+USB_HUB_FEATURE_C_HUB_LOCAL_POWER)) {
    463                 usb_process_hub_local_power_change(hub_info, status);
     489                usb_process_hub_power_change(hub_info, status);
    464490        }
    465491}
Note: See TracChangeset for help on using the changeset viewer.