dc_link.h 11.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
/*
 * Copyright 2012-14 Advanced Micro Devices, Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 *
 * Authors: AMD
 *
 */

#ifndef DC_LINK_H_
#define DC_LINK_H_

29
#include "dc.h"
30 31 32
#include "dc_types.h"
#include "grph_object_defs.h"

33 34 35 36 37
enum dc_link_fec_state {
	dc_link_fec_not_ready,
	dc_link_fec_ready,
	dc_link_fec_enabled
};
38
struct dc_link_status {
39
	bool link_active;
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
	struct dpcd_caps *dpcd_caps;
};

/* DP MST stream allocation (payload bandwidth number) */
struct link_mst_stream_allocation {
	/* DIG front */
	const struct stream_encoder *stream_enc;
	/* associate DRM payload table with DC stream encoder */
	uint8_t vcp_id;
	/* number of slots required for the DP stream in transport packet */
	uint8_t slot_count;
};

/* DP MST stream allocation table */
struct link_mst_stream_allocation_table {
	/* number of DP video streams */
	int stream_count;
	/* array of stream allocations */
	struct link_mst_stream_allocation stream_allocations[MAX_CONTROLLER_NUM];
};

61 62 63 64 65 66 67 68
struct time_stamp {
	uint64_t edp_poweroff;
	uint64_t edp_poweron;
};

struct link_trace {
	struct time_stamp time_stamp;
};
69 70 71 72 73

/* PSR feature flags */
struct psr_settings {
	bool psr_feature_enabled;		// PSR is supported by sink
	bool psr_allow_active;			// PSR is currently active
74
	enum dc_psr_version psr_version;		// Internal PSR version, determined based on DPCD
75 76 77 78 79 80 81 82 83 84

	/* These parameters are calculated in Driver,
	 * based on display timing and Sink capabilities.
	 * If VBLANK region is too small and Sink takes a long time
	 * to set up RFB, it may take an extra frame to enter PSR state.
	 */
	bool psr_frame_capture_indication_req;
	unsigned int psr_sdp_transmit_line_num_deadline;
};

85 86 87 88 89 90 91 92 93 94 95 96 97
/*
 * A link contains one or more sinks and their connected status.
 * The currently active signal type (HDMI, DP-SST, DP-MST) is also reported.
 */
struct dc_link {
	struct dc_sink *remote_sinks[MAX_SINKS_PER_LINK];
	unsigned int sink_count;
	struct dc_sink *local_sink;
	unsigned int link_index;
	enum dc_connection_type type;
	enum signal_type connector_signal;
	enum dc_irq_source irq_source_hpd;
	enum dc_irq_source irq_source_hpd_rx;/* aka DP Short Pulse  */
98
	bool is_hpd_filter_disabled;
99
	bool dp_ss_off;
100
	bool link_state_valid;
101
	bool aux_access_disabled;
102
	bool sync_lt_in_progress;
103
	bool lttpr_non_transparent_mode;
104
	bool is_internal_display;
105

106 107 108 109 110 111 112 113
	/* caps is the same as reported_link_cap. link_traing use
	 * reported_link_cap. Will clean up.  TODO
	 */
	struct dc_link_settings reported_link_cap;
	struct dc_link_settings verified_link_cap;
	struct dc_link_settings cur_link_settings;
	struct dc_lane_settings cur_lane_setting;
	struct dc_link_settings preferred_link_setting;
114
	struct dc_link_training_overrides preferred_training_settings;
115
	struct dp_audio_test_data audio_test_data;
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137

	uint8_t ddc_hw_inst;

	uint8_t hpd_src;

	uint8_t link_enc_hw_inst;

	bool test_pattern_enabled;
	union compliance_test_state compliance_test_state;

	void *priv;

	struct ddc_service *ddc;

	bool aux_mode;

	/* Private to DC core */

	const struct dc *dc;

	struct dc_context *ctx;

138
	struct panel_cntl *panel_cntl;
139 140 141 142 143
	struct link_encoder *link_enc;
	struct graphics_object_id link_id;
	union ddi_channel_mapping ddi_channel_mapping;
	struct connector_device_tag_info device_tag;
	struct dpcd_caps dpcd_caps;
144
	uint32_t dongle_max_pix_clk;
145 146
	unsigned short chip_caps;
	unsigned int dpcd_sink_count;
147 148 149
#if defined(CONFIG_DRM_AMD_DC_HDCP)
	struct hdcp_caps hdcp_caps;
#endif
150
	enum edp_revision edp_revision;
151
	union dpcd_sink_ext_caps dpcd_sink_ext_caps;
152

153 154
	struct psr_settings psr_settings;

155 156 157
	/* MST record stream using this link */
	struct link_flags {
		bool dp_keep_receiver_powered;
158
		bool dp_skip_DID2;
159
		bool dp_skip_reset_segment;
160 161 162 163 164
	} wa_flags;
	struct link_mst_stream_allocation_table mst_stream_alloc_table;

