rsdproto.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. /*
  2. * (C) Copyright 2000
  3. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  4. * Marius Groeger <mgroeger@sysgo.de>
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #include <common.h>
  25. #include <ioports.h>
  26. #include <mpc8260.h>
  27. #include <i2c.h>
  28. /* define to initialise the SDRAM on the local bus */
  29. #undef INIT_LOCAL_BUS_SDRAM
  30. /* I2C Bus adresses for PPC & Protocol board */
  31. #define PPC8260_I2C_ADR 0x30 /*(0)011.0000 */
  32. #define LM84_PPC_I2C_ADR 0x2A /*(0)010.1010 */
  33. #define LM84_SHARC_I2C_ADR 0x29 /*(0)010.1001 */
  34. #define VIRTEX_I2C_ADR 0x25 /*(0)010.0101 */
  35. #define X24645_PPC_I2C_ADR 0x00 /*(0)00X.XXXX -> be careful ! No other i2c-chip should have an adress beginning with (0)00 !!! */
  36. #define RS5C372_PPC_I2C_ADR 0x32 /*(0)011.0010 -> this adress is programmed by the manufacturer and cannot be changed !!! */
  37. /*
  38. * I/O Port configuration table
  39. *
  40. * if conf is 1, then that port pin will be configured at boot time
  41. * according to the five values podr/pdir/ppar/psor/pdat for that entry
  42. */
  43. const iop_conf_t iop_conf_tab[4][32] = {
  44. /* Port A configuration */
  45. { /* conf ppar psor pdir podr pdat */
  46. /* PA31 */ { 0, 0, 0, 0, 0, 0 },
  47. /* PA30 */ { 0, 0, 0, 0, 0, 0 },
  48. /* PA29 */ { 0, 0, 0, 0, 0, 0 },
  49. /* PA28 */ { 0, 0, 0, 0, 0, 0 },
  50. /* PA27 */ { 0, 0, 0, 0, 0, 0 },
  51. /* PA26 */ { 0, 0, 0, 0, 0, 0 },
  52. /* PA25 */ { 0, 0, 0, 0, 0, 0 },
  53. /* PA24 */ { 0, 0, 0, 0, 0, 0 },
  54. /* PA23 */ { 0, 0, 0, 0, 0, 0 },
  55. /* PA22 */ { 0, 0, 0, 0, 0, 0 },
  56. /* PA21 */ { 0, 0, 0, 0, 0, 0 },
  57. /* PA20 */ { 0, 0, 0, 0, 0, 0 },
  58. /* PA19 */ { 0, 0, 0, 0, 0, 0 },
  59. /* PA18 */ { 0, 0, 0, 0, 0, 0 },
  60. /* PA17 */ { 0, 0, 0, 0, 0, 0 },
  61. /* PA16 */ { 0, 0, 0, 0, 0, 0 },
  62. /* PA15 */ { 0, 0, 0, 0, 0, 0 },
  63. /* PA14 */ { 0, 0, 0, 0, 0, 0 },
  64. /* PA13 */ { 0, 0, 0, 0, 0, 0 },
  65. /* PA12 */ { 0, 0, 0, 0, 0, 0 },
  66. /* PA11 */ { 0, 0, 0, 0, 0, 0 },
  67. /* PA10 */ { 0, 0, 0, 0, 0, 0 },
  68. /* PA9 */ { 0, 0, 0, 0, 0, 0 },
  69. /* PA8 */ { 0, 0, 0, 0, 0, 0 },
  70. /* PA7 */ { 0, 0, 0, 0, 0, 0 },
  71. /* PA6 */ { 0, 0, 0, 0, 0, 0 },
  72. /* PA5 */ { 0, 0, 0, 0, 0, 0 },
  73. /* PA4 */ { 0, 0, 0, 0, 0, 0 },
  74. /* PA3 */ { 0, 0, 0, 0, 0, 0 },
  75. /* PA2 */ { 0, 0, 0, 0, 0, 0 },
  76. /* PA1 */ { 0, 0, 0, 0, 0, 0 },
  77. /* PA0 */ { 0, 0, 0, 0, 0, 0 }
  78. },
  79. { /* conf ppar psor pdir podr pdat */
  80. /* PB31 */ { 1, 1, 0, 1, 0, 0 }, /* FCC2 MII TX_ER */
  81. /* PB30 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII RX_DV */
  82. /* PB29 */ { 1, 1, 1, 1, 0, 0 }, /* FCC2 MII TX_EN */
  83. /* PB28 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII RX_ER */
  84. /* PB27 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII COL */
  85. /* PB26 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII CRS */
  86. /* PB25 */ { 1, 1, 0, 1, 0, 0 }, /* FCC2 MII TxD[3] */
  87. /* PB24 */ { 1, 1, 0, 1, 0, 0 }, /* FCC2 MII TxD[2] */
  88. /* PB23 */ { 1, 1, 0, 1, 0, 0 }, /* FCC2 MII TxD[1] */
  89. /* PB22 */ { 1, 1, 0, 1, 0, 0 }, /* FCC2 MII TxD[0] */
  90. /* PB21 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII RxD[0] */
  91. /* PB20 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII RxD[1] */
  92. /* PB19 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII RxD[2] */
  93. /* PB18 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII RxD[3] */
  94. /* PB17 */ { 0, 0, 0, 0, 0, 0 },
  95. /* PB16 */ { 0, 0, 0, 0, 0, 0 },
  96. /* PB15 */ { 0, 0, 0, 0, 0, 0 },
  97. /* PB14 */ { 0, 0, 0, 0, 0, 0 },
  98. /* PB13 */ { 0, 0, 0, 0, 0, 0 },
  99. /* PB12 */ { 0, 0, 0, 0, 0, 0 },
  100. /* PB11 */ { 0, 0, 0, 0, 0, 0 },
  101. /* PB10 */ { 0, 0, 0, 0, 0, 0 },
  102. /* PB9 */ { 0, 0, 0, 0, 0, 0 },
  103. /* PB8 */ { 0, 0, 0, 0, 0, 0 },
  104. /* PB7 */ { 0, 0, 0, 0, 0, 0 },
  105. /* PB6 */ { 0, 0, 0, 0, 0, 0 },
  106. /* PB5 */ { 0, 0, 0, 0, 0, 0 },
  107. /* PB4 */ { 0, 0, 0, 0, 0, 0 },
  108. /* PB3 */ { 0, 0, 0, 0, 0, 0 }, /* pin doesn't exist */
  109. /* PB2 */ { 0, 0, 0, 0, 0, 0 }, /* pin doesn't exist */
  110. /* PB1 */ { 0, 0, 0, 0, 0, 0 }, /* pin doesn't exist */
  111. /* PB0 */ { 0, 0, 0, 0, 0, 0 } /* pin doesn't exist */
  112. },
  113. { /* conf ppar psor pdir podr pdat */
  114. /* PC31 */ { 0, 0, 0, 0, 0, 0 },
  115. /* PC30 */ { 0, 0, 0, 0, 0, 0 },
  116. /* PC29 */ { 0, 0, 0, 0, 0, 0 },
  117. /* PC28 */ { 0, 0, 0, 0, 0, 0 },
  118. /* PC27 */ { 0, 0, 0, 0, 0, 0 },
  119. /* PC26 */ { 0, 0, 0, 0, 0, 0 },
  120. /* PC25 */ { 0, 0, 0, 0, 0, 0 },
  121. /* PC24 */ { 0, 0, 0, 0, 0, 0 },
  122. /* PC23 */ { 0, 0, 0, 0, 0, 0 },
  123. /* PC22 */ { 0, 0, 0, 0, 0, 0 },
  124. /* PC21 */ { 0, 0, 0, 0, 0, 0 },
  125. /* PC20 */ { 0, 0, 0, 0, 0, 0 },
  126. /* PC19 */ { 1, 1, 0, 0, 0, 0 },
  127. /* PC18 */ { 1, 1, 0, 0, 0, 0 }, /* ETHRXCLK: CLK14 */
  128. /* PC17 */ { 0, 0, 0, 0, 0, 0 }, /* ETHTXCLK: CLK15 */
  129. /* PC16 */ { 0, 0, 0, 0, 0, 0 },
  130. /* PC15 */ { 0, 0, 0, 0, 0, 0 },
  131. /* PC14 */ { 1, 1, 0, 0, 0, 0 }, /* SCC1 UART CD/ */
  132. /* PC13 */ { 0, 0, 0, 0, 0, 0 },
  133. /* PC12 */ { 0, 0, 0, 0, 0, 0 },
  134. /* PC11 */ { 0, 0, 0, 0, 0, 0 },
  135. /* PC10 */ { 1, 0, 0, 1, 0, 0 }, /* ETHMDC: GP */
  136. /* PC9 */ { 1, 0, 0, 1, 0, 0 }, /* ETHMDIO: GP */
  137. /* PC8 */ { 0, 0, 0, 0, 0, 0 },
  138. /* PC7 */ { 0, 0, 0, 0, 0, 0 },
  139. /* PC6 */ { 0, 0, 0, 0, 0, 0 },
  140. /* PC5 */ { 0, 0, 0, 0, 0, 0 },
  141. /* PC4 */ { 0, 0, 0, 0, 0, 0 },
  142. /* PC3 */ { 0, 0, 0, 0, 0, 0 },
  143. /* PC2 */ { 0, 0, 0, 0, 0, 0 },
  144. /* PC1 */ { 0, 0, 0, 0, 0, 0 },
  145. /* PC0 */ { 0, 0, 0, 0, 0, 0 }
  146. },
  147. { /* conf ppar psor pdir podr pdat */
  148. /* PD31 */ { 1, 1, 0, 0, 0, 0 }, /* SCC1 UART RxD */
  149. /* PD30 */ { 1, 1, 1, 1, 0, 0 }, /* SCC1 UART TxD */
  150. /* PD29 */ { 0, 0, 0, 0, 0, 0 },
  151. /* PD28 */ { 0, 0, 0, 0, 0, 0 },
  152. /* PD27 */ { 0, 0, 0, 0, 0, 0 },
  153. /* PD26 */ { 0, 0, 0, 0, 0, 0 },
  154. /* PD25 */ { 0, 0, 0, 0, 0, 0 },
  155. /* PD24 */ { 0, 0, 0, 0, 0, 0 },
  156. /* PD23 */ { 0, 0, 0, 0, 0, 0 },
  157. /* PD22 */ { 0, 0, 0, 0, 0, 0 },
  158. /* PD21 */ { 0, 0, 0, 0, 0, 0 },
  159. /* PD20 */ { 0, 0, 0, 0, 0, 0 },
  160. /* PD19 */ { 0, 0, 0, 0, 0, 0 },
  161. /* PD18 */ { 0, 0, 0, 0, 0, 0 },
  162. /* PD17 */ { 0, 0, 0, 0, 0, 0 },
  163. /* PD16 */ { 0, 0, 0, 0, 0, 0 },
  164. /* PD15 */ { 1, 1, 1, 0, 1, 0 }, /* I2C SDA */
  165. /* PD14 */ { 1, 1, 1, 0, 1, 0 }, /* I2C SCL */
  166. /* PD13 */ { 0, 0, 0, 0, 0, 0 },
  167. /* PD12 */ { 0, 0, 0, 0, 0, 0 },
  168. /* PD11 */ { 0, 0, 0, 0, 0, 0 },
  169. /* PD10 */ { 0, 0, 0, 0, 0, 0 },
  170. /* PD9 */ { 0, 0, 0, 0, 0, 0 },
  171. /* PD8 */ { 0, 0, 0, 0, 0, 0 },
  172. /* PD7 */ { 0, 0, 0, 0, 0, 0 },
  173. /* PD6 */ { 0, 0, 0, 0, 0, 0 },
  174. /* PD5 */ { 0, 0, 0, 0, 0, 0 },
  175. /* PD4 */ { 0, 0, 0, 0, 0, 0 },
  176. /* PD3 */ { 0, 0, 0, 0, 0, 0 }, /* pin doesn't exist */
  177. /* PD2 */ { 0, 0, 0, 0, 0, 0 }, /* pin doesn't exist */
  178. /* PD1 */ { 0, 0, 0, 0, 0, 0 }, /* pin doesn't exist */
  179. /* PD0 */ { 0, 0, 0, 0, 0, 0 } /* pin doesn't exist */
  180. }
  181. };
  182. /* ------------------------------------------------------------------------- */
  183. struct tm {
  184. unsigned int tm_sec;
  185. unsigned int tm_min;
  186. unsigned int tm_hour;
  187. unsigned int tm_wday;
  188. unsigned int tm_mday;
  189. unsigned int tm_mon;
  190. unsigned int tm_year;
  191. };
  192. void read_RS5C372_time (struct tm *timedate)
  193. {
  194. unsigned char buffer[8];
  195. #define BCD_TO_BIN(val) ((val)=((val)&15) + ((val)>>4)*10)
  196. if (i2c_read (RS5C372_PPC_I2C_ADR, 0, 1, buffer, sizeof (buffer))) {
  197. timedate->tm_sec = BCD_TO_BIN (buffer[0]);
  198. timedate->tm_min = BCD_TO_BIN (buffer[1]);
  199. timedate->tm_hour = BCD_TO_BIN (buffer[2]);
  200. timedate->tm_wday = BCD_TO_BIN (buffer[3]);
  201. timedate->tm_mday = BCD_TO_BIN (buffer[4]);
  202. timedate->tm_mon = BCD_TO_BIN (buffer[5]);
  203. timedate->tm_year = BCD_TO_BIN (buffer[6]) + 2000;
  204. } else {
  205. /*printf("i2c error %02x\n", rc); */
  206. memset (timedate, 0, sizeof (struct tm));
  207. }
  208. }
  209. /* ------------------------------------------------------------------------- */
  210. int read_LM84_temp (int address)
  211. {
  212. unsigned char buffer[8];
  213. /*int rc;*/
  214. if (i2c_read (address, 0, 1, buffer, 1)) {
  215. return (int) buffer[0];
  216. } else {
  217. /*printf("i2c error %02x\n", rc); */
  218. return -42;
  219. }
  220. }
  221. /* ------------------------------------------------------------------------- */
  222. /*
  223. * Check Board Identity:
  224. */
  225. int checkboard (void)
  226. {
  227. struct tm timedate;
  228. unsigned int ppctemp, prottemp;
  229. puts ("Board: Rohde & Schwarz 8260 Protocol Board\n");
  230. /* initialise i2c */
  231. i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE);
  232. read_RS5C372_time (&timedate);
  233. printf (" Time: %02d:%02d:%02d\n",
  234. timedate.tm_hour, timedate.tm_min, timedate.tm_sec);
  235. printf (" Date: %02d-%02d-%04d\n",
  236. timedate.tm_mday, timedate.tm_mon, timedate.tm_year);
  237. ppctemp = read_LM84_temp (LM84_PPC_I2C_ADR);
  238. prottemp = read_LM84_temp (LM84_SHARC_I2C_ADR);
  239. printf (" Temp: PPC %d C, Protocol Board %d C\n",
  240. ppctemp, prottemp);
  241. return 0;
  242. }
  243. /* ------------------------------------------------------------------------- */
  244. /*
  245. * Miscelaneous platform dependent initialisations while still
  246. * running in flash
  247. */
  248. int misc_init_f (void)
  249. {
  250. return 0;
  251. }
  252. /* ------------------------------------------------------------------------- */
  253. long int initdram (int board_type)
  254. {
  255. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  256. volatile memctl8260_t *memctl = &immap->im_memctl;
  257. #ifdef INIT_LOCAL_BUS_SDRAM
  258. volatile uchar *ramaddr8;
  259. #endif
  260. volatile ulong *ramaddr32;
  261. ulong sdmr;
  262. int i;
  263. /*
  264. * Only initialize SDRAM when running from FLASH.
  265. * When running from RAM, don't touch it.
  266. */
  267. if ((ulong) initdram & 0xff000000) {
  268. immap->im_siu_conf.sc_ppc_acr = 0x02;
  269. immap->im_siu_conf.sc_ppc_alrh = 0x01267893;
  270. immap->im_siu_conf.sc_ppc_alrl = 0x89ABCDEF;
  271. immap->im_siu_conf.sc_lcl_acr = 0x02;
  272. immap->im_siu_conf.sc_lcl_alrh = 0x01234567;
  273. immap->im_siu_conf.sc_lcl_alrl = 0x89ABCDEF;
  274. /*
  275. * Program local/60x bus Transfer Error Status and Control Regs:
  276. * Disable parity errors
  277. */
  278. immap->im_siu_conf.sc_tescr1 = 0x00040000;
  279. immap->im_siu_conf.sc_ltescr1 = 0x00040000;
  280. /*
  281. * Perform Power-Up Initialisation of SDRAM (see 8260 UM, 10.4.2)
  282. *
  283. * The appropriate BRx/ORx registers have already
  284. * been set when we get here (see cpu_init_f). The
  285. * SDRAM can be accessed at the address CFG_SDRAM_BASE.
  286. */
  287. memctl->memc_mptpr = 0x2000;
  288. memctl->memc_mar = 0x0200;
  289. #ifdef INIT_LOCAL_BUS_SDRAM
  290. /* initialise local bus ram
  291. *
  292. * (using the PSRMR_ definitions is NOT an error here
  293. * - the LSDMR has the same fields as the PSDMR!)
  294. */
  295. memctl->memc_lsrt = 0x0b;
  296. memctl->memc_lurt = 0x00;
  297. ramaddr = (uchar *) PHYS_SDRAM_LOCAL;
  298. sdmr = CFG_LSDMR & ~(PSDMR_OP_MSK | PSDMR_RFEN | PSDMR_PBI);
  299. memctl->memc_lsdmr = sdmr | PSDMR_OP_PREA;
  300. *ramaddr = 0xff;
  301. for (i = 0; i < 8; i++) {
  302. memctl->memc_lsdmr = sdmr | PSDMR_OP_CBRR;
  303. *ramaddr = 0xff;
  304. }
  305. memctl->memc_lsdmr = sdmr | PSDMR_OP_MRW;
  306. *ramaddr = 0xff;
  307. memctl->memc_lsdmr = CFG_LSDMR | PSDMR_OP_NORM;
  308. #endif
  309. /* initialise 60x bus ram */
  310. memctl->memc_psrt = 0x0b;
  311. memctl->memc_purt = 0x08;
  312. ramaddr32 = (ulong *) PHYS_SDRAM_60X;
  313. sdmr = CFG_PSDMR & ~(PSDMR_OP_MSK | PSDMR_RFEN | PSDMR_PBI);
  314. memctl->memc_psdmr = sdmr | PSDMR_OP_PREA;
  315. ramaddr32[0] = 0x00ff00ff;
  316. ramaddr32[1] = 0x00ff00ff;
  317. memctl->memc_psdmr = sdmr | PSDMR_OP_CBRR;
  318. for (i = 0; i < 8; i++) {
  319. ramaddr32[0] = 0x00ff00ff;
  320. ramaddr32[1] = 0x00ff00ff;
  321. }
  322. memctl->memc_psdmr = sdmr | PSDMR_OP_MRW;
  323. ramaddr32[0] = 0x00ff00ff;
  324. ramaddr32[1] = 0x00ff00ff;
  325. memctl->memc_psdmr = sdmr | PSDMR_OP_NORM | PSDMR_RFEN;
  326. }
  327. /* return the size of the 60x bus ram */
  328. return PHYS_SDRAM_60X_SIZE;
  329. }
  330. /* ------------------------------------------------------------------------- */
  331. /*
  332. * Miscelaneous platform dependent initialisations after monitor
  333. * has been relocated into ram
  334. */
  335. int misc_init_r (void)
  336. {
  337. printf ("misc_init_r\n");
  338. return (0);
  339. }