Patchwork [U-Boot,v4] usb: new board-specific USB init interface

login
register
mail settings
Submitter Mateusz Zalega
Date Sept. 10, 2013, 3:10 p.m.
Message ID <1378825807-9471-1-git-send-email-m.zalega@samsung.com>
Download mbox | patch
Permalink /patch/273911/
State Superseded
Delegated to: Marek Vasut
Headers show

Comments

Mateusz Zalega - Sept. 10, 2013, 3:10 p.m.
This commit unifies board-specific USB initialization implementations
under one symbol (usb_board_init), declaration of which is available in
usb.h.

New API allows selective initialization of USB controllers whenever needed.

Signed-off-by: Mateusz Zalega <m.zalega@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>
Cc: Marek Vasut <marex@denx.de>
Cc: Lukasz Majewski <l.majewski@samsung.com>
Change-Id: Ia78a1378f30a55dd14598c9a1a1b4b8a762e2cd8
---
Changes since RFC (v1):
- NVIDIA Tegra doesn't postpone its USB init anymore
- board_usb_init()'s sole argument name was shortened
- networking code comment style (/* blurb...) dropped
- squashed RFC changes so that patch won't break bisect

v2 changes:
- commit message fixup

v3 changes:
- added 'index' argument to perform selective port initialization

v4 changes:
- board_usb_init_fail() renamed to board_usb_cleanup()
- board_usb_cleanup() accepts controller index and init type
- DFU and UMS commands don't init all USB controllers anymore
- minor related fixes & refactorization
---
 arch/arm/include/asm/arch-tegra/usb.h         |  3 +-
 arch/arm/include/asm/ehci-omap.h              |  4 +--
 board/amcc/canyonlands/canyonlands.c          |  5 +--
 board/balloon3/balloon3.c                     |  7 +++--
 board/compulab/cm_t35/cm_t35.c                |  2 +-
 board/esd/apc405/apc405.c                     |  8 ++---
 board/esd/pmc440/pmc440.c                     |  8 ++---
 board/htkw/mcx/mcx.c                          |  2 +-
 board/icpdas/lp8x4x/lp8x4x.c                  |  7 +++--
 board/nvidia/common/board.c                   |  4 ++-
 board/samsung/trats/trats.c                   |  5 +--
 board/technexion/twister/twister.c            |  2 +-
 board/teejet/mt_ventoux/mt_ventoux.c          |  2 +-
 board/ti/beagle/beagle.c                      |  2 +-
 board/ti/omap5_uevm/evm.c                     |  2 +-
 board/ti/panda/panda.c                        |  2 +-
 board/toradex/colibri_pxa270/colibri_pxa270.c |  7 +++--
 board/trizepsiv/conxs.c                       |  7 +++--
 board/vpac270/vpac270.c                       |  7 +++--
 common/cmd_dfu.c                              | 31 +++++++++++--------
 common/cmd_usb_mass_storage.c                 | 44 ++++++++++++++-------------
 common/usb.c                                  |  5 +++
 drivers/dfu/dfu.c                             |  2 +-
 drivers/usb/host/ehci-omap.c                  | 12 ++------
 drivers/usb/host/ehci-tegra.c                 |  2 +-
 drivers/usb/host/ohci-hcd.c                   |  4 +--
 drivers/usb/host/ohci.h                       | 11 +++----
 include/g_dnl.h                               |  2 --
 include/usb.h                                 | 30 +++++++++++++++++-
 include/usb_mass_storage.h                    | 13 +++-----
 30 files changed, 138 insertions(+), 104 deletions(-)
Marek Vasut - Sept. 15, 2013, 4:44 p.m.
Dear Mateusz Zalega,

> This commit unifies board-specific USB initialization implementations
> under one symbol (usb_board_init), declaration of which is available in
> usb.h.
> 
> New API allows selective initialization of USB controllers whenever needed.
> 
> Signed-off-by: Mateusz Zalega <m.zalega@samsung.com>
> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
> Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>
> Cc: Marek Vasut <marex@denx.de>
> Cc: Lukasz Majewski <l.majewski@samsung.com>
> Change-Id: Ia78a1378f30a55dd14598c9a1a1b4b8a762e2cd8
> ---
> Changes since RFC (v1):
> - NVIDIA Tegra doesn't postpone its USB init anymore
> - board_usb_init()'s sole argument name was shortened
> - networking code comment style (/* blurb...) dropped
> - squashed RFC changes so that patch won't break bisect
> 
> v2 changes:
> - commit message fixup
> 
> v3 changes:
> - added 'index' argument to perform selective port initialization
> 
> v4 changes:
> - board_usb_init_fail() renamed to board_usb_cleanup()
> - board_usb_cleanup() accepts controller index and init type
> - DFU and UMS commands don't init all USB controllers anymore
> - minor related fixes & refactorization
> ---

Looks pretty much OK. Did you test it on a few platforms? I'd like to apply this 
for -next anyway, since the MW is long closed.

Best regards,
Marek Vasut
Mateusz Zalega - Sept. 16, 2013, 9:10 a.m.
On 09/15/13 18:44, Marek Vasut wrote:
> Dear Mateusz Zalega,
> 
>> This commit unifies board-specific USB initialization implementations
>> under one symbol (usb_board_init), declaration of which is available in
>> usb.h.
>>
>> New API allows selective initialization of USB controllers whenever needed.
>>
>> Signed-off-by: Mateusz Zalega <m.zalega@samsung.com>
>> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
>> Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>
>> Cc: Marek Vasut <marex@denx.de>
>> Cc: Lukasz Majewski <l.majewski@samsung.com>
>> Change-Id: Ia78a1378f30a55dd14598c9a1a1b4b8a762e2cd8
>> ---
>> Changes since RFC (v1):
>> - NVIDIA Tegra doesn't postpone its USB init anymore
>> - board_usb_init()'s sole argument name was shortened
>> - networking code comment style (/* blurb...) dropped
>> - squashed RFC changes so that patch won't break bisect
>>
>> v2 changes:
>> - commit message fixup
>>
>> v3 changes:
>> - added 'index' argument to perform selective port initialization
>>
>> v4 changes:
>> - board_usb_init_fail() renamed to board_usb_cleanup()
>> - board_usb_cleanup() accepts controller index and init type
>> - DFU and UMS commands don't init all USB controllers anymore
>> - minor related fixes & refactorization
>> ---
> 
> Looks pretty much OK. Did you test it on a few platforms? I'd like to apply this 
> for -next anyway, since the MW is long closed.
> 
> Best regards,
> Marek Vasut

I've ran MAKEALL on all arm boards and tested it on Samsung Goni.
Everything seems to be OK.
Marek Vasut - Sept. 16, 2013, 2:24 p.m.
Dear Mateusz Zalega,

> On 09/15/13 18:44, Marek Vasut wrote:
> > Dear Mateusz Zalega,
> > 
> >> This commit unifies board-specific USB initialization implementations
> >> under one symbol (usb_board_init), declaration of which is available in
> >> usb.h.
> >> 
> >> New API allows selective initialization of USB controllers whenever
> >> needed.
> >> 
> >> Signed-off-by: Mateusz Zalega <m.zalega@samsung.com>
> >> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
> >> Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>
> >> Cc: Marek Vasut <marex@denx.de>
> >> Cc: Lukasz Majewski <l.majewski@samsung.com>
> >> Change-Id: Ia78a1378f30a55dd14598c9a1a1b4b8a762e2cd8
> >> ---
> >> Changes since RFC (v1):
> >> - NVIDIA Tegra doesn't postpone its USB init anymore
> >> - board_usb_init()'s sole argument name was shortened
> >> - networking code comment style (/* blurb...) dropped
> >> - squashed RFC changes so that patch won't break bisect
> >> 
> >> v2 changes:
> >> - commit message fixup
> >> 
> >> v3 changes:
> >> - added 'index' argument to perform selective port initialization
> >> 
> >> v4 changes:
> >> - board_usb_init_fail() renamed to board_usb_cleanup()
> >> - board_usb_cleanup() accepts controller index and init type
> >> - DFU and UMS commands don't init all USB controllers anymore
> >> - minor related fixes & refactorization
> >> ---
> > 
> > Looks pretty much OK. Did you test it on a few platforms? I'd like to
> > apply this for -next anyway, since the MW is long closed.
> > 
> > Best regards,
> > Marek Vasut
> 
> I've ran MAKEALL on all arm boards and tested it on Samsung Goni.
> Everything seems to be OK.

I will also have to run this on PPC at least, since it might break there too.

Best regards,
Marek Vasut
Igor Grinberg - Sept. 17, 2013, 4:11 p.m.
Hello,

On 09/10/2013 06:10 PM, Mateusz Zalega wrote:
> This commit unifies board-specific USB initialization implementations
> under one symbol (usb_board_init), declaration of which is available in
> usb.h.
> 
> New API allows selective initialization of USB controllers whenever needed.
> 
> Signed-off-by: Mateusz Zalega <m.zalega@samsung.com>
> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
> Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>
> Cc: Marek Vasut <marex@denx.de>
> Cc: Lukasz Majewski <l.majewski@samsung.com>

I think, you should Cc respective board maintainers as well.

Acked-by: Igor Grinberg <grinberg@compulab.co.il>

> Change-Id: Ia78a1378f30a55dd14598c9a1a1b4b8a762e2cd8
> ---
> Changes since RFC (v1):
> - NVIDIA Tegra doesn't postpone its USB init anymore
> - board_usb_init()'s sole argument name was shortened
> - networking code comment style (/* blurb...) dropped
> - squashed RFC changes so that patch won't break bisect
> 
> v2 changes:
> - commit message fixup
> 
> v3 changes:
> - added 'index' argument to perform selective port initialization
> 
> v4 changes:
> - board_usb_init_fail() renamed to board_usb_cleanup()
> - board_usb_cleanup() accepts controller index and init type
> - DFU and UMS commands don't init all USB controllers anymore
> - minor related fixes & refactorization
> ---
>  arch/arm/include/asm/arch-tegra/usb.h         |  3 +-
>  arch/arm/include/asm/ehci-omap.h              |  4 +--
>  board/amcc/canyonlands/canyonlands.c          |  5 +--
>  board/balloon3/balloon3.c                     |  7 +++--
>  board/compulab/cm_t35/cm_t35.c                |  2 +-
>  board/esd/apc405/apc405.c                     |  8 ++---
>  board/esd/pmc440/pmc440.c                     |  8 ++---
>  board/htkw/mcx/mcx.c                          |  2 +-
>  board/icpdas/lp8x4x/lp8x4x.c                  |  7 +++--
>  board/nvidia/common/board.c                   |  4 ++-
>  board/samsung/trats/trats.c                   |  5 +--
>  board/technexion/twister/twister.c            |  2 +-
>  board/teejet/mt_ventoux/mt_ventoux.c          |  2 +-
>  board/ti/beagle/beagle.c                      |  2 +-
>  board/ti/omap5_uevm/evm.c                     |  2 +-
>  board/ti/panda/panda.c                        |  2 +-
>  board/toradex/colibri_pxa270/colibri_pxa270.c |  7 +++--
>  board/trizepsiv/conxs.c                       |  7 +++--
>  board/vpac270/vpac270.c                       |  7 +++--
>  common/cmd_dfu.c                              | 31 +++++++++++--------
>  common/cmd_usb_mass_storage.c                 | 44 ++++++++++++++-------------
>  common/usb.c                                  |  5 +++
>  drivers/dfu/dfu.c                             |  2 +-
>  drivers/usb/host/ehci-omap.c                  | 12 ++------
>  drivers/usb/host/ehci-tegra.c                 |  2 +-
>  drivers/usb/host/ohci-hcd.c                   |  4 +--
>  drivers/usb/host/ohci.h                       | 11 +++----
>  include/g_dnl.h                               |  2 --
>  include/usb.h                                 | 30 +++++++++++++++++-
>  include/usb_mass_storage.h                    | 13 +++-----
>  30 files changed, 138 insertions(+), 104 deletions(-)
> 
> diff --git a/arch/arm/include/asm/arch-tegra/usb.h b/arch/arm/include/asm/arch-tegra/usb.h
> index f66257c..a1efd07 100644
> --- a/arch/arm/include/asm/arch-tegra/usb.h
> +++ b/arch/arm/include/asm/arch-tegra/usb.h
> @@ -131,8 +131,7 @@
>  /* USB3_IF_USB_PHY_VBUS_SENSORS_0 */
>  #define VBUS_VLD_STS			(1 << 26)
>  
> -
>  /* Setup USB on the board */
> -int board_usb_init(const void *blob);
> +int usb_process_devicetree(const void *blob);
>  
>  #endif	/* _TEGRA_USB_H_ */
> diff --git a/arch/arm/include/asm/ehci-omap.h b/arch/arm/include/asm/ehci-omap.h
> index ac83a53..c7bca05 100644
> --- a/arch/arm/include/asm/ehci-omap.h
> +++ b/arch/arm/include/asm/ehci-omap.h
> @@ -145,8 +145,8 @@ struct omap_ehci {
>  struct ehci_hccr;
>  struct ehci_hcor;
>  
> -int omap_ehci_hcd_init(struct omap_usbhs_board_data *usbhs_pdata,
> -		struct ehci_hccr **hccr, struct ehci_hcor **hcor);
> +int omap_ehci_hcd_init(int index, struct omap_usbhs_board_data *usbhs_pdata,
> +		       struct ehci_hccr **hccr, struct ehci_hcor **hcor);
>  int omap_ehci_hcd_stop(void);
>  
>  #endif /* _OMAP_COMMON_EHCI_H_ */
> diff --git a/board/amcc/canyonlands/canyonlands.c b/board/amcc/canyonlands/canyonlands.c
> index cc36f45..395095e 100644
> --- a/board/amcc/canyonlands/canyonlands.c
> +++ b/board/amcc/canyonlands/canyonlands.c
> @@ -16,6 +16,7 @@
>  #include <asm/4xx_pcie.h>
>  #include <asm/ppc4xx-gpio.h>
>  #include <asm/errno.h>
> +#include <usb.h>
>  
>  extern flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS]; /* info for FLASH chips */
>  
> @@ -188,7 +189,7 @@ int board_early_init_f(void)
>  }
>  
>  #if defined(CONFIG_USB_OHCI_NEW) && defined(CONFIG_SYS_USB_OHCI_BOARD_INIT)
> -int usb_board_init(void)
> +int board_usb_init(int index, enum board_usb_init_type init)
>  {
>  	struct board_bcsr *bcsr_data =
>  		(struct board_bcsr *)CONFIG_SYS_BCSR_BASE;
> @@ -229,7 +230,7 @@ int usb_board_stop(void)
>  	return 0;
>  }
>  
> -int usb_board_init_fail(void)
> +int board_usb_cleanup(int index, enum board_usb_init_type init)
>  {
>  	return usb_board_stop();
>  }
> diff --git a/board/balloon3/balloon3.c b/board/balloon3/balloon3.c
> index ecbac16..19c0e02 100644
> --- a/board/balloon3/balloon3.c
> +++ b/board/balloon3/balloon3.c
> @@ -13,6 +13,7 @@
>  #include <asm/io.h>
>  #include <spartan3.h>
>  #include <command.h>
> +#include <usb.h>
>  
>  DECLARE_GLOBAL_DATA_PTR;
>  
> @@ -59,7 +60,7 @@ void dram_init_banksize(void)
>  }
>  
>  #ifdef	CONFIG_CMD_USB
> -int usb_board_init(void)
> +int board_usb_init(int index, enum board_usb_init_type init)
>  {
>  	writel((readl(UHCHR) | UHCHR_PCPL | UHCHR_PSPL) &
>  		~(UHCHR_SSEP0 | UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSE),
> @@ -90,9 +91,9 @@ int usb_board_init(void)
>  	return 0;
>  }
>  
> -void usb_board_init_fail(void)
> +int board_usb_cleanup(int index, enum board_usb_init_type init)
>  {
> -	return;
> +	return 0;
>  }
>  
>  void usb_board_stop(void)
> diff --git a/board/compulab/cm_t35/cm_t35.c b/board/compulab/cm_t35/cm_t35.c
> index 3caa5be..7626abc 100644
> --- a/board/compulab/cm_t35/cm_t35.c
> +++ b/board/compulab/cm_t35/cm_t35.c
> @@ -591,7 +591,7 @@ int ehci_hcd_init(int index, struct ehci_hccr **hccr, struct ehci_hcor **hcor)
>  	twl4030_i2c_write_u8(TWL4030_CHIP_GPIO, offset, 0xC0);
>  	udelay(1);
>  
> -	return omap_ehci_hcd_init(&usbhs_bdata, hccr, hcor);
> +	return omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor);
>  }
>  
>  int ehci_hcd_stop(void)
> diff --git a/board/esd/apc405/apc405.c b/board/esd/apc405/apc405.c
> index f13f088..79341f5 100644
> --- a/board/esd/apc405/apc405.c
> +++ b/board/esd/apc405/apc405.c
> @@ -17,6 +17,7 @@
>  #include <mtd/cfi_flash.h>
>  #include <asm/4xx_pci.h>
>  #include <pci.h>
> +#include <usb.h>
>  
>  DECLARE_GLOBAL_DATA_PTR;
>  
> @@ -428,7 +429,7 @@ void reset_phy(void)
>  }
>  
>  #if defined(CONFIG_USB_OHCI_NEW) && defined(CONFIG_SYS_USB_OHCI_BOARD_INIT)
> -int usb_board_init(void)
> +int board_usb_init(int index, enum board_usb_init_type init)
>  {
>  	return 0;
>  }
> @@ -453,9 +454,8 @@ int usb_board_stop(void)
>  	return 0;
>  }
>  
> -int usb_board_init_fail(void)
> +int board_usb_cleanup(int index, enum board_usb_init_type init)
>  {
> -	usb_board_stop();
> -	return 0;
> +	return usb_board_stop();
>  }
>  #endif /* defined(CONFIG_USB_OHCI) && defined(CONFIG_SYS_USB_OHCI_BOARD_INIT) */
> diff --git a/board/esd/pmc440/pmc440.c b/board/esd/pmc440/pmc440.c
> index 549b3b7..44b86da 100644
> --- a/board/esd/pmc440/pmc440.c
> +++ b/board/esd/pmc440/pmc440.c
> @@ -27,6 +27,7 @@
>  #endif
>  #include <serial.h>
>  #include <asm/4xx_pci.h>
> +#include <usb.h>
>  
>  #include "fpga.h"
>  #include "pmc440.h"
> @@ -821,7 +822,7 @@ int bootstrap_eeprom_read (unsigned dev_addr, unsigned offset,
>  }
>  
>  #if defined(CONFIG_USB_OHCI_NEW) && defined(CONFIG_SYS_USB_OHCI_BOARD_INIT)
> -int usb_board_init(void)
> +int board_usb_init(int index, enum board_usb_init_type init)
>  {
>  	char *act = getenv("usbact");
>  	int i;
> @@ -845,10 +846,9 @@ int usb_board_stop(void)
>  	return 0;
>  }
>  
> -int usb_board_init_fail(void)
> +int board_usb_cleanup(int index, enum board_usb_init_type init)
>  {
> -	usb_board_stop();
> -	return 0;
> +	return usb_board_stop();
>  }
>  #endif /* defined(CONFIG_USB_OHCI) && defined(CONFIG_SYS_USB_OHCI_BOARD_INIT) */
>  
> diff --git a/board/htkw/mcx/mcx.c b/board/htkw/mcx/mcx.c
> index 653d7ea..6f85b47 100644
> --- a/board/htkw/mcx/mcx.c
> +++ b/board/htkw/mcx/mcx.c
> @@ -42,7 +42,7 @@ static struct omap_usbhs_board_data usbhs_bdata = {
>  
>  int ehci_hcd_init(int index, struct ehci_hccr **hccr, struct ehci_hcor **hcor)
>  {
> -	return omap_ehci_hcd_init(&usbhs_bdata, hccr, hcor);
> +	return omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor);
>  }
>  
>  int ehci_hcd_stop(int index)
> diff --git a/board/icpdas/lp8x4x/lp8x4x.c b/board/icpdas/lp8x4x/lp8x4x.c
> index 1b68ef3..a96bed6 100644
> --- a/board/icpdas/lp8x4x/lp8x4x.c
> +++ b/board/icpdas/lp8x4x/lp8x4x.c
> @@ -15,6 +15,7 @@
>  #include <netdev.h>
>  #include <serial.h>
>  #include <asm/io.h>
> +#include <usb.h>
>  
>  DECLARE_GLOBAL_DATA_PTR;
>  
> @@ -58,7 +59,7 @@ int board_mmc_init(bd_t *bis)
>  #endif
>  
>  #ifdef	CONFIG_CMD_USB
> -int usb_board_init(void)
> +int board_usb_init(int index, enum board_usb_init_type init)
>  {
>  	writel((UHCHR | UHCHR_PCPL | UHCHR_PSPL) &
>  		~(UHCHR_SSEP0 | UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSE),
> @@ -89,9 +90,9 @@ int usb_board_init(void)
>  	return 0;
>  }
>  
> -void usb_board_init_fail(void)
> +int board_usb_cleanup(int index, enum board_usb_init_type init)
>  {
> -	return;
> +	return 0;
>  }
>  
>  void usb_board_stop(void)
> diff --git a/board/nvidia/common/board.c b/board/nvidia/common/board.c
> index 126e56e..1972527 100644
> --- a/board/nvidia/common/board.c
> +++ b/board/nvidia/common/board.c
> @@ -32,6 +32,7 @@
>  #ifdef CONFIG_USB_EHCI_TEGRA
>  #include <asm/arch-tegra/usb.h>
>  #include <asm/arch/usb.h>
> +#include <usb.h>
>  #endif
>  #ifdef CONFIG_TEGRA_MMC
>  #include <asm/arch-tegra/tegra_mmc.h>
> @@ -153,8 +154,9 @@ int board_init(void)
>  
>  #ifdef CONFIG_USB_EHCI_TEGRA
>  	pin_mux_usb();
> -	board_usb_init(gd->fdt_blob);
> +	usb_process_devicetree(gd->fdt_blob);
>  #endif
> +
>  #ifdef CONFIG_LCD
>  	tegra_lcd_check_next_stage(gd->fdt_blob, 0);
>  #endif
> diff --git a/board/samsung/trats/trats.c b/board/samsung/trats/trats.c
> index 7f61d17..58d925f 100644
> --- a/board/samsung/trats/trats.c
> +++ b/board/samsung/trats/trats.c
> @@ -26,6 +26,7 @@
>  #include <power/max8997_muic.h>
>  #include <power/battery.h>
>  #include <power/max17042_fg.h>
> +#include <usb.h>
>  #include <usb_mass_storage.h>
>  
>  #include "setup.h"
> @@ -495,10 +496,10 @@ struct s3c_plat_otg_data s5pc210_otg_data = {
>  	.usb_flags	= PHY0_SLEEP,
>  };
>  
> -void board_usb_init(void)
> +int board_usb_init(int index, enum board_usb_init_type init)
>  {
>  	debug("USB_udc_probe\n");
> -	s3c_udc_probe(&s5pc210_otg_data);
> +	return s3c_udc_probe(&s5pc210_otg_data);
>  }
>  #endif
>  
> diff --git a/board/technexion/twister/twister.c b/board/technexion/twister/twister.c
> index cd91d8f..6f2ff55 100644
> --- a/board/technexion/twister/twister.c
> +++ b/board/technexion/twister/twister.c
> @@ -53,7 +53,7 @@ static struct omap_usbhs_board_data usbhs_bdata = {
>  
>  int ehci_hcd_init(int index, struct ehci_hccr **hccr, struct ehci_hcor **hcor)
>  {
> -	return omap_ehci_hcd_init(&usbhs_bdata, hccr, hcor);
> +	return omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor);
>  }
>  
>  int ehci_hcd_stop(int index)
> diff --git a/board/teejet/mt_ventoux/mt_ventoux.c b/board/teejet/mt_ventoux/mt_ventoux.c
> index b4e01d1..df873f5 100644
> --- a/board/teejet/mt_ventoux/mt_ventoux.c
> +++ b/board/teejet/mt_ventoux/mt_ventoux.c
> @@ -104,7 +104,7 @@ static struct omap_usbhs_board_data usbhs_bdata = {
>  
>  int ehci_hcd_init(int index, struct ehci_hccr **hccr, struct ehci_hcor **hcor)
>  {
> -	return omap_ehci_hcd_init(&usbhs_bdata, hccr, hcor);
> +	return omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor);
>  }
>  
>  int ehci_hcd_stop(int index)
> diff --git a/board/ti/beagle/beagle.c b/board/ti/beagle/beagle.c
> index 62e9bea..41fed54 100644
> --- a/board/ti/beagle/beagle.c
> +++ b/board/ti/beagle/beagle.c
> @@ -523,7 +523,7 @@ static struct omap_usbhs_board_data usbhs_bdata = {
>  
>  int ehci_hcd_init(int index, struct ehci_hccr **hccr, struct ehci_hcor **hcor)
>  {
> -	return omap_ehci_hcd_init(&usbhs_bdata, hccr, hcor);
> +	return omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor);
>  }
>  
>  int ehci_hcd_stop(int index)
> diff --git a/board/ti/omap5_uevm/evm.c b/board/ti/omap5_uevm/evm.c
> index 4706330..3ae0671 100644
> --- a/board/ti/omap5_uevm/evm.c
> +++ b/board/ti/omap5_uevm/evm.c
> @@ -176,7 +176,7 @@ int ehci_hcd_init(int index, struct ehci_hccr **hccr, struct ehci_hcor **hcor)
>  	auxclk |= AUXCLK_ENABLE_MASK;
>  	writel(auxclk, (*prcm)->scrm_auxclk1);
>  
> -	ret = omap_ehci_hcd_init(&usbhs_bdata, hccr, hcor);
> +	ret = omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor);
>  	if (ret < 0) {
>  		puts("Failed to initialize ehci\n");
>  		return ret;
> diff --git a/board/ti/panda/panda.c b/board/ti/panda/panda.c
> index e838ffd..fe7a437 100644
> --- a/board/ti/panda/panda.c
> +++ b/board/ti/panda/panda.c
> @@ -263,7 +263,7 @@ int ehci_hcd_init(int index, struct ehci_hccr **hccr, struct ehci_hcor **hcor)
>  	utmi_clk |= HSUSBHOST_CLKCTRL_CLKSEL_UTMI_P1_MASK;
>  	sr32((void *)CM_L3INIT_HSUSBHOST_CLKCTRL, 0, 32, utmi_clk);
>  
> -	ret = omap_ehci_hcd_init(&usbhs_bdata, hccr, hcor);
> +	ret = omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor);
>  	if (ret < 0)
>  		return ret;
>  
> diff --git a/board/toradex/colibri_pxa270/colibri_pxa270.c b/board/toradex/colibri_pxa270/colibri_pxa270.c
> index c1e2562..b70c1e3 100644
> --- a/board/toradex/colibri_pxa270/colibri_pxa270.c
> +++ b/board/toradex/colibri_pxa270/colibri_pxa270.c
> @@ -13,6 +13,7 @@
>  #include <netdev.h>
>  #include <asm/io.h>
>  #include <serial.h>
> +#include <usb.h>
>  
>  DECLARE_GLOBAL_DATA_PTR;
>  
> @@ -39,7 +40,7 @@ int dram_init(void)
>  }
>  
>  #ifdef	CONFIG_CMD_USB
> -int usb_board_init(void)
> +int board_usb_init(int index, enum board_usb_init_type init)
>  {
>  	writel((readl(UHCHR) | UHCHR_PCPL | UHCHR_PSPL) &
>  		~(UHCHR_SSEP0 | UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSE),
> @@ -70,9 +71,9 @@ int usb_board_init(void)
>  	return 0;
>  }
>  
> -void usb_board_init_fail(void)
> +int board_usb_cleanup(int index, enum board_usb_init_type init)
>  {
> -	return;
> +	return 0;
>  }
>  
>  void usb_board_stop(void)
> diff --git a/board/trizepsiv/conxs.c b/board/trizepsiv/conxs.c
> index c0c318f..830d5a8 100644
> --- a/board/trizepsiv/conxs.c
> +++ b/board/trizepsiv/conxs.c
> @@ -21,6 +21,7 @@
>  #include <asm/arch/regs-mmc.h>
>  #include <netdev.h>
>  #include <asm/io.h>
> +#include <usb.h>
>  
>  DECLARE_GLOBAL_DATA_PTR;
>  
> @@ -42,7 +43,7 @@ extern struct serial_device serial_stuart_device;
>   * Miscelaneous platform dependent initialisations
>   */
>  
> -int usb_board_init(void)
> +int board_usb_init(int index, enum board_usb_init_type init)
>  {
>  	writel((readl(UHCHR) | UHCHR_PCPL | UHCHR_PSPL) &
>  		~(UHCHR_SSEP0 | UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSE),
> @@ -69,9 +70,9 @@ int usb_board_init(void)
>  	return 0;
>  }
>  
> -void usb_board_init_fail(void)
> +int board_usb_cleanup(int index, enum board_usb_init_type init)
>  {
> -	return;
> +	return 0;
>  }
>  
>  void usb_board_stop(void)
> diff --git a/board/vpac270/vpac270.c b/board/vpac270/vpac270.c
> index 616736f..fab4636 100644
> --- a/board/vpac270/vpac270.c
> +++ b/board/vpac270/vpac270.c
> @@ -13,6 +13,7 @@
>  #include <netdev.h>
>  #include <serial.h>
>  #include <asm/io.h>
> +#include <usb.h>
>  
>  DECLARE_GLOBAL_DATA_PTR;
>  
> @@ -66,7 +67,7 @@ int board_mmc_init(bd_t *bis)
>  #endif
>  
>  #ifdef	CONFIG_CMD_USB
> -int usb_board_init(void)
> +int board_usb_init(int index, enum board_usb_init_type init)
>  {
>  	writel((UHCHR | UHCHR_PCPL | UHCHR_PSPL) &
>  		~(UHCHR_SSEP0 | UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSE),
> @@ -97,9 +98,9 @@ int usb_board_init(void)
>  	return 0;
>  }
>  
> -void usb_board_init_fail(void)
> +int board_usb_cleanup(int index, enum board_usb_init_type init)
>  {
> -	return;
> +	return 0;
>  }
>  
>  void usb_board_stop(void)
> diff --git a/common/cmd_dfu.c b/common/cmd_dfu.c
> index 793c422..693b5bc 100644
> --- a/common/cmd_dfu.c
> +++ b/common/cmd_dfu.c
> @@ -14,17 +14,22 @@
>  #include <dfu.h>
>  #include <asm/errno.h>
>  #include <g_dnl.h>
> +#include <usb.h>
>  
>  static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
>  {
> +	if (argc < 4)
> +		return CMD_RET_USAGE;
> +
> +	char *usb_controller = argv[1];
> +	char *interface = argv[2];
> +	char *devstring = argv[3];
> +
>  	const char *str_env;
>  	char *s = "dfu";
>  	int ret, i = 0;
>  	char *env_bkp;
>  
> -	if (argc < 3)
> -		return CMD_RET_USAGE;
> -
>  	str_env = getenv("dfu_alt_info");
>  	if (str_env == NULL) {
>  		printf("%s: \"dfu_alt_info\" env variable not defined!\n",
> @@ -33,19 +38,18 @@ static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
>  	}
>  
>  	env_bkp = strdup(str_env);
> -	ret = dfu_config_entities(env_bkp, argv[1],
> -			    (int)simple_strtoul(argv[2], NULL, 10));
> +	ret = dfu_config_entities(env_bkp, interface,
> +			    (int)simple_strtoul(devstring, NULL, 0));
>  	if (ret)
>  		return CMD_RET_FAILURE;
>  
> -	if (argc > 3 && strcmp(argv[3], "list") == 0) {
> +	if (argc > 4 && strcmp(argv[4], "list") == 0) {
>  		dfu_show_entities();
>  		goto done;
>  	}
>  
> -#ifdef CONFIG_TRATS
> -	board_usb_init();
> -#endif
> +	int controller_index = simple_strtoul(usb_controller, NULL, 0);
> +	board_usb_init(controller_index, USB_INIT_DEVICE);
>  
>  	g_dnl_register(s);
>  	while (1) {
> @@ -77,8 +81,9 @@ done:
>  
>  U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu,
>  	"Device Firmware Upgrade",
> -	"<interface> <dev> [list]\n"
> -	"  - device firmware upgrade on a device <dev>\n"
> -	"    attached to interface <interface>\n"
> -	"    [list] - list available alt settings"
> +	"<USB_controller> <interface> <dev> [list]\n"
> +	"  - device firmware upgrade via <USB_controller>\n"
> +	"    on device <dev>, attached to interface\n"
> +	"    <interface>\n"
> +	"    [list] - list available alt settings\n"
>  );
> diff --git a/common/cmd_usb_mass_storage.c b/common/cmd_usb_mass_storage.c
> index 33a4715..c6dc5b9 100644
> --- a/common/cmd_usb_mass_storage.c
> +++ b/common/cmd_usb_mass_storage.c
> @@ -9,51 +9,53 @@
>  #include <common.h>
>  #include <command.h>
>  #include <g_dnl.h>
> +#include <usb.h>
>  #include <usb_mass_storage.h>
>  
>  int do_usb_mass_storage(cmd_tbl_t *cmdtp, int flag,
>  			       int argc, char * const argv[])
>  {
> -	char *ep;
> -	unsigned int dev_num = 0, offset = 0, part_size = 0;
> -	int rc;
> +	if (argc < 3)
> +		return CMD_RET_USAGE;
>  
> -	struct ums_board_info *ums_info;
> -	static char *s = "ums";
> -
> -	if (argc < 2) {
> -		printf("usage: ums <dev> - e.g. ums 0\n");
> -		return 0;
> -	}
> -
> -	dev_num = (int)simple_strtoul(argv[1], &ep, 16);
> +	const char *usb_controller = argv[1];
> +	const char *mmc_devstring  = argv[2];
>  
> +	unsigned int dev_num = (unsigned int)(simple_strtoul(mmc_devstring,
> +				NULL, 0));
>  	if (dev_num) {
> -		puts("\nSet eMMC device to 0! - e.g. ums 0\n");
> +		error("Set eMMC device to 0! - e.g. ums 0");
>  		goto fail;
>  	}
>  
> -	board_usb_init();
> -	ums_info = board_ums_init(dev_num, offset, part_size);
> +	unsigned int controller_index = (unsigned int)(simple_strtoul(
> +					usb_controller,	NULL, 0));
> +	if (board_usb_init(controller_index, USB_INIT_DEVICE)) {
> +		error("Couldn't init USB controller.");
> +		goto fail;
> +	}
>  
> +	struct ums_board_info *ums_info = board_ums_init(dev_num, 0, 0);
>  	if (!ums_info) {
> -		printf("MMC: %d -> NOT available\n", dev_num);
> +		error("MMC: %d -> NOT available", dev_num);
>  		goto fail;
>  	}
> -	rc = fsg_init(ums_info);
> +
> +	int rc = fsg_init(ums_info);
>  	if (rc) {
> -		printf("cmd ums: fsg_init failed\n");
> +		error("fsg_init failed");
>  		goto fail;
>  	}
>  
> -	g_dnl_register(s);
> +	g_dnl_register("ums");
>  
>  	while (1) {
>  		/* Handle control-c and timeouts */
>  		if (ctrlc()) {
> -			printf("The remote end did not respond in time.\n");
> +			error("The remote end did not respond in time.");
>  			goto exit;
>  		}
> +
>  		usb_gadget_handle_interrupts();
>  		/* Check if USB cable has been detached */
>  		if (fsg_main_thread(NULL) == EIO)
> @@ -69,5 +71,5 @@ fail:
>  
>  U_BOOT_CMD(ums, CONFIG_SYS_MAXARGS, 1, do_usb_mass_storage,
>  	"Use the UMS [User Mass Storage]",
> -	"ums - User Mass Storage Gadget"
> +	"<USB_controller> <mmc_dev>"
>  );
> diff --git a/common/usb.c b/common/usb.c
> index c97f522..bdcdd63 100644
> --- a/common/usb.c
> +++ b/common/usb.c
> @@ -1037,4 +1037,9 @@ int usb_new_device(struct usb_device *dev)
>  	return 0;
>  }
>  
> +__attribute__((weak))
> +int board_usb_init(int index, enum board_usb_init_type init)
> +{
> +	return 0;
> +}
>  /* EOF */
> diff --git a/drivers/dfu/dfu.c b/drivers/dfu/dfu.c
> index d73d510..e785d39 100644
> --- a/drivers/dfu/dfu.c
> +++ b/drivers/dfu/dfu.c
> @@ -307,7 +307,7 @@ int dfu_read(struct dfu_entity *dfu, void *buf, int size, int blk_seq_num)
>  }
>  
>  static int dfu_fill_entity(struct dfu_entity *dfu, char *s, int alt,
> -			    char *interface, int num)
> +			   char *interface, int num)
>  {
>  	char *st;
>  
> diff --git a/drivers/usb/host/ehci-omap.c b/drivers/usb/host/ehci-omap.c
> index 3c58f9e..c4ce487 100644
> --- a/drivers/usb/host/ehci-omap.c
> +++ b/drivers/usb/host/ehci-omap.c
> @@ -96,12 +96,6 @@ static void omap_ehci_soft_phy_reset(int port)
>  }
>  #endif
>  
> -inline int __board_usb_init(void)
> -{
> -	return 0;
> -}
> -int board_usb_init(void) __attribute__((weak, alias("__board_usb_init")));
> -
>  #if defined(CONFIG_OMAP_EHCI_PHY1_RESET_GPIO) || \
>  	defined(CONFIG_OMAP_EHCI_PHY2_RESET_GPIO) || \
>  	defined(CONFIG_OMAP_EHCI_PHY3_RESET_GPIO)
> @@ -157,15 +151,15 @@ int omap_ehci_hcd_stop(void)
>   * Based on "drivers/usb/host/ehci-omap.c" from Linux 3.1
>   * See there for additional Copyrights.
>   */
> -int omap_ehci_hcd_init(struct omap_usbhs_board_data *usbhs_pdata,
> -		struct ehci_hccr **hccr, struct ehci_hcor **hcor)
> +int omap_ehci_hcd_init(int index, struct omap_usbhs_board_data *usbhs_pdata,
> +		       struct ehci_hccr **hccr, struct ehci_hcor **hcor)
>  {
>  	int ret;
>  	unsigned int i, reg = 0, rev = 0;
>  
>  	debug("Initializing OMAP EHCI\n");
>  
> -	ret = board_usb_init();
> +	ret = board_usb_init(index, USB_INIT_HOST);
>  	if (ret < 0)
>  		return ret;
>  
> diff --git a/drivers/usb/host/ehci-tegra.c b/drivers/usb/host/ehci-tegra.c
> index c6da449..cc23133 100644
> --- a/drivers/usb/host/ehci-tegra.c
> +++ b/drivers/usb/host/ehci-tegra.c
> @@ -699,7 +699,7 @@ static int process_usb_nodes(const void *blob, int node_list[], int count)
>  	return 0;
>  }
>  
> -int board_usb_init(const void *blob)
> +int usb_process_devicetree(const void *blob)
>  {
>  	int node_list[USB_PORTS_MAX];
>  	int count, err = 0;
> diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
> index c33c487..756f2fa 100644
> --- a/drivers/usb/host/ohci-hcd.c
> +++ b/drivers/usb/host/ohci-hcd.c
> @@ -1861,7 +1861,7 @@ int usb_lowlevel_init(int index, void **controller)
>  
>  #ifdef CONFIG_SYS_USB_OHCI_BOARD_INIT
>  	/*  board dependant init */
> -	if (usb_board_init())
> +	if (board_usb_init(index, USB_INIT_HOST))
>  		return -1;
>  #endif
>  	memset(&gohci, 0, sizeof(ohci_t));
> @@ -1918,7 +1918,7 @@ int usb_lowlevel_init(int index, void **controller)
>  		err ("can't reset usb-%s", gohci.slot_name);
>  #ifdef CONFIG_SYS_USB_OHCI_BOARD_INIT
>  		/* board dependant cleanup */
> -		usb_board_init_fail();
> +		board_usb_cleanup(index, USB_INIT_HOST);
>  #endif
>  
>  #ifdef CONFIG_SYS_USB_OHCI_CPU_INIT
> diff --git a/drivers/usb/host/ohci.h b/drivers/usb/host/ohci.h
> index d977e8f..9a4a2c2 100644
> --- a/drivers/usb/host/ohci.h
> +++ b/drivers/usb/host/ohci.h
> @@ -19,14 +19,11 @@
>  #endif /* CONFIG_SYS_OHCI_SWAP_REG_ACCESS */
>  
>  /* functions for doing board or CPU specific setup/cleanup */
> -extern int usb_board_init(void);
> -extern int usb_board_stop(void);
> -extern int usb_board_init_fail(void);
> -
> -extern int usb_cpu_init(void);
> -extern int usb_cpu_stop(void);
> -extern int usb_cpu_init_fail(void);
> +int usb_board_stop(void);
>  
> +int usb_cpu_init(void);
> +int usb_cpu_stop(void);
> +int usb_cpu_init_fail(void);
>  
>  static int cc_to_error[16] = {
>  
> diff --git a/include/g_dnl.h b/include/g_dnl.h
> index 2b2f11a..b6c4dd4 100644
> --- a/include/g_dnl.h
> +++ b/include/g_dnl.h
> @@ -14,6 +14,4 @@ int g_dnl_bind_fixup(struct usb_device_descriptor *);
>  int g_dnl_register(const char *s);
>  void g_dnl_unregister(void);
>  
> -/* USB initialization declaration - board specific */
> -void board_usb_init(void);
>  #endif /* __G_DOWNLOAD_H_ */
> diff --git a/include/usb.h b/include/usb.h
> index 60db897..681b408 100644
> --- a/include/usb.h
> +++ b/include/usb.h
> @@ -165,10 +165,38 @@ int submit_int_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
>  
>  extern void udc_disconnect(void);
>  
> -#else
> +#elif !defined(CONFIG_USB_GADGET)
>  #error USB Lowlevel not defined
>  #endif
>  
> +/*
> + * You can initialize platform's USB host or device
> + * ports by passing this enum as an argument to
> + * board_usb_init().
> + */
> +enum board_usb_init_type {
> +	USB_INIT_HOST,
> +	USB_INIT_DEVICE
> +};
> +
> +/*
> + * board-specific hardware initialization, called by
> + * usb drivers and u-boot commands
> + *
> + * @param index USB controller number
> + * @param init initializes controller as USB host or device
> + */
> +int board_usb_init(int index, enum board_usb_init_type init);
> +
> +/*
> + * can be used to clean up after failed USB initialization attempt
> + * vide: board_usb_init()
> + *
> + * @param index USB controller number for selective cleanup
> + * @param init board_usb_init_type passed to board_usb_init()
> + */
> +int board_usb_cleanup(int index, enum board_usb_init_type init);
> +
>  #ifdef CONFIG_USB_STORAGE
>  
>  #define USB_MAX_STOR_DEV 5
> diff --git a/include/usb_mass_storage.h b/include/usb_mass_storage.h
> index 35cdcc3..f26403e 100644
> --- a/include/usb_mass_storage.h
> +++ b/include/usb_mass_storage.h
> @@ -30,13 +30,10 @@ struct ums_board_info {
>  	struct ums_device ums_dev;
>  };
>  
> -extern void board_usb_init(void);
> -
> -extern int fsg_init(struct ums_board_info *);
> -extern void fsg_cleanup(void);
> -extern struct ums_board_info *board_ums_init(unsigned int,
> -					     unsigned int, unsigned int);
> -extern int usb_gadget_handle_interrupts(void);
> -extern int fsg_main_thread(void *);
> +int fsg_init(struct ums_board_info *);
> +void fsg_cleanup(void);
> +struct ums_board_info *board_ums_init(unsigned int, unsigned int,
> +				      unsigned int);
> +int fsg_main_thread(void *);
>  
>  #endif /* __USB_MASS_STORAGE_H__ */
>
Mateusz Zalega - Sept. 18, 2013, 10:58 a.m.
On 09/17/13 18:11, Igor Grinberg wrote:
> Hello,
> 
> On 09/10/2013 06:10 PM, Mateusz Zalega wrote:
>> This commit unifies board-specific USB initialization implementations
>> under one symbol (usb_board_init), declaration of which is available in
>> usb.h.
>>
>> New API allows selective initialization of USB controllers whenever needed.
>>
>> Signed-off-by: Mateusz Zalega <m.zalega@samsung.com>
>> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
>> Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>
>> Cc: Marek Vasut <marex@denx.de>
>> Cc: Lukasz Majewski <l.majewski@samsung.com>
> 
> I think, you should Cc respective board maintainers as well.

Right, I forgot about it. I'll forward last Marek's response to them.

Thanks.
Marek Vasut - Sept. 19, 2013, 1:34 p.m.
Dear Mateusz Zalega,

> This commit unifies board-specific USB initialization implementations
> under one symbol (usb_board_init), declaration of which is available in
> usb.h.
> 
> New API allows selective initialization of USB controllers whenever needed.
> 
> Signed-off-by: Mateusz Zalega <m.zalega@samsung.com>
> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
> Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>
> Cc: Marek Vasut <marex@denx.de>
> Cc: Lukasz Majewski <l.majewski@samsung.com>
> Change-Id: Ia78a1378f30a55dd14598c9a1a1b4b8a762e2cd8
> ---
> Changes since RFC (v1):
> - NVIDIA Tegra doesn't postpone its USB init anymore
> - board_usb_init()'s sole argument name was shortened
> - networking code comment style (/* blurb...) dropped
> - squashed RFC changes so that patch won't break bisect
> 
> v2 changes:
> - commit message fixup
> 
> v3 changes:
> - added 'index' argument to perform selective port initialization
> 
> v4 changes:
> - board_usb_init_fail() renamed to board_usb_cleanup()
> - board_usb_cleanup() accepts controller index and init type
> - DFU and UMS commands don't init all USB controllers anymore
> - minor related fixes & refactorization

How did you test it on all the ARM boards ?

ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- BUILD_DIR=/tmp/u-boot-arm-build 
MAKEALL_LOGDIR=/tmp/u-boot-arm-log ./MAKEALL -a arm

does this work for you ?

Best regards,
Marek Vasut
Marek Vasut - Sept. 19, 2013, 1:40 p.m.
Dear Marek Vasut,

> Dear Mateusz Zalega,
> 
> > This commit unifies board-specific USB initialization implementations
> > under one symbol (usb_board_init), declaration of which is available in
> > usb.h.
> > 
> > New API allows selective initialization of USB controllers whenever
> > needed.
> > 
> > Signed-off-by: Mateusz Zalega <m.zalega@samsung.com>
> > Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
> > Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>
> > Cc: Marek Vasut <marex@denx.de>
> > Cc: Lukasz Majewski <l.majewski@samsung.com>
> > Change-Id: Ia78a1378f30a55dd14598c9a1a1b4b8a762e2cd8
> > ---
> > Changes since RFC (v1):
> > - NVIDIA Tegra doesn't postpone its USB init anymore
> > - board_usb_init()'s sole argument name was shortened
> > - networking code comment style (/* blurb...) dropped
> > - squashed RFC changes so that patch won't break bisect
> > 
> > v2 changes:
> > - commit message fixup
> > 
> > v3 changes:
> > - added 'index' argument to perform selective port initialization
> > 
> > v4 changes:
> > - board_usb_init_fail() renamed to board_usb_cleanup()
> > - board_usb_cleanup() accepts controller index and init type
> > - DFU and UMS commands don't init all USB controllers anymore
> > - minor related fixes & refactorization
> 
> How did you test it on all the ARM boards ?
> 
> ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- BUILD_DIR=/tmp/u-boot-arm-build
> MAKEALL_LOGDIR=/tmp/u-boot-arm-log ./MAKEALL -a arm
> 
> does this work for you ?

Looks like this was a local issue here, sorry for the noise. Once the builds 
finish, I will apply for -next.

Best regards,
Marek Vasut
Marek Vasut - Sept. 19, 2013, 2:34 p.m.
Dear Marek Vasut,

> Dear Marek Vasut,
> 
> > Dear Mateusz Zalega,
> > 
> > > This commit unifies board-specific USB initialization implementations
> > > under one symbol (usb_board_init), declaration of which is available in
> > > usb.h.
> > > 
> > > New API allows selective initialization of USB controllers whenever
> > > needed.
> > > 
> > > Signed-off-by: Mateusz Zalega <m.zalega@samsung.com>
> > > Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
> > > Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>
> > > Cc: Marek Vasut <marex@denx.de>
> > > Cc: Lukasz Majewski <l.majewski@samsung.com>
> > > Change-Id: Ia78a1378f30a55dd14598c9a1a1b4b8a762e2cd8
> > > ---
> > > Changes since RFC (v1):
> > > - NVIDIA Tegra doesn't postpone its USB init anymore
> > > - board_usb_init()'s sole argument name was shortened
> > > - networking code comment style (/* blurb...) dropped
> > > - squashed RFC changes so that patch won't break bisect
> > > 
> > > v2 changes:
> > > - commit message fixup
> > > 
> > > v3 changes:
> > > - added 'index' argument to perform selective port initialization
> > > 
> > > v4 changes:
> > > - board_usb_init_fail() renamed to board_usb_cleanup()
> > > - board_usb_cleanup() accepts controller index and init type
> > > - DFU and UMS commands don't init all USB controllers anymore
> > > - minor related fixes & refactorization
> > 
> > How did you test it on all the ARM boards ?
> > 
> > ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- BUILD_DIR=/tmp/u-boot-arm-build
> > MAKEALL_LOGDIR=/tmp/u-boot-arm-log ./MAKEALL -a arm
> > 
> > does this work for you ?
> 
> Looks like this was a local issue here, sorry for the noise. Once the
> builds finish, I will apply for -next.

I checked powerpc and "arches" "glacier" and "glacier_nand" don't build. Can you 
please check and fix ? You can get the ELDK 5.4 PPC toolchain from [1].

http://www.denx.de/wiki/ELDK-5/

Best regards,
Marek Vasut
Minkyu Kang - Sept. 24, 2013, 11:54 a.m.
Dear Marek Vasut,

On 19/09/13 23:34, Marek Vasut wrote:
> Dear Marek Vasut,
> 
>> Dear Marek Vasut,
>>
>>> Dear Mateusz Zalega,
>>>
>>>> This commit unifies board-specific USB initialization implementations
>>>> under one symbol (usb_board_init), declaration of which is available in
>>>> usb.h.
>>>>
>>>> New API allows selective initialization of USB controllers whenever
>>>> needed.
>>>>
>>>> Signed-off-by: Mateusz Zalega <m.zalega@samsung.com>
>>>> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
>>>> Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>
>>>> Cc: Marek Vasut <marex@denx.de>
>>>> Cc: Lukasz Majewski <l.majewski@samsung.com>
>>>> Change-Id: Ia78a1378f30a55dd14598c9a1a1b4b8a762e2cd8
>>>> ---
>>>> Changes since RFC (v1):
>>>> - NVIDIA Tegra doesn't postpone its USB init anymore
>>>> - board_usb_init()'s sole argument name was shortened
>>>> - networking code comment style (/* blurb...) dropped
>>>> - squashed RFC changes so that patch won't break bisect
>>>>
>>>> v2 changes:
>>>> - commit message fixup
>>>>
>>>> v3 changes:
>>>> - added 'index' argument to perform selective port initialization
>>>>
>>>> v4 changes:
>>>> - board_usb_init_fail() renamed to board_usb_cleanup()
>>>> - board_usb_cleanup() accepts controller index and init type
>>>> - DFU and UMS commands don't init all USB controllers anymore
>>>> - minor related fixes & refactorization
>>>
>>> How did you test it on all the ARM boards ?
>>>
>>> ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- BUILD_DIR=/tmp/u-boot-arm-build
>>> MAKEALL_LOGDIR=/tmp/u-boot-arm-log ./MAKEALL -a arm
>>>
>>> does this work for you ?
>>
>> Looks like this was a local issue here, sorry for the noise. Once the
>> builds finish, I will apply for -next.
> 
> I checked powerpc and "arches" "glacier" and "glacier_nand" don't build. Can you 
> please check and fix ? You can get the ELDK 5.4 PPC toolchain from [1].
> 
> http://www.denx.de/wiki/ELDK-5/
> 
> Best regards,
> Marek Vasut
> _______________________________________________
> U-Boot mailing list
> U-Boot@lists.denx.de
> http://lists.denx.de/mailman/listinfo/u-boot
> 

There are 5 patches that are sent by Mateusz Zalega.
Since those patches are had dependency with this patch.
Could please pick up them to -usb?

http://patchwork.ozlabs.org/patch/268786/
http://patchwork.ozlabs.org/patch/268787/
http://patchwork.ozlabs.org/patch/268788/
http://patchwork.ozlabs.org/patch/268789/

http://patchwork.ozlabs.org/patch/268790/

Thanks,
Minkyu Kang.
Marek Vasut - Sept. 24, 2013, 1:15 p.m.
Dear Minkyu Kang,

> Dear Marek Vasut,
> 
> On 19/09/13 23:34, Marek Vasut wrote:
> > Dear Marek Vasut,
> > 
> >> Dear Marek Vasut,
> >> 
> >>> Dear Mateusz Zalega,
> >>> 
> >>>> This commit unifies board-specific USB initialization implementations
> >>>> under one symbol (usb_board_init), declaration of which is available
> >>>> in usb.h.
> >>>> 
> >>>> New API allows selective initialization of USB controllers whenever
> >>>> needed.
> >>>> 
> >>>> Signed-off-by: Mateusz Zalega <m.zalega@samsung.com>
> >>>> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
> >>>> Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>
> >>>> Cc: Marek Vasut <marex@denx.de>
> >>>> Cc: Lukasz Majewski <l.majewski@samsung.com>
> >>>> Change-Id: Ia78a1378f30a55dd14598c9a1a1b4b8a762e2cd8
> >>>> ---
> >>>> Changes since RFC (v1):
> >>>> - NVIDIA Tegra doesn't postpone its USB init anymore
> >>>> - board_usb_init()'s sole argument name was shortened
> >>>> - networking code comment style (/* blurb...) dropped
> >>>> - squashed RFC changes so that patch won't break bisect
> >>>> 
> >>>> v2 changes:
> >>>> - commit message fixup
> >>>> 
> >>>> v3 changes:
> >>>> - added 'index' argument to perform selective port initialization
> >>>> 
> >>>> v4 changes:
> >>>> - board_usb_init_fail() renamed to board_usb_cleanup()
> >>>> - board_usb_cleanup() accepts controller index and init type
> >>>> - DFU and UMS commands don't init all USB controllers anymore
> >>>> - minor related fixes & refactorization
> >>> 
> >>> How did you test it on all the ARM boards ?
> >>> 
> >>> ARCH=arm CROSS_COMPILE=arm-linux-gnueabi-
> >>> BUILD_DIR=/tmp/u-boot-arm-build MAKEALL_LOGDIR=/tmp/u-boot-arm-log
> >>> ./MAKEALL -a arm
> >>> 
> >>> does this work for you ?
> >> 
> >> Looks like this was a local issue here, sorry for the noise. Once the
> >> builds finish, I will apply for -next.
> > 
> > I checked powerpc and "arches" "glacier" and "glacier_nand" don't build.
> > Can you please check and fix ? You can get the ELDK 5.4 PPC toolchain
> > from [1].
> > 
> > http://www.denx.de/wiki/ELDK-5/
> > 
> > Best regards,
> > Marek Vasut
> > _______________________________________________
> > U-Boot mailing list
> > U-Boot@lists.denx.de
> > http://lists.denx.de/mailman/listinfo/u-boot
> 
> There are 5 patches that are sent by Mateusz Zalega.
> Since those patches are had dependency with this patch.
> Could please pick up them to -usb?
> 
> http://patchwork.ozlabs.org/patch/268786/
> http://patchwork.ozlabs.org/patch/268787/
> http://patchwork.ozlabs.org/patch/268788/
> http://patchwork.ozlabs.org/patch/268789/
> 
> http://patchwork.ozlabs.org/patch/268790/

They don't touch any usb core stuff, they're just samsung-specific configuration 
adjustments. They should go via u-boot-samsung.

Best regards,
Marek Vasut
Mateusz Zalega - Sept. 25, 2013, 11:01 a.m.
On 09/19/13 16:34, Marek Vasut wrote:
> I checked powerpc and "arches" "glacier" and "glacier_nand" don't build. Can you 
> please check and fix ? You can get the ELDK 5.4 PPC toolchain from [1].
> 
> http://www.denx.de/wiki/ELDK-5/

Hello,
it's because I moved some function declarations and had to include usb.h
in their code.

@usb.h, this giant ifdef fails:
134 #if defined(CONFIG_USB_UHCI) || defined(CONFIG_USB_OHCI) || \
135         defined(CONFIG_USB_EHCI) || defined(CONFIG_USB_OHCI_NEW) || \
136         defined(CONFIG_USB_SL811HS) ||
defined(CONFIG_USB_ISP116X_HCD) || \
137         defined(CONFIG_USB_R8A66597_HCD) ||
defined(CONFIG_USB_DAVINCI) || \
138         defined(CONFIG_USB_OMAP3) || defined(CONFIG_USB_DA8XX) || \
139         defined(CONFIG_USB_BLACKFIN) || defined(CONFIG_USB_AM35X) || \
140         defined(CONFIG_USB_MUSB_DSPS) ||
defined(CONFIG_USB_MUSB_AM35X) || \
141         defined(CONFIG_USB_MUSB_OMAP2PLUS)

and results in:
169 #error USB Lowlevel not defined

I don't like the notion of using board-specific CONFIG_* defines in
usb.h. Any ideas on where can we move it? Maybe one generic
CONFIG_USB_HOST specified in board code would do?
Marek Vasut - Sept. 26, 2013, 1:50 a.m.
Dear Mateusz Zalega,

> On 09/19/13 16:34, Marek Vasut wrote:
> > I checked powerpc and "arches" "glacier" and "glacier_nand" don't build.
> > Can you please check and fix ? You can get the ELDK 5.4 PPC toolchain
> > from [1].
> > 
> > http://www.denx.de/wiki/ELDK-5/
> 
> Hello,
> it's because I moved some function declarations and had to include usb.h
> in their code.

Can you please elabore which functions did you exactly move that cause this to 
fail now ?

> @usb.h, this giant ifdef fails:
> 134 #if defined(CONFIG_USB_UHCI) || defined(CONFIG_USB_OHCI) || \
> 135         defined(CONFIG_USB_EHCI) || defined(CONFIG_USB_OHCI_NEW) || \
> 136         defined(CONFIG_USB_SL811HS) ||
> defined(CONFIG_USB_ISP116X_HCD) || \
> 137         defined(CONFIG_USB_R8A66597_HCD) ||
> defined(CONFIG_USB_DAVINCI) || \
> 138         defined(CONFIG_USB_OMAP3) || defined(CONFIG_USB_DA8XX) || \
> 139         defined(CONFIG_USB_BLACKFIN) || defined(CONFIG_USB_AM35X) || \
> 140         defined(CONFIG_USB_MUSB_DSPS) ||
> defined(CONFIG_USB_MUSB_AM35X) || \
> 141         defined(CONFIG_USB_MUSB_OMAP2PLUS)
> 
> and results in:
> 169 #error USB Lowlevel not defined
> 
> I don't like the notion of using board-specific CONFIG_* defines in
> usb.h. Any ideas on where can we move it? Maybe one generic
> CONFIG_USB_HOST specified in board code would do?

The ifdef is pretty much what would CONFIG_USB_HOST do.

Best regards,
Marek Vasut
Mateusz Zalega - Sept. 26, 2013, 10:04 a.m.
On 09/26/13 03:50, Marek Vasut wrote:
> Dear Mateusz Zalega,
> 
>> On 09/19/13 16:34, Marek Vasut wrote:
>>> I checked powerpc and "arches" "glacier" and "glacier_nand" don't build.
>>> Can you please check and fix ? You can get the ELDK 5.4 PPC toolchain
>>> from [1].
>>>
>>> http://www.denx.de/wiki/ELDK-5/
>>
>> Hello,
>> it's because I moved some function declarations and had to include usb.h
>> in their code.
> 
> Can you please elabore which functions did you exactly move that cause this to 
> fail now ?

172 /*
173  * You can initialize platform's USB host or device
174  * ports by passing this enum as an argument to
175  * board_usb_init().
176  */
177 enum board_usb_init_type {
178         USB_INIT_HOST,
179         USB_INIT_DEVICE
180 };
181
182 /*
183  * board-specific hardware initialization, called by
184  * usb drivers and u-boot commands
185  *
186  * @param index USB controller number
187  * @param init initializes controller as USB host or device
188  */
189 int board_usb_init(int index, enum board_usb_init_type init);
190
191 /*
192  * can be used to clean up after failed USB initialization attempt
193  * vide: board_usb_init()
194  *
195  * @param index USB controller number for selective cleanup
196  * @param init board_usb_init_type passed to board_usb_init()
197  */
198 int board_usb_cleanup(int index, enum board_usb_init_type init);

>> @usb.h, this giant ifdef fails:
>> 134 #if defined(CONFIG_USB_UHCI) || defined(CONFIG_USB_OHCI) || \
>> 135         defined(CONFIG_USB_EHCI) || defined(CONFIG_USB_OHCI_NEW) || \
>> 136         defined(CONFIG_USB_SL811HS) ||
>> defined(CONFIG_USB_ISP116X_HCD) || \
>> 137         defined(CONFIG_USB_R8A66597_HCD) ||
>> defined(CONFIG_USB_DAVINCI) || \
>> 138         defined(CONFIG_USB_OMAP3) || defined(CONFIG_USB_DA8XX) || \
>> 139         defined(CONFIG_USB_BLACKFIN) || defined(CONFIG_USB_AM35X) || \
>> 140         defined(CONFIG_USB_MUSB_DSPS) ||
>> defined(CONFIG_USB_MUSB_AM35X) || \
>> 141         defined(CONFIG_USB_MUSB_OMAP2PLUS)
>>
>> and results in:
>> 169 #error USB Lowlevel not defined
>>
>> I don't like the notion of using board-specific CONFIG_* defines in
>> usb.h. Any ideas on where can we move it? Maybe one generic
>> CONFIG_USB_HOST specified in board code would do?
> 
> The ifdef is pretty much what would CONFIG_USB_HOST do.

Yeah, but it would be nice to be able to add more boards to u-boot
without touching usb.h.

CONFIG_USB_OMAP3 <-- what happens in arch/board code should stay there

Patch

diff --git a/arch/arm/include/asm/arch-tegra/usb.h b/arch/arm/include/asm/arch-tegra/usb.h
index f66257c..a1efd07 100644
--- a/arch/arm/include/asm/arch-tegra/usb.h
+++ b/arch/arm/include/asm/arch-tegra/usb.h
@@ -131,8 +131,7 @@ 
 /* USB3_IF_USB_PHY_VBUS_SENSORS_0 */
 #define VBUS_VLD_STS			(1 << 26)
 
-
 /* Setup USB on the board */
-int board_usb_init(const void *blob);
+int usb_process_devicetree(const void *blob);
 
 #endif	/* _TEGRA_USB_H_ */
diff --git a/arch/arm/include/asm/ehci-omap.h b/arch/arm/include/asm/ehci-omap.h
index ac83a53..c7bca05 100644
--- a/arch/arm/include/asm/ehci-omap.h
+++ b/arch/arm/include/asm/ehci-omap.h
@@ -145,8 +145,8 @@  struct omap_ehci {
 struct ehci_hccr;
 struct ehci_hcor;
 
-int omap_ehci_hcd_init(struct omap_usbhs_board_data *usbhs_pdata,
-		struct ehci_hccr **hccr, struct ehci_hcor **hcor);
+int omap_ehci_hcd_init(int index, struct omap_usbhs_board_data *usbhs_pdata,
+		       struct ehci_hccr **hccr, struct ehci_hcor **hcor);
 int omap_ehci_hcd_stop(void);
 
 #endif /* _OMAP_COMMON_EHCI_H_ */
diff --git a/board/amcc/canyonlands/canyonlands.c b/board/amcc/canyonlands/canyonlands.c
index cc36f45..395095e 100644
--- a/board/amcc/canyonlands/canyonlands.c
+++ b/board/amcc/canyonlands/canyonlands.c
@@ -16,6 +16,7 @@ 
 #include <asm/4xx_pcie.h>
 #include <asm/ppc4xx-gpio.h>
 #include <asm/errno.h>
+#include <usb.h>
 
 extern flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS]; /* info for FLASH chips */
 
@@ -188,7 +189,7 @@  int board_early_init_f(void)
 }
 
 #if defined(CONFIG_USB_OHCI_NEW) && defined(CONFIG_SYS_USB_OHCI_BOARD_INIT)
-int usb_board_init(void)
+int board_usb_init(int index, enum board_usb_init_type init)
 {
 	struct board_bcsr *bcsr_data =
 		(struct board_bcsr *)CONFIG_SYS_BCSR_BASE;
@@ -229,7 +230,7 @@  int usb_board_stop(void)
 	return 0;
 }
 
-int usb_board_init_fail(void)
+int board_usb_cleanup(int index, enum board_usb_init_type init)
 {
 	return usb_board_stop();
 }
diff --git a/board/balloon3/balloon3.c b/board/balloon3/balloon3.c
index ecbac16..19c0e02 100644
--- a/board/balloon3/balloon3.c
+++ b/board/balloon3/balloon3.c
@@ -13,6 +13,7 @@ 
 #include <asm/io.h>
 #include <spartan3.h>
 #include <command.h>
+#include <usb.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -59,7 +60,7 @@  void dram_init_banksize(void)
 }
 
 #ifdef	CONFIG_CMD_USB
-int usb_board_init(void)
+int board_usb_init(int index, enum board_usb_init_type init)
 {
 	writel((readl(UHCHR) | UHCHR_PCPL | UHCHR_PSPL) &
 		~(UHCHR_SSEP0 | UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSE),
@@ -90,9 +91,9 @@  int usb_board_init(void)
 	return 0;
 }
 
-void usb_board_init_fail(void)
+int board_usb_cleanup(int index, enum board_usb_init_type init)
 {
-	return;
+	return 0;
 }
 
 void usb_board_stop(void)
diff --git a/board/compulab/cm_t35/cm_t35.c b/board/compulab/cm_t35/cm_t35.c
index 3caa5be..7626abc 100644
--- a/board/compulab/cm_t35/cm_t35.c
+++ b/board/compulab/cm_t35/cm_t35.c
@@ -591,7 +591,7 @@  int ehci_hcd_init(int index, struct ehci_hccr **hccr, struct ehci_hcor **hcor)
 	twl4030_i2c_write_u8(TWL4030_CHIP_GPIO, offset, 0xC0);
 	udelay(1);
 
-	return omap_ehci_hcd_init(&usbhs_bdata, hccr, hcor);
+	return omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor);
 }
 
 int ehci_hcd_stop(void)
diff --git a/board/esd/apc405/apc405.c b/board/esd/apc405/apc405.c
index f13f088..79341f5 100644
--- a/board/esd/apc405/apc405.c
+++ b/board/esd/apc405/apc405.c
@@ -17,6 +17,7 @@ 
 #include <mtd/cfi_flash.h>
 #include <asm/4xx_pci.h>
 #include <pci.h>
+#include <usb.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -428,7 +429,7 @@  void reset_phy(void)
 }
 
 #if defined(CONFIG_USB_OHCI_NEW) && defined(CONFIG_SYS_USB_OHCI_BOARD_INIT)
-int usb_board_init(void)
+int board_usb_init(int index, enum board_usb_init_type init)
 {
 	return 0;
 }
@@ -453,9 +454,8 @@  int usb_board_stop(void)
 	return 0;
 }
 
-int usb_board_init_fail(void)
+int board_usb_cleanup(int index, enum board_usb_init_type init)
 {
-	usb_board_stop();
-	return 0;
+	return usb_board_stop();
 }
 #endif /* defined(CONFIG_USB_OHCI) && defined(CONFIG_SYS_USB_OHCI_BOARD_INIT) */
diff --git a/board/esd/pmc440/pmc440.c b/board/esd/pmc440/pmc440.c
index 549b3b7..44b86da 100644
--- a/board/esd/pmc440/pmc440.c
+++ b/board/esd/pmc440/pmc440.c
@@ -27,6 +27,7 @@ 
 #endif
 #include <serial.h>
 #include <asm/4xx_pci.h>
+#include <usb.h>
 
 #include "fpga.h"
 #include "pmc440.h"
@@ -821,7 +822,7 @@  int bootstrap_eeprom_read (unsigned dev_addr, unsigned offset,
 }
 
 #if defined(CONFIG_USB_OHCI_NEW) && defined(CONFIG_SYS_USB_OHCI_BOARD_INIT)
-int usb_board_init(void)
+int board_usb_init(int index, enum board_usb_init_type init)
 {
 	char *act = getenv("usbact");
 	int i;
@@ -845,10 +846,9 @@  int usb_board_stop(void)
 	return 0;
 }
 
-int usb_board_init_fail(void)
+int board_usb_cleanup(int index, enum board_usb_init_type init)
 {
-	usb_board_stop();
-	return 0;
+	return usb_board_stop();
 }
 #endif /* defined(CONFIG_USB_OHCI) && defined(CONFIG_SYS_USB_OHCI_BOARD_INIT) */
 
diff --git a/board/htkw/mcx/mcx.c b/board/htkw/mcx/mcx.c
index 653d7ea..6f85b47 100644
--- a/board/htkw/mcx/mcx.c
+++ b/board/htkw/mcx/mcx.c
@@ -42,7 +42,7 @@  static struct omap_usbhs_board_data usbhs_bdata = {
 
 int ehci_hcd_init(int index, struct ehci_hccr **hccr, struct ehci_hcor **hcor)
 {
-	return omap_ehci_hcd_init(&usbhs_bdata, hccr, hcor);
+	return omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor);
 }
 
 int ehci_hcd_stop(int index)
diff --git a/board/icpdas/lp8x4x/lp8x4x.c b/board/icpdas/lp8x4x/lp8x4x.c
index 1b68ef3..a96bed6 100644
--- a/board/icpdas/lp8x4x/lp8x4x.c
+++ b/board/icpdas/lp8x4x/lp8x4x.c
@@ -15,6 +15,7 @@ 
 #include <netdev.h>
 #include <serial.h>
 #include <asm/io.h>
+#include <usb.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -58,7 +59,7 @@  int board_mmc_init(bd_t *bis)
 #endif
 
 #ifdef	CONFIG_CMD_USB
-int usb_board_init(void)
+int board_usb_init(int index, enum board_usb_init_type init)
 {
 	writel((UHCHR | UHCHR_PCPL | UHCHR_PSPL) &
 		~(UHCHR_SSEP0 | UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSE),
@@ -89,9 +90,9 @@  int usb_board_init(void)
 	return 0;
 }
 
-void usb_board_init_fail(void)
+int board_usb_cleanup(int index, enum board_usb_init_type init)
 {
-	return;
+	return 0;
 }
 
 void usb_board_stop(void)
diff --git a/board/nvidia/common/board.c b/board/nvidia/common/board.c
index 126e56e..1972527 100644
--- a/board/nvidia/common/board.c
+++ b/board/nvidia/common/board.c
@@ -32,6 +32,7 @@ 
 #ifdef CONFIG_USB_EHCI_TEGRA
 #include <asm/arch-tegra/usb.h>
 #include <asm/arch/usb.h>
+#include <usb.h>
 #endif
 #ifdef CONFIG_TEGRA_MMC
 #include <asm/arch-tegra/tegra_mmc.h>
@@ -153,8 +154,9 @@  int board_init(void)
 
 #ifdef CONFIG_USB_EHCI_TEGRA
 	pin_mux_usb();
-	board_usb_init(gd->fdt_blob);
+	usb_process_devicetree(gd->fdt_blob);
 #endif
+
 #ifdef CONFIG_LCD
 	tegra_lcd_check_next_stage(gd->fdt_blob, 0);
 #endif
diff --git a/board/samsung/trats/trats.c b/board/samsung/trats/trats.c
index 7f61d17..58d925f 100644
--- a/board/samsung/trats/trats.c
+++ b/board/samsung/trats/trats.c
@@ -26,6 +26,7 @@ 
 #include <power/max8997_muic.h>
 #include <power/battery.h>
 #include <power/max17042_fg.h>
+#include <usb.h>
 #include <usb_mass_storage.h>
 
 #include "setup.h"
@@ -495,10 +496,10 @@  struct s3c_plat_otg_data s5pc210_otg_data = {
 	.usb_flags	= PHY0_SLEEP,
 };
 
-void board_usb_init(void)
+int board_usb_init(int index, enum board_usb_init_type init)
 {
 	debug("USB_udc_probe\n");
-	s3c_udc_probe(&s5pc210_otg_data);
+	return s3c_udc_probe(&s5pc210_otg_data);
 }
 #endif
 
diff --git a/board/technexion/twister/twister.c b/board/technexion/twister/twister.c
index cd91d8f..6f2ff55 100644
--- a/board/technexion/twister/twister.c
+++ b/board/technexion/twister/twister.c
@@ -53,7 +53,7 @@  static struct omap_usbhs_board_data usbhs_bdata = {
 
 int ehci_hcd_init(int index, struct ehci_hccr **hccr, struct ehci_hcor **hcor)
 {
-	return omap_ehci_hcd_init(&usbhs_bdata, hccr, hcor);
+	return omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor);
 }
 
 int ehci_hcd_stop(int index)
diff --git a/board/teejet/mt_ventoux/mt_ventoux.c b/board/teejet/mt_ventoux/mt_ventoux.c
index b4e01d1..df873f5 100644
--- a/board/teejet/mt_ventoux/mt_ventoux.c
+++ b/board/teejet/mt_ventoux/mt_ventoux.c
@@ -104,7 +104,7 @@  static struct omap_usbhs_board_data usbhs_bdata = {
 
 int ehci_hcd_init(int index, struct ehci_hccr **hccr, struct ehci_hcor **hcor)
 {
-	return omap_ehci_hcd_init(&usbhs_bdata, hccr, hcor);
+	return omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor);
 }
 
 int ehci_hcd_stop(int index)
diff --git a/board/ti/beagle/beagle.c b/board/ti/beagle/beagle.c
index 62e9bea..41fed54 100644
--- a/board/ti/beagle/beagle.c
+++ b/board/ti/beagle/beagle.c
@@ -523,7 +523,7 @@  static struct omap_usbhs_board_data usbhs_bdata = {
 
 int ehci_hcd_init(int index, struct ehci_hccr **hccr, struct ehci_hcor **hcor)
 {
-	return omap_ehci_hcd_init(&usbhs_bdata, hccr, hcor);
+	return omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor);
 }
 
 int ehci_hcd_stop(int index)
diff --git a/board/ti/omap5_uevm/evm.c b/board/ti/omap5_uevm/evm.c
index 4706330..3ae0671 100644
--- a/board/ti/omap5_uevm/evm.c
+++ b/board/ti/omap5_uevm/evm.c
@@ -176,7 +176,7 @@  int ehci_hcd_init(int index, struct ehci_hccr **hccr, struct ehci_hcor **hcor)
 	auxclk |= AUXCLK_ENABLE_MASK;
 	writel(auxclk, (*prcm)->scrm_auxclk1);
 
-	ret = omap_ehci_hcd_init(&usbhs_bdata, hccr, hcor);
+	ret = omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor);
 	if (ret < 0) {
 		puts("Failed to initialize ehci\n");
 		return ret;
diff --git a/board/ti/panda/panda.c b/board/ti/panda/panda.c
index e838ffd..fe7a437 100644
--- a/board/ti/panda/panda.c
+++ b/board/ti/panda/panda.c
@@ -263,7 +263,7 @@  int ehci_hcd_init(int index, struct ehci_hccr **hccr, struct ehci_hcor **hcor)
 	utmi_clk |= HSUSBHOST_CLKCTRL_CLKSEL_UTMI_P1_MASK;
 	sr32((void *)CM_L3INIT_HSUSBHOST_CLKCTRL, 0, 32, utmi_clk);
 
-	ret = omap_ehci_hcd_init(&usbhs_bdata, hccr, hcor);
+	ret = omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor);
 	if (ret < 0)
 		return ret;
 
diff --git a/board/toradex/colibri_pxa270/colibri_pxa270.c b/board/toradex/colibri_pxa270/colibri_pxa270.c
index c1e2562..b70c1e3 100644
--- a/board/toradex/colibri_pxa270/colibri_pxa270.c
+++ b/board/toradex/colibri_pxa270/colibri_pxa270.c
@@ -13,6 +13,7 @@ 
 #include <netdev.h>
 #include <asm/io.h>
 #include <serial.h>
+#include <usb.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -39,7 +40,7 @@  int dram_init(void)
 }
 
 #ifdef	CONFIG_CMD_USB
-int usb_board_init(void)
+int board_usb_init(int index, enum board_usb_init_type init)
 {
 	writel((readl(UHCHR) | UHCHR_PCPL | UHCHR_PSPL) &
 		~(UHCHR_SSEP0 | UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSE),
@@ -70,9 +71,9 @@  int usb_board_init(void)
 	return 0;
 }
 
-void usb_board_init_fail(void)
+int board_usb_cleanup(int index, enum board_usb_init_type init)
 {
-	return;
+	return 0;
 }
 
 void usb_board_stop(void)
diff --git a/board/trizepsiv/conxs.c b/board/trizepsiv/conxs.c
index c0c318f..830d5a8 100644
--- a/board/trizepsiv/conxs.c
+++ b/board/trizepsiv/conxs.c
@@ -21,6 +21,7 @@ 
 #include <asm/arch/regs-mmc.h>
 #include <netdev.h>
 #include <asm/io.h>
+#include <usb.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -42,7 +43,7 @@  extern struct serial_device serial_stuart_device;
  * Miscelaneous platform dependent initialisations
  */
 
-int usb_board_init(void)
+int board_usb_init(int index, enum board_usb_init_type init)
 {
 	writel((readl(UHCHR) | UHCHR_PCPL | UHCHR_PSPL) &
 		~(UHCHR_SSEP0 | UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSE),
@@ -69,9 +70,9 @@  int usb_board_init(void)
 	return 0;
 }
 
-void usb_board_init_fail(void)
+int board_usb_cleanup(int index, enum board_usb_init_type init)
 {
-	return;
+	return 0;
 }
 
 void usb_board_stop(void)
diff --git a/board/vpac270/vpac270.c b/board/vpac270/vpac270.c
index 616736f..fab4636 100644
--- a/board/vpac270/vpac270.c
+++ b/board/vpac270/vpac270.c
@@ -13,6 +13,7 @@ 
 #include <netdev.h>
 #include <serial.h>
 #include <asm/io.h>
+#include <usb.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -66,7 +67,7 @@  int board_mmc_init(bd_t *bis)
 #endif
 
 #ifdef	CONFIG_CMD_USB
-int usb_board_init(void)
+int board_usb_init(int index, enum board_usb_init_type init)
 {
 	writel((UHCHR | UHCHR_PCPL | UHCHR_PSPL) &
 		~(UHCHR_SSEP0 | UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSE),
@@ -97,9 +98,9 @@  int usb_board_init(void)
 	return 0;
 }
 
-void usb_board_init_fail(void)
+int board_usb_cleanup(int index, enum board_usb_init_type init)
 {
-	return;
+	return 0;
 }
 
 void usb_board_stop(void)
diff --git a/common/cmd_dfu.c b/common/cmd_dfu.c
index 793c422..693b5bc 100644
--- a/common/cmd_dfu.c
+++ b/common/cmd_dfu.c
@@ -14,17 +14,22 @@ 
 #include <dfu.h>
 #include <asm/errno.h>
 #include <g_dnl.h>
+#include <usb.h>
 
 static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
+	if (argc < 4)
+		return CMD_RET_USAGE;
+
+	char *usb_controller = argv[1];
+	char *interface = argv[2];
+	char *devstring = argv[3];
+
 	const char *str_env;
 	char *s = "dfu";
 	int ret, i = 0;
 	char *env_bkp;
 
-	if (argc < 3)
-		return CMD_RET_USAGE;
-
 	str_env = getenv("dfu_alt_info");
 	if (str_env == NULL) {
 		printf("%s: \"dfu_alt_info\" env variable not defined!\n",
@@ -33,19 +38,18 @@  static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	}
 
 	env_bkp = strdup(str_env);
-	ret = dfu_config_entities(env_bkp, argv[1],
-			    (int)simple_strtoul(argv[2], NULL, 10));
+	ret = dfu_config_entities(env_bkp, interface,
+			    (int)simple_strtoul(devstring, NULL, 0));
 	if (ret)
 		return CMD_RET_FAILURE;
 
-	if (argc > 3 && strcmp(argv[3], "list") == 0) {
+	if (argc > 4 && strcmp(argv[4], "list") == 0) {
 		dfu_show_entities();
 		goto done;
 	}
 
-#ifdef CONFIG_TRATS
-	board_usb_init();
-#endif
+	int controller_index = simple_strtoul(usb_controller, NULL, 0);
+	board_usb_init(controller_index, USB_INIT_DEVICE);
 
 	g_dnl_register(s);
 	while (1) {
@@ -77,8 +81,9 @@  done:
 
 U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu,
 	"Device Firmware Upgrade",
-	"<interface> <dev> [list]\n"
-	"  - device firmware upgrade on a device <dev>\n"
-	"    attached to interface <interface>\n"
-	"    [list] - list available alt settings"
+	"<USB_controller> <interface> <dev> [list]\n"
+	"  - device firmware upgrade via <USB_controller>\n"
+	"    on device <dev>, attached to interface\n"
+	"    <interface>\n"
+	"    [list] - list available alt settings\n"
 );
diff --git a/common/cmd_usb_mass_storage.c b/common/cmd_usb_mass_storage.c
index 33a4715..c6dc5b9 100644
--- a/common/cmd_usb_mass_storage.c
+++ b/common/cmd_usb_mass_storage.c
@@ -9,51 +9,53 @@ 
 #include <common.h>
 #include <command.h>
 #include <g_dnl.h>
+#include <usb.h>
 #include <usb_mass_storage.h>
 
 int do_usb_mass_storage(cmd_tbl_t *cmdtp, int flag,
 			       int argc, char * const argv[])
 {
-	char *ep;
-	unsigned int dev_num = 0, offset = 0, part_size = 0;
-	int rc;
+	if (argc < 3)
+		return CMD_RET_USAGE;
 
-	struct ums_board_info *ums_info;
-	static char *s = "ums";
-
-	if (argc < 2) {
-		printf("usage: ums <dev> - e.g. ums 0\n");
-		return 0;
-	}
-
-	dev_num = (int)simple_strtoul(argv[1], &ep, 16);
+	const char *usb_controller = argv[1];
+	const char *mmc_devstring  = argv[2];
 
+	unsigned int dev_num = (unsigned int)(simple_strtoul(mmc_devstring,
+				NULL, 0));
 	if (dev_num) {
-		puts("\nSet eMMC device to 0! - e.g. ums 0\n");
+		error("Set eMMC device to 0! - e.g. ums 0");
 		goto fail;
 	}
 
-	board_usb_init();
-	ums_info = board_ums_init(dev_num, offset, part_size);
+	unsigned int controller_index = (unsigned int)(simple_strtoul(
+					usb_controller,	NULL, 0));
+	if (board_usb_init(controller_index, USB_INIT_DEVICE)) {
+		error("Couldn't init USB controller.");
+		goto fail;
+	}
 
+	struct ums_board_info *ums_info = board_ums_init(dev_num, 0, 0);
 	if (!ums_info) {
-		printf("MMC: %d -> NOT available\n", dev_num);
+		error("MMC: %d -> NOT available", dev_num);
 		goto fail;
 	}
-	rc = fsg_init(ums_info);
+
+	int rc = fsg_init(ums_info);
 	if (rc) {
-		printf("cmd ums: fsg_init failed\n");
+		error("fsg_init failed");
 		goto fail;
 	}
 
-	g_dnl_register(s);
+	g_dnl_register("ums");
 
 	while (1) {
 		/* Handle control-c and timeouts */
 		if (ctrlc()) {
-			printf("The remote end did not respond in time.\n");
+			error("The remote end did not respond in time.");
 			goto exit;
 		}
+
 		usb_gadget_handle_interrupts();
 		/* Check if USB cable has been detached */
 		if (fsg_main_thread(NULL) == EIO)
@@ -69,5 +71,5 @@  fail:
 
 U_BOOT_CMD(ums, CONFIG_SYS_MAXARGS, 1, do_usb_mass_storage,
 	"Use the UMS [User Mass Storage]",
-	"ums - User Mass Storage Gadget"
+	"<USB_controller> <mmc_dev>"
 );
diff --git a/common/usb.c b/common/usb.c
index c97f522..bdcdd63 100644
--- a/common/usb.c
+++ b/common/usb.c
@@ -1037,4 +1037,9 @@  int usb_new_device(struct usb_device *dev)
 	return 0;
 }
 
+__attribute__((weak))
+int board_usb_init(int index, enum board_usb_init_type init)
+{
+	return 0;
+}
 /* EOF */
diff --git a/drivers/dfu/dfu.c b/drivers/dfu/dfu.c
index d73d510..e785d39 100644
--- a/drivers/dfu/dfu.c
+++ b/drivers/dfu/dfu.c
@@ -307,7 +307,7 @@  int dfu_read(struct dfu_entity *dfu, void *buf, int size, int blk_seq_num)
 }
 
 static int dfu_fill_entity(struct dfu_entity *dfu, char *s, int alt,
-			    char *interface, int num)
+			   char *interface, int num)
 {
 	char *st;
 
diff --git a/drivers/usb/host/ehci-omap.c b/drivers/usb/host/ehci-omap.c
index 3c58f9e..c4ce487 100644
--- a/drivers/usb/host/ehci-omap.c
+++ b/drivers/usb/host/ehci-omap.c
@@ -96,12 +96,6 @@  static void omap_ehci_soft_phy_reset(int port)
 }
 #endif
 
-inline int __board_usb_init(void)
-{
-	return 0;
-}
-int board_usb_init(void) __attribute__((weak, alias("__board_usb_init")));
-
 #if defined(CONFIG_OMAP_EHCI_PHY1_RESET_GPIO) || \
 	defined(CONFIG_OMAP_EHCI_PHY2_RESET_GPIO) || \
 	defined(CONFIG_OMAP_EHCI_PHY3_RESET_GPIO)
@@ -157,15 +151,15 @@  int omap_ehci_hcd_stop(void)
  * Based on "drivers/usb/host/ehci-omap.c" from Linux 3.1
  * See there for additional Copyrights.
  */
-int omap_ehci_hcd_init(struct omap_usbhs_board_data *usbhs_pdata,
-		struct ehci_hccr **hccr, struct ehci_hcor **hcor)
+int omap_ehci_hcd_init(int index, struct omap_usbhs_board_data *usbhs_pdata,
+		       struct ehci_hccr **hccr, struct ehci_hcor **hcor)
 {
 	int ret;
 	unsigned int i, reg = 0, rev = 0;
 
 	debug("Initializing OMAP EHCI\n");
 
-	ret = board_usb_init();
+	ret = board_usb_init(index, USB_INIT_HOST);
 	if (ret < 0)
 		return ret;
 
diff --git a/drivers/usb/host/ehci-tegra.c b/drivers/usb/host/ehci-tegra.c
index c6da449..cc23133 100644
--- a/drivers/usb/host/ehci-tegra.c
+++ b/drivers/usb/host/ehci-tegra.c
@@ -699,7 +699,7 @@  static int process_usb_nodes(const void *blob, int node_list[], int count)
 	return 0;
 }
 
-int board_usb_init(const void *blob)
+int usb_process_devicetree(const void *blob)
 {
 	int node_list[USB_PORTS_MAX];
 	int count, err = 0;
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index c33c487..756f2fa 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -1861,7 +1861,7 @@  int usb_lowlevel_init(int index, void **controller)
 
 #ifdef CONFIG_SYS_USB_OHCI_BOARD_INIT
 	/*  board dependant init */
-	if (usb_board_init())
+	if (board_usb_init(index, USB_INIT_HOST))
 		return -1;
 #endif
 	memset(&gohci, 0, sizeof(ohci_t));
@@ -1918,7 +1918,7 @@  int usb_lowlevel_init(int index, void **controller)
 		err ("can't reset usb-%s", gohci.slot_name);
 #ifdef CONFIG_SYS_USB_OHCI_BOARD_INIT
 		/* board dependant cleanup */
-		usb_board_init_fail();
+		board_usb_cleanup(index, USB_INIT_HOST);
 #endif
 
 #ifdef CONFIG_SYS_USB_OHCI_CPU_INIT
diff --git a/drivers/usb/host/ohci.h b/drivers/usb/host/ohci.h
index d977e8f..9a4a2c2 100644
--- a/drivers/usb/host/ohci.h
+++ b/drivers/usb/host/ohci.h
@@ -19,14 +19,11 @@ 
 #endif /* CONFIG_SYS_OHCI_SWAP_REG_ACCESS */
 
 /* functions for doing board or CPU specific setup/cleanup */
-extern int usb_board_init(void);
-extern int usb_board_stop(void);
-extern int usb_board_init_fail(void);
-
-extern int usb_cpu_init(void);
-extern int usb_cpu_stop(void);
-extern int usb_cpu_init_fail(void);
+int usb_board_stop(void);
 
+int usb_cpu_init(void);
+int usb_cpu_stop(void);
+int usb_cpu_init_fail(void);
 
 static int cc_to_error[16] = {
 
diff --git a/include/g_dnl.h b/include/g_dnl.h
index 2b2f11a..b6c4dd4 100644
--- a/include/g_dnl.h
+++ b/include/g_dnl.h
@@ -14,6 +14,4 @@  int g_dnl_bind_fixup(struct usb_device_descriptor *);
 int g_dnl_register(const char *s);
 void g_dnl_unregister(void);
 
-/* USB initialization declaration - board specific */
-void board_usb_init(void);
 #endif /* __G_DOWNLOAD_H_ */
diff --git a/include/usb.h b/include/usb.h
index 60db897..681b408 100644
--- a/include/usb.h
+++ b/include/usb.h
@@ -165,10 +165,38 @@  int submit_int_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
 
 extern void udc_disconnect(void);
 
-#else
+#elif !defined(CONFIG_USB_GADGET)
 #error USB Lowlevel not defined
 #endif
 
+/*
+ * You can initialize platform's USB host or device
+ * ports by passing this enum as an argument to
+ * board_usb_init().
+ */
+enum board_usb_init_type {
+	USB_INIT_HOST,
+	USB_INIT_DEVICE
+};
+
+/*
+ * board-specific hardware initialization, called by
+ * usb drivers and u-boot commands
+ *
+ * @param index USB controller number
+ * @param init initializes controller as USB host or device
+ */
+int board_usb_init(int index, enum board_usb_init_type init);
+
+/*
+ * can be used to clean up after failed USB initialization attempt
+ * vide: board_usb_init()
+ *
+ * @param index USB controller number for selective cleanup
+ * @param init board_usb_init_type passed to board_usb_init()
+ */
+int board_usb_cleanup(int index, enum board_usb_init_type init);
+
 #ifdef CONFIG_USB_STORAGE
 
 #define USB_MAX_STOR_DEV 5
diff --git a/include/usb_mass_storage.h b/include/usb_mass_storage.h
index 35cdcc3..f26403e 100644
--- a/include/usb_mass_storage.h
+++ b/include/usb_mass_storage.h
@@ -30,13 +30,10 @@  struct ums_board_info {
 	struct ums_device ums_dev;
 };
 
-extern void board_usb_init(void);
-
-extern int fsg_init(struct ums_board_info *);
-extern void fsg_cleanup(void);
-extern struct ums_board_info *board_ums_init(unsigned int,
-					     unsigned int, unsigned int);
-extern int usb_gadget_handle_interrupts(void);
-extern int fsg_main_thread(void *);
+int fsg_init(struct ums_board_info *);
+void fsg_cleanup(void);
+struct ums_board_info *board_ums_init(unsigned int, unsigned int,
+				      unsigned int);
+int fsg_main_thread(void *);
 
 #endif /* __USB_MASS_STORAGE_H__ */