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 bool dpu_encoder_is_widebus_enabled(const struct drm_encoder *drm_enc);
144 
145 /**
146  * dpu_encoder_is_dsc_enabled - indicate whether dsc is enabled
147  *				for the encoder.
148  * @drm_enc:    Pointer to previously created drm encoder structure
149  */
150 bool dpu_encoder_is_dsc_enabled(const struct drm_encoder *drm_enc);
151 
152 /**
153  * dpu_encoder_get_crc_values_cnt - get number of physical encoders contained
154  *	in virtual encoder that can collect CRC values
155  * @drm_enc:    Pointer to previously created drm encoder structure
156  * Returns:     Number of physical encoders for given drm encoder
157  */
158 int dpu_encoder_get_crc_values_cnt(const struct drm_encoder *drm_enc);
159 
160 /**
161  * dpu_encoder_setup_misr - enable misr calculations
162  * @drm_enc:    Pointer to previously created drm encoder structure
163  */
164 void dpu_encoder_setup_misr(const struct drm_encoder *drm_encoder);
165 
166 /**
167  * dpu_encoder_get_crc - get the crc value from interface blocks
168  * @drm_enc:    Pointer to previously created drm encoder structure
169  * Returns:     0 on success, error otherwise
170  */
171 int dpu_encoder_get_crc(const struct drm_encoder *drm_enc, u32 *crcs, int pos);
172 
173 /**
174  * dpu_encoder_use_dsc_merge - returns true if the encoder uses DSC merge topology.
175  * @drm_enc:    Pointer to previously created drm encoder structure
176  */
177 bool dpu_encoder_use_dsc_merge(struct drm_encoder *drm_enc);
178 
179 /**
180  * dpu_encoder_prepare_wb_job - prepare writeback job for the encoder.
181  * @drm_enc:    Pointer to previously created drm encoder structure
182  * @job:        Pointer to the current drm writeback job
183  */
184 void dpu_encoder_prepare_wb_job(struct drm_encoder *drm_enc,
185 		struct drm_writeback_job *job);
186 
187 /**
188  * dpu_encoder_cleanup_wb_job - cleanup writeback job for the encoder.
189  * @drm_enc:    Pointer to previously created drm encoder structure
190  * @job:        Pointer to the current drm writeback job
191  */
192 void dpu_encoder_cleanup_wb_job(struct drm_encoder *drm_enc,
193 		struct drm_writeback_job *job);
194 
195 /**
196  * dpu_encoder_is_valid_for_commit - check if encode has valid parameters for commit.
197  * @drm_enc:    Pointer to drm encoder structure
198  */
199 bool dpu_encoder_is_valid_for_commit(struct drm_encoder *drm_enc);
200 
201 #endif /* __DPU_ENCODER_H__ */
202