Skip to contentSkip to conversation

New board-specific USB initialization interface

RFC New Mateusz Zalega 7 participants 63 messages Aug 6, 2013 – Oct 8, 2013

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

cover New board-specific USB initialization interface

Current implementation of do_dfu() and do_usb_mass_storage() requires board-specific board_usb_init() which performs USB hardware initialization.

I noticed that several boards have such a function defined, named either usb_board_init() (which binds to ohci-hcd.c driver and had been used solely by it) or board_usb_init() (as in ehci-omap.c). I _assumed_ that these functions do what's required by do_*() and renamed the earlier in order to unify the naming convention.

It would:
+ make enabling DFU and UMS in these boards easier
+ clean up the namespace
+ improve code reusability
+ enable devs to postpone hardware init until it's needed (as in do_dfu())

Declarations of these functions were scattered all over the codebase. Seeing it as a bad practice, I added declaration of usb_board_init() in usb.h and removed the other.

I added a weak symbol for usb_board_init() in usb.c so that boards which do not require USB initialization or have to initialize hardware earlier would compile and run.

For boards which offer both USB device and host capabilities, you can specify which part, host or device, to initialize, via function argument.

Does this approach sound good and/or reasonable?

Code compiles successfully for all ARM boards and was tested on Samsung Goni.

Mateusz Zalega (10):
New board-specific USB initialization interface
nvidia, tegra: new USB hardware init interface
Voipac PXA270: new USB hardware init interface
Trizeps IV: new USB hardware init interface
Colibri PXA270: new USB hardware init interface
icpdas lp8x4x: new USB hardware init interface
esd pmc440: new USB hardware init interface
esd apc405: new USB hardware init interface
balloon3: new USB hardware init interface
canyonlands: new USB hardware init interface

 arch/arm/include/asm/arch-tegra/usb.h         |  3 +--
 board/amcc/canyonlands/canyonlands.c          |  5 +++--
 board/balloon3/balloon3.c                     |  5 +++--
 board/esd/apc405/apc405.c                     |  5 +++--
 board/esd/pmc440/pmc440.c                     |  5 +++--
 board/icpdas/lp8x4x/lp8x4x.c                  |  5 +++--
 board/nvidia/common/board.c                   | 14 ++++++++++----
 board/toradex/colibri_pxa270/colibri_pxa270.c |  5 +++--
 board/trizepsiv/conxs.c                       |  5 +++--
 board/vpac270/vpac270.c                       |  5 +++--
 common/cmd_dfu.c                              |  5 ++---
 common/cmd_usb_mass_storage.c                 |  3 ++-
 common/usb.c                                  |  5 +++++
 drivers/usb/host/ehci-omap.c                  |  8 +-------
 drivers/usb/host/ehci-tegra.c                 |  2 +-
 drivers/usb/host/ohci-hcd.c                   |  4 ++--
 drivers/usb/host/ohci.h                       | 12 +++++-------
 include/g_dnl.h                               |  2 --
 include/usb.h                                 | 17 ++++++++++++++++-
 include/usb_mass_storage.h                    | 12 +++++-------
 20 files changed, 74 insertions(+), 53 deletions(-)
Signature · 1 line
1.8.2.1
#1 lore raw

RFC 1/10 New board-specific USB initialization interface

This commit unifies board-specific USB initialization implementations under one symbol (usb_board_init), declaration of which is available in usb.h.

---
 common/cmd_dfu.c              |  5 ++---
 common/cmd_usb_mass_storage.c |  3 ++-
 common/usb.c                  |  5 +++++
 drivers/usb/host/ehci-omap.c  |  8 +-------
 drivers/usb/host/ehci-tegra.c |  2 +-
 drivers/usb/host/ohci-hcd.c   |  4 ++--
 drivers/usb/host/ohci.h       | 12 +++++-------
 include/g_dnl.h               |  2 --
 include/usb.h                 | 17 ++++++++++++++++-
 include/usb_mass_storage.h    | 12 +++++-------
 10 files changed, 39 insertions(+), 31 deletions(-)
common/cmd_dfu.c +2 -3
index db066ac..c701ebc 100644
@@ -14,6 +14,7 @@
 #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[])
 {
@@ -43,9 +44,7 @@ static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		goto done;
 	}
 
-#ifdef CONFIG_TRATS
-	board_usb_init();
-#endif
+	board_usb_init(USB_INIT_DEVICE);
 
 	g_dnl_register(s);
 	while (1) {
common/cmd_usb_mass_storage.c +2 -1
index 33a4715..86135b4 100644
@@ -9,6 +9,7 @@
 #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,
@@ -33,7 +34,7 @@ int do_usb_mass_storage(cmd_tbl_t *cmdtp, int flag,
 		goto fail;
 	}
 
-	board_usb_init();
+	board_usb_init(USB_INIT_DEVICE);
 	ums_info = board_ums_init(dev_num, offset, part_size);
 
 	if (!ums_info) {
common/usb.c +5 -0
index f740e5e..793fb35 100644
@@ -982,4 +982,9 @@ int usb_new_device(struct usb_device *dev)
 	return 0;
 }
 
+__attribute__((weak))
+int board_usb_init(enum board_usb_init_type what_to_init)
+{
+	return 0;
+}
 /* EOF */
drivers/usb/host/ehci-omap.c +1 -7
index a47e078..61b7c8d 100644
@@ -86,12 +86,6 @@ static void omap_ehci_soft_phy_reset(int port)
 	ulpi_reset(&ulpi_vp);
 }
 
-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)
 /* controls PHY(s) reset signal(s) */
