hh405.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912
  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 * const 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. /* logo bitmap data - gzip compressed and generated by bin2c */
  232. unsigned char logo_bmp_320[] =
  233. {
  234. #include "logo_320_240_4bpp.c"
  235. };
  236. unsigned char logo_bmp_320_8bpp[] =
  237. {
  238. #include "logo_320_240_8bpp.c"
  239. };
  240. unsigned char logo_bmp_640[] =
  241. {
  242. #include "logo_640_480_24bpp.c"
  243. };
  244. unsigned char logo_bmp_1024[] =
  245. {
  246. #include "logo_1024_768_8bpp.c"
  247. };
  248. /*
  249. * include common lcd code (for esd boards)
  250. */
  251. #include "../common/lcd.c"
  252. #include "../common/s1d13704_320_240_4bpp.h"
  253. #include "../common/s1d13705_320_240_8bpp.h"
  254. #include "../common/s1d13806_640_480_16bpp.h"
  255. #include "../common/s1d13806_1024_768_8bpp.h"
  256. /*
  257. * include common auto-update code (for esd boards)
  258. */
  259. #include "../common/auto_update.h"
  260. au_image_t au_image[] = {
  261. {"hh405/preinst.img", 0, -1, AU_SCRIPT},
  262. {"hh405/u-boot.img", 0xfff80000, 0x00080000, AU_FIRMWARE},
  263. {"hh405/pImage_${bd_type}", 0x00000000, 0x00100000, AU_NAND},
  264. {"hh405/pImage.initrd", 0x00100000, 0x00200000, AU_NAND},
  265. {"hh405/yaffsmt2.img", 0x00300000, 0x01c00000, AU_NAND},
  266. {"hh405/postinst.img", 0, 0, AU_SCRIPT},
  267. };
  268. int N_AU_IMAGES = (sizeof(au_image) / sizeof(au_image[0]));
  269. /*
  270. * Get version of HH405 board from GPIO's
  271. */
  272. int board_revision(void)
  273. {
  274. unsigned long osrh_reg;
  275. unsigned long isr1h_reg;
  276. unsigned long tcr_reg;
  277. unsigned long value;
  278. /*
  279. * Setup GPIO pins (BLAST/GPIO0 and GPIO9 as GPIO)
  280. */
  281. osrh_reg = in_be32((void *)GPIO0_OSRH);
  282. isr1h_reg = in_be32((void *)GPIO0_ISR1H);
  283. tcr_reg = in_be32((void *)GPIO0_TCR);
  284. out_be32((void *)GPIO0_OSRH, osrh_reg & ~0xC0003000); /* output select */
  285. out_be32((void *)GPIO0_ISR1H, isr1h_reg | 0xC0003000); /* input select */
  286. out_be32((void *)GPIO0_TCR, tcr_reg & ~0x80400000); /* select input */
  287. udelay(1000); /* wait some time before reading input */
  288. value = in_be32((void *)GPIO0_IR) & 0x80400000; /* get config bits */
  289. /*
  290. * Restore GPIO settings
  291. */
  292. out_be32((void *)GPIO0_OSRH, osrh_reg); /* output select */
  293. out_be32((void *)GPIO0_ISR1H, isr1h_reg); /* input select */
  294. out_be32((void *)GPIO0_TCR, tcr_reg); /* enable output driver for outputs */
  295. if (value & 0x80000000) {
  296. /* Revision 1.0 or 1.1 detected */
  297. return 1;
  298. } else {
  299. if (value & 0x00400000) {
  300. /* unused */
  301. return 3;
  302. } else {
  303. return 2;
  304. }
  305. }
  306. }
  307. int board_early_init_f (void)
  308. {
  309. /*
  310. * IRQ 0-15 405GP internally generated; active high; level sensitive
  311. * IRQ 16 405GP internally generated; active low; level sensitive
  312. * IRQ 17-24 RESERVED
  313. * IRQ 25 (EXT IRQ 0) CAN0; active low; level sensitive
  314. * IRQ 26 (EXT IRQ 1) SER0 ; active low; level sensitive
  315. * IRQ 27 (EXT IRQ 2) SER1; active low; level sensitive
  316. * IRQ 28 (EXT IRQ 3) FPGA 0; active low; level sensitive
  317. * IRQ 29 (EXT IRQ 4) FPGA 1; active low; level sensitive
  318. * IRQ 30 (EXT IRQ 5) PCI INTA; active low; level sensitive
  319. * IRQ 31 (EXT IRQ 6) COMPACT FLASH; active high; level sensitive
  320. */
  321. mtdcr(UIC0SR, 0xFFFFFFFF); /* clear all ints */
  322. mtdcr(UIC0ER, 0x00000000); /* disable all ints */
  323. mtdcr(UIC0CR, 0x00000000); /* set all to be non-critical*/
  324. mtdcr(UIC0PR, CONFIG_SYS_UIC0_POLARITY);/* set int polarities */
  325. mtdcr(UIC0TR, 0x10000000); /* set int trigger levels */
  326. mtdcr(UIC0VCR, 0x00000001); /* set vect base=0,INT0 highest priority*/
  327. mtdcr(UIC0SR, 0xFFFFFFFF); /* clear all ints */
  328. /*
  329. * EBC Configuration Register: set ready timeout to 512 ebc-clks -> ca. 15 us
  330. */
  331. mtebc(EBC0_CFG, 0xa8400000); /* ebc always driven */
  332. return 0;
  333. }
  334. int cf_enable(void)
  335. {
  336. int i;
  337. if (gd->board_type >= 2) {
  338. if (in_be16(FPGA_STATUS) & FPGA_STATUS_CF_DETECT) {
  339. if (!(in_be16(FPGA_CTRL) & FPGA_CTRL_CF_BUS_EN)) {
  340. out_be16(FPGA_CTRL,
  341. in_be16(FPGA_CTRL) & ~FPGA_CTRL_CF_PWRN);
  342. for (i=0; i<300; i++)
  343. udelay(1000);
  344. out_be16(FPGA_CTRL,
  345. in_be16(FPGA_CTRL) | FPGA_CTRL_CF_BUS_EN);
  346. for (i=0; i<20; i++)
  347. udelay(1000);
  348. }
  349. } else {
  350. out_be16(FPGA_CTRL,
  351. in_be16(FPGA_CTRL) & ~FPGA_CTRL_CF_BUS_EN);
  352. out_be16(FPGA_CTRL,
  353. in_be16(FPGA_CTRL) | FPGA_CTRL_CF_PWRN);
  354. }
  355. }
  356. return 0;
  357. }
  358. int misc_init_r (void)
  359. {
  360. unsigned char *dst;
  361. ulong len = sizeof(fpgadata);
  362. int status;
  363. int index;
  364. int i;
  365. char *str;
  366. unsigned long contrast0 = 0xffffffff;
  367. dst = malloc(CONFIG_SYS_FPGA_MAX_SIZE);
  368. if (gunzip (dst, CONFIG_SYS_FPGA_MAX_SIZE, (uchar *)fpgadata, &len) != 0) {
  369. printf ("GUNZIP ERROR - must RESET board to recover\n");
  370. do_reset (NULL, 0, 0, NULL);
  371. }
  372. status = fpga_boot(dst, len);
  373. if (status != 0) {
  374. printf("\nFPGA: Booting failed ");
  375. switch (status) {
  376. case ERROR_FPGA_PRG_INIT_LOW:
  377. printf("(Timeout: INIT not low after asserting PROGRAM*)\n ");
  378. break;
  379. case ERROR_FPGA_PRG_INIT_HIGH:
  380. printf("(Timeout: INIT not high after deasserting PROGRAM*)\n ");
  381. break;
  382. case ERROR_FPGA_PRG_DONE:
  383. printf("(Timeout: DONE not high after programming FPGA)\n ");
  384. break;
  385. }
  386. /* display infos on fpgaimage */
  387. index = 15;
  388. for (i=0; i<4; i++) {
  389. len = dst[index];
  390. printf("FPGA: %s\n", &(dst[index+1]));
  391. index += len+3;
  392. }
  393. putc ('\n');
  394. /* delayed reboot */
  395. for (i=20; i>0; i--) {
  396. printf("Rebooting in %2d seconds \r",i);
  397. for (index=0;index<1000;index++)
  398. udelay(1000);
  399. }
  400. putc ('\n');
  401. do_reset(NULL, 0, 0, NULL);
  402. }
  403. puts("FPGA: ");
  404. /* display infos on fpgaimage */
  405. index = 15;
  406. for (i=0; i<4; i++) {
  407. len = dst[index];
  408. printf("%s ", &(dst[index+1]));
  409. index += len+3;
  410. }
  411. putc ('\n');
  412. free(dst);
  413. /*
  414. * Reset FPGA via FPGA_INIT pin
  415. */
  416. /* setup FPGA_INIT as output */
  417. out_be32((void *)GPIO0_TCR,
  418. in_be32((void *)GPIO0_TCR) | FPGA_INIT);
  419. out_be32((void *)GPIO0_OR,
  420. in_be32((void *)GPIO0_OR) & ~FPGA_INIT); /* reset low */
  421. udelay(1000); /* wait 1ms */
  422. out_be32((void *)GPIO0_OR,
  423. in_be32((void *)GPIO0_OR) | FPGA_INIT); /* reset high */
  424. udelay(1000); /* wait 1ms */
  425. /*
  426. * Write Board revision into FPGA
  427. */
  428. out_be16(FPGA_CTRL, in_be16(FPGA_CTRL) | (gd->board_type & 0x0003));
  429. /*
  430. * Setup and enable EEPROM write protection
  431. */
  432. out_be32((void *)GPIO0_OR,
  433. in_be32((void *)GPIO0_OR) | CONFIG_SYS_EEPROM_WP);
  434. /*
  435. * Reset touch-screen controller
  436. */
  437. out_be32((void *)GPIO0_OR,
  438. in_be32((void *)GPIO0_OR) & ~CONFIG_SYS_TOUCH_RST);
  439. udelay(1000);
  440. out_be32((void *)GPIO0_OR,
  441. in_be32((void *)GPIO0_OR) | CONFIG_SYS_TOUCH_RST);
  442. /*
  443. * Enable power on PS/2 interface (with reset)
  444. */
  445. out_be16(FPGA_CTRL, in_be16(FPGA_CTRL) & ~FPGA_CTRL_PS2_PWR);
  446. for (i=0;i<500;i++)
  447. udelay(1000);
  448. out_be16(FPGA_CTRL, in_be16(FPGA_CTRL) | FPGA_CTRL_PS2_PWR);
  449. /*
  450. * Get contrast value from environment variable
  451. */
  452. str = getenv("contrast0");
  453. if (str) {
  454. contrast0 = simple_strtol(str, NULL, 16);
  455. if (contrast0 > 255) {
  456. printf("ERROR: contrast0 value too high (0x%lx)!\n",
  457. contrast0);
  458. contrast0 = 0xffffffff;
  459. }
  460. }
  461. /*
  462. * Init lcd interface and display logo
  463. */
  464. str = getenv("bd_type");
  465. if (strcmp(str, "ppc230") == 0) {
  466. /*
  467. * Switch backlight on
  468. */
  469. out_be16(FPGA_CTRL,
  470. in_be16(FPGA_CTRL) | FPGA_CTRL_VGA0_BL);
  471. out_be16(FPGA_BL, 0x0000);
  472. lcd_setup(1, 0);
  473. lcd_init((uchar *)CONFIG_SYS_LCD_BIG_REG, (uchar *)CONFIG_SYS_LCD_BIG_MEM,
  474. regs_13806_1024_768_8bpp,
  475. sizeof(regs_13806_1024_768_8bpp)/sizeof(regs_13806_1024_768_8bpp[0]),
  476. logo_bmp_1024, sizeof(logo_bmp_1024));
  477. } else if (strcmp(str, "ppc220") == 0) {
  478. /*
  479. * Switch backlight on
  480. */
  481. out_be16(FPGA_CTRL,
  482. in_be16(FPGA_CTRL) & ~FPGA_CTRL_VGA0_BL);
  483. out_be16(FPGA_BL, 0x0000);
  484. lcd_setup(1, 0);
  485. lcd_init((uchar *)CONFIG_SYS_LCD_BIG_REG, (uchar *)CONFIG_SYS_LCD_BIG_MEM,
  486. regs_13806_640_480_16bpp,
  487. sizeof(regs_13806_640_480_16bpp)/sizeof(regs_13806_640_480_16bpp[0]),
  488. logo_bmp_640, sizeof(logo_bmp_640));
  489. } else if (strcmp(str, "ppc215") == 0) {
  490. /*
  491. * Set default display contrast voltage
  492. */
  493. if (contrast0 == 0xffffffff) {
  494. out_be16(FPGA_CTR, 0x0082);
  495. } else {
  496. out_be16(FPGA_CTR, contrast0);
  497. }
  498. out_be16(FPGA_BL, 0xffff);
  499. /*
  500. * Switch backlight on
  501. */
  502. out_be16(FPGA_CTRL,
  503. in_be16(FPGA_CTRL) |
  504. FPGA_CTRL_VGA0_BL |
  505. FPGA_CTRL_VGA0_BL_MODE);
  506. /*
  507. * Set lcd clock (small epson)
  508. */
  509. out_be16(FPGA_CTRL, in_be16(FPGA_CTRL) | LCD_CLK_06250);
  510. udelay(100); /* wait for 100 us */
  511. lcd_setup(0, 1);
  512. lcd_init((uchar *)CONFIG_SYS_LCD_SMALL_REG, (uchar *)CONFIG_SYS_LCD_SMALL_MEM,
  513. regs_13705_320_240_8bpp,
  514. sizeof(regs_13705_320_240_8bpp)/sizeof(regs_13705_320_240_8bpp[0]),
  515. logo_bmp_320_8bpp, sizeof(logo_bmp_320_8bpp));
  516. } else if (strcmp(str, "ppc210") == 0) {
  517. /*
  518. * Set default display contrast voltage
  519. */
  520. if (contrast0 == 0xffffffff) {
  521. out_be16(FPGA_CTR, 0x0060);
  522. } else {
  523. out_be16(FPGA_CTR, contrast0);
  524. }
  525. out_be16(FPGA_BL, 0xffff);
  526. /*
  527. * Switch backlight on
  528. */
  529. out_be16(FPGA_CTRL,
  530. in_be16(FPGA_CTRL) |
  531. FPGA_CTRL_VGA0_BL |
  532. FPGA_CTRL_VGA0_BL_MODE);
  533. /*
  534. * Set lcd clock (small epson), enable 1-wire interface
  535. */
  536. out_be16(FPGA_CTRL,
  537. in_be16(FPGA_CTRL) |
  538. LCD_CLK_08330 |
  539. FPGA_CTRL_OW_ENABLE);
  540. lcd_setup(0, 1);
  541. lcd_init((uchar *)CONFIG_SYS_LCD_SMALL_REG, (uchar *)CONFIG_SYS_LCD_SMALL_MEM,
  542. regs_13704_320_240_4bpp,
  543. sizeof(regs_13704_320_240_4bpp)/sizeof(regs_13704_320_240_4bpp[0]),
  544. logo_bmp_320, sizeof(logo_bmp_320));
  545. #ifdef CONFIG_VIDEO_SM501
  546. } else {
  547. pci_dev_t devbusfn;
  548. /*
  549. * Is SM501 connected (ppc221/ppc231)?
  550. */
  551. devbusfn = pci_find_device(PCI_VENDOR_SM, PCI_DEVICE_SM501, 0);
  552. if (devbusfn != -1) {
  553. puts("VGA: SM501 with 8 MB ");
  554. if (strcmp(str, "ppc221") == 0) {
  555. printf("(800*600, %dbpp)\n", BPP);
  556. out_be16(FPGA_BL, 0x002d); /* max. allowed brightness */
  557. } else if (strcmp(str, "ppc231") == 0) {
  558. printf("(1024*768, %dbpp)\n", BPP);
  559. out_be16(FPGA_BL, 0x0000);
  560. } else {
  561. printf("Unsupported bd_type defined (%s) -> No display configured!\n", str);
  562. return 0;
  563. }
  564. } else {
  565. printf("Unsupported bd_type defined (%s) -> No display configured!\n", str);
  566. return 0;
  567. }
  568. #endif /* CONFIG_VIDEO_SM501 */
  569. }
  570. cf_enable();
  571. return (0);
  572. }
  573. /*
  574. * Check Board Identity:
  575. */
  576. int checkboard (void)
  577. {
  578. char str[64];
  579. int i = getenv_f("serial#", str, sizeof(str));
  580. puts ("Board: ");
  581. if (i == -1) {
  582. puts ("### No HW ID - assuming HH405");
  583. } else {
  584. puts(str);
  585. }
  586. if (getenv_f("bd_type", str, sizeof(str)) != -1) {
  587. printf(" (%s", str);
  588. } else {
  589. puts(" (Missing bd_type!");
  590. }
  591. gd->board_type = board_revision();
  592. printf(", Rev %ld.x)\n", gd->board_type);
  593. return 0;
  594. }
  595. #ifdef CONFIG_IDE_RESET
  596. void ide_set_reset(int on)
  597. {
  598. if (((gd->board_type >= 2) &&
  599. (in_be16(FPGA_STATUS) & FPGA_STATUS_CF_DETECT)) ||
  600. (gd->board_type < 2)) {
  601. /*
  602. * Assert or deassert CompactFlash Reset Pin
  603. */
  604. if (on) { /* assert RESET */
  605. cf_enable();
  606. out_be16(FPGA_CTRL,
  607. in_be16(FPGA_CTRL) &
  608. ~FPGA_CTRL_CF_RESET);
  609. } else { /* release RESET */
  610. out_be16(FPGA_CTRL,
  611. in_be16(FPGA_CTRL) |
  612. FPGA_CTRL_CF_RESET);
  613. }
  614. }
  615. }
  616. #endif /* CONFIG_IDE_RESET */
  617. #if defined(CONFIG_SYS_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 (CONFIG_SYS_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. out_be32((void *)GPIO0_OR,
  635. in_be32((void *)GPIO0_OR) & ~CONFIG_SYS_EEPROM_WP);
  636. state = 0;
  637. break;
  638. case 0:
  639. /* Disable write access, set bit GPIO_SINT2. */
  640. out_be32((void *)GPIO0_OR,
  641. in_be32((void *)GPIO0_OR) | CONFIG_SYS_EEPROM_WP);
  642. state = 0;
  643. break;
  644. default:
  645. /* Read current status back. */
  646. state = (0 == (in_be32((void *)GPIO0_OR) &
  647. CONFIG_SYS_EEPROM_WP));
  648. break;
  649. }
  650. }
  651. return state;
  652. }
  653. int do_eep_wren (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  654. {
  655. int query = argc == 1;
  656. int state = 0;
  657. if (query) {
  658. /* Query write access state. */
  659. state = eeprom_write_enable (CONFIG_SYS_I2C_EEPROM_ADDR, -1);
  660. if (state < 0) {
  661. puts ("Query of write access state failed.\n");
  662. } else {
  663. printf ("Write access for device 0x%0x is %sabled.\n",
  664. CONFIG_SYS_I2C_EEPROM_ADDR, state ? "en" : "dis");
  665. state = 0;
  666. }
  667. } else {
  668. if ('0' == argv[1][0]) {
  669. /* Disable write access. */
  670. state = eeprom_write_enable (CONFIG_SYS_I2C_EEPROM_ADDR, 0);
  671. } else {
  672. /* Enable write access. */
  673. state = eeprom_write_enable (CONFIG_SYS_I2C_EEPROM_ADDR, 1);
  674. }
  675. if (state < 0) {
  676. puts ("Setup of write access state failed.\n");
  677. }
  678. }
  679. return state;
  680. }
  681. U_BOOT_CMD(eepwren, 2, 0, do_eep_wren,
  682. "Enable / disable / query EEPROM write access",
  683. ""
  684. );
  685. #endif /* #if defined(CONFIG_SYS_EEPROM_WREN) */
  686. #ifdef CONFIG_VIDEO_SM501
  687. #ifdef CONFIG_CONSOLE_EXTRA_INFO
  688. /*
  689. * Return text to be printed besides the logo.
  690. */
  691. void video_get_info_str (int line_number, char *info)
  692. {
  693. char str[64];
  694. char str2[64];
  695. int i = getenv_f("serial#", str2, sizeof(str));
  696. if (line_number == 1) {
  697. sprintf(str, " Board: ");
  698. if (i == -1) {
  699. strcat(str, "### No HW ID - assuming HH405");
  700. } else {
  701. strcat(str, str2);
  702. }
  703. if (getenv_f("bd_type", str2, sizeof(str2)) != -1) {
  704. strcat(str, " (");
  705. strcat(str, str2);
  706. } else {
  707. strcat(str, " (Missing bd_type!");
  708. }
  709. sprintf(str2, ", Rev %ld.x)", gd->board_type);
  710. strcat(str, str2);
  711. strcpy(info, str);
  712. } else {
  713. info [0] = '\0';
  714. }
  715. }
  716. #endif /* CONFIG_CONSOLE_EXTRA_INFO */
  717. /*
  718. * Returns SM501 register base address. First thing called in the driver.
  719. */
  720. unsigned int board_video_init (void)
  721. {
  722. pci_dev_t devbusfn;
  723. u32 addr;
  724. /*
  725. * Is SM501 connected (ppc221/ppc231)?
  726. */
  727. devbusfn = pci_find_device(PCI_VENDOR_SM, PCI_DEVICE_SM501, 0);
  728. if (devbusfn != -1) {
  729. pci_read_config_dword(devbusfn, PCI_BASE_ADDRESS_1, (u32 *)&addr);
  730. return (addr & 0xfffffffe);
  731. }
  732. return 0;
  733. }
  734. /*
  735. * Returns SM501 framebuffer address
  736. */
  737. unsigned int board_video_get_fb (void)
  738. {
  739. pci_dev_t devbusfn;
  740. u32 addr;
  741. /*
  742. * Is SM501 connected (ppc221/ppc231)?
  743. */
  744. devbusfn = pci_find_device(PCI_VENDOR_SM, PCI_DEVICE_SM501, 0);
  745. if (devbusfn != -1) {
  746. pci_read_config_dword(devbusfn, PCI_BASE_ADDRESS_0, (u32 *)&addr);
  747. addr &= 0xfffffffe;
  748. #ifdef CONFIG_VIDEO_SM501_FBMEM_OFFSET
  749. addr += CONFIG_VIDEO_SM501_FBMEM_OFFSET;
  750. #endif
  751. return addr;
  752. }
  753. return 0;
  754. }
  755. /*
  756. * Called after initializing the SM501 and before clearing the screen.
  757. */
  758. void board_validate_screen (unsigned int base)
  759. {
  760. }
  761. /*
  762. * Return a pointer to the initialization sequence.
  763. */
  764. const SMI_REGS *board_get_regs (void)
  765. {
  766. char *str;
  767. str = getenv("bd_type");
  768. if (strcmp(str, "ppc221") == 0) {
  769. return init_regs_800x600;
  770. } else {
  771. return init_regs_1024x768;
  772. }
  773. }
  774. int board_get_width (void)
  775. {
  776. char *str;
  777. str = getenv("bd_type");
  778. if (strcmp(str, "ppc221") == 0) {
  779. return 800;
  780. } else {
  781. return 1024;
  782. }
  783. }
  784. int board_get_height (void)
  785. {
  786. char *str;
  787. str = getenv("bd_type");
  788. if (strcmp(str, "ppc221") == 0) {
  789. return 600;
  790. } else {
  791. return 768;
  792. }
  793. }
  794. #endif /* CONFIG_VIDEO_SM501 */
  795. void reset_phy(void)
  796. {
  797. #ifdef CONFIG_LXT971_NO_SLEEP
  798. /*
  799. * Disable sleep mode in LXT971
  800. */
  801. lxt971_no_sleep();
  802. #endif
  803. }