From patchwork Wed Jun 17 19:33:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 485637 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 01EDB1401DA for ; Thu, 18 Jun 2015 05:35:39 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id D1A384B6A7; Wed, 17 Jun 2015 21:35:13 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id DLiUnv3GrEx5; Wed, 17 Jun 2015 21:35:13 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 9AFB54B6BB; Wed, 17 Jun 2015 21:35:00 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id B20264B65B for ; Wed, 17 Jun 2015 21:34:50 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id t5yTaM6_sVjs for ; Wed, 17 Jun 2015 21:34:50 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by theia.denx.de (Postfix) with ESMTPS id CF9C84B6A2 for ; Wed, 17 Jun 2015 21:34:29 +0200 (CEST) Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 5C604373BC4; Wed, 17 Jun 2015 19:34:28 +0000 (UTC) Received: from shalem.localdomain.com (vpn1-4-77.ams2.redhat.com [10.36.4.77]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t5HJY6Sw028265; Wed, 17 Jun 2015 15:34:27 -0400 From: Hans de Goede To: Simon Glass , Marek Vasut Date: Wed, 17 Jun 2015 21:33:51 +0200 Message-Id: <1434569645-30322-9-git-send-email-hdegoede@redhat.com> In-Reply-To: <1434569645-30322-1-git-send-email-hdegoede@redhat.com> References: <1434569645-30322-1-git-send-email-hdegoede@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 Cc: Ian Campbell , u-boot@lists.denx.de Subject: [U-Boot] [PATCH 08/22] dm: usb: Use device_chld_remove and _unbind to clean up usb devs on stop X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" On an usb stop instead of leaving orphan usb devices behind simply remove them. This requires CONFIG_DM_DEVICE_REMOVE to be set, so only build usb_stop() when that is set. The result of this commit is best seen in the output of "dm tree" after plugging out an usb hub with 2 devices plugges in and plugging in a keyb. instead, before this commit the output would be: usb [ + ] `-- sunxi-musb usb_hub [ ] |-- usb_hub usb_mass_st [ ] | |-- usb_mass_storage usb_dev_gen [ ] | `-- generic_bus_0_dev_3 usb_dev_gen [ + ] `-- generic_bus_0_dev_1 Notice the non active usb_hub child and its 2 non active children. The first child being non-active as in this example also causes usb_get_dev_index to return NULL when probing the first child, which results in the usb kbd code not binding to the keyboard. With this commit in place the output after swapping and "usb reset" is: usb [ + ] `-- sunxi-musb usb_dev_gen [ + ] `-- generic_bus_0_dev_1 As expected, and usb_get_dev_index works properly and the keyboard works. After this commit usb_find_child() is only necessary for emulated usb devices, so make its body #ifdef CONFIG_USB_EMUL. Signed-off-by: Hans de Goede --- drivers/usb/host/usb-uclass.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/usb/host/usb-uclass.c b/drivers/usb/host/usb-uclass.c index bce6cec..8f26e35 100644 --- a/drivers/usb/host/usb-uclass.c +++ b/drivers/usb/host/usb-uclass.c @@ -128,6 +128,7 @@ int usb_alloc_device(struct usb_device *udev) return ops->alloc_device(bus, udev); } +#ifdef CONFIG_DM_DEVICE_REMOVE int usb_stop(void) { struct udevice *bus; @@ -143,6 +144,12 @@ int usb_stop(void) uc_priv = uc->priv; uclass_foreach_dev(bus, uc) { + ret = device_chld_remove(bus); + if (ret && !err) + err = ret; + ret = device_chld_unbind(bus); + if (ret && !err) + err = ret; ret = device_remove(bus); if (ret && !err) err = ret; @@ -166,6 +173,7 @@ int usb_stop(void) return err; } +#endif static void usb_scan_bus(struct udevice *bus, bool recurse) { @@ -491,6 +499,7 @@ static int usb_find_child(struct udevice *parent, struct usb_interface_descriptor *iface, struct udevice **devp) { +#ifdef CONFIG_USB_EMUL /* Emulated devices are explictily bound */ struct udevice *dev; *devp = NULL; @@ -509,6 +518,7 @@ static int usb_find_child(struct udevice *parent, return 0; } } +#endif return -ENOENT; }