mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 12/12] USB: host: drop force rescan
Date: Sat, 19 Jul 2014 11:16:07 +0200	[thread overview]
Message-ID: <1405761367-23724-13-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1405761367-23724-1-git-send-email-s.hauer@pengutronix.de>

We can now detect changes in the USB device hierarchy properly, so
the 'force' option to the usb command is no longer necessary. We just
scan the busses each time the usb command is called.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/usb.c              |  9 +++------
 drivers/usb/core/usb.c      | 39 ++++++++++++---------------------------
 drivers/usb/host/ehci-hcd.c |  2 +-
 include/usb/usb.h           |  6 +++---
 4 files changed, 19 insertions(+), 37 deletions(-)

diff --git a/commands/usb.c b/commands/usb.c
index c158852..a37d503 100644
--- a/commands/usb.c
+++ b/commands/usb.c
@@ -112,13 +112,10 @@ static void usb_show_devices(bool tree)
 static int do_usb(int argc, char *argv[])
 {
 	int opt;
-	int force = 0, tree = 0, show = 0;
+	int tree = 0, show = 0;
 
-	while ((opt = getopt(argc, argv, "fts")) > 0) {
+	while ((opt = getopt(argc, argv, "ts")) > 0) {
 		switch (opt) {
-		case 'f':
-			force = 1;
-			break;
 		case 't':
 			tree = 1;
 			show = 1;
@@ -129,7 +126,7 @@ static int do_usb(int argc, char *argv[])
 		}
 	}
 
-	usb_rescan(force);
+	usb_rescan();
 
 	if (show)
 		usb_show_devices(tree);
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index faf509e..fdf9d94 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -492,50 +492,35 @@ struct usb_device *usb_alloc_new_device(void)
 	return usbdev;
 }
 
-int usb_host_detect(struct usb_host *host, int force)
+int usb_host_detect(struct usb_host *host)
 {
-	struct usb_device *dev, *tmp;
 	int ret;
 
-	if (host->scanned && !force)
-		return -EBUSY;
-
-	list_for_each_entry_safe(dev, tmp, &usb_device_list, list) {
-		if (dev->host != host)
-			continue;
+	if (!host->root_dev) {
+		ret = host->init(host);
+		if (ret)
+			return ret;
 
-		list_del(&dev->list);
-		unregister_device(&dev->dev);
-		free(dev->hub);
-		dma_free(dev->setup_packet);
-		dma_free(dev->descriptor);
-		free(dev);
+		host->root_dev = usb_alloc_new_device();
+		host->root_dev->dev.parent = host->hw_dev;
+		host->root_dev->host = host;
+		usb_new_device(host->root_dev);
 	}
 
-	ret = host->init(host);
-	if (ret)
-		return ret;
-
-	dev = usb_alloc_new_device();
-	dev->dev.parent = host->hw_dev;
-	dev->host = host;
-	usb_new_device(dev);
-
-	host->scanned = 1;
+	device_detect(&host->root_dev->dev);
 
 	return 0;
 }
 
-void usb_rescan(int force)
+void usb_rescan(void)
 {
 	struct usb_host *host;
 	int ret;
 
 	pr_info("USB: scanning bus for devices...\n");
-	dev_index = 0;
 
 	list_for_each_entry(host, &host_list, list) {
-		ret = usb_host_detect(host, force);
+		ret = usb_host_detect(host);
 		if (ret)
 			continue;
 	}
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index d30c3aa..9e30deb 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -871,7 +871,7 @@ static int ehci_detect(struct device_d *dev)
 {
 	struct ehci_priv *ehci = dev->priv;
 
-	return usb_host_detect(&ehci->host, 0);
+	return usb_host_detect(&ehci->host);
 }
 
 int ehci_register(struct device_d *dev, struct ehci_data *data)
diff --git a/include/usb/usb.h b/include/usb/usb.h
index 34edbae..41f92c2 100644
--- a/include/usb/usb.h
+++ b/include/usb/usb.h
@@ -150,12 +150,12 @@ struct usb_host {
 
 	struct device_d *hw_dev;
 	int busnum;
-	int scanned;
+	struct usb_device *root_dev;
 };
 
 int usb_register_host(struct usb_host *);
 
-int usb_host_detect(struct usb_host *host, int force);
+int usb_host_detect(struct usb_host *host);
 
 int usb_set_protocol(struct usb_device *dev, int ifnum, int protocol);
 int usb_set_idle(struct usb_device *dev, int ifnum, int duration,
@@ -185,7 +185,7 @@ int usb_clear_halt(struct usb_device *dev, int pipe);
 int usb_string(struct usb_device *dev, int index, char *buf, size_t size);
 int usb_set_interface(struct usb_device *dev, int interface, int alternate);
 
-void usb_rescan(int force);
+void usb_rescan(void);
 
 /* big endian -> little endian conversion */
 /* some CPUs are already little endian e.g. the ARM920T */
-- 
2.0.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

      parent reply	other threads:[~2014-07-19  9:16 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-19  9:15 USB Host patches Sascha Hauer
2014-07-19  9:15 ` [PATCH 01/12] USB: i.MX chipidea: Implement OTG support for the poor Sascha Hauer
2014-07-19  9:15 ` [PATCH 02/12] commands: usb: add tree view capability Sascha Hauer
2014-07-19  9:15 ` [PATCH 03/12] USB: host: simplify usb_new_device Sascha Hauer
2014-07-19  9:15 ` [PATCH 04/12] USB: host: hub: Turn into a driver Sascha Hauer
2014-07-19  9:16 ` [PATCH 05/12] USB: host: fixup USB device hierarchy Sascha Hauer
2014-07-19  9:16 ` [PATCH 06/12] USB: host: hub: Use dev_dbg Sascha Hauer
2014-07-19  9:16 ` [PATCH 07/12] USB: host: hub: Use usb_hub_power_on from U-Boot Sascha Hauer
2014-07-19  9:16 ` [PATCH 08/12] USB: host: factor out port configuration to separate function Sascha Hauer
2014-07-19  9:16 ` [PATCH 09/12] USB: host: hub: only configure hub once Sascha Hauer
2014-07-19  9:16 ` [PATCH 10/12] USB: host: implement usb_remove_device Sascha Hauer
2014-07-19  9:16 ` [PATCH 11/12] USB: host: detect port change only once in usb_hub_configure_port Sascha Hauer
2014-07-19  9:16 ` Sascha Hauer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1405761367-23724-13-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox