iphase4539.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. /*
  2. * (C) Copyright 2002 Wolfgang Grandegger <wg@denx.de>
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <ioports.h>
  8. #include <mpc8260.h>
  9. #include <asm/io.h>
  10. #include <asm/immap_8260.h>
  11. int hwc_flash_size (void);
  12. int hwc_local_sdram_size (void);
  13. int hwc_main_sdram_size (void);
  14. int hwc_serial_number (void);
  15. int hwc_mac_address (char *str);
  16. int hwc_manufact_date (char *str);
  17. int seeprom_read (int addr, uchar * data, int size);
  18. /*
  19. * I/O Port configuration table
  20. *
  21. * if conf is 1, then that port pin will be configured at boot time
  22. * according to the five values podr/pdir/ppar/psor/pdat for that entry
  23. *
  24. * The port definitions are taken from the old firmware (see
  25. * also SYS/H/4539.H):
  26. *
  27. * ppar psor pdir podr pdat
  28. * PA: 0x02ffffff 0x02c00000 0xfc403fe6 0x00000000 0x02403fc0
  29. * PB: 0x0fffdeb0 0x000000b0 0x0f032347 0x00000000 0x0f000290
  30. * PC: 0x030ffa55 0x030f0040 0xbcf005ea 0x00000000 0xc0c0ba7d
  31. * PD: 0x09c04e3c 0x01000e3c 0x0a7ff1c3 0x00000000 0x00ce0ae9
  32. */
  33. const iop_conf_t iop_conf_tab[4][32] = {
  34. /* Port A configuration */
  35. { /* conf ppar psor pdir podr pdat */
  36. {0, 1, 0, 0, 0, 0}, /* PA31 FCC1_TXENB SLAVE */
  37. {0, 1, 0, 1, 0, 0}, /* PA30 FCC1_TXCLAV SLAVE */
  38. {0, 1, 0, 1, 0, 0}, /* PA29 FCC1_TXSOC */
  39. {0, 1, 0, 0, 0, 0}, /* PA28 FCC1_RXENB SLAVE */
  40. {0, 1, 0, 0, 0, 0}, /* PA27 FCC1_RXSOC */
  41. {0, 1, 0, 1, 0, 0}, /* PA26 FCC1_RXCLAV SLAVE */
  42. {0, 1, 0, 1, 0, 1}, /* PA25 FCC1_TXD0 */
  43. {0, 1, 0, 1, 0, 1}, /* PA24 FCC1_TXD1 */
  44. {0, 1, 0, 1, 0, 1}, /* PA23 FCC1_TXD2 */
  45. {0, 1, 0, 1, 0, 1}, /* PA22 FCC1_TXD3 */
  46. {0, 1, 0, 1, 0, 1}, /* PA21 FCC1_TXD4 */
  47. {0, 1, 0, 1, 0, 1}, /* PA20 FCC1_TXD5 */
  48. {0, 1, 0, 1, 0, 1}, /* PA19 FCC1_TXD6 */
  49. {0, 1, 0, 1, 0, 1}, /* PA18 FCC1_TXD7 */
  50. {0, 1, 0, 0, 0, 0}, /* PA17 FCC1_RXD7 */
  51. {0, 1, 0, 0, 0, 0}, /* PA16 FCC1_RXD6 */
  52. {0, 1, 0, 0, 0, 0}, /* PA15 FCC1_RXD5 */
  53. {0, 1, 0, 0, 0, 0}, /* PA14 FCC1_RXD4 */
  54. {0, 1, 0, 0, 0, 0}, /* PA13 FCC1_RXD3 */
  55. {0, 1, 0, 0, 0, 0}, /* PA12 FCC1_RXD2 */
  56. {0, 1, 0, 0, 0, 0}, /* PA11 FCC1_RXD1 */
  57. {0, 1, 0, 0, 0, 0}, /* PA10 FCC1_RXD0 */
  58. {0, 1, 1, 1, 0, 1}, /* PA9 TDMA1_L1TXD */
  59. {0, 1, 1, 0, 0, 0}, /* PA8 TDMA1_L1RXD */
  60. {0, 0, 0, 0, 0, 0}, /* PA7 CONFIG0 */
  61. {0, 1, 1, 0, 0, 1}, /* PA6 TDMA1_L1RSYNC */
  62. {0, 0, 0, 1, 0, 0}, /* PA5 FCC2:RxAddr[2] */
  63. {0, 0, 0, 1, 0, 0}, /* PA4 FCC2:RxAddr[1] */
  64. {0, 0, 0, 1, 0, 0}, /* PA3 FCC2:RxAddr[0] */
  65. {0, 0, 0, 1, 0, 0}, /* PA2 FCC2:TxAddr[0] */
  66. {0, 0, 0, 1, 0, 0}, /* PA1 FCC2:TxAddr[1] */
  67. {0, 0, 0, 1, 0, 0} /* PA0 FCC2:TxAddr[2] */
  68. },
  69. /* Port B configuration */
  70. { /* conf ppar psor pdir podr pdat */
  71. {0, 0, 0, 1, 0, 0}, /* PB31 FCC2_RXSOC */
  72. {0, 0, 0, 1, 0, 0}, /* PB30 FCC2_TXSOC */
  73. {0, 0, 0, 1, 0, 0}, /* PB29 FCC2_RXCLAV */
  74. {0, 0, 0, 0, 0, 0}, /* PB28 CONFIG2 */
  75. {0, 1, 1, 0, 0, 1}, /* PB27 FCC2_TXD0 */
  76. {0, 1, 1, 0, 0, 0}, /* PB26 FCC2_TXD1 */
  77. {0, 0, 0, 1, 0, 0}, /* PB25 FCC2_TXD4 */
  78. {0, 1, 1, 0, 0, 1}, /* PB24 FCC2_TXD5 */
  79. {0, 0, 0, 1, 0, 0}, /* PB23 FCC2_TXD6 */
  80. {0, 1, 0, 1, 0, 1}, /* PB22 FCC2_TXD7 */
  81. {0, 1, 0, 0, 0, 0}, /* PB21 FCC2_RXD7 */
  82. {0, 1, 0, 0, 0, 0}, /* PB20 FCC2_RXD6 */
  83. {0, 1, 0, 0, 0, 0}, /* PB19 FCC2_RXD5 */
  84. {0, 0, 0, 1, 0, 0}, /* PB18 FCC2_RXD4 */
  85. {1, 1, 0, 0, 0, 0}, /* PB17 FCC3_RX_DV */
  86. {1, 1, 0, 0, 0, 0}, /* PB16 FCC3_RX_ER */
  87. {1, 1, 0, 1, 0, 0}, /* PB15 FCC3_TX_ER */
  88. {1, 1, 0, 1, 0, 0}, /* PB14 FCC3_TX_EN */
  89. {1, 1, 0, 0, 0, 0}, /* PB13 FCC3_COL */
  90. {1, 1, 0, 0, 0, 0}, /* PB12 FCC3_CRS */
  91. {1, 1, 0, 0, 0, 0}, /* PB11 FCC3_RXD3 */
  92. {1, 1, 0, 0, 0, 0}, /* PB10 FCC3_RXD2 */
  93. {1, 1, 0, 0, 0, 0}, /* PB9 FCC3_RXD1 */
  94. {1, 1, 0, 0, 0, 0}, /* PB8 FCC3_RXD0 */
  95. {1, 1, 0, 1, 0, 1}, /* PB7 FCC3_TXD0 */
  96. {1, 1, 0, 1, 0, 1}, /* PB6 FCC3_TXD1 */
  97. {1, 1, 0, 1, 0, 1}, /* PB5 FCC3_TXD2 */
  98. {1, 1, 0, 1, 0, 1}, /* PB4 FCC3_TXD3 */
  99. {0, 0, 0, 0, 0, 0}, /* PB3 */
  100. {0, 0, 0, 0, 0, 0}, /* PB2 */
  101. {0, 0, 0, 0, 0, 0}, /* PB1 */
  102. {0, 0, 0, 0, 0, 0}, /* PB0 */
  103. },
  104. /* Port C configuration */
  105. { /* conf ppar psor pdir podr pdat */
  106. {0, 1, 0, 0, 0, 1}, /* PC31 CLK1 */
  107. {0, 0, 0, 1, 0, 0}, /* PC30 U1MASTER_N */
  108. {0, 1, 0, 0, 0, 1}, /* PC29 CLK3 */
  109. {0, 0, 0, 1, 0, 1}, /* PC28 -MT90220_RST */
  110. {0, 1, 0, 0, 0, 1}, /* PC27 CLK5 */
  111. {0, 0, 0, 1, 0, 1}, /* PC26 -QUADFALC_RST */
  112. {0, 1, 1, 1, 0, 1}, /* PC25 BRG4 */
  113. {1, 0, 0, 1, 0, 0}, /* PC24 MDIO */
  114. {1, 0, 0, 1, 0, 0}, /* PC23 MDC */
  115. {0, 1, 0, 0, 0, 1}, /* PC22 CLK10 */
  116. {0, 0, 0, 1, 0, 0}, /* PC21 */
  117. {0, 1, 0, 0, 0, 1}, /* PC20 CLK12 */
  118. {0, 1, 0, 0, 0, 1}, /* PC19 CLK13 */
  119. {1, 1, 0, 0, 0, 1}, /* PC18 CLK14 */
  120. {0, 1, 0, 0, 0, 0}, /* PC17 CLK15 */
  121. {1, 1, 0, 0, 0, 1}, /* PC16 CLK16 */
  122. {0, 1, 1, 0, 0, 0}, /* PC15 FCC1_TXADDR0 SLAVE */
  123. {0, 1, 1, 0, 0, 0}, /* PC14 FCC1_RXADDR0 SLAVE */
  124. {0, 1, 1, 0, 0, 0}, /* PC13 FCC1_TXADDR1 SLAVE */
  125. {0, 1, 1, 0, 0, 0}, /* PC12 FCC1_RXADDR1 SLAVE */
  126. {0, 0, 0, 1, 0, 0}, /* PC11 FCC2_RXD2 */
  127. {0, 0, 0, 1, 0, 0}, /* PC10 FCC2_RXD3 */
  128. {0, 0, 0, 1, 0, 1}, /* PC9 LTMODE */
  129. {0, 0, 0, 1, 0, 1}, /* PC8 SELSYNC */
  130. {0, 1, 1, 0, 0, 0}, /* PC7 FCC1_TXADDR2 SLAVE */
  131. {0, 1, 1, 0, 0, 0}, /* PC6 FCC1_RXADDR2 SLAVE */
  132. {0, 0, 0, 1, 0, 0}, /* PC5 FCC2_TXCLAV MASTER */
  133. {0, 0, 0, 1, 0, 0}, /* PC4 FCC2_RXENB MASTER */
  134. {0, 0, 0, 1, 0, 0}, /* PC3 FCC2_TXD2 */
  135. {0, 0, 0, 1, 0, 0}, /* PC2 FCC2_TXD3 */
  136. {0, 0, 0, 0, 0, 1}, /* PC1 PTMC -PTEENB */
  137. {0, 0, 0, 1, 0, 1}, /* PC0 COMCLK_N */
  138. },
  139. /* Port D configuration */
  140. { /* conf ppar psor pdir podr pdat */
  141. {0, 0, 0, 1, 0, 1}, /* PD31 -CAM_RST */
  142. {0, 0, 0, 1, 0, 0}, /* PD30 FCC2_TXENB */
  143. {0, 1, 1, 0, 0, 0}, /* PD29 FCC1_RXADDR3 SLAVE */
  144. {0, 1, 1, 0, 0, 1}, /* PD28 TDMC1_L1TXD */
  145. {0, 1, 1, 0, 0, 0}, /* PD27 TDMC1_L1RXD */
  146. {0, 1, 1, 0, 0, 1}, /* PD26 TDMC1_L1RSYNC */
  147. {0, 0, 0, 1, 0, 1}, /* PD25 LED0 -OFF */
  148. {0, 0, 0, 1, 0, 1}, /* PD24 LED5 -OFF */
  149. {1, 0, 0, 1, 0, 1}, /* PD23 -LXT971_RST */
  150. {0, 1, 1, 0, 0, 1}, /* PD22 TDMA2_L1TXD */
  151. {0, 1, 1, 0, 0, 0}, /* PD21 TDMA2_L1RXD */
  152. {0, 1, 1, 0, 0, 1}, /* PD20 TDMA2_L1RSYNC */
  153. {0, 0, 0, 1, 0, 0}, /* PD19 FCC2_TXADDR3 */
  154. {0, 0, 0, 1, 0, 0}, /* PD18 FCC2_RXADDR3 */
  155. {0, 1, 0, 1, 0, 0}, /* PD17 BRG2 */
  156. {0, 0, 0, 1, 0, 0}, /* PD16 */
  157. {0, 0, 0, 1, 0, 0}, /* PD15 PT2TO1 */
  158. {0, 0, 0, 1, 0, 1}, /* PD14 PT4TO3 */
  159. {0, 0, 0, 1, 0, 1}, /* PD13 -SWMODE */
  160. {0, 0, 0, 1, 0, 1}, /* PD12 -PTMODE */
  161. {0, 0, 0, 1, 0, 0}, /* PD11 FCC2_RXD0 */
  162. {0, 0, 0, 1, 0, 0}, /* PD10 FCC2_RXD1 */
  163. {1, 1, 0, 1, 0, 1}, /* PD9 SMC1_SMTXD */
  164. {1, 1, 0, 0, 0, 1}, /* PD8 SMC1_SMRXD */
  165. {0, 1, 1, 0, 0, 0}, /* PD7 FCC1_TXADDR3 SLAVE */
  166. {0, 0, 0, 1, 0, 0}, /* PD6 IMAMODE */
  167. {0, 0, 0, 0, 0, 0}, /* PD5 CONFIG2 */
  168. {0, 1, 0, 1, 0, 0}, /* PD4 BRG8 */
  169. {0, 0, 0, 0, 0, 0}, /* PD3 */
  170. {0, 0, 0, 0, 0, 0}, /* PD2 */
  171. {0, 0, 0, 0, 0, 0}, /* PD1 */
  172. {0, 0, 0, 0, 0, 0}, /* PD0 */
  173. }
  174. };
  175. phys_size_t initdram (int board_type)
  176. {
  177. volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  178. volatile memctl8260_t *memctl = &immap->im_memctl;
  179. volatile uchar *base;
  180. ulong maxsize;
  181. int i;
  182. memctl->memc_psrt = CONFIG_SYS_PSRT;
  183. memctl->memc_mptpr = CONFIG_SYS_MPTPR;
  184. #ifndef CONFIG_SYS_RAMBOOT
  185. immap->im_siu_conf.sc_ppc_acr = 0x00000026;
  186. immap->im_siu_conf.sc_ppc_alrh = 0x01276345;
  187. immap->im_siu_conf.sc_ppc_alrl = 0x89ABCDEF;
  188. immap->im_siu_conf.sc_lcl_acr = 0x00000000;
  189. immap->im_siu_conf.sc_lcl_alrh = 0x01234567;
  190. immap->im_siu_conf.sc_lcl_alrl = 0x89ABCDEF;
  191. immap->im_siu_conf.sc_tescr1 = 0x00004000;
  192. immap->im_siu_conf.sc_ltescr1 = 0x00004000;
  193. /* Init Main SDRAM */
  194. #define OP_VALUE 0x404A241A
  195. #define OP_VALUE_M (OP_VALUE & 0x87FFFFFF);
  196. base = (uchar *) CONFIG_SYS_SDRAM_BASE;
  197. memctl->memc_psdmr = 0x28000000 | OP_VALUE_M;
  198. *base = 0xFF;
  199. memctl->memc_psdmr = 0x08000000 | OP_VALUE_M;
  200. for (i = 0; i < 8; i++)
  201. *base = 0xFF;
  202. memctl->memc_psdmr = 0x18000000 | OP_VALUE_M;
  203. *(base + 0x110) = 0xFF;
  204. memctl->memc_psdmr = OP_VALUE;
  205. memctl->memc_lsdmr = 0x4086A522;
  206. *base = 0xFF;
  207. /* We must be able to test a location outsize the maximum legal size
  208. * to find out THAT we are outside; but this address still has to be
  209. * mapped by the controller. That means, that the initial mapping has
  210. * to be (at least) twice as large as the maximum expected size.
  211. */
  212. maxsize = (1 + (~memctl->memc_or1 | 0x7fff)) / 2;
  213. maxsize = get_ram_size((long *)base, maxsize);
  214. memctl->memc_or1 |= ~(maxsize - 1);
  215. if (maxsize != hwc_main_sdram_size ())
  216. printf ("Oops: memory test has not found all memory!\n");
  217. #endif
  218. icache_enable ();
  219. /* return total ram size of SDRAM */
  220. return (maxsize);
  221. }
  222. int checkboard (void)
  223. {
  224. char string[32];
  225. hwc_manufact_date (string);
  226. printf ("Board: Interphase 4539 (#%d %s)\n",
  227. hwc_serial_number (),
  228. string);
  229. #ifdef DEBUG
  230. printf ("Manufacturing date: %s\n", string);
  231. printf ("Serial number : %d\n", hwc_serial_number ());
  232. printf ("FLASH size : %d MB\n", hwc_flash_size () >> 20);
  233. printf ("Main SDRAM size : %d MB\n", hwc_main_sdram_size () >> 20);
  234. printf ("Local SDRAM size : %d MB\n", hwc_local_sdram_size () >> 20);
  235. hwc_mac_address (string);
  236. printf ("MAC address : %s\n", string);
  237. #endif
  238. return 0;
  239. }
  240. int misc_init_r (void)
  241. {
  242. char *s, str[32];
  243. int num;
  244. if ((s = getenv ("serial#")) == NULL &&
  245. (num = hwc_serial_number ()) != -1) {
  246. sprintf (str, "%06d", num);
  247. setenv ("serial#", str);
  248. }
  249. if ((s = getenv ("ethaddr")) == NULL && hwc_mac_address (str) == 0) {
  250. setenv ("ethaddr", str);
  251. }
  252. return (0);
  253. }
  254. /***************************************************************
  255. * We take some basic Hardware Configuration Parameter from the
  256. * Serial EEPROM conected to the PSpan bridge. We keep it as
  257. * simple as possible.
  258. */
  259. int hwc_flash_size (void)
  260. {
  261. uchar byte;
  262. if (!seeprom_read (0x40, &byte, sizeof (byte))) {
  263. switch ((byte >> 2) & 0x3) {
  264. case 0x1:
  265. return 0x0400000;
  266. break;
  267. case 0x2:
  268. return 0x0800000;
  269. break;
  270. case 0x3:
  271. return 0x1000000;
  272. default:
  273. return 0x0100000;
  274. }
  275. }
  276. return -1;
  277. }
  278. int hwc_local_sdram_size (void)
  279. {
  280. uchar byte;
  281. if (!seeprom_read (0x40, &byte, sizeof (byte))) {
  282. switch ((byte & 0x03)) {
  283. case 0x1:
  284. return 0x0800000;
  285. case 0x2:
  286. return 0x1000000;
  287. default:
  288. return 0; /* not present */
  289. }
  290. }
  291. return -1;
  292. }
  293. int hwc_main_sdram_size (void)
  294. {
  295. uchar byte;
  296. if (!seeprom_read (0x41, &byte, sizeof (byte))) {
  297. return 0x1000000 << ((byte >> 5) & 0x7);
  298. }
  299. return -1;
  300. }
  301. int hwc_serial_number (void)
  302. {
  303. int sn = -1;
  304. if (!seeprom_read (0xa0, (uchar *) &sn, sizeof (sn))) {
  305. sn = cpu_to_le32 (sn);
  306. }
  307. return sn;
  308. }
  309. int hwc_mac_address (char *str)
  310. {
  311. char mac[6];
  312. if (!seeprom_read (0xb0, (uchar *)mac, sizeof (mac))) {
  313. sprintf (str, "%02x:%02x:%02x:%02x:%02x:%02x\n",
  314. mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
  315. } else {
  316. strcpy (str, "ERROR");
  317. return -1;
  318. }
  319. return 0;
  320. }
  321. int hwc_manufact_date (char *str)
  322. {
  323. uchar byte;
  324. int value;
  325. if (seeprom_read (0x92, &byte, sizeof (byte)))
  326. goto out;
  327. value = byte;
  328. if (seeprom_read (0x93, &byte, sizeof (byte)))
  329. goto out;
  330. value += byte << 8;
  331. sprintf (str, "%02d/%02d/%04d",
  332. value & 0x1F, (value >> 5) & 0xF,
  333. 1980 + ((value >> 9) & 0x1FF));
  334. return 0;
  335. out:
  336. strcpy (str, "ERROR");
  337. return -1;
  338. }
  339. #define PSPAN_ADDR 0xF0020000
  340. #define EEPROM_REG 0x408
  341. #define EEPROM_READ_CMD 0xA000
  342. #define PSPAN_WRITE(a,v) \
  343. *((volatile unsigned long *)(PSPAN_ADDR+(a))) = v; eieio()
  344. #define PSPAN_READ(a) \
  345. *((volatile unsigned long *)(PSPAN_ADDR+(a)))
  346. int seeprom_read (int addr, uchar * data, int size)
  347. {
  348. ulong val, cmd;
  349. int i;
  350. for (i = 0; i < size; i++) {
  351. cmd = EEPROM_READ_CMD;
  352. cmd |= ((addr + i) << 24) & 0xff000000;
  353. /* Wait for ACT to authorize write */
  354. while ((val = PSPAN_READ (EEPROM_REG)) & 0x80)
  355. eieio ();
  356. /* Write command */
  357. PSPAN_WRITE (EEPROM_REG, cmd);
  358. /* Wait for data to be valid */
  359. while ((val = PSPAN_READ (EEPROM_REG)) & 0x80)
  360. eieio ();
  361. /* Do it twice, first read might be erratic */
  362. while ((val = PSPAN_READ (EEPROM_REG)) & 0x80)
  363. eieio ();
  364. /* Read error */
  365. if (val & 0x00000040) {
  366. return -1;
  367. } else {
  368. data[i] = (val >> 16) & 0xff;
  369. }
  370. }
  371. return 0;
  372. }