sequoia.c 12 KB

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