video.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. /*
  2. * Video uclass and legacy implementation
  3. *
  4. * Copyright (c) 2015 Google, Inc
  5. *
  6. * MPC823 Video Controller
  7. * =======================
  8. * (C) 2000 by Paolo Scaffardi (arsenio@tin.it)
  9. * AIRVENT SAM s.p.a - RIMINI(ITALY)
  10. *
  11. */
  12. #ifndef _VIDEO_H_
  13. #define _VIDEO_H_
  14. #ifdef CONFIG_DM_VIDEO
  15. #include <stdio_dev.h>
  16. struct video_uc_platdata {
  17. uint align;
  18. uint size;
  19. ulong base;
  20. };
  21. enum video_polarity {
  22. VIDEO_ACTIVE_HIGH, /* Pins are active high */
  23. VIDEO_ACTIVE_LOW, /* Pins are active low */
  24. };
  25. /*
  26. * Bits per pixel selector. Each value n is such that the bits-per-pixel is
  27. * 2 ^ n
  28. */
  29. enum video_log2_bpp {
  30. VIDEO_BPP1 = 0,
  31. VIDEO_BPP2,
  32. VIDEO_BPP4,
  33. VIDEO_BPP8,
  34. VIDEO_BPP16,
  35. VIDEO_BPP32,
  36. };
  37. /*
  38. * Convert enum video_log2_bpp to bytes and bits. Note we omit the outer
  39. * brackets to allow multiplication by fractional pixels.
  40. */
  41. #define VNBYTES(bpix) (1 << (bpix)) / 8
  42. #define VNBITS(bpix) (1 << (bpix))
  43. /**
  44. * struct video_priv - Device information used by the video uclass
  45. *
  46. * @xsize: Number of pixel columns (e.g. 1366)
  47. * @ysize: Number of pixels rows (e.g.. 768)
  48. * @rot: Display rotation (0=none, 1=90 degrees clockwise, etc.)
  49. * @bpix: Encoded bits per pixel (enum video_log2_bpp)
  50. * @vidconsole_drv_name: Driver to use for the text console, NULL to
  51. * select automatically
  52. * @font_size: Font size in pixels (0 to use a default value)
  53. * @fb: Frame buffer
  54. * @fb_size: Frame buffer size
  55. * @line_length: Length of each frame buffer line, in bytes. This can be
  56. * set by the driver, but if not, the uclass will set it after
  57. * probing
  58. * @colour_fg: Foreground colour (pixel value)
  59. * @colour_bg: Background colour (pixel value)
  60. * @flush_dcache: true to enable flushing of the data cache after
  61. * the LCD is updated
  62. * @cmap: Colour map for 8-bit-per-pixel displays
  63. * @fg_col_idx: Foreground color code (bit 3 = bold, bit 0-2 = color)
  64. * @bg_col_idx: Background color code (bit 3 = bold, bit 0-2 = color)
  65. */
  66. struct video_priv {
  67. /* Things set up by the driver: */
  68. ushort xsize;
  69. ushort ysize;
  70. ushort rot;
  71. enum video_log2_bpp bpix;
  72. const char *vidconsole_drv_name;
  73. int font_size;
  74. /*
  75. * Things that are private to the uclass: don't use these in the
  76. * driver
  77. */
  78. void *fb;
  79. int fb_size;
  80. int line_length;
  81. u32 colour_fg;
  82. u32 colour_bg;
  83. bool flush_dcache;
  84. ushort *cmap;
  85. u8 fg_col_idx;
  86. u8 bg_col_idx;
  87. };
  88. /* Placeholder - there are no video operations at present */
  89. struct video_ops {
  90. };
  91. #define video_get_ops(dev) ((struct video_ops *)(dev)->driver->ops)
  92. /**
  93. * video_reserve() - Reserve frame-buffer memory for video devices
  94. *
  95. * Note: This function is for internal use.
  96. *
  97. * This uses the uclass platdata's @size and @align members to figure out
  98. * a size and position for each frame buffer as part of the pre-relocation
  99. * process of determining the post-relocation memory layout.
  100. *
  101. * gd->video_top is set to the initial value of *@addrp and gd->video_bottom
  102. * is set to the final value.
  103. *
  104. * @addrp: On entry, the top of available memory. On exit, the new top,
  105. * after allocating the required memory.
  106. * @return 0
  107. */
  108. int video_reserve(ulong *addrp);
  109. /**
  110. * video_clear() - Clear a device's frame buffer to background color.
  111. *
  112. * @dev: Device to clear
  113. * @return 0
  114. */
  115. int video_clear(struct udevice *dev);
  116. /**
  117. * video_sync() - Sync a device's frame buffer with its hardware
  118. *
  119. * Some frame buffers are cached or have a secondary frame buffer. This
  120. * function syncs these up so that the current contents of the U-Boot frame
  121. * buffer are displayed to the user.
  122. *
  123. * @dev: Device to sync
  124. * @force: True to force a sync even if there was one recently (this is
  125. * very expensive on sandbox)
  126. */
  127. void video_sync(struct udevice *vid, bool force);
  128. /**
  129. * video_sync_all() - Sync all devices' frame buffers with there hardware
  130. *
  131. * This calls video_sync() on all active video devices.
  132. */
  133. void video_sync_all(void);
  134. /**
  135. * video_bmp_display() - Display a BMP file
  136. *
  137. * @dev: Device to display the bitmap on
  138. * @bmp_image: Address of bitmap image to display
  139. * @x: X position in pixels from the left
  140. * @y: Y position in pixels from the top
  141. * @align: true to adjust the coordinates to centre the image. If false
  142. * the coordinates are used as is. If true:
  143. *
  144. * - if a coordinate is 0x7fff then the image will be centred in
  145. * that direction
  146. * - if a coordinate is -ve then it will be offset to the
  147. * left/top of the centre by that many pixels
  148. * - if a coordinate is positive it will be used unchnaged.
  149. * @return 0 if OK, -ve on error
  150. */
  151. int video_bmp_display(struct udevice *dev, ulong bmp_image, int x, int y,
  152. bool align);
  153. /**
  154. * video_get_xsize() - Get the width of the display in pixels
  155. *
  156. * @dev: Device to check
  157. * @return device frame buffer width in pixels
  158. */
  159. int video_get_xsize(struct udevice *dev);
  160. /**
  161. * video_get_ysize() - Get the height of the display in pixels
  162. *
  163. * @dev: Device to check
  164. * @return device frame buffer height in pixels
  165. */
  166. int video_get_ysize(struct udevice *dev);
  167. /**
  168. * Set whether we need to flush the dcache when changing the image. This
  169. * defaults to off.
  170. *
  171. * @param flush non-zero to flush cache after update, 0 to skip
  172. */
  173. void video_set_flush_dcache(struct udevice *dev, bool flush);
  174. /**
  175. * Set default colors and attributes
  176. *
  177. * @dev: video device
  178. * @invert true to invert colours
  179. */
  180. void video_set_default_colors(struct udevice *dev, bool invert);
  181. #endif /* CONFIG_DM_VIDEO */
  182. #ifndef CONFIG_DM_VIDEO
  183. /* Video functions */
  184. /**
  185. * Display a BMP format bitmap on the screen
  186. *
  187. * @param bmp_image Address of BMP image
  188. * @param x X position to draw image
  189. * @param y Y position to draw image
  190. */
  191. int video_display_bitmap(ulong bmp_image, int x, int y);
  192. /**
  193. * Get the width of the screen in pixels
  194. *
  195. * @return width of screen in pixels
  196. */
  197. int video_get_pixel_width(void);
  198. /**
  199. * Get the height of the screen in pixels
  200. *
  201. * @return height of screen in pixels
  202. */
  203. int video_get_pixel_height(void);
  204. /**
  205. * Get the number of text lines/rows on the screen
  206. *
  207. * @return number of rows
  208. */
  209. int video_get_screen_rows(void);
  210. /**
  211. * Get the number of text columns on the screen
  212. *
  213. * @return number of columns
  214. */
  215. int video_get_screen_columns(void);
  216. /**
  217. * Set the position of the text cursor
  218. *
  219. * @param col Column to place cursor (0 = left side)
  220. * @param row Row to place cursor (0 = top line)
  221. */
  222. void video_position_cursor(unsigned col, unsigned row);
  223. /* Clear the display */
  224. void video_clear(void);
  225. #if defined(CONFIG_FORMIKE)
  226. int kwh043st20_f01_spi_startup(unsigned int bus, unsigned int cs,
  227. unsigned int max_hz, unsigned int spi_mode);
  228. #endif
  229. #if defined(CONFIG_LG4573)
  230. int lg4573_spi_startup(unsigned int bus, unsigned int cs,
  231. unsigned int max_hz, unsigned int spi_mode);
  232. #endif
  233. /*
  234. * video_get_info_str() - obtain a board string: type, speed, etc.
  235. *
  236. * This is called if CONFIG_CONSOLE_EXTRA_INFO is enabled.
  237. *
  238. * line_number: location to place info string beside logo
  239. * info: buffer for info string (empty if nothing to display on this
  240. * line)
  241. */
  242. void video_get_info_str(int line_number, char *info);
  243. #endif /* !CONFIG_DM_VIDEO */
  244. #endif