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 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Stefan Roese | 4f14ed6 | 2007-10-05 17:07:50 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
Stefan Roese | 4f14ed6 | 2007-10-05 17:07:50 +0200 | [diff] [blame] | 8 | #include <common.h> |
| 9 | #include <watchdog.h> |
| 10 | #include <command.h> |
| 11 | #include <asm/cache.h> |
Stefan Roese | b36df56 | 2010-09-09 19:18:00 +0200 | [diff] [blame] | 12 | #include <asm/ppc4xx.h> |
Stefan Roese | 4f14ed6 | 2007-10-05 17:07:50 +0200 | [diff] [blame] | 13 | |
Stefan Roese | cb5d88b | 2008-05-08 11:01:09 +0200 | [diff] [blame] | 14 | #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) |
Stefan Roese | 4f14ed6 | 2007-10-05 17:07:50 +0200 | [diff] [blame] | 15 | #include <libfdt.h> |
Stefan Roese | 1362888 | 2007-12-13 14:52:53 +0100 | [diff] [blame] | 16 | #include <fdt_support.h> |
Stefan Roese | 24bfedb | 2008-04-22 12:20:32 +0200 | [diff] [blame] | 17 | #include <asm/4xx_pcie.h> |
Stefan Roese | 4f14ed6 | 2007-10-05 17:07:50 +0200 | [diff] [blame] | 18 | |
Stefan Roese | f10493c | 2007-10-23 11:31:05 +0200 | [diff] [blame] | 19 | DECLARE_GLOBAL_DATA_PTR; |
| 20 | |
Stefan Roese | cb5d88b | 2008-05-08 11:01:09 +0200 | [diff] [blame] | 21 | void __ft_board_setup(void *blob, bd_t *bd) |
| 22 | { |
Stefan Roese | cb5d88b | 2008-05-08 11:01:09 +0200 | [diff] [blame] | 23 | int rc; |
Stefan Roese | 43cbce6 | 2008-10-13 10:45:14 +0200 | [diff] [blame] | 24 | int i; |
| 25 | u32 bxcr; |
| 26 | u32 ranges[EBC_NUM_BANKS * 4]; |
| 27 | u32 *p = ranges; |
Wolfgang Denk | 76706cb | 2009-10-20 23:12:13 +0200 | [diff] [blame] | 28 | char ebc_path[] = "/plb/opb/ebc"; |
Stefan Roese | cb5d88b | 2008-05-08 11:01:09 +0200 | [diff] [blame] | 29 | |
| 30 | ft_cpu_setup(blob, bd); |
| 31 | |
Stefan Roese | 43cbce6 | 2008-10-13 10:45:14 +0200 | [diff] [blame] | 32 | /* |
| 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 Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 37 | mtdcr(EBC0_CFGADDR, EBC_BXCR(i)); |
| 38 | bxcr = mfdcr(EBC0_CFGDATA); |
Stefan Roese | 43cbce6 | 2008-10-13 10:45:14 +0200 | [diff] [blame] | 39 | |
| 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 Roese | e321801 | 2008-07-10 13:52:44 +0200 | [diff] [blame] | 46 | } |
Stefan Roese | 43cbce6 | 2008-10-13 10:45:14 +0200 | [diff] [blame] | 47 | |
Stefan Roese | 8a805df | 2010-09-16 14:01:53 +0200 | [diff] [blame] | 48 | |
| 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 Roese | 43cbce6 | 2008-10-13 10:45:14 +0200 | [diff] [blame] | 54 | /* 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] | 55 | if (fdt_path_offset(blob, ebc_path) < 0) |
Stefan Roese | 43cbce6 | 2008-10-13 10:45:14 +0200 | [diff] [blame] | 56 | 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 Roese | cb5d88b | 2008-05-08 11:01:09 +0200 | [diff] [blame] | 61 | fdt_strerror(rc)); |
Stefan Roese | 43cbce6 | 2008-10-13 10:45:14 +0200 | [diff] [blame] | 62 | } |
Stefan Roese | cb5d88b | 2008-05-08 11:01:09 +0200 | [diff] [blame] | 63 | } |
| 64 | void ft_board_setup(void *blob, bd_t *bd) __attribute__((weak, alias("__ft_board_setup"))); |
| 65 | |
Stefan Roese | 24bfedb | 2008-04-22 12:20:32 +0200 | [diff] [blame] | 66 | /* |
| 67 | * Fixup all PCIe nodes by setting the device_type property |
| 68 | * to "pci-endpoint" instead is "pci" for endpoint ports. |
| 69 | * This property will get checked later by the Linux driver |
| 70 | * to properly configure the PCIe port in Linux (again). |
| 71 | */ |
| 72 | void fdt_pcie_setup(void *blob) |
| 73 | { |
| 74 | const char *compat = "ibm,plb-pciex"; |
| 75 | const char *prop = "device_type"; |
| 76 | const char *prop_val = "pci-endpoint"; |
| 77 | const u32 *port; |
| 78 | int no; |
| 79 | int rc; |
| 80 | |
| 81 | /* Search first PCIe node */ |
| 82 | no = fdt_node_offset_by_compatible(blob, -1, compat); |
| 83 | while (no != -FDT_ERR_NOTFOUND) { |
| 84 | port = fdt_getprop(blob, no, "port", NULL); |
| 85 | if (port == NULL) { |
| 86 | printf("WARNING: could not find port property\n"); |
| 87 | } else { |
| 88 | if (is_end_point(*port)) { |
| 89 | rc = fdt_setprop(blob, no, prop, prop_val, |
| 90 | strlen(prop_val) + 1); |
| 91 | if (rc < 0) |
| 92 | printf("WARNING: could not set %s for %s: %s.\n", |
| 93 | prop, compat, fdt_strerror(rc)); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | /* Jump to next PCIe node */ |
| 98 | no = fdt_node_offset_by_compatible(blob, no, compat); |
| 99 | } |
| 100 | } |
| 101 | |
Stefan Roese | 4f14ed6 | 2007-10-05 17:07:50 +0200 | [diff] [blame] | 102 | void ft_cpu_setup(void *blob, bd_t *bd) |
| 103 | { |
Stefan Roese | 4f14ed6 | 2007-10-05 17:07:50 +0200 | [diff] [blame] | 104 | sys_info_t sys_info; |
Matthias Fuchs | b129eff | 2009-02-03 22:13:16 +0100 | [diff] [blame] | 105 | int off, ndepth = 0; |
Stefan Roese | 4f14ed6 | 2007-10-05 17:07:50 +0200 | [diff] [blame] | 106 | |
Stefan Roese | 1362888 | 2007-12-13 14:52:53 +0100 | [diff] [blame] | 107 | get_sys_info(&sys_info); |
Stefan Roese | 4f14ed6 | 2007-10-05 17:07:50 +0200 | [diff] [blame] | 108 | |
Stefan Roese | 328a340 | 2007-12-18 08:44:51 +0100 | [diff] [blame] | 109 | do_fixup_by_prop_u32(blob, "device_type", "cpu", 4, "timebase-frequency", |
| 110 | bd->bi_intfreq, 1); |
| 111 | do_fixup_by_prop_u32(blob, "device_type", "cpu", 4, "clock-frequency", |
| 112 | bd->bi_intfreq, 1); |
Stefan Roese | 1362888 | 2007-12-13 14:52:53 +0100 | [diff] [blame] | 113 | do_fixup_by_path_u32(blob, "/plb", "clock-frequency", sys_info.freqPLB, 1); |
| 114 | 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] | 115 | |
| 116 | if (fdt_path_offset(blob, "/plb/opb/ebc") >= 0) |
| 117 | do_fixup_by_path_u32(blob, "/plb/opb/ebc", "clock-frequency", |
| 118 | sys_info.freqEBC, 1); |
| 119 | else |
| 120 | do_fixup_by_path_u32(blob, "/plb/ebc", "clock-frequency", |
| 121 | sys_info.freqEBC, 1); |
| 122 | |
Stefan Roese | 1362888 | 2007-12-13 14:52:53 +0100 | [diff] [blame] | 123 | fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize); |
Stefan Roese | 4f14ed6 | 2007-10-05 17:07:50 +0200 | [diff] [blame] | 124 | |
| 125 | /* |
Matthias Fuchs | b129eff | 2009-02-03 22:13:16 +0100 | [diff] [blame] | 126 | * Fixup all UART clocks for CPU internal UARTs |
Simon Glass | 3a1dc8f | 2012-12-13 20:48:59 +0000 | [diff] [blame] | 127 | * (only these UARTs are definitely clocked by gd->arch.uart_clk) |
Matthias Fuchs | b129eff | 2009-02-03 22:13:16 +0100 | [diff] [blame] | 128 | * |
| 129 | * These UARTs are direct childs of /plb/opb. This code |
| 130 | * does not touch any UARTs that are connected to the ebc. |
Stefan Roese | 4f14ed6 | 2007-10-05 17:07:50 +0200 | [diff] [blame] | 131 | */ |
Matthias Fuchs | b129eff | 2009-02-03 22:13:16 +0100 | [diff] [blame] | 132 | off = fdt_path_offset(blob, "/plb/opb"); |
| 133 | while ((off = fdt_next_node(blob, off, &ndepth)) >= 0) { |
| 134 | /* |
| 135 | * process all sub nodes and stop when we are back |
| 136 | * at the starting depth |
| 137 | */ |
| 138 | if (ndepth <= 0) |
| 139 | break; |
| 140 | |
| 141 | /* only update direct childs */ |
| 142 | if ((ndepth == 1) && |
| 143 | (fdt_node_check_compatible(blob, off, "ns16550") == 0)) |
| 144 | fdt_setprop(blob, off, |
| 145 | "clock-frequency", |
Simon Glass | 3a1dc8f | 2012-12-13 20:48:59 +0000 | [diff] [blame] | 146 | (void *)&gd->arch.uart_clk, 4); |
Matthias Fuchs | b129eff | 2009-02-03 22:13:16 +0100 | [diff] [blame] | 147 | } |
Stefan Roese | 4f14ed6 | 2007-10-05 17:07:50 +0200 | [diff] [blame] | 148 | |
Stefan Roese | 4f14ed6 | 2007-10-05 17:07:50 +0200 | [diff] [blame] | 149 | /* |
Stefan Roese | 871e6ce | 2007-12-14 08:41:29 +0100 | [diff] [blame] | 150 | * Fixup all ethernet nodes |
| 151 | * Note: aliases in the dts are required for this |
Stefan Roese | 4f14ed6 | 2007-10-05 17:07:50 +0200 | [diff] [blame] | 152 | */ |
Kumar Gala | ba37aa0 | 2008-08-19 15:41:18 -0500 | [diff] [blame] | 153 | fdt_fixup_ethernet(blob); |
Stefan Roese | 24bfedb | 2008-04-22 12:20:32 +0200 | [diff] [blame] | 154 | |
| 155 | /* |
| 156 | * Fixup all available PCIe nodes by setting the device_type property |
| 157 | */ |
| 158 | fdt_pcie_setup(blob); |
Stefan Roese | 4f14ed6 | 2007-10-05 17:07:50 +0200 | [diff] [blame] | 159 | } |
Stefan Roese | cb5d88b | 2008-05-08 11:01:09 +0200 | [diff] [blame] | 160 | #endif /* CONFIG_OF_LIBFDT && CONFIG_OF_BOARD_SETUP */ |