summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2014-07-15 15:19:53 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2014-07-18 14:50:21 +0200
commit4bff0a0553b739427834ef7669621f08ee84dec0 (patch)
tree36f786dbad82db161e63eed04516544ad4112b35
parentc7d3ec47f9699bb210799593ebb277168259b8c5 (diff)
downloadbarebox-4bff0a0553b739427834ef7669621f08ee84dec0.tar.gz
USB: host: implement usb_remove_device
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--drivers/usb/core/hub.c1
-rw-r--r--drivers/usb/core/usb.c19
-rw-r--r--drivers/usb/core/usb.h1
3 files changed, 21 insertions, 0 deletions
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 39cadb5..144442a 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -189,6 +189,7 @@ static void usb_hub_port_connect_change(struct usb_device *dev, int port)
if (((!(portstatus & USB_PORT_STAT_CONNECTION)) &&
(!(portstatus & USB_PORT_STAT_ENABLE))) || (dev->children[port])) {
dev_dbg(&dev->dev, "usb_disconnect(&hub->children[port]);\n");
+ usb_remove_device(dev->children[port]);
/* Return now if nothing is connected */
if (!(portstatus & USB_PORT_STAT_CONNECTION))
return;
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index 7c69e10..faf509e 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -455,6 +455,25 @@ err_out:
return err;
}
+void usb_remove_device(struct usb_device *usbdev)
+{
+ int i, ret;
+
+ for (i = 0; i < usbdev->maxchild; i++) {
+ if (usbdev->children[i])
+ usb_remove_device(usbdev->children[i]);
+ }
+
+ dev_info(&usbdev->dev, "removing\n");
+
+ ret = unregister_device(&usbdev->dev);
+ if (ret)
+ dev_err(&usbdev->dev, "failed to unregister\n");
+
+ usbdev->parent->children[usbdev->portnr - 1] = NULL;
+ free(usbdev);
+}
+
struct usb_device *usb_alloc_new_device(void)
{
struct usb_device *usbdev = xzalloc(sizeof (*usbdev));
diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h
index 3e79407..a0c0550 100644
--- a/drivers/usb/core/usb.h
+++ b/drivers/usb/core/usb.h
@@ -3,5 +3,6 @@
struct usb_device *usb_alloc_new_device(void);
int usb_new_device(struct usb_device *dev);
+void usb_remove_device(struct usb_device *dev);
#endif /* __CORE_USB_H */