Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 1 | /* |
Kumar Gala | 365024c | 2011-01-31 15:51:20 -0600 | [diff] [blame] | 2 | * Copyright 2006, 2007, 2010-2011 Freescale Semiconductor. |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 3 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 4 | * SPDX-License-Identifier: GPL-2.0+ |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <pci.h> |
| 9 | #include <asm/processor.h> |
| 10 | #include <asm/immap_86xx.h> |
Kumar Gala | 9bbd643 | 2009-04-02 13:22:48 -0500 | [diff] [blame] | 11 | #include <asm/fsl_pci.h> |
York Sun | f062659 | 2013-09-30 09:22:09 -0700 | [diff] [blame] | 12 | #include <fsl_ddr_sdram.h> |
Kumar Gala | 3d02038 | 2010-12-15 04:55:20 -0600 | [diff] [blame] | 13 | #include <asm/fsl_serdes.h> |
Haiying Wang | 57b6e9c | 2007-01-22 12:37:30 -0600 | [diff] [blame] | 14 | #include <asm/io.h> |
Jon Loeliger | 6160aa4 | 2007-11-28 14:47:18 -0600 | [diff] [blame] | 15 | #include <libfdt.h> |
| 16 | #include <fdt_support.h> |
Ben Warren | 65b8623 | 2008-08-31 21:41:08 -0700 | [diff] [blame] | 17 | #include <netdev.h> |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 18 | |
Simon Glass | 39f90ba | 2017-03-31 08:40:25 -0600 | [diff] [blame^] | 19 | DECLARE_GLOBAL_DATA_PTR; |
| 20 | |
Becky Bruce | cc064ed | 2008-10-31 17:13:32 -0500 | [diff] [blame] | 21 | phys_size_t fixed_sdram(void); |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 22 | |
Jon Loeliger | 4fbb09c | 2006-08-22 12:25:27 -0500 | [diff] [blame] | 23 | int checkboard(void) |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 24 | { |
Kumar Gala | aba6397 | 2009-07-15 13:45:00 -0500 | [diff] [blame] | 25 | u8 vboot; |
| 26 | u8 *pixis_base = (u8 *)PIXIS_BASE; |
| 27 | |
| 28 | printf ("Board: MPC8641HPCN, Sys ID: 0x%02x, " |
| 29 | "Sys Ver: 0x%02x, FPGA Ver: 0x%02x, ", |
| 30 | in_8(pixis_base + PIXIS_ID), in_8(pixis_base + PIXIS_VER), |
| 31 | in_8(pixis_base + PIXIS_PVER)); |
| 32 | |
| 33 | vboot = in_8(pixis_base + PIXIS_VBOOT); |
| 34 | if (vboot & PIXIS_VBOOT_FMAP) |
| 35 | printf ("vBank: %d\n", ((vboot & PIXIS_VBOOT_FBANK) >> 6)); |
| 36 | else |
| 37 | puts ("Promjet\n"); |
| 38 | |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 39 | return 0; |
| 40 | } |
| 41 | |
Simon Glass | 39f90ba | 2017-03-31 08:40:25 -0600 | [diff] [blame^] | 42 | int initdram(void) |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 43 | { |
Becky Bruce | cc064ed | 2008-10-31 17:13:32 -0500 | [diff] [blame] | 44 | phys_size_t dram_size = 0; |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 45 | |
| 46 | #if defined(CONFIG_SPD_EEPROM) |
Kumar Gala | cad506c | 2008-08-26 15:01:35 -0500 | [diff] [blame] | 47 | dram_size = fsl_ddr_sdram(); |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 48 | #else |
Jon Loeliger | 4fbb09c | 2006-08-22 12:25:27 -0500 | [diff] [blame] | 49 | dram_size = fixed_sdram(); |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 50 | #endif |
| 51 | |
Timur Tabi | 107e9cd | 2010-03-29 12:51:07 -0500 | [diff] [blame] | 52 | setup_ddr_bat(dram_size); |
| 53 | |
Wolfgang Denk | f2bbb53 | 2011-07-25 10:13:53 +0200 | [diff] [blame] | 54 | debug(" DDR: "); |
Simon Glass | 39f90ba | 2017-03-31 08:40:25 -0600 | [diff] [blame^] | 55 | gd->ram_size = dram_size; |
| 56 | |
| 57 | return 0; |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 58 | } |
| 59 | |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 60 | |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 61 | #if !defined(CONFIG_SPD_EEPROM) |
Jon Loeliger | 465b9d8 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 62 | /* |
| 63 | * Fixed sdram init -- doesn't use serial presence detect. |
| 64 | */ |
Becky Bruce | cc064ed | 2008-10-31 17:13:32 -0500 | [diff] [blame] | 65 | phys_size_t |
Jon Loeliger | 4fbb09c | 2006-08-22 12:25:27 -0500 | [diff] [blame] | 66 | fixed_sdram(void) |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 67 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 68 | #if !defined(CONFIG_SYS_RAMBOOT) |
| 69 | volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; |
York Sun | a21803d | 2013-11-18 10:29:32 -0800 | [diff] [blame] | 70 | struct ccsr_ddr __iomem *ddr = &immap->im_ddr1; |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 71 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 72 | ddr->cs0_bnds = CONFIG_SYS_DDR_CS0_BNDS; |
| 73 | ddr->cs0_config = CONFIG_SYS_DDR_CS0_CONFIG; |
| 74 | ddr->timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3; |
| 75 | ddr->timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0; |
| 76 | ddr->timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1; |
| 77 | ddr->timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2; |
Peter Tyser | af5829cb | 2009-07-17 10:14:45 -0500 | [diff] [blame] | 78 | ddr->sdram_mode = CONFIG_SYS_DDR_MODE_1; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 79 | ddr->sdram_mode_2 = CONFIG_SYS_DDR_MODE_2; |
| 80 | ddr->sdram_interval = CONFIG_SYS_DDR_INTERVAL; |
| 81 | ddr->sdram_data_init = CONFIG_SYS_DDR_DATA_INIT; |
| 82 | ddr->sdram_clk_cntl = CONFIG_SYS_DDR_CLK_CTRL; |
| 83 | ddr->sdram_ocd_cntl = CONFIG_SYS_DDR_OCD_CTRL; |
| 84 | ddr->sdram_ocd_status = CONFIG_SYS_DDR_OCD_STATUS; |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 85 | |
| 86 | #if defined (CONFIG_DDR_ECC) |
| 87 | ddr->err_disable = 0x0000008D; |
| 88 | ddr->err_sbe = 0x00ff0000; |
| 89 | #endif |
| 90 | asm("sync;isync"); |
Jon Loeliger | e65e32e | 2006-05-31 12:44:44 -0500 | [diff] [blame] | 91 | |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 92 | udelay(500); |
| 93 | |
| 94 | #if defined (CONFIG_DDR_ECC) |
| 95 | /* Enable ECC checking */ |
Peter Tyser | af5829cb | 2009-07-17 10:14:45 -0500 | [diff] [blame] | 96 | ddr->sdram_cfg = (CONFIG_SYS_DDR_CONTROL | 0x20000000); |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 97 | #else |
Peter Tyser | af5829cb | 2009-07-17 10:14:45 -0500 | [diff] [blame] | 98 | ddr->sdram_cfg = CONFIG_SYS_DDR_CONTROL; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 99 | ddr->sdram_cfg_2 = CONFIG_SYS_DDR_CONTROL2; |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 100 | #endif |
| 101 | asm("sync; isync"); |
Jon Loeliger | e65e32e | 2006-05-31 12:44:44 -0500 | [diff] [blame] | 102 | |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 103 | udelay(500); |
| 104 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 105 | return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024; |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 106 | } |
| 107 | #endif /* !defined(CONFIG_SPD_EEPROM) */ |
| 108 | |
Jon Loeliger | 4fbb09c | 2006-08-22 12:25:27 -0500 | [diff] [blame] | 109 | void pci_init_board(void) |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 110 | { |
Kumar Gala | dbbfb00 | 2010-12-17 10:47:36 -0600 | [diff] [blame] | 111 | fsl_pcie_init_board(0); |
Peter Tyser | 8d6f9fa | 2010-09-29 13:37:26 -0500 | [diff] [blame] | 112 | |
Kumar Gala | e78f665 | 2010-07-09 00:02:34 -0500 | [diff] [blame] | 113 | #ifdef CONFIG_PCIE1 |
Ed Swarthout | 91080f7 | 2007-08-02 14:09:49 -0500 | [diff] [blame] | 114 | /* |
| 115 | * Activate ULI1575 legacy chip by performing a fake |
| 116 | * memory access. Needed to make ULI RTC work. |
| 117 | */ |
Kumar Gala | e78f665 | 2010-07-09 00:02:34 -0500 | [diff] [blame] | 118 | in_be32((unsigned *) ((char *)(CONFIG_SYS_PCIE1_MEM_VIRT |
| 119 | + CONFIG_SYS_PCIE1_MEM_SIZE - 0x1000000))); |
Kumar Gala | e78f665 | 2010-07-09 00:02:34 -0500 | [diff] [blame] | 120 | #endif /* CONFIG_PCIE1 */ |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 121 | } |
| 122 | |
Jon Loeliger | 84640c9 | 2008-02-18 14:01:56 -0600 | [diff] [blame] | 123 | |
Jon Loeliger | 6160aa4 | 2007-11-28 14:47:18 -0600 | [diff] [blame] | 124 | #if defined(CONFIG_OF_BOARD_SETUP) |
Simon Glass | 2aec3cc | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 125 | int ft_board_setup(void *blob, bd_t *bd) |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 126 | { |
Becky Bruce | 48d3ce2 | 2008-11-07 13:46:19 -0600 | [diff] [blame] | 127 | int off; |
| 128 | u64 *tmp; |
Simon Glass | 9fbc632 | 2014-10-23 18:58:57 -0600 | [diff] [blame] | 129 | int addrcells; |
Becky Bruce | 48d3ce2 | 2008-11-07 13:46:19 -0600 | [diff] [blame] | 130 | |
Jon Loeliger | 84640c9 | 2008-02-18 14:01:56 -0600 | [diff] [blame] | 131 | ft_cpu_setup(blob, bd); |
Jon Loeliger | 6160aa4 | 2007-11-28 14:47:18 -0600 | [diff] [blame] | 132 | |
Kumar Gala | d0f27d3 | 2010-07-08 22:37:44 -0500 | [diff] [blame] | 133 | FT_FSL_PCI_SETUP; |
Becky Bruce | 48d3ce2 | 2008-11-07 13:46:19 -0600 | [diff] [blame] | 134 | |
| 135 | /* |
| 136 | * Warn if it looks like the device tree doesn't match u-boot. |
| 137 | * This is just an estimation, based on the location of CCSR, |
| 138 | * which is defined by the "reg" property in the soc node. |
| 139 | */ |
| 140 | off = fdt_path_offset(blob, "/soc8641"); |
Simon Glass | 9fbc632 | 2014-10-23 18:58:57 -0600 | [diff] [blame] | 141 | addrcells = fdt_address_cells(blob, 0); |
Becky Bruce | 48d3ce2 | 2008-11-07 13:46:19 -0600 | [diff] [blame] | 142 | tmp = (u64 *)fdt_getprop(blob, off, "reg", NULL); |
| 143 | |
| 144 | if (tmp) { |
| 145 | u64 addr; |
Simon Glass | 9fbc632 | 2014-10-23 18:58:57 -0600 | [diff] [blame] | 146 | |
| 147 | if (addrcells == 1) |
Becky Bruce | 48d3ce2 | 2008-11-07 13:46:19 -0600 | [diff] [blame] | 148 | addr = *(u32 *)tmp; |
Becky Bruce | eccb5e7 | 2008-11-10 19:45:35 -0600 | [diff] [blame] | 149 | else |
| 150 | addr = *tmp; |
Becky Bruce | 48d3ce2 | 2008-11-07 13:46:19 -0600 | [diff] [blame] | 151 | |
| 152 | if (addr != CONFIG_SYS_CCSRBAR_PHYS) |
| 153 | printf("WARNING: The CCSRBAR address in your .dts " |
| 154 | "does not match the address of the CCSR " |
| 155 | "in u-boot. This means your .dts might " |
| 156 | "be old.\n"); |
| 157 | } |
Simon Glass | 2aec3cc | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 158 | |
| 159 | return 0; |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 160 | } |
| 161 | #endif |
| 162 | |
Jon Loeliger | 72f8a8e | 2006-05-31 11:24:28 -0500 | [diff] [blame] | 163 | |
Haiying Wang | 43d624d | 2006-07-28 12:41:18 -0400 | [diff] [blame] | 164 | /* |
| 165 | * get_board_sys_clk |
| 166 | * Reads the FPGA on board for CONFIG_SYS_CLK_FREQ |
| 167 | */ |
| 168 | |
Jon Loeliger | 4fbb09c | 2006-08-22 12:25:27 -0500 | [diff] [blame] | 169 | unsigned long |
| 170 | get_board_sys_clk(ulong dummy) |
Haiying Wang | 43d624d | 2006-07-28 12:41:18 -0400 | [diff] [blame] | 171 | { |
| 172 | u8 i, go_bit, rd_clks; |
| 173 | ulong val = 0; |
Kumar Gala | 146c4b2 | 2009-07-22 10:12:39 -0500 | [diff] [blame] | 174 | u8 *pixis_base = (u8 *)PIXIS_BASE; |
Haiying Wang | 43d624d | 2006-07-28 12:41:18 -0400 | [diff] [blame] | 175 | |
Kumar Gala | 146c4b2 | 2009-07-22 10:12:39 -0500 | [diff] [blame] | 176 | go_bit = in_8(pixis_base + PIXIS_VCTL); |
Haiying Wang | 43d624d | 2006-07-28 12:41:18 -0400 | [diff] [blame] | 177 | go_bit &= 0x01; |
| 178 | |
Kumar Gala | 146c4b2 | 2009-07-22 10:12:39 -0500 | [diff] [blame] | 179 | rd_clks = in_8(pixis_base + PIXIS_VCFGEN0); |
Haiying Wang | 43d624d | 2006-07-28 12:41:18 -0400 | [diff] [blame] | 180 | rd_clks &= 0x1C; |
| 181 | |
| 182 | /* |
| 183 | * Only if both go bit and the SCLK bit in VCFGEN0 are set |
| 184 | * should we be using the AUX register. Remember, we also set the |
| 185 | * GO bit to boot from the alternate bank on the on-board flash |
| 186 | */ |
| 187 | |
| 188 | if (go_bit) { |
| 189 | if (rd_clks == 0x1c) |
Kumar Gala | 146c4b2 | 2009-07-22 10:12:39 -0500 | [diff] [blame] | 190 | i = in_8(pixis_base + PIXIS_AUX); |
Haiying Wang | 43d624d | 2006-07-28 12:41:18 -0400 | [diff] [blame] | 191 | else |
Kumar Gala | 146c4b2 | 2009-07-22 10:12:39 -0500 | [diff] [blame] | 192 | i = in_8(pixis_base + PIXIS_SPD); |
Haiying Wang | 43d624d | 2006-07-28 12:41:18 -0400 | [diff] [blame] | 193 | } else { |
Kumar Gala | 146c4b2 | 2009-07-22 10:12:39 -0500 | [diff] [blame] | 194 | i = in_8(pixis_base + PIXIS_SPD); |
Haiying Wang | 43d624d | 2006-07-28 12:41:18 -0400 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | i &= 0x07; |
| 198 | |
| 199 | switch (i) { |
| 200 | case 0: |
| 201 | val = 33000000; |
| 202 | break; |
| 203 | case 1: |
| 204 | val = 40000000; |
| 205 | break; |
| 206 | case 2: |
| 207 | val = 50000000; |
| 208 | break; |
| 209 | case 3: |
| 210 | val = 66000000; |
| 211 | break; |
| 212 | case 4: |
| 213 | val = 83000000; |
| 214 | break; |
| 215 | case 5: |
| 216 | val = 100000000; |
| 217 | break; |
| 218 | case 6: |
| 219 | val = 134000000; |
| 220 | break; |
| 221 | case 7: |
| 222 | val = 166000000; |
| 223 | break; |
| 224 | } |
| 225 | |
| 226 | return val; |
| 227 | } |
Ben Warren | 65b8623 | 2008-08-31 21:41:08 -0700 | [diff] [blame] | 228 | |
| 229 | int board_eth_init(bd_t *bis) |
| 230 | { |
| 231 | /* Initialize TSECs */ |
| 232 | cpu_eth_init(bis); |
| 233 | return pci_eth_init(bis); |
| 234 | } |
Peter Tyser | 6945440 | 2009-02-05 11:25:25 -0600 | [diff] [blame] | 235 | |
| 236 | void board_reset(void) |
| 237 | { |
Kumar Gala | 146c4b2 | 2009-07-22 10:12:39 -0500 | [diff] [blame] | 238 | u8 *pixis_base = (u8 *)PIXIS_BASE; |
| 239 | |
| 240 | out_8(pixis_base + PIXIS_RST, 0); |
Peter Tyser | 6945440 | 2009-02-05 11:25:25 -0600 | [diff] [blame] | 241 | |
| 242 | while (1) |
| 243 | ; |
| 244 | } |