2 * (C) Copyright 2007-2008
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,
27 #include <asm/cache.h>
28 #include <asm/ppc4xx.h>
30 #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
32 #include <fdt_support.h>
33 #include <asm/4xx_pcie.h>
35 DECLARE_GLOBAL_DATA_PTR;
37 void __ft_board_setup(void *blob, bd_t *bd)
42 u32 ranges[EBC_NUM_BANKS * 4];
44 char ebc_path[] = "/plb/opb/ebc";
46 ft_cpu_setup(blob, bd);
49 * Read 4xx EBC bus bridge registers to get mappings of the
50 * peripheral banks into the OPB/PLB address space
52 for (i = 0; i < EBC_NUM_BANKS; i++) {
53 mtdcr(EBC0_CFGADDR, EBC_BXCR(i));
54 bxcr = mfdcr(EBC0_CFGDATA);
56 if ((bxcr & EBC_BXCR_BU_MASK) != EBC_BXCR_BU_NONE) {
59 *p++ = bxcr & EBC_BXCR_BAS_MASK;
60 *p++ = EBC_BXCR_BANK_SIZE(bxcr);
65 #ifdef CONFIG_FDT_FIXUP_NOR_FLASH_SIZE
66 /* Update reg property in all nor flash nodes too */
67 fdt_fixup_nor_flash_size(blob);
70 /* Some 405 PPC's have EBC as direct PLB child in the dts */
71 if (fdt_path_offset(blob, ebc_path) < 0)
72 strcpy(ebc_path, "/plb/ebc");
73 rc = fdt_find_and_setprop(blob, ebc_path, "ranges", ranges,
74 (p - ranges) * sizeof(u32), 1);
76 printf("Unable to update property EBC mappings, err=%s\n",
80 void ft_board_setup(void *blob, bd_t *bd) __attribute__((weak, alias("__ft_board_setup")));
83 * Fixup all PCIe nodes by setting the device_type property
84 * to "pci-endpoint" instead is "pci" for endpoint ports.
85 * This property will get checked later by the Linux driver
86 * to properly configure the PCIe port in Linux (again).
88 void fdt_pcie_setup(void *blob)
90 const char *compat = "ibm,plb-pciex";
91 const char *prop = "device_type";
92 const char *prop_val = "pci-endpoint";
97 /* Search first PCIe node */
98 no = fdt_node_offset_by_compatible(blob, -1, compat);
99 while (no != -FDT_ERR_NOTFOUND) {
100 port = fdt_getprop(blob, no, "port", NULL);
102 printf("WARNING: could not find port property\n");
104 if (is_end_point(*port)) {
105 rc = fdt_setprop(blob, no, prop, prop_val,
106 strlen(prop_val) + 1);
108 printf("WARNING: could not set %s for %s: %s.\n",
109 prop, compat, fdt_strerror(rc));
113 /* Jump to next PCIe node */
114 no = fdt_node_offset_by_compatible(blob, no, compat);
118 void ft_cpu_setup(void *blob, bd_t *bd)
123 get_sys_info(&sys_info);
125 do_fixup_by_prop_u32(blob, "device_type", "cpu", 4, "timebase-frequency",
127 do_fixup_by_prop_u32(blob, "device_type", "cpu", 4, "clock-frequency",
129 do_fixup_by_path_u32(blob, "/plb", "clock-frequency", sys_info.freqPLB, 1);
130 do_fixup_by_path_u32(blob, "/plb/opb", "clock-frequency", sys_info.freqOPB, 1);
132 if (fdt_path_offset(blob, "/plb/opb/ebc") >= 0)
133 do_fixup_by_path_u32(blob, "/plb/opb/ebc", "clock-frequency",
134 sys_info.freqEBC, 1);
136 do_fixup_by_path_u32(blob, "/plb/ebc", "clock-frequency",
137 sys_info.freqEBC, 1);
139 fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize);
142 * Fixup all UART clocks for CPU internal UARTs
143 * (only these UARTs are definitely clocked by gd->arch.uart_clk)
145 * These UARTs are direct childs of /plb/opb. This code
146 * does not touch any UARTs that are connected to the ebc.
148 off = fdt_path_offset(blob, "/plb/opb");
149 while ((off = fdt_next_node(blob, off, &ndepth)) >= 0) {
151 * process all sub nodes and stop when we are back
152 * at the starting depth
157 /* only update direct childs */
159 (fdt_node_check_compatible(blob, off, "ns16550") == 0))
160 fdt_setprop(blob, off,
162 (void *)&gd->arch.uart_clk, 4);
166 * Fixup all ethernet nodes
167 * Note: aliases in the dts are required for this
169 fdt_fixup_ethernet(blob);
172 * Fixup all available PCIe nodes by setting the device_type property
174 fdt_pcie_setup(blob);
176 #endif /* CONFIG_OF_LIBFDT && CONFIG_OF_BOARD_SETUP */