blob: 5ddb8802417ea373fc65d6e6ea50524fb3163d9d [file] [log] [blame]
Stefan Roese4f14ed62007-10-05 17:07:50 +02001/*
Stefan Roesecb5d88b2008-05-08 11:01:09 +02002 * (C) Copyright 2007-2008
Stefan Roese4f14ed62007-10-05 17:07:50 +02003 * 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
Stefan Roese4f14ed62007-10-05 17:07:50 +020024#include <common.h>
25#include <watchdog.h>
26#include <command.h>
27#include <asm/cache.h>
Stefan Roeseb36df562010-09-09 19:18:00 +020028#include <asm/ppc4xx.h>
Stefan Roese4f14ed62007-10-05 17:07:50 +020029
Stefan Roesecb5d88b2008-05-08 11:01:09 +020030#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
Stefan Roese4f14ed62007-10-05 17:07:50 +020031#include <libfdt.h>
32#include <libfdt_env.h>
Stefan Roese13628882007-12-13 14:52:53 +010033#include <fdt_support.h>
Stefan Roese24bfedb2008-04-22 12:20:32 +020034#include <asm/4xx_pcie.h>
Stefan Roese4f14ed62007-10-05 17:07:50 +020035
Stefan Roesef10493c2007-10-23 11:31:05 +020036DECLARE_GLOBAL_DATA_PTR;
37
Stefan Roesecb5d88b2008-05-08 11:01:09 +020038void __ft_board_setup(void *blob, bd_t *bd)
39{
Stefan Roesecb5d88b2008-05-08 11:01:09 +020040 int rc;
Stefan Roese43cbce62008-10-13 10:45:14 +020041 int i;
42 u32 bxcr;
43 u32 ranges[EBC_NUM_BANKS * 4];
44 u32 *p = ranges;
Wolfgang Denk76706cb2009-10-20 23:12:13 +020045 char ebc_path[] = "/plb/opb/ebc";
Stefan Roesecb5d88b2008-05-08 11:01:09 +020046
47 ft_cpu_setup(blob, bd);
48
Stefan Roese43cbce62008-10-13 10:45:14 +020049 /*
50 * Read 4xx EBC bus bridge registers to get mappings of the
51 * peripheral banks into the OPB/PLB address space
52 */
53 for (i = 0; i < EBC_NUM_BANKS; i++) {
Stefan Roesed1c3b272009-09-09 16:25:29 +020054 mtdcr(EBC0_CFGADDR, EBC_BXCR(i));
55 bxcr = mfdcr(EBC0_CFGDATA);
Stefan Roese43cbce62008-10-13 10:45:14 +020056
57 if ((bxcr & EBC_BXCR_BU_MASK) != EBC_BXCR_BU_NONE) {
58 *p++ = i;
59 *p++ = 0;
60 *p++ = bxcr & EBC_BXCR_BAS_MASK;
61 *p++ = EBC_BXCR_BANK_SIZE(bxcr);
62 }
Stefan Roesee3218012008-07-10 13:52:44 +020063 }
Stefan Roese43cbce62008-10-13 10:45:14 +020064
Stefan Roese8a805df2010-09-16 14:01:53 +020065
66#ifdef CONFIG_FDT_FIXUP_NOR_FLASH_SIZE
67 /* Update reg property in all nor flash nodes too */
68 fdt_fixup_nor_flash_size(blob);
69#endif
70
Stefan Roese43cbce62008-10-13 10:45:14 +020071 /* Some 405 PPC's have EBC as direct PLB child in the dts */
Stefan Roese92b89642009-10-16 10:01:09 +020072 if (fdt_path_offset(blob, ebc_path) < 0)
Stefan Roese43cbce62008-10-13 10:45:14 +020073 strcpy(ebc_path, "/plb/ebc");
74 rc = fdt_find_and_setprop(blob, ebc_path, "ranges", ranges,
75 (p - ranges) * sizeof(u32), 1);
76 if (rc) {
77 printf("Unable to update property EBC mappings, err=%s\n",
Stefan Roesecb5d88b2008-05-08 11:01:09 +020078 fdt_strerror(rc));
Stefan Roese43cbce62008-10-13 10:45:14 +020079 }
Stefan Roesecb5d88b2008-05-08 11:01:09 +020080}
81void ft_board_setup(void *blob, bd_t *bd) __attribute__((weak, alias("__ft_board_setup")));
82
Stefan Roese24bfedb2008-04-22 12:20:32 +020083/*
84 * Fixup all PCIe nodes by setting the device_type property
85 * to "pci-endpoint" instead is "pci" for endpoint ports.
86 * This property will get checked later by the Linux driver
87 * to properly configure the PCIe port in Linux (again).
88 */
89void fdt_pcie_setup(void *blob)
90{
91 const char *compat = "ibm,plb-pciex";
92 const char *prop = "device_type";
93 const char *prop_val = "pci-endpoint";
94 const u32 *port;
95 int no;
96 int rc;
97
98 /* Search first PCIe node */
99 no = fdt_node_offset_by_compatible(blob, -1, compat);
100 while (no != -FDT_ERR_NOTFOUND) {
101 port = fdt_getprop(blob, no, "port", NULL);
102 if (port == NULL) {
103 printf("WARNING: could not find port property\n");
104 } else {
105 if (is_end_point(*port)) {
106 rc = fdt_setprop(blob, no, prop, prop_val,
107 strlen(prop_val) + 1);
108 if (rc < 0)
109 printf("WARNING: could not set %s for %s: %s.\n",
110 prop, compat, fdt_strerror(rc));
111 }
112 }
113
114 /* Jump to next PCIe node */
115 no = fdt_node_offset_by_compatible(blob, no, compat);
116 }
117}
118
Stefan Roese4f14ed62007-10-05 17:07:50 +0200119void ft_cpu_setup(void *blob, bd_t *bd)
120{
Stefan Roese4f14ed62007-10-05 17:07:50 +0200121 sys_info_t sys_info;
Matthias Fuchsb129eff2009-02-03 22:13:16 +0100122 int off, ndepth = 0;
Stefan Roese4f14ed62007-10-05 17:07:50 +0200123
Stefan Roese13628882007-12-13 14:52:53 +0100124 get_sys_info(&sys_info);
Stefan Roese4f14ed62007-10-05 17:07:50 +0200125
Stefan Roese328a3402007-12-18 08:44:51 +0100126 do_fixup_by_prop_u32(blob, "device_type", "cpu", 4, "timebase-frequency",
127 bd->bi_intfreq, 1);
128 do_fixup_by_prop_u32(blob, "device_type", "cpu", 4, "clock-frequency",
129 bd->bi_intfreq, 1);
Stefan Roese13628882007-12-13 14:52:53 +0100130 do_fixup_by_path_u32(blob, "/plb", "clock-frequency", sys_info.freqPLB, 1);
131 do_fixup_by_path_u32(blob, "/plb/opb", "clock-frequency", sys_info.freqOPB, 1);
Markus Brunnereea5a742008-04-28 08:47:47 +0200132
133 if (fdt_path_offset(blob, "/plb/opb/ebc") >= 0)
134 do_fixup_by_path_u32(blob, "/plb/opb/ebc", "clock-frequency",
135 sys_info.freqEBC, 1);
136 else
137 do_fixup_by_path_u32(blob, "/plb/ebc", "clock-frequency",
138 sys_info.freqEBC, 1);
139
Stefan Roese13628882007-12-13 14:52:53 +0100140 fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize);
Stefan Roese4f14ed62007-10-05 17:07:50 +0200141
142 /*
Matthias Fuchsb129eff2009-02-03 22:13:16 +0100143 * Fixup all UART clocks for CPU internal UARTs
144 * (only these UARTs are definitely clocked by gd->uart_clk)
145 *
146 * These UARTs are direct childs of /plb/opb. This code
147 * does not touch any UARTs that are connected to the ebc.
Stefan Roese4f14ed62007-10-05 17:07:50 +0200148 */
Matthias Fuchsb129eff2009-02-03 22:13:16 +0100149 off = fdt_path_offset(blob, "/plb/opb");
150 while ((off = fdt_next_node(blob, off, &ndepth)) >= 0) {
151 /*
152 * process all sub nodes and stop when we are back
153 * at the starting depth
154 */
155 if (ndepth <= 0)
156 break;
157
158 /* only update direct childs */
159 if ((ndepth == 1) &&
160 (fdt_node_check_compatible(blob, off, "ns16550") == 0))
161 fdt_setprop(blob, off,
162 "clock-frequency",
163 (void*)&(gd->uart_clk), 4);
164 }
Stefan Roese4f14ed62007-10-05 17:07:50 +0200165
Stefan Roese4f14ed62007-10-05 17:07:50 +0200166 /*
Stefan Roese871e6ce2007-12-14 08:41:29 +0100167 * Fixup all ethernet nodes
168 * Note: aliases in the dts are required for this
Stefan Roese4f14ed62007-10-05 17:07:50 +0200169 */
Kumar Galaba37aa02008-08-19 15:41:18 -0500170 fdt_fixup_ethernet(blob);
Stefan Roese24bfedb2008-04-22 12:20:32 +0200171
172 /*
173 * Fixup all available PCIe nodes by setting the device_type property
174 */
175 fdt_pcie_setup(blob);
Stefan Roese4f14ed62007-10-05 17:07:50 +0200176}
Stefan Roesecb5d88b2008-05-08 11:01:09 +0200177#endif /* CONFIG_OF_LIBFDT && CONFIG_OF_BOARD_SETUP */