sde_encoder.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820
  1. /*
  2. * Copyright (c) 2021-2023 Qualcomm Innovation Center, Inc. All rights reserved.
  3. * Copyright (c) 2015-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (C) 2013 Red Hat
  5. * Author: Rob Clark <[email protected]>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2 as published by
  9. * the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef __SDE_ENCODER_H__
  20. #define __SDE_ENCODER_H__
  21. #include <drm/drm_crtc.h>
  22. #include <drm/drm_bridge.h>
  23. #include <linux/sde_rsc.h>
  24. #include "msm_prop.h"
  25. #include "sde_hw_mdss.h"
  26. #include "sde_kms.h"
  27. #include "sde_connector.h"
  28. #include "sde_power_handle.h"
  29. /*
  30. * Two to anticipate panels that can do cmd/vid dynamic switching
  31. * plan is to create all possible physical encoder types, and switch between
  32. * them at runtime
  33. */
  34. #define NUM_PHYS_ENCODER_TYPES 2
  35. #define MAX_PHYS_ENCODERS_PER_VIRTUAL \
  36. (MAX_H_TILES_PER_DISPLAY * NUM_PHYS_ENCODER_TYPES)
  37. #define MAX_CHANNELS_PER_ENC 4
  38. #define SDE_ENCODER_FRAME_EVENT_DONE BIT(0)
  39. #define SDE_ENCODER_FRAME_EVENT_ERROR BIT(1)
  40. #define SDE_ENCODER_FRAME_EVENT_PANEL_DEAD BIT(2)
  41. #define SDE_ENCODER_FRAME_EVENT_SIGNAL_RELEASE_FENCE BIT(3)
  42. #define SDE_ENCODER_FRAME_EVENT_SIGNAL_RETIRE_FENCE BIT(4)
  43. #define SDE_ENCODER_FRAME_EVENT_CWB_DONE BIT(5)
  44. #define IDLE_POWERCOLLAPSE_DURATION (66 - 16/2)
  45. #define IDLE_POWERCOLLAPSE_IN_EARLY_WAKEUP (200 - 16/2)
  46. /* below this fps limit, timeouts are adjusted based on fps */
  47. #define DEFAULT_TIMEOUT_FPS_THRESHOLD 24
  48. #define SDE_ENC_IRQ_REGISTERED(phys_enc, idx) \
  49. ((!(phys_enc) || ((idx) < 0) || ((idx) >= INTR_IDX_MAX)) ? \
  50. 0 : ((phys_enc)->irq[(idx)].irq_idx >= 0))
  51. #define DEFAULT_MIN_FPS 10
  52. /**
  53. * Encoder functions and data types
  54. * @intfs: Interfaces this encoder is using, INTF_MODE_NONE if unused
  55. * @wbs: Writebacks this encoder is using, INTF_MODE_NONE if unused
  56. * @needs_cdm: Encoder requests a CDM based on pixel format conversion needs
  57. * @display_num_of_h_tiles: Number of horizontal tiles in case of split
  58. * interface
  59. * @display_type: Type of the display
  60. * @topology: Topology of the display
  61. * @comp_info: Compression parameters information
  62. */
  63. struct sde_encoder_hw_resources {
  64. enum sde_intf_mode intfs[INTF_MAX];
  65. enum sde_intf_mode wbs[WB_MAX];
  66. bool needs_cdm;
  67. u32 display_num_of_h_tiles;
  68. enum sde_connector_display display_type;
  69. struct msm_display_topology topology;
  70. struct msm_compression_info *comp_info;
  71. };
  72. /**
  73. * sde_encoder_kickoff_params - info encoder requires at kickoff
  74. * @affected_displays: bitmask, bit set means the ROI of the commit lies within
  75. * the bounds of the physical display at the bit index
  76. * @recovery_events_enabled: indicates status of client for recoovery events
  77. * @frame_trigger_mode: indicates frame trigger mode
  78. */
  79. struct sde_encoder_kickoff_params {
  80. unsigned long affected_displays;
  81. bool recovery_events_enabled;
  82. enum frame_trigger_mode_type frame_trigger_mode;
  83. };
  84. /*
  85. * enum sde_enc_rc_states - states that the resource control maintains
  86. * @SDE_ENC_RC_STATE_OFF: Resource is in OFF state
  87. * @SDE_ENC_RC_STATE_PRE_OFF: Resource is transitioning to OFF state
  88. * @SDE_ENC_RC_STATE_ON: Resource is in ON state
  89. * @SDE_ENC_RC_STATE_MODESET: Resource is in modeset state
  90. * @SDE_ENC_RC_STATE_IDLE: Resource is in IDLE state
  91. */
  92. enum sde_enc_rc_states {
  93. SDE_ENC_RC_STATE_OFF,
  94. SDE_ENC_RC_STATE_PRE_OFF,
  95. SDE_ENC_RC_STATE_ON,
  96. SDE_ENC_RC_STATE_MODESET,
  97. SDE_ENC_RC_STATE_IDLE
  98. };
  99. /*
  100. * enum sde_sim_qsync_frame - simulated QSYNC frame type
  101. * @SDE_SIM_QSYNC_FRAME_NOMINAL: Frame is triggered early and TE must come at nominal frame rate.
  102. * @SDE_SIM_QSYNC_FRAME_EARLY_OR_LATE: Frame could be triggered early or late and TE must adjust
  103. * accordingly.
  104. * @SDE_SIM_QSYNC_FRAME_TIMEOUT: Frame is triggered too late and TE must adjust to the
  105. * minimum QSYNC FPS.
  106. */
  107. enum sde_sim_qsync_frame {
  108. SDE_SIM_QSYNC_FRAME_NOMINAL,
  109. SDE_SIM_QSYNC_FRAME_EARLY_OR_LATE,
  110. SDE_SIM_QSYNC_FRAME_TIMEOUT
  111. };
  112. /*
  113. * enum sde_sim_qsync_event - events that simulates a QSYNC panel
  114. * @SDE_SIM_QSYNC_EVENT_FRAME_DETECTED: Event when DDIC is detecting a frame.
  115. * @SDE_SIM_QSYNC_EVENT_TE_TRIGGER: Event when DDIC is triggering TE signal.
  116. */
  117. enum sde_sim_qsync_event {
  118. SDE_SIM_QSYNC_EVENT_FRAME_DETECTED,
  119. SDE_SIM_QSYNC_EVENT_TE_TRIGGER
  120. };
  121. /* Frame rate value to trigger the watchdog TE in 200 us */
  122. #define SDE_SIM_QSYNC_IMMEDIATE_FPS 5000
  123. /**
  124. * struct sde_encoder_virt - virtual encoder. Container of one or more physical
  125. * encoders. Virtual encoder manages one "logical" display. Physical
  126. * encoders manage one intf block, tied to a specific panel/sub-panel.
  127. * Virtual encoder defers as much as possible to the physical encoders.
  128. * Virtual encoder registers itself with the DRM Framework as the encoder.
  129. * @base: drm_encoder base class for registration with DRM
  130. * @enc_spin_lock: Virtual-Encoder-Wide Spin Lock for IRQ purposes
  131. * @bus_scaling_client: Client handle to the bus scaling interface
  132. * @te_source: vsync source pin information
  133. * @num_phys_encs: Actual number of physical encoders contained.
  134. * @phys_encs: Container of physical encoders managed.
  135. * @phys_vid_encs: Video physical encoders for panel mode switch.
  136. * @phys_cmd_encs: Command physical encoders for panel mode switch.
  137. * @cur_master: Pointer to the current master in this mode. Optimization
  138. * Only valid after enable. Cleared as disable.
  139. * @hw_pp Handle to the pingpong blocks used for the display. No.
  140. * pingpong blocks can be different than num_phys_encs.
  141. * @hw_dsc: Array of DSC block handles used for the display.
  142. * @hw_vdc: Array of VDC block handles used for the display.
  143. * @cur_channel_cnt Number of data channels currently used for the display
  144. * @dirty_dsc_ids: Cached dsc indexes for dirty DSC blocks needing flush
  145. * @intfs_swapped Whether or not the phys_enc interfaces have been swapped
  146. * for partial update right-only cases, such as pingpong
  147. * split where virtual pingpong does not generate IRQs
  148. * @qdss_status: indicate if qdss is modified since last update
  149. * @crtc_vblank_cb: Callback into the upper layer / CRTC for
  150. * notification of the VBLANK
  151. * @crtc_vblank_cb_data: Data from upper layer for VBLANK notification
  152. * @crtc_kickoff_cb: Callback into CRTC that will flush & start
  153. * all CTL paths
  154. * @crtc_kickoff_cb_data: Opaque user data given to crtc_kickoff_cb
  155. * @debugfs_root: Debug file system root file node
  156. * @enc_lock: Lock around physical encoder create/destroy and
  157. access.
  158. * @frame_done_cnt: Atomic counter for tracking which phys_enc is
  159. * done with frame processing
  160. * @crtc_frame_event_cb: callback handler for frame event
  161. * @crtc_frame_event_cb_data: callback handler private data
  162. * @rsc_client: rsc client pointer
  163. * @rsc_state_init: boolean to indicate rsc config init
  164. * @disp_info: local copy of msm_display_info struct
  165. * @misr_enable: misr enable/disable status
  166. * @misr_reconfigure: boolean entry indicates misr reconfigure status
  167. * @misr_frame_count: misr frame count before start capturing the data
  168. * @idle_pc_enabled: indicate if idle power collapse is enabled
  169. * currently. This can be controlled by user-mode
  170. * @restore_te_rd_ptr: flag to indicate that te read pointer value must
  171. * be restored after idle power collapse
  172. * @rc_lock: resource control mutex lock to protect
  173. * virt encoder over various state changes
  174. * @rc_state: resource controller state
  175. * @delayed_off_work: delayed worker to schedule disabling of
  176. * clks and resources after IDLE_TIMEOUT time.
  177. * @early_wakeup_work: worker to handle early wakeup event
  178. * @input_event_work: worker to handle input device touch events
  179. * @esd_trigger_work: worker to handle esd trigger events
  180. * @input_handler: handler for input device events
  181. * @topology: topology of the display
  182. * @vblank_enabled: boolean to track userspace vblank vote
  183. * @idle_pc_restore: flag to indicate idle_pc_restore happened
  184. * @frame_trigger_mode: frame trigger mode indication for command mode
  185. * display
  186. * @dynamic_hdr_updated: flag to indicate if mempool was unchanged
  187. * @rsc_config: rsc configuration for display vtotal, fps, etc.
  188. * @cur_conn_roi: current connector roi
  189. * @prv_conn_roi: previous connector roi to optimize if unchanged
  190. * @crtc pointer to drm_crtc
  191. * @fal10_veto_override: software override for micro idle fal10 veto
  192. * @recovery_events_enabled: status of hw recovery feature enable by client
  193. * @elevated_ahb_vote: increase AHB bus speed for the first frame
  194. * after power collapse
  195. * @pm_qos_cpu_req: qos request for all cpu core frequency
  196. * @valid_cpu_mask: actual voted cpu core mask
  197. * @mode_info: stores the current mode and should be used
  198. * only in commit phase
  199. * @delay_kickoff boolean to delay the kickoff, used in case
  200. * of esd attack to ensure esd workqueue detects
  201. * the previous frame transfer completion before
  202. * next update is triggered.
  203. * @autorefresh_solver_disable It tracks if solver state is disabled from this
  204. * encoder due to autorefresh concurrency.
  205. * @ctl_done_supported boolean flag to indicate the availability of
  206. * ctl done irq support for the hardware
  207. * @dynamic_irqs_config bitmask config to enable encoder dynamic irqs
  208. * @vsync_event_wq Queue to wait for the vsync event complete
  209. */
  210. struct sde_encoder_virt {
  211. struct drm_encoder base;
  212. spinlock_t enc_spinlock;
  213. struct mutex vblank_ctl_lock;
  214. uint32_t bus_scaling_client;
  215. uint32_t display_num_of_h_tiles;
  216. uint32_t te_source;
  217. unsigned int num_phys_encs;
  218. struct sde_encoder_phys *phys_encs[MAX_PHYS_ENCODERS_PER_VIRTUAL];
  219. struct sde_encoder_phys *phys_vid_encs[MAX_PHYS_ENCODERS_PER_VIRTUAL];
  220. struct sde_encoder_phys *phys_cmd_encs[MAX_PHYS_ENCODERS_PER_VIRTUAL];
  221. struct sde_encoder_phys *cur_master;
  222. struct sde_hw_pingpong *hw_pp[MAX_CHANNELS_PER_ENC];
  223. struct sde_hw_dsc *hw_dsc[MAX_CHANNELS_PER_ENC];
  224. struct sde_hw_vdc *hw_vdc[MAX_CHANNELS_PER_ENC];
  225. struct sde_hw_pingpong *hw_dsc_pp[MAX_CHANNELS_PER_ENC];
  226. enum sde_dsc dirty_dsc_ids[MAX_CHANNELS_PER_ENC];
  227. enum sde_vdc dirty_vdc_ids[MAX_CHANNELS_PER_ENC];
  228. u32 cur_channel_cnt;
  229. bool intfs_swapped;
  230. bool qdss_status;
  231. void (*crtc_vblank_cb)(void *data, ktime_t ts);
  232. void *crtc_vblank_cb_data;
  233. struct dentry *debugfs_root;
  234. struct mutex enc_lock;
  235. atomic_t frame_done_cnt[MAX_PHYS_ENCODERS_PER_VIRTUAL];
  236. void (*crtc_frame_event_cb)(void *data, u32 event, ktime_t ts);
  237. struct sde_kms_frame_event_cb_data crtc_frame_event_cb_data;
  238. struct sde_rsc_client *rsc_client;
  239. bool rsc_state_init;
  240. struct msm_display_info disp_info;
  241. atomic_t misr_enable;
  242. bool misr_reconfigure;
  243. u32 misr_frame_count;
  244. bool idle_pc_enabled;
  245. bool input_event_enabled;
  246. struct mutex rc_lock;
  247. enum sde_enc_rc_states rc_state;
  248. struct kthread_delayed_work delayed_off_work;
  249. struct kthread_work early_wakeup_work;
  250. struct kthread_work input_event_work;
  251. struct kthread_work esd_trigger_work;
  252. struct input_handler *input_handler;
  253. bool vblank_enabled;
  254. bool idle_pc_restore;
  255. bool restore_te_rd_ptr;
  256. enum frame_trigger_mode_type frame_trigger_mode;
  257. bool dynamic_hdr_updated;
  258. struct sde_rsc_cmd_config rsc_config;
  259. struct sde_rect cur_conn_roi;
  260. struct sde_rect prv_conn_roi;
  261. struct drm_crtc *crtc;
  262. bool fal10_veto_override;
  263. bool recovery_events_enabled;
  264. bool elevated_ahb_vote;
  265. struct dev_pm_qos_request pm_qos_cpu_req[NR_CPUS];
  266. struct cpumask valid_cpu_mask;
  267. struct msm_mode_info mode_info;
  268. bool delay_kickoff;
  269. bool autorefresh_solver_disable;
  270. bool ctl_done_supported;
  271. unsigned long dynamic_irqs_config;
  272. wait_queue_head_t vsync_event_wq;
  273. };
  274. #define to_sde_encoder_virt(x) container_of(x, struct sde_encoder_virt, base)
  275. /**
  276. * sde_encoder_get_hw_resources - Populate table of required hardware resources
  277. * @encoder: encoder pointer
  278. * @hw_res: resource table to populate with encoder required resources
  279. * @conn_state: report hw reqs based on this proposed connector state
  280. */
  281. void sde_encoder_get_hw_resources(struct drm_encoder *encoder,
  282. struct sde_encoder_hw_resources *hw_res,
  283. struct drm_connector_state *conn_state);
  284. /**
  285. * sde_encoder_early_wakeup - early wake up display
  286. * @encoder: encoder pointer
  287. */
  288. void sde_encoder_early_wakeup(struct drm_encoder *drm_enc);
  289. /**
  290. * sde_encoder_handle_hw_fence_error - hw fence error handing in sde encoder
  291. * @ctl_idx: control path index
  292. * @sde_kms: Pointer to sde_kms
  293. * @handle: hash of fence signaled with error
  294. * @error: error signaled for fence from hw fence callback
  295. */
  296. void sde_encoder_handle_hw_fence_error(int ctl_idx, struct sde_kms *sde_kms, u32 handle, int error);
  297. /**
  298. * sde_encoder_hw_fence_error_handle - fence error handing while hw fence error
  299. * @drm_enc: Pointer to drm encoder structure
  300. * return: 0 on success; error code otherwise
  301. */
  302. int sde_encoder_hw_fence_error_handle(struct drm_encoder *drm_enc);
  303. /**
  304. * sde_encoder_register_vblank_callback - provide callback to encoder that
  305. * will be called on the next vblank.
  306. * @encoder: encoder pointer
  307. * @cb: callback pointer, provide NULL to deregister and disable IRQs
  308. * @data: user data provided to callback
  309. */
  310. void sde_encoder_register_vblank_callback(struct drm_encoder *encoder,
  311. void (*cb)(void *, ktime_t), void *data);
  312. /**
  313. * sde_encoder_register_frame_event_callback - provide callback to encoder that
  314. * will be called after the request is complete, or other events.
  315. * @encoder: encoder pointer
  316. * @cb: callback pointer, provide NULL to deregister
  317. * @crtc: pointer to drm_crtc object interested in frame events
  318. */
  319. void sde_encoder_register_frame_event_callback(struct drm_encoder *encoder,
  320. void (*cb)(void *, u32, ktime_t), struct drm_crtc *crtc);
  321. /**
  322. * sde_encoder_get_rsc_client - gets the rsc client state for primary
  323. * for primary display.
  324. * @encoder: encoder pointer
  325. */
  326. struct sde_rsc_client *sde_encoder_get_rsc_client(struct drm_encoder *encoder);
  327. /**
  328. * sde_encoder_poll_line_counts - poll encoder line counts for start of frame
  329. * @encoder: encoder pointer
  330. * @Returns: zero on success
  331. */
  332. int sde_encoder_poll_line_counts(struct drm_encoder *encoder);
  333. /**
  334. * sde_encoder_prepare_for_kickoff - schedule double buffer flip of the ctl
  335. * path (i.e. ctl flush and start) at next appropriate time.
  336. * Immediately: if no previous commit is outstanding.
  337. * Delayed: Block until next trigger can be issued.
  338. * @encoder: encoder pointer
  339. * @params: kickoff time parameters
  340. * @Returns: Zero on success, last detected error otherwise
  341. */
  342. int sde_encoder_prepare_for_kickoff(struct drm_encoder *encoder,
  343. struct sde_encoder_kickoff_params *params);
  344. /**
  345. * sde_encoder_trigger_kickoff_pending - Clear the flush bits from previous
  346. * kickoff and trigger the ctl prepare progress for command mode display.
  347. * @encoder: encoder pointer
  348. */
  349. void sde_encoder_trigger_kickoff_pending(struct drm_encoder *encoder);
  350. /**
  351. * sde_encoder_reset_kickoff_timeout_ms - Reset the kickoff_timout after modeset
  352. * commit for command mode display.
  353. * @encoder: encoder pointer
  354. */
  355. void sde_encoder_reset_kickoff_timeout_ms(struct drm_encoder *encoder);
  356. /**
  357. * sde_encoder_kickoff - trigger a double buffer flip of the ctl path
  358. * (i.e. ctl flush and start) immediately.
  359. * @encoder: encoder pointer
  360. * @config_changed: if true new configuration is applied on the control path
  361. */
  362. void sde_encoder_kickoff(struct drm_encoder *encoder, bool config_changed);
  363. /**
  364. * sde_encoder_wait_for_event - Waits for encoder events
  365. * @encoder: encoder pointer
  366. * @event: event to wait for
  367. * MSM_ENC_COMMIT_DONE - Wait for hardware to have flushed the current pending
  368. * frames to hardware at a vblank or wr_ptr_start
  369. * Encoders will map this differently depending on the
  370. * panel type.
  371. * vid mode -> vsync_irq
  372. * cmd mode -> wr_ptr_start_irq
  373. * MSM_ENC_TX_COMPLETE - Wait for the hardware to transfer all the pixels to
  374. * the panel. Encoders will map this differently
  375. * depending on the panel type.
  376. * vid mode -> vsync_irq
  377. * cmd mode -> pp_done
  378. * Returns: 0 on success, -EWOULDBLOCK if already signaled, error otherwise
  379. */
  380. int sde_encoder_wait_for_event(struct drm_encoder *drm_encoder,
  381. enum msm_event_wait event);
  382. /**
  383. * sde_encoder_idle_request - request for idle request to avoid 4 vsync cycle
  384. * to turn off the clocks.
  385. * @encoder: encoder pointer
  386. * Returns: 0 on success, errorcode otherwise
  387. */
  388. int sde_encoder_idle_request(struct drm_encoder *drm_enc);
  389. /*
  390. * sde_encoder_get_fps - get interface frame rate of the given encoder
  391. * @encoder: Pointer to drm encoder object
  392. */
  393. u32 sde_encoder_get_fps(struct drm_encoder *encoder);
  394. /*
  395. * sde_encoder_get_intf_mode - get interface mode of the given encoder
  396. * @encoder: Pointer to drm encoder object
  397. */
  398. enum sde_intf_mode sde_encoder_get_intf_mode(struct drm_encoder *encoder);
  399. /*
  400. * sde_encoder_get_frame_count - get hardware frame count of the given encoder
  401. * @encoder: Pointer to drm encoder object
  402. */
  403. u32 sde_encoder_get_frame_count(struct drm_encoder *encoder);
  404. /**
  405. * sde_encoder_get_avr_status - get combined avr_status from all intfs for given virt encoder
  406. * @drm_enc: Pointer to drm encoder structure
  407. */
  408. int sde_encoder_get_avr_status(struct drm_encoder *drm_enc);
  409. /*
  410. * sde_encoder_get_vblank_timestamp - get the last vsync timestamp
  411. * @encoder: Pointer to drm encoder object
  412. * @tvblank: vblank timestamp
  413. */
  414. bool sde_encoder_get_vblank_timestamp(struct drm_encoder *encoder,
  415. ktime_t *tvblank);
  416. /**
  417. * sde_encoder_idle_pc_enter - control enable/disable VSYNC_IN_EN & cache display status at ipc
  418. * @encoder: encoder pointer
  419. */
  420. void sde_encoder_idle_pc_enter(struct drm_encoder *encoder);
  421. /**
  422. * sde_encoder_virt_restore - restore the encoder configs
  423. * @encoder: encoder pointer
  424. */
  425. void sde_encoder_virt_restore(struct drm_encoder *encoder);
  426. /**
  427. * sde_encoder_is_dsc_merge - check if encoder is in DSC merge mode
  428. * @drm_enc: Pointer to drm encoder object
  429. * @Return: true if encoder is in DSC merge mode
  430. */
  431. bool sde_encoder_is_dsc_merge(struct drm_encoder *drm_enc);
  432. /**
  433. * sde_encoder_check_curr_mode - check if given mode is supported or not
  434. * @drm_enc: Pointer to drm encoder object
  435. * @mode: Mode to be checked
  436. * @Return: true if it is cmd mode
  437. */
  438. bool sde_encoder_check_curr_mode(struct drm_encoder *drm_enc, u32 mode);
  439. /**
  440. * sde_encoder_init - initialize virtual encoder object
  441. * @dev: Pointer to drm device structure
  442. * @disp_info: Pointer to display information structure
  443. * Returns: Pointer to newly created drm encoder
  444. */
  445. struct drm_encoder *sde_encoder_init(
  446. struct drm_device *dev,
  447. struct msm_display_info *disp_info);
  448. /**
  449. * sde_encoder_destroy - destroy previously initialized virtual encoder
  450. * @drm_enc: Pointer to previously created drm encoder structure
  451. */
  452. void sde_encoder_destroy(struct drm_encoder *drm_enc);
  453. /**
  454. * sde_encoder_prepare_commit - prepare encoder at the very beginning of an
  455. * atomic commit, before any registers are written
  456. * @drm_enc: Pointer to previously created drm encoder structure
  457. */
  458. int sde_encoder_prepare_commit(struct drm_encoder *drm_enc);
  459. /**
  460. * sde_encoder_update_caps_for_cont_splash - update encoder settings during
  461. * device bootup when cont_splash is enabled
  462. * @drm_enc: Pointer to drm encoder structure
  463. * @splash_display: Pointer to sde_splash_display corresponding to this encoder
  464. * @enable: boolean indicates enable or displae state of splash
  465. * @Return: true if successful in updating the encoder structure
  466. */
  467. int sde_encoder_update_caps_for_cont_splash(struct drm_encoder *encoder,
  468. struct sde_splash_display *splash_display, bool enable);
  469. /**
  470. * sde_encoder_display_failure_notification - update sde encoder state for
  471. * esd timeout or other display failure notification. This event flows from
  472. * dsi, sde_connector to sde_encoder.
  473. *
  474. * This api must not be called from crtc_commit (display) thread because it
  475. * requests the flush work on same thread. It is called from esd check thread
  476. * based on current design.
  477. *
  478. * TODO: manage the event at sde_kms level for forward processing.
  479. * @drm_enc: Pointer to drm encoder structure
  480. * @skip_pre_kickoff: Caller can avoid pre_kickoff if it is triggering this
  481. * event only to switch the panel TE to watchdog mode.
  482. * @Return: true if successful in updating the encoder structure
  483. */
  484. int sde_encoder_display_failure_notification(struct drm_encoder *enc,
  485. bool skip_pre_kickoff);
  486. /**
  487. * sde_encoder_recovery_events_enabled - checks if client has enabled
  488. * sw recovery mechanism for this connector
  489. * @drm_enc: Pointer to drm encoder structure
  490. * @Return: true if enabled
  491. */
  492. bool sde_encoder_recovery_events_enabled(struct drm_encoder *encoder);
  493. /**
  494. * sde_encoder_enable_recovery_event - handler to enable the sw recovery
  495. * for this connector
  496. * @drm_enc: Pointer to drm encoder structure
  497. */
  498. void sde_encoder_enable_recovery_event(struct drm_encoder *encoder);
  499. /**
  500. * sde_encoder_in_clone_mode - checks if underlying phys encoder is in clone
  501. * mode or independent display mode. ref@ WB in Concurrent writeback mode.
  502. * @drm_enc: Pointer to drm encoder structure
  503. * @Return: true if successful in updating the encoder structure
  504. */
  505. bool sde_encoder_in_clone_mode(struct drm_encoder *enc);
  506. /**
  507. * sde_encoder_set_clone_mode - cwb in wb phys enc is enabled.
  508. * drm_enc: Pointer to drm encoder structure
  509. * drm_crtc_state: Pointer to drm_crtc_state
  510. */
  511. void sde_encoder_set_clone_mode(struct drm_encoder *drm_enc,
  512. struct drm_crtc_state *crtc_state);
  513. /*
  514. * sde_encoder_is_cwb_disabling - check if cwb encoder disable is pending
  515. * @drm_enc: Pointer to drm encoder structure
  516. * @drm_crtc: Pointer to drm crtc structure
  517. * @Return: true if cwb encoder disable is pending
  518. */
  519. bool sde_encoder_is_cwb_disabling(struct drm_encoder *drm_enc,
  520. struct drm_crtc *drm_crtc);
  521. /**
  522. * sde_encoder_is_primary_display - checks if underlying display is primary
  523. * display or not.
  524. * @drm_enc: Pointer to drm encoder structure
  525. * @Return: true if it is primary display. false otherwise
  526. */
  527. bool sde_encoder_is_primary_display(struct drm_encoder *enc);
  528. /**
  529. * sde_encoder_is_built_in_display - checks if underlying display is built in
  530. * display or not.
  531. * @drm_enc: Pointer to drm encoder structure
  532. * @Return: true if it is a built in display. false otherwise
  533. */
  534. bool sde_encoder_is_built_in_display(struct drm_encoder *enc);
  535. /**
  536. * sde_encoder_check_ctl_done_support - checks if ctl_done irq is available
  537. * for the display
  538. * @drm_enc: Pointer to drm encoder structure
  539. * @Return: true if scheduler update is enabled
  540. */
  541. static inline bool sde_encoder_check_ctl_done_support(struct drm_encoder *drm_enc)
  542. {
  543. struct sde_encoder_virt *sde_enc = to_sde_encoder_virt(drm_enc);
  544. return sde_enc && sde_enc->ctl_done_supported;
  545. }
  546. /**
  547. * sde_encoder_is_dsi_display - checks if underlying display is DSI
  548. * display or not.
  549. * @drm_enc: Pointer to drm encoder structure
  550. * @Return: true if it is a dsi display. false otherwise
  551. */
  552. bool sde_encoder_is_dsi_display(struct drm_encoder *enc);
  553. /**
  554. * sde_encoder_control_idle_pc - control enable/disable of idle power collapse
  555. * @drm_enc: Pointer to drm encoder structure
  556. * @enable: enable/disable flag
  557. */
  558. void sde_encoder_control_idle_pc(struct drm_encoder *enc, bool enable);
  559. /**
  560. * sde_encoder_in_cont_splash - checks if display is in continuous splash
  561. * @drm_enc: Pointer to drm encoder structure
  562. * @Return: true if display in continuous splash
  563. */
  564. int sde_encoder_in_cont_splash(struct drm_encoder *enc);
  565. /**
  566. * sde_encoder_helper_hw_reset - hw reset helper function
  567. * @drm_enc: Pointer to drm encoder structure
  568. */
  569. void sde_encoder_needs_hw_reset(struct drm_encoder *enc);
  570. /**
  571. * sde_encoder_uidle_enable - control enable/disable of uidle
  572. * @drm_enc: Pointer to drm encoder structure
  573. * @enable: enable/disable flag
  574. */
  575. void sde_encoder_uidle_enable(struct drm_encoder *drm_enc, bool enable);
  576. /**
  577. * sde_encoder_irq_control - control enable/disable of IRQ's
  578. * @drm_enc: Pointer to drm encoder structure
  579. * @enable: enable/disable flag
  580. */
  581. void sde_encoder_irq_control(struct drm_encoder *drm_enc, bool enable);
  582. /**sde_encoder_get_connector - get connector corresponding to encoder
  583. * @dev: Pointer to drm device structure
  584. * @drm_enc: Pointer to drm encoder structure
  585. * Returns: drm connector if found, null if not found
  586. */
  587. struct drm_connector *sde_encoder_get_connector(struct drm_device *dev,
  588. struct drm_encoder *drm_enc);
  589. /**sde_encoder_needs_dsc_disable - indicates if dsc should be disabled
  590. * based on previous topology
  591. * @drm_enc: Pointer to drm encoder structure
  592. */
  593. bool sde_encoder_needs_dsc_disable(struct drm_encoder *drm_enc);
  594. /**
  595. * sde_encoder_get_transfer_time - get the mdp transfer time in usecs
  596. * @drm_enc: Pointer to drm encoder structure
  597. * @transfer_time_us: Pointer to store the output value
  598. */
  599. void sde_encoder_get_transfer_time(struct drm_encoder *drm_enc,
  600. u32 *transfer_time_us);
  601. /**
  602. * sde_encoder_helper_update_out_fence_txq - updates hw-fence tx queue
  603. * @sde_enc: Pointer to sde encoder structure
  604. * @is_vid: Boolean to indicate if is video-mode
  605. */
  606. void sde_encoder_helper_update_out_fence_txq(struct sde_encoder_virt *sde_enc, bool is_vid);
  607. /*
  608. * sde_encoder_get_dfps_maxfps - get dynamic FPS max frame rate of
  609. the given encoder
  610. * @encoder: Pointer to drm encoder object
  611. */
  612. static inline u32 sde_encoder_get_dfps_maxfps(struct drm_encoder *drm_enc)
  613. {
  614. struct sde_encoder_virt *sde_enc;
  615. if (!drm_enc) {
  616. SDE_ERROR("invalid encoder\n");
  617. return 0;
  618. }
  619. sde_enc = to_sde_encoder_virt(drm_enc);
  620. return sde_enc->mode_info.dfps_maxfps;
  621. }
  622. /**
  623. * sde_encoder_virt_reset - delay encoder virt reset
  624. * @drm_enc: Pointer to drm encoder structure
  625. */
  626. void sde_encoder_virt_reset(struct drm_encoder *drm_enc);
  627. /**
  628. * sde_encoder_calc_last_vsync_timestamp - read last HW vsync timestamp counter
  629. * and calculate the corresponding vsync ktime. Return ktime_get
  630. * when HW support is not available
  631. * @drm_enc: Pointer to drm encoder structure
  632. */
  633. ktime_t sde_encoder_calc_last_vsync_timestamp(struct drm_encoder *drm_enc);
  634. /**
  635. * sde_encoder_cancel_delayed_work - cancel delayed off work for encoder
  636. * @drm_enc: Pointer to drm encoder structure
  637. */
  638. void sde_encoder_cancel_delayed_work(struct drm_encoder *encoder);
  639. /**
  640. * sde_encoder_get_kms - retrieve the kms from encoder
  641. * @drm_enc: Pointer to drm encoder structure
  642. */
  643. static inline struct sde_kms *sde_encoder_get_kms(struct drm_encoder *drm_enc)
  644. {
  645. struct msm_drm_private *priv;
  646. if (!drm_enc || !drm_enc->dev) {
  647. SDE_ERROR("invalid encoder\n");
  648. return NULL;
  649. }
  650. priv = drm_enc->dev->dev_private;
  651. if (!priv || !priv->kms) {
  652. SDE_ERROR("invalid kms\n");
  653. return NULL;
  654. }
  655. return to_sde_kms(priv->kms);
  656. }
  657. /*
  658. * sde_encoder_is_widebus_enabled - check if widebus is enabled for current mode
  659. * @drm_enc: Pointer to drm encoder structure
  660. * @Return: true if widebus is enabled for current mode
  661. */
  662. static inline bool sde_encoder_is_widebus_enabled(struct drm_encoder *drm_enc)
  663. {
  664. struct sde_encoder_virt *sde_enc;
  665. if (!drm_enc)
  666. return false;
  667. sde_enc = to_sde_encoder_virt(drm_enc);
  668. return sde_enc->mode_info.wide_bus_en;
  669. }
  670. /*
  671. * sde_encoder_is_line_insertion_supported - get line insertion
  672. * feature bit value from panel
  673. * @drm_enc: Pointer to drm encoder structure
  674. * @Return: line insertion support status
  675. */
  676. bool sde_encoder_is_line_insertion_supported(struct drm_encoder *drm_enc);
  677. /**
  678. * sde_encoder_get_hw_ctl - gets hw ctl from the connector
  679. * @c_conn: sde connector
  680. * @Return: pointer to the hw ctl from the encoder upon success, otherwise null
  681. */
  682. struct sde_hw_ctl *sde_encoder_get_hw_ctl(struct sde_connector *c_conn);
  683. /*
  684. * sde_encoder_get_programmed_fetch_time - gets the programmable fetch time for video encoders
  685. * @drm_enc: Pointer to drm encoder structure
  686. * @Return: programmable fetch time in microseconds
  687. */
  688. u32 sde_encoder_get_programmed_fetch_time(struct drm_encoder *encoder);
  689. void sde_encoder_add_data_to_minidump_va(struct drm_encoder *drm_enc);
  690. /**
  691. * sde_encoder_misr_sign_event_notify - collect MISR, check with previous value
  692. * if change then notify to client with custom event
  693. * @drm_enc: pointer to drm encoder
  694. */
  695. void sde_encoder_misr_sign_event_notify(struct drm_encoder *drm_enc);
  696. /**
  697. * sde_encoder_handle_dma_fence_out_of_order - sw dma fence out of order signal
  698. * @drm_enc: pointer to drm encoder
  699. */
  700. int sde_encoder_handle_dma_fence_out_of_order(struct drm_encoder *drm_enc);
  701. /**
  702. * sde_encoder_register_misr_event - register or deregister MISR event
  703. * @drm_enc: pointer to drm encoder
  704. * @val: indicates register or deregister
  705. */
  706. static inline int sde_encoder_register_misr_event(struct drm_encoder *drm_enc, bool val)
  707. {
  708. struct sde_encoder_virt *sde_enc = NULL;
  709. if (!drm_enc)
  710. return -EINVAL;
  711. sde_enc = to_sde_encoder_virt(drm_enc);
  712. atomic_set(&sde_enc->misr_enable, val);
  713. /*
  714. * To setup MISR ctl reg, set misr_reconfigure as true.
  715. * MISR is calculated for the specific number of frames.
  716. */
  717. if (atomic_read(&sde_enc->misr_enable)) {
  718. sde_enc->misr_reconfigure = true;
  719. sde_enc->misr_frame_count = 1;
  720. }
  721. return 0;
  722. }
  723. #endif /* __SDE_ENCODER_H__ */