voh405.c 11 KB

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