tqm85xx.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. /*
  2. * (C) Copyright 2005
  3. * Stefan Roese, DENX Software Engineering, sr@denx.de.
  4. *
  5. * Copyright 2004 Freescale Semiconductor.
  6. * (C) Copyright 2002,2003, Motorola Inc.
  7. * Xianghua Xiao, (X.Xiao@motorola.com)
  8. *
  9. * (C) Copyright 2002 Scott McNutt <smcnutt@artesyncp.com>
  10. *
  11. * See file CREDITS for list of people who contributed to this
  12. * project.
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License as
  16. * published by the Free Software Foundation; either version 2 of
  17. * the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  27. * MA 02111-1307 USA
  28. */
  29. #include <common.h>
  30. #include <pci.h>
  31. #include <asm/processor.h>
  32. #include <asm/immap_85xx.h>
  33. #include <ioports.h>
  34. #include <spd.h>
  35. #include <flash.h>
  36. extern flash_info_t flash_info[]; /* FLASH chips info */
  37. void local_bus_init (void);
  38. long int fixed_sdram (void);
  39. ulong flash_get_size (ulong base, int banknum);
  40. #ifdef CONFIG_CPM2
  41. /*
  42. * I/O Port configuration table
  43. *
  44. * if conf is 1, then that port pin will be configured at boot time
  45. * according to the five values podr/pdir/ppar/psor/pdat for that entry
  46. */
  47. const iop_conf_t iop_conf_tab[4][32] = {
  48. /* Port A configuration */
  49. { /* conf ppar psor pdir podr pdat */
  50. /* PA31 */ { 1, 1, 1, 0, 0, 0 }, /* FCC1 MII COL */
  51. /* PA30 */ { 1, 1, 1, 0, 0, 0 }, /* FCC1 MII CRS */
  52. /* PA29 */ { 1, 1, 1, 1, 0, 0 }, /* FCC1 MII TX_ER */
  53. /* PA28 */ { 1, 1, 1, 1, 0, 0 }, /* FCC1 MII TX_EN */
  54. /* PA27 */ { 1, 1, 1, 0, 0, 0 }, /* FCC1 MII RX_DV */
  55. /* PA26 */ { 1, 1, 1, 0, 0, 0 }, /* FCC1 MII RX_ER */
  56. /* PA25 */ { 0, 1, 0, 1, 0, 0 }, /* FCC1 ATMTXD[0] */
  57. /* PA24 */ { 0, 1, 0, 1, 0, 0 }, /* FCC1 ATMTXD[1] */
  58. /* PA23 */ { 0, 1, 0, 1, 0, 0 }, /* FCC1 ATMTXD[2] */
  59. /* PA22 */ { 0, 1, 0, 1, 0, 0 }, /* FCC1 ATMTXD[3] */
  60. /* PA21 */ { 1, 1, 0, 1, 0, 0 }, /* FCC1 MII TxD[3] */
  61. /* PA20 */ { 1, 1, 0, 1, 0, 0 }, /* FCC1 MII TxD[2] */
  62. /* PA19 */ { 1, 1, 0, 1, 0, 0 }, /* FCC1 MII TxD[1] */
  63. /* PA18 */ { 1, 1, 0, 1, 0, 0 }, /* FCC1 MII TxD[0] */
  64. /* PA17 */ { 1, 1, 0, 0, 0, 0 }, /* FCC1 MII RxD[0] */
  65. /* PA16 */ { 1, 1, 0, 0, 0, 0 }, /* FCC1 MII RxD[1] */
  66. /* PA15 */ { 1, 1, 0, 0, 0, 0 }, /* FCC1 MII RxD[2] */
  67. /* PA14 */ { 1, 1, 0, 0, 0, 0 }, /* FCC1 MII RxD[3] */
  68. /* PA13 */ { 0, 1, 0, 0, 0, 0 }, /* FCC1 ATMRXD[3] */
  69. /* PA12 */ { 0, 1, 0, 0, 0, 0 }, /* FCC1 ATMRXD[2] */
  70. /* PA11 */ { 0, 1, 0, 0, 0, 0 }, /* FCC1 ATMRXD[1] */
  71. /* PA10 */ { 0, 1, 0, 0, 0, 0 }, /* FCC1 ATMRXD[0] */
  72. /* PA9 */ { 0, 1, 1, 1, 0, 0 }, /* FCC1 L1TXD */
  73. /* PA8 */ { 0, 1, 1, 0, 0, 0 }, /* FCC1 L1RXD */
  74. /* PA7 */ { 0, 0, 0, 1, 0, 0 }, /* PA7 */
  75. /* PA6 */ { 0, 1, 1, 1, 0, 0 }, /* TDM A1 L1RSYNC */
  76. /* PA5 */ { 0, 0, 0, 1, 0, 0 }, /* PA5 */
  77. /* PA4 */ { 0, 0, 0, 1, 0, 0 }, /* PA4 */
  78. /* PA3 */ { 0, 0, 0, 1, 0, 0 }, /* PA3 */
  79. /* PA2 */ { 0, 0, 0, 1, 0, 0 }, /* PA2 */
  80. /* PA1 */ { 0, 0, 0, 0, 0, 0 }, /* FREERUN */
  81. /* PA0 */ { 0, 0, 0, 1, 0, 0 } /* PA0 */
  82. },
  83. /* Port B configuration */
  84. { /* conf ppar psor pdir podr pdat */
  85. /* PB31 */ { 1, 1, 0, 1, 0, 0 }, /* FCC2 MII TX_ER */
  86. /* PB30 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII RX_DV */
  87. /* PB29 */ { 1, 1, 1, 1, 0, 0 }, /* FCC2 MII TX_EN */
  88. /* PB28 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII RX_ER */
  89. /* PB27 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII COL */
  90. /* PB26 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII CRS */
  91. /* PB25 */ { 1, 1, 0, 1, 0, 0 }, /* FCC2 MII TxD[3] */
  92. /* PB24 */ { 1, 1, 0, 1, 0, 0 }, /* FCC2 MII TxD[2] */
  93. /* PB23 */ { 1, 1, 0, 1, 0, 0 }, /* FCC2 MII TxD[1] */
  94. /* PB22 */ { 1, 1, 0, 1, 0, 0 }, /* FCC2 MII TxD[0] */
  95. /* PB21 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII RxD[0] */
  96. /* PB20 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII RxD[1] */
  97. /* PB19 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII RxD[2] */
  98. /* PB18 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII RxD[3] */
  99. /* PB17 */ { 1, 1, 0, 0, 0, 0 }, /* FCC3:RX_DIV */
  100. /* PB16 */ { 1, 1, 0, 0, 0, 0 }, /* FCC3:RX_ERR */
  101. /* PB15 */ { 1, 1, 0, 1, 0, 0 }, /* FCC3:TX_ERR */
  102. /* PB14 */ { 1, 1, 0, 1, 0, 0 }, /* FCC3:TX_EN */
  103. /* PB13 */ { 1, 1, 0, 0, 0, 0 }, /* FCC3:COL */
  104. /* PB12 */ { 1, 1, 0, 0, 0, 0 }, /* FCC3:CRS */
  105. /* PB11 */ { 1, 1, 0, 0, 0, 0 }, /* FCC3:RXD */
  106. /* PB10 */ { 1, 1, 0, 0, 0, 0 }, /* FCC3:RXD */
  107. /* PB9 */ { 1, 1, 0, 0, 0, 0 }, /* FCC3:RXD */
  108. /* PB8 */ { 1, 1, 0, 0, 0, 0 }, /* FCC3:RXD */
  109. /* PB7 */ { 1, 1, 0, 1, 0, 0 }, /* FCC3:TXD */
  110. /* PB6 */ { 1, 1, 0, 1, 0, 0 }, /* FCC3:TXD */
  111. /* PB5 */ { 1, 1, 0, 1, 0, 0 }, /* FCC3:TXD */
  112. /* PB4 */ { 1, 1, 0, 1, 0, 0 }, /* FCC3:TXD */
  113. /* PB3 */ { 0, 0, 0, 0, 0, 0 }, /* pin doesn't exist */
  114. /* PB2 */ { 0, 0, 0, 0, 0, 0 }, /* pin doesn't exist */
  115. /* PB1 */ { 0, 0, 0, 0, 0, 0 }, /* pin doesn't exist */
  116. /* PB0 */ { 0, 0, 0, 0, 0, 0 } /* pin doesn't exist */
  117. },
  118. /* Port C */
  119. { /* conf ppar psor pdir podr pdat */
  120. /* PC31 */ { 0, 0, 0, 1, 0, 0 }, /* PC31 */
  121. /* PC30 */ { 0, 0, 0, 1, 0, 0 }, /* PC30 */
  122. /* PC29 */ { 0, 1, 1, 0, 0, 0 }, /* SCC1 EN *CLSN */
  123. /* PC28 */ { 0, 0, 0, 1, 0, 0 }, /* PC28 */
  124. /* PC27 */ { 0, 0, 0, 1, 0, 0 }, /* UART Clock in */
  125. /* PC26 */ { 0, 0, 0, 1, 0, 0 }, /* PC26 */
  126. /* PC25 */ { 0, 0, 0, 1, 0, 0 }, /* PC25 */
  127. /* PC24 */ { 0, 0, 0, 1, 0, 0 }, /* PC24 */
  128. /* PC23 */ { 0, 1, 0, 1, 0, 0 }, /* ATMTFCLK */
  129. /* PC22 */ { 0, 1, 0, 0, 0, 0 }, /* ATMRFCLK */
  130. /* PC21 */ { 1, 1, 0, 0, 0, 0 }, /* SCC1 EN RXCLK */
  131. /* PC20 */ { 1, 1, 0, 0, 0, 0 }, /* SCC1 EN TXCLK */
  132. /* PC19 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII RX_CLK CLK13 */
  133. /* PC18 */ { 1, 1, 0, 0, 0, 0 }, /* FCC Tx Clock (CLK14) */
  134. /* PC17 */ { 1, 1, 0, 0, 0, 0 }, /* PC17 */
  135. /* PC16 */ { 1, 1, 0, 0, 0, 0 }, /* FCC Tx Clock (CLK16) */
  136. /* PC15 */ { 0, 1, 0, 0, 0, 0 }, /* PC15 */
  137. /* PC14 */ { 0, 1, 0, 0, 0, 0 }, /* SCC1 EN *CD */
  138. /* PC13 */ { 0, 1, 0, 0, 0, 0 }, /* PC13 */
  139. /* PC12 */ { 0, 1, 0, 1, 0, 0 }, /* PC12 */
  140. /* PC11 */ { 0, 0, 0, 1, 0, 0 }, /* LXT971 transmit control */
  141. /* PC10 */ { 0, 0, 0, 1, 0, 0 }, /* FETHMDC */
  142. /* PC9 */ { 0, 0, 0, 0, 0, 0 }, /* FETHMDIO */
  143. /* PC8 */ { 0, 0, 0, 1, 0, 0 }, /* PC8 */
  144. /* PC7 */ { 0, 0, 0, 1, 0, 0 }, /* PC7 */
  145. /* PC6 */ { 0, 0, 0, 1, 0, 0 }, /* PC6 */
  146. /* PC5 */ { 0, 0, 0, 1, 0, 0 }, /* PC5 */
  147. /* PC4 */ { 0, 0, 0, 1, 0, 0 }, /* PC4 */
  148. /* PC3 */ { 0, 0, 0, 1, 0, 0 }, /* PC3 */
  149. /* PC2 */ { 0, 0, 0, 1, 0, 1 }, /* ENET FDE */
  150. /* PC1 */ { 0, 0, 0, 1, 0, 0 }, /* ENET DSQE */
  151. /* PC0 */ { 0, 0, 0, 1, 0, 0 }, /* ENET LBK */
  152. },
  153. /* Port D */
  154. { /* conf ppar psor pdir podr pdat */
  155. /* PD31 */ { 1, 1, 0, 0, 0, 0 }, /* SCC1 EN RxD */
  156. /* PD30 */ { 1, 1, 1, 1, 0, 0 }, /* SCC1 EN TxD */
  157. /* PD29 */ { 1, 1, 0, 1, 0, 0 }, /* SCC1 EN TENA */
  158. /* PD28 */ { 1, 1, 0, 0, 0, 0 }, /* PD28 */
  159. /* PD27 */ { 1, 1, 0, 1, 0, 0 }, /* PD27 */
  160. /* PD26 */ { 1, 1, 0, 1, 0, 0 }, /* PD26 */
  161. /* PD25 */ { 0, 0, 0, 1, 0, 0 }, /* PD25 */
  162. /* PD24 */ { 0, 0, 0, 1, 0, 0 }, /* PD24 */
  163. /* PD23 */ { 0, 0, 0, 1, 0, 0 }, /* PD23 */
  164. /* PD22 */ { 0, 0, 0, 1, 0, 0 }, /* PD22 */
  165. /* PD21 */ { 0, 0, 0, 1, 0, 0 }, /* PD21 */
  166. /* PD20 */ { 0, 0, 0, 1, 0, 0 }, /* PD20 */
  167. /* PD19 */ { 0, 0, 0, 1, 0, 0 }, /* PD19 */
  168. /* PD18 */ { 0, 0, 0, 1, 0, 0 }, /* PD18 */
  169. /* PD17 */ { 0, 1, 0, 0, 0, 0 }, /* FCC1 ATMRXPRTY */
  170. /* PD16 */ { 0, 1, 0, 1, 0, 0 }, /* FCC1 ATMTXPRTY */
  171. /* PD15 */ { 0, 1, 1, 0, 1, 0 }, /* I2C SDA */
  172. /* PD14 */ { 0, 0, 0, 1, 0, 0 }, /* LED */
  173. /* PD13 */ { 0, 0, 0, 0, 0, 0 }, /* PD13 */
  174. /* PD12 */ { 0, 0, 0, 0, 0, 0 }, /* PD12 */
  175. /* PD11 */ { 0, 0, 0, 0, 0, 0 }, /* PD11 */
  176. /* PD10 */ { 0, 0, 0, 0, 0, 0 }, /* PD10 */
  177. /* PD9 */ { 0, 1, 0, 1, 0, 0 }, /* SMC1 TXD */
  178. /* PD8 */ { 0, 1, 0, 0, 0, 0 }, /* SMC1 RXD */
  179. /* PD7 */ { 0, 0, 0, 1, 0, 1 }, /* PD7 */
  180. /* PD6 */ { 0, 0, 0, 1, 0, 1 }, /* PD6 */
  181. /* PD5 */ { 0, 0, 0, 1, 0, 1 }, /* PD5 */
  182. /* PD4 */ { 0, 0, 0, 1, 0, 1 }, /* PD4 */
  183. /* PD3 */ { 0, 0, 0, 0, 0, 0 }, /* pin doesn't exist */
  184. /* PD2 */ { 0, 0, 0, 0, 0, 0 }, /* pin doesn't exist */
  185. /* PD1 */ { 0, 0, 0, 0, 0, 0 }, /* pin doesn't exist */
  186. /* PD0 */ { 0, 0, 0, 0, 0, 0 } /* pin doesn't exist */
  187. }
  188. };
  189. #endif /* CONFIG_CPM2 */
  190. #define CASL_STRING1 "casl=xx"
  191. #define CASL_STRING2 "casl="
  192. static const int casl_table[] = { 20, 25, 30 };
  193. #define N_CASL (sizeof(casl_table) / sizeof(casl_table[0]))
  194. int cas_latency(void)
  195. {
  196. char *s = getenv("serial#");
  197. int casl;
  198. int val;
  199. int i;
  200. casl = CONFIG_DDR_DEFAULT_CL;
  201. if (s != NULL) {
  202. if (strncmp(s + strlen(s) - strlen(CASL_STRING1), CASL_STRING2,
  203. strlen(CASL_STRING2)) == 0) {
  204. val = simple_strtoul(s + strlen(s) - 2, NULL, 10);
  205. for (i=0; i<N_CASL; ++i) {
  206. if (val == casl_table[i]) {
  207. return val;
  208. }
  209. }
  210. }
  211. }
  212. return casl;
  213. }
  214. int checkboard (void)
  215. {
  216. char *s = getenv("serial#");
  217. printf("Board: %s", CONFIG_BOARDNAME);
  218. if (s != NULL) {
  219. puts(", serial# ");
  220. puts(s);
  221. }
  222. putc('\n');
  223. #ifdef CONFIG_PCI
  224. printf ("PCI1: 32 bit, %d MHz (compiled)\n",
  225. CONFIG_SYS_CLK_FREQ / 1000000);
  226. #else
  227. printf ("PCI1: disabled\n");
  228. #endif
  229. /*
  230. * Initialize local bus.
  231. */
  232. local_bus_init ();
  233. return 0;
  234. }
  235. int misc_init_r (void)
  236. {
  237. DECLARE_GLOBAL_DATA_PTR;
  238. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  239. volatile ccsr_lbc_t *memctl = &immap->im_lbc;
  240. /*
  241. * Adjust flash start and offset to detected values
  242. */
  243. gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
  244. gd->bd->bi_flashoffset = 0;
  245. /*
  246. * Check if boot FLASH isn't max size
  247. */
  248. if (gd->bd->bi_flashsize < (0 - CFG_FLASH0)) {
  249. memctl->or0 = gd->bd->bi_flashstart | (CFG_OR0_PRELIM & 0x00007fff);
  250. memctl->br0 = gd->bd->bi_flashstart | (CFG_BR0_PRELIM & 0x00007fff);
  251. /*
  252. * Re-check to get correct base address
  253. */
  254. flash_get_size(gd->bd->bi_flashstart, CFG_MAX_FLASH_BANKS - 1);
  255. }
  256. /*
  257. * Check if only one FLASH bank is available
  258. */
  259. if (gd->bd->bi_flashsize != CFG_MAX_FLASH_BANKS * (0 - CFG_FLASH0)) {
  260. memctl->or1 = 0;
  261. memctl->br1 = 0;
  262. /*
  263. * Re-do flash protection upon new addresses
  264. */
  265. flash_protect (FLAG_PROTECT_CLEAR,
  266. gd->bd->bi_flashstart, 0xffffffff,
  267. &flash_info[CFG_MAX_FLASH_BANKS - 1]);
  268. /* Monitor protection ON by default */
  269. flash_protect (FLAG_PROTECT_SET,
  270. CFG_MONITOR_BASE, 0xffffffff,
  271. &flash_info[CFG_MAX_FLASH_BANKS - 1]);
  272. /* Environment protection ON by default */
  273. flash_protect (FLAG_PROTECT_SET,
  274. CFG_ENV_ADDR,
  275. CFG_ENV_ADDR + CFG_ENV_SECT_SIZE - 1,
  276. &flash_info[CFG_MAX_FLASH_BANKS - 1]);
  277. /* Redundant environment protection ON by default */
  278. flash_protect (FLAG_PROTECT_SET,
  279. CFG_ENV_ADDR_REDUND,
  280. CFG_ENV_ADDR_REDUND + CFG_ENV_SIZE_REDUND - 1,
  281. &flash_info[CFG_MAX_FLASH_BANKS - 1]);
  282. }
  283. return 0;
  284. }
  285. /*
  286. * Initialize Local Bus
  287. */
  288. void local_bus_init (void)
  289. {
  290. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  291. volatile ccsr_gur_t *gur = &immap->im_gur;
  292. volatile ccsr_lbc_t *lbc = &immap->im_lbc;
  293. uint clkdiv;
  294. uint lbc_hz;
  295. sys_info_t sysinfo;
  296. /*
  297. * Errata LBC11.
  298. * Fix Local Bus clock glitch when DLL is enabled.
  299. *
  300. * If localbus freq is < 66Mhz, DLL bypass mode must be used.
  301. * If localbus freq is > 133Mhz, DLL can be safely enabled.
  302. * Between 66 and 133, the DLL is enabled with an override workaround.
  303. */
  304. get_sys_info (&sysinfo);
  305. clkdiv = lbc->lcrr & 0x0f;
  306. lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
  307. if (lbc_hz < 66) {
  308. lbc->lcrr = CFG_LBC_LCRR | 0x80000000; /* DLL Bypass */
  309. lbc->ltedr = 0xa4c80000; /* DK: !!! */
  310. } else if (lbc_hz >= 133) {
  311. lbc->lcrr = CFG_LBC_LCRR & (~0x80000000); /* DLL Enabled */
  312. } else {
  313. /*
  314. * On REV1 boards, need to change CLKDIV before enable DLL.
  315. * Default CLKDIV is 8, change it to 4 temporarily.
  316. */
  317. uint pvr = get_pvr ();
  318. uint temp_lbcdll = 0;
  319. if (pvr == PVR_85xx_REV1) {
  320. /* FIXME: Justify the high bit here. */
  321. lbc->lcrr = 0x10000004;
  322. }
  323. lbc->lcrr = CFG_LBC_LCRR & (~0x80000000); /* DLL Enabled */
  324. udelay (200);
  325. /*
  326. * Sample LBC DLL ctrl reg, upshift it to set the
  327. * override bits.
  328. */
  329. temp_lbcdll = gur->lbcdllcr;
  330. gur->lbcdllcr = (((temp_lbcdll & 0xff) << 16) | 0x80000000);
  331. asm ("sync;isync;msync");
  332. }
  333. }
  334. #if defined(CONFIG_PCI)
  335. /*
  336. * Initialize PCI Devices, report devices found.
  337. */
  338. #ifndef CONFIG_PCI_PNP
  339. static struct pci_config_table pci_mpc85xxads_config_table[] = {
  340. {PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  341. PCI_IDSEL_NUMBER, PCI_ANY_ID,
  342. pci_cfgfunc_config_device, {PCI_ENET0_IOADDR,
  343. PCI_ENET0_MEMADDR,
  344. PCI_COMMAND_MEMORY |
  345. PCI_COMMAND_MASTER}},
  346. {}
  347. };
  348. #endif
  349. static struct pci_controller hose = {
  350. #ifndef CONFIG_PCI_PNP
  351. config_table:pci_mpc85xxads_config_table,
  352. #endif
  353. };
  354. #endif /* CONFIG_PCI */
  355. void pci_init_board (void)
  356. {
  357. #ifdef CONFIG_PCI
  358. extern void pci_mpc85xx_init (struct pci_controller *hose);
  359. pci_mpc85xx_init (&hose);
  360. #endif /* CONFIG_PCI */
  361. }