korat.c 22 KB

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