lwmon5.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. /*
  2. * (C) Copyright 2007
  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. DECLARE_GLOBAL_DATA_PTR;
  27. extern flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS]; /* info for FLASH chips */
  28. ulong flash_get_size(ulong base, int banknum);
  29. int misc_init_r_kbd(void);
  30. int board_early_init_f(void)
  31. {
  32. u32 sdr0_pfc1, sdr0_pfc2;
  33. u32 reg;
  34. /* PLB Write pipelining disabled. Denali Core workaround */
  35. mtdcr(PLB4A0_ACR, 0xDE000000);
  36. mtdcr(PLB4A1_ACR, 0xDE000000);
  37. /*--------------------------------------------------------------------
  38. * Setup the interrupt controller polarities, triggers, etc.
  39. *-------------------------------------------------------------------*/
  40. mtdcr(UIC0SR, 0xffffffff); /* clear all. if write with 1 then the status is cleared */
  41. mtdcr(UIC0ER, 0x00000000); /* disable all */
  42. mtdcr(UIC0CR, 0x00000000); /* we have not critical interrupts at the moment */
  43. mtdcr(UIC0PR, 0xFFBFF1EF); /* Adjustment of the polarity */
  44. mtdcr(UIC0TR, 0x00000900); /* per ref-board manual */
  45. mtdcr(UIC0VR, 0x00000000); /* int31 highest, base=0x000 is within DDRAM */
  46. mtdcr(UIC0SR, 0xffffffff); /* clear all */
  47. mtdcr(UIC1SR, 0xffffffff); /* clear all */
  48. mtdcr(UIC1ER, 0x00000000); /* disable all */
  49. mtdcr(UIC1CR, 0x00000000); /* all non-critical */
  50. mtdcr(UIC1PR, 0xFFFFC6A5); /* Adjustment of the polarity */
  51. mtdcr(UIC1TR, 0x60000040); /* per ref-board manual */
  52. mtdcr(UIC1VR, 0x00000000); /* int31 highest, base=0x000 is within DDRAM */
  53. mtdcr(UIC1SR, 0xffffffff); /* clear all */
  54. mtdcr(UIC2SR, 0xffffffff); /* clear all */
  55. mtdcr(UIC2ER, 0x00000000); /* disable all */
  56. mtdcr(UIC2CR, 0x00000000); /* all non-critical */
  57. mtdcr(UIC2PR, 0x27C00000); /* Adjustment of the polarity */
  58. mtdcr(UIC2TR, 0x3C000000); /* per ref-board manual */
  59. mtdcr(UIC2VR, 0x00000000); /* int31 highest, base=0x000 is within DDRAM */
  60. mtdcr(UIC2SR, 0xffffffff); /* clear all */
  61. /* Trace Pins are disabled. SDR0_PFC0 Register */
  62. mtsdr(SDR0_PFC0, 0x0);
  63. /* select Ethernet pins */
  64. mfsdr(SDR0_PFC1, sdr0_pfc1);
  65. /* SMII via ZMII */
  66. sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_SELECT_MASK) |
  67. SDR0_PFC1_SELECT_CONFIG_6;
  68. mfsdr(SDR0_PFC2, sdr0_pfc2);
  69. sdr0_pfc2 = (sdr0_pfc2 & ~SDR0_PFC2_SELECT_MASK) |
  70. SDR0_PFC2_SELECT_CONFIG_6;
  71. /* enable SPI (SCP) */
  72. sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_SIS_MASK) | SDR0_PFC1_SIS_SCP_SEL;
  73. mtsdr(SDR0_PFC2, sdr0_pfc2);
  74. mtsdr(SDR0_PFC1, sdr0_pfc1);
  75. mtsdr(SDR0_PFC4, 0x80000000);
  76. /* PCI arbiter disabled */
  77. /* PCI Host Configuration disbaled */
  78. mfsdr(SDR0_PCI0, reg);
  79. reg = 0;
  80. mtsdr(SDR0_PCI0, 0x00000000 | reg);
  81. gpio_write_bit(CONFIG_SYS_GPIO_FLASH_WP, 1);
  82. #if CONFIG_POST & CONFIG_SYS_POST_BSPEC1
  83. gpio_write_bit(CONFIG_SYS_GPIO_HIGHSIDE, 1);
  84. reg = 0; /* reuse as counter */
  85. out_be32((void *)CONFIG_SYS_DSPIC_TEST_ADDR,
  86. in_be32((void *)CONFIG_SYS_DSPIC_TEST_ADDR)
  87. & ~CONFIG_SYS_DSPIC_TEST_MASK);
  88. while (!gpio_read_in_bit(CONFIG_SYS_GPIO_DSPIC_READY) && reg++ < 1000) {
  89. udelay(1000);
  90. }
  91. gpio_write_bit(CONFIG_SYS_GPIO_HIGHSIDE, 0);
  92. if (gpio_read_in_bit(CONFIG_SYS_GPIO_DSPIC_READY)) {
  93. /* set "boot error" flag */
  94. out_be32((void *)CONFIG_SYS_DSPIC_TEST_ADDR,
  95. in_be32((void *)CONFIG_SYS_DSPIC_TEST_ADDR) |
  96. CONFIG_SYS_DSPIC_TEST_MASK);
  97. }
  98. #endif
  99. /*
  100. * Reset PHY's:
  101. * The PHY's need a 2nd reset pulse, since the MDIO address is latched
  102. * upon reset, and with the first reset upon powerup, the addresses are
  103. * not latched reliable, since the IRQ line is multiplexed with an
  104. * MDIO address. A 2nd reset at this time will make sure, that the
  105. * correct address is latched.
  106. */
  107. gpio_write_bit(CONFIG_SYS_GPIO_PHY0_RST, 1);
  108. gpio_write_bit(CONFIG_SYS_GPIO_PHY1_RST, 1);
  109. udelay(1000);
  110. gpio_write_bit(CONFIG_SYS_GPIO_PHY0_RST, 0);
  111. gpio_write_bit(CONFIG_SYS_GPIO_PHY1_RST, 0);
  112. udelay(1000);
  113. gpio_write_bit(CONFIG_SYS_GPIO_PHY0_RST, 1);
  114. gpio_write_bit(CONFIG_SYS_GPIO_PHY1_RST, 1);
  115. return 0;
  116. }
  117. /*---------------------------------------------------------------------------+
  118. | misc_init_r.
  119. +---------------------------------------------------------------------------*/
  120. int misc_init_r(void)
  121. {
  122. u32 pbcr;
  123. int size_val = 0;
  124. u32 reg;
  125. unsigned long usb2d0cr = 0;
  126. unsigned long usb2phy0cr, usb2h0cr = 0;
  127. unsigned long sdr0_pfc1;
  128. /*
  129. * FLASH stuff...
  130. */
  131. /* Re-do sizing to get full correct info */
  132. /* adjust flash start and offset */
  133. gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
  134. gd->bd->bi_flashoffset = 0;
  135. mfebc(PB0CR, pbcr);
  136. switch (gd->bd->bi_flashsize) {
  137. case 1 << 20:
  138. size_val = 0;
  139. break;
  140. case 2 << 20:
  141. size_val = 1;
  142. break;
  143. case 4 << 20:
  144. size_val = 2;
  145. break;
  146. case 8 << 20:
  147. size_val = 3;
  148. break;
  149. case 16 << 20:
  150. size_val = 4;
  151. break;
  152. case 32 << 20:
  153. size_val = 5;
  154. break;
  155. case 64 << 20:
  156. size_val = 6;
  157. break;
  158. case 128 << 20:
  159. size_val = 7;
  160. break;
  161. }
  162. pbcr = (pbcr & 0x0001ffff) | gd->bd->bi_flashstart | (size_val << 17);
  163. mtebc(PB0CR, pbcr);
  164. /*
  165. * Re-check to get correct base address
  166. */
  167. flash_get_size(gd->bd->bi_flashstart, 0);
  168. /* Monitor protection ON by default */
  169. (void)flash_protect(FLAG_PROTECT_SET,
  170. -CONFIG_SYS_MONITOR_LEN,
  171. 0xffffffff,
  172. &flash_info[1]);
  173. /* Env protection ON by default */
  174. (void)flash_protect(FLAG_PROTECT_SET,
  175. CONFIG_ENV_ADDR_REDUND,
  176. CONFIG_ENV_ADDR_REDUND + 2*CONFIG_ENV_SECT_SIZE - 1,
  177. &flash_info[1]);
  178. /*
  179. * USB suff...
  180. */
  181. /* SDR Setting */
  182. mfsdr(SDR0_PFC1, sdr0_pfc1);
  183. mfsdr(SDR0_USB0, usb2d0cr);
  184. mfsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  185. mfsdr(SDR0_USB2H0CR, usb2h0cr);
  186. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_XOCLK_MASK;
  187. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL; /*0*/
  188. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_WDINT_MASK;
  189. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_WDINT_16BIT_30MHZ; /*1*/
  190. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DVBUS_MASK;
  191. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PURDIS; /*0*/
  192. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DWNSTR_MASK;
  193. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_HOST; /*1*/
  194. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_UTMICN_MASK;
  195. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_HOST; /*1*/
  196. /* An 8-bit/60MHz interface is the only possible alternative
  197. when connecting the Device to the PHY */
  198. usb2h0cr = usb2h0cr &~SDR0_USB2H0CR_WDINT_MASK;
  199. usb2h0cr = usb2h0cr | SDR0_USB2H0CR_WDINT_16BIT_30MHZ; /*1*/
  200. mtsdr(SDR0_PFC1, sdr0_pfc1);
  201. mtsdr(SDR0_USB0, usb2d0cr);
  202. mtsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  203. mtsdr(SDR0_USB2H0CR, usb2h0cr);
  204. /*
  205. * Clear resets
  206. */
  207. udelay (1000);
  208. mtsdr(SDR0_SRST1, 0x00000000);
  209. udelay (1000);
  210. mtsdr(SDR0_SRST0, 0x00000000);
  211. printf("USB: Host(int phy) Device(ext phy)\n");
  212. /*
  213. * Clear PLB4A0_ACR[WRP]
  214. * This fix will make the MAL burst disabling patch for the Linux
  215. * EMAC driver obsolete.
  216. */
  217. reg = mfdcr(PLB4A0_ACR) & ~PLB4Ax_ACR_WRP_MASK;
  218. mtdcr(PLB4A0_ACR, reg);
  219. /*
  220. * Init matrix keyboard
  221. */
  222. misc_init_r_kbd();
  223. return 0;
  224. }
  225. int checkboard(void)
  226. {
  227. char *s = getenv("serial#");
  228. printf("Board: lwmon5");
  229. if (s != NULL) {
  230. puts(", serial# ");
  231. puts(s);
  232. }
  233. putc('\n');
  234. return (0);
  235. }
  236. void hw_watchdog_reset(void)
  237. {
  238. int val;
  239. #if defined(CONFIG_WD_MAX_RATE)
  240. unsigned long long ct = get_ticks();
  241. /*
  242. * Don't allow watch-dog triggering more frequently than
  243. * the predefined value CONFIG_WD_MAX_RATE [ticks].
  244. */
  245. if (ct >= gd->wdt_last) {
  246. if ((ct - gd->wdt_last) < CONFIG_WD_MAX_RATE)
  247. return;
  248. } else {
  249. /* Time base counter had been reset */
  250. if (((unsigned long long)(-1) - gd->wdt_last + ct) <
  251. CONFIG_WD_MAX_RATE)
  252. return;
  253. }
  254. gd->wdt_last = get_ticks();
  255. #endif
  256. /*
  257. * Toggle watchdog output
  258. */
  259. val = gpio_read_out_bit(CONFIG_SYS_GPIO_WATCHDOG) == 0 ? 1 : 0;
  260. gpio_write_bit(CONFIG_SYS_GPIO_WATCHDOG, val);
  261. }
  262. int do_eeprom_wp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  263. {
  264. if (argc < 2)
  265. return cmd_usage(cmdtp);
  266. if ((strcmp(argv[1], "on") == 0))
  267. gpio_write_bit(CONFIG_SYS_GPIO_EEPROM_EXT_WP, 1);
  268. else if ((strcmp(argv[1], "off") == 0))
  269. gpio_write_bit(CONFIG_SYS_GPIO_EEPROM_EXT_WP, 0);
  270. else
  271. return cmd_usage(cmdtp);
  272. return 0;
  273. }
  274. U_BOOT_CMD(
  275. eepromwp, 2, 0, do_eeprom_wp,
  276. "eeprom write protect off/on",
  277. "<on|off> - enable (on) or disable (off) I2C EEPROM write protect"
  278. );
  279. #if defined(CONFIG_VIDEO)
  280. #include <video_fb.h>
  281. #include <mb862xx.h>
  282. extern GraphicDevice mb862xx;
  283. static const gdc_regs init_regs [] =
  284. {
  285. {0x0100, 0x00000f00},
  286. {0x0020, 0x801401df},
  287. {0x0024, 0x00000000},
  288. {0x0028, 0x00000000},
  289. {0x002c, 0x00000000},
  290. {0x0110, 0x00000000},
  291. {0x0114, 0x00000000},
  292. {0x0118, 0x01df0280},
  293. {0x0004, 0x031f0000},
  294. {0x0008, 0x027f027f},
  295. {0x000c, 0x015f028f},
  296. {0x0010, 0x020c0000},
  297. {0x0014, 0x01df01ea},
  298. {0x0018, 0x00000000},
  299. {0x001c, 0x01e00280},
  300. {0x0100, 0x80010f00},
  301. {0x0, 0x0}
  302. };
  303. const gdc_regs *board_get_regs (void)
  304. {
  305. return init_regs;
  306. }
  307. /* Returns Lime base address */
  308. unsigned int board_video_init (void)
  309. {
  310. /*
  311. * Reset Lime controller
  312. */
  313. gpio_write_bit(CONFIG_SYS_GPIO_LIME_S, 1);
  314. udelay(500);
  315. gpio_write_bit(CONFIG_SYS_GPIO_LIME_RST, 1);
  316. mb862xx.winSizeX = 640;
  317. mb862xx.winSizeY = 480;
  318. mb862xx.gdfBytesPP = 2;
  319. mb862xx.gdfIndex = GDF_15BIT_555RGB;
  320. return CONFIG_SYS_LIME_BASE_0;
  321. }
  322. #define DEFAULT_BRIGHTNESS 0x64
  323. static void board_backlight_brightness(int brightness)
  324. {
  325. if (brightness > 0) {
  326. /* pwm duty, lamp on */
  327. out_be32((void *)(CONFIG_SYS_FPGA_BASE_0 + 0x00000024), brightness);
  328. out_be32((void *)(CONFIG_SYS_FPGA_BASE_0 + 0x00000020), 0x701);
  329. } else {
  330. /* lamp off */
  331. out_be32((void *)(CONFIG_SYS_FPGA_BASE_0 + 0x00000024), 0x00);
  332. out_be32((void *)(CONFIG_SYS_FPGA_BASE_0 + 0x00000020), 0x00);
  333. }
  334. }
  335. void board_backlight_switch (int flag)
  336. {
  337. char * param;
  338. int rc;
  339. if (flag) {
  340. param = getenv("brightness");
  341. rc = param ? simple_strtol(param, NULL, 10) : -1;
  342. if (rc < 0)
  343. rc = DEFAULT_BRIGHTNESS;
  344. } else {
  345. rc = 0;
  346. }
  347. board_backlight_brightness(rc);
  348. }
  349. #if defined(CONFIG_CONSOLE_EXTRA_INFO)
  350. /*
  351. * Return text to be printed besides the logo.
  352. */
  353. void video_get_info_str (int line_number, char *info)
  354. {
  355. if (line_number == 1) {
  356. strcpy (info, " Board: Lwmon5 (Liebherr Elektronik GmbH)");
  357. } else {
  358. info [0] = '\0';
  359. }
  360. }
  361. #endif
  362. #endif /* CONFIG_VIDEO */
  363. void board_reset(void)
  364. {
  365. gpio_write_bit(CONFIG_SYS_GPIO_BOARD_RESET, 1);
  366. }