Changeset aa1922c in mainline


Ignore:
Timestamp:
2011-10-12T17:22:43Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4501e207
Parents:
8e5ce07
Message:

uhcirh: Implement removal of attached devices.

Location:
uspace/drv/bus/usb/uhcirh
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/uhcirh/port.c

    r8e5ce07 raa1922c  
    3737#include <str_error.h>
    3838#include <async.h>
     39#include <devman.h>
    3940
    4041#include <usb/usb.h>    /* usb_address_t */
    41 #include <usb/dev/hub.h>    /* usb_hc_new_device_wrapper */
    4242#include <usb/debug.h>
    4343
     
    100100        port->number = number;
    101101        port->wait_period_usec = usec;
    102         port->attached_device = 0;
     102        port->attached_device.handle = 0;
     103        port->attached_device.address = -1;
    103104        port->rh = rh;
    104105
     
    168169
    169170                /* Remove any old device */
    170                 if (instance->attached_device) {
     171                if (instance->attached_device.handle) {
    171172                        usb_log_debug2("%s: Removing device.\n",
    172173                            instance->id_string);
     
    257258
    258259        int ret, count = 0;
    259         usb_address_t dev_addr;
    260260        do {
    261261                ret = usb_hc_new_device_wrapper(port->rh, &port->hc_connection,
    262262                    speed, uhci_port_reset_enable, port->number, port,
    263                     &dev_addr, &port->attached_device, NULL, NULL, NULL);
     263                    &port->attached_device.address,
     264                    &port->attached_device.handle, NULL, NULL, NULL);
    264265        } while (ret != EOK && ++count < 4);
    265266
     
    272273
    273274        usb_log_info("New device at port %u, address %d (handle %" PRIun ").\n",
    274             port->number, dev_addr, port->attached_device);
     275            port->number, port->attached_device.address,
     276            port->attached_device.handle);
    275277        return EOK;
    276278}
     
    278280/** Remove device.
    279281 *
    280  * @param[in] port Memory structure to use.
    281  * @return Error code.
    282  *
    283  * Does not work, DDF does not support device removal.
    284  * Does not even free used USB address (it would be dangerous if tis driver
    285  * is still running).
     282 * @param[in] port Port instance to use.
     283 * @return Error code.
    286284 */
    287285int uhci_port_remove_device(uhci_port_t *port)
    288286{
    289         usb_log_error("%s: Don't know how to remove device %" PRIun ".\n",
    290             port->id_string, port->attached_device);
    291         port->attached_device = 0;
    292         return ENOTSUP;
     287        usb_log_debug("Removing device on port %zu.\n", port->number);
     288
     289        /* Stop driver first */
     290        int ret = devman_remove_function(port->attached_device.handle);
     291        if (ret != EOK) {
     292                usb_log_error("Failed to remove child function on port"
     293                   " %zu: %s.\n", port->number, str_error(ret));
     294                return ret;
     295        }
     296        port->attached_device.handle = 0;
     297
     298        /* Driver stopped, free used address */
     299        ret = usb_hc_unregister_device(&port->hc_connection,
     300            port->attached_device.address);
     301        if (ret != EOK) {
     302                usb_log_error("Failed to unregister address of removed device: "
     303                    "%s.\n", str_error(ret));
     304                return ret;
     305        }
     306
     307        port->attached_device.address = -1;
     308        usb_log_info("Removed device on port %zu.\n", port->number);
     309        return EOK;
    293310}
    294311/*----------------------------------------------------------------------------*/
  • uspace/drv/bus/usb/uhcirh/port.h

    r8e5ce07 raa1922c  
    3939#include <ddf/driver.h>
    4040#include <usb/hc.h> /* usb_hc_connection_t */
     41#include <usb/dev/hub.h>
    4142
    4243typedef uint16_t port_status_t;
     
    6263        usb_hc_connection_t hc_connection;
    6364        ddf_dev_t *rh;
    64         devman_handle_t attached_device;
     65        usb_hc_attached_device_t attached_device;
    6566        fid_t checker;
    6667} uhci_port_t;
Note: See TracChangeset for help on using the changeset viewer.