mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] usb: implement detect callback
@ 2013-06-20 14:05 Sascha Hauer
  2013-06-20 14:05 ` [PATCH 1/4] usb: rename USB devices to reflect bus structure Sascha Hauer
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Sascha Hauer @ 2013-06-20 14:05 UTC (permalink / raw)
  To: barebox


The following prepares to implement the detect callback for USB
and finally implements it in the ehci driver.

With this series all frameworks in barebox supporting on-demand-probing
support the new 'detect' command.

Sascha

----------------------------------------------------------------
Sascha Hauer (4):
      usb: rename USB devices to reflect bus structure
      usb: move scanned status into core
      usb: implement a usb_host_detect to scan individual USB hosts
      usb: ehci: implement detect callback

 commands/usb.c              | 10 +++-------
 drivers/usb/core/usb.c      | 47 +++++++++++++++++++++++++++++++++++----------
 drivers/usb/host/ehci-hcd.c |  9 +++++++++
 include/usb/usb.h           |  5 ++++-
 4 files changed, 53 insertions(+), 18 deletions(-)

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/4] usb: rename USB devices to reflect bus structure
  2013-06-20 14:05 [PATCH] usb: implement detect callback Sascha Hauer
@ 2013-06-20 14:05 ` Sascha Hauer
  2013-06-20 14:05 ` [PATCH 2/4] usb: move scanned status into core Sascha Hauer
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2013-06-20 14:05 UTC (permalink / raw)
  To: barebox

This renames the USB devices to reflect the bus structure.
The base name for a USB device is usb<devno>. For each child
device we add a -<parent-port-no>. This makes it more easy
to identify devices.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/usb/core/usb.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index 9a0723a..e232111 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -431,14 +431,22 @@ static int usb_new_device(struct usb_device *dev)
 	if (dev->descriptor->iSerialNumber)
 		usb_string(dev, dev->descriptor->iSerialNumber,
 			   dev->serial, sizeof(dev->serial));
+
+	if (parent) {
+		sprintf(dev->dev.name, "%s-%d", parent->dev.name, port);
+	} else {
+		sprintf(dev->dev.name, "usb%d", dev->host->busnum);
+	}
+
+	dev->dev.id = DEVICE_ID_SINGLE;
+
+	register_device(&dev->dev);
+
 	/* now prode if the device is a hub */
 	usb_hub_probe(dev, 0);
 
-	sprintf(dev->dev.name, "usb%d-%d", dev->host->busnum, dev->devnum);
-
 	print_usb_device(dev);
 
-	register_device(&dev->dev);
 	dev_add_param_int_ro(&dev->dev, "iManufacturer",
 			dev->descriptor->iManufacturer, "%d");
 	dev_add_param_int_ro(&dev->dev, "iProduct",
-- 
1.8.3.1


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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/4] usb: move scanned status into core
  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 ` Sascha Hauer
  2013-06-20 14:05 ` [PATCH 3/4] usb: implement a usb_host_detect to scan individual USB hosts Sascha Hauer
  2013-06-20 14:05 ` [PATCH 4/4] usb: ehci: implement detect callback Sascha Hauer
  3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2013-06-20 14:05 UTC (permalink / raw)
  To: barebox

A command should not be interested in the internal USB core state, so
move the state handling into the core.

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

diff --git a/commands/usb.c b/commands/usb.c
index e503065..9aee430 100644
--- a/commands/usb.c
+++ b/commands/usb.c
@@ -22,24 +22,20 @@
 #include <usb/usb.h>
 #include <getopt.h>
 
-static int scanned;
-
 static int do_usb(int argc, char *argv[])
 {
 	int opt;
+	int force = 0;
 
 	while ((opt = getopt(argc, argv, "f")) > 0) {
 		switch (opt) {
 		case 'f':
-			scanned = 0;
+			force = 1;
 			break;
 		}
 	}
 
-	if (!scanned) {
-		usb_rescan();
-		scanned = 1;
-	}
+	usb_rescan(force);
 
 	return 0;
 }
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index e232111..07175dc 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -488,12 +488,19 @@ static struct usb_device *usb_alloc_new_device(void)
 	return usbdev;
 }
 
-void usb_rescan(void)
+static int scanned;
+
+void usb_rescan(int force)
 {
 	struct usb_device *dev, *tmp;
 	struct usb_host *host;
 	int ret;
 
+	if (scanned && !force)
+		return;
+
+	scanned = 1;
+
 	list_for_each_entry_safe(dev, tmp, &usb_device_list, list) {
 		list_del(&dev->list);
 		unregister_device(&dev->dev);
diff --git a/include/usb/usb.h b/include/usb/usb.h
index da0090e..2e1498c 100644
--- a/include/usb/usb.h
+++ b/include/usb/usb.h
@@ -248,7 +248,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(void);
+void usb_rescan(int force);
 
 /* big endian -> little endian conversion */
 /* some CPUs are already little endian e.g. the ARM920T */
-- 
1.8.3.1


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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 3/4] usb: implement a usb_host_detect to scan individual USB hosts
  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
  2013-06-20 14:05 ` [PATCH 4/4] usb: ehci: implement detect callback Sascha Hauer
  3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2013-06-20 14:05 UTC (permalink / raw)
  To: barebox

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 4/4] usb: ehci: implement detect callback
  2013-06-20 14:05 [PATCH] usb: implement detect callback Sascha Hauer
                   ` (2 preceding siblings ...)
  2013-06-20 14:05 ` [PATCH 3/4] usb: implement a usb_host_detect to scan individual USB hosts Sascha Hauer
@ 2013-06-20 14:05 ` Sascha Hauer
  3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2013-06-20 14:05 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/usb/host/ehci-hcd.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 7c389aa..840aa1a 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -847,6 +847,13 @@ submit_int_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
 	return -1;
 }
 
+static int ehci_detect(struct device_d *dev)
+{
+	struct ehci_priv *ehci = dev->priv;
+
+	return usb_host_detect(&ehci->host, 0);
+}
+
 int ehci_register(struct device_d *dev, struct ehci_data *data)
 {
 	struct usb_host *host;
@@ -882,6 +889,8 @@ int ehci_register(struct device_d *dev, struct ehci_data *data)
 		ehci_reset(ehci);
 	}
 
+	dev->detect = ehci_detect;
+
 	usb_register_host(host);
 
 	reg = HC_VERSION(ehci_readl(&ehci->hccr->cr_capbase));
-- 
1.8.3.1


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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-06-20 14:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 3/4] usb: implement a usb_host_detect to scan individual USB hosts Sascha Hauer
2013-06-20 14:05 ` [PATCH 4/4] usb: ehci: implement detect callback Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox