lcd.h 12 KB

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