Kumar Gala | af5b326 | 2008-06-06 13:12:18 -0500 | [diff] [blame] | 1 | /* |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 2 | * Copyright 2004 Freescale Semiconductor. |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 3 | * (C) Copyright 2002,2003, Motorola Inc. |
| 4 | * Xianghua Xiao, (X.Xiao@motorola.com) |
| 5 | * |
| 6 | * (C) Copyright 2002 Scott McNutt <smcnutt@artesyncp.com> |
| 7 | * |
Wolfgang Denk | bd8ec7e | 2013-10-07 13:07:26 +0200 | [diff] [blame] | 8 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 12 | #include <common.h> |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 13 | #include <pci.h> |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 14 | #include <asm/processor.h> |
Kumar Gala | af5b326 | 2008-06-06 13:12:18 -0500 | [diff] [blame] | 15 | #include <asm/mmu.h> |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 16 | #include <asm/immap_85xx.h> |
York Sun | f062659 | 2013-09-30 09:22:09 -0700 | [diff] [blame] | 17 | #include <fsl_ddr_sdram.h> |
Kumar Gala | 6e57840 | 2007-11-28 22:54:27 -0600 | [diff] [blame] | 18 | #include <libfdt.h> |
| 19 | #include <fdt_support.h> |
Matthew McClintock | 148e26a | 2006-06-28 10:43:36 -0500 | [diff] [blame] | 20 | |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 21 | #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER) |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 22 | extern void ddr_enable_ecc(unsigned int dram_size); |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 23 | #endif |
| 24 | |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 25 | void local_bus_init(void); |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 26 | |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 27 | int checkboard (void) |
| 28 | { |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 29 | puts("Board: ADS\n"); |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 30 | |
| 31 | #ifdef CONFIG_PCI |
Peter Tyser | 2b91f71 | 2010-10-29 17:59:24 -0500 | [diff] [blame] | 32 | printf("PCI1: 32 bit, %d MHz (compiled)\n", |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 33 | CONFIG_SYS_CLK_FREQ / 1000000); |
| 34 | #else |
Peter Tyser | 2b91f71 | 2010-10-29 17:59:24 -0500 | [diff] [blame] | 35 | printf("PCI1: disabled\n"); |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 36 | #endif |
| 37 | |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 38 | /* |
| 39 | * Initialize local bus. |
| 40 | */ |
| 41 | local_bus_init(); |
| 42 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 43 | return 0; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 44 | } |
| 45 | |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 46 | /* |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 47 | * Initialize Local Bus |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 48 | */ |
| 49 | |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 50 | void |
| 51 | local_bus_init(void) |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 52 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 53 | volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); |
Becky Bruce | 0d4cee1 | 2010-06-17 11:37:20 -0500 | [diff] [blame] | 54 | volatile fsl_lbc_t *lbc = LBC_BASE_ADDR; |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 55 | |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 56 | uint clkdiv; |
| 57 | uint lbc_hz; |
| 58 | sys_info_t sysinfo; |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 59 | |
| 60 | /* |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 61 | * Errata LBC11. |
| 62 | * Fix Local Bus clock glitch when DLL is enabled. |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 63 | * |
Wolfgang Denk | af0501a | 2008-10-19 02:35:50 +0200 | [diff] [blame] | 64 | * If localbus freq is < 66MHz, DLL bypass mode must be used. |
| 65 | * If localbus freq is > 133MHz, DLL can be safely enabled. |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 66 | * Between 66 and 133, the DLL is enabled with an override workaround. |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 67 | */ |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 68 | |
| 69 | get_sys_info(&sysinfo); |
Trent Piepho | 1b560ac | 2008-12-03 15:16:34 -0800 | [diff] [blame] | 70 | clkdiv = lbc->lcrr & LCRR_CLKDIV; |
Prabhakar Kushwaha | d169808 | 2013-08-16 14:52:26 +0530 | [diff] [blame] | 71 | lbc_hz = sysinfo.freq_systembus / 1000000 / clkdiv; |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 72 | |
| 73 | if (lbc_hz < 66) { |
Paul Gortmaker | e5b89d5 | 2012-08-13 13:48:57 +0000 | [diff] [blame] | 74 | lbc->lcrr = CONFIG_SYS_LBC_LCRR | LCRR_DBYP; /* DLL Bypass */ |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 75 | |
| 76 | } else if (lbc_hz >= 133) { |
Paul Gortmaker | e5b89d5 | 2012-08-13 13:48:57 +0000 | [diff] [blame] | 77 | lbc->lcrr = CONFIG_SYS_LBC_LCRR & (~LCRR_DBYP); /* DLL Enabled */ |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 78 | |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 79 | } else { |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 80 | /* |
| 81 | * On REV1 boards, need to change CLKDIV before enable DLL. |
| 82 | * Default CLKDIV is 8, change it to 4 temporarily. |
| 83 | */ |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 84 | uint pvr = get_pvr(); |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 85 | uint temp_lbcdll = 0; |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 86 | |
| 87 | if (pvr == PVR_85xx_REV1) { |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 88 | /* FIXME: Justify the high bit here. */ |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 89 | lbc->lcrr = 0x10000004; |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 90 | } |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 91 | |
Paul Gortmaker | e5b89d5 | 2012-08-13 13:48:57 +0000 | [diff] [blame] | 92 | lbc->lcrr = CONFIG_SYS_LBC_LCRR & (~LCRR_DBYP); /* DLL Enabled */ |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 93 | udelay(200); |
| 94 | |
| 95 | /* |
| 96 | * Sample LBC DLL ctrl reg, upshift it to set the |
| 97 | * override bits. |
| 98 | */ |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 99 | temp_lbcdll = gur->lbcdllcr; |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 100 | gur->lbcdllcr = (((temp_lbcdll & 0xff) << 16) | 0x80000000); |
| 101 | asm("sync;isync;msync"); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 102 | } |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | |
| 106 | /* |
| 107 | * Initialize SDRAM memory on the Local Bus. |
| 108 | */ |
Becky Bruce | b88d3d0 | 2010-12-17 17:17:57 -0600 | [diff] [blame] | 109 | void lbc_sdram_init(void) |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 110 | { |
Becky Bruce | 0d4cee1 | 2010-06-17 11:37:20 -0500 | [diff] [blame] | 111 | volatile fsl_lbc_t *lbc = LBC_BASE_ADDR; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 112 | uint *sdram_addr = (uint *)CONFIG_SYS_LBC_SDRAM_BASE; |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 113 | |
Becky Bruce | 2d8ecac | 2010-12-17 17:17:59 -0600 | [diff] [blame] | 114 | puts("LBC SDRAM: "); |
| 115 | print_size(CONFIG_SYS_LBC_SDRAM_SIZE * 1024 * 1024, |
| 116 | "\n "); |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 117 | |
| 118 | /* |
| 119 | * Setup SDRAM Base and Option Registers |
| 120 | */ |
Becky Bruce | 0d4cee1 | 2010-06-17 11:37:20 -0500 | [diff] [blame] | 121 | set_lbc_or(2, CONFIG_SYS_OR2_PRELIM); |
| 122 | set_lbc_br(2, CONFIG_SYS_BR2_PRELIM); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 123 | lbc->lbcr = CONFIG_SYS_LBC_LBCR; |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 124 | asm("msync"); |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 125 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 126 | lbc->lsrt = CONFIG_SYS_LBC_LSRT; |
| 127 | lbc->mrtpr = CONFIG_SYS_LBC_MRTPR; |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 128 | asm("sync"); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 129 | |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 130 | /* |
| 131 | * Configure the SDRAM controller. |
| 132 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 133 | lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_1; |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 134 | asm("sync"); |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 135 | *sdram_addr = 0xff; |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 136 | ppcDcbf((unsigned long) sdram_addr); |
| 137 | udelay(100); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 138 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 139 | lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_2; |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 140 | asm("sync"); |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 141 | *sdram_addr = 0xff; |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 142 | ppcDcbf((unsigned long) sdram_addr); |
| 143 | udelay(100); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 144 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 145 | lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_3; |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 146 | asm("sync"); |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 147 | *sdram_addr = 0xff; |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 148 | ppcDcbf((unsigned long) sdram_addr); |
| 149 | udelay(100); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 150 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 151 | lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_4; |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 152 | asm("sync"); |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 153 | *sdram_addr = 0xff; |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 154 | ppcDcbf((unsigned long) sdram_addr); |
| 155 | udelay(100); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 156 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 157 | lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_5; |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 158 | asm("sync"); |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 159 | *sdram_addr = 0xff; |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 160 | ppcDcbf((unsigned long) sdram_addr); |
| 161 | udelay(100); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 162 | } |
| 163 | |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 164 | #if !defined(CONFIG_SPD_EEPROM) |
| 165 | /************************************************************************* |
| 166 | * fixed sdram init -- doesn't use serial presence detect. |
| 167 | ************************************************************************/ |
Becky Bruce | 5e35d8a | 2010-12-17 17:17:56 -0600 | [diff] [blame] | 168 | phys_size_t fixed_sdram(void) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 169 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 170 | #ifndef CONFIG_SYS_RAMBOOT |
York Sun | a21803d | 2013-11-18 10:29:32 -0800 | [diff] [blame] | 171 | struct ccsr_ddr __iomem *ddr = |
| 172 | (struct ccsr_ddr __iomem *)(CONFIG_SYS_FSL_DDR_ADDR); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 173 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 174 | ddr->cs0_bnds = CONFIG_SYS_DDR_CS0_BNDS; |
| 175 | ddr->cs0_config = CONFIG_SYS_DDR_CS0_CONFIG; |
| 176 | ddr->timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1; |
| 177 | ddr->timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2; |
| 178 | ddr->sdram_mode = CONFIG_SYS_DDR_MODE; |
| 179 | ddr->sdram_interval = CONFIG_SYS_DDR_INTERVAL; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 180 | #if defined (CONFIG_DDR_ECC) |
| 181 | ddr->err_disable = 0x0000000D; |
| 182 | ddr->err_sbe = 0x00ff0000; |
| 183 | #endif |
| 184 | asm("sync;isync;msync"); |
| 185 | udelay(500); |
| 186 | #if defined (CONFIG_DDR_ECC) |
| 187 | /* Enable ECC checking */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 188 | ddr->sdram_cfg = (CONFIG_SYS_DDR_CONTROL | 0x20000000); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 189 | #else |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 190 | ddr->sdram_cfg = CONFIG_SYS_DDR_CONTROL; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 191 | #endif |
| 192 | asm("sync; isync; msync"); |
| 193 | udelay(500); |
| 194 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 195 | return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 196 | } |
| 197 | #endif /* !defined(CONFIG_SPD_EEPROM) */ |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 198 | |
| 199 | |
| 200 | #if defined(CONFIG_PCI) |
| 201 | /* |
| 202 | * Initialize PCI Devices, report devices found. |
| 203 | */ |
| 204 | |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 205 | |
Matthew McClintock | 8c0da86 | 2006-06-28 10:45:41 -0500 | [diff] [blame] | 206 | static struct pci_controller hose; |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 207 | |
| 208 | #endif /* CONFIG_PCI */ |
| 209 | |
| 210 | |
| 211 | void |
| 212 | pci_init_board(void) |
| 213 | { |
| 214 | #ifdef CONFIG_PCI |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 215 | pci_mpc85xx_init(&hose); |
| 216 | #endif /* CONFIG_PCI */ |
| 217 | } |
Matthew McClintock | 148e26a | 2006-06-28 10:43:36 -0500 | [diff] [blame] | 218 | |
| 219 | |
Kumar Gala | 6e57840 | 2007-11-28 22:54:27 -0600 | [diff] [blame] | 220 | #if defined(CONFIG_OF_BOARD_SETUP) |
Matthew McClintock | 148e26a | 2006-06-28 10:43:36 -0500 | [diff] [blame] | 221 | void |
| 222 | ft_board_setup(void *blob, bd_t *bd) |
| 223 | { |
Kumar Gala | 6e57840 | 2007-11-28 22:54:27 -0600 | [diff] [blame] | 224 | int node, tmp[2]; |
| 225 | const char *path; |
Matthew McClintock | 148e26a | 2006-06-28 10:43:36 -0500 | [diff] [blame] | 226 | |
| 227 | ft_cpu_setup(blob, bd); |
| 228 | |
Kumar Gala | 6e57840 | 2007-11-28 22:54:27 -0600 | [diff] [blame] | 229 | node = fdt_path_offset(blob, "/aliases"); |
| 230 | tmp[0] = 0; |
| 231 | if (node >= 0) { |
| 232 | #ifdef CONFIG_PCI |
| 233 | path = fdt_getprop(blob, node, "pci0", NULL); |
| 234 | if (path) { |
| 235 | tmp[1] = hose.last_busno - hose.first_busno; |
| 236 | do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1); |
| 237 | } |
| 238 | #endif |
Matthew McClintock | 148e26a | 2006-06-28 10:43:36 -0500 | [diff] [blame] | 239 | } |
| 240 | } |
| 241 | #endif |