From patchwork Sun Mar 13 15:13:48 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kumar Gala X-Patchwork-Id: 86602 X-Patchwork-Delegate: galak@kernel.crashing.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 92EA5B6F7C for ; Mon, 14 Mar 2011 02:14:00 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id B2E1B28106; Sun, 13 Mar 2011 16:13:58 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id qoIIiKKPVvNW; Sun, 13 Mar 2011 16:13:58 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 2B002280FC; Sun, 13 Mar 2011 16:13:57 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id F0E03280FC for ; Sun, 13 Mar 2011 16:13:54 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id HvxFu9eTmvjz for ; Sun, 13 Mar 2011 16:13:54 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from gate.crashing.org (gate.crashing.org [63.228.1.57]) by theia.denx.de (Postfix) with ESMTPS id 132A0280F8 for ; Sun, 13 Mar 2011 16:13:52 +0100 (CET) Received: from localhost (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.13.8) with ESMTP id p2DFDmP5022912; Sun, 13 Mar 2011 10:13:49 -0500 From: Kumar Gala To: u-boot@lists.denx.de Date: Sun, 13 Mar 2011 10:13:48 -0500 Message-Id: <1300029228-30050-1-git-send-email-galak@kernel.crashing.org> X-Mailer: git-send-email 1.5.6.5 In-Reply-To: <1299471449-26715-2-git-send-email-galak@kernel.crashing.org> References: <1299471449-26715-2-git-send-email-galak@kernel.crashing.org> Cc: Ramneek Mehresh Subject: [U-Boot] [PATCH v2 2/2] powerpc/8xxx: Update USB device tree fixup X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.9 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de From: Ramneek Mehresh Modify support for USB mode fixup: * Add support for fetching USB mode and phy type via hwconfig * Add common support for USB mode and phy type device tree fix-up for all USB controllers mentioned in hwconfig string Signed-off-by: Ramneek Mehresh Signed-off-by: Kumar Gala --- * minor bug fix in fdt_fixup_dr_usb logic: mode_idx should be set to 'j'. arch/powerpc/cpu/mpc8xxx/fdt.c | 81 +++++++++++++++++++++++++++++++++------- 1 files changed, 67 insertions(+), 14 deletions(-) diff --git a/arch/powerpc/cpu/mpc8xxx/fdt.c b/arch/powerpc/cpu/mpc8xxx/fdt.c index 0c166fd..68f3e4e 100644 --- a/arch/powerpc/cpu/mpc8xxx/fdt.c +++ b/arch/powerpc/cpu/mpc8xxx/fdt.c @@ -29,6 +29,10 @@ #include #include #include +#include +#ifdef CONFIG_HAS_FSL_DR_USB +#include +#endif #if defined(CONFIG_MP) && (defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx)) static int ft_del_cpuhandle(void *blob, int cpuhandle) @@ -84,25 +88,22 @@ 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)); + printf("WARNING: could not find compatible" + "node %s: %s.\n", compat, + fdt_strerror(node_offset)); return; } @@ -114,14 +115,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 str[5]; + char usb1_defined = 0; + 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 = -1; + break; + } + } + if ((mode_idx >= 0) || (phy_idx >= 0)) { + fdt_fixup_usb_mode_phy_type(blob, + modes[mode_idx], phys[phy_idx]); + if (!strcmp(str, "usb1")) + usb1_defined = 1; + } else { + 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 */ /*