1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (c) 2015-2018, The Linux Foundation. All rights reserved.
4  * Copyright (C) 2013 Red Hat
5  * Author: Rob Clark <robdclark@gmail.com>
6  */
7 
8 #ifndef __DPU_ENCODER_H__
9 #define __DPU_ENCODER_H__
10 
11 #include <drm/drm_crtc.h>
12 #include "dpu_hw_mdss.h"
13 
14 #define DPU_ENCODER_FRAME_EVENT_DONE			BIT(0)
15 #define DPU_ENCODER_FRAME_EVENT_ERROR			BIT(1)
16 #define DPU_ENCODER_FRAME_EVENT_PANEL_DEAD		BIT(2)
17 #define DPU_ENCODER_FRAME_EVENT_IDLE			BIT(3)
18 
19 #define IDLE_TIMEOUT	(66 - 16/2)
20 
21 /**
22  * struct msm_display_info - defines display properties
23  * @intf_type:          DRM_MODE_ENCODER_ type
24  * @capabilities:       Bitmask of display flags
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_te_using_watchdog_timer:  Boolean to indicate watchdog TE is
29  *				 used instead of panel TE in cmd mode panels
30  */
31 struct msm_display_info {
32 	int intf_type;
33 	uint32_t capabilities;
34 	uint32_t num_of_h_tiles;
35 	uint32_t h_tile_instance[MAX_H_TILES_PER_DISPLAY];
36 	bool is_te_using_watchdog_timer;
37 };
38 
39 /**
40  * dpu_encoder_assign_crtc - Link the encoder to the crtc it's assigned to
41  * @encoder:	encoder pointer
42  * @crtc:	crtc pointer
43  */
44 void dpu_encoder_assign_crtc(struct drm_encoder *encoder,
45 			     struct drm_crtc *crtc);
46 
47 /**
48  * dpu_encoder_toggle_vblank_for_crtc - Toggles vblank interrupts on or off if
49  *	the encoder is assigned to the given crtc
50  * @encoder:	encoder pointer
51  * @crtc:	crtc pointer
52  * @enable:	true if vblank should be enabled
53  */
54 void dpu_encoder_toggle_vblank_for_crtc(struct drm_encoder *encoder,
55 					struct drm_crtc *crtc, bool enable);
56 
57 /**
58  * dpu_encoder_register_frame_event_callback - provide callback to encoder that
59  *	will be called after the request is complete, or other events.
60  * @encoder:	encoder pointer
61  * @cb:		callback pointer, provide NULL to deregister
62  * @data:	user data provided to callback
63  */
64 void dpu_encoder_register_frame_event_callback(struct drm_encoder *encoder,
65 		void (*cb)(void *, u32), void *data);
66 
67 /**
68  * dpu_encoder_prepare_for_kickoff - schedule double buffer flip of the ctl
69  *	path (i.e. ctl flush and start) at next appropriate time.
70  *	Immediately: if no previous commit is outstanding.
71  *	Delayed: Block until next trigger can be issued.
72  * @encoder:	encoder pointer
73  */
74 void dpu_encoder_prepare_for_kickoff(struct drm_encoder *encoder);
75 
76 /**
77  * dpu_encoder_trigger_kickoff_pending - Clear the flush bits from previous
78  *        kickoff and trigger the ctl prepare progress for command mode display.
79  * @encoder:	encoder pointer
80  */
81 void dpu_encoder_trigger_kickoff_pending(struct drm_encoder *encoder);
82 
83 /**
84  * dpu_encoder_kickoff - trigger a double buffer flip of the ctl path
85  *	(i.e. ctl flush and start) immediately.
86  * @encoder:	encoder pointer
87  */
88 void dpu_encoder_kickoff(struct drm_encoder *encoder);
89 
90 /**
91  * dpu_encoder_wakeup_time - get the time of the next vsync
92  */
93 int dpu_encoder_vsync_time(struct drm_encoder *drm_enc, ktime_t *wakeup_time);
94 
95 /**
96  * dpu_encoder_wait_for_event - Waits for encoder events
97  * @encoder:	encoder pointer
98  * @event:      event to wait for
99  * MSM_ENC_COMMIT_DONE -  Wait for hardware to have flushed the current pending
100  *                        frames to hardware at a vblank or ctl_start
101  *                        Encoders will map this differently depending on the
102  *                        panel type.
103  *	                  vid mode -> vsync_irq
104  *                        cmd mode -> ctl_start
105  * MSM_ENC_TX_COMPLETE -  Wait for the hardware to transfer all the pixels to
106  *                        the panel. Encoders will map this differently
107  *                        depending on the panel type.
108  *                        vid mode -> vsync_irq
109  *                        cmd mode -> pp_done
110  * Returns: 0 on success, -EWOULDBLOCK if already signaled, error otherwise
111  */
112 int dpu_encoder_wait_for_event(struct drm_encoder *drm_encoder,
113 						enum msm_event_wait event);
114 
115 /*
116  * dpu_encoder_get_intf_mode - get interface mode of the given encoder
117  * @encoder: Pointer to drm encoder object
118  */
119 enum dpu_intf_mode dpu_encoder_get_intf_mode(struct drm_encoder *encoder);
120 
121 /**
122  * dpu_encoder_virt_runtime_resume - pm runtime resume the encoder configs
123  * @encoder:	encoder pointer
124  */
125 void dpu_encoder_virt_runtime_resume(struct drm_encoder *encoder);
126 
127 /**
128  * dpu_encoder_init - initialize virtual encoder object
129  * @dev:        Pointer to drm device structure
130  * @disp_info:  Pointer to display information structure
131  * Returns:     Pointer to newly created drm encoder
132  */
133 struct drm_encoder *dpu_encoder_init(
134 		struct drm_device *dev,
135 		int drm_enc_mode);
136 
137 /**
138  * dpu_encoder_setup - setup dpu_encoder for the display probed
139  * @dev:		Pointer to drm device structure
140  * @enc:		Pointer to the drm_encoder
141  * @disp_info:	Pointer to the display info
142  */
143 int dpu_encoder_setup(struct drm_device *dev, struct drm_encoder *enc,
144 		struct msm_display_info *disp_info);
145 
146 /**
147  * dpu_encoder_prepare_commit - prepare encoder at the very beginning of an
148  *	atomic commit, before any registers are written
149  * @drm_enc:    Pointer to previously created drm encoder structure
150  */
151 void dpu_encoder_prepare_commit(struct drm_encoder *drm_enc);
152 
153 /**
154  * dpu_encoder_set_idle_timeout - set the idle timeout for video
155  *                    and command mode encoders.
156  * @drm_enc:    Pointer to previously created drm encoder structure
157  * @idle_timeout:    idle timeout duration in milliseconds
158  */
159 void dpu_encoder_set_idle_timeout(struct drm_encoder *drm_enc,
160 							u32 idle_timeout);
161 /**
162  * dpu_encoder_get_linecount - get interface line count for the encoder.
163  * @drm_enc:    Pointer to previously created drm encoder structure
164  */
165 int dpu_encoder_get_linecount(struct drm_encoder *drm_enc);
166 
167 /**
168  * dpu_encoder_get_vsync_count - get vsync count for the encoder.
169  * @drm_enc:    Pointer to previously created drm encoder structure
170  */
171 int dpu_encoder_get_vsync_count(struct drm_encoder *drm_enc);
172 
173 #endif /* __DPU_ENCODER_H__ */
174