sde_wb.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2015-2019, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef __SDE_WB_H__
  6. #define __SDE_WB_H__
  7. #include <linux/platform_device.h>
  8. #include "msm_kms.h"
  9. #include "sde_kms.h"
  10. #include "sde_connector.h"
  11. /**
  12. * struct sde_wb_device - Writeback device context
  13. * @drm_dev: Pointer to controlling DRM device
  14. * @index: Index of hardware instance from device tree
  15. * @wb_idx: Writeback identifier of enum sde_wb
  16. * @wb_cfg: Writeback configuration catalog
  17. * @name: Name of writeback device from device tree
  18. * @display_type: Display type from device tree
  19. * @wb_list List of all writeback devices
  20. * @wb_lock Serialization lock for writeback context structure
  21. * @connector: Connector associated with writeback device
  22. * @encoder: Encoder associated with writeback device
  23. * @max_mixer_width: Max width supported by SDE LM HW block
  24. * @count_modes: Length of writeback connector modes array
  25. * @modes: Writeback connector modes array
  26. */
  27. struct sde_wb_device {
  28. struct drm_device *drm_dev;
  29. u32 index;
  30. u32 wb_idx;
  31. struct sde_wb_cfg *wb_cfg;
  32. const char *name;
  33. struct list_head wb_list;
  34. struct mutex wb_lock;
  35. struct drm_connector *connector;
  36. struct drm_encoder *encoder;
  37. enum drm_connector_status detect_status;
  38. u32 max_mixer_width;
  39. u32 count_modes;
  40. struct drm_mode_modeinfo *modes;
  41. };
  42. /**
  43. * sde_wb_get_index - get device index of the given writeback device
  44. * @wb_dev: Pointer to writeback device
  45. * Returns: Index of hardware instance
  46. */
  47. static inline
  48. int sde_wb_get_index(struct sde_wb_device *wb_dev)
  49. {
  50. return wb_dev ? wb_dev->index : -1;
  51. }
  52. #ifdef CONFIG_DRM_SDE_WB
  53. /**
  54. * sde_wb_get_output_fb - get framebuffer in current atomic state
  55. * @wb_dev: Pointer to writeback device
  56. * Returns: Pointer to framebuffer
  57. */
  58. struct drm_framebuffer *sde_wb_get_output_fb(struct sde_wb_device *wb_dev);
  59. /**
  60. * sde_wb_get_output_roi - get region-of-interest in current atomic state
  61. * @wb_dev: Pointer to writeback device
  62. * @roi: Pointer to region of interest
  63. * Returns: 0 if success; error code otherwise
  64. */
  65. int sde_wb_get_output_roi(struct sde_wb_device *wb_dev, struct sde_rect *roi);
  66. /**
  67. * sde_wb_get_num_of_displays - get total number of writeback devices
  68. * Returns: Number of writeback devices
  69. */
  70. u32 sde_wb_get_num_of_displays(void);
  71. /**
  72. * wb_display_get_displays - returns pointers for supported display devices
  73. * @display_array: Pointer to display array to be filled
  74. * @max_display_count: Size of display_array
  75. * @Returns: Number of display entries filled
  76. */
  77. int wb_display_get_displays(void **display_array, u32 max_display_count);
  78. void sde_wb_set_active_state(struct sde_wb_device *wb_dev, bool is_active);
  79. bool sde_wb_is_active(struct sde_wb_device *wb_dev);
  80. /**
  81. * sde_wb_drm_init - perform DRM initialization
  82. * @wb_dev: Pointer to writeback device
  83. * @encoder: Pointer to associated encoder
  84. * Returns: 0 if success; error code otherwise
  85. */
  86. int sde_wb_drm_init(struct sde_wb_device *wb_dev, struct drm_encoder *encoder);
  87. /**
  88. * sde_wb_drm_deinit - perform DRM de-initialization
  89. * @wb_dev: Pointer to writeback device
  90. * Returns: 0 if success; error code otherwise
  91. */
  92. int sde_wb_drm_deinit(struct sde_wb_device *wb_dev);
  93. /**
  94. * sde_wb_config - setup connection status and available drm modes of the
  95. * given writeback connector
  96. * @drm_dev: Pointer to DRM device
  97. * @data: Pointer to writeback configuration
  98. * @file_priv: Pointer file private data
  99. * Returns: 0 if success; error code otherwise
  100. *
  101. * This function will initiate hot-plug detection event.
  102. */
  103. int sde_wb_config(struct drm_device *drm_dev, void *data,
  104. struct drm_file *file_priv);
  105. /**
  106. * sde_wb_connector_post_init - perform writeback specific initialization
  107. * @connector: Pointer to drm connector structure
  108. * @display: Pointer to private display structure
  109. * Returns: Zero on success
  110. */
  111. int sde_wb_connector_post_init(struct drm_connector *connector, void *display);
  112. /**
  113. * sde_wb_connector_set_info_blob - perform writeback info blob initialization
  114. * @connector: Pointer to drm connector structure
  115. * @info: Pointer to connector info
  116. * @display: Pointer to private display structure
  117. * @mode_info: Pointer to the mode info structure
  118. * Returns: Zero on success
  119. */
  120. int sde_wb_connector_set_info_blob(struct drm_connector *connector,
  121. void *info,
  122. void *display,
  123. struct msm_mode_info *mode_info);
  124. /**
  125. * sde_wb_connector_detect - perform writeback connection status detection
  126. * @connector: Pointer to connector
  127. * @force: Indicate force detection
  128. * @display: Pointer to writeback device
  129. * Returns: connector status
  130. */
  131. enum drm_connector_status
  132. sde_wb_connector_detect(struct drm_connector *connector,
  133. bool force,
  134. void *display);
  135. /**
  136. * sde_wb_connector_get_modes - get display modes of connector
  137. * @connector: Pointer to connector
  138. * @display: Pointer to writeback device
  139. * Returns: Number of modes
  140. *
  141. * If display modes are not specified in writeback configuration IOCTL, this
  142. * function will install default EDID modes up to maximum resolution support.
  143. */
  144. int sde_wb_connector_get_modes(struct drm_connector *connector, void *display);
  145. /**
  146. * sde_wb_connector_set_property - set atomic connector property
  147. * @connector: Pointer to drm connector structure
  148. * @state: Pointer to drm connector state structure
  149. * @property_index: DRM property index
  150. * @value: Incoming property value
  151. * @display: Pointer to private display structure
  152. * Returns: Zero on success
  153. */
  154. int sde_wb_connector_set_property(struct drm_connector *connector,
  155. struct drm_connector_state *state,
  156. int property_index,
  157. uint64_t value,
  158. void *display);
  159. /**
  160. * sde_wb_get_info - retrieve writeback 'display' information
  161. * @connector: Pointer to drm connector structure
  162. * @info: Pointer to display info structure
  163. * @display: Pointer to private display structure
  164. * Returns: Zero on success
  165. */
  166. int sde_wb_get_info(struct drm_connector *connector,
  167. struct msm_display_info *info, void *display);
  168. /**
  169. * sde_wb_get_mode_info - retrieve information of the mode selected
  170. * @connector: Pointer to drm connector structure
  171. * @drm_mode: Display mode set for the display
  172. * @mode_info: Out parameter. information of the mode.
  173. * @max_mixer_width: max width supported by HW layer mixer
  174. * @display: Pointer to private display structure
  175. * Returns: zero on success
  176. */
  177. int sde_wb_get_mode_info(struct drm_connector *connector,
  178. const struct drm_display_mode *drm_mode,
  179. struct msm_mode_info *mode_info, u32 max_mixer_width,
  180. void *display);
  181. /**
  182. * sde_wb_connector_get_wb - retrieve writeback device of the given connector
  183. * @connector: Pointer to drm connector
  184. * Returns: Pointer to writeback device on success; NULL otherwise
  185. */
  186. static inline
  187. struct sde_wb_device *sde_wb_connector_get_wb(struct drm_connector *connector)
  188. {
  189. if (!connector ||
  190. (connector->connector_type != DRM_MODE_CONNECTOR_VIRTUAL)) {
  191. SDE_ERROR("invalid params\n");
  192. return NULL;
  193. }
  194. return sde_connector_get_display(connector);
  195. }
  196. /**
  197. * sde_wb_connector_state_get_output_fb - get framebuffer of given state
  198. * @state: Pointer to connector state
  199. * Returns: Pointer to framebuffer
  200. */
  201. struct drm_framebuffer *
  202. sde_wb_connector_state_get_output_fb(struct drm_connector_state *state);
  203. /**
  204. * sde_wb_connector_state_get_output_roi - get roi from given atomic state
  205. * @state: Pointer to atomic state
  206. * @roi: Pointer to region of interest
  207. * Returns: 0 if success; error code otherwise
  208. */
  209. int sde_wb_connector_state_get_output_roi(struct drm_connector_state *state,
  210. struct sde_rect *roi);
  211. #else
  212. static inline
  213. struct drm_framebuffer *sde_wb_get_output_fb(struct sde_wb_device *wb_dev)
  214. {
  215. return NULL;
  216. }
  217. static inline
  218. int sde_wb_get_output_roi(struct sde_wb_device *wb_dev, struct sde_rect *roi)
  219. {
  220. return 0;
  221. }
  222. static inline
  223. u32 sde_wb_get_num_of_displays(void)
  224. {
  225. return 0;
  226. }
  227. static inline
  228. int wb_display_get_displays(void **display_array, u32 max_display_count)
  229. {
  230. return 0;
  231. }
  232. static inline
  233. void sde_wb_set_active_state(struct sde_wb_device *wb_dev, bool is_active)
  234. {
  235. }
  236. static inline
  237. bool sde_wb_is_active(struct sde_wb_device *wb_dev)
  238. {
  239. return false;
  240. }
  241. static inline
  242. int sde_wb_drm_init(struct sde_wb_device *wb_dev, struct drm_encoder *encoder)
  243. {
  244. return 0;
  245. }
  246. static inline
  247. int sde_wb_drm_deinit(struct sde_wb_device *wb_dev)
  248. {
  249. return 0;
  250. }
  251. static inline
  252. int sde_wb_config(struct drm_device *drm_dev, void *data,
  253. struct drm_file *file_priv)
  254. {
  255. return 0;
  256. }
  257. static inline
  258. int sde_wb_connector_post_init(struct drm_connector *connector,
  259. void *info,
  260. void *display,
  261. struct msm_mode_info *mode_info)
  262. {
  263. return 0;
  264. }
  265. static inline
  266. enum drm_connector_status
  267. sde_wb_connector_detect(struct drm_connector *connector,
  268. bool force,
  269. void *display)
  270. {
  271. return connector_status_disconnected;
  272. }
  273. static inline
  274. int sde_wb_connector_get_modes(struct drm_connector *connector, void *display)
  275. {
  276. return -EINVAL;
  277. }
  278. static inline
  279. int sde_wb_connector_set_property(struct drm_connector *connector,
  280. struct drm_connector_state *state,
  281. int property_index,
  282. uint64_t value,
  283. void *display)
  284. {
  285. return 0;
  286. }
  287. static inline
  288. int sde_wb_get_info(struct msm_display_info *info, void *display)
  289. {
  290. return 0;
  291. }
  292. static inline
  293. struct sde_wb_device *sde_wb_connector_get_wb(struct drm_connector *connector)
  294. {
  295. return NULL;
  296. }
  297. static inline
  298. struct drm_framebuffer *
  299. sde_wb_connector_state_get_output_fb(struct drm_connector_state *state)
  300. {
  301. return NULL;
  302. }
  303. static inline
  304. int sde_wb_connector_state_get_output_roi(struct drm_connector_state *state,
  305. struct sde_rect *roi)
  306. {
  307. return 0;
  308. }
  309. #endif
  310. #endif /* __SDE_WB_H__ */