tqm85xx.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  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/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. /*
  250. * Adjust flash start and offset to detected values
  251. */
  252. gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
  253. gd->bd->bi_flashoffset = 0;
  254. /*
  255. * Recalculate CS configuration if second FLASH bank is available
  256. */
  257. if (flash_info[0].size > 0) {
  258. set_lbc_or(1, ((-flash_info[0].size) & 0xffff8000) |
  259. (CONFIG_SYS_OR1_PRELIM & 0x00007fff));
  260. set_lbc_br(1, gd->bd->bi_flashstart |
  261. (CONFIG_SYS_BR1_PRELIM & 0x00007fff));
  262. /*
  263. * Re-check to get correct base address for bank 1
  264. */
  265. flash_get_size (gd->bd->bi_flashstart, 0);
  266. } else {
  267. set_lbc_or(1, 0);
  268. set_lbc_br(1, 0);
  269. }
  270. /*
  271. * If bank 1 is equipped, bank 0 is mapped after bank 1
  272. */
  273. set_lbc_or(0, ((-flash_info[1].size) & 0xffff8000) |
  274. (CONFIG_SYS_OR0_PRELIM & 0x00007fff));
  275. set_lbc_br(0, gd->bd->bi_flashstart |
  276. (CONFIG_SYS_BR0_PRELIM & 0x00007fff));
  277. /*
  278. * Re-check to get correct base address for bank 0
  279. */
  280. flash_get_size (gd->bd->bi_flashstart + flash_info[0].size, 1);
  281. /*
  282. * Re-do flash protection upon new addresses
  283. */
  284. flash_protect (FLAG_PROTECT_CLEAR,
  285. gd->bd->bi_flashstart, 0xffffffff,
  286. &flash_info[CONFIG_SYS_MAX_FLASH_BANKS - 1]);
  287. /* Monitor protection ON by default */
  288. flash_protect (FLAG_PROTECT_SET,
  289. CONFIG_SYS_MONITOR_BASE, 0xffffffff,
  290. &flash_info[CONFIG_SYS_MAX_FLASH_BANKS - 1]);
  291. /* Environment protection ON by default */
  292. flash_protect (FLAG_PROTECT_SET,
  293. CONFIG_ENV_ADDR,
  294. CONFIG_ENV_ADDR + CONFIG_ENV_SECT_SIZE - 1,
  295. &flash_info[CONFIG_SYS_MAX_FLASH_BANKS - 1]);
  296. #ifdef CONFIG_ENV_ADDR_REDUND
  297. /* Redundant environment protection ON by default */
  298. flash_protect (FLAG_PROTECT_SET,
  299. CONFIG_ENV_ADDR_REDUND,
  300. CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SECT_SIZE - 1,
  301. &flash_info[CONFIG_SYS_MAX_FLASH_BANKS - 1]);
  302. #endif
  303. return 0;
  304. }
  305. #ifdef CONFIG_CAN_DRIVER
  306. /*
  307. * Initialize UPMC RAM
  308. */
  309. static void upmc_write (u_char addr, uint val)
  310. {
  311. volatile fsl_lbc_t *lbc = LBC_BASE_ADDR;
  312. out_be32 (&lbc->mdr, val);
  313. clrsetbits_be32(&lbc->mcmr, MxMR_MAD_MSK,
  314. MxMR_OP_WARR | (addr & MxMR_MAD_MSK));
  315. /* dummy access to perform write */
  316. out_8 ((void __iomem *)CONFIG_SYS_CAN_BASE, 0);
  317. /* normal operation */
  318. clrbits_be32(&lbc->mcmr, MxMR_OP_WARR);
  319. }
  320. #endif /* CONFIG_CAN_DRIVER */
  321. uint get_lbc_clock (void)
  322. {
  323. volatile fsl_lbc_t *lbc = LBC_BASE_ADDR;
  324. sys_info_t sys_info;
  325. ulong clkdiv = lbc->lcrr & LCRR_CLKDIV;
  326. get_sys_info (&sys_info);
  327. if (clkdiv == 2 || clkdiv == 4 || clkdiv == 8) {
  328. #ifdef CONFIG_MPC8548
  329. /*
  330. * Yes, the entire PQ38 family use the same
  331. * bit-representation for twice the clock divider value.
  332. */
  333. clkdiv *= 2;
  334. #endif
  335. return sys_info.freqSystemBus / clkdiv;
  336. }
  337. puts("Invalid clock divider value in CONFIG_SYS_LBC_LCRR\n");
  338. return 0;
  339. }
  340. /*
  341. * Initialize Local Bus
  342. */
  343. void local_bus_init (void)
  344. {
  345. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  346. volatile fsl_lbc_t *lbc = LBC_BASE_ADDR;
  347. uint lbc_mhz = get_lbc_clock () / 1000000;
  348. #ifdef CONFIG_MPC8548
  349. uint svr = get_svr ();
  350. uint lcrr;
  351. /*
  352. * MPC revision < 2.0
  353. * According to MPC8548E_Device_Errata Rev. L, Erratum LBIU1:
  354. * Modify engineering use only register at address 0xE_0F20.
  355. * "1. Read register at offset 0xE_0F20
  356. * 2. And value with 0x0000_FFFF
  357. * 3. OR result with 0x0000_0004
  358. * 4. Write result back to offset 0xE_0F20."
  359. *
  360. * According to MPC8548E_Device_Errata Rev. L, Erratum LBIU2:
  361. * Modify engineering use only register at address 0xE_0F20.
  362. * "1. Read register at offset 0xE_0F20
  363. * 2. And value with 0xFFFF_FFDF
  364. * 3. Write result back to offset 0xE_0F20."
  365. *
  366. * Since it is the same register, we do the modification in one step.
  367. */
  368. if (SVR_MAJ (svr) < 2) {
  369. uint dummy = gur->lbiuiplldcr1;
  370. dummy &= 0x0000FFDF;
  371. dummy |= 0x00000004;
  372. gur->lbiuiplldcr1 = dummy;
  373. }
  374. lcrr = CONFIG_SYS_LBC_LCRR;
  375. /*
  376. * Local Bus Clock > 83.3 MHz. According to timing
  377. * specifications set LCRR[EADC] to 2 delay cycles.
  378. */
  379. if (lbc_mhz > 83) {
  380. lcrr &= ~LCRR_EADC;
  381. lcrr |= LCRR_EADC_2;
  382. }
  383. /*
  384. * According to MPC8548ERMAD Rev. 1.3, 13.3.1.16, 13-30
  385. * disable PLL bypass for Local Bus Clock > 83 MHz.
  386. */
  387. if (lbc_mhz >= 66)
  388. lcrr &= (~LCRR_DBYP); /* DLL Enabled */
  389. else
  390. lcrr |= LCRR_DBYP; /* DLL Bypass */
  391. lbc->lcrr = lcrr;
  392. asm ("sync;isync;msync");
  393. /*
  394. * According to MPC8548ERMAD Rev.1.3 read back LCRR
  395. * and terminate with isync
  396. */
  397. lcrr = lbc->lcrr;
  398. asm ("isync;");
  399. /* let DLL stabilize */
  400. udelay (500);
  401. #else /* !CONFIG_MPC8548 */
  402. /*
  403. * Errata LBC11.
  404. * Fix Local Bus clock glitch when DLL is enabled.
  405. *
  406. * If localbus freq is < 66MHz, DLL bypass mode must be used.
  407. * If localbus freq is > 133MHz, DLL can be safely enabled.
  408. * Between 66 and 133, the DLL is enabled with an override workaround.
  409. */
  410. if (lbc_mhz < 66) {
  411. lbc->lcrr = CONFIG_SYS_LBC_LCRR | LCRR_DBYP; /* DLL Bypass */
  412. lbc->ltedr = LTEDR_BMD | LTEDR_PARD | LTEDR_WPD | LTEDR_WARA |
  413. LTEDR_RAWA | LTEDR_CSD; /* Disable all error checking */
  414. } else if (lbc_mhz >= 133) {
  415. lbc->lcrr = CONFIG_SYS_LBC_LCRR & (~LCRR_DBYP); /* DLL Enabled */
  416. } else {
  417. /*
  418. * On REV1 boards, need to change CLKDIV before enable DLL.
  419. * Default CLKDIV is 8, change it to 4 temporarily.
  420. */
  421. uint pvr = get_pvr ();
  422. uint temp_lbcdll = 0;
  423. if (pvr == PVR_85xx_REV1) {
  424. /* FIXME: Justify the high bit here. */
  425. lbc->lcrr = 0x10000004;
  426. }
  427. lbc->lcrr = CONFIG_SYS_LBC_LCRR & (~LCRR_DBYP); /* DLL Enabled */
  428. udelay (200);
  429. /*
  430. * Sample LBC DLL ctrl reg, upshift it to set the
  431. * override bits.
  432. */
  433. temp_lbcdll = gur->lbcdllcr;
  434. gur->lbcdllcr = (((temp_lbcdll & 0xff) << 16) | 0x80000000);
  435. asm ("sync;isync;msync");
  436. }
  437. #endif /* !CONFIG_MPC8548 */
  438. #ifdef CONFIG_CAN_DRIVER
  439. /*
  440. * According to timing specifications EAD must be
  441. * set if Local Bus Clock is > 83 MHz.
  442. */
  443. if (lbc_mhz > 83)
  444. set_lbc_or(2, CONFIG_SYS_OR2_CAN | OR_UPM_EAD);
  445. else
  446. set_lbc_or(2, CONFIG_SYS_OR2_CAN);
  447. set_lbc_br(2, CONFIG_SYS_BR2_CAN);
  448. /* LGPL4 is UPWAIT */
  449. out_be32(&lbc->mcmr, MxMR_DSx_3_CYCL | MxMR_GPL_x4DIS | MxMR_WLFx_3X);
  450. /* Initialize UPMC for CAN: single read */
  451. upmc_write (0x00, 0xFFFFED00);
  452. upmc_write (0x01, 0xCCFFCC00);
  453. upmc_write (0x02, 0x00FFCF00);
  454. upmc_write (0x03, 0x00FFCF00);
  455. upmc_write (0x04, 0x00FFDC00);
  456. upmc_write (0x05, 0x00FFCF00);
  457. upmc_write (0x06, 0x00FFED00);
  458. upmc_write (0x07, 0x3FFFCC07);
  459. /* Initialize UPMC for CAN: single write */
  460. upmc_write (0x18, 0xFFFFED00);
  461. upmc_write (0x19, 0xCCFFEC00);
  462. upmc_write (0x1A, 0x00FFED80);
  463. upmc_write (0x1B, 0x00FFED80);
  464. upmc_write (0x1C, 0x00FFFC00);
  465. upmc_write (0x1D, 0x0FFFEC00);
  466. upmc_write (0x1E, 0x0FFFEF00);
  467. upmc_write (0x1F, 0x3FFFEC05);
  468. #endif /* CONFIG_CAN_DRIVER */
  469. }
  470. /*
  471. * Initialize PCI Devices, report devices found.
  472. */
  473. static int first_free_busno;
  474. #ifdef CONFIG_PCI1
  475. static struct pci_controller pci1_hose;
  476. #endif /* CONFIG_PCI1 */
  477. #ifdef CONFIG_PCIE1
  478. static struct pci_controller pcie1_hose;
  479. #endif /* CONFIG_PCIE1 */
  480. static inline void init_pci1(void)
  481. {
  482. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  483. #ifdef CONFIG_PCI1
  484. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *)CONFIG_SYS_PCI1_ADDR;
  485. struct pci_controller *hose = &pci1_hose;
  486. struct pci_region *r = hose->regions;
  487. /* PORDEVSR[15] */
  488. uint pci_32 = gur->pordevsr & MPC85xx_PORDEVSR_PCI1_PCI32;
  489. /* PORDEVSR[14] */
  490. uint pci_arb = gur->pordevsr & MPC85xx_PORDEVSR_PCI1_ARB;
  491. /* PORPLLSR[16] */
  492. uint pci_clk_sel = gur->porpllsr & MPC85xx_PORDEVSR_PCI1_SPD;
  493. int pci_agent = fsl_setup_hose(hose, CONFIG_SYS_PCI1_ADDR);
  494. uint pci_speed = CONFIG_SYS_CLK_FREQ; /* PCI PSPEED in [4:5] */
  495. if (!(gur->devdisr & MPC85xx_DEVDISR_PCI1)) {
  496. printf ("PCI1: %d bit, %s MHz, %s, %s, %s\n",
  497. (pci_32) ? 32 : 64,
  498. (pci_speed == 33333333) ? "33" :
  499. (pci_speed == 66666666) ? "66" : "unknown",
  500. pci_clk_sel ? "sync" : "async",
  501. pci_agent ? "agent" : "host",
  502. pci_arb ? "arbiter" : "external-arbiter");
  503. /* outbound memory */
  504. pci_set_region (r++,
  505. CONFIG_SYS_PCI1_MEM_BASE,
  506. CONFIG_SYS_PCI1_MEM_PHYS,
  507. CONFIG_SYS_PCI1_MEM_SIZE,
  508. PCI_REGION_MEM);
  509. /* outbound io */
  510. pci_set_region (r++,
  511. CONFIG_SYS_PCI1_IO_BASE,
  512. CONFIG_SYS_PCI1_IO_PHYS,
  513. CONFIG_SYS_PCI1_IO_SIZE,
  514. PCI_REGION_IO);
  515. hose->region_count = r - hose->regions;
  516. hose->first_busno = first_free_busno;
  517. fsl_pci_init(hose, (u32)&pci->cfg_addr, (u32)&pci->cfg_data);
  518. printf (" PCI on bus %02x..%02x\n",
  519. hose->first_busno, hose->last_busno);
  520. first_free_busno = hose->last_busno + 1;
  521. #ifdef CONFIG_PCIX_CHECK
  522. if (!(gur->pordevsr & MPC85xx_PORDEVSR_PCI1)) {
  523. ushort reg16 =
  524. PCI_X_CMD_MAX_SPLIT | PCI_X_CMD_MAX_READ |
  525. PCI_X_CMD_ERO | PCI_X_CMD_DPERR_E;
  526. uint dev = PCI_BDF(hose->first_busno, 0, 0);
  527. /* PCI-X init */
  528. if (CONFIG_SYS_CLK_FREQ < 66000000)
  529. puts ("PCI-X will only work at 66 MHz\n");
  530. pci_hose_write_config_word (hose, dev, PCIX_COMMAND,
  531. reg16);
  532. }
  533. #endif
  534. } else {
  535. puts ("PCI1: disabled\n");
  536. }
  537. #else /* !CONFIG_PCI1 */
  538. gur->devdisr |= MPC85xx_DEVDISR_PCI1; /* disable */
  539. #endif /* CONFIG_PCI1 */
  540. }
  541. static inline void init_pcie1(void)
  542. {
  543. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  544. #ifdef CONFIG_PCIE1
  545. uint io_sel = (gur->pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19;
  546. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *)CONFIG_SYS_PCIE1_ADDR;
  547. struct pci_controller *hose = &pcie1_hose;
  548. int pcie_ep;
  549. struct pci_region *r = hose->regions;
  550. int pcie_configured = is_fsl_pci_cfg(LAW_TRGT_IF_PCIE_1, io_sel);
  551. pcie_ep = fsl_setup_hose(hose, CONFIG_SYS_PCIE1_ADDR);
  552. if (pcie_configured && !(gur->devdisr & MPC85xx_DEVDISR_PCIE)){
  553. printf ("PCIe: %s, base address %x",
  554. pcie_ep ? "Endpoint" : "Root complex", (uint)pci);
  555. if (pci->pme_msg_det) {
  556. pci->pme_msg_det = 0xffffffff;
  557. debug (", with errors. Clearing. Now 0x%08x",
  558. pci->pme_msg_det);
  559. }
  560. puts ("\n");
  561. /* outbound memory */
  562. pci_set_region (r++,
  563. CONFIG_SYS_PCIE1_MEM_BASE,
  564. CONFIG_SYS_PCIE1_MEM_PHYS,
  565. CONFIG_SYS_PCIE1_MEM_SIZE,
  566. PCI_REGION_MEM);
  567. /* outbound io */
  568. pci_set_region (r++,
  569. CONFIG_SYS_PCIE1_IO_BASE,
  570. CONFIG_SYS_PCIE1_IO_PHYS,
  571. CONFIG_SYS_PCIE1_IO_SIZE,
  572. PCI_REGION_IO);
  573. hose->region_count = r - hose->regions;
  574. hose->first_busno = first_free_busno;
  575. fsl_pci_init(hose, (u32)&pci->cfg_addr, (u32)&pci->cfg_data);
  576. printf (" PCIe on bus %02x..%02x\n",
  577. hose->first_busno, hose->last_busno);
  578. first_free_busno = hose->last_busno + 1;
  579. } else {
  580. printf ("PCIe: disabled\n");
  581. }
  582. #else /* !CONFIG_PCIE1 */
  583. gur->devdisr |= MPC85xx_DEVDISR_PCIE; /* disable */
  584. #endif /* CONFIG_PCIE1 */
  585. }
  586. void pci_init_board (void)
  587. {
  588. init_pci1();
  589. init_pcie1();
  590. }
  591. #ifdef CONFIG_OF_BOARD_SETUP
  592. void ft_board_setup (void *blob, bd_t *bd)
  593. {
  594. ft_cpu_setup (blob, bd);
  595. FT_FSL_PCI_SETUP;
  596. }
  597. #endif /* CONFIG_OF_BOARD_SETUP */
  598. #ifdef CONFIG_BOARD_EARLY_INIT_R
  599. int board_early_init_r (void)
  600. {
  601. #ifdef CONFIG_PS2MULT
  602. ps2mult_early_init ();
  603. #endif /* CONFIG_PS2MULT */
  604. return (0);
  605. }
  606. #endif /* CONFIG_BOARD_EARLY_INIT_R */
  607. int board_eth_init(bd_t *bis)
  608. {
  609. cpu_eth_init(bis); /* Intialize TSECs first */
  610. return pci_eth_init(bis);
  611. }