lwmon5.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. /*
  2. * (C) Copyright 2007-2010
  3. * Stefan Roese, DENX Software Engineering, sr@denx.de.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  18. * MA 02111-1307 USA
  19. */
  20. #include <common.h>
  21. #include <command.h>
  22. #include <asm/ppc440.h>
  23. #include <asm/processor.h>
  24. #include <asm/ppc4xx-gpio.h>
  25. #include <asm/io.h>
  26. #include <post.h>
  27. #include <flash.h>
  28. #include <mtd/cfi_flash.h>
  29. DECLARE_GLOBAL_DATA_PTR;
  30. static phys_addr_t lwmon5_cfi_flash_bank_addr[2] = CONFIG_SYS_FLASH_BANKS_LIST;
  31. ulong flash_get_size(ulong base, int banknum);
  32. int misc_init_r_kbd(void);
  33. int board_early_init_f(void)
  34. {
  35. u32 sdr0_pfc1, sdr0_pfc2;
  36. u32 reg;
  37. /* PLB Write pipelining disabled. Denali Core workaround */
  38. mtdcr(PLB4A0_ACR, 0xDE000000);
  39. mtdcr(PLB4A1_ACR, 0xDE000000);
  40. /*--------------------------------------------------------------------
  41. * Setup the interrupt controller polarities, triggers, etc.
  42. *-------------------------------------------------------------------*/
  43. mtdcr(UIC0SR, 0xffffffff); /* clear all. if write with 1 then the status is cleared */
  44. mtdcr(UIC0ER, 0x00000000); /* disable all */
  45. mtdcr(UIC0CR, 0x00000000); /* we have not critical interrupts at the moment */
  46. mtdcr(UIC0PR, 0xFFBFF1EF); /* Adjustment of the polarity */
  47. mtdcr(UIC0TR, 0x00000900); /* per ref-board manual */
  48. mtdcr(UIC0VR, 0x00000000); /* int31 highest, base=0x000 is within DDRAM */
  49. mtdcr(UIC0SR, 0xffffffff); /* clear all */
  50. mtdcr(UIC1SR, 0xffffffff); /* clear all */
  51. mtdcr(UIC1ER, 0x00000000); /* disable all */
  52. mtdcr(UIC1CR, 0x00000000); /* all non-critical */
  53. mtdcr(UIC1PR, 0xFFFFC6A5); /* Adjustment of the polarity */
  54. mtdcr(UIC1TR, 0x60000040); /* per ref-board manual */
  55. mtdcr(UIC1VR, 0x00000000); /* int31 highest, base=0x000 is within DDRAM */
  56. mtdcr(UIC1SR, 0xffffffff); /* clear all */
  57. mtdcr(UIC2SR, 0xffffffff); /* clear all */
  58. mtdcr(UIC2ER, 0x00000000); /* disable all */
  59. mtdcr(UIC2CR, 0x00000000); /* all non-critical */
  60. mtdcr(UIC2PR, 0x27C00000); /* Adjustment of the polarity */
  61. mtdcr(UIC2TR, 0x3C000000); /* per ref-board manual */
  62. mtdcr(UIC2VR, 0x00000000); /* int31 highest, base=0x000 is within DDRAM */
  63. mtdcr(UIC2SR, 0xffffffff); /* clear all */
  64. /* Trace Pins are disabled. SDR0_PFC0 Register */
  65. mtsdr(SDR0_PFC0, 0x0);
  66. /* select Ethernet pins */
  67. mfsdr(SDR0_PFC1, sdr0_pfc1);
  68. /* SMII via ZMII */
  69. sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_SELECT_MASK) |
  70. SDR0_PFC1_SELECT_CONFIG_6;
  71. mfsdr(SDR0_PFC2, sdr0_pfc2);
  72. sdr0_pfc2 = (sdr0_pfc2 & ~SDR0_PFC2_SELECT_MASK) |
  73. SDR0_PFC2_SELECT_CONFIG_6;
  74. /* enable SPI (SCP) */
  75. sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_SIS_MASK) | SDR0_PFC1_SIS_SCP_SEL;
  76. mtsdr(SDR0_PFC2, sdr0_pfc2);
  77. mtsdr(SDR0_PFC1, sdr0_pfc1);
  78. mtsdr(SDR0_PFC4, 0x80000000);
  79. /* PCI arbiter disabled */
  80. /* PCI Host Configuration disbaled */
  81. mfsdr(SDR0_PCI0, reg);
  82. reg = 0;
  83. mtsdr(SDR0_PCI0, 0x00000000 | reg);
  84. gpio_write_bit(CONFIG_SYS_GPIO_FLASH_WP, 1);
  85. #if CONFIG_POST & CONFIG_SYS_POST_BSPEC1
  86. /* enable the LSB transmitter */
  87. gpio_write_bit(CONFIG_SYS_GPIO_LSB_ENABLE, 1);
  88. /* enable the CAN transmitter */
  89. gpio_write_bit(CONFIG_SYS_GPIO_CAN_ENABLE, 1);
  90. reg = 0; /* reuse as counter */
  91. out_be32((void *)CONFIG_SYS_DSPIC_TEST_ADDR,
  92. in_be32((void *)CONFIG_SYS_DSPIC_TEST_ADDR)
  93. & ~CONFIG_SYS_DSPIC_TEST_MASK);
  94. while (gpio_read_in_bit(CONFIG_SYS_GPIO_DSPIC_READY) && reg++ < 1000) {
  95. udelay(1000);
  96. }
  97. if (gpio_read_in_bit(CONFIG_SYS_GPIO_DSPIC_READY)) {
  98. /* set "boot error" flag */
  99. out_be32((void *)CONFIG_SYS_DSPIC_TEST_ADDR,
  100. in_be32((void *)CONFIG_SYS_DSPIC_TEST_ADDR) |
  101. CONFIG_SYS_DSPIC_TEST_MASK);
  102. }
  103. #endif
  104. /*
  105. * Reset PHY's:
  106. * The PHY's need a 2nd reset pulse, since the MDIO address is latched
  107. * upon reset, and with the first reset upon powerup, the addresses are
  108. * not latched reliable, since the IRQ line is multiplexed with an
  109. * MDIO address. A 2nd reset at this time will make sure, that the
  110. * correct address is latched.
  111. */
  112. gpio_write_bit(CONFIG_SYS_GPIO_PHY0_RST, 1);
  113. gpio_write_bit(CONFIG_SYS_GPIO_PHY1_RST, 1);
  114. udelay(1000);
  115. gpio_write_bit(CONFIG_SYS_GPIO_PHY0_RST, 0);
  116. gpio_write_bit(CONFIG_SYS_GPIO_PHY1_RST, 0);
  117. udelay(1000);
  118. gpio_write_bit(CONFIG_SYS_GPIO_PHY0_RST, 1);
  119. gpio_write_bit(CONFIG_SYS_GPIO_PHY1_RST, 1);
  120. return 0;
  121. }
  122. /*
  123. * Override weak default with board specific version
  124. */
  125. phys_addr_t cfi_flash_bank_addr(int bank)
  126. {
  127. return lwmon5_cfi_flash_bank_addr[bank];
  128. }
  129. /*
  130. * Override the weak default mapping function with a board specific one
  131. */
  132. u32 flash_get_bank_size(int cs, int idx)
  133. {
  134. return flash_info[idx].size;
  135. }
  136. int board_early_init_r(void)
  137. {
  138. u32 val0, val1;
  139. /*
  140. * lwmon5 is manufactured in 2 different board versions:
  141. * The lwmon5a board has 64MiB NOR flash instead of the
  142. * 128MiB of the original lwmon5. Unfortunately the CFI driver
  143. * will report 2 banks of 64MiB even for the smaller flash
  144. * chip, since the bank is mirrored. To fix this, we bring
  145. * one bank into CFI query mode and read its response. This
  146. * enables us to detect the real number of flash devices/
  147. * banks which will be used later on by the common CFI driver.
  148. */
  149. /* Put bank 0 into CFI command mode and read */
  150. out_be32((void *)CONFIG_SYS_FLASH0, 0x00980098);
  151. val0 = in_be32((void *)CONFIG_SYS_FLASH0 + FLASH_OFFSET_CFI_RESP);
  152. val1 = in_be32((void *)CONFIG_SYS_FLASH1 + FLASH_OFFSET_CFI_RESP);
  153. /* Reset flash again out of query mode */
  154. out_be32((void *)CONFIG_SYS_FLASH0, 0x00f000f0);
  155. /* When not identical, we have 2 different flash devices/banks */
  156. if (val0 != val1)
  157. return 0;
  158. /*
  159. * Now we're sure that we're running on a LWMON5a board with
  160. * only 64MiB NOR flash in one bank:
  161. *
  162. * Set flash base address and bank count for CFI driver probing.
  163. */
  164. cfi_flash_num_flash_banks = 1;
  165. lwmon5_cfi_flash_bank_addr[0] = CONFIG_SYS_FLASH0;
  166. return 0;
  167. }
  168. int misc_init_r(void)
  169. {
  170. u32 pbcr;
  171. int size_val = 0;
  172. u32 reg;
  173. unsigned long usb2d0cr = 0;
  174. unsigned long usb2phy0cr, usb2h0cr = 0;
  175. unsigned long sdr0_pfc1, sdr0_srst;
  176. /*
  177. * FLASH stuff...
  178. */
  179. /* Re-do sizing to get full correct info */
  180. /* adjust flash start and offset */
  181. gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
  182. gd->bd->bi_flashoffset = 0;
  183. mfebc(PB0CR, pbcr);
  184. size_val = ffs(gd->bd->bi_flashsize) - 21;
  185. pbcr = (pbcr & 0x0001ffff) | gd->bd->bi_flashstart | (size_val << 17);
  186. mtebc(PB0CR, pbcr);
  187. /*
  188. * Re-check to get correct base address
  189. */
  190. flash_get_size(gd->bd->bi_flashstart, 0);
  191. /* Monitor protection ON by default */
  192. flash_protect(FLAG_PROTECT_SET, -CONFIG_SYS_MONITOR_LEN, 0xffffffff,
  193. &flash_info[cfi_flash_num_flash_banks - 1]);
  194. /* Env protection ON by default */
  195. flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR_REDUND,
  196. CONFIG_ENV_ADDR_REDUND + 2 * CONFIG_ENV_SECT_SIZE - 1,
  197. &flash_info[cfi_flash_num_flash_banks - 1]);
  198. /*
  199. * USB suff...
  200. */
  201. /* Reset USB */
  202. /* Reset of USB2PHY0 must be active at least 10 us */
  203. mtsdr(SDR0_SRST0, SDR0_SRST0_USB2H | SDR0_SRST0_USB2D);
  204. udelay(2000);
  205. mtsdr(SDR0_SRST1, SDR0_SRST1_USB20PHY | SDR0_SRST1_USB2HUTMI |
  206. SDR0_SRST1_USB2HPHY | SDR0_SRST1_OPBA2 |
  207. SDR0_SRST1_PLB42OPB1 | SDR0_SRST1_OPB2PLB40);
  208. udelay(2000);
  209. /* Errata CHIP_6 */
  210. /* 1. Set internal PHY configuration */
  211. /* SDR Setting */
  212. mfsdr(SDR0_PFC1, sdr0_pfc1);
  213. mfsdr(SDR0_USB0, usb2d0cr);
  214. mfsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  215. mfsdr(SDR0_USB2H0CR, usb2h0cr);
  216. usb2phy0cr = usb2phy0cr & ~SDR0_USB2PHY0CR_XOCLK_MASK;
  217. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL; /*0*/
  218. usb2phy0cr = usb2phy0cr & ~SDR0_USB2PHY0CR_WDINT_MASK;
  219. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_WDINT_16BIT_30MHZ; /*1*/
  220. usb2phy0cr = usb2phy0cr & ~SDR0_USB2PHY0CR_DVBUS_MASK;
  221. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PUREN; /*1*/
  222. usb2phy0cr = usb2phy0cr & ~SDR0_USB2PHY0CR_DWNSTR_MASK;
  223. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_HOST; /*1*/
  224. usb2phy0cr = usb2phy0cr & ~SDR0_USB2PHY0CR_UTMICN_MASK;
  225. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_HOST; /*1*/
  226. /*
  227. * An 8-bit/60MHz interface is the only possible alternative
  228. * when connecting the Device to the PHY
  229. */
  230. usb2h0cr = usb2h0cr & ~SDR0_USB2H0CR_WDINT_MASK;
  231. usb2h0cr = usb2h0cr | SDR0_USB2H0CR_WDINT_16BIT_30MHZ; /*1*/
  232. mtsdr(SDR0_PFC1, sdr0_pfc1);
  233. mtsdr(SDR0_USB0, usb2d0cr);
  234. mtsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  235. mtsdr(SDR0_USB2H0CR, usb2h0cr);
  236. /* 2. De-assert internal PHY reset */
  237. mfsdr(SDR0_SRST1, sdr0_srst);
  238. sdr0_srst = sdr0_srst & ~SDR0_SRST1_USB20PHY;
  239. mtsdr(SDR0_SRST1, sdr0_srst);
  240. /* 3. Wait for more than 1 ms */
  241. udelay(2000);
  242. /* 4. De-assert USB 2.0 Host main reset */
  243. mfsdr(SDR0_SRST0, sdr0_srst);
  244. sdr0_srst = sdr0_srst &~ SDR0_SRST0_USB2H;
  245. mtsdr(SDR0_SRST0, sdr0_srst);
  246. udelay(1000);
  247. /* 5. De-assert reset of OPB2 cores */
  248. mfsdr(SDR0_SRST1, sdr0_srst);
  249. sdr0_srst = sdr0_srst &~ SDR0_SRST1_PLB42OPB1;
  250. sdr0_srst = sdr0_srst &~ SDR0_SRST1_OPB2PLB40;
  251. sdr0_srst = sdr0_srst &~ SDR0_SRST1_OPBA2;
  252. mtsdr(SDR0_SRST1, sdr0_srst);
  253. udelay(1000);
  254. /* 6. Set EHCI Configure FLAG */
  255. /* 7. Reassert internal PHY reset: */
  256. mtsdr(SDR0_SRST1, SDR0_SRST1_USB20PHY);
  257. udelay(1000);
  258. /*
  259. * Clear resets
  260. */
  261. mtsdr(SDR0_SRST1, 0x00000000);
  262. mtsdr(SDR0_SRST0, 0x00000000);
  263. printf("USB: Host(int phy) Device(ext phy)\n");
  264. /*
  265. * Clear PLB4A0_ACR[WRP]
  266. * This fix will make the MAL burst disabling patch for the Linux
  267. * EMAC driver obsolete.
  268. */
  269. reg = mfdcr(PLB4A0_ACR) & ~PLB4Ax_ACR_WRP_MASK;
  270. mtdcr(PLB4A0_ACR, reg);
  271. /*
  272. * Init matrix keyboard
  273. */
  274. misc_init_r_kbd();
  275. return 0;
  276. }
  277. int checkboard(void)
  278. {
  279. char *s = getenv("serial#");
  280. puts("Board: lwmon5");
  281. if (s != NULL) {
  282. puts(", serial# ");
  283. puts(s);
  284. }
  285. putc('\n');
  286. return (0);
  287. }
  288. void hw_watchdog_reset(void)
  289. {
  290. int val;
  291. #if defined(CONFIG_WD_MAX_RATE)
  292. unsigned long long ct = get_ticks();
  293. /*
  294. * Don't allow watch-dog triggering more frequently than
  295. * the predefined value CONFIG_WD_MAX_RATE [ticks].
  296. */
  297. if (ct >= gd->wdt_last) {
  298. if ((ct - gd->wdt_last) < CONFIG_WD_MAX_RATE)
  299. return;
  300. } else {
  301. /* Time base counter had been reset */
  302. if (((unsigned long long)(-1) - gd->wdt_last + ct) <
  303. CONFIG_WD_MAX_RATE)
  304. return;
  305. }
  306. gd->wdt_last = get_ticks();
  307. #endif
  308. /*
  309. * Toggle watchdog output
  310. */
  311. val = gpio_read_out_bit(CONFIG_SYS_GPIO_WATCHDOG) == 0 ? 1 : 0;
  312. gpio_write_bit(CONFIG_SYS_GPIO_WATCHDOG, val);
  313. }
  314. int do_eeprom_wp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  315. {
  316. if (argc < 2)
  317. return cmd_usage(cmdtp);
  318. if ((strcmp(argv[1], "on") == 0))
  319. gpio_write_bit(CONFIG_SYS_GPIO_EEPROM_EXT_WP, 1);
  320. else if ((strcmp(argv[1], "off") == 0))
  321. gpio_write_bit(CONFIG_SYS_GPIO_EEPROM_EXT_WP, 0);
  322. else
  323. return cmd_usage(cmdtp);
  324. return 0;
  325. }
  326. U_BOOT_CMD(
  327. eepromwp, 2, 0, do_eeprom_wp,
  328. "eeprom write protect off/on",
  329. "<on|off> - enable (on) or disable (off) I2C EEPROM write protect"
  330. );
  331. #if defined(CONFIG_VIDEO)
  332. #include <video_fb.h>
  333. #include <mb862xx.h>
  334. extern GraphicDevice mb862xx;
  335. static const gdc_regs init_regs [] = {
  336. { 0x0100, 0x00000f00 },
  337. { 0x0020, 0x801401df },
  338. { 0x0024, 0x00000000 },
  339. { 0x0028, 0x00000000 },
  340. { 0x002c, 0x00000000 },
  341. { 0x0110, 0x00000000 },
  342. { 0x0114, 0x00000000 },
  343. { 0x0118, 0x01df0280 },
  344. { 0x0004, 0x031f0000 },
  345. { 0x0008, 0x027f027f },
  346. { 0x000c, 0x015f028f },
  347. { 0x0010, 0x020c0000 },
  348. { 0x0014, 0x01df01ea },
  349. { 0x0018, 0x00000000 },
  350. { 0x001c, 0x01e00280 },
  351. { 0x0100, 0x80010f00 },
  352. { 0x0, 0x0 }
  353. };
  354. const gdc_regs *board_get_regs(void)
  355. {
  356. return init_regs;
  357. }
  358. /* Returns Lime base address */
  359. unsigned int board_video_init(void)
  360. {
  361. /*
  362. * Reset Lime controller
  363. */
  364. gpio_write_bit(CONFIG_SYS_GPIO_LIME_S, 1);
  365. udelay(500);
  366. gpio_write_bit(CONFIG_SYS_GPIO_LIME_RST, 1);
  367. mb862xx.winSizeX = 640;
  368. mb862xx.winSizeY = 480;
  369. mb862xx.gdfBytesPP = 2;
  370. mb862xx.gdfIndex = GDF_15BIT_555RGB;
  371. return CONFIG_SYS_LIME_BASE_0;
  372. }
  373. #define DEFAULT_BRIGHTNESS 0x64
  374. static void board_backlight_brightness(int brightness)
  375. {
  376. if (brightness > 0) {
  377. /* pwm duty, lamp on */
  378. out_be32((void *)(CONFIG_SYS_FPGA_BASE_0 + 0x00000024), brightness);
  379. out_be32((void *)(CONFIG_SYS_FPGA_BASE_0 + 0x00000020), 0x701);
  380. } else {
  381. /* lamp off */
  382. out_be32((void *)(CONFIG_SYS_FPGA_BASE_0 + 0x00000024), 0x00);
  383. out_be32((void *)(CONFIG_SYS_FPGA_BASE_0 + 0x00000020), 0x00);
  384. }
  385. }
  386. void board_backlight_switch(int flag)
  387. {
  388. char * param;
  389. int rc;
  390. if (flag) {
  391. param = getenv("brightness");
  392. rc = param ? simple_strtol(param, NULL, 10) : -1;
  393. if (rc < 0)
  394. rc = DEFAULT_BRIGHTNESS;
  395. } else {
  396. rc = 0;
  397. }
  398. board_backlight_brightness(rc);
  399. }
  400. #if defined(CONFIG_CONSOLE_EXTRA_INFO)
  401. /*
  402. * Return text to be printed besides the logo.
  403. */
  404. void video_get_info_str(int line_number, char *info)
  405. {
  406. if (line_number == 1)
  407. strcpy(info, " Board: Lwmon5 (Liebherr Elektronik GmbH)");
  408. else
  409. info [0] = '\0';
  410. }
  411. #endif /* CONFIG_CONSOLE_EXTRA_INFO */
  412. #endif /* CONFIG_VIDEO */
  413. void board_reset(void)
  414. {
  415. gpio_write_bit(CONFIG_SYS_GPIO_BOARD_RESET, 1);
  416. }