korat.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. /*
  2. * (C) Copyright 2007-2010
  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 <fdt_support.h>
  29. #include <i2c.h>
  30. #include <libfdt.h>
  31. #include <asm/ppc440.h>
  32. #include <asm/bitops.h>
  33. #include <asm/ppc4xx-gpio.h>
  34. #include <asm/io.h>
  35. #include <asm/ppc4xx-uic.h>
  36. #include <asm/processor.h>
  37. #include <asm/4xx_pci.h>
  38. DECLARE_GLOBAL_DATA_PTR;
  39. extern flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS]; /* info for FLASH chips */
  40. ulong flash_get_size(ulong base, int banknum);
  41. #if defined(CONFIG_KORAT_PERMANENT)
  42. void korat_buzzer(int const on)
  43. {
  44. if (on) {
  45. out_8((u8 *) CONFIG_SYS_CPLD_BASE + 0x05,
  46. in_8((u8 *) CONFIG_SYS_CPLD_BASE + 0x05) | 0x80);
  47. } else {
  48. out_8((u8 *) CONFIG_SYS_CPLD_BASE + 0x05,
  49. in_8((u8 *) CONFIG_SYS_CPLD_BASE + 0x05) & ~0x80);
  50. }
  51. }
  52. #endif
  53. int board_early_init_f(void)
  54. {
  55. uint32_t sdr0_pfc1, sdr0_pfc2;
  56. uint32_t reg;
  57. int eth;
  58. #if defined(CONFIG_KORAT_PERMANENT)
  59. unsigned mscount;
  60. extern void korat_branch_absolute(uint32_t addr);
  61. for (mscount = 0; mscount < CONFIG_SYS_KORAT_MAN_RESET_MS; ++mscount) {
  62. udelay(1000);
  63. if (gpio_read_in_bit(CONFIG_SYS_GPIO_RESET_PRESSED_)) {
  64. /* This call does not return. */
  65. korat_branch_absolute(
  66. CONFIG_SYS_FLASH1_TOP - 2 * CONFIG_ENV_SECT_SIZE - 4);
  67. }
  68. }
  69. korat_buzzer(1);
  70. while (!gpio_read_in_bit(CONFIG_SYS_GPIO_RESET_PRESSED_))
  71. udelay(1000);
  72. korat_buzzer(0);
  73. #endif
  74. mtdcr(EBC0_CFGADDR, EBC0_CFG);
  75. mtdcr(EBC0_CFGDATA, 0xb8400000);
  76. /*
  77. * Setup the interrupt controller polarities, triggers, etc.
  78. */
  79. mtdcr(UIC0SR, 0xffffffff); /* clear all */
  80. mtdcr(UIC0ER, 0x00000000); /* disable all */
  81. mtdcr(UIC0CR, 0x00000005); /* ATI & UIC1 crit are critical */
  82. mtdcr(UIC0PR, 0xfffff7ff); /* per ref-board manual */
  83. mtdcr(UIC0TR, 0x00000000); /* per ref-board manual */
  84. mtdcr(UIC0VR, 0x00000000); /* int31 highest, base=0x000 */
  85. mtdcr(UIC0SR, 0xffffffff); /* clear all */
  86. mtdcr(UIC1SR, 0xffffffff); /* clear all */
  87. mtdcr(UIC1ER, 0x00000000); /* disable all */
  88. mtdcr(UIC1CR, 0x00000000); /* all non-critical */
  89. mtdcr(UIC1PR, 0xffffffff); /* per ref-board manual */
  90. mtdcr(UIC1TR, 0x00000000); /* per ref-board manual */
  91. mtdcr(UIC1VR, 0x00000000); /* int31 highest, base=0x000 */
  92. mtdcr(UIC1SR, 0xffffffff); /* clear all */
  93. mtdcr(UIC2SR, 0xffffffff); /* clear all */
  94. mtdcr(UIC2ER, 0x00000000); /* disable all */
  95. mtdcr(UIC2CR, 0x00000000); /* all non-critical */
  96. mtdcr(UIC2PR, 0xffffffff); /* per ref-board manual */
  97. mtdcr(UIC2TR, 0x00000000); /* per ref-board manual */
  98. mtdcr(UIC2VR, 0x00000000); /* int31 highest, base=0x000 */
  99. mtdcr(UIC2SR, 0xffffffff); /* clear all */
  100. /*
  101. * Take sim card reader and CF controller out of reset. Also enable PHY
  102. * auto-detect until board-specific PHY resets are available.
  103. */
  104. out_8((u8 *) CONFIG_SYS_CPLD_BASE + 0x02, 0xC0);
  105. /* Configure the two Ethernet PHYs. For each PHY, configure for fiber
  106. * if the SFP module is present, and for copper if it is not present.
  107. */
  108. for (eth = 0; eth < 2; ++eth) {
  109. if (gpio_read_in_bit(CONFIG_SYS_GPIO_SFP0_PRESENT_ + eth)) {
  110. /* SFP module not present: configure PHY for copper. */
  111. /* Set PHY to autonegotate 10 MB, 100MB, or 1 GB */
  112. out_8((u8 *) CONFIG_SYS_CPLD_BASE + 0x03,
  113. in_8((u8 *) CONFIG_SYS_CPLD_BASE + 0x03) |
  114. 0x06 << (4 * eth));
  115. } else {
  116. /* SFP module present: configure PHY for fiber and
  117. enable output */
  118. gpio_write_bit(CONFIG_SYS_GPIO_PHY0_FIBER_SEL + eth, 1);
  119. gpio_write_bit(CONFIG_SYS_GPIO_SFP0_TX_EN_ + eth, 0);
  120. }
  121. }
  122. /* enable Ethernet: set GPIO45 and GPIO46 to 1 */
  123. gpio_write_bit(CONFIG_SYS_GPIO_PHY0_EN, 1);
  124. gpio_write_bit(CONFIG_SYS_GPIO_PHY1_EN, 1);
  125. /* Wait 1 ms, then enable Fiber signal detect to PHYs. */
  126. udelay(1000);
  127. out_8((u8 *) CONFIG_SYS_CPLD_BASE + 0x03,
  128. in_8((u8 *) CONFIG_SYS_CPLD_BASE + 0x03) | 0x88);
  129. /* select Ethernet (and optionally IIC1) pins */
  130. mfsdr(SDR0_PFC1, sdr0_pfc1);
  131. sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_SELECT_MASK) |
  132. SDR0_PFC1_SELECT_CONFIG_4;
  133. #ifdef CONFIG_I2C_MULTI_BUS
  134. sdr0_pfc1 |= ((sdr0_pfc1 & ~SDR0_PFC1_SIS_MASK) | SDR0_PFC1_SIS_IIC1_SEL);
  135. #endif
  136. mfsdr(SDR0_PFC2, sdr0_pfc2);
  137. sdr0_pfc2 = (sdr0_pfc2 & ~SDR0_PFC2_SELECT_MASK) |
  138. SDR0_PFC2_SELECT_CONFIG_4;
  139. mtsdr(SDR0_PFC2, sdr0_pfc2);
  140. mtsdr(SDR0_PFC1, sdr0_pfc1);
  141. /* PCI arbiter enabled */
  142. mfsdr(SDR0_PCI0, reg);
  143. mtsdr(SDR0_PCI0, 0x80000000 | reg);
  144. return 0;
  145. }
  146. /*
  147. * The boot flash on CS0 normally has its write-enable pin disabled, and so will
  148. * not respond to CFI commands. This routine therefore fills in the flash
  149. * information for the boot flash. (The flash at CS1 operates normally.)
  150. */
  151. ulong board_flash_get_legacy (ulong base, int banknum, flash_info_t * info)
  152. {
  153. uint32_t addr;
  154. int i;
  155. if (1 != banknum)
  156. return 0;
  157. info->size = CONFIG_SYS_FLASH0_SIZE;
  158. info->sector_count = CONFIG_SYS_FLASH0_SIZE / 0x20000;
  159. info->flash_id = 0x01000000;
  160. info->portwidth = 2;
  161. info->chipwidth = 2;
  162. info->buffer_size = 32;
  163. info->erase_blk_tout = 16384;
  164. info->write_tout = 2;
  165. info->buffer_write_tout = 5;
  166. info->vendor = 2;
  167. info->cmd_reset = 0x00F0;
  168. info->interface = 2;
  169. info->legacy_unlock = 0;
  170. info->manufacturer_id = 1;
  171. info->device_id = 0x007E;
  172. #if CONFIG_SYS_FLASH0_SIZE == 0x01000000
  173. info->device_id2 = 0x2101;
  174. #elif CONFIG_SYS_FLASH0_SIZE == 0x04000000
  175. info->device_id2 = 0x2301;
  176. #else
  177. #error Unable to set device_id2 for current CONFIG_SYS_FLASH0_SIZE
  178. #endif
  179. info->ext_addr = 0x0040;
  180. info->cfi_version = 0x3133;
  181. info->cfi_offset = 0x0055;
  182. info->addr_unlock1 = 0x00000555;
  183. info->addr_unlock2 = 0x000002AA;
  184. info->name = "CFI conformant";
  185. for (i = 0, addr = -info->size;
  186. i < info->sector_count;
  187. ++i, addr += 0x20000) {
  188. info->start[i] = addr;
  189. info->protect[i] = 0x00;
  190. }
  191. return 1;
  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_INFO_LENGTH + MAN_MAC_ADDR_LENGTH + 2];
  256. if (getenv("serial#"))
  257. return;
  258. if (!man_data_read_field(s, MAN_INFO_FIELD, MAN_INFO_LENGTH))
  259. return;
  260. s[MAN_INFO_LENGTH] = '-';
  261. if (!man_data_read_field(s + MAN_INFO_LENGTH + 1, MAN_MAC_ADDR_FIELD,
  262. MAN_MAC_ADDR_LENGTH))
  263. return;
  264. setenv("serial#", s);
  265. }
  266. static void set_mac_addresses(void)
  267. {
  268. /*
  269. * If the environmental variables "ethaddr" and/or "eth1addr" are not
  270. * set, try to set them from the manufacturer's information serial
  271. * EEPROM.
  272. */
  273. #if MAN_MAC_ADDR_LENGTH % 2 != 0
  274. #error MAN_MAC_ADDR_LENGTH must be an even number
  275. #endif
  276. char s[(3 * MAN_MAC_ADDR_LENGTH) / 2];
  277. char *src;
  278. char *dst;
  279. if (0 != getenv("ethaddr") && 0 != getenv("eth1addr"))
  280. return;
  281. if (0 == man_data_read_field(s + (MAN_MAC_ADDR_LENGTH / 2) - 1,
  282. MAN_MAC_ADDR_FIELD, MAN_MAC_ADDR_LENGTH))
  283. return;
  284. for (src = s + (MAN_MAC_ADDR_LENGTH / 2) - 1, dst = s; src != dst;) {
  285. *dst++ = *src++;
  286. *dst++ = *src++;
  287. *dst++ = ':';
  288. }
  289. if (0 == getenv("ethaddr"))
  290. setenv("ethaddr", s);
  291. if (0 == getenv("eth1addr")) {
  292. ++s[((3 * MAN_MAC_ADDR_LENGTH) / 2) - 2];
  293. setenv("eth1addr", s);
  294. }
  295. }
  296. int misc_init_r(void)
  297. {
  298. uint32_t pbcr;
  299. int size_val;
  300. uint32_t reg;
  301. unsigned long usb2d0cr = 0;
  302. unsigned long usb2phy0cr, usb2h0cr = 0;
  303. unsigned long sdr0_pfc1;
  304. uint32_t const flash1_size = gd->bd->bi_flashsize - CONFIG_SYS_FLASH0_SIZE;
  305. char const *const act = getenv("usbact");
  306. char const *const usbcf = getenv("korat_usbcf");
  307. /*
  308. * Re-do FLASH1 sizing and adjust flash start and offset.
  309. */
  310. gd->bd->bi_flashstart = CONFIG_SYS_FLASH1_TOP - flash1_size;
  311. gd->bd->bi_flashoffset = 0;
  312. mtdcr(EBC0_CFGADDR, PB1CR);
  313. pbcr = mfdcr(EBC0_CFGDATA);
  314. size_val = ffs(flash1_size) - 21;
  315. pbcr = (pbcr & 0x0001ffff) | gd->bd->bi_flashstart | (size_val << 17);
  316. mtdcr(EBC0_CFGADDR, PB1CR);
  317. mtdcr(EBC0_CFGDATA, pbcr);
  318. /*
  319. * Re-check to get correct base address
  320. */
  321. flash_get_size(gd->bd->bi_flashstart, 0);
  322. /*
  323. * Re-do FLASH1 sizing and adjust flash offset to reserve space for
  324. * environment
  325. */
  326. gd->bd->bi_flashoffset =
  327. CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SECT_SIZE - CONFIG_SYS_FLASH1_ADDR;
  328. mtdcr(EBC0_CFGADDR, PB1CR);
  329. pbcr = mfdcr(EBC0_CFGDATA);
  330. size_val = ffs(gd->bd->bi_flashsize - CONFIG_SYS_FLASH0_SIZE) - 21;
  331. pbcr = (pbcr & 0x0001ffff) | gd->bd->bi_flashstart | (size_val << 17);
  332. mtdcr(EBC0_CFGADDR, PB1CR);
  333. mtdcr(EBC0_CFGDATA, pbcr);
  334. /* Monitor protection ON by default */
  335. #if defined(CONFIG_KORAT_PERMANENT)
  336. (void)flash_protect(FLAG_PROTECT_SET, CONFIG_SYS_MONITOR_BASE,
  337. CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN - 1,
  338. flash_info + 1);
  339. #else
  340. (void)flash_protect(FLAG_PROTECT_SET, CONFIG_SYS_MONITOR_BASE,
  341. CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN - 1,
  342. flash_info);
  343. #endif
  344. /* Env protection ON by default */
  345. (void)flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR,
  346. CONFIG_ENV_ADDR + CONFIG_ENV_SECT_SIZE - 1,
  347. flash_info);
  348. (void)flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR_REDUND,
  349. CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SECT_SIZE - 1,
  350. flash_info);
  351. /*
  352. * USB suff...
  353. */
  354. /*
  355. * Select the USB controller on the 440EPx ("ppc") or on the PCI bus
  356. * ("pci") for the CompactFlash.
  357. */
  358. if (usbcf != NULL && (strcmp(usbcf, "ppc") == 0)) {
  359. /*
  360. * If environment variable "usbcf" is defined and set to "ppc",
  361. * then connect the CompactFlash controller to the PowerPC USB
  362. * port.
  363. */
  364. printf("Attaching CompactFlash controller to PPC USB\n");
  365. out_8((u8 *) CONFIG_SYS_CPLD_BASE + 0x02,
  366. in_8((u8 *) CONFIG_SYS_CPLD_BASE + 0x02) | 0x10);
  367. } else {
  368. if (usbcf != NULL && (strcmp(usbcf, "pci") != 0))
  369. printf("Warning: \"korat_usbcf\" is not set to a legal "
  370. "value (\"ppc\" or \"pci\")\n");
  371. printf("Attaching CompactFlash controller to PCI USB\n");
  372. }
  373. if (act == NULL || strcmp(act, "hostdev") == 0) {
  374. /* SDR Setting */
  375. mfsdr(SDR0_PFC1, sdr0_pfc1);
  376. mfsdr(SDR0_USB2D0CR, usb2d0cr);
  377. mfsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  378. mfsdr(SDR0_USB2H0CR, usb2h0cr);
  379. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_XOCLK_MASK;
  380. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL;
  381. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_WDINT_MASK;
  382. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_WDINT_16BIT_30MHZ;
  383. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DVBUS_MASK;
  384. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PURDIS;
  385. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DWNSTR_MASK;
  386. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_HOST;
  387. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_UTMICN_MASK;
  388. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_HOST;
  389. /*
  390. * An 8-bit/60MHz interface is the only possible alternative
  391. * when connecting the Device to the PHY
  392. */
  393. usb2h0cr = usb2h0cr &~SDR0_USB2H0CR_WDINT_MASK;
  394. usb2h0cr = usb2h0cr | SDR0_USB2H0CR_WDINT_16BIT_30MHZ;
  395. /*
  396. * To enable the USB 2.0 Device function
  397. * through the UTMI interface
  398. */
  399. usb2d0cr = usb2d0cr &~SDR0_USB2D0CR_USB2DEV_EBC_SEL_MASK;
  400. usb2d0cr = usb2d0cr | SDR0_USB2D0CR_USB2DEV_SELECTION;
  401. sdr0_pfc1 = sdr0_pfc1 &~SDR0_PFC1_UES_MASK;
  402. sdr0_pfc1 = sdr0_pfc1 | SDR0_PFC1_UES_USB2D_SEL;
  403. mtsdr(SDR0_PFC1, sdr0_pfc1);
  404. mtsdr(SDR0_USB2D0CR, usb2d0cr);
  405. mtsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  406. mtsdr(SDR0_USB2H0CR, usb2h0cr);
  407. /* clear resets */
  408. udelay(1000);
  409. mtsdr(SDR0_SRST1, 0x00000000);
  410. udelay(1000);
  411. mtsdr(SDR0_SRST0, 0x00000000);
  412. printf("USB: Host(int phy) Device(ext phy)\n");
  413. } else if (strcmp(act, "dev") == 0) {
  414. /*-------------------PATCH-------------------------------*/
  415. mfsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  416. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_XOCLK_MASK;
  417. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL;
  418. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DVBUS_MASK;
  419. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PURDIS;
  420. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DWNSTR_MASK;
  421. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_HOST;
  422. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_UTMICN_MASK;
  423. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_HOST;
  424. mtsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  425. udelay(1000);
  426. mtsdr(SDR0_SRST1, 0x672c6000);
  427. udelay(1000);
  428. mtsdr(SDR0_SRST0, 0x00000080);
  429. udelay(1000);
  430. mtsdr(SDR0_SRST1, 0x60206000);
  431. *(unsigned int *)(0xe0000350) = 0x00000001;
  432. udelay(1000);
  433. mtsdr(SDR0_SRST1, 0x60306000);
  434. /*-------------------PATCH-------------------------------*/
  435. /* SDR Setting */
  436. mfsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  437. mfsdr(SDR0_USB2H0CR, usb2h0cr);
  438. mfsdr(SDR0_USB2D0CR, usb2d0cr);
  439. mfsdr(SDR0_PFC1, sdr0_pfc1);
  440. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_XOCLK_MASK;
  441. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL;
  442. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_WDINT_MASK;
  443. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_WDINT_8BIT_60MHZ;
  444. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DVBUS_MASK;
  445. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PUREN;
  446. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DWNSTR_MASK;
  447. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_DEV;
  448. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_UTMICN_MASK;
  449. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_DEV;
  450. usb2h0cr = usb2h0cr &~SDR0_USB2H0CR_WDINT_MASK;
  451. usb2h0cr = usb2h0cr | SDR0_USB2H0CR_WDINT_8BIT_60MHZ;
  452. usb2d0cr = usb2d0cr &~SDR0_USB2D0CR_USB2DEV_EBC_SEL_MASK;
  453. usb2d0cr = usb2d0cr | SDR0_USB2D0CR_EBC_SELECTION;
  454. sdr0_pfc1 = sdr0_pfc1 &~SDR0_PFC1_UES_MASK;
  455. sdr0_pfc1 = sdr0_pfc1 | SDR0_PFC1_UES_EBCHR_SEL;
  456. mtsdr(SDR0_USB2H0CR, usb2h0cr);
  457. mtsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  458. mtsdr(SDR0_USB2D0CR, usb2d0cr);
  459. mtsdr(SDR0_PFC1, sdr0_pfc1);
  460. /* clear resets */
  461. udelay(1000);
  462. mtsdr(SDR0_SRST1, 0x00000000);
  463. udelay(1000);
  464. mtsdr(SDR0_SRST0, 0x00000000);
  465. printf("USB: Device(int phy)\n");
  466. }
  467. mfsdr(SDR0_SRST1, reg); /* enable security/kasumi engines */
  468. reg &= ~(SDR0_SRST1_CRYP0 | SDR0_SRST1_KASU0);
  469. mtsdr(SDR0_SRST1, reg);
  470. /*
  471. * Clear PLB4A0_ACR[WRP]
  472. * This fix will make the MAL burst disabling patch for the Linux
  473. * EMAC driver obsolete.
  474. */
  475. reg = mfdcr(PLB4A0_ACR) & ~PLB4Ax_ACR_WRP_MASK;
  476. mtdcr(PLB4A0_ACR, reg);
  477. set_serial_number();
  478. set_mac_addresses();
  479. gpio_write_bit(CONFIG_SYS_GPIO_ATMEGA_RESET_, 1);
  480. return 0;
  481. }
  482. int checkboard(void)
  483. {
  484. char const *const s = getenv("serial#");
  485. u8 const rev = in_8((u8 *) CONFIG_SYS_CPLD_BASE + 0);
  486. printf("Board: Korat, Rev. %X", rev);
  487. if (s)
  488. printf(", serial# %s", s);
  489. printf(".\n Ethernet PHY 0: ");
  490. if (gpio_read_out_bit(CONFIG_SYS_GPIO_PHY0_FIBER_SEL))
  491. printf("fiber");
  492. else
  493. printf("copper");
  494. printf(", PHY 1: ");
  495. if (gpio_read_out_bit(CONFIG_SYS_GPIO_PHY1_FIBER_SEL))
  496. printf("fiber");
  497. else
  498. printf("copper");
  499. printf(".\n");
  500. #if defined(CONFIG_KORAT_PERMANENT)
  501. printf(" Executing permanent copy of U-Boot.\n");
  502. #endif
  503. return 0;
  504. }
  505. #if defined(CONFIG_PCI) && defined(CONFIG_PCI_PNP)
  506. /*
  507. * Assign interrupts to PCI devices.
  508. */
  509. void board_pci_fixup_irq(struct pci_controller *hose, pci_dev_t dev)
  510. {
  511. pci_hose_write_config_byte(hose, dev, PCI_INTERRUPT_LINE, VECNUM_EIRQ2);
  512. }
  513. #endif
  514. /*
  515. * pci_target_init
  516. *
  517. * The bootstrap configuration provides default settings for the pci
  518. * inbound map (PIM). But the bootstrap config choices are limited and
  519. * may not be sufficient for a given board.
  520. */
  521. #if defined(CONFIG_PCI) && defined(CONFIG_SYS_PCI_TARGET_INIT)
  522. void pci_target_init(struct pci_controller *hose)
  523. {
  524. /* First do 440EP(x) common setup */
  525. __pci_target_init(hose);
  526. /*
  527. * Set up Configuration registers for on-board NEC uPD720101 USB
  528. * controller.
  529. */
  530. pci_write_config_dword(PCI_BDF(0x0, 0xC, 0x0), 0xE4, 0x00000020);
  531. }
  532. #endif /* defined(CONFIG_PCI) && defined(CONFIG_SYS_PCI_TARGET_INIT) */
  533. #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
  534. void ft_board_setup(void *blob, bd_t *bd)
  535. {
  536. u32 val[4];
  537. int rc;
  538. ft_cpu_setup(blob, bd);
  539. /* Fixup NOR mapping */
  540. val[0] = 1; /* chip select number */
  541. val[1] = 0; /* always 0 */
  542. val[2] = gd->bd->bi_flashstart;
  543. val[3] = gd->bd->bi_flashsize - CONFIG_SYS_FLASH0_SIZE;
  544. rc = fdt_find_and_setprop(blob, "/plb/opb/ebc", "ranges",
  545. val, sizeof(val), 1);
  546. if (rc)
  547. printf("Unable to update property NOR mapping, err=%s\n",
  548. fdt_strerror(rc));
  549. }
  550. #endif /* defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) */