From patchwork Thu Aug 30 16:03:24 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lucas Stach X-Patchwork-Id: 180839 X-Patchwork-Delegate: marek.vasut@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 10FC92C0201 for ; Fri, 31 Aug 2012 02:04:31 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id D8588280B4; Thu, 30 Aug 2012 18:03:59 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 02s1l4ZaUq0d; Thu, 30 Aug 2012 18:03:59 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 33C7F280A6; Thu, 30 Aug 2012 18:03:41 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 03A8028095 for ; Thu, 30 Aug 2012 18:03:36 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id lTm+5759SfqH for ; Thu, 30 Aug 2012 18:03:35 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from km20343-01.keymachine.de (ns.km20343-01.keymachine.de [84.19.182.79]) by theia.denx.de (Postfix) with ESMTP id 5CAC928098 for ; Thu, 30 Aug 2012 18:03:30 +0200 (CEST) Received: from localhost.localdomain (f053086002.adsl.alicedsl.de [78.53.86.2]) by km20343-01.keymachine.de (Postfix) with ESMTPA id 2777D7D4422; Thu, 30 Aug 2012 18:03:30 +0200 (CEST) From: Lucas Stach To: u-boot@lists.denx.de Date: Thu, 30 Aug 2012 18:03:24 +0200 Message-Id: <1346342604-13355-5-git-send-email-dev@lynxeye.de> X-Mailer: git-send-email 1.7.11.4 In-Reply-To: <1346342604-13355-1-git-send-email-dev@lynxeye.de> References: <1346342604-13355-1-git-send-email-dev@lynxeye.de> MIME-Version: 1.0 Cc: Marek Vasut Subject: [U-Boot] =?utf-8?q?=5BPATCH_4/4=5D_usb=3A_add_support_for_multipl?= =?utf-8?q?e_usb_controllers?= X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de Allows to initialize more than one USB controller at once. Signed-off-by: Lucas Stach Reviewed-by: Marek Vasut --- common/cmd_usb.c | 16 +++++-- common/usb.c | 104 +++++++++++++++++++++++--------------------- common/usb_storage.c | 2 +- drivers/usb/eth/usb_ether.c | 2 +- 4 Dateien geändert, 68 Zeilen hinzugefügt(+), 56 Zeilen entfernt(-) diff --git a/common/cmd_usb.c b/common/cmd_usb.c index a8e3ae5..6cefc0c 100644 --- a/common/cmd_usb.c +++ b/common/cmd_usb.c @@ -517,8 +517,7 @@ int do_usb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) bootstage_mark_name(BOOTSTAGE_ID_USB_START, "usb_start"); usb_stop(); printf("(Re)start USB...\n"); - i = usb_init(); - if (i >= 0) { + if (usb_init() >= 0) { #ifdef CONFIG_USB_STORAGE /* try to recognize storage devices immediately */ usb_stor_curr_dev = usb_stor_scan(1); @@ -527,6 +526,9 @@ int do_usb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) /* try to recognize ethernet devices immediately */ usb_ether_curr_dev = usb_host_eth_scan(1); #endif +#ifdef CONFIG_USB_KEYBOARD + drv_usb_kbd_init(); +#endif } return 0; } @@ -553,8 +555,14 @@ int do_usb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) return 1; } if (strncmp(argv[1], "tree", 4) == 0) { - printf("\nDevice Tree:\n"); - usb_show_tree(usb_get_dev_index(0)); + puts("USB device tree:\n"); + for (i = 0; i < USB_MAX_DEVICE; i++) { + dev = usb_get_dev_index(i); + if (dev == NULL) + break; + if (dev->parent == NULL) + usb_show_tree(dev); + } return 0; } if (strncmp(argv[1], "inf", 3) == 0) { diff --git a/common/usb.c b/common/usb.c index e58b6f4..78a410d 100644 --- a/common/usb.c +++ b/common/usb.c @@ -72,45 +72,72 @@ static struct usb_device usb_dev[USB_MAX_DEVICE]; static int dev_index; -static int running; static int asynch_allowed; char usb_started; /* flag for the started/stopped USB status */ -void *ctrl; /* goes away in a following commit, but don't break bisect */ -/********************************************************************** - * some forward declerations... - */ -static void usb_scan_devices(void); +#ifndef CONFIG_USB_MAX_CONTROLLER_COUNT +#define CONFIG_USB_MAX_CONTROLLER_COUNT 1 +#endif /*************************************************************************** * Init USB Device */ - int usb_init(void) { - int result; + void *ctrl; + struct usb_device *dev; + int i, start_index = 0; - running = 0; dev_index = 0; asynch_allowed = 1; usb_hub_reset(); + + /* first make all devices unknown */ + for (i = 0; i < USB_MAX_DEVICE; i++) { + memset(&usb_dev[i], 0, sizeof(struct usb_device)); + usb_dev[i].devnum = -1; + } + /* init low_level USB */ - printf("USB: "); - result = usb_lowlevel_init(0, &ctrl); - /* if lowlevel init is OK, scan the bus for devices - * i.e. search HUBs and configure them */ - if (result == 0) { - printf("scanning bus for devices... "); - running = 1; - usb_scan_devices(); + for (i = 0; i < CONFIG_USB_MAX_CONTROLLER_COUNT; i++) { + /* init low_level USB */ + printf("USB%d: ", i); + if (usb_lowlevel_init(i, &ctrl)) { + puts("lowlevel init failed\n"); + continue; + } + /* + * lowlevel init is OK, now scan the bus for devices + * i.e. search HUBs and configure them + */ + start_index = dev_index; + printf("scanning bus %d for devices... ", i); + dev = usb_alloc_new_device(ctrl); + /* + * device 0 is always present + * (root hub, so let it analyze) + */ + if (dev) + usb_new_device(dev); + + if (start_index == dev_index) + puts("No USB Device found\n"); + else + printf("%d USB Device(s) found\n", + dev_index - start_index); + usb_started = 1; - return 0; - } else { - printf("Error, couldn't init Lowlevel part\n"); - usb_started = 0; + } + + USB_PRINTF("scan end\n"); + /* if we were not able to find at least one working bus, bail out */ + if (!usb_started) { + puts("USB error: all controllers failed lowlevel init\n"); return -1; } + + return 0; } /****************************************************************************** @@ -118,15 +145,18 @@ int usb_init(void) */ int usb_stop(void) { - int res = 0; + int i; if (usb_started) { asynch_allowed = 1; usb_started = 0; usb_hub_reset(); - res = usb_lowlevel_stop(0); + + for (i = 0; i < CONFIG_USB_MAX_CONTROLLER_COUNT; i++) + usb_lowlevel_stop(i); } - return res; + + return 0; } /* @@ -751,7 +781,6 @@ struct usb_device *usb_get_dev_index(int index) return &usb_dev[index]; } - /* returns a pointer of a new device structure or NULL, if * no device struct is available */ @@ -947,29 +976,4 @@ int usb_new_device(struct usb_device *dev) return 0; } -/* build device Tree */ -static void usb_scan_devices(void) -{ - int i; - struct usb_device *dev; - - /* first make all devices unknown */ - for (i = 0; i < USB_MAX_DEVICE; i++) { - memset(&usb_dev[i], 0, sizeof(struct usb_device)); - usb_dev[i].devnum = -1; - } - dev_index = 0; - /* device 0 is always present (root hub, so let it analyze) */ - dev = usb_alloc_new_device(ctrl); - if (usb_new_device(dev)) - printf("No USB Device found\n"); - else - printf("%d USB Device(s) found\n", dev_index); - /* insert "driver" if possible */ -#ifdef CONFIG_USB_KEYBOARD - drv_usb_kbd_init(); -#endif - USB_PRINTF("scan end\n"); -} - /* EOF */ diff --git a/common/usb_storage.c b/common/usb_storage.c index 4aeed82..950451e 100644 --- a/common/usb_storage.c +++ b/common/usb_storage.c @@ -244,7 +244,7 @@ int usb_stor_scan(int mode) struct usb_device *dev; if (mode == 1) - printf(" scanning bus for storage devices... "); + printf(" scanning usb for storage devices... "); usb_disable_asynch(1); /* asynch transfer not allowed */ diff --git a/drivers/usb/eth/usb_ether.c b/drivers/usb/eth/usb_ether.c index 6cad6c8..f361e8b 100644 --- a/drivers/usb/eth/usb_ether.c +++ b/drivers/usb/eth/usb_ether.c @@ -123,7 +123,7 @@ int usb_host_eth_scan(int mode) if (mode == 1) - printf(" scanning bus for ethernet devices... "); + printf(" scanning usb for ethernet devices... "); old_async = usb_disable_asynch(1); /* asynch transfer not allowed */