Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/ohci/root_hub.c

    r8123695a r66a54cc  
    110110        .poll_interval = 255,
    111111};
    112 
    113 static const uint32_t hub_clear_feature_valid_mask =
    114         (1 << USB_HUB_FEATURE_C_HUB_LOCAL_POWER) +
    115         (1 << USB_HUB_FEATURE_C_HUB_OVER_CURRENT);
    116 
    117 static const uint32_t hub_clear_feature_by_writing_one_mask =
    118         1 << USB_HUB_FEATURE_C_HUB_LOCAL_POWER;
    119 
    120 static const uint32_t hub_set_feature_valid_mask =
    121         (1 << USB_HUB_FEATURE_C_HUB_OVER_CURRENT);
    122 
    123        
    124 static const uint32_t hub_set_feature_direct_mask =
    125         (1 << USB_HUB_FEATURE_C_HUB_OVER_CURRENT);
    126 
    127 static const uint32_t port_set_feature_valid_mask =
    128         (1 << USB_HUB_FEATURE_PORT_ENABLE) +
    129         (1 << USB_HUB_FEATURE_PORT_SUSPEND) +
    130         (1 << USB_HUB_FEATURE_PORT_RESET) +
    131         (1 << USB_HUB_FEATURE_PORT_POWER);
    132 
    133 static const uint32_t port_clear_feature_valid_mask =
    134         (1 << USB_HUB_FEATURE_PORT_CONNECTION) +
    135         (1 << USB_HUB_FEATURE_PORT_SUSPEND) +
    136         (1 << USB_HUB_FEATURE_PORT_OVER_CURRENT) +
    137         (1 << USB_HUB_FEATURE_PORT_POWER) +
    138         (1 << USB_HUB_FEATURE_C_PORT_CONNECTION) +
    139         (1 << USB_HUB_FEATURE_C_PORT_ENABLE) +
    140         (1 << USB_HUB_FEATURE_C_PORT_SUSPEND) +
    141         (1 << USB_HUB_FEATURE_C_PORT_OVER_CURRENT) +
    142         (1 << USB_HUB_FEATURE_C_PORT_RESET);
    143 //note that USB_HUB_FEATURE_PORT_POWER bit is translated into USB_HUB_FEATURE_PORT_LOW_SPEED
    144 
    145 
    146 
    147112
    148113/**
     
    247212        instance->registers = regs;
    248213        instance->device = dev;
    249         instance->port_count = instance->registers->rh_desc_a & 0xff;
    250214        rh_init_descriptors(instance);
    251         /// \TODO set port power mode
    252215
    253216
     
    463426
    464427/**
    465  * process feature-enabling request on hub
     428 * process feature-enabling/disabling request on hub
    466429 *
    467430 * @param instance root hub instance
    468431 * @param feature feature selector
     432 * @param enable enable or disable specified feature
    469433 * @return error code
    470434 */
    471435static int process_hub_feature_set_request(rh_t *instance,
    472                 uint16_t feature){
    473         if(! ((1<<feature) & hub_set_feature_valid_mask))
     436                uint16_t feature, bool enable){
     437        if(feature > USB_HUB_FEATURE_C_HUB_OVER_CURRENT)
    474438                return EINVAL;
    475439        instance->registers->rh_status =
     440                        enable ?
    476441                        (instance->registers->rh_status | (1<<feature))
    477                         & (~ hub_clear_feature_by_writing_one_mask);
    478         return EOK;
    479 }
    480 
    481 /**
    482  * process feature-disabling request on hub
    483  *
    484  * @param instance root hub instance
    485  * @param feature feature selector
    486  * @return error code
    487  */
    488 static int process_hub_feature_clear_request(rh_t *instance,
    489                 uint16_t feature){
    490         if(! ((1<<feature) & hub_clear_feature_valid_mask))
    491                 return EINVAL;
    492         //is the feature cleared directly?
    493         if ((1<<feature) & hub_set_feature_direct_mask){
    494                 instance->registers->rh_status =
    495                         (instance->registers->rh_status & (~(1<<feature)))
    496                         & (~ hub_clear_feature_by_writing_one_mask);
    497         }else{//the feature is cleared by writing '1'
    498                 instance->registers->rh_status =
    499                                 (instance->registers->rh_status
    500                                 & (~ hub_clear_feature_by_writing_one_mask))
    501                                 | (1<<feature);
    502         }
    503         return EOK;
    504 }
    505 
    506 
    507 
    508 /**
    509  * process feature-enabling request on hub
     442                        :
     443                        (instance->registers->rh_status & (~(1<<feature)));
     444        /// \TODO any error?
     445        return EOK;
     446}
     447
     448/**
     449 * process feature-enabling/disabling request on hub
    510450 *
    511451 * @param instance root hub instance
     
    516456 */
    517457static int process_port_feature_set_request(rh_t *instance,
    518                 uint16_t feature, uint16_t port){
    519         if(!((1<<feature) & port_set_feature_valid_mask))
     458                uint16_t feature, uint16_t port, bool enable){
     459        if(feature > USB_HUB_FEATURE_C_PORT_RESET)
    520460                return EINVAL;
    521461        if(port<1 || port>instance->port_count)
    522462                return EINVAL;
    523463        instance->registers->rh_port_status[port - 1] =
     464                        enable ?
    524465                        (instance->registers->rh_port_status[port - 1] | (1<<feature))
    525                         & (~port_clear_feature_valid_mask);
     466                        :
     467                        (instance->registers->rh_port_status[port - 1] & (~(1<<feature)));
    526468        /// \TODO any error?
    527469        return EOK;
    528470}
    529 
    530 /**
    531  * process feature-disabling request on hub
    532  *
    533  * @param instance root hub instance
    534  * @param feature feature selector
    535  * @param port port number, counted from 1
    536  * @param enable enable or disable the specified feature
    537  * @return error code
    538  */
    539 static int process_port_feature_clear_request(rh_t *instance,
    540                 uint16_t feature, uint16_t port){
    541         if(!((1<<feature) & port_clear_feature_valid_mask))
    542                 return EINVAL;
    543         if(port<1 || port>instance->port_count)
    544                 return EINVAL;
    545         if(feature == USB_HUB_FEATURE_PORT_POWER)
    546                 feature = USB_HUB_FEATURE_PORT_LOW_SPEED;
    547         if(feature == USB_HUB_FEATURE_PORT_SUSPEND)
    548                 feature = USB_HUB_FEATURE_PORT_OVER_CURRENT;
    549         instance->registers->rh_port_status[port - 1] =
    550                         (instance->registers->rh_port_status[port - 1]
    551                         & (~port_clear_feature_valid_mask))
    552                         | (1<<feature);
    553         /// \TODO any error?
    554         return EOK;
    555 }
    556 
    557471
    558472/**
     
    636550                        (usb_device_request_setup_packet_t*)request->setup_buffer;
    637551        request->transfered_size = 0;
    638         if(setup_request->request == USB_DEVREQ_CLEAR_FEATURE){
     552        if(setup_request->request == USB_DEVREQ_CLEAR_FEATURE
     553                                || setup_request->request == USB_DEVREQ_SET_FEATURE){
    639554                if(setup_request->request_type == USB_HUB_REQ_TYPE_SET_HUB_FEATURE){
    640555                        usb_log_debug("USB_HUB_REQ_TYPE_SET_HUB_FEATURE\n");
    641                         return process_hub_feature_clear_request(instance,
    642                                         setup_request->value);
     556                        return process_hub_feature_set_request(instance, setup_request->value,
     557                                        setup_request->request == USB_DEVREQ_SET_FEATURE);
    643558                }
    644559                if(setup_request->request_type == USB_HUB_REQ_TYPE_SET_PORT_FEATURE){
    645560                        usb_log_debug("USB_HUB_REQ_TYPE_SET_PORT_FEATURE\n");
    646                         return process_port_feature_clear_request(instance,
    647                                         setup_request->value,
    648                                         setup_request->index);
    649                 }
    650                 usb_log_debug("USB_HUB_REQ_TYPE_INVALID %d\n",
    651                                 setup_request->request_type);
    652                 return EINVAL;
    653         }
    654         if(setup_request->request == USB_DEVREQ_SET_FEATURE){
    655                 if(setup_request->request_type == USB_HUB_REQ_TYPE_SET_HUB_FEATURE){
    656                         usb_log_debug("USB_HUB_REQ_TYPE_SET_HUB_FEATURE\n");
    657                         return process_hub_feature_set_request(instance,
    658                                         setup_request->value);
    659                 }
    660                 if(setup_request->request_type == USB_HUB_REQ_TYPE_SET_PORT_FEATURE){
    661                         usb_log_debug("USB_HUB_REQ_TYPE_SET_PORT_FEATURE\n");
    662                         return process_port_feature_set_request(instance,
    663                                         setup_request->value,
    664                                         setup_request->index);
     561                        return process_port_feature_set_request(instance, setup_request->value,
     562                                        setup_request->index,
     563                                        setup_request->request == USB_DEVREQ_SET_FEATURE);
    665564                }
    666565                usb_log_debug("USB_HUB_REQ_TYPE_INVALID %d\n",setup_request->request_type);
Note: See TracChangeset for help on using the changeset viewer.