1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23#ifndef _DRM_DP_HELPER_H_
24#define _DRM_DP_HELPER_H_
25
26#include <linux/delay.h>
27#include <linux/i2c.h>
28
29#include <drm/display/drm_dp.h>
30#include <drm/drm_connector.h>
31
32struct drm_device;
33struct drm_dp_aux;
34struct drm_panel;
35
36bool drm_dp_channel_eq_ok(const u8 link_status[DP_LINK_STATUS_SIZE],
37 int lane_count);
38bool drm_dp_clock_recovery_ok(const u8 link_status[DP_LINK_STATUS_SIZE],
39 int lane_count);
40u8 drm_dp_get_adjust_request_voltage(const u8 link_status[DP_LINK_STATUS_SIZE],
41 int lane);
42u8 drm_dp_get_adjust_request_pre_emphasis(const u8 link_status[DP_LINK_STATUS_SIZE],
43 int lane);
44u8 drm_dp_get_adjust_tx_ffe_preset(const u8 link_status[DP_LINK_STATUS_SIZE],
45 int lane);
46
47int drm_dp_read_clock_recovery_delay(struct drm_dp_aux *aux, const u8 dpcd[DP_RECEIVER_CAP_SIZE],
48 enum drm_dp_phy dp_phy, bool uhbr);
49int drm_dp_read_channel_eq_delay(struct drm_dp_aux *aux, const u8 dpcd[DP_RECEIVER_CAP_SIZE],
50 enum drm_dp_phy dp_phy, bool uhbr);
51
52void drm_dp_link_train_clock_recovery_delay(const struct drm_dp_aux *aux,
53 const u8 dpcd[DP_RECEIVER_CAP_SIZE]);
54void drm_dp_lttpr_link_train_clock_recovery_delay(void);
55void drm_dp_link_train_channel_eq_delay(const struct drm_dp_aux *aux,
56 const u8 dpcd[DP_RECEIVER_CAP_SIZE]);
57void drm_dp_lttpr_link_train_channel_eq_delay(const struct drm_dp_aux *aux,
58 const u8 caps[DP_LTTPR_PHY_CAP_SIZE]);
59
60int drm_dp_128b132b_read_aux_rd_interval(struct drm_dp_aux *aux);
61bool drm_dp_128b132b_lane_channel_eq_done(const u8 link_status[DP_LINK_STATUS_SIZE],
62 int lane_count);
63bool drm_dp_128b132b_lane_symbol_locked(const u8 link_status[DP_LINK_STATUS_SIZE],
64 int lane_count);
65bool drm_dp_128b132b_eq_interlane_align_done(const u8 link_status[DP_LINK_STATUS_SIZE]);
66bool drm_dp_128b132b_cds_interlane_align_done(const u8 link_status[DP_LINK_STATUS_SIZE]);
67bool drm_dp_128b132b_link_training_failed(const u8 link_status[DP_LINK_STATUS_SIZE]);
68
69u8 drm_dp_link_rate_to_bw_code(int link_rate);
70int drm_dp_bw_code_to_link_rate(u8 link_bw);
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88struct drm_dp_vsc_sdp {
89 unsigned char sdp_type;
90 unsigned char revision;
91 unsigned char length;
92 enum dp_pixelformat pixelformat;
93 enum dp_colorimetry colorimetry;
94 int bpc;
95 enum dp_dynamic_range dynamic_range;
96 enum dp_content_type content_type;
97};
98
99void drm_dp_vsc_sdp_log(const char *level, struct device *dev,
100 const struct drm_dp_vsc_sdp *vsc);
101
102int drm_dp_psr_setup_time(const u8 psr_cap[EDP_PSR_RECEIVER_CAP_SIZE]);
103
104static inline int
105drm_dp_max_link_rate(const u8 dpcd[DP_RECEIVER_CAP_SIZE])
106{
107 return drm_dp_bw_code_to_link_rate(dpcd[DP_MAX_LINK_RATE]);
108}
109
110static inline u8
111drm_dp_max_lane_count(const u8 dpcd[DP_RECEIVER_CAP_SIZE])
112{
113 return dpcd[DP_MAX_LANE_COUNT] & DP_MAX_LANE_COUNT_MASK;
114}
115
116static inline bool
117drm_dp_enhanced_frame_cap(const u8 dpcd[DP_RECEIVER_CAP_SIZE])
118{
119 return dpcd[DP_DPCD_REV] >= 0x11 &&
120 (dpcd[DP_MAX_LANE_COUNT] & DP_ENHANCED_FRAME_CAP);
121}
122
123static inline bool
124drm_dp_fast_training_cap(const u8 dpcd[DP_RECEIVER_CAP_SIZE])
125{
126 return dpcd[DP_DPCD_REV] >= 0x11 &&
127 (dpcd[DP_MAX_DOWNSPREAD] & DP_NO_AUX_HANDSHAKE_LINK_TRAINING);
128}
129
130static inline bool
131drm_dp_tps3_supported(const u8 dpcd[DP_RECEIVER_CAP_SIZE])
132{
133 return dpcd[DP_DPCD_REV] >= 0x12 &&
134 dpcd[DP_MAX_LANE_COUNT] & DP_TPS3_SUPPORTED;
135}
136
137static inline bool
138drm_dp_max_downspread(const u8 dpcd[DP_RECEIVER_CAP_SIZE])
139{
140 return dpcd[DP_DPCD_REV] >= 0x11 ||
141 dpcd[DP_MAX_DOWNSPREAD] & DP_MAX_DOWNSPREAD_0_5;
142}
143
144static inline bool
145drm_dp_tps4_supported(const u8 dpcd[DP_RECEIVER_CAP_SIZE])
146{
147 return dpcd[DP_DPCD_REV] >= 0x14 &&
148 dpcd[DP_MAX_DOWNSPREAD] & DP_TPS4_SUPPORTED;
149}
150
151static inline u8
152drm_dp_training_pattern_mask(const u8 dpcd[DP_RECEIVER_CAP_SIZE])
153{
154 return (dpcd[DP_DPCD_REV] >= 0x14) ? DP_TRAINING_PATTERN_MASK_1_4 :
155 DP_TRAINING_PATTERN_MASK;
156}
157
158static inline bool
159drm_dp_is_branch(const u8 dpcd[DP_RECEIVER_CAP_SIZE])
160{
161 return dpcd[DP_DOWNSTREAMPORT_PRESENT] & DP_DWN_STRM_PORT_PRESENT;
162}
163
164
165u8 drm_dp_dsc_sink_max_slice_count(const u8 dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE],
166 bool is_edp);
167u8 drm_dp_dsc_sink_line_buf_depth(const u8 dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE]);
168int drm_dp_dsc_sink_supported_input_bpcs(const u8 dsc_dpc[DP_DSC_RECEIVER_CAP_SIZE],
169 u8 dsc_bpc[3]);
170
171static inline bool
172drm_dp_sink_supports_dsc(const u8 dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE])
173{
174 return dsc_dpcd[DP_DSC_SUPPORT - DP_DSC_SUPPORT] &
175 DP_DSC_DECOMPRESSION_IS_SUPPORTED;
176}
177
178static inline u16
179drm_edp_dsc_sink_output_bpp(const u8 dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE])
180{
181 return dsc_dpcd[DP_DSC_MAX_BITS_PER_PIXEL_LOW - DP_DSC_SUPPORT] |
182 (dsc_dpcd[DP_DSC_MAX_BITS_PER_PIXEL_HI - DP_DSC_SUPPORT] &
183 DP_DSC_MAX_BITS_PER_PIXEL_HI_MASK <<
184 DP_DSC_MAX_BITS_PER_PIXEL_HI_SHIFT);
185}
186
187static inline u32
188drm_dp_dsc_sink_max_slice_width(const u8 dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE])
189{
190
191 return dsc_dpcd[DP_DSC_MAX_SLICE_WIDTH - DP_DSC_SUPPORT] *
192 DP_DSC_SLICE_WIDTH_MULTIPLIER;
193}
194
195
196static inline bool
197drm_dp_sink_supports_fec(const u8 fec_capable)
198{
199 return fec_capable & DP_FEC_CAPABLE;
200}
201
202static inline bool
203drm_dp_channel_coding_supported(const u8 dpcd[DP_RECEIVER_CAP_SIZE])
204{
205 return dpcd[DP_MAIN_LINK_CHANNEL_CODING] & DP_CAP_ANSI_8B10B;
206}
207
208static inline bool
209drm_dp_alternate_scrambler_reset_cap(const u8 dpcd[DP_RECEIVER_CAP_SIZE])
210{
211 return dpcd[DP_EDP_CONFIGURATION_CAP] &
212 DP_ALTERNATE_SCRAMBLER_RESET_CAP;
213}
214
215
216static inline bool
217drm_dp_sink_can_do_video_without_timing_msa(const u8 dpcd[DP_RECEIVER_CAP_SIZE])
218{
219 return dpcd[DP_DOWN_STREAM_PORT_COUNT] &
220 DP_MSA_TIMING_PAR_IGNORED;
221}
222
223
224
225
226
227
228
229
230
231
232
233
234static inline bool
235drm_edp_backlight_supported(const u8 edp_dpcd[EDP_DISPLAY_CTL_CAP_SIZE])
236{
237 return !!(edp_dpcd[1] & DP_EDP_TCON_BACKLIGHT_ADJUSTMENT_CAP);
238}
239
240
241
242
243
244
245
246
247
248
249
250
251
252struct drm_dp_aux_msg {
253 unsigned int address;
254 u8 request;
255 u8 reply;
256 void *buffer;
257 size_t size;
258};
259
260struct cec_adapter;
261struct edid;
262struct drm_connector;
263
264
265
266
267
268
269
270
271struct drm_dp_aux_cec {
272 struct mutex lock;
273 struct cec_adapter *adap;
274 struct drm_connector *connector;
275 struct delayed_work unregister_work;
276};
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291struct drm_dp_aux {
292
293
294
295
296
297
298
299 const char *name;
300
301
302
303
304
305 struct i2c_adapter ddc;
306
307
308
309
310
311 struct device *dev;
312
313
314
315
316
317
318
319
320
321
322
323
324 struct drm_device *drm_dev;
325
326
327
328
329
330 struct drm_crtc *crtc;
331
332
333
334
335
336
337
338
339 struct mutex hw_mutex;
340
341
342
343
344 struct work_struct crc_work;
345
346
347
348
349 u8 crc_count;
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377 ssize_t (*transfer)(struct drm_dp_aux *aux,
378 struct drm_dp_aux_msg *msg);
379
380
381
382
383 unsigned i2c_nack_count;
384
385
386
387 unsigned i2c_defer_count;
388
389
390
391 struct drm_dp_aux_cec cec;
392
393
394
395 bool is_remote;
396};
397
398int drm_dp_dpcd_probe(struct drm_dp_aux *aux, unsigned int offset);
399ssize_t drm_dp_dpcd_read(struct drm_dp_aux *aux, unsigned int offset,
400 void *buffer, size_t size);
401ssize_t drm_dp_dpcd_write(struct drm_dp_aux *aux, unsigned int offset,
402 void *buffer, size_t size);
403
404
405
406
407
408
409
410
411
412
413static inline ssize_t drm_dp_dpcd_readb(struct drm_dp_aux *aux,
414 unsigned int offset, u8 *valuep)
415{
416 return drm_dp_dpcd_read(aux, offset, valuep, 1);
417}
418
419
420
421
422
423
424
425
426
427
428static inline ssize_t drm_dp_dpcd_writeb(struct drm_dp_aux *aux,
429 unsigned int offset, u8 value)
430{
431 return drm_dp_dpcd_write(aux, offset, &value, 1);
432}
433
434int drm_dp_read_dpcd_caps(struct drm_dp_aux *aux,
435 u8 dpcd[DP_RECEIVER_CAP_SIZE]);
436
437int drm_dp_dpcd_read_link_status(struct drm_dp_aux *aux,
438 u8 status[DP_LINK_STATUS_SIZE]);
439
440int drm_dp_dpcd_read_phy_link_status(struct drm_dp_aux *aux,
441 enum drm_dp_phy dp_phy,
442 u8 link_status[DP_LINK_STATUS_SIZE]);
443
444bool drm_dp_send_real_edid_checksum(struct drm_dp_aux *aux,
445 u8 real_edid_checksum);
446
447int drm_dp_read_downstream_info(struct drm_dp_aux *aux,
448 const u8 dpcd[DP_RECEIVER_CAP_SIZE],
449 u8 downstream_ports[DP_MAX_DOWNSTREAM_PORTS]);
450bool drm_dp_downstream_is_type(const u8 dpcd[DP_RECEIVER_CAP_SIZE],
451 const u8 port_cap[4], u8 type);
452bool drm_dp_downstream_is_tmds(const u8 dpcd[DP_RECEIVER_CAP_SIZE],
453 const u8 port_cap[4],
454 const struct edid *edid);
455int drm_dp_downstream_max_dotclock(const u8 dpcd[DP_RECEIVER_CAP_SIZE],
456 const u8 port_cap[4]);
457int drm_dp_downstream_max_tmds_clock(const u8 dpcd[DP_RECEIVER_CAP_SIZE],
458 const u8 port_cap[4],
459 const struct edid *edid);
460int drm_dp_downstream_min_tmds_clock(const u8 dpcd[DP_RECEIVER_CAP_SIZE],
461 const u8 port_cap[4],
462 const struct edid *edid);
463int drm_dp_downstream_max_bpc(const u8 dpcd[DP_RECEIVER_CAP_SIZE],
464 const u8 port_cap[4],
465 const struct edid *edid);
466bool drm_dp_downstream_420_passthrough(const u8 dpcd[DP_RECEIVER_CAP_SIZE],
467 const u8 port_cap[4]);
468bool drm_dp_downstream_444_to_420_conversion(const u8 dpcd[DP_RECEIVER_CAP_SIZE],
469 const u8 port_cap[4]);
470struct drm_display_mode *drm_dp_downstream_mode(struct drm_device *dev,
471 const u8 dpcd[DP_RECEIVER_CAP_SIZE],
472 const u8 port_cap[4]);
473int drm_dp_downstream_id(struct drm_dp_aux *aux, char id[6]);
474void drm_dp_downstream_debug(struct seq_file *m,
475 const u8 dpcd[DP_RECEIVER_CAP_SIZE],
476 const u8 port_cap[4],
477 const struct edid *edid,
478 struct drm_dp_aux *aux);
479enum drm_mode_subconnector
480drm_dp_subconnector_type(const u8 dpcd[DP_RECEIVER_CAP_SIZE],
481 const u8 port_cap[4]);
482void drm_dp_set_subconnector_property(struct drm_connector *connector,
483 enum drm_connector_status status,
484 const u8 *dpcd,
485 const u8 port_cap[4]);
486
487struct drm_dp_desc;
488bool drm_dp_read_sink_count_cap(struct drm_connector *connector,
489 const u8 dpcd[DP_RECEIVER_CAP_SIZE],
490 const struct drm_dp_desc *desc);
491int drm_dp_read_sink_count(struct drm_dp_aux *aux);
492
493int drm_dp_read_lttpr_common_caps(struct drm_dp_aux *aux,
494 const u8 dpcd[DP_RECEIVER_CAP_SIZE],
495 u8 caps[DP_LTTPR_COMMON_CAP_SIZE]);
496int drm_dp_read_lttpr_phy_caps(struct drm_dp_aux *aux,
497 const u8 dpcd[DP_RECEIVER_CAP_SIZE],
498 enum drm_dp_phy dp_phy,
499 u8 caps[DP_LTTPR_PHY_CAP_SIZE]);
500int drm_dp_lttpr_count(const u8 cap[DP_LTTPR_COMMON_CAP_SIZE]);
501int drm_dp_lttpr_max_link_rate(const u8 caps[DP_LTTPR_COMMON_CAP_SIZE]);
502int drm_dp_lttpr_max_lane_count(const u8 caps[DP_LTTPR_COMMON_CAP_SIZE]);
503bool drm_dp_lttpr_voltage_swing_level_3_supported(const u8 caps[DP_LTTPR_PHY_CAP_SIZE]);
504bool drm_dp_lttpr_pre_emphasis_level_3_supported(const u8 caps[DP_LTTPR_PHY_CAP_SIZE]);
505
506void drm_dp_remote_aux_init(struct drm_dp_aux *aux);
507void drm_dp_aux_init(struct drm_dp_aux *aux);
508int drm_dp_aux_register(struct drm_dp_aux *aux);
509void drm_dp_aux_unregister(struct drm_dp_aux *aux);
510
511int drm_dp_start_crc(struct drm_dp_aux *aux, struct drm_crtc *crtc);
512int drm_dp_stop_crc(struct drm_dp_aux *aux);
513
514struct drm_dp_dpcd_ident {
515 u8 oui[3];
516 u8 device_id[6];
517 u8 hw_rev;
518 u8 sw_major_rev;
519 u8 sw_minor_rev;
520} __packed;
521
522
523
524
525
526
527struct drm_dp_desc {
528 struct drm_dp_dpcd_ident ident;
529 u32 quirks;
530};
531
532int drm_dp_read_desc(struct drm_dp_aux *aux, struct drm_dp_desc *desc,
533 bool is_branch);
534
535
536
537
538
539
540
541
542enum drm_dp_quirk {
543
544
545
546
547
548
549 DP_DPCD_QUIRK_CONSTANT_N,
550
551
552
553
554
555
556 DP_DPCD_QUIRK_NO_PSR,
557
558
559
560
561
562
563
564 DP_DPCD_QUIRK_NO_SINK_COUNT,
565
566
567
568
569
570
571 DP_DPCD_QUIRK_DSC_WITHOUT_VIRTUAL_DPCD,
572
573
574
575
576
577
578 DP_DPCD_QUIRK_CAN_DO_MAX_LINK_RATE_3_24_GBPS,
579};
580
581
582
583
584
585
586
587
588static inline bool
589drm_dp_has_quirk(const struct drm_dp_desc *desc, enum drm_dp_quirk quirk)
590{
591 return desc->quirks & BIT(quirk);
592}
593
594
595
596
597
598
599
600
601
602
603
604
605
606struct drm_edp_backlight_info {
607 u8 pwmgen_bit_count;
608 u8 pwm_freq_pre_divider;
609 u16 max;
610
611 bool lsb_reg_used : 1;
612 bool aux_enable : 1;
613 bool aux_set : 1;
614};
615
616int
617drm_edp_backlight_init(struct drm_dp_aux *aux, struct drm_edp_backlight_info *bl,
618 u16 driver_pwm_freq_hz, const u8 edp_dpcd[EDP_DISPLAY_CTL_CAP_SIZE],
619 u16 *current_level, u8 *current_mode);
620int drm_edp_backlight_set_level(struct drm_dp_aux *aux, const struct drm_edp_backlight_info *bl,
621 u16 level);
622int drm_edp_backlight_enable(struct drm_dp_aux *aux, const struct drm_edp_backlight_info *bl,
623 u16 level);
624int drm_edp_backlight_disable(struct drm_dp_aux *aux, const struct drm_edp_backlight_info *bl);
625
626#if IS_ENABLED(CONFIG_DRM_KMS_HELPER) && (IS_BUILTIN(CONFIG_BACKLIGHT_CLASS_DEVICE) || \
627 (IS_MODULE(CONFIG_DRM_KMS_HELPER) && IS_MODULE(CONFIG_BACKLIGHT_CLASS_DEVICE)))
628
629int drm_panel_dp_aux_backlight(struct drm_panel *panel, struct drm_dp_aux *aux);
630
631#else
632
633static inline int drm_panel_dp_aux_backlight(struct drm_panel *panel,
634 struct drm_dp_aux *aux)
635{
636 return 0;
637}
638
639#endif
640
641#ifdef CONFIG_DRM_DP_CEC
642void drm_dp_cec_irq(struct drm_dp_aux *aux);
643void drm_dp_cec_register_connector(struct drm_dp_aux *aux,
644 struct drm_connector *connector);
645void drm_dp_cec_unregister_connector(struct drm_dp_aux *aux);
646void drm_dp_cec_set_edid(struct drm_dp_aux *aux, const struct edid *edid);
647void drm_dp_cec_unset_edid(struct drm_dp_aux *aux);
648#else
649static inline void drm_dp_cec_irq(struct drm_dp_aux *aux)
650{
651}
652
653static inline void
654drm_dp_cec_register_connector(struct drm_dp_aux *aux,
655 struct drm_connector *connector)
656{
657}
658
659static inline void drm_dp_cec_unregister_connector(struct drm_dp_aux *aux)
660{
661}
662
663static inline void drm_dp_cec_set_edid(struct drm_dp_aux *aux,
664 const struct edid *edid)
665{
666}
667
668static inline void drm_dp_cec_unset_edid(struct drm_dp_aux *aux)
669{
670}
671
672#endif
673
674
675
676
677
678
679
680
681
682
683struct drm_dp_phy_test_params {
684 int link_rate;
685 u8 num_lanes;
686 u8 phy_pattern;
687 u8 hbr2_reset[2];
688 u8 custom80[10];
689 bool enhanced_frame_cap;
690};
691
692int drm_dp_get_phy_test_pattern(struct drm_dp_aux *aux,
693 struct drm_dp_phy_test_params *data);
694int drm_dp_set_phy_test_pattern(struct drm_dp_aux *aux,
695 struct drm_dp_phy_test_params *data, u8 dp_rev);
696int drm_dp_get_pcon_max_frl_bw(const u8 dpcd[DP_RECEIVER_CAP_SIZE],
697 const u8 port_cap[4]);
698int drm_dp_pcon_frl_prepare(struct drm_dp_aux *aux, bool enable_frl_ready_hpd);
699bool drm_dp_pcon_is_frl_ready(struct drm_dp_aux *aux);
700int drm_dp_pcon_frl_configure_1(struct drm_dp_aux *aux, int max_frl_gbps,
701 u8 frl_mode);
702int drm_dp_pcon_frl_configure_2(struct drm_dp_aux *aux, int max_frl_mask,
703 u8 frl_type);
704int drm_dp_pcon_reset_frl_config(struct drm_dp_aux *aux);
705int drm_dp_pcon_frl_enable(struct drm_dp_aux *aux);
706
707bool drm_dp_pcon_hdmi_link_active(struct drm_dp_aux *aux);
708int drm_dp_pcon_hdmi_link_mode(struct drm_dp_aux *aux, u8 *frl_trained_mask);
709void drm_dp_pcon_hdmi_frl_link_error_count(struct drm_dp_aux *aux,
710 struct drm_connector *connector);
711bool drm_dp_pcon_enc_is_dsc_1_2(const u8 pcon_dsc_dpcd[DP_PCON_DSC_ENCODER_CAP_SIZE]);
712int drm_dp_pcon_dsc_max_slices(const u8 pcon_dsc_dpcd[DP_PCON_DSC_ENCODER_CAP_SIZE]);
713int drm_dp_pcon_dsc_max_slice_width(const u8 pcon_dsc_dpcd[DP_PCON_DSC_ENCODER_CAP_SIZE]);
714int drm_dp_pcon_dsc_bpp_incr(const u8 pcon_dsc_dpcd[DP_PCON_DSC_ENCODER_CAP_SIZE]);
715int drm_dp_pcon_pps_default(struct drm_dp_aux *aux);
716int drm_dp_pcon_pps_override_buf(struct drm_dp_aux *aux, u8 pps_buf[128]);
717int drm_dp_pcon_pps_override_param(struct drm_dp_aux *aux, u8 pps_param[6]);
718bool drm_dp_downstream_rgb_to_ycbcr_conversion(const u8 dpcd[DP_RECEIVER_CAP_SIZE],
719 const u8 port_cap[4], u8 color_spc);
720int drm_dp_pcon_convert_rgb_to_ycbcr(struct drm_dp_aux *aux, u8 color_spc);
721
722#endif
723