blob: ccc73d5d64e6d6de50bfe98d9dc56cd759252ad6 [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>
28#include <ppc4xx.h>
29
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{
40 u32 val[4];
41 int rc;
42
43 ft_cpu_setup(blob, bd);
44
45 /* Fixup NOR mapping */
46 val[0] = 0; /* chip select number */
47 val[1] = 0; /* always 0 */
48 val[2] = gd->bd->bi_flashstart;
49 val[3] = gd->bd->bi_flashsize;
50 rc = fdt_find_and_setprop(blob, "/plb/opb/ebc", "ranges",
51 val, sizeof(val), 1);
52 if (rc)
53 printf("Unable to update property NOR mapping, err=%s\n",
54 fdt_strerror(rc));
55}
56void ft_board_setup(void *blob, bd_t *bd) __attribute__((weak, alias("__ft_board_setup")));
57
Stefan Roese24bfedb2008-04-22 12:20:32 +020058/*
59 * Fixup all PCIe nodes by setting the device_type property
60 * to "pci-endpoint" instead is "pci" for endpoint ports.
61 * This property will get checked later by the Linux driver
62 * to properly configure the PCIe port in Linux (again).
63 */
64void fdt_pcie_setup(void *blob)
65{
66 const char *compat = "ibm,plb-pciex";
67 const char *prop = "device_type";
68 const char *prop_val = "pci-endpoint";
69 const u32 *port;
70 int no;
71 int rc;
72
73 /* Search first PCIe node */
74 no = fdt_node_offset_by_compatible(blob, -1, compat);
75 while (no != -FDT_ERR_NOTFOUND) {
76 port = fdt_getprop(blob, no, "port", NULL);
77 if (port == NULL) {
78 printf("WARNING: could not find port property\n");
79 } else {
80 if (is_end_point(*port)) {
81 rc = fdt_setprop(blob, no, prop, prop_val,
82 strlen(prop_val) + 1);
83 if (rc < 0)
84 printf("WARNING: could not set %s for %s: %s.\n",
85 prop, compat, fdt_strerror(rc));
86 }
87 }
88
89 /* Jump to next PCIe node */
90 no = fdt_node_offset_by_compatible(blob, no, compat);
91 }
92}
93
Stefan Roese4f14ed62007-10-05 17:07:50 +020094void ft_cpu_setup(void *blob, bd_t *bd)
95{
Stefan Roese4f14ed62007-10-05 17:07:50 +020096 sys_info_t sys_info;
Stefan Roese4f14ed62007-10-05 17:07:50 +020097
Stefan Roese13628882007-12-13 14:52:53 +010098 get_sys_info(&sys_info);
Stefan Roese4f14ed62007-10-05 17:07:50 +020099
Stefan Roese328a3402007-12-18 08:44:51 +0100100 do_fixup_by_prop_u32(blob, "device_type", "cpu", 4, "timebase-frequency",
101 bd->bi_intfreq, 1);
102 do_fixup_by_prop_u32(blob, "device_type", "cpu", 4, "clock-frequency",
103 bd->bi_intfreq, 1);
Stefan Roese13628882007-12-13 14:52:53 +0100104 do_fixup_by_path_u32(blob, "/plb", "clock-frequency", sys_info.freqPLB, 1);
105 do_fixup_by_path_u32(blob, "/plb/opb", "clock-frequency", sys_info.freqOPB, 1);
Markus Brunnereea5a742008-04-28 08:47:47 +0200106
107 if (fdt_path_offset(blob, "/plb/opb/ebc") >= 0)
108 do_fixup_by_path_u32(blob, "/plb/opb/ebc", "clock-frequency",
109 sys_info.freqEBC, 1);
110 else
111 do_fixup_by_path_u32(blob, "/plb/ebc", "clock-frequency",
112 sys_info.freqEBC, 1);
113
Stefan Roese13628882007-12-13 14:52:53 +0100114 fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize);
Stefan Roese4f14ed62007-10-05 17:07:50 +0200115
116 /*
117 * Setup all baudrates for the UARTs
118 */
Stefan Roese13628882007-12-13 14:52:53 +0100119 do_fixup_by_compat_u32(blob, "ns16550", "clock-frequency", gd->uart_clk, 1);
Stefan Roese4f14ed62007-10-05 17:07:50 +0200120
Stefan Roese4f14ed62007-10-05 17:07:50 +0200121 /*
Stefan Roese871e6ce2007-12-14 08:41:29 +0100122 * Fixup all ethernet nodes
123 * Note: aliases in the dts are required for this
Stefan Roese4f14ed62007-10-05 17:07:50 +0200124 */
Stefan Roese13628882007-12-13 14:52:53 +0100125 fdt_fixup_ethernet(blob, bd);
Stefan Roese24bfedb2008-04-22 12:20:32 +0200126
127 /*
128 * Fixup all available PCIe nodes by setting the device_type property
129 */
130 fdt_pcie_setup(blob);
Stefan Roese4f14ed62007-10-05 17:07:50 +0200131}
Stefan Roesecb5d88b2008-05-08 11:01:09 +0200132#endif /* CONFIG_OF_LIBFDT && CONFIG_OF_BOARD_SETUP */