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 3/4] usb: implement a usb_host_detect to scan individual USB hosts
Date: Thu, 20 Jun 2013 16:05:24 +0200	[thread overview]
Message-ID: <1371737125-18820-4-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1371737125-18820-1-git-send-email-s.hauer@pengutronix.de>

Currently we can only (re)scan all USB hosts. Add a function to
scan individual hosts. This is useful for implementing the detect
callback in the next patch.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/usb/core/usb.c | 38 +++++++++++++++++++++++++-------------
 include/usb/usb.h      |  3 +++
 2 files changed, 28 insertions(+), 13 deletions(-)

diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index 07175dc..36fc736 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -488,20 +488,18 @@ static struct usb_device *usb_alloc_new_device(void)
 	return usbdev;
 }
 
-static int scanned;
-
-void usb_rescan(int force)
+int usb_host_detect(struct usb_host *host, int force)
 {
 	struct usb_device *dev, *tmp;
-	struct usb_host *host;
 	int ret;
 
-	if (scanned && !force)
-		return;
-
-	scanned = 1;
+	if (host->scanned && !force)
+		return -EBUSY;
 
 	list_for_each_entry_safe(dev, tmp, &usb_device_list, list) {
+		if (dev->host != host)
+			continue;
+
 		list_del(&dev->list);
 		unregister_device(&dev->dev);
 		if (dev->hub)
@@ -511,17 +509,31 @@ void usb_rescan(int force)
 		free(dev);
 	}
 
+	ret = host->init(host);
+	if (ret)
+		return ret;
+
+	dev = usb_alloc_new_device();
+	dev->host = host;
+	usb_new_device(dev);
+
+	host->scanned = 1;
+
+	return 0;
+}
+
+void usb_rescan(int force)
+{
+	struct usb_host *host;
+	int ret;
+
 	printf("USB: scanning bus for devices...\n");
 	dev_index = 0;
 
 	list_for_each_entry(host, &host_list, list) {
-		ret = host->init(host);
+		ret = usb_host_detect(host, force);
 		if (ret)
 			continue;
-
-		dev = usb_alloc_new_device();
-		dev->host = host;
-		usb_new_device(dev);
 	}
 
 	printf("%d USB Device(s) found\n", dev_index);
diff --git a/include/usb/usb.h b/include/usb/usb.h
index 2e1498c..95fb6f3 100644
--- a/include/usb/usb.h
+++ b/include/usb/usb.h
@@ -211,10 +211,13 @@ struct usb_host {
 	struct list_head list;
 
 	int busnum;
+	int scanned;
 };
 
 int usb_register_host(struct usb_host *);
 
+int usb_host_detect(struct usb_host *host, int force);
+
 /* Defines */
 #define USB_UHCI_VEND_ID	0x8086
 #define USB_UHCI_DEV_ID		0x7112
-- 
1.8.3.1


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

  parent reply	other threads:[~2013-06-20 14:05 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-20 14:05 [PATCH] usb: implement detect callback Sascha Hauer
2013-06-20 14:05 ` [PATCH 1/4] usb: rename USB devices to reflect bus structure Sascha Hauer
2013-06-20 14:05 ` [PATCH 2/4] usb: move scanned status into core Sascha Hauer
2013-06-20 14:05 ` Sascha Hauer [this message]
2013-06-20 14:05 ` [PATCH 4/4] usb: ehci: implement detect callback Sascha Hauer

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=1371737125-18820-4-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