18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (c) 2012-2020, The Linux Foundation. All rights reserved.
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#ifndef _DP_LINK_H_
78c2ecf20Sopenharmony_ci#define _DP_LINK_H_
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include "dp_aux.h"
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#define DS_PORT_STATUS_CHANGED 0x200
128c2ecf20Sopenharmony_ci#define DP_TEST_BIT_DEPTH_UNKNOWN 0xFFFFFFFF
138c2ecf20Sopenharmony_ci#define DP_LINK_CAP_ENHANCED_FRAMING (1 << 0)
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_cistruct dp_link_info {
168c2ecf20Sopenharmony_ci	unsigned char revision;
178c2ecf20Sopenharmony_ci	unsigned int rate;
188c2ecf20Sopenharmony_ci	unsigned int num_lanes;
198c2ecf20Sopenharmony_ci	unsigned long capabilities;
208c2ecf20Sopenharmony_ci};
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_cienum dp_link_voltage_level {
238c2ecf20Sopenharmony_ci	DP_TRAIN_VOLTAGE_SWING_LVL_0	= 0,
248c2ecf20Sopenharmony_ci	DP_TRAIN_VOLTAGE_SWING_LVL_1	= 1,
258c2ecf20Sopenharmony_ci	DP_TRAIN_VOLTAGE_SWING_LVL_2	= 2,
268c2ecf20Sopenharmony_ci	DP_TRAIN_VOLTAGE_SWING_MAX	= DP_TRAIN_VOLTAGE_SWING_LVL_2,
278c2ecf20Sopenharmony_ci};
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_cienum dp_link_preemaphasis_level {
308c2ecf20Sopenharmony_ci	DP_TRAIN_PRE_EMPHASIS_LVL_0	= 0,
318c2ecf20Sopenharmony_ci	DP_TRAIN_PRE_EMPHASIS_LVL_1	= 1,
328c2ecf20Sopenharmony_ci	DP_TRAIN_PRE_EMPHASIS_LVL_2	= 2,
338c2ecf20Sopenharmony_ci	DP_TRAIN_PRE_EMPHASIS_MAX	= DP_TRAIN_PRE_EMPHASIS_LVL_2,
348c2ecf20Sopenharmony_ci};
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_cistruct dp_link_test_video {
378c2ecf20Sopenharmony_ci	u32 test_video_pattern;
388c2ecf20Sopenharmony_ci	u32 test_bit_depth;
398c2ecf20Sopenharmony_ci	u32 test_dyn_range;
408c2ecf20Sopenharmony_ci	u32 test_h_total;
418c2ecf20Sopenharmony_ci	u32 test_v_total;
428c2ecf20Sopenharmony_ci	u32 test_h_start;
438c2ecf20Sopenharmony_ci	u32 test_v_start;
448c2ecf20Sopenharmony_ci	u32 test_hsync_pol;
458c2ecf20Sopenharmony_ci	u32 test_hsync_width;
468c2ecf20Sopenharmony_ci	u32 test_vsync_pol;
478c2ecf20Sopenharmony_ci	u32 test_vsync_width;
488c2ecf20Sopenharmony_ci	u32 test_h_width;
498c2ecf20Sopenharmony_ci	u32 test_v_height;
508c2ecf20Sopenharmony_ci	u32 test_rr_d;
518c2ecf20Sopenharmony_ci	u32 test_rr_n;
528c2ecf20Sopenharmony_ci};
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_cistruct dp_link_test_audio {
558c2ecf20Sopenharmony_ci	u32 test_audio_sampling_rate;
568c2ecf20Sopenharmony_ci	u32 test_audio_channel_count;
578c2ecf20Sopenharmony_ci	u32 test_audio_pattern_type;
588c2ecf20Sopenharmony_ci	u32 test_audio_period_ch_1;
598c2ecf20Sopenharmony_ci	u32 test_audio_period_ch_2;
608c2ecf20Sopenharmony_ci	u32 test_audio_period_ch_3;
618c2ecf20Sopenharmony_ci	u32 test_audio_period_ch_4;
628c2ecf20Sopenharmony_ci	u32 test_audio_period_ch_5;
638c2ecf20Sopenharmony_ci	u32 test_audio_period_ch_6;
648c2ecf20Sopenharmony_ci	u32 test_audio_period_ch_7;
658c2ecf20Sopenharmony_ci	u32 test_audio_period_ch_8;
668c2ecf20Sopenharmony_ci};
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_cistruct dp_link_phy_params {
698c2ecf20Sopenharmony_ci	u32 phy_test_pattern_sel;
708c2ecf20Sopenharmony_ci	u8 v_level;
718c2ecf20Sopenharmony_ci	u8 p_level;
728c2ecf20Sopenharmony_ci};
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_cistruct dp_link {
758c2ecf20Sopenharmony_ci	u32 sink_request;
768c2ecf20Sopenharmony_ci	u32 test_response;
778c2ecf20Sopenharmony_ci	bool psm_enabled;
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci	u8 sink_count;
808c2ecf20Sopenharmony_ci	struct dp_link_test_video test_video;
818c2ecf20Sopenharmony_ci	struct dp_link_test_audio test_audio;
828c2ecf20Sopenharmony_ci	struct dp_link_phy_params phy_params;
838c2ecf20Sopenharmony_ci	struct dp_link_info link_params;
848c2ecf20Sopenharmony_ci};
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci/**
878c2ecf20Sopenharmony_ci * mdss_dp_test_bit_depth_to_bpp() - convert test bit depth to bpp
888c2ecf20Sopenharmony_ci * @tbd: test bit depth
898c2ecf20Sopenharmony_ci *
908c2ecf20Sopenharmony_ci * Returns the bits per pixel (bpp) to be used corresponding to the
918c2ecf20Sopenharmony_ci * git bit depth value. This function assumes that bit depth has
928c2ecf20Sopenharmony_ci * already been validated.
938c2ecf20Sopenharmony_ci */
948c2ecf20Sopenharmony_cistatic inline u32 dp_link_bit_depth_to_bpp(u32 tbd)
958c2ecf20Sopenharmony_ci{
968c2ecf20Sopenharmony_ci	/*
978c2ecf20Sopenharmony_ci	 * Few simplistic rules and assumptions made here:
988c2ecf20Sopenharmony_ci	 *    1. Bit depth is per color component
998c2ecf20Sopenharmony_ci	 *    2. If bit depth is unknown return 0
1008c2ecf20Sopenharmony_ci	 *    3. Assume 3 color components
1018c2ecf20Sopenharmony_ci	 */
1028c2ecf20Sopenharmony_ci	switch (tbd) {
1038c2ecf20Sopenharmony_ci	case DP_TEST_BIT_DEPTH_6:
1048c2ecf20Sopenharmony_ci		return 18;
1058c2ecf20Sopenharmony_ci	case DP_TEST_BIT_DEPTH_8:
1068c2ecf20Sopenharmony_ci		return 24;
1078c2ecf20Sopenharmony_ci	case DP_TEST_BIT_DEPTH_10:
1088c2ecf20Sopenharmony_ci		return 30;
1098c2ecf20Sopenharmony_ci	case DP_TEST_BIT_DEPTH_UNKNOWN:
1108c2ecf20Sopenharmony_ci	default:
1118c2ecf20Sopenharmony_ci		return 0;
1128c2ecf20Sopenharmony_ci	}
1138c2ecf20Sopenharmony_ci}
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci/**
1168c2ecf20Sopenharmony_ci * dp_test_bit_depth_to_bpc() - convert test bit depth to bpc
1178c2ecf20Sopenharmony_ci * @tbd: test bit depth
1188c2ecf20Sopenharmony_ci *
1198c2ecf20Sopenharmony_ci * Returns the bits per comp (bpc) to be used corresponding to the
1208c2ecf20Sopenharmony_ci * bit depth value. This function assumes that bit depth has
1218c2ecf20Sopenharmony_ci * already been validated.
1228c2ecf20Sopenharmony_ci */
1238c2ecf20Sopenharmony_cistatic inline u32 dp_link_bit_depth_to_bpc(u32 tbd)
1248c2ecf20Sopenharmony_ci{
1258c2ecf20Sopenharmony_ci	switch (tbd) {
1268c2ecf20Sopenharmony_ci	case DP_TEST_BIT_DEPTH_6:
1278c2ecf20Sopenharmony_ci		return 6;
1288c2ecf20Sopenharmony_ci	case DP_TEST_BIT_DEPTH_8:
1298c2ecf20Sopenharmony_ci		return 8;
1308c2ecf20Sopenharmony_ci	case DP_TEST_BIT_DEPTH_10:
1318c2ecf20Sopenharmony_ci		return 10;
1328c2ecf20Sopenharmony_ci	case DP_TEST_BIT_DEPTH_UNKNOWN:
1338c2ecf20Sopenharmony_ci	default:
1348c2ecf20Sopenharmony_ci		return 0;
1358c2ecf20Sopenharmony_ci	}
1368c2ecf20Sopenharmony_ci}
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_civoid dp_link_reset_phy_params_vx_px(struct dp_link *dp_link);
1398c2ecf20Sopenharmony_ciu32 dp_link_get_test_bits_depth(struct dp_link *dp_link, u32 bpp);
1408c2ecf20Sopenharmony_ciint dp_link_process_request(struct dp_link *dp_link);
1418c2ecf20Sopenharmony_ciint dp_link_get_colorimetry_config(struct dp_link *dp_link);
1428c2ecf20Sopenharmony_ciint dp_link_adjust_levels(struct dp_link *dp_link, u8 *link_status);
1438c2ecf20Sopenharmony_cibool dp_link_send_test_response(struct dp_link *dp_link);
1448c2ecf20Sopenharmony_ciint dp_link_psm_config(struct dp_link *dp_link,
1458c2ecf20Sopenharmony_ci		struct dp_link_info *link_info, bool enable);
1468c2ecf20Sopenharmony_cibool dp_link_send_edid_checksum(struct dp_link *dp_link, u8 checksum);
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ci/**
1498c2ecf20Sopenharmony_ci * dp_link_get() - get the functionalities of dp test module
1508c2ecf20Sopenharmony_ci *
1518c2ecf20Sopenharmony_ci *
1528c2ecf20Sopenharmony_ci * return: a pointer to dp_link struct
1538c2ecf20Sopenharmony_ci */
1548c2ecf20Sopenharmony_cistruct dp_link *dp_link_get(struct device *dev, struct drm_dp_aux *aux);
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_ci#endif /* _DP_LINK_H_ */
157