	struct dc_link_status link_status;

165
	struct link_trace link_trace;
166
	struct gpio *hpd_gpio;
167
	enum dc_link_fec_state fec_state;
168 169 170 171
};

const struct dc_link_status *dc_link_get_status(const struct dc_link *dc_link);

172 173 174 175
/**
 * dc_get_link_at_index() - Return an enumerated dc_link.
 *
 * dc_link order is constant and determined at
176 177 178 179 180 181 182 183
 * boot time.  They cannot be created or destroyed.
 * Use dc_get_caps() to get number of links.
 */
static inline struct dc_link *dc_get_link_at_index(struct dc *dc, uint32_t link_index)
{
	return dc->links[link_index];
}

184 185 186 187 188 189 190 191 192 193 194 195
static inline struct dc_link *get_edp_link(const struct dc *dc)
{
	int i;

	// report any eDP links, even unconnected DDI's
	for (i = 0; i < dc->link_count; i++) {
		if (dc->links[i]->connector_signal == SIGNAL_TYPE_EDP)
			return dc->links[i];
	}
	return NULL;
}

196 197 198 199 200 201
/* Set backlight level of an embedded panel (eDP, LVDS).
 * backlight_pwm_u16_16 is unsigned 32 bit with 16 bit integer
 * and 16 bit fractional, where 1.0 is max backlight value.
 */
bool dc_link_set_backlight_level(const struct dc_link *dc_link,
		uint32_t backlight_pwm_u16_16,
202
		uint32_t frame_ramp);
203

204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
/* Set/get nits-based backlight level of an embedded panel (eDP, LVDS). */
bool dc_link_set_backlight_level_nits(struct dc_link *link,
		bool isHDR,
		uint32_t backlight_millinits,
		uint32_t transition_time_in_ms);

bool dc_link_get_backlight_level_nits(struct dc_link *link,
		uint32_t *backlight_millinits,
		uint32_t *backlight_millinits_peak);

bool dc_link_backlight_enable_aux(struct dc_link *link, bool enable);

bool dc_link_read_default_bl_aux(struct dc_link *link, uint32_t *backlight_millinits);
bool dc_link_set_default_brightness_aux(struct dc_link *link);

219 220
int dc_link_get_backlight_level(const struct dc_link *dc_link);

221 222
int dc_link_get_target_backlight_pwm(const struct dc_link *link);

223 224
bool dc_link_set_psr_allow_active(struct dc_link *dc_link, bool enable,
		bool wait, bool force_static);
225

226
bool dc_link_get_psr_state(const struct dc_link *dc_link, enum dc_psr_state *state);
227 228 229 230 231

bool dc_link_setup_psr(struct dc_link *dc_link,
		const struct dc_stream_state *stream, struct psr_config *psr_config,
		struct psr_context *psr_context);

232 233
void dc_link_get_psr_residency(const struct dc_link *link, uint32_t *residency);

234 235 236 237 238 239 240 241 242 243
/* Request DC to detect if there is a Panel connected.
 * boot - If this call is during initial boot.
 * Return false for any type of detection failure or MST detection
 * true otherwise. True meaning further action is required (status update
 * and OS notification).
 */
enum dc_detect_reason {
	DETECT_REASON_BOOT,
	DETECT_REASON_HPD,
	DETECT_REASON_HPDRX,
244 245
	DETECT_REASON_FALLBACK,
	DETECT_REASON_RETRAIN
246 247 248
};

bool dc_link_detect(struct dc_link *dc_link, enum dc_detect_reason reason);
249
bool dc_link_get_hpd_state(struct dc_link *dc_link);
250
enum dc_status dc_link_allocate_mst_payload(struct pipe_ctx *pipe_ctx);
251
enum dc_status dc_link_reallocate_mst_payload(struct dc_link *link);
252 253 254 255 256 257 258 259

/* Notify DC about DP RX Interrupt (aka Short Pulse Interrupt).
 * Return:
 * true - Downstream port status changed. DM should call DC to do the
 * detection.
 * false - no change in Downstream port status. No further action required
 * from DM. */
bool dc_link_handle_hpd_rx_irq(struct dc_link *dc_link,
260
		union hpd_irq_data *hpd_irq_dpcd_data, bool *out_link_loss);
261

262 263 264 265 266 267 268
/*
 * On eDP links this function call will stall until T12 has elapsed.
 * If the panel is not in power off state, this function will return
 * immediately.
 */
