blob: eef9c5a17fa78cabf27de3d4d834cd9f335b592c [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 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Stefan Roese4f14ed62007-10-05 17:07:50 +02006 */
7
Stefan Roese4f14ed62007-10-05 17:07:50 +02008#include <common.h>
9#include <watchdog.h>
10#include <command.h>
11#include <asm/cache.h>
Stefan Roeseb36df562010-09-09 19:18:00 +020012#include <asm/ppc4xx.h>
Stefan Roese4f14ed62007-10-05 17:07:50 +020013
Stefan Roesecb5d88b2008-05-08 11:01:09 +020014#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
Stefan Roese4f14ed62007-10-05 17:07:50 +020015#include <libfdt.h>
Stefan Roese13628882007-12-13 14:52:53 +010016#include <fdt_support.h>
Stefan Roese24bfedb2008-04-22 12:20:32 +020017#include <asm/4xx_pcie.h>
Stefan Roese4f14ed62007-10-05 17:07:50 +020018
Stefan Roesef10493c2007-10-23 11:31:05 +020019DECLARE_GLOBAL_DATA_PTR;
20
Simon Glasse895a4b2014-10-23 18:58:47 -060021int __ft_board_setup(void *blob, bd_t *bd)
Stefan Roesecb5d88b2008-05-08 11:01:09 +020022{
Stefan Roesecb5d88b2008-05-08 11:01:09 +020023 int rc;
Stefan Roese43cbce62008-10-13 10:45:14 +020024 int i;
25 u32 bxcr;
26 u32 ranges[EBC_NUM_BANKS * 4];
27 u32 *p = ranges;
Wolfgang Denk76706cb2009-10-20 23:12:13 +020028 char ebc_path[] = "/plb/opb/ebc";
Stefan Roesecb5d88b2008-05-08 11:01:09 +020029
30 ft_cpu_setup(blob, bd);
31
Stefan Roese43cbce62008-10-13 10:45:14 +020032 /*
33 * Read 4xx EBC bus bridge registers to get mappings of the
34 * peripheral banks into the OPB/PLB address space
35 */
36 for (i = 0; i < EBC_NUM_BANKS; i++) {
Stefan Roesed1c3b272009-09-09 16:25:29 +020037 mtdcr(EBC0_CFGADDR, EBC_BXCR(i));
38 bxcr = mfdcr(EBC0_CFGDATA);
Stefan Roese43cbce62008-10-13 10:45:14 +020039
40 if ((bxcr & EBC_BXCR_BU_MASK) != EBC_BXCR_BU_NONE) {
41 *p++ = i;
42 *p++ = 0;
43 *p++ = bxcr & EBC_BXCR_BAS_MASK;
44 *p++ = EBC_BXCR_BANK_SIZE(bxcr);
45 }
Stefan Roesee3218012008-07-10 13:52:44 +020046 }
Stefan Roese43cbce62008-10-13 10:45:14 +020047
Stefan Roese8a805df2010-09-16 14:01:53 +020048
49#ifdef CONFIG_FDT_FIXUP_NOR_FLASH_SIZE
50 /* Update reg property in all nor flash nodes too */
51 fdt_fixup_nor_flash_size(blob);
52#endif
53
Stefan Roese43cbce62008-10-13 10:45:14 +020054 /* Some 405 PPC's have EBC as direct PLB child in the dts */
Stefan Roese92b89642009-10-16 10:01:09 +020055 if (fdt_path_offset(blob, ebc_path) < 0)
Stefan Roese43cbce62008-10-13 10:45:14 +020056 strcpy(ebc_path, "/plb/ebc");
57 rc = fdt_find_and_setprop(blob, ebc_path, "ranges", ranges,
58 (p - ranges) * sizeof(u32), 1);
59 if (rc) {
60 printf("Unable to update property EBC mappings, err=%s\n",
Stefan Roesecb5d88b2008-05-08 11:01:09 +020061 fdt_strerror(rc));
Stefan Roese43cbce62008-10-13 10:45:14 +020062 }
Simon Glasse895a4b2014-10-23 18:58:47 -060063
64 return 0;
Stefan Roesecb5d88b2008-05-08 11:01:09 +020065}
Simon Glasse895a4b2014-10-23 18:58:47 -060066int ft_board_setup(void *blob, bd_t *bd)
67 __attribute__((weak, alias("__ft_board_setup")));
Stefan Roesecb5d88b2008-05-08 11:01:09 +020068
Stefan Roese24bfedb2008-04-22 12:20:32 +020069/*
70 * Fixup all PCIe nodes by setting the device_type property
71 * to "pci-endpoint" instead is "pci" for endpoint ports.
72 * This property will get checked later by the Linux driver
73 * to properly configure the PCIe port in Linux (again).
74 */
75void fdt_pcie_setup(void *blob)
76{
77 const char *compat = "ibm,plb-pciex";
78 const char *prop = "device_type";
79 const char *prop_val = "pci-endpoint";
80 const u32 *port;
81 int no;
82 int rc;
83
84 /* Search first PCIe node */
85 no = fdt_node_offset_by_compatible(blob, -1, compat);
86 while (no != -FDT_ERR_NOTFOUND) {
87 port = fdt_getprop(blob, no, "port", NULL);
88 if (port == NULL) {
89 printf("WARNING: could not find port property\n");
90 } else {
91 if (is_end_point(*port)) {
92 rc = fdt_setprop(blob, no, prop, prop_val,
93 strlen(prop_val) + 1);
94 if (rc < 0)
95 printf("WARNING: could not set %s for %s: %s.\n",
96 prop, compat, fdt_strerror(rc));
97 }
98 }
99
100 /* Jump to next PCIe node */
101 no = fdt_node_offset_by_compatible(blob, no, compat);
102 }
103}
104
Stefan Roese4f14ed62007-10-05 17:07:50 +0200105void ft_cpu_setup(void *blob, bd_t *bd)
106{
Stefan Roese4f14ed62007-10-05 17:07:50 +0200107 sys_info_t sys_info;
Matthias Fuchsb129eff2009-02-03 22:13:16 +0100108 int off, ndepth = 0;
Stefan Roese4f14ed62007-10-05 17:07:50 +0200109
Stefan Roese13628882007-12-13 14:52:53 +0100110 get_sys_info(&sys_info);
Stefan Roese4f14ed62007-10-05 17:07:50 +0200111
Stefan Roese328a3402007-12-18 08:44:51 +0100112 do_fixup_by_prop_u32(blob, "device_type", "cpu", 4, "timebase-frequency",
113 bd->bi_intfreq, 1);
114 do_fixup_by_prop_u32(blob, "device_type", "cpu", 4, "clock-frequency",
115 bd->bi_intfreq, 1);
Stefan Roese13628882007-12-13 14:52:53 +0100116 do_fixup_by_path_u32(blob, "/plb", "clock-frequency", sys_info.freqPLB, 1);
117 do_fixup_by_path_u32(blob, "/plb/opb", "clock-frequency", sys_info.freqOPB, 1);
Markus Brunnereea5a742008-04-28 08:47:47 +0200118
119 if (fdt_path_offset(blob, "/plb/opb/ebc") >= 0)
120 do_fixup_by_path_u32(blob, "/plb/opb/ebc", "clock-frequency",
121 sys_info.freqEBC, 1);
122 else
123 do_fixup_by_path_u32(blob, "/plb/ebc", "clock-frequency",
124 sys_info.freqEBC, 1);
125
Stefan Roese13628882007-12-13 14:52:53 +0100126 fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize);
Stefan Roese4f14ed62007-10-05 17:07:50 +0200127
128 /*
Matthias Fuchsb129eff2009-02-03 22:13:16 +0100129 * Fixup all UART clocks for CPU internal UARTs
Simon Glass3a1dc8f2012-12-13 20:48:59 +0000130 * (only these UARTs are definitely clocked by gd->arch.uart_clk)
Matthias Fuchsb129eff2009-02-03 22:13:16 +0100131 *
132 * These UARTs are direct childs of /plb/opb. This code
133 * does not touch any UARTs that are connected to the ebc.
Stefan Roese4f14ed62007-10-05 17:07:50 +0200134 */
Matthias Fuchsb129eff2009-02-03 22:13:16 +0100135 off = fdt_path_offset(blob, "/plb/opb");
136 while ((off = fdt_next_node(blob, off, &ndepth)) >= 0) {
137 /*
138 * process all sub nodes and stop when we are back
139 * at the starting depth
140 */
141 if (ndepth <= 0)
142 break;
143
144 /* only update direct childs */
145 if ((ndepth == 1) &&
146 (fdt_node_check_compatible(blob, off, "ns16550") == 0))
147 fdt_setprop(blob, off,
148 "clock-frequency",
Simon Glass3a1dc8f2012-12-13 20:48:59 +0000149 (void *)&gd->arch.uart_clk, 4);
Matthias Fuchsb129eff2009-02-03 22:13:16 +0100150 }
Stefan Roese4f14ed62007-10-05 17:07:50 +0200151
Stefan Roese4f14ed62007-10-05 17:07:50 +0200152 /*
Stefan Roese871e6ce2007-12-14 08:41:29 +0100153 * Fixup all ethernet nodes
154 * Note: aliases in the dts are required for this
Stefan Roese4f14ed62007-10-05 17:07:50 +0200155 */
Kumar Galaba37aa02008-08-19 15:41:18 -0500156 fdt_fixup_ethernet(blob);
Stefan Roese24bfedb2008-04-22 12:20:32 +0200157
158 /*
159 * Fixup all available PCIe nodes by setting the device_type property
160 */
161 fdt_pcie_setup(blob);
Stefan Roese4f14ed62007-10-05 17:07:50 +0200162}
Stefan Roesecb5d88b2008-05-08 11:01:09 +0200163#endif /* CONFIG_OF_LIBFDT && CONFIG_OF_BOARD_SETUP */