Stefan Roese | 4f14ed6 | 2007-10-05 17:07:50 +0200 | [diff] [blame] | 1 | /* |
Stefan Roese | cb5d88b | 2008-05-08 11:01:09 +0200 | [diff] [blame] | 2 | * (C) Copyright 2007-2008 |
Stefan Roese | 4f14ed6 | 2007-10-05 17:07:50 +0200 | [diff] [blame] | 3 | * 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 Roese | 4f14ed6 | 2007-10-05 17:07:50 +0200 | [diff] [blame] | 24 | #include <common.h> |
| 25 | #include <watchdog.h> |
| 26 | #include <command.h> |
| 27 | #include <asm/cache.h> |
Stefan Roese | b36df56 | 2010-09-09 19:18:00 +0200 | [diff] [blame] | 28 | #include <asm/ppc4xx.h> |
Stefan Roese | 4f14ed6 | 2007-10-05 17:07:50 +0200 | [diff] [blame] | 29 | |
Stefan Roese | cb5d88b | 2008-05-08 11:01:09 +0200 | [diff] [blame] | 30 | #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) |
Stefan Roese | 4f14ed6 | 2007-10-05 17:07:50 +0200 | [diff] [blame] | 31 | #include <libfdt.h> |
Stefan Roese | 1362888 | 2007-12-13 14:52:53 +0100 | [diff] [blame] | 32 | #include <fdt_support.h> |
Stefan Roese | 24bfedb | 2008-04-22 12:20:32 +0200 | [diff] [blame] | 33 | #include <asm/4xx_pcie.h> |
Stefan Roese | 4f14ed6 | 2007-10-05 17:07:50 +0200 | [diff] [blame] | 34 | |
Stefan Roese | f10493c | 2007-10-23 11:31:05 +0200 | [diff] [blame] | 35 | DECLARE_GLOBAL_DATA_PTR; |
| 36 | |
Stefan Roese | cb5d88b | 2008-05-08 11:01:09 +0200 | [diff] [blame] | 37 | void __ft_board_setup(void *blob, bd_t *bd) |
| 38 | { |
Stefan Roese | cb5d88b | 2008-05-08 11:01:09 +0200 | [diff] [blame] | 39 | int rc; |
Stefan Roese | 43cbce6 | 2008-10-13 10:45:14 +0200 | [diff] [blame] | 40 | int i; |
| 41 | u32 bxcr; |
| 42 | u32 ranges[EBC_NUM_BANKS * 4]; |
| 43 | u32 *p = ranges; |
Wolfgang Denk | 76706cb | 2009-10-20 23:12:13 +0200 | [diff] [blame] | 44 | char ebc_path[] = "/plb/opb/ebc"; |
Stefan Roese | cb5d88b | 2008-05-08 11:01:09 +0200 | [diff] [blame] | 45 | |
| 46 | ft_cpu_setup(blob, bd); |
| 47 | |
Stefan Roese | 43cbce6 | 2008-10-13 10:45:14 +0200 | [diff] [blame] | 48 | /* |
| 49 | * Read 4xx EBC bus bridge registers to get mappings of the |
| 50 | * peripheral banks into the OPB/PLB address space |
| 51 | */ |
| 52 | for (i = 0; i < EBC_NUM_BANKS; i++) { |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 53 | mtdcr(EBC0_CFGADDR, EBC_BXCR(i)); |
| 54 | bxcr = mfdcr(EBC0_CFGDATA); |
Stefan Roese | 43cbce6 | 2008-10-13 10:45:14 +0200 | [diff] [blame] | 55 | |
| 56 | if ((bxcr & EBC_BXCR_BU_MASK) != EBC_BXCR_BU_NONE) { |
| 57 | *p++ = i; |
| 58 | *p++ = 0; |
| 59 | *p++ = bxcr & EBC_BXCR_BAS_MASK; |
| 60 | *p++ = EBC_BXCR_BANK_SIZE(bxcr); |
| 61 | } |
Stefan Roese | e321801 | 2008-07-10 13:52:44 +0200 | [diff] [blame] | 62 | } |
Stefan Roese | 43cbce6 | 2008-10-13 10:45:14 +0200 | [diff] [blame] | 63 | |
Stefan Roese | 8a805df | 2010-09-16 14:01:53 +0200 | [diff] [blame] | 64 | |
| 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); |
| 68 | #endif |
| 69 | |
Stefan Roese | 43cbce6 | 2008-10-13 10:45:14 +0200 | [diff] [blame] | 70 | /* Some 405 PPC's have EBC as direct PLB child in the dts */ |
Stefan Roese | 92b8964 | 2009-10-16 10:01:09 +0200 | [diff] [blame] | 71 | if (fdt_path_offset(blob, ebc_path) < 0) |
Stefan Roese | 43cbce6 | 2008-10-13 10:45:14 +0200 | [diff] [blame] | 72 | strcpy(ebc_path, "/plb/ebc"); |
| 73 | rc = fdt_find_and_setprop(blob, ebc_path, "ranges", ranges, |
| 74 | (p - ranges) * sizeof(u32), 1); |
| 75 | if (rc) { |
| 76 | printf("Unable to update property EBC mappings, err=%s\n", |
Stefan Roese | cb5d88b | 2008-05-08 11:01:09 +0200 | [diff] [blame] | 77 | fdt_strerror(rc)); |
Stefan Roese | 43cbce6 | 2008-10-13 10:45:14 +0200 | [diff] [blame] | 78 | } |
Stefan Roese | cb5d88b | 2008-05-08 11:01:09 +0200 | [diff] [blame] | 79 | } |
| 80 | void ft_board_setup(void *blob, bd_t *bd) __attribute__((weak, alias("__ft_board_setup"))); |
| 81 | |
Stefan Roese | 24bfedb | 2008-04-22 12:20:32 +0200 | [diff] [blame] | 82 | /* |
| 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). |
| 87 | */ |
| 88 | void fdt_pcie_setup(void *blob) |
| 89 | { |
| 90 | const char *compat = "ibm,plb-pciex"; |
| 91 | const char *prop = "device_type"; |
| 92 | const char *prop_val = "pci-endpoint"; |
| 93 | const u32 *port; |
| 94 | int no; |
| 95 | int rc; |
| 96 | |
| 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); |
| 101 | if (port == NULL) { |
| 102 | printf("WARNING: could not find port property\n"); |
| 103 | } else { |
| 104 | if (is_end_point(*port)) { |
| 105 | rc = fdt_setprop(blob, no, prop, prop_val, |
| 106 | strlen(prop_val) + 1); |
| 107 | if (rc < 0) |
| 108 | printf("WARNING: could not set %s for %s: %s.\n", |
| 109 | prop, compat, fdt_strerror(rc)); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | /* Jump to next PCIe node */ |
| 114 | no = fdt_node_offset_by_compatible(blob, no, compat); |
| 115 | } |
| 116 | } |
| 117 | |
Stefan Roese | 4f14ed6 | 2007-10-05 17:07:50 +0200 | [diff] [blame] | 118 | void ft_cpu_setup(void *blob, bd_t *bd) |
| 119 | { |
Stefan Roese | 4f14ed6 | 2007-10-05 17:07:50 +0200 | [diff] [blame] | 120 | sys_info_t sys_info; |
Matthias Fuchs | b129eff | 2009-02-03 22:13:16 +0100 | [diff] [blame] | 121 | int off, ndepth = 0; |
Stefan Roese | 4f14ed6 | 2007-10-05 17:07:50 +0200 | [diff] [blame] | 122 | |
Stefan Roese | 1362888 | 2007-12-13 14:52:53 +0100 | [diff] [blame] | 123 | get_sys_info(&sys_info); |
Stefan Roese | 4f14ed6 | 2007-10-05 17:07:50 +0200 | [diff] [blame] | 124 | |
Stefan Roese | 328a340 | 2007-12-18 08:44:51 +0100 | [diff] [blame] | 125 | do_fixup_by_prop_u32(blob, "device_type", "cpu", 4, "timebase-frequency", |
| 126 | bd->bi_intfreq, 1); |
| 127 | do_fixup_by_prop_u32(blob, "device_type", "cpu", 4, "clock-frequency", |
| 128 | bd->bi_intfreq, 1); |
Stefan Roese | 1362888 | 2007-12-13 14:52:53 +0100 | [diff] [blame] | 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); |
Markus Brunner | eea5a74 | 2008-04-28 08:47:47 +0200 | [diff] [blame] | 131 | |
| 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); |
| 135 | else |
| 136 | do_fixup_by_path_u32(blob, "/plb/ebc", "clock-frequency", |
| 137 | sys_info.freqEBC, 1); |
| 138 | |
Stefan Roese | 1362888 | 2007-12-13 14:52:53 +0100 | [diff] [blame] | 139 | fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize); |
Stefan Roese | 4f14ed6 | 2007-10-05 17:07:50 +0200 | [diff] [blame] | 140 | |
| 141 | /* |
Matthias Fuchs | b129eff | 2009-02-03 22:13:16 +0100 | [diff] [blame] | 142 | * Fixup all UART clocks for CPU internal UARTs |
Simon Glass | 3a1dc8f | 2012-12-13 20:48:59 +0000 | [diff] [blame] | 143 | * (only these UARTs are definitely clocked by gd->arch.uart_clk) |
Matthias Fuchs | b129eff | 2009-02-03 22:13:16 +0100 | [diff] [blame] | 144 | * |
| 145 | * These UARTs are direct childs of /plb/opb. This code |
| 146 | * does not touch any UARTs that are connected to the ebc. |
Stefan Roese | 4f14ed6 | 2007-10-05 17:07:50 +0200 | [diff] [blame] | 147 | */ |
Matthias Fuchs | b129eff | 2009-02-03 22:13:16 +0100 | [diff] [blame] | 148 | off = fdt_path_offset(blob, "/plb/opb"); |
| 149 | while ((off = fdt_next_node(blob, off, &ndepth)) >= 0) { |
| 150 | /* |
| 151 | * process all sub nodes and stop when we are back |
| 152 | * at the starting depth |
| 153 | */ |
| 154 | if (ndepth <= 0) |
| 155 | break; |
| 156 | |
| 157 | /* only update direct childs */ |
| 158 | if ((ndepth == 1) && |
| 159 | (fdt_node_check_compatible(blob, off, "ns16550") == 0)) |
| 160 | fdt_setprop(blob, off, |
| 161 | "clock-frequency", |
Simon Glass | 3a1dc8f | 2012-12-13 20:48:59 +0000 | [diff] [blame] | 162 | (void *)&gd->arch.uart_clk, 4); |
Matthias Fuchs | b129eff | 2009-02-03 22:13:16 +0100 | [diff] [blame] | 163 | } |
Stefan Roese | 4f14ed6 | 2007-10-05 17:07:50 +0200 | [diff] [blame] | 164 | |
Stefan Roese | 4f14ed6 | 2007-10-05 17:07:50 +0200 | [diff] [blame] | 165 | /* |
Stefan Roese | 871e6ce | 2007-12-14 08:41:29 +0100 | [diff] [blame] | 166 | * Fixup all ethernet nodes |
| 167 | * Note: aliases in the dts are required for this |
Stefan Roese | 4f14ed6 | 2007-10-05 17:07:50 +0200 | [diff] [blame] | 168 | */ |
Kumar Gala | ba37aa0 | 2008-08-19 15:41:18 -0500 | [diff] [blame] | 169 | fdt_fixup_ethernet(blob); |
Stefan Roese | 24bfedb | 2008-04-22 12:20:32 +0200 | [diff] [blame] | 170 | |
| 171 | /* |
| 172 | * Fixup all available PCIe nodes by setting the device_type property |
| 173 | */ |
| 174 | fdt_pcie_setup(blob); |
Stefan Roese | 4f14ed6 | 2007-10-05 17:07:50 +0200 | [diff] [blame] | 175 | } |
Stefan Roese | cb5d88b | 2008-05-08 11:01:09 +0200 | [diff] [blame] | 176 | #endif /* CONFIG_OF_LIBFDT && CONFIG_OF_BOARD_SETUP */ |