mpc8266ads.c 20 KB

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