pmc440.c 24 KB

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