pmc440.c 24 KB

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