diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/console/Kconfig | 25 | ||||
-rw-r--r-- | src/lib/usbdebug.c | 105 |
2 files changed, 128 insertions, 2 deletions
diff --git a/src/console/Kconfig b/src/console/Kconfig index 38f51e361b..9bfb6e9446 100644 --- a/src/console/Kconfig +++ b/src/console/Kconfig @@ -173,10 +173,11 @@ config USBDEBUG If unsure, say N. +if USBDEBUG + config USBDEBUG_HCD_INDEX int "Index for EHCI controller to use with usbdebug" default 0 - depends on USBDEBUG help Some boards have multiple EHCI controllers with possibly only one having the Debug Port capability on an external USB port. @@ -188,7 +189,6 @@ config USBDEBUG_HCD_INDEX config USBDEBUG_DEFAULT_PORT int "Default USB port to use as Debug Port" default 0 - depends on USBDEBUG help Selects which physical USB port usbdebug dongle is connected to. Setting of 0 means to scan possible ports starting from 1. @@ -202,6 +202,27 @@ config USBDEBUG_DEFAULT_PORT your mainboard) is highly board-specific, and you'll likely have to find out by trial-and-error. +choice + prompt "Type of dongle" + default USBDEBUG_DONGLE_STD + +config USBDEBUG_DONGLE_STD + bool "Net20DC or compatible" + +config USBDEBUG_DONGLE_BEAGLEBONE + bool "BeagleBone" + help + Use this to configure the USB hub on BeagleBone board. + +endchoice + +config USBDEBUG_OPTIONAL_HUB_PORT + int + default 2 if USBDEBUG_DONGLE_BEAGLEBONE + default 0 + +endif # USBDEBUG + # TODO: Deps? # TODO: Improve description. config ONBOARD_VGA_IS_PRIMARY 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: |