hh405.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  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/processor.h>
  25. #include <command.h>
  26. #include <malloc.h>
  27. /* ------------------------------------------------------------------------- */
  28. #if 0
  29. #define FPGA_DEBUG
  30. #endif
  31. extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
  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. /* Prototypes */
  43. int gunzip(void *, int, unsigned char *, unsigned long *);
  44. /* logo bitmap data - gzip compressed and generated by bin2c */
  45. unsigned char logo_bmp_320[] =
  46. {
  47. #include "logo_320_240_4bpp.c"
  48. };
  49. unsigned char logo_bmp_320_8bpp[] =
  50. {
  51. #include "logo_320_240_8bpp.c"
  52. };
  53. unsigned char logo_bmp_640[] =
  54. {
  55. #include "logo_640_480_24bpp.c"
  56. };
  57. unsigned char logo_bmp_1024[] =
  58. {
  59. #include "logo_1024_768_8bpp.c"
  60. };
  61. /*
  62. * include common lcd code (for esd boards)
  63. */
  64. #include "../common/lcd.c"
  65. #include "../common/s1d13704_320_240_4bpp.h"
  66. #include "../common/s1d13705_320_240_8bpp.h"
  67. #include "../common/s1d13806_640_480_16bpp.h"
  68. #include "../common/s1d13806_1024_768_8bpp.h"
  69. /*
  70. * include common auto-update code (for esd boards)
  71. */
  72. #include "../common/auto_update.h"
  73. au_image_t au_image[] = {
  74. {"hh405/preinst.img", 0, -1, AU_SCRIPT},
  75. {"hh405/u-boot.img", 0xfff80000, 0x00080000, AU_FIRMWARE},
  76. {"hh405/pImage_$(bd_type)", 0x00000000, 0x00100000, AU_NAND},
  77. {"hh405/pImage.initrd", 0x00100000, 0x00200000, AU_NAND},
  78. {"hh405/yaffsmt2.img", 0x00300000, 0x01c00000, AU_NAND},
  79. {"hh405/postinst.img", 0, 0, AU_SCRIPT},
  80. };
  81. int N_AU_IMAGES = (sizeof(au_image) / sizeof(au_image[0]));
  82. int board_revision(void)
  83. {
  84. unsigned long osrh_reg;
  85. unsigned long isr1h_reg;
  86. unsigned long tcr_reg;
  87. unsigned long value;
  88. /*
  89. * Get version of HH405 board from GPIO's
  90. */
  91. /*
  92. * Setup GPIO pins (BLAST/GPIO0 and GPIO9 as GPIO)
  93. */
  94. osrh_reg = in32(GPIO0_OSRH);
  95. isr1h_reg = in32(GPIO0_ISR1H);
  96. tcr_reg = in32(GPIO0_TCR);
  97. out32(GPIO0_OSRH, osrh_reg & ~0xC0003000); /* output select */
  98. out32(GPIO0_ISR1H, isr1h_reg | 0xC0003000); /* input select */
  99. out32(GPIO0_TCR, tcr_reg & ~0x80400000); /* select input */
  100. udelay(1000); /* wait some time before reading input */
  101. value = in32(GPIO0_IR) & 0x80400000; /* get config bits */
  102. /*
  103. * Restore GPIO settings
  104. */
  105. out32(GPIO0_OSRH, osrh_reg); /* output select */
  106. out32(GPIO0_ISR1H, isr1h_reg); /* input select */
  107. out32(GPIO0_TCR, tcr_reg); /* enable output driver for outputs */
  108. if (value & 0x80000000) {
  109. /* Revision 1.0 or 1.1 detected */
  110. return 1;
  111. } else {
  112. if (value & 0x00400000) {
  113. /* Revision 1.3 detected */
  114. return 3;
  115. } else {
  116. /* Revision 1.2 detected */
  117. return 2;
  118. }
  119. }
  120. }
  121. int board_early_init_f (void)
  122. {
  123. /*
  124. * IRQ 0-15 405GP internally generated; active high; level sensitive
  125. * IRQ 16 405GP internally generated; active low; level sensitive
  126. * IRQ 17-24 RESERVED
  127. * IRQ 25 (EXT IRQ 0) CAN0; active low; level sensitive
  128. * IRQ 26 (EXT IRQ 1) SER0 ; active low; level sensitive
  129. * IRQ 27 (EXT IRQ 2) SER1; active low; level sensitive
  130. * IRQ 28 (EXT IRQ 3) FPGA 0; active low; level sensitive
  131. * IRQ 29 (EXT IRQ 4) FPGA 1; active low; level sensitive
  132. * IRQ 30 (EXT IRQ 5) PCI INTA; active low; level sensitive
  133. * IRQ 31 (EXT IRQ 6) COMPACT FLASH; active high; level sensitive
  134. */
  135. mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
  136. mtdcr(uicer, 0x00000000); /* disable all ints */
  137. mtdcr(uiccr, 0x00000000); /* set all to be non-critical*/
  138. mtdcr(uicpr, CFG_UIC0_POLARITY);/* set int polarities */
  139. mtdcr(uictr, 0x10000000); /* set int trigger levels */
  140. mtdcr(uicvcr, 0x00000001); /* set vect base=0,INT0 highest priority*/
  141. mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
  142. /*
  143. * EBC Configuration Register: set ready timeout to 512 ebc-clks -> ca. 15 us
  144. */
  145. mtebc (epcr, 0xa8400000); /* ebc always driven */
  146. return 0;
  147. }
  148. int misc_init_r (void)
  149. {
  150. DECLARE_GLOBAL_DATA_PTR;
  151. volatile unsigned short *fpga_ctrl =
  152. (unsigned short *)((ulong)CFG_FPGA_BASE_ADDR + CFG_FPGA_CTRL);
  153. volatile unsigned short *lcd_contrast =
  154. (unsigned short *)((ulong)CFG_FPGA_BASE_ADDR + CFG_FPGA_CTRL + 4);
  155. volatile unsigned short *lcd_backlight =
  156. (unsigned short *)((ulong)CFG_FPGA_BASE_ADDR + CFG_FPGA_CTRL + 6);
  157. unsigned char *dst;
  158. ulong len = sizeof(fpgadata);
  159. int status;
  160. int index;
  161. int i;
  162. char *str;
  163. unsigned long contrast0 = 0xffffffff;
  164. dst = malloc(CFG_FPGA_MAX_SIZE);
  165. if (gunzip (dst, CFG_FPGA_MAX_SIZE, (uchar *)fpgadata, &len) != 0) {
  166. printf ("GUNZIP ERROR - must RESET board to recover\n");
  167. do_reset (NULL, 0, 0, NULL);
  168. }
  169. status = fpga_boot(dst, len);
  170. if (status != 0) {
  171. printf("\nFPGA: Booting failed ");
  172. switch (status) {
  173. case ERROR_FPGA_PRG_INIT_LOW:
  174. printf("(Timeout: INIT not low after asserting PROGRAM*)\n ");
  175. break;
  176. case ERROR_FPGA_PRG_INIT_HIGH:
  177. printf("(Timeout: INIT not high after deasserting PROGRAM*)\n ");
  178. break;
  179. case ERROR_FPGA_PRG_DONE:
  180. printf("(Timeout: DONE not high after programming FPGA)\n ");
  181. break;
  182. }
  183. /* display infos on fpgaimage */
  184. index = 15;
  185. for (i=0; i<4; i++) {
  186. len = dst[index];
  187. printf("FPGA: %s\n", &(dst[index+1]));
  188. index += len+3;
  189. }
  190. putc ('\n');
  191. /* delayed reboot */
  192. for (i=20; i>0; i--) {
  193. printf("Rebooting in %2d seconds \r",i);
  194. for (index=0;index<1000;index++)
  195. udelay(1000);
  196. }
  197. putc ('\n');
  198. do_reset(NULL, 0, 0, NULL);
  199. }
  200. puts("FPGA: ");
  201. /* display infos on fpgaimage */
  202. index = 15;
  203. for (i=0; i<4; i++) {
  204. len = dst[index];
  205. printf("%s ", &(dst[index+1]));
  206. index += len+3;
  207. }
  208. putc ('\n');
  209. free(dst);
  210. /*
  211. * Reset FPGA via FPGA_INIT pin
  212. */
  213. out32(GPIO0_TCR, in32(GPIO0_TCR) | FPGA_INIT); /* setup FPGA_INIT as output */
  214. out32(GPIO0_OR, in32(GPIO0_OR) & ~FPGA_INIT); /* reset low */
  215. udelay(1000); /* wait 1ms */
  216. out32(GPIO0_OR, in32(GPIO0_OR) | FPGA_INIT); /* reset high */
  217. udelay(1000); /* wait 1ms */
  218. /*
  219. * Write Board revision into FPGA
  220. */
  221. *fpga_ctrl |= gd->board_type & 0x0003;
  222. if (gd->board_type >= 2) {
  223. *fpga_ctrl |= CFG_FPGA_CTRL_CF_BUS_EN;
  224. }
  225. /*
  226. * Set NAND-FLASH GPIO signals to default
  227. */
  228. out32(GPIO0_OR, in32(GPIO0_OR) & ~(CFG_NAND_CLE | CFG_NAND_ALE));
  229. out32(GPIO0_OR, in32(GPIO0_OR) | CFG_NAND_CE);
  230. /*
  231. * Reset touch-screen controller
  232. */
  233. out32(GPIO0_OR, in32(GPIO0_OR) & ~CFG_TOUCH_RST);
  234. udelay(1000);
  235. out32(GPIO0_OR, in32(GPIO0_OR) | CFG_TOUCH_RST);
  236. /*
  237. * Enable power on PS/2 interface (with reset)
  238. */
  239. *fpga_ctrl &= ~(CFG_FPGA_CTRL_PS2_PWR);
  240. for (i=0;i<500;i++)
  241. udelay(1000);
  242. *fpga_ctrl |= (CFG_FPGA_CTRL_PS2_PWR);
  243. /*
  244. * Get contrast value from environment variable
  245. */
  246. str = getenv("contrast0");
  247. if (str) {
  248. contrast0 = simple_strtol(str, NULL, 16);
  249. if (contrast0 > 255) {
  250. printf("ERROR: contrast0 value too high (0x%lx)!\n", contrast0);
  251. contrast0 = 0;
  252. }
  253. }
  254. /*
  255. * Init lcd interface and display logo
  256. */
  257. str = getenv("bd_type");
  258. if (strcmp(str, "ppc230") == 0) {
  259. /*
  260. * Switch backlight on
  261. */
  262. *fpga_ctrl |= CFG_FPGA_CTRL_VGA0_BL;
  263. *lcd_backlight = 0x0000;
  264. lcd_setup(1, 0);
  265. lcd_init((uchar *)CFG_LCD_BIG_REG, (uchar *)CFG_LCD_BIG_MEM,
  266. regs_13806_1024_768_8bpp,
  267. sizeof(regs_13806_1024_768_8bpp)/sizeof(regs_13806_1024_768_8bpp[0]),
  268. logo_bmp_1024, sizeof(logo_bmp_1024));
  269. } else if (strcmp(str, "ppc220") == 0) {
  270. /*
  271. * Switch backlight on
  272. */
  273. *fpga_ctrl &= ~CFG_FPGA_CTRL_VGA0_BL;
  274. *lcd_backlight = 0x0000;
  275. lcd_setup(1, 0);
  276. lcd_init((uchar *)CFG_LCD_BIG_REG, (uchar *)CFG_LCD_BIG_MEM,
  277. regs_13806_640_480_16bpp,
  278. sizeof(regs_13806_640_480_16bpp)/sizeof(regs_13806_640_480_16bpp[0]),
  279. logo_bmp_640, sizeof(logo_bmp_640));
  280. } else if (strcmp(str, "ppc215") == 0) {
  281. /*
  282. * Set default display contrast voltage
  283. */
  284. if (contrast0 == 0xffffffff) {
  285. *lcd_contrast = 0x0082;
  286. } else {
  287. *lcd_contrast = contrast0;
  288. }
  289. *lcd_backlight = 0xffff;
  290. /*
  291. * Switch backlight on
  292. */
  293. *fpga_ctrl |= CFG_FPGA_CTRL_VGA0_BL | CFG_FPGA_CTRL_VGA0_BL_MODE;
  294. /*
  295. * Set lcd clock (small epson)
  296. */
  297. *fpga_ctrl |= LCD_CLK_06250;
  298. udelay(100); /* wait for 100 us */
  299. lcd_setup(0, 1);
  300. lcd_init((uchar *)CFG_LCD_SMALL_REG, (uchar *)CFG_LCD_SMALL_MEM,
  301. regs_13705_320_240_8bpp,
  302. sizeof(regs_13705_320_240_8bpp)/sizeof(regs_13705_320_240_8bpp[0]),
  303. logo_bmp_320_8bpp, sizeof(logo_bmp_320_8bpp));
  304. } else if (strcmp(str, "ppc210") == 0) {
  305. /*
  306. * Set default display contrast voltage
  307. */
  308. if (contrast0 == 0xffffffff) {
  309. *lcd_contrast = 0x0060;
  310. } else {
  311. *lcd_contrast = contrast0;
  312. }
  313. *lcd_backlight = 0xffff;
  314. /*
  315. * Switch backlight on
  316. */
  317. *fpga_ctrl |= CFG_FPGA_CTRL_VGA0_BL | CFG_FPGA_CTRL_VGA0_BL_MODE;
  318. /*
  319. * Set lcd clock (small epson)
  320. */
  321. *fpga_ctrl |= LCD_CLK_08330;
  322. lcd_setup(0, 1);
  323. lcd_init((uchar *)CFG_LCD_SMALL_REG, (uchar *)CFG_LCD_SMALL_MEM,
  324. regs_13704_320_240_4bpp,
  325. sizeof(regs_13704_320_240_4bpp)/sizeof(regs_13704_320_240_4bpp[0]),
  326. logo_bmp_320, sizeof(logo_bmp_320));
  327. } else {
  328. printf("Unsupported bd_type defined (%s) -> No display configured!\n", str);
  329. return 0;
  330. }
  331. return (0);
  332. }
  333. /*
  334. * Check Board Identity:
  335. */
  336. int checkboard (void)
  337. {
  338. DECLARE_GLOBAL_DATA_PTR;
  339. unsigned char str[64];
  340. int i = getenv_r ("serial#", str, sizeof(str));
  341. puts ("Board: ");
  342. if (i == -1) {
  343. puts ("### No HW ID - assuming HH405");
  344. } else {
  345. puts(str);
  346. }
  347. if (getenv_r("bd_type", str, sizeof(str)) != -1) {
  348. printf(" (%s", str);
  349. } else {
  350. puts(" (Missing bd_type!");
  351. }
  352. gd->board_type = board_revision();
  353. printf(", Rev 1.%ld)\n", gd->board_type);
  354. /*
  355. * Disable sleep mode in LXT971
  356. */
  357. lxt971_no_sleep();
  358. return 0;
  359. }
  360. /* ------------------------------------------------------------------------- */
  361. long int initdram (int board_type)
  362. {
  363. unsigned long val;
  364. mtdcr(memcfga, mem_mb0cf);
  365. val = mfdcr(memcfgd);
  366. #if 0
  367. printf("\nmb0cf=%x\n", val); /* test-only */
  368. printf("strap=%x\n", mfdcr(strap)); /* test-only */
  369. #endif
  370. return (4*1024*1024 << ((val & 0x000e0000) >> 17));
  371. }
  372. /* ------------------------------------------------------------------------- */
  373. int testdram (void)
  374. {
  375. /* TODO: XXX XXX XXX */
  376. printf ("test: 16 MB - ok\n");
  377. return (0);
  378. }
  379. /* ------------------------------------------------------------------------- */
  380. #ifdef CONFIG_IDE_RESET
  381. void ide_set_reset(int on)
  382. {
  383. volatile unsigned short *fpga_mode =
  384. (unsigned short *)((ulong)CFG_FPGA_BASE_ADDR + CFG_FPGA_CTRL);
  385. /*
  386. * Assert or deassert CompactFlash Reset Pin
  387. */
  388. if (on) { /* assert RESET */
  389. *fpga_mode &= ~(CFG_FPGA_CTRL_CF_RESET);
  390. } else { /* release RESET */
  391. *fpga_mode |= CFG_FPGA_CTRL_CF_RESET;
  392. }
  393. }
  394. #endif /* CONFIG_IDE_RESET */
  395. #if (CONFIG_COMMANDS & CFG_CMD_NAND)
  396. #include <linux/mtd/nand.h>
  397. extern struct nand_chip nand_dev_desc[CFG_MAX_NAND_DEVICE];
  398. void nand_init(void)
  399. {
  400. nand_probe(CFG_NAND_BASE);
  401. if (nand_dev_desc[0].ChipID != NAND_ChipID_UNKNOWN) {
  402. print_size(nand_dev_desc[0].totlen, "\n");
  403. }
  404. }
  405. #endif