bool dc_link_wait_for_t12(struct dc_link *link);

269 270 271 272
enum dc_status read_hpd_rx_irq_data(
	struct dc_link *link,
	union hpd_irq_data *irq_data);

273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
struct dc_sink_init_data;

struct dc_sink *dc_link_add_remote_sink(
		struct dc_link *dc_link,
		const uint8_t *edid,
		int len,
		struct dc_sink_init_data *init_data);

void dc_link_remove_remote_sink(
	struct dc_link *link,
	struct dc_sink *sink);

/* Used by diagnostics for virtual link at the moment */

void dc_link_dp_set_drive_settings(
	struct dc_link *link,
	struct link_training_settings *lt_settings);

291 292 293 294
bool dc_link_dp_perform_link_training_skip_aux(
	struct dc_link *link,
	const struct dc_link_settings *link_setting);

295 296 297 298 299
enum link_training_result dc_link_dp_perform_link_training(
	struct dc_link *link,
	const struct dc_link_settings *link_setting,
	bool skip_video_pattern);

300 301 302 303 304 305 306 307 308
bool dc_link_dp_sync_lt_begin(struct dc_link *link);

enum link_training_result dc_link_dp_sync_lt_attempt(
	struct dc_link *link,
	struct dc_link_settings *link_setting,
	struct dc_link_training_overrides *lt_settings);

bool dc_link_dp_sync_lt_end(struct dc_link *link, bool link_down);

309 310 311 312 313 314 315
void dc_link_dp_enable_hpd(const struct dc_link *link);

void dc_link_dp_disable_hpd(const struct dc_link *link);

bool dc_link_dp_set_test_pattern(
	struct dc_link *link,
	enum dp_test_pattern test_pattern,
316
	enum dp_test_pattern_color_space test_pattern_color_space,
317 318 319 320
	const struct link_training_settings *p_link_settings,
	const unsigned char *p_custom_pattern,
	unsigned int cust_pattern_size);

321
void dc_link_enable_hpd_filter(struct dc_link *link, bool enable);
322

323 324
bool dc_link_is_dp_sink_present(struct dc_link *link);

325
bool dc_link_detect_sink(struct dc_link *link, enum dc_connection_type *type);
326 327 328 329
/*
 * DPCD access interfaces
 */

330
#ifdef CONFIG_DRM_AMD_DC_HDCP
331 332
bool dc_link_is_hdcp14(struct dc_link *link, enum signal_type signal);
bool dc_link_is_hdcp22(struct dc_link *link, enum signal_type signal);
333
#endif
334 335 336 337 338 339 340 341 342
void dc_link_set_drive_settings(struct dc *dc,
				struct link_training_settings *lt_settings,
				const struct dc_link *link);
void dc_link_perform_link_training(struct dc *dc,
				   struct dc_link_settings *link_setting,
				   bool skip_video_pattern);
void dc_link_set_preferred_link_settings(struct dc *dc,
					 struct dc_link_settings *link_setting,
					 struct dc_link *link);
343 344 345 346 347
void dc_link_set_preferred_training_settings(struct dc *dc,
					struct dc_link_settings *link_setting,
					struct dc_link_training_overrides *lt_overrides,
					struct dc_link *link,
					bool skip_immediate_retrain);
348 349 350 351
void dc_link_enable_hpd(const struct dc_link *link);
void dc_link_disable_hpd(const struct dc_link *link);
void dc_link_set_test_pattern(struct dc_link *link,
			enum dp_test_pattern test_pattern,
352
			enum dp_test_pattern_color_space test_pattern_color_space,
353 354 355
			const struct link_training_settings *p_link_settings,
			const unsigned char *p_custom_pattern,
			unsigned int cust_pattern_size);
356 357 358
uint32_t dc_link_bandwidth_kbps(
	const struct dc_link *link,
	const struct dc_link_settings *link_setting);
359

360
const struct dc_link_settings *dc_link_get_link_cap(
361 362
		const struct dc_link *link);

363 364 365
void dc_link_overwrite_extended_receiver_cap(
		struct dc_link *link);

366 367 368 369 370
bool dc_submit_i2c(
		struct dc *dc,
		uint32_t link_index,
		struct i2c_command *cmd);

371 372 373 374
bool dc_submit_i2c_oem(
		struct dc *dc,
		struct i2c_command *cmd);

375 376
uint32_t dc_bandwidth_in_kbps_from_timing(
	const struct dc_crtc_timing *timing);
377 378

bool dc_link_is_fec_supported(const struct dc_link *link);
379
bool dc_link_should_enable_fec(const struct dc_link *link);
380

381
#endif /* DC_LINK_H_ */