korat.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802
  1. /*
  2. * (C) Copyright 2007-2009
  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[CONFIG_SYS_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 *) CONFIG_SYS_CPLD_BASE + 0x05,
  45. in_8((u8 *) CONFIG_SYS_CPLD_BASE + 0x05) | 0x80);
  46. } else {
  47. out_8((u8 *) CONFIG_SYS_CPLD_BASE + 0x05,
  48. in_8((u8 *) CONFIG_SYS_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 < CONFIG_SYS_KORAT_MAN_RESET_MS; ++mscount) {
  61. udelay(1000);
  62. if (gpio_read_in_bit(CONFIG_SYS_GPIO_RESET_PRESSED_)) {
  63. /* This call does not return. */
  64. korat_branch_absolute(
  65. CONFIG_SYS_FLASH1_TOP - 2 * CONFIG_ENV_SECT_SIZE - 4);
  66. }
  67. }
  68. korat_buzzer(1);
  69. while (!gpio_read_in_bit(CONFIG_SYS_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 *) CONFIG_SYS_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(CONFIG_SYS_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 *) CONFIG_SYS_CPLD_BASE + 0x03,
  112. in_8((u8 *) CONFIG_SYS_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(CONFIG_SYS_GPIO_PHY0_FIBER_SEL + eth, 1);
  118. gpio_write_bit(CONFIG_SYS_GPIO_SFP0_TX_EN_ + eth, 0);
  119. }
  120. }
  121. /* enable Ethernet: set GPIO45 and GPIO46 to 1 */
  122. gpio_write_bit(CONFIG_SYS_GPIO_PHY0_EN, 1);
  123. gpio_write_bit(CONFIG_SYS_GPIO_PHY1_EN, 1);
  124. /* Wait 1 ms, then enable Fiber signal detect to PHYs. */
  125. udelay(1000);
  126. out_8((u8 *) CONFIG_SYS_CPLD_BASE + 0x03,
  127. in_8((u8 *) CONFIG_SYS_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 = CONFIG_SYS_FLASH0_SIZE;
  157. info->sector_count = CONFIG_SYS_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 CONFIG_SYS_FLASH0_SIZE == 0x01000000
  172. info->device_id2 = 0x2101;
  173. #elif CONFIG_SYS_FLASH0_SIZE == 0x04000000
  174. info->device_id2 = 0x2301;
  175. #else
  176. #error Unable to set device_id2 for current CONFIG_SYS_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 - CONFIG_SYS_FLASH0_SIZE;
  304. char const *const act = getenv("usbact");
  305. char const *const usbcf = getenv("korat_usbcf");
  306. /*
  307. * Re-do FLASH1 sizing and adjust flash start and offset.
  308. */
  309. gd->bd->bi_flashstart = CONFIG_SYS_FLASH1_TOP - flash1_size;
  310. gd->bd->bi_flashoffset = 0;
  311. mtdcr(ebccfga, pb1cr);
  312. pbcr = mfdcr(ebccfgd);
  313. size_val = ffs(flash1_size) - 21;
  314. pbcr = (pbcr & 0x0001ffff) | gd->bd->bi_flashstart | (size_val << 17);
  315. mtdcr(ebccfga, pb1cr);
  316. mtdcr(ebccfgd, pbcr);
  317. /*
  318. * Re-check to get correct base address
  319. */
  320. flash_get_size(gd->bd->bi_flashstart, 0);
  321. /*
  322. * Re-do FLASH1 sizing and adjust flash offset to reserve space for
  323. * environment
  324. */
  325. gd->bd->bi_flashoffset =
  326. CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SECT_SIZE - CONFIG_SYS_FLASH1_ADDR;
  327. mtdcr(ebccfga, pb1cr);
  328. pbcr = mfdcr(ebccfgd);
  329. size_val = ffs(gd->bd->bi_flashsize - CONFIG_SYS_FLASH0_SIZE) - 21;
  330. pbcr = (pbcr & 0x0001ffff) | gd->bd->bi_flashstart | (size_val << 17);
  331. mtdcr(ebccfga, pb1cr);
  332. mtdcr(ebccfgd, pbcr);
  333. /* Monitor protection ON by default */
  334. #if defined(CONFIG_KORAT_PERMANENT)
  335. (void)flash_protect(FLAG_PROTECT_SET, CONFIG_SYS_MONITOR_BASE,
  336. CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN - 1,
  337. flash_info + 1);
  338. #else
  339. (void)flash_protect(FLAG_PROTECT_SET, CONFIG_SYS_MONITOR_BASE,
  340. CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN - 1,
  341. flash_info);
  342. #endif
  343. /* Env protection ON by default */
  344. (void)flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR,
  345. CONFIG_ENV_ADDR + CONFIG_ENV_SECT_SIZE - 1,
  346. flash_info);
  347. (void)flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR_REDUND,
  348. CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SECT_SIZE - 1,
  349. flash_info);
  350. /*
  351. * USB suff...
  352. */
  353. /*
  354. * Select the USB controller on the 440EPx ("ppc") or on the PCI bus
  355. * ("pci") for the CompactFlash.
  356. */
  357. if (usbcf != NULL && (strcmp(usbcf, "ppc") == 0)) {
  358. /*
  359. * If environment variable "usbcf" is defined and set to "ppc",
  360. * then connect the CompactFlash controller to the PowerPC USB
  361. * port.
  362. */
  363. printf("Attaching CompactFalsh controller to PPC USB\n");
  364. out_8((u8 *) CONFIG_SYS_CPLD_BASE + 0x02,
  365. in_8((u8 *) CONFIG_SYS_CPLD_BASE + 0x02) | 0x10);
  366. } else {
  367. if (usbcf != NULL && (strcmp(usbcf, "pci") != 0))
  368. printf("Warning: \"korat_usbcf\" is not set to a legal "
  369. "value (\"ppc\" or \"pci\")\n");
  370. printf("Attaching CompactFalsh controller to PCI USB\n");
  371. }
  372. if (act == NULL || strcmp(act, "hostdev") == 0) {
  373. /* SDR Setting */
  374. mfsdr(SDR0_PFC1, sdr0_pfc1);
  375. mfsdr(SDR0_USB2D0CR, usb2d0cr);
  376. mfsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  377. mfsdr(SDR0_USB2H0CR, usb2h0cr);
  378. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_XOCLK_MASK;
  379. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL;
  380. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_WDINT_MASK;
  381. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_WDINT_16BIT_30MHZ;
  382. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DVBUS_MASK;
  383. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PURDIS;
  384. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DWNSTR_MASK;
  385. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_HOST;
  386. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_UTMICN_MASK;
  387. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_HOST;
  388. /*
  389. * An 8-bit/60MHz interface is the only possible alternative
  390. * when connecting the Device to the PHY
  391. */
  392. usb2h0cr = usb2h0cr &~SDR0_USB2H0CR_WDINT_MASK;
  393. usb2h0cr = usb2h0cr | SDR0_USB2H0CR_WDINT_16BIT_30MHZ;
  394. /*
  395. * To enable the USB 2.0 Device function
  396. * through the UTMI interface
  397. */
  398. usb2d0cr = usb2d0cr &~SDR0_USB2D0CR_USB2DEV_EBC_SEL_MASK;
  399. usb2d0cr = usb2d0cr | SDR0_USB2D0CR_USB2DEV_SELECTION;
  400. sdr0_pfc1 = sdr0_pfc1 &~SDR0_PFC1_UES_MASK;
  401. sdr0_pfc1 = sdr0_pfc1 | SDR0_PFC1_UES_USB2D_SEL;
  402. mtsdr(SDR0_PFC1, sdr0_pfc1);
  403. mtsdr(SDR0_USB2D0CR, usb2d0cr);
  404. mtsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  405. mtsdr(SDR0_USB2H0CR, usb2h0cr);
  406. /* clear resets */
  407. udelay(1000);
  408. mtsdr(SDR0_SRST1, 0x00000000);
  409. udelay(1000);
  410. mtsdr(SDR0_SRST0, 0x00000000);
  411. printf("USB: Host(int phy) Device(ext phy)\n");
  412. } else if (strcmp(act, "dev") == 0) {
  413. /*-------------------PATCH-------------------------------*/
  414. mfsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  415. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_XOCLK_MASK;
  416. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL;
  417. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DVBUS_MASK;
  418. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PURDIS;
  419. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DWNSTR_MASK;
  420. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_HOST;
  421. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_UTMICN_MASK;
  422. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_HOST;
  423. mtsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  424. udelay(1000);
  425. mtsdr(SDR0_SRST1, 0x672c6000);
  426. udelay(1000);
  427. mtsdr(SDR0_SRST0, 0x00000080);
  428. udelay(1000);
  429. mtsdr(SDR0_SRST1, 0x60206000);
  430. *(unsigned int *)(0xe0000350) = 0x00000001;
  431. udelay(1000);
  432. mtsdr(SDR0_SRST1, 0x60306000);
  433. /*-------------------PATCH-------------------------------*/
  434. /* SDR Setting */
  435. mfsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  436. mfsdr(SDR0_USB2H0CR, usb2h0cr);
  437. mfsdr(SDR0_USB2D0CR, usb2d0cr);
  438. mfsdr(SDR0_PFC1, sdr0_pfc1);
  439. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_XOCLK_MASK;
  440. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL;
  441. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_WDINT_MASK;
  442. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_WDINT_8BIT_60MHZ;
  443. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DVBUS_MASK;
  444. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PUREN;
  445. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DWNSTR_MASK;
  446. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_DEV;
  447. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_UTMICN_MASK;
  448. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_DEV;
  449. usb2h0cr = usb2h0cr &~SDR0_USB2H0CR_WDINT_MASK;
  450. usb2h0cr = usb2h0cr | SDR0_USB2H0CR_WDINT_8BIT_60MHZ;
  451. usb2d0cr = usb2d0cr &~SDR0_USB2D0CR_USB2DEV_EBC_SEL_MASK;
  452. usb2d0cr = usb2d0cr | SDR0_USB2D0CR_EBC_SELECTION;
  453. sdr0_pfc1 = sdr0_pfc1 &~SDR0_PFC1_UES_MASK;
  454. sdr0_pfc1 = sdr0_pfc1 | SDR0_PFC1_UES_EBCHR_SEL;
  455. mtsdr(SDR0_USB2H0CR, usb2h0cr);
  456. mtsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  457. mtsdr(SDR0_USB2D0CR, usb2d0cr);
  458. mtsdr(SDR0_PFC1, sdr0_pfc1);
  459. /* clear resets */
  460. udelay(1000);
  461. mtsdr(SDR0_SRST1, 0x00000000);
  462. udelay(1000);
  463. mtsdr(SDR0_SRST0, 0x00000000);
  464. printf("USB: Device(int phy)\n");
  465. }
  466. mfsdr(SDR0_SRST1, reg); /* enable security/kasumi engines */
  467. reg &= ~(SDR0_SRST1_CRYP0 | SDR0_SRST1_KASU0);
  468. mtsdr(SDR0_SRST1, reg);
  469. /*
  470. * Clear PLB4A0_ACR[WRP]
  471. * This fix will make the MAL burst disabling patch for the Linux
  472. * EMAC driver obsolete.
  473. */
  474. reg = mfdcr(plb4_acr) & ~PLB4_ACR_WRP;
  475. mtdcr(plb4_acr, reg);
  476. set_serial_number();
  477. set_mac_addresses();
  478. gpio_write_bit(CONFIG_SYS_GPIO_ATMEGA_RESET_, 1);
  479. return 0;
  480. }
  481. int checkboard(void)
  482. {
  483. char const *const s = getenv("serial#");
  484. u8 const rev = in_8((u8 *) CONFIG_SYS_CPLD_BASE + 0);
  485. printf("Board: Korat, Rev. %X", rev);
  486. if (s)
  487. printf(", serial# %s", s);
  488. printf(".\n Ethernet PHY 0: ");
  489. if (gpio_read_out_bit(CONFIG_SYS_GPIO_PHY0_FIBER_SEL))
  490. printf("fiber");
  491. else
  492. printf("copper");
  493. printf(", PHY 1: ");
  494. if (gpio_read_out_bit(CONFIG_SYS_GPIO_PHY1_FIBER_SEL))
  495. printf("fiber");
  496. else
  497. printf("copper");
  498. printf(".\n");
  499. #if defined(CONFIG_KORAT_PERMANENT)
  500. printf(" Executing permanent copy of U-Boot.\n");
  501. #endif
  502. return 0;
  503. }
  504. #if defined(CONFIG_PCI) && defined(CONFIG_PCI_PNP)
  505. /*
  506. * Assign interrupts to PCI devices.
  507. */
  508. void korat_pci_fixup_irq(struct pci_controller *hose, pci_dev_t dev)
  509. {
  510. pci_hose_write_config_byte(hose, dev, PCI_INTERRUPT_LINE, VECNUM_EIRQ2);
  511. }
  512. #endif
  513. /*
  514. * pci_pre_init
  515. *
  516. * This routine is called just prior to registering the hose and gives
  517. * the board the opportunity to check things. Returning a value of zero
  518. * indicates that things are bad & PCI initialization should be aborted.
  519. *
  520. * Different boards may wish to customize the pci controller structure
  521. * (add regions, override default access routines, etc) or perform
  522. * certain pre-initialization actions.
  523. */
  524. #if defined(CONFIG_PCI)
  525. int pci_pre_init(struct pci_controller *hose)
  526. {
  527. unsigned long addr;
  528. /*
  529. * Set priority for all PLB3 devices to 0.
  530. * Set PLB3 arbiter to fair mode.
  531. */
  532. mfsdr(sdr_amp1, addr);
  533. mtsdr(sdr_amp1, (addr & 0x000000FF) | 0x0000FF00);
  534. addr = mfdcr(plb3_acr);
  535. mtdcr(plb3_acr, addr | 0x80000000);
  536. /*
  537. * Set priority for all PLB4 devices to 0.
  538. */
  539. mfsdr(sdr_amp0, addr);
  540. mtsdr(sdr_amp0, (addr & 0x000000FF) | 0x0000FF00);
  541. addr = mfdcr(plb4_acr) | 0xa0000000; /* Was 0x8---- */
  542. mtdcr(plb4_acr, addr);
  543. /*
  544. * Set Nebula PLB4 arbiter to fair mode.
  545. */
  546. /* Segment0 */
  547. addr = (mfdcr(plb0_acr) & ~plb0_acr_ppm_mask) | plb0_acr_ppm_fair;
  548. addr = (addr & ~plb0_acr_hbu_mask) | plb0_acr_hbu_enabled;
  549. addr = (addr & ~plb0_acr_rdp_mask) | plb0_acr_rdp_4deep;
  550. addr = (addr & ~plb0_acr_wrp_mask) | plb0_acr_wrp_2deep;
  551. mtdcr(plb0_acr, addr);
  552. /* Segment1 */
  553. addr = (mfdcr(plb1_acr) & ~plb1_acr_ppm_mask) | plb1_acr_ppm_fair;
  554. addr = (addr & ~plb1_acr_hbu_mask) | plb1_acr_hbu_enabled;
  555. addr = (addr & ~plb1_acr_rdp_mask) | plb1_acr_rdp_4deep;
  556. addr = (addr & ~plb1_acr_wrp_mask) | plb1_acr_wrp_2deep;
  557. mtdcr(plb1_acr, addr);
  558. #if defined(CONFIG_PCI_PNP)
  559. hose->fixup_irq = korat_pci_fixup_irq;
  560. #endif
  561. return 1;
  562. }
  563. #endif /* defined(CONFIG_PCI) */
  564. /*
  565. * pci_target_init
  566. *
  567. * The bootstrap configuration provides default settings for the pci
  568. * inbound map (PIM). But the bootstrap config choices are limited and
  569. * may not be sufficient for a given board.
  570. */
  571. #if defined(CONFIG_PCI) && defined(CONFIG_SYS_PCI_TARGET_INIT)
  572. void pci_target_init(struct pci_controller *hose)
  573. {
  574. /*
  575. * Set up Direct MMIO registers
  576. */
  577. /*
  578. * PowerPC440EPX PCI Master configuration.
  579. * Map one 1Gig range of PLB/processor addresses to PCI memory space.
  580. * PLB address 0x80000000-0xBFFFFFFF
  581. * ==> PCI address 0x80000000-0xBFFFFFFF
  582. * Use byte reversed out routines to handle endianess.
  583. * Make this region non-prefetchable.
  584. */
  585. out32r(PCIX0_PMM0MA, 0x00000000); /* PMM0 Mask/Attribute */
  586. /* - disabled b4 setting */
  587. out32r(PCIX0_PMM0LA, CONFIG_SYS_PCI_MEMBASE); /* PMM0 Local Address */
  588. out32r(PCIX0_PMM0PCILA,
  589. CONFIG_SYS_PCI_MEMBASE); /* PMM0 PCI Low Address */
  590. out32r(PCIX0_PMM0PCIHA, 0x00000000); /* PMM0 PCI High Address */
  591. out32r(PCIX0_PMM0MA, 0xE0000001); /* 512M + No prefetching, */
  592. /* and enable region */
  593. out32r(PCIX0_PMM1MA, 0x00000000); /* PMM0 Mask/Attribute */
  594. /* - disabled b4 setting */
  595. out32r(PCIX0_PMM1LA,
  596. CONFIG_SYS_PCI_MEMBASE + 0x20000000); /* PMM0 Local Address */
  597. out32r(PCIX0_PMM1PCILA,
  598. CONFIG_SYS_PCI_MEMBASE + 0x20000000); /* PMM0 PCI Low Address */
  599. out32r(PCIX0_PMM1PCIHA, 0x00000000); /* PMM0 PCI High Address */
  600. out32r(PCIX0_PMM1MA, 0xE0000001); /* 512M + No prefetching, */
  601. /* and enable region */
  602. out32r(PCIX0_PTM1MS, 0x00000001); /* Memory Size/Attribute */
  603. out32r(PCIX0_PTM1LA, 0); /* Local Addr. Reg */
  604. out32r(PCIX0_PTM2MS, 0); /* Memory Size/Attribute */
  605. out32r(PCIX0_PTM2LA, 0); /* Local Addr. Reg */
  606. /*
  607. * Set up Configuration registers
  608. */
  609. /* Program the board's subsystem id/vendor id */
  610. pci_write_config_word(0, PCI_SUBSYSTEM_VENDOR_ID,
  611. CONFIG_SYS_PCI_SUBSYS_VENDORID);
  612. pci_write_config_word(0, PCI_SUBSYSTEM_ID, CONFIG_SYS_PCI_SUBSYS_ID);
  613. /* Configure command register as bus master */
  614. pci_write_config_word(0, PCI_COMMAND, PCI_COMMAND_MASTER);
  615. /* 240nS PCI clock */
  616. pci_write_config_word(0, PCI_LATENCY_TIMER, 1);
  617. /* No error reporting */
  618. pci_write_config_word(0, PCI_ERREN, 0);
  619. pci_write_config_dword(0, PCI_BRDGOPT2, 0x00000101);
  620. /*
  621. * Set up Configuration registers for on-board NEC uPD720101 USB
  622. * controller.
  623. */
  624. pci_write_config_dword(PCI_BDF(0x0, 0xC, 0x0), 0xE4, 0x00000020);
  625. }
  626. #endif /* defined(CONFIG_PCI) && defined(CONFIG_SYS_PCI_TARGET_INIT) */
  627. #if defined(CONFIG_PCI) && defined(CONFIG_SYS_PCI_MASTER_INIT)
  628. void pci_master_init(struct pci_controller *hose)
  629. {
  630. unsigned short temp_short;
  631. /*
  632. * Write the PowerPC440 EP PCI Configuration regs.
  633. * Enable PowerPC440 EP to be a master on the PCI bus (PMM).
  634. * Enable PowerPC440 EP to act as a PCI memory target (PTM).
  635. */
  636. pci_read_config_word(0, PCI_COMMAND, &temp_short);
  637. pci_write_config_word(0, PCI_COMMAND,
  638. temp_short | PCI_COMMAND_MASTER |
  639. PCI_COMMAND_MEMORY);
  640. }
  641. #endif
  642. /*
  643. * is_pci_host
  644. *
  645. * This routine is called to determine if a pci scan should be
  646. * performed. With various hardware environments (especially cPCI and
  647. * PPMC) it's insufficient to depend on the state of the arbiter enable
  648. * bit in the strap register, or generic host/adapter assumptions.
  649. *
  650. * Rather than hard-code a bad assumption in the general 440 code, the
  651. * 440 pci code requires the board to decide at runtime.
  652. *
  653. * Return 0 for adapter mode, non-zero for host (monarch) mode.
  654. */
  655. #if defined(CONFIG_PCI)
  656. int is_pci_host(struct pci_controller *hose)
  657. {
  658. /* Korat is always configured as host. */
  659. return (1);
  660. }
  661. #endif /* defined(CONFIG_PCI) */
  662. #if defined(CONFIG_POST)
  663. /*
  664. * Returns 1 if keys pressed to start the power-on long-running tests
  665. * Called from board_init_f().
  666. */
  667. int post_hotkeys_pressed(void)
  668. {
  669. return 0; /* No hotkeys supported */
  670. }
  671. #endif /* CONFIG_POST */
  672. #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
  673. void ft_board_setup(void *blob, bd_t *bd)
  674. {
  675. u32 val[4];
  676. int rc;
  677. ft_cpu_setup(blob, bd);
  678. /* Fixup NOR mapping */
  679. val[0] = 1; /* chip select number */
  680. val[1] = 0; /* always 0 */
  681. val[2] = gd->bd->bi_flashstart;
  682. val[3] = gd->bd->bi_flashsize - CONFIG_SYS_FLASH0_SIZE;
  683. rc = fdt_find_and_setprop(blob, "/plb/opb/ebc", "ranges",
  684. val, sizeof(val), 1);
  685. if (rc)
  686. printf("Unable to update property NOR mapping, err=%s\n",
  687. fdt_strerror(rc));
  688. }
  689. #endif /* defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) */