public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot-Users] [PATCH] fdt, mpc5xxx: Adapt MPC5xxx to use libfdt in ft_cpu_setup()
@ 2007-08-02 18:24 Bartlomiej Sieka
  2007-08-03  9:07 ` [U-Boot-Users] [PATCH CORRECTION] " Bartlomiej Sieka
  2007-08-04 21:21 ` [U-Boot-Users] [PATCH] " Jerry Van Baren
  0 siblings, 2 replies; 20+ messages in thread
From: Bartlomiej Sieka @ 2007-08-02 18:24 UTC (permalink / raw)
  To: u-boot

Signed-off-by: Grzegorz Bernacki <gjb@semihalf.com>
---
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 <ft_build.h>
+#elif defined(CONFIG_OF_LIBFDT)
+#include <libfdt.h>
+#include <libfdt_env.h>
 #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) */

^ permalink raw reply related	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2007-08-30 12:49 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-02 18:24 [U-Boot-Users] [PATCH] fdt, mpc5xxx: Adapt MPC5xxx to use libfdt in ft_cpu_setup() Bartlomiej Sieka
2007-08-03  9:07 ` [U-Boot-Users] [PATCH CORRECTION] " Bartlomiej Sieka
2007-08-03 14:25   ` Grant Likely
2007-08-22 11:54     ` [U-Boot-Users] [PATCH] RFC: generic property fixup mechanism for LIBFDT Bartlomiej Sieka
2007-08-22 13:18       ` Jerry Van Baren
2007-08-22 21:09         ` Kim Phillips
2007-08-22 23:16           ` Jerry Van Baren
2007-08-23 16:24             ` Kim Phillips
2007-08-23 17:01               ` Jerry Van Baren
2007-08-29 18:01                 ` Grant Likely
2007-08-30  2:40                   ` Jerry Van Baren
2007-08-30 11:51                     ` Jerry Van Baren
2007-08-30 12:49                       ` Bartlomiej Sieka
2007-08-22 23:30           ` Wolfgang Denk
2007-08-23 16:48             ` Kim Phillips
2007-08-23 17:28               ` Jerry Van Baren
2007-08-23 19:25               ` Wolfgang Denk
2007-08-29 10:59     ` [U-Boot-Users] [PATCH CORRECTION] fdt, mpc5xxx: Adapt MPC5xxx to use libfdt in ft_cpu_setup() Wolfgang Denk
2007-08-29 18:23       ` Grant Likely
2007-08-04 21:21 ` [U-Boot-Users] [PATCH] " Jerry Van Baren

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox