sde_encoder.h 13 KB

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