diff options
Diffstat (limited to 'hw/usb.c')
-rw-r--r-- | hw/usb.c | 35 |
1 files changed, 16 insertions, 19 deletions
@@ -27,26 +27,23 @@ #include "usb.h" #include "iov.h" -void usb_attach(USBPort *port, USBDevice *dev) +void usb_attach(USBPort *port) { - if (dev != NULL) { - /* attach */ - if (port->dev) { - usb_attach(port, NULL); - } - dev->port = port; - port->dev = dev; - port->ops->attach(port); - usb_send_msg(dev, USB_MSG_ATTACH); - } else { - /* detach */ - dev = port->dev; - assert(dev); - port->ops->detach(port); - usb_send_msg(dev, USB_MSG_DETACH); - dev->port = NULL; - port->dev = NULL; - } + USBDevice *dev = port->dev; + + assert(dev != NULL); + assert(dev->attached); + port->ops->attach(port); + usb_send_msg(dev, USB_MSG_ATTACH); +} + +void usb_detach(USBPort *port) +{ + USBDevice *dev = port->dev; + + assert(dev != NULL); + port->ops->detach(port); + usb_send_msg(dev, USB_MSG_DETACH); } void usb_wakeup(USBDevice *dev) |