lcd.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336
  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)
  56. #include <bmp_layout.h>
  57. #endif /* (CONFIG_COMMANDS & CFG_CMD_BMP) */
  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. r360_i2c_lcd_write(0x10, 0x01);
  861. r360_i2c_lcd_write(0x20, 0x01);
  862. r360_i2c_lcd_write(0x3F, 0xFF);
  863. r360_i2c_lcd_write(0x47, 0xFF);
  864. }
  865. #endif /* CONFIG_R360MPI */
  866. #ifdef CONFIG_RBC823
  867. udelay(200000); /* wait 200ms */
  868. /* Turn VEE_ON first */
  869. immr->im_cpm.cp_pbdat |= 0x00000001;
  870. udelay(200000); /* wait 200ms */
  871. /* Now turn on LCD_ON */
  872. immr->im_cpm.cp_pbdat |= 0x00001000;
  873. #endif
  874. #ifdef CONFIG_RRVISION
  875. debug ("PC4->Output(1): enable LVDS\n");
  876. debug ("PC5->Output(0): disable PAL clock\n");
  877. immr->im_ioport.iop_pddir |= 0x1000;
  878. immr->im_ioport.iop_pcpar &= ~(0x0C00);
  879. immr->im_ioport.iop_pcdir |= 0x0C00 ;
  880. immr->im_ioport.iop_pcdat |= 0x0800 ;
  881. immr->im_ioport.iop_pcdat &= ~(0x0400);
  882. debug ("PDPAR=0x%04X PDDIR=0x%04X PDDAT=0x%04X\n",
  883. immr->im_ioport.iop_pdpar,
  884. immr->im_ioport.iop_pddir,
  885. immr->im_ioport.iop_pddat);
  886. debug ("PCPAR=0x%04X PCDIR=0x%04X PCDAT=0x%04X\n",
  887. immr->im_ioport.iop_pcpar,
  888. immr->im_ioport.iop_pcdir,
  889. immr->im_ioport.iop_pcdat);
  890. #endif
  891. }
  892. /*----------------------------------------------------------------------*/
  893. #if defined (CONFIG_RBC823)
  894. void lcd_disable (void)
  895. {
  896. volatile immap_t *immr = (immap_t *) CFG_IMMR;
  897. volatile lcd823_t *lcdp = &immr->im_lcd;
  898. #if defined(CONFIG_LWMON)
  899. { uchar c = pic_read (0x60);
  900. c &= ~0x07; /* Power off CCFL, Disable CCFL, Chip Disable LCD */
  901. pic_write (0x60, c);
  902. }
  903. #elif defined(CONFIG_R360MPI)
  904. {
  905. extern void r360_i2c_lcd_write (uchar data0, uchar data1);
  906. r360_i2c_lcd_write(0x10, 0x00);
  907. r360_i2c_lcd_write(0x20, 0x00);
  908. r360_i2c_lcd_write(0x30, 0x00);
  909. r360_i2c_lcd_write(0x40, 0x00);
  910. }
  911. #endif /* CONFIG_LWMON */
  912. /* Disable the LCD panel */
  913. lcdp->lcd_lccr &= ~LCCR_PON;
  914. #ifdef CONFIG_RBC823
  915. /* Turn off display backlight, VEE and LCD_ON */
  916. immr->im_cpm.cp_pbdat &= ~0x00005001;
  917. #else
  918. immr->im_siu_conf.sc_sdcr &= ~(1 << (31 - 25)); /* LAM = 0 */
  919. #endif /* CONFIG_RBC823 */
  920. }
  921. #endif /* NOT_USED_SO_FAR || CONFIG_RBC823 */
  922. /************************************************************************/
  923. /* ** Chipset depending Bitmap / Logo stuff... */
  924. /************************************************************************/
  925. #ifdef CONFIG_LCD_LOGO
  926. static void bitmap_plot (int x, int y)
  927. {
  928. volatile immap_t *immr = (immap_t *) CFG_IMMR;
  929. volatile cpm8xx_t *cp = &(immr->im_cpm);
  930. ushort *cmap;
  931. ushort i;
  932. uchar *bmap;
  933. uchar *fb;
  934. debug ("Logo: width %d height %d colors %d cmap %d\n",
  935. BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS,
  936. sizeof(bmp_logo_palette)/(sizeof(ushort))
  937. );
  938. /* Leave room for default color map */
  939. cmap = (ushort *)&(cp->lcd_cmap[BMP_LOGO_OFFSET*sizeof(ushort)]);
  940. WATCHDOG_RESET();
  941. /* Set color map */
  942. for (i=0; i<(sizeof(bmp_logo_palette)/(sizeof(ushort))); ++i) {
  943. ushort colreg = bmp_logo_palette[i];
  944. #ifdef CFG_INVERT_COLORS
  945. colreg ^= 0xFFF;
  946. #endif
  947. *cmap++ = colreg;
  948. }
  949. bmap = &bmp_logo_bitmap[0];
  950. fb = (char *)(lcd_base + y * lcd_line_length + x);
  951. WATCHDOG_RESET();
  952. for (i=0; i<BMP_LOGO_HEIGHT; ++i) {
  953. memcpy (fb, bmap, BMP_LOGO_WIDTH);
  954. bmap += BMP_LOGO_WIDTH;
  955. fb += panel_info.vl_col;
  956. }
  957. WATCHDOG_RESET();
  958. }
  959. #endif /* CONFIG_LCD_LOGO */
  960. #if (CONFIG_COMMANDS & CFG_CMD_BMP)
  961. /*
  962. * Display the BMP file located at address bmp_image.
  963. * Only uncompressed
  964. */
  965. int lcd_display_bitmap(ulong bmp_image)
  966. {
  967. volatile immap_t *immr = (immap_t *) CFG_IMMR;
  968. volatile cpm8xx_t *cp = &(immr->im_cpm);
  969. ushort *cmap;
  970. ushort i, j;
  971. uchar *fb;
  972. bmp_image_t *bmp=(bmp_image_t *)bmp_image;
  973. uchar *bmap;
  974. ushort padded_line;
  975. unsigned long width, height;
  976. unsigned colors,bpix;
  977. unsigned long compression;
  978. WATCHDOG_RESET();
  979. if (!((bmp->header.signature[0]=='B') &&
  980. (bmp->header.signature[1]=='M'))) {
  981. printf ("Error: no valid bmp image at %lx\n", bmp_image);
  982. return 1;
  983. }
  984. width = le32_to_cpu (bmp->header.width);
  985. height = le32_to_cpu (bmp->header.height);
  986. colors = 1<<le16_to_cpu (bmp->header.bit_count);
  987. compression = le32_to_cpu (bmp->header.compression);
  988. bpix = NBITS(panel_info.vl_bpix);
  989. if ((bpix != 1) && (bpix != 8)) {
  990. printf ("Error: %d bit/pixel mode not supported by U-Boot\n",
  991. bpix);
  992. return 1;
  993. }
  994. if (bpix != le16_to_cpu(bmp->header.bit_count)) {
  995. printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
  996. bpix,
  997. le16_to_cpu(bmp->header.bit_count));
  998. return 1;
  999. }
  1000. if (compression!=BMP_BI_RGB) {
  1001. printf ("Error: compression type %ld not supported\n",
  1002. compression);
  1003. return 1;
  1004. }
  1005. debug ("Display-bmp: %d x %d with %d colors\n",
  1006. width, height, colors);
  1007. if (bpix==8) {
  1008. /* Fill the entire color map */
  1009. cmap = (ushort *)&(cp->lcd_cmap[255*sizeof(ushort)]);
  1010. /* Set color map */
  1011. for (i = 0; i < colors; ++i) {
  1012. bmp_color_table_entry_t cte = bmp->color_table[i];
  1013. ushort colreg =
  1014. ((cte.red>>4) << 8) |
  1015. ((cte.green>>4) << 4) |
  1016. (cte.blue>>4) ;
  1017. #ifdef CFG_INVERT_COLORS
  1018. colreg ^= 0xFFF;
  1019. #endif
  1020. *cmap-- = colreg;
  1021. }
  1022. WATCHDOG_RESET();
  1023. }
  1024. padded_line = (width&0x3) ? ((width&~0x3)+4) : (width);
  1025. if (width>panel_info.vl_col)
  1026. width = panel_info.vl_col;
  1027. if (height>panel_info.vl_row)
  1028. height = panel_info.vl_row;
  1029. bmap = (uchar *)bmp + le32_to_cpu (bmp->header.data_offset);
  1030. fb = (uchar *)
  1031. (lcd_base +
  1032. (((height>=panel_info.vl_row) ? panel_info.vl_row : height)-1)
  1033. * lcd_line_length);
  1034. for (i = 0; i < height; ++i) {
  1035. WATCHDOG_RESET();
  1036. for (j = 0; j < width ; j++)
  1037. *(fb++)=255-*(bmap++);
  1038. bmap += (width - padded_line);
  1039. fb -= (width + lcd_line_length);
  1040. }
  1041. return (0);
  1042. }
  1043. #endif /* (CONFIG_COMMANDS & CFG_CMD_BMP) */
  1044. /*----------------------------------------------------------------------*/
  1045. static void *lcd_logo (void)
  1046. {
  1047. #ifdef LCD_INFO
  1048. DECLARE_GLOBAL_DATA_PTR;
  1049. char info[80];
  1050. char temp[32];
  1051. #endif /* LCD_INFO */
  1052. #ifdef CONFIG_SPLASH_SCREEN
  1053. char *s;
  1054. ulong addr;
  1055. if ((s = getenv("splashimage")) != NULL) {
  1056. addr = simple_strtoul(s, NULL, 16);
  1057. if (lcd_display_bitmap (addr) == 0) {
  1058. return ((void *)lcd_base);
  1059. }
  1060. }
  1061. #endif /* CONFIG_SPLASH_SCREEN */
  1062. #ifdef CONFIG_LCD_LOGO
  1063. bitmap_plot (0, 0);
  1064. #endif /* CONFIG_LCD_LOGO */
  1065. #ifdef LCD_INFO
  1066. sprintf (info, "%s (%s - %s) ", U_BOOT_VERSION, __DATE__, __TIME__);
  1067. lcd_drawchars (LCD_INFO_X, LCD_INFO_Y, info, strlen(info));
  1068. sprintf (info, "(C) 2003 DENX Software Engineering");
  1069. lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT,
  1070. info, strlen(info));
  1071. sprintf (info, " Wolfgang DENK, wd@denx.de");
  1072. lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 2,
  1073. info, strlen(info));
  1074. #ifdef LCD_INFO_BELOW_LOGO
  1075. sprintf (info, "MPC823 CPU at %s MHz",
  1076. strmhz(temp, gd->cpu_clk));
  1077. lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 3,
  1078. info, strlen(info));
  1079. sprintf (info, " %ld MB RAM, %ld MB Flash",
  1080. gd->ram_size >> 20,
  1081. gd->bd->bi_flashsize >> 20 );
  1082. lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 4,
  1083. info, strlen(info));
  1084. #else
  1085. /* leave one blank line */
  1086. sprintf (info, "MPC823 CPU at %s MHz, %ld MB RAM, %ld MB Flash",
  1087. strmhz(temp, gd->cpu_clk),
  1088. gd->ram_size >> 20,
  1089. gd->bd->bi_flashsize >> 20 );
  1090. lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 4,
  1091. info, strlen(info));
  1092. #endif /* LCD_INFO_BELOW_LOGO */
  1093. #endif /* LCD_INFO */
  1094. #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
  1095. return ((void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length));
  1096. #else
  1097. return ((void *)lcd_base);
  1098. #endif /* CONFIG_LCD_LOGO */
  1099. }
  1100. /************************************************************************/
  1101. /************************************************************************/
  1102. #endif /* CONFIG_LCD */