ppc4xx: Bring 4xx fdt support up-to-date
[platform/kernel/u-boot.git] / cpu / ppc4xx / fdt.c
1 /*
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>
38 #include <fdt_support.h>
39
40 DECLARE_GLOBAL_DATA_PTR;
41
42 /*
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
48
49 #ifndef USES_FDT_ALIASES
50 static 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 }
65 #endif /* USES_FDT_ALIASES */
66
67 void ft_cpu_setup(void *blob, bd_t *bd)
68 {
69         char *cpu_path = "/cpus/" OF_CPU;
70         sys_info_t sys_info;
71         int offset;
72         int i;
73
74         get_sys_info(&sys_info);
75
76         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);
83
84         /*
85          * Setup all baudrates for the UARTs
86          */
87         do_fixup_by_compat_u32(blob, "ns16550", "clock-frequency", gd->uart_clk, 1);
88
89 #ifdef USES_FDT_ALIASES
90         /*
91          * 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.
94          */
95         fdt_fixup_ethernet(blob, bd);
96 #else
97         offset = -1;
98         for (i = 0; i < 4; i++) {
99                 /*
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");
106                 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         }
130 #endif /* USES_FDT_ALIASES */
131 }
132 #endif /* CONFIG_OF_LIBFDT */