summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorKyösti Mälkki <kyosti.malkki@gmail.com>2013-08-23 23:33:16 +0300
committerKyösti Mälkki <kyosti.malkki@gmail.com>2013-09-20 14:22:29 +0200
commitd2dac0a7d62c89b24eae9de17bcfdde1aea7a5b3 (patch)
tree76118ae4f125391256d9ba09382cb75e784036bc /src/lib
parent8f485dee0d38c1c5f1a29fa8840602774ef5f63d (diff)
usbdebug: Allow an USB hub on the debug dongle
Some development kits with USB 2.0 HS OTG have an USB hub instead of being directly connected to the USB host/device controller. Send the necessary initialisation sequence, using HUB CLASS requests of PORT_POWER and PORT_RESET to enable a pre-selected port number where a device supporting debug descriptor is located. This also adds the Kconfig option for BeagleBone. Change-Id: I7a5d0ba0962a9ca06bf3196232ed4a03bdfb2b06 Signed-off-by: Kyösti Mälkki <kyosti.malkki@gmail.com> Reviewed-on: http://review.coreboot.org/3925 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <patrick@georgi-clan.de> Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/usbdebug.c105
1 files changed, 105 insertions, 0 deletions
diff --git a/src/lib/usbdebug.c b/src/lib/usbdebug.c
index 7a8402dfa3..27097c7c9b 100644
--- a/src/lib/usbdebug.c
+++ b/src/lib/usbdebug.c
@@ -483,6 +483,102 @@ static int ehci_wait_for_port(struct ehci_regs *ehci_regs, int port)
return -1; //-ENOTCONN;
}
+#define USB_HUB_PORT_CONNECTION 0
+#define USB_HUB_PORT_ENABLED 1
+#define USB_HUB_PORT_RESET 4
+#define USB_HUB_PORT_POWER 8
+#define USB_HUB_C_PORT_CONNECTION 16
+#define USB_HUB_C_PORT_RESET 20
+
+#if CONFIG_USBDEBUG_OPTIONAL_HUB_PORT
+
+static int hub_port_status(const char * buf, int feature)
+{
+ return !!(buf[feature>>3] & (1<<(feature&0x7)));
+}
+
+static int dbgp_hub_enable(struct ehci_dbg_port *ehci_debug, unsigned int port)
+{
+ const u8 hub_addr = USB_DEBUG_DEVNUM-1;
+ char status[8];
+ int ret, loop;
+
+ /* Move hub to address 126. */
+ ret = dbgp_control_msg(ehci_debug, 0,
+ USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE,
+ USB_REQ_SET_ADDRESS, hub_addr, 0, NULL, 0);
+ if (ret < 0)
+ goto err;
+
+ /* Enter configured state on hub. */
+ ret = dbgp_control_msg(ehci_debug, hub_addr,
+ USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE,
+ USB_REQ_SET_CONFIGURATION, 1, 0, NULL, 0);
+ if (ret < 0)
+ goto err;
+
+ /* Set PORT_POWER, poll for PORT_CONNECTION. */
+ ret = dbgp_control_msg(ehci_debug, hub_addr,
+ USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_OTHER,
+ USB_REQ_SET_FEATURE, USB_HUB_PORT_POWER, port, NULL, 0);
+ if (ret < 0)
+ goto err;
+
+ loop = 100;
+ do {
+ dbgp_mdelay(10);
+ ret = dbgp_control_msg(ehci_debug, hub_addr,
+ USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_OTHER,
+ USB_REQ_GET_STATUS, 0, port, status, 4);
+ if (ret < 0)
+ goto err;
+ if (hub_port_status(status, USB_HUB_PORT_CONNECTION))
+ break;
+ } while (--loop);
+ if (! loop)
+ goto err;
+
+ ret = dbgp_control_msg(ehci_debug, hub_addr,
+ USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_OTHER,
+ USB_REQ_CLEAR_FEATURE, USB_HUB_C_PORT_CONNECTION, port, NULL, 0);
+ if (ret < 0)
+ goto err;
+
+
+ /* Set PORT_RESET, poll for C_PORT_RESET. */
+ ret = dbgp_control_msg(ehci_debug, hub_addr,
+ USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_OTHER,
+ USB_REQ_SET_FEATURE, USB_HUB_PORT_RESET, port, NULL, 0);
+ if (ret < 0)
+ goto err;
+
+ loop = 100;
+ do {
+ dbgp_mdelay(10);
+ ret = dbgp_control_msg(ehci_debug, hub_addr,
+ USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_OTHER,
+ USB_REQ_GET_STATUS, 0, port, status, 4);
+ if (ret < 0)
+ goto err;
+ if (hub_port_status(status, USB_HUB_C_PORT_RESET))
+ break;
+ } while (--loop);
+ if (! loop)
+ goto err;
+
+ ret = dbgp_control_msg(ehci_debug, hub_addr,
+ USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_OTHER,
+ USB_REQ_CLEAR_FEATURE, USB_HUB_C_PORT_RESET, port, NULL, 0);
+ if (ret < 0)
+ goto err;
+
+ if (hub_port_status(status, USB_HUB_PORT_ENABLED))
+ return 0;
+err:
+ return -1;
+}
+#endif /* CONFIG_USBDEBUG_OPTIONAL_HUB_PORT */
+
#if defined(__PRE_RAM__) || !CONFIG_EARLY_CONSOLE
static void enable_usbdebug(void)
{
@@ -640,6 +736,15 @@ try_next_port:
dbgp_mdelay(100);
+#if CONFIG_USBDEBUG_OPTIONAL_HUB_PORT
+ ret = dbgp_hub_enable(ehci_debug, CONFIG_USBDEBUG_OPTIONAL_HUB_PORT);
+ if (ret < 0) {
+ dprintk(BIOS_INFO, "Could not enable USB hub on debug port.\n");
+ ret = -6;
+ goto err;
+ }
+#endif
+
/* Find the debug device and make it device number 127 */
devnum = 0;
debug_dev_retry: