xref: /openbmc/linux/drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.h (revision 26d0dfbb16fcb17d128a79dc70f3020ea6992af0)
1caab277bSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
225fdd593SJeykumar Sankaran /*
3b1665047SJessica Zhang  * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
425fdd593SJeykumar Sankaran  * Copyright (c) 2015-2018, The Linux Foundation. All rights reserved.
525fdd593SJeykumar Sankaran  * Copyright (C) 2013 Red Hat
625fdd593SJeykumar Sankaran  * Author: Rob Clark <robdclark@gmail.com>
725fdd593SJeykumar Sankaran  */
825fdd593SJeykumar Sankaran 
925fdd593SJeykumar Sankaran #ifndef __DPU_ENCODER_H__
1025fdd593SJeykumar Sankaran #define __DPU_ENCODER_H__
1125fdd593SJeykumar Sankaran 
1225fdd593SJeykumar Sankaran #include <drm/drm_crtc.h>
1325fdd593SJeykumar Sankaran #include "dpu_hw_mdss.h"
1425fdd593SJeykumar Sankaran 
1525fdd593SJeykumar Sankaran #define DPU_ENCODER_FRAME_EVENT_DONE			BIT(0)
1625fdd593SJeykumar Sankaran #define DPU_ENCODER_FRAME_EVENT_ERROR			BIT(1)
1725fdd593SJeykumar Sankaran #define DPU_ENCODER_FRAME_EVENT_PANEL_DEAD		BIT(2)
1825fdd593SJeykumar Sankaran #define DPU_ENCODER_FRAME_EVENT_IDLE			BIT(3)
1925fdd593SJeykumar Sankaran 
2025fdd593SJeykumar Sankaran #define IDLE_TIMEOUT	(66 - 16/2)
2125fdd593SJeykumar Sankaran 
2225fdd593SJeykumar Sankaran /**
23b7420739SDmitry Baryshkov  * struct msm_display_info - defines display properties
245a7a86bfSDmitry Baryshkov  * @intf_type:          INTF_ type
25b7420739SDmitry Baryshkov  * @num_of_h_tiles:     Number of horizontal tiles in case of split interface
26b7420739SDmitry Baryshkov  * @h_tile_instance:    Controller instance used per tile. Number of elements is
27b7420739SDmitry Baryshkov  *                      based on num_of_h_tiles
28b6529e33SDmitry Baryshkov  * @is_cmd_mode		Boolean to indicate if the CMD mode is requested
29b7420739SDmitry Baryshkov  * @is_te_using_watchdog_timer:  Boolean to indicate watchdog TE is
30b7420739SDmitry Baryshkov  *				 used instead of panel TE in cmd mode panels
31b7420739SDmitry Baryshkov  */
32b7420739SDmitry Baryshkov struct msm_display_info {
335a7a86bfSDmitry Baryshkov 	enum dpu_intf_type intf_type;
34b7420739SDmitry Baryshkov 	uint32_t num_of_h_tiles;
35b7420739SDmitry Baryshkov 	uint32_t h_tile_instance[MAX_H_TILES_PER_DISPLAY];
36b6529e33SDmitry Baryshkov 	bool is_cmd_mode;
37b7420739SDmitry Baryshkov 	bool is_te_using_watchdog_timer;
38b7420739SDmitry Baryshkov };
39b7420739SDmitry Baryshkov 
40b7420739SDmitry Baryshkov /**
41e4914867SSean Paul  * dpu_encoder_assign_crtc - Link the encoder to the crtc it's assigned to
4225fdd593SJeykumar Sankaran  * @encoder:	encoder pointer
43e4914867SSean Paul  * @crtc:	crtc pointer
4425fdd593SJeykumar Sankaran  */
45e4914867SSean Paul void dpu_encoder_assign_crtc(struct drm_encoder *encoder,
46e4914867SSean Paul 			     struct drm_crtc *crtc);
4725fdd593SJeykumar Sankaran 
4825fdd593SJeykumar Sankaran /**
49a796ba2cSSean Paul  * dpu_encoder_toggle_vblank_for_crtc - Toggles vblank interrupts on or off if
50a796ba2cSSean Paul  *	the encoder is assigned to the given crtc
51a796ba2cSSean Paul  * @encoder:	encoder pointer
52a796ba2cSSean Paul  * @crtc:	crtc pointer
53a796ba2cSSean Paul  * @enable:	true if vblank should be enabled
54a796ba2cSSean Paul  */
55a796ba2cSSean Paul void dpu_encoder_toggle_vblank_for_crtc(struct drm_encoder *encoder,
56a796ba2cSSean Paul 					struct drm_crtc *crtc, bool enable);
57a796ba2cSSean Paul 
58a796ba2cSSean Paul /**
5925fdd593SJeykumar Sankaran  * dpu_encoder_register_frame_event_callback - provide callback to encoder that
6025fdd593SJeykumar Sankaran  *	will be called after the request is complete, or other events.
6125fdd593SJeykumar Sankaran  * @encoder:	encoder pointer
6225fdd593SJeykumar Sankaran  * @cb:		callback pointer, provide NULL to deregister
6325fdd593SJeykumar Sankaran  * @data:	user data provided to callback
6425fdd593SJeykumar Sankaran  */
6525fdd593SJeykumar Sankaran void dpu_encoder_register_frame_event_callback(struct drm_encoder *encoder,
6625fdd593SJeykumar Sankaran 		void (*cb)(void *, u32), void *data);
6725fdd593SJeykumar Sankaran 
6825fdd593SJeykumar Sankaran /**
6925fdd593SJeykumar Sankaran  * dpu_encoder_prepare_for_kickoff - schedule double buffer flip of the ctl
7025fdd593SJeykumar Sankaran  *	path (i.e. ctl flush and start) at next appropriate time.
7125fdd593SJeykumar Sankaran  *	Immediately: if no previous commit is outstanding.
7225fdd593SJeykumar Sankaran  *	Delayed: Block until next trigger can be issued.
7325fdd593SJeykumar Sankaran  * @encoder:	encoder pointer
7425fdd593SJeykumar Sankaran  */
750c91ed51SRob Clark void dpu_encoder_prepare_for_kickoff(struct drm_encoder *encoder);
7625fdd593SJeykumar Sankaran 
7725fdd593SJeykumar Sankaran /**
7825fdd593SJeykumar Sankaran  * dpu_encoder_trigger_kickoff_pending - Clear the flush bits from previous
7925fdd593SJeykumar Sankaran  *        kickoff and trigger the ctl prepare progress for command mode display.
8025fdd593SJeykumar Sankaran  * @encoder:	encoder pointer
8125fdd593SJeykumar Sankaran  */
8225fdd593SJeykumar Sankaran void dpu_encoder_trigger_kickoff_pending(struct drm_encoder *encoder);
8325fdd593SJeykumar Sankaran 
8425fdd593SJeykumar Sankaran /**
8525fdd593SJeykumar Sankaran  * dpu_encoder_kickoff - trigger a double buffer flip of the ctl path
8625fdd593SJeykumar Sankaran  *	(i.e. ctl flush and start) immediately.
8725fdd593SJeykumar Sankaran  * @encoder:	encoder pointer
8825fdd593SJeykumar Sankaran  */
89b4bb9f15SRob Clark void dpu_encoder_kickoff(struct drm_encoder *encoder);
9025fdd593SJeykumar Sankaran 
9125fdd593SJeykumar Sankaran /**
92cd6d9231SRob Clark  * dpu_encoder_wakeup_time - get the time of the next vsync
93cd6d9231SRob Clark  */
94cd6d9231SRob Clark int dpu_encoder_vsync_time(struct drm_encoder *drm_enc, ktime_t *wakeup_time);
95cd6d9231SRob Clark 
96*801f49c8SDmitry Baryshkov int dpu_encoder_wait_for_commit_done(struct drm_encoder *drm_encoder);
97*801f49c8SDmitry Baryshkov 
98*801f49c8SDmitry Baryshkov int dpu_encoder_wait_for_tx_complete(struct drm_encoder *drm_encoder);
9925fdd593SJeykumar Sankaran 
10025fdd593SJeykumar Sankaran /*
10125fdd593SJeykumar Sankaran  * dpu_encoder_get_intf_mode - get interface mode of the given encoder
10225fdd593SJeykumar Sankaran  * @encoder: Pointer to drm encoder object
10325fdd593SJeykumar Sankaran  */
10425fdd593SJeykumar Sankaran enum dpu_intf_mode dpu_encoder_get_intf_mode(struct drm_encoder *encoder);
10525fdd593SJeykumar Sankaran 
10625fdd593SJeykumar Sankaran /**
10718a63b3cSSean Paul  * dpu_encoder_virt_runtime_resume - pm runtime resume the encoder configs
10825fdd593SJeykumar Sankaran  * @encoder:	encoder pointer
10925fdd593SJeykumar Sankaran  */
11018a63b3cSSean Paul void dpu_encoder_virt_runtime_resume(struct drm_encoder *encoder);
11125fdd593SJeykumar Sankaran 
11225fdd593SJeykumar Sankaran /**
11325fdd593SJeykumar Sankaran  * dpu_encoder_init - initialize virtual encoder object
11425fdd593SJeykumar Sankaran  * @dev:        Pointer to drm device structure
1159b930f14SDmitry Baryshkov  * @drm_enc_mode: corresponding DRM_MODE_ENCODER_* constant
11625fdd593SJeykumar Sankaran  * @disp_info:  Pointer to display information structure
11725fdd593SJeykumar Sankaran  * Returns:     Pointer to newly created drm encoder
11825fdd593SJeykumar Sankaran  */
1199b930f14SDmitry Baryshkov struct drm_encoder *dpu_encoder_init(struct drm_device *dev,
1209b930f14SDmitry Baryshkov 		int drm_enc_mode,
12125fdd593SJeykumar Sankaran 		struct msm_display_info *disp_info);
12225fdd593SJeykumar Sankaran 
12325fdd593SJeykumar Sankaran /**
12425fdd593SJeykumar Sankaran  * dpu_encoder_set_idle_timeout - set the idle timeout for video
12525fdd593SJeykumar Sankaran  *                    and command mode encoders.
12625fdd593SJeykumar Sankaran  * @drm_enc:    Pointer to previously created drm encoder structure
12725fdd593SJeykumar Sankaran  * @idle_timeout:    idle timeout duration in milliseconds
12825fdd593SJeykumar Sankaran  */
12925fdd593SJeykumar Sankaran void dpu_encoder_set_idle_timeout(struct drm_encoder *drm_enc,
13025fdd593SJeykumar Sankaran 							u32 idle_timeout);
13173743e72SKalyan Thota /**
13273743e72SKalyan Thota  * dpu_encoder_get_linecount - get interface line count for the encoder.
13373743e72SKalyan Thota  * @drm_enc:    Pointer to previously created drm encoder structure
13473743e72SKalyan Thota  */
13573743e72SKalyan Thota int dpu_encoder_get_linecount(struct drm_encoder *drm_enc);
13673743e72SKalyan Thota 
13773743e72SKalyan Thota /**
138885455d6SMark Yacoub  * dpu_encoder_get_vsync_count - get vsync count for the encoder.
13973743e72SKalyan Thota  * @drm_enc:    Pointer to previously created drm encoder structure
14073743e72SKalyan Thota  */
141885455d6SMark Yacoub int dpu_encoder_get_vsync_count(struct drm_encoder *drm_enc);
14225fdd593SJeykumar Sankaran 
1433309a756SKuogee Hsieh bool dpu_encoder_is_widebus_enabled(const struct drm_encoder *drm_enc);
1443309a756SKuogee Hsieh 
14563f4a7beSDmitry Baryshkov /**
1463bb4f4b1SAbhinav Kumar  * dpu_encoder_is_dsc_enabled - indicate whether dsc is enabled
1473bb4f4b1SAbhinav Kumar  *				for the encoder.
1483bb4f4b1SAbhinav Kumar  * @drm_enc:    Pointer to previously created drm encoder structure
1493bb4f4b1SAbhinav Kumar  */
1503bb4f4b1SAbhinav Kumar bool dpu_encoder_is_dsc_enabled(const struct drm_encoder *drm_enc);
1513bb4f4b1SAbhinav Kumar 
1523bb4f4b1SAbhinav Kumar /**
153b1665047SJessica Zhang  * dpu_encoder_get_crc_values_cnt - get number of physical encoders contained
154b1665047SJessica Zhang  *	in virtual encoder that can collect CRC values
155b1665047SJessica Zhang  * @drm_enc:    Pointer to previously created drm encoder structure
156b1665047SJessica Zhang  * Returns:     Number of physical encoders for given drm encoder
157b1665047SJessica Zhang  */
158b1665047SJessica Zhang int dpu_encoder_get_crc_values_cnt(const struct drm_encoder *drm_enc);
159b1665047SJessica Zhang 
160b1665047SJessica Zhang /**
161b1665047SJessica Zhang  * dpu_encoder_setup_misr - enable misr calculations
162b1665047SJessica Zhang  * @drm_enc:    Pointer to previously created drm encoder structure
163b1665047SJessica Zhang  */
164b1665047SJessica Zhang void dpu_encoder_setup_misr(const struct drm_encoder *drm_encoder);
165b1665047SJessica Zhang 
166b1665047SJessica Zhang /**
167b1665047SJessica Zhang  * dpu_encoder_get_crc - get the crc value from interface blocks
168b1665047SJessica Zhang  * @drm_enc:    Pointer to previously created drm encoder structure
169b1665047SJessica Zhang  * Returns:     0 on success, error otherwise
170b1665047SJessica Zhang  */
171b1665047SJessica Zhang int dpu_encoder_get_crc(const struct drm_encoder *drm_enc, u32 *crcs, int pos);
172b1665047SJessica Zhang 
173b1665047SJessica Zhang /**
17463f4a7beSDmitry Baryshkov  * dpu_encoder_use_dsc_merge - returns true if the encoder uses DSC merge topology.
17563f4a7beSDmitry Baryshkov  * @drm_enc:    Pointer to previously created drm encoder structure
17663f4a7beSDmitry Baryshkov  */
17763f4a7beSDmitry Baryshkov bool dpu_encoder_use_dsc_merge(struct drm_encoder *drm_enc);
17863f4a7beSDmitry Baryshkov 
179d4e5f450SAbhinav Kumar /**
180d4e5f450SAbhinav Kumar  * dpu_encoder_prepare_wb_job - prepare writeback job for the encoder.
181d4e5f450SAbhinav Kumar  * @drm_enc:    Pointer to previously created drm encoder structure
182d4e5f450SAbhinav Kumar  * @job:        Pointer to the current drm writeback job
183d4e5f450SAbhinav Kumar  */
184d4e5f450SAbhinav Kumar void dpu_encoder_prepare_wb_job(struct drm_encoder *drm_enc,
185d4e5f450SAbhinav Kumar 		struct drm_writeback_job *job);
186d4e5f450SAbhinav Kumar 
187d4e5f450SAbhinav Kumar /**
188d4e5f450SAbhinav Kumar  * dpu_encoder_cleanup_wb_job - cleanup writeback job for the encoder.
189d4e5f450SAbhinav Kumar  * @drm_enc:    Pointer to previously created drm encoder structure
190d4e5f450SAbhinav Kumar  * @job:        Pointer to the current drm writeback job
191d4e5f450SAbhinav Kumar  */
192d4e5f450SAbhinav Kumar void dpu_encoder_cleanup_wb_job(struct drm_encoder *drm_enc,
193d4e5f450SAbhinav Kumar 		struct drm_writeback_job *job);
194d4e5f450SAbhinav Kumar 
195f2969c49SAbhinav Kumar /**
196f2969c49SAbhinav Kumar  * dpu_encoder_is_valid_for_commit - check if encode has valid parameters for commit.
197f2969c49SAbhinav Kumar  * @drm_enc:    Pointer to drm encoder structure
198f2969c49SAbhinav Kumar  */
199f2969c49SAbhinav Kumar bool dpu_encoder_is_valid_for_commit(struct drm_encoder *drm_enc);
200f2969c49SAbhinav Kumar 
20125fdd593SJeykumar Sankaran #endif /* __DPU_ENCODER_H__ */
202