lcd.h 13 KB

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