lcd.c 38 KB

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