hh405.c 23 KB

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