[U-Boot] [PATCH] powerpc/8xxx: Update USB mode device tree fixup

Modify support for USB mode fixup: - Add common support for USB mode and phy type device tree fix-up for all USB controllers mentioned in hwconfig string - Fetch USB mode and phy type via hwconfig; if not defined in hwconfig, then fetch them from env
Signed-off-by: Ramneek Mehresh ramneek.mehresh@freescale.com --- arch/powerpc/cpu/mpc8xxx/fdt.c | 77 +++++++++++++++++++++++++++++++++------ 1 files changed, 65 insertions(+), 12 deletions(-)
diff --git a/arch/powerpc/cpu/mpc8xxx/fdt.c b/arch/powerpc/cpu/mpc8xxx/fdt.c index 520cb90..d9e3e7e 100644 --- a/arch/powerpc/cpu/mpc8xxx/fdt.c +++ b/arch/powerpc/cpu/mpc8xxx/fdt.c @@ -29,6 +29,10 @@ #include <asm/mp.h> #include <asm/fsl_serdes.h> #include <phy.h> +#include <hwconfig.h> +#ifdef CONFIG_HAS_FSL_DR_USB +#include <usb.h> +#endif
#if defined(CONFIG_MP) && (defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx)) static int ft_del_cpuhandle(void *blob, int cpuhandle) @@ -84,22 +88,18 @@ void ft_fixup_num_cores(void *blob) { #endif /* defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx) */
#ifdef CONFIG_HAS_FSL_DR_USB -void fdt_fixup_dr_usb(void *blob, bd_t *bd) +static void fdt_fixup_usb_mode_phy_type(void *blob, const char *mode, + const char *phy_type) { - char *mode; - char *type; const char *compat = "fsl-usb2-dr"; const char *prop_mode = "dr_mode"; const char *prop_type = "phy_type"; + static int start_offset = -1; int node_offset; int err;
- mode = getenv("usb_dr_mode"); - type = getenv("usb_phy_type"); - if (!mode && !type) - return; - - node_offset = fdt_node_offset_by_compatible(blob, 0, compat); + node_offset = fdt_node_offset_by_compatible(blob, + start_offset, compat); if (node_offset < 0) { printf("WARNING: could not find compatible node %s: %s.\n", compat, fdt_strerror(node_offset)); @@ -114,13 +114,66 @@ void fdt_fixup_dr_usb(void *blob, bd_t *bd) prop_mode, compat, fdt_strerror(err)); }
- if (type) { - err = fdt_setprop(blob, node_offset, prop_type, type, - strlen(type) + 1); + if (phy_type) { + err = fdt_setprop(blob, node_offset, prop_type, phy_type, + strlen(phy_type) + 1); if (err < 0) printf("WARNING: could not set %s for %s: %s.\n", prop_type, compat, fdt_strerror(err)); } + + start_offset = node_offset; +} + +void fdt_fixup_dr_usb(void *blob, bd_t *bd) +{ + const char *modes[] = { "host", "peripheral", "otg" }; + const char *phys[] = { "ulpi", "umti" }; + const char *mode = NULL; + const char *phy_type = NULL; + char usb1_defined = 0; + char str[5]; + int i, j; + + for (i = 1; i <= USB_MAX_DEVICE; i++) { + int mode_idx = -1, phy_idx = -1; + sprintf(str, "%s%d", "usb", i); + if (hwconfig(str)) { + for (j = 0; j < sizeof(modes); j++) { + if (hwconfig_subarg_cmp(str, "dr_mode", + modes[j])) { + mode_idx = j; + break; + } + } + for (j = 0; j < sizeof(phys); j++) { + if (hwconfig_subarg_cmp(str, "phy_type", + phys[j])) { + phy_idx = j; + break; + } + } + if (mode_idx >= 0) + fdt_fixup_usb_mode_phy_type(blob, + modes[mode_idx], NULL); + if (phy_idx >= 0) + fdt_fixup_usb_mode_phy_type(blob, + NULL, phys[phy_idx]); + if (!strcmp(str, "usb1")) + usb1_defined = 1; + if (mode_idx < 0 && phy_idx < 0) + printf("WARNING: invalid phy or mode\n"); + } else { + break; + } + } + if (!usb1_defined) { + mode = getenv("usb_dr_mode"); + phy_type = getenv("usb_phy_type"); + if (!mode && !phy_type) + return; + fdt_fixup_usb_mode_phy_type(blob, mode, phy_type); + } } #endif /* CONFIG_HAS_FSL_DR_USB */

