pmc440.c 26 KB

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