From: Bartlomiej Sieka Date: Thu, 2 Aug 2007 20:24:03 +0200 Subject: [U-Boot-Users] [PATCH] fdt, mpc5xxx: Adapt MPC5xxx to use libfdt in ft_cpu_setup() Message-ID: <20070802182403.GA27073@frozen.semihalf.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Signed-off-by: Grzegorz Bernacki --- Not sure where this should be merged, it was applied to u-boot-fdt#fdt (as of 01f771763ed822145b54819abb9c4516c8216d48) merged with the master (as of cc3023b9f95d7ac959a764471a65001062aecf41). 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..c4484ef 100644 --- a/cpu/mpc5xxx/cpu.c +++ b/cpu/mpc5xxx/cpu.c @@ -33,6 +33,9 @@ #if defined(CONFIG_OF_FLAT_TREE) #include +#elif defined(CONFIG_OF_LIBFDT) +#include +#include #endif DECLARE_GLOBAL_DATA_PTR; @@ -109,9 +112,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 at 3000", + "mac-address", + fdt_set_macaddress + }, + { "/" OF_SOC "/ethernet at 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) + printf("Problem setting %s = %s: %s\n", + fixup_props[j].node, + fixup_props[j].prop, + fdt_strerror(err)); + } else { + printf("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 +251,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 at 3000/local-mac-address", &len); + p = ft_get_prop(blob, "/" OF_SOC "/ethernet at 3000/local-mac-address", + &len); if (p != NULL) memcpy(p, bd->bi_enetaddr, 6); } -#endif +#endif /* defined(CONFIG_OF_LIBFDT) */