lcd.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. /*
  2. * MPC823 and PXA LCD Controller
  3. *
  4. * Modeled after video interface by Paolo Scaffardi
  5. *
  6. *
  7. * (C) Copyright 2001
  8. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  9. *
  10. * See file CREDITS for list of people who contributed to this
  11. * project.
  12. *
  13. * This program is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU General Public License as
  15. * published by the Free Software Foundation; either version 2 of
  16. * the License, or (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  26. * MA 02111-1307 USA
  27. */
  28. #ifndef _LCD_H_
  29. #define _LCD_H_
  30. extern char lcd_is_enabled;
  31. extern int lcd_line_length;
  32. extern struct vidinfo panel_info;
  33. extern void lcd_ctrl_init (void *lcdbase);
  34. extern void lcd_enable (void);
  35. extern int board_splash_screen_prepare(void);
  36. /* setcolreg used in 8bpp/16bpp; initcolregs used in monochrome */
  37. extern void lcd_setcolreg (ushort regno,
  38. ushort red, ushort green, ushort blue);
  39. extern void lcd_initcolregs (void);
  40. extern int lcd_getfgcolor(void);
  41. /* gunzip_bmp used if CONFIG_VIDEO_BMP_GZIP */
  42. extern struct bmp_image *gunzip_bmp(unsigned long addr, unsigned long *lenp);
  43. extern int bmp_display(ulong addr, int x, int y);
  44. /**
  45. * Set whether we need to flush the dcache when changing the LCD image. This
  46. * defaults to off.
  47. *
  48. * @param flush non-zero to flush cache after update, 0 to skip
  49. */
  50. void lcd_set_flush_dcache(int flush);
  51. #if defined CONFIG_MPC823
  52. /*
  53. * LCD controller stucture for MPC823 CPU
  54. */
  55. typedef struct vidinfo {
  56. ushort vl_col; /* Number of columns (i.e. 640) */
  57. ushort vl_row; /* Number of rows (i.e. 480) */
  58. ushort vl_width; /* Width of display area in millimeters */
  59. ushort vl_height; /* Height of display area in millimeters */
  60. /* LCD configuration register */
  61. u_char vl_clkp; /* Clock polarity */
  62. u_char vl_oep; /* Output Enable polarity */
  63. u_char vl_hsp; /* Horizontal Sync polarity */
  64. u_char vl_vsp; /* Vertical Sync polarity */
  65. u_char vl_dp; /* Data polarity */
  66. u_char vl_bpix; /* Bits per pixel, 0 = 1, 1 = 2, 2 = 4, 3 = 8 */
  67. u_char vl_lbw; /* LCD Bus width, 0 = 4, 1 = 8 */
  68. u_char vl_splt; /* Split display, 0 = single-scan, 1 = dual-scan */
  69. u_char vl_clor; /* Color, 0 = mono, 1 = color */
  70. u_char vl_tft; /* 0 = passive, 1 = TFT */
  71. /* Horizontal control register. Timing from data sheet */
  72. ushort vl_wbl; /* Wait between lines */
  73. /* Vertical control register */
  74. u_char vl_vpw; /* Vertical sync pulse width */
  75. u_char vl_lcdac; /* LCD AC timing */
  76. u_char vl_wbf; /* Wait between frames */
  77. } vidinfo_t;
  78. #elif defined(CONFIG_CPU_PXA25X) || defined(CONFIG_CPU_PXA27X) || \
  79. defined CONFIG_CPU_MONAHANS
  80. /*
  81. * PXA LCD DMA descriptor
  82. */
  83. struct pxafb_dma_descriptor {
  84. u_long fdadr; /* Frame descriptor address register */
  85. u_long fsadr; /* Frame source address register */
  86. u_long fidr; /* Frame ID register */
  87. u_long ldcmd; /* Command register */
  88. };
  89. /*
  90. * PXA LCD info
  91. */
  92. struct pxafb_info {
  93. /* Misc registers */
  94. u_long reg_lccr3;
  95. u_long reg_lccr2;
  96. u_long reg_lccr1;
  97. u_long reg_lccr0;
  98. u_long fdadr0;
  99. u_long fdadr1;
  100. /* DMA descriptors */
  101. struct pxafb_dma_descriptor * dmadesc_fblow;
  102. struct pxafb_dma_descriptor * dmadesc_fbhigh;
  103. struct pxafb_dma_descriptor * dmadesc_palette;
  104. u_long screen; /* physical address of frame buffer */
  105. u_long palette; /* physical address of palette memory */
  106. u_int palette_size;
  107. };
  108. /*
  109. * LCD controller stucture for PXA CPU
  110. */
  111. typedef struct vidinfo {
  112. ushort vl_col; /* Number of columns (i.e. 640) */
  113. ushort vl_row; /* Number of rows (i.e. 480) */
  114. ushort vl_width; /* Width of display area in millimeters */
  115. ushort vl_height; /* Height of display area in millimeters */
  116. /* LCD configuration register */
  117. u_char vl_clkp; /* Clock polarity */
  118. u_char vl_oep; /* Output Enable polarity */
  119. u_char vl_hsp; /* Horizontal Sync polarity */
  120. u_char vl_vsp; /* Vertical Sync polarity */
  121. u_char vl_dp; /* Data polarity */
  122. u_char vl_bpix; /* Bits per pixel, 0 = 1, 1 = 2, 2 = 4, 3 = 8, 4 = 16 */
  123. u_char vl_lbw; /* LCD Bus width, 0 = 4, 1 = 8 */
  124. u_char vl_splt; /* Split display, 0 = single-scan, 1 = dual-scan */
  125. u_char vl_clor; /* Color, 0 = mono, 1 = color */
  126. u_char vl_tft; /* 0 = passive, 1 = TFT */
  127. /* Horizontal control register. Timing from data sheet */
  128. ushort vl_hpw; /* Horz sync pulse width */
  129. u_char vl_blw; /* Wait before of line */
  130. u_char vl_elw; /* Wait end of line */
  131. /* Vertical control register. */
  132. u_char vl_vpw; /* Vertical sync pulse width */
  133. u_char vl_bfw; /* Wait before of frame */
  134. u_char vl_efw; /* Wait end of frame */
  135. /* PXA LCD controller params */
  136. struct pxafb_info pxa;
  137. } vidinfo_t;
  138. #elif defined(CONFIG_ATMEL_LCD) || defined(CONFIG_ATMEL_HLCD)
  139. typedef struct vidinfo {
  140. ushort vl_col; /* Number of columns (i.e. 640) */
  141. ushort vl_row; /* Number of rows (i.e. 480) */
  142. u_long vl_clk; /* pixel clock in ps */
  143. /* LCD configuration register */
  144. u_long vl_sync; /* Horizontal / vertical sync */
  145. u_long vl_bpix; /* Bits per pixel, 0 = 1, 1 = 2, 2 = 4, 3 = 8, 4 = 16 */
  146. u_long vl_tft; /* 0 = passive, 1 = TFT */
  147. u_long vl_cont_pol_low; /* contrast polarity is low */
  148. u_long vl_clk_pol; /* clock polarity */
  149. /* Horizontal control register. */
  150. u_long vl_hsync_len; /* Length of horizontal sync */
  151. u_long vl_left_margin; /* Time from sync to picture */
  152. u_long vl_right_margin; /* Time from picture to sync */
  153. /* Vertical control register. */
  154. u_long vl_vsync_len; /* Length of vertical sync */
  155. u_long vl_upper_margin; /* Time from sync to picture */
  156. u_long vl_lower_margin; /* Time from picture to sync */
  157. u_long mmio; /* Memory mapped registers */
  158. } vidinfo_t;
  159. #elif defined(CONFIG_EXYNOS_FB)
  160. enum {
  161. FIMD_RGB_INTERFACE = 1,
  162. FIMD_CPU_INTERFACE = 2,
  163. };
  164. enum exynos_fb_rgb_mode_t {
  165. MODE_RGB_P = 0,
  166. MODE_BGR_P = 1,
  167. MODE_RGB_S = 2,
  168. MODE_BGR_S = 3,
  169. };
  170. typedef struct vidinfo {
  171. ushort vl_col; /* Number of columns (i.e. 640) */
  172. ushort vl_row; /* Number of rows (i.e. 480) */
  173. ushort vl_width; /* Width of display area in millimeters */
  174. ushort vl_height; /* Height of display area in millimeters */
  175. /* LCD configuration register */
  176. u_char vl_freq; /* Frequency */
  177. u_char vl_clkp; /* Clock polarity */
  178. u_char vl_oep; /* Output Enable polarity */
  179. u_char vl_hsp; /* Horizontal Sync polarity */
  180. u_char vl_vsp; /* Vertical Sync polarity */
  181. u_char vl_dp; /* Data polarity */
  182. u_char vl_bpix; /* Bits per pixel */
  183. /* Horizontal control register. Timing from data sheet */
  184. u_char vl_hspw; /* Horz sync pulse width */
  185. u_char vl_hfpd; /* Wait before of line */
  186. u_char vl_hbpd; /* Wait end of line */
  187. /* Vertical control register. */
  188. u_char vl_vspw; /* Vertical sync pulse width */
  189. u_char vl_vfpd; /* Wait before of frame */
  190. u_char vl_vbpd; /* Wait end of frame */
  191. u_char vl_cmd_allow_len; /* Wait end of frame */
  192. void (*cfg_gpio)(void);
  193. void (*backlight_on)(unsigned int onoff);
  194. void (*reset_lcd)(void);
  195. void (*lcd_power_on)(void);
  196. void (*cfg_ldo)(void);
  197. void (*enable_ldo)(unsigned int onoff);
  198. void (*mipi_power)(void);
  199. void (*backlight_reset)(void);
  200. unsigned int win_id;
  201. unsigned int init_delay;
  202. unsigned int power_on_delay;
  203. unsigned int reset_delay;
  204. unsigned int interface_mode;
  205. unsigned int mipi_enabled;
  206. unsigned int dp_enabled;
  207. unsigned int cs_setup;
  208. unsigned int wr_setup;
  209. unsigned int wr_act;
  210. unsigned int wr_hold;
  211. unsigned int logo_on;
  212. unsigned int logo_width;
  213. unsigned int logo_height;
  214. unsigned long logo_addr;
  215. unsigned int rgb_mode;
  216. unsigned int resolution;
  217. /* parent clock name(MPLL, EPLL or VPLL) */
  218. unsigned int pclk_name;
  219. /* ratio value for source clock from parent clock. */
  220. unsigned int sclk_div;
  221. unsigned int dual_lcd_enabled;
  222. } vidinfo_t;
  223. void init_panel_info(vidinfo_t *vid);
  224. #else
  225. typedef struct vidinfo {
  226. ushort vl_col; /* Number of columns (i.e. 160) */
  227. ushort vl_row; /* Number of rows (i.e. 100) */
  228. u_char vl_bpix; /* Bits per pixel, 0 = 1 */
  229. ushort *cmap; /* Pointer to the colormap */
  230. void *priv; /* Pointer to driver-specific data */
  231. } vidinfo_t;
  232. #endif /* CONFIG_MPC823, CONFIG_CPU_PXA25X, CONFIG_MCC200, CONFIG_ATMEL_LCD */
  233. extern vidinfo_t panel_info;
  234. /* Video functions */
  235. #if defined(CONFIG_RBC823)
  236. void lcd_disable (void);
  237. #endif
  238. /* int lcd_init (void *lcdbase); */
  239. void lcd_putc (const char c);
  240. void lcd_puts (const char *s);
  241. void lcd_printf (const char *fmt, ...);
  242. void lcd_clear(void);
  243. int lcd_display_bitmap(ulong bmp_image, int x, int y);
  244. /**
  245. * Get the width of the LCD in pixels
  246. *
  247. * @return width of LCD in pixels
  248. */
  249. int lcd_get_pixel_width(void);
  250. /**
  251. * Get the height of the LCD in pixels
  252. *
  253. * @return height of LCD in pixels
  254. */
  255. int lcd_get_pixel_height(void);
  256. /**
  257. * Get the number of text lines/rows on the LCD
  258. *
  259. * @return number of rows
  260. */
  261. int lcd_get_screen_rows(void);
  262. /**
  263. * Get the number of text columns on the LCD
  264. *
  265. * @return number of columns
  266. */
  267. int lcd_get_screen_columns(void);
  268. /**
  269. * Set the position of the text cursor
  270. *
  271. * @param col Column to place cursor (0 = left side)
  272. * @param row Row to place cursor (0 = top line)
  273. */
  274. void lcd_position_cursor(unsigned col, unsigned row);
  275. /* Allow boards to customize the information displayed */
  276. void lcd_show_board_info(void);
  277. /* Return the size of the LCD frame buffer, and the line length */
  278. int lcd_get_size(int *line_length);
  279. /************************************************************************/
  280. /* ** BITMAP DISPLAY SUPPORT */
  281. /************************************************************************/
  282. #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
  283. # include <bmp_layout.h>
  284. # include <asm/byteorder.h>
  285. #endif
  286. /*
  287. * Information about displays we are using. This is for configuring
  288. * the LCD controller and memory allocation. Someone has to know what
  289. * is connected, as we can't autodetect anything.
  290. */
  291. #define CONFIG_SYS_HIGH 0 /* Pins are active high */
  292. #define CONFIG_SYS_LOW 1 /* Pins are active low */
  293. #define LCD_MONOCHROME 0
  294. #define LCD_COLOR2 1
  295. #define LCD_COLOR4 2
  296. #define LCD_COLOR8 3
  297. #define LCD_COLOR16 4
  298. /*----------------------------------------------------------------------*/
  299. #if defined(CONFIG_LCD_INFO_BELOW_LOGO)
  300. # define LCD_INFO_X 0
  301. # define LCD_INFO_Y (BMP_LOGO_HEIGHT + VIDEO_FONT_HEIGHT)
  302. #elif defined(CONFIG_LCD_LOGO)
  303. # define LCD_INFO_X (BMP_LOGO_WIDTH + 4 * VIDEO_FONT_WIDTH)
  304. # define LCD_INFO_Y (VIDEO_FONT_HEIGHT)
  305. #else
  306. # define LCD_INFO_X (VIDEO_FONT_WIDTH)
  307. # define LCD_INFO_Y (VIDEO_FONT_HEIGHT)
  308. #endif
  309. /* Default to 8bpp if bit depth not specified */
  310. #ifndef LCD_BPP
  311. # define LCD_BPP LCD_COLOR8
  312. #endif
  313. #ifndef LCD_DF
  314. # define LCD_DF 1
  315. #endif
  316. /* Calculate nr. of bits per pixel and nr. of colors */
  317. #define NBITS(bit_code) (1 << (bit_code))
  318. #define NCOLORS(bit_code) (1 << NBITS(bit_code))
  319. /************************************************************************/
  320. /* ** CONSOLE CONSTANTS */
  321. /************************************************************************/
  322. #if LCD_BPP == LCD_MONOCHROME
  323. /*
  324. * Simple black/white definitions
  325. */
  326. # define CONSOLE_COLOR_BLACK 0
  327. # define CONSOLE_COLOR_WHITE 1 /* Must remain last / highest */
  328. #elif LCD_BPP == LCD_COLOR8
  329. /*
  330. * 8bpp color definitions
  331. */
  332. # define CONSOLE_COLOR_BLACK 0
  333. # define CONSOLE_COLOR_RED 1
  334. # define CONSOLE_COLOR_GREEN 2
  335. # define CONSOLE_COLOR_YELLOW 3
  336. # define CONSOLE_COLOR_BLUE 4
  337. # define CONSOLE_COLOR_MAGENTA 5
  338. # define CONSOLE_COLOR_CYAN 6
  339. # define CONSOLE_COLOR_GREY 14
  340. # define CONSOLE_COLOR_WHITE 15 /* Must remain last / highest */
  341. #else
  342. /*
  343. * 16bpp color definitions
  344. */
  345. # define CONSOLE_COLOR_BLACK 0x0000
  346. # define CONSOLE_COLOR_WHITE 0xffff /* Must remain last / highest */
  347. #endif /* color definitions */
  348. /************************************************************************/
  349. #ifndef PAGE_SIZE
  350. # define PAGE_SIZE 4096
  351. #endif
  352. /************************************************************************/
  353. /* ** CONSOLE DEFINITIONS & FUNCTIONS */
  354. /************************************************************************/
  355. #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
  356. # define CONSOLE_ROWS ((panel_info.vl_row-BMP_LOGO_HEIGHT) \
  357. / VIDEO_FONT_HEIGHT)
  358. #else
  359. # define CONSOLE_ROWS (panel_info.vl_row / VIDEO_FONT_HEIGHT)
  360. #endif
  361. #define CONSOLE_COLS (panel_info.vl_col / VIDEO_FONT_WIDTH)
  362. #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * lcd_line_length)
  363. #define CONSOLE_ROW_FIRST (lcd_console_address)
  364. #define CONSOLE_ROW_SECOND (lcd_console_address + CONSOLE_ROW_SIZE)
  365. #define CONSOLE_ROW_LAST (lcd_console_address + CONSOLE_SIZE \
  366. - CONSOLE_ROW_SIZE)
  367. #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
  368. #define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
  369. #if LCD_BPP == LCD_MONOCHROME
  370. # define COLOR_MASK(c) ((c) | (c) << 1 | (c) << 2 | (c) << 3 | \
  371. (c) << 4 | (c) << 5 | (c) << 6 | (c) << 7)
  372. #elif (LCD_BPP == LCD_COLOR8) || (LCD_BPP == LCD_COLOR16)
  373. # define COLOR_MASK(c) (c)
  374. #else
  375. # error Unsupported LCD BPP.
  376. #endif
  377. /************************************************************************/
  378. #endif /* _LCD_H_ */