video.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. /*
  2. * Video uclass to support displays (see also vidconsole for text)
  3. *
  4. * Copyright (c) 2015 Google, Inc
  5. */
  6. #ifndef _VIDEO_H_
  7. #define _VIDEO_H_
  8. #include <stdio_dev.h>
  9. struct udevice;
  10. /**
  11. * struct video_uc_plat - uclass platform data for a video device
  12. *
  13. * This holds information that the uclass needs to know about each device. It
  14. * is accessed using dev_get_uclass_plat(dev). See 'Theory of operation' at
  15. * the top of video-uclass.c for details on how this information is set.
  16. *
  17. * @align: Frame-buffer alignment, indicating the memory boundary the frame
  18. * buffer should start on. If 0, 1MB is assumed
  19. * @size: Frame-buffer size, in bytes
  20. * @base: Base address of frame buffer, 0 if not yet known
  21. * @copy_base: Base address of a hardware copy of the frame buffer. See
  22. * CONFIG_VIDEO_COPY.
  23. * @copy_size: Size of copy framebuffer, used if @size is 0
  24. * @hide_logo: Hide the logo (used for testing)
  25. */
  26. struct video_uc_plat {
  27. uint align;
  28. uint size;
  29. ulong base;
  30. ulong copy_base;
  31. ulong copy_size;
  32. bool hide_logo;
  33. };
  34. enum video_polarity {
  35. VIDEO_ACTIVE_HIGH, /* Pins are active high */
  36. VIDEO_ACTIVE_LOW, /* Pins are active low */
  37. };
  38. /*
  39. * Bits per pixel selector. Each value n is such that the bits-per-pixel is
  40. * 2 ^ n
  41. */
  42. enum video_log2_bpp {
  43. VIDEO_BPP1 = 0,
  44. VIDEO_BPP2,
  45. VIDEO_BPP4,
  46. VIDEO_BPP8,
  47. VIDEO_BPP16,
  48. VIDEO_BPP32,
  49. };
  50. /*
  51. * Convert enum video_log2_bpp to bytes and bits. Note we omit the outer
  52. * brackets to allow multiplication by fractional pixels.
  53. */
  54. #define VNBYTES(bpix) (1 << (bpix)) / 8
  55. #define VNBITS(bpix) (1 << (bpix))
  56. enum video_format {
  57. VIDEO_UNKNOWN,
  58. VIDEO_RGBA8888,
  59. VIDEO_X8B8G8R8,
  60. VIDEO_X8R8G8B8,
  61. VIDEO_X2R10G10B10,
  62. };
  63. /**
  64. * struct video_priv - Device information used by the video uclass
  65. *
  66. * @xsize: Number of pixel columns (e.g. 1366)
  67. * @ysize: Number of pixels rows (e.g.. 768)
  68. * @rot: Display rotation (0=none, 1=90 degrees clockwise, etc.)
  69. * @bpix: Encoded bits per pixel (enum video_log2_bpp)
  70. * @format: Pixel format (enum video_format)
  71. * @vidconsole_drv_name: Driver to use for the text console, NULL to
  72. * select automatically
  73. * @font_size: Font size in pixels (0 to use a default value)
  74. * @fb: Frame buffer
  75. * @fb_size: Frame buffer size
  76. * @copy_fb: Copy of the frame buffer to keep up to date; see struct
  77. * video_uc_plat
  78. * @line_length: Length of each frame buffer line, in bytes. This can be
  79. * set by the driver, but if not, the uclass will set it after
  80. * probing
  81. * @colour_fg: Foreground colour (pixel value)
  82. * @colour_bg: Background colour (pixel value)
  83. * @flush_dcache: true to enable flushing of the data cache after
  84. * the LCD is updated
  85. * @fg_col_idx: Foreground color code (bit 3 = bold, bit 0-2 = color)
  86. * @bg_col_idx: Background color code (bit 3 = bold, bit 0-2 = color)
  87. */
  88. struct video_priv {
  89. /* Things set up by the driver: */
  90. ushort xsize;
  91. ushort ysize;
  92. ushort rot;
  93. enum video_log2_bpp bpix;
  94. enum video_format format;
  95. const char *vidconsole_drv_name;
  96. int font_size;
  97. /*
  98. * Things that are private to the uclass: don't use these in the
  99. * driver
  100. */
  101. void *fb;
  102. int fb_size;
  103. void *copy_fb;
  104. int line_length;
  105. u32 colour_fg;
  106. u32 colour_bg;
  107. bool flush_dcache;
  108. u8 fg_col_idx;
  109. u8 bg_col_idx;
  110. };
  111. /**
  112. * struct video_ops - structure for keeping video operations
  113. * @video_sync: Synchronize FB with device. Some device like SPI based LCD
  114. * displays needs synchronization when data in an FB is available.
  115. * For these devices implement video_sync hook to call a sync
  116. * function. vid is pointer to video device udevice. Function
  117. * should return 0 on success video_sync and error code otherwise
  118. */
  119. struct video_ops {
  120. int (*video_sync)(struct udevice *vid);
  121. };
  122. #define video_get_ops(dev) ((struct video_ops *)(dev)->driver->ops)
  123. /**
  124. * struct video_handoff - video information passed from SPL
  125. *
  126. * This is used when video is set up by SPL, to provide the details to U-Boot
  127. * proper.
  128. *
  129. * @fb: Base address of frame buffer, 0 if not yet known
  130. * @size: Frame-buffer size, in bytes
  131. * @xsize: Number of pixel columns (e.g. 1366)
  132. * @ysize: Number of pixels rows (e.g.. 768)
  133. * @line_length: Length of each frame buffer line, in bytes. This can be
  134. * set by the driver, but if not, the uclass will set it after
  135. * probing
  136. * @bpix: Encoded bits per pixel (enum video_log2_bpp)
  137. */
  138. struct video_handoff {
  139. u64 fb;
  140. u32 size;
  141. u16 xsize;
  142. u16 ysize;
  143. u32 line_length;
  144. u8 bpix;
  145. };
  146. /** enum colour_idx - the 16 colors supported by consoles */
  147. enum colour_idx {
  148. VID_BLACK = 0,
  149. VID_RED,
  150. VID_GREEN,
  151. VID_BROWN,
  152. VID_BLUE,
  153. VID_MAGENTA,
  154. VID_CYAN,
  155. VID_LIGHT_GRAY,
  156. VID_GRAY,
  157. VID_LIGHT_RED,
  158. VID_LIGHT_GREEN,
  159. VID_YELLOW,
  160. VID_LIGHT_BLUE,
  161. VID_LIGHT_MAGENTA,
  162. VID_LIGHT_CYAN,
  163. VID_WHITE,
  164. VID_COLOUR_COUNT
  165. };
  166. /**
  167. * video_index_to_colour() - convert a color code to a pixel's internal
  168. * representation
  169. *
  170. * The caller has to guarantee that the color index is less than
  171. * VID_COLOR_COUNT.
  172. *
  173. * @priv private data of the video device (UCLASS_VIDEO)
  174. * @idx color index (e.g. VID_YELLOW)
  175. * Return: color value
  176. */
  177. u32 video_index_to_colour(struct video_priv *priv, enum colour_idx idx);
  178. /**
  179. * video_reserve() - Reserve frame-buffer memory for video devices
  180. *
  181. * Note: This function is for internal use.
  182. *
  183. * This uses the uclass plat's @size and @align members to figure out
  184. * a size and position for each frame buffer as part of the pre-relocation
  185. * process of determining the post-relocation memory layout.
  186. *
  187. * gd->video_top is set to the initial value of *@addrp and gd->video_bottom
  188. * is set to the final value.
  189. *
  190. * @addrp: On entry, the top of available memory. On exit, the new top,
  191. * after allocating the required memory.
  192. * Return: 0
  193. */
  194. int video_reserve(ulong *addrp);
  195. /**
  196. * video_clear() - Clear a device's frame buffer to background colour.
  197. *
  198. * @dev: Device to clear
  199. * Return: 0 on success
  200. */
  201. int video_clear(struct udevice *dev);
  202. /**
  203. * video_fill() - Fill a device's frame buffer to a colour.
  204. *
  205. * @dev: Device to fill
  206. * @colour: Colour to use, in the frame buffer's format
  207. * Return: 0 on success
  208. */
  209. int video_fill(struct udevice *dev, u32 colour);
  210. /**
  211. * video_fill_part() - Erase a region
  212. *
  213. * Erase a rectangle of the display within the given bounds.
  214. *
  215. * @dev: Device to update
  216. * @xstart: X start position in pixels from the left
  217. * @ystart: Y start position in pixels from the top
  218. * @xend: X end position in pixels from the left
  219. * @yend: Y end position in pixels from the top
  220. * @colour: Value to write
  221. * Return: 0 if OK, -ENOSYS if the display depth is not supported
  222. */
  223. int video_fill_part(struct udevice *dev, int xstart, int ystart, int xend,
  224. int yend, u32 colour);
  225. /**
  226. * video_sync() - Sync a device's frame buffer with its hardware
  227. *
  228. * @vid: Device to sync
  229. * @force: True to force a sync even if there was one recently (this is
  230. * very expensive on sandbox)
  231. *
  232. * @return: 0 on success, error code otherwise
  233. *
  234. * Some frame buffers are cached or have a secondary frame buffer. This
  235. * function syncs these up so that the current contents of the U-Boot frame
  236. * buffer are displayed to the user.
  237. */
  238. int video_sync(struct udevice *vid, bool force);
  239. /**
  240. * video_sync_all() - Sync all devices' frame buffers with their hardware
  241. *
  242. * This calls video_sync() on all active video devices.
  243. */
  244. void video_sync_all(void);
  245. /**
  246. * video_bmp_get_info() - Get information about a bitmap image
  247. *
  248. * @bmp_image: Pointer to BMP image to check
  249. * @widthp: Returns width in pixels
  250. * @heightp: Returns height in pixels
  251. * @bpixp: Returns log2 of bits per pixel
  252. */
  253. void video_bmp_get_info(void *bmp_image, ulong *widthp, ulong *heightp,
  254. uint *bpixp);
  255. /**
  256. * video_bmp_display() - Display a BMP file
  257. *
  258. * @dev: Device to display the bitmap on
  259. * @bmp_image: Address of bitmap image to display
  260. * @x: X position in pixels from the left
  261. * @y: Y position in pixels from the top
  262. * @align: true to adjust the coordinates to centre the image. If false
  263. * the coordinates are used as is. If true:
  264. *
  265. * - if a coordinate is 0x7fff then the image will be centred in
  266. * that direction
  267. * - if a coordinate is -ve then it will be offset to the
  268. * left/top of the centre by that many pixels
  269. * - if a coordinate is positive it will be used unchanged.
  270. * Return: 0 if OK, -ve on error
  271. */
  272. int video_bmp_display(struct udevice *dev, ulong bmp_image, int x, int y,
  273. bool align);
  274. /**
  275. * video_get_xsize() - Get the width of the display in pixels
  276. *
  277. * @dev: Device to check
  278. * Return: device frame buffer width in pixels
  279. */
  280. int video_get_xsize(struct udevice *dev);
  281. /**
  282. * video_get_ysize() - Get the height of the display in pixels
  283. *
  284. * @dev: Device to check
  285. * Return: device frame buffer height in pixels
  286. */
  287. int video_get_ysize(struct udevice *dev);
  288. /**
  289. * Set whether we need to flush the dcache when changing the image. This
  290. * defaults to off.
  291. *
  292. * @param flush non-zero to flush cache after update, 0 to skip
  293. */
  294. void video_set_flush_dcache(struct udevice *dev, bool flush);
  295. /**
  296. * Set default colors and attributes
  297. *
  298. * @dev: video device
  299. * @invert true to invert colours
  300. */
  301. void video_set_default_colors(struct udevice *dev, bool invert);
  302. /**
  303. * video_default_font_height() - Get the default font height
  304. *
  305. * @dev: video device
  306. * Returns: Default font height in pixels, which depends on which console driver
  307. * is in use
  308. */
  309. int video_default_font_height(struct udevice *dev);
  310. #ifdef CONFIG_VIDEO_COPY
  311. /**
  312. * vidconsole_sync_copy() - Sync back to the copy framebuffer
  313. *
  314. * This ensures that the copy framebuffer has the same data as the framebuffer
  315. * for a particular region. It should be called after the framebuffer is updated
  316. *
  317. * @from and @to can be in either order. The region between them is synced.
  318. *
  319. * @dev: Vidconsole device being updated
  320. * @from: Start/end address within the framebuffer (->fb)
  321. * @to: Other address within the frame buffer
  322. * Return: 0 if OK, -EFAULT if the start address is before the start of the
  323. * frame buffer start
  324. */
  325. int video_sync_copy(struct udevice *dev, void *from, void *to);
  326. /**
  327. * video_sync_copy_all() - Sync the entire framebuffer to the copy
  328. *
  329. * @dev: Vidconsole device being updated
  330. * Return: 0 (always)
  331. */
  332. int video_sync_copy_all(struct udevice *dev);
  333. #else
  334. static inline int video_sync_copy(struct udevice *dev, void *from, void *to)
  335. {
  336. return 0;
  337. }
  338. static inline int video_sync_copy_all(struct udevice *dev)
  339. {
  340. return 0;
  341. }
  342. #endif
  343. /**
  344. * video_is_active() - Test if one video device it active
  345. *
  346. * Return: true if at least one video device is active, else false.
  347. */
  348. bool video_is_active(void);
  349. /**
  350. * video_get_u_boot_logo() - Get a pointer to the U-Boot logo
  351. *
  352. * Returns: Pointer to logo
  353. */
  354. void *video_get_u_boot_logo(void);
  355. /*
  356. * bmp_display() - Display BMP (bitmap) data located in memory
  357. *
  358. * @addr: address of the bmp data
  359. * @x: Position of bitmap from the left side, in pixels
  360. * @y: Position of bitmap from the top, in pixels
  361. */
  362. int bmp_display(ulong addr, int x, int y);
  363. /*
  364. * bmp_info() - Show information about bmp file
  365. *
  366. * @addr: address of bmp file
  367. * Returns: 0 if OK, else 1 if bmp image not found
  368. */
  369. int bmp_info(ulong addr);
  370. /*
  371. * video_reserve_from_bloblist()- Reserve frame-buffer memory for video devices
  372. * using blobs.
  373. *
  374. * @ho: video information passed from SPL
  375. * Returns: 0 (always)
  376. */
  377. int video_reserve_from_bloblist(struct video_handoff *ho);
  378. #endif