gud.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. /* SPDX-License-Identifier: MIT */
  2. /*
  3. * Copyright 2020 Noralf Trønnes
  4. */
  5. #ifndef __LINUX_GUD_H
  6. #define __LINUX_GUD_H
  7. #include <linux/types.h>
  8. /*
  9. * struct gud_display_descriptor_req - Display descriptor
  10. * @magic: Magic value GUD_DISPLAY_MAGIC
  11. * @version: Protocol version
  12. * @flags: Flags
  13. * - STATUS_ON_SET: Always do a status request after a SET request.
  14. * This is used by the Linux gadget driver since it has
  15. * no way to control the status stage of a control OUT
  16. * request that has a payload.
  17. * - FULL_UPDATE: Always send the entire framebuffer when flushing changes.
  18. * The GUD_REQ_SET_BUFFER request will not be sent
  19. * before each bulk transfer, it will only be sent if the
  20. * previous bulk transfer had failed. This gives the device
  21. * a chance to reset its state machine if needed.
  22. * This flag can not be used in combination with compression.
  23. * @compression: Supported compression types
  24. * - GUD_COMPRESSION_LZ4: LZ4 lossless compression.
  25. * @max_buffer_size: Maximum buffer size the device can handle (optional).
  26. * This is useful for devices that don't have a big enough
  27. * buffer to decompress the entire framebuffer in one go.
  28. * @min_width: Minimum pixel width the controller can handle
  29. * @max_width: Maximum width
  30. * @min_height: Minimum height
  31. * @max_height: Maximum height
  32. *
  33. * Devices that have only one display mode will have min_width == max_width
  34. * and min_height == max_height.
  35. */
  36. struct gud_display_descriptor_req {
  37. __le32 magic;
  38. #define GUD_DISPLAY_MAGIC 0x1d50614d
  39. __u8 version;
  40. __le32 flags;
  41. #define GUD_DISPLAY_FLAG_STATUS_ON_SET BIT(0)
  42. #define GUD_DISPLAY_FLAG_FULL_UPDATE BIT(1)
  43. __u8 compression;
  44. #define GUD_COMPRESSION_LZ4 BIT(0)
  45. __le32 max_buffer_size;
  46. __le32 min_width;
  47. __le32 max_width;
  48. __le32 min_height;
  49. __le32 max_height;
  50. } __packed;
  51. /*
  52. * struct gud_property_req - Property
  53. * @prop: Property
  54. * @val: Value
  55. */
  56. struct gud_property_req {
  57. __le16 prop;
  58. __le64 val;
  59. } __packed;
  60. /*
  61. * struct gud_display_mode_req - Display mode
  62. * @clock: Pixel clock in kHz
  63. * @hdisplay: Horizontal display size
  64. * @hsync_start: Horizontal sync start
  65. * @hsync_end: Horizontal sync end
  66. * @htotal: Horizontal total size
  67. * @vdisplay: Vertical display size
  68. * @vsync_start: Vertical sync start
  69. * @vsync_end: Vertical sync end
  70. * @vtotal: Vertical total size
  71. * @flags: Bits 0-13 are the same as in the RandR protocol and also what DRM uses.
  72. * The deprecated bits are reused for internal protocol flags leaving us
  73. * free to follow DRM for the other bits in the future.
  74. * - FLAG_PREFERRED: Set on the preferred display mode.
  75. */
  76. struct gud_display_mode_req {
  77. __le32 clock;
  78. __le16 hdisplay;
  79. __le16 hsync_start;
  80. __le16 hsync_end;
  81. __le16 htotal;
  82. __le16 vdisplay;
  83. __le16 vsync_start;
  84. __le16 vsync_end;
  85. __le16 vtotal;
  86. __le32 flags;
  87. #define GUD_DISPLAY_MODE_FLAG_PHSYNC BIT(0)
  88. #define GUD_DISPLAY_MODE_FLAG_NHSYNC BIT(1)
  89. #define GUD_DISPLAY_MODE_FLAG_PVSYNC BIT(2)
  90. #define GUD_DISPLAY_MODE_FLAG_NVSYNC BIT(3)
  91. #define GUD_DISPLAY_MODE_FLAG_INTERLACE BIT(4)
  92. #define GUD_DISPLAY_MODE_FLAG_DBLSCAN BIT(5)
  93. #define GUD_DISPLAY_MODE_FLAG_CSYNC BIT(6)
  94. #define GUD_DISPLAY_MODE_FLAG_PCSYNC BIT(7)
  95. #define GUD_DISPLAY_MODE_FLAG_NCSYNC BIT(8)
  96. #define GUD_DISPLAY_MODE_FLAG_HSKEW BIT(9)
  97. /* BCast and PixelMultiplex are deprecated */
  98. #define GUD_DISPLAY_MODE_FLAG_DBLCLK BIT(12)
  99. #define GUD_DISPLAY_MODE_FLAG_CLKDIV2 BIT(13)
  100. #define GUD_DISPLAY_MODE_FLAG_USER_MASK \
  101. (GUD_DISPLAY_MODE_FLAG_PHSYNC | GUD_DISPLAY_MODE_FLAG_NHSYNC | \
  102. GUD_DISPLAY_MODE_FLAG_PVSYNC | GUD_DISPLAY_MODE_FLAG_NVSYNC | \
  103. GUD_DISPLAY_MODE_FLAG_INTERLACE | GUD_DISPLAY_MODE_FLAG_DBLSCAN | \
  104. GUD_DISPLAY_MODE_FLAG_CSYNC | GUD_DISPLAY_MODE_FLAG_PCSYNC | \
  105. GUD_DISPLAY_MODE_FLAG_NCSYNC | GUD_DISPLAY_MODE_FLAG_HSKEW | \
  106. GUD_DISPLAY_MODE_FLAG_DBLCLK | GUD_DISPLAY_MODE_FLAG_CLKDIV2)
  107. /* Internal protocol flags */
  108. #define GUD_DISPLAY_MODE_FLAG_PREFERRED BIT(10)
  109. } __packed;
  110. /*
  111. * struct gud_connector_descriptor_req - Connector descriptor
  112. * @connector_type: Connector type (GUD_CONNECTOR_TYPE_*).
  113. * If the host doesn't support the type it should fall back to PANEL.
  114. * @flags: Flags
  115. * - POLL_STATUS: Connector status can change (polled every 10 seconds)
  116. * - INTERLACE: Interlaced modes are supported
  117. * - DOUBLESCAN: Doublescan modes are supported
  118. */
  119. struct gud_connector_descriptor_req {
  120. __u8 connector_type;
  121. #define GUD_CONNECTOR_TYPE_PANEL 0
  122. #define GUD_CONNECTOR_TYPE_VGA 1
  123. #define GUD_CONNECTOR_TYPE_COMPOSITE 2
  124. #define GUD_CONNECTOR_TYPE_SVIDEO 3
  125. #define GUD_CONNECTOR_TYPE_COMPONENT 4
  126. #define GUD_CONNECTOR_TYPE_DVI 5
  127. #define GUD_CONNECTOR_TYPE_DISPLAYPORT 6
  128. #define GUD_CONNECTOR_TYPE_HDMI 7
  129. __le32 flags;
  130. #define GUD_CONNECTOR_FLAGS_POLL_STATUS BIT(0)
  131. #define GUD_CONNECTOR_FLAGS_INTERLACE BIT(1)
  132. #define GUD_CONNECTOR_FLAGS_DOUBLESCAN BIT(2)
  133. } __packed;
  134. /*
  135. * struct gud_set_buffer_req - Set buffer transfer info
  136. * @x: X position of rectangle
  137. * @y: Y position
  138. * @width: Pixel width of rectangle
  139. * @height: Pixel height
  140. * @length: Buffer length in bytes
  141. * @compression: Transfer compression
  142. * @compressed_length: Compressed buffer length
  143. *
  144. * This request is issued right before the bulk transfer.
  145. * @x, @y, @width and @height specifies the rectangle where the buffer should be
  146. * placed inside the framebuffer.
  147. */
  148. struct gud_set_buffer_req {
  149. __le32 x;
  150. __le32 y;
  151. __le32 width;
  152. __le32 height;
  153. __le32 length;
  154. __u8 compression;
  155. __le32 compressed_length;
  156. } __packed;
  157. /*
  158. * struct gud_state_req - Display state
  159. * @mode: Display mode
  160. * @format: Pixel format GUD_PIXEL_FORMAT_*
  161. * @connector: Connector index
  162. * @properties: Array of properties
  163. *
  164. * The entire state is transferred each time there's a change.
  165. */
  166. struct gud_state_req {
  167. struct gud_display_mode_req mode;
  168. __u8 format;
  169. __u8 connector;
  170. struct gud_property_req properties[];
  171. } __packed;
  172. /* List of supported connector properties: */
  173. /* Margins in pixels to deal with overscan, range 0-100 */
  174. #define GUD_PROPERTY_TV_LEFT_MARGIN 1
  175. #define GUD_PROPERTY_TV_RIGHT_MARGIN 2
  176. #define GUD_PROPERTY_TV_TOP_MARGIN 3
  177. #define GUD_PROPERTY_TV_BOTTOM_MARGIN 4
  178. #define GUD_PROPERTY_TV_MODE 5
  179. /* Brightness in percent, range 0-100 */
  180. #define GUD_PROPERTY_TV_BRIGHTNESS 6
  181. /* Contrast in percent, range 0-100 */
  182. #define GUD_PROPERTY_TV_CONTRAST 7
  183. /* Flicker reduction in percent, range 0-100 */
  184. #define GUD_PROPERTY_TV_FLICKER_REDUCTION 8
  185. /* Overscan in percent, range 0-100 */
  186. #define GUD_PROPERTY_TV_OVERSCAN 9
  187. /* Saturation in percent, range 0-100 */
  188. #define GUD_PROPERTY_TV_SATURATION 10
  189. /* Hue in percent, range 0-100 */
  190. #define GUD_PROPERTY_TV_HUE 11
  191. /*
  192. * Backlight brightness is in the range 0-100 inclusive. The value represents the human perceptual
  193. * brightness and not a linear PWM value. 0 is minimum brightness which should not turn the
  194. * backlight completely off. The DPMS connector property should be used to control power which will
  195. * trigger a GUD_REQ_SET_DISPLAY_ENABLE request.
  196. *
  197. * This does not map to a DRM property, it is used with the backlight device.
  198. */
  199. #define GUD_PROPERTY_BACKLIGHT_BRIGHTNESS 12
  200. /* List of supported properties that are not connector propeties: */
  201. /*
  202. * Plane rotation. Should return the supported bitmask on
  203. * GUD_REQ_GET_PROPERTIES. GUD_ROTATION_0 is mandatory.
  204. *
  205. * Note: This is not display rotation so 90/270 will need scaling to make it fit (unless squared).
  206. */
  207. #define GUD_PROPERTY_ROTATION 50
  208. #define GUD_ROTATION_0 BIT(0)
  209. #define GUD_ROTATION_90 BIT(1)
  210. #define GUD_ROTATION_180 BIT(2)
  211. #define GUD_ROTATION_270 BIT(3)
  212. #define GUD_ROTATION_REFLECT_X BIT(4)
  213. #define GUD_ROTATION_REFLECT_Y BIT(5)
  214. #define GUD_ROTATION_MASK (GUD_ROTATION_0 | GUD_ROTATION_90 | \
  215. GUD_ROTATION_180 | GUD_ROTATION_270 | \
  216. GUD_ROTATION_REFLECT_X | GUD_ROTATION_REFLECT_Y)
  217. /* USB Control requests: */
  218. /* Get status from the last GET/SET control request. Value is u8. */
  219. #define GUD_REQ_GET_STATUS 0x00
  220. /* Status values: */
  221. #define GUD_STATUS_OK 0x00
  222. #define GUD_STATUS_BUSY 0x01
  223. #define GUD_STATUS_REQUEST_NOT_SUPPORTED 0x02
  224. #define GUD_STATUS_PROTOCOL_ERROR 0x03
  225. #define GUD_STATUS_INVALID_PARAMETER 0x04
  226. #define GUD_STATUS_ERROR 0x05
  227. /* Get display descriptor as a &gud_display_descriptor_req */
  228. #define GUD_REQ_GET_DESCRIPTOR 0x01
  229. /* Get supported pixel formats as a byte array of GUD_PIXEL_FORMAT_* */
  230. #define GUD_REQ_GET_FORMATS 0x40
  231. #define GUD_FORMATS_MAX_NUM 32
  232. #define GUD_PIXEL_FORMAT_R1 0x01 /* 1-bit monochrome */
  233. #define GUD_PIXEL_FORMAT_R8 0x08 /* 8-bit greyscale */
  234. #define GUD_PIXEL_FORMAT_XRGB1111 0x20
  235. #define GUD_PIXEL_FORMAT_RGB332 0x30
  236. #define GUD_PIXEL_FORMAT_RGB565 0x40
  237. #define GUD_PIXEL_FORMAT_RGB888 0x50
  238. #define GUD_PIXEL_FORMAT_XRGB8888 0x80
  239. #define GUD_PIXEL_FORMAT_ARGB8888 0x81
  240. /*
  241. * Get supported properties that are not connector propeties as a &gud_property_req array.
  242. * gud_property_req.val often contains the initial value for the property.
  243. */
  244. #define GUD_REQ_GET_PROPERTIES 0x41
  245. #define GUD_PROPERTIES_MAX_NUM 32
  246. /* Connector requests have the connector index passed in the wValue field */
  247. /* Get connector descriptors as an array of &gud_connector_descriptor_req */
  248. #define GUD_REQ_GET_CONNECTORS 0x50
  249. #define GUD_CONNECTORS_MAX_NUM 32
  250. /*
  251. * Get properties supported by the connector as a &gud_property_req array.
  252. * gud_property_req.val often contains the initial value for the property.
  253. */
  254. #define GUD_REQ_GET_CONNECTOR_PROPERTIES 0x51
  255. #define GUD_CONNECTOR_PROPERTIES_MAX_NUM 32
  256. /*
  257. * Issued when there's a TV_MODE property present.
  258. * Gets an array of the supported TV_MODE names each entry of length
  259. * GUD_CONNECTOR_TV_MODE_NAME_LEN. Names must be NUL-terminated.
  260. */
  261. #define GUD_REQ_GET_CONNECTOR_TV_MODE_VALUES 0x52
  262. #define GUD_CONNECTOR_TV_MODE_NAME_LEN 16
  263. #define GUD_CONNECTOR_TV_MODE_MAX_NUM 16
  264. /* When userspace checks connector status, this is issued first, not used for poll requests. */
  265. #define GUD_REQ_SET_CONNECTOR_FORCE_DETECT 0x53
  266. /*
  267. * Get connector status. Value is u8.
  268. *
  269. * Userspace will get a HOTPLUG uevent if one of the following is true:
  270. * - Connection status has changed since last
  271. * - CHANGED is set
  272. */
  273. #define GUD_REQ_GET_CONNECTOR_STATUS 0x54
  274. #define GUD_CONNECTOR_STATUS_DISCONNECTED 0x00
  275. #define GUD_CONNECTOR_STATUS_CONNECTED 0x01
  276. #define GUD_CONNECTOR_STATUS_UNKNOWN 0x02
  277. #define GUD_CONNECTOR_STATUS_CONNECTED_MASK 0x03
  278. #define GUD_CONNECTOR_STATUS_CHANGED BIT(7)
  279. /*
  280. * Display modes can be fetched as either EDID data or an array of &gud_display_mode_req.
  281. *
  282. * If GUD_REQ_GET_CONNECTOR_MODES returns zero, EDID is used to create display modes.
  283. * If both display modes and EDID are returned, EDID is just passed on to userspace
  284. * in the EDID connector property.
  285. */
  286. /* Get &gud_display_mode_req array of supported display modes */
  287. #define GUD_REQ_GET_CONNECTOR_MODES 0x55
  288. #define GUD_CONNECTOR_MAX_NUM_MODES 128
  289. /* Get Extended Display Identification Data */
  290. #define GUD_REQ_GET_CONNECTOR_EDID 0x56
  291. #define GUD_CONNECTOR_MAX_EDID_LEN 2048
  292. /* Set buffer properties before bulk transfer as &gud_set_buffer_req */
  293. #define GUD_REQ_SET_BUFFER 0x60
  294. /* Check display configuration as &gud_state_req */
  295. #define GUD_REQ_SET_STATE_CHECK 0x61
  296. /* Apply the previous STATE_CHECK configuration */
  297. #define GUD_REQ_SET_STATE_COMMIT 0x62
  298. /* Enable/disable the display controller, value is u8: 0/1 */
  299. #define GUD_REQ_SET_CONTROLLER_ENABLE 0x63
  300. /* Enable/disable display/output (DPMS), value is u8: 0/1 */
  301. #define GUD_REQ_SET_DISPLAY_ENABLE 0x64
  302. #endif