3 * Stefan Roese, DENX Software Engineering, sr@denx.de.
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24 /* define DEBUG for debugging output (obviously ;-)) */
32 #include <asm/cache.h>
35 #if defined(CONFIG_OF_LIBFDT)
37 #include <libfdt_env.h>
39 static void do_fixup(void *fdt, const char *node, const char *prop,
40 const void *val, int len, int create)
44 debug("Updating property '%s/%s' = ", node, prop);
45 for (i = 0; i < len; i++)
46 debug(" %.2x", *(u8*)(val+i));
49 int rc = fdt_find_and_setprop(fdt, node, prop, val, len, create);
51 printf("Unable to update property %s:%s, err=%s\n",
52 node, prop, fdt_strerror(rc));
55 static void do_fixup_macaddr(void *fdt, int offset, const void *val, int i)
59 debug("Updating node EMAC%d\n", i);
61 rc = fdt_setprop(fdt, offset, "mac-address", val, 6);
63 printf("Unable to update property %s, err=%s\n",
64 "mac-address", fdt_strerror(rc));
65 rc = fdt_setprop(fdt, offset, "local-mac-address", val, 6);
67 printf("Unable to update property %s, err=%s\n",
68 "local-mac-address", fdt_strerror(rc));
71 static void do_fixup_u32(void *fdt, const char *node, const char *prop,
74 val = cpu_to_fdt32(val);
75 do_fixup(fdt, node, prop, &val, sizeof(val), create);
78 static void do_fixup_uart(void *fdt, int offset, int i, bd_t *bd)
82 PPC4xx_SYS_INFO sys_info;
84 get_sys_info(&sys_info);
86 debug("Updating node UART%d\n", i);
88 val = cpu_to_fdt32(sys_info.freqUART);
89 rc = fdt_setprop(fdt, offset, "clock-frequency", &val, 4);
91 printf("Unable to update node UART, err=%s\n", fdt_strerror(rc));
93 val = cpu_to_fdt32(bd->bi_baudrate);
94 rc = fdt_setprop(fdt, offset, "current-speed", &val, 4);
96 printf("Unable to update node UART, err=%s\n", fdt_strerror(rc));
99 void ft_cpu_setup(void *blob, bd_t *bd)
101 char * cpu_path = "/cpus/" OF_CPU;
107 get_sys_info (&sys_info);
109 do_fixup_u32(blob, cpu_path, "timebase-frequency", bd->bi_intfreq, 1);
110 do_fixup_u32(blob, cpu_path, "clock-frequency", bd->bi_intfreq, 1);
111 do_fixup_u32(blob, "/plb", "clock-frequency", sys_info.freqPLB, 1);
112 do_fixup_u32(blob, "/plb/opb", "clock-frequency", sys_info.freqOPB, 1);
113 do_fixup_u32(blob, "/plb/opb/ebc", "clock-frequency", sys_info.freqEBC, 1);
115 /* update, or add and update /memory node */
116 offset = fdt_find_node_by_path(blob, "/memory");
118 offset = fdt_add_subnode(blob, 0, "memory");
120 debug("failed to add /memory node: %s\n",
121 fdt_strerror(offset));
124 fdt_setprop(blob, offset, "device_type",
125 "memory", sizeof("memory"));
126 tmp[0] = cpu_to_fdt32(bd->bi_memstart);
127 tmp[1] = cpu_to_fdt32(bd->bi_memsize);
128 fdt_setprop(blob, offset, "reg", tmp, sizeof(tmp));
129 debug("Updating /memory node to %d:%d\n",
130 bd->bi_memstart, bd->bi_memsize);
134 * Setup all baudrates for the UARTs
137 for (i = 0; i < 4; i++) {
138 offset = fdt_find_node_by_type(blob, offset, "serial");
142 do_fixup_uart(blob, offset, i, bd);
146 * Setup all MAC addresses in fdt
149 for (i = 0; i < 4; i++) {
150 offset = fdt_find_node_by_type(blob, offset, "network");
156 do_fixup_macaddr(blob, offset, bd->bi_enetaddr, 0);
158 #ifdef CONFIG_HAS_ETH1
160 do_fixup_macaddr(blob, offset, bd->bi_enet1addr, 1);
163 #ifdef CONFIG_HAS_ETH2
165 do_fixup_macaddr(blob, offset, bd->bi_enet2addr, 2);
168 #ifdef CONFIG_HAS_ETH3
170 do_fixup_macaddr(blob, offset, bd->bi_enet3addr, 3);
176 #endif /* CONFIG_OF_LIBFDT */