korat.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  1. /*
  2. * (C) Copyright 2007
  3. * Larry Johnson, lrj@acm.org
  4. *
  5. * (C) Copyright 2006
  6. * Stefan Roese, DENX Software Engineering, sr@denx.de.
  7. *
  8. * (C) Copyright 2006
  9. * Jacqueline Pira-Ferriol, AMCC/IBM, jpira-ferriol@fr.ibm.com
  10. * Alain Saurel, AMCC/IBM, alain.saurel@fr.ibm.com
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation; either version 2 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  25. * MA 02111-1307 USA
  26. */
  27. #include <common.h>
  28. #include <asm/processor.h>
  29. #include <asm-ppc/io.h>
  30. #include <i2c.h>
  31. #include <ppc440.h>
  32. DECLARE_GLOBAL_DATA_PTR;
  33. extern flash_info_t flash_info[CFG_MAX_FLASH_BANKS]; /* info for FLASH chips */
  34. ulong flash_get_size(ulong base, int banknum);
  35. int board_early_init_f(void)
  36. {
  37. u32 sdr0_pfc1, sdr0_pfc2;
  38. u32 gpio0_ir;
  39. u32 reg;
  40. int eth;
  41. mtdcr(ebccfga, xbcfg);
  42. mtdcr(ebccfgd, 0xb8400000);
  43. /*--------------------------------------------------------------------
  44. * Setup the GPIO pins
  45. *
  46. * Korat GPIO usage:
  47. *
  48. * Init.
  49. * Pin Source I/O value Function
  50. * ------ ------ --- ----- ---------------------------------
  51. * GPIO00 Alt1 I/O x PerAddr07
  52. * GPIO01 Alt1 I/O x PerAddr06
  53. * GPIO02 Alt1 I/O x PerAddr05
  54. * GPIO03 GPIO x x GPIO03 to expansion bus connector
  55. * GPIO04 GPIO x x GPIO04 to expansion bus connector
  56. * GPIO05 GPIO x x GPIO05 to expansion bus connector
  57. * GPIO06 Alt1 O x PerCS1 (2nd NOR flash)
  58. * GPIO07 Alt1 O x PerCS2 (CPLD)
  59. * GPIO08 Alt1 O x PerCS3 to expansion bus connector
  60. * GPIO09 Alt1 O x PerCS4 to expansion bus connector
  61. * GPIO10 Alt1 O x PerCS5 to expansion bus connector
  62. * GPIO11 Alt1 I x PerErr
  63. * GPIO12 GPIO O 0 ATMega !Reset
  64. * GPIO13 GPIO O 1 SPI Atmega !SS
  65. * GPIO14 GPIO O 1 Write protect EEPROM #1 (0xA8)
  66. * GPIO15 GPIO O 0 CPU Run LED !On
  67. * GPIO16 Alt1 O x GMC1TxD0
  68. * GPIO17 Alt1 O x GMC1TxD1
  69. * GPIO18 Alt1 O x GMC1TxD2
  70. * GPIO19 Alt1 O x GMC1TxD3
  71. * GPIO20 Alt1 O x RejectPkt0
  72. * GPIO21 Alt1 O x RejectPkt1
  73. * GPIO22 GPIO I x PGOOD_DDR
  74. * GPIO23 Alt1 O x SCPD0
  75. * GPIO24 Alt1 O x GMC0TxD2
  76. * GPIO25 Alt1 O x GMC0TxD3
  77. * GPIO26 GPIO? I/O x IIC0SDA (selected in SDR0_PFC4)
  78. * GPIO27 GPIO O 0 PHY #0 1000BASE-X
  79. * GPIO28 GPIO O 0 PHY #1 1000BASE-X
  80. * GPIO29 GPIO I x Test jumper !Present
  81. * GPIO30 GPIO I x SFP module #0 !Present
  82. * GPIO31 GPIO I x SFP module #1 !Present
  83. *
  84. * GPIO32 GPIO O 1 SFP module #0 Tx !Enable
  85. * GPIO33 GPIO O 1 SFP module #1 Tx !Enable
  86. * GPIO34 Alt2 I x !UART1_CTS
  87. * GPIO35 Alt2 O x !UART1_RTS
  88. * GPIO36 Alt1 I x !UART0_CTS
  89. * GPIO37 Alt1 O x !UART0_RTS
  90. * GPIO38 Alt2 O x UART1_Tx
  91. * GPIO39 Alt2 I x UART1_Rx
  92. * GPIO40 Alt1 I x IRQ0 (Ethernet 0)
  93. * GPIO41 Alt1 I x IRQ1 (Ethernet 1)
  94. * GPIO42 Alt1 I x IRQ2 (PCI interrupt)
  95. * GPIO43 Alt1 I x IRQ3 (System Alert from CPLD)
  96. * GPIO44 xxxx x x (grounded through pulldown)
  97. * GPIO45 GPIO O 0 PHY #0 Enable
  98. * GPIO46 GPIO O 0 PHY #1 Enable
  99. * GPIO47 GPIO I x Reset switch !Pressed
  100. * GPIO48 GPIO I x Shutdown switch !Pressed
  101. * GPIO49 xxxx x x (reserved for trace port)
  102. * . . . . .
  103. * . . . . .
  104. * . . . . .
  105. * GPIO63 xxxx x x (reserved for trace port)
  106. *-------------------------------------------------------------------*/
  107. out_be32((u32 *) GPIO0_OR, 0x00060000);
  108. out_be32((u32 *) GPIO1_OR, 0xC0000000);
  109. out_be32((u32 *) GPIO0_OSRL, 0x54055400);
  110. out_be32((u32 *) GPIO0_OSRH, 0x55015000);
  111. out_be32((u32 *) GPIO1_OSRL, 0x02180000);
  112. out_be32((u32 *) GPIO1_OSRH, 0x00000000);
  113. out_be32((u32 *) GPIO0_TSRL, 0x54055500);
  114. out_be32((u32 *) GPIO0_TSRH, 0x00015000);
  115. out_be32((u32 *) GPIO1_TSRL, 0x00000000);
  116. out_be32((u32 *) GPIO1_TSRH, 0x00000000);
  117. out_be32((u32 *) GPIO0_TCR, 0x000FF0D8);
  118. out_be32((u32 *) GPIO1_TCR, 0xD6060000);
  119. out_be32((u32 *) GPIO0_ISR1L, 0x54000100);
  120. out_be32((u32 *) GPIO0_ISR1H, 0x00500000);
  121. out_be32((u32 *) GPIO1_ISR1L, 0x00405500);
  122. out_be32((u32 *) GPIO1_ISR1H, 0x00000000);
  123. out_be32((u32 *) GPIO0_ISR2L, 0x00000000);
  124. out_be32((u32 *) GPIO0_ISR2H, 0x00000000);
  125. out_be32((u32 *) GPIO1_ISR2L, 0x04010000);
  126. out_be32((u32 *) GPIO1_ISR2H, 0x00000000);
  127. out_be32((u32 *) GPIO0_ISR3L, 0x00000000);
  128. out_be32((u32 *) GPIO0_ISR3H, 0x00000000);
  129. out_be32((u32 *) GPIO1_ISR3L, 0x00000000);
  130. out_be32((u32 *) GPIO1_ISR3H, 0x00000000);
  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, 0xfffff7ff); /* per ref-board manual */
  138. mtdcr(uic0tr, 0x00000000); /* per ref-board manual */
  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, 0xffffffff); /* per ref-board manual */
  145. mtdcr(uic1tr, 0x00000000); /* per ref-board manual */
  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, 0xffffffff); /* per ref-board manual */
  152. mtdcr(uic2tr, 0x00000000); /* per ref-board manual */
  153. mtdcr(uic2vr, 0x00000000); /* int31 highest, base=0x000 */
  154. mtdcr(uic2sr, 0xffffffff); /* clear all */
  155. /* take sim card reader and CF controller out of reset */
  156. out_8((u8 *) CFG_CPLD_BASE + 0x04, 0x80);
  157. /* Configure the two Ethernet PHYs. For each PHY, configure for fiber
  158. * if the SFP module is present, and for copper if it is not present.
  159. */
  160. gpio0_ir = in_be32((u32 *) GPIO0_IR);
  161. for (eth = 0; eth < 2; ++eth) {
  162. if (gpio0_ir & (0x00000001 << (1 - eth))) {
  163. /* SFP module not present: configure PHY for copper. */
  164. /* Set PHY to autonegotate 10 MB, 100MB, or 1 GB */
  165. out_8((u8 *) CFG_CPLD_BASE + 0x06,
  166. in_8((u8 *) CFG_CPLD_BASE + 0x06) |
  167. 0x06 << (4 * eth));
  168. } else {
  169. /* SFP module present: configure PHY for fiber and
  170. enable output */
  171. out_be32((u32 *) GPIO0_OR, in_be32((u32 *) GPIO0_OR) |
  172. (0x00000001 << (4 - eth)));
  173. out_be32((u32 *) GPIO1_OR, in_be32((u32 *) GPIO1_OR) &
  174. ~(0x00000001 << (31 - eth)));
  175. }
  176. }
  177. /* enable Ethernet: set GPIO45 and GPIO46 to 1 */
  178. out_be32((u32 *) GPIO1_OR, in_be32((u32 *) GPIO1_OR) | 0x00060000);
  179. /* select Ethernet pins */
  180. mfsdr(SDR0_PFC1, sdr0_pfc1);
  181. sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_SELECT_MASK) |
  182. SDR0_PFC1_SELECT_CONFIG_4;
  183. mfsdr(SDR0_PFC2, sdr0_pfc2);
  184. sdr0_pfc2 = (sdr0_pfc2 & ~SDR0_PFC2_SELECT_MASK) |
  185. SDR0_PFC2_SELECT_CONFIG_4;
  186. mtsdr(SDR0_PFC2, sdr0_pfc2);
  187. mtsdr(SDR0_PFC1, sdr0_pfc1);
  188. /* PCI arbiter enabled */
  189. mfsdr(sdr_pci0, reg);
  190. mtsdr(sdr_pci0, 0x80000000 | reg);
  191. return 0;
  192. }
  193. static int man_data_read(unsigned int addr)
  194. {
  195. /*
  196. * Read an octet of data from address "addr" in the manufacturer's
  197. * information serial EEPROM, or -1 on error.
  198. */
  199. u8 data[2];
  200. if (0 != i2c_probe(MAN_DATA_EEPROM_ADDR) ||
  201. 0 != i2c_read(MAN_DATA_EEPROM_ADDR, addr, 1, data, 1)) {
  202. debug("man_data_read(0x%02X) failed\n", addr);
  203. return -1;
  204. }
  205. debug("man_info_read(0x%02X) returned 0x%02X\n", addr, data[0]);
  206. return data[0];
  207. }
  208. static unsigned int man_data_field_addr(unsigned int const field)
  209. {
  210. /*
  211. * The manufacturer's information serial EEPROM contains a sequence of
  212. * zero-delimited fields. Return the starting address of field "field",
  213. * or 0 on error.
  214. */
  215. unsigned addr, i;
  216. if (0 == field || 'A' != man_data_read(0) || '\0' != man_data_read(1))
  217. /* Only format "A" is currently supported */
  218. return 0;
  219. for (addr = 2, i = 1; i < field && addr < 256; ++addr) {
  220. if ('\0' == man_data_read(addr))
  221. ++i;
  222. }
  223. return (addr < 256) ? addr : 0;
  224. }
  225. static char *man_data_read_field(char s[], unsigned const field,
  226. unsigned const length)
  227. {
  228. /*
  229. * Place the null-terminated contents of field "field" of length
  230. * "length" from the manufacturer's information serial EEPROM into
  231. * string "s[length + 1]" and return a pointer to s, or return 0 on
  232. * error. In either case the original contents of s[] is not preserved.
  233. */
  234. unsigned addr, i;
  235. addr = man_data_field_addr(field);
  236. if (0 == addr || addr + length >= 255)
  237. return 0;
  238. for (i = 0; i < length; ++i) {
  239. int const c = man_data_read(addr++);
  240. if (c <= 0)
  241. return 0;
  242. s[i] = (char)c;
  243. }
  244. if (0 != man_data_read(addr))
  245. return 0;
  246. s[i] = '\0';
  247. return s;
  248. }
  249. static void set_serial_number(void)
  250. {
  251. /*
  252. * If the environmental variable "serial#" is not set, try to set it
  253. * from the manufacturer's information serial EEPROM.
  254. */
  255. char s[MAN_SERIAL_NO_LENGTH + 1];
  256. if (0 == getenv("serial#") &&
  257. 0 != man_data_read_field(s, MAN_SERIAL_NO_FIELD,
  258. MAN_SERIAL_NO_LENGTH))
  259. setenv("serial#", s);
  260. }
  261. static void set_mac_addresses(void)
  262. {
  263. /*
  264. * If the environmental variables "ethaddr" and/or "eth1addr" are not
  265. * set, try to set them from the manufacturer's information serial
  266. * EEPROM.
  267. */
  268. char s[MAN_MAC_ADDR_LENGTH + 1];
  269. if (0 != getenv("ethaddr") && 0 != getenv("eth1addr"))
  270. return;
  271. if (0 == man_data_read_field(s, MAN_MAC_ADDR_FIELD,
  272. MAN_MAC_ADDR_LENGTH))
  273. return;
  274. if (0 == getenv("ethaddr"))
  275. setenv("ethaddr", s);
  276. if (0 == getenv("eth1addr")) {
  277. ++s[MAN_MAC_ADDR_LENGTH - 1];
  278. setenv("eth1addr", s);
  279. }
  280. }
  281. /*---------------------------------------------------------------------------+
  282. | misc_init_r.
  283. +---------------------------------------------------------------------------*/
  284. int misc_init_r(void)
  285. {
  286. uint pbcr;
  287. int size_val = 0;
  288. u32 reg;
  289. unsigned long usb2d0cr = 0;
  290. unsigned long usb2phy0cr, usb2h0cr = 0;
  291. unsigned long sdr0_pfc1;
  292. char *act = getenv("usbact");
  293. /*
  294. * FLASH stuff...
  295. */
  296. /* Re-do sizing to get full correct info */
  297. /* adjust flash start and offset */
  298. gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
  299. gd->bd->bi_flashoffset = 0;
  300. mtdcr(ebccfga, pb0cr);
  301. pbcr = mfdcr(ebccfgd);
  302. switch (gd->bd->bi_flashsize) {
  303. case 1 << 20:
  304. size_val = 0;
  305. break;
  306. case 2 << 20:
  307. size_val = 1;
  308. break;
  309. case 4 << 20:
  310. size_val = 2;
  311. break;
  312. case 8 << 20:
  313. size_val = 3;
  314. break;
  315. case 16 << 20:
  316. size_val = 4;
  317. break;
  318. case 32 << 20:
  319. size_val = 5;
  320. break;
  321. case 64 << 20:
  322. size_val = 6;
  323. break;
  324. case 128 << 20:
  325. size_val = 7;
  326. break;
  327. }
  328. pbcr = (pbcr & 0x0001ffff) | gd->bd->bi_flashstart | (size_val << 17);
  329. mtdcr(ebccfga, pb0cr);
  330. mtdcr(ebccfgd, pbcr);
  331. /*
  332. * Re-check to get correct base address
  333. */
  334. flash_get_size(gd->bd->bi_flashstart, 0);
  335. /* Monitor protection ON by default */
  336. (void)flash_protect(FLAG_PROTECT_SET, -CFG_MONITOR_LEN, 0xffffffff,
  337. &flash_info[0]);
  338. /* Env protection ON by default */
  339. (void)flash_protect(FLAG_PROTECT_SET,
  340. CFG_ENV_ADDR_REDUND,
  341. CFG_ENV_ADDR_REDUND + 2 * CFG_ENV_SECT_SIZE - 1,
  342. &flash_info[0]);
  343. /*
  344. * USB suff...
  345. */
  346. if (act == NULL || strcmp(act, "hostdev") == 0) {
  347. /* SDR Setting */
  348. mfsdr(SDR0_PFC1, sdr0_pfc1);
  349. mfsdr(SDR0_USB2D0CR, usb2d0cr);
  350. mfsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  351. mfsdr(SDR0_USB2H0CR, usb2h0cr);
  352. usb2phy0cr = usb2phy0cr & ~SDR0_USB2PHY0CR_XOCLK_MASK;
  353. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL; /*0 */
  354. usb2phy0cr = usb2phy0cr & ~SDR0_USB2PHY0CR_WDINT_MASK;
  355. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_WDINT_16BIT_30MHZ; /*1 */
  356. usb2phy0cr = usb2phy0cr & ~SDR0_USB2PHY0CR_DVBUS_MASK;
  357. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PURDIS; /*0 */
  358. usb2phy0cr = usb2phy0cr & ~SDR0_USB2PHY0CR_DWNSTR_MASK;
  359. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_HOST; /*1 */
  360. usb2phy0cr = usb2phy0cr & ~SDR0_USB2PHY0CR_UTMICN_MASK;
  361. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_HOST; /*1 */
  362. /* An 8-bit/60MHz interface is the only possible alternative
  363. when connecting the Device to the PHY */
  364. usb2h0cr = usb2h0cr & ~SDR0_USB2H0CR_WDINT_MASK;
  365. usb2h0cr = usb2h0cr | SDR0_USB2H0CR_WDINT_16BIT_30MHZ; /*1 */
  366. /* To enable the USB 2.0 Device function through the UTMI interface */
  367. usb2d0cr = usb2d0cr & ~SDR0_USB2D0CR_USB2DEV_EBC_SEL_MASK;
  368. usb2d0cr = usb2d0cr | SDR0_USB2D0CR_USB2DEV_SELECTION; /*1 */
  369. sdr0_pfc1 = sdr0_pfc1 & ~SDR0_PFC1_UES_MASK;
  370. sdr0_pfc1 = sdr0_pfc1 | SDR0_PFC1_UES_USB2D_SEL; /*0 */
  371. mtsdr(SDR0_PFC1, sdr0_pfc1);
  372. mtsdr(SDR0_USB2D0CR, usb2d0cr);
  373. mtsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  374. mtsdr(SDR0_USB2H0CR, usb2h0cr);
  375. /*clear resets */
  376. udelay(1000);
  377. mtsdr(SDR0_SRST1, 0x00000000);
  378. udelay(1000);
  379. mtsdr(SDR0_SRST0, 0x00000000);
  380. printf("USB: Host(int phy) Device(ext phy)\n");
  381. } else if (strcmp(act, "dev") == 0) {
  382. /*-------------------PATCH-------------------------------*/
  383. mfsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  384. usb2phy0cr = usb2phy0cr & ~SDR0_USB2PHY0CR_XOCLK_MASK;
  385. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL; /*0 */
  386. usb2phy0cr = usb2phy0cr & ~SDR0_USB2PHY0CR_DVBUS_MASK;
  387. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PURDIS; /*0 */
  388. usb2phy0cr = usb2phy0cr & ~SDR0_USB2PHY0CR_DWNSTR_MASK;
  389. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_HOST; /*1 */
  390. usb2phy0cr = usb2phy0cr & ~SDR0_USB2PHY0CR_UTMICN_MASK;
  391. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_HOST; /*1 */
  392. mtsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  393. udelay(1000);
  394. mtsdr(SDR0_SRST1, 0x672c6000);
  395. udelay(1000);
  396. mtsdr(SDR0_SRST0, 0x00000080);
  397. udelay(1000);
  398. mtsdr(SDR0_SRST1, 0x60206000);
  399. *(unsigned int *)(0xe0000350) = 0x00000001;
  400. udelay(1000);
  401. mtsdr(SDR0_SRST1, 0x60306000);
  402. /*-------------------PATCH-------------------------------*/
  403. /* SDR Setting */
  404. mfsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  405. mfsdr(SDR0_USB2H0CR, usb2h0cr);
  406. mfsdr(SDR0_USB2D0CR, usb2d0cr);
  407. mfsdr(SDR0_PFC1, sdr0_pfc1);
  408. usb2phy0cr = usb2phy0cr & ~SDR0_USB2PHY0CR_XOCLK_MASK;
  409. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL; /*0 */
  410. usb2phy0cr = usb2phy0cr & ~SDR0_USB2PHY0CR_WDINT_MASK;
  411. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_WDINT_8BIT_60MHZ; /*0 */
  412. usb2phy0cr = usb2phy0cr & ~SDR0_USB2PHY0CR_DVBUS_MASK;
  413. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PUREN; /*1 */
  414. usb2phy0cr = usb2phy0cr & ~SDR0_USB2PHY0CR_DWNSTR_MASK;
  415. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_DEV; /*0 */
  416. usb2phy0cr = usb2phy0cr & ~SDR0_USB2PHY0CR_UTMICN_MASK;
  417. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_DEV; /*0 */
  418. usb2h0cr = usb2h0cr & ~SDR0_USB2H0CR_WDINT_MASK;
  419. usb2h0cr = usb2h0cr | SDR0_USB2H0CR_WDINT_8BIT_60MHZ; /*0 */
  420. usb2d0cr = usb2d0cr & ~SDR0_USB2D0CR_USB2DEV_EBC_SEL_MASK;
  421. usb2d0cr = usb2d0cr | SDR0_USB2D0CR_EBC_SELECTION; /*0 */
  422. sdr0_pfc1 = sdr0_pfc1 & ~SDR0_PFC1_UES_MASK;
  423. sdr0_pfc1 = sdr0_pfc1 | SDR0_PFC1_UES_EBCHR_SEL; /*1 */
  424. mtsdr(SDR0_USB2H0CR, usb2h0cr);
  425. mtsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  426. mtsdr(SDR0_USB2D0CR, usb2d0cr);
  427. mtsdr(SDR0_PFC1, sdr0_pfc1);
  428. /*clear resets */
  429. udelay(1000);
  430. mtsdr(SDR0_SRST1, 0x00000000);
  431. udelay(1000);
  432. mtsdr(SDR0_SRST0, 0x00000000);
  433. printf("USB: Device(int phy)\n");
  434. }
  435. mfsdr(SDR0_SRST1, reg); /* enable security/kasumi engines */
  436. reg &= ~(SDR0_SRST1_CRYP0 | SDR0_SRST1_KASU0);
  437. mtsdr(SDR0_SRST1, reg);
  438. /*
  439. * Clear PLB4A0_ACR[WRP]
  440. * This fix will make the MAL burst disabling patch for the Linux
  441. * EMAC driver obsolete.
  442. */
  443. reg = mfdcr(plb4_acr) & ~PLB4_ACR_WRP;
  444. mtdcr(plb4_acr, reg);
  445. set_serial_number();
  446. set_mac_addresses();
  447. return 0;
  448. }
  449. int checkboard(void)
  450. {
  451. char const *const s = getenv("serial#");
  452. u8 const rev = in_8((u8 *) CFG_CPLD_BASE + 0);
  453. u32 const gpio0_or = in_be32((u32 *) GPIO0_OR);
  454. printf("Board: Korat, Rev. %X", rev);
  455. if (s != NULL)
  456. printf(", serial# %s", s);
  457. printf(", Ethernet PHY 0: ");
  458. if (gpio0_or & 0x00000010)
  459. printf("fiber");
  460. else
  461. printf("copper");
  462. printf(", PHY 1: ");
  463. if (gpio0_or & 0x00000008)
  464. printf("fiber");
  465. else
  466. printf("copper");
  467. printf(".\n");
  468. return (0);
  469. }
  470. #if defined(CFG_DRAM_TEST)
  471. int testdram(void)
  472. {
  473. unsigned long *mem = (unsigned long *)0;
  474. const unsigned long kend = (1024 / sizeof(unsigned long));
  475. unsigned long k, n;
  476. mtmsr(0);
  477. /* TODO: find correct size of SDRAM */
  478. for (k = 0; k < CFG_MBYTES_SDRAM;
  479. ++k, mem += (1024 / sizeof(unsigned long))) {
  480. if ((k & 1023) == 0)
  481. printf("%3d MB\r", k / 1024);
  482. memset(mem, 0xaaaaaaaa, 1024);
  483. for (n = 0; n < kend; ++n) {
  484. if (mem[n] != 0xaaaaaaaa) {
  485. printf("SDRAM test fails at: %08x\n",
  486. (uint) & mem[n]);
  487. return 1;
  488. }
  489. }
  490. memset(mem, 0x55555555, 1024);
  491. for (n = 0; n < kend; ++n) {
  492. if (mem[n] != 0x55555555) {
  493. printf("SDRAM test fails at: %08x\n",
  494. (uint) & mem[n]);
  495. return 1;
  496. }
  497. }
  498. }
  499. printf("SDRAM test passes\n");
  500. return 0;
  501. }
  502. #endif /* defined(CFG_DRAM_TEST) */
  503. /*************************************************************************
  504. * pci_pre_init
  505. *
  506. * This routine is called just prior to registering the hose and gives
  507. * the board the opportunity to check things. Returning a value of zero
  508. * indicates that things are bad & PCI initialization should be aborted.
  509. *
  510. * Different boards may wish to customize the pci controller structure
  511. * (add regions, override default access routines, etc) or perform
  512. * certain pre-initialization actions.
  513. *
  514. ************************************************************************/
  515. #if defined(CONFIG_PCI)
  516. int pci_pre_init(struct pci_controller *hose)
  517. {
  518. unsigned long addr;
  519. /*-------------------------------------------------------------------------+
  520. | Set priority for all PLB3 devices to 0.
  521. | Set PLB3 arbiter to fair mode.
  522. +-------------------------------------------------------------------------*/
  523. mfsdr(sdr_amp1, addr);
  524. mtsdr(sdr_amp1, (addr & 0x000000FF) | 0x0000FF00);
  525. addr = mfdcr(plb3_acr);
  526. mtdcr(plb3_acr, addr | 0x80000000);
  527. /*-------------------------------------------------------------------------+
  528. | Set priority for all PLB4 devices to 0.
  529. +-------------------------------------------------------------------------*/
  530. mfsdr(sdr_amp0, addr);
  531. mtsdr(sdr_amp0, (addr & 0x000000FF) | 0x0000FF00);
  532. addr = mfdcr(plb4_acr) | 0xa0000000; /* Was 0x8---- */
  533. mtdcr(plb4_acr, addr);
  534. /*-------------------------------------------------------------------------+
  535. | Set Nebula PLB4 arbiter to fair mode.
  536. +-------------------------------------------------------------------------*/
  537. /* Segment0 */
  538. addr = (mfdcr(plb0_acr) & ~plb0_acr_ppm_mask) | plb0_acr_ppm_fair;
  539. addr = (addr & ~plb0_acr_hbu_mask) | plb0_acr_hbu_enabled;
  540. addr = (addr & ~plb0_acr_rdp_mask) | plb0_acr_rdp_4deep;
  541. addr = (addr & ~plb0_acr_wrp_mask) | plb0_acr_wrp_2deep;
  542. mtdcr(plb0_acr, addr);
  543. /* Segment1 */
  544. addr = (mfdcr(plb1_acr) & ~plb1_acr_ppm_mask) | plb1_acr_ppm_fair;
  545. addr = (addr & ~plb1_acr_hbu_mask) | plb1_acr_hbu_enabled;
  546. addr = (addr & ~plb1_acr_rdp_mask) | plb1_acr_rdp_4deep;
  547. addr = (addr & ~plb1_acr_wrp_mask) | plb1_acr_wrp_2deep;
  548. mtdcr(plb1_acr, addr);
  549. return 1;
  550. }
  551. #endif /* defined(CONFIG_PCI) */
  552. /*************************************************************************
  553. * pci_target_init
  554. *
  555. * The bootstrap configuration provides default settings for the pci
  556. * inbound map (PIM). But the bootstrap config choices are limited and
  557. * may not be sufficient for a given board.
  558. *
  559. ************************************************************************/
  560. #if defined(CONFIG_PCI) && defined(CFG_PCI_TARGET_INIT)
  561. void pci_target_init(struct pci_controller *hose)
  562. {
  563. /*--------------------------------------------------------------------------+
  564. * Set up Direct MMIO registers
  565. *--------------------------------------------------------------------------*/
  566. /*--------------------------------------------------------------------------+
  567. | PowerPC440EPX PCI Master configuration.
  568. | Map one 1Gig range of PLB/processor addresses to PCI memory space.
  569. | PLB address 0xA0000000-0xDFFFFFFF ==> PCI address 0xA0000000-0xDFFFFFFF
  570. | Use byte reversed out routines to handle endianess.
  571. | Make this region non-prefetchable.
  572. +--------------------------------------------------------------------------*/
  573. out32r(PCIX0_PMM0MA, 0x00000000); /* PMM0 Mask/Attribute - disabled b4 setting */
  574. out32r(PCIX0_PMM0LA, CFG_PCI_MEMBASE); /* PMM0 Local Address */
  575. out32r(PCIX0_PMM0PCILA, CFG_PCI_MEMBASE); /* PMM0 PCI Low Address */
  576. out32r(PCIX0_PMM0PCIHA, 0x00000000); /* PMM0 PCI High Address */
  577. out32r(PCIX0_PMM0MA, 0xE0000001); /* 512M + No prefetching, and enable region */
  578. out32r(PCIX0_PMM1MA, 0x00000000); /* PMM0 Mask/Attribute - disabled b4 setting */
  579. out32r(PCIX0_PMM1LA, CFG_PCI_MEMBASE2); /* PMM0 Local Address */
  580. out32r(PCIX0_PMM1PCILA, CFG_PCI_MEMBASE2); /* PMM0 PCI Low Address */
  581. out32r(PCIX0_PMM1PCIHA, 0x00000000); /* PMM0 PCI High Address */
  582. out32r(PCIX0_PMM1MA, 0xE0000001); /* 512M + No prefetching, and enable region */
  583. out32r(PCIX0_PTM1MS, 0x00000001); /* Memory Size/Attribute */
  584. out32r(PCIX0_PTM1LA, 0); /* Local Addr. Reg */
  585. out32r(PCIX0_PTM2MS, 0); /* Memory Size/Attribute */
  586. out32r(PCIX0_PTM2LA, 0); /* Local Addr. Reg */
  587. /*--------------------------------------------------------------------------+
  588. * Set up Configuration registers
  589. *--------------------------------------------------------------------------*/
  590. /* Program the board's subsystem id/vendor id */
  591. pci_write_config_word(0, PCI_SUBSYSTEM_VENDOR_ID,
  592. CFG_PCI_SUBSYS_VENDORID);
  593. pci_write_config_word(0, PCI_SUBSYSTEM_ID, CFG_PCI_SUBSYS_ID);
  594. /* Configure command register as bus master */
  595. pci_write_config_word(0, PCI_COMMAND, PCI_COMMAND_MASTER);
  596. /* 240nS PCI clock */
  597. pci_write_config_word(0, PCI_LATENCY_TIMER, 1);
  598. /* No error reporting */
  599. pci_write_config_word(0, PCI_ERREN, 0);
  600. pci_write_config_dword(0, PCI_BRDGOPT2, 0x00000101);
  601. /*--------------------------------------------------------------------------+
  602. * Set up Configuration registers for on-board NEC uPD720101 USB controller
  603. *--------------------------------------------------------------------------*/
  604. pci_write_config_dword(PCI_BDF(0x0, 0xC, 0x0), 0xE4, 0x00000020);
  605. }
  606. #endif /* defined(CONFIG_PCI) && defined(CFG_PCI_TARGET_INIT) */
  607. /*************************************************************************
  608. * pci_master_init
  609. *
  610. ************************************************************************/
  611. #if defined(CONFIG_PCI) && defined(CFG_PCI_MASTER_INIT)
  612. void pci_master_init(struct pci_controller *hose)
  613. {
  614. unsigned short temp_short;
  615. /*--------------------------------------------------------------------------+
  616. | Write the PowerPC440 EP PCI Configuration regs.
  617. | Enable PowerPC440 EP to be a master on the PCI bus (PMM).
  618. | Enable PowerPC440 EP to act as a PCI memory target (PTM).
  619. +--------------------------------------------------------------------------*/
  620. pci_read_config_word(0, PCI_COMMAND, &temp_short);
  621. pci_write_config_word(0, PCI_COMMAND,
  622. temp_short | PCI_COMMAND_MASTER |
  623. PCI_COMMAND_MEMORY);
  624. }
  625. #endif
  626. /*************************************************************************
  627. * is_pci_host
  628. *
  629. * This routine is called to determine if a pci scan should be
  630. * performed. With various hardware environments (especially cPCI and
  631. * PPMC) it's insufficient to depend on the state of the arbiter enable
  632. * bit in the strap register, or generic host/adapter assumptions.
  633. *
  634. * Rather than hard-code a bad assumption in the general 440 code, the
  635. * 440 pci code requires the board to decide at runtime.
  636. *
  637. * Return 0 for adapter mode, non-zero for host (monarch) mode.
  638. *
  639. *
  640. ************************************************************************/
  641. #if defined(CONFIG_PCI)
  642. int is_pci_host(struct pci_controller *hose)
  643. {
  644. /* Korat is always configured as host. */
  645. return (1);
  646. }
  647. #endif
  648. #if defined(CONFIG_POST)
  649. /*
  650. * Returns 1 if keys pressed to start the power-on long-running tests
  651. * Called from board_init_f().
  652. */
  653. int post_hotkeys_pressed(void)
  654. {
  655. return 0; /* No hotkeys supported */
  656. }
  657. #endif