tqm85xx.c 21 KB

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