On Jun 8, 2011, at 6:44 AM, Ramneek Mehresh wrote:
Modify support for USB mode fixup: - Add common support for USB mode and phy type device tree fix-up for all USB controllers mentioned in hwconfig string - Fetch USB mode and phy type via hwconfig; if not defined in hwconfig, then fetch them from env
Signed-off-by: Ramneek Mehresh ramneek.mehresh@freescale.com
arch/powerpc/cpu/mpc8xxx/fdt.c | 77 +++++++++++++++++++++++++++++++++------ 1 files changed, 65 insertions(+), 12 deletions(-)
applied to 85xx
- k

On Thu, 30 Jun 2011 20:25:02 -0500 Kumar Gala kumar.gala@freescale.com wrote:
On Jun 8, 2011, at 6:44 AM, Ramneek Mehresh wrote:
Modify support for USB mode fixup: - Add common support for USB mode and phy type device tree fix-up for all USB controllers mentioned in hwconfig string - Fetch USB mode and phy type via hwconfig; if not defined in hwconfig, then fetch them from env
Signed-off-by: Ramneek Mehresh ramneek.mehresh@freescale.com
arch/powerpc/cpu/mpc8xxx/fdt.c | 77 +++++++++++++++++++++++++++++++++------ 1 files changed, 65 insertions(+), 12 deletions(-)
applied to 85xx
turns out this commit (72f4980) breaks some 83xx boards:
$ ./MAKEALL MPC837XERDB Configuring for MPC837XERDB board... /home/r1aaha/git/u-boot/include/usb.h:159:2: error: #error USB Lowlevel not defined In file included from fdt.c:34:0: /home/r1aaha/git/u-boot/include/usb.h:159:2: error: #error USB Lowlevel not defined make[1]: *** [fdt.o] Error 1
it adds a USB-configured dependency by including usb.h in arch/powerpc/cpu/mpc8xxx/fdt.c, presumably just to get the USB_MAX_DEVICE constant.
There are multiple ways to fix:
a. configure USB in all boards that don't have it configured, b. repurpose CONFIG_HAS_FSL_DR_USB to also configure USB, c. remove #error USB Lowlevel not defined from usb.h, d. hardcode USB_MAX_DEVICE in fdt.c, e. have fdt.c loop only over existing usb nodes in the device tree.
my personal preference is e. What do you think?
Kim

Hi Kim,
I just checked that this error comes when you don't have any of the following defined in the board file: CONFIG_USB_UHCI CONFIG_USB_OHCI CONFIG_USB_EHCI CONFIG_USB_OHCI_NEW ... MPC837xRDB has EHCI host controller. Hence, CONFIG_USB_EHCI and its relevant support macros should be defined in include/configs/MPC837XERDB.h file.
This support is missing from MPC837XERDB.h file. If you include EHCI support inside this file, this error won't come.
So I think option (a) makes more sense, that USB should be configured in all boards using it.
Regards, Ramneek
-----Original Message----- From: Phillips Kim-R1AAHA Sent: Wednesday, July 20, 2011 1:09 AM To: Gala Kumar-B11780 Cc: Mehresh Ramneek-B31383; u-boot@lists.denx.de Subject: Re: [U-Boot] [PATCH] powerpc/8xxx: Update USB mode device tree fixup
On Thu, 30 Jun 2011 20:25:02 -0500 Kumar Gala kumar.gala@freescale.com wrote:
On Jun 8, 2011, at 6:44 AM, Ramneek Mehresh wrote:
Modify support for USB mode fixup: - Add common support for USB mode and phy type device tree fix-up for all USB controllers mentioned in hwconfig string - Fetch USB mode and phy type via hwconfig; if not defined in hwconfig, then fetch them from env
Signed-off-by: Ramneek Mehresh ramneek.mehresh@freescale.com
arch/powerpc/cpu/mpc8xxx/fdt.c | 77 +++++++++++++++++++++++++++++++++------ 1 files changed, 65 insertions(+), 12 deletions(-)
applied to 85xx
turns out this commit (72f4980) breaks some 83xx boards:
$ ./MAKEALL MPC837XERDB Configuring for MPC837XERDB board... /home/r1aaha/git/u-boot/include/usb.h:159:2: error: #error USB Lowlevel not defined In file included from fdt.c:34:0: /home/r1aaha/git/u-boot/include/usb.h:159:2: error: #error USB Lowlevel not defined make[1]: *** [fdt.o] Error 1
it adds a USB-configured dependency by including usb.h in arch/powerpc/cpu/mpc8xxx/fdt.c, presumably just to get the USB_MAX_DEVICE constant.
There are multiple ways to fix:
a. configure USB in all boards that don't have it configured, b. repurpose CONFIG_HAS_FSL_DR_USB to also configure USB, c. remove #error USB Lowlevel not defined from usb.h, d. hardcode USB_MAX_DEVICE in fdt.c, e. have fdt.c loop only over existing usb nodes in the device tree.
my personal preference is e. What do you think?
Kim

