video.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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. #include <stdio_dev.h>
  15. struct udevice;
  16. /**
  17. * struct video_uc_plat - uclass platform data for a video device
  18. *
  19. * This holds information that the uclass needs to know about each device. It
  20. * is accessed using dev_get_uclass_plat(dev). See 'Theory of operation' at
  21. * the top of video-uclass.c for details on how this information is set.
  22. *
  23. * @align: Frame-buffer alignment, indicating the memory boundary the frame
  24. * buffer should start on. If 0, 1MB is assumed
  25. * @size: Frame-buffer size, in bytes
  26. * @base: Base address of frame buffer, 0 if not yet known
  27. * @copy_base: Base address of a hardware copy of the frame buffer. See
  28. * CONFIG_VIDEO_COPY.
  29. */
  30. struct video_uc_plat {
  31. uint align;
  32. uint size;
  33. ulong base;
  34. ulong copy_base;
  35. };
  36. enum video_polarity {
  37. VIDEO_ACTIVE_HIGH, /* Pins are active high */
  38. VIDEO_ACTIVE_LOW, /* Pins are active low */
  39. };
  40. /*
  41. * Bits per pixel selector. Each value n is such that the bits-per-pixel is
  42. * 2 ^ n
  43. */
  44. enum video_log2_bpp {
  45. VIDEO_BPP1 = 0,
  46. VIDEO_BPP2,
  47. VIDEO_BPP4,
  48. VIDEO_BPP8,
  49. VIDEO_BPP16,
  50. VIDEO_BPP32,
  51. };
  52. /*
  53. * Convert enum video_log2_bpp to bytes and bits. Note we omit the outer
  54. * brackets to allow multiplication by fractional pixels.
  55. */
  56. #define VNBYTES(bpix) (1 << (bpix)) / 8
  57. #define VNBITS(bpix) (1 << (bpix))
  58. /**
  59. * struct video_priv - Device information used by the video uclass
  60. *
  61. * @xsize: Number of pixel columns (e.g. 1366)
  62. * @ysize: Number of pixels rows (e.g.. 768)
  63. * @rot: Display rotation (0=none, 1=90 degrees clockwise, etc.)
  64. * @bpix: Encoded bits per pixel (enum video_log2_bpp)
  65. * @vidconsole_drv_name: Driver to use for the text console, NULL to
  66. * select automatically
  67. * @font_size: Font size in pixels (0 to use a default value)
  68. * @fb: Frame buffer
  69. * @fb_size: Frame buffer size
  70. * @copy_fb: Copy of the frame buffer to keep up to date; see struct
  71. * video_uc_plat
  72. * @line_length: Length of each frame buffer line, in bytes. This can be
  73. * set by the driver, but if not, the uclass will set it after
  74. * probing
  75. * @colour_fg: Foreground colour (pixel value)
  76. * @colour_bg: Background colour (pixel value)
  77. * @flush_dcache: true to enable flushing of the data cache after
  78. * the LCD is updated
  79. * @cmap: Colour map for 8-bit-per-pixel displays
  80. * @fg_col_idx: Foreground color code (bit 3 = bold, bit 0-2 = color)
  81. * @bg_col_idx: Background color code (bit 3 = bold, bit 0-2 = color)
  82. */
  83. struct video_priv {
  84. /* Things set up by the driver: */
  85. ushort xsize;
  86. ushort ysize;
  87. ushort rot;
  88. enum video_log2_bpp bpix;
  89. const char *vidconsole_drv_name;
  90. int font_size;
  91. /*
  92. * Things that are private to the uclass: don't use these in the
  93. * driver
  94. */
  95. void *fb;
  96. int fb_size;
  97. void *copy_fb;
  98. int line_length;
  99. u32 colour_fg;
  100. u32 colour_bg;
  101. bool flush_dcache;
  102. ushort *cmap;
  103. u8 fg_col_idx;
  104. u8 bg_col_idx;
  105. };
  106. /**
  107. * struct video_ops - structure for keeping video operations
  108. * @video_sync: Synchronize FB with device. Some device like SPI based LCD
  109. * displays needs synchronization when data in an FB is available.
  110. * For these devices implement video_sync hook to call a sync
  111. * function. vid is pointer to video device udevice. Function
  112. * should return 0 on success video_sync and error code otherwise
  113. */
  114. struct video_ops {
  115. int (*video_sync)(struct udevice *vid);
  116. };
  117. #define video_get_ops(dev) ((struct video_ops *)(dev)->driver->ops)
  118. /**
  119. * video_reserve() - Reserve frame-buffer memory for video devices
  120. *
  121. * Note: This function is for internal use.
  122. *
  123. * This uses the uclass plat's @size and @align members to figure out
  124. * a size and position for each frame buffer as part of the pre-relocation
  125. * process of determining the post-relocation memory layout.
  126. *
  127. * gd->video_top is set to the initial value of *@addrp and gd->video_bottom
  128. * is set to the final value.
  129. *
  130. * @addrp: On entry, the top of available memory. On exit, the new top,
  131. * after allocating the required memory.
  132. * @return 0
  133. */
  134. int video_reserve(ulong *addrp);
  135. #ifdef CONFIG_DM_VIDEO
  136. /**
  137. * video_clear() - Clear a device's frame buffer to background color.
  138. *
  139. * @dev: Device to clear
  140. * @return 0
  141. */
  142. int video_clear(struct udevice *dev);
  143. #endif /* CONFIG_DM_VIDEO */
  144. /**
  145. * video_sync() - Sync a device's frame buffer with its hardware
  146. *
  147. * @vid: Device to sync
  148. * @force: True to force a sync even if there was one recently (this is
  149. * very expensive on sandbox)
  150. *
  151. * @return: 0 on success, error code otherwise
  152. *
  153. * Some frame buffers are cached or have a secondary frame buffer. This
  154. * function syncs these up so that the current contents of the U-Boot frame
  155. * buffer are displayed to the user.
  156. */
  157. int video_sync(struct udevice *vid, bool force);
  158. /**
  159. * video_sync_all() - Sync all devices' frame buffers with there hardware
  160. *
  161. * This calls video_sync() on all active video devices.
  162. */
  163. void video_sync_all(void);
  164. /**
  165. * video_bmp_display() - Display a BMP file
  166. *
  167. * @dev: Device to display the bitmap on
  168. * @bmp_image: Address of bitmap image to display
  169. * @x: X position in pixels from the left
  170. * @y: Y position in pixels from the top
  171. * @align: true to adjust the coordinates to centre the image. If false
  172. * the coordinates are used as is. If true:
  173. *
  174. * - if a coordinate is 0x7fff then the image will be centred in
  175. * that direction
  176. * - if a coordinate is -ve then it will be offset to the
  177. * left/top of the centre by that many pixels
  178. * - if a coordinate is positive it will be used unchnaged.
  179. * @return 0 if OK, -ve on error
  180. */
  181. int video_bmp_display(struct udevice *dev, ulong bmp_image, int x, int y,
  182. bool align);
  183. /**
  184. * video_get_xsize() - Get the width of the display in pixels
  185. *
  186. * @dev: Device to check
  187. * @return device frame buffer width in pixels
  188. */
  189. int video_get_xsize(struct udevice *dev);
  190. /**
  191. * video_get_ysize() - Get the height of the display in pixels
  192. *
  193. * @dev: Device to check
  194. * @return device frame buffer height in pixels
  195. */
  196. int video_get_ysize(struct udevice *dev);
  197. /**
  198. * Set whether we need to flush the dcache when changing the image. This
  199. * defaults to off.
  200. *
  201. * @param flush non-zero to flush cache after update, 0 to skip
  202. */
  203. void video_set_flush_dcache(struct udevice *dev, bool flush);
  204. /**
  205. * Set default colors and attributes
  206. *
  207. * @dev: video device
  208. * @invert true to invert colours
  209. */
  210. void video_set_default_colors(struct udevice *dev, bool invert);
  211. #ifdef CONFIG_VIDEO_COPY
  212. /**
  213. * vidconsole_sync_copy() - Sync back to the copy framebuffer
  214. *
  215. * This ensures that the copy framebuffer has the same data as the framebuffer
  216. * for a particular region. It should be called after the framebuffer is updated
  217. *
  218. * @from and @to can be in either order. The region between them is synced.
  219. *
  220. * @dev: Vidconsole device being updated
  221. * @from: Start/end address within the framebuffer (->fb)
  222. * @to: Other address within the frame buffer
  223. * @return 0 if OK, -EFAULT if the start address is before the start of the
  224. * frame buffer start
  225. */
  226. int video_sync_copy(struct udevice *dev, void *from, void *to);
  227. /**
  228. * video_sync_copy_all() - Sync the entire framebuffer to the copy
  229. *
  230. * @dev: Vidconsole device being updated
  231. * @return 0 (always)
  232. */
  233. int video_sync_copy_all(struct udevice *dev);
  234. #else
  235. static inline int video_sync_copy(struct udevice *dev, void *from, void *to)
  236. {
  237. return 0;
  238. }
  239. static inline int video_sync_copy_all(struct udevice *dev)
  240. {
  241. return 0;
  242. }
  243. #endif
  244. #ifndef CONFIG_DM_VIDEO
  245. /* Video functions */
  246. /**
  247. * Display a BMP format bitmap on the screen
  248. *
  249. * @param bmp_image Address of BMP image
  250. * @param x X position to draw image
  251. * @param y Y position to draw image
  252. */
  253. int video_display_bitmap(ulong bmp_image, int x, int y);
  254. /**
  255. * Get the width of the screen in pixels
  256. *
  257. * @return width of screen in pixels
  258. */
  259. int video_get_pixel_width(void);
  260. /**
  261. * Get the height of the screen in pixels
  262. *
  263. * @return height of screen in pixels
  264. */
  265. int video_get_pixel_height(void);
  266. /**
  267. * Get the number of text lines/rows on the screen
  268. *
  269. * @return number of rows
  270. */
  271. int video_get_screen_rows(void);
  272. /**
  273. * Get the number of text columns on the screen
  274. *
  275. * @return number of columns
  276. */
  277. int video_get_screen_columns(void);
  278. /**
  279. * Set the position of the text cursor
  280. *
  281. * @param col Column to place cursor (0 = left side)
  282. * @param row Row to place cursor (0 = top line)
  283. */
  284. void video_position_cursor(unsigned col, unsigned row);
  285. /* Clear the display */
  286. void video_clear(void);
  287. #if defined(CONFIG_FORMIKE)
  288. int kwh043st20_f01_spi_startup(unsigned int bus, unsigned int cs,
  289. unsigned int max_hz, unsigned int spi_mode);
  290. #endif
  291. #if defined(CONFIG_LG4573)
  292. int lg4573_spi_startup(unsigned int bus, unsigned int cs,
  293. unsigned int max_hz, unsigned int spi_mode);
  294. #endif
  295. /*
  296. * video_get_info_str() - obtain a board string: type, speed, etc.
  297. *
  298. * This is called if CONFIG_CONSOLE_EXTRA_INFO is enabled.
  299. *
  300. * line_number: location to place info string beside logo
  301. * info: buffer for info string (empty if nothing to display on this
  302. * line)
  303. */
  304. void video_get_info_str(int line_number, char *info);
  305. #endif /* !CONFIG_DM_VIDEO */
  306. #endif