voh405.c 11 KB

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