pm828.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. /*
  2. * (C) Copyright 2001-2004
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <ioports.h>
  25. #include <mpc8260.h>
  26. #include <pci.h>
  27. /*
  28. * I/O Port configuration table
  29. *
  30. * if conf is 1, then that port pin will be configured at boot time
  31. * according to the five values podr/pdir/ppar/psor/pdat for that entry
  32. */
  33. const iop_conf_t iop_conf_tab[4][32] = {
  34. /* Port A configuration */
  35. { /* conf ppar psor pdir podr pdat */
  36. /* PA31 */ { 1, 1, 1, 0, 0, 0 }, /* FCC1 COL */
  37. /* PA30 */ { 1, 1, 1, 0, 0, 0 }, /* FCC1 CRS */
  38. /* PA29 */ { 1, 1, 1, 1, 0, 0 }, /* FCC1 TXER */
  39. /* PA28 */ { 1, 1, 1, 1, 0, 0 }, /* FCC1 TXEN */
  40. /* PA27 */ { 1, 1, 1, 0, 0, 0 }, /* FCC1 RXDV */
  41. /* PA26 */ { 1, 1, 1, 0, 0, 0 }, /* FCC1 RXER */
  42. /* PA25 */ { 0, 0, 0, 1, 0, 0 }, /* PA25 */
  43. /* PA24 */ { 0, 0, 0, 1, 0, 0 }, /* PA24 */
  44. /* PA23 */ { 0, 0, 0, 1, 0, 0 }, /* PA23 */
  45. /* PA22 */ { 0, 0, 0, 1, 0, 0 }, /* PA22 */
  46. /* PA21 */ { 1, 1, 0, 1, 0, 0 }, /* FCC1 TXD3 */
  47. /* PA20 */ { 1, 1, 0, 1, 0, 0 }, /* FCC1 TXD2 */
  48. /* PA19 */ { 1, 1, 0, 1, 0, 0 }, /* FCC1 TXD1 */
  49. /* PA18 */ { 1, 1, 0, 1, 0, 0 }, /* FCC1 TXD0 */
  50. /* PA17 */ { 1, 1, 0, 0, 0, 0 }, /* FCC1 RXD0 */
  51. /* PA16 */ { 1, 1, 0, 0, 0, 0 }, /* FCC1 RXD1*/
  52. /* PA15 */ { 1, 1, 0, 0, 0, 0 }, /* FCC1 RXD2 */
  53. /* PA14 */ { 1, 1, 0, 0, 0, 0 }, /* FCC1 RXD3 */
  54. /* PA13 */ { 0, 0, 0, 1, 0, 0 }, /* PA13 */
  55. /* PA12 */ { 0, 0, 0, 1, 0, 0 }, /* PA12 */
  56. /* PA11 */ { 0, 0, 0, 1, 0, 0 }, /* PA11 */
  57. /* PA10 */ { 0, 0, 0, 1, 0, 0 }, /* PA10 */
  58. /* PA9 */ { 0, 1, 0, 1, 0, 0 }, /* PA9 */
  59. /* PA8 */ { 0, 1, 0, 0, 0, 0 }, /* PA8 */
  60. /* PA7 */ { 0, 0, 0, 1, 0, 0 }, /* PA7 */
  61. /* PA6 */ { 0, 0, 0, 1, 0, 0 }, /* PA6 */
  62. /* PA5 */ { 0, 0, 0, 1, 0, 0 }, /* PA5 */
  63. /* PA4 */ { 0, 0, 0, 1, 0, 0 }, /* PA4 */
  64. /* PA3 */ { 0, 0, 0, 1, 0, 0 }, /* PA3 */
  65. /* PA2 */ { 0, 0, 0, 1, 0, 0 }, /* PA2 */
  66. /* PA1 */ { 0, 0, 0, 1, 0, 0 }, /* PA1 */
  67. /* PA0 */ { 0, 0, 0, 1, 0, 0 } /* PA0 */
  68. },
  69. /* Port B configuration */
  70. { /* conf ppar psor pdir podr pdat */
  71. /* PB31 */ { 1, 1, 0, 1, 0, 0 }, /* FCC2 TX_ER */
  72. /* PB30 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 RX_DV */
  73. /* PB29 */ { 1, 1, 1, 1, 0, 0 }, /* FCC2 TX_EN */
  74. #if defined(CONFIG_ETHER_ON_SCC) && (CONFIG_ETHER_INDEX == 1)
  75. #ifdef CONFIG_ETHER_ON_FCC2
  76. #error "SCC1 conflicts with FCC2"
  77. #endif
  78. /* PB28 */ { 1, 1, 1, 1, 0, 0 }, /* SCC1 TXD */
  79. #else
  80. /* PB28 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 RX_ER */
  81. #endif
  82. /* PB27 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 COL */
  83. /* PB26 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 CRS */
  84. /* PB25 */ { 1, 1, 0, 1, 0, 0 }, /* FCC2 TxD[3] */
  85. /* PB24 */ { 1, 1, 0, 1, 0, 0 }, /* FCC2 TxD[2] */
  86. /* PB23 */ { 1, 1, 0, 1, 0, 0 }, /* FCC2 TxD[1] */
  87. /* PB22 */ { 1, 1, 0, 1, 0, 0 }, /* FCC2 TxD[0] */
  88. /* PB21 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 RxD[0] */
  89. /* PB20 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 RxD[1] */
  90. /* PB19 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 RxD[2] */
  91. /* PB18 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 RxD[3] */
  92. /* PB17 */ { 0, 0, 0, 0, 0, 0 }, /* PB17 */
  93. /* PB16 */ { 0, 0, 0, 0, 0, 0 }, /* PB16 */
  94. /* PB15 */ { 1, 1, 0, 0, 0, 0 }, /* SCC2 RXD */
  95. /* PB14 */ { 1, 1, 0, 0, 0, 0 }, /* SCC3 RXD */
  96. /* PB13 */ { 0, 0, 0, 0, 0, 0 }, /* PB13 */
  97. /* PB12 */ { 0, 0, 0, 0, 0, 0 }, /* PB12 */
  98. /* PB11 */ { 0, 0, 0, 0, 0, 0 }, /* PB11 */
  99. /* PB10 */ { 0, 0, 0, 0, 0, 0 }, /* PB10 */
  100. /* PB9 */ { 0, 0, 0, 0, 0, 0 }, /* PB9 */
  101. /* PB8 */ { 1, 1, 1, 1, 0, 0 }, /* SCC3 TXD */
  102. /* PB7 */ { 0, 0, 0, 0, 0, 0 }, /* PB7 */
  103. /* PB6 */ { 0, 0, 0, 0, 0, 0 }, /* PB6 */
  104. /* PB5 */ { 0, 0, 0, 0, 0, 0 }, /* PB5 */
  105. /* PB4 */ { 0, 0, 0, 0, 0, 0 }, /* PB4 */
  106. /* PB3 */ { 0, 0, 0, 0, 0, 0 }, /* pin doesn't exist */
  107. /* PB2 */ { 0, 0, 0, 0, 0, 0 }, /* pin doesn't exist */
  108. /* PB1 */ { 0, 0, 0, 0, 0, 0 }, /* pin doesn't exist */
  109. /* PB0 */ { 0, 0, 0, 0, 0, 0 } /* pin doesn't exist */
  110. },
  111. /* Port C */
  112. { /* conf ppar psor pdir podr pdat */
  113. /* PC31 */ { 0, 0, 0, 1, 0, 0 }, /* PC31 */
  114. /* PC30 */ { 0, 0, 0, 1, 0, 0 }, /* PC30 */
  115. /* PC29 */ { 0, 1, 1, 0, 0, 0 }, /* SCC1 CTS */
  116. /* PC28 */ { 0, 0, 0, 1, 0, 0 }, /* SCC2 CTS */
  117. /* PC27 */ { 0, 0, 0, 1, 0, 0 }, /* PC27 */
  118. /* PC26 */ { 0, 0, 0, 1, 0, 0 }, /* PC26 */
  119. /* PC25 */ { 0, 0, 0, 1, 0, 0 }, /* PC25 */
  120. /* PC24 */ { 0, 0, 0, 1, 0, 0 }, /* PC24 */
  121. /* PC23 */ { 0, 1, 0, 1, 0, 0 }, /* PC23 */
  122. /* PC22 */ { 1, 1, 0, 0, 0, 0 }, /* FCC1 TXCK */
  123. /* PC21 */ { 1, 1, 0, 0, 0, 0 }, /* FCC1 RXCK */
  124. /* PC20 */ { 1, 1, 0, 0, 0, 0 }, /* FCC1 TXCK(2) */
  125. /* PC19 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 RXCK */
  126. /* PC18 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 TXCK */
  127. /* PC17 */ { 0, 0, 0, 1, 0, 0 }, /* PC17 */
  128. /* PC16 */ { 0, 0, 0, 1, 0, 0 }, /* PC16 */
  129. /* PC15 */ { 1, 1, 0, 1, 0, 0 }, /* SMC2 TXD */
  130. /* PC14 */ { 0, 1, 0, 0, 0, 0 }, /* SCC1 DCD */
  131. /* PC13 */ { 0, 0, 0, 1, 0, 0 }, /* PC13 */
  132. /* PC12 */ { 0, 0, 0, 1, 0, 0 }, /* SCC2 DCD */
  133. /* PC11 */ { 0, 0, 0, 1, 0, 0 }, /* SCC3 CTS */
  134. /* PC10 */ { 0, 0, 0, 1, 0, 0 }, /* SCC3 DCD */
  135. /* PC9 */ { 0, 0, 0, 1, 0, 0 }, /* SCC4 CTS */
  136. /* PC8 */ { 0, 0, 0, 1, 0, 0 }, /* SCC4 DCD */
  137. /* PC7 */ { 0, 0, 0, 1, 0, 0 }, /* PC7 */
  138. /* PC6 */ { 0, 0, 0, 1, 0, 0 }, /* PC6 */
  139. /* PC5 */ { 0, 0, 0, 1, 0, 0 }, /* PC5 */
  140. /* PC4 */ { 0, 0, 0, 1, 0, 0 }, /* PC4 */
  141. /* PC3 */ { 0, 0, 0, 1, 0, 0 }, /* PC3 */
  142. /* PC2 */ { 0, 0, 0, 1, 0, 1 }, /* PC2 */
  143. /* PC1 */ { 0, 0, 0, 1, 0, 0 }, /* PC1 */
  144. /* PC0 */ { 0, 0, 0, 1, 0, 0 }, /* PC0 */
  145. },
  146. /* Port D */
  147. { /* conf ppar psor pdir podr pdat */
  148. /* PD31 */ { 1, 1, 0, 0, 0, 0 }, /* SCC1 RXD */
  149. /* PD30 */ { 0, 1, 1, 1, 0, 0 }, /* PD30 */
  150. /* PD29 */ { 0, 1, 0, 1, 0, 0 }, /* SCC1 RTS */
  151. /* PD28 */ { 0, 0, 0, 1, 0, 0 }, /* PD28 */
  152. /* PD27 */ { 0, 1, 0, 1, 0, 0 }, /* SCC2 RTS */
  153. /* PD26 */ { 0, 0, 0, 1, 0, 0 }, /* PD26 */
  154. /* PD25 */ { 0, 0, 0, 1, 0, 0 }, /* PD25 */
  155. /* PD24 */ { 0, 0, 0, 1, 0, 0 }, /* PD24 */
  156. /* PD23 */ { 0, 0, 0, 1, 0, 0 }, /* SCC3 RTS */
  157. /* PD22 */ { 1, 1, 0, 0, 0, 0 }, /* SCC4 RXD */
  158. /* PD21 */ { 1, 1, 0, 1, 0, 0 }, /* SCC4 TXD */
  159. /* PD20 */ { 0, 0, 1, 1, 0, 0 }, /* SCC4 RTS */
  160. /* PD19 */ { 0, 0, 0, 1, 0, 0 }, /* PD19 */
  161. /* PD18 */ { 0, 0, 0, 1, 0, 0 }, /* PD18 */
  162. /* PD17 */ { 0, 1, 0, 0, 0, 0 }, /* PD17 */
  163. /* PD16 */ { 0, 1, 0, 1, 0, 0 }, /* PD16 */
  164. #if defined(CONFIG_SOFT_I2C)
  165. /* PD15 */ { 1, 0, 0, 1, 1, 1 }, /* I2C SDA */
  166. /* PD14 */ { 1, 0, 0, 1, 1, 1 }, /* I2C SCL */
  167. #else
  168. #if defined(CONFIG_HARD_I2C)
  169. /* PD15 */ { 1, 1, 1, 0, 1, 0 }, /* I2C SDA */
  170. /* PD14 */ { 1, 1, 1, 0, 1, 0 }, /* I2C SCL */
  171. #else /* normal I/O port pins */
  172. /* PD15 */ { 0, 1, 1, 0, 1, 0 }, /* I2C SDA */
  173. /* PD14 */ { 0, 1, 1, 0, 1, 0 }, /* I2C SCL */
  174. #endif
  175. #endif
  176. /* PD13 */ { 0, 0, 0, 0, 0, 0 }, /* PD13 */
  177. /* PD12 */ { 0, 0, 0, 0, 0, 0 }, /* PD12 */
  178. /* PD11 */ { 0, 0, 0, 0, 0, 0 }, /* PD11 */
  179. /* PD10 */ { 0, 0, 0, 0, 0, 0 }, /* PD10 */
  180. /* PD9 */ { 0, 1, 0, 1, 0, 0 }, /* PD9 */
  181. /* PD8 */ { 0, 1, 0, 0, 0, 0 }, /* PD8 */
  182. /* PD7 */ { 0, 0, 0, 1, 0, 1 }, /* PD7 */
  183. /* PD6 */ { 0, 0, 0, 1, 0, 1 }, /* PD6 */
  184. /* PD5 */ { 0, 0, 0, 1, 0, 1 }, /* PD5 */
  185. /* PD4 */ { 1, 1, 1, 0, 0, 0 }, /* SMC2 RXD */
  186. /* PD3 */ { 0, 0, 0, 0, 0, 0 }, /* pin doesn't exist */
  187. /* PD2 */ { 0, 0, 0, 0, 0, 0 }, /* pin doesn't exist */
  188. /* PD1 */ { 0, 0, 0, 0, 0, 0 }, /* pin doesn't exist */
  189. /* PD0 */ { 0, 0, 0, 0, 0, 0 } /* pin doesn't exist */
  190. }
  191. };
  192. /* ------------------------------------------------------------------------- */
  193. /* Check Board Identity:
  194. */
  195. int checkboard (void)
  196. {
  197. puts ("Board: PM828\n");
  198. return 0;
  199. }
  200. /* ------------------------------------------------------------------------- */
  201. /* Try SDRAM initialization with P/LSDMR=sdmr and ORx=orx
  202. *
  203. * This routine performs standard 8260 initialization sequence
  204. * and calculates the available memory size. It may be called
  205. * several times to try different SDRAM configurations on both
  206. * 60x and local buses.
  207. */
  208. static long int try_init (volatile memctl8260_t * memctl, ulong sdmr,
  209. ulong orx, volatile uchar * base)
  210. {
  211. volatile uchar c = 0xff;
  212. volatile ulong cnt, val;
  213. volatile ulong *addr;
  214. volatile uint *sdmr_ptr;
  215. volatile uint *orx_ptr;
  216. int i;
  217. ulong save[32]; /* to make test non-destructive */
  218. ulong maxsize;
  219. /* We must be able to test a location outsize the maximum legal size
  220. * to find out THAT we are outside; but this address still has to be
  221. * mapped by the controller. That means, that the initial mapping has
  222. * to be (at least) twice as large as the maximum expected size.
  223. */
  224. maxsize = (1 + (~orx | 0x7fff)) / 2;
  225. sdmr_ptr = &memctl->memc_psdmr;
  226. orx_ptr = &memctl->memc_or2;
  227. *orx_ptr = orx;
  228. /*
  229. * Quote from 8260 UM (10.4.2 SDRAM Power-On Initialization, 10-35):
  230. *
  231. * "At system reset, initialization software must set up the
  232. * programmable parameters in the memory controller banks registers
  233. * (ORx, BRx, P/LSDMR). After all memory parameters are configured,
  234. * system software should execute the following initialization sequence
  235. * for each SDRAM device.
  236. *
  237. * 1. Issue a PRECHARGE-ALL-BANKS command
  238. * 2. Issue eight CBR REFRESH commands
  239. * 3. Issue a MODE-SET command to initialize the mode register
  240. *
  241. * The initial commands are executed by setting P/LSDMR[OP] and
  242. * accessing the SDRAM with a single-byte transaction."
  243. *
  244. * The appropriate BRx/ORx registers have already been set when we
  245. * get here. The SDRAM can be accessed at the address CFG_SDRAM_BASE.
  246. */
  247. *sdmr_ptr = sdmr | PSDMR_OP_PREA;
  248. *base = c;
  249. *sdmr_ptr = sdmr | PSDMR_OP_CBRR;
  250. for (i = 0; i < 8; i++)
  251. *base = c;
  252. *sdmr_ptr = sdmr | PSDMR_OP_MRW;
  253. *(base + CFG_MRS_OFFS) = c; /* setting MR on address lines */
  254. *sdmr_ptr = sdmr | PSDMR_OP_NORM | PSDMR_RFEN;
  255. *base = c;
  256. /*
  257. * Check memory range for valid RAM. A simple memory test determines
  258. * the actually available RAM size between addresses `base' and
  259. * `base + maxsize'. Some (not all) hardware errors are detected:
  260. * - short between address lines
  261. * - short between data lines
  262. */
  263. i = 0;
  264. for (cnt = maxsize / sizeof (long); cnt > 0; cnt >>= 1) {
  265. addr = (volatile ulong *) base + cnt; /* pointer arith! */
  266. save[i++] = *addr;
  267. *addr = ~cnt;
  268. }
  269. addr = (volatile ulong *) base;
  270. save[i] = *addr;
  271. *addr = 0;
  272. if ((val = *addr) != 0) {
  273. *addr = save[i];
  274. return (0);
  275. }
  276. for (cnt = 1; cnt <= maxsize / sizeof (long); cnt <<= 1) {
  277. addr = (volatile ulong *) base + cnt; /* pointer arith! */
  278. val = *addr;
  279. *addr = save[--i];
  280. if (val != ~cnt) {
  281. /* Write the actual size to ORx
  282. */
  283. *orx_ptr = orx | ~(cnt * sizeof (long) - 1);
  284. return (cnt * sizeof (long));
  285. }
  286. }
  287. return (maxsize);
  288. }
  289. long int initdram (int board_type)
  290. {
  291. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  292. volatile memctl8260_t *memctl = &immap->im_memctl;
  293. #ifndef CFG_RAMBOOT
  294. ulong size8, size9;
  295. #endif
  296. ulong psize = 32 * 1024 * 1024;
  297. memctl->memc_psrt = CFG_PSRT;
  298. memctl->memc_mptpr = CFG_MPTPR;
  299. #ifndef CFG_RAMBOOT
  300. size8 = try_init (memctl, CFG_PSDMR_8COL, CFG_OR2_8COL,
  301. (uchar *) CFG_SDRAM_BASE);
  302. size9 = try_init (memctl, CFG_PSDMR_9COL, CFG_OR2_9COL,
  303. (uchar *) CFG_SDRAM_BASE);
  304. if (size8 < size9) {
  305. psize = size9;
  306. printf ("(60x:9COL) ");
  307. } else {
  308. psize = try_init (memctl, CFG_PSDMR_8COL, CFG_OR2_8COL,
  309. (uchar *) CFG_SDRAM_BASE);
  310. printf ("(60x:8COL) ");
  311. }
  312. #endif
  313. return (psize);
  314. }
  315. #if defined(CONFIG_CMD_DOC)
  316. extern void doc_probe (ulong physadr);
  317. void doc_init (void)
  318. {
  319. doc_probe (CFG_DOC_BASE);
  320. }
  321. #endif
  322. #ifdef CONFIG_PCI
  323. struct pci_controller hose;
  324. extern void pci_mpc8250_init(struct pci_controller *);
  325. void pci_init_board(void)
  326. {
  327. pci_mpc8250_init(&hose);
  328. }
  329. #endif