Paul Gortmaker | 91e2576 | 2007-01-16 11:38:14 -0500 | [diff] [blame] | 1 | /* |
| 2 | * sbc8349.c -- WindRiver SBC8349 board support. |
| 3 | * Copyright (c) 2006-2007 Wind River Systems, Inc. |
| 4 | * |
| 5 | * Paul Gortmaker <paul.gortmaker@windriver.com> |
| 6 | * Based on board/mpc8349emds/mpc8349emds.c (and previous 834x releases.) |
| 7 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 8 | * SPDX-License-Identifier: GPL-2.0+ |
Paul Gortmaker | 91e2576 | 2007-01-16 11:38:14 -0500 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <common.h> |
| 12 | #include <ioports.h> |
| 13 | #include <mpc83xx.h> |
| 14 | #include <asm/mpc8349_pci.h> |
| 15 | #include <i2c.h> |
Paul Gortmaker | 91e2576 | 2007-01-16 11:38:14 -0500 | [diff] [blame] | 16 | #include <spd_sdram.h> |
Jon Loeliger | a30a549 | 2008-03-04 10:03:03 -0600 | [diff] [blame] | 17 | #include <miiphy.h> |
Kim Phillips | b3458d2 | 2007-12-20 15:57:28 -0600 | [diff] [blame] | 18 | #if defined(CONFIG_OF_LIBFDT) |
Paul Gortmaker | 2408b3f | 2007-12-20 12:58:16 -0500 | [diff] [blame] | 19 | #include <libfdt.h> |
Paul Gortmaker | 91e2576 | 2007-01-16 11:38:14 -0500 | [diff] [blame] | 20 | #endif |
| 21 | |
Simon Glass | 088454c | 2017-03-31 08:40:25 -0600 | [diff] [blame] | 22 | DECLARE_GLOBAL_DATA_PTR; |
| 23 | |
Paul Gortmaker | 91e2576 | 2007-01-16 11:38:14 -0500 | [diff] [blame] | 24 | int fixed_sdram(void); |
| 25 | void sdram_init(void); |
| 26 | |
Peter Tyser | 0f89860 | 2009-05-22 17:23:24 -0500 | [diff] [blame] | 27 | #if defined(CONFIG_DDR_ECC) && defined(CONFIG_MPC83xx) |
Paul Gortmaker | 91e2576 | 2007-01-16 11:38:14 -0500 | [diff] [blame] | 28 | void ddr_enable_ecc(unsigned int dram_size); |
| 29 | #endif |
| 30 | |
| 31 | #ifdef CONFIG_BOARD_EARLY_INIT_F |
| 32 | int board_early_init_f (void) |
| 33 | { |
| 34 | return 0; |
| 35 | } |
| 36 | #endif |
| 37 | |
| 38 | #define ns2clk(ns) (ns / (1000000000 / CONFIG_8349_CLKIN) + 1) |
| 39 | |
Simon Glass | f1683aa | 2017-04-06 12:47:05 -0600 | [diff] [blame] | 40 | int dram_init(void) |
Paul Gortmaker | 91e2576 | 2007-01-16 11:38:14 -0500 | [diff] [blame] | 41 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 42 | volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR; |
Paul Gortmaker | 91e2576 | 2007-01-16 11:38:14 -0500 | [diff] [blame] | 43 | u32 msize = 0; |
| 44 | |
| 45 | if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32)im) |
| 46 | return -1; |
| 47 | |
Paul Gortmaker | 91e2576 | 2007-01-16 11:38:14 -0500 | [diff] [blame] | 48 | /* DDR SDRAM - Main SODIMM */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 49 | im->sysconf.ddrlaw[0].bar = CONFIG_SYS_DDR_BASE & LAWBAR_BAR; |
Paul Gortmaker | 91e2576 | 2007-01-16 11:38:14 -0500 | [diff] [blame] | 50 | #if defined(CONFIG_SPD_EEPROM) |
| 51 | msize = spd_sdram(); |
| 52 | #else |
| 53 | msize = fixed_sdram(); |
| 54 | #endif |
| 55 | /* |
| 56 | * Initialize SDRAM if it is on local bus. |
| 57 | */ |
| 58 | sdram_init(); |
| 59 | |
| 60 | #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER) |
| 61 | /* |
| 62 | * Initialize and enable DDR ECC. |
| 63 | */ |
| 64 | ddr_enable_ecc(msize * 1024 * 1024); |
| 65 | #endif |
Simon Glass | 088454c | 2017-03-31 08:40:25 -0600 | [diff] [blame] | 66 | /* set total bus SDRAM size(bytes) -- DDR */ |
| 67 | gd->ram_size = msize * 1024 * 1024; |
| 68 | |
| 69 | return 0; |
Paul Gortmaker | 91e2576 | 2007-01-16 11:38:14 -0500 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | #if !defined(CONFIG_SPD_EEPROM) |
| 73 | /************************************************************************* |
| 74 | * fixed sdram init -- doesn't use serial presence detect. |
| 75 | ************************************************************************/ |
| 76 | int fixed_sdram(void) |
| 77 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 78 | volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR; |
Joe Hershberger | 2e651b2 | 2011-10-11 23:57:31 -0500 | [diff] [blame] | 79 | u32 msize = CONFIG_SYS_DDR_SIZE; |
| 80 | u32 ddr_size = msize << 20; /* DDR size in bytes */ |
| 81 | u32 ddr_size_log2 = __ilog2(msize); |
Paul Gortmaker | 91e2576 | 2007-01-16 11:38:14 -0500 | [diff] [blame] | 82 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 83 | im->sysconf.ddrlaw[0].bar = CONFIG_SYS_DDR_SDRAM_BASE & 0xfffff000; |
Paul Gortmaker | 91e2576 | 2007-01-16 11:38:14 -0500 | [diff] [blame] | 84 | im->sysconf.ddrlaw[0].ar = LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE); |
| 85 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 86 | #if (CONFIG_SYS_DDR_SIZE != 256) |
Paul Gortmaker | 91e2576 | 2007-01-16 11:38:14 -0500 | [diff] [blame] | 87 | #warning Currently any ddr size other than 256 is not supported |
| 88 | #endif |
Joe Hershberger | 2e651b2 | 2011-10-11 23:57:31 -0500 | [diff] [blame] | 89 | |
| 90 | #if ((CONFIG_SYS_DDR_SDRAM_BASE & 0x00FFFFFF) != 0) |
| 91 | #warning Chip select bounds is only configurable in 16MB increments |
| 92 | #endif |
| 93 | im->ddr.csbnds[2].csbnds = |
| 94 | ((CONFIG_SYS_DDR_SDRAM_BASE >> CSBNDS_SA_SHIFT) & CSBNDS_SA) | |
| 95 | (((CONFIG_SYS_DDR_SDRAM_BASE + ddr_size - 1) >> |
| 96 | CSBNDS_EA_SHIFT) & CSBNDS_EA); |
| 97 | im->ddr.cs_config[2] = CONFIG_SYS_DDR_CS2_CONFIG; |
Paul Gortmaker | 91e2576 | 2007-01-16 11:38:14 -0500 | [diff] [blame] | 98 | |
| 99 | /* currently we use only one CS, so disable the other banks */ |
| 100 | im->ddr.cs_config[0] = 0; |
| 101 | im->ddr.cs_config[1] = 0; |
| 102 | im->ddr.cs_config[3] = 0; |
| 103 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 104 | im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1; |
| 105 | im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2; |
Paul Gortmaker | 91e2576 | 2007-01-16 11:38:14 -0500 | [diff] [blame] | 106 | |
| 107 | im->ddr.sdram_cfg = |
| 108 | SDRAM_CFG_SREN |
| 109 | #if defined(CONFIG_DDR_2T_TIMING) |
| 110 | | SDRAM_CFG_2T_EN |
| 111 | #endif |
Kim Phillips | bbea46f | 2007-08-16 22:52:48 -0500 | [diff] [blame] | 112 | | SDRAM_CFG_SDRAM_TYPE_DDR1; |
Paul Gortmaker | 91e2576 | 2007-01-16 11:38:14 -0500 | [diff] [blame] | 113 | #if defined (CONFIG_DDR_32BIT) |
| 114 | /* for 32-bit mode burst length is 8 */ |
| 115 | im->ddr.sdram_cfg |= (SDRAM_CFG_32_BE | SDRAM_CFG_8_BE); |
| 116 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 117 | im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE; |
Paul Gortmaker | 91e2576 | 2007-01-16 11:38:14 -0500 | [diff] [blame] | 118 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 119 | im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL; |
Paul Gortmaker | 91e2576 | 2007-01-16 11:38:14 -0500 | [diff] [blame] | 120 | udelay(200); |
| 121 | |
| 122 | /* enable DDR controller */ |
| 123 | im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN; |
| 124 | return msize; |
| 125 | } |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 126 | #endif/*!CONFIG_SYS_SPD_EEPROM*/ |
Paul Gortmaker | 91e2576 | 2007-01-16 11:38:14 -0500 | [diff] [blame] | 127 | |
| 128 | |
| 129 | int checkboard (void) |
| 130 | { |
| 131 | puts("Board: Wind River SBC834x\n"); |
| 132 | return 0; |
| 133 | } |
| 134 | |
| 135 | /* |
| 136 | * if board is fitted with SDRAM |
| 137 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 138 | #if defined(CONFIG_SYS_BR2_PRELIM) \ |
| 139 | && defined(CONFIG_SYS_OR2_PRELIM) \ |
| 140 | && defined(CONFIG_SYS_LBLAWBAR2_PRELIM) \ |
| 141 | && defined(CONFIG_SYS_LBLAWAR2_PRELIM) |
Paul Gortmaker | 91e2576 | 2007-01-16 11:38:14 -0500 | [diff] [blame] | 142 | /* |
| 143 | * Initialize SDRAM memory on the Local Bus. |
| 144 | */ |
| 145 | |
| 146 | void sdram_init(void) |
| 147 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 148 | volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR; |
Becky Bruce | f51cdaf | 2010-06-17 11:37:20 -0500 | [diff] [blame] | 149 | volatile fsl_lbc_t *lbc = &immap->im_lbc; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 150 | uint *sdram_addr = (uint *)CONFIG_SYS_LBC_SDRAM_BASE; |
Paul Gortmaker | 91e2576 | 2007-01-16 11:38:14 -0500 | [diff] [blame] | 151 | |
| 152 | puts("\n SDRAM on Local Bus: "); |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 153 | print_size (CONFIG_SYS_LBC_SDRAM_SIZE * 1024 * 1024, "\n"); |
Paul Gortmaker | 91e2576 | 2007-01-16 11:38:14 -0500 | [diff] [blame] | 154 | |
| 155 | /* |
| 156 | * Setup SDRAM Base and Option Registers, already done in cpu_init.c |
| 157 | */ |
| 158 | |
| 159 | /* setup mtrpt, lsrt and lbcr for LB bus */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 160 | lbc->lbcr = CONFIG_SYS_LBC_LBCR; |
| 161 | lbc->mrtpr = CONFIG_SYS_LBC_MRTPR; |
| 162 | lbc->lsrt = CONFIG_SYS_LBC_LSRT; |
Paul Gortmaker | 91e2576 | 2007-01-16 11:38:14 -0500 | [diff] [blame] | 163 | asm("sync"); |
| 164 | |
| 165 | /* |
| 166 | * Configure the SDRAM controller Machine Mode Register. |
| 167 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 168 | lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_5; /* 0x40636733; normal operation */ |
Paul Gortmaker | 91e2576 | 2007-01-16 11:38:14 -0500 | [diff] [blame] | 169 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 170 | lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_1; /* 0x68636733; precharge all the banks */ |
Paul Gortmaker | 91e2576 | 2007-01-16 11:38:14 -0500 | [diff] [blame] | 171 | asm("sync"); |
| 172 | *sdram_addr = 0xff; |
| 173 | udelay(100); |
| 174 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 175 | lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_2; /* 0x48636733; auto refresh */ |
Paul Gortmaker | 91e2576 | 2007-01-16 11:38:14 -0500 | [diff] [blame] | 176 | asm("sync"); |
| 177 | /*1 times*/ |
| 178 | *sdram_addr = 0xff; |
| 179 | udelay(100); |
| 180 | /*2 times*/ |
| 181 | *sdram_addr = 0xff; |
| 182 | udelay(100); |
| 183 | /*3 times*/ |
| 184 | *sdram_addr = 0xff; |
| 185 | udelay(100); |
| 186 | /*4 times*/ |
| 187 | *sdram_addr = 0xff; |
| 188 | udelay(100); |
| 189 | /*5 times*/ |
| 190 | *sdram_addr = 0xff; |
| 191 | udelay(100); |
| 192 | /*6 times*/ |
| 193 | *sdram_addr = 0xff; |
| 194 | udelay(100); |
| 195 | /*7 times*/ |
| 196 | *sdram_addr = 0xff; |
| 197 | udelay(100); |
| 198 | /*8 times*/ |
| 199 | *sdram_addr = 0xff; |
| 200 | udelay(100); |
| 201 | |
| 202 | /* 0x58636733; mode register write operation */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 203 | lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_4; |
Paul Gortmaker | 91e2576 | 2007-01-16 11:38:14 -0500 | [diff] [blame] | 204 | asm("sync"); |
| 205 | *sdram_addr = 0xff; |
| 206 | udelay(100); |
| 207 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 208 | lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_5; /* 0x40636733; normal operation */ |
Paul Gortmaker | 91e2576 | 2007-01-16 11:38:14 -0500 | [diff] [blame] | 209 | asm("sync"); |
| 210 | *sdram_addr = 0xff; |
| 211 | udelay(100); |
| 212 | } |
| 213 | #else |
| 214 | void sdram_init(void) |
| 215 | { |
| 216 | puts(" SDRAM on Local Bus: Disabled in config\n"); |
| 217 | } |
| 218 | #endif |
| 219 | |
Paul Gortmaker | 2408b3f | 2007-12-20 12:58:16 -0500 | [diff] [blame] | 220 | #if defined(CONFIG_OF_BOARD_SETUP) |
Simon Glass | e895a4b | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 221 | int ft_board_setup(void *blob, bd_t *bd) |
Paul Gortmaker | 91e2576 | 2007-01-16 11:38:14 -0500 | [diff] [blame] | 222 | { |
Paul Gortmaker | 2408b3f | 2007-12-20 12:58:16 -0500 | [diff] [blame] | 223 | ft_cpu_setup(blob, bd); |
| 224 | #ifdef CONFIG_PCI |
| 225 | ft_pci_setup(blob, bd); |
| 226 | #endif |
Simon Glass | e895a4b | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 227 | |
| 228 | return 0; |
Paul Gortmaker | 91e2576 | 2007-01-16 11:38:14 -0500 | [diff] [blame] | 229 | } |
| 230 | #endif |