blob: c55e1cfbb72f94da0838fac7f341ba19d51b3a8c [file] [log] [blame]
Stefan Roese46669902007-10-05 17:07:50 +02001/*
Stefan Roese1b254362008-05-08 11:01:09 +02002 * (C) Copyright 2007-2008
Stefan Roese46669902007-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 Roese46669902007-10-05 17:07:50 +020024#include <common.h>
25#include <watchdog.h>
26#include <command.h>
27#include <asm/cache.h>
28#include <ppc4xx.h>
29
Stefan Roese1b254362008-05-08 11:01:09 +020030#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
Stefan Roese46669902007-10-05 17:07:50 +020031#include <libfdt.h>
32#include <libfdt_env.h>
Stefan Roesefbcee002007-12-13 14:52:53 +010033#include <fdt_support.h>
Stefan Roese1e01fd22008-04-22 12:20:32 +020034#include <asm/4xx_pcie.h>
Stefan Roese46669902007-10-05 17:07:50 +020035
Stefan Roese19b77f42007-10-23 11:31:05 +020036DECLARE_GLOBAL_DATA_PTR;
37
Stefan Roese1b254362008-05-08 11:01:09 +020038void __ft_board_setup(void *blob, bd_t *bd)
39{
Stefan Roese1b254362008-05-08 11:01:09 +020040 int rc;
Stefan Roese1c97e0c2008-10-13 10:45:14 +020041 int i;
42 u32 bxcr;
43 u32 ranges[EBC_NUM_BANKS * 4];
44 u32 *p = ranges;
45 char *ebc_path = "/plb/opb/ebc";
Stefan Roese1b254362008-05-08 11:01:09 +020046
47 ft_cpu_setup(blob, bd);
48
Stefan Roese1c97e0c2008-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++) {
54 mtdcr(ebccfga, EBC_BXCR(i));
55 bxcr = mfdcr(ebccfgd);
56
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 Roeseff459fb2008-07-10 13:52:44 +020063 }
Stefan Roese1c97e0c2008-10-13 10:45:14 +020064
65 /* Some 405 PPC's have EBC as direct PLB child in the dts */
66 if (fdt_path_offset(blob, "/plb/opb/ebc") < 0)
67 strcpy(ebc_path, "/plb/ebc");
68 rc = fdt_find_and_setprop(blob, ebc_path, "ranges", ranges,
69 (p - ranges) * sizeof(u32), 1);
70 if (rc) {
71 printf("Unable to update property EBC mappings, err=%s\n",
Stefan Roese1b254362008-05-08 11:01:09 +020072 fdt_strerror(rc));
Stefan Roese1c97e0c2008-10-13 10:45:14 +020073 }
Stefan Roese1b254362008-05-08 11:01:09 +020074}
75void ft_board_setup(void *blob, bd_t *bd) __attribute__((weak, alias("__ft_board_setup")));
76
Stefan Roese1e01fd22008-04-22 12:20:32 +020077/*
78 * Fixup all PCIe nodes by setting the device_type property
79 * to "pci-endpoint" instead is "pci" for endpoint ports.
80 * This property will get checked later by the Linux driver
81 * to properly configure the PCIe port in Linux (again).
82 */
83void fdt_pcie_setup(void *blob)
84{
85 const char *compat = "ibm,plb-pciex";
86 const char *prop = "device_type";
87 const char *prop_val = "pci-endpoint";
88 const u32 *port;
89 int no;
90 int rc;
91
92 /* Search first PCIe node */
93 no = fdt_node_offset_by_compatible(blob, -1, compat);
94 while (no != -FDT_ERR_NOTFOUND) {
95 port = fdt_getprop(blob, no, "port", NULL);
96 if (port == NULL) {
97 printf("WARNING: could not find port property\n");
98 } else {
99 if (is_end_point(*port)) {
100 rc = fdt_setprop(blob, no, prop, prop_val,
101 strlen(prop_val) + 1);
102 if (rc < 0)
103 printf("WARNING: could not set %s for %s: %s.\n",
104 prop, compat, fdt_strerror(rc));
105 }
106 }
107
108 /* Jump to next PCIe node */
109 no = fdt_node_offset_by_compatible(blob, no, compat);
110 }
111}
112
Stefan Roese46669902007-10-05 17:07:50 +0200113void ft_cpu_setup(void *blob, bd_t *bd)
114{
Stefan Roese46669902007-10-05 17:07:50 +0200115 sys_info_t sys_info;
Stefan Roese46669902007-10-05 17:07:50 +0200116
Stefan Roesefbcee002007-12-13 14:52:53 +0100117 get_sys_info(&sys_info);
Stefan Roese46669902007-10-05 17:07:50 +0200118
Stefan Roese16dbccc2007-12-18 08:44:51 +0100119 do_fixup_by_prop_u32(blob, "device_type", "cpu", 4, "timebase-frequency",
120 bd->bi_intfreq, 1);
121 do_fixup_by_prop_u32(blob, "device_type", "cpu", 4, "clock-frequency",
122 bd->bi_intfreq, 1);
Stefan Roesefbcee002007-12-13 14:52:53 +0100123 do_fixup_by_path_u32(blob, "/plb", "clock-frequency", sys_info.freqPLB, 1);
124 do_fixup_by_path_u32(blob, "/plb/opb", "clock-frequency", sys_info.freqOPB, 1);
Markus Brunner9c4ebb02008-04-28 08:47:47 +0200125
126 if (fdt_path_offset(blob, "/plb/opb/ebc") >= 0)
127 do_fixup_by_path_u32(blob, "/plb/opb/ebc", "clock-frequency",
128 sys_info.freqEBC, 1);
129 else
130 do_fixup_by_path_u32(blob, "/plb/ebc", "clock-frequency",
131 sys_info.freqEBC, 1);
132
Stefan Roesefbcee002007-12-13 14:52:53 +0100133 fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize);
Stefan Roese46669902007-10-05 17:07:50 +0200134
135 /*
136 * Setup all baudrates for the UARTs
137 */
Stefan Roesefbcee002007-12-13 14:52:53 +0100138 do_fixup_by_compat_u32(blob, "ns16550", "clock-frequency", gd->uart_clk, 1);
Stefan Roese46669902007-10-05 17:07:50 +0200139
140 /*
Stefan Roeseac9f2182007-12-14 08:41:29 +0100141 * Fixup all ethernet nodes
142 * Note: aliases in the dts are required for this
Stefan Roese46669902007-10-05 17:07:50 +0200143 */
Kumar Galafabda922008-08-19 15:41:18 -0500144 fdt_fixup_ethernet(blob);
Stefan Roese1e01fd22008-04-22 12:20:32 +0200145
146 /*
147 * Fixup all available PCIe nodes by setting the device_type property
148 */
149 fdt_pcie_setup(blob);
Stefan Roese46669902007-10-05 17:07:50 +0200150}
Stefan Roese1b254362008-05-08 11:01:09 +0200151#endif /* CONFIG_OF_LIBFDT && CONFIG_OF_BOARD_SETUP */