video.h 7.0 KB

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