@@ -150,7 +144,7 @@ int omap_ehci_hcd_init(struct omap_usbhs_board_data *usbhs_pdata,
 
 	debug("Initializing OMAP EHCI\n");
 
-	ret = board_usb_init();
+	ret = board_usb_init(USB_INIT_HOST);
 	if (ret < 0)
 		return ret;
 
drivers/usb/host/ehci-tegra.c +1 -1
index c6da449..cc23133 100644
@@ -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;
drivers/usb/host/ohci-hcd.c +2 -2
index c33c487..e6a5623 100644
@@ -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(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_init_fail();
 #endif
 
 #ifdef CONFIG_SYS_USB_OHCI_CPU_INIT
drivers/usb/host/ohci.h +5 -7
index d977e8f..9f7f961 100644
@@ -19,14 +19,12 @@
 #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 board_usb_init_fail(void);
 
+int usb_cpu_init(void);
+int usb_cpu_stop(void);
+int usb_cpu_init_fail(void);
 
 static int cc_to_error[16] = {
 
include/g_dnl.h +0 -2
index 2b2f11a..b6c4dd4 100644
@@ -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_ */
include/usb.h +16 -1
index 60db897..29f67bf 100644
@@ -165,10 +165,25 @@ 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, device or both
+ * capabilities by passing this enum as an argument to
+ * board_usb_init().
+ */
+enum board_usb_init_type {
+	USB_INIT_ALL,
+	USB_INIT_HOST,
+	USB_INIT_DEVICE
+};
+
+/* board-specific hardware initialization, called by
+ * usb drivers and u-boot commands
+ */
+int board_usb_init(enum board_usb_init_type what_to_init);
+
 #ifdef CONFIG_USB_STORAGE
 
 #define USB_MAX_STOR_DEV 5
include/usb_mass_storage.h +5 -7
index 35cdcc3..de31b0e 100644
@@ -30,13 +30,11 @@ 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,
+int fsg_init(struct ums_board_info *);
+void fsg_cleanup(void);
+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 usb_gadget_handle_interrupts(void);
+int fsg_main_thread(void *);
 
 #endif /* __USB_MASS_STORAGE_H__ */
Signature · 1 line
1.8.2.1
#2 lore raw

RFC 1/10 New board-specific USB initialization interface

drivers/usb/host/ehci-tegra.c static int process_usb_nodes(const void *blob, int node_list[], int count) · line 705

Quoted 11 lines · Mateusz Zalega

This commit unifies board-specific USB initialization implementations under one symbol (usb_board_init), declaration of which is available in usb.h.

drivers/usb/host/ehci-tegra.c +1 -1
 
-int board_usb_init(const void *blob)
+int usb_process_devicetree(const void *blob)
 {
 	int node_list[USB_PORTS_MAX];
 	int count, err = 0;

With just this patch applied, nothing calls that function. This breaks "git bisect".

#3 lore raw

RFC 1/10 New board-specific USB initialization interface

In reply to Mateusz Zalega

Dear Mateusz Zalega,

Quoted 20 lines

This commit unifies board-specific USB initialization implementations under one symbol (usb_board_init), declaration of which is available in usb.h.

---
 common/cmd_dfu.c              |  5 ++---
 common/cmd_usb_mass_storage.c |  3 ++-
 common/usb.c                  |  5 +++++
 drivers/usb/host/ehci-omap.c  |  8 +-------
 drivers/usb/host/ehci-tegra.c |  2 +-
 drivers/usb/host/ohci-hcd.c   |  4 ++--
 drivers/usb/host/ohci.h       | 12 +++++-------
 include/g_dnl.h               |  2 --
 include/usb.h                 | 17 ++++++++++++++++-
 include/usb_mass_storage.h    | 12 +++++-------
 10 files changed, 39 insertions(+), 31 deletions(-)

[...]

Quoted 6 lines
include/usb.h +0 -0
@@ -165,10 +165,25 @@ int submit_int_msg(struct usb_device *dev, unsigned
 long pipe, void *buffer,
 
 extern void udc_disconnect(void);

include/usb.h int submit_int_msg(struct usb_device *dev, unsigned · line 176

Quoted 10 lines
include/usb.h +5 -1
 
-#else
+#elif !defined(CONFIG_USB_GADGET)
 #error USB Lowlevel not defined
 #endif
 
+/* You can initialize platform's USB host, device or both
+ * capabilities by passing this enum as an argument to
+ * board_usb_init().
+ */

The comment style is wrong, please fix. Did the patchset pass checkpatch ?

/*
* multi
* line
* comment
*/

Quoted 27 lines
include/usb.h +11 -0
+enum board_usb_init_type {
+	USB_INIT_ALL,
+	USB_INIT_HOST,
+	USB_INIT_DEVICE
+};
+
+/* board-specific hardware initialization, called by
+ * usb drivers and u-boot commands
+ */
+int board_usb_init(enum board_usb_init_type what_to_init);
+
 #ifdef CONFIG_USB_STORAGE
 

#define USB_MAX_STOR_DEV 5

include/usb_mass_storage.h +0 -5
index 35cdcc3..de31b0e 100644
@@ -30,13 +30,11 @@ 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,

include/usb_mass_storage.h struct ums_board_info { · line 40

Quoted 10 lines
include/usb_mass_storage.h +5 -2
+int fsg_init(struct ums_board_info *);
+void fsg_cleanup(void);
+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 usb_gadget_handle_interrupts(void);
+int fsg_main_thread(void *);
 
 #endif /* __USB_MASS_STORAGE_H__ */

Best regards,
Marek Vasut

#4 lore raw

RFC 1/10 New board-specific USB initialization interface

Quoted 5 lines · Marek Vasut
Quoted 4 lines

+/* You can initialize platform's USB host, device or both
+ * capabilities by passing this enum as an argument to
+ * board_usb_init().
+ */

Quoted 7 lines

The comment style is wrong, please fix. Did the patchset pass checkpatch ?

/*
* multi
* line
* comment
*/

Yes, it did:

---8<---

$ ./tools/checkpatch.pl
0001-New-board-specific-USB-initialization-interface.patch
total: 0 errors, 0 warnings, 0 checks, 154 lines checked

NOTE: Ignored message types: COMPLEX_MACRO CONSIDER_KSTRTO MINMAX MULTISTATEMENT_MACRO_USE_DO_WHILE NETWORKING_BLOCK_COMMENT_STYLE USLEEP_RANGE

0001-New-board-specific-USB-initialization-interface.patch has no obvious style problems and is ready for submission. --->8---

NETWORKING_BLOCK_COMMENT_STYLE - ...and, in our case, this option is the culprit. Will fix.

Thanks,

Signature · 2 lines
Mateusz Zalega
Samsung R&D Institute Poland (SRPOL) | Kernel and System Framework group
#5 lore raw

RFC 2/10 nvidia, tegra: new USB hardware init interface

In reply to Mateusz Zalega

This commit postpones initialization of USB hardware until usb_board_init() is called by a command implementation (ie. do_dfu()) or a driver.

---
 arch/arm/include/asm/arch-tegra/usb.h |  3 +--
 board/nvidia/common/board.c           | 14 ++++++++++----
 2 files changed, 11 insertions(+), 6 deletions(-)
arch/arm/include/asm/arch-tegra/usb.h +1 -2
index f66257c..a1efd07 100644
@@ -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_ */
board/nvidia/common/board.c +10 -4
index 126e56e..cdb02ee 100644
@@ -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>
@@ -151,10 +152,6 @@ int board_init(void)
 # endif /* CONFIG_TEGRA_PMU */
 #endif /* CONFIG_SYS_I2C_TEGRA */
 
-#ifdef CONFIG_USB_EHCI_TEGRA
-	pin_mux_usb();
-	board_usb_init(gd->fdt_blob);
-#endif
 #ifdef CONFIG_LCD
 	tegra_lcd_check_next_stage(gd->fdt_blob, 0);
 #endif
@@ -257,3 +254,12 @@ void pad_init_mmc(struct mmc_host *host)
 #endif	/* T30 */
 }
 #endif	/* MMC */
+
+#ifdef CONFIG_USB_EHCI_TEGRA
+int board_usb_init(enum board_usb_init_type what_to_init)
+{
+	pin_mux_usb();
+	usb_process_devicetree(gd->fdt_blob);
+	return 0;
+}
+#endif
Signature · 1 line
1.8.2.1
#6 lore raw

RFC 2/10 nvidia, tegra: new USB hardware init interface

arch/arm/include/asm/arch-tegra/usb.h line 135

Quoted 9 lines · Mateusz Zalega

This commit postpones initialization of USB hardware until usb_board_init() is called by a command implementation (ie. do_dfu()) or a driver.

arch/arm/include/asm/arch-tegra/usb.h +1 -1
 
 /* Setup USB on the board */
-int board_usb_init(const void *blob);
+int usb_process_devicetree(const void *blob);

This needs to be part of the previous patch (or part of that patch needs to be split out and put into this patch) so that this prototype change happens in the same patch that the implementation is renamed. Perhaps this can happen before the current patch 1?

Quoted 9 lines
board/nvidia/common/board.c +0 -3
@@ -151,10 +152,6 @@ int board_init(void)
 # endif /* CONFIG_TEGRA_PMU */
 #endif /* CONFIG_SYS_I2C_TEGRA */
 
-#ifdef CONFIG_USB_EHCI_TEGRA
-	pin_mux_usb();
-	board_usb_init(gd->fdt_blob);

board/nvidia/common/board.c int board_init(void)

Quoted 10 lines
board/nvidia/common/board.c +8 -1
-#endif
 
+#ifdef CONFIG_USB_EHCI_TEGRA
+int board_usb_init(enum board_usb_init_type what_to_init)
+{
+	pin_mux_usb();
+	usb_process_devicetree(gd->fdt_blob);
+	return 0;
+}
+#endif

Moving the pinmux initialization might be dangerous; pin_mux_usb() might prevent the pins used for USB having a mux function selected that conflicts with some other pins selected mux function. We really do need to initialize all of the pinmux early, and not defer it.

#7 lore raw

RFC 3/10 Voipac PXA270: new USB hardware init interface

In reply to Mateusz Zalega

This commit changes name of an existing initialization function to board_usb_init(), so that such functions could be reached by every USB driver and command (ie. do_dfu()).

---
 board/vpac270/vpac270.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
board/vpac270/vpac270.c +3 -2
index 616736f..ac941e7 100644
@@ -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(enum board_usb_init_type what_to_init)
 {
 	writel((UHCHR | UHCHR_PCPL | UHCHR_PSPL) &
 		~(UHCHR_SSEP0 | UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSE),
@@ -97,7 +98,7 @@ int usb_board_init(void)
 	return 0;
 }
 
-void usb_board_init_fail(void)
+void board_usb_init_fail(void)
 {
 	return;
 }
Signature · 1 line
1.8.2.1
#8 lore raw

RFC 4/10 Trizeps IV: new USB hardware init interface

In reply to Mateusz Zalega

This commit changes name of an existing initialization function to board_usb_init(), so that such functions could be reached by every USB driver and command (ie. do_dfu()).

---
 board/trizepsiv/conxs.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
board/trizepsiv/conxs.c +3 -2
index c0c318f..9c00ea5 100644
@@ -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(enum board_usb_init_type what_to_init)
 {
 	writel((readl(UHCHR) | UHCHR_PCPL | UHCHR_PSPL) &
 		~(UHCHR_SSEP0 | UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSE),
@@ -69,7 +70,7 @@ int usb_board_init(void)
 	return 0;
 }
 
-void usb_board_init_fail(void)
+void board_usb_init_fail(void)
 {
 	return;
 }
Signature · 1 line
1.8.2.1
#9 lore raw

RFC 5/10 Colibri PXA270: new USB hardware init interface

In reply to Mateusz Zalega

This commit changes name of an existing initialization function to board_usb_init(), so that such functions could be reached by every USB driver and command (ie. do_dfu()).

---
 board/toradex/colibri_pxa270/colibri_pxa270.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
board/toradex/colibri_pxa270/colibri_pxa270.c +3 -2
index c1e2562..3bc69bb 100644
@@ -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(enum board_usb_init_type what_to_init)
 {
 	writel((readl(UHCHR) | UHCHR_PCPL | UHCHR_PSPL) &
 		~(UHCHR_SSEP0 | UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSE),
@@ -70,7 +71,7 @@ int usb_board_init(void)
 	return 0;
 }
 
-void usb_board_init_fail(void)
+void board_usb_init_fail(void)
 {
 	return;
 }
Signature · 1 line
1.8.2.1
#10 lore raw

RFC 6/10 icpdas lp8x4x: new USB hardware init interface

In reply to Mateusz Zalega

This commit changes name of an existing initialization function to board_usb_init(), so that such functions could be reached by every USB driver and command (ie. do_dfu()).

---
 board/icpdas/lp8x4x/lp8x4x.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
board/icpdas/lp8x4x/lp8x4x.c +3 -2
index 1b68ef3..54f8bba 100644
@@ -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(enum board_usb_init_type what_to_init)
 {
 	writel((UHCHR | UHCHR_PCPL | UHCHR_PSPL) &
 		~(UHCHR_SSEP0 | UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSE),
@@ -89,7 +90,7 @@ int usb_board_init(void)
 	return 0;
 }
 
-void usb_board_init_fail(void)
+void board_usb_init_fail(void)
 {
 	return;
 }
Signature · 1 line
1.8.2.1
#11 lore raw

RFC 6/10 icpdas lp8x4x: new USB hardware init interface

Dear Mateusz Zalega,

Quoted 10 lines

This commit changes name of an existing initialization function to board_usb_init(), so that such functions could be reached by every USB driver and command (ie. do_dfu()).

---
 board/icpdas/lp8x4x/lp8x4x.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Saw 03-06, OK.

Quoted 22 lines
board/icpdas/lp8x4x/lp8x4x.c +2 -1
index 1b68ef3..54f8bba 100644
@@ -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(enum board_usb_init_type what_to_init)
 {
 	writel((UHCHR | UHCHR_PCPL | UHCHR_PSPL) &
 		~(UHCHR_SSEP0 | UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSE),

board/icpdas/lp8x4x/lp8x4x.c int usb_board_init(void) · line 96

Quoted 8 lines
board/icpdas/lp8x4x/lp8x4x.c +1 -1
@@ -89,7 +90,7 @@ int usb_board_init(void)
 	return 0;
 }
 
-void usb_board_init_fail(void)
+void board_usb_init_fail(void)
 {
 	return;
 }

Best regards,
Marek Vasut

#12 lore raw

RFC 7/10 esd pmc440: new USB hardware init interface

In reply to Mateusz Zalega

This commit changes name of an existing initialization function to board_usb_init(), so that such functions could be reached by every USB driver and command (ie. do_dfu()).

---
 board/esd/pmc440/pmc440.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
board/esd/pmc440/pmc440.c +3 -2
index 549b3b7..4cdfb7c 100644
@@ -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(enum board_usb_init_type what_to_init)
 {
 	char *act = getenv("usbact");
 	int i;
@@ -845,7 +846,7 @@ int usb_board_stop(void)
 	return 0;
 }
 
-int usb_board_init_fail(void)
+int board_usb_init_fail(void)
 {
 	usb_board_stop();
 	return 0;
Signature · 1 line
1.8.2.1
#13 lore raw

RFC 8/10 esd apc405: new USB hardware init interface

In reply to Mateusz Zalega

This commit changes name of an existing initialization function to board_usb_init(), so that such functions could be reached by every USB driver and command (ie. do_dfu()).

---
 board/esd/apc405/apc405.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
board/esd/apc405/apc405.c +3 -2
index f13f088..a05f771 100644
@@ -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(enum board_usb_init_type what_to_init)
 {
 	return 0;
 }
@@ -453,7 +454,7 @@ int usb_board_stop(void)
 	return 0;
 }
 
-int usb_board_init_fail(void)
+int board_usb_init_fail(void)
 {
 	usb_board_stop();
 	return 0;
Signature · 1 line
1.8.2.1
#14 lore raw

RFC 9/10 balloon3: new USB hardware init interface

In reply to Mateusz Zalega

This commit changes name of an existing initialization function to board_usb_init(), so that such functions could be reached by every USB driver and command (ie. do_dfu()).

---
 board/balloon3/balloon3.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
board/balloon3/balloon3.c +3 -2
index ecbac16..d92d843 100644
@@ -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(enum board_usb_init_type what_to_init)
 {
 	writel((readl(UHCHR) | UHCHR_PCPL | UHCHR_PSPL) &
 		~(UHCHR_SSEP0 | UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSE),
@@ -90,7 +91,7 @@ int usb_board_init(void)
 	return 0;
 }
 
-void usb_board_init_fail(void)
+void board_usb_init_fail(void)
 {
 	return;
 }
Signature · 1 line
1.8.2.1
#15 lore raw

RFC 10/10 canyonlands: new USB hardware init interface

In reply to Mateusz Zalega

This commit changes name of an existing initialization function to board_usb_init(), so that such functions could be reached by every USB driver and command (ie. do_dfu()).

---
 board/amcc/canyonlands/canyonlands.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
board/amcc/canyonlands/canyonlands.c +3 -2
index cc36f45..31db133 100644
@@ -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(enum board_usb_init_type what_to_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_init_fail(void)
 {
 	return usb_board_stop();
 }
Signature · 1 line
1.8.2.1
#16 lore raw

cover New board-specific USB initialization interface

In reply to Mateusz Zalega

Dear Mateusz Zalega,

Quoted 8 lines · In message <[email protected]> you wrote:

Current implementation of do_dfu() and do_usb_mass_storage() requires board-specific board_usb_init() which performs USB hardware initialization.

I noticed that several boards have such a function defined, named either usb_board_init() (which binds to ohci-hcd.c driver and had been used solely by it) or board_usb_init() (as in ehci-omap.c). I _assumed_ that these functions do what's required by do_*() and renamed the earlier in order to unify the naming convention.

I appreciate your efforts, but this whole area clearly falls into the domain of the device model rework. Is your suggested implementation in any way synchronized with what has been discussed about this topic before?

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
It is easier to write an incorrect program than understand a  correct
one.
#17 lore raw

cover New board-specific USB initialization interface

Quoted 12 lines · Wolfgang Denk

Dear Mateusz Zalega,

Quoted 8 lines · In message <[email protected]> you wrote:

Current implementation of do_dfu() and do_usb_mass_storage() requires board-specific board_usb_init() which performs USB hardware initialization.

I noticed that several boards have such a function defined, named either usb_board_init() (which binds to ohci-hcd.c driver and had been used solely by it) or board_usb_init() (as in ehci-omap.c). I _assumed_ that these functions do what's required by do_*() and renamed the earlier in order to unify the naming convention.

Quoted 4 lines

I appreciate your efforts, but this whole area clearly falls into the domain of the device model rework. Is your suggested implementation in any way synchronized with what has been discussed about this topic before?

Hello,

I've caught up with driver model discussion. The changes I submitted are related to sharing of board-specific hardware initialization functions between drivers, therefore my patches, if I don't miss anything, do not collide with driver model rework - these changes would have to be done anyway.

Regards,

Signature · 2 lines
Mateusz Zalega
Samsung R&D Institute Poland (SRPOL) | Kernel and System Framework group
#18 lore raw

cover New board-specific USB initialization interface

Quoted 18 lines · Wolfgang Denk
Quoted 12 lines

Dear Mateusz Zalega,

Quoted 8 lines · In message <[email protected]> you wrote:

Current implementation of do_dfu() and do_usb_mass_storage() requires board-specific board_usb_init() which performs USB hardware initialization.

I noticed that several boards have such a function defined, named either usb_board_init() (which binds to ohci-hcd.c driver and had been used solely by it) or board_usb_init() (as in ehci-omap.c). I _assumed_ that these functions do what's required by do_*() and renamed the earlier in order to unify the naming convention.

Quoted 4 lines

I appreciate your efforts, but this whole area clearly falls into the domain of the device model rework. Is your suggested implementation in any way synchronized with what has been discussed about this topic before?

Quoted 5 lines

I've caught up with driver model discussion. The changes I submitted are related to sharing of board-specific hardware initialization functions between drivers, therefore my patches, if I don't miss anything, do not collide with driver model rework - these changes would have to be done anyway.

If new USB driver model would use some other API to deal with board-specific functions, please correct me. I didn't manage to find related information, maybe I didn't look for it carefully enough.

Signature · 2 lines
Mateusz Zalega
Samsung R&D Institute Poland (SRPOL) | Kernel and System Framework group
#19 lore raw

cover New board-specific USB initialization interface

In reply to Mateusz Zalega

Dear Mateusz Zalega,

Quoted 11 lines · In message <[email protected]> you wrote:
Quoted 5 lines

I appreciate your efforts, but this whole area clearly falls into the domain of the device model rework. Is your suggested implementation in any way synchronized with what has been discussed about this topic before?

I've caught up with driver model discussion. The changes I submitted are related to sharing of board-specific hardware initialization functions between drivers, therefore my patches, if I don't miss anything, do not collide with driver model rework - these changes would have to be done anyway.

OK, thanks for checking!

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"The one charm of marriage is that it makes a  life  of  deception  a
neccessity."                                            - Oscar Wilde
#20 lore raw

PATCH 1/1 usb: new board-specific USB init interface

In reply to Mateusz Zalega

This commit unifies board-specific USB initialization implementations under one symbol (usb_board_init), declaration of which is available in usb.h.

---
Changes since RFC:
- 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

---
 arch/arm/include/asm/arch-tegra/usb.h         |  3 +--
 board/amcc/canyonlands/canyonlands.c          |  5 +++--
 board/balloon3/balloon3.c                     |  5 +++--
 board/esd/apc405/apc405.c                     |  5 +++--
 board/esd/pmc440/pmc440.c                     |  5 +++--
 board/icpdas/lp8x4x/lp8x4x.c                  |  5 +++--
 board/nvidia/common/board.c                   |  4 +++-
 board/samsung/trats/trats.c                   |  5 +++--
 board/toradex/colibri_pxa270/colibri_pxa270.c |  5 +++--
 board/trizepsiv/conxs.c                       |  5 +++--
 board/vpac270/vpac270.c                       |  5 +++--
 common/cmd_dfu.c                              |  5 ++---
 common/cmd_usb_mass_storage.c                 |  3 ++-
 common/usb.c                                  |  5 +++++
 drivers/usb/host/ehci-omap.c                  |  8 +-------
 drivers/usb/host/ehci-tegra.c                 |  2 +-
 drivers/usb/host/ohci-hcd.c                   |  4 ++--
 drivers/usb/host/ohci.h                       | 12 +++++-------
 include/g_dnl.h                               |  2 --
 include/usb.h                                 | 19 ++++++++++++++++++-
 include/usb_mass_storage.h                    | 12 +++++-------
 21 files changed, 72 insertions(+), 52 deletions(-)
arch/arm/include/asm/arch-tegra/usb.h +1 -2
index f66257c..a1efd07 100644
@@ -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_ */
board/amcc/canyonlands/canyonlands.c +3 -2
index cc36f45..27ab243 100644
@@ -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(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_init_fail(void)
 {
 	return usb_board_stop();
 }
board/balloon3/balloon3.c +3 -2
index ecbac16..b15d60f 100644
@@ -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(enum board_usb_init_type init)
 {
 	writel((readl(UHCHR) | UHCHR_PCPL | UHCHR_PSPL) &
 		~(UHCHR_SSEP0 | UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSE),
@@ -90,7 +91,7 @@ int usb_board_init(void)
 	return 0;
 }
 
-void usb_board_init_fail(void)
+void board_usb_init_fail(void)
 {
 	return;
 }
board/esd/apc405/apc405.c +3 -2
index f13f088..8f0fd1c 100644
@@ -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(enum board_usb_init_type init)
 {
 	return 0;
 }
@@ -453,7 +454,7 @@ int usb_board_stop(void)
 	return 0;
 }
 
-int usb_board_init_fail(void)
+int board_usb_init_fail(void)
 {
 	usb_board_stop();
 	return 0;
board/esd/pmc440/pmc440.c +3 -2
index 549b3b7..6a3b52a 100644
@@ -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(enum board_usb_init_type init)
 {
 	char *act = getenv("usbact");
 	int i;
@@ -845,7 +846,7 @@ int usb_board_stop(void)
 	return 0;
 }
 
-int usb_board_init_fail(void)
+int board_usb_init_fail(void)
 {
 	usb_board_stop();
 	return 0;
board/icpdas/lp8x4x/lp8x4x.c +3 -2
index 1b68ef3..622ca28 100644
@@ -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(enum board_usb_init_type init)
 {
 	writel((UHCHR | UHCHR_PCPL | UHCHR_PSPL) &
 		~(UHCHR_SSEP0 | UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSE),
@@ -89,7 +90,7 @@ int usb_board_init(void)
 	return 0;
 }
 
-void usb_board_init_fail(void)
+void board_usb_init_fail(void)
 {
 	return;
 }
board/nvidia/common/board.c +3 -1
index 126e56e..1972527 100644
@@ -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
board/samsung/trats/trats.c +3 -2
index c8698f3..d15e1fe 100644
@@ -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"
@@ -488,10 +489,10 @@ struct s3c_plat_otg_data s5pc210_otg_data = {
 	.usb_flags	= PHY0_SLEEP,
 };
 
-void board_usb_init(void)
+int board_usb_init(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
 
board/toradex/colibri_pxa270/colibri_pxa270.c +3 -2
index c1e2562..5437290 100644
@@ -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(enum board_usb_init_type init)
 {
 	writel((readl(UHCHR) | UHCHR_PCPL | UHCHR_PSPL) &
 		~(UHCHR_SSEP0 | UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSE),
@@ -70,7 +71,7 @@ int usb_board_init(void)
 	return 0;
 }
 
-void usb_board_init_fail(void)
+void board_usb_init_fail(void)
 {
 	return;
 }
board/trizepsiv/conxs.c +3 -2
index c0c318f..01264b3 100644
@@ -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(enum board_usb_init_type init)
 {
 	writel((readl(UHCHR) | UHCHR_PCPL | UHCHR_PSPL) &
 		~(UHCHR_SSEP0 | UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSE),
@@ -69,7 +70,7 @@ int usb_board_init(void)
 	return 0;
 }
 
-void usb_board_init_fail(void)
+void board_usb_init_fail(void)
 {
 	return;
 }
board/vpac270/vpac270.c +3 -2
index 616736f..3ec81f3 100644
@@ -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(enum board_usb_init_type init)
 {
 	writel((UHCHR | UHCHR_PCPL | UHCHR_PSPL) &
 		~(UHCHR_SSEP0 | UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSE),
@@ -97,7 +98,7 @@ int usb_board_init(void)
 	return 0;
 }
 
-void usb_board_init_fail(void)
+void board_usb_init_fail(void)
 {
 	return;
 }
common/cmd_dfu.c +2 -3
index 793c422..7122423 100644
@@ -14,6 +14,7 @@
 #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[])
 {
@@ -43,9 +44,7 @@ static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		goto done;
 	}
 
-#ifdef CONFIG_TRATS
-	board_usb_init();
-#endif
+	board_usb_init(USB_INIT_DEVICE);
 
 	g_dnl_register(s);
 	while (1) {
common/cmd_usb_mass_storage.c +2 -1
index 33a4715..86135b4 100644
@@ -9,6 +9,7 @@
 #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,
@@ -33,7 +34,7 @@ int do_usb_mass_storage(cmd_tbl_t *cmdtp, int flag,
 		goto fail;
 	}
 
-	board_usb_init();
+	board_usb_init(USB_INIT_DEVICE);
 	ums_info = board_ums_init(dev_num, offset, part_size);
 
 	if (!ums_info) {
common/usb.c +5 -0
index f740e5e..307e47a 100644
@@ -982,4 +982,9 @@ int usb_new_device(struct usb_device *dev)
 	return 0;
 }
 
+__attribute__((weak))
+int board_usb_init(enum board_usb_init_type init)
+{
+	return 0;
+}
 /* EOF */
drivers/usb/host/ehci-omap.c +1 -7
index 032d5e5..fd8c4d8 100644
@@ -89,12 +89,6 @@ static void omap_ehci_soft_phy_reset(int port)
 	ulpi_reset(&ulpi_vp);
 }
 
-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)
 /* controls PHY(s) reset signal(s) */
@@ -153,7 +147,7 @@ int omap_ehci_hcd_init(struct omap_usbhs_board_data *usbhs_pdata,
 
 	debug("Initializing OMAP EHCI\n");
 
-	ret = board_usb_init();
+	ret = board_usb_init(USB_INIT_HOST);
 	if (ret < 0)
 		return ret;
 
drivers/usb/host/ehci-tegra.c +1 -1
index c6da449..cc23133 100644
@@ -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;
drivers/usb/host/ohci-hcd.c +2 -2
index c33c487..e6a5623 100644
@@ -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(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_init_fail();
 #endif
 
 #ifdef CONFIG_SYS_USB_OHCI_CPU_INIT
drivers/usb/host/ohci.h +5 -7
index d977e8f..9f7f961 100644
@@ -19,14 +19,12 @@
 #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 board_usb_init_fail(void);
 
+int usb_cpu_init(void);
+int usb_cpu_stop(void);
+int usb_cpu_init_fail(void);
 
 static int cc_to_error[16] = {
 
include/g_dnl.h +0 -2
index 2b2f11a..b6c4dd4 100644
@@ -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_ */
include/usb.h +18 -1
index 60db897..2ee867f 100644
@@ -165,10 +165,27 @@ 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, device or both
+ * capabilities by passing this enum as an argument to
+ * board_usb_init().
+ */
+enum board_usb_init_type {
+	USB_INIT_ALL,
+	USB_INIT_HOST,
+	USB_INIT_DEVICE
+};
+
+/*
+ * board-specific hardware initialization, called by
+ * usb drivers and u-boot commands
+ */
+int board_usb_init(enum board_usb_init_type init);
+
 #ifdef CONFIG_USB_STORAGE
 
 #define USB_MAX_STOR_DEV 5
include/usb_mass_storage.h +5 -7
index 35cdcc3..de31b0e 100644
@@ -30,13 +30,11 @@ 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,
+int fsg_init(struct ums_board_info *);
+void fsg_cleanup(void);
+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 usb_gadget_handle_interrupts(void);
+int fsg_main_thread(void *);
 
 #endif /* __USB_MASS_STORAGE_H__ */
Signature · 1 line
1.8.2.1
#21 lore raw

PATCH 1/1 usb: new board-specific USB init interface

Dear Mateusz Zalega,

Quoted 33 lines

This commit unifies board-specific USB initialization implementations under one symbol (usb_board_init), declaration of which is available in usb.h.

---
Changes since RFC:
- 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

---
 arch/arm/include/asm/arch-tegra/usb.h         |  3 +--
 board/amcc/canyonlands/canyonlands.c          |  5 +++--
 board/balloon3/balloon3.c                     |  5 +++--
 board/esd/apc405/apc405.c                     |  5 +++--
 board/esd/pmc440/pmc440.c                     |  5 +++--
 board/icpdas/lp8x4x/lp8x4x.c                  |  5 +++--
 board/nvidia/common/board.c                   |  4 +++-
 board/samsung/trats/trats.c                   |  5 +++--
 board/toradex/colibri_pxa270/colibri_pxa270.c |  5 +++--
 board/trizepsiv/conxs.c                       |  5 +++--
 board/vpac270/vpac270.c                       |  5 +++--
 common/cmd_dfu.c                              |  5 ++---
 common/cmd_usb_mass_storage.c                 |  3 ++-
 common/usb.c                                  |  5 +++++
Quoted 8 lines
 drivers/usb/host/ehci-omap.c                  |  8 +-------
 drivers/usb/host/ehci-tegra.c                 |  2 +-
 drivers/usb/host/ohci-hcd.c                   |  4 ++--
 drivers/usb/host/ohci.h                       | 12 +++++-------
 include/g_dnl.h                               |  2 --
 include/usb.h                                 | 19 ++++++++++++++++++-
 include/usb_mass_storage.h                    | 12 +++++-------
 21 files changed, 72 insertions(+), 52 deletions(-)

The EHCI supports multi-bus thing (passing the controller *), will this be viable to pass in this case too, so the busses can be inited selectively in host/gadget functions?

Best regards,
Marek Vasut

#22 lore raw

PATCH 1/1 usb: new board-specific USB init interface

Quoted 3 lines · Marek Vasut

The EHCI supports multi-bus thing (passing the controller *), will this be viable to pass in this case too, so the busses can be inited selectively in host/gadget functions?

Hello, Marek.
I need more context. Could you show me the part of code in which you'd like to pass/use additional arguments?

Regards,

Signature · 2 lines
Mateusz Zalega
Samsung R&D Institute Poland
#23 lore raw

PATCH 1/1 usb: new board-specific USB init interface

Dear Mateusz Zalega,

Quoted 8 lines · Marek Vasut
Quoted 3 lines

The EHCI supports multi-bus thing (passing the controller *), will this be viable to pass in this case too, so the busses can be inited selectively in host/gadget functions?

Hello, Marek.
I need more context. Could you show me the part of code in which you'd like to pass/use additional arguments?

Please grep the 'controller' pointer that is passed to various functions at least in the EHCI case. It would be nice to pass that to the init functions too, no?

Best regards,
Marek Vasut

#24 lore raw

PATCH 1/1 usb: new board-specific USB init interface

Quoted 11 lines
Quoted 7 lines
Quoted 3 lines

The EHCI supports multi-bus thing (passing the controller *), will this be viable to pass in this case too, so the busses can be inited selectively in host/gadget functions?

Hello, Marek.
I need more context. Could you show me the part of code in which you'd like to pass/use additional arguments?

Please grep the 'controller' pointer that is passed to various functions at least in the EHCI case. It would be nice to pass that to the init functions too, no?

It may be possible, but note that board_usb_init() is not used solely by EHCI code (please grep or cscope function calls). In order to do that, we would need to devise some generic interface.

Is it worth the time? Are there targets that would benefit from this change?

Signature · 2 lines
Mateusz Zalega
Samsung R&D Institute Poland
#25 lore raw

PATCH 1/1 usb: new board-specific USB init interface

Dear Mateusz Zalega,

Quoted 12 lines
Quoted 11 lines
Quoted 7 lines
Quoted 3 lines

The EHCI supports multi-bus thing (passing the controller *), will this be viable to pass in this case too, so the busses can be inited selectively in host/gadget functions?

Hello, Marek.
I need more context. Could you show me the part of code in which you'd like to pass/use additional arguments?

Please grep the 'controller' pointer that is passed to various functions at least in the EHCI case. It would be nice to pass that to the init functions too, no?

Quoted 6 lines

It may be possible, but note that board_usb_init() is not used solely by EHCI code (please grep or cscope function calls). In order to do that, we would need to devise some generic interface.

Is it worth the time? Are there targets that would benefit from this change?

In case you want to separatelly init one port for USB peripheral mode and one for Host mode, yes.

Best regards,
Marek Vasut

#26 lore raw

PATCH 1/1 usb: new board-specific USB init interface

Quoted 18 lines · Marek Vasut

Dear Mateusz Zalega,

Quoted 16 lines
Quoted 11 lines
Quoted 7 lines
Quoted 3 lines

The EHCI supports multi-bus thing (passing the controller *), will this be viable to pass in this case too, so the busses can be inited selectively in host/gadget functions?

Hello, Marek.
I need more context. Could you show me the part of code in which you'd like to pass/use additional arguments?

Please grep the 'controller' pointer that is passed to various functions at least in the EHCI case. It would be nice to pass that to the init functions too, no?

It may be possible, but note that board_usb_init() is not used solely by EHCI code (please grep or cscope function calls). In order to do that, we would need to devise some generic interface.

Quoted 5 lines
Quoted 2 lines

Is it worth the time? Are there targets that would benefit from this change?

In case you want to separatelly init one port for USB peripheral mode and one for Host mode, yes.

We could add another argument: "int controller_index" (or maybe "const char* controller_id"), which would correspond to node names or aliases defined in devicetree source files (ie. see: tegra30.dtsi). List of available controllers would be accesible via ie. "usb list" command. Implementations of board_usb_init() would lookup applicable hardware in gd_t.

We would need to find a way to differentiate between these controllers in cases when it would be expected from u-boot to automatically initialize devices it needs. It looks easy in case of ehci-tegra.c.

Devicetree-agnostic boards would have their own "usb list" implementation, and those of them that can't initialize their controllers selectively would be left the way they are with just one additional, unused board_usb_init() argument.

Signature · 2 lines
Mateusz Zalega
Samsung R&D Institute Poland
#27 lore raw

PATCH 1/1 usb: new board-specific USB init interface

Dear Mateusz Zalega,

Quoted 22 lines · Marek Vasut
Quoted 21 lines

Dear Mateusz Zalega,

Quoted 18 lines
Quoted 11 lines
Quoted 7 lines
Quoted 3 lines

The EHCI supports multi-bus thing (passing the controller *), will this be viable to pass in this case too, so the busses can be inited selectively in host/gadget functions?

Hello, Marek.
I need more context. Could you show me the part of code in which you'd like to pass/use additional arguments?

Please grep the 'controller' pointer that is passed to various functions at least in the EHCI case. It would be nice to pass that to the init functions too, no?

It may be possible, but note that board_usb_init() is not used solely by EHCI code (please grep or cscope function calls). In order to do that, we would need to devise some generic interface.

Is it worth the time? Are there targets that would benefit from this change?

Quoted 6 lines
Quoted 2 lines

In case you want to separatelly init one port for USB peripheral mode and one for Host mode, yes.

We could add another argument: "int controller_index" (or maybe "const char* controller_id"), which would correspond to node names or aliases defined in devicetree source files (ie. see: tegra30.dtsi).

Device tree is completely ortogonal to this. See how "int usb_lowlevel_init(int index, void **controller)" is declared. Pass something similar, index at least. Also pass the mode in which the controller should operate.

Quoted 4 lines

List of
available controllers would be accesible via ie. "usb list" command. Implementations of board_usb_init() would lookup applicable hardware in gd_t.

DT is not present on all platforms, so you _MUST_ handle the non-DT case too.

Quoted 8 lines

We would need to find a way to differentiate between these controllers in cases when it would be expected from u-boot to automatically initialize devices it needs. It looks easy in case of ehci-tegra.c.

Devicetree-agnostic boards would have their own "usb list" implementation, and those of them that can't initialize their controllers selectively would be left the way they are with just one additional, unused board_usb_init() argument.

Best regards,
Marek Vasut

#28 lore raw

PATCH v2 1/1 usb: new board-specific USB init interface

In reply to Mateusz Zalega

This commit unifies board-specific USB initialization implementations under one symbol (usb_board_init), declaration of which is available in usb.h.

---
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

---
 arch/arm/include/asm/arch-tegra/usb.h         |  3 +--
 board/amcc/canyonlands/canyonlands.c          |  5 +++--
 board/balloon3/balloon3.c                     |  5 +++--
 board/esd/apc405/apc405.c                     |  5 +++--
 board/esd/pmc440/pmc440.c                     |  5 +++--
 board/icpdas/lp8x4x/lp8x4x.c                  |  5 +++--
 board/nvidia/common/board.c                   |  4 +++-
 board/samsung/trats/trats.c                   |  5 +++--
 board/toradex/colibri_pxa270/colibri_pxa270.c |  5 +++--
 board/trizepsiv/conxs.c                       |  5 +++--
 board/vpac270/vpac270.c                       |  5 +++--
 common/cmd_dfu.c                              |  5 ++---
 common/cmd_usb_mass_storage.c                 |  3 ++-
 common/usb.c                                  |  5 +++++
 drivers/usb/host/ehci-omap.c                  |  8 +-------
 drivers/usb/host/ehci-tegra.c                 |  2 +-
 drivers/usb/host/ohci-hcd.c                   |  4 ++--
 drivers/usb/host/ohci.h                       | 12 +++++-------
 include/g_dnl.h                               |  2 --
 include/usb.h                                 | 19 ++++++++++++++++++-
 include/usb_mass_storage.h                    | 12 +++++-------
 21 files changed, 72 insertions(+), 52 deletions(-)
arch/arm/include/asm/arch-tegra/usb.h +1 -2
index f66257c..a1efd07 100644
@@ -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_ */
board/amcc/canyonlands/canyonlands.c +3 -2
index cc36f45..27ab243 100644
@@ -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(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_init_fail(void)
 {
 	return usb_board_stop();
 }
board/balloon3/balloon3.c +3 -2
index ecbac16..b15d60f 100644
@@ -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(enum board_usb_init_type init)
 {
 	writel((readl(UHCHR) | UHCHR_PCPL | UHCHR_PSPL) &
 		~(UHCHR_SSEP0 | UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSE),
@@ -90,7 +91,7 @@ int usb_board_init(void)
 	return 0;
 }
 
-void usb_board_init_fail(void)
+void board_usb_init_fail(void)
 {
 	return;
 }
board/esd/apc405/apc405.c +3 -2
index f13f088..8f0fd1c 100644
@@ -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(enum board_usb_init_type init)
 {
 	return 0;
 }
@@ -453,7 +454,7 @@ int usb_board_stop(void)
 	return 0;
 }
 
-int usb_board_init_fail(void)
+int board_usb_init_fail(void)
 {
 	usb_board_stop();
 	return 0;
board/esd/pmc440/pmc440.c +3 -2
index 549b3b7..6a3b52a 100644
@@ -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(enum board_usb_init_type init)
 {
 	char *act = getenv("usbact");
 	int i;
@@ -845,7 +846,7 @@ int usb_board_stop(void)
 	return 0;
 }
 
-int usb_board_init_fail(void)
+int board_usb_init_fail(void)
 {
 	usb_board_stop();
 	return 0;
board/icpdas/lp8x4x/lp8x4x.c +3 -2
index 1b68ef3..622ca28 100644
@@ -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(enum board_usb_init_type init)
 {
 	writel((UHCHR | UHCHR_PCPL | UHCHR_PSPL) &
 		~(UHCHR_SSEP0 | UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSE),
@@ -89,7 +90,7 @@ int usb_board_init(void)
 	return 0;
 }
 
-void usb_board_init_fail(void)
+void board_usb_init_fail(void)
 {
 	return;
 }
board/nvidia/common/board.c +3 -1
index 126e56e..1972527 100644
@@ -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
board/samsung/trats/trats.c +3 -2
index c8698f3..d15e1fe 100644
@@ -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"
@@ -488,10 +489,10 @@ struct s3c_plat_otg_data s5pc210_otg_data = {
 	.usb_flags	= PHY0_SLEEP,
 };
 
-void board_usb_init(void)
+int board_usb_init(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
 
board/toradex/colibri_pxa270/colibri_pxa270.c +3 -2
index c1e2562..5437290 100644
@@ -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(enum board_usb_init_type init)
 {
 	writel((readl(UHCHR) | UHCHR_PCPL | UHCHR_PSPL) &
 		~(UHCHR_SSEP0 | UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSE),
@@ -70,7 +71,7 @@ int usb_board_init(void)
 	return 0;
 }
 
-void usb_board_init_fail(void)
+void board_usb_init_fail(void)
 {
 	return;
 }
board/trizepsiv/conxs.c +3 -2
index c0c318f..01264b3 100644
@@ -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(enum board_usb_init_type init)
 {
 	writel((readl(UHCHR) | UHCHR_PCPL | UHCHR_PSPL) &
 		~(UHCHR_SSEP0 | UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSE),
@@ -69,7 +70,7 @@ int usb_board_init(void)
 	return 0;
 }
 
-void usb_board_init_fail(void)
+void board_usb_init_fail(void)
 {
 	return;
 }
board/vpac270/vpac270.c +3 -2
index 616736f..3ec81f3 100644
@@ -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(enum board_usb_init_type init)
 {
 	writel((UHCHR | UHCHR_PCPL | UHCHR_PSPL) &
 		~(UHCHR_SSEP0 | UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSE),
@@ -97,7 +98,7 @@ int usb_board_init(void)
 	return 0;
 }
 
-void usb_board_init_fail(void)
+void board_usb_init_fail(void)
 {
 	return;
 }
common/cmd_dfu.c +2 -3
index 793c422..7122423 100644
@@ -14,6 +14,7 @@
 #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[])
 {
@@ -43,9 +44,7 @@ static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		goto done;
 	}
 
-#ifdef CONFIG_TRATS
-	board_usb_init();
-#endif
+	board_usb_init(USB_INIT_DEVICE);
 
 	g_dnl_register(s);
 	while (1) {
common/cmd_usb_mass_storage.c +2 -1
index 33a4715..86135b4 100644
@@ -9,6 +9,7 @@
 #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,
@@ -33,7 +34,7 @@ int do_usb_mass_storage(cmd_tbl_t *cmdtp, int flag,
 		goto fail;
 	}
 
-	board_usb_init();
+	board_usb_init(USB_INIT_DEVICE);
 	ums_info = board_ums_init(dev_num, offset, part_size);
 
 	if (!ums_info) {
common/usb.c +5 -0
index f740e5e..307e47a 100644
@@ -982,4 +982,9 @@ int usb_new_device(struct usb_device *dev)
 	return 0;
 }
 
+__attribute__((weak))
+int board_usb_init(enum board_usb_init_type init)
+{
+	return 0;
+}
 /* EOF */
drivers/usb/host/ehci-omap.c +1 -7
index 032d5e5..fd8c4d8 100644
@@ -89,12 +89,6 @@ static void omap_ehci_soft_phy_reset(int port)
 	ulpi_reset(&ulpi_vp);
 }
 
-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)
 /* controls PHY(s) reset signal(s) */
@@ -153,7 +147,7 @@ int omap_ehci_hcd_init(struct omap_usbhs_board_data *usbhs_pdata,
 
 	debug("Initializing OMAP EHCI\n");
 
-	ret = board_usb_init();
+	ret = board_usb_init(USB_INIT_HOST);
 	if (ret < 0)
 		return ret;
 
drivers/usb/host/ehci-tegra.c +1 -1
index c6da449..cc23133 100644
@@ -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;
drivers/usb/host/ohci-hcd.c +2 -2
index c33c487..e6a5623 100644
@@ -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(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_init_fail();
 #endif
 
 #ifdef CONFIG_SYS_USB_OHCI_CPU_INIT
drivers/usb/host/ohci.h +5 -7
index d977e8f..9f7f961 100644
@@ -19,14 +19,12 @@
 #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 board_usb_init_fail(void);
 
+int usb_cpu_init(void);
+int usb_cpu_stop(void);
+int usb_cpu_init_fail(void);
 
 static int cc_to_error[16] = {
 
include/g_dnl.h +0 -2
index 2b2f11a..b6c4dd4 100644
@@ -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_ */
include/usb.h +18 -1
index 60db897..2ee867f 100644
@@ -165,10 +165,27 @@ 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, device or both
+ * capabilities by passing this enum as an argument to
+ * board_usb_init().
+ */
+enum board_usb_init_type {
+	USB_INIT_ALL,
+	USB_INIT_HOST,
+	USB_INIT_DEVICE
+};
+
+/*
+ * board-specific hardware initialization, called by
+ * usb drivers and u-boot commands
+ */
+int board_usb_init(enum board_usb_init_type init);
+
 #ifdef CONFIG_USB_STORAGE
 
 #define USB_MAX_STOR_DEV 5
include/usb_mass_storage.h +5 -7
index 35cdcc3..de31b0e 100644
@@ -30,13 +30,11 @@ 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,
+int fsg_init(struct ums_board_info *);
+void fsg_cleanup(void);
+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 usb_gadget_handle_interrupts(void);
+int fsg_main_thread(void *);
 
 #endif /* __USB_MASS_STORAGE_H__ */
Signature · 1 line
1.8.2.1
#29 lore raw

PATCH v2 1/1 usb: new board-specific USB init interface

Quoted 19 lines · Mateusz Zalega

This commit unifies board-specific USB initialization implementations under one symbol (usb_board_init), declaration of which is available in usb.h.

---
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

Quoted 2 lines

v2 changes:
- commit message fixup

ICMP Echo Request

It's already been a week, any comments?

Signature · 2 lines
Mateusz Zalega
Samsung R&D Institute Poland
#30 lore raw

PATCH v3 1/1 usb: new board-specific USB init interface

In reply to Mateusz Zalega

This commit unifies board-specific USB initialization implementations under one symbol (usb_board_init), declaration of which is available in usb.h.

---
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

---
 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                     |  5 +++--
 board/compulab/cm_t35/cm_t35.c                |  2 +-
 board/esd/apc405/apc405.c                     |  5 +++--
 board/esd/pmc440/pmc440.c                     |  5 +++--
 board/htkw/mcx/mcx.c                          |  2 +-
 board/icpdas/lp8x4x/lp8x4x.c                  |  5 +++--
 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/panda/panda.c                        |  2 +-
 board/toradex/colibri_pxa270/colibri_pxa270.c |  5 +++--
 board/trizepsiv/conxs.c                       |  5 +++--
 board/vpac270/vpac270.c                       |  5 +++--
 common/cmd_dfu.c                              |  5 ++---
 common/cmd_usb_mass_storage.c                 |  3 ++-
 common/usb.c                                  |  5 +++++
 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                       | 12 +++++-------
 include/g_dnl.h                               |  2 --
 include/usb.h                                 | 28 ++++++++++++++++++++++++++-
 include/usb_mass_storage.h                    | 14 ++++++--------
 28 files changed, 92 insertions(+), 63 deletions(-)
arch/arm/include/asm/arch-tegra/usb.h +1 -2
index f66257c..a1efd07 100644
@@ -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_ */
arch/arm/include/asm/ehci-omap.h +2 -2
index ac83a53..c7bca05 100644
@@ -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_ */
board/amcc/canyonlands/canyonlands.c +3 -2
index cc36f45..8e85bee 100644
@@ -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_init_fail(void)
 {
 	return usb_board_stop();
 }
board/balloon3/balloon3.c +3 -2
index ecbac16..891e48a 100644
@@ -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,7 +91,7 @@ int usb_board_init(void)
 	return 0;
 }
 
-void usb_board_init_fail(void)
+void board_usb_init_fail(void)
 {
 	return;
 }
board/compulab/cm_t35/cm_t35.c +1 -1
index 3caa5be..7626abc 100644
@@ -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)
board/esd/apc405/apc405.c +3 -2
index f13f088..7592b61 100644
@@ -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,7 +454,7 @@ int usb_board_stop(void)
 	return 0;
 }
 
-int usb_board_init_fail(void)
+int board_usb_init_fail(void)
 {
 	usb_board_stop();
 	return 0;
board/esd/pmc440/pmc440.c +3 -2
index 549b3b7..b81da1e 100644
@@ -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,7 +846,7 @@ int usb_board_stop(void)
 	return 0;
 }
 
-int usb_board_init_fail(void)
+int board_usb_init_fail(void)
 {
 	usb_board_stop();
 	return 0;
board/htkw/mcx/mcx.c +1 -1
index 653d7ea..6f85b47 100644
@@ -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)
board/icpdas/lp8x4x/lp8x4x.c +3 -2
index 1b68ef3..73e0266 100644
@@ -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,7 +90,7 @@ int usb_board_init(void)
 	return 0;
 }
 
-void usb_board_init_fail(void)
+void board_usb_init_fail(void)
 {
 	return;
 }
board/nvidia/common/board.c +3 -1
index 126e56e..1972527 100644
@@ -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
board/samsung/trats/trats.c +3 -2
index 7f61d17..58d925f 100644
@@ -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
 
board/technexion/twister/twister.c +1 -1
index cd91d8f..6f2ff55 100644
@@ -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)
board/teejet/mt_ventoux/mt_ventoux.c +1 -1
index b4e01d1..df873f5 100644
@@ -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)
board/ti/beagle/beagle.c +1 -1
index 62e9bea..41fed54 100644
@@ -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)
board/ti/panda/panda.c +1 -1
index e838ffd..fe7a437 100644
@@ -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;
 
board/toradex/colibri_pxa270/colibri_pxa270.c +3 -2
index c1e2562..2e0ee0d 100644
@@ -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,7 +71,7 @@ int usb_board_init(void)
 	return 0;
 }
 
-void usb_board_init_fail(void)
+void board_usb_init_fail(void)
 {
 	return;
 }
board/trizepsiv/conxs.c +3 -2
index c0c318f..2063288 100644
@@ -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,7 +70,7 @@ int usb_board_init(void)
 	return 0;
 }
 
-void usb_board_init_fail(void)
+void board_usb_init_fail(void)
 {
 	return;
 }
board/vpac270/vpac270.c +3 -2
index 616736f..39d3b4b 100644
@@ -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,7 +98,7 @@ int usb_board_init(void)
 	return 0;
 }
 
-void usb_board_init_fail(void)
+void board_usb_init_fail(void)
 {
 	return;
 }
common/cmd_dfu.c +2 -3
index 793c422..933d0d6 100644
@@ -14,6 +14,7 @@
 #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[])
 {
@@ -43,9 +44,7 @@ static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		goto done;
 	}
 
-#ifdef CONFIG_TRATS
-	board_usb_init();
-#endif
+	board_usb_init(USB_INIT_ALL, USB_INIT_DEVICE);
 
 	g_dnl_register(s);
 	while (1) {
common/cmd_usb_mass_storage.c +2 -1
index 33a4715..42efd5c 100644
@@ -9,6 +9,7 @@
 #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,
@@ -33,7 +34,7 @@ int do_usb_mass_storage(cmd_tbl_t *cmdtp, int flag,
 		goto fail;
 	}
 
-	board_usb_init();
+	board_usb_init(USB_INIT_ALL, USB_INIT_DEVICE);
 	ums_info = board_ums_init(dev_num, offset, part_size);
 
 	if (!ums_info) {
common/usb.c +5 -0
index c97f522..bdcdd63 100644
@@ -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 */
drivers/usb/host/ehci-omap.c +3 -9
index 3c58f9e..c4ce487 100644
@@ -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;
 
drivers/usb/host/ehci-tegra.c +1 -1
index c6da449..cc23133 100644
@@ -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;
drivers/usb/host/ohci-hcd.c +2 -2
index c33c487..004f9dc 100644
@@ -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_init_fail();
 #endif
 
 #ifdef CONFIG_SYS_USB_OHCI_CPU_INIT
drivers/usb/host/ohci.h +5 -7
index d977e8f..9f7f961 100644
@@ -19,14 +19,12 @@
 #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 board_usb_init_fail(void);
 
+int usb_cpu_init(void);
+int usb_cpu_stop(void);
+int usb_cpu_init_fail(void);
 
 static int cc_to_error[16] = {
 
include/g_dnl.h +0 -2
index 2b2f11a..b6c4dd4 100644
@@ -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_ */
include/usb.h +27 -1
index 60db897..5be90ff 100644
@@ -165,10 +165,36 @@ 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
+};
+
+/*
+ * Pass USB_INIT_ALL as board_usb_init's 'index' argument
+ * to initialize every available USB port of type specified
+ * by board_usb_init_type argument.
+ */
+#define USB_INIT_ALL -1
+
+/*
+ * board-specific hardware initialization, called by
+ * usb drivers and u-boot commands
+ *
+ * @param index USB port number
+ * @param init initializes port as USB host or device
+ */
+int board_usb_init(int index, enum board_usb_init_type init);
+
 #ifdef CONFIG_USB_STORAGE
 
 #define USB_MAX_STOR_DEV 5
include/usb_mass_storage.h +6 -8
index 35cdcc3..ed27aeb 100644
@@ -30,13 +30,11 @@ 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 usb_gadget_handle_interrupts(void);
+int fsg_main_thread(void *);
 
 #endif /* __USB_MASS_STORAGE_H__ */
Signature · 1 line
1.8.2.1
#31 lore raw

PATCH v3 1/1 usb: new board-specific USB init interface

Dear Mateusz Zalega,

Quoted 16 lines

This commit unifies board-specific USB initialization implementations under one symbol (usb_board_init), declaration of which is available in usb.h.

---
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

Quoted 5 lines

v2 changes:
- commit message fixup

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

OK, a few general ideas again:

Why not wrap board_usb_init() and board_usb_init_fail() into single call. You now pass some flags to board_usb_init() already, so just add another for the fail case. How does it sound to you?

Moreover, the 'int index' should likely be unsigned int and the special value to init all controllers at once should probably then be 0xffffffff

Best regards,
Marek Vasut

#32 lore raw

PATCH v3 1/1 usb: new board-specific USB init interface

Quoted 8 lines · Marek Vasut
Quoted 2 lines

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

OK, a few general ideas again:

Why not wrap board_usb_init() and board_usb_init_fail() into single call. You now pass some flags to board_usb_init() already, so just add another for the fail case. How does it sound to you?

Like overengineering. It would lead to "board_usb_init(USB_INIT_ALL, USB_INIT_DEVICE, USB_CLEANUP)" calls, which are not very readable.

Quoted 2 lines

Moreover, the 'int index' should likely be unsigned int and the special value to init all controllers at once should probably then be 0xffffffff

Despite our greatest ambitions, I don't think we're likely to use more than 2^31-1 USB controllers at a time. Besides, negative values look better both in code and debugger session.

Best Regards,

Signature · 2 lines
Mateusz Zalega
Samsung R&D Institute Poland
#33 lore raw

PATCH v3 1/1 usb: new board-specific USB init interface

Dear Mateusz Zalega,

Quoted 12 lines · Marek Vasut
Quoted 8 lines
Quoted 2 lines

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

OK, a few general ideas again:

Why not wrap board_usb_init() and board_usb_init_fail() into single call. You now pass some flags to board_usb_init() already, so just add another for the fail case. How does it sound to you?

Like overengineering. It would lead to "board_usb_init(USB_INIT_ALL, USB_INIT_DEVICE, USB_CLEANUP)" calls, which are not very readable.

This is not what I mean, see this:

int board_usb_init(int index, enum board_usb_init_type init)

Add a new "init" type (or maybe change the init field to be flags) that will say "OK, do a fail init" ?

Quoted 6 lines
Quoted 2 lines

Moreover, the 'int index' should likely be unsigned int and the special value to init all controllers at once should probably then be 0xffffffff

Despite our greatest ambitions, I don't think we're likely to use more than 2^31-1 USB controllers at a time. Besides, negative values look better both in code and debugger session.

Thinking of it further, instead of using negative value here, like I mentioned above, why not make the "board_usb_init_type" into a field of flags , then add flag to init all controllers at once ?

Best regards,
Marek Vasut

#34 lore raw

PATCH v3 1/1 usb: new board-specific USB init interface

Quoted 7 lines · Marek Vasut
Quoted 6 lines
Quoted 3 lines

Why not wrap board_usb_init() and board_usb_init_fail() into single call. You now pass some flags to board_usb_init() already, so just add another for the fail case. How does it sound to you?

Like overengineering. It would lead to "board_usb_init(USB_INIT_ALL, USB_INIT_DEVICE, USB_CLEANUP)" calls, which are not very readable.

Quoted 6 lines

This is not what I mean, see this:

int board_usb_init(int index, enum board_usb_init_type init)

Add a new "init" type (or maybe change the init field to be flags) that will say "OK, do a fail init" ?

As for providing a way to do a selective cleanup if anything gone wrong, it's a good idea, but adding such functionality to board_usb_init() would be confusing, especially for newcomers. Why not do this in board_usb_init_fail(int index, enum board_usb_init_type)?

...and maybe rename board_usb_init_fail to board_usb_cleanup.

Quoted 10 lines
Quoted 6 lines
Quoted 2 lines

Moreover, the 'int index' should likely be unsigned int and the special value to init all controllers at once should probably then be 0xffffffff

Despite our greatest ambitions, I don't think we're likely to use more than 2^31-1 USB controllers at a time. Besides, negative values look better both in code and debugger session.

Thinking of it further, instead of using negative value here, like I mentioned above, why not make the "board_usb_init_type" into a field of flags , then add flag to init all controllers at once ?

That's unnecessary. It wouldn't lead to any practical advantage over existing interface.

Best Regards,

Signature · 2 lines
Mateusz Zalega
Samsung R&D Institute Poland
#35 lore raw

PATCH v3 1/1 usb: new board-specific USB init interface

Dear Mateusz Zalega,

Quoted 15 lines · Marek Vasut
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

Why not wrap board_usb_init() and board_usb_init_fail() into single call. You now pass some flags to board_usb_init() already, so just add another for the fail case. How does it sound to you?

Like overengineering. It would lead to "board_usb_init(USB_INIT_ALL, USB_INIT_DEVICE, USB_CLEANUP)" calls, which are not very readable.

Quoted 6 lines

This is not what I mean, see this:

int board_usb_init(int index, enum board_usb_init_type init)

Add a new "init" type (or maybe change the init field to be flags) that will say "OK, do a fail init" ?

Quoted 6 lines

As for providing a way to do a selective cleanup if anything gone wrong, it's a good idea, but adding such functionality to board_usb_init() would be confusing, especially for newcomers. Why not do this in board_usb_init_fail(int index, enum board_usb_init_type)?

...and maybe rename board_usb_init_fail to board_usb_cleanup.

Cleanup is nice name, yeah.

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines

Moreover, the 'int index' should likely be unsigned int and the special value to init all controllers at once should probably then be 0xffffffff

Despite our greatest ambitions, I don't think we're likely to use more than 2^31-1 USB controllers at a time. Besides, negative values look better both in code and debugger session.

Quoted 6 lines
Quoted 3 lines

Thinking of it further, instead of using negative value here, like I mentioned above, why not make the "board_usb_init_type" into a field of flags , then add flag to init all controllers at once ?

That's unnecessary. It wouldn't lead to any practical advantage over existing interface.

The advantage would be you won't be mixing two things (value AND value with special meaning) into the "index" parameter.

Best regards,
Marek Vasut

#36 lore raw

PATCH v3 1/1 usb: new board-specific USB init interface

Quoted 12 lines · Marek Vasut
Quoted 12 lines
Quoted 11 lines
Quoted 7 lines
Quoted 3 lines

Moreover, the 'int index' should likely be unsigned int and the special value to init all controllers at once should probably then be 0xffffffff

Despite our greatest ambitions, I don't think we're likely to use more than 2^31-1 USB controllers at a time. Besides, negative values look better both in code and debugger session.

Thinking of it further, instead of using negative value here, like I mentioned above, why not make the "board_usb_init_type" into a field of flags , then add flag to init all controllers at once ?

Quoted 5 lines
Quoted 2 lines

That's unnecessary. It wouldn't lead to any practical advantage over existing interface.

The advantage would be you won't be mixing two things (value AND value with special meaning) into the "index" parameter.

Alright, provide a use-case. The only 'special' value we have now doesn't interfere with controller index. Why write code or interfaces that won't ever be used?

Best regards,

Signature · 2 lines
Mateusz Zalega
Samsung R&D Institute Poland
#37 lore raw

PATCH v3 1/1 usb: new board-specific USB init interface

Dear Mateusz Zalega,

Quoted 16 lines · Marek Vasut
Quoted 15 lines
Quoted 14 lines
Quoted 11 lines
Quoted 7 lines
Quoted 3 lines

Moreover, the 'int index' should likely be unsigned int and the special value to init all controllers at once should probably then be 0xffffffff

Despite our greatest ambitions, I don't think we're likely to use more than 2^31-1 USB controllers at a time. Besides, negative values look better both in code and debugger session.

Thinking of it further, instead of using negative value here, like I mentioned above, why not make the "board_usb_init_type" into a field of flags , then add flag to init all controllers at once ?

That's unnecessary. It wouldn't lead to any practical advantage over existing interface.

Quoted 6 lines
Quoted 2 lines

The advantage would be you won't be mixing two things (value AND value with special meaning) into the "index" parameter.

Alright, provide a use-case. The only 'special' value we have now doesn't interfere with controller index. Why write code or interfaces that won't ever be used?

Look, abusing the index field with a special value is moronic, especially if you _do_ have another field that can very well be turned into a block of flags instead of enum right next to it.

function(int foo , enum bar)

            |         ^
            |         |
            `---------'
             flags go
               here

Then int foo can be turned into unsigned int foo _and_ be used for it's one singular purpose. Likewise, enum bar will now be "unsigned int flags" . Do you see the separation now ?

Best regards,
Marek Vasut

#38 lore raw

PATCH v3 1/1 usb: new board-specific USB init interface

Quoted 15 lines · Marek Vasut
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
Quoted 11 lines
Quoted 7 lines
Quoted 3 lines

Moreover, the 'int index' should likely be unsigned int and the special value to init all controllers at once should probably then be 0xffffffff

Despite our greatest ambitions, I don't think we're likely to use more than 2^31-1 USB controllers at a time. Besides, negative values look better both in code and debugger session.

Thinking of it further, instead of using negative value here, like I mentioned above, why not make the "board_usb_init_type" into a field of flags , then add flag to init all controllers at once ?

That's unnecessary. It wouldn't lead to any practical advantage over existing interface.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

The advantage would be you won't be mixing two things (value AND value with special meaning) into the "index" parameter.

Alright, provide a use-case. The only 'special' value we have now doesn't interfere with controller index. Why write code or interfaces that won't ever be used?

Look, abusing the index field with a special value is moronic, especially if you

I wouldn't call a de-facto standard abusive or moronic. On the other hand, contributing to unnecessary code bloat would be.

Quoted 1 line

_do_ have another field that can very well be turned into a block of flags

Have you provided another use-case for that, as I asked?

Quoted 9 lines

instead of enum right next to it.

function(int foo , enum bar)

            |         ^
            |         |
            `---------'
             flags go
               here
Quoted 3 lines

Then int foo can be turned into unsigned int foo _and_ be used for it's one singular purpose. Likewise, enum bar will now be "unsigned int flags" . Do you see the separation now ?

Read your mail carefully - at this point I don't have any problems understanding what you wish to do, but I see your API changes as unjustified. Can you justify them without appealing to your authority and maybe inserting a couple of ad-hominems here and there?

Signature · 2 lines
Mateusz Zalega
Samsung R&D Institute Poland
#39 lore raw

PATCH v3 1/1 usb: new board-specific USB init interface

Dear Mateusz Zalega,

Quoted 46 lines · Marek Vasut
Quoted 18 lines
Quoted 18 lines
Quoted 17 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines

Moreover, the 'int index' should likely be unsigned int and the special value to init all controllers at once should probably then be 0xffffffff

Despite our greatest ambitions, I don't think we're likely to use more than 2^31-1 USB controllers at a time. Besides, negative values look better both in code and debugger session.

Quoted 6 lines
Quoted 3 lines

Thinking of it further, instead of using negative value here, like I mentioned above, why not make the "board_usb_init_type" into a field of flags , then add flag to init all controllers at once ?

That's unnecessary. It wouldn't lead to any practical advantage over existing interface.

The advantage would be you won't be mixing two things (value AND value with special meaning) into the "index" parameter.

Quoted 6 lines
Quoted 3 lines

Alright, provide a use-case. The only 'special' value we have now doesn't interfere with controller index. Why write code or interfaces that won't ever be used?

Look, abusing the index field with a special value is moronic, especially if you

I wouldn't call a de-facto standard abusive or moronic. On the other hand, contributing to unnecessary code bloat would be.

Quoted 2 lines

_do_ have another field that can very well be turned into a block of flags

Have you provided another use-case for that, as I asked?

Quoted 12 lines

instead of enum right next to it.

function(int foo , enum bar)

            |         ^
            
            `---------'
            
             flags go
             
               here
Quoted 8 lines
Quoted 3 lines

Then int foo can be turned into unsigned int foo _and_ be used for it's one singular purpose. Likewise, enum bar will now be "unsigned int flags" . Do you see the separation now ?

Read your mail carefully - at this point I don't have any problems understanding what you wish to do, but I see your API changes as unjustified. Can you justify them without appealing to your authority and maybe inserting a couple of ad-hominems here and there?

I suppose this thread can be concluded by droping the INIT_ALL stuff entirely. Afterall, we do not want to init _ALL_ ports at once, but we want to init them selectively.

Best regards,
Marek Vasut

#40 lore raw

PATCH v3 1/1 usb: new board-specific USB init interface

Quoted 6 lines · Marek Vasut

I suppose this thread can be concluded by droping the INIT_ALL stuff entirely. Afterall, we do not want to init _ALL_ ports at once, but we want to init them selectively.

Best regards,
Marek Vasut

+1

Signature · 2 lines
Mateusz Zalega
Samsung R&D Institute Poland
#41 lore raw

PATCH v4 1/1 usb: new board-specific USB init interface

In reply to 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.

Cc Marek Vasut <[email protected]>
Cc Lukasz Majewski <[email protected]>
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(-)
arch/arm/include/asm/arch-tegra/usb.h +1 -2
index f66257c..a1efd07 100644
@@ -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_ */
arch/arm/include/asm/ehci-omap.h +2 -2
index ac83a53..c7bca05 100644
@@ -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_ */
board/amcc/canyonlands/canyonlands.c +3 -2
index cc36f45..395095e 100644
@@ -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();
 }
board/balloon3/balloon3.c +4 -3
index ecbac16..19c0e02 100644
@@ -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)
board/compulab/cm_t35/cm_t35.c +1 -1
index 3caa5be..7626abc 100644
@@ -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)
board/esd/apc405/apc405.c +4 -4
index f13f088..79341f5 100644
@@ -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) */
board/esd/pmc440/pmc440.c +4 -4
index 549b3b7..44b86da 100644
@@ -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) */
 
board/htkw/mcx/mcx.c +1 -1
index 653d7ea..6f85b47 100644
@@ -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)
board/icpdas/lp8x4x/lp8x4x.c +4 -3
index 1b68ef3..a96bed6 100644
@@ -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)
board/nvidia/common/board.c +3 -1
index 126e56e..1972527 100644
@@ -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
board/samsung/trats/trats.c +3 -2
index 7f61d17..58d925f 100644
@@ -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
 
board/technexion/twister/twister.c +1 -1
index cd91d8f..6f2ff55 100644
@@ -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)
board/teejet/mt_ventoux/mt_ventoux.c +1 -1
index b4e01d1..df873f5 100644
@@ -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)
board/ti/beagle/beagle.c +1 -1
index 62e9bea..41fed54 100644
@@ -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)
board/ti/omap5_uevm/evm.c +1 -1
index 4706330..3ae0671 100644
@@ -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;
board/ti/panda/panda.c +1 -1
index e838ffd..fe7a437 100644
@@ -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;
 
board/toradex/colibri_pxa270/colibri_pxa270.c +4 -3
index c1e2562..b70c1e3 100644
@@ -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)
board/trizepsiv/conxs.c +4 -3
index c0c318f..830d5a8 100644
@@ -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)
board/vpac270/vpac270.c +4 -3
index 616736f..fab4636 100644
@@ -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)
common/cmd_dfu.c +18 -13
index 793c422..693b5bc 100644
@@ -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"
 );
common/cmd_usb_mass_storage.c +23 -21

79 lines not on this page · raw message

common/usb.c +5 -0
index c97f522..bdcdd63 100644
@@ -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 */
drivers/dfu/dfu.c +1 -1
index d73d510..e785d39 100644
@@ -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;
 
drivers/usb/host/ehci-omap.c +3 -9
index 3c58f9e..c4ce487 100644
@@ -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;
 
drivers/usb/host/ehci-tegra.c +1 -1
index c6da449..cc23133 100644
@@ -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;
drivers/usb/host/ohci-hcd.c +2 -2
index c33c487..756f2fa 100644
@@ -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
drivers/usb/host/ohci.h +4 -7
index d977e8f..9a4a2c2 100644
@@ -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] = {
 
include/g_dnl.h +0 -2
index 2b2f11a..b6c4dd4 100644
@@ -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_ */
include/usb.h +29 -1
index 60db897..681b408 100644
@@ -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
include/usb_mass_storage.h +5 -8
index 35cdcc3..f26403e 100644
@@ -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__ */
Signature · 1 line
1.8.2.1
#42 lore raw

PATCH v4 1/1 usb: new board-specific USB init interface

Dear Mateusz Zalega,

Quoted 25 lines

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.

Cc Marek Vasut <[email protected]>
Cc Lukasz Majewski <[email protected]>
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

Quoted 6 lines

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

#43 lore raw

PATCH v4 1/1 usb: new board-specific USB init interface

Quoted 34 lines · Marek Vasut

Dear Mateusz Zalega,

Quoted 25 lines

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.

Cc Marek Vasut <[email protected]>
Cc Lukasz Majewski <[email protected]>
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

Quoted 6 lines

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
---

Quoted 5 lines

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.

Signature · 2 lines
Mateusz Zalega
Samsung R&D Institute Poland
#44 lore raw

PATCH v4 1/1 usb: new board-specific USB init interface

Dear Mateusz Zalega,

Quoted 36 lines · Marek Vasut
Quoted 35 lines

Dear Mateusz Zalega,

Quoted 32 lines

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.

Cc Marek Vasut <[email protected]>
Cc Lukasz Majewski <[email protected]>
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
---

Quoted 8 lines
Quoted 5 lines

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

#45 lore raw

PATCH v4 1/1 usb: new board-specific USB init interface

In reply to Mateusz Zalega

Hello,

Quoted 11 lines · 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.

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

Quoted 836 lines

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(-)
arch/arm/include/asm/arch-tegra/usb.h +1 -2
index f66257c..a1efd07 100644
@@ -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_ */
arch/arm/include/asm/ehci-omap.h +2 -2
index ac83a53..c7bca05 100644
@@ -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_ */
board/amcc/canyonlands/canyonlands.c +3 -2
index cc36f45..395095e 100644
@@ -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();
 }
board/balloon3/balloon3.c +4 -3
index ecbac16..19c0e02 100644
@@ -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)
board/compulab/cm_t35/cm_t35.c +1 -1
index 3caa5be..7626abc 100644
@@ -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)
board/esd/apc405/apc405.c +4 -4
index f13f088..79341f5 100644
@@ -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) */
board/esd/pmc440/pmc440.c +4 -4
index 549b3b7..44b86da 100644
@@ -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) */
 
board/htkw/mcx/mcx.c +1 -1
index 653d7ea..6f85b47 100644
@@ -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)
board/icpdas/lp8x4x/lp8x4x.c +4 -3
index 1b68ef3..a96bed6 100644
@@ -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)
board/nvidia/common/board.c +3 -1
index 126e56e..1972527 100644
@@ -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
board/samsung/trats/trats.c +3 -2
index 7f61d17..58d925f 100644
@@ -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
 
board/technexion/twister/twister.c +1 -1
index cd91d8f..6f2ff55 100644
@@ -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)
board/teejet/mt_ventoux/mt_ventoux.c +1 -1
index b4e01d1..df873f5 100644
@@ -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)
board/ti/beagle/beagle.c +1 -1
index 62e9bea..41fed54 100644
@@ -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)
board/ti/omap5_uevm/evm.c +1 -1
index 4706330..3ae0671 100644
@@ -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;
board/ti/panda/panda.c +1 -1
index e838ffd..fe7a437 100644
@@ -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;
 
board/toradex/colibri_pxa270/colibri_pxa270.c +4 -3
index c1e2562..b70c1e3 100644
@@ -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)
board/trizepsiv/conxs.c +4 -3
index c0c318f..830d5a8 100644
@@ -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)
board/vpac270/vpac270.c +4 -3
index 616736f..fab4636 100644
@@ -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)
common/cmd_dfu.c +18 -13
index 793c422..693b5bc 100644
@@ -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"
 );
common/cmd_usb_mass_storage.c +23 -21
index 33a4715..c6dc5b9 100644
@@ -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>"
 );
common/usb.c +5 -0
index c97f522..bdcdd63 100644
@@ -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 */
drivers/dfu/dfu.c +1 -1
index d73d510..e785d39 100644
@@ -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;
 
drivers/usb/host/ehci-omap.c +3 -9
index 3c58f9e..c4ce487 100644
@@ -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;
 
drivers/usb/host/ehci-tegra.c +1 -1
index c6da449..cc23133 100644
@@ -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;
drivers/usb/host/ohci-hcd.c +2 -2
index c33c487..756f2fa 100644
@@ -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
drivers/usb/host/ohci.h +4 -7
index d977e8f..9a4a2c2 100644
@@ -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] = {
 
include/g_dnl.h +0 -2
index 2b2f11a..b6c4dd4 100644
@@ -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_ */
include/usb.h +29 -1
index 60db897..681b408 100644
@@ -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
include/usb_mass_storage.h +5 -8
index 35cdcc3..f26403e 100644
@@ -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__ */
Signature · 2 lines
Regards,
Igor
#46 lore raw

PATCH v4 1/1 usb: new board-specific USB init interface

Quoted 9 lines · Igor Grinberg

Hello,

Quoted 6 lines · 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.

Quoted 7 lines
Quoted 5 lines

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.

Signature · 2 lines
Mateusz Zalega
Samsung R&D Institute Poland
#47 lore raw

PATCH v4 1/1 usb: new board-specific USB init interface

In reply to Mateusz Zalega

Dear Mateusz Zalega,

Quoted 22 lines

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.

Cc Marek Vasut <[email protected]>
Cc Lukasz Majewski <[email protected]>
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

Quoted 8 lines

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

#48 lore raw

PATCH v4 1/1 usb: new board-specific USB init interface

Dear Marek Vasut,

Quoted 34 lines

Dear Mateusz Zalega,

Quoted 23 lines

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.

Cc Marek Vasut <[email protected]>
Cc Lukasz Majewski <[email protected]>
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

Quoted 8 lines

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

Quoted 6 lines

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

#49 lore raw

PATCH v4 1/1 usb: new board-specific USB init interface

Dear Marek Vasut,

Quoted 38 lines

Dear Marek Vasut,

Quoted 36 lines

Dear Mateusz Zalega,

Quoted 23 lines

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.

Cc Marek Vasut <[email protected]>
Cc Lukasz Majewski <[email protected]>
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

Quoted 8 lines

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 ?

Quoted 7 lines
Quoted 4 lines

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

#50 lore raw

PATCH v4 1/1 usb: new board-specific USB init interface

Dear Marek Vasut,

Quoted 51 lines · Marek Vasut

Dear Marek Vasut,

Quoted 38 lines

Dear Marek Vasut,

Quoted 36 lines

Dear Mateusz Zalega,

Quoted 23 lines

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.

Cc Marek Vasut <[email protected]>
Cc Lukasz Majewski <[email protected]>
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

Quoted 8 lines

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 ?

Quoted 7 lines
Quoted 4 lines

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].

Quoted 9 lines

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

Best regards,
Marek Vasut
_______________________________________________
U-Boot mailing list
U-Boot at 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.

#51 lore raw

PATCH v4 1/1 usb: new board-specific USB init interface

Dear Minkyu Kang,

Quoted 69 lines

Dear Marek Vasut,

Quoted 53 lines · Marek Vasut

Dear Marek Vasut,

Quoted 38 lines

Dear Marek Vasut,

Quoted 36 lines

Dear Mateusz Zalega,

Quoted 23 lines

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.

Cc Marek Vasut <[email protected]>
Cc Lukasz Majewski <[email protected]>
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

Quoted 8 lines

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 ?

Quoted 8 lines
Quoted 5 lines

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].

Quoted 8 lines

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

Best regards,
Marek Vasut
_______________________________________________
U-Boot mailing list
U-Boot at 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?

Quoted 6 lines

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

#52 lore raw

PATCH v4 1/1 usb: new board-specific USB init interface

In reply to Marek Vasut
Quoted 4 lines · Marek Vasut

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?

Signature · 2 lines
Mateusz Zalega
Samsung R&D Institute Poland
#53 lore raw

PATCH v4 1/1 usb: new board-specific USB init interface

Dear Mateusz Zalega,

Quoted 10 lines · Marek Vasut
Quoted 5 lines

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 ?

Quoted 13 lines

@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)

Quoted 6 lines

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

#54 lore raw

PATCH v4 1/1 usb: new board-specific USB init interface

Quoted 7 lines · Marek Vasut

Dear Mateusz Zalega,

Quoted 5 lines · Marek Vasut
Quoted 4 lines

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].

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

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);

Quoted 13 lines
Quoted 13 lines

@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)

Quoted 8 lines
Quoted 6 lines

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

Signature · 2 lines
Mateusz Zalega
Samsung R&D Institute Poland
#55 lore raw

PATCH v5 1/1 usb: new board-specific USB init interface

In reply to 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.

---
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

v5 changes:
- fixed an issue with boards based on canyonlands.c
- patch passes MAKEALL -a powerpc (vide: ^)
---

 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, 137 insertions(+), 105 deletions(-)
arch/arm/include/asm/arch-tegra/usb.h +1 -2
index f66257c..a1efd07 100644
@@ -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_ */
arch/arm/include/asm/ehci-omap.h +2 -2
index ac83a53..c7bca05 100644
@@ -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_ */
board/amcc/canyonlands/canyonlands.c +3 -2
index cc36f45..395095e 100644
@@ -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();
 }
board/balloon3/balloon3.c +4 -3
index ecbac16..19c0e02 100644
@@ -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)
board/compulab/cm_t35/cm_t35.c +1 -1
index 3caa5be..7626abc 100644
@@ -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)
board/esd/apc405/apc405.c +4 -4
index f13f088..79341f5 100644
@@ -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) */
board/esd/pmc440/pmc440.c +4 -4
index 549b3b7..44b86da 100644
@@ -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) */
 
board/htkw/mcx/mcx.c +1 -1
index 653d7ea..6f85b47 100644
@@ -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)
board/icpdas/lp8x4x/lp8x4x.c +4 -3
index 1b68ef3..a96bed6 100644
@@ -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)
board/nvidia/common/board.c +3 -1
index 126e56e..1972527 100644
@@ -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
board/samsung/trats/trats.c +3 -2
index 7f61d17..58d925f 100644
@@ -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
 
board/technexion/twister/twister.c +1 -1
index cd91d8f..6f2ff55 100644
@@ -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)
board/teejet/mt_ventoux/mt_ventoux.c +1 -1
index b4e01d1..df873f5 100644
@@ -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)
board/ti/beagle/beagle.c +1 -1
index 62e9bea..41fed54 100644
@@ -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)
board/ti/omap5_uevm/evm.c +1 -1
index 4706330..3ae0671 100644
@@ -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;
board/ti/panda/panda.c +1 -1
index e838ffd..fe7a437 100644
@@ -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;
 
board/toradex/colibri_pxa270/colibri_pxa270.c +4 -3
index c1e2562..b70c1e3 100644
@@ -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)
board/trizepsiv/conxs.c +4 -3
index c0c318f..830d5a8 100644
@@ -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)
board/vpac270/vpac270.c +4 -3
index 616736f..fab4636 100644
@@ -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)
common/cmd_dfu.c +18 -13
index 793c422..693b5bc 100644
@@ -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"
 );
common/cmd_usb_mass_storage.c +23 -21

79 lines not on this page · raw message

common/usb.c +5 -0
index c97f522..bdcdd63 100644
@@ -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 */
drivers/dfu/dfu.c +1 -1
index d73d510..e785d39 100644
@@ -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;
 
drivers/usb/host/ehci-omap.c +3 -9
index 3c58f9e..c4ce487 100644
@@ -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;
 
drivers/usb/host/ehci-tegra.c +1 -1
index c6da449..cc23133 100644
@@ -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;
drivers/usb/host/ohci-hcd.c +2 -2
index c33c487..756f2fa 100644
@@ -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
drivers/usb/host/ohci.h +4 -7
index d977e8f..9a4a2c2 100644
@@ -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] = {
 
include/g_dnl.h +0 -2
index 2b2f11a..b6c4dd4 100644
@@ -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_ */
include/usb.h +28 -2
index 60db897..e7cc35a 100644
@@ -165,10 +165,36 @@ int submit_int_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
 
 extern void udc_disconnect(void);
 
-#else
-#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
include/usb_mass_storage.h +5 -8
index 35cdcc3..f26403e 100644
@@ -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__ */
Signature · 1 line
1.8.2.1
#56 lore raw

PATCH v5 1/1 usb: new board-specific USB init interface

Dear Mateusz Zalega,

Quoted 30 lines

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.

---
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

Quoted 3 lines

v5 changes:
- fixed an issue with boards based on canyonlands.c
- patch passes MAKEALL -a powerpc (vide: ^)

Hey, can you please rebase on top of usb/next ? I'd like to run build tests and apply.

Best regards,
Marek Vasut

#57 lore raw

PATCH v6 1/1 usb: new board-specific USB init interface

In reply to 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.

---
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

v5 changes:
- fixed an issue with boards based on canyonlands.c
- patch passes MAKEALL -a powerpc (vide: ^)

v6 changes:
- rebased onto usb/next

---
 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                              | 30 ++++++++++--------
 common/cmd_usb_mass_storage.c                 | 44 ++++++++++++++-------------
 common/usb.c                                  |  6 ++++
 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(-)
arch/arm/include/asm/arch-tegra/usb.h +1 -2
index f66257c..a1efd07 100644
@@ -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_ */
arch/arm/include/asm/ehci-omap.h +2 -2
index ac83a53..c7bca05 100644
@@ -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_ */
board/amcc/canyonlands/canyonlands.c +3 -2
index cc36f45..395095e 100644
@@ -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();
 }
board/balloon3/balloon3.c +4 -3
index ecbac16..19c0e02 100644
@@ -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)
board/compulab/cm_t35/cm_t35.c +1 -1
index 3caa5be..7626abc 100644
@@ -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)
board/esd/apc405/apc405.c +4 -4
index f13f088..79341f5 100644
@@ -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) */
board/esd/pmc440/pmc440.c +4 -4
index 549b3b7..44b86da 100644
@@ -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) */
 
board/htkw/mcx/mcx.c +1 -1
index 653d7ea..6f85b47 100644
@@ -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)
board/icpdas/lp8x4x/lp8x4x.c +4 -3
index 1b68ef3..a96bed6 100644
@@ -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)
board/nvidia/common/board.c +3 -1
index 126e56e..1972527 100644
@@ -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
board/samsung/trats/trats.c +3 -2
index 7f61d17..58d925f 100644
@@ -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
 
board/technexion/twister/twister.c +1 -1
index cd91d8f..6f2ff55 100644
@@ -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)
board/teejet/mt_ventoux/mt_ventoux.c +1 -1
index b4e01d1..df873f5 100644
@@ -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)
board/ti/beagle/beagle.c +1 -1
index 62e9bea..41fed54 100644
@@ -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)
board/ti/omap5_uevm/evm.c +1 -1
index 4706330..3ae0671 100644
@@ -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;
board/ti/panda/panda.c +1 -1
index e838ffd..fe7a437 100644
@@ -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;
 
board/toradex/colibri_pxa270/colibri_pxa270.c +4 -3
index c1e2562..b70c1e3 100644
@@ -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)
board/trizepsiv/conxs.c +4 -3
index c0c318f..830d5a8 100644
@@ -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)
board/vpac270/vpac270.c +4 -3
index 616736f..fab4636 100644
@@ -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)
common/cmd_dfu.c +18 -12
index 7ce92ce..5547678 100644
@@ -11,27 +11,32 @@
 #include <common.h>
 #include <dfu.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];
+
 	char *s = "dfu";
 	int ret, i = 0;
 
-	if (argc < 3)
-		return CMD_RET_USAGE;
-
-	ret = dfu_init_env_entities(argv[1], simple_strtoul(argv[2], NULL, 10));
+	ret = dfu_init_env_entities(interface, simple_strtoul(devstring,
+							      NULL, 10));
 	if (ret)
 		return ret;
 
-	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) {
@@ -62,8 +67,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"
 );
common/cmd_usb_mass_storage.c +23 -21

79 lines not on this page · raw message

common/usb.c +6 -0
index c97f522..8b678b7 100644
@@ -33,6 +33,7 @@
 #include <linux/ctype.h>
 #include <asm/byteorder.h>
 #include <asm/unaligned.h>
+#include <compiler.h>
 
 #include <usb.h>
 #ifdef CONFIG_4xx
@@ -1037,4 +1038,9 @@ int usb_new_device(struct usb_device *dev)
 	return 0;
 }
 
+__weak
+int board_usb_init(int index, enum board_usb_init_type init)
+{
+	return 0;
+}
 /* EOF */
drivers/dfu/dfu.c +1 -1
index 56b21c7..f328735 100644
@@ -330,7 +330,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;
 
drivers/usb/host/ehci-omap.c +3 -9
index 3c58f9e..c4ce487 100644
@@ -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;
 
drivers/usb/host/ehci-tegra.c +1 -1
index c6da449..cc23133 100644
@@ -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;
drivers/usb/host/ohci-hcd.c +2 -2
index c33c487..756f2fa 100644
@@ -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
drivers/usb/host/ohci.h +4 -7
index d977e8f..9a4a2c2 100644
@@ -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] = {
 
include/g_dnl.h +0 -2
index 2b2f11a..b6c4dd4 100644
@@ -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_ */
include/usb.h +28 -2
index 60db897..e7cc35a 100644
@@ -165,10 +165,36 @@ int submit_int_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
 
 extern void udc_disconnect(void);
 
-#else
-#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
include/usb_mass_storage.h +5 -8
index e08deb4..13f535c 100644
@@ -31,14 +31,11 @@ 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 *);
 
 #ifdef CONFIG_USB_GADGET_MASS_STORAGE
 int fsg_add(struct usb_configuration *c);
Signature · 1 line
1.8.2.1
#58 lore raw

PATCH v6 1/1 usb: new board-specific USB init interface

include/usb.h int submit_int_msg(struct usb_device *dev, unsigned long pipe, void *buffer, · line 179

Quoted 12 lines · Mateusz Zalega
include/usb.h +10 -0
+/*
+ * 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
+};
+

I'm a little late to the game, but can you rename this to just usb_init_type ?
I'm wanting to use this as a parameter to usb_lowlevel_init, moving it above the usb_lowlevel_init definition would help me too.

Thanks
Troy

#59 lore raw

PATCH v6 1/1 usb: new board-specific USB init interface

Quoted 16 lines · Troy Kisky

include/usb.h int submit_int_msg(struct usb_device *dev, unsigned long pipe, void *buffer, · line 179

Quoted 11 lines · Mateusz Zalega

+/*
+ * You can initialize platform's USB host or device
+ * ports by passing this enum as an argument to
+ * board_usb_init().
+ */

include/usb.h +5 -0
+enum board_usb_init_type {
+    USB_INIT_HOST,
+    USB_INIT_DEVICE
+};
+

I'm a little late to the game, but can you rename this to just usb_init_type ?
I'm wanting to use this as a parameter to usb_lowlevel_init, moving it above the usb_lowlevel_init definition would help me too.

Looks like Marek already applied it. You can always send another RFC.

Regards,

Signature · 2 lines
Mateusz Zalega
Samsung R&D Institute Poland
#60 lore raw

PATCH v6 1/1 usb: new board-specific USB init interface

Quoted 17 lines · Mateusz Zalega
Quoted 16 lines · Troy Kisky

include/usb.h int submit_int_msg(struct usb_device *dev, unsigned long pipe, void *buffer, · line 179

Quoted 11 lines · Mateusz Zalega
   +/*

+ * You can initialize platform's USB host or device
+ * ports by passing this enum as an argument to
+ * board_usb_init().
+ */

include/usb.h +5 -0
+enum board_usb_init_type {
+    USB_INIT_HOST,
+    USB_INIT_DEVICE
+};
+

I'm a little late to the game, but can you rename this to just usb_init_type ?
I'm wanting to use this as a parameter to usb_lowlevel_init, moving it above the usb_lowlevel_init definition would help me too.

Quoted 4 lines

Looks like Marek already applied it. You can always send another RFC.

Regards,

So you are O.K. with me sending a rename patch?

Thanks
Troy

#61 lore raw

PATCH v6 1/1 usb: new board-specific USB init interface

Dear Troy Kisky,

Quoted 20 lines · Mateusz Zalega
Quoted 19 lines · Troy Kisky
Quoted 17 lines · Mateusz Zalega

include/usb.h int submit_int_msg(struct usb_device *dev, unsigned long pipe, void *buffer, · line 179

Quoted 11 lines
   +/*

+ * You can initialize platform's USB host or device
+ * ports by passing this enum as an argument to
+ * board_usb_init().
+ */

include/usb.h +5 -0
+enum board_usb_init_type {
+    USB_INIT_HOST,
+    USB_INIT_DEVICE
+};
+

I'm a little late to the game, but can you rename this to just usb_init_type ?
I'm wanting to use this as a parameter to usb_lowlevel_init, moving it above the usb_lowlevel_init definition would help me too.

Quoted 5 lines
Quoted 3 lines

Looks like Marek already applied it. You can always send another RFC.

Regards,

So you are O.K. with me sending a rename patch?

Send a patch on top of usb/next please.

Best regards,
Marek Vasut

Applied
#62 lore raw

PATCH v6 1/1 usb: new board-specific USB init interface

In reply to Mateusz Zalega

Dear Mateusz Zalega,

Quoted 11 lines

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.

Quoted 6 lines

---
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

Applied to usb/next, thanks

Best regards,
Marek Vasut