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