lcd.c 37 KB

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