xref: /linux/drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.h (revision 24168c5e6dfbdd5b414f048f47f75d64533296ca)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
4  * Copyright (c) 2015-2018, The Linux Foundation. All rights reserved.
5  * Copyright (C) 2013 Red Hat
6  * Author: Rob Clark <robdclark@gmail.com>
7  */
8 
9 #ifndef __DPU_ENCODER_H__
10 #define __DPU_ENCODER_H__
11 
12 #include <drm/drm_crtc.h>
13 #include "dpu_hw_mdss.h"
14 
15 #define DPU_ENCODER_FRAME_EVENT_DONE			BIT(0)
16 #define DPU_ENCODER_FRAME_EVENT_ERROR			BIT(1)
17 #define DPU_ENCODER_FRAME_EVENT_PANEL_DEAD		BIT(2)
18 #define DPU_ENCODER_FRAME_EVENT_IDLE			BIT(3)
19 
20 #define IDLE_TIMEOUT	(66 - 16/2)
21 
22 /**
23  * struct msm_display_info - defines display properties
24  * @intf_type:          INTF_ type
25  * @num_of_h_tiles:     Number of horizontal tiles in case of split interface
26  * @h_tile_instance:    Controller instance used per tile. Number of elements is
27  *                      based on num_of_h_tiles
28  * @is_cmd_mode		Boolean to indicate if the CMD mode is requested
29  * @is_te_using_watchdog_timer:  Boolean to indicate watchdog TE is
30  *				 used instead of panel TE in cmd mode panels
31  */
32 struct msm_display_info {
33 	enum dpu_intf_type intf_type;
34 	uint32_t num_of_h_tiles;
35 	uint32_t h_tile_instance[MAX_H_TILES_PER_DISPLAY];
36 	bool is_cmd_mode;
37 	bool is_te_using_watchdog_timer;
38 };
39 
40 /**
41  * dpu_encoder_assign_crtc - Link the encoder to the crtc it's assigned to
42  * @encoder:	encoder pointer
43  * @crtc:	crtc pointer
44  */
45 void dpu_encoder_assign_crtc(struct drm_encoder *encoder,
46 			     struct drm_crtc *crtc);
47 
48 /**
49  * dpu_encoder_toggle_vblank_for_crtc - Toggles vblank interrupts on or off if
50  *	the encoder is assigned to the given crtc
51  * @encoder:	encoder pointer
52  * @crtc:	crtc pointer
53  * @enable:	true if vblank should be enabled
54  */
55 void dpu_encoder_toggle_vblank_for_crtc(struct drm_encoder *encoder,
56 					struct drm_crtc *crtc, bool enable);
57 
58 /**
59  * dpu_encoder_register_frame_event_callback - provide callback to encoder that
60  *	will be called after the request is complete, or other events.
61  * @encoder:	encoder pointer
62  * @cb:		callback pointer, provide NULL to deregister
63  * @data:	user data provided to callback
64  */
65 void dpu_encoder_register_frame_event_callback(struct drm_encoder *encoder,
66 		void (*cb)(void *, u32), void *data);
67 
68 /**
69  * dpu_encoder_prepare_for_kickoff - schedule double buffer flip of the ctl
70  *	path (i.e. ctl flush and start) at next appropriate time.
71  *	Immediately: if no previous commit is outstanding.
72  *	Delayed: Block until next trigger can be issued.
73  * @encoder:	encoder pointer
74  */
75 void dpu_encoder_prepare_for_kickoff(struct drm_encoder *encoder);
76 
77 /**
78  * dpu_encoder_trigger_kickoff_pending - Clear the flush bits from previous
79  *        kickoff and trigger the ctl prepare progress for command mode display.
80  * @encoder:	encoder pointer
81  */
82 void dpu_encoder_trigger_kickoff_pending(struct drm_encoder *encoder);
83 
84 /**
85  * dpu_encoder_kickoff - trigger a double buffer flip of the ctl path
86  *	(i.e. ctl flush and start) immediately.
87  * @encoder:	encoder pointer
88  */
89 void dpu_encoder_kickoff(struct drm_encoder *encoder);
90 
91 /**
92  * dpu_encoder_wakeup_time - get the time of the next vsync
93  */
94 int dpu_encoder_vsync_time(struct drm_encoder *drm_enc, ktime_t *wakeup_time);
95 
96 int dpu_encoder_wait_for_commit_done(struct drm_encoder *drm_encoder);
97 
98 int dpu_encoder_wait_for_tx_complete(struct drm_encoder *drm_encoder);
99 
100 /*
101  * dpu_encoder_get_intf_mode - get interface mode of the given encoder
102  * @encoder: Pointer to drm encoder object
103  */
104 enum dpu_intf_mode dpu_encoder_get_intf_mode(struct drm_encoder *encoder);
105 
106 /**
107  * dpu_encoder_virt_runtime_resume - pm runtime resume the encoder configs
108  * @encoder:	encoder pointer
109  */
110 void dpu_encoder_virt_runtime_resume(struct drm_encoder *encoder);
111 
112 /**
113  * dpu_encoder_init - initialize virtual encoder object
114  * @dev:        Pointer to drm device structure
115  * @drm_enc_mode: corresponding DRM_MODE_ENCODER_* constant
116  * @disp_info:  Pointer to display information structure
117  * Returns:     Pointer to newly created drm encoder
118  */
119 struct drm_encoder *dpu_encoder_init(struct drm_device *dev,
120 		int drm_enc_mode,
121 		struct msm_display_info *disp_info);
122 
123 /**
124  * dpu_encoder_set_idle_timeout - set the idle timeout for video
125  *                    and command mode encoders.
126  * @drm_enc:    Pointer to previously created drm encoder structure
127  * @idle_timeout:    idle timeout duration in milliseconds
128  */
129 void dpu_encoder_set_idle_timeout(struct drm_encoder *drm_enc,
130 							u32 idle_timeout);
131 /**
132  * dpu_encoder_get_linecount - get interface line count for the encoder.
133  * @drm_enc:    Pointer to previously created drm encoder structure
134  */
135 int dpu_encoder_get_linecount(struct drm_encoder *drm_enc);
136 
137 /**
138  * dpu_encoder_get_vsync_count - get vsync count for the encoder.
139  * @drm_enc:    Pointer to previously created drm encoder structure
140  */
141 int dpu_encoder_get_vsync_count(struct drm_encoder *drm_enc);
142 
143 /**
144  * dpu_encoder_is_widebus_enabled - return bool value if widebus is enabled
145  * @drm_enc:    Pointer to previously created drm encoder structure
146  */
147 bool dpu_encoder_is_widebus_enabled(const struct drm_encoder *drm_enc);
148 
149 /**
150  * dpu_encoder_is_dsc_enabled - indicate whether dsc is enabled
151  *				for the encoder.
152  * @drm_enc:    Pointer to previously created drm encoder structure
153  */
154 bool dpu_encoder_is_dsc_enabled(const struct drm_encoder *drm_enc);
155 
156 /**
157  * dpu_encoder_get_crc_values_cnt - get number of physical encoders contained
158  *	in virtual encoder that can collect CRC values
159  * @drm_enc:    Pointer to previously created drm encoder structure
160  * Returns:     Number of physical encoders for given drm encoder
161  */
162 int dpu_encoder_get_crc_values_cnt(const struct drm_encoder *drm_enc);
163 
164 /**
165  * dpu_encoder_setup_misr - enable misr calculations
166  * @drm_enc:    Pointer to previously created drm encoder structure
167  */
168 void dpu_encoder_setup_misr(const struct drm_encoder *drm_encoder);
169 
170 /**
171  * dpu_encoder_get_crc - get the crc value from interface blocks
172  * @drm_enc:    Pointer to previously created drm encoder structure
173  * Returns:     0 on success, error otherwise
174  */
175 int dpu_encoder_get_crc(const struct drm_encoder *drm_enc, u32 *crcs, int pos);
176 
177 /**
178  * dpu_encoder_use_dsc_merge - returns true if the encoder uses DSC merge topology.
179  * @drm_enc:    Pointer to previously created drm encoder structure
180  */
181 bool dpu_encoder_use_dsc_merge(struct drm_encoder *drm_enc);
182 
183 /**
184  * dpu_encoder_prepare_wb_job - prepare writeback job for the encoder.
185  * @drm_enc:    Pointer to previously created drm encoder structure
186  * @job:        Pointer to the current drm writeback job
187  */
188 void dpu_encoder_prepare_wb_job(struct drm_encoder *drm_enc,
189 		struct drm_writeback_job *job);
190 
191 /**
192  * dpu_encoder_cleanup_wb_job - cleanup writeback job for the encoder.
193  * @drm_enc:    Pointer to previously created drm encoder structure
194  * @job:        Pointer to the current drm writeback job
195  */
196 void dpu_encoder_cleanup_wb_job(struct drm_encoder *drm_enc,
197 		struct drm_writeback_job *job);
198 
199 /**
200  * dpu_encoder_is_valid_for_commit - check if encode has valid parameters for commit.
201  * @drm_enc:    Pointer to drm encoder structure
202  */
203 bool dpu_encoder_is_valid_for_commit(struct drm_encoder *drm_enc);
204 
205 #endif /* __DPU_ENCODER_H__ */
206