hh405.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924
  1. /*
  2. * (C) Copyright 2001-2004
  3. * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com
  4. *
  5. * (C) Copyright 2005
  6. * Stefan Roese, DENX Software Engineering, sr@denx.de.
  7. *
  8. * (C) Copyright 2006
  9. * Matthias Fuchs, esd GmbH, matthias.fuchs@esd-electronics.com
  10. *
  11. * See file CREDITS for list of people who contributed to this
  12. * project.
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License as
  16. * published by the Free Software Foundation; either version 2 of
  17. * the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  27. * MA 02111-1307 USA
  28. */
  29. #include <common.h>
  30. #include <asm/processor.h>
  31. #include <command.h>
  32. #include <malloc.h>
  33. #include <pci.h>
  34. #include <sm501.h>
  35. #ifdef CONFIG_VIDEO_SM501
  36. #define SWAP32(x) ((((x) & 0x000000ff) << 24) | (((x) & 0x0000ff00) << 8)|\
  37. (((x) & 0x00ff0000) >> 8) | (((x) & 0xff000000) >> 24) )
  38. #ifdef CONFIG_VIDEO_SM501_8BPP
  39. #error CONFIG_VIDEO_SM501_8BPP not supported.
  40. #endif /* CONFIG_VIDEO_SM501_8BPP */
  41. #ifdef CONFIG_VIDEO_SM501_16BPP
  42. #define BPP 16
  43. /*
  44. * 800x600 display B084SN03: PCLK = 40MHz
  45. * => 2*PCLK = 80MHz
  46. * 336/4 = 84MHz
  47. * => PCLK = 84MHz
  48. */
  49. static const SMI_REGS init_regs_800x600 [] =
  50. {
  51. #if 1 /* test-only */
  52. {0x0005c, SWAP32(0xffffffff)}, /* set endianess to big endian */
  53. #else
  54. {0x0005c, SWAP32(0x00000000)}, /* set endianess to little endian */
  55. #endif
  56. {0x00004, SWAP32(0x00000000)},
  57. /* clocks for pm1... */
  58. {0x00048, SWAP32(0x00021807)},
  59. {0x0004C, SWAP32(0x221a0a01)},
  60. {0x00054, SWAP32(0x00000001)},
  61. /* clocks for pm0... */
  62. {0x00040, SWAP32(0x00021807)},
  63. {0x00044, SWAP32(0x221a0a01)},
  64. {0x00054, SWAP32(0x00000000)},
  65. /* GPIO */
  66. {0x1000c, SWAP32(0xfffffff0)}, /* GPIO32..63 direction */
  67. /* panel control regs... */
  68. {0x80000, SWAP32(0x0f013105)}, /* panel display control: 16-bit RGB 5:6:5 mode */
  69. {0x80004, SWAP32(0xc428bb17)}, /* panel panning control ??? */
  70. {0x8000C, SWAP32(0x00010000)}, /* panel fb address */
  71. {0x80010, SWAP32(0x06400640)}, /* panel fb offset/window width */
  72. {0x80014, SWAP32(0x03200000)}, /* panel fb width (0x320=800) */
  73. {0x80018, SWAP32(0x02580000)}, /* panel fb height (0x258=600) */
  74. {0x8001C, SWAP32(0x00000000)}, /* panel plane tl location */
  75. {0x80020, SWAP32(0x02580320)}, /* panel plane br location */
  76. {0x80024, SWAP32(0x041f031f)}, /* panel horizontal total */
  77. {0x80028, SWAP32(0x00800347)}, /* panel horizontal sync */
  78. {0x8002C, SWAP32(0x02730257)}, /* panel vertical total */
  79. {0x80030, SWAP32(0x00040258)}, /* panel vertical sync */
  80. {0x80200, SWAP32(0x00010000)}, /* crt display control */
  81. {0, 0}
  82. };
  83. /*
  84. * 1024x768 display G150XG02: PCLK = 65MHz
  85. * => 2*PCLK = 130MHz
  86. * 288/2 = 144MHz
  87. * => PCLK = 72MHz
  88. */
  89. static const SMI_REGS init_regs_1024x768 [] =
  90. {
  91. {0x00004, SWAP32(0x00000000)},
  92. /* clocks for pm1... */
  93. {0x00048, SWAP32(0x00021807)},
  94. {0x0004C, SWAP32(0x011a0a01)},
  95. {0x00054, SWAP32(0x00000001)},
  96. /* clocks for pm0... */
  97. {0x00040, SWAP32(0x00021807)},
  98. {0x00044, SWAP32(0x011a0a01)},
  99. {0x00054, SWAP32(0x00000000)},
  100. /* GPIO */
  101. {0x1000c, SWAP32(0xfffffff0)}, /* GPIO32..63 direction */
  102. /* panel control regs... */
  103. {0x80000, SWAP32(0x0f013105)}, /* panel display control: 16-bit RGB 5:6:5 mode */
  104. {0x80004, SWAP32(0xc428bb17)}, /* panel panning control ??? */
  105. {0x8000C, SWAP32(0x00010000)}, /* panel fb address */
  106. {0x80010, SWAP32(0x08000800)}, /* panel fb offset/window width */
  107. {0x80014, SWAP32(0x04000000)}, /* panel fb width (0x400=1024) */
  108. {0x80018, SWAP32(0x03000000)}, /* panel fb height (0x300=768) */
  109. {0x8001C, SWAP32(0x00000000)}, /* panel plane tl location */
  110. {0x80020, SWAP32(0x03000400)}, /* panel plane br location */
  111. {0x80024, SWAP32(0x053f03ff)}, /* panel horizontal total */
  112. {0x80028, SWAP32(0x0140040f)}, /* panel horizontal sync */
  113. {0x8002C, SWAP32(0x032502ff)}, /* panel vertical total */
  114. {0x80030, SWAP32(0x00260301)}, /* panel vertical sync */
  115. {0x80200, SWAP32(0x00010000)}, /* crt display control */
  116. {0, 0}
  117. };
  118. #endif /* CONFIG_VIDEO_SM501_16BPP */
  119. #ifdef CONFIG_VIDEO_SM501_32BPP
  120. #define BPP 32
  121. /*
  122. * 800x600 display B084SN03: PCLK = 40MHz
  123. * => 2*PCLK = 80MHz
  124. * 336/4 = 84MHz
  125. * => PCLK = 84MHz
  126. */
  127. static const SMI_REGS init_regs_800x600 [] =
  128. {
  129. #if 0 /* test-only */
  130. {0x0005c, SWAP32(0xffffffff)}, /* set endianess to big endian */
  131. #else
  132. {0x0005c, SWAP32(0x00000000)}, /* set endianess to little endian */
  133. #endif
  134. {0x00004, SWAP32(0x00000000)},
  135. /* clocks for pm1... */
  136. {0x00048, SWAP32(0x00021807)},
  137. {0x0004C, SWAP32(0x221a0a01)},
  138. {0x00054, SWAP32(0x00000001)},
  139. /* clocks for pm0... */
  140. {0x00040, SWAP32(0x00021807)},
  141. {0x00044, SWAP32(0x221a0a01)},
  142. {0x00054, SWAP32(0x00000000)},
  143. /* GPIO */
  144. {0x1000c, SWAP32(0xfffffff0)}, /* GPIO32..63 direction */
  145. /* panel control regs... */
  146. {0x80000, SWAP32(0x0f013106)}, /* panel display control: 32-bit RGB 8:8:8 mode */
  147. {0x80004, SWAP32(0xc428bb17)}, /* panel panning control ??? */
  148. {0x8000C, SWAP32(0x00010000)}, /* panel fb address */
  149. {0x80010, SWAP32(0x0c800c80)}, /* panel fb offset/window width */
  150. {0x80014, SWAP32(0x03200000)}, /* panel fb width (0x320=800) */
  151. {0x80018, SWAP32(0x02580000)}, /* panel fb height (0x258=600) */
  152. {0x8001C, SWAP32(0x00000000)}, /* panel plane tl location */
  153. {0x80020, SWAP32(0x02580320)}, /* panel plane br location */
  154. {0x80024, SWAP32(0x041f031f)}, /* panel horizontal total */
  155. {0x80028, SWAP32(0x00800347)}, /* panel horizontal sync */
  156. {0x8002C, SWAP32(0x02730257)}, /* panel vertical total */
  157. {0x80030, SWAP32(0x00040258)}, /* panel vertical sync */
  158. {0x80200, SWAP32(0x00010000)}, /* crt display control */
  159. {0, 0}
  160. };
  161. /*
  162. * 1024x768 display G150XG02: PCLK = 65MHz
  163. * => 2*PCLK = 130MHz
  164. * 288/2 = 144MHz
  165. * => PCLK = 72MHz
  166. */
  167. static const SMI_REGS init_regs_1024x768 [] =
  168. {
  169. {0x00004, SWAP32(0x00000000)},
  170. /* clocks for pm1... */
  171. {0x00048, SWAP32(0x00021807)},
  172. {0x0004C, SWAP32(0x011a0a01)},
  173. {0x00054, SWAP32(0x00000001)},
  174. /* clocks for pm0... */
  175. {0x00040, SWAP32(0x00021807)},
  176. {0x00044, SWAP32(0x011a0a01)},
  177. {0x00054, SWAP32(0x00000000)},
  178. /* GPIO */
  179. {0x1000c, SWAP32(0xfffffff0)}, /* GPIO32..63 direction */
  180. /* panel control regs... */
  181. {0x80000, SWAP32(0x0f013106)}, /* panel display control: 32-bit RGB 8:8:8 mode */
  182. {0x80004, SWAP32(0xc428bb17)}, /* panel panning control ??? */
  183. {0x8000C, SWAP32(0x00010000)}, /* panel fb address */
  184. {0x80010, SWAP32(0x10001000)}, /* panel fb offset/window width */
  185. {0x80014, SWAP32(0x04000000)}, /* panel fb width (0x400=1024) */
  186. {0x80018, SWAP32(0x03000000)}, /* panel fb height (0x300=768) */
  187. {0x8001C, SWAP32(0x00000000)}, /* panel plane tl location */
  188. {0x80020, SWAP32(0x03000400)}, /* panel plane br location */
  189. {0x80024, SWAP32(0x053f03ff)}, /* panel horizontal total */
  190. {0x80028, SWAP32(0x0140040f)}, /* panel horizontal sync */
  191. {0x8002C, SWAP32(0x032502ff)}, /* panel vertical total */
  192. {0x80030, SWAP32(0x00260301)}, /* panel vertical sync */
  193. {0x80200, SWAP32(0x00010000)}, /* crt display control */
  194. {0, 0}
  195. };
  196. #endif /* CONFIG_VIDEO_SM501_32BPP */
  197. #endif /* CONFIG_VIDEO_SM501 */
  198. #if 0
  199. #define FPGA_DEBUG
  200. #endif
  201. extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
  202. extern void lxt971_no_sleep(void);
  203. /* fpga configuration data - gzip compressed and generated by bin2c */
  204. const unsigned char fpgadata[] =
  205. {
  206. #include "fpgadata.c"
  207. };
  208. /*
  209. * include common fpga code (for esd boards)
  210. */
  211. #include "../common/fpga.c"
  212. /* Prototypes */
  213. int gunzip(void *, int, unsigned char *, unsigned long *);
  214. /* logo bitmap data - gzip compressed and generated by bin2c */
  215. unsigned char logo_bmp_320[] =
  216. {
  217. #include "logo_320_240_4bpp.c"
  218. };
  219. unsigned char logo_bmp_320_8bpp[] =
  220. {
  221. #include "logo_320_240_8bpp.c"
  222. };
  223. unsigned char logo_bmp_640[] =
  224. {
  225. #include "logo_640_480_24bpp.c"
  226. };
  227. unsigned char logo_bmp_1024[] =
  228. {
  229. #include "logo_1024_768_8bpp.c"
  230. };
  231. /*
  232. * include common lcd code (for esd boards)
  233. */
  234. #include "../common/lcd.c"
  235. #include "../common/s1d13704_320_240_4bpp.h"
  236. #include "../common/s1d13705_320_240_8bpp.h"
  237. #include "../common/s1d13806_640_480_16bpp.h"
  238. #include "../common/s1d13806_1024_768_8bpp.h"
  239. /*
  240. * include common auto-update code (for esd boards)
  241. */
  242. #include "../common/auto_update.h"
  243. au_image_t au_image[] = {
  244. {"hh405/preinst.img", 0, -1, AU_SCRIPT},
  245. {"hh405/u-boot.img", 0xfff80000, 0x00080000, AU_FIRMWARE},
  246. {"hh405/pImage_${bd_type}", 0x00000000, 0x00100000, AU_NAND},
  247. {"hh405/pImage.initrd", 0x00100000, 0x00200000, AU_NAND},
  248. {"hh405/yaffsmt2.img", 0x00300000, 0x01c00000, AU_NAND},
  249. {"hh405/postinst.img", 0, 0, AU_SCRIPT},
  250. };
  251. int N_AU_IMAGES = (sizeof(au_image) / sizeof(au_image[0]));
  252. /*
  253. * Get version of HH405 board from GPIO's
  254. */
  255. int board_revision(void)
  256. {
  257. unsigned long osrh_reg;
  258. unsigned long isr1h_reg;
  259. unsigned long tcr_reg;
  260. unsigned long value;
  261. /*
  262. * Setup GPIO pins (BLAST/GPIO0 and GPIO9 as GPIO)
  263. */
  264. osrh_reg = in32(GPIO0_OSRH);
  265. isr1h_reg = in32(GPIO0_ISR1H);
  266. tcr_reg = in32(GPIO0_TCR);
  267. out32(GPIO0_OSRH, osrh_reg & ~0xC0003000); /* output select */
  268. out32(GPIO0_ISR1H, isr1h_reg | 0xC0003000); /* input select */
  269. out32(GPIO0_TCR, tcr_reg & ~0x80400000); /* select input */
  270. udelay(1000); /* wait some time before reading input */
  271. value = in32(GPIO0_IR) & 0x80400000; /* get config bits */
  272. /*
  273. * Restore GPIO settings
  274. */
  275. out32(GPIO0_OSRH, osrh_reg); /* output select */
  276. out32(GPIO0_ISR1H, isr1h_reg); /* input select */
  277. out32(GPIO0_TCR, tcr_reg); /* enable output driver for outputs */
  278. if (value & 0x80000000) {
  279. /* Revision 1.0 or 1.1 detected */
  280. return 1;
  281. } else {
  282. if (value & 0x00400000) {
  283. /* unused */
  284. return 3;
  285. } else {
  286. return 2;
  287. }
  288. }
  289. }
  290. int board_early_init_f (void)
  291. {
  292. /*
  293. * IRQ 0-15 405GP internally generated; active high; level sensitive
  294. * IRQ 16 405GP internally generated; active low; level sensitive
  295. * IRQ 17-24 RESERVED
  296. * IRQ 25 (EXT IRQ 0) CAN0; active low; level sensitive
  297. * IRQ 26 (EXT IRQ 1) SER0 ; active low; level sensitive
  298. * IRQ 27 (EXT IRQ 2) SER1; active low; level sensitive
  299. * IRQ 28 (EXT IRQ 3) FPGA 0; active low; level sensitive
  300. * IRQ 29 (EXT IRQ 4) FPGA 1; active low; level sensitive
  301. * IRQ 30 (EXT IRQ 5) PCI INTA; active low; level sensitive
  302. * IRQ 31 (EXT IRQ 6) COMPACT FLASH; active high; level sensitive
  303. */
  304. mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
  305. mtdcr(uicer, 0x00000000); /* disable all ints */
  306. mtdcr(uiccr, 0x00000000); /* set all to be non-critical*/
  307. mtdcr(uicpr, CFG_UIC0_POLARITY);/* set int polarities */
  308. mtdcr(uictr, 0x10000000); /* set int trigger levels */
  309. mtdcr(uicvcr, 0x00000001); /* set vect base=0,INT0 highest priority*/
  310. mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
  311. /*
  312. * EBC Configuration Register: set ready timeout to 512 ebc-clks -> ca. 15 us
  313. */
  314. mtebc (epcr, 0xa8400000); /* ebc always driven */
  315. return 0;
  316. }
  317. int cf_enable(void)
  318. {
  319. DECLARE_GLOBAL_DATA_PTR;
  320. int i;
  321. volatile unsigned short *fpga_ctrl =
  322. (unsigned short *)((ulong)CFG_FPGA_BASE_ADDR + CFG_FPGA_CTRL);
  323. volatile unsigned short *fpga_status =
  324. (unsigned short *)((ulong)CFG_FPGA_BASE_ADDR + CFG_FPGA_CTRL + 2);
  325. if (gd->board_type >= 2) {
  326. if (*fpga_status & CFG_FPGA_STATUS_CF_DETECT) {
  327. if (!(*fpga_ctrl & CFG_FPGA_CTRL_CF_BUS_EN)) {
  328. *fpga_ctrl &= ~CFG_FPGA_CTRL_CF_PWRN;
  329. for (i=0; i<300; i++)
  330. udelay(1000);
  331. *fpga_ctrl |= CFG_FPGA_CTRL_CF_BUS_EN;
  332. for (i=0; i<20; i++)
  333. udelay(1000);
  334. }
  335. } else {
  336. *fpga_ctrl &= ~CFG_FPGA_CTRL_CF_BUS_EN;
  337. *fpga_ctrl |= CFG_FPGA_CTRL_CF_PWRN;
  338. }
  339. }
  340. return 0;
  341. }
  342. int misc_init_r (void)
  343. {
  344. DECLARE_GLOBAL_DATA_PTR;
  345. volatile unsigned short *fpga_ctrl =
  346. (unsigned short *)((ulong)CFG_FPGA_BASE_ADDR + CFG_FPGA_CTRL);
  347. volatile unsigned short *lcd_contrast =
  348. (unsigned short *)((ulong)CFG_FPGA_BASE_ADDR + CFG_FPGA_CTRL + 4);
  349. volatile unsigned short *lcd_backlight =
  350. (unsigned short *)((ulong)CFG_FPGA_BASE_ADDR + CFG_FPGA_CTRL + 6);
  351. unsigned char *dst;
  352. ulong len = sizeof(fpgadata);
  353. int status;
  354. int index;
  355. int i;
  356. char *str;
  357. unsigned long contrast0 = 0xffffffff;
  358. dst = malloc(CFG_FPGA_MAX_SIZE);
  359. if (gunzip (dst, CFG_FPGA_MAX_SIZE, (uchar *)fpgadata, &len) != 0) {
  360. printf ("GUNZIP ERROR - must RESET board to recover\n");
  361. do_reset (NULL, 0, 0, NULL);
  362. }
  363. status = fpga_boot(dst, len);
  364. if (status != 0) {
  365. printf("\nFPGA: Booting failed ");
  366. switch (status) {
  367. case ERROR_FPGA_PRG_INIT_LOW:
  368. printf("(Timeout: INIT not low after asserting PROGRAM*)\n ");
  369. break;
  370. case ERROR_FPGA_PRG_INIT_HIGH:
  371. printf("(Timeout: INIT not high after deasserting PROGRAM*)\n ");
  372. break;
  373. case ERROR_FPGA_PRG_DONE:
  374. printf("(Timeout: DONE not high after programming FPGA)\n ");
  375. break;
  376. }
  377. /* display infos on fpgaimage */
  378. index = 15;
  379. for (i=0; i<4; i++) {
  380. len = dst[index];
  381. printf("FPGA: %s\n", &(dst[index+1]));
  382. index += len+3;
  383. }
  384. putc ('\n');
  385. /* delayed reboot */
  386. for (i=20; i>0; i--) {
  387. printf("Rebooting in %2d seconds \r",i);
  388. for (index=0;index<1000;index++)
  389. udelay(1000);
  390. }
  391. putc ('\n');
  392. do_reset(NULL, 0, 0, NULL);
  393. }
  394. puts("FPGA: ");
  395. /* display infos on fpgaimage */
  396. index = 15;
  397. for (i=0; i<4; i++) {
  398. len = dst[index];
  399. printf("%s ", &(dst[index+1]));
  400. index += len+3;
  401. }
  402. putc ('\n');
  403. free(dst);
  404. /*
  405. * Reset FPGA via FPGA_INIT pin
  406. */
  407. out32(GPIO0_TCR, in32(GPIO0_TCR) | FPGA_INIT); /* setup FPGA_INIT as output */
  408. out32(GPIO0_OR, in32(GPIO0_OR) & ~FPGA_INIT); /* reset low */
  409. udelay(1000); /* wait 1ms */
  410. out32(GPIO0_OR, in32(GPIO0_OR) | FPGA_INIT); /* reset high */
  411. udelay(1000); /* wait 1ms */
  412. /*
  413. * Write Board revision into FPGA
  414. */
  415. *fpga_ctrl |= gd->board_type & 0x0003;
  416. /*
  417. * Setup and enable EEPROM write protection
  418. */
  419. out32(GPIO0_OR, in32(GPIO0_OR) | CFG_EEPROM_WP);
  420. /*
  421. * Set NAND-FLASH GPIO signals to default
  422. */
  423. out32(GPIO0_OR, in32(GPIO0_OR) & ~(CFG_NAND_CLE | CFG_NAND_ALE));
  424. out32(GPIO0_OR, in32(GPIO0_OR) | CFG_NAND_CE);
  425. /*
  426. * Reset touch-screen controller
  427. */
  428. out32(GPIO0_OR, in32(GPIO0_OR) & ~CFG_TOUCH_RST);
  429. udelay(1000);
  430. out32(GPIO0_OR, in32(GPIO0_OR) | CFG_TOUCH_RST);
  431. /*
  432. * Enable power on PS/2 interface (with reset)
  433. */
  434. *fpga_ctrl &= ~(CFG_FPGA_CTRL_PS2_PWR);
  435. for (i=0;i<500;i++)
  436. udelay(1000);
  437. *fpga_ctrl |= (CFG_FPGA_CTRL_PS2_PWR);
  438. /*
  439. * Get contrast value from environment variable
  440. */
  441. str = getenv("contrast0");
  442. if (str) {
  443. contrast0 = simple_strtol(str, NULL, 16);
  444. if (contrast0 > 255) {
  445. printf("ERROR: contrast0 value too high (0x%lx)!\n", contrast0);
  446. contrast0 = 0xffffffff;
  447. }
  448. }
  449. /*
  450. * Init lcd interface and display logo
  451. */
  452. str = getenv("bd_type");
  453. if (strcmp(str, "ppc230") == 0) {
  454. /*
  455. * Switch backlight on
  456. */
  457. *fpga_ctrl |= CFG_FPGA_CTRL_VGA0_BL;
  458. *lcd_backlight = 0x0000;
  459. lcd_setup(1, 0);
  460. lcd_init((uchar *)CFG_LCD_BIG_REG, (uchar *)CFG_LCD_BIG_MEM,
  461. regs_13806_1024_768_8bpp,
  462. sizeof(regs_13806_1024_768_8bpp)/sizeof(regs_13806_1024_768_8bpp[0]),
  463. logo_bmp_1024, sizeof(logo_bmp_1024));
  464. } else if (strcmp(str, "ppc220") == 0) {
  465. /*
  466. * Switch backlight on
  467. */
  468. *fpga_ctrl &= ~CFG_FPGA_CTRL_VGA0_BL;
  469. *lcd_backlight = 0x0000;
  470. lcd_setup(1, 0);
  471. lcd_init((uchar *)CFG_LCD_BIG_REG, (uchar *)CFG_LCD_BIG_MEM,
  472. regs_13806_640_480_16bpp,
  473. sizeof(regs_13806_640_480_16bpp)/sizeof(regs_13806_640_480_16bpp[0]),
  474. logo_bmp_640, sizeof(logo_bmp_640));
  475. } else if (strcmp(str, "ppc215") == 0) {
  476. /*
  477. * Set default display contrast voltage
  478. */
  479. if (contrast0 == 0xffffffff) {
  480. *lcd_contrast = 0x0082;
  481. } else {
  482. *lcd_contrast = contrast0;
  483. }
  484. *lcd_backlight = 0xffff;
  485. /*
  486. * Switch backlight on
  487. */
  488. *fpga_ctrl |= CFG_FPGA_CTRL_VGA0_BL | CFG_FPGA_CTRL_VGA0_BL_MODE;
  489. /*
  490. * Set lcd clock (small epson)
  491. */
  492. *fpga_ctrl |= LCD_CLK_06250;
  493. udelay(100); /* wait for 100 us */
  494. lcd_setup(0, 1);
  495. lcd_init((uchar *)CFG_LCD_SMALL_REG, (uchar *)CFG_LCD_SMALL_MEM,
  496. regs_13705_320_240_8bpp,
  497. sizeof(regs_13705_320_240_8bpp)/sizeof(regs_13705_320_240_8bpp[0]),
  498. logo_bmp_320_8bpp, sizeof(logo_bmp_320_8bpp));
  499. } else if (strcmp(str, "ppc210") == 0) {
  500. /*
  501. * Set default display contrast voltage
  502. */
  503. if (contrast0 == 0xffffffff) {
  504. *lcd_contrast = 0x0060;
  505. } else {
  506. *lcd_contrast = contrast0;
  507. }
  508. *lcd_backlight = 0xffff;
  509. /*
  510. * Switch backlight on
  511. */
  512. *fpga_ctrl |= CFG_FPGA_CTRL_VGA0_BL | CFG_FPGA_CTRL_VGA0_BL_MODE;
  513. /*
  514. * Set lcd clock (small epson), enable 1-wire interface
  515. */
  516. *fpga_ctrl |= LCD_CLK_08330 | CFG_FPGA_CTRL_OW_ENABLE;
  517. lcd_setup(0, 1);
  518. lcd_init((uchar *)CFG_LCD_SMALL_REG, (uchar *)CFG_LCD_SMALL_MEM,
  519. regs_13704_320_240_4bpp,
  520. sizeof(regs_13704_320_240_4bpp)/sizeof(regs_13704_320_240_4bpp[0]),
  521. logo_bmp_320, sizeof(logo_bmp_320));
  522. #ifdef CONFIG_VIDEO_SM501
  523. } else {
  524. pci_dev_t devbusfn;
  525. /*
  526. * Is SM501 connected (ppc221/ppc231)?
  527. */
  528. devbusfn = pci_find_device(PCI_VENDOR_SM, PCI_DEVICE_SM501, 0);
  529. if (devbusfn != -1) {
  530. puts("VGA: SM501 with 8 MB ");
  531. if (strcmp(str, "ppc221") == 0) {
  532. printf("(800*600, %dbpp)\n", BPP);
  533. *lcd_backlight = 0x002d; /* max. allowed brightness */
  534. } else if (strcmp(str, "ppc231") == 0) {
  535. printf("(1024*768, %dbpp)\n", BPP);
  536. *lcd_backlight = 0x0000;
  537. } else {
  538. printf("Unsupported bd_type defined (%s) -> No display configured!\n", str);
  539. return 0;
  540. }
  541. } else {
  542. printf("Unsupported bd_type defined (%s) -> No display configured!\n", str);
  543. return 0;
  544. }
  545. #endif /* CONFIG_VIDEO_SM501 */
  546. }
  547. cf_enable();
  548. return (0);
  549. }
  550. /*
  551. * Check Board Identity:
  552. */
  553. int checkboard (void)
  554. {
  555. DECLARE_GLOBAL_DATA_PTR;
  556. char str[64];
  557. int i = getenv_r ("serial#", str, sizeof(str));
  558. puts ("Board: ");
  559. if (i == -1) {
  560. puts ("### No HW ID - assuming HH405");
  561. } else {
  562. puts(str);
  563. }
  564. if (getenv_r("bd_type", str, sizeof(str)) != -1) {
  565. printf(" (%s", str);
  566. } else {
  567. puts(" (Missing bd_type!");
  568. }
  569. gd->board_type = board_revision();
  570. printf(", Rev %ld.x)\n", gd->board_type);
  571. return 0;
  572. }
  573. long int initdram (int board_type)
  574. {
  575. unsigned long val;
  576. mtdcr(memcfga, mem_mb0cf);
  577. val = mfdcr(memcfgd);
  578. #if 0
  579. printf("\nmb0cf=%x\n", val); /* test-only */
  580. printf("strap=%x\n", mfdcr(strap)); /* test-only */
  581. #endif
  582. return (4*1024*1024 << ((val & 0x000e0000) >> 17));
  583. }
  584. #ifdef CONFIG_IDE_RESET
  585. void ide_set_reset(int on)
  586. {
  587. DECLARE_GLOBAL_DATA_PTR;
  588. volatile unsigned short *fpga_mode =
  589. (unsigned short *)((ulong)CFG_FPGA_BASE_ADDR + CFG_FPGA_CTRL);
  590. volatile unsigned short *fpga_status =
  591. (unsigned short *)((ulong)CFG_FPGA_BASE_ADDR + CFG_FPGA_CTRL + 2);
  592. if (((gd->board_type >= 2) && (*fpga_status & CFG_FPGA_STATUS_CF_DETECT)) ||
  593. (gd->board_type < 2)) {
  594. /*
  595. * Assert or deassert CompactFlash Reset Pin
  596. */
  597. if (on) { /* assert RESET */
  598. cf_enable();
  599. *fpga_mode &= ~(CFG_FPGA_CTRL_CF_RESET);
  600. } else { /* release RESET */
  601. *fpga_mode |= CFG_FPGA_CTRL_CF_RESET;
  602. }
  603. }
  604. }
  605. #endif /* CONFIG_IDE_RESET */
  606. #if (CONFIG_COMMANDS & CFG_CMD_NAND)
  607. #include <linux/mtd/nand_legacy.h>
  608. extern struct nand_chip nand_dev_desc[CFG_MAX_NAND_DEVICE];
  609. void nand_init(void)
  610. {
  611. nand_probe(CFG_NAND_BASE);
  612. if (nand_dev_desc[0].ChipID != NAND_ChipID_UNKNOWN) {
  613. print_size(nand_dev_desc[0].totlen, "\n");
  614. }
  615. }
  616. #endif
  617. #if defined(CFG_EEPROM_WREN)
  618. /* Input: <dev_addr> I2C address of EEPROM device to enable.
  619. * <state> -1: deliver current state
  620. * 0: disable write
  621. * 1: enable write
  622. * Returns: -1: wrong device address
  623. * 0: dis-/en- able done
  624. * 0/1: current state if <state> was -1.
  625. */
  626. int eeprom_write_enable (unsigned dev_addr, int state)
  627. {
  628. if (CFG_I2C_EEPROM_ADDR != dev_addr) {
  629. return -1;
  630. } else {
  631. switch (state) {
  632. case 1:
  633. /* Enable write access, clear bit GPIO_SINT2. */
  634. out32(GPIO0_OR, in32(GPIO0_OR) & ~CFG_EEPROM_WP);
  635. state = 0;
  636. break;
  637. case 0:
  638. /* Disable write access, set bit GPIO_SINT2. */
  639. out32(GPIO0_OR, in32(GPIO0_OR) | CFG_EEPROM_WP);
  640. state = 0;
  641. break;
  642. default:
  643. /* Read current status back. */
  644. state = (0 == (in32(GPIO0_OR) & CFG_EEPROM_WP));
  645. break;
  646. }
  647. }
  648. return state;
  649. }
  650. int do_eep_wren (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  651. {
  652. int query = argc == 1;
  653. int state = 0;
  654. if (query) {
  655. /* Query write access state. */
  656. state = eeprom_write_enable (CFG_I2C_EEPROM_ADDR, -1);
  657. if (state < 0) {
  658. puts ("Query of write access state failed.\n");
  659. } else {
  660. printf ("Write access for device 0x%0x is %sabled.\n",
  661. CFG_I2C_EEPROM_ADDR, state ? "en" : "dis");
  662. state = 0;
  663. }
  664. } else {
  665. if ('0' == argv[1][0]) {
  666. /* Disable write access. */
  667. state = eeprom_write_enable (CFG_I2C_EEPROM_ADDR, 0);
  668. } else {
  669. /* Enable write access. */
  670. state = eeprom_write_enable (CFG_I2C_EEPROM_ADDR, 1);
  671. }
  672. if (state < 0) {
  673. puts ("Setup of write access state failed.\n");
  674. }
  675. }
  676. return state;
  677. }
  678. U_BOOT_CMD(eepwren, 2, 0, do_eep_wren,
  679. "eepwren - Enable / disable / query EEPROM write access\n",
  680. NULL);
  681. #endif /* #if defined(CFG_EEPROM_WREN) */
  682. #ifdef CONFIG_VIDEO_SM501
  683. #ifdef CONFIG_CONSOLE_EXTRA_INFO
  684. /*
  685. * Return text to be printed besides the logo.
  686. */
  687. void video_get_info_str (int line_number, char *info)
  688. {
  689. DECLARE_GLOBAL_DATA_PTR;
  690. char str[64];
  691. char str2[64];
  692. int i = getenv_r("serial#", str2, sizeof(str));
  693. if (line_number == 1) {
  694. sprintf(str, " Board: ");
  695. if (i == -1) {
  696. strcat(str, "### No HW ID - assuming HH405");
  697. } else {
  698. strcat(str, str2);
  699. }
  700. if (getenv_r("bd_type", str2, sizeof(str2)) != -1) {
  701. strcat(str, " (");
  702. strcat(str, str2);
  703. } else {
  704. strcat(str, " (Missing bd_type!");
  705. }
  706. sprintf(str2, ", Rev %ld.x)", gd->board_type);
  707. strcat(str, str2);
  708. strcpy(info, str);
  709. } else {
  710. info [0] = '\0';
  711. }
  712. }
  713. #endif /* CONFIG_CONSOLE_EXTRA_INFO */
  714. /*
  715. * Returns SM501 register base address. First thing called in the driver.
  716. */
  717. unsigned int board_video_init (void)
  718. {
  719. pci_dev_t devbusfn;
  720. u32 addr;
  721. /*
  722. * Is SM501 connected (ppc221/ppc231)?
  723. */
  724. devbusfn = pci_find_device(PCI_VENDOR_SM, PCI_DEVICE_SM501, 0);
  725. if (devbusfn != -1) {
  726. pci_read_config_dword(devbusfn, PCI_BASE_ADDRESS_1, (u32 *)&addr);
  727. return (addr & 0xfffffffe);
  728. }
  729. return 0;
  730. }
  731. /*
  732. * Returns SM501 framebuffer address
  733. */
  734. unsigned int board_video_get_fb (void)
  735. {
  736. pci_dev_t devbusfn;
  737. u32 addr;
  738. /*
  739. * Is SM501 connected (ppc221/ppc231)?
  740. */
  741. devbusfn = pci_find_device(PCI_VENDOR_SM, PCI_DEVICE_SM501, 0);
  742. if (devbusfn != -1) {
  743. pci_read_config_dword(devbusfn, PCI_BASE_ADDRESS_0, (u32 *)&addr);
  744. addr &= 0xfffffffe;
  745. #ifdef CONFIG_VIDEO_SM501_FBMEM_OFFSET
  746. addr += CONFIG_VIDEO_SM501_FBMEM_OFFSET;
  747. #endif
  748. return addr;
  749. }
  750. return 0;
  751. }
  752. /*
  753. * Called after initializing the SM501 and before clearing the screen.
  754. */
  755. void board_validate_screen (unsigned int base)
  756. {
  757. }
  758. /*
  759. * Return a pointer to the initialization sequence.
  760. */
  761. const SMI_REGS *board_get_regs (void)
  762. {
  763. char *str;
  764. str = getenv("bd_type");
  765. if (strcmp(str, "ppc221") == 0) {
  766. return init_regs_800x600;
  767. } else {
  768. return init_regs_1024x768;
  769. }
  770. }
  771. int board_get_width (void)
  772. {
  773. char *str;
  774. str = getenv("bd_type");
  775. if (strcmp(str, "ppc221") == 0) {
  776. return 800;
  777. } else {
  778. return 1024;
  779. }
  780. }
  781. int board_get_height (void)
  782. {
  783. char *str;
  784. str = getenv("bd_type");
  785. if (strcmp(str, "ppc221") == 0) {
  786. return 600;
  787. } else {
  788. return 768;
  789. }
  790. }
  791. #endif /* CONFIG_VIDEO_SM501 */
  792. void reset_phy(void)
  793. {
  794. #ifdef CONFIG_LXT971_NO_SLEEP
  795. /*
  796. * Disable sleep mode in LXT971
  797. */
  798. lxt971_no_sleep();
  799. #endif
  800. }