lcd.c 30 KB

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