Changeset aff1880 in mainline


Ignore:
Timestamp:
2011-09-23T12:59:35Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6c5abf9
Parents:
48a31be
Message:

usbhub: Move feature set/clear to ports.h, refactor reset sequence.

Location:
uspace/drv/bus/usb/usbhub
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/usbhub/port_status.h

    r48a31be raff1880  
    3131 */
    3232
    33 #ifndef HUB_PORT_STATUS_H
    34 #define HUB_PORT_STATUS_H
     33#ifndef HUB_STATUS_H
     34#define HUB_STATUS_H
    3535
    3636#include <bool.h>
     
    8989    (1 << (16 + USB_HUB_FEATURE_C_HUB_LOCAL_POWER))
    9090
    91 /**
    92  * set the device request to be a port feature enable request
    93  * @param request
    94  * @param port
    95  * @param feature_selector
    96  */
    97 static inline void usb_hub_set_enable_port_feature_request(
    98     usb_device_request_setup_packet_t *request, uint16_t port,
    99     uint16_t feature_selector) {
    100         request->index = port;
    101         request->request_type = USB_HUB_REQ_TYPE_SET_PORT_FEATURE;
    102         request->request = USB_HUB_REQUEST_SET_FEATURE;
    103         request->value = feature_selector;
    104         request->length = 0;
    105 }
    106 
    107 /**
    108  * set the device request to be a port feature clear request
    109  * @param request
    110  * @param port
    111  * @param feature_selector
    112  */
    113 static inline void usb_hub_set_disable_port_feature_request(
    114     usb_device_request_setup_packet_t *request, uint16_t port,
    115     uint16_t feature_selector
    116     ) {
    117         request->index = port;
    118         request->request_type = USB_HUB_REQ_TYPE_SET_PORT_FEATURE;
    119         request->request = USB_HUB_REQUEST_CLEAR_FEATURE;
    120         request->value = feature_selector;
    121         request->length = 0;
    122 }
    123 
    124 /**
    125  * set the device request to be a port disable request
    126  * @param request
    127  * @param port
    128  */
    129 static inline void usb_hub_set_reset_port_request(
    130     usb_device_request_setup_packet_t *request, uint16_t port
    131     ) {
    132         request->index = port;
    133         request->request_type = USB_HUB_REQ_TYPE_SET_PORT_FEATURE;
    134         request->request = USB_HUB_REQUEST_SET_FEATURE;
    135         request->value = USB_HUB_FEATURE_PORT_RESET;
    136         request->length = 0;
    137 }
    138 
    139 /**
    140  * get i`th bit of port status
    141  *
    142  * @param status
    143  * @param idx
    144  * @return
    145  */
    146 static inline bool usb_port_is_status(usb_port_status_t status, int idx) {
    147         return (status & (1 << idx)) != 0;
    148 }
    14991
    15092/**
     
    15496 * @return speed of usb device (for more see usb specification)
    15597 */
    156 static inline usb_speed_t usb_port_speed(usb_port_status_t status) {
     98static inline usb_speed_t usb_port_speed(usb_port_status_t status)
     99{
    157100        if ((status & USB_HUB_PORT_STATUS_LOW_SPEED) != 0)
    158101                return USB_SPEED_LOW;
     
    162105}
    163106
    164 
    165 
    166 #endif  /* HUB_PORT_STATUS_H */
     107#endif  /* HUB_STATUS_H */
    167108/**
    168109 * @}
  • uspace/drv/bus/usb/usbhub/ports.c

    r48a31be raff1880  
    5555
    5656static void usb_hub_removed_device(usb_hub_info_t *hub, size_t port);
    57 static void usb_hub_port_reset_completed(usb_hub_info_t *hub,
    58     uint16_t port, uint32_t status);
     57static void usb_hub_port_reset_completed(const usb_hub_info_t *hub,
     58    size_t port, usb_port_status_t status);
    5959static int get_port_status(usb_pipe_t *ctrl_pipe, size_t port,
    6060    usb_port_status_t *status);
     
    6363static int create_add_device_fibril(usb_hub_info_t *hub, size_t port,
    6464    usb_speed_t speed);
     65
     66/**
     67 * Clear feature on hub port.
     68 *
     69 * @param hc Host controller telephone
     70 * @param address Hub address
     71 * @param port_index Port
     72 * @param feature Feature selector
     73 * @return Operation result
     74 */
     75int usb_hub_clear_port_feature(usb_pipe_t *pipe,
     76    int port_index, usb_hub_class_feature_t feature)
     77{
     78        usb_device_request_setup_packet_t clear_request = {
     79                .request_type = USB_HUB_REQ_TYPE_CLEAR_PORT_FEATURE,
     80                .request = USB_DEVREQ_CLEAR_FEATURE,
     81                .value = feature,
     82                .index = port_index,
     83                .length = 0,
     84        };
     85        return usb_pipe_control_write(pipe, &clear_request,
     86            sizeof(clear_request), NULL, 0);
     87}
     88/*----------------------------------------------------------------------------*/
     89/**
     90 * Clear feature on hub port.
     91 *
     92 * @param hc Host controller telephone
     93 * @param address Hub address
     94 * @param port_index Port
     95 * @param feature Feature selector
     96 * @return Operation result
     97 */
     98int usb_hub_set_port_feature(usb_pipe_t *pipe,
     99    int port_index, usb_hub_class_feature_t feature)
     100{
     101
     102        usb_device_request_setup_packet_t clear_request = {
     103                .request_type = USB_HUB_REQ_TYPE_SET_PORT_FEATURE,
     104                .request = USB_DEVREQ_SET_FEATURE,
     105                .index = port_index,
     106                .value = feature,
     107                .length = 0,
     108        };
     109        return usb_pipe_control_write(pipe, &clear_request,
     110            sizeof(clear_request), NULL, 0);
     111}
    65112
    66113/**
     
    160207static void usb_hub_removed_device(usb_hub_info_t *hub, size_t port)
    161208{
    162 
    163209        /** \TODO remove device from device manager - not yet implemented in
    164210         * devide manager
    165211         */
    166 
    167         //close address
    168 
    169212        usb_hub_port_t *the_port = hub->ports + port;
    170213
     
    204247 * @param status
    205248 */
    206 static void usb_hub_port_reset_completed(usb_hub_info_t *hub,
    207     uint16_t port, uint32_t status)
    208 {
    209         usb_log_debug("Port %zu reset complete.\n", (size_t) port);
    210         if (usb_port_is_status(status, USB_HUB_FEATURE_PORT_ENABLE)) {
    211                 /* Finalize device adding. */
    212                 usb_hub_port_t *the_port = hub->ports + port;
    213                 fibril_mutex_lock(&the_port->reset_mutex);
    214                 the_port->reset_completed = true;
    215                 the_port->reset_okay = true;
    216                 fibril_condvar_broadcast(&the_port->reset_cv);
    217                 fibril_mutex_unlock(&the_port->reset_mutex);
     249static void usb_hub_port_reset_completed(const usb_hub_info_t *hub,
     250    size_t port, usb_port_status_t status)
     251{
     252        usb_hub_port_t *the_port = hub->ports + port;
     253        fibril_mutex_lock(&the_port->reset_mutex);
     254        /* Finalize device adding. */
     255        the_port->reset_completed = true;
     256        the_port->reset_okay = (status & USB_HUB_PORT_STATUS_ENABLED) != 0;
     257
     258        if (the_port->reset_okay) {
     259                usb_log_debug("Port %zu reset complete.\n", port);
    218260        } else {
    219261                usb_log_warning(
    220                     "Port %zu reset complete but port not enabled.\n",
    221                     (size_t) port);
    222         }
     262                    "Port %zu reset complete but port not enabled.\n", port);
     263        }
     264        fibril_condvar_broadcast(&the_port->reset_cv);
     265        fibril_mutex_unlock(&the_port->reset_mutex);
     266
    223267        /* Clear the port reset change. */
    224268        int rc = usb_hub_clear_port_feature(hub->control_pipe,
     
    229273        }
    230274}
    231 
     275/*----------------------------------------------------------------------------*/
    232276/** Retrieve port status.
    233277 *
     
    285329        assert(hub);
    286330        usb_hub_port_t *my_port = hub->ports + port_no;
    287 
    288         usb_device_request_setup_packet_t request;
    289         usb_hub_set_reset_port_request(&request, port_no);
    290 
    291         const int rc = usb_pipe_control_write(hub->control_pipe,
    292             &request, sizeof (request), NULL, 0);
     331        const int rc = usb_hub_set_port_feature(hub->control_pipe,
     332                port_no, USB_HUB_FEATURE_PORT_RESET);
    293333        if (rc != EOK) {
    294334                usb_log_warning("Port reset failed: %s.\n", str_error(rc));
  • uspace/drv/bus/usb/usbhub/ports.h

    r48a31be raff1880  
    3838#include <usb/dev/driver.h>
    3939#include <usb/dev/hub.h>
     40#include <usb/classes/hub.h>
    4041
    4142typedef struct usb_hub_info_t usb_hub_info_t;
     
    7374
    7475void usb_hub_process_port_interrupt(usb_hub_info_t *hub, size_t port);
    75 
     76int usb_hub_clear_port_feature(usb_pipe_t *pipe,
     77    int port_index, usb_hub_class_feature_t feature);
     78int usb_hub_set_port_feature(usb_pipe_t *pipe,
     79    int port_index, usb_hub_class_feature_t feature);
    7680
    7781
  • uspace/drv/bus/usb/usbhub/utils.h

    r48a31be raff1880  
    5050#include "usbhub.h"
    5151
    52 /**
    53  * Clear feature on hub port.
    54  *
    55  * @param hc Host controller telephone
    56  * @param address Hub address
    57  * @param port_index Port
    58  * @param feature Feature selector
    59  * @return Operation result
    60  */
    61 static inline int usb_hub_clear_port_feature(usb_pipe_t *pipe,
    62     int port_index, usb_hub_class_feature_t feature)
    63 {
    64 
    65         usb_device_request_setup_packet_t clear_request = {
    66                 .request_type = USB_HUB_REQ_TYPE_CLEAR_PORT_FEATURE,
    67                 .request = USB_DEVREQ_CLEAR_FEATURE,
    68                 .length = 0,
    69                 .index = port_index
    70         };
    71         clear_request.value = feature;
    72         return usb_pipe_control_write(pipe, &clear_request,
    73             sizeof (clear_request), NULL, 0);
    74 }
    75 
    76 /**
    77  * Clear feature on hub port.
    78  *
    79  * @param hc Host controller telephone
    80  * @param address Hub address
    81  * @param port_index Port
    82  * @param feature Feature selector
    83  * @return Operation result
    84  */
    85 static inline int usb_hub_set_port_feature(usb_pipe_t *pipe,
    86     int port_index, usb_hub_class_feature_t feature)
    87 {
    88 
    89         usb_device_request_setup_packet_t clear_request = {
    90                 .request_type = USB_HUB_REQ_TYPE_SET_PORT_FEATURE,
    91                 .request = USB_DEVREQ_SET_FEATURE,
    92                 .length = 0,
    93                 .index = port_index
    94         };
    95         clear_request.value = feature;
    96         return usb_pipe_control_write(pipe, &clear_request,
    97             sizeof (clear_request), NULL, 0);
    98 }
    9952
    10053void * usb_create_serialized_hub_descriptor(usb_hub_descriptor_t *descriptor);
Note: See TracChangeset for help on using the changeset viewer.