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


Ignore:
Timestamp:
2011-09-23T12:59:35Z (14 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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));
Note: See TracChangeset for help on using the changeset viewer.