ids8247.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. /*
  2. * (C) Copyright 2005
  3. * Heiko Schocher, DENX Software Engineering, <hs@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. #if defined(CONFIG_OF_LIBFDT)
  27. #include <libfdt.h>
  28. #include <libfdt_env.h>
  29. #include <fdt_support.h>
  30. #endif
  31. DECLARE_GLOBAL_DATA_PTR;
  32. /*
  33. * I/O Port configuration table
  34. *
  35. * if conf is 1, then that port pin will be configured at boot time
  36. * according to the five values podr/pdir/ppar/psor/pdat for that entry
  37. */
  38. const iop_conf_t iop_conf_tab[4][32] = {
  39. /* Port A configuration */
  40. { /* conf ppar psor pdir podr pdat */
  41. /* PA31 */ { 1, 1, 1, 0, 0, 0 }, /* FCC1 COL */
  42. /* PA30 */ { 1, 1, 1, 0, 0, 0 }, /* FCC1 CRS */
  43. /* PA29 */ { 1, 1, 1, 1, 0, 0 }, /* FCC1 TXER */
  44. /* PA28 */ { 1, 1, 1, 1, 0, 0 }, /* FCC1 TXEN */
  45. /* PA27 */ { 1, 1, 1, 0, 0, 0 }, /* FCC1 RXDV */
  46. /* PA26 */ { 1, 1, 1, 0, 0, 0 }, /* FCC1 RXER */
  47. /* PA25 */ { 0, 0, 0, 0, 1, 0 }, /* 8247_P0 */
  48. #if defined(CONFIG_SOFT_I2C)
  49. /* PA24 */ { 1, 0, 0, 0, 1, 1 }, /* I2C_SDA2 */
  50. /* PA23 */ { 1, 0, 0, 1, 1, 1 }, /* I2C_SCL2 */
  51. #else /* normal I/O port pins */
  52. /* PA24 */ { 0, 0, 0, 1, 0, 0 }, /* PA24 */
  53. /* PA23 */ { 0, 0, 0, 1, 0, 0 }, /* PA23 */
  54. #endif
  55. /* PA22 */ { 0, 0, 0, 0, 1, 0 }, /* SMC2_DCD */
  56. /* PA21 */ { 1, 1, 0, 1, 0, 0 }, /* FCC1 TXD3 */
  57. /* PA20 */ { 1, 1, 0, 1, 0, 0 }, /* FCC1 TXD2 */
  58. /* PA19 */ { 1, 1, 0, 1, 0, 0 }, /* FCC1 TXD1 */
  59. /* PA18 */ { 1, 1, 0, 1, 0, 0 }, /* FCC1 TXD0 */
  60. /* PA17 */ { 1, 1, 0, 0, 0, 0 }, /* FCC1 RXD0 */
  61. /* PA16 */ { 1, 1, 0, 0, 0, 0 }, /* FCC1 RXD1 */
  62. /* PA15 */ { 1, 1, 0, 0, 0, 0 }, /* FCC1 RXD2 */
  63. /* PA14 */ { 1, 1, 0, 0, 0, 0 }, /* FCC1 RXD3 */
  64. /* PA13 */ { 0, 0, 0, 1, 1, 0 }, /* SMC2_RTS */
  65. /* PA12 */ { 0, 0, 0, 0, 1, 0 }, /* SMC2_CTS */
  66. /* PA11 */ { 0, 0, 0, 1, 1, 0 }, /* SMC2_DTR */
  67. /* PA10 */ { 0, 0, 0, 0, 1, 0 }, /* SMC2_DSR */
  68. /* PA9 */ { 0, 1, 0, 1, 0, 0 }, /* SMC2 TXD */
  69. /* PA8 */ { 0, 1, 0, 0, 0, 0 }, /* SMC2 RXD */
  70. /* PA7 */ { 0, 0, 0, 1, 0, 0 }, /* PA7 */
  71. /* PA6 */ { 0, 0, 0, 1, 0, 0 }, /* PA6 */
  72. /* PA5 */ { 0, 0, 0, 1, 0, 0 }, /* PA5 */
  73. /* PA4 */ { 0, 0, 0, 1, 0, 0 }, /* PA4 */
  74. /* PA3 */ { 0, 0, 0, 1, 0, 0 }, /* PA3 */
  75. /* PA2 */ { 0, 0, 0, 1, 0, 0 }, /* PA2 */
  76. /* PA1 */ { 0, 0, 0, 1, 0, 0 }, /* PA1 */
  77. /* PA0 */ { 0, 0, 0, 1, 0, 0 } /* PA0 */
  78. },
  79. /* Port B configuration */
  80. { /* conf ppar psor pdir podr pdat */
  81. /* PB31 */ { 0, 1, 0, 1, 0, 0 }, /* FCC2 MII TX_ER */
  82. /* PB30 */ { 0, 1, 0, 0, 0, 0 }, /* FCC2 MII RX_DV */
  83. /* PB29 */ { 0, 1, 1, 1, 0, 0 }, /* FCC2 MII TX_EN */
  84. /* PB28 */ { 0, 1, 0, 0, 0, 0 }, /* FCC2 MII RX_ER */
  85. /* PB27 */ { 0, 1, 0, 0, 0, 0 }, /* FCC2 MII COL */
  86. /* PB26 */ { 0, 1, 0, 0, 0, 0 }, /* FCC2 MII CRS */
  87. /* PB25 */ { 0, 1, 0, 1, 0, 0 }, /* FCC2 MII TxD[3] */
  88. /* PB24 */ { 0, 1, 0, 1, 0, 0 }, /* FCC2 MII TxD[2] */
  89. /* PB23 */ { 0, 1, 0, 1, 0, 0 }, /* FCC2 MII TxD[1] */
  90. /* PB22 */ { 0, 1, 0, 1, 0, 0 }, /* FCC2 MII TxD[0] */
  91. /* PB21 */ { 0, 1, 0, 0, 0, 0 }, /* FCC2 MII RxD[0] */
  92. /* PB20 */ { 0, 1, 0, 0, 0, 0 }, /* FCC2 MII RxD[1] */
  93. /* PB19 */ { 0, 1, 0, 0, 0, 0 }, /* FCC2 MII RxD[2] */
  94. /* PB18 */ { 0, 1, 0, 0, 0, 0 }, /* FCC2 MII RxD[3] */
  95. /* PB17 */ { 0, 0, 0, 0, 0, 0 }, /* PB17 */
  96. /* PB16 */ { 0, 0, 0, 0, 0, 0 }, /* PB16 */
  97. /* PB15 */ { 0, 0, 0, 0, 0, 0 }, /* PB15 */
  98. /* PB14 */ { 0, 0, 0, 0, 0, 0 }, /* PB14 */
  99. /* PB13 */ { 0, 0, 0, 0, 0, 0 }, /* PB13 */
  100. /* PB12 */ { 0, 0, 0, 0, 0, 0 }, /* PB12 */
  101. /* PB11 */ { 0, 0, 0, 0, 0, 0 }, /* PB11 */
  102. /* PB10 */ { 0, 0, 0, 0, 0, 0 }, /* PB10 */
  103. /* PB9 */ { 0, 0, 0, 0, 0, 0 }, /* PB9 */
  104. /* PB8 */ { 0, 0, 0, 0, 0, 0 }, /* PB8 */
  105. /* PB7 */ { 0, 0, 0, 0, 0, 0 }, /* PB7 */
  106. /* PB6 */ { 0, 0, 0, 0, 0, 0 }, /* PB6 */
  107. /* PB5 */ { 0, 0, 0, 0, 0, 0 }, /* PB5 */
  108. /* PB4 */ { 0, 0, 0, 0, 0, 0 }, /* PB4 */
  109. /* PB3 */ { 0, 0, 0, 0, 0, 0 }, /* pin doesn't exist */
  110. /* PB2 */ { 0, 0, 0, 0, 0, 0 }, /* pin doesn't exist */
  111. /* PB1 */ { 0, 0, 0, 0, 0, 0 }, /* pin doesn't exist */
  112. /* PB0 */ { 0, 0, 0, 0, 0, 0 } /* pin doesn't exist */
  113. },
  114. /* Port C */
  115. { /* conf ppar psor pdir podr pdat */
  116. /* PC31 */ { 0, 0, 0, 1, 0, 0 }, /* PC31 */
  117. /* PC30 */ { 0, 0, 0, 1, 0, 0 }, /* PC30 */
  118. /* PC29 */ { 0, 1, 0, 0, 0, 0 }, /* SCC1 EN *CLSN */
  119. /* PC28 */ { 0, 1, 1, 0, 0, 0 }, /* SYNC_OUT */
  120. /* PC27 */ { 0, 0, 0, 1, 0, 0 }, /* PC27 */
  121. /* PC26 */ { 0, 0, 0, 1, 0, 0 }, /* PC26 */
  122. /* PC25 */ { 0, 1, 1, 0, 0, 0 }, /* SYNC_IN */
  123. /* PC24 */ { 0, 0, 0, 1, 0, 0 }, /* PC24 */
  124. /* PC23 */ { 1, 1, 0, 0, 0, 0 }, /* FCC1 MII TX_CLK */
  125. /* PC22 */ { 1, 1, 0, 0, 0, 0 }, /* FCC1 MII RX_CLK */
  126. /* PC21 */ { 0, 1, 0, 0, 0, 0 }, /* SCC1 EN RXCLK */
  127. /* PC20 */ { 0, 1, 0, 0, 0, 0 }, /* SCC1 EN TXCLK */
  128. /* PC19 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII RX_CLK */
  129. /* PC18 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII TX_CLK */
  130. /* PC17 */ { 0, 0, 0, 1, 0, 0 }, /* PC17 */
  131. /* PC16 */ { 0, 0, 0, 1, 0, 0 }, /* PC16 */
  132. /* PC15 */ { 0, 0, 0, 1, 0, 0 }, /* PC15 */
  133. /* PC14 */ { 0, 1, 0, 0, 0, 0 }, /* SCC1 EN *CD */
  134. /* PC13 */ { 0, 0, 0, 1, 0, 0 }, /* PC13 */
  135. /* PC12 */ { 0, 0, 0, 1, 0, 0 }, /* PC12 */
  136. /* PC11 */ { 0, 0, 0, 1, 0, 0 }, /* PC11 */
  137. /* PC10 */ { 0, 0, 0, 1, 0, 0 }, /* FCC2 MDC */
  138. /* PC9 */ { 0, 0, 0, 1, 0, 0 }, /* FCC2 MDIO */
  139. /* PC8 */ { 0, 0, 0, 1, 0, 0 }, /* PC8 */
  140. /* PC7 */ { 0, 0, 0, 1, 0, 0 }, /* PC7 */
  141. /* PC6 */ { 0, 0, 0, 1, 0, 0 }, /* PC6 */
  142. /* PC5 */ { 0, 0, 0, 1, 0, 0 }, /* PC5 */
  143. /* PC4 */ { 0, 0, 0, 1, 0, 0 }, /* PC4 */
  144. /* PC3 */ { 0, 0, 0, 1, 0, 0 }, /* PC3 */
  145. /* PC2 */ { 0, 0, 0, 1, 0, 1 }, /* ENET FDE */
  146. /* PC1 */ { 0, 0, 0, 1, 0, 0 }, /* ENET DSQE */
  147. /* PC0 */ { 0, 0, 0, 1, 0, 0 }, /* ENET LBK */
  148. },
  149. /* Port D */
  150. { /* conf ppar psor pdir podr pdat */
  151. /* PD31 */ { 0, 1, 0, 0, 0, 0 }, /* SCC1 EN RxD */
  152. /* PD30 */ { 0, 1, 1, 1, 0, 0 }, /* SCC1 EN TxD */
  153. /* PD29 */ { 0, 1, 0, 1, 0, 0 }, /* SCC1 EN TENA */
  154. /* PD28 */ { 0, 0, 0, 1, 0, 0 }, /* PD28 */
  155. /* PD27 */ { 0, 0, 0, 1, 0, 0 }, /* PD27 */
  156. /* PD26 */ { 0, 0, 0, 1, 0, 0 }, /* PD26 */
  157. /* PD25 */ { 0, 1, 0, 0, 0, 0 }, /* SCC3_RX */
  158. /* PD24 */ { 0, 1, 0, 1, 0, 0 }, /* SCC3_TX */
  159. /* PD23 */ { 0, 1, 0, 1, 0, 0 }, /* SCC3_RTS */
  160. /* PD22 */ { 0, 1, 0, 0, 0, 0 }, /* SCC4_RXD */
  161. /* PD21 */ { 0, 1, 0, 1, 0, 0 }, /* SCC4_TXD */
  162. /* PD20 */ { 0, 1, 0, 1, 0, 0 }, /* SCC4_RTS */
  163. /* PD19 */ { 0, 1, 1, 0, 0, 0 }, /* SPI_SEL */
  164. /* PD18 */ { 0, 1, 1, 0, 0, 0 }, /* SPI_CLK */
  165. /* PD17 */ { 0, 1, 1, 0, 0, 0 }, /* SPI_MOSI */
  166. /* PD16 */ { 0, 1, 1, 0, 0, 0 }, /* SPI_MISO */
  167. #if defined(CONFIG_HARD_I2C)
  168. /* PD15 */ { 1, 1, 1, 0, 1, 0 }, /* I2C SDA1 */
  169. /* PD14 */ { 1, 1, 1, 0, 1, 0 }, /* I2C SCL1 */
  170. #else /* normal I/O port pins */
  171. /* PD15 */ { 0, 1, 1, 0, 1, 0 }, /* PD15 */
  172. /* PD14 */ { 0, 1, 1, 0, 1, 0 }, /* PD14 */
  173. #endif
  174. /* PD13 */ { 0, 0, 0, 0, 0, 0 }, /* PD13 */
  175. /* PD12 */ { 0, 0, 0, 0, 0, 0 }, /* PD12 */
  176. /* PD11 */ { 0, 0, 0, 0, 0, 0 }, /* PD11 */
  177. /* PD10 */ { 0, 0, 0, 0, 0, 0 }, /* PD10 */
  178. /* PD9 */ { 0, 0, 0, 0, 0, 0 }, /* PD9 */
  179. /* PD8 */ { 0, 0, 0, 0, 0, 0 }, /* PD8 */
  180. /* PD7 */ { 1, 0, 0, 1, 0, 1 }, /* MII_MDIO */
  181. /* PD6 */ { 0, 0, 0, 1, 0, 1 }, /* PD6 */
  182. /* PD5 */ { 0, 0, 0, 1, 0, 1 }, /* PD5 */
  183. /* PD4 */ { 0, 0, 0, 1, 0, 1 }, /* PD4 */
  184. /* PD3 */ { 0, 0, 0, 0, 0, 0 }, /* pin doesn't exist */
  185. /* PD2 */ { 0, 0, 0, 0, 0, 0 }, /* pin doesn't exist */
  186. /* PD1 */ { 0, 0, 0, 0, 0, 0 }, /* pin doesn't exist */
  187. /* PD0 */ { 0, 0, 0, 0, 0, 0 } /* pin doesn't exist */
  188. }
  189. };
  190. /* ------------------------------------------------------------------------- */
  191. /* Check Board Identity:
  192. */
  193. int checkboard (void)
  194. {
  195. puts ("Board: IDS 8247\n");
  196. return 0;
  197. }
  198. /* ------------------------------------------------------------------------- */
  199. /* Try SDRAM initialization with P/LSDMR=sdmr and ORx=orx
  200. *
  201. * This routine performs standard 8260 initialization sequence
  202. * and calculates the available memory size. It may be called
  203. * several times to try different SDRAM configurations on both
  204. * 60x and local buses.
  205. */
  206. static long int try_init (volatile memctl8260_t * memctl, ulong sdmr,
  207. ulong orx, volatile uchar * base)
  208. {
  209. volatile uchar c = 0xff;
  210. volatile uint *sdmr_ptr;
  211. volatile uint *orx_ptr;
  212. ulong maxsize, size;
  213. int i;
  214. /* We must be able to test a location outsize the maximum legal size
  215. * to find out THAT we are outside; but this address still has to be
  216. * mapped by the controller. That means, that the initial mapping has
  217. * to be (at least) twice as large as the maximum expected size.
  218. */
  219. maxsize = (1 + (~orx | 0x7fff))/* / 2*/;
  220. sdmr_ptr = &memctl->memc_psdmr;
  221. orx_ptr = &memctl->memc_or2;
  222. *orx_ptr = orx;
  223. /*
  224. * Quote from 8260 UM (10.4.2 SDRAM Power-On Initialization, 10-35):
  225. *
  226. * "At system reset, initialization software must set up the
  227. * programmable parameters in the memory controller banks registers
  228. * (ORx, BRx, P/LSDMR). After all memory parameters are configured,
  229. * system software should execute the following initialization sequence
  230. * for each SDRAM device.
  231. *
  232. * 1. Issue a PRECHARGE-ALL-BANKS command
  233. * 2. Issue eight CBR REFRESH commands
  234. * 3. Issue a MODE-SET command to initialize the mode register
  235. *
  236. * The initial commands are executed by setting P/LSDMR[OP] and
  237. * accessing the SDRAM with a single-byte transaction."
  238. *
  239. * The appropriate BRx/ORx registers have already been set when we
  240. * get here. The SDRAM can be accessed at the address CFG_SDRAM_BASE.
  241. */
  242. *sdmr_ptr = sdmr | PSDMR_OP_PREA;
  243. *base = c;
  244. *sdmr_ptr = sdmr | PSDMR_OP_CBRR;
  245. for (i = 0; i < 8; i++)
  246. *base = c;
  247. *sdmr_ptr = sdmr | PSDMR_OP_MRW;
  248. *(base + CFG_MRS_OFFS) = c; /* setting MR on address lines */
  249. *sdmr_ptr = sdmr | PSDMR_OP_NORM | PSDMR_RFEN;
  250. *base = c;
  251. size = get_ram_size((long *)base, maxsize);
  252. *orx_ptr = orx | ~(size - 1);
  253. return (size);
  254. }
  255. phys_size_t initdram (int board_type)
  256. {
  257. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  258. volatile memctl8260_t *memctl = &immap->im_memctl;
  259. long psize, lsize;
  260. psize = 16 * 1024 * 1024;
  261. lsize = 0;
  262. memctl->memc_psrt = CFG_PSRT;
  263. memctl->memc_mptpr = CFG_MPTPR;
  264. #ifndef CFG_RAMBOOT
  265. /* 60x SDRAM setup:
  266. */
  267. psize = try_init (memctl, CFG_PSDMR, CFG_OR2,
  268. (uchar *) CFG_SDRAM_BASE);
  269. #endif /* CFG_RAMBOOT */
  270. icache_enable ();
  271. return (psize);
  272. }
  273. int misc_init_r (void)
  274. {
  275. gd->bd->bi_flashstart = 0xff800000;
  276. }
  277. #if defined(CONFIG_CMD_NAND)
  278. extern ulong
  279. nand_probe (ulong physadr);
  280. void
  281. nand_init (void)
  282. {
  283. ulong totlen = 0;
  284. debug ("Probing at 0x%.8x\n", CFG_NAND0_BASE);
  285. totlen += nand_probe (CFG_NAND0_BASE);
  286. printf ("%4lu MB\n", totlen >>20);
  287. }
  288. #endif /* CONFIG_CMD_NAND */
  289. #if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT)
  290. /*
  291. * update "memory" property in the blob
  292. */
  293. void ft_blob_update(void *blob, bd_t *bd)
  294. {
  295. int ret;
  296. ret = fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize);
  297. if (ret < 0) {
  298. printf("ft_blob_update(): cannot set /memory/reg "
  299. "property err:%s\n", fdt_strerror(ret));
  300. }
  301. }
  302. void ft_board_setup(void *blob, bd_t *bd)
  303. {
  304. ft_cpu_setup( blob, bd);
  305. ft_blob_update(blob, bd);
  306. }
  307. #endif /* defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT) */