iphase4539.c 13 KB

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