pmc440.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874
  1. /*
  2. * (Cg) Copyright 2007-2008
  3. * Matthias Fuchs, esd gmbh, matthias.fuchs@esd-electronics.com.
  4. * Based on board/amcc/sequoia/sequoia.c
  5. *
  6. * (C) Copyright 2006
  7. * Stefan Roese, DENX Software Engineering, sr@denx.de.
  8. *
  9. * (C) Copyright 2006
  10. * Jacqueline Pira-Ferriol, AMCC/IBM, jpira-ferriol@fr.ibm.com
  11. * Alain Saurel, AMCC/IBM, alain.saurel@fr.ibm.com
  12. *
  13. * SPDX-License-Identifier: GPL-2.0+
  14. */
  15. #include <common.h>
  16. #include <libfdt.h>
  17. #include <fdt_support.h>
  18. #include <asm/ppc440.h>
  19. #include <asm/processor.h>
  20. #include <asm/io.h>
  21. #include <asm/bitops.h>
  22. #include <command.h>
  23. #include <i2c.h>
  24. #ifdef CONFIG_RESET_PHY_R
  25. #include <miiphy.h>
  26. #endif
  27. #include <serial.h>
  28. #include <asm/4xx_pci.h>
  29. #include <usb.h>
  30. #include "fpga.h"
  31. #include "pmc440.h"
  32. DECLARE_GLOBAL_DATA_PTR;
  33. extern flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS]; /* info for FLASH chips */
  34. extern void __ft_board_setup(void *blob, bd_t *bd);
  35. ulong flash_get_size(ulong base, int banknum);
  36. int pci_is_66mhz(void);
  37. int is_monarch(void);
  38. int bootstrap_eeprom_read(unsigned dev_addr, unsigned offset,
  39. uchar *buffer, unsigned cnt);
  40. struct serial_device *default_serial_console(void)
  41. {
  42. uchar buf[4];
  43. ulong delay;
  44. int i;
  45. ulong val;
  46. /*
  47. * Use default console on P4 when strapping jumper
  48. * is installed (bootstrap option != 'H').
  49. */
  50. mfsdr(SDR0_PINSTP, val);
  51. if (((val & 0xf0000000) >> 29) != 7)
  52. return &eserial2_device;
  53. ulong scratchreg = in_be32((void*)GPIO0_ISR3L);
  54. if (!(scratchreg & 0x80)) {
  55. /* mark scratchreg valid */
  56. scratchreg = (scratchreg & 0xffffff00) | 0x80;
  57. i = bootstrap_eeprom_read(CONFIG_SYS_I2C_BOOT_EEPROM_ADDR,
  58. 0x10, buf, 4);
  59. if ((i != -1) && (buf[0] == 0x19) && (buf[1] == 0x75)) {
  60. scratchreg |= buf[2];
  61. /* bringup delay for console */
  62. for (delay=0; delay<(1000 * (ulong)buf[3]); delay++) {
  63. udelay(1000);
  64. }
  65. } else
  66. scratchreg |= 0x01;
  67. out_be32((void*)GPIO0_ISR3L, scratchreg);
  68. }
  69. if (scratchreg & 0x01)
  70. return &eserial2_device;
  71. else
  72. return &eserial1_device;
  73. }
  74. int board_early_init_f(void)
  75. {
  76. u32 sdr0_cust0;
  77. u32 sdr0_pfc1, sdr0_pfc2;
  78. u32 reg;
  79. /* general EBC configuration (disable EBC timeouts) */
  80. mtdcr(EBC0_CFGADDR, EBC0_CFG);
  81. mtdcr(EBC0_CFGDATA, 0xf8400000);
  82. /*
  83. * Setup the GPIO pins
  84. * TODO: setup GPIOs via CONFIG_SYS_4xx_GPIO_TABLE in board's config file
  85. */
  86. out_be32((void *)GPIO0_OR, 0x40000102);
  87. out_be32((void *)GPIO0_TCR, 0x4c90011f);
  88. out_be32((void *)GPIO0_OSRL, 0x28051400);
  89. out_be32((void *)GPIO0_OSRH, 0x55005000);
  90. out_be32((void *)GPIO0_TSRL, 0x08051400);
  91. out_be32((void *)GPIO0_TSRH, 0x55005000);
  92. out_be32((void *)GPIO0_ISR1L, 0x54000000);
  93. out_be32((void *)GPIO0_ISR1H, 0x00000000);
  94. out_be32((void *)GPIO0_ISR2L, 0x44000000);
  95. out_be32((void *)GPIO0_ISR2H, 0x00000100);
  96. out_be32((void *)GPIO0_ISR3L, 0x00000000);
  97. out_be32((void *)GPIO0_ISR3H, 0x00000000);
  98. out_be32((void *)GPIO1_OR, 0x80002408);
  99. out_be32((void *)GPIO1_TCR, 0xd6003c08);
  100. out_be32((void *)GPIO1_OSRL, 0x0a5a0000);
  101. out_be32((void *)GPIO1_OSRH, 0x00000000);
  102. out_be32((void *)GPIO1_TSRL, 0x00000000);
  103. out_be32((void *)GPIO1_TSRH, 0x00000000);
  104. out_be32((void *)GPIO1_ISR1L, 0x00005555);
  105. out_be32((void *)GPIO1_ISR1H, 0x40000000);
  106. out_be32((void *)GPIO1_ISR2L, 0x04010000);
  107. out_be32((void *)GPIO1_ISR2H, 0x00000000);
  108. out_be32((void *)GPIO1_ISR3L, 0x01400000);
  109. out_be32((void *)GPIO1_ISR3H, 0x00000000);
  110. /* patch PLB:PCI divider for 66MHz PCI */
  111. mfcpr(CPR0_SPCID, reg);
  112. if (pci_is_66mhz() && (reg != 0x02000000)) {
  113. mtcpr(CPR0_SPCID, 0x02000000); /* 133MHZ : 2 for 66MHz PCI */
  114. mfcpr(CPR0_ICFG, reg);
  115. reg |= CPR0_ICFG_RLI_MASK;
  116. mtcpr(CPR0_ICFG, reg);
  117. mtspr(SPRN_DBCR0, 0x20000000); /* do chip reset */
  118. }
  119. /*
  120. * Setup the interrupt controller polarities, triggers, etc.
  121. */
  122. mtdcr(UIC0SR, 0xffffffff); /* clear all */
  123. mtdcr(UIC0ER, 0x00000000); /* disable all */
  124. mtdcr(UIC0CR, 0x00000005); /* ATI & UIC1 crit are critical */
  125. mtdcr(UIC0PR, 0xfffff7ef);
  126. mtdcr(UIC0TR, 0x00000000);
  127. mtdcr(UIC0VR, 0x00000000); /* int31 highest, base=0x000 */
  128. mtdcr(UIC0SR, 0xffffffff); /* clear all */
  129. mtdcr(UIC1SR, 0xffffffff); /* clear all */
  130. mtdcr(UIC1ER, 0x00000000); /* disable all */
  131. mtdcr(UIC1CR, 0x00000000); /* all non-critical */
  132. mtdcr(UIC1PR, 0xffffc7f5);
  133. mtdcr(UIC1TR, 0x00000000);
  134. mtdcr(UIC1VR, 0x00000000); /* int31 highest, base=0x000 */
  135. mtdcr(UIC1SR, 0xffffffff); /* clear all */
  136. mtdcr(UIC2SR, 0xffffffff); /* clear all */
  137. mtdcr(UIC2ER, 0x00000000); /* disable all */
  138. mtdcr(UIC2CR, 0x00000000); /* all non-critical */
  139. mtdcr(UIC2PR, 0x27ffffff);
  140. mtdcr(UIC2TR, 0x00000000);
  141. mtdcr(UIC2VR, 0x00000000); /* int31 highest, base=0x000 */
  142. mtdcr(UIC2SR, 0xffffffff); /* clear all */
  143. /* select Ethernet pins */
  144. mfsdr(SDR0_PFC1, sdr0_pfc1);
  145. sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_SELECT_MASK) |
  146. SDR0_PFC1_SELECT_CONFIG_4;
  147. mfsdr(SDR0_PFC2, sdr0_pfc2);
  148. sdr0_pfc2 = (sdr0_pfc2 & ~SDR0_PFC2_SELECT_MASK) |
  149. SDR0_PFC2_SELECT_CONFIG_4;
  150. /* enable 2nd IIC */
  151. sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_SIS_MASK) | SDR0_PFC1_SIS_IIC1_SEL;
  152. mtsdr(SDR0_PFC2, sdr0_pfc2);
  153. mtsdr(SDR0_PFC1, sdr0_pfc1);
  154. /* setup NAND FLASH */
  155. mfsdr(SDR0_CUST0, sdr0_cust0);
  156. sdr0_cust0 = SDR0_CUST0_MUX_NDFC_SEL |
  157. SDR0_CUST0_NDFC_ENABLE |
  158. SDR0_CUST0_NDFC_BW_8_BIT |
  159. SDR0_CUST0_NDFC_ARE_MASK |
  160. (0x80000000 >> (28 + CONFIG_SYS_NAND_CS));
  161. mtsdr(SDR0_CUST0, sdr0_cust0);
  162. return 0;
  163. }
  164. #if defined(CONFIG_MISC_INIT_F)
  165. int misc_init_f(void)
  166. {
  167. struct pci_controller hose;
  168. hose.first_busno = 0;
  169. hose.last_busno = 0;
  170. hose.region_count = 0;
  171. if (getenv("pciearly") && (!is_monarch())) {
  172. printf("PCI: early target init\n");
  173. pci_setup_indirect(&hose, PCIL0_CFGADR, PCIL0_CFGDATA);
  174. pci_target_init(&hose);
  175. }
  176. return 0;
  177. }
  178. #endif
  179. /*
  180. * misc_init_r.
  181. */
  182. int misc_init_r(void)
  183. {
  184. uint pbcr;
  185. int size_val = 0;
  186. u32 reg;
  187. unsigned long usb2d0cr = 0;
  188. unsigned long usb2phy0cr, usb2h0cr = 0;
  189. unsigned long sdr0_pfc1;
  190. unsigned long sdr0_srst0, sdr0_srst1;
  191. char *act = getenv("usbact");
  192. /*
  193. * FLASH stuff...
  194. */
  195. /* Re-do sizing to get full correct info */
  196. /* adjust flash start and offset */
  197. gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
  198. gd->bd->bi_flashoffset = 0;
  199. #if defined(CONFIG_NAND_U_BOOT) || defined(CONFIG_NAND_SPL)
  200. mtdcr(EBC0_CFGADDR, PB2CR);
  201. #else
  202. mtdcr(EBC0_CFGADDR, PB0CR);
  203. #endif
  204. pbcr = mfdcr(EBC0_CFGDATA);
  205. size_val = ffs(gd->bd->bi_flashsize) - 21;
  206. pbcr = (pbcr & 0x0001ffff) | gd->bd->bi_flashstart | (size_val << 17);
  207. #if defined(CONFIG_NAND_U_BOOT) || defined(CONFIG_NAND_SPL)
  208. mtdcr(EBC0_CFGADDR, PB2CR);
  209. #else
  210. mtdcr(EBC0_CFGADDR, PB0CR);
  211. #endif
  212. mtdcr(EBC0_CFGDATA, pbcr);
  213. /*
  214. * Re-check to get correct base address
  215. */
  216. flash_get_size(gd->bd->bi_flashstart, 0);
  217. #ifdef CONFIG_ENV_IS_IN_FLASH
  218. /* Monitor protection ON by default */
  219. (void)flash_protect(FLAG_PROTECT_SET,
  220. -CONFIG_SYS_MONITOR_LEN,
  221. 0xffffffff,
  222. &flash_info[0]);
  223. /* Env protection ON by default */
  224. (void)flash_protect(FLAG_PROTECT_SET,
  225. CONFIG_ENV_ADDR_REDUND,
  226. CONFIG_ENV_ADDR_REDUND + 2*CONFIG_ENV_SECT_SIZE - 1,
  227. &flash_info[0]);
  228. #endif
  229. /*
  230. * USB suff...
  231. */
  232. if ((act == NULL || strcmp(act, "host") == 0) &&
  233. !(in_be32((void*)GPIO0_IR) & GPIO0_USB_PRSNT)){
  234. /* SDR Setting */
  235. mfsdr(SDR0_PFC1, sdr0_pfc1);
  236. mfsdr(SDR0_USB2D0CR, usb2d0cr);
  237. mfsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  238. mfsdr(SDR0_USB2H0CR, usb2h0cr);
  239. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_XOCLK_MASK;
  240. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL;
  241. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_WDINT_MASK;
  242. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_WDINT_16BIT_30MHZ;
  243. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DVBUS_MASK;
  244. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PURDIS;
  245. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DWNSTR_MASK;
  246. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_HOST;
  247. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_UTMICN_MASK;
  248. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_HOST;
  249. /*
  250. * An 8-bit/60MHz interface is the only possible alternative
  251. * when connecting the Device to the PHY
  252. */
  253. usb2h0cr = usb2h0cr &~SDR0_USB2H0CR_WDINT_MASK;
  254. usb2h0cr = usb2h0cr | SDR0_USB2H0CR_WDINT_16BIT_30MHZ;
  255. usb2d0cr = usb2d0cr &~SDR0_USB2D0CR_USB2DEV_EBC_SEL_MASK;
  256. sdr0_pfc1 = sdr0_pfc1 &~SDR0_PFC1_UES_MASK;
  257. mtsdr(SDR0_PFC1, sdr0_pfc1);
  258. mtsdr(SDR0_USB2D0CR, usb2d0cr);
  259. mtsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  260. mtsdr(SDR0_USB2H0CR, usb2h0cr);
  261. /*
  262. * Take USB out of reset:
  263. * -Initial status = all cores are in reset
  264. * -deassert reset to OPB1, P4OPB0, OPB2, PLB42OPB1 OPB2PLB40 cores
  265. * -wait 1 ms
  266. * -deassert reset to PHY
  267. * -wait 1 ms
  268. * -deassert reset to HOST
  269. * -wait 4 ms
  270. * -deassert all other resets
  271. */
  272. mfsdr(SDR0_SRST1, sdr0_srst1);
  273. sdr0_srst1 &= ~(SDR0_SRST1_OPBA1 | \
  274. SDR0_SRST1_P4OPB0 | \
  275. SDR0_SRST1_OPBA2 | \
  276. SDR0_SRST1_PLB42OPB1 | \
  277. SDR0_SRST1_OPB2PLB40);
  278. mtsdr(SDR0_SRST1, sdr0_srst1);
  279. udelay(1000);
  280. mfsdr(SDR0_SRST1, sdr0_srst1);
  281. sdr0_srst1 &= ~SDR0_SRST1_USB20PHY;
  282. mtsdr(SDR0_SRST1, sdr0_srst1);
  283. udelay(1000);
  284. mfsdr(SDR0_SRST0, sdr0_srst0);
  285. sdr0_srst0 &= ~SDR0_SRST0_USB2H;
  286. mtsdr(SDR0_SRST0, sdr0_srst0);
  287. udelay(4000);
  288. /* finally all the other resets */
  289. mtsdr(SDR0_SRST1, 0x00000000);
  290. mtsdr(SDR0_SRST0, 0x00000000);
  291. if (!(in_be32((void*)GPIO0_IR) & GPIO0_USB_PRSNT)) {
  292. /* enable power on USB socket */
  293. out_be32((void*)GPIO1_OR,
  294. in_be32((void*)GPIO1_OR) & ~GPIO1_USB_PWR_N);
  295. }
  296. printf("USB: Host\n");
  297. } else if ((strcmp(act, "dev") == 0) ||
  298. (in_be32((void*)GPIO0_IR) & GPIO0_USB_PRSNT)) {
  299. mfsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  300. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_XOCLK_MASK;
  301. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL;
  302. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DVBUS_MASK;
  303. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PURDIS;
  304. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DWNSTR_MASK;
  305. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_HOST;
  306. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_UTMICN_MASK;
  307. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_HOST;
  308. mtsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  309. udelay (1000);
  310. mtsdr(SDR0_SRST1, 0x672c6000);
  311. udelay (1000);
  312. mtsdr(SDR0_SRST0, 0x00000080);
  313. udelay (1000);
  314. mtsdr(SDR0_SRST1, 0x60206000);
  315. *(unsigned int *)(0xe0000350) = 0x00000001;
  316. udelay (1000);
  317. mtsdr(SDR0_SRST1, 0x60306000);
  318. /* SDR Setting */
  319. mfsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  320. mfsdr(SDR0_USB2H0CR, usb2h0cr);
  321. mfsdr(SDR0_USB2D0CR, usb2d0cr);
  322. mfsdr(SDR0_PFC1, sdr0_pfc1);
  323. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_XOCLK_MASK;
  324. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL;
  325. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_WDINT_MASK;
  326. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_WDINT_8BIT_60MHZ;
  327. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DVBUS_MASK;
  328. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PUREN;
  329. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DWNSTR_MASK;
  330. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_DEV;
  331. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_UTMICN_MASK;
  332. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_DEV;
  333. usb2h0cr = usb2h0cr &~SDR0_USB2H0CR_WDINT_MASK;
  334. usb2h0cr = usb2h0cr | SDR0_USB2H0CR_WDINT_8BIT_60MHZ;
  335. usb2d0cr = usb2d0cr &~SDR0_USB2D0CR_USB2DEV_EBC_SEL_MASK;
  336. sdr0_pfc1 = sdr0_pfc1 &~SDR0_PFC1_UES_MASK;
  337. sdr0_pfc1 = sdr0_pfc1 | SDR0_PFC1_UES_EBCHR_SEL;
  338. mtsdr(SDR0_USB2H0CR, usb2h0cr);
  339. mtsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  340. mtsdr(SDR0_USB2D0CR, usb2d0cr);
  341. mtsdr(SDR0_PFC1, sdr0_pfc1);
  342. /*clear resets*/
  343. udelay(1000);
  344. mtsdr(SDR0_SRST1, 0x00000000);
  345. udelay(1000);
  346. mtsdr(SDR0_SRST0, 0x00000000);
  347. printf("USB: Device\n");
  348. }
  349. /*
  350. * Clear PLB4A0_ACR[WRP]
  351. * This fix will make the MAL burst disabling patch for the Linux
  352. * EMAC driver obsolete.
  353. */
  354. reg = mfdcr(PLB4A0_ACR) & ~PLB4Ax_ACR_WRP_MASK;
  355. mtdcr(PLB4A0_ACR, reg);
  356. #ifdef CONFIG_FPGA
  357. pmc440_init_fpga();
  358. #endif
  359. /* turn off POST LED */
  360. out_be32((void*)GPIO1_OR, in_be32((void*)GPIO1_OR) & ~GPIO1_POST_N);
  361. /* turn on RUN LED */
  362. out_be32((void*)GPIO0_OR, in_be32((void*)GPIO0_OR) & ~GPIO0_LED_RUN_N);
  363. return 0;
  364. }
  365. int is_monarch(void)
  366. {
  367. if (in_be32((void*)GPIO1_IR) & GPIO1_NONMONARCH)
  368. return 0;
  369. return 1;
  370. }
  371. int pci_is_66mhz(void)
  372. {
  373. if (in_be32((void*)GPIO1_IR) & GPIO1_M66EN)
  374. return 1;
  375. return 0;
  376. }
  377. int board_revision(void)
  378. {
  379. return (int)((in_be32((void*)GPIO1_IR) & GPIO1_HWID_MASK) >> 4);
  380. }
  381. int checkboard(void)
  382. {
  383. puts("Board: esd GmbH - PMC440");
  384. gd->board_type = board_revision();
  385. printf(", Rev 1.%ld, ", gd->board_type);
  386. if (!is_monarch()) {
  387. puts("non-");
  388. }
  389. printf("monarch, PCI=%s MHz\n", pci_is_66mhz() ? "66" : "33");
  390. return (0);
  391. }
  392. #if defined(CONFIG_PCI) && defined(CONFIG_PCI_PNP)
  393. /*
  394. * Assign interrupts to PCI devices. Some OSs rely on this.
  395. */
  396. void board_pci_fixup_irq(struct pci_controller *hose, pci_dev_t dev)
  397. {
  398. unsigned char int_line[] = {IRQ_PCIC, IRQ_PCID, IRQ_PCIA, IRQ_PCIB};
  399. pci_hose_write_config_byte(hose, dev, PCI_INTERRUPT_LINE,
  400. int_line[PCI_DEV(dev) & 0x03]);
  401. }
  402. #endif
  403. /*
  404. * pci_target_init
  405. *
  406. * The bootstrap configuration provides default settings for the pci
  407. * inbound map (PIM). But the bootstrap config choices are limited and
  408. * may not be sufficient for a given board.
  409. */
  410. #if defined(CONFIG_PCI) && defined(CONFIG_SYS_PCI_TARGET_INIT)
  411. void pci_target_init(struct pci_controller *hose)
  412. {
  413. char *ptmla_str, *ptmms_str;
  414. /*
  415. * Set up Direct MMIO registers
  416. */
  417. /*
  418. * PowerPC440EPX PCI Master configuration.
  419. * Map one 1Gig range of PLB/processor addresses to PCI memory space.
  420. * PLB address 0x80000000-0xBFFFFFFF
  421. * ==> PCI address 0x80000000-0xBFFFFFFF
  422. * Use byte reversed out routines to handle endianess.
  423. * Make this region non-prefetchable.
  424. */
  425. out32r(PCIL0_PMM0MA, 0x00000000); /* PMM0 Mask/Attribute */
  426. /* - disabled b4 setting */
  427. out32r(PCIL0_PMM0LA, CONFIG_SYS_PCI_MEMBASE); /* PMM0 Local Address */
  428. out32r(PCIL0_PMM0PCILA, CONFIG_SYS_PCI_MEMBASE); /* PMM0 PCI Low Address */
  429. out32r(PCIL0_PMM0PCIHA, 0x00000000); /* PMM0 PCI High Address */
  430. out32r(PCIL0_PMM0MA, 0xc0000001); /* 1G + No prefetching, */
  431. /* and enable region */
  432. if (!is_monarch()) {
  433. ptmla_str = getenv("ptm1la");
  434. ptmms_str = getenv("ptm1ms");
  435. if(NULL != ptmla_str && NULL != ptmms_str ) {
  436. out32r(PCIL0_PTM1MS,
  437. simple_strtoul(ptmms_str, NULL, 16));
  438. out32r(PCIL0_PTM1LA,
  439. simple_strtoul(ptmla_str, NULL, 16));
  440. } else {
  441. /* BAR1: default top 64MB of RAM */
  442. out32r(PCIL0_PTM1MS, 0xfc000001);
  443. out32r(PCIL0_PTM1LA, 0x0c000000);
  444. }
  445. } else {
  446. /* BAR1: default: complete 256MB RAM */
  447. out32r(PCIL0_PTM1MS, 0xf0000001);
  448. out32r(PCIL0_PTM1LA, 0x00000000);
  449. }
  450. ptmla_str = getenv("ptm2la"); /* Local Addr. Reg */
  451. ptmms_str = getenv("ptm2ms"); /* Memory Size/Attribute */
  452. if(NULL != ptmla_str && NULL != ptmms_str ) {
  453. out32r(PCIL0_PTM2MS, simple_strtoul(ptmms_str, NULL, 16));
  454. out32r(PCIL0_PTM2LA, simple_strtoul(ptmla_str, NULL, 16));
  455. } else {
  456. /* BAR2: default: 4MB FPGA */
  457. out32r(PCIL0_PTM2MS, 0xffc00001); /* Memory Size/Attribute */
  458. out32r(PCIL0_PTM2LA, 0xef000000); /* Local Addr. Reg */
  459. }
  460. if (is_monarch()) {
  461. /* BAR2: map FPGA registers behind system memory at 1GB */
  462. pci_hose_write_config_dword(hose, 0, PCI_BASE_ADDRESS_2, 0x40000008);
  463. }
  464. /*
  465. * Set up Configuration registers
  466. */
  467. /* Program the board's vendor id */
  468. pci_hose_write_config_word(hose, 0, PCI_SUBSYSTEM_VENDOR_ID,
  469. CONFIG_SYS_PCI_SUBSYS_VENDORID);
  470. /* disabled for PMC405 backward compatibility */
  471. /* Configure command register as bus master */
  472. /* pci_write_config_word(0, PCI_COMMAND, PCI_COMMAND_MASTER); */
  473. /* 240nS PCI clock */
  474. pci_hose_write_config_word(hose, 0, PCI_LATENCY_TIMER, 1);
  475. /* No error reporting */
  476. pci_hose_write_config_word(hose, 0, PCI_ERREN, 0);
  477. if (!is_monarch()) {
  478. /* Program the board's subsystem id/classcode */
  479. pci_hose_write_config_word(hose, 0, PCI_SUBSYSTEM_ID,
  480. CONFIG_SYS_PCI_SUBSYS_ID_NONMONARCH);
  481. pci_hose_write_config_word(hose, 0, PCI_CLASS_SUB_CODE,
  482. CONFIG_SYS_PCI_CLASSCODE_NONMONARCH);
  483. /* PCI configuration done: release ERREADY */
  484. out_be32((void*)GPIO1_OR,
  485. in_be32((void*)GPIO1_OR) | GPIO1_PPC_EREADY);
  486. out_be32((void*)GPIO1_TCR,
  487. in_be32((void*)GPIO1_TCR) | GPIO1_PPC_EREADY);
  488. } else {
  489. /* Program the board's subsystem id/classcode */
  490. pci_hose_write_config_word(hose, 0, PCI_SUBSYSTEM_ID,
  491. CONFIG_SYS_PCI_SUBSYS_ID_MONARCH);
  492. pci_hose_write_config_word(hose, 0, PCI_CLASS_SUB_CODE,
  493. CONFIG_SYS_PCI_CLASSCODE_MONARCH);
  494. }
  495. /* enable host configuration */
  496. pci_hose_write_config_dword(hose, 0, PCI_BRDGOPT2, 0x00000101);
  497. }
  498. #endif /* defined(CONFIG_PCI) && defined(CONFIG_SYS_PCI_TARGET_INIT) */
  499. /*
  500. * Override weak default pci_master_init()
  501. */
  502. #if defined(CONFIG_PCI) && defined(CONFIG_SYS_PCI_MASTER_INIT)
  503. void pci_master_init(struct pci_controller *hose)
  504. {
  505. /*
  506. * Only configure the master in monach mode
  507. */
  508. if (is_monarch())
  509. __pci_master_init(hose);
  510. }
  511. #endif /* defined(CONFIG_PCI) && defined(CONFIG_SYS_PCI_MASTER_INIT) */
  512. static void wait_for_pci_ready(void)
  513. {
  514. if (!(in_be32((void*)GPIO1_IR) & GPIO1_PPC_EREADY)) {
  515. printf("PCI: Waiting for EREADY (CTRL-C to skip) ... ");
  516. while (1) {
  517. if (ctrlc()) {
  518. puts("abort\n");
  519. break;
  520. }
  521. if (in_be32((void*)GPIO1_IR) & GPIO1_PPC_EREADY) {
  522. printf("done\n");
  523. break;
  524. }
  525. }
  526. }
  527. }
  528. /*
  529. * Override weak is_pci_host()
  530. *
  531. * This routine is called to determine if a pci scan should be
  532. * performed. With various hardware environments (especially cPCI and
  533. * PPMC) it's insufficient to depend on the state of the arbiter enable
  534. * bit in the strap register, or generic host/adapter assumptions.
  535. *
  536. * Rather than hard-code a bad assumption in the general 440 code, the
  537. * 440 pci code requires the board to decide at runtime.
  538. *
  539. * Return 0 for adapter mode, non-zero for host (monarch) mode.
  540. */
  541. #if defined(CONFIG_PCI)
  542. int is_pci_host(struct pci_controller *hose)
  543. {
  544. char *s = getenv("pciscan");
  545. if (s == NULL)
  546. if (is_monarch()) {
  547. wait_for_pci_ready();
  548. return 1;
  549. } else
  550. return 0;
  551. else if (!strcmp(s, "yes"))
  552. return 1;
  553. return 0;
  554. }
  555. #endif /* defined(CONFIG_PCI) */
  556. #ifdef CONFIG_RESET_PHY_R
  557. void reset_phy(void)
  558. {
  559. char *s;
  560. unsigned short val_method, val_behavior;
  561. /* special LED setup for NGCC/CANDES */
  562. if ((s = getenv("bd_type")) &&
  563. ((!strcmp(s, "ngcc")) || (!strcmp(s, "candes")))) {
  564. val_method = 0x0e0a;
  565. val_behavior = 0x0cf2;
  566. } else {
  567. /* PMC440 standard type */
  568. val_method = 0x0e10;
  569. val_behavior = 0x0cf0;
  570. }
  571. if (miiphy_write("ppc_4xx_eth0", CONFIG_PHY_ADDR, 0x1f, 0x0001) == 0) {
  572. miiphy_write("ppc_4xx_eth0", CONFIG_PHY_ADDR, 0x11, 0x0010);
  573. miiphy_write("ppc_4xx_eth0", CONFIG_PHY_ADDR, 0x11, val_behavior);
  574. miiphy_write("ppc_4xx_eth0", CONFIG_PHY_ADDR, 0x10, val_method);
  575. miiphy_write("ppc_4xx_eth0", CONFIG_PHY_ADDR, 0x1f, 0x0000);
  576. }
  577. if (miiphy_write("ppc_4xx_eth1", CONFIG_PHY1_ADDR, 0x1f, 0x0001) == 0) {
  578. miiphy_write("ppc_4xx_eth1", CONFIG_PHY1_ADDR, 0x11, 0x0010);
  579. miiphy_write("ppc_4xx_eth1", CONFIG_PHY1_ADDR, 0x11, val_behavior);
  580. miiphy_write("ppc_4xx_eth1", CONFIG_PHY1_ADDR, 0x10, val_method);
  581. miiphy_write("ppc_4xx_eth1", CONFIG_PHY1_ADDR, 0x1f, 0x0000);
  582. }
  583. }
  584. #endif
  585. #if defined(CONFIG_SYS_EEPROM_WREN)
  586. /*
  587. * Input: <dev_addr> I2C address of EEPROM device to enable.
  588. * <state> -1: deliver current state
  589. * 0: disable write
  590. * 1: enable write
  591. * Returns: -1: wrong device address
  592. * 0: dis-/en- able done
  593. * 0/1: current state if <state> was -1.
  594. */
  595. int eeprom_write_enable(unsigned dev_addr, int state)
  596. {
  597. if ((CONFIG_SYS_I2C_EEPROM_ADDR != dev_addr) &&
  598. (CONFIG_SYS_I2C_BOOT_EEPROM_ADDR != dev_addr)) {
  599. return -1;
  600. } else {
  601. switch (state) {
  602. case 1:
  603. /* Enable write access, clear bit GPIO_SINT2. */
  604. out_be32((void *)GPIO0_OR,
  605. in_be32((void *)GPIO0_OR) & ~GPIO0_EP_EEP);
  606. state = 0;
  607. break;
  608. case 0:
  609. /* Disable write access, set bit GPIO_SINT2. */
  610. out_be32((void *)GPIO0_OR,
  611. in_be32((void *)GPIO0_OR) | GPIO0_EP_EEP);
  612. state = 0;
  613. break;
  614. default:
  615. /* Read current status back. */
  616. state = (0 == (in_be32((void *)GPIO0_OR)
  617. & GPIO0_EP_EEP));
  618. break;
  619. }
  620. }
  621. return state;
  622. }
  623. #endif /* #if defined(CONFIG_SYS_EEPROM_WREN) */
  624. #define CONFIG_SYS_BOOT_EEPROM_PAGE_WRITE_BITS 3
  625. int bootstrap_eeprom_write(unsigned dev_addr, unsigned offset,
  626. uchar *buffer, unsigned cnt)
  627. {
  628. unsigned end = offset + cnt;
  629. unsigned blk_off;
  630. int rcode = 0;
  631. #if defined(CONFIG_SYS_EEPROM_WREN)
  632. eeprom_write_enable(dev_addr, 1);
  633. #endif
  634. /*
  635. * Write data until done or would cross a write page boundary.
  636. * We must write the address again when changing pages
  637. * because the address counter only increments within a page.
  638. */
  639. while (offset < end) {
  640. unsigned alen, len;
  641. unsigned maxlen;
  642. uchar addr[2];
  643. blk_off = offset & 0xFF; /* block offset */
  644. addr[0] = offset >> 8; /* block number */
  645. addr[1] = blk_off; /* block offset */
  646. alen = 2;
  647. addr[0] |= dev_addr; /* insert device address */
  648. len = end - offset;
  649. #define BOOT_EEPROM_PAGE_SIZE (1 << CONFIG_SYS_BOOT_EEPROM_PAGE_WRITE_BITS)
  650. #define BOOT_EEPROM_PAGE_OFFSET(x) ((x) & (BOOT_EEPROM_PAGE_SIZE - 1))
  651. maxlen = BOOT_EEPROM_PAGE_SIZE -
  652. BOOT_EEPROM_PAGE_OFFSET(blk_off);
  653. if (maxlen > I2C_RXTX_LEN)
  654. maxlen = I2C_RXTX_LEN;
  655. if (len > maxlen)
  656. len = maxlen;
  657. if (i2c_write (addr[0], offset, alen-1, buffer, len) != 0)
  658. rcode = 1;
  659. buffer += len;
  660. offset += len;
  661. #if defined(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS)
  662. udelay(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS * 1000);
  663. #endif
  664. }
  665. #if defined(CONFIG_SYS_EEPROM_WREN)
  666. eeprom_write_enable(dev_addr, 0);
  667. #endif
  668. return rcode;
  669. }
  670. int bootstrap_eeprom_read (unsigned dev_addr, unsigned offset,
  671. uchar *buffer, unsigned cnt)
  672. {
  673. unsigned end = offset + cnt;
  674. unsigned blk_off;
  675. int rcode = 0;
  676. /*
  677. * Read data until done or would cross a page boundary.
  678. * We must write the address again when changing pages
  679. * because the next page may be in a different device.
  680. */
  681. while (offset < end) {
  682. unsigned alen, len;
  683. unsigned maxlen;
  684. uchar addr[2];
  685. blk_off = offset & 0xFF; /* block offset */
  686. addr[0] = offset >> 8; /* block number */
  687. addr[1] = blk_off; /* block offset */
  688. alen = 2;
  689. addr[0] |= dev_addr; /* insert device address */
  690. len = end - offset;
  691. maxlen = 0x100 - blk_off;
  692. if (maxlen > I2C_RXTX_LEN)
  693. maxlen = I2C_RXTX_LEN;
  694. if (len > maxlen)
  695. len = maxlen;
  696. if (i2c_read (addr[0], offset, alen-1, buffer, len) != 0)
  697. rcode = 1;
  698. buffer += len;
  699. offset += len;
  700. }
  701. return rcode;
  702. }
  703. #if defined(CONFIG_USB_OHCI_NEW) && defined(CONFIG_SYS_USB_OHCI_BOARD_INIT)
  704. int board_usb_init(int index, enum usb_init_type init)
  705. {
  706. char *act = getenv("usbact");
  707. int i;
  708. if ((act == NULL || strcmp(act, "host") == 0) &&
  709. !(in_be32((void*)GPIO0_IR) & GPIO0_USB_PRSNT))
  710. /* enable power on USB socket */
  711. out_be32((void*)GPIO1_OR,
  712. in_be32((void*)GPIO1_OR) & ~GPIO1_USB_PWR_N);
  713. for (i=0; i<1000; i++)
  714. udelay(1000);
  715. return 0;
  716. }
  717. int usb_board_stop(void)
  718. {
  719. /* disable power on USB socket */
  720. out_be32((void*)GPIO1_OR, in_be32((void*)GPIO1_OR) | GPIO1_USB_PWR_N);
  721. return 0;
  722. }
  723. int board_usb_cleanup(int index, enum usb_init_type init)
  724. {
  725. return usb_board_stop();
  726. }
  727. #endif /* defined(CONFIG_USB_OHCI) && defined(CONFIG_SYS_USB_OHCI_BOARD_INIT) */
  728. #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
  729. void ft_board_setup(void *blob, bd_t *bd)
  730. {
  731. int rc;
  732. __ft_board_setup(blob, bd);
  733. /*
  734. * Disable PCI in non-monarch mode.
  735. */
  736. if (!is_monarch()) {
  737. rc = fdt_find_and_setprop(blob, "/plb/pci@1ec000000", "status",
  738. "disabled", sizeof("disabled"), 1);
  739. if (rc) {
  740. printf("Unable to update property status in PCI node, err=%s\n",
  741. fdt_strerror(rc));
  742. }
  743. }
  744. }
  745. #endif /* defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) */