
On 8/3/07, Bartlomiej Sieka tur@semihalf.com wrote:
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
Comments below g.
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.
Isn't OF_LIBFDT supposed to replace OF_FLAT_TREE? There aren't many 5xxx boards using OF_FLAT_TREE. You should craft your patch to update all the OF_FLAT_TREE users to OF_LIBFDT.
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));
+}
These 4 functions are pretty close to identical (except for the parameter to cpu_to_be32()). Surely there is a more compact way to do this. In addition, these function don't really contain anything that screams out "5xxx only!". Can this be common support code usable by all boards?
Alternately, this is a very verbose block of code. If it cannot be consolidated and simplified, then it should all just be rolled into ft_cpu_setup. (Table driven works well when there is a lot of entries using common functions/data, which is not currently the case).
+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) */
This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ U-Boot-Users mailing list U-Boot-Users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/u-boot-users