hh405.c 24 KB

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