Dear Mehresh Ramneek-B31383,
In message 16867771548D2F469F1A8F817F38278820AF77@039-SN1MPN1-003.039d.mgd.msft.net you wrote:
I just checked that this error comes when you don't have any of the following defined in the board file: CONFIG_USB_UHCI CONFIG_USB_OHCI CONFIG_USB_EHCI CONFIG_USB_OHCI_NEW ... MPC837xRDB has EHCI host controller. Hence, CONFIG_USB_EHCI and its relevant support macros should be defined in include/configs/MPC837XERDB.h file.
No, I disagree. It must be possible to configure such a port without USB as well. Not all boards based on this processer ever want to use USB (or even have it on their boards).
Please fix this in a way that no such definitions are ever mandatory.
Thanks.
Best regards,
Wolfgang Denk

Hi Wolfgang,
I agree with you that there may be some boards that have USB (on soc) but do not use it.
But in that case, they should not define CONFIG_HAS_FSL_DR_USB in their board file.
usb.h file has a logic that if this file is included, and the USB protocol is not defined then it throws compilation error (which is correct because the driver will not be able to perform low level initialization which is specific to a protocol)
The issue here is that we have some boards that are declaring that they have USB (by defining CONFIG_HAS_FSL_DR_USB), but they are not defining the protocol itself. This issue is not related to including <usb.h> file or using any macro from within it.
What's the point of declaring the availability of an IP on a board without mentioning the protocol being used by this IP !!
In case the board is not using USB, CONFIG_HAS_FSL_DR_USB should not be defined in the board file itself.
Even if I make changes for not using a macro defined in <usb.h> file, the issue will still remain for boards defining CONFIG_HAS_FSL_DR_USB (without defining protocol) and using <usb.h> file...
Thanks and Regards, Ramneek
-----Original Message----- From: Wolfgang Denk [mailto:wd@denx.de] Sent: Wednesday, July 20, 2011 5:35 PM To: Mehresh Ramneek-B31383 Cc: Phillips Kim-R1AAHA; Gala Kumar-B11780; u-boot@lists.denx.de Subject: Re: [U-Boot] [PATCH] powerpc/8xxx: Update USB mode device tree fixup
Dear Mehresh Ramneek-B31383,
In message 16867771548D2F469F1A8F817F38278820AF77@039-SN1MPN1-003.039d.mgd.msft.net you wrote:
I just checked that this error comes when you don't have any of the following defined in the board file: CONFIG_USB_UHCI CONFIG_USB_OHCI CONFIG_USB_EHCI CONFIG_USB_OHCI_NEW ... MPC837xRDB has EHCI host controller. Hence, CONFIG_USB_EHCI and its relevant support macros should be defined in include/configs/MPC837XERDB.h file.
No, I disagree. It must be possible to configure such a port without USB as well. Not all boards based on this processer ever want to use USB (or even have it on their boards).
Please fix this in a way that no such definitions are ever mandatory.
Thanks.
Best regards,
Wolfgang Denk
participants (5)
-
Kim Phillips
-
Kumar Gala
-
Mehresh Ramneek-B31383
-
Ramneek Mehresh
-
Wolfgang Denk