blob: 5d489681842d24816461b60422fa9f21621d5244 [file] [log] [blame]
wdenkdb2f721f2003-03-06 00:58:30 +00001/*
Wolfgang Denk55e33272011-11-05 05:13:16 +00002 * (C) Copyright 2001-2011
wdenkdb2f721f2003-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 *
12 * See file CREDITS for list of people who contributed to this
13 * project.
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License as
17 * published by the Free Software Foundation; either version 2 of
18 * the License, or (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 * MA 02111-1307 USA
29 */
30
31#include <common.h>
32#include <ioports.h>
33#include <i2c.h>
34#include <mpc8260.h>
wdenk5d232d02003-05-22 22:52:13 +000035#include <pci.h>
wdenkdb2f721f2003-03-06 00:58:30 +000036
37/*
38 * PBI Page Based Interleaving
39 * PSDMR_PBI page based interleaving
40 * 0 bank based interleaving
41 * External Address Multiplexing (EAMUX) adds a clock to address cycles
42 * (this can help with marginal board layouts)
43 * PSDMR_EAMUX adds a clock
44 * 0 no extra clock
45 * Buffer Command (BUFCMD) adds a clock to command cycles.
46 * PSDMR_BUFCMD adds a clock
47 * 0 no extra clock
48 */
wdenkb70e7a02003-09-12 20:09:09 +000049#define CONFIG_PBI 0
wdenkdb2f721f2003-03-06 00:58:30 +000050#define PESSIMISTIC_SDRAM 0
51#define EAMUX 0 /* EST requires EAMUX */
52#define BUFCMD 0
53
54
55/*
56 * I/O Port configuration table
57 *
58 * if conf is 1, then that port pin will be configured at boot time
59 * according to the five values podr/pdir/ppar/psor/pdat for that entry
60 */
61
62const iop_conf_t iop_conf_tab[4][32] = {
63
Wolfgang Denk55e33272011-11-05 05:13:16 +000064 /* Port A configuration */
65 { /* conf ppar psor pdir podr pdat */
wdenk8bde7f72003-06-27 21:31:46 +000066 /* PA31 */ { 0, 1, 0, 1, 0, 0 }, /* FCC1 TxENB */
wdenkdb2f721f2003-03-06 00:58:30 +000067 /* PA30 */ { 0, 1, 0, 0, 0, 0 }, /* FCC1 TxClav */
68 /* PA29 */ { 0, 1, 0, 1, 0, 0 }, /* FCC1 TxSOC */
69 /* PA28 */ { 0, 1, 0, 1, 0, 0 }, /* FCC1 RxENB */
70 /* PA27 */ { 0, 1, 0, 0, 0, 0 }, /* FCC1 RxSOC */
71 /* PA26 */ { 0, 1, 0, 0, 0, 0 }, /* FCC1 RxClav */
72 /* PA25 */ { 0, 1, 0, 1, 0, 0 }, /* FCC1 ATMTXD[0] */
73 /* PA24 */ { 0, 1, 0, 1, 0, 0 }, /* FCC1 ATMTXD[1] */
74 /* PA23 */ { 0, 1, 0, 1, 0, 0 }, /* FCC1 ATMTXD[2] */
75 /* PA22 */ { 0, 1, 0, 1, 0, 0 }, /* FCC1 ATMTXD[3] */
76 /* PA21 */ { 0, 1, 0, 1, 0, 0 }, /* FCC1 ATMTXD[4] */
77 /* PA20 */ { 0, 1, 0, 1, 0, 0 }, /* FCC1 ATMTXD[5] */
78 /* PA19 */ { 0, 1, 0, 1, 0, 0 }, /* FCC1 ATMTXD[6] */
79 /* PA18 */ { 0, 1, 0, 1, 0, 0 }, /* FCC1 ATMTXD[7] */
80 /* PA17 */ { 0, 1, 0, 0, 0, 0 }, /* FCC1 ATMRXD[7] */
81 /* PA16 */ { 0, 1, 0, 0, 0, 0 }, /* FCC1 ATMRXD[6] */
82 /* PA15 */ { 0, 1, 0, 0, 0, 0 }, /* FCC1 ATMRXD[5] */
83 /* PA14 */ { 0, 1, 0, 0, 0, 0 }, /* FCC1 ATMRXD[4] */
84 /* PA13 */ { 0, 1, 0, 0, 0, 0 }, /* FCC1 ATMRXD[3] */
85 /* PA12 */ { 0, 1, 0, 0, 0, 0 }, /* FCC1 ATMRXD[2] */
86 /* PA11 */ { 0, 1, 0, 0, 0, 0 }, /* FCC1 ATMRXD[1] */
87 /* PA10 */ { 0, 1, 0, 0, 0, 0 }, /* FCC1 ATMRXD[0] */
88 /* PA9 */ { 0, 1, 1, 1, 0, 0 }, /* FCC1 L1TXD */
89 /* PA8 */ { 0, 1, 1, 0, 0, 0 }, /* FCC1 L1RXD */
90 /* PA7 */ { 0, 0, 0, 1, 0, 0 }, /* PA7 */
91 /* PA6 */ { 1, 1, 1, 1, 0, 0 }, /* TDM A1 L1RSYNC */
92 /* PA5 */ { 0, 0, 0, 1, 0, 0 }, /* PA5 */
93 /* PA4 */ { 0, 0, 0, 1, 0, 0 }, /* PA4 */
94 /* PA3 */ { 0, 0, 0, 1, 0, 0 }, /* PA3 */
95 /* PA2 */ { 0, 0, 0, 1, 0, 0 }, /* PA2 */
96 /* PA1 */ { 1, 0, 0, 0, 0, 0 }, /* FREERUN */
97 /* PA0 */ { 0, 0, 0, 1, 0, 0 } /* PA0 */
Wolfgang Denk55e33272011-11-05 05:13:16 +000098 },
wdenkdb2f721f2003-03-06 00:58:30 +000099
Wolfgang Denk55e33272011-11-05 05:13:16 +0000100 /* Port B configuration */
101 { /* conf ppar psor pdir podr pdat */
wdenkdb2f721f2003-03-06 00:58:30 +0000102 /* PB31 */ { 1, 1, 0, 1, 0, 0 }, /* FCC2 MII TX_ER */
103 /* PB30 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII RX_DV */
104 /* PB29 */ { 1, 1, 1, 1, 0, 0 }, /* FCC2 MII TX_EN */
105 /* PB28 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII RX_ER */
106 /* PB27 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII COL */
107 /* PB26 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII CRS */
108 /* PB25 */ { 1, 1, 0, 1, 0, 0 }, /* FCC2 MII TxD[3] */
109 /* PB24 */ { 1, 1, 0, 1, 0, 0 }, /* FCC2 MII TxD[2] */
110 /* PB23 */ { 1, 1, 0, 1, 0, 0 }, /* FCC2 MII TxD[1] */
111 /* PB22 */ { 1, 1, 0, 1, 0, 0 }, /* FCC2 MII TxD[0] */
112 /* PB21 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII RxD[0] */
113 /* PB20 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII RxD[1] */
114 /* PB19 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII RxD[2] */
115 /* PB18 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII RxD[3] */
116 /* PB17 */ { 0, 1, 0, 0, 0, 0 }, /* FCC3:RX_DIV */
117 /* PB16 */ { 0, 1, 0, 0, 0, 0 }, /* FCC3:RX_ERR */
118 /* PB15 */ { 0, 1, 0, 1, 0, 0 }, /* FCC3:TX_ERR */
119 /* PB14 */ { 0, 1, 0, 1, 0, 0 }, /* FCC3:TX_EN */
120 /* PB13 */ { 0, 1, 0, 0, 0, 0 }, /* FCC3:COL */
121 /* PB12 */ { 0, 1, 0, 0, 0, 0 }, /* FCC3:CRS */
122 /* PB11 */ { 0, 1, 0, 0, 0, 0 }, /* FCC3:RXD */
123 /* PB10 */ { 0, 1, 0, 0, 0, 0 }, /* FCC3:RXD */
124 /* PB9 */ { 0, 1, 0, 0, 0, 0 }, /* FCC3:RXD */
125 /* PB8 */ { 0, 1, 0, 0, 0, 0 }, /* FCC3:RXD */
126 /* PB7 */ { 0, 1, 0, 1, 0, 0 }, /* FCC3:TXD */
127 /* PB6 */ { 0, 1, 0, 1, 0, 0 }, /* FCC3:TXD */
128 /* PB5 */ { 0, 1, 0, 1, 0, 0 }, /* FCC3:TXD */
129 /* PB4 */ { 0, 1, 0, 1, 0, 0 }, /* FCC3:TXD */
130 /* PB3 */ { 0, 0, 0, 0, 0, 0 }, /* pin doesn't exist */
131 /* PB2 */ { 0, 0, 0, 0, 0, 0 }, /* pin doesn't exist */
132 /* PB1 */ { 0, 0, 0, 0, 0, 0 }, /* pin doesn't exist */
133 /* PB0 */ { 0, 0, 0, 0, 0, 0 } /* pin doesn't exist */
Wolfgang Denk55e33272011-11-05 05:13:16 +0000134 },
wdenkdb2f721f2003-03-06 00:58:30 +0000135
Wolfgang Denk55e33272011-11-05 05:13:16 +0000136 /* Port C */
137 { /* conf ppar psor pdir podr pdat */
wdenkdb2f721f2003-03-06 00:58:30 +0000138 /* PC31 */ { 0, 0, 0, 1, 0, 0 }, /* PC31 */
139 /* PC30 */ { 0, 0, 0, 1, 0, 0 }, /* PC30 */
140 /* PC29 */ { 0, 1, 1, 0, 0, 0 }, /* SCC1 EN *CLSN */
141 /* PC28 */ { 0, 0, 0, 1, 0, 0 }, /* PC28 */
142 /* PC27 */ { 0, 0, 0, 1, 0, 0 }, /* UART Clock in */
143 /* PC26 */ { 0, 0, 0, 1, 0, 0 }, /* PC26 */
144 /* PC25 */ { 0, 0, 0, 1, 0, 0 }, /* PC25 */
145 /* PC24 */ { 0, 0, 0, 1, 0, 0 }, /* PC24 */
146 /* PC23 */ { 0, 1, 0, 1, 0, 0 }, /* ATMTFCLK */
147 /* PC22 */ { 0, 1, 0, 0, 0, 0 }, /* ATMRFCLK */
148 /* PC21 */ { 0, 1, 0, 0, 0, 0 }, /* SCC1 EN RXCLK */
149 /* PC20 */ { 0, 1, 0, 0, 0, 0 }, /* SCC1 EN TXCLK */
150 /* PC19 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII RX_CLK CLK13 */
151 /* PC18 */ { 1, 1, 0, 0, 0, 0 }, /* FCC Tx Clock (CLK14) */
152 /* PC17 */ { 0, 0, 0, 1, 0, 0 }, /* PC17 */
153 /* PC16 */ { 0, 1, 0, 0, 0, 0 }, /* FCC Tx Clock (CLK16) */
154 /* PC15 */ { 0, 0, 0, 1, 0, 0 }, /* PC15 */
155 /* PC14 */ { 0, 1, 0, 0, 0, 0 }, /* SCC1 EN *CD */
156 /* PC13 */ { 0, 0, 0, 1, 0, 0 }, /* PC13 */
157 /* PC12 */ { 0, 1, 0, 1, 0, 0 }, /* PC12 */
158 /* PC11 */ { 0, 0, 0, 1, 0, 0 }, /* LXT971 transmit control */
wdenk5d232d02003-05-22 22:52:13 +0000159 /* PC10 */ { 1, 0, 0, 1, 0, 0 }, /* LXT970 FETHMDC */
160 /* PC9 */ { 1, 0, 0, 0, 0, 0 }, /* LXT970 FETHMDIO */
wdenkdb2f721f2003-03-06 00:58:30 +0000161 /* PC8 */ { 0, 0, 0, 1, 0, 0 }, /* PC8 */
162 /* PC7 */ { 0, 0, 0, 1, 0, 0 }, /* PC7 */
163 /* PC6 */ { 0, 0, 0, 1, 0, 0 }, /* PC6 */
164 /* PC5 */ { 0, 0, 0, 1, 0, 0 }, /* PC5 */
165 /* PC4 */ { 0, 0, 0, 1, 0, 0 }, /* PC4 */
166 /* PC3 */ { 0, 0, 0, 1, 0, 0 }, /* PC3 */
167 /* PC2 */ { 0, 0, 0, 1, 0, 1 }, /* ENET FDE */
168 /* PC1 */ { 0, 0, 0, 1, 0, 0 }, /* ENET DSQE */
169 /* PC0 */ { 0, 0, 0, 1, 0, 0 }, /* ENET LBK */
Wolfgang Denk55e33272011-11-05 05:13:16 +0000170 },
wdenkdb2f721f2003-03-06 00:58:30 +0000171
Wolfgang Denk55e33272011-11-05 05:13:16 +0000172 /* Port D */
173 { /* conf ppar psor pdir podr pdat */
wdenkdb2f721f2003-03-06 00:58:30 +0000174 /* PD31 */ { 1, 1, 0, 0, 0, 0 }, /* SCC1 EN RxD */
175 /* PD30 */ { 1, 1, 1, 1, 0, 0 }, /* SCC1 EN TxD */
176 /* PD29 */ { 0, 1, 0, 1, 0, 0 }, /* SCC1 EN TENA */
177 /* PD28 */ { 0, 1, 0, 0, 0, 0 }, /* PD28 */
178 /* PD27 */ { 0, 1, 1, 1, 0, 0 }, /* PD27 */
179 /* PD26 */ { 0, 0, 0, 1, 0, 0 }, /* PD26 */
180 /* PD25 */ { 0, 0, 0, 1, 0, 0 }, /* PD25 */
181 /* PD24 */ { 0, 0, 0, 1, 0, 0 }, /* PD24 */
182 /* PD23 */ { 0, 0, 0, 1, 0, 0 }, /* PD23 */
183 /* PD22 */ { 0, 0, 0, 1, 0, 0 }, /* PD22 */
184 /* PD21 */ { 0, 0, 0, 1, 0, 0 }, /* PD21 */
185 /* PD20 */ { 0, 0, 0, 1, 0, 0 }, /* PD20 */
186 /* PD19 */ { 0, 0, 0, 1, 0, 0 }, /* PD19 */
187 /* PD18 */ { 0, 0, 0, 1, 0, 0 }, /* PD18 */
188 /* PD17 */ { 0, 1, 0, 0, 0, 0 }, /* FCC1 ATMRXPRTY */
189 /* PD16 */ { 0, 1, 0, 1, 0, 0 }, /* FCC1 ATMTXPRTY */
190 /* PD15 */ { 1, 1, 1, 0, 1, 0 }, /* I2C SDA */
191 /* PD14 */ { 1, 1, 1, 0, 1, 0 }, /* I2C SCL */
192 /* PD13 */ { 0, 0, 0, 0, 0, 0 }, /* PD13 */
193 /* PD12 */ { 0, 0, 0, 0, 0, 0 }, /* PD12 */
194 /* PD11 */ { 0, 0, 0, 0, 0, 0 }, /* PD11 */
195 /* PD10 */ { 0, 0, 0, 0, 0, 0 }, /* PD10 */
196 /* PD9 */ { 1, 1, 0, 1, 0, 0 }, /* SMC1 TXD */
197 /* PD8 */ { 1, 1, 0, 0, 0, 0 }, /* SMC1 RXD */
198 /* PD7 */ { 0, 0, 0, 1, 0, 1 }, /* PD7 */
199 /* PD6 */ { 0, 0, 0, 1, 0, 1 }, /* PD6 */
200 /* PD5 */ { 0, 0, 0, 1, 0, 1 }, /* PD5 */
201 /* PD4 */ { 0, 0, 0, 1, 0, 1 }, /* PD4 */
202 /* PD3 */ { 0, 0, 0, 0, 0, 0 }, /* pin doesn't exist */
203 /* PD2 */ { 0, 0, 0, 0, 0, 0 }, /* pin doesn't exist */
204 /* PD1 */ { 0, 0, 0, 0, 0, 0 }, /* pin doesn't exist */
205 /* PD0 */ { 0, 0, 0, 0, 0, 0 } /* pin doesn't exist */
Wolfgang Denk55e33272011-11-05 05:13:16 +0000206 }
wdenkdb2f721f2003-03-06 00:58:30 +0000207};
208
209typedef struct bscr_ {
210 unsigned long bcsr0;
211 unsigned long bcsr1;
212 unsigned long bcsr2;
213 unsigned long bcsr3;
214 unsigned long bcsr4;
215 unsigned long bcsr5;
216 unsigned long bcsr6;
217 unsigned long bcsr7;
218} bcsr_t;
219
wdenk5d232d02003-05-22 22:52:13 +0000220typedef struct pci_ic_s {
221 unsigned long pci_int_stat;
222 unsigned long pci_int_mask;
223} pci_ic_t;
224
wdenkdb2f721f2003-03-06 00:58:30 +0000225void reset_phy(void)
226{
Wolfgang Denk55e33272011-11-05 05:13:16 +0000227 volatile bcsr_t *bcsr = (bcsr_t *)CONFIG_SYS_BCSR;
wdenkdb2f721f2003-03-06 00:58:30 +0000228
Wolfgang Denk55e33272011-11-05 05:13:16 +0000229 /* reset the FEC port */
230 bcsr->bcsr1 &= ~FETH_RST;
231 bcsr->bcsr1 |= FETH_RST;
wdenkdb2f721f2003-03-06 00:58:30 +0000232}
233
234
Wolfgang Denk55e33272011-11-05 05:13:16 +0000235int board_early_init_f(void)
wdenkdb2f721f2003-03-06 00:58:30 +0000236{
Wolfgang Denk55e33272011-11-05 05:13:16 +0000237 volatile bcsr_t *bcsr = (bcsr_t *)CONFIG_SYS_BCSR;
238 volatile pci_ic_t *pci_ic = (pci_ic_t *)CONFIG_SYS_PCI_INT;
wdenkdb2f721f2003-03-06 00:58:30 +0000239
Wolfgang Denk55e33272011-11-05 05:13:16 +0000240 bcsr->bcsr1 = ~FETHIEN & ~RS232EN_1 & ~RS232EN_2;
wdenk5d232d02003-05-22 22:52:13 +0000241
Wolfgang Denk55e33272011-11-05 05:13:16 +0000242 /* mask all PCI interrupts */
243 pci_ic->pci_int_mask |= 0xfff00000;
wdenk8bde7f72003-06-27 21:31:46 +0000244
Wolfgang Denk55e33272011-11-05 05:13:16 +0000245 return 0;
wdenkdb2f721f2003-03-06 00:58:30 +0000246}
247
248int checkboard(void)
249{
Wolfgang Denk55e33272011-11-05 05:13:16 +0000250 puts("Board: Motorola MPC8266ADS\n");
251 return 0;
wdenkdb2f721f2003-03-06 00:58:30 +0000252}
253
Becky Bruce9973e3c2008-06-09 16:03:40 -0500254phys_size_t initdram(int board_type)
wdenkdb2f721f2003-03-06 00:58:30 +0000255{
256 /* Autoinit part stolen from board/sacsng/sacsng.c */
Wolfgang Denk55e33272011-11-05 05:13:16 +0000257 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
258 volatile memctl8260_t *memctl = &immap->im_memctl;
259 volatile uchar c = 0xff;
260 volatile uchar *ramaddr = (uchar *) (CONFIG_SYS_SDRAM_BASE + 0x8);
261 uint psdmr = CONFIG_SYS_PSDMR;
262 int i;
wdenkdb2f721f2003-03-06 00:58:30 +0000263
Wolfgang Denk55e33272011-11-05 05:13:16 +0000264 uint psrt = 0x21; /* for no SPD */
265 uint chipselects = 1; /* for no SPD */
266 uint sdram_size = CONFIG_SYS_SDRAM_SIZE * 1024 * 1024; /* for no SPD */
267 uint or = CONFIG_SYS_OR2_PRELIM; /* for no SPD */
268 uint data_width;
269 uint rows;
270 uint banks;
271 uint cols;
272 uint caslatency;
273 uint width;
274 uint rowst;
275 uint sdam;
276 uint bsma;
277 uint sda10;
Wolfgang Denk55e33272011-11-05 05:13:16 +0000278 u_char data;
279 u_char cksum;
280 int j;
wdenkdb2f721f2003-03-06 00:58:30 +0000281
Wolfgang Denk55e33272011-11-05 05:13:16 +0000282 /*
283 * Keep the compiler from complaining about
284 * potentially uninitialized vars
285 */
286 data_width = rows = banks = cols = caslatency = 0;
wdenkdb2f721f2003-03-06 00:58:30 +0000287
Wolfgang Denk55e33272011-11-05 05:13:16 +0000288 /*
289 * Read the SDRAM SPD EEPROM via I2C.
290 */
291 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
wdenkdb2f721f2003-03-06 00:58:30 +0000292
Wolfgang Denk55e33272011-11-05 05:13:16 +0000293 i2c_read(SDRAM_SPD_ADDR, 0, 1, &data, 1);
Wolfgang Denk55e33272011-11-05 05:13:16 +0000294 cksum = data;
295 for (j = 1; j < 64; j++) { /* read only the checksummed bytes */
296 /* note: the I2C address autoincrements when alen == 0 */
wdenkdb2f721f2003-03-06 00:58:30 +0000297 i2c_read(SDRAM_SPD_ADDR, 0, 0, &data, 1);
Wolfgang Denk55e33272011-11-05 05:13:16 +0000298 /*printf("addr %d = 0x%02x\n", j, data); */
299 if (j == 5)
300 chipselects = data & 0x0F;
301 else if (j == 6)
302 data_width = data;
303 else if (j == 7)
304 data_width |= data << 8;
305 else if (j == 3)
306 rows = data & 0x0F;
307 else if (j == 4)
308 cols = data & 0x0F;
309 else if (j == 12) {
wdenkdb2f721f2003-03-06 00:58:30 +0000310 /*
Wolfgang Denk55e33272011-11-05 05:13:16 +0000311 * Refresh rate: this assumes the prescaler is set to
312 * approximately 0.39uSec per tick and the target
313 * refresh period is about 85% of maximum.
wdenkdb2f721f2003-03-06 00:58:30 +0000314 */
Wolfgang Denk55e33272011-11-05 05:13:16 +0000315 switch (data & 0x7F) {
316 default:
317 case 0:
318 psrt = 0x21; /* 15.625uS */
319 break;
320 case 1:
321 psrt = 0x07; /* 3.9uS */
322 break;
323 case 2:
324 psrt = 0x0F; /* 7.8uS */
325 break;
326 case 3:
327 psrt = 0x43; /* 31.3uS */
328 break;
329 case 4:
330 psrt = 0x87; /* 62.5uS */
331 break;
332 case 5:
333 psrt = 0xFF; /* 125uS */
334 break;
wdenkdb2f721f2003-03-06 00:58:30 +0000335 }
Wolfgang Denk55e33272011-11-05 05:13:16 +0000336 } else if (j == 17)
337 banks = data;
338 else if (j == 18) {
339 caslatency = 3; /* default CL */
340#if (PESSIMISTIC_SDRAM)
341 if ((data & 0x04) != 0)
342 caslatency = 3;
343 else if ((data & 0x02) != 0)
344 caslatency = 2;
345 else if ((data & 0x01) != 0)
346 caslatency = 1;
347#else
348 if ((data & 0x01) != 0)
349 caslatency = 1;
350 else if ((data & 0x02) != 0)
351 caslatency = 2;
352 else if ((data & 0x04) != 0)
353 caslatency = 3;
354#endif
355 else {
356 printf("WARNING: Unknown CAS latency 0x%02X, using 3\n",
wdenkdb2f721f2003-03-06 00:58:30 +0000357 data);
358 }
Wolfgang Denk55e33272011-11-05 05:13:16 +0000359 } else if (j == 63) {
360 if (data != cksum) {
361 printf("WARNING: Configuration data checksum failure:"
wdenkdb2f721f2003-03-06 00:58:30 +0000362 " is 0x%02x, calculated 0x%02x\n",
Wolfgang Denk55e33272011-11-05 05:13:16 +0000363 data, cksum);
wdenkdb2f721f2003-03-06 00:58:30 +0000364 }
365 }
366 cksum += data;
Wolfgang Denk55e33272011-11-05 05:13:16 +0000367 }
wdenkdb2f721f2003-03-06 00:58:30 +0000368
Wolfgang Denk55e33272011-11-05 05:13:16 +0000369 /* We don't trust CL less than 2 (only saw it on an old 16MByte DIMM) */
370 if (caslatency < 2) {
wdenkdb2f721f2003-03-06 00:58:30 +0000371 printf("CL was %d, forcing to 2\n", caslatency);
372 caslatency = 2;
Wolfgang Denk55e33272011-11-05 05:13:16 +0000373 }
374 if (rows > 14) {
375 printf("This doesn't look good, rows = %d, should be <= 14\n",
376 rows);
wdenkdb2f721f2003-03-06 00:58:30 +0000377 rows = 14;
Wolfgang Denk55e33272011-11-05 05:13:16 +0000378 }
379 if (cols > 11) {
380 printf("This doesn't look good, columns = %d, should be <= 11\n",
381 cols);
wdenkdb2f721f2003-03-06 00:58:30 +0000382 cols = 11;
Wolfgang Denk55e33272011-11-05 05:13:16 +0000383 }
wdenkdb2f721f2003-03-06 00:58:30 +0000384
Wolfgang Denk55e33272011-11-05 05:13:16 +0000385 if ((data_width != 64) && (data_width != 72)) {
wdenkdb2f721f2003-03-06 00:58:30 +0000386 printf("WARNING: SDRAM width unsupported, is %d, expected 64 or 72.\n",
387 data_width);
Wolfgang Denk55e33272011-11-05 05:13:16 +0000388 }
389 width = 3; /* 2^3 = 8 bytes = 64 bits wide */
390 /*
391 * Convert banks into log2(banks)
392 */
393 if (banks == 2)
394 banks = 1;
395 else if (banks == 4)
396 banks = 2;
397 else if (banks == 8)
398 banks = 3;
wdenkdb2f721f2003-03-06 00:58:30 +0000399
400
Wolfgang Denk55e33272011-11-05 05:13:16 +0000401 sdram_size = 1 << (rows + cols + banks + width);
402 /* hack for high density memory (512MB per CS) */
403 /* !!!!! Will ONLY work with Page Based Interleave !!!!!
404 ( PSDMR[PBI] = 1 )
405 */
406 /*
407 * memory actually has 11 column addresses, but the memory
408 * controller doesn't really care.
409 *
410 * the calculations that follow will however move the rows so
411 * that they are muxed one bit off if you use 11 bit columns.
412 *
413 * The solution is to tell the memory controller the correct
414 * size of the memory but change the number of columns to 10
415 * afterwards.
416 *
417 * The 11th column addre will still be mucxed correctly onto
418 * the bus.
419 *
420 * Also be aware that the MPC8266ADS board Rev B has not
421 * connected Row address 13 to anything.
422 *
423 * The fix is to connect ADD16 (from U37-47) to SADDR12 (U28-126)
424 */
425 if (cols > 10)
426 cols = 10;
wdenk3595ac42003-06-22 17:18:28 +0000427
Wolfgang Denk55e33272011-11-05 05:13:16 +0000428#if (CONFIG_PBI == 0) /* bank-based interleaving */
429 rowst = ((32 - 6) - (rows + cols + width)) * 2;
wdenkdb2f721f2003-03-06 00:58:30 +0000430#else
Wolfgang Denk55e33272011-11-05 05:13:16 +0000431 rowst = 32 - (rows + banks + cols + width);
wdenkdb2f721f2003-03-06 00:58:30 +0000432#endif
433
Wolfgang Denk55e33272011-11-05 05:13:16 +0000434 or = ~(sdram_size - 1) | /* SDAM address mask */
435 ((banks - 1) << 13) | /* banks per device */
436 (rowst << 9) | /* rowst */
437 ((rows - 9) << 6); /* numr */
wdenkdb2f721f2003-03-06 00:58:30 +0000438
439
Wolfgang Denk55e33272011-11-05 05:13:16 +0000440 /*printf("memctl->memc_or2 = 0x%08x\n", or); */
wdenkdb2f721f2003-03-06 00:58:30 +0000441
Wolfgang Denk55e33272011-11-05 05:13:16 +0000442 /*
443 * SDAM specifies the number of columns that are multiplexed
444 * (reference AN2165/D), defined to be (columns - 6) for page
445 * interleave, (columns - 8) for bank interleave.
446 *
447 * BSMA is 14 - max(rows, cols). The bank select lines come
448 * into play above the highest "address" line going into the
449 * the SDRAM.
450 */
451#if (CONFIG_PBI == 0) /* bank-based interleaving */
452 sdam = cols - 8;
453 bsma = ((31 - width) - 14) - ((rows > cols) ? rows : cols);
454 sda10 = sdam + 2;
wdenkdb2f721f2003-03-06 00:58:30 +0000455#else
Wolfgang Denk55e33272011-11-05 05:13:16 +0000456 sdam = cols + banks - 8;
457 bsma = ((31 - width) - 14) - ((rows > cols) ? rows : cols);
458 sda10 = sdam;
wdenkdb2f721f2003-03-06 00:58:30 +0000459#endif
Wolfgang Denk55e33272011-11-05 05:13:16 +0000460#if (PESSIMISTIC_SDRAM)
461 psdmr = (CONFIG_PBI | PSDMR_RFEN | PSDMR_RFRC_16_CLK |
462 PSDMR_PRETOACT_8W | PSDMR_ACTTORW_8W | PSDMR_WRC_4C |
463 PSDMR_EAMUX | PSDMR_BUFCMD) | caslatency |
464 ((caslatency - 1) << 6) | /* LDOTOPRE is CL - 1 */
465 (sdam << 24) | (bsma << 21) | (sda10 << 18);
wdenkdb2f721f2003-03-06 00:58:30 +0000466#else
Wolfgang Denk55e33272011-11-05 05:13:16 +0000467 psdmr = (CONFIG_PBI | PSDMR_RFEN | PSDMR_RFRC_7_CLK |
468 PSDMR_PRETOACT_3W | /* 1 for 7E parts (fast PC-133) */
469 PSDMR_ACTTORW_2W | /* 1 for 7E parts (fast PC-133) */
470 PSDMR_WRC_1C | /* 1 clock + 7nSec */
471 EAMUX | BUFCMD) | caslatency |
472 ((caslatency - 1) << 6) | /* LDOTOPRE is CL - 1 */
473 (sdam << 24) | (bsma << 21) | (sda10 << 18);
wdenkdb2f721f2003-03-06 00:58:30 +0000474#endif
Wolfgang Denk55e33272011-11-05 05:13:16 +0000475 /*printf("psdmr = 0x%08x\n", psdmr); */
wdenkdb2f721f2003-03-06 00:58:30 +0000476
Wolfgang Denk55e33272011-11-05 05:13:16 +0000477 /*
478 * Quote from 8260 UM (10.4.2 SDRAM Power-On Initialization, 10-35):
479 *
480 * "At system reset, initialization software must set up the
481 * programmable parameters in the memory controller banks registers
482 * (ORx, BRx, P/LSDMR). After all memory parameters are configured,
483 * system software should execute the following initialization sequence
484 * for each SDRAM device.
485 *
486 * 1. Issue a PRECHARGE-ALL-BANKS command
487 * 2. Issue eight CBR REFRESH commands
488 * 3. Issue a MODE-SET command to initialize the mode register
489 *
490 * Quote from Micron MT48LC8M16A2 data sheet:
491 *
492 * "...the SDRAM requires a 100uS delay prior to issuing any
493 * command other than a COMMAND INHIBIT or NOP. Starting at some
494 * point during this 100uS period and continuing at least through
495 * the end of this period, COMMAND INHIBIT or NOP commands should
496 * be applied."
497 *
498 * "Once the 100uS delay has been satisfied with at least one COMMAND
499 * INHIBIT or NOP command having been applied, a /PRECHARGE command/
500 * should be applied. All banks must then be precharged, thereby
501 * placing the device in the all banks idle state."
502 *
503 * "Once in the idle state, /two/ AUTO REFRESH cycles must be
504 * performed. After the AUTO REFRESH cycles are complete, the
505 * SDRAM is ready for mode register programming."
506 *
507 * (/emphasis/ mine, gvb)
508 *
509 * The way I interpret this, Micron start up sequence is:
510 * 1. Issue a PRECHARGE-BANK command (initial precharge)
511 * 2. Issue a PRECHARGE-ALL-BANKS command ("all banks ... precharged")
512 * 3. Issue two (presumably, doing eight is OK) CBR REFRESH commands
513 * 4. Issue a MODE-SET command to initialize the mode register
514 *
515 * --------
516 *
517 * The initial commands are executed by setting P/LSDMR[OP] and
518 * accessing the SDRAM with a single-byte transaction."
519 *
520 * The appropriate BRx/ORx registers have already been set
521 * when we get here. The SDRAM can be accessed at the address
522 * CONFIG_SYS_SDRAM_BASE.
523 */
wdenk7a8e9bed2003-05-31 18:35:21 +0000524
Wolfgang Denk55e33272011-11-05 05:13:16 +0000525 memctl->memc_mptpr = CONFIG_SYS_MPTPR;
526 memctl->memc_psrt = psrt;
wdenkdb2f721f2003-03-06 00:58:30 +0000527
Wolfgang Denk55e33272011-11-05 05:13:16 +0000528 memctl->memc_br2 = CONFIG_SYS_BR2_PRELIM;
529 memctl->memc_or2 = or;
wdenk8bde7f72003-06-27 21:31:46 +0000530
Wolfgang Denk55e33272011-11-05 05:13:16 +0000531 memctl->memc_psdmr = psdmr | PSDMR_OP_PREA;
wdenkdb2f721f2003-03-06 00:58:30 +0000532 *ramaddr = c;
533
Wolfgang Denk55e33272011-11-05 05:13:16 +0000534 memctl->memc_psdmr = psdmr | PSDMR_OP_CBRR;
535 for (i = 0; i < 8; i++)
536 *ramaddr = c;
wdenkdb2f721f2003-03-06 00:58:30 +0000537
Wolfgang Denk55e33272011-11-05 05:13:16 +0000538 memctl->memc_psdmr = psdmr | PSDMR_OP_MRW;
539 *ramaddr = c;
wdenkdb2f721f2003-03-06 00:58:30 +0000540
Wolfgang Denk55e33272011-11-05 05:13:16 +0000541 memctl->memc_psdmr = psdmr | PSDMR_OP_NORM | PSDMR_RFEN;
542 *ramaddr = c;
543
544 /*
545 * Do it a second time for the second set of chips if the DIMM has
546 * two chip selects (double sided).
547 */
548 if (chipselects > 1) {
549 ramaddr += sdram_size;
wdenkdb2f721f2003-03-06 00:58:30 +0000550
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200551 memctl->memc_br3 = CONFIG_SYS_BR3_PRELIM + sdram_size;
wdenkdb2f721f2003-03-06 00:58:30 +0000552 memctl->memc_or3 = or;
553
554 memctl->memc_psdmr = psdmr | PSDMR_OP_PREA;
555 *ramaddr = c;
556
557 memctl->memc_psdmr = psdmr | PSDMR_OP_CBRR;
558 for (i = 0; i < 8; i++)
559 *ramaddr = c;
560
561 memctl->memc_psdmr = psdmr | PSDMR_OP_MRW;
562 *ramaddr = c;
563
564 memctl->memc_psdmr = psdmr | PSDMR_OP_NORM | PSDMR_RFEN;
565 *ramaddr = c;
Wolfgang Denk55e33272011-11-05 05:13:16 +0000566 }
wdenkdb2f721f2003-03-06 00:58:30 +0000567
wdenkdb2f721f2003-03-06 00:58:30 +0000568 /* print info */
569 printf("SDRAM configuration read from SPD\n");
570 printf("\tSize per side = %dMB\n", sdram_size >> 20);
Wolfgang Denk55e33272011-11-05 05:13:16 +0000571 printf("\tOrganization: %d sides, %d banks, %d Columns, %d Rows, Data width = %d bits\n",
572 chipselects, 1 << (banks), cols, rows, data_width);
wdenk65bd0e22003-09-18 10:45:21 +0000573 printf("\tRefresh rate = %d, CAS latency = %d", psrt, caslatency);
Wolfgang Denk55e33272011-11-05 05:13:16 +0000574#if (CONFIG_PBI == 0) /* bank-based interleaving */
575 printf(", Using Bank Based Interleave\n");
wdenk65bd0e22003-09-18 10:45:21 +0000576#else
Wolfgang Denk55e33272011-11-05 05:13:16 +0000577 printf(", Using Page Based Interleave\n");
wdenk42d1f032003-10-15 23:53:47 +0000578#endif
wdenkdb2f721f2003-03-06 00:58:30 +0000579 printf("\tTotal size: ");
580
Wolfgang Denk55e33272011-11-05 05:13:16 +0000581 /* this delay only needed for original 16MB DIMM...
582 * Not needed for any other memory configuration */
583 if ((sdram_size * chipselects) == (16 * 1024 * 1024))
584 udelay(250000);
wdenk5d232d02003-05-22 22:52:13 +0000585
Wolfgang Denk55e33272011-11-05 05:13:16 +0000586 return sdram_size * chipselects;
587}
wdenk7a8e9bed2003-05-31 18:35:21 +0000588
wdenk5d232d02003-05-22 22:52:13 +0000589#ifdef CONFIG_PCI
590struct pci_controller hose;
591
592extern void pci_mpc8250_init(struct pci_controller *);
593
594void pci_init_board(void)
595{
596 pci_mpc8250_init(&hose);
597}
598#endif