sde_encoder.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. /*
  2. * Copyright (c) 2015-2019, The Linux Foundation. All rights reserved.
  3. * Copyright (C) 2013 Red Hat
  4. * Author: Rob Clark <[email protected]>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published by
  8. * the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with
  16. * this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef __SDE_ENCODER_H__
  19. #define __SDE_ENCODER_H__
  20. #include <drm/drm_crtc.h>
  21. #include "msm_prop.h"
  22. #include "sde_hw_mdss.h"
  23. #include "sde_kms.h"
  24. #define MAX_CHANNELS_PER_ENC 2
  25. #define SDE_ENCODER_FRAME_EVENT_DONE BIT(0)
  26. #define SDE_ENCODER_FRAME_EVENT_ERROR BIT(1)
  27. #define SDE_ENCODER_FRAME_EVENT_PANEL_DEAD BIT(2)
  28. #define SDE_ENCODER_FRAME_EVENT_SIGNAL_RELEASE_FENCE BIT(3)
  29. #define SDE_ENCODER_FRAME_EVENT_SIGNAL_RETIRE_FENCE BIT(4)
  30. #define IDLE_POWERCOLLAPSE_DURATION (66 - 16/2)
  31. #define IDLE_POWERCOLLAPSE_IN_EARLY_WAKEUP (200 - 16/2)
  32. /**
  33. * Encoder functions and data types
  34. * @intfs: Interfaces this encoder is using, INTF_MODE_NONE if unused
  35. * @wbs: Writebacks this encoder is using, INTF_MODE_NONE if unused
  36. * @needs_cdm: Encoder requests a CDM based on pixel format conversion needs
  37. * @display_num_of_h_tiles: Number of horizontal tiles in case of split
  38. * interface
  39. * @is_primary: set to true if the display is primary display
  40. * @topology: Topology of the display
  41. */
  42. struct sde_encoder_hw_resources {
  43. enum sde_intf_mode intfs[INTF_MAX];
  44. enum sde_intf_mode wbs[WB_MAX];
  45. bool needs_cdm;
  46. u32 display_num_of_h_tiles;
  47. bool is_primary;
  48. struct msm_display_topology topology;
  49. };
  50. /**
  51. * sde_encoder_kickoff_params - info encoder requires at kickoff
  52. * @is_primary: set to true if the display is primary display
  53. * @affected_displays: bitmask, bit set means the ROI of the commit lies within
  54. * the bounds of the physical display at the bit index
  55. * @recovery_events_enabled: indicates status of client for recoovery events
  56. * @frame_trigger_mode: indicates frame trigger mode
  57. */
  58. struct sde_encoder_kickoff_params {
  59. u32 is_primary;
  60. unsigned long affected_displays;
  61. bool recovery_events_enabled;
  62. enum frame_trigger_mode_type frame_trigger_mode;
  63. };
  64. /**
  65. * struct sde_encoder_ops - callback functions for generic sde encoder
  66. * Individual callbacks documented below.
  67. */
  68. struct sde_encoder_ops {
  69. /**
  70. * phys_init - phys initialization function
  71. * @type: controller type
  72. * @controller_id: controller id
  73. * @phys_init_params: Pointer of structure sde_enc_phys_init_params
  74. * Returns: Pointer of sde_encoder_phys, NULL if failed
  75. */
  76. void *(*phys_init)(enum sde_intf_type type,
  77. u32 controller_id, void *phys_init_params);
  78. };
  79. /**
  80. * sde_encoder_get_hw_resources - Populate table of required hardware resources
  81. * @encoder: encoder pointer
  82. * @hw_res: resource table to populate with encoder required resources
  83. * @conn_state: report hw reqs based on this proposed connector state
  84. */
  85. void sde_encoder_get_hw_resources(struct drm_encoder *encoder,
  86. struct sde_encoder_hw_resources *hw_res,
  87. struct drm_connector_state *conn_state);
  88. /**
  89. * sde_encoder_register_vblank_callback - provide callback to encoder that
  90. * will be called on the next vblank.
  91. * @encoder: encoder pointer
  92. * @cb: callback pointer, provide NULL to deregister and disable IRQs
  93. * @data: user data provided to callback
  94. */
  95. void sde_encoder_register_vblank_callback(struct drm_encoder *encoder,
  96. void (*cb)(void *), void *data);
  97. /**
  98. * sde_encoder_register_frame_event_callback - provide callback to encoder that
  99. * will be called after the request is complete, or other events.
  100. * @encoder: encoder pointer
  101. * @cb: callback pointer, provide NULL to deregister
  102. * @crtc: pointer to drm_crtc object interested in frame events
  103. */
  104. void sde_encoder_register_frame_event_callback(struct drm_encoder *encoder,
  105. void (*cb)(void *, u32), struct drm_crtc *crtc);
  106. /**
  107. * sde_encoder_get_rsc_client - gets the rsc client state for primary
  108. * for primary display.
  109. * @encoder: encoder pointer
  110. */
  111. struct sde_rsc_client *sde_encoder_get_rsc_client(struct drm_encoder *encoder);
  112. /**
  113. * sde_encoder_poll_line_counts - poll encoder line counts for start of frame
  114. * @encoder: encoder pointer
  115. * @Returns: zero on success
  116. */
  117. int sde_encoder_poll_line_counts(struct drm_encoder *encoder);
  118. /**
  119. * sde_encoder_prepare_for_kickoff - schedule double buffer flip of the ctl
  120. * path (i.e. ctl flush and start) at next appropriate time.
  121. * Immediately: if no previous commit is outstanding.
  122. * Delayed: Block until next trigger can be issued.
  123. * @encoder: encoder pointer
  124. * @params: kickoff time parameters
  125. * @Returns: Zero on success, last detected error otherwise
  126. */
  127. int sde_encoder_prepare_for_kickoff(struct drm_encoder *encoder,
  128. struct sde_encoder_kickoff_params *params);
  129. /**
  130. * sde_encoder_trigger_kickoff_pending - Clear the flush bits from previous
  131. * kickoff and trigger the ctl prepare progress for command mode display.
  132. * @encoder: encoder pointer
  133. */
  134. void sde_encoder_trigger_kickoff_pending(struct drm_encoder *encoder);
  135. /**
  136. * sde_encoder_kickoff - trigger a double buffer flip of the ctl path
  137. * (i.e. ctl flush and start) immediately.
  138. * @encoder: encoder pointer
  139. * @is_error: whether the current commit needs to be aborted and replaced
  140. * with a 'safe' commit
  141. */
  142. void sde_encoder_kickoff(struct drm_encoder *encoder, bool is_error);
  143. /**
  144. * sde_encoder_wait_for_event - Waits for encoder events
  145. * @encoder: encoder pointer
  146. * @event: event to wait for
  147. * MSM_ENC_COMMIT_DONE - Wait for hardware to have flushed the current pending
  148. * frames to hardware at a vblank or wr_ptr_start
  149. * Encoders will map this differently depending on the
  150. * panel type.
  151. * vid mode -> vsync_irq
  152. * cmd mode -> wr_ptr_start_irq
  153. * MSM_ENC_TX_COMPLETE - Wait for the hardware to transfer all the pixels to
  154. * the panel. Encoders will map this differently
  155. * depending on the panel type.
  156. * vid mode -> vsync_irq
  157. * cmd mode -> pp_done
  158. * Returns: 0 on success, -EWOULDBLOCK if already signaled, error otherwise
  159. */
  160. int sde_encoder_wait_for_event(struct drm_encoder *drm_encoder,
  161. enum msm_event_wait event);
  162. /**
  163. * sde_encoder_idle_request - request for idle request to avoid 4 vsync cycle
  164. * to turn off the clocks.
  165. * @encoder: encoder pointer
  166. * Returns: 0 on success, errorcode otherwise
  167. */
  168. int sde_encoder_idle_request(struct drm_encoder *drm_enc);
  169. /*
  170. * sde_encoder_get_fps - get interface frame rate of the given encoder
  171. * @encoder: Pointer to drm encoder object
  172. */
  173. u32 sde_encoder_get_fps(struct drm_encoder *encoder);
  174. /*
  175. * sde_encoder_get_intf_mode - get interface mode of the given encoder
  176. * @encoder: Pointer to drm encoder object
  177. */
  178. enum sde_intf_mode sde_encoder_get_intf_mode(struct drm_encoder *encoder);
  179. /**
  180. * sde_encoder_control_te - control enabling/disabling VSYNC_IN_EN
  181. * @encoder: encoder pointer
  182. * @enable: boolean to indicate enable/disable
  183. */
  184. void sde_encoder_control_te(struct drm_encoder *encoder, bool enable);
  185. /**
  186. * sde_encoder_virt_restore - restore the encoder configs
  187. * @encoder: encoder pointer
  188. */
  189. void sde_encoder_virt_restore(struct drm_encoder *encoder);
  190. /**
  191. * sde_encoder_is_dsc_merge - check if encoder is in DSC merge mode
  192. * @drm_enc: Pointer to drm encoder object
  193. * @Return: true if encoder is in DSC merge mode
  194. */
  195. bool sde_encoder_is_dsc_merge(struct drm_encoder *drm_enc);
  196. /**
  197. * sde_encoder_check_curr_mode - check if given mode is supported or not
  198. * @drm_enc: Pointer to drm encoder object
  199. * @mode: Mode to be checked
  200. * @Return: true if it is cmd mode
  201. */
  202. bool sde_encoder_check_curr_mode(struct drm_encoder *drm_enc, u32 mode);
  203. /**
  204. * sde_encoder_init - initialize virtual encoder object
  205. * @dev: Pointer to drm device structure
  206. * @disp_info: Pointer to display information structure
  207. * Returns: Pointer to newly created drm encoder
  208. */
  209. struct drm_encoder *sde_encoder_init(
  210. struct drm_device *dev,
  211. struct msm_display_info *disp_info);
  212. /**
  213. * sde_encoder_init_with_ops - initialize virtual encoder object with init ops
  214. * @dev: Pointer to drm device structure
  215. * @disp_info: Pointer to display information structure
  216. * @ops: Pointer to encoder ops structure
  217. * Returns: Pointer to newly created drm encoder
  218. */
  219. struct drm_encoder *sde_encoder_init_with_ops(
  220. struct drm_device *dev,
  221. struct msm_display_info *disp_info,
  222. const struct sde_encoder_ops *ops);
  223. /**
  224. * sde_encoder_destroy - destroy previously initialized virtual encoder
  225. * @drm_enc: Pointer to previously created drm encoder structure
  226. */
  227. void sde_encoder_destroy(struct drm_encoder *drm_enc);
  228. /**
  229. * sde_encoder_prepare_commit - prepare encoder at the very beginning of an
  230. * atomic commit, before any registers are written
  231. * @drm_enc: Pointer to previously created drm encoder structure
  232. */
  233. void sde_encoder_prepare_commit(struct drm_encoder *drm_enc);
  234. /**
  235. * sde_encoder_update_caps_for_cont_splash - update encoder settings during
  236. * device bootup when cont_splash is enabled
  237. * @drm_enc: Pointer to drm encoder structure
  238. * @splash_display: Pointer to sde_splash_display corresponding to this encoder
  239. * @enable: boolean indicates enable or displae state of splash
  240. * @Return: true if successful in updating the encoder structure
  241. */
  242. int sde_encoder_update_caps_for_cont_splash(struct drm_encoder *encoder,
  243. struct sde_splash_display *splash_display, bool enable);
  244. /**
  245. * sde_encoder_display_failure_notification - update sde encoder state for
  246. * esd timeout or other display failure notification. This event flows from
  247. * dsi, sde_connector to sde_encoder.
  248. *
  249. * This api must not be called from crtc_commit (display) thread because it
  250. * requests the flush work on same thread. It is called from esd check thread
  251. * based on current design.
  252. *
  253. * TODO: manage the event at sde_kms level for forward processing.
  254. * @drm_enc: Pointer to drm encoder structure
  255. * @Return: true if successful in updating the encoder structure
  256. */
  257. int sde_encoder_display_failure_notification(struct drm_encoder *enc);
  258. /**
  259. * sde_encoder_recovery_events_enabled - checks if client has enabled
  260. * sw recovery mechanism for this connector
  261. * @drm_enc: Pointer to drm encoder structure
  262. * @Return: true if enabled
  263. */
  264. bool sde_encoder_recovery_events_enabled(struct drm_encoder *encoder);
  265. /**
  266. * sde_encoder_recovery_events_handler - handler to enable/disable the
  267. * sw recovery for this connector
  268. * @drm_enc: Pointer to drm encoder structure
  269. */
  270. void sde_encoder_recovery_events_handler(struct drm_encoder *encoder,
  271. bool val);
  272. /**
  273. * sde_encoder_in_clone_mode - checks if underlying phys encoder is in clone
  274. * mode or independent display mode. ref@ WB in Concurrent writeback mode.
  275. * @drm_enc: Pointer to drm encoder structure
  276. * @Return: true if successful in updating the encoder structure
  277. */
  278. bool sde_encoder_in_clone_mode(struct drm_encoder *enc);
  279. /**
  280. * sde_encoder_is_primary_display - checks if underlying display is primary
  281. * display or not.
  282. * @drm_enc: Pointer to drm encoder structure
  283. * @Return: true if it is primary display. false if secondary display
  284. */
  285. bool sde_encoder_is_primary_display(struct drm_encoder *enc);
  286. /**
  287. * sde_encoder_control_idle_pc - control enable/disable of idle power collapse
  288. * @drm_enc: Pointer to drm encoder structure
  289. * @enable: enable/disable flag
  290. */
  291. void sde_encoder_control_idle_pc(struct drm_encoder *enc, bool enable);
  292. /**
  293. * sde_encoder_in_cont_splash - checks if display is in continuous splash
  294. * @drm_enc: Pointer to drm encoder structure
  295. * @Return: true if display in continuous splash
  296. */
  297. int sde_encoder_in_cont_splash(struct drm_encoder *enc);
  298. /**
  299. * sde_encoder_uidle_enable - control enable/disable of uidle
  300. * @drm_enc: Pointer to drm encoder structure
  301. * @enable: enable/disable flag
  302. */
  303. void sde_encoder_uidle_enable(struct drm_encoder *drm_enc, bool enable);
  304. #endif /* __SDE_ENCODER_H__ */