lcd.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350
  1. /*
  2. * (C) Copyright 2001-2002
  3. * Wolfgang Denk, DENX Software Engineering -- wd@denx.de
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. /************************************************************************/
  24. /* ** HEADER FILES */
  25. /************************************************************************/
  26. /* #define DEBUG */
  27. #include <config.h>
  28. #include <common.h>
  29. #include <watchdog.h>
  30. #include <version.h>
  31. #include <stdarg.h>
  32. #include <lcdvideo.h>
  33. #include <linux/types.h>
  34. #include <devices.h>
  35. #if defined(CONFIG_POST)
  36. #include <post.h>
  37. #endif
  38. #include <lcd.h>
  39. #ifdef CONFIG_LCD
  40. /************************************************************************/
  41. /* ** CONFIG STUFF -- should be moved to board config file */
  42. /************************************************************************/
  43. #define CONFIG_LCD_LOGO
  44. #define LCD_INFO /* Display Logo, (C) and system info */
  45. #if defined(CONFIG_V37) || defined(CONFIG_EDT32F10)
  46. #undef CONFIG_LCD_LOGO
  47. #undef LCD_INFO
  48. #endif
  49. /* #define LCD_TEST_PATTERN */ /* color backgnd for frame/color adjust */
  50. /* #define CFG_INVERT_COLORS */ /* Not needed - adjust vl_dp instead */
  51. /************************************************************************/
  52. /************************************************************************/
  53. /* ** BITMAP DISPLAY SUPPORT -- should probably be moved elsewhere */
  54. /************************************************************************/
  55. #if (CONFIG_COMMANDS & CFG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
  56. #include <bmp_layout.h>
  57. #endif /* (CONFIG_COMMANDS & CFG_CMD_BMP) || CONFIG_SPLASH_SCREEN */
  58. /************************************************************************/
  59. /* ** FONT AND LOGO DATA */
  60. /************************************************************************/
  61. #include <video_font.h> /* Get font data, width and height */
  62. #ifdef CONFIG_LCD_LOGO
  63. # include <bmp_logo.h> /* Get logo data, width and height */
  64. #endif
  65. /************************************************************************/
  66. /************************************************************************/
  67. /*
  68. * Information about displays we are using. This is for configuring
  69. * the LCD controller and memory allocation. Someone has to know what
  70. * is connected, as we can't autodetect anything.
  71. */
  72. #define CFG_HIGH 0 /* Pins are active high */
  73. #define CFG_LOW 1 /* Pins are active low */
  74. typedef struct vidinfo {
  75. ushort vl_col; /* Number of columns (i.e. 640) */
  76. ushort vl_row; /* Number of rows (i.e. 480) */
  77. ushort vl_width; /* Width of display area in millimeters */
  78. ushort vl_height; /* Height of display area in millimeters */
  79. /* LCD configuration register.
  80. */
  81. u_char vl_clkp; /* Clock polarity */
  82. u_char vl_oep; /* Output Enable polarity */
  83. u_char vl_hsp; /* Horizontal Sync polarity */
  84. u_char vl_vsp; /* Vertical Sync polarity */
  85. u_char vl_dp; /* Data polarity */
  86. u_char vl_bpix; /* Bits per pixel, 0 = 1, 1 = 2, 2 = 4, 3 = 8 */
  87. u_char vl_lbw; /* LCD Bus width, 0 = 4, 1 = 8 */
  88. u_char vl_splt; /* Split display, 0 = single-scan, 1 = dual-scan */
  89. u_char vl_clor; /* Color, 0 = mono, 1 = color */
  90. u_char vl_tft; /* 0 = passive, 1 = TFT */
  91. /* Horizontal control register. Timing from data sheet.
  92. */
  93. ushort vl_wbl; /* Wait between lines */
  94. /* Vertical control register.
  95. */
  96. u_char vl_vpw; /* Vertical sync pulse width */
  97. u_char vl_lcdac; /* LCD AC timing */
  98. u_char vl_wbf; /* Wait between frames */
  99. } vidinfo_t;
  100. #define LCD_MONOCHROME 0
  101. #define LCD_COLOR2 1
  102. #define LCD_COLOR4 2
  103. #define LCD_COLOR8 3
  104. /*----------------------------------------------------------------------*/
  105. #ifdef CONFIG_KYOCERA_KCS057QV1AJ
  106. /*
  107. * Kyocera KCS057QV1AJ-G23. Passive, color, single scan.
  108. */
  109. #define LCD_BPP LCD_COLOR4
  110. static vidinfo_t panel_info = {
  111. 640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH,
  112. LCD_BPP, 1, 0, 1, 0, 5, 0, 0, 0
  113. /* wbl, vpw, lcdac, wbf */
  114. };
  115. #endif /* CONFIG_KYOCERA_KCS057QV1AJ */
  116. /*----------------------------------------------------------------------*/
  117. /*----------------------------------------------------------------------*/
  118. #ifdef CONFIG_HITACHI_SP19X001_Z1A
  119. /*
  120. * Hitachi SP19X001-. Active, color, single scan.
  121. */
  122. static vidinfo_t panel_info = {
  123. 640, 480, 154, 116, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH,
  124. LCD_COLOR8, 1, 0, 1, 0, 0, 0, 0, 0
  125. /* wbl, vpw, lcdac, wbf */
  126. };
  127. #endif /* CONFIG_HITACHI_SP19X001_Z1A */
  128. /*----------------------------------------------------------------------*/
  129. /*----------------------------------------------------------------------*/
  130. #ifdef CONFIG_NEC_NL6648AC33
  131. /*
  132. * NEC NL6648AC33-18. Active, color, single scan.
  133. */
  134. static vidinfo_t panel_info = {
  135. 640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
  136. 3, 0, 0, 1, 1, 144, 2, 0, 33
  137. /* wbl, vpw, lcdac, wbf */
  138. };
  139. #endif /* CONFIG_NEC_NL6648AC33 */
  140. /*----------------------------------------------------------------------*/
  141. #ifdef CONFIG_NEC_NL6648BC20
  142. /*
  143. * NEC NL6648BC20-08. 6.5", 640x480. Active, color, single scan.
  144. */
  145. static vidinfo_t panel_info = {
  146. 640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
  147. 3, 0, 0, 1, 1, 144, 2, 0, 33
  148. /* wbl, vpw, lcdac, wbf */
  149. };
  150. #endif /* CONFIG_NEC_NL6648BC20 */
  151. /*----------------------------------------------------------------------*/
  152. #ifdef CONFIG_SHARP_LQ104V7DS01
  153. /*
  154. * SHARP LQ104V7DS01. 6.5", 640x480. Active, color, single scan.
  155. */
  156. static vidinfo_t panel_info = {
  157. 640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_LOW,
  158. 3, 0, 0, 1, 1, 25, 1, 0, 33
  159. /* wbl, vpw, lcdac, wbf */
  160. };
  161. #endif /* CONFIG_SHARP_LQ104V7DS01 */
  162. /*----------------------------------------------------------------------*/
  163. #ifdef CONFIG_SHARP_16x9
  164. /*
  165. * Sharp 320x240. Active, color, single scan. It isn't 16x9, and I am
  166. * not sure what it is.......
  167. */
  168. static vidinfo_t panel_info = {
  169. 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH,
  170. 3, 0, 0, 1, 1, 15, 4, 0, 3
  171. };
  172. #endif /* CONFIG_SHARP_16x9 */
  173. /*----------------------------------------------------------------------*/
  174. #ifdef CONFIG_SHARP_LQ057Q3DC02
  175. /*
  176. * Sharp LQ057Q3DC02 display. Active, color, single scan.
  177. */
  178. #define LCD_DF 12
  179. static vidinfo_t panel_info = {
  180. 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
  181. 3, 0, 0, 1, 1, 15, 4, 0, 3
  182. /* wbl, vpw, lcdac, wbf */
  183. };
  184. #define LCD_INFO_BELOW_LOGO
  185. #endif /* CONFIG_SHARP_LQ057Q3DC02 */
  186. /*----------------------------------------------------------------------*/
  187. #ifdef CONFIG_SHARP_LQ64D341
  188. /*
  189. * Sharp LQ64D341 display, 640x480. Active, color, single scan.
  190. */
  191. static vidinfo_t panel_info = {
  192. 640, 480, 0, 0, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
  193. 3, 0, 0, 1, 1, 128, 16, 0, 32
  194. /* wbl, vpw, lcdac, wbf */
  195. };
  196. #endif /* CONFIG_SHARP_LQ64D341 */
  197. #ifdef CONFIG_SHARP_LQ084V1DG21
  198. /*
  199. * Sharp LQ084V1DG21 display, 640x480. Active, color, single scan.
  200. */
  201. static vidinfo_t panel_info = {
  202. 640, 480, 171, 129, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_LOW,
  203. 3, 0, 0, 1, 1, 160, 3, 0, 48
  204. /* wbl, vpw, lcdac, wbf */
  205. };
  206. #endif /* CONFIG_SHARP_LQ084V1DG21 */
  207. /*----------------------------------------------------------------------*/
  208. #ifdef CONFIG_HLD1045
  209. /*
  210. * HLD1045 display, 640x480. Active, color, single scan.
  211. */
  212. static vidinfo_t panel_info = {
  213. 640, 480, 0, 0, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
  214. 3, 0, 0, 1, 1, 160, 3, 0, 48
  215. /* wbl, vpw, lcdac, wbf */
  216. };
  217. #endif /* CONFIG_HLD1045 */
  218. /*----------------------------------------------------------------------*/
  219. #ifdef CONFIG_PRIMEVIEW_V16C6448AC
  220. /*
  221. * Prime View V16C6448AC
  222. */
  223. static vidinfo_t panel_info = {
  224. 640, 480, 130, 98, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
  225. 3, 0, 0, 1, 1, 144, 2, 0, 35
  226. /* wbl, vpw, lcdac, wbf */
  227. };
  228. #endif /* CONFIG_PRIMEVIEW_V16C6448AC */
  229. /*----------------------------------------------------------------------*/
  230. #ifdef CONFIG_OPTREX_BW
  231. /*
  232. * Optrex CBL50840-2 NF-FW 99 22 M5
  233. * or
  234. * Hitachi LMG6912RPFC-00T
  235. * or
  236. * Hitachi SP14Q002
  237. *
  238. * 320x240. Black & white.
  239. */
  240. #define OPTREX_BPP 0 /* 0 - monochrome, 1 bpp */
  241. /* 1 - 4 grey levels, 2 bpp */
  242. /* 2 - 16 grey levels, 4 bpp */
  243. static vidinfo_t panel_info = {
  244. 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_LOW,
  245. OPTREX_BPP, 0, 0, 0, 0, 0, 0, 0, 0, 4
  246. };
  247. #endif /* CONFIG_OPTREX_BW */
  248. /*-----------------------------------------------------------------*/
  249. #ifdef CONFIG_EDT32F10
  250. /*
  251. * Emerging Display Technologies 320x240. Passive, monochrome, single scan.
  252. */
  253. #define LCD_BPP LCD_MONOCHROME
  254. #define LCD_DF 10
  255. static vidinfo_t panel_info = {
  256. 320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_LOW,
  257. LCD_BPP, 0, 0, 0, 0, 33, 0, 0, 0
  258. };
  259. #endif
  260. /*----------------------------------------------------------------------*/
  261. #if defined(LCD_INFO_BELOW_LOGO)
  262. # define LCD_INFO_X 0
  263. # define LCD_INFO_Y (BMP_LOGO_HEIGHT + VIDEO_FONT_HEIGHT)
  264. #elif defined(CONFIG_LCD_LOGO)
  265. # define LCD_INFO_X (BMP_LOGO_WIDTH + 4 * VIDEO_FONT_WIDTH)
  266. # define LCD_INFO_Y (VIDEO_FONT_HEIGHT)
  267. #else
  268. # define LCD_INFO_X (VIDEO_FONT_WIDTH)
  269. # define LCD_INFO_Y (VIDEO_FONT_HEIGHT)
  270. #endif
  271. #ifndef LCD_BPP
  272. #define LCD_BPP LCD_COLOR8
  273. #endif
  274. #ifndef LCD_DF
  275. #define LCD_DF 1
  276. #endif
  277. #define NBITS(bit_code) (1 << (bit_code))
  278. #define NCOLORS(bit_code) (1 << NBITS(bit_code))
  279. static int lcd_line_length;
  280. static int lcd_color_fg;
  281. static int lcd_color_bg;
  282. char lcd_is_enabled = 0; /* Indicate that LCD is enabled */
  283. /*
  284. * Frame buffer memory information
  285. */
  286. static void *lcd_base; /* Start of framebuffer memory */
  287. static void *lcd_console_address; /* Start of console buffer */
  288. /************************************************************************/
  289. /* ** CONSOLE CONSTANTS */
  290. /************************************************************************/
  291. #if LCD_BPP == LCD_MONOCHROME
  292. /*
  293. * Simple color definitions
  294. */
  295. #define CONSOLE_COLOR_BLACK 0
  296. #define CONSOLE_COLOR_WHITE 1 /* Must remain last / highest */
  297. #else
  298. /*
  299. * Simple color definitions
  300. */
  301. #define CONSOLE_COLOR_BLACK 0
  302. #define CONSOLE_COLOR_RED 1
  303. #define CONSOLE_COLOR_GREEN 2
  304. #define CONSOLE_COLOR_YELLOW 3
  305. #define CONSOLE_COLOR_BLUE 4
  306. #define CONSOLE_COLOR_MAGENTA 5
  307. #define CONSOLE_COLOR_CYAN 6
  308. #define CONSOLE_COLOR_GREY 14
  309. #define CONSOLE_COLOR_WHITE 15 /* Must remain last / highest */
  310. #endif
  311. #if defined(CONFIG_LCD_LOGO) && (CONSOLE_COLOR_WHITE >= BMP_LOGO_OFFSET)
  312. #error Default Color Map overlaps with Logo Color Map
  313. #endif
  314. /************************************************************************/
  315. #ifndef PAGE_SIZE
  316. #define PAGE_SIZE 4096
  317. #endif
  318. /************************************************************************/
  319. /* ** CONSOLE DEFINITIONS & FUNCTIONS */
  320. /************************************************************************/
  321. #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
  322. #define CONSOLE_ROWS ((panel_info.vl_row-BMP_LOGO_HEIGHT) \
  323. / VIDEO_FONT_HEIGHT)
  324. #else
  325. #define CONSOLE_ROWS (panel_info.vl_row / VIDEO_FONT_HEIGHT)
  326. #endif
  327. #define CONSOLE_COLS (panel_info.vl_col / VIDEO_FONT_WIDTH)
  328. #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * lcd_line_length)
  329. #define CONSOLE_ROW_FIRST (lcd_console_address)
  330. #define CONSOLE_ROW_SECOND (lcd_console_address + CONSOLE_ROW_SIZE)
  331. #define CONSOLE_ROW_LAST (lcd_console_address + CONSOLE_SIZE \
  332. - CONSOLE_ROW_SIZE)
  333. #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
  334. #define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
  335. #if LCD_BPP == LCD_MONOCHROME
  336. #define COLOR_MASK(c) ((c) | (c) << 1 | (c) << 2 | (c) << 3 | \
  337. (c) << 4 | (c) << 5 | (c) << 6 | (c) << 7)
  338. #elif LCD_BPP == LCD_COLOR8
  339. #define COLOR_MASK(c) (c)
  340. #else
  341. #error Unsupported LCD BPP.
  342. #endif
  343. static short console_col;
  344. static short console_row;
  345. /************************************************************************/
  346. ulong lcd_setmem (ulong addr);
  347. static void lcd_drawchars (ushort x, ushort y, uchar *str, int count);
  348. static inline void lcd_puts_xy (ushort x, ushort y, uchar *s);
  349. static inline void lcd_putc_xy (ushort x, ushort y, uchar c);
  350. int lcd_init (void *lcdbase);
  351. static void lcd_ctrl_init (void *lcdbase);
  352. static void lcd_enable (void);
  353. static void *lcd_logo (void);
  354. #if LCD_BPP == LCD_COLOR8
  355. static void lcd_setcolreg (ushort regno,
  356. ushort red, ushort green, ushort blue);
  357. #endif
  358. #if LCD_BPP == LCD_MONOCHROME
  359. static void lcd_initcolregs (void);
  360. #endif
  361. static int lcd_getbgcolor (void);
  362. static void lcd_setfgcolor (int color);
  363. static void lcd_setbgcolor (int color);
  364. #if defined(CONFIG_RBC823)
  365. void lcd_disable (void);
  366. #endif
  367. #ifdef NOT_USED_SO_FAR
  368. static void lcd_getcolreg (ushort regno,
  369. ushort *red, ushort *green, ushort *blue);
  370. static int lcd_getfgcolor (void);
  371. #endif /* NOT_USED_SO_FAR */
  372. /************************************************************************/
  373. /*----------------------------------------------------------------------*/
  374. static void console_scrollup (void)
  375. {
  376. #if 1
  377. /* Copy up rows ignoring the first one */
  378. memcpy (CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND, CONSOLE_SCROLL_SIZE);
  379. /* Clear the last one */
  380. memset (CONSOLE_ROW_LAST, COLOR_MASK(lcd_color_bg), CONSOLE_ROW_SIZE);
  381. #else
  382. /*
  383. * Poor attempt to optimize speed by moving "long"s.
  384. * But the code is ugly, and not a bit faster :-(
  385. */
  386. ulong *t = (ulong *)CONSOLE_ROW_FIRST;
  387. ulong *s = (ulong *)CONSOLE_ROW_SECOND;
  388. ulong l = CONSOLE_SCROLL_SIZE / sizeof(ulong);
  389. uchar c = lcd_color_bg & 0xFF;
  390. ulong val= (c<<24) | (c<<16) | (c<<8) | c;
  391. while (l--)
  392. *t++ = *s++;
  393. t = (ulong *)CONSOLE_ROW_LAST;
  394. l = CONSOLE_ROW_SIZE / sizeof(ulong);
  395. while (l-- > 0)
  396. *t++ = val;
  397. #endif
  398. }
  399. /*----------------------------------------------------------------------*/
  400. static inline void console_back (void)
  401. {
  402. if (--console_col < 0) {
  403. console_col = CONSOLE_COLS-1 ;
  404. if (--console_row < 0) {
  405. console_row = 0;
  406. }
  407. }
  408. lcd_putc_xy (console_col * VIDEO_FONT_WIDTH,
  409. console_row * VIDEO_FONT_HEIGHT,
  410. ' ');
  411. }
  412. /*----------------------------------------------------------------------*/
  413. static inline void console_newline (void)
  414. {
  415. ++console_row;
  416. console_col = 0;
  417. /* Check if we need to scroll the terminal */
  418. if (console_row >= CONSOLE_ROWS) {
  419. /* Scroll everything up */
  420. console_scrollup () ;
  421. --console_row;
  422. }
  423. }
  424. /*----------------------------------------------------------------------*/
  425. void lcd_putc (const char c)
  426. {
  427. if (!lcd_is_enabled) {
  428. serial_putc(c);
  429. return;
  430. }
  431. switch (c) {
  432. case '\r': console_col = 0;
  433. return;
  434. case '\n': console_newline();
  435. return;
  436. case '\t': /* Tab (8 chars alignment) */
  437. console_col |= 8;
  438. console_col &= ~7;
  439. if (console_col >= CONSOLE_COLS) {
  440. console_newline();
  441. }
  442. return;
  443. case '\b': console_back();
  444. return;
  445. default: lcd_putc_xy (console_col * VIDEO_FONT_WIDTH,
  446. console_row * VIDEO_FONT_HEIGHT,
  447. c);
  448. if (++console_col >= CONSOLE_COLS) {
  449. console_newline();
  450. }
  451. return;
  452. }
  453. /* NOTREACHED */
  454. }
  455. /*----------------------------------------------------------------------*/
  456. void lcd_puts (const char *s)
  457. {
  458. if (!lcd_is_enabled) {
  459. serial_puts (s);
  460. return;
  461. }
  462. while (*s) {
  463. lcd_putc (*s++);
  464. }
  465. }
  466. /************************************************************************/
  467. /* ** Low-Level Graphics Routines */
  468. /************************************************************************/
  469. static void lcd_drawchars (ushort x, ushort y, uchar *str, int count)
  470. {
  471. uchar *dest;
  472. ushort off, row;
  473. dest = (uchar *)(lcd_base + y * lcd_line_length + x * (1 << LCD_BPP) / 8);
  474. off = x * (1 << LCD_BPP) % 8;
  475. for (row=0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) {
  476. uchar *s = str;
  477. uchar *d = dest;
  478. int i;
  479. #if LCD_BPP == LCD_MONOCHROME
  480. uchar rest = *d & -(1 << (8-off));
  481. uchar sym;
  482. #endif
  483. for (i=0; i<count; ++i) {
  484. uchar c, bits;
  485. c = *s++;
  486. bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
  487. #if LCD_BPP == LCD_MONOCHROME
  488. sym = (COLOR_MASK(lcd_color_fg) & bits) |
  489. (COLOR_MASK(lcd_color_bg) & ~bits);
  490. *d++ = rest | (sym >> off);
  491. rest = sym << (8-off);
  492. #elif LCD_BPP == LCD_COLOR8
  493. for (c=0; c<8; ++c) {
  494. *d++ = (bits & 0x80) ?
  495. lcd_color_fg : lcd_color_bg;
  496. bits <<= 1;
  497. }
  498. #endif
  499. }
  500. #if LCD_BPP == LCD_MONOCHROME
  501. *d = rest | (*d & ((1 << (8-off)) - 1));
  502. #endif
  503. }
  504. }
  505. /*----------------------------------------------------------------------*/
  506. static inline void lcd_puts_xy (ushort x, ushort y, uchar *s)
  507. {
  508. #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
  509. lcd_drawchars (x, y+BMP_LOGO_HEIGHT, s, strlen (s));
  510. #else
  511. lcd_drawchars (x, y, s, strlen (s));
  512. #endif
  513. }
  514. /*----------------------------------------------------------------------*/
  515. static inline void lcd_putc_xy (ushort x, ushort y, uchar c)
  516. {
  517. #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
  518. lcd_drawchars (x, y+BMP_LOGO_HEIGHT, &c, 1);
  519. #else
  520. lcd_drawchars (x, y, &c, 1);
  521. #endif
  522. }
  523. /************************************************************************/
  524. /** Small utility to check that you got the colours right */
  525. /************************************************************************/
  526. #ifdef LCD_TEST_PATTERN
  527. #define N_BLK_VERT 2
  528. #define N_BLK_HOR 3
  529. static int test_colors[N_BLK_HOR*N_BLK_VERT] = {
  530. CONSOLE_COLOR_RED, CONSOLE_COLOR_GREEN, CONSOLE_COLOR_YELLOW,
  531. CONSOLE_COLOR_BLUE, CONSOLE_COLOR_MAGENTA, CONSOLE_COLOR_CYAN,
  532. };
  533. static void test_pattern (void)
  534. {
  535. ushort v_max = panel_info.vl_row;
  536. ushort h_max = panel_info.vl_col;
  537. ushort v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT;
  538. ushort h_step = (h_max + N_BLK_HOR - 1) / N_BLK_HOR;
  539. ushort v, h;
  540. uchar *pix = (uchar *)lcd_base;
  541. printf ("[LCD] Test Pattern: %d x %d [%d x %d]\n",
  542. h_max, v_max, h_step, v_step);
  543. /* WARNING: Code silently assumes 8bit/pixel */
  544. for (v=0; v<v_max; ++v) {
  545. uchar iy = v / v_step;
  546. for (h=0; h<h_max; ++h) {
  547. uchar ix = N_BLK_HOR * iy + (h/h_step);
  548. *pix++ = test_colors[ix];
  549. }
  550. }
  551. }
  552. #endif /* LCD_TEST_PATTERN */
  553. /************************************************************************/
  554. /* ** GENERIC Initialization Routines */
  555. /************************************************************************/
  556. int drv_lcd_init (void)
  557. {
  558. DECLARE_GLOBAL_DATA_PTR;
  559. device_t lcddev;
  560. int rc;
  561. lcd_base = (void *)(gd->fb_base);
  562. lcd_line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8;
  563. lcd_init (lcd_base); /* LCD initialization */
  564. /* Device initialization */
  565. memset (&lcddev, 0, sizeof (lcddev));
  566. strcpy (lcddev.name, "lcd");
  567. lcddev.ext = 0; /* No extensions */
  568. lcddev.flags = DEV_FLAGS_OUTPUT; /* Output only */
  569. lcddev.putc = lcd_putc; /* 'putc' function */
  570. lcddev.puts = lcd_puts; /* 'puts' function */
  571. rc = device_register (&lcddev);
  572. return (rc == 0) ? 1 : rc;
  573. }
  574. /*----------------------------------------------------------------------*/
  575. int lcd_init (void *lcdbase)
  576. {
  577. /* Initialize the lcd controller */
  578. debug ("[LCD] Initializing LCD frambuffer at %p\n", lcdbase);
  579. lcd_ctrl_init (lcdbase);
  580. #if LCD_BPP == LCD_MONOCHROME
  581. /* Setting the palette */
  582. lcd_initcolregs();
  583. #elif LCD_BPP == LCD_COLOR8
  584. /* Setting the palette */
  585. lcd_setcolreg (CONSOLE_COLOR_BLACK, 0, 0, 0);
  586. lcd_setcolreg (CONSOLE_COLOR_RED, 0xFF, 0, 0);
  587. lcd_setcolreg (CONSOLE_COLOR_GREEN, 0, 0xFF, 0);
  588. lcd_setcolreg (CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0);
  589. lcd_setcolreg (CONSOLE_COLOR_BLUE, 0, 0, 0xFF);
  590. lcd_setcolreg (CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF);
  591. lcd_setcolreg (CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF);
  592. lcd_setcolreg (CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA);
  593. lcd_setcolreg (CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF);
  594. #endif
  595. #ifndef CFG_WHITE_ON_BLACK
  596. lcd_setfgcolor (CONSOLE_COLOR_BLACK);
  597. lcd_setbgcolor (CONSOLE_COLOR_WHITE);
  598. #else
  599. lcd_setfgcolor (CONSOLE_COLOR_WHITE);
  600. lcd_setbgcolor (CONSOLE_COLOR_BLACK);
  601. #endif /* CFG_WHITE_ON_BLACK */
  602. #ifdef LCD_TEST_PATTERN
  603. test_pattern();
  604. #else
  605. /* set framebuffer to background color */
  606. memset ((char *)lcd_base,
  607. COLOR_MASK(lcd_getbgcolor()),
  608. lcd_line_length*panel_info.vl_row);
  609. #endif
  610. lcd_enable ();
  611. /* Paint the logo and retrieve LCD base address */
  612. debug ("[LCD] Drawing the logo...\n");
  613. lcd_console_address = lcd_logo ();
  614. /* Initialize the console */
  615. console_col = 0;
  616. #ifdef LCD_INFO_BELOW_LOGO
  617. console_row = 7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT;
  618. #else
  619. console_row = 1; /* leave 1 blank line below logo */
  620. #endif
  621. lcd_is_enabled = 1;
  622. return 0;
  623. }
  624. /************************************************************************/
  625. /* ** ROM capable initialization part - needed to reserve FB memory */
  626. /************************************************************************/
  627. /*
  628. * This is called early in the system initialization to grab memory
  629. * for the LCD controller.
  630. * Returns new address for monitor, after reserving LCD buffer memory
  631. *
  632. * Note that this is running from ROM, so no write access to global data.
  633. */
  634. ulong lcd_setmem (ulong addr)
  635. {
  636. ulong size;
  637. int line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8;
  638. debug ("LCD panel info: %d x %d, %d bit/pix\n",
  639. panel_info.vl_col, panel_info.vl_row, NBITS (panel_info.vl_bpix) );
  640. size = line_length * panel_info.vl_row;
  641. /* Round up to nearest full page */
  642. size = (size + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
  643. /* Allocate pages for the frame buffer. */
  644. addr -= size;
  645. debug ("Reserving %ldk for LCD Framebuffer at: %08lx\n", size>>10, addr);
  646. return (addr);
  647. }
  648. /************************************************************************/
  649. /* ----------------- chipset specific functions ----------------------- */
  650. /************************************************************************/
  651. static void lcd_ctrl_init (void *lcdbase)
  652. {
  653. volatile immap_t *immr = (immap_t *) CFG_IMMR;
  654. volatile lcd823_t *lcdp = &immr->im_lcd;
  655. uint lccrtmp;
  656. uint lchcr_hpc_tmp;
  657. /* Initialize the LCD control register according to the LCD
  658. * parameters defined. We do everything here but enable
  659. * the controller.
  660. */
  661. lccrtmp = LCDBIT (LCCR_BNUM_BIT,
  662. (((panel_info.vl_row * panel_info.vl_col) * (1 << LCD_BPP)) / 128));
  663. lccrtmp |= LCDBIT (LCCR_CLKP_BIT, panel_info.vl_clkp) |
  664. LCDBIT (LCCR_OEP_BIT, panel_info.vl_oep) |
  665. LCDBIT (LCCR_HSP_BIT, panel_info.vl_hsp) |
  666. LCDBIT (LCCR_VSP_BIT, panel_info.vl_vsp) |
  667. LCDBIT (LCCR_DP_BIT, panel_info.vl_dp) |
  668. LCDBIT (LCCR_BPIX_BIT, panel_info.vl_bpix) |
  669. LCDBIT (LCCR_LBW_BIT, panel_info.vl_lbw) |
  670. LCDBIT (LCCR_SPLT_BIT, panel_info.vl_splt) |
  671. LCDBIT (LCCR_CLOR_BIT, panel_info.vl_clor) |
  672. LCDBIT (LCCR_TFT_BIT, panel_info.vl_tft);
  673. #if 0
  674. lccrtmp |= ((SIU_LEVEL5 / 2) << 12);
  675. lccrtmp |= LCCR_EIEN;
  676. #endif
  677. lcdp->lcd_lccr = lccrtmp;
  678. lcdp->lcd_lcsr = 0xFF; /* Clear pending interrupts */
  679. /* Initialize LCD controller bus priorities.
  680. */
  681. #ifdef CONFIG_RBC823
  682. immr->im_siu_conf.sc_sdcr = (immr->im_siu_conf.sc_sdcr & ~0x0f) | 1; /* RAID = 01, LAID = 00 */
  683. #else
  684. immr->im_siu_conf.sc_sdcr &= ~0x0f; /* RAID = LAID = 0 */
  685. /* set SHFT/CLOCK division factor 4
  686. * This needs to be set based upon display type and processor
  687. * speed. The TFT displays run about 20 to 30 MHz.
  688. * I was running 64 MHz processor speed.
  689. * The value for this divider must be chosen so the result is
  690. * an integer of the processor speed (i.e., divide by 3 with
  691. * 64 MHz would be bad).
  692. */
  693. immr->im_clkrst.car_sccr &= ~0x1F;
  694. immr->im_clkrst.car_sccr |= LCD_DF; /* was 8 */
  695. #endif /* CONFIG_RBC823 */
  696. #if defined(CONFIG_RBC823)
  697. /* Enable LCD on port D.
  698. */
  699. immr->im_ioport.iop_pddat &= 0x0300;
  700. immr->im_ioport.iop_pdpar |= 0x1CFF;
  701. immr->im_ioport.iop_pddir |= 0x1CFF;
  702. /* Configure LCD_ON, VEE_ON, CCFL_ON on port B.
  703. */
  704. immr->im_cpm.cp_pbdat &= ~0x00005001;
  705. immr->im_cpm.cp_pbpar &= ~0x00005001;
  706. immr->im_cpm.cp_pbdir |= 0x00005001;
  707. #elif !defined(CONFIG_EDT32F10)
  708. /* Enable LCD on port D.
  709. */
  710. immr->im_ioport.iop_pdpar |= 0x1FFF;
  711. immr->im_ioport.iop_pddir |= 0x1FFF;
  712. /* Enable LCD_A/B/C on port B.
  713. */
  714. immr->im_cpm.cp_pbpar |= 0x00005001;
  715. immr->im_cpm.cp_pbdir |= 0x00005001;
  716. #else
  717. /* Enable LCD on port D.
  718. */
  719. immr->im_ioport.iop_pdpar |= 0x1DFF;
  720. immr->im_ioport.iop_pdpar &= ~0x0200;
  721. immr->im_ioport.iop_pddir |= 0x1FFF;
  722. immr->im_ioport.iop_pddat |= 0x0200;
  723. #endif
  724. /* Load the physical address of the linear frame buffer
  725. * into the LCD controller.
  726. * BIG NOTE: This has to be modified to load A and B depending
  727. * upon the split mode of the LCD.
  728. */
  729. lcdp->lcd_lcfaa = (ulong)lcd_base;
  730. lcdp->lcd_lcfba = (ulong)lcd_base;
  731. /* MORE HACKS...This must be updated according to 823 manual
  732. * for different panels.
  733. * Udi Finkelstein - done - see below:
  734. * Note: You better not try unsupported combinations such as
  735. * 4-bit wide passive dual scan LCD at 4/8 Bit color.
  736. */
  737. lchcr_hpc_tmp =
  738. (panel_info.vl_col *
  739. (panel_info.vl_tft ? 8 :
  740. (((2 - panel_info.vl_lbw) << /* 4 bit=2, 8-bit = 1 */
  741. /* use << to mult by: single scan = 1, dual scan = 2 */
  742. panel_info.vl_splt) *
  743. (panel_info.vl_bpix | 1)))) >> 3; /* 2/4 BPP = 1, 8/16 BPP = 3 */
  744. lcdp->lcd_lchcr = LCHCR_BO |
  745. LCDBIT (LCHCR_AT_BIT, 4) |
  746. LCDBIT (LCHCR_HPC_BIT, lchcr_hpc_tmp) |
  747. panel_info.vl_wbl;
  748. lcdp->lcd_lcvcr = LCDBIT (LCVCR_VPW_BIT, panel_info.vl_vpw) |
  749. LCDBIT (LCVCR_LCD_AC_BIT, panel_info.vl_lcdac) |
  750. LCDBIT (LCVCR_VPC_BIT, panel_info.vl_row) |
  751. panel_info.vl_wbf;
  752. }
  753. /*----------------------------------------------------------------------*/
  754. #ifdef NOT_USED_SO_FAR
  755. static void
  756. lcd_getcolreg (ushort regno, ushort *red, ushort *green, ushort *blue)
  757. {
  758. volatile immap_t *immr = (immap_t *) CFG_IMMR;
  759. volatile cpm8xx_t *cp = &(immr->im_cpm);
  760. unsigned short colreg, *cmap_ptr;
  761. cmap_ptr = (unsigned short *)&cp->lcd_cmap[regno * 2];
  762. colreg = *cmap_ptr;
  763. #ifdef CFG_INVERT_COLORS
  764. colreg ^= 0x0FFF;
  765. #endif
  766. *red = (colreg >> 8) & 0x0F;
  767. *green = (colreg >> 4) & 0x0F;
  768. *blue = colreg & 0x0F;
  769. }
  770. #endif /* NOT_USED_SO_FAR */
  771. /*----------------------------------------------------------------------*/
  772. #if LCD_BPP == LCD_COLOR8
  773. static void
  774. lcd_setcolreg (ushort regno, ushort red, ushort green, ushort blue)
  775. {
  776. volatile immap_t *immr = (immap_t *) CFG_IMMR;
  777. volatile cpm8xx_t *cp = &(immr->im_cpm);
  778. unsigned short colreg, *cmap_ptr;
  779. cmap_ptr = (unsigned short *)&cp->lcd_cmap[regno * 2];
  780. colreg = ((red & 0x0F) << 8) |
  781. ((green & 0x0F) << 4) |
  782. (blue & 0x0F) ;
  783. #ifdef CFG_INVERT_COLORS
  784. colreg ^= 0x0FFF;
  785. #endif
  786. *cmap_ptr = colreg;
  787. debug ("setcolreg: reg %2d @ %p: R=%02X G=%02X B=%02X => %02X%02X\n",
  788. regno, &(cp->lcd_cmap[regno * 2]),
  789. red, green, blue,
  790. cp->lcd_cmap[ regno * 2 ], cp->lcd_cmap[(regno * 2) + 1]);
  791. }
  792. #endif /* LCD_COLOR8 */
  793. /*----------------------------------------------------------------------*/
  794. #if LCD_BPP == LCD_MONOCHROME
  795. static
  796. void lcd_initcolregs (void)
  797. {
  798. volatile immap_t *immr = (immap_t *) CFG_IMMR;
  799. volatile cpm8xx_t *cp = &(immr->im_cpm);
  800. ushort regno;
  801. for (regno = 0; regno < 16; regno++) {
  802. cp->lcd_cmap[regno * 2] = 0;
  803. cp->lcd_cmap[(regno * 2) + 1] = regno & 0x0f;
  804. }
  805. }
  806. #endif
  807. /*----------------------------------------------------------------------*/
  808. static void lcd_setfgcolor (int color)
  809. {
  810. lcd_color_fg = color & 0x0F;
  811. }
  812. /*----------------------------------------------------------------------*/
  813. static void lcd_setbgcolor (int color)
  814. {
  815. lcd_color_bg = color & 0x0F;
  816. }
  817. /*----------------------------------------------------------------------*/
  818. #ifdef NOT_USED_SO_FAR
  819. static int lcd_getfgcolor (void)
  820. {
  821. return lcd_color_fg;
  822. }
  823. #endif /* NOT_USED_SO_FAR */
  824. /*----------------------------------------------------------------------*/
  825. static int lcd_getbgcolor (void)
  826. {
  827. return lcd_color_bg;
  828. }
  829. /*----------------------------------------------------------------------*/
  830. static void lcd_enable (void)
  831. {
  832. volatile immap_t *immr = (immap_t *) CFG_IMMR;
  833. volatile lcd823_t *lcdp = &immr->im_lcd;
  834. /* Enable the LCD panel */
  835. #ifndef CONFIG_RBC823
  836. immr->im_siu_conf.sc_sdcr |= (1 << (31 - 25)); /* LAM = 1 */
  837. #endif
  838. lcdp->lcd_lccr |= LCCR_PON;
  839. #ifdef CONFIG_V37
  840. /* Turn on display backlight */
  841. immr->im_cpm.cp_pbpar |= 0x00008000;
  842. immr->im_cpm.cp_pbdir |= 0x00008000;
  843. #elif defined(CONFIG_RBC823)
  844. /* Turn on display backlight */
  845. immr->im_cpm.cp_pbdat |= 0x00004000;
  846. #endif
  847. #if defined(CONFIG_LWMON)
  848. { uchar c = pic_read (0x60);
  849. #if defined(CONFIG_LCD) && defined(CONFIG_LWMON) && (CONFIG_POST & CFG_POST_SYSMON)
  850. c |= 0x04; /* Chip Enable LCD */
  851. #else
  852. c |= 0x07; /* Power on CCFL, Enable CCFL, Chip Enable LCD */
  853. #endif
  854. pic_write (0x60, c);
  855. }
  856. #endif /* CONFIG_LWMON */
  857. #if defined(CONFIG_R360MPI)
  858. {
  859. extern void r360_i2c_lcd_write (uchar data0, uchar data1);
  860. unsigned long bgi, ctr;
  861. char *p;
  862. if ((p = getenv("lcdbgi")) != NULL) {
  863. bgi = simple_strtoul (p, 0, 10) & 0xFFF;
  864. } else {
  865. bgi = 0xFFF;
  866. }
  867. if ((p = getenv("lcdctr")) != NULL) {
  868. ctr = simple_strtoul (p, 0, 10) & 0xFFF;
  869. } else {
  870. ctr=0x7FF;
  871. }
  872. r360_i2c_lcd_write(0x10, 0x01);
  873. r360_i2c_lcd_write(0x20, 0x01);
  874. r360_i2c_lcd_write(0x30 | ((bgi>>8) & 0xF), bgi & 0xFF);
  875. r360_i2c_lcd_write(0x40 | ((ctr>>8) & 0xF), ctr & 0xFF);
  876. }
  877. #endif /* CONFIG_R360MPI */
  878. #ifdef CONFIG_RBC823
  879. udelay(200000); /* wait 200ms */
  880. /* Turn VEE_ON first */
  881. immr->im_cpm.cp_pbdat |= 0x00000001;
  882. udelay(200000); /* wait 200ms */
  883. /* Now turn on LCD_ON */
  884. immr->im_cpm.cp_pbdat |= 0x00001000;
  885. #endif
  886. #ifdef CONFIG_RRVISION
  887. debug ("PC4->Output(1): enable LVDS\n");
  888. debug ("PC5->Output(0): disable PAL clock\n");
  889. immr->im_ioport.iop_pddir |= 0x1000;
  890. immr->im_ioport.iop_pcpar &= ~(0x0C00);
  891. immr->im_ioport.iop_pcdir |= 0x0C00 ;
  892. immr->im_ioport.iop_pcdat |= 0x0800 ;
  893. immr->im_ioport.iop_pcdat &= ~(0x0400);
  894. debug ("PDPAR=0x%04X PDDIR=0x%04X PDDAT=0x%04X\n",
  895. immr->im_ioport.iop_pdpar,
  896. immr->im_ioport.iop_pddir,
  897. immr->im_ioport.iop_pddat);
  898. debug ("PCPAR=0x%04X PCDIR=0x%04X PCDAT=0x%04X\n",
  899. immr->im_ioport.iop_pcpar,
  900. immr->im_ioport.iop_pcdir,
  901. immr->im_ioport.iop_pcdat);
  902. #endif
  903. }
  904. /*----------------------------------------------------------------------*/
  905. #if defined (CONFIG_RBC823)
  906. void lcd_disable (void)
  907. {
  908. volatile immap_t *immr = (immap_t *) CFG_IMMR;
  909. volatile lcd823_t *lcdp = &immr->im_lcd;
  910. #if defined(CONFIG_LWMON)
  911. { uchar c = pic_read (0x60);
  912. c &= ~0x07; /* Power off CCFL, Disable CCFL, Chip Disable LCD */
  913. pic_write (0x60, c);
  914. }
  915. #elif defined(CONFIG_R360MPI)
  916. {
  917. extern void r360_i2c_lcd_write (uchar data0, uchar data1);
  918. r360_i2c_lcd_write(0x10, 0x00);
  919. r360_i2c_lcd_write(0x20, 0x00);
  920. r360_i2c_lcd_write(0x30, 0x00);
  921. r360_i2c_lcd_write(0x40, 0x00);
  922. }
  923. #endif /* CONFIG_LWMON */
  924. /* Disable the LCD panel */
  925. lcdp->lcd_lccr &= ~LCCR_PON;
  926. #ifdef CONFIG_RBC823
  927. /* Turn off display backlight, VEE and LCD_ON */
  928. immr->im_cpm.cp_pbdat &= ~0x00005001;
  929. #else
  930. immr->im_siu_conf.sc_sdcr &= ~(1 << (31 - 25)); /* LAM = 0 */
  931. #endif /* CONFIG_RBC823 */
  932. }
  933. #endif /* NOT_USED_SO_FAR || CONFIG_RBC823 */
  934. /************************************************************************/
  935. /* ** Chipset depending Bitmap / Logo stuff... */
  936. /************************************************************************/
  937. #ifdef CONFIG_LCD_LOGO
  938. static void bitmap_plot (int x, int y)
  939. {
  940. volatile immap_t *immr = (immap_t *) CFG_IMMR;
  941. volatile cpm8xx_t *cp = &(immr->im_cpm);
  942. ushort *cmap;
  943. ushort i;
  944. uchar *bmap;
  945. uchar *fb;
  946. debug ("Logo: width %d height %d colors %d cmap %d\n",
  947. BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS,
  948. sizeof(bmp_logo_palette)/(sizeof(ushort))
  949. );
  950. /* Leave room for default color map */
  951. cmap = (ushort *)&(cp->lcd_cmap[BMP_LOGO_OFFSET*sizeof(ushort)]);
  952. WATCHDOG_RESET();
  953. /* Set color map */
  954. for (i=0; i<(sizeof(bmp_logo_palette)/(sizeof(ushort))); ++i) {
  955. ushort colreg = bmp_logo_palette[i];
  956. #ifdef CFG_INVERT_COLORS
  957. colreg ^= 0xFFF;
  958. #endif
  959. *cmap++ = colreg;
  960. }
  961. bmap = &bmp_logo_bitmap[0];
  962. fb = (char *)(lcd_base + y * lcd_line_length + x);
  963. WATCHDOG_RESET();
  964. for (i=0; i<BMP_LOGO_HEIGHT; ++i) {
  965. memcpy (fb, bmap, BMP_LOGO_WIDTH);
  966. bmap += BMP_LOGO_WIDTH;
  967. fb += panel_info.vl_col;
  968. }
  969. WATCHDOG_RESET();
  970. }
  971. #endif /* CONFIG_LCD_LOGO */
  972. #if (CONFIG_COMMANDS & CFG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
  973. /*
  974. * Display the BMP file located at address bmp_image.
  975. * Only uncompressed
  976. */
  977. int lcd_display_bitmap(ulong bmp_image)
  978. {
  979. volatile immap_t *immr = (immap_t *) CFG_IMMR;
  980. volatile cpm8xx_t *cp = &(immr->im_cpm);
  981. ushort *cmap;
  982. ushort i, j;
  983. uchar *fb;
  984. bmp_image_t *bmp=(bmp_image_t *)bmp_image;
  985. uchar *bmap;
  986. ushort padded_line;
  987. unsigned long width, height;
  988. unsigned colors,bpix;
  989. unsigned long compression;
  990. WATCHDOG_RESET();
  991. if (!((bmp->header.signature[0]=='B') &&
  992. (bmp->header.signature[1]=='M'))) {
  993. printf ("Error: no valid bmp image at %lx\n", bmp_image);
  994. return 1;
  995. }
  996. width = le32_to_cpu (bmp->header.width);
  997. height = le32_to_cpu (bmp->header.height);
  998. colors = 1<<le16_to_cpu (bmp->header.bit_count);
  999. compression = le32_to_cpu (bmp->header.compression);
  1000. bpix = NBITS(panel_info.vl_bpix);
  1001. if ((bpix != 1) && (bpix != 8)) {
  1002. printf ("Error: %d bit/pixel mode not supported by U-Boot\n",
  1003. bpix);
  1004. return 1;
  1005. }
  1006. if (bpix != le16_to_cpu(bmp->header.bit_count)) {
  1007. printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
  1008. bpix,
  1009. le16_to_cpu(bmp->header.bit_count));
  1010. return 1;
  1011. }
  1012. if (compression!=BMP_BI_RGB) {
  1013. printf ("Error: compression type %ld not supported\n",
  1014. compression);
  1015. return 1;
  1016. }
  1017. debug ("Display-bmp: %d x %d with %d colors\n",
  1018. width, height, colors);
  1019. if (bpix==8) {
  1020. /* Fill the entire color map */
  1021. cmap = (ushort *)&(cp->lcd_cmap[255*sizeof(ushort)]);
  1022. /* Set color map */
  1023. for (i = 0; i < colors; ++i) {
  1024. bmp_color_table_entry_t cte = bmp->color_table[i];
  1025. ushort colreg =
  1026. ((cte.red>>4) << 8) |
  1027. ((cte.green>>4) << 4) |
  1028. (cte.blue>>4) ;
  1029. #ifdef CFG_INVERT_COLORS
  1030. colreg ^= 0xFFF;
  1031. #endif
  1032. *cmap-- = colreg;
  1033. }
  1034. WATCHDOG_RESET();
  1035. }
  1036. padded_line = (width&0x3) ? ((width&~0x3)+4) : (width);
  1037. if (width>panel_info.vl_col)
  1038. width = panel_info.vl_col;
  1039. if (height>panel_info.vl_row)
  1040. height = panel_info.vl_row;
  1041. bmap = (uchar *)bmp + le32_to_cpu (bmp->header.data_offset);
  1042. fb = (uchar *)
  1043. (lcd_base +
  1044. (((height>=panel_info.vl_row) ? panel_info.vl_row : height)-1)
  1045. * lcd_line_length);
  1046. for (i = 0; i < height; ++i) {
  1047. WATCHDOG_RESET();
  1048. for (j = 0; j < width ; j++)
  1049. *(fb++)=255-*(bmap++);
  1050. bmap += (width - padded_line);
  1051. fb -= (width + lcd_line_length);
  1052. }
  1053. return (0);
  1054. }
  1055. #endif /* (CONFIG_COMMANDS & CFG_CMD_BMP) || CONFIG_SPLASH_SCREEN */
  1056. /*----------------------------------------------------------------------*/
  1057. static void *lcd_logo (void)
  1058. {
  1059. #ifdef LCD_INFO
  1060. DECLARE_GLOBAL_DATA_PTR;
  1061. char info[80];
  1062. char temp[32];
  1063. #endif /* LCD_INFO */
  1064. #ifdef CONFIG_SPLASH_SCREEN
  1065. char *s;
  1066. ulong addr;
  1067. if ((s = getenv("splashimage")) != NULL) {
  1068. addr = simple_strtoul(s, NULL, 16);
  1069. if (lcd_display_bitmap (addr) == 0) {
  1070. return ((void *)lcd_base);
  1071. }
  1072. }
  1073. #endif /* CONFIG_SPLASH_SCREEN */
  1074. #ifdef CONFIG_LCD_LOGO
  1075. bitmap_plot (0, 0);
  1076. #endif /* CONFIG_LCD_LOGO */
  1077. #ifdef LCD_INFO
  1078. sprintf (info, "%s (%s - %s) ", U_BOOT_VERSION, __DATE__, __TIME__);
  1079. lcd_drawchars (LCD_INFO_X, LCD_INFO_Y, info, strlen(info));
  1080. sprintf (info, "(C) 2003 DENX Software Engineering");
  1081. lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT,
  1082. info, strlen(info));
  1083. sprintf (info, " Wolfgang DENK, wd@denx.de");
  1084. lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 2,
  1085. info, strlen(info));
  1086. #ifdef LCD_INFO_BELOW_LOGO
  1087. sprintf (info, "MPC823 CPU at %s MHz",
  1088. strmhz(temp, gd->cpu_clk));
  1089. lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 3,
  1090. info, strlen(info));
  1091. sprintf (info, " %ld MB RAM, %ld MB Flash",
  1092. gd->ram_size >> 20,
  1093. gd->bd->bi_flashsize >> 20 );
  1094. lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 4,
  1095. info, strlen(info));
  1096. #else
  1097. /* leave one blank line */
  1098. sprintf (info, "MPC823 CPU at %s MHz, %ld MB RAM, %ld MB Flash",
  1099. strmhz(temp, gd->cpu_clk),
  1100. gd->ram_size >> 20,
  1101. gd->bd->bi_flashsize >> 20 );
  1102. lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 4,
  1103. info, strlen(info));
  1104. #endif /* LCD_INFO_BELOW_LOGO */
  1105. #endif /* LCD_INFO */
  1106. #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
  1107. return ((void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length));
  1108. #else
  1109. return ((void *)lcd_base);
  1110. #endif /* CONFIG_LCD_LOGO */
  1111. }
  1112. /************************************************************************/
  1113. /************************************************************************/
  1114. #endif /* CONFIG_LCD */