mpc8266ads.c 21 KB

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