korat.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. /*
  2. * (C) Copyright 2007-2008
  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/gpio.h>
  29. #include <asm/processor.h>
  30. #include <asm-ppc/io.h>
  31. #include <i2c.h>
  32. #include <ppc440.h>
  33. DECLARE_GLOBAL_DATA_PTR;
  34. extern flash_info_t flash_info[CFG_MAX_FLASH_BANKS]; /* info for FLASH chips */
  35. ulong flash_get_size(ulong base, int banknum);
  36. int board_early_init_f(void)
  37. {
  38. u32 sdr0_pfc1, sdr0_pfc2;
  39. u32 reg;
  40. int eth;
  41. mtdcr(ebccfga, xbcfg);
  42. mtdcr(ebccfgd, 0xb8400000);
  43. /*--------------------------------------------------------------------
  44. * Setup the interrupt controller polarities, triggers, etc.
  45. *-------------------------------------------------------------------*/
  46. mtdcr(uic0sr, 0xffffffff); /* clear all */
  47. mtdcr(uic0er, 0x00000000); /* disable all */
  48. mtdcr(uic0cr, 0x00000005); /* ATI & UIC1 crit are critical */
  49. mtdcr(uic0pr, 0xfffff7ff); /* per ref-board manual */
  50. mtdcr(uic0tr, 0x00000000); /* per ref-board manual */
  51. mtdcr(uic0vr, 0x00000000); /* int31 highest, base=0x000 */
  52. mtdcr(uic0sr, 0xffffffff); /* clear all */
  53. mtdcr(uic1sr, 0xffffffff); /* clear all */
  54. mtdcr(uic1er, 0x00000000); /* disable all */
  55. mtdcr(uic1cr, 0x00000000); /* all non-critical */
  56. mtdcr(uic1pr, 0xffffffff); /* per ref-board manual */
  57. mtdcr(uic1tr, 0x00000000); /* per ref-board manual */
  58. mtdcr(uic1vr, 0x00000000); /* int31 highest, base=0x000 */
  59. mtdcr(uic1sr, 0xffffffff); /* clear all */
  60. mtdcr(uic2sr, 0xffffffff); /* clear all */
  61. mtdcr(uic2er, 0x00000000); /* disable all */
  62. mtdcr(uic2cr, 0x00000000); /* all non-critical */
  63. mtdcr(uic2pr, 0xffffffff); /* per ref-board manual */
  64. mtdcr(uic2tr, 0x00000000); /* per ref-board manual */
  65. mtdcr(uic2vr, 0x00000000); /* int31 highest, base=0x000 */
  66. mtdcr(uic2sr, 0xffffffff); /* clear all */
  67. /* take sim card reader and CF controller out of reset */
  68. out_8((u8 *) CFG_CPLD_BASE + 0x04, 0x80);
  69. /* Configure the two Ethernet PHYs. For each PHY, configure for fiber
  70. * if the SFP module is present, and for copper if it is not present.
  71. */
  72. for (eth = 0; eth < 2; ++eth) {
  73. if (gpio_read_in_bit(CFG_GPIO_SFP0_PRESENT_ + eth)) {
  74. /* SFP module not present: configure PHY for copper. */
  75. /* Set PHY to autonegotate 10 MB, 100MB, or 1 GB */
  76. out_8((u8 *) CFG_CPLD_BASE + 0x06,
  77. in_8((u8 *) CFG_CPLD_BASE + 0x06) |
  78. 0x06 << (4 * eth));
  79. } else {
  80. /* SFP module present: configure PHY for fiber and
  81. enable output */
  82. gpio_write_bit(CFG_GPIO_PHY0_FIBER_SEL + eth, 1);
  83. gpio_write_bit(CFG_GPIO_SFP0_TX_EN_ + eth, 0);
  84. }
  85. }
  86. /* enable Ethernet: set GPIO45 and GPIO46 to 1 */
  87. gpio_write_bit(CFG_GPIO_PHY0_EN, 1);
  88. gpio_write_bit(CFG_GPIO_PHY1_EN, 1);
  89. /* select Ethernet pins */
  90. mfsdr(SDR0_PFC1, sdr0_pfc1);
  91. sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_SELECT_MASK) |
  92. SDR0_PFC1_SELECT_CONFIG_4;
  93. mfsdr(SDR0_PFC2, sdr0_pfc2);
  94. sdr0_pfc2 = (sdr0_pfc2 & ~SDR0_PFC2_SELECT_MASK) |
  95. SDR0_PFC2_SELECT_CONFIG_4;
  96. mtsdr(SDR0_PFC2, sdr0_pfc2);
  97. mtsdr(SDR0_PFC1, sdr0_pfc1);
  98. /* PCI arbiter enabled */
  99. mfsdr(sdr_pci0, reg);
  100. mtsdr(sdr_pci0, 0x80000000 | reg);
  101. return 0;
  102. }
  103. static int man_data_read(unsigned int addr)
  104. {
  105. /*
  106. * Read an octet of data from address "addr" in the manufacturer's
  107. * information serial EEPROM, or -1 on error.
  108. */
  109. u8 data[2];
  110. if (0 != i2c_probe(MAN_DATA_EEPROM_ADDR) ||
  111. 0 != i2c_read(MAN_DATA_EEPROM_ADDR, addr, 1, data, 1)) {
  112. debug("man_data_read(0x%02X) failed\n", addr);
  113. return -1;
  114. }
  115. debug("man_info_read(0x%02X) returned 0x%02X\n", addr, data[0]);
  116. return data[0];
  117. }
  118. static unsigned int man_data_field_addr(unsigned int const field)
  119. {
  120. /*
  121. * The manufacturer's information serial EEPROM contains a sequence of
  122. * zero-delimited fields. Return the starting address of field "field",
  123. * or 0 on error.
  124. */
  125. unsigned addr, i;
  126. if (0 == field || 'A' != man_data_read(0) || '\0' != man_data_read(1))
  127. /* Only format "A" is currently supported */
  128. return 0;
  129. for (addr = 2, i = 1; i < field && addr < 256; ++addr) {
  130. if ('\0' == man_data_read(addr))
  131. ++i;
  132. }
  133. return (addr < 256) ? addr : 0;
  134. }
  135. static char *man_data_read_field(char s[], unsigned const field,
  136. unsigned const length)
  137. {
  138. /*
  139. * Place the null-terminated contents of field "field" of length
  140. * "length" from the manufacturer's information serial EEPROM into
  141. * string "s[length + 1]" and return a pointer to s, or return 0 on
  142. * error. In either case the original contents of s[] is not preserved.
  143. */
  144. unsigned addr, i;
  145. addr = man_data_field_addr(field);
  146. if (0 == addr || addr + length >= 255)
  147. return 0;
  148. for (i = 0; i < length; ++i) {
  149. int const c = man_data_read(addr++);
  150. if (c <= 0)
  151. return 0;
  152. s[i] = (char)c;
  153. }
  154. if (0 != man_data_read(addr))
  155. return 0;
  156. s[i] = '\0';
  157. return s;
  158. }
  159. static void set_serial_number(void)
  160. {
  161. /*
  162. * If the environmental variable "serial#" is not set, try to set it
  163. * from the manufacturer's information serial EEPROM.
  164. */
  165. char s[MAN_SERIAL_NO_LENGTH + 1];
  166. if (0 == getenv("serial#") &&
  167. 0 != man_data_read_field(s, MAN_SERIAL_NO_FIELD,
  168. MAN_SERIAL_NO_LENGTH))
  169. setenv("serial#", s);
  170. }
  171. static void set_mac_addresses(void)
  172. {
  173. /*
  174. * If the environmental variables "ethaddr" and/or "eth1addr" are not
  175. * set, try to set them from the manufacturer's information serial
  176. * EEPROM.
  177. */
  178. char s[MAN_MAC_ADDR_LENGTH + 1];
  179. if (0 != getenv("ethaddr") && 0 != getenv("eth1addr"))
  180. return;
  181. if (0 == man_data_read_field(s, MAN_MAC_ADDR_FIELD,
  182. MAN_MAC_ADDR_LENGTH))
  183. return;
  184. if (0 == getenv("ethaddr"))
  185. setenv("ethaddr", s);
  186. if (0 == getenv("eth1addr")) {
  187. ++s[MAN_MAC_ADDR_LENGTH - 1];
  188. setenv("eth1addr", s);
  189. }
  190. }
  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. 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. mtdcr(ebccfga, pb0cr);
  211. pbcr = mfdcr(ebccfgd);
  212. switch (gd->bd->bi_flashsize) {
  213. case 1 << 20:
  214. size_val = 0;
  215. break;
  216. case 2 << 20:
  217. size_val = 1;
  218. break;
  219. case 4 << 20:
  220. size_val = 2;
  221. break;
  222. case 8 << 20:
  223. size_val = 3;
  224. break;
  225. case 16 << 20:
  226. size_val = 4;
  227. break;
  228. case 32 << 20:
  229. size_val = 5;
  230. break;
  231. case 64 << 20:
  232. size_val = 6;
  233. break;
  234. case 128 << 20:
  235. size_val = 7;
  236. break;
  237. }
  238. pbcr = (pbcr & 0x0001ffff) | gd->bd->bi_flashstart | (size_val << 17);
  239. mtdcr(ebccfga, pb0cr);
  240. mtdcr(ebccfgd, pbcr);
  241. /*
  242. * Re-check to get correct base address
  243. */
  244. flash_get_size(gd->bd->bi_flashstart, 0);
  245. /* Monitor protection ON by default */
  246. (void)flash_protect(FLAG_PROTECT_SET, -CFG_MONITOR_LEN, 0xffffffff,
  247. &flash_info[0]);
  248. /* Env protection ON by default */
  249. (void)flash_protect(FLAG_PROTECT_SET,
  250. CFG_ENV_ADDR_REDUND,
  251. CFG_ENV_ADDR_REDUND + 2 * CFG_ENV_SECT_SIZE - 1,
  252. &flash_info[0]);
  253. /*
  254. * USB suff...
  255. */
  256. if (act == NULL || strcmp(act, "hostdev") == 0) {
  257. /* SDR Setting */
  258. mfsdr(SDR0_PFC1, sdr0_pfc1);
  259. mfsdr(SDR0_USB2D0CR, usb2d0cr);
  260. mfsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  261. mfsdr(SDR0_USB2H0CR, usb2h0cr);
  262. usb2phy0cr = usb2phy0cr & ~SDR0_USB2PHY0CR_XOCLK_MASK;
  263. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL; /*0 */
  264. usb2phy0cr = usb2phy0cr & ~SDR0_USB2PHY0CR_WDINT_MASK;
  265. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_WDINT_16BIT_30MHZ; /*1 */
  266. usb2phy0cr = usb2phy0cr & ~SDR0_USB2PHY0CR_DVBUS_MASK;
  267. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PURDIS; /*0 */
  268. usb2phy0cr = usb2phy0cr & ~SDR0_USB2PHY0CR_DWNSTR_MASK;
  269. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_HOST; /*1 */
  270. usb2phy0cr = usb2phy0cr & ~SDR0_USB2PHY0CR_UTMICN_MASK;
  271. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_HOST; /*1 */
  272. /* An 8-bit/60MHz interface is the only possible alternative
  273. when connecting the Device to the PHY */
  274. usb2h0cr = usb2h0cr & ~SDR0_USB2H0CR_WDINT_MASK;
  275. usb2h0cr = usb2h0cr | SDR0_USB2H0CR_WDINT_16BIT_30MHZ; /*1 */
  276. /* To enable the USB 2.0 Device function through the UTMI interface */
  277. usb2d0cr = usb2d0cr & ~SDR0_USB2D0CR_USB2DEV_EBC_SEL_MASK;
  278. usb2d0cr = usb2d0cr | SDR0_USB2D0CR_USB2DEV_SELECTION; /*1 */
  279. sdr0_pfc1 = sdr0_pfc1 & ~SDR0_PFC1_UES_MASK;
  280. sdr0_pfc1 = sdr0_pfc1 | SDR0_PFC1_UES_USB2D_SEL; /*0 */
  281. mtsdr(SDR0_PFC1, sdr0_pfc1);
  282. mtsdr(SDR0_USB2D0CR, usb2d0cr);
  283. mtsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  284. mtsdr(SDR0_USB2H0CR, usb2h0cr);
  285. /*clear resets */
  286. udelay(1000);
  287. mtsdr(SDR0_SRST1, 0x00000000);
  288. udelay(1000);
  289. mtsdr(SDR0_SRST0, 0x00000000);
  290. printf("USB: Host(int phy) Device(ext phy)\n");
  291. } else if (strcmp(act, "dev") == 0) {
  292. /*-------------------PATCH-------------------------------*/
  293. mfsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  294. usb2phy0cr = usb2phy0cr & ~SDR0_USB2PHY0CR_XOCLK_MASK;
  295. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL; /*0 */
  296. usb2phy0cr = usb2phy0cr & ~SDR0_USB2PHY0CR_DVBUS_MASK;
  297. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PURDIS; /*0 */
  298. usb2phy0cr = usb2phy0cr & ~SDR0_USB2PHY0CR_DWNSTR_MASK;
  299. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_HOST; /*1 */
  300. usb2phy0cr = usb2phy0cr & ~SDR0_USB2PHY0CR_UTMICN_MASK;
  301. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_HOST; /*1 */
  302. mtsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  303. udelay(1000);
  304. mtsdr(SDR0_SRST1, 0x672c6000);
  305. udelay(1000);
  306. mtsdr(SDR0_SRST0, 0x00000080);
  307. udelay(1000);
  308. mtsdr(SDR0_SRST1, 0x60206000);
  309. *(unsigned int *)(0xe0000350) = 0x00000001;
  310. udelay(1000);
  311. mtsdr(SDR0_SRST1, 0x60306000);
  312. /*-------------------PATCH-------------------------------*/
  313. /* SDR Setting */
  314. mfsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  315. mfsdr(SDR0_USB2H0CR, usb2h0cr);
  316. mfsdr(SDR0_USB2D0CR, usb2d0cr);
  317. mfsdr(SDR0_PFC1, sdr0_pfc1);
  318. usb2phy0cr = usb2phy0cr & ~SDR0_USB2PHY0CR_XOCLK_MASK;
  319. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL; /*0 */
  320. usb2phy0cr = usb2phy0cr & ~SDR0_USB2PHY0CR_WDINT_MASK;
  321. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_WDINT_8BIT_60MHZ; /*0 */
  322. usb2phy0cr = usb2phy0cr & ~SDR0_USB2PHY0CR_DVBUS_MASK;
  323. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PUREN; /*1 */
  324. usb2phy0cr = usb2phy0cr & ~SDR0_USB2PHY0CR_DWNSTR_MASK;
  325. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_DEV; /*0 */
  326. usb2phy0cr = usb2phy0cr & ~SDR0_USB2PHY0CR_UTMICN_MASK;
  327. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_DEV; /*0 */
  328. usb2h0cr = usb2h0cr & ~SDR0_USB2H0CR_WDINT_MASK;
  329. usb2h0cr = usb2h0cr | SDR0_USB2H0CR_WDINT_8BIT_60MHZ; /*0 */
  330. usb2d0cr = usb2d0cr & ~SDR0_USB2D0CR_USB2DEV_EBC_SEL_MASK;
  331. usb2d0cr = usb2d0cr | SDR0_USB2D0CR_EBC_SELECTION; /*0 */
  332. sdr0_pfc1 = sdr0_pfc1 & ~SDR0_PFC1_UES_MASK;
  333. sdr0_pfc1 = sdr0_pfc1 | SDR0_PFC1_UES_EBCHR_SEL; /*1 */
  334. mtsdr(SDR0_USB2H0CR, usb2h0cr);
  335. mtsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  336. mtsdr(SDR0_USB2D0CR, usb2d0cr);
  337. mtsdr(SDR0_PFC1, sdr0_pfc1);
  338. /*clear resets */
  339. udelay(1000);
  340. mtsdr(SDR0_SRST1, 0x00000000);
  341. udelay(1000);
  342. mtsdr(SDR0_SRST0, 0x00000000);
  343. printf("USB: Device(int phy)\n");
  344. }
  345. mfsdr(SDR0_SRST1, reg); /* enable security/kasumi engines */
  346. reg &= ~(SDR0_SRST1_CRYP0 | SDR0_SRST1_KASU0);
  347. mtsdr(SDR0_SRST1, reg);
  348. /*
  349. * Clear PLB4A0_ACR[WRP]
  350. * This fix will make the MAL burst disabling patch for the Linux
  351. * EMAC driver obsolete.
  352. */
  353. reg = mfdcr(plb4_acr) & ~PLB4_ACR_WRP;
  354. mtdcr(plb4_acr, reg);
  355. set_serial_number();
  356. set_mac_addresses();
  357. return 0;
  358. }
  359. int checkboard(void)
  360. {
  361. char const *const s = getenv("serial#");
  362. u8 const rev = in_8((u8 *) CFG_CPLD_BASE + 0);
  363. printf("Board: Korat, Rev. %X", rev);
  364. if (s != NULL)
  365. printf(", serial# %s", s);
  366. printf(", Ethernet PHY 0: ");
  367. if (gpio_read_out_bit(CFG_GPIO_PHY0_FIBER_SEL))
  368. printf("fiber");
  369. else
  370. printf("copper");
  371. printf(", PHY 1: ");
  372. if (gpio_read_out_bit(CFG_GPIO_PHY1_FIBER_SEL))
  373. printf("fiber");
  374. else
  375. printf("copper");
  376. printf(".\n");
  377. return (0);
  378. }
  379. #if defined(CFG_DRAM_TEST)
  380. int testdram(void)
  381. {
  382. unsigned long *mem = (unsigned long *)0;
  383. const unsigned long kend = (1024 / sizeof(unsigned long));
  384. unsigned long k, n;
  385. mtmsr(0);
  386. /* TODO: find correct size of SDRAM */
  387. for (k = 0; k < CFG_MBYTES_SDRAM;
  388. ++k, mem += (1024 / sizeof(unsigned long))) {
  389. if ((k & 1023) == 0)
  390. printf("%3d MB\r", k / 1024);
  391. memset(mem, 0xaaaaaaaa, 1024);
  392. for (n = 0; n < kend; ++n) {
  393. if (mem[n] != 0xaaaaaaaa) {
  394. printf("SDRAM test fails at: %08x\n",
  395. (uint) & mem[n]);
  396. return 1;
  397. }
  398. }
  399. memset(mem, 0x55555555, 1024);
  400. for (n = 0; n < kend; ++n) {
  401. if (mem[n] != 0x55555555) {
  402. printf("SDRAM test fails at: %08x\n",
  403. (uint) & mem[n]);
  404. return 1;
  405. }
  406. }
  407. }
  408. printf("SDRAM test passes\n");
  409. return 0;
  410. }
  411. #endif /* defined(CFG_DRAM_TEST) */
  412. /*************************************************************************
  413. * pci_pre_init
  414. *
  415. * This routine is called just prior to registering the hose and gives
  416. * the board the opportunity to check things. Returning a value of zero
  417. * indicates that things are bad & PCI initialization should be aborted.
  418. *
  419. * Different boards may wish to customize the pci controller structure
  420. * (add regions, override default access routines, etc) or perform
  421. * certain pre-initialization actions.
  422. *
  423. ************************************************************************/
  424. #if defined(CONFIG_PCI)
  425. int pci_pre_init(struct pci_controller *hose)
  426. {
  427. unsigned long addr;
  428. /*-------------------------------------------------------------------------+
  429. | Set priority for all PLB3 devices to 0.
  430. | Set PLB3 arbiter to fair mode.
  431. +-------------------------------------------------------------------------*/
  432. mfsdr(sdr_amp1, addr);
  433. mtsdr(sdr_amp1, (addr & 0x000000FF) | 0x0000FF00);
  434. addr = mfdcr(plb3_acr);
  435. mtdcr(plb3_acr, addr | 0x80000000);
  436. /*-------------------------------------------------------------------------+
  437. | Set priority for all PLB4 devices to 0.
  438. +-------------------------------------------------------------------------*/
  439. mfsdr(sdr_amp0, addr);
  440. mtsdr(sdr_amp0, (addr & 0x000000FF) | 0x0000FF00);
  441. addr = mfdcr(plb4_acr) | 0xa0000000; /* Was 0x8---- */
  442. mtdcr(plb4_acr, addr);
  443. /*-------------------------------------------------------------------------+
  444. | Set Nebula PLB4 arbiter to fair mode.
  445. +-------------------------------------------------------------------------*/
  446. /* Segment0 */
  447. addr = (mfdcr(plb0_acr) & ~plb0_acr_ppm_mask) | plb0_acr_ppm_fair;
  448. addr = (addr & ~plb0_acr_hbu_mask) | plb0_acr_hbu_enabled;
  449. addr = (addr & ~plb0_acr_rdp_mask) | plb0_acr_rdp_4deep;
  450. addr = (addr & ~plb0_acr_wrp_mask) | plb0_acr_wrp_2deep;
  451. mtdcr(plb0_acr, addr);
  452. /* Segment1 */
  453. addr = (mfdcr(plb1_acr) & ~plb1_acr_ppm_mask) | plb1_acr_ppm_fair;
  454. addr = (addr & ~plb1_acr_hbu_mask) | plb1_acr_hbu_enabled;
  455. addr = (addr & ~plb1_acr_rdp_mask) | plb1_acr_rdp_4deep;
  456. addr = (addr & ~plb1_acr_wrp_mask) | plb1_acr_wrp_2deep;
  457. mtdcr(plb1_acr, addr);
  458. return 1;
  459. }
  460. #endif /* defined(CONFIG_PCI) */
  461. /*************************************************************************
  462. * pci_target_init
  463. *
  464. * The bootstrap configuration provides default settings for the pci
  465. * inbound map (PIM). But the bootstrap config choices are limited and
  466. * may not be sufficient for a given board.
  467. *
  468. ************************************************************************/
  469. #if defined(CONFIG_PCI) && defined(CFG_PCI_TARGET_INIT)
  470. void pci_target_init(struct pci_controller *hose)
  471. {
  472. /*--------------------------------------------------------------------------+
  473. * Set up Direct MMIO registers
  474. *--------------------------------------------------------------------------*/
  475. /*--------------------------------------------------------------------------+
  476. | PowerPC440EPX PCI Master configuration.
  477. | Map one 1Gig range of PLB/processor addresses to PCI memory space.
  478. | PLB address 0xA0000000-0xDFFFFFFF ==> PCI address 0xA0000000-0xDFFFFFFF
  479. | Use byte reversed out routines to handle endianess.
  480. | Make this region non-prefetchable.
  481. +--------------------------------------------------------------------------*/
  482. out32r(PCIX0_PMM0MA, 0x00000000); /* PMM0 Mask/Attribute - disabled b4 setting */
  483. out32r(PCIX0_PMM0LA, CFG_PCI_MEMBASE); /* PMM0 Local Address */
  484. out32r(PCIX0_PMM0PCILA, CFG_PCI_MEMBASE); /* PMM0 PCI Low Address */
  485. out32r(PCIX0_PMM0PCIHA, 0x00000000); /* PMM0 PCI High Address */
  486. out32r(PCIX0_PMM0MA, 0xE0000001); /* 512M + No prefetching, and enable region */
  487. out32r(PCIX0_PMM1MA, 0x00000000); /* PMM0 Mask/Attribute - disabled b4 setting */
  488. out32r(PCIX0_PMM1LA, CFG_PCI_MEMBASE2); /* PMM0 Local Address */
  489. out32r(PCIX0_PMM1PCILA, CFG_PCI_MEMBASE2); /* PMM0 PCI Low Address */
  490. out32r(PCIX0_PMM1PCIHA, 0x00000000); /* PMM0 PCI High Address */
  491. out32r(PCIX0_PMM1MA, 0xE0000001); /* 512M + No prefetching, and enable region */
  492. out32r(PCIX0_PTM1MS, 0x00000001); /* Memory Size/Attribute */
  493. out32r(PCIX0_PTM1LA, 0); /* Local Addr. Reg */
  494. out32r(PCIX0_PTM2MS, 0); /* Memory Size/Attribute */
  495. out32r(PCIX0_PTM2LA, 0); /* Local Addr. Reg */
  496. /*--------------------------------------------------------------------------+
  497. * Set up Configuration registers
  498. *--------------------------------------------------------------------------*/
  499. /* Program the board's subsystem id/vendor id */
  500. pci_write_config_word(0, PCI_SUBSYSTEM_VENDOR_ID,
  501. CFG_PCI_SUBSYS_VENDORID);
  502. pci_write_config_word(0, PCI_SUBSYSTEM_ID, CFG_PCI_SUBSYS_ID);
  503. /* Configure command register as bus master */
  504. pci_write_config_word(0, PCI_COMMAND, PCI_COMMAND_MASTER);
  505. /* 240nS PCI clock */
  506. pci_write_config_word(0, PCI_LATENCY_TIMER, 1);
  507. /* No error reporting */
  508. pci_write_config_word(0, PCI_ERREN, 0);
  509. pci_write_config_dword(0, PCI_BRDGOPT2, 0x00000101);
  510. /*--------------------------------------------------------------------------+
  511. * Set up Configuration registers for on-board NEC uPD720101 USB controller
  512. *--------------------------------------------------------------------------*/
  513. pci_write_config_dword(PCI_BDF(0x0, 0xC, 0x0), 0xE4, 0x00000020);
  514. }
  515. #endif /* defined(CONFIG_PCI) && defined(CFG_PCI_TARGET_INIT) */
  516. /*************************************************************************
  517. * pci_master_init
  518. *
  519. ************************************************************************/
  520. #if defined(CONFIG_PCI) && defined(CFG_PCI_MASTER_INIT)
  521. void pci_master_init(struct pci_controller *hose)
  522. {
  523. unsigned short temp_short;
  524. /*--------------------------------------------------------------------------+
  525. | Write the PowerPC440 EP PCI Configuration regs.
  526. | Enable PowerPC440 EP to be a master on the PCI bus (PMM).
  527. | Enable PowerPC440 EP to act as a PCI memory target (PTM).
  528. +--------------------------------------------------------------------------*/
  529. pci_read_config_word(0, PCI_COMMAND, &temp_short);
  530. pci_write_config_word(0, PCI_COMMAND,
  531. temp_short | PCI_COMMAND_MASTER |
  532. PCI_COMMAND_MEMORY);
  533. }
  534. #endif
  535. /*************************************************************************
  536. * is_pci_host
  537. *
  538. * This routine is called to determine if a pci scan should be
  539. * performed. With various hardware environments (especially cPCI and
  540. * PPMC) it's insufficient to depend on the state of the arbiter enable
  541. * bit in the strap register, or generic host/adapter assumptions.
  542. *
  543. * Rather than hard-code a bad assumption in the general 440 code, the
  544. * 440 pci code requires the board to decide at runtime.
  545. *
  546. * Return 0 for adapter mode, non-zero for host (monarch) mode.
  547. *
  548. *
  549. ************************************************************************/
  550. #if defined(CONFIG_PCI)
  551. int is_pci_host(struct pci_controller *hose)
  552. {
  553. /* Korat is always configured as host. */
  554. return (1);
  555. }
  556. #endif
  557. #if defined(CONFIG_POST)
  558. /*
  559. * Returns 1 if keys pressed to start the power-on long-running tests
  560. * Called from board_init_f().
  561. */
  562. int post_hotkeys_pressed(void)
  563. {
  564. return 0; /* No hotkeys supported */
  565. }
  566. #endif