
Add necessary functions to allow MPC5XXX machines to use libfdt. Code was derived from analogous MPC83xx implementation. Also, add a small coding style fix while in the area.
Signed-off-by: Grzegorz Bernacki gjb@semihalf.com --- I have sent a wrong patch with wrong comments before, please disregard my previous email on the same topic; and sorry for the noise.
The baseline used to generate the patch was the master (as of cc3023b9f95d7ac959a764471a65001062aecf41) with pulled u-boot-fdt#fdt branch (as of 01f771763ed822145b54819abb9c4516c8216d48).
The patch has been tested on two MPC5200B-based boards, one using CONFIG_OF_LIBFDT, the other using CONFIG_OF_FLAT_TREE.
diff --git a/cpu/mpc5xxx/cpu.c b/cpu/mpc5xxx/cpu.c index 1eac2bb..2be5caa 100644 --- a/cpu/mpc5xxx/cpu.c +++ b/cpu/mpc5xxx/cpu.c @@ -19,6 +19,8 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA + * + * Libfdt related routines derived from the MPC83xx. */
/* @@ -33,6 +35,9 @@
#if defined(CONFIG_OF_FLAT_TREE) #include <ft_build.h> +#elif defined(CONFIG_OF_LIBFDT) +#include <libfdt.h> +#include <libfdt_env.h> #endif
DECLARE_GLOBAL_DATA_PTR; @@ -109,9 +114,125 @@ unsigned long get_tbclk (void) return (tbclk); }
+#if defined(CONFIG_OF_LIBFDT) +/* + * "Setter" functions used to add/modify FDT entries. + */ +static int fdt_set_tbfreq(void *fdt, int nodeoffset, const char *name, bd_t *bd) +{ + u32 tmp; + /* + * Create or update the property. + */ + tmp = cpu_to_be32(OF_TBCLK); + return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp)); +} + +static int fdt_set_busfreq(void *fdt, int nodeoffset, const char *name, + bd_t *bd) +{ + u32 tmp; + /* + * Create or update the property. + */ + tmp = cpu_to_be32(bd->bi_busfreq); + return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp)); +} + +static int fdt_set_clockfreq(void *fdt, int nodeoffset, const char *name, + bd_t *bd) +{ + u32 tmp; + /* + * Create or update the property. + */ + tmp = cpu_to_be32(bd->bi_intfreq); + return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp)); +} + +static int fdt_set_ipbusfreq(void *fdt, int nodeoffset, const char *name, + bd_t *bd) +{ + u32 tmp; + /* + * Create or update the property. + */ + tmp = cpu_to_be32(bd->bi_ipbfreq); + return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp)); +} + +static int fdt_set_macaddress(void *fdt, int nodeoffset, const char *name, + bd_t *bd) +{ + /* + * Fix it up if it exists, don't create it if it doesn't exist. + */ + if (fdt_get_property(fdt, nodeoffset, name, 0)) { + return fdt_setprop(fdt, nodeoffset, name, bd->bi_enetaddr, 6); + } + return 0; +} + /* ------------------------------------------------------------------------- */ +/* + * Fixups to the fdt. + */ +static const struct { + char *node; + char *prop; + int (*set_fn)(void *fdt, int nodeoffset, const char *name, bd_t *bd); +} fixup_props[] = { + { "/cpus/" OF_CPU, + "timebase-frequency", + fdt_set_tbfreq + }, + { "/cpus/" OF_CPU, + "bus-frequency", + fdt_set_busfreq + }, + { "/cpus/" OF_CPU, + "clock-frequency", + fdt_set_clockfreq + }, + { "/" OF_SOC, + "bus-frequency", + fdt_set_ipbusfreq + }, + { "/" OF_SOC "/ethernet@3000", + "mac-address", + fdt_set_macaddress + }, + { "/" OF_SOC "/ethernet@3000", + "local-mac-address", + fdt_set_macaddress + } +};
-#ifdef CONFIG_OF_FLAT_TREE +void +ft_cpu_setup(void *blob, bd_t *bd) +{ + int nodeoffset; + int err; + int j; + + for (j = 0; j < (sizeof(fixup_props) / sizeof(fixup_props[0])); j++) { + nodeoffset = fdt_find_node_by_path(blob, fixup_props[j].node); + if (nodeoffset >= 0) { + err = fixup_props[j].set_fn(blob, nodeoffset, + fixup_props[j].prop, bd); + if (err < 0) + debug("Problem setting %s = %s: %s\n", + fixup_props[j].node, + fixup_props[j].prop, + fdt_strerror(err)); + } else { + debug("Couldn't find %s: %s\n", + fixup_props[j].node, + fdt_strerror(nodeoffset)); + } + } +} +#elif defined(CONFIG_OF_FLAT_TREE) void ft_cpu_setup(void *blob, bd_t *bd) { @@ -132,8 +253,9 @@ ft_cpu_setup(void *blob, bd_t *bd) if (p != NULL) memcpy(p, bd->bi_enetaddr, 6);
- p = ft_get_prop(blob, "/" OF_SOC "/ethernet@3000/local-mac-address", &len); + p = ft_get_prop(blob, "/" OF_SOC "/ethernet@3000/local-mac-address", + &len); if (p != NULL) memcpy(p, bd->bi_enetaddr, 6); } -#endif +#endif /* defined(CONFIG_OF_FLAT_TREE) */