tqm85xx.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  1. /*
  2. * (C) Copyright 2008 Wolfgang Grandegger <wg@denx.de>
  3. *
  4. * (C) Copyright 2006
  5. * Thomas Waehner, TQ-Systems GmbH, thomas.waehner@tqs.de.
  6. *
  7. * (C) Copyright 2005
  8. * Stefan Roese, DENX Software Engineering, sr@denx.de.
  9. *
  10. * Copyright 2004 Freescale Semiconductor.
  11. * (C) Copyright 2002,2003, Motorola Inc.
  12. * Xianghua Xiao, (X.Xiao@motorola.com)
  13. *
  14. * (C) Copyright 2002 Scott McNutt <smcnutt@artesyncp.com>
  15. *
  16. * See file CREDITS for list of people who contributed to this
  17. * project.
  18. *
  19. * This program is free software; you can redistribute it and/or
  20. * modify it under the terms of the GNU General Public License as
  21. * published by the Free Software Foundation; either version 2 of
  22. * the License, or (at your option) any later version.
  23. *
  24. * This program is distributed in the hope that it will be useful,
  25. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. * GNU General Public License for more details.
  28. *
  29. * You should have received a copy of the GNU General Public License
  30. * along with this program; if not, write to the Free Software
  31. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  32. * MA 02111-1307 USA
  33. */
  34. #include <common.h>
  35. #include <pci.h>
  36. #include <asm/processor.h>
  37. #include <asm/immap_85xx.h>
  38. #include <asm/immap_fsl_pci.h>
  39. #include <asm/io.h>
  40. #include <ioports.h>
  41. #include <flash.h>
  42. #include <libfdt.h>
  43. #include <fdt_support.h>
  44. #include <netdev.h>
  45. DECLARE_GLOBAL_DATA_PTR;
  46. extern flash_info_t flash_info[]; /* FLASH chips info */
  47. void local_bus_init (void);
  48. ulong flash_get_size (ulong base, int banknum);
  49. #ifdef CONFIG_PS2MULT
  50. void ps2mult_early_init (void);
  51. #endif
  52. #ifdef CONFIG_CPM2
  53. /*
  54. * I/O Port configuration table
  55. *
  56. * if conf is 1, then that port pin will be configured at boot time
  57. * according to the five values podr/pdir/ppar/psor/pdat for that entry
  58. */
  59. const iop_conf_t iop_conf_tab[4][32] = {
  60. /* Port A: conf, ppar, psor, pdir, podr, pdat */
  61. {
  62. {1, 1, 1, 0, 0, 0}, /* PA31: FCC1 MII COL */
  63. {1, 1, 1, 0, 0, 0}, /* PA30: FCC1 MII CRS */
  64. {1, 1, 1, 1, 0, 0}, /* PA29: FCC1 MII TX_ER */
  65. {1, 1, 1, 1, 0, 0}, /* PA28: FCC1 MII TX_EN */
  66. {1, 1, 1, 0, 0, 0}, /* PA27: FCC1 MII RX_DV */
  67. {1, 1, 1, 0, 0, 0}, /* PA26: FCC1 MII RX_ER */
  68. {0, 1, 0, 1, 0, 0}, /* PA25: FCC1 ATMTXD[0] */
  69. {0, 1, 0, 1, 0, 0}, /* PA24: FCC1 ATMTXD[1] */
  70. {0, 1, 0, 1, 0, 0}, /* PA23: FCC1 ATMTXD[2] */
  71. {0, 1, 0, 1, 0, 0}, /* PA22: FCC1 ATMTXD[3] */
  72. {1, 1, 0, 1, 0, 0}, /* PA21: FCC1 MII TxD[3] */
  73. {1, 1, 0, 1, 0, 0}, /* PA20: FCC1 MII TxD[2] */
  74. {1, 1, 0, 1, 0, 0}, /* PA19: FCC1 MII TxD[1] */
  75. {1, 1, 0, 1, 0, 0}, /* PA18: FCC1 MII TxD[0] */
  76. {1, 1, 0, 0, 0, 0}, /* PA17: FCC1 MII RxD[0] */
  77. {1, 1, 0, 0, 0, 0}, /* PA16: FCC1 MII RxD[1] */
  78. {1, 1, 0, 0, 0, 0}, /* PA15: FCC1 MII RxD[2] */
  79. {1, 1, 0, 0, 0, 0}, /* PA14: FCC1 MII RxD[3] */
  80. {0, 1, 0, 0, 0, 0}, /* PA13: FCC1 ATMRXD[3] */
  81. {0, 1, 0, 0, 0, 0}, /* PA12: FCC1 ATMRXD[2] */
  82. {0, 1, 0, 0, 0, 0}, /* PA11: FCC1 ATMRXD[1] */
  83. {0, 1, 0, 0, 0, 0}, /* PA10: FCC1 ATMRXD[0] */
  84. {0, 1, 1, 1, 0, 0}, /* PA9 : FCC1 L1TXD */
  85. {0, 1, 1, 0, 0, 0}, /* PA8 : FCC1 L1RXD */
  86. {0, 0, 0, 1, 0, 0}, /* PA7 : PA7 */
  87. {0, 1, 1, 1, 0, 0}, /* PA6 : TDM A1 L1RSYNC */
  88. {0, 0, 0, 1, 0, 0}, /* PA5 : PA5 */
  89. {0, 0, 0, 1, 0, 0}, /* PA4 : PA4 */
  90. {0, 0, 0, 1, 0, 0}, /* PA3 : PA3 */
  91. {0, 0, 0, 1, 0, 0}, /* PA2 : PA2 */
  92. {0, 0, 0, 0, 0, 0}, /* PA1 : FREERUN */
  93. {0, 0, 0, 1, 0, 0} /* PA0 : PA0 */
  94. },
  95. /* Port B: conf, ppar, psor, pdir, podr, pdat */
  96. {
  97. {1, 1, 0, 1, 0, 0}, /* PB31: FCC2 MII TX_ER */
  98. {1, 1, 0, 0, 0, 0}, /* PB30: FCC2 MII RX_DV */
  99. {1, 1, 1, 1, 0, 0}, /* PB29: FCC2 MII TX_EN */
  100. {1, 1, 0, 0, 0, 0}, /* PB28: FCC2 MII RX_ER */
  101. {1, 1, 0, 0, 0, 0}, /* PB27: FCC2 MII COL */
  102. {1, 1, 0, 0, 0, 0}, /* PB26: FCC2 MII CRS */
  103. {1, 1, 0, 1, 0, 0}, /* PB25: FCC2 MII TxD[3] */
  104. {1, 1, 0, 1, 0, 0}, /* PB24: FCC2 MII TxD[2] */
  105. {1, 1, 0, 1, 0, 0}, /* PB23: FCC2 MII TxD[1] */
  106. {1, 1, 0, 1, 0, 0}, /* PB22: FCC2 MII TxD[0] */
  107. {1, 1, 0, 0, 0, 0}, /* PB21: FCC2 MII RxD[0] */
  108. {1, 1, 0, 0, 0, 0}, /* PB20: FCC2 MII RxD[1] */
  109. {1, 1, 0, 0, 0, 0}, /* PB19: FCC2 MII RxD[2] */
  110. {1, 1, 0, 0, 0, 0}, /* PB18: FCC2 MII RxD[3] */
  111. {1, 1, 0, 0, 0, 0}, /* PB17: FCC3:RX_DIV */
  112. {1, 1, 0, 0, 0, 0}, /* PB16: FCC3:RX_ERR */
  113. {1, 1, 0, 1, 0, 0}, /* PB15: FCC3:TX_ERR */
  114. {1, 1, 0, 1, 0, 0}, /* PB14: FCC3:TX_EN */
  115. {1, 1, 0, 0, 0, 0}, /* PB13: FCC3:COL */
  116. {1, 1, 0, 0, 0, 0}, /* PB12: FCC3:CRS */
  117. {1, 1, 0, 0, 0, 0}, /* PB11: FCC3:RXD */
  118. {1, 1, 0, 0, 0, 0}, /* PB10: FCC3:RXD */
  119. {1, 1, 0, 0, 0, 0}, /* PB9 : FCC3:RXD */
  120. {1, 1, 0, 0, 0, 0}, /* PB8 : FCC3:RXD */
  121. {1, 1, 0, 1, 0, 0}, /* PB7 : FCC3:TXD */
  122. {1, 1, 0, 1, 0, 0}, /* PB6 : FCC3:TXD */
  123. {1, 1, 0, 1, 0, 0}, /* PB5 : FCC3:TXD */
  124. {1, 1, 0, 1, 0, 0}, /* PB4 : FCC3:TXD */
  125. {0, 0, 0, 0, 0, 0}, /* PB3 : pin doesn't exist */
  126. {0, 0, 0, 0, 0, 0}, /* PB2 : pin doesn't exist */
  127. {0, 0, 0, 0, 0, 0}, /* PB1 : pin doesn't exist */
  128. {0, 0, 0, 0, 0, 0} /* PB0 : pin doesn't exist */
  129. },
  130. /* Port C: conf, ppar, psor, pdir, podr, pdat */
  131. {
  132. {0, 0, 0, 1, 0, 0}, /* PC31: PC31 */
  133. {0, 0, 0, 1, 0, 0}, /* PC30: PC30 */
  134. {0, 1, 1, 0, 0, 0}, /* PC29: SCC1 EN *CLSN */
  135. {0, 0, 0, 1, 0, 0}, /* PC28: PC28 */
  136. {0, 0, 0, 1, 0, 0}, /* PC27: UART Clock in */
  137. {0, 0, 0, 1, 0, 0}, /* PC26: PC26 */
  138. {0, 0, 0, 1, 0, 0}, /* PC25: PC25 */
  139. {0, 0, 0, 1, 0, 0}, /* PC24: PC24 */
  140. {0, 1, 0, 1, 0, 0}, /* PC23: ATMTFCLK */
  141. {0, 1, 0, 0, 0, 0}, /* PC22: ATMRFCLK */
  142. {1, 1, 0, 0, 0, 0}, /* PC21: SCC1 EN RXCLK */
  143. {1, 1, 0, 0, 0, 0}, /* PC20: SCC1 EN TXCLK */
  144. {1, 1, 0, 0, 0, 0}, /* PC19: FCC2 MII RX_CLK CLK13 */
  145. {1, 1, 0, 0, 0, 0}, /* PC18: FCC Tx Clock (CLK14) */
  146. {1, 1, 0, 0, 0, 0}, /* PC17: PC17 */
  147. {1, 1, 0, 0, 0, 0}, /* PC16: FCC Tx Clock (CLK16) */
  148. {0, 1, 0, 0, 0, 0}, /* PC15: PC15 */
  149. {0, 1, 0, 0, 0, 0}, /* PC14: SCC1 EN *CD */
  150. {0, 1, 0, 0, 0, 0}, /* PC13: PC13 */
  151. {0, 1, 0, 1, 0, 0}, /* PC12: PC12 */
  152. {0, 0, 0, 1, 0, 0}, /* PC11: LXT971 transmit control */
  153. {0, 0, 0, 1, 0, 0}, /* PC10: FETHMDC */
  154. {0, 0, 0, 0, 0, 0}, /* PC9 : FETHMDIO */
  155. {0, 0, 0, 1, 0, 0}, /* PC8 : PC8 */
  156. {0, 0, 0, 1, 0, 0}, /* PC7 : PC7 */
  157. {0, 0, 0, 1, 0, 0}, /* PC6 : PC6 */
  158. {0, 0, 0, 1, 0, 0}, /* PC5 : PC5 */
  159. {0, 0, 0, 1, 0, 0}, /* PC4 : PC4 */
  160. {0, 0, 0, 1, 0, 0}, /* PC3 : PC3 */
  161. {0, 0, 0, 1, 0, 1}, /* PC2 : ENET FDE */
  162. {0, 0, 0, 1, 0, 0}, /* PC1 : ENET DSQE */
  163. {0, 0, 0, 1, 0, 0}, /* PC0 : ENET LBK */
  164. },
  165. /* Port D: conf, ppar, psor, pdir, podr, pdat */
  166. {
  167. #ifdef CONFIG_TQM8560
  168. {1, 1, 0, 0, 0, 0}, /* PD31: SCC1 EN RxD */
  169. {1, 1, 1, 1, 0, 0}, /* PD30: SCC1 EN TxD */
  170. {1, 1, 0, 1, 0, 0}, /* PD29: SCC1 EN TENA */
  171. #else /* !CONFIG_TQM8560 */
  172. {0, 0, 0, 0, 0, 0}, /* PD31: PD31 */
  173. {0, 0, 0, 0, 0, 0}, /* PD30: PD30 */
  174. {0, 0, 0, 0, 0, 0}, /* PD29: PD29 */
  175. #endif /* CONFIG_TQM8560 */
  176. {1, 1, 0, 0, 0, 0}, /* PD28: PD28 */
  177. {1, 1, 0, 1, 0, 0}, /* PD27: PD27 */
  178. {1, 1, 0, 1, 0, 0}, /* PD26: PD26 */
  179. {0, 0, 0, 1, 0, 0}, /* PD25: PD25 */
  180. {0, 0, 0, 1, 0, 0}, /* PD24: PD24 */
  181. {0, 0, 0, 1, 0, 0}, /* PD23: PD23 */
  182. {0, 0, 0, 1, 0, 0}, /* PD22: PD22 */
  183. {0, 0, 0, 1, 0, 0}, /* PD21: PD21 */
  184. {0, 0, 0, 1, 0, 0}, /* PD20: PD20 */
  185. {0, 0, 0, 1, 0, 0}, /* PD19: PD19 */
  186. {0, 0, 0, 1, 0, 0}, /* PD18: PD18 */
  187. {0, 1, 0, 0, 0, 0}, /* PD17: FCC1 ATMRXPRTY */
  188. {0, 1, 0, 1, 0, 0}, /* PD16: FCC1 ATMTXPRTY */
  189. {0, 1, 1, 0, 1, 0}, /* PD15: I2C SDA */
  190. {0, 0, 0, 1, 0, 0}, /* PD14: LED */
  191. {0, 0, 0, 0, 0, 0}, /* PD13: PD13 */
  192. {0, 0, 0, 0, 0, 0}, /* PD12: PD12 */
  193. {0, 0, 0, 0, 0, 0}, /* PD11: PD11 */
  194. {0, 0, 0, 0, 0, 0}, /* PD10: PD10 */
  195. {0, 1, 0, 1, 0, 0}, /* PD9 : SMC1 TXD */
  196. {0, 1, 0, 0, 0, 0}, /* PD8 : SMC1 RXD */
  197. {0, 0, 0, 1, 0, 1}, /* PD7 : PD7 */
  198. {0, 0, 0, 1, 0, 1}, /* PD6 : PD6 */
  199. {0, 0, 0, 1, 0, 1}, /* PD5 : PD5 */
  200. {0, 0, 0, 1, 0, 1}, /* PD4 : PD4 */
  201. {0, 0, 0, 0, 0, 0}, /* PD3 : pin doesn't exist */
  202. {0, 0, 0, 0, 0, 0}, /* PD2 : pin doesn't exist */
  203. {0, 0, 0, 0, 0, 0}, /* PD1 : pin doesn't exist */
  204. {0, 0, 0, 0, 0, 0} /* PD0 : pin doesn't exist */
  205. }
  206. };
  207. #endif /* CONFIG_CPM2 */
  208. #define CASL_STRING1 "casl=xx"
  209. #define CASL_STRING2 "casl="
  210. static const int casl_table[] = { 20, 25, 30 };
  211. #define N_CASL (sizeof(casl_table) / sizeof(casl_table[0]))
  212. int cas_latency (void)
  213. {
  214. char *s = getenv ("serial#");
  215. int casl;
  216. int val;
  217. int i;
  218. casl = CONFIG_DDR_DEFAULT_CL;
  219. if (s != NULL) {
  220. if (strncmp(s + strlen (s) - strlen (CASL_STRING1),
  221. CASL_STRING2, strlen (CASL_STRING2)) == 0) {
  222. val = simple_strtoul (s + strlen (s) - 2, NULL, 10);
  223. for (i = 0; i < N_CASL; ++i) {
  224. if (val == casl_table[i]) {
  225. return val;
  226. }
  227. }
  228. }
  229. }
  230. return casl;
  231. }
  232. int checkboard (void)
  233. {
  234. char *s = getenv ("serial#");
  235. printf ("Board: %s", CONFIG_BOARDNAME);
  236. if (s != NULL) {
  237. puts (", serial# ");
  238. puts (s);
  239. }
  240. putc ('\n');
  241. /*
  242. * Initialize local bus.
  243. */
  244. local_bus_init ();
  245. return 0;
  246. }
  247. int misc_init_r (void)
  248. {
  249. volatile ccsr_lbc_t *memctl = (void *)(CONFIG_SYS_MPC85xx_LBC_ADDR);
  250. /*
  251. * Adjust flash start and offset to detected values
  252. */
  253. gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
  254. gd->bd->bi_flashoffset = 0;
  255. /*
  256. * Recalculate CS configuration if second FLASH bank is available
  257. */
  258. if (flash_info[0].size > 0) {
  259. memctl->or1 = ((-flash_info[0].size) & 0xffff8000) |
  260. (CONFIG_SYS_OR1_PRELIM & 0x00007fff);
  261. memctl->br1 = gd->bd->bi_flashstart |
  262. (CONFIG_SYS_BR1_PRELIM & 0x00007fff);
  263. /*
  264. * Re-check to get correct base address for bank 1
  265. */
  266. flash_get_size (gd->bd->bi_flashstart, 0);
  267. } else {
  268. memctl->or1 = 0;
  269. memctl->br1 = 0;
  270. }
  271. /*
  272. * If bank 1 is equipped, bank 0 is mapped after bank 1
  273. */
  274. memctl->or0 = ((-flash_info[1].size) & 0xffff8000) |
  275. (CONFIG_SYS_OR0_PRELIM & 0x00007fff);
  276. memctl->br0 = (gd->bd->bi_flashstart + flash_info[0].size) |
  277. (CONFIG_SYS_BR0_PRELIM & 0x00007fff);
  278. /*
  279. * Re-check to get correct base address for bank 0
  280. */
  281. flash_get_size (gd->bd->bi_flashstart + flash_info[0].size, 1);
  282. /*
  283. * Re-do flash protection upon new addresses
  284. */
  285. flash_protect (FLAG_PROTECT_CLEAR,
  286. gd->bd->bi_flashstart, 0xffffffff,
  287. &flash_info[CONFIG_SYS_MAX_FLASH_BANKS - 1]);
  288. /* Monitor protection ON by default */
  289. flash_protect (FLAG_PROTECT_SET,
  290. CONFIG_SYS_MONITOR_BASE,
  291. CONFIG_SYS_MONITOR_BASE + monitor_flash_len - 1,
  292. &flash_info[CONFIG_SYS_MAX_FLASH_BANKS - 1]);
  293. /* Environment protection ON by default */
  294. flash_protect (FLAG_PROTECT_SET,
  295. CONFIG_ENV_ADDR,
  296. CONFIG_ENV_ADDR + CONFIG_ENV_SECT_SIZE - 1,
  297. &flash_info[CONFIG_SYS_MAX_FLASH_BANKS - 1]);
  298. #ifdef CONFIG_ENV_ADDR_REDUND
  299. /* Redundant environment protection ON by default */
  300. flash_protect (FLAG_PROTECT_SET,
  301. CONFIG_ENV_ADDR_REDUND,
  302. CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SIZE_REDUND - 1,
  303. &flash_info[CONFIG_SYS_MAX_FLASH_BANKS - 1]);
  304. #endif
  305. return 0;
  306. }
  307. #ifdef CONFIG_CAN_DRIVER
  308. /*
  309. * Initialize UPMC RAM
  310. */
  311. static void upmc_write (u_char addr, uint val)
  312. {
  313. volatile ccsr_lbc_t *lbc = (void *)(CONFIG_SYS_MPC85xx_LBC_ADDR);
  314. out_be32 (&lbc->mdr, val);
  315. clrsetbits_be32(&lbc->mcmr, MxMR_MAD_MSK,
  316. MxMR_OP_WARR | (addr & MxMR_MAD_MSK));
  317. /* dummy access to perform write */
  318. out_8 ((void __iomem *)CONFIG_SYS_CAN_BASE, 0);
  319. /* normal operation */
  320. clrbits_be32(&lbc->mcmr, MxMR_OP_WARR);
  321. }
  322. #endif /* CONFIG_CAN_DRIVER */
  323. uint get_lbc_clock (void)
  324. {
  325. volatile ccsr_lbc_t *lbc = (void *)(CONFIG_SYS_MPC85xx_LBC_ADDR);
  326. sys_info_t sys_info;
  327. ulong clkdiv = lbc->lcrr & LCRR_CLKDIV;
  328. get_sys_info (&sys_info);
  329. if (clkdiv == 2 || clkdiv == 4 || clkdiv == 8) {
  330. #ifdef CONFIG_MPC8548
  331. /*
  332. * Yes, the entire PQ38 family use the same
  333. * bit-representation for twice the clock divider value.
  334. */
  335. clkdiv *= 2;
  336. #endif
  337. return sys_info.freqSystemBus / clkdiv;
  338. }
  339. puts("Invalid clock divider value in CONFIG_SYS_LBC_LCRR\n");
  340. return 0;
  341. }
  342. /*
  343. * Initialize Local Bus
  344. */
  345. void local_bus_init (void)
  346. {
  347. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  348. volatile ccsr_lbc_t *lbc = (void *)(CONFIG_SYS_MPC85xx_LBC_ADDR);
  349. uint lbc_mhz = get_lbc_clock () / 1000000;
  350. #ifdef CONFIG_MPC8548
  351. uint svr = get_svr ();
  352. uint lcrr;
  353. /*
  354. * MPC revision < 2.0
  355. * According to MPC8548E_Device_Errata Rev. L, Erratum LBIU1:
  356. * Modify engineering use only register at address 0xE_0F20.
  357. * "1. Read register at offset 0xE_0F20
  358. * 2. And value with 0x0000_FFFF
  359. * 3. OR result with 0x0000_0004
  360. * 4. Write result back to offset 0xE_0F20."
  361. *
  362. * According to MPC8548E_Device_Errata Rev. L, Erratum LBIU2:
  363. * Modify engineering use only register at address 0xE_0F20.
  364. * "1. Read register at offset 0xE_0F20
  365. * 2. And value with 0xFFFF_FFDF
  366. * 3. Write result back to offset 0xE_0F20."
  367. *
  368. * Since it is the same register, we do the modification in one step.
  369. */
  370. if (SVR_MAJ (svr) < 2) {
  371. uint dummy = gur->lbiuiplldcr1;
  372. dummy &= 0x0000FFDF;
  373. dummy |= 0x00000004;
  374. gur->lbiuiplldcr1 = dummy;
  375. }
  376. lcrr = CONFIG_SYS_LBC_LCRR;
  377. /*
  378. * Local Bus Clock > 83.3 MHz. According to timing
  379. * specifications set LCRR[EADC] to 2 delay cycles.
  380. */
  381. if (lbc_mhz > 83) {
  382. lcrr &= ~LCRR_EADC;
  383. lcrr |= LCRR_EADC_2;
  384. }
  385. /*
  386. * According to MPC8548ERMAD Rev. 1.3, 13.3.1.16, 13-30
  387. * disable PLL bypass for Local Bus Clock > 83 MHz.
  388. */
  389. if (lbc_mhz >= 66)
  390. lcrr &= (~LCRR_DBYP); /* DLL Enabled */
  391. else
  392. lcrr |= LCRR_DBYP; /* DLL Bypass */
  393. lbc->lcrr = lcrr;
  394. asm ("sync;isync;msync");
  395. /*
  396. * According to MPC8548ERMAD Rev.1.3 read back LCRR
  397. * and terminate with isync
  398. */
  399. lcrr = lbc->lcrr;
  400. asm ("isync;");
  401. /* let DLL stabilize */
  402. udelay (500);
  403. #else /* !CONFIG_MPC8548 */
  404. /*
  405. * Errata LBC11.
  406. * Fix Local Bus clock glitch when DLL is enabled.
  407. *
  408. * If localbus freq is < 66MHz, DLL bypass mode must be used.
  409. * If localbus freq is > 133MHz, DLL can be safely enabled.
  410. * Between 66 and 133, the DLL is enabled with an override workaround.
  411. */
  412. if (lbc_mhz < 66) {
  413. lbc->lcrr = CONFIG_SYS_LBC_LCRR | LCRR_DBYP; /* DLL Bypass */
  414. lbc->ltedr = LTEDR_BMD | LTEDR_PARD | LTEDR_WPD | LTEDR_WARA |
  415. LTEDR_RAWA | LTEDR_CSD; /* Disable all error checking */
  416. } else if (lbc_mhz >= 133) {
  417. lbc->lcrr = CONFIG_SYS_LBC_LCRR & (~LCRR_DBYP); /* DLL Enabled */
  418. } else {
  419. /*
  420. * On REV1 boards, need to change CLKDIV before enable DLL.
  421. * Default CLKDIV is 8, change it to 4 temporarily.
  422. */
  423. uint pvr = get_pvr ();
  424. uint temp_lbcdll = 0;
  425. if (pvr == PVR_85xx_REV1) {
  426. /* FIXME: Justify the high bit here. */
  427. lbc->lcrr = 0x10000004;
  428. }
  429. lbc->lcrr = CONFIG_SYS_LBC_LCRR & (~LCRR_DBYP); /* DLL Enabled */
  430. udelay (200);
  431. /*
  432. * Sample LBC DLL ctrl reg, upshift it to set the
  433. * override bits.
  434. */
  435. temp_lbcdll = gur->lbcdllcr;
  436. gur->lbcdllcr = (((temp_lbcdll & 0xff) << 16) | 0x80000000);
  437. asm ("sync;isync;msync");
  438. }
  439. #endif /* !CONFIG_MPC8548 */
  440. #ifdef CONFIG_CAN_DRIVER
  441. /*
  442. * According to timing specifications EAD must be
  443. * set if Local Bus Clock is > 83 MHz.
  444. */
  445. if (lbc_mhz > 83)
  446. out_be32 (&lbc->or2, CONFIG_SYS_OR2_CAN | OR_UPM_EAD);
  447. else
  448. out_be32 (&lbc->or2, CONFIG_SYS_OR2_CAN);
  449. out_be32 (&lbc->br2, CONFIG_SYS_BR2_CAN);
  450. /* LGPL4 is UPWAIT */
  451. out_be32(&lbc->mcmr, MxMR_DSx_3_CYCL | MxMR_GPL_x4DIS | MxMR_WLFx_3X);
  452. /* Initialize UPMC for CAN: single read */
  453. upmc_write (0x00, 0xFFFFED00);
  454. upmc_write (0x01, 0xCCFFCC00);
  455. upmc_write (0x02, 0x00FFCF00);
  456. upmc_write (0x03, 0x00FFCF00);
  457. upmc_write (0x04, 0x00FFDC00);
  458. upmc_write (0x05, 0x00FFCF00);
  459. upmc_write (0x06, 0x00FFED00);
  460. upmc_write (0x07, 0x3FFFCC07);
  461. /* Initialize UPMC for CAN: single write */
  462. upmc_write (0x18, 0xFFFFED00);
  463. upmc_write (0x19, 0xCCFFEC00);
  464. upmc_write (0x1A, 0x00FFED80);
  465. upmc_write (0x1B, 0x00FFED80);
  466. upmc_write (0x1C, 0x00FFFC00);
  467. upmc_write (0x1D, 0x0FFFEC00);
  468. upmc_write (0x1E, 0x0FFFEF00);
  469. upmc_write (0x1F, 0x3FFFEC05);
  470. #endif /* CONFIG_CAN_DRIVER */
  471. }
  472. /*
  473. * Initialize PCI Devices, report devices found.
  474. */
  475. static int first_free_busno;
  476. extern int fsl_pci_setup_inbound_windows(struct pci_region *r);
  477. extern void fsl_pci_init(struct pci_controller *hose);
  478. #if defined(CONFIG_PCI) || defined(CONFIG_PCI1)
  479. static struct pci_controller pci1_hose;
  480. #endif /* CONFIG_PCI || CONFIG_PCI1 */
  481. #ifdef CONFIG_PCIE1
  482. static struct pci_controller pcie1_hose;
  483. #endif /* CONFIG_PCIE1 */
  484. static inline void init_pci1(void)
  485. {
  486. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  487. #if defined(CONFIG_PCI) || defined(CONFIG_PCI1)
  488. uint host_agent = (gur->porbmsr & MPC85xx_PORBMSR_HA) >> 16;
  489. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *)CONFIG_SYS_PCI1_ADDR;
  490. struct pci_controller *hose = &pci1_hose;
  491. struct pci_region *r = hose->regions;
  492. /* PORDEVSR[15] */
  493. uint pci_32 = gur->pordevsr & MPC85xx_PORDEVSR_PCI1_PCI32;
  494. /* PORDEVSR[14] */
  495. uint pci_arb = gur->pordevsr & MPC85xx_PORDEVSR_PCI1_ARB;
  496. /* PORPLLSR[16] */
  497. uint pci_clk_sel = gur->porpllsr & MPC85xx_PORDEVSR_PCI1_SPD;
  498. uint pci_agent = (host_agent == 3) || (host_agent == 4 ) ||
  499. (host_agent == 6);
  500. uint pci_speed = CONFIG_SYS_CLK_FREQ; /* PCI PSPEED in [4:5] */
  501. if (!(gur->devdisr & MPC85xx_DEVDISR_PCI1)) {
  502. printf ("PCI1: %d bit, %s MHz, %s, %s, %s\n",
  503. (pci_32) ? 32 : 64,
  504. (pci_speed == 33333333) ? "33" :
  505. (pci_speed == 66666666) ? "66" : "unknown",
  506. pci_clk_sel ? "sync" : "async",
  507. pci_agent ? "agent" : "host",
  508. pci_arb ? "arbiter" : "external-arbiter");
  509. /* inbound */
  510. r += fsl_pci_setup_inbound_windows(r);
  511. /* outbound memory */
  512. pci_set_region (r++,
  513. CONFIG_SYS_PCI1_MEM_BASE,
  514. CONFIG_SYS_PCI1_MEM_PHYS,
  515. CONFIG_SYS_PCI1_MEM_SIZE,
  516. PCI_REGION_MEM);
  517. /* outbound io */
  518. pci_set_region (r++,
  519. CONFIG_SYS_PCI1_IO_BASE,
  520. CONFIG_SYS_PCI1_IO_PHYS,
  521. CONFIG_SYS_PCI1_IO_SIZE,
  522. PCI_REGION_IO);
  523. hose->region_count = r - hose->regions;
  524. hose->first_busno = first_free_busno;
  525. pci_setup_indirect (hose, (int)&pci->cfg_addr,
  526. (int)&pci->cfg_data);
  527. fsl_pci_init (hose);
  528. printf (" PCI on bus %02x..%02x\n",
  529. hose->first_busno, hose->last_busno);
  530. first_free_busno = hose->last_busno + 1;
  531. #ifdef CONFIG_PCIX_CHECK
  532. if (!(gur->pordevsr & MPC85xx_PORDEVSR_PCI1)) {
  533. ushort reg16 =
  534. PCI_X_CMD_MAX_SPLIT | PCI_X_CMD_MAX_READ |
  535. PCI_X_CMD_ERO | PCI_X_CMD_DPERR_E;
  536. uint dev = PCI_BDF(hose->first_busno, 0, 0);
  537. /* PCI-X init */
  538. if (CONFIG_SYS_CLK_FREQ < 66000000)
  539. puts ("PCI-X will only work at 66 MHz\n");
  540. pci_hose_write_config_word (hose, dev, PCIX_COMMAND,
  541. reg16);
  542. }
  543. #endif
  544. } else {
  545. puts ("PCI1: disabled\n");
  546. }
  547. #else /* !(CONFIG_PCI || CONFIG_PCI1) */
  548. gur->devdisr |= MPC85xx_DEVDISR_PCI1; /* disable */
  549. #endif /* CONFIG_PCI || CONFIG_PCI1) */
  550. }
  551. static inline void init_pcie1(void)
  552. {
  553. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  554. #ifdef CONFIG_PCIE1
  555. uint io_sel = (gur->pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19;
  556. uint host_agent = (gur->porbmsr & MPC85xx_PORBMSR_HA) >> 16;
  557. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *)CONFIG_SYS_PCIE1_ADDR;
  558. struct pci_controller *hose = &pcie1_hose;
  559. int pcie_ep = (host_agent == 0) || (host_agent == 2 ) ||
  560. (host_agent == 3);
  561. struct pci_region *r = hose->regions;
  562. int pcie_configured = io_sel >= 1;
  563. if (pcie_configured && !(gur->devdisr & MPC85xx_DEVDISR_PCIE)){
  564. printf ("PCIe: %s, base address %x",
  565. pcie_ep ? "End point" : "Root complex", (uint)pci);
  566. if (pci->pme_msg_det) {
  567. pci->pme_msg_det = 0xffffffff;
  568. debug (", with errors. Clearing. Now 0x%08x",
  569. pci->pme_msg_det);
  570. }
  571. puts ("\n");
  572. /* inbound */
  573. r += fsl_pci_setup_inbound_windows(r);
  574. /* outbound memory */
  575. pci_set_region (r++,
  576. CONFIG_SYS_PCIE1_MEM_BASE,
  577. CONFIG_SYS_PCIE1_MEM_PHYS,
  578. CONFIG_SYS_PCIE1_MEM_SIZE,
  579. PCI_REGION_MEM);
  580. /* outbound io */
  581. pci_set_region (r++,
  582. CONFIG_SYS_PCIE1_IO_BASE,
  583. CONFIG_SYS_PCIE1_IO_PHYS,
  584. CONFIG_SYS_PCIE1_IO_SIZE,
  585. PCI_REGION_IO);
  586. hose->region_count = r - hose->regions;
  587. hose->first_busno = first_free_busno;
  588. pci_setup_indirect(hose, (int)&pci->cfg_addr,
  589. (int)&pci->cfg_data);
  590. fsl_pci_init (hose);
  591. printf (" PCIe on bus %02x..%02x\n",
  592. hose->first_busno, hose->last_busno);
  593. first_free_busno = hose->last_busno + 1;
  594. } else {
  595. printf ("PCIe: disabled\n");
  596. }
  597. #else /* !CONFIG_PCIE1 */
  598. gur->devdisr |= MPC85xx_DEVDISR_PCIE; /* disable */
  599. #endif /* CONFIG_PCIE1 */
  600. }
  601. void pci_init_board (void)
  602. {
  603. init_pci1();
  604. init_pcie1();
  605. }
  606. #ifdef CONFIG_OF_BOARD_SETUP
  607. extern void ft_fsl_pci_setup(void *blob, const char *pci_alias,
  608. struct pci_controller *hose);
  609. void ft_board_setup (void *blob, bd_t *bd)
  610. {
  611. ft_cpu_setup (blob, bd);
  612. #if defined(CONFIG_PCI) || defined(CONFIG_PCI1)
  613. ft_fsl_pci_setup(blob, "pci0", &pci1_hose);
  614. #endif
  615. #ifdef CONFIG_PCIE1
  616. ft_fsl_pci_setup(blob, "pci1", &pcie1_hose);
  617. #endif
  618. }
  619. #endif /* CONFIG_OF_BOARD_SETUP */
  620. #ifdef CONFIG_BOARD_EARLY_INIT_R
  621. int board_early_init_r (void)
  622. {
  623. #ifdef CONFIG_PS2MULT
  624. ps2mult_early_init ();
  625. #endif /* CONFIG_PS2MULT */
  626. return (0);
  627. }
  628. #endif /* CONFIG_BOARD_EARLY_INIT_R */
  629. int board_eth_init(bd_t *bis)
  630. {
  631. cpu_eth_init(bis); /* Intialize TSECs first */
  632. return pci_eth_init(bis);
  633. }