From patchwork Fri Oct 14 19:10:43 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kumar Gala X-Patchwork-Id: 119908 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 C9E10B702E for ; Sat, 15 Oct 2011 06:11:21 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 1C6D628DAE; Fri, 14 Oct 2011 21:11:13 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id kwA39aud7GIr; Fri, 14 Oct 2011 21:11:12 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 4C91428DAF; Fri, 14 Oct 2011 21:11:05 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 80B9F28D1A for ; Fri, 14 Oct 2011 21:11:03 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id zCWTIJhr6QOz for ; Fri, 14 Oct 2011 21:10:59 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from gate.crashing.org (unknown [63.228.1.57]) by theia.denx.de (Postfix) with ESMTPS id 196E128D14 for ; Fri, 14 Oct 2011 21:10:57 +0200 (CEST) Received: from localhost (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.13.8) with ESMTP id p9EJAiE1031745; Fri, 14 Oct 2011 14:10:45 -0500 From: Kumar Gala To: u-boot@lists.denx.de Date: Fri, 14 Oct 2011 14:10:43 -0500 Message-Id: <1318619444-2059-1-git-send-email-galak@kernel.crashing.org> X-Mailer: git-send-email 1.5.6.5 Cc: Shengzhou Liu Subject: [U-Boot] [PATCH 1/2] fdt: Add new fdt_set_node_status & fdt_set_status_by_alias helpers 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: Shengzhou Liu Add common function fdt_set_node_status() to assist in various locations that we set a nodes status. This function utilizes the status values that are part of the EPAPR spec (on power.org). fdt_set_status_by_alias() is based on fdt_set_node_status() but uses an alias string to identify the node to update. We also add some shortcut functions to help the common cases of setting "okay" and "disabled": fdt_status_okay() fdt_status_disabled() fdt_status_okay_by_alias() fdt_status_disabled_by_alias() Finally, we fixup the corenet_ds ethernet code which previously had a function by the same name that can be replaced with the new helpers. Signed-off-by: Shengzhou Liu Signed-off-by: Kumar Gala Acked-by: Gerald Van Baren --- board/freescale/corenet_ds/eth_hydra.c | 26 ++------------ board/freescale/corenet_ds/eth_p4080.c | 36 +++++-------------- common/fdt_support.c | 60 +++++++++++++++++++++++++++++++- include/fdt_support.h | 28 +++++++++++++++ 4 files changed, 101 insertions(+), 49 deletions(-) diff --git a/board/freescale/corenet_ds/eth_hydra.c b/board/freescale/corenet_ds/eth_hydra.c index 91b3408..a7a5e13 100644 --- a/board/freescale/corenet_ds/eth_hydra.c +++ b/board/freescale/corenet_ds/eth_hydra.c @@ -70,6 +70,7 @@ #include #include #include +#include #include #include "../common/ngpixis.h" @@ -200,25 +201,6 @@ static int hydra_mdio_init(char *realbusname, char *fakebusname) } /* - * Given an alias or a path for a node, set the status of that node. - * - * If 'alias' is not a valid alias, then it is treated as a full path to the - * node. No error checking is performed. - * - * This function is normally called to set the status for a virtual MDIO node. - */ -static void fdt_set_node_status(void *fdt, const char *alias, - const char *status) -{ - const char *path = fdt_get_alias(fdt, alias); - - if (!path) - path = alias; - - do_fixup_by_path(fdt, path, "status", status, strlen(status) + 1, 1); -} - -/* * Given an alias or a path for a node, set the mux value of that node. * * If 'alias' is not a valid alias, then it is treated as a full path to the @@ -372,14 +354,14 @@ void fdt_fixup_board_enet(void *fdt) case PHY_INTERFACE_MODE_SGMII: lane = serdes_get_first_lane(SGMII_FM1_DTSEC1 + idx); if (lane >= 0) { - fdt_set_node_status(fdt, "emi1_sgmii", "okay"); + fdt_status_okay_by_alias(fdt, "emi1_sgmii"); /* Also set the MUX value */ fdt_set_mdio_mux(fdt, "emi1_sgmii", mdio_mux[i].val); } break; case PHY_INTERFACE_MODE_RGMII: - fdt_set_node_status(fdt, "emi1_rgmii", "okay"); + fdt_status_okay_by_alias(fdt, "emi1_rgmii"); break; default: break; @@ -388,7 +370,7 @@ void fdt_fixup_board_enet(void *fdt) lane = serdes_get_first_lane(XAUI_FM1); if (lane >= 0) - fdt_set_node_status(fdt, "emi2_xgmii", "okay"); + fdt_status_okay_by_alias(fdt, "emi2_xgmii"); #endif } diff --git a/board/freescale/corenet_ds/eth_p4080.c b/board/freescale/corenet_ds/eth_p4080.c index d4657f7..00dfa9a 100644 --- a/board/freescale/corenet_ds/eth_p4080.c +++ b/board/freescale/corenet_ds/eth_p4080.c @@ -199,22 +199,6 @@ static int p4080ds_mdio_init(char *realbusname, u32 muxval) return mdio_register(bus); } -/* - * Sets the specified node's status to the value contained in "status" - * If the first character of the specified path is "/" then we use - * alias as a path. Otherwise, we look for an alias of that name - */ -static void fdt_set_node_status(void *fdt, const char *alias, - const char *status) -{ - const char *path = fdt_get_alias(fdt, alias); - - if (!path) - path = alias; - - do_fixup_by_path(fdt, path, "status", status, strlen(status) + 1, 1); -} - void board_ft_fman_fixup_port(void *blob, char * prop, phys_addr_t pa, enum fm_port port, int offset) { @@ -255,28 +239,28 @@ void fdt_fixup_board_enet(void *fdt) */ /* We've got six MDIO nodes that may or may not need to exist */ - fdt_set_node_status(fdt, "emi1_slot3", "disabled"); - fdt_set_node_status(fdt, "emi1_slot4", "disabled"); - fdt_set_node_status(fdt, "emi1_slot5", "disabled"); - fdt_set_node_status(fdt, "emi2_slot4", "disabled"); - fdt_set_node_status(fdt, "emi2_slot5", "disabled"); + fdt_status_disabled_by_alias(fdt, "emi1_slot3"); + fdt_status_disabled_by_alias(fdt, "emi1_slot4"); + fdt_status_disabled_by_alias(fdt, "emi1_slot5"); + fdt_status_disabled_by_alias(fdt, "emi2_slot4"); + fdt_status_disabled_by_alias(fdt, "emi2_slot5"); for (i = 0; i < NUM_FM_PORTS; i++) { switch (mdio_mux[i]) { case EMI1_SLOT3: - fdt_set_node_status(fdt, "emi1_slot3", "okay"); + fdt_status_okay_by_alias(fdt, "emi1_slot3"); break; case EMI1_SLOT4: - fdt_set_node_status(fdt, "emi1_slot4", "okay"); + fdt_status_okay_by_alias(fdt, "emi1_slot4"); break; case EMI1_SLOT5: - fdt_set_node_status(fdt, "emi1_slot5", "okay"); + fdt_status_okay_by_alias(fdt, "emi1_slot5"); break; case EMI2_SLOT4: - fdt_set_node_status(fdt, "emi2_slot4", "okay"); + fdt_status_okay_by_alias(fdt, "emi2_slot4"); break; case EMI2_SLOT5: - fdt_set_node_status(fdt, "emi2_slot5", "okay"); + fdt_status_okay_by_alias(fdt, "emi2_slot5"); break; } } diff --git a/common/fdt_support.c b/common/fdt_support.c index 46aa842..16854f6 100644 --- a/common/fdt_support.c +++ b/common/fdt_support.c @@ -2,7 +2,7 @@ * (C) Copyright 2007 * Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com * - * Copyright 2010 Freescale Semiconductor, Inc. + * Copyright 2010-2011 Freescale Semiconductor, Inc. * * See file CREDITS for list of people who contributed to this * project. @@ -1255,6 +1255,64 @@ int fdt_create_phandle(void *fdt, int nodeoffset) return phandle; } +/* + * fdt_set_node_status: Set status for the given node + * + * @fdt: ptr to device tree + * @nodeoffset: node to update + * @status: FDT_STATUS_OKAY, FDT_STATUS_DISABLED, + * FDT_STATUS_FAIL, FDT_STATUS_FAIL_ERROR_CODE + * @error_code: optional, only used if status is FDT_STATUS_FAIL_ERROR_CODE + */ +int fdt_set_node_status(void *fdt, int nodeoffset, + enum fdt_status status, unsigned int error_code) +{ + char buf[16]; + int ret = 0; + + if (nodeoffset < 0) + return nodeoffset; + + switch (status) { + case FDT_STATUS_OKAY: + ret = fdt_setprop_string(fdt, nodeoffset, "status", "okay"); + break; + case FDT_STATUS_DISABLED: + ret = fdt_setprop_string(fdt, nodeoffset, "status", "disabled"); + break; + case FDT_STATUS_FAIL: + ret = fdt_setprop_string(fdt, nodeoffset, "status", "fail"); + break; + case FDT_STATUS_FAIL_ERROR_CODE: + sprintf(buf, "fail-%d", error_code); + ret = fdt_setprop_string(fdt, nodeoffset, "status", buf); + break; + default: + printf("Invalid fdt status: %x\n", status); + ret = -1; + break; + } + + return ret; +} + +/* + * fdt_set_status_by_alias: Set status for the given node given an alias + * + * @fdt: ptr to device tree + * @alias: alias of node to update + * @status: FDT_STATUS_OKAY, FDT_STATUS_DISABLED, + * FDT_STATUS_FAIL, FDT_STATUS_FAIL_ERROR_CODE + * @error_code: optional, only used if status is FDT_STATUS_FAIL_ERROR_CODE + */ +int fdt_set_status_by_alias(void *fdt, const char* alias, + enum fdt_status status, unsigned int error_code) +{ + int offset = fdt_path_offset(fdt, alias); + + return fdt_set_node_status(fdt, offset, status, error_code); +} + #if defined(CONFIG_VIDEO) int fdt_add_edid(void *blob, const char *compat, unsigned char *edid_buf) { diff --git a/include/fdt_support.h b/include/fdt_support.h index 8f06aac..08b4de1 100644 --- a/include/fdt_support.h +++ b/include/fdt_support.h @@ -97,5 +97,33 @@ int fdt_verify_alias_address(void *fdt, int anode, const char *alias, u64 addr); u64 fdt_get_base_address(void *fdt, int node); +enum fdt_status { + FDT_STATUS_OKAY, + FDT_STATUS_DISABLED, + FDT_STATUS_FAIL, + FDT_STATUS_FAIL_ERROR_CODE, +}; +int fdt_set_node_status(void *fdt, int nodeoffset, + enum fdt_status status, unsigned int error_code); +static inline int fdt_status_okay(void *fdt, int nodeoffset) +{ + return fdt_set_node_status(fdt, nodeoffset, FDT_STATUS_OKAY, 0); +} +static inline int fdt_status_disabled(void *fdt, int nodeoffset) +{ + return fdt_set_node_status(fdt, nodeoffset, FDT_STATUS_DISABLED, 0); +} + +int fdt_set_status_by_alias(void *fdt, const char* alias, + enum fdt_status status, unsigned int error_code); +static inline int fdt_status_okay_by_alias(void *fdt, const char* alias) +{ + return fdt_set_status_by_alias(fdt, alias, FDT_STATUS_OKAY, 0); +} +static inline int fdt_status_disabled_by_alias(void *fdt, const char* alias) +{ + return fdt_set_status_by_alias(fdt, alias, FDT_STATUS_DISABLED, 0); +} + #endif /* ifdef CONFIG_OF_LIBFDT */ #endif /* ifndef __FDT_SUPPORT_H */