mpc8266ads.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. /*
  2. * (C) Copyright 2001
  3. * 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. #include <common.h>
  31. #include <ioports.h>
  32. #include <i2c.h>
  33. #include <mpc8260.h>
  34. /*
  35. * PBI Page Based Interleaving
  36. * PSDMR_PBI page based interleaving
  37. * 0 bank based interleaving
  38. * External Address Multiplexing (EAMUX) adds a clock to address cycles
  39. * (this can help with marginal board layouts)
  40. * PSDMR_EAMUX adds a clock
  41. * 0 no extra clock
  42. * Buffer Command (BUFCMD) adds a clock to command cycles.
  43. * PSDMR_BUFCMD adds a clock
  44. * 0 no extra clock
  45. */
  46. #define CONFIG_PBI 0
  47. #define PESSIMISTIC_SDRAM 0
  48. #define EAMUX 0 /* EST requires EAMUX */
  49. #define BUFCMD 0
  50. /*
  51. * I/O Port configuration table
  52. *
  53. * if conf is 1, then that port pin will be configured at boot time
  54. * according to the five values podr/pdir/ppar/psor/pdat for that entry
  55. */
  56. const iop_conf_t iop_conf_tab[4][32] = {
  57. /* Port A configuration */
  58. { /* conf ppar psor pdir podr pdat */
  59. /* PA31 */ { 0, 1, 0, 1, 0, 0 }, /* FCC1 TxENB */
  60. /* PA30 */ { 0, 1, 0, 0, 0, 0 }, /* FCC1 TxClav */
  61. /* PA29 */ { 0, 1, 0, 1, 0, 0 }, /* FCC1 TxSOC */
  62. /* PA28 */ { 0, 1, 0, 1, 0, 0 }, /* FCC1 RxENB */
  63. /* PA27 */ { 0, 1, 0, 0, 0, 0 }, /* FCC1 RxSOC */
  64. /* PA26 */ { 0, 1, 0, 0, 0, 0 }, /* FCC1 RxClav */
  65. /* PA25 */ { 0, 1, 0, 1, 0, 0 }, /* FCC1 ATMTXD[0] */
  66. /* PA24 */ { 0, 1, 0, 1, 0, 0 }, /* FCC1 ATMTXD[1] */
  67. /* PA23 */ { 0, 1, 0, 1, 0, 0 }, /* FCC1 ATMTXD[2] */
  68. /* PA22 */ { 0, 1, 0, 1, 0, 0 }, /* FCC1 ATMTXD[3] */
  69. /* PA21 */ { 0, 1, 0, 1, 0, 0 }, /* FCC1 ATMTXD[4] */
  70. /* PA20 */ { 0, 1, 0, 1, 0, 0 }, /* FCC1 ATMTXD[5] */
  71. /* PA19 */ { 0, 1, 0, 1, 0, 0 }, /* FCC1 ATMTXD[6] */
  72. /* PA18 */ { 0, 1, 0, 1, 0, 0 }, /* FCC1 ATMTXD[7] */
  73. /* PA17 */ { 0, 1, 0, 0, 0, 0 }, /* FCC1 ATMRXD[7] */
  74. /* PA16 */ { 0, 1, 0, 0, 0, 0 }, /* FCC1 ATMRXD[6] */
  75. /* PA15 */ { 0, 1, 0, 0, 0, 0 }, /* FCC1 ATMRXD[5] */
  76. /* PA14 */ { 0, 1, 0, 0, 0, 0 }, /* FCC1 ATMRXD[4] */
  77. /* PA13 */ { 0, 1, 0, 0, 0, 0 }, /* FCC1 ATMRXD[3] */
  78. /* PA12 */ { 0, 1, 0, 0, 0, 0 }, /* FCC1 ATMRXD[2] */
  79. /* PA11 */ { 0, 1, 0, 0, 0, 0 }, /* FCC1 ATMRXD[1] */
  80. /* PA10 */ { 0, 1, 0, 0, 0, 0 }, /* FCC1 ATMRXD[0] */
  81. /* PA9 */ { 0, 1, 1, 1, 0, 0 }, /* FCC1 L1TXD */
  82. /* PA8 */ { 0, 1, 1, 0, 0, 0 }, /* FCC1 L1RXD */
  83. /* PA7 */ { 0, 0, 0, 1, 0, 0 }, /* PA7 */
  84. /* PA6 */ { 1, 1, 1, 1, 0, 0 }, /* TDM A1 L1RSYNC */
  85. /* PA5 */ { 0, 0, 0, 1, 0, 0 }, /* PA5 */
  86. /* PA4 */ { 0, 0, 0, 1, 0, 0 }, /* PA4 */
  87. /* PA3 */ { 0, 0, 0, 1, 0, 0 }, /* PA3 */
  88. /* PA2 */ { 0, 0, 0, 1, 0, 0 }, /* PA2 */
  89. /* PA1 */ { 1, 0, 0, 0, 0, 0 }, /* FREERUN */
  90. /* PA0 */ { 0, 0, 0, 1, 0, 0 } /* PA0 */
  91. },
  92. /* Port B configuration */
  93. { /* conf ppar psor pdir podr pdat */
  94. /* PB31 */ { 1, 1, 0, 1, 0, 0 }, /* FCC2 MII TX_ER */
  95. /* PB30 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII RX_DV */
  96. /* PB29 */ { 1, 1, 1, 1, 0, 0 }, /* FCC2 MII TX_EN */
  97. /* PB28 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII RX_ER */
  98. /* PB27 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII COL */
  99. /* PB26 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII CRS */
  100. /* PB25 */ { 1, 1, 0, 1, 0, 0 }, /* FCC2 MII TxD[3] */
  101. /* PB24 */ { 1, 1, 0, 1, 0, 0 }, /* FCC2 MII TxD[2] */
  102. /* PB23 */ { 1, 1, 0, 1, 0, 0 }, /* FCC2 MII TxD[1] */
  103. /* PB22 */ { 1, 1, 0, 1, 0, 0 }, /* FCC2 MII TxD[0] */
  104. /* PB21 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII RxD[0] */
  105. /* PB20 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII RxD[1] */
  106. /* PB19 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII RxD[2] */
  107. /* PB18 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII RxD[3] */
  108. /* PB17 */ { 0, 1, 0, 0, 0, 0 }, /* FCC3:RX_DIV */
  109. /* PB16 */ { 0, 1, 0, 0, 0, 0 }, /* FCC3:RX_ERR */
  110. /* PB15 */ { 0, 1, 0, 1, 0, 0 }, /* FCC3:TX_ERR */
  111. /* PB14 */ { 0, 1, 0, 1, 0, 0 }, /* FCC3:TX_EN */
  112. /* PB13 */ { 0, 1, 0, 0, 0, 0 }, /* FCC3:COL */
  113. /* PB12 */ { 0, 1, 0, 0, 0, 0 }, /* FCC3:CRS */
  114. /* PB11 */ { 0, 1, 0, 0, 0, 0 }, /* FCC3:RXD */
  115. /* PB10 */ { 0, 1, 0, 0, 0, 0 }, /* FCC3:RXD */
  116. /* PB9 */ { 0, 1, 0, 0, 0, 0 }, /* FCC3:RXD */
  117. /* PB8 */ { 0, 1, 0, 0, 0, 0 }, /* FCC3:RXD */
  118. /* PB7 */ { 0, 1, 0, 1, 0, 0 }, /* FCC3:TXD */
  119. /* PB6 */ { 0, 1, 0, 1, 0, 0 }, /* FCC3:TXD */
  120. /* PB5 */ { 0, 1, 0, 1, 0, 0 }, /* FCC3:TXD */
  121. /* PB4 */ { 0, 1, 0, 1, 0, 0 }, /* FCC3:TXD */
  122. /* PB3 */ { 0, 0, 0, 0, 0, 0 }, /* pin doesn't exist */
  123. /* PB2 */ { 0, 0, 0, 0, 0, 0 }, /* pin doesn't exist */
  124. /* PB1 */ { 0, 0, 0, 0, 0, 0 }, /* pin doesn't exist */
  125. /* PB0 */ { 0, 0, 0, 0, 0, 0 } /* pin doesn't exist */
  126. },
  127. /* Port C */
  128. { /* conf ppar psor pdir podr pdat */
  129. /* PC31 */ { 0, 0, 0, 1, 0, 0 }, /* PC31 */
  130. /* PC30 */ { 0, 0, 0, 1, 0, 0 }, /* PC30 */
  131. /* PC29 */ { 0, 1, 1, 0, 0, 0 }, /* SCC1 EN *CLSN */
  132. /* PC28 */ { 0, 0, 0, 1, 0, 0 }, /* PC28 */
  133. /* PC27 */ { 0, 0, 0, 1, 0, 0 }, /* UART Clock in */
  134. /* PC26 */ { 0, 0, 0, 1, 0, 0 }, /* PC26 */
  135. /* PC25 */ { 0, 0, 0, 1, 0, 0 }, /* PC25 */
  136. /* PC24 */ { 0, 0, 0, 1, 0, 0 }, /* PC24 */
  137. /* PC23 */ { 0, 1, 0, 1, 0, 0 }, /* ATMTFCLK */
  138. /* PC22 */ { 0, 1, 0, 0, 0, 0 }, /* ATMRFCLK */
  139. /* PC21 */ { 0, 1, 0, 0, 0, 0 }, /* SCC1 EN RXCLK */
  140. /* PC20 */ { 0, 1, 0, 0, 0, 0 }, /* SCC1 EN TXCLK */
  141. /* PC19 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII RX_CLK CLK13 */
  142. /* PC18 */ { 1, 1, 0, 0, 0, 0 }, /* FCC Tx Clock (CLK14) */
  143. /* PC17 */ { 0, 0, 0, 1, 0, 0 }, /* PC17 */
  144. /* PC16 */ { 0, 1, 0, 0, 0, 0 }, /* FCC Tx Clock (CLK16) */
  145. /* PC15 */ { 0, 0, 0, 1, 0, 0 }, /* PC15 */
  146. /* PC14 */ { 0, 1, 0, 0, 0, 0 }, /* SCC1 EN *CD */
  147. /* PC13 */ { 0, 0, 0, 1, 0, 0 }, /* PC13 */
  148. /* PC12 */ { 0, 1, 0, 1, 0, 0 }, /* PC12 */
  149. /* PC11 */ { 0, 0, 0, 1, 0, 0 }, /* LXT971 transmit control */
  150. /* PC10 */ { 1, 1, 0, 0, 0, 0 }, /* LXT970 FETHMDC */
  151. /* PC9 */ { 1, 1, 0, 0, 0, 0 }, /* LXT970 FETHMDIO */
  152. /* PC8 */ { 0, 0, 0, 1, 0, 0 }, /* PC8 */
  153. /* PC7 */ { 0, 0, 0, 1, 0, 0 }, /* PC7 */
  154. /* PC6 */ { 0, 0, 0, 1, 0, 0 }, /* PC6 */
  155. /* PC5 */ { 0, 0, 0, 1, 0, 0 }, /* PC5 */
  156. /* PC4 */ { 0, 0, 0, 1, 0, 0 }, /* PC4 */
  157. /* PC3 */ { 0, 0, 0, 1, 0, 0 }, /* PC3 */
  158. /* PC2 */ { 0, 0, 0, 1, 0, 1 }, /* ENET FDE */
  159. /* PC1 */ { 0, 0, 0, 1, 0, 0 }, /* ENET DSQE */
  160. /* PC0 */ { 0, 0, 0, 1, 0, 0 }, /* ENET LBK */
  161. },
  162. /* Port D */
  163. { /* conf ppar psor pdir podr pdat */
  164. /* PD31 */ { 1, 1, 0, 0, 0, 0 }, /* SCC1 EN RxD */
  165. /* PD30 */ { 1, 1, 1, 1, 0, 0 }, /* SCC1 EN TxD */
  166. /* PD29 */ { 0, 1, 0, 1, 0, 0 }, /* SCC1 EN TENA */
  167. /* PD28 */ { 0, 1, 0, 0, 0, 0 }, /* PD28 */
  168. /* PD27 */ { 0, 1, 1, 1, 0, 0 }, /* PD27 */
  169. /* PD26 */ { 0, 0, 0, 1, 0, 0 }, /* PD26 */
  170. /* PD25 */ { 0, 0, 0, 1, 0, 0 }, /* PD25 */
  171. /* PD24 */ { 0, 0, 0, 1, 0, 0 }, /* PD24 */
  172. /* PD23 */ { 0, 0, 0, 1, 0, 0 }, /* PD23 */
  173. /* PD22 */ { 0, 0, 0, 1, 0, 0 }, /* PD22 */
  174. /* PD21 */ { 0, 0, 0, 1, 0, 0 }, /* PD21 */
  175. /* PD20 */ { 0, 0, 0, 1, 0, 0 }, /* PD20 */
  176. /* PD19 */ { 0, 0, 0, 1, 0, 0 }, /* PD19 */
  177. /* PD18 */ { 0, 0, 0, 1, 0, 0 }, /* PD18 */
  178. /* PD17 */ { 0, 1, 0, 0, 0, 0 }, /* FCC1 ATMRXPRTY */
  179. /* PD16 */ { 0, 1, 0, 1, 0, 0 }, /* FCC1 ATMTXPRTY */
  180. /* PD15 */ { 1, 1, 1, 0, 1, 0 }, /* I2C SDA */
  181. /* PD14 */ { 1, 1, 1, 0, 1, 0 }, /* I2C SCL */
  182. /* PD13 */ { 0, 0, 0, 0, 0, 0 }, /* PD13 */
  183. /* PD12 */ { 0, 0, 0, 0, 0, 0 }, /* PD12 */
  184. /* PD11 */ { 0, 0, 0, 0, 0, 0 }, /* PD11 */
  185. /* PD10 */ { 0, 0, 0, 0, 0, 0 }, /* PD10 */
  186. /* PD9 */ { 1, 1, 0, 1, 0, 0 }, /* SMC1 TXD */
  187. /* PD8 */ { 1, 1, 0, 0, 0, 0 }, /* SMC1 RXD */
  188. /* PD7 */ { 0, 0, 0, 1, 0, 1 }, /* PD7 */
  189. /* PD6 */ { 0, 0, 0, 1, 0, 1 }, /* PD6 */
  190. /* PD5 */ { 0, 0, 0, 1, 0, 1 }, /* PD5 */
  191. /* PD4 */ { 0, 0, 0, 1, 0, 1 }, /* PD4 */
  192. /* PD3 */ { 0, 0, 0, 0, 0, 0 }, /* pin doesn't exist */
  193. /* PD2 */ { 0, 0, 0, 0, 0, 0 }, /* pin doesn't exist */
  194. /* PD1 */ { 0, 0, 0, 0, 0, 0 }, /* pin doesn't exist */
  195. /* PD0 */ { 0, 0, 0, 0, 0, 0 } /* pin doesn't exist */
  196. }
  197. };
  198. typedef struct bscr_ {
  199. unsigned long bcsr0;
  200. unsigned long bcsr1;
  201. unsigned long bcsr2;
  202. unsigned long bcsr3;
  203. unsigned long bcsr4;
  204. unsigned long bcsr5;
  205. unsigned long bcsr6;
  206. unsigned long bcsr7;
  207. } bcsr_t;
  208. void reset_phy(void)
  209. {
  210. volatile bcsr_t *bcsr = (bcsr_t *)CFG_BCSR;
  211. /* reset the FEC port */
  212. bcsr->bcsr1 &= ~FETH_RST;
  213. bcsr->bcsr1 |= FETH_RST;
  214. }
  215. int board_pre_init (void)
  216. {
  217. volatile bcsr_t *bcsr = (bcsr_t *)CFG_BCSR;
  218. bcsr->bcsr1 = ~FETHIEN & ~RS232EN_1;
  219. return 0;
  220. }
  221. int checkboard(void)
  222. {
  223. puts ("Board: Motorola MPC8266ADS\n");
  224. return 0;
  225. }
  226. long int initdram(int board_type)
  227. {
  228. /* Autoinit part stolen from board/sacsng/sacsng.c */
  229. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  230. volatile memctl8260_t *memctl = &immap->im_memctl;
  231. volatile uchar c = 0xff;
  232. volatile uchar *ramaddr = (uchar *)(CFG_SDRAM_BASE + 0x8);
  233. uint psdmr = CFG_PSDMR;
  234. int i;
  235. uint psrt = 14; /* for no SPD */
  236. uint chipselects = 1; /* for no SPD */
  237. uint sdram_size = CFG_SDRAM_SIZE * 1024 * 1024; /* for no SPD */
  238. uint or = CFG_OR2_PRELIM; /* for no SPD */
  239. uint data_width;
  240. uint rows;
  241. uint banks;
  242. uint cols;
  243. uint caslatency;
  244. uint width;
  245. uint rowst;
  246. uint sdam;
  247. uint bsma;
  248. uint sda10;
  249. u_char spd_size;
  250. u_char data;
  251. u_char cksum;
  252. int j;
  253. /* Keep the compiler from complaining about potentially uninitialized vars */
  254. data_width = chipselects = rows = banks = cols = caslatency = psrt = 0;
  255. /*
  256. * Read the SDRAM SPD EEPROM via I2C.
  257. */
  258. i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE);
  259. i2c_read(SDRAM_SPD_ADDR, 0, 1, &data, 1);
  260. spd_size = data;
  261. cksum = data;
  262. for(j = 1; j < 64; j++)
  263. { /* read only the checksummed bytes */
  264. /* note: the I2C address autoincrements when alen == 0 */
  265. i2c_read(SDRAM_SPD_ADDR, 0, 0, &data, 1);
  266. /*printf("addr %d = 0x%02x\n", j, data);*/
  267. if(j == 5) chipselects = data & 0x0F;
  268. else if(j == 6) data_width = data;
  269. else if(j == 7) data_width |= data << 8;
  270. else if(j == 3) rows = data & 0x0F;
  271. else if(j == 4) cols = data & 0x0F;
  272. else if(j == 12)
  273. {
  274. /*
  275. * Refresh rate: this assumes the prescaler is set to
  276. * approximately 1uSec per tick.
  277. */
  278. switch(data & 0x7F)
  279. {
  280. default:
  281. case 0: psrt = 16; /* 15.625uS */ break;
  282. case 1: psrt = 2; /* 3.9uS */ break;
  283. case 2: psrt = 6; /* 7.8uS */ break;
  284. case 3: psrt = 29; /* 31.3uS */ break;
  285. case 4: psrt = 60; /* 62.5uS */ break;
  286. case 5: psrt = 120; /* 125uS */ break;
  287. }
  288. }
  289. else if(j == 17) banks = data;
  290. else if(j == 18)
  291. {
  292. caslatency = 3; /* default CL */
  293. # if(PESSIMISTIC_SDRAM)
  294. if((data & 0x04) != 0) caslatency = 3;
  295. else if((data & 0x02) != 0) caslatency = 2;
  296. else if((data & 0x01) != 0) caslatency = 1;
  297. # else
  298. if((data & 0x01) != 0) caslatency = 1;
  299. else if((data & 0x02) != 0) caslatency = 2;
  300. else if((data & 0x04) != 0) caslatency = 3;
  301. # endif
  302. else
  303. {
  304. printf ("WARNING: Unknown CAS latency 0x%02X, using 3\n",
  305. data);
  306. }
  307. }
  308. else if(j == 63)
  309. {
  310. if(data != cksum)
  311. {
  312. printf ("WARNING: Configuration data checksum failure:"
  313. " is 0x%02x, calculated 0x%02x\n",
  314. data, cksum);
  315. }
  316. }
  317. cksum += data;
  318. }
  319. /* We don't trust CL less than 2 (only saw it on an old 16MByte DIMM) */
  320. if(caslatency < 2) {
  321. printf("CL was %d, forcing to 2\n", caslatency);
  322. caslatency = 2;
  323. }
  324. if(rows > 14) {
  325. printf("This doesn't look good, rows = %d, should be <= 14\n", rows);
  326. rows = 14;
  327. }
  328. if(cols > 11) {
  329. printf("This doesn't look good, columns = %d, should be <= 11\n", cols);
  330. cols = 11;
  331. }
  332. if((data_width != 64) && (data_width != 72))
  333. {
  334. printf("WARNING: SDRAM width unsupported, is %d, expected 64 or 72.\n",
  335. data_width);
  336. }
  337. width = 3; /* 2^3 = 8 bytes = 64 bits wide */
  338. /*
  339. * Convert banks into log2(banks)
  340. */
  341. if (banks == 2) banks = 1;
  342. else if(banks == 4) banks = 2;
  343. else if(banks == 8) banks = 3;
  344. sdram_size = 1 << (rows + cols + banks + width);
  345. #if(CONFIG_PBI == 0) /* bank-based interleaving */
  346. rowst = ((32 - 6) - (rows + cols + width)) * 2;
  347. #else
  348. rowst = 32 - (rows + banks + cols + width);
  349. #endif
  350. or = ~(sdram_size - 1) | /* SDAM address mask */
  351. ((banks-1) << 13) | /* banks per device */
  352. (rowst << 9) | /* rowst */
  353. ((rows - 9) << 6); /* numr */
  354. /*printf("memctl->memc_or2 = 0x%08x\n", or);*/
  355. /*
  356. * SDAM specifies the number of columns that are multiplexed
  357. * (reference AN2165/D), defined to be (columns - 6) for page
  358. * interleave, (columns - 8) for bank interleave.
  359. *
  360. * BSMA is 14 - max(rows, cols). The bank select lines come
  361. * into play above the highest "address" line going into the
  362. * the SDRAM.
  363. */
  364. #if(CONFIG_PBI == 0) /* bank-based interleaving */
  365. sdam = cols - 8;
  366. bsma = ((31 - width) - 14) - ((rows > cols) ? rows : cols);
  367. sda10 = sdam + 2;
  368. #else
  369. sdam = cols - 6;
  370. bsma = ((31 - width) - 14) - ((rows > cols) ? rows : cols);
  371. sda10 = sdam;
  372. #endif
  373. #if(PESSIMISTIC_SDRAM)
  374. psdmr = (CONFIG_PBI |\
  375. PSDMR_RFEN |\
  376. PSDMR_RFRC_16_CLK |\
  377. PSDMR_PRETOACT_8W |\
  378. PSDMR_ACTTORW_8W |\
  379. PSDMR_WRC_4C |\
  380. PSDMR_EAMUX |\
  381. PSDMR_BUFCMD) |\
  382. caslatency |\
  383. ((caslatency - 1) << 6) | /* LDOTOPRE is CL - 1 */ \
  384. (sdam << 24) |\
  385. (bsma << 21) |\
  386. (sda10 << 18);
  387. #else
  388. psdmr = (CONFIG_PBI |\
  389. PSDMR_RFEN |\
  390. PSDMR_RFRC_7_CLK |\
  391. PSDMR_PRETOACT_3W | /* 1 for 7E parts (fast PC-133) */ \
  392. PSDMR_ACTTORW_2W | /* 1 for 7E parts (fast PC-133) */ \
  393. PSDMR_WRC_1C | /* 1 clock + 7nSec */
  394. EAMUX |\
  395. BUFCMD) |\
  396. caslatency |\
  397. ((caslatency - 1) << 6) | /* LDOTOPRE is CL - 1 */ \
  398. (sdam << 24) |\
  399. (bsma << 21) |\
  400. (sda10 << 18);
  401. #endif
  402. /*printf("psdmr = 0x%08x\n", psdmr);*/
  403. /*
  404. * Quote from 8260 UM (10.4.2 SDRAM Power-On Initialization, 10-35):
  405. *
  406. * "At system reset, initialization software must set up the
  407. * programmable parameters in the memory controller banks registers
  408. * (ORx, BRx, P/LSDMR). After all memory parameters are configured,
  409. * system software should execute the following initialization sequence
  410. * for each SDRAM device.
  411. *
  412. * 1. Issue a PRECHARGE-ALL-BANKS command
  413. * 2. Issue eight CBR REFRESH commands
  414. * 3. Issue a MODE-SET command to initialize the mode register
  415. *
  416. * Quote from Micron MT48LC8M16A2 data sheet:
  417. *
  418. * "...the SDRAM requires a 100uS delay prior to issuing any
  419. * command other than a COMMAND INHIBIT or NOP. Starting at some
  420. * point during this 100uS period and continuing at least through
  421. * the end of this period, COMMAND INHIBIT or NOP commands should
  422. * be applied."
  423. *
  424. * "Once the 100uS delay has been satisfied with at least one COMMAND
  425. * INHIBIT or NOP command having been applied, a /PRECHARGE command/
  426. * should be applied. All banks must then be precharged, thereby
  427. * placing the device in the all banks idle state."
  428. *
  429. * "Once in the idle state, /two/ AUTO REFRESH cycles must be
  430. * performed. After the AUTO REFRESH cycles are complete, the
  431. * SDRAM is ready for mode register programming."
  432. *
  433. * (/emphasis/ mine, gvb)
  434. *
  435. * The way I interpret this, Micron start up sequence is:
  436. * 1. Issue a PRECHARGE-BANK command (initial precharge)
  437. * 2. Issue a PRECHARGE-ALL-BANKS command ("all banks ... precharged")
  438. * 3. Issue two (presumably, doing eight is OK) CBR REFRESH commands
  439. * 4. Issue a MODE-SET command to initialize the mode register
  440. *
  441. * --------
  442. *
  443. * The initial commands are executed by setting P/LSDMR[OP] and
  444. * accessing the SDRAM with a single-byte transaction."
  445. *
  446. * The appropriate BRx/ORx registers have already been set when we
  447. * get here. The SDRAM can be accessed at the address CFG_SDRAM_BASE.
  448. */
  449. #if 1
  450. memctl->memc_mptpr = CFG_MPTPR;
  451. memctl->memc_psrt = psrt;
  452. memctl->memc_psdmr = psdmr | PSDMR_OP_PREA;
  453. *ramaddr = c;
  454. memctl->memc_psdmr = psdmr | PSDMR_OP_CBRR;
  455. for (i = 0; i < 8; i++)
  456. *ramaddr = c;
  457. memctl->memc_psdmr = psdmr | PSDMR_OP_MRW;
  458. *ramaddr = c;
  459. memctl->memc_psdmr = psdmr | PSDMR_OP_NORM | PSDMR_RFEN;
  460. *ramaddr = c;
  461. /*
  462. * Do it a second time for the second set of chips if the DIMM has
  463. * two chip selects (double sided).
  464. */
  465. if(chipselects > 1)
  466. {
  467. ramaddr += sdram_size;
  468. memctl->memc_br3 = CFG_BR3_PRELIM + sdram_size;
  469. memctl->memc_or3 = or;
  470. memctl->memc_psdmr = psdmr | PSDMR_OP_PREA;
  471. *ramaddr = c;
  472. memctl->memc_psdmr = psdmr | PSDMR_OP_CBRR;
  473. for (i = 0; i < 8; i++)
  474. *ramaddr = c;
  475. memctl->memc_psdmr = psdmr | PSDMR_OP_MRW;
  476. *ramaddr = c;
  477. memctl->memc_psdmr = psdmr | PSDMR_OP_NORM | PSDMR_RFEN;
  478. *ramaddr = c;
  479. }
  480. #endif
  481. /*
  482. printf("memctl->memc_mptpr = 0x%08x\n", CFG_MPTPR);
  483. printf("memctl->memc_psrt = 0x%08x\n", psrt);
  484. printf("memctl->memc_psdmr = 0x%08x\n", psdmr | PSDMR_OP_PREA);
  485. printf("ramaddr = 0x%08x\n", ramaddr);
  486. printf("memctl->memc_psdmr = 0x%08x\n", psdmr | PSDMR_OP_CBRR);
  487. printf("memctl->memc_psdmr = 0x%08x\n", psdmr | PSDMR_OP_MRW);
  488. printf("memctl->memc_psdmr = 0x%08x\n", psdmr | PSDMR_OP_NORM | PSDMR_RFEN);
  489. immap->im_siu_conf.sc_ppc_acr = 0x00000002;
  490. immap->im_siu_conf.sc_ppc_alrh = 0x01267893;
  491. immap->im_siu_conf.sc_tescr1 = 0x00004000;
  492. */
  493. #if 0
  494. /* init sdram dimm */
  495. ramaddr = (uchar *)CFG_SDRAM_BASE;
  496. memctl->memc_psrt = 0x00000010;
  497. immap->im_memctl.memc_or2 = 0xFF000CA0;
  498. immap->im_memctl.memc_br2 = 0x00000041;
  499. memctl->memc_psdmr = 0x296EB452;
  500. *ramaddr = c;
  501. memctl->memc_psdmr = 0x096EB452;
  502. for (i = 0; i < 8; i++)
  503. *ramaddr = c;
  504. memctl->memc_psdmr = 0x196EB452;
  505. *ramaddr = c;
  506. memctl->memc_psdmr = 0x416EB452;
  507. *ramaddr = c;
  508. #endif
  509. /* print info */
  510. printf("SDRAM configuration read from SPD\n");
  511. printf("\tSize per side = %dMB\n", sdram_size >> 20);
  512. printf("\tOrganization: %d sides, %d banks, %d Columns, %d Rows, Data width = %d bits\n", chipselects, 1<<(banks), cols, rows, data_width);
  513. printf("\tRefresh rate = %d, CAS latency = %d\n", psrt, caslatency);
  514. printf("\tTotal size: ");
  515. return (sdram_size * chipselects);
  516. /*return (16 * 1024 * 1024);*/
  517. }