blob: 1eeec3f72430fbd6af369d3256e26688dca50c77 [file] [log] [blame]
wdenkb666c8f2003-03-06 00:58:30 +00001/*
Wolfgang Denk23cddaf2011-11-05 05:13:16 +00002 * (C) Copyright 2001-2011
wdenkb666c8f2003-03-06 00:58:30 +00003 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * Modified during 2001 by
6 * Advanced Communications Technologies (Australia) Pty. Ltd.
7 * Howard Walker, Tuong Vu-Dinh
8 *
9 * (C) Copyright 2001, Stuart Hughes, Lineo Inc, stuarth@lineo.com
10 * Added support for the 16M dram simm on the 8260ads boards
11 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +020012 * SPDX-License-Identifier: GPL-2.0+
wdenkb666c8f2003-03-06 00:58:30 +000013 */
14
15#include <common.h>
16#include <ioports.h>
17#include <i2c.h>
18#include <mpc8260.h>
wdenkbf2f8c92003-05-22 22:52:13 +000019#include <pci.h>
wdenkb666c8f2003-03-06 00:58:30 +000020
21/*
22 * PBI Page Based Interleaving
23 * PSDMR_PBI page based interleaving
24 * 0 bank based interleaving
25 * External Address Multiplexing (EAMUX) adds a clock to address cycles
26 * (this can help with marginal board layouts)
27 * PSDMR_EAMUX adds a clock
28 * 0 no extra clock
29 * Buffer Command (BUFCMD) adds a clock to command cycles.
30 * PSDMR_BUFCMD adds a clock
31 * 0 no extra clock
32 */
wdenkf28560f2003-09-12 20:09:09 +000033#define CONFIG_PBI 0
wdenkb666c8f2003-03-06 00:58:30 +000034#define PESSIMISTIC_SDRAM 0
35#define EAMUX 0 /* EST requires EAMUX */
36#define BUFCMD 0
37
38
39/*
40 * I/O Port configuration table
41 *
42 * if conf is 1, then that port pin will be configured at boot time
43 * according to the five values podr/pdir/ppar/psor/pdat for that entry
44 */
45
46const iop_conf_t iop_conf_tab[4][32] = {
47
Wolfgang Denk23cddaf2011-11-05 05:13:16 +000048 /* Port A configuration */
49 { /* conf ppar psor pdir podr pdat */
wdenk57b2d802003-06-27 21:31:46 +000050 /* PA31 */ { 0, 1, 0, 1, 0, 0 }, /* FCC1 TxENB */
wdenkb666c8f2003-03-06 00:58:30 +000051 /* PA30 */ { 0, 1, 0, 0, 0, 0 }, /* FCC1 TxClav */
52 /* PA29 */ { 0, 1, 0, 1, 0, 0 }, /* FCC1 TxSOC */
53 /* PA28 */ { 0, 1, 0, 1, 0, 0 }, /* FCC1 RxENB */
54 /* PA27 */ { 0, 1, 0, 0, 0, 0 }, /* FCC1 RxSOC */
55 /* PA26 */ { 0, 1, 0, 0, 0, 0 }, /* FCC1 RxClav */
56 /* PA25 */ { 0, 1, 0, 1, 0, 0 }, /* FCC1 ATMTXD[0] */
57 /* PA24 */ { 0, 1, 0, 1, 0, 0 }, /* FCC1 ATMTXD[1] */
58 /* PA23 */ { 0, 1, 0, 1, 0, 0 }, /* FCC1 ATMTXD[2] */
59 /* PA22 */ { 0, 1, 0, 1, 0, 0 }, /* FCC1 ATMTXD[3] */
60 /* PA21 */ { 0, 1, 0, 1, 0, 0 }, /* FCC1 ATMTXD[4] */
61 /* PA20 */ { 0, 1, 0, 1, 0, 0 }, /* FCC1 ATMTXD[5] */
62 /* PA19 */ { 0, 1, 0, 1, 0, 0 }, /* FCC1 ATMTXD[6] */
63 /* PA18 */ { 0, 1, 0, 1, 0, 0 }, /* FCC1 ATMTXD[7] */
64 /* PA17 */ { 0, 1, 0, 0, 0, 0 }, /* FCC1 ATMRXD[7] */
65 /* PA16 */ { 0, 1, 0, 0, 0, 0 }, /* FCC1 ATMRXD[6] */
66 /* PA15 */ { 0, 1, 0, 0, 0, 0 }, /* FCC1 ATMRXD[5] */
67 /* PA14 */ { 0, 1, 0, 0, 0, 0 }, /* FCC1 ATMRXD[4] */
68 /* PA13 */ { 0, 1, 0, 0, 0, 0 }, /* FCC1 ATMRXD[3] */
69 /* PA12 */ { 0, 1, 0, 0, 0, 0 }, /* FCC1 ATMRXD[2] */
70 /* PA11 */ { 0, 1, 0, 0, 0, 0 }, /* FCC1 ATMRXD[1] */
71 /* PA10 */ { 0, 1, 0, 0, 0, 0 }, /* FCC1 ATMRXD[0] */
72 /* PA9 */ { 0, 1, 1, 1, 0, 0 }, /* FCC1 L1TXD */
73 /* PA8 */ { 0, 1, 1, 0, 0, 0 }, /* FCC1 L1RXD */
74 /* PA7 */ { 0, 0, 0, 1, 0, 0 }, /* PA7 */
75 /* PA6 */ { 1, 1, 1, 1, 0, 0 }, /* TDM A1 L1RSYNC */
76 /* PA5 */ { 0, 0, 0, 1, 0, 0 }, /* PA5 */
77 /* PA4 */ { 0, 0, 0, 1, 0, 0 }, /* PA4 */
78 /* PA3 */ { 0, 0, 0, 1, 0, 0 }, /* PA3 */
79 /* PA2 */ { 0, 0, 0, 1, 0, 0 }, /* PA2 */
80 /* PA1 */ { 1, 0, 0, 0, 0, 0 }, /* FREERUN */
81 /* PA0 */ { 0, 0, 0, 1, 0, 0 } /* PA0 */
Wolfgang Denk23cddaf2011-11-05 05:13:16 +000082 },
wdenkb666c8f2003-03-06 00:58:30 +000083
Wolfgang Denk23cddaf2011-11-05 05:13:16 +000084 /* Port B configuration */
85 { /* conf ppar psor pdir podr pdat */
wdenkb666c8f2003-03-06 00:58:30 +000086 /* PB31 */ { 1, 1, 0, 1, 0, 0 }, /* FCC2 MII TX_ER */
87 /* PB30 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII RX_DV */
88 /* PB29 */ { 1, 1, 1, 1, 0, 0 }, /* FCC2 MII TX_EN */
89 /* PB28 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII RX_ER */
90 /* PB27 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII COL */
91 /* PB26 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII CRS */
92 /* PB25 */ { 1, 1, 0, 1, 0, 0 }, /* FCC2 MII TxD[3] */
93 /* PB24 */ { 1, 1, 0, 1, 0, 0 }, /* FCC2 MII TxD[2] */
94 /* PB23 */ { 1, 1, 0, 1, 0, 0 }, /* FCC2 MII TxD[1] */
95 /* PB22 */ { 1, 1, 0, 1, 0, 0 }, /* FCC2 MII TxD[0] */
96 /* PB21 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII RxD[0] */
97 /* PB20 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII RxD[1] */
98 /* PB19 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII RxD[2] */
99 /* PB18 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII RxD[3] */
100 /* PB17 */ { 0, 1, 0, 0, 0, 0 }, /* FCC3:RX_DIV */
101 /* PB16 */ { 0, 1, 0, 0, 0, 0 }, /* FCC3:RX_ERR */
102 /* PB15 */ { 0, 1, 0, 1, 0, 0 }, /* FCC3:TX_ERR */
103 /* PB14 */ { 0, 1, 0, 1, 0, 0 }, /* FCC3:TX_EN */
104 /* PB13 */ { 0, 1, 0, 0, 0, 0 }, /* FCC3:COL */
105 /* PB12 */ { 0, 1, 0, 0, 0, 0 }, /* FCC3:CRS */
106 /* PB11 */ { 0, 1, 0, 0, 0, 0 }, /* FCC3:RXD */
107 /* PB10 */ { 0, 1, 0, 0, 0, 0 }, /* FCC3:RXD */
108 /* PB9 */ { 0, 1, 0, 0, 0, 0 }, /* FCC3:RXD */
109 /* PB8 */ { 0, 1, 0, 0, 0, 0 }, /* FCC3:RXD */
110 /* PB7 */ { 0, 1, 0, 1, 0, 0 }, /* FCC3:TXD */
111 /* PB6 */ { 0, 1, 0, 1, 0, 0 }, /* FCC3:TXD */
112 /* PB5 */ { 0, 1, 0, 1, 0, 0 }, /* FCC3:TXD */
113 /* PB4 */ { 0, 1, 0, 1, 0, 0 }, /* FCC3:TXD */
114 /* PB3 */ { 0, 0, 0, 0, 0, 0 }, /* pin doesn't exist */
115 /* PB2 */ { 0, 0, 0, 0, 0, 0 }, /* pin doesn't exist */
116 /* PB1 */ { 0, 0, 0, 0, 0, 0 }, /* pin doesn't exist */
117 /* PB0 */ { 0, 0, 0, 0, 0, 0 } /* pin doesn't exist */
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000118 },
wdenkb666c8f2003-03-06 00:58:30 +0000119
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000120 /* Port C */
121 { /* conf ppar psor pdir podr pdat */
wdenkb666c8f2003-03-06 00:58:30 +0000122 /* PC31 */ { 0, 0, 0, 1, 0, 0 }, /* PC31 */
123 /* PC30 */ { 0, 0, 0, 1, 0, 0 }, /* PC30 */
124 /* PC29 */ { 0, 1, 1, 0, 0, 0 }, /* SCC1 EN *CLSN */
125 /* PC28 */ { 0, 0, 0, 1, 0, 0 }, /* PC28 */
126 /* PC27 */ { 0, 0, 0, 1, 0, 0 }, /* UART Clock in */
127 /* PC26 */ { 0, 0, 0, 1, 0, 0 }, /* PC26 */
128 /* PC25 */ { 0, 0, 0, 1, 0, 0 }, /* PC25 */
129 /* PC24 */ { 0, 0, 0, 1, 0, 0 }, /* PC24 */
130 /* PC23 */ { 0, 1, 0, 1, 0, 0 }, /* ATMTFCLK */
131 /* PC22 */ { 0, 1, 0, 0, 0, 0 }, /* ATMRFCLK */
132 /* PC21 */ { 0, 1, 0, 0, 0, 0 }, /* SCC1 EN RXCLK */
133 /* PC20 */ { 0, 1, 0, 0, 0, 0 }, /* SCC1 EN TXCLK */
134 /* PC19 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII RX_CLK CLK13 */
135 /* PC18 */ { 1, 1, 0, 0, 0, 0 }, /* FCC Tx Clock (CLK14) */
136 /* PC17 */ { 0, 0, 0, 1, 0, 0 }, /* PC17 */
137 /* PC16 */ { 0, 1, 0, 0, 0, 0 }, /* FCC Tx Clock (CLK16) */
138 /* PC15 */ { 0, 0, 0, 1, 0, 0 }, /* PC15 */
139 /* PC14 */ { 0, 1, 0, 0, 0, 0 }, /* SCC1 EN *CD */
140 /* PC13 */ { 0, 0, 0, 1, 0, 0 }, /* PC13 */
141 /* PC12 */ { 0, 1, 0, 1, 0, 0 }, /* PC12 */
142 /* PC11 */ { 0, 0, 0, 1, 0, 0 }, /* LXT971 transmit control */
wdenkbf2f8c92003-05-22 22:52:13 +0000143 /* PC10 */ { 1, 0, 0, 1, 0, 0 }, /* LXT970 FETHMDC */
144 /* PC9 */ { 1, 0, 0, 0, 0, 0 }, /* LXT970 FETHMDIO */
wdenkb666c8f2003-03-06 00:58:30 +0000145 /* PC8 */ { 0, 0, 0, 1, 0, 0 }, /* PC8 */
146 /* PC7 */ { 0, 0, 0, 1, 0, 0 }, /* PC7 */
147 /* PC6 */ { 0, 0, 0, 1, 0, 0 }, /* PC6 */
148 /* PC5 */ { 0, 0, 0, 1, 0, 0 }, /* PC5 */
149 /* PC4 */ { 0, 0, 0, 1, 0, 0 }, /* PC4 */
150 /* PC3 */ { 0, 0, 0, 1, 0, 0 }, /* PC3 */
151 /* PC2 */ { 0, 0, 0, 1, 0, 1 }, /* ENET FDE */
152 /* PC1 */ { 0, 0, 0, 1, 0, 0 }, /* ENET DSQE */
153 /* PC0 */ { 0, 0, 0, 1, 0, 0 }, /* ENET LBK */
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000154 },
wdenkb666c8f2003-03-06 00:58:30 +0000155
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000156 /* Port D */
157 { /* conf ppar psor pdir podr pdat */
wdenkb666c8f2003-03-06 00:58:30 +0000158 /* PD31 */ { 1, 1, 0, 0, 0, 0 }, /* SCC1 EN RxD */
159 /* PD30 */ { 1, 1, 1, 1, 0, 0 }, /* SCC1 EN TxD */
160 /* PD29 */ { 0, 1, 0, 1, 0, 0 }, /* SCC1 EN TENA */
161 /* PD28 */ { 0, 1, 0, 0, 0, 0 }, /* PD28 */
162 /* PD27 */ { 0, 1, 1, 1, 0, 0 }, /* PD27 */
163 /* PD26 */ { 0, 0, 0, 1, 0, 0 }, /* PD26 */
164 /* PD25 */ { 0, 0, 0, 1, 0, 0 }, /* PD25 */
165 /* PD24 */ { 0, 0, 0, 1, 0, 0 }, /* PD24 */
166 /* PD23 */ { 0, 0, 0, 1, 0, 0 }, /* PD23 */
167 /* PD22 */ { 0, 0, 0, 1, 0, 0 }, /* PD22 */
168 /* PD21 */ { 0, 0, 0, 1, 0, 0 }, /* PD21 */
169 /* PD20 */ { 0, 0, 0, 1, 0, 0 }, /* PD20 */
170 /* PD19 */ { 0, 0, 0, 1, 0, 0 }, /* PD19 */
171 /* PD18 */ { 0, 0, 0, 1, 0, 0 }, /* PD18 */
172 /* PD17 */ { 0, 1, 0, 0, 0, 0 }, /* FCC1 ATMRXPRTY */
173 /* PD16 */ { 0, 1, 0, 1, 0, 0 }, /* FCC1 ATMTXPRTY */
174 /* PD15 */ { 1, 1, 1, 0, 1, 0 }, /* I2C SDA */
175 /* PD14 */ { 1, 1, 1, 0, 1, 0 }, /* I2C SCL */
176 /* PD13 */ { 0, 0, 0, 0, 0, 0 }, /* PD13 */
177 /* PD12 */ { 0, 0, 0, 0, 0, 0 }, /* PD12 */
178 /* PD11 */ { 0, 0, 0, 0, 0, 0 }, /* PD11 */
179 /* PD10 */ { 0, 0, 0, 0, 0, 0 }, /* PD10 */
180 /* PD9 */ { 1, 1, 0, 1, 0, 0 }, /* SMC1 TXD */
181 /* PD8 */ { 1, 1, 0, 0, 0, 0 }, /* SMC1 RXD */
182 /* PD7 */ { 0, 0, 0, 1, 0, 1 }, /* PD7 */
183 /* PD6 */ { 0, 0, 0, 1, 0, 1 }, /* PD6 */
184 /* PD5 */ { 0, 0, 0, 1, 0, 1 }, /* PD5 */
185 /* PD4 */ { 0, 0, 0, 1, 0, 1 }, /* PD4 */
186 /* PD3 */ { 0, 0, 0, 0, 0, 0 }, /* pin doesn't exist */
187 /* PD2 */ { 0, 0, 0, 0, 0, 0 }, /* pin doesn't exist */
188 /* PD1 */ { 0, 0, 0, 0, 0, 0 }, /* pin doesn't exist */
189 /* PD0 */ { 0, 0, 0, 0, 0, 0 } /* pin doesn't exist */
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000190 }
wdenkb666c8f2003-03-06 00:58:30 +0000191};
192
193typedef struct bscr_ {
194 unsigned long bcsr0;
195 unsigned long bcsr1;
196 unsigned long bcsr2;
197 unsigned long bcsr3;
198 unsigned long bcsr4;
199 unsigned long bcsr5;
200 unsigned long bcsr6;
201 unsigned long bcsr7;
202} bcsr_t;
203
wdenkbf2f8c92003-05-22 22:52:13 +0000204typedef struct pci_ic_s {
205 unsigned long pci_int_stat;
206 unsigned long pci_int_mask;
207} pci_ic_t;
208
wdenkb666c8f2003-03-06 00:58:30 +0000209void reset_phy(void)
210{
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000211 volatile bcsr_t *bcsr = (bcsr_t *)CONFIG_SYS_BCSR;
wdenkb666c8f2003-03-06 00:58:30 +0000212
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000213 /* reset the FEC port */
214 bcsr->bcsr1 &= ~FETH_RST;
215 bcsr->bcsr1 |= FETH_RST;
wdenkb666c8f2003-03-06 00:58:30 +0000216}
217
218
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000219int board_early_init_f(void)
wdenkb666c8f2003-03-06 00:58:30 +0000220{
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000221 volatile bcsr_t *bcsr = (bcsr_t *)CONFIG_SYS_BCSR;
222 volatile pci_ic_t *pci_ic = (pci_ic_t *)CONFIG_SYS_PCI_INT;
wdenkbf2f8c92003-05-22 22:52:13 +0000223
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000224 bcsr->bcsr1 = ~FETHIEN & ~RS232EN_1 & ~RS232EN_2;
wdenkb666c8f2003-03-06 00:58:30 +0000225
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000226 /* mask all PCI interrupts */
227 pci_ic->pci_int_mask |= 0xfff00000;
wdenk57b2d802003-06-27 21:31:46 +0000228
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000229 return 0;
wdenkb666c8f2003-03-06 00:58:30 +0000230}
231
232int checkboard(void)
233{
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000234 puts("Board: Motorola MPC8266ADS\n");
235 return 0;
wdenkb666c8f2003-03-06 00:58:30 +0000236}
237
Becky Brucebd99ae72008-06-09 16:03:40 -0500238phys_size_t initdram(int board_type)
wdenkb666c8f2003-03-06 00:58:30 +0000239{
240 /* Autoinit part stolen from board/sacsng/sacsng.c */
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000241 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
242 volatile memctl8260_t *memctl = &immap->im_memctl;
243 volatile uchar c = 0xff;
244 volatile uchar *ramaddr = (uchar *) (CONFIG_SYS_SDRAM_BASE + 0x8);
245 uint psdmr = CONFIG_SYS_PSDMR;
246 int i;
wdenkb666c8f2003-03-06 00:58:30 +0000247
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000248 uint psrt = 0x21; /* for no SPD */
249 uint chipselects = 1; /* for no SPD */
250 uint sdram_size = CONFIG_SYS_SDRAM_SIZE * 1024 * 1024; /* for no SPD */
251 uint or = CONFIG_SYS_OR2_PRELIM; /* for no SPD */
252 uint data_width;
253 uint rows;
254 uint banks;
255 uint cols;
256 uint caslatency;
257 uint width;
258 uint rowst;
259 uint sdam;
260 uint bsma;
261 uint sda10;
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000262 u_char data;
263 u_char cksum;
264 int j;
wdenkb666c8f2003-03-06 00:58:30 +0000265
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000266 /*
267 * Keep the compiler from complaining about
268 * potentially uninitialized vars
269 */
270 data_width = rows = banks = cols = caslatency = 0;
wdenkb666c8f2003-03-06 00:58:30 +0000271
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000272 /*
273 * Read the SDRAM SPD EEPROM via I2C.
274 */
275 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
wdenkb666c8f2003-03-06 00:58:30 +0000276
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000277 i2c_read(SDRAM_SPD_ADDR, 0, 1, &data, 1);
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000278 cksum = data;
279 for (j = 1; j < 64; j++) { /* read only the checksummed bytes */
280 /* note: the I2C address autoincrements when alen == 0 */
wdenkb666c8f2003-03-06 00:58:30 +0000281 i2c_read(SDRAM_SPD_ADDR, 0, 0, &data, 1);
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000282 /*printf("addr %d = 0x%02x\n", j, data); */
283 if (j == 5)
284 chipselects = data & 0x0F;
285 else if (j == 6)
286 data_width = data;
287 else if (j == 7)
288 data_width |= data << 8;
289 else if (j == 3)
290 rows = data & 0x0F;
291 else if (j == 4)
292 cols = data & 0x0F;
293 else if (j == 12) {
wdenkb666c8f2003-03-06 00:58:30 +0000294 /*
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000295 * Refresh rate: this assumes the prescaler is set to
296 * approximately 0.39uSec per tick and the target
297 * refresh period is about 85% of maximum.
wdenkb666c8f2003-03-06 00:58:30 +0000298 */
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000299 switch (data & 0x7F) {
300 default:
301 case 0:
302 psrt = 0x21; /* 15.625uS */
303 break;
304 case 1:
305 psrt = 0x07; /* 3.9uS */
306 break;
307 case 2:
308 psrt = 0x0F; /* 7.8uS */
309 break;
310 case 3:
311 psrt = 0x43; /* 31.3uS */
312 break;
313 case 4:
314 psrt = 0x87; /* 62.5uS */
315 break;
316 case 5:
317 psrt = 0xFF; /* 125uS */
318 break;
wdenkb666c8f2003-03-06 00:58:30 +0000319 }
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000320 } else if (j == 17)
321 banks = data;
322 else if (j == 18) {
323 caslatency = 3; /* default CL */
324#if (PESSIMISTIC_SDRAM)
325 if ((data & 0x04) != 0)
326 caslatency = 3;
327 else if ((data & 0x02) != 0)
328 caslatency = 2;
329 else if ((data & 0x01) != 0)
330 caslatency = 1;
331#else
332 if ((data & 0x01) != 0)
333 caslatency = 1;
334 else if ((data & 0x02) != 0)
335 caslatency = 2;
336 else if ((data & 0x04) != 0)
337 caslatency = 3;
338#endif
339 else {
340 printf("WARNING: Unknown CAS latency 0x%02X, using 3\n",
wdenkb666c8f2003-03-06 00:58:30 +0000341 data);
342 }
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000343 } else if (j == 63) {
344 if (data != cksum) {
345 printf("WARNING: Configuration data checksum failure:"
wdenkb666c8f2003-03-06 00:58:30 +0000346 " is 0x%02x, calculated 0x%02x\n",
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000347 data, cksum);
wdenkb666c8f2003-03-06 00:58:30 +0000348 }
349 }
350 cksum += data;
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000351 }
wdenkb666c8f2003-03-06 00:58:30 +0000352
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000353 /* We don't trust CL less than 2 (only saw it on an old 16MByte DIMM) */
354 if (caslatency < 2) {
wdenkb666c8f2003-03-06 00:58:30 +0000355 printf("CL was %d, forcing to 2\n", caslatency);
356 caslatency = 2;
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000357 }
358 if (rows > 14) {
359 printf("This doesn't look good, rows = %d, should be <= 14\n",
360 rows);
wdenkb666c8f2003-03-06 00:58:30 +0000361 rows = 14;
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000362 }
363 if (cols > 11) {
364 printf("This doesn't look good, columns = %d, should be <= 11\n",
365 cols);
wdenkb666c8f2003-03-06 00:58:30 +0000366 cols = 11;
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000367 }
wdenkb666c8f2003-03-06 00:58:30 +0000368
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000369 if ((data_width != 64) && (data_width != 72)) {
wdenkb666c8f2003-03-06 00:58:30 +0000370 printf("WARNING: SDRAM width unsupported, is %d, expected 64 or 72.\n",
371 data_width);
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000372 }
373 width = 3; /* 2^3 = 8 bytes = 64 bits wide */
374 /*
375 * Convert banks into log2(banks)
376 */
377 if (banks == 2)
378 banks = 1;
379 else if (banks == 4)
380 banks = 2;
381 else if (banks == 8)
382 banks = 3;
wdenkb666c8f2003-03-06 00:58:30 +0000383
384
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000385 sdram_size = 1 << (rows + cols + banks + width);
386 /* hack for high density memory (512MB per CS) */
387 /* !!!!! Will ONLY work with Page Based Interleave !!!!!
388 ( PSDMR[PBI] = 1 )
389 */
390 /*
391 * memory actually has 11 column addresses, but the memory
392 * controller doesn't really care.
393 *
394 * the calculations that follow will however move the rows so
395 * that they are muxed one bit off if you use 11 bit columns.
396 *
397 * The solution is to tell the memory controller the correct
398 * size of the memory but change the number of columns to 10
399 * afterwards.
400 *
401 * The 11th column addre will still be mucxed correctly onto
402 * the bus.
403 *
404 * Also be aware that the MPC8266ADS board Rev B has not
405 * connected Row address 13 to anything.
406 *
407 * The fix is to connect ADD16 (from U37-47) to SADDR12 (U28-126)
408 */
409 if (cols > 10)
410 cols = 10;
wdenk56958612003-06-22 17:18:28 +0000411
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000412#if (CONFIG_PBI == 0) /* bank-based interleaving */
413 rowst = ((32 - 6) - (rows + cols + width)) * 2;
wdenkb666c8f2003-03-06 00:58:30 +0000414#else
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000415 rowst = 32 - (rows + banks + cols + width);
wdenkb666c8f2003-03-06 00:58:30 +0000416#endif
417
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000418 or = ~(sdram_size - 1) | /* SDAM address mask */
419 ((banks - 1) << 13) | /* banks per device */
420 (rowst << 9) | /* rowst */
421 ((rows - 9) << 6); /* numr */
wdenkb666c8f2003-03-06 00:58:30 +0000422
423
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000424 /*printf("memctl->memc_or2 = 0x%08x\n", or); */
wdenkb666c8f2003-03-06 00:58:30 +0000425
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000426 /*
427 * SDAM specifies the number of columns that are multiplexed
428 * (reference AN2165/D), defined to be (columns - 6) for page
429 * interleave, (columns - 8) for bank interleave.
430 *
431 * BSMA is 14 - max(rows, cols). The bank select lines come
432 * into play above the highest "address" line going into the
433 * the SDRAM.
434 */
435#if (CONFIG_PBI == 0) /* bank-based interleaving */
436 sdam = cols - 8;
437 bsma = ((31 - width) - 14) - ((rows > cols) ? rows : cols);
438 sda10 = sdam + 2;
wdenkb666c8f2003-03-06 00:58:30 +0000439#else
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000440 sdam = cols + banks - 8;
441 bsma = ((31 - width) - 14) - ((rows > cols) ? rows : cols);
442 sda10 = sdam;
wdenkb666c8f2003-03-06 00:58:30 +0000443#endif
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000444#if (PESSIMISTIC_SDRAM)
445 psdmr = (CONFIG_PBI | PSDMR_RFEN | PSDMR_RFRC_16_CLK |
446 PSDMR_PRETOACT_8W | PSDMR_ACTTORW_8W | PSDMR_WRC_4C |
447 PSDMR_EAMUX | PSDMR_BUFCMD) | caslatency |
448 ((caslatency - 1) << 6) | /* LDOTOPRE is CL - 1 */
449 (sdam << 24) | (bsma << 21) | (sda10 << 18);
wdenkb666c8f2003-03-06 00:58:30 +0000450#else
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000451 psdmr = (CONFIG_PBI | PSDMR_RFEN | PSDMR_RFRC_7_CLK |
452 PSDMR_PRETOACT_3W | /* 1 for 7E parts (fast PC-133) */
453 PSDMR_ACTTORW_2W | /* 1 for 7E parts (fast PC-133) */
454 PSDMR_WRC_1C | /* 1 clock + 7nSec */
455 EAMUX | BUFCMD) | caslatency |
456 ((caslatency - 1) << 6) | /* LDOTOPRE is CL - 1 */
457 (sdam << 24) | (bsma << 21) | (sda10 << 18);
wdenkb666c8f2003-03-06 00:58:30 +0000458#endif
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000459 /*printf("psdmr = 0x%08x\n", psdmr); */
wdenkb666c8f2003-03-06 00:58:30 +0000460
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000461 /*
462 * Quote from 8260 UM (10.4.2 SDRAM Power-On Initialization, 10-35):
463 *
464 * "At system reset, initialization software must set up the
465 * programmable parameters in the memory controller banks registers
466 * (ORx, BRx, P/LSDMR). After all memory parameters are configured,
467 * system software should execute the following initialization sequence
468 * for each SDRAM device.
469 *
470 * 1. Issue a PRECHARGE-ALL-BANKS command
471 * 2. Issue eight CBR REFRESH commands
472 * 3. Issue a MODE-SET command to initialize the mode register
473 *
474 * Quote from Micron MT48LC8M16A2 data sheet:
475 *
476 * "...the SDRAM requires a 100uS delay prior to issuing any
477 * command other than a COMMAND INHIBIT or NOP. Starting at some
478 * point during this 100uS period and continuing at least through
479 * the end of this period, COMMAND INHIBIT or NOP commands should
480 * be applied."
481 *
482 * "Once the 100uS delay has been satisfied with at least one COMMAND
483 * INHIBIT or NOP command having been applied, a /PRECHARGE command/
484 * should be applied. All banks must then be precharged, thereby
485 * placing the device in the all banks idle state."
486 *
487 * "Once in the idle state, /two/ AUTO REFRESH cycles must be
488 * performed. After the AUTO REFRESH cycles are complete, the
489 * SDRAM is ready for mode register programming."
490 *
491 * (/emphasis/ mine, gvb)
492 *
493 * The way I interpret this, Micron start up sequence is:
494 * 1. Issue a PRECHARGE-BANK command (initial precharge)
495 * 2. Issue a PRECHARGE-ALL-BANKS command ("all banks ... precharged")
496 * 3. Issue two (presumably, doing eight is OK) CBR REFRESH commands
497 * 4. Issue a MODE-SET command to initialize the mode register
498 *
499 * --------
500 *
501 * The initial commands are executed by setting P/LSDMR[OP] and
502 * accessing the SDRAM with a single-byte transaction."
503 *
504 * The appropriate BRx/ORx registers have already been set
505 * when we get here. The SDRAM can be accessed at the address
506 * CONFIG_SYS_SDRAM_BASE.
507 */
wdenkabda5ca2003-05-31 18:35:21 +0000508
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000509 memctl->memc_mptpr = CONFIG_SYS_MPTPR;
510 memctl->memc_psrt = psrt;
wdenkb666c8f2003-03-06 00:58:30 +0000511
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000512 memctl->memc_br2 = CONFIG_SYS_BR2_PRELIM;
513 memctl->memc_or2 = or;
wdenk57b2d802003-06-27 21:31:46 +0000514
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000515 memctl->memc_psdmr = psdmr | PSDMR_OP_PREA;
wdenkb666c8f2003-03-06 00:58:30 +0000516 *ramaddr = c;
517
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000518 memctl->memc_psdmr = psdmr | PSDMR_OP_CBRR;
519 for (i = 0; i < 8; i++)
520 *ramaddr = c;
521
522 memctl->memc_psdmr = psdmr | PSDMR_OP_MRW;
523 *ramaddr = c;
wdenkb666c8f2003-03-06 00:58:30 +0000524
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000525 memctl->memc_psdmr = psdmr | PSDMR_OP_NORM | PSDMR_RFEN;
526 *ramaddr = c;
wdenkb666c8f2003-03-06 00:58:30 +0000527
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000528 /*
529 * Do it a second time for the second set of chips if the DIMM has
530 * two chip selects (double sided).
531 */
532 if (chipselects > 1) {
533 ramaddr += sdram_size;
wdenkb666c8f2003-03-06 00:58:30 +0000534
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200535 memctl->memc_br3 = CONFIG_SYS_BR3_PRELIM + sdram_size;
wdenkb666c8f2003-03-06 00:58:30 +0000536 memctl->memc_or3 = or;
537
538 memctl->memc_psdmr = psdmr | PSDMR_OP_PREA;
539 *ramaddr = c;
540
541 memctl->memc_psdmr = psdmr | PSDMR_OP_CBRR;
542 for (i = 0; i < 8; i++)
543 *ramaddr = c;
544
545 memctl->memc_psdmr = psdmr | PSDMR_OP_MRW;
546 *ramaddr = c;
547
548 memctl->memc_psdmr = psdmr | PSDMR_OP_NORM | PSDMR_RFEN;
549 *ramaddr = c;
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000550 }
wdenkb666c8f2003-03-06 00:58:30 +0000551
wdenkb666c8f2003-03-06 00:58:30 +0000552 /* print info */
553 printf("SDRAM configuration read from SPD\n");
554 printf("\tSize per side = %dMB\n", sdram_size >> 20);
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000555 printf("\tOrganization: %d sides, %d banks, %d Columns, %d Rows, Data width = %d bits\n",
556 chipselects, 1 << (banks), cols, rows, data_width);
wdenk5256def2003-09-18 10:45:21 +0000557 printf("\tRefresh rate = %d, CAS latency = %d", psrt, caslatency);
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000558#if (CONFIG_PBI == 0) /* bank-based interleaving */
559 printf(", Using Bank Based Interleave\n");
wdenk5256def2003-09-18 10:45:21 +0000560#else
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000561 printf(", Using Page Based Interleave\n");
wdenk9c53f402003-10-15 23:53:47 +0000562#endif
wdenkb666c8f2003-03-06 00:58:30 +0000563 printf("\tTotal size: ");
564
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000565 /* this delay only needed for original 16MB DIMM...
566 * Not needed for any other memory configuration */
567 if ((sdram_size * chipselects) == (16 * 1024 * 1024))
568 udelay(250000);
wdenkbf2f8c92003-05-22 22:52:13 +0000569
Wolfgang Denk23cddaf2011-11-05 05:13:16 +0000570 return sdram_size * chipselects;
571}
wdenkabda5ca2003-05-31 18:35:21 +0000572
wdenkbf2f8c92003-05-22 22:52:13 +0000573#ifdef CONFIG_PCI
574struct pci_controller hose;
575
576extern void pci_mpc8250_init(struct pci_controller *);
577
578void pci_init_board(void)
579{
580 pci_mpc8250_init(&hose);
581}
582#endif