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