blob: 3ef30004fb7601b2d0879a0a2920e31d577fee1c [file] [log] [blame]
Stefan Roese4f14ed62007-10-05 17:07:50 +02001/*
2 * (C) Copyright 2007
3 * Stefan Roese, DENX Software Engineering, sr@denx.de.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
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.
12 *
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.
17 *
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,
21 * MA 02111-1307 USA
22 */
23
24/* define DEBUG for debugging output (obviously ;-)) */
25#if 0
26#define DEBUG
27#endif
28
29#include <common.h>
30#include <watchdog.h>
31#include <command.h>
32#include <asm/cache.h>
33#include <ppc4xx.h>
34
35#if defined(CONFIG_OF_LIBFDT)
36#include <libfdt.h>
37#include <libfdt_env.h>
Stefan Roese13628882007-12-13 14:52:53 +010038#include <fdt_support.h>
Stefan Roese4f14ed62007-10-05 17:07:50 +020039
Stefan Roesef10493c2007-10-23 11:31:05 +020040DECLARE_GLOBAL_DATA_PTR;
41
Stefan Roese13628882007-12-13 14:52:53 +010042/*
43 * The aliases needed for this generic etherne MAC address
44 * fixup function are not in place yet. So don't use this
45 * approach for now. This will be enabled later.
46 */
47#undef USES_FDT_ALIASES
Stefan Roese4f14ed62007-10-05 17:07:50 +020048
Stefan Roese13628882007-12-13 14:52:53 +010049#ifndef USES_FDT_ALIASES
Stefan Roese4f14ed62007-10-05 17:07:50 +020050static void do_fixup_macaddr(void *fdt, int offset, const void *val, int i)
51{
52 int rc;
53
54 debug("Updating node EMAC%d\n", i);
55
56 rc = fdt_setprop(fdt, offset, "mac-address", val, 6);
57 if (rc)
58 printf("Unable to update property %s, err=%s\n",
59 "mac-address", fdt_strerror(rc));
60 rc = fdt_setprop(fdt, offset, "local-mac-address", val, 6);
61 if (rc)
62 printf("Unable to update property %s, err=%s\n",
63 "local-mac-address", fdt_strerror(rc));
64}
Stefan Roese13628882007-12-13 14:52:53 +010065#endif /* USES_FDT_ALIASES */
Stefan Roese4f14ed62007-10-05 17:07:50 +020066
67void ft_cpu_setup(void *blob, bd_t *bd)
68{
Stefan Roese13628882007-12-13 14:52:53 +010069 char *cpu_path = "/cpus/" OF_CPU;
Stefan Roese4f14ed62007-10-05 17:07:50 +020070 sys_info_t sys_info;
71 int offset;
72 int i;
Stefan Roese4f14ed62007-10-05 17:07:50 +020073
Stefan Roese13628882007-12-13 14:52:53 +010074 get_sys_info(&sys_info);
Stefan Roese4f14ed62007-10-05 17:07:50 +020075
Stefan Roese13628882007-12-13 14:52:53 +010076 do_fixup_by_path_u32(blob, cpu_path, "timebase-frequency", bd->bi_intfreq, 1);
77 do_fixup_by_path_u32(blob, cpu_path, "clock-frequency", bd->bi_intfreq, 1);
78 do_fixup_by_path_u32(blob, "/plb", "clock-frequency", sys_info.freqPLB, 1);
79 do_fixup_by_path_u32(blob, "/plb/opb", "clock-frequency", sys_info.freqOPB, 1);
80 do_fixup_by_path_u32(blob, "/plb/opb/ebc", "clock-frequency",
81 sys_info.freqEBC, 1);
82 fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize);
Stefan Roese4f14ed62007-10-05 17:07:50 +020083
84 /*
85 * Setup all baudrates for the UARTs
86 */
Stefan Roese13628882007-12-13 14:52:53 +010087 do_fixup_by_compat_u32(blob, "ns16550", "clock-frequency", gd->uart_clk, 1);
Stefan Roese4f14ed62007-10-05 17:07:50 +020088
Stefan Roese13628882007-12-13 14:52:53 +010089#ifdef USES_FDT_ALIASES
Stefan Roese4f14ed62007-10-05 17:07:50 +020090 /*
Stefan Roese13628882007-12-13 14:52:53 +010091 * The aliases needed for this generic etherne MAC address
92 * fixup function are not in place yet. So don't use this
93 * approach for now. This will be enabled later.
Stefan Roese4f14ed62007-10-05 17:07:50 +020094 */
Stefan Roese13628882007-12-13 14:52:53 +010095 fdt_fixup_ethernet(blob, bd);
96#else
97 offset = -1;
Stefan Roese4f14ed62007-10-05 17:07:50 +020098 for (i = 0; i < 4; i++) {
Stefan Roese13628882007-12-13 14:52:53 +010099 /*
100 * FIXME: This will cause problems with emac3 compatible
101 * devices, like on 405GP. But hopefully when we deal
102 * with those devices, the aliases stuff will be in
103 * place.
104 */
105 offset = fdt_node_offset_by_compatible(blob, offset, "ibm,emac4");
Stefan Roese4f14ed62007-10-05 17:07:50 +0200106 if (offset < 0)
107 break;
108
109 switch (i) {
110 case 0:
111 do_fixup_macaddr(blob, offset, bd->bi_enetaddr, 0);
112 break;
113#ifdef CONFIG_HAS_ETH1
114 case 1:
115 do_fixup_macaddr(blob, offset, bd->bi_enet1addr, 1);
116 break;
117#endif
118#ifdef CONFIG_HAS_ETH2
119 case 2:
120 do_fixup_macaddr(blob, offset, bd->bi_enet2addr, 2);
121 break;
122#endif
123#ifdef CONFIG_HAS_ETH3
124 case 3:
125 do_fixup_macaddr(blob, offset, bd->bi_enet3addr, 3);
126 break;
127#endif
128 }
129 }
Stefan Roese13628882007-12-13 14:52:53 +0100130#endif /* USES_FDT_ALIASES */
Stefan Roese4f14ed62007-10-05 17:07:50 +0200131}
132#endif /* CONFIG_OF_LIBFDT */