sequoia.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. /*
  2. * (C) Copyright 2006-2009
  3. * Stefan Roese, DENX Software Engineering, sr@denx.de.
  4. *
  5. * (C) Copyright 2006
  6. * Jacqueline Pira-Ferriol, AMCC/IBM, jpira-ferriol@fr.ibm.com
  7. * Alain Saurel, AMCC/IBM, alain.saurel@fr.ibm.com
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #include <common.h>
  25. #include <libfdt.h>
  26. #include <fdt_support.h>
  27. #include <asm/ppc4xx.h>
  28. #include <asm/ppc4xx-gpio.h>
  29. #include <asm/processor.h>
  30. #include <asm/io.h>
  31. #include <asm/bitops.h>
  32. DECLARE_GLOBAL_DATA_PTR;
  33. #if !defined(CONFIG_SYS_NO_FLASH)
  34. extern flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS]; /* info for FLASH chips */
  35. #endif
  36. extern void __ft_board_setup(void *blob, bd_t *bd);
  37. ulong flash_get_size(ulong base, int banknum);
  38. static inline u32 get_async_pci_freq(void)
  39. {
  40. if (in_8((void *)(CONFIG_SYS_BCSR_BASE + 5)) &
  41. CONFIG_SYS_BCSR5_PCI66EN)
  42. return 66666666;
  43. else
  44. return 33333333;
  45. }
  46. int board_early_init_f(void)
  47. {
  48. u32 sdr0_cust0;
  49. u32 sdr0_pfc1, sdr0_pfc2;
  50. u32 reg;
  51. mtdcr(EBC0_CFGADDR, EBC0_CFG);
  52. mtdcr(EBC0_CFGDATA, 0xb8400000);
  53. /*
  54. * Setup the interrupt controller polarities, triggers, etc.
  55. */
  56. mtdcr(UIC0SR, 0xffffffff); /* clear all */
  57. mtdcr(UIC0ER, 0x00000000); /* disable all */
  58. mtdcr(UIC0CR, 0x00000005); /* ATI & UIC1 crit are critical */
  59. mtdcr(UIC0PR, 0xfffff7ff); /* per ref-board manual */
  60. mtdcr(UIC0TR, 0x00000000); /* per ref-board manual */
  61. mtdcr(UIC0VR, 0x00000000); /* int31 highest, base=0x000 */
  62. mtdcr(UIC0SR, 0xffffffff); /* clear all */
  63. mtdcr(UIC1SR, 0xffffffff); /* clear all */
  64. mtdcr(UIC1ER, 0x00000000); /* disable all */
  65. mtdcr(UIC1CR, 0x00000000); /* all non-critical */
  66. mtdcr(UIC1PR, 0xffffffff); /* per ref-board manual */
  67. mtdcr(UIC1TR, 0x00000000); /* per ref-board manual */
  68. mtdcr(UIC1VR, 0x00000000); /* int31 highest, base=0x000 */
  69. mtdcr(UIC1SR, 0xffffffff); /* clear all */
  70. mtdcr(UIC2SR, 0xffffffff); /* clear all */
  71. mtdcr(UIC2ER, 0x00000000); /* disable all */
  72. mtdcr(UIC2CR, 0x00000000); /* all non-critical */
  73. mtdcr(UIC2PR, 0xffffffff); /* per ref-board manual */
  74. mtdcr(UIC2TR, 0x00000000); /* per ref-board manual */
  75. mtdcr(UIC2VR, 0x00000000); /* int31 highest, base=0x000 */
  76. mtdcr(UIC2SR, 0xffffffff); /* clear all */
  77. /* Check and reconfigure the PCI sync clock if necessary */
  78. ppc4xx_pci_sync_clock_config(get_async_pci_freq());
  79. /* 50MHz tmrclk */
  80. out_8((u8 *) CONFIG_SYS_BCSR_BASE + 0x04, 0x00);
  81. /* clear write protects */
  82. out_8((u8 *) CONFIG_SYS_BCSR_BASE + 0x07, 0x00);
  83. /* enable Ethernet */
  84. out_8((u8 *) CONFIG_SYS_BCSR_BASE + 0x08, 0x00);
  85. /* enable USB device */
  86. out_8((u8 *) CONFIG_SYS_BCSR_BASE + 0x09, 0x20);
  87. /* select Ethernet (and optionally IIC1) pins */
  88. mfsdr(SDR0_PFC1, sdr0_pfc1);
  89. sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_SELECT_MASK) |
  90. SDR0_PFC1_SELECT_CONFIG_4;
  91. #ifdef CONFIG_I2C_MULTI_BUS
  92. sdr0_pfc1 |= ((sdr0_pfc1 & ~SDR0_PFC1_SIS_MASK) | SDR0_PFC1_SIS_IIC1_SEL);
  93. #endif
  94. /* Two UARTs, so we need 4-pin mode. Also, we want CTS/RTS mode. */
  95. sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_U0IM_MASK) | SDR0_PFC1_U0IM_4PINS;
  96. sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_U0ME_MASK) | SDR0_PFC1_U0ME_CTS_RTS;
  97. sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_U1ME_MASK) | SDR0_PFC1_U1ME_CTS_RTS;
  98. mfsdr(SDR0_PFC2, sdr0_pfc2);
  99. sdr0_pfc2 = (sdr0_pfc2 & ~SDR0_PFC2_SELECT_MASK) |
  100. SDR0_PFC2_SELECT_CONFIG_4;
  101. mtsdr(SDR0_PFC2, sdr0_pfc2);
  102. mtsdr(SDR0_PFC1, sdr0_pfc1);
  103. /* PCI arbiter enabled */
  104. mfsdr(SDR0_PCI0, reg);
  105. mtsdr(SDR0_PCI0, 0x80000000 | reg);
  106. /* setup NAND FLASH */
  107. mfsdr(SDR0_CUST0, sdr0_cust0);
  108. sdr0_cust0 = SDR0_CUST0_MUX_NDFC_SEL |
  109. SDR0_CUST0_NDFC_ENABLE |
  110. SDR0_CUST0_NDFC_BW_8_BIT |
  111. SDR0_CUST0_NDFC_ARE_MASK |
  112. (0x80000000 >> (28 + CONFIG_SYS_NAND_CS));
  113. mtsdr(SDR0_CUST0, sdr0_cust0);
  114. return 0;
  115. }
  116. int misc_init_r(void)
  117. {
  118. #if !defined(CONFIG_SYS_NO_FLASH)
  119. uint pbcr;
  120. int size_val = 0;
  121. #endif
  122. #ifdef CONFIG_440EPX
  123. unsigned long usb2d0cr = 0;
  124. unsigned long usb2phy0cr, usb2h0cr = 0;
  125. unsigned long sdr0_pfc1;
  126. char *act = getenv("usbact");
  127. #endif
  128. u32 reg;
  129. #if !defined(CONFIG_SYS_NO_FLASH)
  130. /* Re-do flash sizing to get full correct info */
  131. /* adjust flash start and offset */
  132. gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
  133. gd->bd->bi_flashoffset = 0;
  134. #if defined(CONFIG_NAND_U_BOOT) || defined(CONFIG_NAND_SPL)
  135. mtdcr(EBC0_CFGADDR, PB3CR);
  136. #else
  137. mtdcr(EBC0_CFGADDR, PB0CR);
  138. #endif
  139. pbcr = mfdcr(EBC0_CFGDATA);
  140. size_val = ffs(gd->bd->bi_flashsize) - 21;
  141. pbcr = (pbcr & 0x0001ffff) | gd->bd->bi_flashstart | (size_val << 17);
  142. #if defined(CONFIG_NAND_U_BOOT) || defined(CONFIG_NAND_SPL)
  143. mtdcr(EBC0_CFGADDR, PB3CR);
  144. #else
  145. mtdcr(EBC0_CFGADDR, PB0CR);
  146. #endif
  147. mtdcr(EBC0_CFGDATA, pbcr);
  148. /*
  149. * Re-check to get correct base address
  150. */
  151. flash_get_size(gd->bd->bi_flashstart, 0);
  152. #ifdef CONFIG_ENV_IS_IN_FLASH
  153. /* Monitor protection ON by default */
  154. (void)flash_protect(FLAG_PROTECT_SET,
  155. -CONFIG_SYS_MONITOR_LEN,
  156. 0xffffffff,
  157. &flash_info[0]);
  158. /* Env protection ON by default */
  159. (void)flash_protect(FLAG_PROTECT_SET,
  160. CONFIG_ENV_ADDR_REDUND,
  161. CONFIG_ENV_ADDR_REDUND + 2*CONFIG_ENV_SECT_SIZE - 1,
  162. &flash_info[0]);
  163. #endif
  164. #endif /* CONFIG_SYS_NO_FLASH */
  165. /*
  166. * USB suff...
  167. */
  168. #ifdef CONFIG_440EPX
  169. if (act == NULL || strcmp(act, "hostdev") == 0) {
  170. /* SDR Setting */
  171. mfsdr(SDR0_PFC1, sdr0_pfc1);
  172. mfsdr(SDR0_USB2D0CR, usb2d0cr);
  173. mfsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  174. mfsdr(SDR0_USB2H0CR, usb2h0cr);
  175. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_XOCLK_MASK;
  176. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL;
  177. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_WDINT_MASK;
  178. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_WDINT_16BIT_30MHZ;
  179. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DVBUS_MASK;
  180. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PURDIS;
  181. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DWNSTR_MASK;
  182. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_HOST;
  183. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_UTMICN_MASK;
  184. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_HOST;
  185. /*
  186. * An 8-bit/60MHz interface is the only possible alternative
  187. * when connecting the Device to the PHY
  188. */
  189. usb2h0cr = usb2h0cr &~SDR0_USB2H0CR_WDINT_MASK;
  190. usb2h0cr = usb2h0cr | SDR0_USB2H0CR_WDINT_16BIT_30MHZ;
  191. /*
  192. * To enable the USB 2.0 Device function
  193. * through the UTMI interface
  194. */
  195. usb2d0cr = usb2d0cr &~SDR0_USB2D0CR_USB2DEV_EBC_SEL_MASK;
  196. usb2d0cr = usb2d0cr | SDR0_USB2D0CR_USB2DEV_SELECTION;
  197. sdr0_pfc1 = sdr0_pfc1 &~SDR0_PFC1_UES_MASK;
  198. sdr0_pfc1 = sdr0_pfc1 | SDR0_PFC1_UES_USB2D_SEL;
  199. mtsdr(SDR0_PFC1, sdr0_pfc1);
  200. mtsdr(SDR0_USB2D0CR, usb2d0cr);
  201. mtsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  202. mtsdr(SDR0_USB2H0CR, usb2h0cr);
  203. /*clear resets*/
  204. udelay (1000);
  205. mtsdr(SDR0_SRST1, 0x00000000);
  206. udelay (1000);
  207. mtsdr(SDR0_SRST0, 0x00000000);
  208. printf("USB: Host(int phy) Device(ext phy)\n");
  209. } else if (strcmp(act, "dev") == 0) {
  210. /*-------------------PATCH-------------------------------*/
  211. mfsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  212. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_XOCLK_MASK;
  213. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL;
  214. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DVBUS_MASK;
  215. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PURDIS;
  216. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DWNSTR_MASK;
  217. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_HOST;
  218. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_UTMICN_MASK;
  219. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_HOST;
  220. mtsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  221. udelay (1000);
  222. mtsdr(SDR0_SRST1, 0x672c6000);
  223. udelay (1000);
  224. mtsdr(SDR0_SRST0, 0x00000080);
  225. udelay (1000);
  226. mtsdr(SDR0_SRST1, 0x60206000);
  227. *(unsigned int *)(0xe0000350) = 0x00000001;
  228. udelay (1000);
  229. mtsdr(SDR0_SRST1, 0x60306000);
  230. /*-------------------PATCH-------------------------------*/
  231. /* SDR Setting */
  232. mfsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  233. mfsdr(SDR0_USB2H0CR, usb2h0cr);
  234. mfsdr(SDR0_USB2D0CR, usb2d0cr);
  235. mfsdr(SDR0_PFC1, sdr0_pfc1);
  236. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_XOCLK_MASK;
  237. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL;
  238. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_WDINT_MASK;
  239. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_WDINT_8BIT_60MHZ;
  240. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DVBUS_MASK;
  241. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PUREN;
  242. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DWNSTR_MASK;
  243. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_DEV;
  244. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_UTMICN_MASK;
  245. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_DEV;
  246. usb2h0cr = usb2h0cr &~SDR0_USB2H0CR_WDINT_MASK;
  247. usb2h0cr = usb2h0cr | SDR0_USB2H0CR_WDINT_8BIT_60MHZ;
  248. usb2d0cr = usb2d0cr &~SDR0_USB2D0CR_USB2DEV_EBC_SEL_MASK;
  249. usb2d0cr = usb2d0cr | SDR0_USB2D0CR_EBC_SELECTION;
  250. sdr0_pfc1 = sdr0_pfc1 &~SDR0_PFC1_UES_MASK;
  251. sdr0_pfc1 = sdr0_pfc1 | SDR0_PFC1_UES_EBCHR_SEL;
  252. mtsdr(SDR0_USB2H0CR, usb2h0cr);
  253. mtsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  254. mtsdr(SDR0_USB2D0CR, usb2d0cr);
  255. mtsdr(SDR0_PFC1, sdr0_pfc1);
  256. /* clear resets */
  257. udelay (1000);
  258. mtsdr(SDR0_SRST1, 0x00000000);
  259. udelay (1000);
  260. mtsdr(SDR0_SRST0, 0x00000000);
  261. printf("USB: Device(int phy)\n");
  262. }
  263. #endif /* CONFIG_440EPX */
  264. mfsdr(SDR0_SRST1, reg); /* enable security/kasumi engines */
  265. reg &= ~(SDR0_SRST1_CRYP0 | SDR0_SRST1_KASU0);
  266. mtsdr(SDR0_SRST1, reg);
  267. /*
  268. * Clear PLB4A0_ACR[WRP]
  269. * This fix will make the MAL burst disabling patch for the Linux
  270. * EMAC driver obsolete.
  271. */
  272. reg = mfdcr(PLB4A0_ACR) & ~PLB4Ax_ACR_WRP_MASK;
  273. mtdcr(PLB4A0_ACR, reg);
  274. return 0;
  275. }
  276. int checkboard(void)
  277. {
  278. char *s = getenv("serial#");
  279. u8 rev;
  280. u32 clock = get_async_pci_freq();
  281. #ifdef CONFIG_440EPX
  282. printf("Board: Sequoia - AMCC PPC440EPx Evaluation Board");
  283. #else
  284. printf("Board: Rainier - AMCC PPC440GRx Evaluation Board");
  285. #endif
  286. rev = in_8((void *)(CONFIG_SYS_BCSR_BASE + 0));
  287. printf(", Rev. %X, PCI-Async=%d MHz", rev, clock / 1000000);
  288. if (s != NULL) {
  289. puts(", serial# ");
  290. puts(s);
  291. }
  292. putc('\n');
  293. /*
  294. * Reconfiguration of the PCI sync clock is already done,
  295. * now check again if everything is in range:
  296. */
  297. if (ppc4xx_pci_sync_clock_config(clock)) {
  298. printf("ERROR: PCI clocking incorrect (async=%d "
  299. "sync=%ld)!\n", clock, get_PCI_freq());
  300. }
  301. return (0);
  302. }
  303. #if defined(CONFIG_PCI) && defined(CONFIG_PCI_PNP)
  304. /*
  305. * Assign interrupts to PCI devices.
  306. */
  307. void board_pci_fixup_irq(struct pci_controller *hose, pci_dev_t dev)
  308. {
  309. pci_hose_write_config_byte(hose, dev, PCI_INTERRUPT_LINE, VECNUM_EIRQ2);
  310. }
  311. #endif
  312. #if defined(CONFIG_NAND_U_BOOT) || defined(CONFIG_SYS_RAMBOOT)
  313. /*
  314. * On NAND-booting sequoia, we need to patch the chips select numbers
  315. * in the dtb (CS0 - NAND, CS3 - NOR)
  316. */
  317. void ft_board_setup(void *blob, bd_t *bd)
  318. {
  319. int rc;
  320. int len;
  321. int nodeoffset;
  322. struct fdt_property *prop;
  323. u32 *reg;
  324. char path[32];
  325. /* First do common fdt setup */
  326. __ft_board_setup(blob, bd);
  327. /* And now configure NOR chip select to 3 instead of 0 */
  328. strcpy(path, "/plb/opb/ebc/nor_flash@0,0");
  329. nodeoffset = fdt_path_offset(blob, path);
  330. prop = fdt_get_property_w(blob, nodeoffset, "reg", &len);
  331. if (prop == NULL) {
  332. printf("Unable to update NOR chip select for NAND booting\n");
  333. return;
  334. }
  335. reg = (u32 *)&prop->data[0];
  336. reg[0] = 3;
  337. rc = fdt_find_and_setprop(blob, path, "reg", reg, 3 * sizeof(u32), 1);
  338. if (rc) {
  339. printf("Unable to update property NOR mappings, err=%s\n",
  340. fdt_strerror(rc));
  341. return;
  342. }
  343. /* And now configure NAND chip select to 0 instead of 3 */
  344. strcpy(path, "/plb/opb/ebc/ndfc@3,0");
  345. nodeoffset = fdt_path_offset(blob, path);
  346. prop = fdt_get_property_w(blob, nodeoffset, "reg", &len);
  347. if (prop == NULL) {
  348. printf("Unable to update NDFC chip select for NAND booting\n");
  349. return;
  350. }
  351. reg = (u32 *)&prop->data[0];
  352. reg[0] = 0;
  353. rc = fdt_find_and_setprop(blob, path, "reg", reg, 3 * sizeof(u32), 1);
  354. if (rc) {
  355. printf("Unable to update property NDFC mappings, err=%s\n",
  356. fdt_strerror(rc));
  357. return;
  358. }
  359. }
  360. #endif /* CONFIG_NAND_U_BOOT */