video.h 8.4 KB

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