diff mbox

[U-Boot,v2,18/80] dm: usb: Split out more code from usb_new_device()

Message ID 1427307788-7496-19-git-send-email-sjg@chromium.org
State Accepted
Delegated to: Simon Glass
Headers show

Commit Message

Simon Glass March 25, 2015, 6:22 p.m. UTC
Move the code that sets up the device with a new address into its own
function, usb_prepare_device().

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v2: None

 common/usb.c | 72 +++++++++++++++++++++++++++++++++++-------------------------
 1 file changed, 42 insertions(+), 30 deletions(-)

Comments

Simon Glass April 7, 2015, 6:41 p.m. UTC | #1
On 25 March 2015 at 12:22, Simon Glass <sjg@chromium.org> wrote:
> Move the code that sets up the device with a new address into its own
> function, usb_prepare_device().
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
> Changes in v2: None
>
>  common/usb.c | 72 +++++++++++++++++++++++++++++++++++-------------------------
>  1 file changed, 42 insertions(+), 30 deletions(-)

Applied to u-boot-dm/next.
diff mbox

Patch

diff --git a/common/usb.c b/common/usb.c
index d0debbc..c3f805d 100644
--- a/common/usb.c
+++ b/common/usb.c
@@ -956,19 +956,10 @@  static int usb_setup_descriptor(struct usb_device *dev, bool do_read)
 	return 0;
 }
 
-/*
- * By the time we get here, the device has gotten a new device ID
- * and is in the default state. We need to identify the thing and
- * get the ball rolling..
- *
- * Returns 0 for success, != 0 for error.
- */
-int usb_new_device(struct usb_device *dev)
+static int usb_prepare_device(struct usb_device *dev, int addr, bool do_read,
+			      struct usb_device *parent, int portnr)
 {
-	bool do_read = true;
-	int addr, err;
-	int tmp;
-	ALLOC_CACHE_ALIGN_BUFFER(unsigned char, tmpbuf, USB_BUFSIZ);
+	int err;
 
 	/*
 	 * Allocate usb 3.0 device context.
@@ -976,28 +967,15 @@  int usb_new_device(struct usb_device *dev)
 	 * and related data structures first. This call does that.
 	 * Refer to sec 4.3.2 in xHCI spec rev1.0
 	 */
-	if (usb_alloc_device(dev)) {
+	err = usb_alloc_device(dev);
+	if (err) {
 		printf("Cannot allocate device context to get SLOT_ID\n");
-		return -1;
+		return err;
 	}
-
-	/* We still haven't set the Address yet */
-	addr = dev->devnum;
-	dev->devnum = 0;
-
-	/*
-	 * XHCI needs to issue a Address device command to setup
-	 * proper device context structures, before it can interact
-	 * with the device. So a get_descriptor will fail before any
-	 * of that is done for XHCI unlike EHCI.
-	 */
-#ifndef CONFIG_USB_XHCI
-	do_read = false;
-#endif
 	err = usb_setup_descriptor(dev, do_read);
 	if (err)
 		return err;
-	err = usb_legacy_port_reset(dev->parent, dev->portnr);
+	err = usb_legacy_port_reset(parent, portnr);
 	if (err)
 		return err;
 
@@ -1008,11 +986,45 @@  int usb_new_device(struct usb_device *dev)
 	if (err < 0) {
 		printf("\n      USB device not accepting new address " \
 			"(error=%lX)\n", dev->status);
-		return 1;
+		return err;
 	}
 
 	mdelay(10);	/* Let the SET_ADDRESS settle */
 
+	return 0;
+}
+
+/*
+ * By the time we get here, the device has gotten a new device ID
+ * and is in the default state. We need to identify the thing and
+ * get the ball rolling..
+ *
+ * Returns 0 for success, != 0 for error.
+ */
+int usb_new_device(struct usb_device *dev)
+{
+	bool do_read = true;
+	int addr, err;
+	int tmp, ret;
+	ALLOC_CACHE_ALIGN_BUFFER(unsigned char, tmpbuf, USB_BUFSIZ);
+
+	/* We still haven't set the Address yet */
+	addr = dev->devnum;
+	dev->devnum = 0;
+
+	/*
+	 * XHCI needs to issue a Address device command to setup
+	 * proper device context structures, before it can interact
+	 * with the device. So a get_descriptor will fail before any
+	 * of that is done for XHCI unlike EHCI.
+	 */
+#ifndef CONFIG_USB_XHCI
+	do_read = false;
+#endif
+	ret = usb_prepare_device(dev, addr, do_read, dev->parent, dev->portnr);
+	if (ret)
+		return ret;
+
 	tmp = sizeof(dev->descriptor);
 
 	err = usb_get_descriptor(dev, USB_DT_DEVICE, 0,