voh405.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. /*
  2. * (C) Copyright 2001-2004
  3. * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <asm/io.h>
  25. #include <asm/processor.h>
  26. #include <command.h>
  27. #include <malloc.h>
  28. /* ------------------------------------------------------------------------- */
  29. #if 0
  30. #define FPGA_DEBUG
  31. #endif
  32. extern void lxt971_no_sleep(void);
  33. /* fpga configuration data - gzip compressed and generated by bin2c */
  34. const unsigned char fpgadata[] =
  35. {
  36. #include "fpgadata.c"
  37. };
  38. /*
  39. * include common fpga code (for esd boards)
  40. */
  41. #include "../common/fpga.c"
  42. /* logo bitmap data - gzip compressed and generated by bin2c */
  43. unsigned char logo_bmp_320[] =
  44. {
  45. #include "logo_320_240_4bpp.c"
  46. };
  47. unsigned char logo_bmp_640[] =
  48. {
  49. #include "logo_640_480_24bpp.c"
  50. };
  51. /*
  52. * include common lcd code (for esd boards)
  53. */
  54. #include "../common/lcd.c"
  55. #include "../common/s1d13704_320_240_4bpp.h"
  56. #include "../common/s1d13806_320_240_4bpp.h"
  57. #include "../common/s1d13806_640_480_16bpp.h"
  58. int board_early_init_f (void)
  59. {
  60. /*
  61. * IRQ 0-15 405GP internally generated; active high; level sensitive
  62. * IRQ 16 405GP internally generated; active low; level sensitive
  63. * IRQ 17-24 RESERVED
  64. * IRQ 25 (EXT IRQ 0) CAN0; active low; level sensitive
  65. * IRQ 26 (EXT IRQ 1) SER0 ; active low; level sensitive
  66. * IRQ 27 (EXT IRQ 2) SER1; active low; level sensitive
  67. * IRQ 28 (EXT IRQ 3) FPGA 0; active low; level sensitive
  68. * IRQ 29 (EXT IRQ 4) FPGA 1; active low; level sensitive
  69. * IRQ 30 (EXT IRQ 5) PCI INTA; active low; level sensitive
  70. * IRQ 31 (EXT IRQ 6) COMPACT FLASH; active high; level sensitive
  71. */
  72. mtdcr(UIC0SR, 0xFFFFFFFF); /* clear all ints */
  73. mtdcr(UIC0ER, 0x00000000); /* disable all ints */
  74. mtdcr(UIC0CR, 0x00000000); /* set all to be non-critical*/
  75. mtdcr(UIC0PR, 0xFFFFFFB5); /* set int polarities */
  76. mtdcr(UIC0TR, 0x10000000); /* set int trigger levels */
  77. mtdcr(UIC0VCR, 0x00000001); /* set vect base=0,INT0 highest priority*/
  78. mtdcr(UIC0SR, 0xFFFFFFFF); /* clear all ints */
  79. /*
  80. * EBC Configuration Register: set ready timeout to 512 ebc-clks -> ca. 15 us
  81. */
  82. mtebc (EBC0_CFG, 0xa8400000); /* ebc always driven */
  83. return 0;
  84. }
  85. int misc_init_r (void)
  86. {
  87. unsigned char *duart0_mcr = (unsigned char *)((ulong)DUART0_BA + 4);
  88. unsigned char *duart1_mcr = (unsigned char *)((ulong)DUART1_BA + 4);
  89. unsigned short *lcd_contrast =
  90. (unsigned short *)((ulong)CONFIG_SYS_FPGA_BASE_ADDR + CONFIG_SYS_FPGA_CTRL + 4);
  91. unsigned short *lcd_backlight =
  92. (unsigned short *)((ulong)CONFIG_SYS_FPGA_BASE_ADDR + CONFIG_SYS_FPGA_CTRL + 6);
  93. unsigned char *dst;
  94. ulong len = sizeof(fpgadata);
  95. int status;
  96. int index;
  97. int i;
  98. char *str;
  99. dst = malloc(CONFIG_SYS_FPGA_MAX_SIZE);
  100. if (gunzip (dst, CONFIG_SYS_FPGA_MAX_SIZE, (uchar *)fpgadata, &len) != 0) {
  101. printf ("GUNZIP ERROR - must RESET board to recover\n");
  102. do_reset (NULL, 0, 0, NULL);
  103. }
  104. status = fpga_boot(dst, len);
  105. if (status != 0) {
  106. printf("\nFPGA: Booting failed ");
  107. switch (status) {
  108. case ERROR_FPGA_PRG_INIT_LOW:
  109. printf("(Timeout: INIT not low after asserting PROGRAM*)\n ");
  110. break;
  111. case ERROR_FPGA_PRG_INIT_HIGH:
  112. printf("(Timeout: INIT not high after deasserting PROGRAM*)\n ");
  113. break;
  114. case ERROR_FPGA_PRG_DONE:
  115. printf("(Timeout: DONE not high after programming FPGA)\n ");
  116. break;
  117. }
  118. /* display infos on fpgaimage */
  119. index = 15;
  120. for (i=0; i<4; i++) {
  121. len = dst[index];
  122. printf("FPGA: %s\n", &(dst[index+1]));
  123. index += len+3;
  124. }
  125. putc ('\n');
  126. /* delayed reboot */
  127. for (i=20; i>0; i--) {
  128. printf("Rebooting in %2d seconds \r",i);
  129. for (index=0;index<1000;index++)
  130. udelay(1000);
  131. }
  132. putc ('\n');
  133. do_reset(NULL, 0, 0, NULL);
  134. }
  135. puts("FPGA: ");
  136. /* display infos on fpgaimage */
  137. index = 15;
  138. for (i=0; i<4; i++) {
  139. len = dst[index];
  140. printf("%s ", &(dst[index+1]));
  141. index += len+3;
  142. }
  143. putc ('\n');
  144. free(dst);
  145. /*
  146. * Reset FPGA via FPGA_INIT pin
  147. */
  148. out_be32((void*)GPIO0_TCR, in_be32((void*)GPIO0_TCR) | FPGA_INIT); /* setup FPGA_INIT as output */
  149. out_be32((void*)GPIO0_OR, in_be32((void*)GPIO0_OR) & ~FPGA_INIT); /* reset low */
  150. udelay(1000); /* wait 1ms */
  151. out_be32((void*)GPIO0_OR, in_be32((void*)GPIO0_OR) | FPGA_INIT); /* reset high */
  152. udelay(1000); /* wait 1ms */
  153. /*
  154. * Reset external DUARTs
  155. */
  156. out_be32((void*)GPIO0_OR, in_be32((void*)GPIO0_OR) | CONFIG_SYS_DUART_RST); /* set reset to high */
  157. udelay(10); /* wait 10us */
  158. out_be32((void*)GPIO0_OR, in_be32((void*)GPIO0_OR) & ~CONFIG_SYS_DUART_RST); /* set reset to low */
  159. udelay(1000); /* wait 1ms */
  160. /*
  161. * Set NAND-FLASH GPIO signals to default
  162. */
  163. out_be32((void*)GPIO0_OR, in_be32((void*)GPIO0_OR) & ~(CONFIG_SYS_NAND_CLE | CONFIG_SYS_NAND_ALE));
  164. out_be32((void*)GPIO0_OR, in_be32((void*)GPIO0_OR) | CONFIG_SYS_NAND_CE);
  165. /*
  166. * Setup EEPROM write protection
  167. */
  168. out_be32((void*)GPIO0_OR, in_be32((void*)GPIO0_OR) | CONFIG_SYS_EEPROM_WP);
  169. out_be32((void*)GPIO0_TCR, in_be32((void*)GPIO0_TCR) | CONFIG_SYS_EEPROM_WP);
  170. /*
  171. * Enable interrupts in exar duart mcr[3]
  172. */
  173. out_8(duart0_mcr, 0x08);
  174. out_8(duart1_mcr, 0x08);
  175. /*
  176. * Init lcd interface and display logo
  177. */
  178. str = getenv("bd_type");
  179. if (strcmp(str, "voh405_bw") == 0) {
  180. lcd_setup(0, 1);
  181. lcd_init((uchar *)CONFIG_SYS_LCD_SMALL_REG, (uchar *)CONFIG_SYS_LCD_SMALL_MEM,
  182. regs_13704_320_240_4bpp,
  183. sizeof(regs_13704_320_240_4bpp)/sizeof(regs_13704_320_240_4bpp[0]),
  184. logo_bmp_320, sizeof(logo_bmp_320));
  185. } else if (strcmp(str, "voh405_bwbw") == 0) {
  186. lcd_setup(0, 1);
  187. lcd_init((uchar *)CONFIG_SYS_LCD_SMALL_REG, (uchar *)CONFIG_SYS_LCD_SMALL_MEM,
  188. regs_13704_320_240_4bpp,
  189. sizeof(regs_13704_320_240_4bpp)/sizeof(regs_13704_320_240_4bpp[0]),
  190. logo_bmp_320, sizeof(logo_bmp_320));
  191. lcd_setup(1, 1);
  192. lcd_init((uchar *)CONFIG_SYS_LCD_BIG_REG, (uchar *)CONFIG_SYS_LCD_BIG_MEM,
  193. regs_13806_320_240_4bpp,
  194. sizeof(regs_13806_320_240_4bpp)/sizeof(regs_13806_320_240_4bpp[0]),
  195. logo_bmp_320, sizeof(logo_bmp_320));
  196. } else if (strcmp(str, "voh405_bwc") == 0) {
  197. lcd_setup(0, 1);
  198. lcd_init((uchar *)CONFIG_SYS_LCD_SMALL_REG, (uchar *)CONFIG_SYS_LCD_SMALL_MEM,
  199. regs_13704_320_240_4bpp,
  200. sizeof(regs_13704_320_240_4bpp)/sizeof(regs_13704_320_240_4bpp[0]),
  201. logo_bmp_320, sizeof(logo_bmp_320));
  202. lcd_setup(1, 0);
  203. lcd_init((uchar *)CONFIG_SYS_LCD_BIG_REG, (uchar *)CONFIG_SYS_LCD_BIG_MEM,
  204. regs_13806_640_480_16bpp,
  205. sizeof(regs_13806_640_480_16bpp)/sizeof(regs_13806_640_480_16bpp[0]),
  206. logo_bmp_640, sizeof(logo_bmp_640));
  207. } else {
  208. printf("Unsupported bd_type defined (%s) -> No display configured!\n", str);
  209. return 0;
  210. }
  211. /*
  212. * Set invert bit in small lcd controller
  213. */
  214. out_8((unsigned char *)(CONFIG_SYS_LCD_SMALL_REG + 2),
  215. in_8((unsigned char *)(CONFIG_SYS_LCD_SMALL_REG + 2)) | 0x01);
  216. /*
  217. * Set default contrast voltage on epson vga controller
  218. */
  219. out_be16(lcd_contrast, 0x4646);
  220. /*
  221. * Enable backlight
  222. */
  223. out_be16(lcd_backlight, 0xffff);
  224. /*
  225. * Enable external I2C bus
  226. */
  227. out_be32((void*)GPIO0_TCR, in_be32((void*)GPIO0_TCR) | CONFIG_SYS_IIC_ON);
  228. return (0);
  229. }
  230. /*
  231. * Check Board Identity:
  232. */
  233. int checkboard (void)
  234. {
  235. char str[64];
  236. int i = getenv_f("serial#", str, sizeof(str));
  237. puts ("Board: ");
  238. if (i == -1) {
  239. puts ("### No HW ID - assuming VOH405");
  240. } else {
  241. puts(str);
  242. }
  243. if (getenv_f("bd_type", str, sizeof(str)) != -1) {
  244. printf(" (%s)", str);
  245. } else {
  246. puts(" (Missing bd_type!)");
  247. }
  248. putc ('\n');
  249. return 0;
  250. }
  251. #ifdef CONFIG_IDE_RESET
  252. #define FPGA_MODE (CONFIG_SYS_FPGA_BASE_ADDR + CONFIG_SYS_FPGA_CTRL)
  253. void ide_set_reset(int on)
  254. {
  255. /*
  256. * Assert or deassert CompactFlash Reset Pin
  257. */
  258. if (on) { /* assert RESET */
  259. out_be16((void *)FPGA_MODE,
  260. in_be16((void *)FPGA_MODE) & ~CONFIG_SYS_FPGA_CTRL_CF_RESET);
  261. } else { /* release RESET */
  262. out_be16((void *)FPGA_MODE,
  263. in_be16((void *)FPGA_MODE) | CONFIG_SYS_FPGA_CTRL_CF_RESET);
  264. }
  265. }
  266. #endif /* CONFIG_IDE_RESET */
  267. #if defined(CONFIG_RESET_PHY_R)
  268. void reset_phy(void)
  269. {
  270. #ifdef CONFIG_LXT971_NO_SLEEP
  271. /*
  272. * Disable sleep mode in LXT971
  273. */
  274. lxt971_no_sleep();
  275. #endif
  276. }
  277. #endif
  278. #if defined(CONFIG_SYS_EEPROM_WREN)
  279. /* Input: <dev_addr> I2C address of EEPROM device to enable.
  280. * <state> -1: deliver current state
  281. * 0: disable write
  282. * 1: enable write
  283. * Returns: -1: wrong device address
  284. * 0: dis-/en- able done
  285. * 0/1: current state if <state> was -1.
  286. */
  287. int eeprom_write_enable (unsigned dev_addr, int state)
  288. {
  289. if (CONFIG_SYS_I2C_EEPROM_ADDR != dev_addr) {
  290. return -1;
  291. } else {
  292. switch (state) {
  293. case 1:
  294. /* Enable write access, clear bit GPIO0. */
  295. out_be32((void*)GPIO0_OR, in_be32((void*)GPIO0_OR) & ~CONFIG_SYS_EEPROM_WP);
  296. state = 0;
  297. break;
  298. case 0:
  299. /* Disable write access, set bit GPIO0. */
  300. out_be32((void*)GPIO0_OR, in_be32((void*)GPIO0_OR) | CONFIG_SYS_EEPROM_WP);
  301. state = 0;
  302. break;
  303. default:
  304. /* Read current status back. */
  305. state = (0 == (in_be32((void*)GPIO0_OR) & CONFIG_SYS_EEPROM_WP));
  306. break;
  307. }
  308. }
  309. return state;
  310. }
  311. int do_eep_wren (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  312. {
  313. int query = argc == 1;
  314. int state = 0;
  315. if (query) {
  316. /* Query write access state. */
  317. state = eeprom_write_enable (CONFIG_SYS_I2C_EEPROM_ADDR, -1);
  318. if (state < 0) {
  319. puts ("Query of write access state failed.\n");
  320. } else {
  321. printf ("Write access for device 0x%0x is %sabled.\n",
  322. CONFIG_SYS_I2C_EEPROM_ADDR, state ? "en" : "dis");
  323. state = 0;
  324. }
  325. } else {
  326. if ('0' == argv[1][0]) {
  327. /* Disable write access. */
  328. state = eeprom_write_enable (CONFIG_SYS_I2C_EEPROM_ADDR, 0);
  329. } else {
  330. /* Enable write access. */
  331. state = eeprom_write_enable (CONFIG_SYS_I2C_EEPROM_ADDR, 1);
  332. }
  333. if (state < 0) {
  334. puts ("Setup of write access state failed.\n");
  335. }
  336. }
  337. return state;
  338. }
  339. U_BOOT_CMD(eepwren, 2, 0, do_eep_wren,
  340. "Enable / disable / query EEPROM write access",
  341. ""
  342. );
  343. #endif /* #if defined(CONFIG_SYS_EEPROM_WREN) */