sde_encoder.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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. * @display_type: Type of the 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 display_type;
  48. struct msm_display_topology topology;
  49. };
  50. /**
  51. * sde_encoder_kickoff_params - info encoder requires at kickoff
  52. * @affected_displays: bitmask, bit set means the ROI of the commit lies within
  53. * the bounds of the physical display at the bit index
  54. * @recovery_events_enabled: indicates status of client for recoovery events
  55. * @frame_trigger_mode: indicates frame trigger mode
  56. */
  57. struct sde_encoder_kickoff_params {
  58. unsigned long affected_displays;
  59. bool recovery_events_enabled;
  60. enum frame_trigger_mode_type frame_trigger_mode;
  61. };
  62. /**
  63. * struct sde_encoder_ops - callback functions for generic sde encoder
  64. * Individual callbacks documented below.
  65. */
  66. struct sde_encoder_ops {
  67. /**
  68. * phys_init - phys initialization function
  69. * @type: controller type
  70. * @controller_id: controller id
  71. * @phys_init_params: Pointer of structure sde_enc_phys_init_params
  72. * Returns: Pointer of sde_encoder_phys, NULL if failed
  73. */
  74. void *(*phys_init)(enum sde_intf_type type,
  75. u32 controller_id, void *phys_init_params);
  76. };
  77. /**
  78. * sde_encoder_get_hw_resources - Populate table of required hardware resources
  79. * @encoder: encoder pointer
  80. * @hw_res: resource table to populate with encoder required resources
  81. * @conn_state: report hw reqs based on this proposed connector state
  82. */
  83. void sde_encoder_get_hw_resources(struct drm_encoder *encoder,
  84. struct sde_encoder_hw_resources *hw_res,
  85. struct drm_connector_state *conn_state);
  86. /**
  87. * sde_encoder_register_vblank_callback - provide callback to encoder that
  88. * will be called on the next vblank.
  89. * @encoder: encoder pointer
  90. * @cb: callback pointer, provide NULL to deregister and disable IRQs
  91. * @data: user data provided to callback
  92. */
  93. void sde_encoder_register_vblank_callback(struct drm_encoder *encoder,
  94. void (*cb)(void *), void *data);
  95. /**
  96. * sde_encoder_register_frame_event_callback - provide callback to encoder that
  97. * will be called after the request is complete, or other events.
  98. * @encoder: encoder pointer
  99. * @cb: callback pointer, provide NULL to deregister
  100. * @crtc: pointer to drm_crtc object interested in frame events
  101. */
  102. void sde_encoder_register_frame_event_callback(struct drm_encoder *encoder,
  103. void (*cb)(void *, u32), struct drm_crtc *crtc);
  104. /**
  105. * sde_encoder_get_rsc_client - gets the rsc client state for primary
  106. * for primary display.
  107. * @encoder: encoder pointer
  108. */
  109. struct sde_rsc_client *sde_encoder_get_rsc_client(struct drm_encoder *encoder);
  110. /**
  111. * sde_encoder_poll_line_counts - poll encoder line counts for start of frame
  112. * @encoder: encoder pointer
  113. * @Returns: zero on success
  114. */
  115. int sde_encoder_poll_line_counts(struct drm_encoder *encoder);
  116. /**
  117. * sde_encoder_prepare_for_kickoff - schedule double buffer flip of the ctl
  118. * path (i.e. ctl flush and start) at next appropriate time.
  119. * Immediately: if no previous commit is outstanding.
  120. * Delayed: Block until next trigger can be issued.
  121. * @encoder: encoder pointer
  122. * @params: kickoff time parameters
  123. * @Returns: Zero on success, last detected error otherwise
  124. */
  125. int sde_encoder_prepare_for_kickoff(struct drm_encoder *encoder,
  126. struct sde_encoder_kickoff_params *params);
  127. /**
  128. * sde_encoder_trigger_kickoff_pending - Clear the flush bits from previous
  129. * kickoff and trigger the ctl prepare progress for command mode display.
  130. * @encoder: encoder pointer
  131. */
  132. void sde_encoder_trigger_kickoff_pending(struct drm_encoder *encoder);
  133. /**
  134. * sde_encoder_kickoff - trigger a double buffer flip of the ctl path
  135. * (i.e. ctl flush and start) immediately.
  136. * @encoder: encoder pointer
  137. * @is_error: whether the current commit needs to be aborted and replaced
  138. * with a 'safe' commit
  139. */
  140. void sde_encoder_kickoff(struct drm_encoder *encoder, bool is_error);
  141. /**
  142. * sde_encoder_wait_for_event - Waits for encoder events
  143. * @encoder: encoder pointer
  144. * @event: event to wait for
  145. * MSM_ENC_COMMIT_DONE - Wait for hardware to have flushed the current pending
  146. * frames to hardware at a vblank or wr_ptr_start
  147. * Encoders will map this differently depending on the
  148. * panel type.
  149. * vid mode -> vsync_irq
  150. * cmd mode -> wr_ptr_start_irq
  151. * MSM_ENC_TX_COMPLETE - Wait for the hardware to transfer all the pixels to
  152. * the panel. Encoders will map this differently
  153. * depending on the panel type.
  154. * vid mode -> vsync_irq
  155. * cmd mode -> pp_done
  156. * Returns: 0 on success, -EWOULDBLOCK if already signaled, error otherwise
  157. */
  158. int sde_encoder_wait_for_event(struct drm_encoder *drm_encoder,
  159. enum msm_event_wait event);
  160. /**
  161. * sde_encoder_idle_request - request for idle request to avoid 4 vsync cycle
  162. * to turn off the clocks.
  163. * @encoder: encoder pointer
  164. * Returns: 0 on success, errorcode otherwise
  165. */
  166. int sde_encoder_idle_request(struct drm_encoder *drm_enc);
  167. /*
  168. * sde_encoder_get_fps - get interface frame rate of the given encoder
  169. * @encoder: Pointer to drm encoder object
  170. */
  171. u32 sde_encoder_get_fps(struct drm_encoder *encoder);
  172. /*
  173. * sde_encoder_get_intf_mode - get interface mode of the given encoder
  174. * @encoder: Pointer to drm encoder object
  175. */
  176. enum sde_intf_mode sde_encoder_get_intf_mode(struct drm_encoder *encoder);
  177. /**
  178. * sde_encoder_control_te - control enabling/disabling VSYNC_IN_EN
  179. * @encoder: encoder pointer
  180. * @enable: boolean to indicate enable/disable
  181. */
  182. void sde_encoder_control_te(struct drm_encoder *encoder, bool enable);
  183. /**
  184. * sde_encoder_virt_restore - restore the encoder configs
  185. * @encoder: encoder pointer
  186. */
  187. void sde_encoder_virt_restore(struct drm_encoder *encoder);
  188. /**
  189. * sde_encoder_is_dsc_merge - check if encoder is in DSC merge mode
  190. * @drm_enc: Pointer to drm encoder object
  191. * @Return: true if encoder is in DSC merge mode
  192. */
  193. bool sde_encoder_is_dsc_merge(struct drm_encoder *drm_enc);
  194. /**
  195. * sde_encoder_check_curr_mode - check if given mode is supported or not
  196. * @drm_enc: Pointer to drm encoder object
  197. * @mode: Mode to be checked
  198. * @Return: true if it is cmd mode
  199. */
  200. bool sde_encoder_check_curr_mode(struct drm_encoder *drm_enc, u32 mode);
  201. /**
  202. * sde_encoder_init - initialize virtual encoder object
  203. * @dev: Pointer to drm device structure
  204. * @disp_info: Pointer to display information structure
  205. * Returns: Pointer to newly created drm encoder
  206. */
  207. struct drm_encoder *sde_encoder_init(
  208. struct drm_device *dev,
  209. struct msm_display_info *disp_info);
  210. /**
  211. * sde_encoder_init_with_ops - initialize virtual encoder object with init ops
  212. * @dev: Pointer to drm device structure
  213. * @disp_info: Pointer to display information structure
  214. * @ops: Pointer to encoder ops structure
  215. * Returns: Pointer to newly created drm encoder
  216. */
  217. struct drm_encoder *sde_encoder_init_with_ops(
  218. struct drm_device *dev,
  219. struct msm_display_info *disp_info,
  220. const struct sde_encoder_ops *ops);
  221. /**
  222. * sde_encoder_destroy - destroy previously initialized virtual encoder
  223. * @drm_enc: Pointer to previously created drm encoder structure
  224. */
  225. void sde_encoder_destroy(struct drm_encoder *drm_enc);
  226. /**
  227. * sde_encoder_prepare_commit - prepare encoder at the very beginning of an
  228. * atomic commit, before any registers are written
  229. * @drm_enc: Pointer to previously created drm encoder structure
  230. */
  231. void sde_encoder_prepare_commit(struct drm_encoder *drm_enc);
  232. /**
  233. * sde_encoder_update_caps_for_cont_splash - update encoder settings during
  234. * device bootup when cont_splash is enabled
  235. * @drm_enc: Pointer to drm encoder structure
  236. * @splash_display: Pointer to sde_splash_display corresponding to this encoder
  237. * @enable: boolean indicates enable or displae state of splash
  238. * @Return: true if successful in updating the encoder structure
  239. */
  240. int sde_encoder_update_caps_for_cont_splash(struct drm_encoder *encoder,
  241. struct sde_splash_display *splash_display, bool enable);
  242. /**
  243. * sde_encoder_display_failure_notification - update sde encoder state for
  244. * esd timeout or other display failure notification. This event flows from
  245. * dsi, sde_connector to sde_encoder.
  246. *
  247. * This api must not be called from crtc_commit (display) thread because it
  248. * requests the flush work on same thread. It is called from esd check thread
  249. * based on current design.
  250. *
  251. * TODO: manage the event at sde_kms level for forward processing.
  252. * @drm_enc: Pointer to drm encoder structure
  253. * @skip_pre_kickoff: Caller can avoid pre_kickoff if it is triggering this
  254. * event only to switch the panel TE to watchdog mode.
  255. * @Return: true if successful in updating the encoder structure
  256. */
  257. int sde_encoder_display_failure_notification(struct drm_encoder *enc,
  258. bool skip_pre_kickoff);
  259. /**
  260. * sde_encoder_recovery_events_enabled - checks if client has enabled
  261. * sw recovery mechanism for this connector
  262. * @drm_enc: Pointer to drm encoder structure
  263. * @Return: true if enabled
  264. */
  265. bool sde_encoder_recovery_events_enabled(struct drm_encoder *encoder);
  266. /**
  267. * sde_encoder_recovery_events_handler - handler to enable/disable the
  268. * sw recovery for this connector
  269. * @drm_enc: Pointer to drm encoder structure
  270. */
  271. void sde_encoder_recovery_events_handler(struct drm_encoder *encoder,
  272. bool val);
  273. /**
  274. * sde_encoder_in_clone_mode - checks if underlying phys encoder is in clone
  275. * mode or independent display mode. ref@ WB in Concurrent writeback mode.
  276. * @drm_enc: Pointer to drm encoder structure
  277. * @Return: true if successful in updating the encoder structure
  278. */
  279. bool sde_encoder_in_clone_mode(struct drm_encoder *enc);
  280. /**
  281. * sde_encoder_is_primary_display - checks if underlying display is primary
  282. * display or not.
  283. * @drm_enc: Pointer to drm encoder structure
  284. * @Return: true if it is primary display. false if secondary display
  285. */
  286. bool sde_encoder_is_primary_display(struct drm_encoder *enc);
  287. /**
  288. * sde_encoder_control_idle_pc - control enable/disable of idle power collapse
  289. * @drm_enc: Pointer to drm encoder structure
  290. * @enable: enable/disable flag
  291. */
  292. void sde_encoder_control_idle_pc(struct drm_encoder *enc, bool enable);
  293. /**
  294. * sde_encoder_in_cont_splash - checks if display is in continuous splash
  295. * @drm_enc: Pointer to drm encoder structure
  296. * @Return: true if display in continuous splash
  297. */
  298. int sde_encoder_in_cont_splash(struct drm_encoder *enc);
  299. /**
  300. * sde_encoder_uidle_enable - control enable/disable of uidle
  301. * @drm_enc: Pointer to drm encoder structure
  302. * @enable: enable/disable flag
  303. */
  304. void sde_encoder_uidle_enable(struct drm_encoder *drm_enc, bool enable);
  305. #endif /* __SDE_ENCODER_H__ */