sequoia.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  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. defined(CONFIG_SYS_RAMBOOT)
  136. mtdcr(EBC0_CFGADDR, PB3CR);
  137. #else
  138. mtdcr(EBC0_CFGADDR, PB0CR);
  139. #endif
  140. pbcr = mfdcr(EBC0_CFGDATA);
  141. size_val = ffs(gd->bd->bi_flashsize) - 21;
  142. pbcr = (pbcr & 0x0001ffff) | gd->bd->bi_flashstart | (size_val << 17);
  143. #if defined(CONFIG_NAND_U_BOOT) || defined(CONFIG_NAND_SPL) || \
  144. defined(CONFIG_SYS_RAMBOOT)
  145. mtdcr(EBC0_CFGADDR, PB3CR);
  146. #else
  147. mtdcr(EBC0_CFGADDR, PB0CR);
  148. #endif
  149. mtdcr(EBC0_CFGDATA, pbcr);
  150. /*
  151. * Re-check to get correct base address
  152. */
  153. flash_get_size(gd->bd->bi_flashstart, 0);
  154. #ifdef CONFIG_ENV_IS_IN_FLASH
  155. /* Monitor protection ON by default */
  156. (void)flash_protect(FLAG_PROTECT_SET,
  157. -CONFIG_SYS_MONITOR_LEN,
  158. 0xffffffff,
  159. &flash_info[0]);
  160. /* Env protection ON by default */
  161. (void)flash_protect(FLAG_PROTECT_SET,
  162. CONFIG_ENV_ADDR_REDUND,
  163. CONFIG_ENV_ADDR_REDUND + 2*CONFIG_ENV_SECT_SIZE - 1,
  164. &flash_info[0]);
  165. #endif
  166. #endif /* CONFIG_SYS_NO_FLASH */
  167. /*
  168. * USB suff...
  169. */
  170. #ifdef CONFIG_440EPX
  171. if (act == NULL || strcmp(act, "hostdev") == 0) {
  172. /* SDR Setting */
  173. mfsdr(SDR0_PFC1, sdr0_pfc1);
  174. mfsdr(SDR0_USB2D0CR, usb2d0cr);
  175. mfsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  176. mfsdr(SDR0_USB2H0CR, usb2h0cr);
  177. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_XOCLK_MASK;
  178. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL;
  179. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_WDINT_MASK;
  180. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_WDINT_16BIT_30MHZ;
  181. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DVBUS_MASK;
  182. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PURDIS;
  183. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DWNSTR_MASK;
  184. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_HOST;
  185. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_UTMICN_MASK;
  186. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_HOST;
  187. /*
  188. * An 8-bit/60MHz interface is the only possible alternative
  189. * when connecting the Device to the PHY
  190. */
  191. usb2h0cr = usb2h0cr &~SDR0_USB2H0CR_WDINT_MASK;
  192. usb2h0cr = usb2h0cr | SDR0_USB2H0CR_WDINT_16BIT_30MHZ;
  193. /*
  194. * To enable the USB 2.0 Device function
  195. * through the UTMI interface
  196. */
  197. usb2d0cr = usb2d0cr &~SDR0_USB2D0CR_USB2DEV_EBC_SEL_MASK;
  198. usb2d0cr = usb2d0cr | SDR0_USB2D0CR_USB2DEV_SELECTION;
  199. sdr0_pfc1 = sdr0_pfc1 &~SDR0_PFC1_UES_MASK;
  200. sdr0_pfc1 = sdr0_pfc1 | SDR0_PFC1_UES_USB2D_SEL;
  201. mtsdr(SDR0_PFC1, sdr0_pfc1);
  202. mtsdr(SDR0_USB2D0CR, usb2d0cr);
  203. mtsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  204. mtsdr(SDR0_USB2H0CR, usb2h0cr);
  205. /*clear resets*/
  206. udelay (1000);
  207. mtsdr(SDR0_SRST1, 0x00000000);
  208. udelay (1000);
  209. mtsdr(SDR0_SRST0, 0x00000000);
  210. printf("USB: Host(int phy) Device(ext phy)\n");
  211. } else if (strcmp(act, "dev") == 0) {
  212. /*-------------------PATCH-------------------------------*/
  213. mfsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  214. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_XOCLK_MASK;
  215. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL;
  216. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DVBUS_MASK;
  217. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PURDIS;
  218. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DWNSTR_MASK;
  219. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_HOST;
  220. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_UTMICN_MASK;
  221. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_HOST;
  222. mtsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  223. udelay (1000);
  224. mtsdr(SDR0_SRST1, 0x672c6000);
  225. udelay (1000);
  226. mtsdr(SDR0_SRST0, 0x00000080);
  227. udelay (1000);
  228. mtsdr(SDR0_SRST1, 0x60206000);
  229. *(unsigned int *)(0xe0000350) = 0x00000001;
  230. udelay (1000);
  231. mtsdr(SDR0_SRST1, 0x60306000);
  232. /*-------------------PATCH-------------------------------*/
  233. /* SDR Setting */
  234. mfsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  235. mfsdr(SDR0_USB2H0CR, usb2h0cr);
  236. mfsdr(SDR0_USB2D0CR, usb2d0cr);
  237. mfsdr(SDR0_PFC1, sdr0_pfc1);
  238. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_XOCLK_MASK;
  239. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL;
  240. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_WDINT_MASK;
  241. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_WDINT_8BIT_60MHZ;
  242. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DVBUS_MASK;
  243. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PUREN;
  244. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DWNSTR_MASK;
  245. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_DEV;
  246. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_UTMICN_MASK;
  247. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_DEV;
  248. usb2h0cr = usb2h0cr &~SDR0_USB2H0CR_WDINT_MASK;
  249. usb2h0cr = usb2h0cr | SDR0_USB2H0CR_WDINT_8BIT_60MHZ;
  250. usb2d0cr = usb2d0cr &~SDR0_USB2D0CR_USB2DEV_EBC_SEL_MASK;
  251. usb2d0cr = usb2d0cr | SDR0_USB2D0CR_EBC_SELECTION;
  252. sdr0_pfc1 = sdr0_pfc1 &~SDR0_PFC1_UES_MASK;
  253. sdr0_pfc1 = sdr0_pfc1 | SDR0_PFC1_UES_EBCHR_SEL;
  254. mtsdr(SDR0_USB2H0CR, usb2h0cr);
  255. mtsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  256. mtsdr(SDR0_USB2D0CR, usb2d0cr);
  257. mtsdr(SDR0_PFC1, sdr0_pfc1);
  258. /* clear resets */
  259. udelay (1000);
  260. mtsdr(SDR0_SRST1, 0x00000000);
  261. udelay (1000);
  262. mtsdr(SDR0_SRST0, 0x00000000);
  263. printf("USB: Device(int phy)\n");
  264. }
  265. #endif /* CONFIG_440EPX */
  266. mfsdr(SDR0_SRST1, reg); /* enable security/kasumi engines */
  267. reg &= ~(SDR0_SRST1_CRYP0 | SDR0_SRST1_KASU0);
  268. mtsdr(SDR0_SRST1, reg);
  269. /*
  270. * Clear PLB4A0_ACR[WRP]
  271. * This fix will make the MAL burst disabling patch for the Linux
  272. * EMAC driver obsolete.
  273. */
  274. reg = mfdcr(PLB4A0_ACR) & ~PLB4Ax_ACR_WRP_MASK;
  275. mtdcr(PLB4A0_ACR, reg);
  276. return 0;
  277. }
  278. int checkboard(void)
  279. {
  280. char *s = getenv("serial#");
  281. u8 rev;
  282. u32 clock = get_async_pci_freq();
  283. #ifdef CONFIG_440EPX
  284. printf("Board: Sequoia - AMCC PPC440EPx Evaluation Board");
  285. #else
  286. printf("Board: Rainier - AMCC PPC440GRx Evaluation Board");
  287. #endif
  288. rev = in_8((void *)(CONFIG_SYS_BCSR_BASE + 0));
  289. printf(", Rev. %X, PCI-Async=%d MHz", rev, clock / 1000000);
  290. if (s != NULL) {
  291. puts(", serial# ");
  292. puts(s);
  293. }
  294. putc('\n');
  295. /*
  296. * Reconfiguration of the PCI sync clock is already done,
  297. * now check again if everything is in range:
  298. */
  299. if (ppc4xx_pci_sync_clock_config(clock)) {
  300. printf("ERROR: PCI clocking incorrect (async=%d "
  301. "sync=%ld)!\n", clock, get_PCI_freq());
  302. }
  303. return (0);
  304. }
  305. #if defined(CONFIG_PCI) && defined(CONFIG_PCI_PNP)
  306. /*
  307. * Assign interrupts to PCI devices.
  308. */
  309. void board_pci_fixup_irq(struct pci_controller *hose, pci_dev_t dev)
  310. {
  311. pci_hose_write_config_byte(hose, dev, PCI_INTERRUPT_LINE, VECNUM_EIRQ2);
  312. }
  313. #endif
  314. #if defined(CONFIG_NAND_U_BOOT) || defined(CONFIG_SYS_RAMBOOT)
  315. /*
  316. * On NAND-booting sequoia, we need to patch the chips select numbers
  317. * in the dtb (CS0 - NAND, CS3 - NOR)
  318. */
  319. void ft_board_setup(void *blob, bd_t *bd)
  320. {
  321. int rc;
  322. int len;
  323. int nodeoffset;
  324. struct fdt_property *prop;
  325. u32 *reg;
  326. char path[32];
  327. /* First do common fdt setup */
  328. __ft_board_setup(blob, bd);
  329. /* And now configure NOR chip select to 3 instead of 0 */
  330. strcpy(path, "/plb/opb/ebc/nor_flash@0,0");
  331. nodeoffset = fdt_path_offset(blob, path);
  332. prop = fdt_get_property_w(blob, nodeoffset, "reg", &len);
  333. if (prop == NULL) {
  334. printf("Unable to update NOR chip select for NAND booting\n");
  335. return;
  336. }
  337. reg = (u32 *)&prop->data[0];
  338. reg[0] = 3;
  339. rc = fdt_find_and_setprop(blob, path, "reg", reg, 3 * sizeof(u32), 1);
  340. if (rc) {
  341. printf("Unable to update property NOR mappings, err=%s\n",
  342. fdt_strerror(rc));
  343. return;
  344. }
  345. /* And now configure NAND chip select to 0 instead of 3 */
  346. strcpy(path, "/plb/opb/ebc/ndfc@3,0");
  347. nodeoffset = fdt_path_offset(blob, path);
  348. prop = fdt_get_property_w(blob, nodeoffset, "reg", &len);
  349. if (prop == NULL) {
  350. printf("Unable to update NDFC chip select for NAND booting\n");
  351. return;
  352. }
  353. reg = (u32 *)&prop->data[0];
  354. reg[0] = 0;
  355. rc = fdt_find_and_setprop(blob, path, "reg", reg, 3 * sizeof(u32), 1);
  356. if (rc) {
  357. printf("Unable to update property NDFC mappings, err=%s\n",
  358. fdt_strerror(rc));
  359. return;
  360. }
  361. }
  362. #endif /* CONFIG_NAND_U_BOOT */