From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 08/12] USB: host: factor out port configuration to separate function
Date: Sat, 19 Jul 2014 11:16:03 +0200 [thread overview]
Message-ID: <1405761367-23724-9-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1405761367-23724-1-git-send-email-s.hauer@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/usb/core/hub.c | 125 +++++++++++++++++++++++++++++--------------------
1 file changed, 74 insertions(+), 51 deletions(-)
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 9c87037..689a79c 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -227,6 +227,65 @@ static void usb_hub_port_connect_change(struct usb_device *dev, int port)
}
}
+static int usb_hub_configure_port(struct usb_device *dev, int port)
+{
+ struct usb_port_status portsts;
+ unsigned short portstatus, portchange;
+
+ if (usb_get_port_status(dev, port + 1, &portsts) < 0) {
+ dev_dbg(&dev->dev, "get_port_status failed\n");
+ return -EIO;
+ }
+
+ portstatus = le16_to_cpu(portsts.wPortStatus);
+ portchange = le16_to_cpu(portsts.wPortChange);
+ dev_dbg(&dev->dev, "Port %d Status %X Change %X\n",
+ port + 1, portstatus, portchange);
+
+ if (portchange & USB_PORT_STAT_C_CONNECTION) {
+ dev_dbg(&dev->dev, "port %d connection change\n", port + 1);
+ usb_hub_port_connect_change(dev, port);
+ }
+ if (portchange & USB_PORT_STAT_C_ENABLE) {
+ dev_dbg(&dev->dev, "port %d enable change, status %x\n",
+ port + 1, portstatus);
+ usb_clear_port_feature(dev, port + 1,
+ USB_PORT_FEAT_C_ENABLE);
+
+ /* EM interference sometimes causes bad shielded USB
+ * devices to be shutdown by the hub, this hack enables
+ * them again. Works at least with mouse driver */
+ if (!(portstatus & USB_PORT_STAT_ENABLE) &&
+ (portstatus & USB_PORT_STAT_CONNECTION) &&
+ ((dev->children[port]))) {
+ dev_dbg(&dev->dev, "already running port %i " \
+ "disabled by hub (EMI?), " \
+ "re-enabling...\n", port + 1);
+ usb_hub_port_connect_change(dev, port);
+ }
+ }
+ if (portstatus & USB_PORT_STAT_SUSPEND) {
+ dev_dbg(&dev->dev, "port %d suspend change\n", port + 1);
+ usb_clear_port_feature(dev, port + 1,
+ USB_PORT_FEAT_SUSPEND);
+ }
+
+ if (portchange & USB_PORT_STAT_C_OVERCURRENT) {
+ dev_dbg(&dev->dev, "port %d over-current change\n", port + 1);
+ usb_clear_port_feature(dev, port + 1,
+ USB_PORT_FEAT_C_OVER_CURRENT);
+ usb_hub_power_on(dev->hub);
+ }
+
+ if (portchange & USB_PORT_STAT_C_RESET) {
+ dev_dbg(&dev->dev, "port %d reset change\n", port + 1);
+ usb_clear_port_feature(dev, port + 1,
+ USB_PORT_FEAT_C_RESET);
+ }
+
+ return 0;
+}
+
static int usb_hub_configure(struct usb_device *dev)
{
unsigned char buffer[USB_BUFSIZ], *bitmap;
@@ -346,61 +405,23 @@ static int usb_hub_configure(struct usb_device *dev)
"" : "no ");
usb_hub_power_on(hub);
- for (i = 0; i < dev->maxchild; i++) {
- struct usb_port_status portsts;
- unsigned short portstatus, portchange;
-
- if (usb_get_port_status(dev, i + 1, &portsts) < 0) {
- dev_dbg(&dev->dev, "get_port_status failed\n");
- continue;
- }
+ for (i = 0; i < dev->maxchild; i++)
+ usb_hub_configure_port(dev, i);
- portstatus = le16_to_cpu(portsts.wPortStatus);
- portchange = le16_to_cpu(portsts.wPortChange);
- dev_dbg(&dev->dev, "Port %d Status %X Change %X\n",
- i + 1, portstatus, portchange);
+ return 0;
+}
- if (portchange & USB_PORT_STAT_C_CONNECTION) {
- dev_dbg(&dev->dev, "port %d connection change\n", i + 1);
- usb_hub_port_connect_change(dev, i);
- }
- if (portchange & USB_PORT_STAT_C_ENABLE) {
- dev_dbg(&dev->dev, "port %d enable change, status %x\n",
- i + 1, portstatus);
- usb_clear_port_feature(dev, i + 1,
- USB_PORT_FEAT_C_ENABLE);
-
- /* EM interference sometimes causes bad shielded USB
- * devices to be shutdown by the hub, this hack enables
- * them again. Works at least with mouse driver */
- if (!(portstatus & USB_PORT_STAT_ENABLE) &&
- (portstatus & USB_PORT_STAT_CONNECTION) &&
- ((dev->children[i]))) {
- dev_dbg(&dev->dev, "already running port %i " \
- "disabled by hub (EMI?), " \
- "re-enabling...\n", i + 1);
- usb_hub_port_connect_change(dev, i);
- }
- }
- if (portstatus & USB_PORT_STAT_SUSPEND) {
- dev_dbg(&dev->dev, "port %d suspend change\n", i + 1);
- usb_clear_port_feature(dev, i + 1,
- USB_PORT_FEAT_SUSPEND);
- }
+static int usb_hub_detect(struct device_d *dev)
+{
+ struct usb_device *usbdev = container_of(dev, struct usb_device, dev);
+ int i;
- if (portchange & USB_PORT_STAT_C_OVERCURRENT) {
- dev_dbg(&dev->dev, "port %d over-current change\n", i + 1);
- usb_clear_port_feature(dev, i + 1,
- USB_PORT_FEAT_C_OVER_CURRENT);
- usb_hub_power_on(hub);
- }
+ usb_hub_configure(usbdev);
- if (portchange & USB_PORT_STAT_C_RESET) {
- dev_dbg(&dev->dev, "port %d reset change\n", i + 1);
- usb_clear_port_feature(dev, i + 1,
- USB_PORT_FEAT_C_RESET);
- }
- } /* end for i all ports */
+ for (i = 0; i < usbdev->maxchild; i++) {
+ if (usbdev->children[i])
+ device_detect(&usbdev->children[i]->dev);
+ }
return 0;
}
@@ -408,6 +429,8 @@ static int usb_hub_configure(struct usb_device *dev)
static int usb_hub_probe(struct usb_device *usbdev,
const struct usb_device_id *id)
{
+ usbdev->dev.detect = usb_hub_detect;
+
return usb_hub_configure(usbdev);
}
--
2.0.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev 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 ` Sascha Hauer [this message]
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 ` [PATCH 12/12] USB: host: drop force rescan 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=1405761367-23724-9-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