xref: /OK3568_Linux_fs/kernel/drivers/gpu/drm/bridge/analogix/analogix_dp_core.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * Header file for Analogix DP (Display Port) core interface driver.
4  *
5  * Copyright (C) 2012 Samsung Electronics Co., Ltd.
6  * Author: Jingoo Han <jg1.han@samsung.com>
7  */
8 
9 #ifndef _ANALOGIX_DP_CORE_H
10 #define _ANALOGIX_DP_CORE_H
11 
12 #include <drm/drm_crtc.h>
13 #include <drm/drm_bridge.h>
14 #include <drm/drm_dp_helper.h>
15 
16 #define DP_TIMEOUT_LOOP_COUNT 100
17 #define MAX_CR_LOOP 5
18 #define MAX_EQ_LOOP 5
19 #define MAX_PLL_LOCK_LOOP 5
20 
21 /* Training takes 22ms if AUX channel comm fails. Use this as retry interval */
22 #define DP_TIMEOUT_TRAINING_US			22000
23 #define DP_TIMEOUT_PSR_LOOP_MS			300
24 
25 /* DP_MAX_LANE_COUNT */
26 #define DPCD_ENHANCED_FRAME_CAP(x)		(((x) >> 7) & 0x1)
27 #define DPCD_MAX_LANE_COUNT(x)			((x) & 0x1f)
28 
29 /* DP_LANE_COUNT_SET */
30 #define DPCD_LANE_COUNT_SET(x)			((x) & 0x1f)
31 
32 /* DP_TRAINING_LANE0_SET */
33 #define DPCD_PRE_EMPHASIS_SET(x)		(((x) & 0x3) << 3)
34 #define DPCD_PRE_EMPHASIS_GET(x)		(((x) >> 3) & 0x3)
35 #define DPCD_VOLTAGE_SWING_SET(x)		(((x) & 0x3) << 0)
36 #define DPCD_VOLTAGE_SWING_GET(x)		(((x) >> 0) & 0x3)
37 
38 struct gpio_desc;
39 
40 enum link_lane_count_type {
41 	LANE_COUNT1 = 1,
42 	LANE_COUNT2 = 2,
43 	LANE_COUNT4 = 4
44 };
45 
46 enum link_training_state {
47 	START,
48 	CLOCK_RECOVERY,
49 	EQUALIZER_TRAINING,
50 	FINISHED,
51 	FAILED
52 };
53 
54 enum voltage_swing_level {
55 	VOLTAGE_LEVEL_0,
56 	VOLTAGE_LEVEL_1,
57 	VOLTAGE_LEVEL_2,
58 	VOLTAGE_LEVEL_3,
59 };
60 
61 enum pre_emphasis_level {
62 	PRE_EMPHASIS_LEVEL_0,
63 	PRE_EMPHASIS_LEVEL_1,
64 	PRE_EMPHASIS_LEVEL_2,
65 	PRE_EMPHASIS_LEVEL_3,
66 };
67 
68 enum pattern_set {
69 	PRBS7,
70 	D10_2,
71 	TRAINING_PTN1,
72 	TRAINING_PTN2,
73 	TRAINING_PTN3,
74 	TEST_PATTERN_80BIT,
75 	TEST_PATTERN_HBR2,
76 	DP_NONE
77 };
78 
79 enum color_space {
80 	COLOR_RGB,
81 	COLOR_YCBCR422,
82 	COLOR_YCBCR444
83 };
84 
85 enum color_depth {
86 	COLOR_6,
87 	COLOR_8,
88 	COLOR_10,
89 	COLOR_12
90 };
91 
92 enum color_coefficient {
93 	COLOR_YCBCR601,
94 	COLOR_YCBCR709
95 };
96 
97 enum dynamic_range {
98 	VESA,
99 	CEA
100 };
101 
102 enum pll_status {
103 	PLL_UNLOCKED,
104 	PLL_LOCKED
105 };
106 
107 enum clock_recovery_m_value_type {
108 	CALCULATED_M,
109 	REGISTER_M
110 };
111 
112 enum video_timing_recognition_type {
113 	VIDEO_TIMING_FROM_CAPTURE,
114 	VIDEO_TIMING_FROM_REGISTER
115 };
116 
117 enum analog_power_block {
118 	AUX_BLOCK,
119 	CH0_BLOCK,
120 	CH1_BLOCK,
121 	CH2_BLOCK,
122 	CH3_BLOCK,
123 	ANALOG_TOTAL,
124 	POWER_ALL
125 };
126 
127 struct video_info {
128 	char *name;
129 	struct drm_display_mode mode;
130 
131 	bool h_sync_polarity;
132 	bool v_sync_polarity;
133 	bool interlaced;
134 
135 	enum color_space color_space;
136 	enum dynamic_range dynamic_range;
137 	enum color_coefficient ycbcr_coeff;
138 	enum color_depth color_depth;
139 
140 	int max_link_rate;
141 	enum link_lane_count_type max_lane_count;
142 	u32 lane_map[4];
143 
144 	bool video_bist_enable;
145 	bool force_stream_valid;
146 };
147 
148 struct link_train {
149 	int eq_loop;
150 	int cr_loop[4];
151 
152 	u8 link_rate;
153 	u8 lane_count;
154 	u8 training_lane[4];
155 	bool ssc;
156 	bool enhanced_framing;
157 
158 	enum link_training_state lt_state;
159 };
160 
161 struct analogix_dp_compliance {
162 	struct drm_dp_phy_test_params phytest;
163 	int test_link_rate;
164 	u8 test_lane_count;
165 	unsigned long test_type;
166 	bool test_active;
167 };
168 
169 struct analogix_dp_device {
170 	struct drm_encoder	*encoder;
171 	struct device		*dev;
172 	struct drm_device	*drm_dev;
173 	struct drm_connector	connector;
174 	struct drm_bridge	bridge;
175 	struct drm_dp_aux       aux;
176 	struct clk_bulk_data	*clks;
177 	int			nr_clks;
178 	unsigned int		irq;
179 	void __iomem		*reg_base;
180 
181 	struct video_info	video_info;
182 	struct link_train	link_train;
183 	struct phy		*phy;
184 	int			dpms_mode;
185 	struct gpio_desc	*hpd_gpiod;
186 	bool                    force_hpd;
187 	bool			fast_train_enable;
188 	bool			psr_supported;
189 	struct work_struct	modeset_retry_work;
190 
191 	struct mutex		panel_lock;
192 	bool			panel_is_prepared;
193 
194 	u8 dpcd[DP_RECEIVER_CAP_SIZE];
195 	struct analogix_dp_plat_data *plat_data;
196 	struct extcon_dev *extcon;
197 	struct analogix_dp_compliance compliance;
198 
199 	u32 split_area;
200 };
201 
202 /* analogix_dp_reg.c */
203 void analogix_dp_enable_video_mute(struct analogix_dp_device *dp, bool enable);
204 void analogix_dp_stop_video(struct analogix_dp_device *dp);
205 void analogix_dp_init_analog_param(struct analogix_dp_device *dp);
206 void analogix_dp_init_interrupt(struct analogix_dp_device *dp);
207 void analogix_dp_reset(struct analogix_dp_device *dp);
208 void analogix_dp_swreset(struct analogix_dp_device *dp);
209 void analogix_dp_config_interrupt(struct analogix_dp_device *dp);
210 void analogix_dp_mute_hpd_interrupt(struct analogix_dp_device *dp);
211 void analogix_dp_unmute_hpd_interrupt(struct analogix_dp_device *dp);
212 enum pll_status analogix_dp_get_pll_lock_status(struct analogix_dp_device *dp);
213 void analogix_dp_set_pll_power_down(struct analogix_dp_device *dp, bool enable);
214 void analogix_dp_set_analog_power_down(struct analogix_dp_device *dp,
215 				       enum analog_power_block block,
216 				       bool enable);
217 int analogix_dp_init_analog_func(struct analogix_dp_device *dp);
218 void analogix_dp_init_hpd(struct analogix_dp_device *dp);
219 void analogix_dp_force_hpd(struct analogix_dp_device *dp);
220 void analogix_dp_clear_hotplug_interrupts(struct analogix_dp_device *dp);
221 void analogix_dp_reset_aux(struct analogix_dp_device *dp);
222 void analogix_dp_init_aux(struct analogix_dp_device *dp);
223 int analogix_dp_get_plug_in_status(struct analogix_dp_device *dp);
224 void analogix_dp_enable_sw_function(struct analogix_dp_device *dp);
225 void analogix_dp_set_link_bandwidth(struct analogix_dp_device *dp, u32 bwtype);
226 void analogix_dp_get_link_bandwidth(struct analogix_dp_device *dp, u32 *bwtype);
227 void analogix_dp_set_lane_count(struct analogix_dp_device *dp, u32 count);
228 void analogix_dp_get_lane_count(struct analogix_dp_device *dp, u32 *count);
229 void analogix_dp_enable_enhanced_mode(struct analogix_dp_device *dp,
230 				      bool enable);
231 bool analogix_dp_get_enhanced_mode(struct analogix_dp_device *dp);
232 void analogix_dp_set_training_pattern(struct analogix_dp_device *dp,
233 				      enum pattern_set pattern);
234 void analogix_dp_set_lane_link_training(struct analogix_dp_device *dp);
235 u32 analogix_dp_get_lane_link_training(struct analogix_dp_device *dp, u8 lane);
236 void analogix_dp_reset_macro(struct analogix_dp_device *dp);
237 void analogix_dp_init_video(struct analogix_dp_device *dp);
238 
239 void analogix_dp_set_video_color_format(struct analogix_dp_device *dp);
240 int analogix_dp_is_slave_video_stream_clock_on(struct analogix_dp_device *dp);
241 void analogix_dp_set_video_cr_mn(struct analogix_dp_device *dp,
242 				 enum clock_recovery_m_value_type type,
243 				 u32 m_value,
244 				 u32 n_value);
245 void analogix_dp_set_video_timing_mode(struct analogix_dp_device *dp, u32 type);
246 void analogix_dp_enable_video_master(struct analogix_dp_device *dp,
247 				     bool enable);
248 void analogix_dp_start_video(struct analogix_dp_device *dp);
249 int analogix_dp_is_video_stream_on(struct analogix_dp_device *dp);
250 void analogix_dp_config_video_slave_mode(struct analogix_dp_device *dp);
251 void analogix_dp_enable_scrambling(struct analogix_dp_device *dp);
252 void analogix_dp_disable_scrambling(struct analogix_dp_device *dp);
253 void analogix_dp_enable_psr_crc(struct analogix_dp_device *dp);
254 int analogix_dp_send_psr_spd(struct analogix_dp_device *dp,
255 			     struct dp_sdp *vsc, bool blocking);
256 ssize_t analogix_dp_transfer(struct analogix_dp_device *dp,
257 			     struct drm_dp_aux_msg *msg);
258 void analogix_dp_set_video_format(struct analogix_dp_device *dp);
259 void analogix_dp_video_bist_enable(struct analogix_dp_device *dp);
260 bool analogix_dp_ssc_supported(struct analogix_dp_device *dp);
261 int analogix_dp_phy_power_on(struct analogix_dp_device *dp);
262 void analogix_dp_phy_power_off(struct analogix_dp_device *dp);
263 void analogix_dp_audio_config_spdif(struct analogix_dp_device *dp);
264 void analogix_dp_audio_config_i2s(struct analogix_dp_device *dp);
265 void analogix_dp_audio_enable(struct analogix_dp_device *dp);
266 void analogix_dp_audio_disable(struct analogix_dp_device *dp);
267 void analogix_dp_init(struct analogix_dp_device *dp);
268 void analogix_dp_irq_handler(struct analogix_dp_device *dp);
269 void analogix_dp_phy_test(struct analogix_dp_device *dp);
270 void analogix_dp_check_device_service_irq(struct analogix_dp_device *dp);
271 
272 #endif /* _ANALOGIX_DP_CORE_H */
273