Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/uhci-rhd/port.c

    r87157982 rdced52a  
    3434#include <errno.h>
    3535#include <str_error.h>
     36#include <fibril_synch.h>
    3637
    3738#include <usb/usb.h>    /* usb_address_t */
     
    4546#include "port_status.h"
    4647
    47 static int uhci_port_new_device(uhci_port_t *port);
     48static int uhci_port_new_device(uhci_port_t *port, uint16_t status);
    4849static int uhci_port_remove_device(uhci_port_t *port);
    4950static int uhci_port_set_enabled(uhci_port_t *port, bool enabled);
    5051static int uhci_port_check(void *port);
     52static int new_device_enable_port(int portno, void *arg);
    5153
    5254int uhci_port_init(
    5355  uhci_port_t *port, port_status_t *address, unsigned number,
    54   unsigned usec, ddf_dev_t *rh, int parent_phone)
     56  unsigned usec, ddf_dev_t *rh)
    5557{
    5658        assert(port);
     
    6971        port->checker = fibril_create(uhci_port_check, port);
    7072        if (port->checker == 0) {
    71                 usb_log_error(": failed to launch root hub fibril.");
     73                usb_log_error("Port(%p - %d): failed to launch root hub fibril.",
     74                    port->address, port->number);
    7275                return ENOMEM;
    7376        }
    7477        fibril_add_ready(port->checker);
    75         usb_log_debug(
    76           "Added fibril for port %d: %p.\n", number, port->checker);
     78        usb_log_debug("Port(%p - %d): Added fibril. %x\n",
     79            port->address, port->number, port->checker);
    7780        return EOK;
    7881}
     
    9093        uhci_port_t *port_instance = port;
    9194        assert(port_instance);
     95//      port_status_write(port_instance->address, 0);
     96
     97        unsigned count = 0;
    9298
    9399        while (1) {
     100                async_usleep(port_instance->wait_period_usec);
     101
    94102                /* read register value */
    95103                port_status_t port_status =
     
    97105
    98106                /* debug print */
    99                 usb_log_debug("Port %d status at %p: 0x%04x.\n",
    100                   port_instance->number, port_instance->address, port_status);
    101                 print_port_status(port_status);
    102 
    103                 if (port_status & STATUS_CONNECTED_CHANGED) {
     107                static fibril_mutex_t dbg_mtx = FIBRIL_MUTEX_INITIALIZER(dbg_mtx);
     108                fibril_mutex_lock(&dbg_mtx);
     109                usb_log_debug2("Port(%p - %d): Status: %#04x. === %u\n",
     110                  port_instance->address, port_instance->number, port_status, count++);
     111//              print_port_status(port_status);
     112                fibril_mutex_unlock(&dbg_mtx);
     113
     114                if ((port_status & STATUS_CONNECTED_CHANGED) != 0) {
     115                        usb_log_debug("Port(%p - %d): Connected change detected: %x.\n",
     116                            port_instance->address, port_instance->number, port_status);
     117
     118
    104119                        int rc = usb_hc_connection_open(
    105120                            &port_instance->hc_connection);
    106121                        if (rc != EOK) {
    107                                 usb_log_error("Failed to connect to HC.");
    108                                 goto next;
    109                         }
    110 
    111                         if (port_status & STATUS_CONNECTED) {
     122                                usb_log_error("Port(%p - %d): Failed to connect to HC.",
     123                                    port_instance->address, port_instance->number);
     124                                continue;
     125                        }
     126
     127                        /* remove any old device */
     128                        if (port_instance->attached_device) {
     129                                usb_log_debug("Port(%p - %d): Removing device.\n",
     130                                    port_instance->address, port_instance->number);
     131                                uhci_port_remove_device(port_instance);
     132                        }
     133
     134                        if ((port_status & STATUS_CONNECTED) != 0) {
    112135                                /* new device */
    113                                 uhci_port_new_device(port_instance);
     136                                uhci_port_new_device(port_instance, port_status);
    114137                        } else {
    115                                 uhci_port_remove_device(port_instance);
     138                                /* ack changes by writing one to WC bits */
     139                                port_status_write(port_instance->address, port_status);
     140                                usb_log_debug("Port(%p - %d): Change status ACK.\n",
     141                                                port_instance->address, port_instance->number);
    116142                        }
    117143
     
    119145                            &port_instance->hc_connection);
    120146                        if (rc != EOK) {
    121                                 usb_log_error("Failed to disconnect from HC.");
    122                                 goto next;
     147                                usb_log_error("Port(%p - %d): Failed to disconnect from HC.",
     148                                    port_instance->address, port_instance->number);
    123149                        }
    124150                }
    125         next:
    126                 async_usleep(port_instance->wait_period_usec);
    127151        }
    128152        return EOK;
     
    139163        uhci_port_t *port = (uhci_port_t *) arg;
    140164
    141         usb_log_debug("new_device_enable_port(%d)\n", port->number);
     165        usb_log_debug2("Port(%p - %d): new_device_enable_port.\n",
     166            port->address, port->number);
    142167
    143168        /*
     
    147172        async_usleep(100000);
    148173
    149         /* Enable the port. */
    150         uhci_port_set_enabled(port, true);
    151174
    152175        /* The hub maintains the reset signal to that port for 10 ms
     
    154177         */
    155178        {
    156                 usb_log_debug("Reset Signal start on port %d.\n",
    157                     port->number);
     179                usb_log_debug("Port(%p - %d): Reset Signal start.\n",
     180                    port->address, port->number);
    158181                port_status_t port_status =
    159182                        port_status_read(port->address);
     
    165188                port_status &= ~STATUS_IN_RESET;
    166189                port_status_write(port->address, port_status);
    167                 usb_log_debug("Reset Signal stop on port %d.\n",
    168                     port->number);
    169         }
    170 
    171         return EOK;
    172 }
    173 
    174 /*----------------------------------------------------------------------------*/
    175 static int uhci_port_new_device(uhci_port_t *port)
     190                usb_log_debug("Port(%p - %d): Reset Signal stop.\n",
     191                    port->address, port->number);
     192        }
     193
     194        /* Enable the port. */
     195        uhci_port_set_enabled(port, true);
     196
     197        return EOK;
     198}
     199
     200/*----------------------------------------------------------------------------*/
     201static int uhci_port_new_device(uhci_port_t *port, uint16_t status)
    176202{
    177203        assert(port);
    178204        assert(usb_hc_connection_is_opened(&port->hc_connection));
    179205
    180         usb_log_info("Detected new device on port %u.\n", port->number);
     206        usb_log_info("Port(%p-%d): Detected new device.\n",
     207            port->address, port->number);
    181208
    182209        usb_address_t dev_addr;
    183210        int rc = usb_hc_new_device_wrapper(port->rh, &port->hc_connection,
    184             USB_SPEED_FULL,
     211            ((status & STATUS_LOW_SPEED) != 0) ? USB_SPEED_LOW : USB_SPEED_FULL,
    185212            new_device_enable_port, port->number, port,
    186213            &dev_addr, &port->attached_device, NULL, NULL, NULL);
     214
    187215        if (rc != EOK) {
    188                 usb_log_error("Failed adding new device on port %u: %s.\n",
    189                     port->number, str_error(rc));
     216                usb_log_error("Port(%p-%d): Failed(%d) adding new device: %s.\n",
     217                    port->address, port->number, rc, str_error(rc));
    190218                uhci_port_set_enabled(port, false);
    191219                return rc;
    192220        }
    193221
    194         usb_log_info("New device on port %u has address %d (handle %zu).\n",
    195             port->number, dev_addr, port->attached_device);
     222        usb_log_info("Port(%p-%d): New device has address %d (handle %zu).\n",
     223            port->address, port->number, dev_addr, port->attached_device);
    196224
    197225        return EOK;
     
    201229static int uhci_port_remove_device(uhci_port_t *port)
    202230{
    203         usb_log_error("Don't know how to remove device %#x.\n",
    204                 (unsigned int)port->attached_device);
     231        usb_log_error("Port(%p-%d): Don't know how to remove device %#x.\n",
     232                port->address, port->number, (unsigned int)port->attached_device);
    205233//      uhci_port_set_enabled(port, false);
    206234        return EOK;
     
    223251        port_status_write(port->address, port_status);
    224252
    225         usb_log_info("%s port %d.\n",
    226           enabled ? "Enabled" : "Disabled", port->number);
     253        usb_log_info("Port(%p-%d): %sabled port.\n",
     254                port->address, port->number, enabled ? "En" : "Dis");
    227255        return EOK;
    228256}
Note: See TracChangeset for help on using the changeset viewer.