From 618c169b577db64ac6589ad48825d2e11760d1a6 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Wed, 1 Dec 2010 11:27:05 +0100 Subject: usb: rework attach/detach workflow Add separate detach callback to USBPortOps, split uhci/ohci/musb/usbhub attach functions into two. Move common code to the usb_attach() function, only the hardware-specific bits remain in the attach/detach callbacks. Keep track of the port it is attached to for each usb device. [ v3: fix tyops in usb-musb.c ] Signed-off-by: Gerd Hoffmann --- hw/usb.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'hw/usb.c') diff --git a/hw/usb.c b/hw/usb.c index 39d29f3daf..2eda86a58c 100644 --- a/hw/usb.c +++ b/hw/usb.c @@ -28,7 +28,25 @@ void usb_attach(USBPort *port, USBDevice *dev) { - port->ops->attach(port, dev); + 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; + port->ops->detach(port); + if (dev) { + usb_send_msg(dev, USB_MSG_DETACH); + dev->port = NULL; + port->dev = NULL; + } + } } /**********************/ -- cgit v1.2.3