#include <fm_eth.h>
#include <fsl_mdio.h>
#include <malloc.h>
+#include <fdt_support.h>
#include <asm/fsl_dtsec.h>
#include "../common/ngpixis.h"
return mdio_register(bus);
}
-/*
- * 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.
*
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;
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
}
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)
{
*/
/* 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;
}
}
* (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.
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)
{
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 */