1da68386dSThomas Zimmermann /*
2da68386dSThomas Zimmermann * Copyright © 2008 Keith Packard
3da68386dSThomas Zimmermann *
4da68386dSThomas Zimmermann * Permission to use, copy, modify, distribute, and sell this software and its
5da68386dSThomas Zimmermann * documentation for any purpose is hereby granted without fee, provided that
6da68386dSThomas Zimmermann * the above copyright notice appear in all copies and that both that copyright
7da68386dSThomas Zimmermann * notice and this permission notice appear in supporting documentation, and
8da68386dSThomas Zimmermann * that the name of the copyright holders not be used in advertising or
9da68386dSThomas Zimmermann * publicity pertaining to distribution of the software without specific,
10da68386dSThomas Zimmermann * written prior permission. The copyright holders make no representations
11da68386dSThomas Zimmermann * about the suitability of this software for any purpose. It is provided "as
12da68386dSThomas Zimmermann * is" without express or implied warranty.
13da68386dSThomas Zimmermann *
14da68386dSThomas Zimmermann * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15da68386dSThomas Zimmermann * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16da68386dSThomas Zimmermann * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17da68386dSThomas Zimmermann * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18da68386dSThomas Zimmermann * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19da68386dSThomas Zimmermann * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20da68386dSThomas Zimmermann * OF THIS SOFTWARE.
21da68386dSThomas Zimmermann */
22da68386dSThomas Zimmermann
23da68386dSThomas Zimmermann #ifndef _DRM_DP_HELPER_H_
24da68386dSThomas Zimmermann #define _DRM_DP_HELPER_H_
25da68386dSThomas Zimmermann
26da68386dSThomas Zimmermann #include <linux/delay.h>
27da68386dSThomas Zimmermann #include <linux/i2c.h>
285d1b8b4aSThomas Zimmermann
295d1b8b4aSThomas Zimmermann #include <drm/display/drm_dp.h>
30da68386dSThomas Zimmermann #include <drm/drm_connector.h>
31da68386dSThomas Zimmermann
32da68386dSThomas Zimmermann struct drm_device;
33da68386dSThomas Zimmermann struct drm_dp_aux;
34da68386dSThomas Zimmermann struct drm_panel;
35da68386dSThomas Zimmermann
36da68386dSThomas Zimmermann bool drm_dp_channel_eq_ok(const u8 link_status[DP_LINK_STATUS_SIZE],
37da68386dSThomas Zimmermann int lane_count);
38da68386dSThomas Zimmermann bool drm_dp_clock_recovery_ok(const u8 link_status[DP_LINK_STATUS_SIZE],
39da68386dSThomas Zimmermann int lane_count);
40da68386dSThomas Zimmermann u8 drm_dp_get_adjust_request_voltage(const u8 link_status[DP_LINK_STATUS_SIZE],
41da68386dSThomas Zimmermann int lane);
42da68386dSThomas Zimmermann u8 drm_dp_get_adjust_request_pre_emphasis(const u8 link_status[DP_LINK_STATUS_SIZE],
43da68386dSThomas Zimmermann int lane);
44da68386dSThomas Zimmermann u8 drm_dp_get_adjust_tx_ffe_preset(const u8 link_status[DP_LINK_STATUS_SIZE],
45da68386dSThomas Zimmermann int lane);
46da68386dSThomas Zimmermann
47da68386dSThomas Zimmermann int drm_dp_read_clock_recovery_delay(struct drm_dp_aux *aux, const u8 dpcd[DP_RECEIVER_CAP_SIZE],
48da68386dSThomas Zimmermann enum drm_dp_phy dp_phy, bool uhbr);
49da68386dSThomas Zimmermann int drm_dp_read_channel_eq_delay(struct drm_dp_aux *aux, const u8 dpcd[DP_RECEIVER_CAP_SIZE],
50da68386dSThomas Zimmermann enum drm_dp_phy dp_phy, bool uhbr);
51da68386dSThomas Zimmermann
52da68386dSThomas Zimmermann void drm_dp_link_train_clock_recovery_delay(const struct drm_dp_aux *aux,
53da68386dSThomas Zimmermann const u8 dpcd[DP_RECEIVER_CAP_SIZE]);
54da68386dSThomas Zimmermann void drm_dp_lttpr_link_train_clock_recovery_delay(void);
55da68386dSThomas Zimmermann void drm_dp_link_train_channel_eq_delay(const struct drm_dp_aux *aux,
56da68386dSThomas Zimmermann const u8 dpcd[DP_RECEIVER_CAP_SIZE]);
57da68386dSThomas Zimmermann void drm_dp_lttpr_link_train_channel_eq_delay(const struct drm_dp_aux *aux,
58da68386dSThomas Zimmermann const u8 caps[DP_LTTPR_PHY_CAP_SIZE]);
59da68386dSThomas Zimmermann
60da68386dSThomas Zimmermann int drm_dp_128b132b_read_aux_rd_interval(struct drm_dp_aux *aux);
61da68386dSThomas Zimmermann bool drm_dp_128b132b_lane_channel_eq_done(const u8 link_status[DP_LINK_STATUS_SIZE],
62da68386dSThomas Zimmermann int lane_count);
63da68386dSThomas Zimmermann bool drm_dp_128b132b_lane_symbol_locked(const u8 link_status[DP_LINK_STATUS_SIZE],
64da68386dSThomas Zimmermann int lane_count);
65da68386dSThomas Zimmermann bool drm_dp_128b132b_eq_interlane_align_done(const u8 link_status[DP_LINK_STATUS_SIZE]);
66da68386dSThomas Zimmermann bool drm_dp_128b132b_cds_interlane_align_done(const u8 link_status[DP_LINK_STATUS_SIZE]);
67da68386dSThomas Zimmermann bool drm_dp_128b132b_link_training_failed(const u8 link_status[DP_LINK_STATUS_SIZE]);
68da68386dSThomas Zimmermann
69da68386dSThomas Zimmermann u8 drm_dp_link_rate_to_bw_code(int link_rate);
70da68386dSThomas Zimmermann int drm_dp_bw_code_to_link_rate(u8 link_bw);
71da68386dSThomas Zimmermann
725b04aab6SJani Nikula const char *drm_dp_phy_name(enum drm_dp_phy dp_phy);
735b04aab6SJani Nikula
74da68386dSThomas Zimmermann /**
75da68386dSThomas Zimmermann * struct drm_dp_vsc_sdp - drm DP VSC SDP
76da68386dSThomas Zimmermann *
77da68386dSThomas Zimmermann * This structure represents a DP VSC SDP of drm
78da68386dSThomas Zimmermann * It is based on DP 1.4 spec [Table 2-116: VSC SDP Header Bytes] and
79da68386dSThomas Zimmermann * [Table 2-117: VSC SDP Payload for DB16 through DB18]
80da68386dSThomas Zimmermann *
81da68386dSThomas Zimmermann * @sdp_type: secondary-data packet type
82da68386dSThomas Zimmermann * @revision: revision number
83da68386dSThomas Zimmermann * @length: number of valid data bytes
84da68386dSThomas Zimmermann * @pixelformat: pixel encoding format
85da68386dSThomas Zimmermann * @colorimetry: colorimetry format
86da68386dSThomas Zimmermann * @bpc: bit per color
87da68386dSThomas Zimmermann * @dynamic_range: dynamic range information
88da68386dSThomas Zimmermann * @content_type: CTA-861-G defines content types and expected processing by a sink device
89da68386dSThomas Zimmermann */
90da68386dSThomas Zimmermann struct drm_dp_vsc_sdp {
91da68386dSThomas Zimmermann unsigned char sdp_type;
92da68386dSThomas Zimmermann unsigned char revision;
93da68386dSThomas Zimmermann unsigned char length;
94da68386dSThomas Zimmermann enum dp_pixelformat pixelformat;
95da68386dSThomas Zimmermann enum dp_colorimetry colorimetry;
96da68386dSThomas Zimmermann int bpc;
97da68386dSThomas Zimmermann enum dp_dynamic_range dynamic_range;
98da68386dSThomas Zimmermann enum dp_content_type content_type;
99da68386dSThomas Zimmermann };
100da68386dSThomas Zimmermann
101da68386dSThomas Zimmermann void drm_dp_vsc_sdp_log(const char *level, struct device *dev,
102da68386dSThomas Zimmermann const struct drm_dp_vsc_sdp *vsc);
103da68386dSThomas Zimmermann
104da68386dSThomas Zimmermann int drm_dp_psr_setup_time(const u8 psr_cap[EDP_PSR_RECEIVER_CAP_SIZE]);
105da68386dSThomas Zimmermann
106da68386dSThomas Zimmermann static inline int
drm_dp_max_link_rate(const u8 dpcd[DP_RECEIVER_CAP_SIZE])107da68386dSThomas Zimmermann drm_dp_max_link_rate(const u8 dpcd[DP_RECEIVER_CAP_SIZE])
108da68386dSThomas Zimmermann {
109da68386dSThomas Zimmermann return drm_dp_bw_code_to_link_rate(dpcd[DP_MAX_LINK_RATE]);
110da68386dSThomas Zimmermann }
111da68386dSThomas Zimmermann
112da68386dSThomas Zimmermann static inline u8
drm_dp_max_lane_count(const u8 dpcd[DP_RECEIVER_CAP_SIZE])113da68386dSThomas Zimmermann drm_dp_max_lane_count(const u8 dpcd[DP_RECEIVER_CAP_SIZE])
114da68386dSThomas Zimmermann {
115da68386dSThomas Zimmermann return dpcd[DP_MAX_LANE_COUNT] & DP_MAX_LANE_COUNT_MASK;
116da68386dSThomas Zimmermann }
117da68386dSThomas Zimmermann
118da68386dSThomas Zimmermann static inline bool
drm_dp_enhanced_frame_cap(const u8 dpcd[DP_RECEIVER_CAP_SIZE])119da68386dSThomas Zimmermann drm_dp_enhanced_frame_cap(const u8 dpcd[DP_RECEIVER_CAP_SIZE])
120da68386dSThomas Zimmermann {
121da68386dSThomas Zimmermann return dpcd[DP_DPCD_REV] >= 0x11 &&
122da68386dSThomas Zimmermann (dpcd[DP_MAX_LANE_COUNT] & DP_ENHANCED_FRAME_CAP);
123da68386dSThomas Zimmermann }
124da68386dSThomas Zimmermann
125da68386dSThomas Zimmermann static inline bool
drm_dp_fast_training_cap(const u8 dpcd[DP_RECEIVER_CAP_SIZE])126da68386dSThomas Zimmermann drm_dp_fast_training_cap(const u8 dpcd[DP_RECEIVER_CAP_SIZE])
127da68386dSThomas Zimmermann {
128da68386dSThomas Zimmermann return dpcd[DP_DPCD_REV] >= 0x11 &&
129da68386dSThomas Zimmermann (dpcd[DP_MAX_DOWNSPREAD] & DP_NO_AUX_HANDSHAKE_LINK_TRAINING);
130da68386dSThomas Zimmermann }
131da68386dSThomas Zimmermann
132da68386dSThomas Zimmermann static inline bool
drm_dp_tps3_supported(const u8 dpcd[DP_RECEIVER_CAP_SIZE])133da68386dSThomas Zimmermann drm_dp_tps3_supported(const u8 dpcd[DP_RECEIVER_CAP_SIZE])
134da68386dSThomas Zimmermann {
135da68386dSThomas Zimmermann return dpcd[DP_DPCD_REV] >= 0x12 &&
136da68386dSThomas Zimmermann dpcd[DP_MAX_LANE_COUNT] & DP_TPS3_SUPPORTED;
137da68386dSThomas Zimmermann }
138da68386dSThomas Zimmermann
139da68386dSThomas Zimmermann static inline bool
drm_dp_max_downspread(const u8 dpcd[DP_RECEIVER_CAP_SIZE])140da68386dSThomas Zimmermann drm_dp_max_downspread(const u8 dpcd[DP_RECEIVER_CAP_SIZE])
141da68386dSThomas Zimmermann {
142da68386dSThomas Zimmermann return dpcd[DP_DPCD_REV] >= 0x11 ||
143da68386dSThomas Zimmermann dpcd[DP_MAX_DOWNSPREAD] & DP_MAX_DOWNSPREAD_0_5;
144da68386dSThomas Zimmermann }
145da68386dSThomas Zimmermann
146da68386dSThomas Zimmermann static inline bool
drm_dp_tps4_supported(const u8 dpcd[DP_RECEIVER_CAP_SIZE])147da68386dSThomas Zimmermann drm_dp_tps4_supported(const u8 dpcd[DP_RECEIVER_CAP_SIZE])
148da68386dSThomas Zimmermann {
149da68386dSThomas Zimmermann return dpcd[DP_DPCD_REV] >= 0x14 &&
150da68386dSThomas Zimmermann dpcd[DP_MAX_DOWNSPREAD] & DP_TPS4_SUPPORTED;
151da68386dSThomas Zimmermann }
152da68386dSThomas Zimmermann
153da68386dSThomas Zimmermann static inline u8
drm_dp_training_pattern_mask(const u8 dpcd[DP_RECEIVER_CAP_SIZE])154da68386dSThomas Zimmermann drm_dp_training_pattern_mask(const u8 dpcd[DP_RECEIVER_CAP_SIZE])
155da68386dSThomas Zimmermann {
156da68386dSThomas Zimmermann return (dpcd[DP_DPCD_REV] >= 0x14) ? DP_TRAINING_PATTERN_MASK_1_4 :
157da68386dSThomas Zimmermann DP_TRAINING_PATTERN_MASK;
158da68386dSThomas Zimmermann }
159da68386dSThomas Zimmermann
160da68386dSThomas Zimmermann static inline bool
drm_dp_is_branch(const u8 dpcd[DP_RECEIVER_CAP_SIZE])161da68386dSThomas Zimmermann drm_dp_is_branch(const u8 dpcd[DP_RECEIVER_CAP_SIZE])
162da68386dSThomas Zimmermann {
163da68386dSThomas Zimmermann return dpcd[DP_DOWNSTREAMPORT_PRESENT] & DP_DWN_STRM_PORT_PRESENT;
164da68386dSThomas Zimmermann }
165da68386dSThomas Zimmermann
166da68386dSThomas Zimmermann /* DP/eDP DSC support */
167da68386dSThomas Zimmermann u8 drm_dp_dsc_sink_max_slice_count(const u8 dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE],
168da68386dSThomas Zimmermann bool is_edp);
169da68386dSThomas Zimmermann u8 drm_dp_dsc_sink_line_buf_depth(const u8 dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE]);
170da68386dSThomas Zimmermann int drm_dp_dsc_sink_supported_input_bpcs(const u8 dsc_dpc[DP_DSC_RECEIVER_CAP_SIZE],
171da68386dSThomas Zimmermann u8 dsc_bpc[3]);
172da68386dSThomas Zimmermann
173da68386dSThomas Zimmermann static inline bool
drm_dp_sink_supports_dsc(const u8 dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE])174da68386dSThomas Zimmermann drm_dp_sink_supports_dsc(const u8 dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE])
175da68386dSThomas Zimmermann {
176da68386dSThomas Zimmermann return dsc_dpcd[DP_DSC_SUPPORT - DP_DSC_SUPPORT] &
177da68386dSThomas Zimmermann DP_DSC_DECOMPRESSION_IS_SUPPORTED;
178da68386dSThomas Zimmermann }
179da68386dSThomas Zimmermann
180da68386dSThomas Zimmermann static inline u16
drm_edp_dsc_sink_output_bpp(const u8 dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE])181da68386dSThomas Zimmermann drm_edp_dsc_sink_output_bpp(const u8 dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE])
182da68386dSThomas Zimmermann {
183da68386dSThomas Zimmermann return dsc_dpcd[DP_DSC_MAX_BITS_PER_PIXEL_LOW - DP_DSC_SUPPORT] |
18413525645SJani Nikula ((dsc_dpcd[DP_DSC_MAX_BITS_PER_PIXEL_HI - DP_DSC_SUPPORT] &
18513525645SJani Nikula DP_DSC_MAX_BITS_PER_PIXEL_HI_MASK) << 8);
186da68386dSThomas Zimmermann }
187da68386dSThomas Zimmermann
188da68386dSThomas Zimmermann static inline u32
drm_dp_dsc_sink_max_slice_width(const u8 dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE])189da68386dSThomas Zimmermann drm_dp_dsc_sink_max_slice_width(const u8 dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE])
190da68386dSThomas Zimmermann {
191da68386dSThomas Zimmermann /* Max Slicewidth = Number of Pixels * 320 */
192da68386dSThomas Zimmermann return dsc_dpcd[DP_DSC_MAX_SLICE_WIDTH - DP_DSC_SUPPORT] *
193da68386dSThomas Zimmermann DP_DSC_SLICE_WIDTH_MULTIPLIER;
194da68386dSThomas Zimmermann }
195da68386dSThomas Zimmermann
196a389789cSAnkit Nautiyal /**
197a389789cSAnkit Nautiyal * drm_dp_dsc_sink_supports_format() - check if sink supports DSC with given output format
198a389789cSAnkit Nautiyal * @dsc_dpcd : DSC-capability DPCDs of the sink
199a389789cSAnkit Nautiyal * @output_format: output_format which is to be checked
200a389789cSAnkit Nautiyal *
201a389789cSAnkit Nautiyal * Returns true if the sink supports DSC with the given output_format, false otherwise.
202a389789cSAnkit Nautiyal */
203a389789cSAnkit Nautiyal static inline bool
drm_dp_dsc_sink_supports_format(const u8 dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE],u8 output_format)204a389789cSAnkit Nautiyal drm_dp_dsc_sink_supports_format(const u8 dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE], u8 output_format)
205a389789cSAnkit Nautiyal {
206a389789cSAnkit Nautiyal return dsc_dpcd[DP_DSC_DEC_COLOR_FORMAT_CAP - DP_DSC_SUPPORT] & output_format;
207a389789cSAnkit Nautiyal }
208a389789cSAnkit Nautiyal
209da68386dSThomas Zimmermann /* Forward Error Correction Support on DP 1.4 */
210da68386dSThomas Zimmermann static inline bool
drm_dp_sink_supports_fec(const u8 fec_capable)211da68386dSThomas Zimmermann drm_dp_sink_supports_fec(const u8 fec_capable)
212da68386dSThomas Zimmermann {
213da68386dSThomas Zimmermann return fec_capable & DP_FEC_CAPABLE;
214da68386dSThomas Zimmermann }
215da68386dSThomas Zimmermann
216da68386dSThomas Zimmermann static inline bool
drm_dp_channel_coding_supported(const u8 dpcd[DP_RECEIVER_CAP_SIZE])217da68386dSThomas Zimmermann drm_dp_channel_coding_supported(const u8 dpcd[DP_RECEIVER_CAP_SIZE])
218da68386dSThomas Zimmermann {
219da68386dSThomas Zimmermann return dpcd[DP_MAIN_LINK_CHANNEL_CODING] & DP_CAP_ANSI_8B10B;
220da68386dSThomas Zimmermann }
221da68386dSThomas Zimmermann
222da68386dSThomas Zimmermann static inline bool
drm_dp_alternate_scrambler_reset_cap(const u8 dpcd[DP_RECEIVER_CAP_SIZE])223da68386dSThomas Zimmermann drm_dp_alternate_scrambler_reset_cap(const u8 dpcd[DP_RECEIVER_CAP_SIZE])
224da68386dSThomas Zimmermann {
225da68386dSThomas Zimmermann return dpcd[DP_EDP_CONFIGURATION_CAP] &
226da68386dSThomas Zimmermann DP_ALTERNATE_SCRAMBLER_RESET_CAP;
227da68386dSThomas Zimmermann }
228da68386dSThomas Zimmermann
229da68386dSThomas Zimmermann /* Ignore MSA timing for Adaptive Sync support on DP 1.4 */
230da68386dSThomas Zimmermann static inline bool
drm_dp_sink_can_do_video_without_timing_msa(const u8 dpcd[DP_RECEIVER_CAP_SIZE])231da68386dSThomas Zimmermann drm_dp_sink_can_do_video_without_timing_msa(const u8 dpcd[DP_RECEIVER_CAP_SIZE])
232da68386dSThomas Zimmermann {
233da68386dSThomas Zimmermann return dpcd[DP_DOWN_STREAM_PORT_COUNT] &
234da68386dSThomas Zimmermann DP_MSA_TIMING_PAR_IGNORED;
235da68386dSThomas Zimmermann }
236da68386dSThomas Zimmermann
237da68386dSThomas Zimmermann /**
238da68386dSThomas Zimmermann * drm_edp_backlight_supported() - Check an eDP DPCD for VESA backlight support
239da68386dSThomas Zimmermann * @edp_dpcd: The DPCD to check
240da68386dSThomas Zimmermann *
241da68386dSThomas Zimmermann * Note that currently this function will return %false for panels which support various DPCD
242da68386dSThomas Zimmermann * backlight features but which require the brightness be set through PWM, and don't support setting
243da68386dSThomas Zimmermann * the brightness level via the DPCD.
244da68386dSThomas Zimmermann *
245da68386dSThomas Zimmermann * Returns: %True if @edp_dpcd indicates that VESA backlight controls are supported, %false
246da68386dSThomas Zimmermann * otherwise
247da68386dSThomas Zimmermann */
248da68386dSThomas Zimmermann static inline bool
drm_edp_backlight_supported(const u8 edp_dpcd[EDP_DISPLAY_CTL_CAP_SIZE])249da68386dSThomas Zimmermann drm_edp_backlight_supported(const u8 edp_dpcd[EDP_DISPLAY_CTL_CAP_SIZE])
250da68386dSThomas Zimmermann {
251da68386dSThomas Zimmermann return !!(edp_dpcd[1] & DP_EDP_TCON_BACKLIGHT_ADJUSTMENT_CAP);
252da68386dSThomas Zimmermann }
253da68386dSThomas Zimmermann
254da68386dSThomas Zimmermann /*
255da68386dSThomas Zimmermann * DisplayPort AUX channel
256da68386dSThomas Zimmermann */
257da68386dSThomas Zimmermann
258da68386dSThomas Zimmermann /**
259da68386dSThomas Zimmermann * struct drm_dp_aux_msg - DisplayPort AUX channel transaction
260da68386dSThomas Zimmermann * @address: address of the (first) register to access
261da68386dSThomas Zimmermann * @request: contains the type of transaction (see DP_AUX_* macros)
262da68386dSThomas Zimmermann * @reply: upon completion, contains the reply type of the transaction
263da68386dSThomas Zimmermann * @buffer: pointer to a transmission or reception buffer
264da68386dSThomas Zimmermann * @size: size of @buffer
265da68386dSThomas Zimmermann */
266da68386dSThomas Zimmermann struct drm_dp_aux_msg {
267da68386dSThomas Zimmermann unsigned int address;
268da68386dSThomas Zimmermann u8 request;
269da68386dSThomas Zimmermann u8 reply;
270da68386dSThomas Zimmermann void *buffer;
271da68386dSThomas Zimmermann size_t size;
272da68386dSThomas Zimmermann };
273da68386dSThomas Zimmermann
274da68386dSThomas Zimmermann struct cec_adapter;
275da68386dSThomas Zimmermann struct edid;
276da68386dSThomas Zimmermann struct drm_connector;
277da68386dSThomas Zimmermann
278da68386dSThomas Zimmermann /**
279da68386dSThomas Zimmermann * struct drm_dp_aux_cec - DisplayPort CEC-Tunneling-over-AUX
280da68386dSThomas Zimmermann * @lock: mutex protecting this struct
281da68386dSThomas Zimmermann * @adap: the CEC adapter for CEC-Tunneling-over-AUX support.
282da68386dSThomas Zimmermann * @connector: the connector this CEC adapter is associated with
283da68386dSThomas Zimmermann * @unregister_work: unregister the CEC adapter
284da68386dSThomas Zimmermann */
285da68386dSThomas Zimmermann struct drm_dp_aux_cec {
286da68386dSThomas Zimmermann struct mutex lock;
287da68386dSThomas Zimmermann struct cec_adapter *adap;
288da68386dSThomas Zimmermann struct drm_connector *connector;
289da68386dSThomas Zimmermann struct delayed_work unregister_work;
290da68386dSThomas Zimmermann };
291da68386dSThomas Zimmermann
292da68386dSThomas Zimmermann /**
293da68386dSThomas Zimmermann * struct drm_dp_aux - DisplayPort AUX channel
294da68386dSThomas Zimmermann *
295da68386dSThomas Zimmermann * An AUX channel can also be used to transport I2C messages to a sink. A
296da68386dSThomas Zimmermann * typical application of that is to access an EDID that's present in the sink
297da68386dSThomas Zimmermann * device. The @transfer() function can also be used to execute such
298da68386dSThomas Zimmermann * transactions. The drm_dp_aux_register() function registers an I2C adapter
299da68386dSThomas Zimmermann * that can be passed to drm_probe_ddc(). Upon removal, drivers should call
300da68386dSThomas Zimmermann * drm_dp_aux_unregister() to remove the I2C adapter. The I2C adapter uses long
301da68386dSThomas Zimmermann * transfers by default; if a partial response is received, the adapter will
302da68386dSThomas Zimmermann * drop down to the size given by the partial response for this transaction
303da68386dSThomas Zimmermann * only.
304da68386dSThomas Zimmermann */
305da68386dSThomas Zimmermann struct drm_dp_aux {
306da68386dSThomas Zimmermann /**
307da68386dSThomas Zimmermann * @name: user-visible name of this AUX channel and the
308da68386dSThomas Zimmermann * I2C-over-AUX adapter.
309da68386dSThomas Zimmermann *
310da68386dSThomas Zimmermann * It's also used to specify the name of the I2C adapter. If set
311da68386dSThomas Zimmermann * to %NULL, dev_name() of @dev will be used.
312da68386dSThomas Zimmermann */
313da68386dSThomas Zimmermann const char *name;
314da68386dSThomas Zimmermann
315da68386dSThomas Zimmermann /**
316da68386dSThomas Zimmermann * @ddc: I2C adapter that can be used for I2C-over-AUX
317da68386dSThomas Zimmermann * communication
318da68386dSThomas Zimmermann */
319da68386dSThomas Zimmermann struct i2c_adapter ddc;
320da68386dSThomas Zimmermann
321da68386dSThomas Zimmermann /**
322da68386dSThomas Zimmermann * @dev: pointer to struct device that is the parent for this
323da68386dSThomas Zimmermann * AUX channel.
324da68386dSThomas Zimmermann */
325da68386dSThomas Zimmermann struct device *dev;
326da68386dSThomas Zimmermann
327da68386dSThomas Zimmermann /**
328da68386dSThomas Zimmermann * @drm_dev: pointer to the &drm_device that owns this AUX channel.
329da68386dSThomas Zimmermann * Beware, this may be %NULL before drm_dp_aux_register() has been
330da68386dSThomas Zimmermann * called.
331da68386dSThomas Zimmermann *
332da68386dSThomas Zimmermann * It should be set to the &drm_device that will be using this AUX
333da68386dSThomas Zimmermann * channel as early as possible. For many graphics drivers this should
334da68386dSThomas Zimmermann * happen before drm_dp_aux_init(), however it's perfectly fine to set
335da68386dSThomas Zimmermann * this field later so long as it's assigned before calling
336da68386dSThomas Zimmermann * drm_dp_aux_register().
337da68386dSThomas Zimmermann */
338da68386dSThomas Zimmermann struct drm_device *drm_dev;
339da68386dSThomas Zimmermann
340da68386dSThomas Zimmermann /**
341da68386dSThomas Zimmermann * @crtc: backpointer to the crtc that is currently using this
342da68386dSThomas Zimmermann * AUX channel
343da68386dSThomas Zimmermann */
344da68386dSThomas Zimmermann struct drm_crtc *crtc;
345da68386dSThomas Zimmermann
346da68386dSThomas Zimmermann /**
347da68386dSThomas Zimmermann * @hw_mutex: internal mutex used for locking transfers.
348da68386dSThomas Zimmermann *
349da68386dSThomas Zimmermann * Note that if the underlying hardware is shared among multiple
350da68386dSThomas Zimmermann * channels, the driver needs to do additional locking to
351da68386dSThomas Zimmermann * prevent concurrent access.
352da68386dSThomas Zimmermann */
353da68386dSThomas Zimmermann struct mutex hw_mutex;
354da68386dSThomas Zimmermann
355da68386dSThomas Zimmermann /**
356da68386dSThomas Zimmermann * @crc_work: worker that captures CRCs for each frame
357da68386dSThomas Zimmermann */
358da68386dSThomas Zimmermann struct work_struct crc_work;
359da68386dSThomas Zimmermann
360da68386dSThomas Zimmermann /**
361da68386dSThomas Zimmermann * @crc_count: counter of captured frame CRCs
362da68386dSThomas Zimmermann */
363da68386dSThomas Zimmermann u8 crc_count;
364da68386dSThomas Zimmermann
365da68386dSThomas Zimmermann /**
366da68386dSThomas Zimmermann * @transfer: transfers a message representing a single AUX
367da68386dSThomas Zimmermann * transaction.
368da68386dSThomas Zimmermann *
369da68386dSThomas Zimmermann * This is a hardware-specific implementation of how
370da68386dSThomas Zimmermann * transactions are executed that the drivers must provide.
371da68386dSThomas Zimmermann *
372da68386dSThomas Zimmermann * A pointer to a &drm_dp_aux_msg structure describing the
373da68386dSThomas Zimmermann * transaction is passed into this function. Upon success, the
374da68386dSThomas Zimmermann * implementation should return the number of payload bytes that
375da68386dSThomas Zimmermann * were transferred, or a negative error-code on failure.
376da68386dSThomas Zimmermann *
377da68386dSThomas Zimmermann * Helpers will propagate these errors, with the exception of
378da68386dSThomas Zimmermann * the %-EBUSY error, which causes a transaction to be retried.
379da68386dSThomas Zimmermann * On a short, helpers will return %-EPROTO to make it simpler
380da68386dSThomas Zimmermann * to check for failure.
381da68386dSThomas Zimmermann *
382da68386dSThomas Zimmermann * The @transfer() function must only modify the reply field of
383da68386dSThomas Zimmermann * the &drm_dp_aux_msg structure. The retry logic and i2c
384da68386dSThomas Zimmermann * helpers assume this is the case.
385da68386dSThomas Zimmermann *
386da68386dSThomas Zimmermann * Also note that this callback can be called no matter the
38769ef4a19SDouglas Anderson * state @dev is in and also no matter what state the panel is
38869ef4a19SDouglas Anderson * in. It's expected:
3897d188c52SDouglas Anderson *
39069ef4a19SDouglas Anderson * - If the @dev providing the AUX bus is currently unpowered then
39169ef4a19SDouglas Anderson * it will power itself up for the transfer.
3927d188c52SDouglas Anderson *
39369ef4a19SDouglas Anderson * - If we're on eDP (using a drm_panel) and the panel is not in a
39469ef4a19SDouglas Anderson * state where it can respond (it's not powered or it's in a
39569ef4a19SDouglas Anderson * low power state) then this function may return an error, but
39669ef4a19SDouglas Anderson * not crash. It's up to the caller of this code to make sure that
39769ef4a19SDouglas Anderson * the panel is powered on if getting an error back is not OK. If a
39869ef4a19SDouglas Anderson * drm_panel driver is initiating a DP AUX transfer it may power
39969ef4a19SDouglas Anderson * itself up however it wants. All other code should ensure that
40069ef4a19SDouglas Anderson * the pre_enable() bridge chain (which eventually calls the
40169ef4a19SDouglas Anderson * drm_panel prepare function) has powered the panel.
402da68386dSThomas Zimmermann */
403da68386dSThomas Zimmermann ssize_t (*transfer)(struct drm_dp_aux *aux,
404da68386dSThomas Zimmermann struct drm_dp_aux_msg *msg);
405da68386dSThomas Zimmermann
406da68386dSThomas Zimmermann /**
407841d742fSDouglas Anderson * @wait_hpd_asserted: wait for HPD to be asserted
408841d742fSDouglas Anderson *
409841d742fSDouglas Anderson * This is mainly useful for eDP panels drivers to wait for an eDP
410841d742fSDouglas Anderson * panel to finish powering on. This is an optional function.
411841d742fSDouglas Anderson *
412841d742fSDouglas Anderson * This function will efficiently wait for the HPD signal to be
413841d742fSDouglas Anderson * asserted. The `wait_us` parameter that is passed in says that we
414841d742fSDouglas Anderson * know that the HPD signal is expected to be asserted within `wait_us`
415841d742fSDouglas Anderson * microseconds. This function could wait for longer than `wait_us` if
416841d742fSDouglas Anderson * the logic in the DP controller has a long debouncing time. The
417841d742fSDouglas Anderson * important thing is that if this function returns success that the
418841d742fSDouglas Anderson * DP controller is ready to send AUX transactions.
419841d742fSDouglas Anderson *
420841d742fSDouglas Anderson * This function returns 0 if HPD was asserted or -ETIMEDOUT if time
421841d742fSDouglas Anderson * expired and HPD wasn't asserted. This function should not print
422841d742fSDouglas Anderson * timeout errors to the log.
423841d742fSDouglas Anderson *
424841d742fSDouglas Anderson * The semantics of this function are designed to match the
425841d742fSDouglas Anderson * readx_poll_timeout() function. That means a `wait_us` of 0 means
426841d742fSDouglas Anderson * to wait forever. Like readx_poll_timeout(), this function may sleep.
427841d742fSDouglas Anderson *
428841d742fSDouglas Anderson * NOTE: this function specifically reports the state of the HPD pin
429841d742fSDouglas Anderson * that's associated with the DP AUX channel. This is different from
430841d742fSDouglas Anderson * the HPD concept in much of the rest of DRM which is more about
431841d742fSDouglas Anderson * physical presence of a display. For eDP, for instance, a display is
432841d742fSDouglas Anderson * assumed always present even if the HPD pin is deasserted.
433841d742fSDouglas Anderson */
434841d742fSDouglas Anderson int (*wait_hpd_asserted)(struct drm_dp_aux *aux, unsigned long wait_us);
435841d742fSDouglas Anderson
436841d742fSDouglas Anderson /**
437da68386dSThomas Zimmermann * @i2c_nack_count: Counts I2C NACKs, used for DP validation.
438da68386dSThomas Zimmermann */
439da68386dSThomas Zimmermann unsigned i2c_nack_count;
440da68386dSThomas Zimmermann /**
441da68386dSThomas Zimmermann * @i2c_defer_count: Counts I2C DEFERs, used for DP validation.
442da68386dSThomas Zimmermann */
443da68386dSThomas Zimmermann unsigned i2c_defer_count;
444da68386dSThomas Zimmermann /**
445da68386dSThomas Zimmermann * @cec: struct containing fields used for CEC-Tunneling-over-AUX.
446da68386dSThomas Zimmermann */
447da68386dSThomas Zimmermann struct drm_dp_aux_cec cec;
448da68386dSThomas Zimmermann /**
449da68386dSThomas Zimmermann * @is_remote: Is this AUX CH actually using sideband messaging.
450da68386dSThomas Zimmermann */
451da68386dSThomas Zimmermann bool is_remote;
452*9429b12dSDouglas Anderson
453*9429b12dSDouglas Anderson /**
454*9429b12dSDouglas Anderson * @powered_down: If true then the remote endpoint is powered down.
455*9429b12dSDouglas Anderson */
456*9429b12dSDouglas Anderson bool powered_down;
457da68386dSThomas Zimmermann };
458da68386dSThomas Zimmermann
459da68386dSThomas Zimmermann int drm_dp_dpcd_probe(struct drm_dp_aux *aux, unsigned int offset);
460*9429b12dSDouglas Anderson void drm_dp_dpcd_set_powered(struct drm_dp_aux *aux, bool powered);
461da68386dSThomas Zimmermann ssize_t drm_dp_dpcd_read(struct drm_dp_aux *aux, unsigned int offset,
462da68386dSThomas Zimmermann void *buffer, size_t size);
463da68386dSThomas Zimmermann ssize_t drm_dp_dpcd_write(struct drm_dp_aux *aux, unsigned int offset,
464da68386dSThomas Zimmermann void *buffer, size_t size);
465da68386dSThomas Zimmermann
466da68386dSThomas Zimmermann /**
467da68386dSThomas Zimmermann * drm_dp_dpcd_readb() - read a single byte from the DPCD
468da68386dSThomas Zimmermann * @aux: DisplayPort AUX channel
469da68386dSThomas Zimmermann * @offset: address of the register to read
470da68386dSThomas Zimmermann * @valuep: location where the value of the register will be stored
471da68386dSThomas Zimmermann *
472da68386dSThomas Zimmermann * Returns the number of bytes transferred (1) on success, or a negative
473da68386dSThomas Zimmermann * error code on failure.
474da68386dSThomas Zimmermann */
drm_dp_dpcd_readb(struct drm_dp_aux * aux,unsigned int offset,u8 * valuep)475da68386dSThomas Zimmermann static inline ssize_t drm_dp_dpcd_readb(struct drm_dp_aux *aux,
476da68386dSThomas Zimmermann unsigned int offset, u8 *valuep)
477da68386dSThomas Zimmermann {
478da68386dSThomas Zimmermann return drm_dp_dpcd_read(aux, offset, valuep, 1);
479da68386dSThomas Zimmermann }
480da68386dSThomas Zimmermann
481da68386dSThomas Zimmermann /**
482da68386dSThomas Zimmermann * drm_dp_dpcd_writeb() - write a single byte to the DPCD
483da68386dSThomas Zimmermann * @aux: DisplayPort AUX channel
484da68386dSThomas Zimmermann * @offset: address of the register to write
485da68386dSThomas Zimmermann * @value: value to write to the register
486da68386dSThomas Zimmermann *
487da68386dSThomas Zimmermann * Returns the number of bytes transferred (1) on success, or a negative
488da68386dSThomas Zimmermann * error code on failure.
489da68386dSThomas Zimmermann */
drm_dp_dpcd_writeb(struct drm_dp_aux * aux,unsigned int offset,u8 value)490da68386dSThomas Zimmermann static inline ssize_t drm_dp_dpcd_writeb(struct drm_dp_aux *aux,
491da68386dSThomas Zimmermann unsigned int offset, u8 value)
492da68386dSThomas Zimmermann {
493da68386dSThomas Zimmermann return drm_dp_dpcd_write(aux, offset, &value, 1);
494da68386dSThomas Zimmermann }
495da68386dSThomas Zimmermann
496da68386dSThomas Zimmermann int drm_dp_read_dpcd_caps(struct drm_dp_aux *aux,
497da68386dSThomas Zimmermann u8 dpcd[DP_RECEIVER_CAP_SIZE]);
498da68386dSThomas Zimmermann
499da68386dSThomas Zimmermann int drm_dp_dpcd_read_link_status(struct drm_dp_aux *aux,
500da68386dSThomas Zimmermann u8 status[DP_LINK_STATUS_SIZE]);
501da68386dSThomas Zimmermann
502da68386dSThomas Zimmermann int drm_dp_dpcd_read_phy_link_status(struct drm_dp_aux *aux,
503da68386dSThomas Zimmermann enum drm_dp_phy dp_phy,
504da68386dSThomas Zimmermann u8 link_status[DP_LINK_STATUS_SIZE]);
505da68386dSThomas Zimmermann
506da68386dSThomas Zimmermann bool drm_dp_send_real_edid_checksum(struct drm_dp_aux *aux,
507da68386dSThomas Zimmermann u8 real_edid_checksum);
508da68386dSThomas Zimmermann
509da68386dSThomas Zimmermann int drm_dp_read_downstream_info(struct drm_dp_aux *aux,
510da68386dSThomas Zimmermann const u8 dpcd[DP_RECEIVER_CAP_SIZE],
511da68386dSThomas Zimmermann u8 downstream_ports[DP_MAX_DOWNSTREAM_PORTS]);
512da68386dSThomas Zimmermann bool drm_dp_downstream_is_type(const u8 dpcd[DP_RECEIVER_CAP_SIZE],
513da68386dSThomas Zimmermann const u8 port_cap[4], u8 type);
514da68386dSThomas Zimmermann bool drm_dp_downstream_is_tmds(const u8 dpcd[DP_RECEIVER_CAP_SIZE],
515da68386dSThomas Zimmermann const u8 port_cap[4],
516da68386dSThomas Zimmermann const struct edid *edid);
517da68386dSThomas Zimmermann int drm_dp_downstream_max_dotclock(const u8 dpcd[DP_RECEIVER_CAP_SIZE],
518da68386dSThomas Zimmermann const u8 port_cap[4]);
519da68386dSThomas Zimmermann int drm_dp_downstream_max_tmds_clock(const u8 dpcd[DP_RECEIVER_CAP_SIZE],
520da68386dSThomas Zimmermann const u8 port_cap[4],
521da68386dSThomas Zimmermann const struct edid *edid);
522da68386dSThomas Zimmermann int drm_dp_downstream_min_tmds_clock(const u8 dpcd[DP_RECEIVER_CAP_SIZE],
523da68386dSThomas Zimmermann const u8 port_cap[4],
524da68386dSThomas Zimmermann const struct edid *edid);
525da68386dSThomas Zimmermann int drm_dp_downstream_max_bpc(const u8 dpcd[DP_RECEIVER_CAP_SIZE],
526da68386dSThomas Zimmermann const u8 port_cap[4],
527da68386dSThomas Zimmermann const struct edid *edid);
528da68386dSThomas Zimmermann bool drm_dp_downstream_420_passthrough(const u8 dpcd[DP_RECEIVER_CAP_SIZE],
529da68386dSThomas Zimmermann const u8 port_cap[4]);
530da68386dSThomas Zimmermann bool drm_dp_downstream_444_to_420_conversion(const u8 dpcd[DP_RECEIVER_CAP_SIZE],
531da68386dSThomas Zimmermann const u8 port_cap[4]);
532da68386dSThomas Zimmermann struct drm_display_mode *drm_dp_downstream_mode(struct drm_device *dev,
533da68386dSThomas Zimmermann const u8 dpcd[DP_RECEIVER_CAP_SIZE],
534da68386dSThomas Zimmermann const u8 port_cap[4]);
535da68386dSThomas Zimmermann int drm_dp_downstream_id(struct drm_dp_aux *aux, char id[6]);
536da68386dSThomas Zimmermann void drm_dp_downstream_debug(struct seq_file *m,
537da68386dSThomas Zimmermann const u8 dpcd[DP_RECEIVER_CAP_SIZE],
538da68386dSThomas Zimmermann const u8 port_cap[4],
539da68386dSThomas Zimmermann const struct edid *edid,
540da68386dSThomas Zimmermann struct drm_dp_aux *aux);
541da68386dSThomas Zimmermann enum drm_mode_subconnector
542da68386dSThomas Zimmermann drm_dp_subconnector_type(const u8 dpcd[DP_RECEIVER_CAP_SIZE],
543da68386dSThomas Zimmermann const u8 port_cap[4]);
544da68386dSThomas Zimmermann void drm_dp_set_subconnector_property(struct drm_connector *connector,
545da68386dSThomas Zimmermann enum drm_connector_status status,
546da68386dSThomas Zimmermann const u8 *dpcd,
547da68386dSThomas Zimmermann const u8 port_cap[4]);
548da68386dSThomas Zimmermann
549da68386dSThomas Zimmermann struct drm_dp_desc;
550da68386dSThomas Zimmermann bool drm_dp_read_sink_count_cap(struct drm_connector *connector,
551da68386dSThomas Zimmermann const u8 dpcd[DP_RECEIVER_CAP_SIZE],
552da68386dSThomas Zimmermann const struct drm_dp_desc *desc);
553da68386dSThomas Zimmermann int drm_dp_read_sink_count(struct drm_dp_aux *aux);
554da68386dSThomas Zimmermann
555da68386dSThomas Zimmermann int drm_dp_read_lttpr_common_caps(struct drm_dp_aux *aux,
556da68386dSThomas Zimmermann const u8 dpcd[DP_RECEIVER_CAP_SIZE],
557da68386dSThomas Zimmermann u8 caps[DP_LTTPR_COMMON_CAP_SIZE]);
558da68386dSThomas Zimmermann int drm_dp_read_lttpr_phy_caps(struct drm_dp_aux *aux,
559da68386dSThomas Zimmermann const u8 dpcd[DP_RECEIVER_CAP_SIZE],
560da68386dSThomas Zimmermann enum drm_dp_phy dp_phy,
561da68386dSThomas Zimmermann u8 caps[DP_LTTPR_PHY_CAP_SIZE]);
562da68386dSThomas Zimmermann int drm_dp_lttpr_count(const u8 cap[DP_LTTPR_COMMON_CAP_SIZE]);
563da68386dSThomas Zimmermann int drm_dp_lttpr_max_link_rate(const u8 caps[DP_LTTPR_COMMON_CAP_SIZE]);
564da68386dSThomas Zimmermann int drm_dp_lttpr_max_lane_count(const u8 caps[DP_LTTPR_COMMON_CAP_SIZE]);
565da68386dSThomas Zimmermann bool drm_dp_lttpr_voltage_swing_level_3_supported(const u8 caps[DP_LTTPR_PHY_CAP_SIZE]);
566da68386dSThomas Zimmermann bool drm_dp_lttpr_pre_emphasis_level_3_supported(const u8 caps[DP_LTTPR_PHY_CAP_SIZE]);
567da68386dSThomas Zimmermann
568da68386dSThomas Zimmermann void drm_dp_remote_aux_init(struct drm_dp_aux *aux);
569da68386dSThomas Zimmermann void drm_dp_aux_init(struct drm_dp_aux *aux);
570da68386dSThomas Zimmermann int drm_dp_aux_register(struct drm_dp_aux *aux);
571da68386dSThomas Zimmermann void drm_dp_aux_unregister(struct drm_dp_aux *aux);
572da68386dSThomas Zimmermann
573da68386dSThomas Zimmermann int drm_dp_start_crc(struct drm_dp_aux *aux, struct drm_crtc *crtc);
574da68386dSThomas Zimmermann int drm_dp_stop_crc(struct drm_dp_aux *aux);
575da68386dSThomas Zimmermann
576da68386dSThomas Zimmermann struct drm_dp_dpcd_ident {
577da68386dSThomas Zimmermann u8 oui[3];
578da68386dSThomas Zimmermann u8 device_id[6];
579da68386dSThomas Zimmermann u8 hw_rev;
580da68386dSThomas Zimmermann u8 sw_major_rev;
581da68386dSThomas Zimmermann u8 sw_minor_rev;
582da68386dSThomas Zimmermann } __packed;
583da68386dSThomas Zimmermann
584da68386dSThomas Zimmermann /**
585da68386dSThomas Zimmermann * struct drm_dp_desc - DP branch/sink device descriptor
586da68386dSThomas Zimmermann * @ident: DP device identification from DPCD 0x400 (sink) or 0x500 (branch).
587da68386dSThomas Zimmermann * @quirks: Quirks; use drm_dp_has_quirk() to query for the quirks.
588da68386dSThomas Zimmermann */
589da68386dSThomas Zimmermann struct drm_dp_desc {
590da68386dSThomas Zimmermann struct drm_dp_dpcd_ident ident;
591da68386dSThomas Zimmermann u32 quirks;
592da68386dSThomas Zimmermann };
593da68386dSThomas Zimmermann
594da68386dSThomas Zimmermann int drm_dp_read_desc(struct drm_dp_aux *aux, struct drm_dp_desc *desc,
595da68386dSThomas Zimmermann bool is_branch);
596da68386dSThomas Zimmermann
597da68386dSThomas Zimmermann /**
598da68386dSThomas Zimmermann * enum drm_dp_quirk - Display Port sink/branch device specific quirks
599da68386dSThomas Zimmermann *
600da68386dSThomas Zimmermann * Display Port sink and branch devices in the wild have a variety of bugs, try
601da68386dSThomas Zimmermann * to collect them here. The quirks are shared, but it's up to the drivers to
602da68386dSThomas Zimmermann * implement workarounds for them.
603da68386dSThomas Zimmermann */
604da68386dSThomas Zimmermann enum drm_dp_quirk {
605da68386dSThomas Zimmermann /**
606da68386dSThomas Zimmermann * @DP_DPCD_QUIRK_CONSTANT_N:
607da68386dSThomas Zimmermann *
608da68386dSThomas Zimmermann * The device requires main link attributes Mvid and Nvid to be limited
609da68386dSThomas Zimmermann * to 16 bits. So will give a constant value (0x8000) for compatability.
610da68386dSThomas Zimmermann */
611da68386dSThomas Zimmermann DP_DPCD_QUIRK_CONSTANT_N,
612da68386dSThomas Zimmermann /**
613da68386dSThomas Zimmermann * @DP_DPCD_QUIRK_NO_PSR:
614da68386dSThomas Zimmermann *
615da68386dSThomas Zimmermann * The device does not support PSR even if reports that it supports or
616da68386dSThomas Zimmermann * driver still need to implement proper handling for such device.
617da68386dSThomas Zimmermann */
618da68386dSThomas Zimmermann DP_DPCD_QUIRK_NO_PSR,
619da68386dSThomas Zimmermann /**
620da68386dSThomas Zimmermann * @DP_DPCD_QUIRK_NO_SINK_COUNT:
621da68386dSThomas Zimmermann *
622da68386dSThomas Zimmermann * The device does not set SINK_COUNT to a non-zero value.
623da68386dSThomas Zimmermann * The driver should ignore SINK_COUNT during detection. Note that
624da68386dSThomas Zimmermann * drm_dp_read_sink_count_cap() automatically checks for this quirk.
625da68386dSThomas Zimmermann */
626da68386dSThomas Zimmermann DP_DPCD_QUIRK_NO_SINK_COUNT,
627da68386dSThomas Zimmermann /**
628da68386dSThomas Zimmermann * @DP_DPCD_QUIRK_DSC_WITHOUT_VIRTUAL_DPCD:
629da68386dSThomas Zimmermann *
630da68386dSThomas Zimmermann * The device supports MST DSC despite not supporting Virtual DPCD.
631da68386dSThomas Zimmermann * The DSC caps can be read from the physical aux instead.
632da68386dSThomas Zimmermann */
633da68386dSThomas Zimmermann DP_DPCD_QUIRK_DSC_WITHOUT_VIRTUAL_DPCD,
634da68386dSThomas Zimmermann /**
635da68386dSThomas Zimmermann * @DP_DPCD_QUIRK_CAN_DO_MAX_LINK_RATE_3_24_GBPS:
636da68386dSThomas Zimmermann *
637da68386dSThomas Zimmermann * The device supports a link rate of 3.24 Gbps (multiplier 0xc) despite
638da68386dSThomas Zimmermann * the DP_MAX_LINK_RATE register reporting a lower max multiplier.
639da68386dSThomas Zimmermann */
640da68386dSThomas Zimmermann DP_DPCD_QUIRK_CAN_DO_MAX_LINK_RATE_3_24_GBPS,
641da68386dSThomas Zimmermann };
642da68386dSThomas Zimmermann
643da68386dSThomas Zimmermann /**
644da68386dSThomas Zimmermann * drm_dp_has_quirk() - does the DP device have a specific quirk
645da68386dSThomas Zimmermann * @desc: Device descriptor filled by drm_dp_read_desc()
646da68386dSThomas Zimmermann * @quirk: Quirk to query for
647da68386dSThomas Zimmermann *
648da68386dSThomas Zimmermann * Return true if DP device identified by @desc has @quirk.
649da68386dSThomas Zimmermann */
650da68386dSThomas Zimmermann static inline bool
drm_dp_has_quirk(const struct drm_dp_desc * desc,enum drm_dp_quirk quirk)651da68386dSThomas Zimmermann drm_dp_has_quirk(const struct drm_dp_desc *desc, enum drm_dp_quirk quirk)
652da68386dSThomas Zimmermann {
653da68386dSThomas Zimmermann return desc->quirks & BIT(quirk);
654da68386dSThomas Zimmermann }
655da68386dSThomas Zimmermann
656da68386dSThomas Zimmermann /**
657da68386dSThomas Zimmermann * struct drm_edp_backlight_info - Probed eDP backlight info struct
658da68386dSThomas Zimmermann * @pwmgen_bit_count: The pwmgen bit count
659da68386dSThomas Zimmermann * @pwm_freq_pre_divider: The PWM frequency pre-divider value being used for this backlight, if any
660da68386dSThomas Zimmermann * @max: The maximum backlight level that may be set
661da68386dSThomas Zimmermann * @lsb_reg_used: Do we also write values to the DP_EDP_BACKLIGHT_BRIGHTNESS_LSB register?
662da68386dSThomas Zimmermann * @aux_enable: Does the panel support the AUX enable cap?
663da68386dSThomas Zimmermann * @aux_set: Does the panel support setting the brightness through AUX?
664da68386dSThomas Zimmermann *
665da68386dSThomas Zimmermann * This structure contains various data about an eDP backlight, which can be populated by using
666da68386dSThomas Zimmermann * drm_edp_backlight_init().
667da68386dSThomas Zimmermann */
668da68386dSThomas Zimmermann struct drm_edp_backlight_info {
669da68386dSThomas Zimmermann u8 pwmgen_bit_count;
670da68386dSThomas Zimmermann u8 pwm_freq_pre_divider;
671da68386dSThomas Zimmermann u16 max;
672da68386dSThomas Zimmermann
673da68386dSThomas Zimmermann bool lsb_reg_used : 1;
674da68386dSThomas Zimmermann bool aux_enable : 1;
675da68386dSThomas Zimmermann bool aux_set : 1;
676da68386dSThomas Zimmermann };
677da68386dSThomas Zimmermann
678da68386dSThomas Zimmermann int
679da68386dSThomas Zimmermann drm_edp_backlight_init(struct drm_dp_aux *aux, struct drm_edp_backlight_info *bl,
680da68386dSThomas Zimmermann u16 driver_pwm_freq_hz, const u8 edp_dpcd[EDP_DISPLAY_CTL_CAP_SIZE],
681da68386dSThomas Zimmermann u16 *current_level, u8 *current_mode);
682da68386dSThomas Zimmermann int drm_edp_backlight_set_level(struct drm_dp_aux *aux, const struct drm_edp_backlight_info *bl,
683da68386dSThomas Zimmermann u16 level);
684da68386dSThomas Zimmermann int drm_edp_backlight_enable(struct drm_dp_aux *aux, const struct drm_edp_backlight_info *bl,
685da68386dSThomas Zimmermann u16 level);
686da68386dSThomas Zimmermann int drm_edp_backlight_disable(struct drm_dp_aux *aux, const struct drm_edp_backlight_info *bl);
687da68386dSThomas Zimmermann
688da68386dSThomas Zimmermann #if IS_ENABLED(CONFIG_DRM_KMS_HELPER) && (IS_BUILTIN(CONFIG_BACKLIGHT_CLASS_DEVICE) || \
689da68386dSThomas Zimmermann (IS_MODULE(CONFIG_DRM_KMS_HELPER) && IS_MODULE(CONFIG_BACKLIGHT_CLASS_DEVICE)))
690da68386dSThomas Zimmermann
691da68386dSThomas Zimmermann int drm_panel_dp_aux_backlight(struct drm_panel *panel, struct drm_dp_aux *aux);
692da68386dSThomas Zimmermann
693da68386dSThomas Zimmermann #else
694da68386dSThomas Zimmermann
drm_panel_dp_aux_backlight(struct drm_panel * panel,struct drm_dp_aux * aux)695da68386dSThomas Zimmermann static inline int drm_panel_dp_aux_backlight(struct drm_panel *panel,
696da68386dSThomas Zimmermann struct drm_dp_aux *aux)
697da68386dSThomas Zimmermann {
698da68386dSThomas Zimmermann return 0;
699da68386dSThomas Zimmermann }
700da68386dSThomas Zimmermann
701da68386dSThomas Zimmermann #endif
702da68386dSThomas Zimmermann
703da68386dSThomas Zimmermann #ifdef CONFIG_DRM_DP_CEC
704da68386dSThomas Zimmermann void drm_dp_cec_irq(struct drm_dp_aux *aux);
705da68386dSThomas Zimmermann void drm_dp_cec_register_connector(struct drm_dp_aux *aux,
706da68386dSThomas Zimmermann struct drm_connector *connector);
707da68386dSThomas Zimmermann void drm_dp_cec_unregister_connector(struct drm_dp_aux *aux);
708da68386dSThomas Zimmermann void drm_dp_cec_set_edid(struct drm_dp_aux *aux, const struct edid *edid);
709da68386dSThomas Zimmermann void drm_dp_cec_unset_edid(struct drm_dp_aux *aux);
710da68386dSThomas Zimmermann #else
drm_dp_cec_irq(struct drm_dp_aux * aux)711da68386dSThomas Zimmermann static inline void drm_dp_cec_irq(struct drm_dp_aux *aux)
712da68386dSThomas Zimmermann {
713da68386dSThomas Zimmermann }
714da68386dSThomas Zimmermann
715da68386dSThomas Zimmermann static inline void
drm_dp_cec_register_connector(struct drm_dp_aux * aux,struct drm_connector * connector)716da68386dSThomas Zimmermann drm_dp_cec_register_connector(struct drm_dp_aux *aux,
717da68386dSThomas Zimmermann struct drm_connector *connector)
718da68386dSThomas Zimmermann {
719da68386dSThomas Zimmermann }
720da68386dSThomas Zimmermann
drm_dp_cec_unregister_connector(struct drm_dp_aux * aux)721da68386dSThomas Zimmermann static inline void drm_dp_cec_unregister_connector(struct drm_dp_aux *aux)
722da68386dSThomas Zimmermann {
723da68386dSThomas Zimmermann }
724da68386dSThomas Zimmermann
drm_dp_cec_set_edid(struct drm_dp_aux * aux,const struct edid * edid)725da68386dSThomas Zimmermann static inline void drm_dp_cec_set_edid(struct drm_dp_aux *aux,
726da68386dSThomas Zimmermann const struct edid *edid)
727da68386dSThomas Zimmermann {
728da68386dSThomas Zimmermann }
729da68386dSThomas Zimmermann
drm_dp_cec_unset_edid(struct drm_dp_aux * aux)730da68386dSThomas Zimmermann static inline void drm_dp_cec_unset_edid(struct drm_dp_aux *aux)
731da68386dSThomas Zimmermann {
732da68386dSThomas Zimmermann }
733da68386dSThomas Zimmermann
734da68386dSThomas Zimmermann #endif
735da68386dSThomas Zimmermann
736da68386dSThomas Zimmermann /**
737da68386dSThomas Zimmermann * struct drm_dp_phy_test_params - DP Phy Compliance parameters
738da68386dSThomas Zimmermann * @link_rate: Requested Link rate from DPCD 0x219
739da68386dSThomas Zimmermann * @num_lanes: Number of lanes requested by sing through DPCD 0x220
740da68386dSThomas Zimmermann * @phy_pattern: DP Phy test pattern from DPCD 0x248
741da68386dSThomas Zimmermann * @hbr2_reset: DP HBR2_COMPLIANCE_SCRAMBLER_RESET from DCPD 0x24A and 0x24B
742da68386dSThomas Zimmermann * @custom80: DP Test_80BIT_CUSTOM_PATTERN from DPCDs 0x250 through 0x259
743da68386dSThomas Zimmermann * @enhanced_frame_cap: flag for enhanced frame capability.
744da68386dSThomas Zimmermann */
745da68386dSThomas Zimmermann struct drm_dp_phy_test_params {
746da68386dSThomas Zimmermann int link_rate;
747da68386dSThomas Zimmermann u8 num_lanes;
748da68386dSThomas Zimmermann u8 phy_pattern;
749da68386dSThomas Zimmermann u8 hbr2_reset[2];
750da68386dSThomas Zimmermann u8 custom80[10];
751da68386dSThomas Zimmermann bool enhanced_frame_cap;
752da68386dSThomas Zimmermann };
753da68386dSThomas Zimmermann
754da68386dSThomas Zimmermann int drm_dp_get_phy_test_pattern(struct drm_dp_aux *aux,
755da68386dSThomas Zimmermann struct drm_dp_phy_test_params *data);
756da68386dSThomas Zimmermann int drm_dp_set_phy_test_pattern(struct drm_dp_aux *aux,
757da68386dSThomas Zimmermann struct drm_dp_phy_test_params *data, u8 dp_rev);
758da68386dSThomas Zimmermann int drm_dp_get_pcon_max_frl_bw(const u8 dpcd[DP_RECEIVER_CAP_SIZE],
759da68386dSThomas Zimmermann const u8 port_cap[4]);
760da68386dSThomas Zimmermann int drm_dp_pcon_frl_prepare(struct drm_dp_aux *aux, bool enable_frl_ready_hpd);
761da68386dSThomas Zimmermann bool drm_dp_pcon_is_frl_ready(struct drm_dp_aux *aux);
762da68386dSThomas Zimmermann int drm_dp_pcon_frl_configure_1(struct drm_dp_aux *aux, int max_frl_gbps,
763da68386dSThomas Zimmermann u8 frl_mode);
764da68386dSThomas Zimmermann int drm_dp_pcon_frl_configure_2(struct drm_dp_aux *aux, int max_frl_mask,
765da68386dSThomas Zimmermann u8 frl_type);
766da68386dSThomas Zimmermann int drm_dp_pcon_reset_frl_config(struct drm_dp_aux *aux);
767da68386dSThomas Zimmermann int drm_dp_pcon_frl_enable(struct drm_dp_aux *aux);
768da68386dSThomas Zimmermann
769da68386dSThomas Zimmermann bool drm_dp_pcon_hdmi_link_active(struct drm_dp_aux *aux);
770da68386dSThomas Zimmermann int drm_dp_pcon_hdmi_link_mode(struct drm_dp_aux *aux, u8 *frl_trained_mask);
771da68386dSThomas Zimmermann void drm_dp_pcon_hdmi_frl_link_error_count(struct drm_dp_aux *aux,
772da68386dSThomas Zimmermann struct drm_connector *connector);
773da68386dSThomas Zimmermann bool drm_dp_pcon_enc_is_dsc_1_2(const u8 pcon_dsc_dpcd[DP_PCON_DSC_ENCODER_CAP_SIZE]);
774da68386dSThomas Zimmermann int drm_dp_pcon_dsc_max_slices(const u8 pcon_dsc_dpcd[DP_PCON_DSC_ENCODER_CAP_SIZE]);
775da68386dSThomas Zimmermann int drm_dp_pcon_dsc_max_slice_width(const u8 pcon_dsc_dpcd[DP_PCON_DSC_ENCODER_CAP_SIZE]);
776da68386dSThomas Zimmermann int drm_dp_pcon_dsc_bpp_incr(const u8 pcon_dsc_dpcd[DP_PCON_DSC_ENCODER_CAP_SIZE]);
777da68386dSThomas Zimmermann int drm_dp_pcon_pps_default(struct drm_dp_aux *aux);
778da68386dSThomas Zimmermann int drm_dp_pcon_pps_override_buf(struct drm_dp_aux *aux, u8 pps_buf[128]);
779da68386dSThomas Zimmermann int drm_dp_pcon_pps_override_param(struct drm_dp_aux *aux, u8 pps_param[6]);
780da68386dSThomas Zimmermann bool drm_dp_downstream_rgb_to_ycbcr_conversion(const u8 dpcd[DP_RECEIVER_CAP_SIZE],
781da68386dSThomas Zimmermann const u8 port_cap[4], u8 color_spc);
782da68386dSThomas Zimmermann int drm_dp_pcon_convert_rgb_to_ycbcr(struct drm_dp_aux *aux, u8 color_spc);
783da68386dSThomas Zimmermann
784da68386dSThomas Zimmermann #endif /* _DRM_DP_HELPER_H_ */
785