162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (c) 2012-2020, The Linux Foundation. All rights reserved.
462306a36Sopenharmony_ci */
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci#ifndef _DP_LINK_H_
762306a36Sopenharmony_ci#define _DP_LINK_H_
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#include "dp_aux.h"
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#define DS_PORT_STATUS_CHANGED 0x200
1262306a36Sopenharmony_ci#define DP_TEST_BIT_DEPTH_UNKNOWN 0xFFFFFFFF
1362306a36Sopenharmony_ci#define DP_LINK_CAP_ENHANCED_FRAMING (1 << 0)
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_cistruct dp_link_info {
1662306a36Sopenharmony_ci	unsigned char revision;
1762306a36Sopenharmony_ci	unsigned int rate;
1862306a36Sopenharmony_ci	unsigned int num_lanes;
1962306a36Sopenharmony_ci	unsigned long capabilities;
2062306a36Sopenharmony_ci};
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_cienum dp_link_voltage_level {
2362306a36Sopenharmony_ci	DP_TRAIN_VOLTAGE_SWING_LVL_0	= 0,
2462306a36Sopenharmony_ci	DP_TRAIN_VOLTAGE_SWING_LVL_1	= 1,
2562306a36Sopenharmony_ci	DP_TRAIN_VOLTAGE_SWING_LVL_2	= 2,
2662306a36Sopenharmony_ci	DP_TRAIN_VOLTAGE_SWING_MAX	= DP_TRAIN_VOLTAGE_SWING_LVL_2,
2762306a36Sopenharmony_ci};
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_cienum dp_link_preemaphasis_level {
3062306a36Sopenharmony_ci	DP_TRAIN_PRE_EMPHASIS_LVL_0	= 0,
3162306a36Sopenharmony_ci	DP_TRAIN_PRE_EMPHASIS_LVL_1	= 1,
3262306a36Sopenharmony_ci	DP_TRAIN_PRE_EMPHASIS_LVL_2	= 2,
3362306a36Sopenharmony_ci	DP_TRAIN_PRE_EMPHASIS_MAX	= DP_TRAIN_PRE_EMPHASIS_LVL_2,
3462306a36Sopenharmony_ci};
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_cistruct dp_link_test_video {
3762306a36Sopenharmony_ci	u32 test_video_pattern;
3862306a36Sopenharmony_ci	u32 test_bit_depth;
3962306a36Sopenharmony_ci	u32 test_dyn_range;
4062306a36Sopenharmony_ci	u32 test_h_total;
4162306a36Sopenharmony_ci	u32 test_v_total;
4262306a36Sopenharmony_ci	u32 test_h_start;
4362306a36Sopenharmony_ci	u32 test_v_start;
4462306a36Sopenharmony_ci	u32 test_hsync_pol;
4562306a36Sopenharmony_ci	u32 test_hsync_width;
4662306a36Sopenharmony_ci	u32 test_vsync_pol;
4762306a36Sopenharmony_ci	u32 test_vsync_width;
4862306a36Sopenharmony_ci	u32 test_h_width;
4962306a36Sopenharmony_ci	u32 test_v_height;
5062306a36Sopenharmony_ci	u32 test_rr_d;
5162306a36Sopenharmony_ci	u32 test_rr_n;
5262306a36Sopenharmony_ci};
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_cistruct dp_link_test_audio {
5562306a36Sopenharmony_ci	u32 test_audio_sampling_rate;
5662306a36Sopenharmony_ci	u32 test_audio_channel_count;
5762306a36Sopenharmony_ci	u32 test_audio_pattern_type;
5862306a36Sopenharmony_ci	u32 test_audio_period_ch_1;
5962306a36Sopenharmony_ci	u32 test_audio_period_ch_2;
6062306a36Sopenharmony_ci	u32 test_audio_period_ch_3;
6162306a36Sopenharmony_ci	u32 test_audio_period_ch_4;
6262306a36Sopenharmony_ci	u32 test_audio_period_ch_5;
6362306a36Sopenharmony_ci	u32 test_audio_period_ch_6;
6462306a36Sopenharmony_ci	u32 test_audio_period_ch_7;
6562306a36Sopenharmony_ci	u32 test_audio_period_ch_8;
6662306a36Sopenharmony_ci};
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_cistruct dp_link_phy_params {
6962306a36Sopenharmony_ci	u32 phy_test_pattern_sel;
7062306a36Sopenharmony_ci	u8 v_level;
7162306a36Sopenharmony_ci	u8 p_level;
7262306a36Sopenharmony_ci};
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_cistruct dp_link {
7562306a36Sopenharmony_ci	u32 sink_request;
7662306a36Sopenharmony_ci	u32 test_response;
7762306a36Sopenharmony_ci	bool psm_enabled;
7862306a36Sopenharmony_ci
7962306a36Sopenharmony_ci	u8 sink_count;
8062306a36Sopenharmony_ci	struct dp_link_test_video test_video;
8162306a36Sopenharmony_ci	struct dp_link_test_audio test_audio;
8262306a36Sopenharmony_ci	struct dp_link_phy_params phy_params;
8362306a36Sopenharmony_ci	struct dp_link_info link_params;
8462306a36Sopenharmony_ci};
8562306a36Sopenharmony_ci
8662306a36Sopenharmony_ci/**
8762306a36Sopenharmony_ci * mdss_dp_test_bit_depth_to_bpp() - convert test bit depth to bpp
8862306a36Sopenharmony_ci * @tbd: test bit depth
8962306a36Sopenharmony_ci *
9062306a36Sopenharmony_ci * Returns the bits per pixel (bpp) to be used corresponding to the
9162306a36Sopenharmony_ci * git bit depth value. This function assumes that bit depth has
9262306a36Sopenharmony_ci * already been validated.
9362306a36Sopenharmony_ci */
9462306a36Sopenharmony_cistatic inline u32 dp_link_bit_depth_to_bpp(u32 tbd)
9562306a36Sopenharmony_ci{
9662306a36Sopenharmony_ci	/*
9762306a36Sopenharmony_ci	 * Few simplistic rules and assumptions made here:
9862306a36Sopenharmony_ci	 *    1. Bit depth is per color component
9962306a36Sopenharmony_ci	 *    2. If bit depth is unknown return 0
10062306a36Sopenharmony_ci	 *    3. Assume 3 color components
10162306a36Sopenharmony_ci	 */
10262306a36Sopenharmony_ci	switch (tbd) {
10362306a36Sopenharmony_ci	case DP_TEST_BIT_DEPTH_6:
10462306a36Sopenharmony_ci		return 18;
10562306a36Sopenharmony_ci	case DP_TEST_BIT_DEPTH_8:
10662306a36Sopenharmony_ci		return 24;
10762306a36Sopenharmony_ci	case DP_TEST_BIT_DEPTH_10:
10862306a36Sopenharmony_ci		return 30;
10962306a36Sopenharmony_ci	case DP_TEST_BIT_DEPTH_UNKNOWN:
11062306a36Sopenharmony_ci	default:
11162306a36Sopenharmony_ci		return 0;
11262306a36Sopenharmony_ci	}
11362306a36Sopenharmony_ci}
11462306a36Sopenharmony_ci
11562306a36Sopenharmony_ci/**
11662306a36Sopenharmony_ci * dp_test_bit_depth_to_bpc() - convert test bit depth to bpc
11762306a36Sopenharmony_ci * @tbd: test bit depth
11862306a36Sopenharmony_ci *
11962306a36Sopenharmony_ci * Returns the bits per comp (bpc) to be used corresponding to the
12062306a36Sopenharmony_ci * bit depth value. This function assumes that bit depth has
12162306a36Sopenharmony_ci * already been validated.
12262306a36Sopenharmony_ci */
12362306a36Sopenharmony_cistatic inline u32 dp_link_bit_depth_to_bpc(u32 tbd)
12462306a36Sopenharmony_ci{
12562306a36Sopenharmony_ci	switch (tbd) {
12662306a36Sopenharmony_ci	case DP_TEST_BIT_DEPTH_6:
12762306a36Sopenharmony_ci		return 6;
12862306a36Sopenharmony_ci	case DP_TEST_BIT_DEPTH_8:
12962306a36Sopenharmony_ci		return 8;
13062306a36Sopenharmony_ci	case DP_TEST_BIT_DEPTH_10:
13162306a36Sopenharmony_ci		return 10;
13262306a36Sopenharmony_ci	case DP_TEST_BIT_DEPTH_UNKNOWN:
13362306a36Sopenharmony_ci	default:
13462306a36Sopenharmony_ci		return 0;
13562306a36Sopenharmony_ci	}
13662306a36Sopenharmony_ci}
13762306a36Sopenharmony_ci
13862306a36Sopenharmony_civoid dp_link_reset_phy_params_vx_px(struct dp_link *dp_link);
13962306a36Sopenharmony_ciu32 dp_link_get_test_bits_depth(struct dp_link *dp_link, u32 bpp);
14062306a36Sopenharmony_ciint dp_link_process_request(struct dp_link *dp_link);
14162306a36Sopenharmony_ciint dp_link_get_colorimetry_config(struct dp_link *dp_link);
14262306a36Sopenharmony_ciint dp_link_adjust_levels(struct dp_link *dp_link, u8 *link_status);
14362306a36Sopenharmony_cibool dp_link_send_test_response(struct dp_link *dp_link);
14462306a36Sopenharmony_ciint dp_link_psm_config(struct dp_link *dp_link,
14562306a36Sopenharmony_ci		struct dp_link_info *link_info, bool enable);
14662306a36Sopenharmony_cibool dp_link_send_edid_checksum(struct dp_link *dp_link, u8 checksum);
14762306a36Sopenharmony_ci
14862306a36Sopenharmony_ci/**
14962306a36Sopenharmony_ci * dp_link_get() - get the functionalities of dp test module
15062306a36Sopenharmony_ci *
15162306a36Sopenharmony_ci *
15262306a36Sopenharmony_ci * return: a pointer to dp_link struct
15362306a36Sopenharmony_ci */
15462306a36Sopenharmony_cistruct dp_link *dp_link_get(struct device *dev, struct drm_dp_aux *aux);
15562306a36Sopenharmony_ci
15662306a36Sopenharmony_ci#endif /* _DP_LINK_H_ */
157