Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Joe Hamman | 8ac2732 | 2007-08-09 15:10:53 -0500 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2007 Wind River Systemes, Inc. <www.windriver.com> |
| 4 | * Copyright 2007 Embedded Specialties, Inc. |
| 5 | * Joe Hamman joe.hamman@embeddedspecialties.com |
| 6 | * |
| 7 | * Copyright 2004 Freescale Semiconductor. |
| 8 | * Jeff Brown |
| 9 | * Srikanth Srinivasan (srikanth.srinivasan@freescale.com) |
| 10 | * |
| 11 | * (C) Copyright 2002 Scott McNutt <smcnutt@artesyncp.com> |
Joe Hamman | 8ac2732 | 2007-08-09 15:10:53 -0500 | [diff] [blame] | 12 | */ |
| 13 | |
| 14 | #include <common.h> |
| 15 | #include <command.h> |
Simon Glass | 2cf431c | 2019-11-14 12:57:47 -0700 | [diff] [blame] | 16 | #include <init.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 17 | #include <log.h> |
Joe Hamman | 8ac2732 | 2007-08-09 15:10:53 -0500 | [diff] [blame] | 18 | #include <pci.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 19 | #include <asm/global_data.h> |
Joe Hamman | 8ac2732 | 2007-08-09 15:10:53 -0500 | [diff] [blame] | 20 | #include <asm/processor.h> |
| 21 | #include <asm/immap_86xx.h> |
Kumar Gala | c851462 | 2009-04-02 13:22:48 -0500 | [diff] [blame] | 22 | #include <asm/fsl_pci.h> |
York Sun | 5614e71 | 2013-09-30 09:22:09 -0700 | [diff] [blame] | 23 | #include <fsl_ddr_sdram.h> |
Kumar Gala | 5d27e02 | 2010-12-15 04:55:20 -0600 | [diff] [blame] | 24 | #include <asm/fsl_serdes.h> |
Simon Glass | c05ed00 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 25 | #include <linux/delay.h> |
Masahiro Yamada | b08c8c4 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 26 | #include <linux/libfdt.h> |
Jon Loeliger | 13f5433 | 2008-02-18 14:01:56 -0600 | [diff] [blame] | 27 | #include <fdt_support.h> |
Joe Hamman | 8ac2732 | 2007-08-09 15:10:53 -0500 | [diff] [blame] | 28 | |
Simon Glass | 088454c | 2017-03-31 08:40:25 -0600 | [diff] [blame] | 29 | DECLARE_GLOBAL_DATA_PTR; |
| 30 | |
Joe Hamman | 8ac2732 | 2007-08-09 15:10:53 -0500 | [diff] [blame] | 31 | long int fixed_sdram (void); |
| 32 | |
| 33 | int board_early_init_f (void) |
| 34 | { |
| 35 | return 0; |
| 36 | } |
| 37 | |
| 38 | int checkboard (void) |
| 39 | { |
| 40 | puts ("Board: Wind River SBC8641D\n"); |
| 41 | |
Joe Hamman | 8ac2732 | 2007-08-09 15:10:53 -0500 | [diff] [blame] | 42 | return 0; |
| 43 | } |
| 44 | |
Simon Glass | f1683aa | 2017-04-06 12:47:05 -0600 | [diff] [blame] | 45 | int dram_init(void) |
Joe Hamman | 8ac2732 | 2007-08-09 15:10:53 -0500 | [diff] [blame] | 46 | { |
| 47 | long dram_size = 0; |
| 48 | |
| 49 | #if defined(CONFIG_SPD_EEPROM) |
Kumar Gala | 9bd4e59 | 2008-08-26 15:01:37 -0500 | [diff] [blame] | 50 | dram_size = fsl_ddr_sdram(); |
Joe Hamman | 8ac2732 | 2007-08-09 15:10:53 -0500 | [diff] [blame] | 51 | #else |
| 52 | dram_size = fixed_sdram (); |
| 53 | #endif |
| 54 | |
Simon Glass | 3c7dded | 2020-05-10 11:40:04 -0600 | [diff] [blame] | 55 | debug(" DDR: "); |
Simon Glass | 088454c | 2017-03-31 08:40:25 -0600 | [diff] [blame] | 56 | gd->ram_size = dram_size; |
| 57 | |
| 58 | return 0; |
Joe Hamman | 8ac2732 | 2007-08-09 15:10:53 -0500 | [diff] [blame] | 59 | } |
| 60 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 61 | #if defined(CONFIG_SYS_DRAM_TEST) |
Simon Glass | 49acd56 | 2019-12-28 10:45:06 -0700 | [diff] [blame] | 62 | int testdram(void) |
Joe Hamman | 8ac2732 | 2007-08-09 15:10:53 -0500 | [diff] [blame] | 63 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 64 | uint *pstart = (uint *) CONFIG_SYS_MEMTEST_START; |
| 65 | uint *pend = (uint *) CONFIG_SYS_MEMTEST_END; |
Joe Hamman | 8ac2732 | 2007-08-09 15:10:53 -0500 | [diff] [blame] | 66 | uint *p; |
| 67 | |
| 68 | puts ("SDRAM test phase 1:\n"); |
| 69 | for (p = pstart; p < pend; p++) |
| 70 | *p = 0xaaaaaaaa; |
| 71 | |
| 72 | for (p = pstart; p < pend; p++) { |
| 73 | if (*p != 0xaaaaaaaa) { |
| 74 | printf ("SDRAM test fails at: %08x\n", (uint) p); |
| 75 | return 1; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | puts ("SDRAM test phase 2:\n"); |
| 80 | for (p = pstart; p < pend; p++) |
| 81 | *p = 0x55555555; |
| 82 | |
| 83 | for (p = pstart; p < pend; p++) { |
| 84 | if (*p != 0x55555555) { |
| 85 | printf ("SDRAM test fails at: %08x\n", (uint) p); |
| 86 | return 1; |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | puts ("SDRAM test passed.\n"); |
| 91 | return 0; |
| 92 | } |
| 93 | #endif |
| 94 | |
| 95 | #if !defined(CONFIG_SPD_EEPROM) |
| 96 | /* |
| 97 | * Fixed sdram init -- doesn't use serial presence detect. |
| 98 | */ |
| 99 | long int fixed_sdram (void) |
| 100 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 101 | #if !defined(CONFIG_SYS_RAMBOOT) |
| 102 | volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; |
York Sun | 9a17eb5 | 2013-11-18 10:29:32 -0800 | [diff] [blame] | 103 | volatile struct ccsr_ddr *ddr = &immap->im_ddr1; |
Joe Hamman | 8ac2732 | 2007-08-09 15:10:53 -0500 | [diff] [blame] | 104 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 105 | ddr->cs0_bnds = CONFIG_SYS_DDR_CS0_BNDS; |
| 106 | ddr->cs1_bnds = CONFIG_SYS_DDR_CS1_BNDS; |
| 107 | ddr->cs2_bnds = CONFIG_SYS_DDR_CS2_BNDS; |
| 108 | ddr->cs3_bnds = CONFIG_SYS_DDR_CS3_BNDS; |
| 109 | ddr->cs0_config = CONFIG_SYS_DDR_CS0_CONFIG; |
| 110 | ddr->cs1_config = CONFIG_SYS_DDR_CS1_CONFIG; |
| 111 | ddr->cs2_config = CONFIG_SYS_DDR_CS2_CONFIG; |
| 112 | ddr->cs3_config = CONFIG_SYS_DDR_CS3_CONFIG; |
| 113 | ddr->timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3; |
| 114 | ddr->timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0; |
| 115 | ddr->timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1; |
| 116 | ddr->timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2; |
Peter Tyser | e7ee23e | 2009-07-17 10:14:45 -0500 | [diff] [blame] | 117 | ddr->sdram_cfg = CONFIG_SYS_DDR_CFG_1A; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 118 | ddr->sdram_cfg_2 = CONFIG_SYS_DDR_CFG_2; |
Peter Tyser | e7ee23e | 2009-07-17 10:14:45 -0500 | [diff] [blame] | 119 | ddr->sdram_mode = CONFIG_SYS_DDR_MODE_1; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 120 | ddr->sdram_mode_2 = CONFIG_SYS_DDR_MODE_2; |
York Sun | 9a17eb5 | 2013-11-18 10:29:32 -0800 | [diff] [blame] | 121 | ddr->sdram_md_cntl = CONFIG_SYS_DDR_MODE_CTL; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 122 | ddr->sdram_interval = CONFIG_SYS_DDR_INTERVAL; |
| 123 | ddr->sdram_data_init = CONFIG_SYS_DDR_DATA_INIT; |
| 124 | ddr->sdram_clk_cntl = CONFIG_SYS_DDR_CLK_CTRL; |
Joe Hamman | 8ac2732 | 2007-08-09 15:10:53 -0500 | [diff] [blame] | 125 | |
| 126 | asm ("sync;isync"); |
| 127 | |
Simon Glass | 07e1114 | 2020-05-10 11:40:10 -0600 | [diff] [blame] | 128 | udelay(500); |
Joe Hamman | 8ac2732 | 2007-08-09 15:10:53 -0500 | [diff] [blame] | 129 | |
Peter Tyser | e7ee23e | 2009-07-17 10:14:45 -0500 | [diff] [blame] | 130 | ddr->sdram_cfg = CONFIG_SYS_DDR_CFG_1B; |
Joe Hamman | 8ac2732 | 2007-08-09 15:10:53 -0500 | [diff] [blame] | 131 | asm ("sync; isync"); |
| 132 | |
Simon Glass | 07e1114 | 2020-05-10 11:40:10 -0600 | [diff] [blame] | 133 | udelay(500); |
Joe Hamman | 8ac2732 | 2007-08-09 15:10:53 -0500 | [diff] [blame] | 134 | ddr = &immap->im_ddr2; |
| 135 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 136 | ddr->cs0_bnds = CONFIG_SYS_DDR2_CS0_BNDS; |
| 137 | ddr->cs1_bnds = CONFIG_SYS_DDR2_CS1_BNDS; |
| 138 | ddr->cs2_bnds = CONFIG_SYS_DDR2_CS2_BNDS; |
| 139 | ddr->cs3_bnds = CONFIG_SYS_DDR2_CS3_BNDS; |
| 140 | ddr->cs0_config = CONFIG_SYS_DDR2_CS0_CONFIG; |
| 141 | ddr->cs1_config = CONFIG_SYS_DDR2_CS1_CONFIG; |
| 142 | ddr->cs2_config = CONFIG_SYS_DDR2_CS2_CONFIG; |
| 143 | ddr->cs3_config = CONFIG_SYS_DDR2_CS3_CONFIG; |
| 144 | ddr->timing_cfg_3 = CONFIG_SYS_DDR2_EXT_REFRESH; |
| 145 | ddr->timing_cfg_0 = CONFIG_SYS_DDR2_TIMING_0; |
| 146 | ddr->timing_cfg_1 = CONFIG_SYS_DDR2_TIMING_1; |
| 147 | ddr->timing_cfg_2 = CONFIG_SYS_DDR2_TIMING_2; |
Peter Tyser | e7ee23e | 2009-07-17 10:14:45 -0500 | [diff] [blame] | 148 | ddr->sdram_cfg = CONFIG_SYS_DDR2_CFG_1A; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 149 | ddr->sdram_cfg_2 = CONFIG_SYS_DDR2_CFG_2; |
Peter Tyser | e7ee23e | 2009-07-17 10:14:45 -0500 | [diff] [blame] | 150 | ddr->sdram_mode = CONFIG_SYS_DDR2_MODE_1; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 151 | ddr->sdram_mode_2 = CONFIG_SYS_DDR2_MODE_2; |
York Sun | 9a17eb5 | 2013-11-18 10:29:32 -0800 | [diff] [blame] | 152 | ddr->sdram_md_cntl = CONFIG_SYS_DDR2_MODE_CTL; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 153 | ddr->sdram_interval = CONFIG_SYS_DDR2_INTERVAL; |
| 154 | ddr->sdram_data_init = CONFIG_SYS_DDR2_DATA_INIT; |
| 155 | ddr->sdram_clk_cntl = CONFIG_SYS_DDR2_CLK_CTRL; |
Joe Hamman | 8ac2732 | 2007-08-09 15:10:53 -0500 | [diff] [blame] | 156 | |
| 157 | asm ("sync;isync"); |
| 158 | |
Simon Glass | 07e1114 | 2020-05-10 11:40:10 -0600 | [diff] [blame] | 159 | udelay(500); |
Joe Hamman | 8ac2732 | 2007-08-09 15:10:53 -0500 | [diff] [blame] | 160 | |
Peter Tyser | e7ee23e | 2009-07-17 10:14:45 -0500 | [diff] [blame] | 161 | ddr->sdram_cfg = CONFIG_SYS_DDR2_CFG_1B; |
Joe Hamman | 8ac2732 | 2007-08-09 15:10:53 -0500 | [diff] [blame] | 162 | asm ("sync; isync"); |
| 163 | |
Simon Glass | 07e1114 | 2020-05-10 11:40:10 -0600 | [diff] [blame] | 164 | udelay(500); |
Joe Hamman | 8ac2732 | 2007-08-09 15:10:53 -0500 | [diff] [blame] | 165 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 166 | return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024; |
Joe Hamman | 8ac2732 | 2007-08-09 15:10:53 -0500 | [diff] [blame] | 167 | } |
| 168 | #endif /* !defined(CONFIG_SPD_EEPROM) */ |
| 169 | |
| 170 | #if defined(CONFIG_PCI) |
| 171 | /* |
| 172 | * Initialize PCI Devices, report devices found. |
| 173 | */ |
| 174 | |
Joe Hamman | cca3496 | 2007-08-11 06:54:58 -0500 | [diff] [blame] | 175 | void pci_init_board(void) |
Joe Hamman | 8ac2732 | 2007-08-09 15:10:53 -0500 | [diff] [blame] | 176 | { |
Kumar Gala | c51136e | 2010-12-17 10:26:44 -0600 | [diff] [blame] | 177 | fsl_pcie_init_board(0); |
Joe Hamman | 8ac2732 | 2007-08-09 15:10:53 -0500 | [diff] [blame] | 178 | } |
Kumar Gala | c51136e | 2010-12-17 10:26:44 -0600 | [diff] [blame] | 179 | #endif /* CONFIG_PCI */ |
Joe Hamman | 8ac2732 | 2007-08-09 15:10:53 -0500 | [diff] [blame] | 180 | |
Jon Loeliger | 13f5433 | 2008-02-18 14:01:56 -0600 | [diff] [blame] | 181 | |
| 182 | #if defined(CONFIG_OF_BOARD_SETUP) |
Masahiro Yamada | b75d8dc | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 183 | int ft_board_setup(void *blob, struct bd_info *bd) |
Joe Hamman | 8ac2732 | 2007-08-09 15:10:53 -0500 | [diff] [blame] | 184 | { |
Jon Loeliger | 13f5433 | 2008-02-18 14:01:56 -0600 | [diff] [blame] | 185 | ft_cpu_setup(blob, bd); |
Joe Hamman | 8ac2732 | 2007-08-09 15:10:53 -0500 | [diff] [blame] | 186 | |
Kumar Gala | 6525d51 | 2010-07-08 22:37:44 -0500 | [diff] [blame] | 187 | FT_FSL_PCI_SETUP; |
Simon Glass | e895a4b | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 188 | |
| 189 | return 0; |
Joe Hamman | 8ac2732 | 2007-08-09 15:10:53 -0500 | [diff] [blame] | 190 | } |
| 191 | #endif |
| 192 | |
| 193 | void sbc8641d_reset_board (void) |
| 194 | { |
| 195 | puts ("Resetting board....\n"); |
| 196 | } |
| 197 | |
| 198 | /* |
| 199 | * get_board_sys_clk |
| 200 | * Clock is fixed at 1GHz on this board. Used for CONFIG_SYS_CLK_FREQ |
| 201 | */ |
| 202 | |
| 203 | unsigned long get_board_sys_clk (ulong dummy) |
| 204 | { |
| 205 | int i; |
| 206 | ulong val = 0; |
| 207 | |
| 208 | i = 5; |
| 209 | i &= 0x07; |
| 210 | |
| 211 | switch (i) { |
| 212 | case 0: |
| 213 | val = 33000000; |
| 214 | break; |
| 215 | case 1: |
| 216 | val = 40000000; |
| 217 | break; |
| 218 | case 2: |
| 219 | val = 50000000; |
| 220 | break; |
| 221 | case 3: |
| 222 | val = 66000000; |
| 223 | break; |
| 224 | case 4: |
| 225 | val = 83000000; |
| 226 | break; |
| 227 | case 5: |
| 228 | val = 100000000; |
| 229 | break; |
| 230 | case 6: |
| 231 | val = 134000000; |
| 232 | break; |
| 233 | case 7: |
| 234 | val = 166000000; |
| 235 | break; |
| 236 | } |
| 237 | |
| 238 | return val; |
| 239 | } |
Peter Tyser | 4ef630d | 2009-02-05 11:25:25 -0600 | [diff] [blame] | 240 | |
| 241 | void board_reset(void) |
| 242 | { |
| 243 | #ifdef CONFIG_SYS_RESET_ADDRESS |
| 244 | ulong addr = CONFIG_SYS_RESET_ADDRESS; |
| 245 | |
| 246 | /* flush and disable I/D cache */ |
| 247 | __asm__ __volatile__ ("mfspr 3, 1008" ::: "r3"); |
| 248 | __asm__ __volatile__ ("ori 5, 5, 0xcc00" ::: "r5"); |
| 249 | __asm__ __volatile__ ("ori 4, 3, 0xc00" ::: "r4"); |
| 250 | __asm__ __volatile__ ("andc 5, 3, 5" ::: "r5"); |
| 251 | __asm__ __volatile__ ("sync"); |
| 252 | __asm__ __volatile__ ("mtspr 1008, 4"); |
| 253 | __asm__ __volatile__ ("isync"); |
| 254 | __asm__ __volatile__ ("sync"); |
| 255 | __asm__ __volatile__ ("mtspr 1008, 5"); |
| 256 | __asm__ __volatile__ ("isync"); |
| 257 | __asm__ __volatile__ ("sync"); |
| 258 | |
| 259 | /* |
| 260 | * SRR0 has system reset vector, SRR1 has default MSR value |
| 261 | * rfi restores MSR from SRR1 and sets the PC to the SRR0 value |
| 262 | */ |
| 263 | __asm__ __volatile__ ("mtspr 26, %0" :: "r" (addr)); |
| 264 | __asm__ __volatile__ ("li 4, (1 << 6)" ::: "r4"); |
| 265 | __asm__ __volatile__ ("mtspr 27, 4"); |
| 266 | __asm__ __volatile__ ("rfi"); |
| 267 | #endif |
| 268 | } |