intel_dp_mst.c 19.2 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 © 2008 Intel Corporation
 *             2014 Red Hat 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 (including the next
 * paragraph) 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 AUTHORS OR COPYRIGHT HOLDERS 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.
 *
 */

#include <drm/drmP.h>
#include "i915_drv.h"
#include "intel_drv.h"
29
#include <drm/drm_atomic_helper.h>
30 31 32 33
#include <drm/drm_crtc_helper.h>
#include <drm/drm_edid.h>

static bool intel_dp_mst_compute_config(struct intel_encoder *encoder,
34 35
					struct intel_crtc_state *pipe_config,
					struct drm_connector_state *conn_state)
36
{
37
	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
38 39 40
	struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base);
	struct intel_digital_port *intel_dig_port = intel_mst->primary;
	struct intel_dp *intel_dp = &intel_dig_port->dp;
L
Libin Yang 已提交
41 42
	struct intel_connector *connector =
		to_intel_connector(conn_state->connector);
43
	struct drm_atomic_state *state = pipe_config->base.state;
44
	int bpp;
45
	int lane_count, slots;
46
	const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
47
	int mst_pbn;
48 49
	bool reduce_m_n = drm_dp_has_quirk(&intel_dp->desc,
					   DP_DPCD_QUIRK_LIMITED_M_N);
50

51 52 53
	if (adjusted_mode->flags & DRM_MODE_FLAG_DBLSCAN)
		return false;

54 55
	pipe_config->has_pch_encoder = false;
	bpp = 24;
56 57 58 59 60
	if (intel_dp->compliance.test_data.bpc) {
		bpp = intel_dp->compliance.test_data.bpc * 3;
		DRM_DEBUG_KMS("Setting pipe bpp to %d\n",
			      bpp);
	}
61 62 63 64
	/*
	 * for MST we always configure max link bw - the spec doesn't
	 * seem to suggest we should do otherwise.
	 */
65
	lane_count = intel_dp_max_lane_count(intel_dp);
66

67
	pipe_config->lane_count = lane_count;
68

69
	pipe_config->pipe_bpp = bpp;
70

71
	pipe_config->port_clock = intel_dp_max_link_rate(intel_dp);
72

L
Libin Yang 已提交
73 74
	if (drm_dp_mst_port_has_audio(&intel_dp->mst_mgr, connector->port))
		pipe_config->has_audio = true;
75

76
	mst_pbn = drm_dp_calc_pbn_mode(adjusted_mode->crtc_clock, bpp);
77
	pipe_config->pbn = mst_pbn;
78 79 80 81 82 83 84

	slots = drm_dp_atomic_find_vcpi_slots(state, &intel_dp->mst_mgr,
					      connector->port, mst_pbn);
	if (slots < 0) {
		DRM_DEBUG_KMS("failed finding vcpi slots:%d\n", slots);
		return false;
	}
85 86 87 88

	intel_link_compute_m_n(bpp, lane_count,
			       adjusted_mode->crtc_clock,
			       pipe_config->port_clock,
89 90
			       &pipe_config->dp_m_n,
			       reduce_m_n);
91 92

	pipe_config->dp_m_n.tu = slots;
93

94 95 96 97
	if (IS_GEN9_LP(dev_priv))
		pipe_config->lane_lat_optim_mask =
			bxt_ddi_phy_calc_lane_lat_optim_mask(pipe_config->lane_count);

98 99
	intel_ddi_compute_min_voltage_level(dev_priv, pipe_config);

100
	return true;
101
}
102

103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
static int intel_dp_mst_atomic_check(struct drm_connector *connector,
		struct drm_connector_state *new_conn_state)
{
	struct drm_atomic_state *state = new_conn_state->state;
	struct drm_connector_state *old_conn_state;
	struct drm_crtc *old_crtc;
	struct drm_crtc_state *crtc_state;
	int slots, ret = 0;

	old_conn_state = drm_atomic_get_old_connector_state(state, connector);
	old_crtc = old_conn_state->crtc;
	if (!old_crtc)
		return ret;

	crtc_state = drm_atomic_get_new_crtc_state(state, old_crtc);
	slots = to_intel_crtc_state(crtc_state)->dp_m_n.tu;
	if (drm_atomic_crtc_needs_modeset(crtc_state) && slots > 0) {
		struct drm_dp_mst_topology_mgr *mgr;
		struct drm_encoder *old_encoder;

		old_encoder = old_conn_state->best_encoder;
		mgr = &enc_to_mst(old_encoder)->primary->dp.mst_mgr;

		ret = drm_dp_atomic_release_vcpi_slots(state, mgr, slots);
		if (ret)
			DRM_DEBUG_KMS("failed releasing %d vcpi slots:%d\n", slots, ret);
		else
			to_intel_crtc_state(crtc_state)->dp_m_n.tu = 0;
	}
	return ret;
133 134
}

135
static void intel_mst_disable_dp(struct intel_encoder *encoder,
136 137
				 const struct intel_crtc_state *old_crtc_state,
				 const struct drm_connector_state *old_conn_state)
138 139 140 141
{
	struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base);
	struct intel_digital_port *intel_dig_port = intel_mst->primary;
	struct intel_dp *intel_dp = &intel_dig_port->dp;
142 143
	struct intel_connector *connector =
		to_intel_connector(old_conn_state->connector);
144 145
	int ret;

146
	DRM_DEBUG_KMS("active links %d\n", intel_dp->active_mst_links);
147

148
	drm_dp_mst_reset_vcpi_slots(&intel_dp->mst_mgr, connector->port);
149 150 151 152 153

	ret = drm_dp_update_payload_part1(&intel_dp->mst_mgr);
	if (ret) {
		DRM_ERROR("failed to update payload %d\n", ret);
	}
154
	if (old_crtc_state->has_audio)
155 156
		intel_audio_codec_disable(encoder,
					  old_crtc_state, old_conn_state);
157 158
}

159
static void intel_mst_post_disable_dp(struct intel_encoder *encoder,
160 161
				      const struct intel_crtc_state *old_crtc_state,
				      const struct drm_connector_state *old_conn_state)
162 163 164 165
{
	struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base);
	struct intel_digital_port *intel_dig_port = intel_mst->primary;
	struct intel_dp *intel_dp = &intel_dig_port->dp;
166 167
	struct intel_connector *connector =
		to_intel_connector(old_conn_state->connector);
168 169 170 171 172 173

	/* this can fail */
	drm_dp_check_act_status(&intel_dp->mst_mgr);
	/* and this can also fail */
	drm_dp_update_payload_part2(&intel_dp->mst_mgr);

174
	drm_dp_mst_deallocate_vcpi(&intel_dp->mst_mgr, connector->port);
175

176 177 178 179 180 181 182
	/*
	 * Power down mst path before disabling the port, otherwise we end
	 * up getting interrupts from the sink upon detecting link loss.
	 */
	drm_dp_send_power_updown_phy(&intel_dp->mst_mgr, connector->port,
				     false);

183
	intel_dp->active_mst_links--;
184 185

	intel_mst->connector = NULL;
186 187
	if (intel_dp->active_mst_links == 0) {
		intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
188
		intel_dig_port->base.post_disable(&intel_dig_port->base,
189
						  old_crtc_state, NULL);
190
	}
191

192
	DRM_DEBUG_KMS("active links %d\n", intel_dp->active_mst_links);
193 194
}

195 196 197 198 199 200 201 202 203 204 205 206 207 208
static void intel_mst_pre_pll_enable_dp(struct intel_encoder *encoder,
					const struct intel_crtc_state *pipe_config,
					const struct drm_connector_state *conn_state)
{
	struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base);
	struct intel_digital_port *intel_dig_port = intel_mst->primary;
	struct intel_dp *intel_dp = &intel_dig_port->dp;

	if (intel_dp->active_mst_links == 0 &&
	    intel_dig_port->base.pre_pll_enable)
		intel_dig_port->base.pre_pll_enable(&intel_dig_port->base,
						    pipe_config, NULL);
}

209
static void intel_mst_pre_enable_dp(struct intel_encoder *encoder,
210 211
				    const struct intel_crtc_state *pipe_config,
				    const struct drm_connector_state *conn_state)
212 213 214 215
{
	struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base);
	struct intel_digital_port *intel_dig_port = intel_mst->primary;
	struct intel_dp *intel_dp = &intel_dig_port->dp;
216
	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
217
	enum port port = intel_dig_port->base.port;
218 219
	struct intel_connector *connector =
		to_intel_connector(conn_state->connector);
220 221 222
	int ret;
	uint32_t temp;

223 224 225
	/* MST encoders are bound to a crtc, not to a connector,
	 * force the mapping here for get_hw_state.
	 */
226 227
	connector->encoder = encoder;
	intel_mst->connector = connector;
228

229
	DRM_DEBUG_KMS("active links %d\n", intel_dp->active_mst_links);
230

231 232 233
	if (intel_dp->active_mst_links == 0)
		intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);

234
	drm_dp_send_power_updown_phy(&intel_dp->mst_mgr, connector->port, true);
235

236 237 238
	if (intel_dp->active_mst_links == 0)
		intel_dig_port->base.pre_enable(&intel_dig_port->base,
						pipe_config, NULL);
239 240

	ret = drm_dp_mst_allocate_vcpi(&intel_dp->mst_mgr,
241
				       connector->port,
242 243
				       pipe_config->pbn,
				       pipe_config->dp_m_n.tu);
244 245 246 247 248 249
	if (ret == false) {
		DRM_ERROR("failed to allocate vcpi\n");
		return;
	}


250
	intel_dp->active_mst_links++;
251 252 253 254 255 256
	temp = I915_READ(DP_TP_STATUS(port));
	I915_WRITE(DP_TP_STATUS(port), temp);

	ret = drm_dp_update_payload_part1(&intel_dp->mst_mgr);
}

257
static void intel_mst_enable_dp(struct intel_encoder *encoder,
258 259
				const struct intel_crtc_state *pipe_config,
				const struct drm_connector_state *conn_state)
260 261 262 263
{
	struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base);
	struct intel_digital_port *intel_dig_port = intel_mst->primary;
	struct intel_dp *intel_dp = &intel_dig_port->dp;
264
	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
265
	enum port port = intel_dig_port->base.port;
266 267
	int ret;

268
	DRM_DEBUG_KMS("active links %d\n", intel_dp->active_mst_links);
269

270 271 272 273 274
	if (intel_wait_for_register(dev_priv,
				    DP_TP_STATUS(port),
				    DP_TP_STATUS_ACT_SENT,
				    DP_TP_STATUS_ACT_SENT,
				    1))
275 276 277 278 279
		DRM_ERROR("Timed out waiting for ACT sent\n");

	ret = drm_dp_check_act_status(&intel_dp->mst_mgr);

	ret = drm_dp_update_payload_part2(&intel_dp->mst_mgr);
280
	if (pipe_config->has_audio)
L
Libin Yang 已提交
281
		intel_audio_codec_enable(encoder, pipe_config, conn_state);
282 283 284 285 286 287 288
}

static bool intel_dp_mst_enc_get_hw_state(struct intel_encoder *encoder,
				      enum pipe *pipe)
{
	struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base);
	*pipe = intel_mst->pipe;
289
	if (intel_mst->connector)
290 291 292 293 294
		return true;
	return false;
}

static void intel_dp_mst_enc_get_config(struct intel_encoder *encoder,
295
					struct intel_crtc_state *pipe_config)
296 297 298
{
	struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base);
	struct intel_digital_port *intel_dig_port = intel_mst->primary;
299

300
	intel_ddi_get_config(&intel_dig_port->base, pipe_config);
301 302 303 304 305 306 307 308 309
}

static int intel_dp_mst_get_ddc_modes(struct drm_connector *connector)
{
	struct intel_connector *intel_connector = to_intel_connector(connector);
	struct intel_dp *intel_dp = intel_connector->mst_port;
	struct edid *edid;
	int ret;

310 311 312
	if (!intel_dp) {
		return intel_connector_update_modes(connector, NULL);
	}
313

314
	edid = drm_dp_mst_get_edid(connector, &intel_dp->mst_mgr, intel_connector->port);
315 316 317 318 319 320 321
	ret = intel_connector_update_modes(connector, edid);
	kfree(edid);

	return ret;
}

static enum drm_connector_status
322
intel_dp_mst_detect(struct drm_connector *connector, bool force)
323 324 325 326
{
	struct intel_connector *intel_connector = to_intel_connector(connector);
	struct intel_dp *intel_dp = intel_connector->mst_port;

327 328
	if (!intel_dp)
		return connector_status_disconnected;
329
	return drm_dp_mst_detect_port(connector, &intel_dp->mst_mgr, intel_connector->port);
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346
}

static void
intel_dp_mst_connector_destroy(struct drm_connector *connector)
{
	struct intel_connector *intel_connector = to_intel_connector(connector);

	if (!IS_ERR_OR_NULL(intel_connector->edid))
		kfree(intel_connector->edid);

	drm_connector_cleanup(connector);
	kfree(connector);
}

static const struct drm_connector_funcs intel_dp_mst_connector_funcs = {
	.detect = intel_dp_mst_detect,
	.fill_modes = drm_helper_probe_single_connector_modes,
347
	.late_register = intel_connector_register,
348
	.early_unregister = intel_connector_unregister,
349
	.destroy = intel_dp_mst_connector_destroy,
350
	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
351
	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
352 353 354 355 356 357 358 359 360 361 362
};

static int intel_dp_mst_get_modes(struct drm_connector *connector)
{
	return intel_dp_mst_get_ddc_modes(connector);
}

static enum drm_mode_status
intel_dp_mst_mode_valid(struct drm_connector *connector,
			struct drm_display_mode *mode)
{
363 364
	struct intel_connector *intel_connector = to_intel_connector(connector);
	struct intel_dp *intel_dp = intel_connector->mst_port;
365
	int max_dotclk = to_i915(connector->dev)->max_dotclk_freq;
366 367 368
	int bpp = 24; /* MST uses fixed bpp */
	int max_rate, mode_rate, max_lanes, max_link_clock;

369 370 371
	if (!intel_dp)
		return MODE_ERROR;

372 373 374
	if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
		return MODE_NO_DBLESCAN;

375
	max_link_clock = intel_dp_max_link_rate(intel_dp);
376
	max_lanes = intel_dp_max_lane_count(intel_dp);
377 378 379

	max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
	mode_rate = intel_dp_link_required(mode->clock, bpp);
380

381 382 383 384 385 386 387
	/* TODO - validate mode against available PBN for link */
	if (mode->clock < 10000)
		return MODE_CLOCK_LOW;

	if (mode->flags & DRM_MODE_FLAG_DBLCLK)
		return MODE_H_ILLEGAL;

388
	if (mode_rate > max_rate || mode->clock > max_dotclk)
389 390
		return MODE_CLOCK_HIGH;

391 392 393
	return MODE_OK;
}

394 395 396 397 398 399 400
static struct drm_encoder *intel_mst_atomic_best_encoder(struct drm_connector *connector,
							 struct drm_connector_state *state)
{
	struct intel_connector *intel_connector = to_intel_connector(connector);
	struct intel_dp *intel_dp = intel_connector->mst_port;
	struct intel_crtc *crtc = to_intel_crtc(state->crtc);

401 402
	if (!intel_dp)
		return NULL;
403 404 405
	return &intel_dp->mst_encoders[crtc->pipe]->base.base;
}

406 407 408
static const struct drm_connector_helper_funcs intel_dp_mst_connector_helper_funcs = {
	.get_modes = intel_dp_mst_get_modes,
	.mode_valid = intel_dp_mst_mode_valid,
409
	.atomic_best_encoder = intel_mst_atomic_best_encoder,
410
	.atomic_check = intel_dp_mst_atomic_check,
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426
};

static void intel_dp_mst_encoder_destroy(struct drm_encoder *encoder)
{
	struct intel_dp_mst_encoder *intel_mst = enc_to_mst(encoder);

	drm_encoder_cleanup(encoder);
	kfree(intel_mst);
}

static const struct drm_encoder_funcs intel_dp_mst_enc_funcs = {
	.destroy = intel_dp_mst_encoder_destroy,
};

static bool intel_dp_mst_get_hw_state(struct intel_connector *connector)
{
427
	if (connector->encoder && connector->base.state->crtc) {
428 429 430 431 432 433 434 435
		enum pipe pipe;
		if (!connector->encoder->get_hw_state(connector->encoder, &pipe))
			return false;
		return true;
	}
	return false;
}

436
static struct drm_connector *intel_dp_add_mst_connector(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port, const char *pathprop)
437 438 439 440
{
	struct intel_dp *intel_dp = container_of(mgr, struct intel_dp, mst_mgr);
	struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
	struct drm_device *dev = intel_dig_port->base.base.dev;
M
Mika Kahola 已提交
441
	struct drm_i915_private *dev_priv = to_i915(dev);
442 443
	struct intel_connector *intel_connector;
	struct drm_connector *connector;
M
Mika Kahola 已提交
444
	enum pipe pipe;
445
	int ret;
446

447
	intel_connector = intel_connector_alloc();
448 449 450 451
	if (!intel_connector)
		return NULL;

	connector = &intel_connector->base;
452 453 454 455 456 457 458
	ret = drm_connector_init(dev, connector, &intel_dp_mst_connector_funcs,
				 DRM_MODE_CONNECTOR_DisplayPort);
	if (ret) {
		intel_connector_free(intel_connector);
		return NULL;
	}

459 460 461 462 463 464
	drm_connector_helper_add(connector, &intel_dp_mst_connector_helper_funcs);

	intel_connector->get_hw_state = intel_dp_mst_get_hw_state;
	intel_connector->mst_port = intel_dp;
	intel_connector->port = port;

M
Mika Kahola 已提交
465
	for_each_pipe(dev_priv, pipe) {
466 467 468
		struct drm_encoder *enc =
			&intel_dp->mst_encoders[pipe]->base.base;

469
		ret = drm_connector_attach_encoder(&intel_connector->base, enc);
470 471
		if (ret)
			goto err;
472 473 474
	}

	drm_object_attach_property(&connector->base, dev->mode_config.path_property, 0);
475 476
	drm_object_attach_property(&connector->base, dev->mode_config.tile_property, 0);

477 478 479 480
	ret = drm_mode_connector_set_path_property(connector, pathprop);
	if (ret)
		goto err;

481
	return connector;
482 483 484 485

err:
	drm_connector_cleanup(connector);
	return NULL;
486 487 488 489
}

static void intel_dp_register_mst_connector(struct drm_connector *connector)
{
490
	struct drm_i915_private *dev_priv = to_i915(connector->dev);
491

492 493 494
	if (dev_priv->fbdev)
		drm_fb_helper_add_one_connector(&dev_priv->fbdev->helper,
						connector);
495

496
	drm_connector_register(connector);
497 498 499 500 501 502
}

static void intel_dp_destroy_mst_connector(struct drm_dp_mst_topology_mgr *mgr,
					   struct drm_connector *connector)
{
	struct intel_connector *intel_connector = to_intel_connector(connector);
503
	struct drm_i915_private *dev_priv = to_i915(connector->dev);
504

505
	DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", connector->base.id, connector->name);
506
	drm_connector_unregister(connector);
507

508 509 510
	if (dev_priv->fbdev)
		drm_fb_helper_remove_one_connector(&dev_priv->fbdev->helper,
						   connector);
511 512
	/* prevent race with the check in ->detect */
	drm_modeset_lock(&connector->dev->mode_config.connection_mutex, NULL);
513
	intel_connector->mst_port = NULL;
514
	drm_modeset_unlock(&connector->dev->mode_config.connection_mutex);
515

516
	drm_connector_unreference(connector);
517 518 519 520 521 522 523 524 525 526 527
}

static void intel_dp_mst_hotplug(struct drm_dp_mst_topology_mgr *mgr)
{
	struct intel_dp *intel_dp = container_of(mgr, struct intel_dp, mst_mgr);
	struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
	struct drm_device *dev = intel_dig_port->base.base.dev;

	drm_kms_helper_hotplug_event(dev);
}

528
static const struct drm_dp_mst_topology_cbs mst_cbs = {
529
	.add_connector = intel_dp_add_mst_connector,
530
	.register_connector = intel_dp_register_mst_connector,
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551
	.destroy_connector = intel_dp_destroy_mst_connector,
	.hotplug = intel_dp_mst_hotplug,
};

static struct intel_dp_mst_encoder *
intel_dp_create_fake_mst_encoder(struct intel_digital_port *intel_dig_port, enum pipe pipe)
{
	struct intel_dp_mst_encoder *intel_mst;
	struct intel_encoder *intel_encoder;
	struct drm_device *dev = intel_dig_port->base.base.dev;

	intel_mst = kzalloc(sizeof(*intel_mst), GFP_KERNEL);

	if (!intel_mst)
		return NULL;

	intel_mst->pipe = pipe;
	intel_encoder = &intel_mst->base;
	intel_mst->primary = intel_dig_port;

	drm_encoder_init(dev, &intel_encoder->base, &intel_dp_mst_enc_funcs,
552
			 DRM_MODE_ENCODER_DPMST, "DP-MST %c", pipe_name(pipe));
553 554

	intel_encoder->type = INTEL_OUTPUT_DP_MST;
555
	intel_encoder->power_domain = intel_dig_port->base.power_domain;
556
	intel_encoder->port = intel_dig_port->base.port;
557 558 559 560 561 562
	intel_encoder->crtc_mask = 0x7;
	intel_encoder->cloneable = 0;

	intel_encoder->compute_config = intel_dp_mst_compute_config;
	intel_encoder->disable = intel_mst_disable_dp;
	intel_encoder->post_disable = intel_mst_post_disable_dp;
563
	intel_encoder->pre_pll_enable = intel_mst_pre_pll_enable_dp;
564 565 566 567 568 569 570 571 572 573 574 575 576
	intel_encoder->pre_enable = intel_mst_pre_enable_dp;
	intel_encoder->enable = intel_mst_enable_dp;
	intel_encoder->get_hw_state = intel_dp_mst_enc_get_hw_state;
	intel_encoder->get_config = intel_dp_mst_enc_get_config;

	return intel_mst;

}

static bool
intel_dp_create_fake_mst_encoders(struct intel_digital_port *intel_dig_port)
{
	struct intel_dp *intel_dp = &intel_dig_port->dp;
M
Mika Kahola 已提交
577 578
	struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
	enum pipe pipe;
579

M
Mika Kahola 已提交
580 581
	for_each_pipe(dev_priv, pipe)
		intel_dp->mst_encoders[pipe] = intel_dp_create_fake_mst_encoder(intel_dig_port, pipe);
582 583 584 585 586 587 588 589 590 591 592 593 594 595 596
	return true;
}

int
intel_dp_mst_encoder_init(struct intel_digital_port *intel_dig_port, int conn_base_id)
{
	struct intel_dp *intel_dp = &intel_dig_port->dp;
	struct drm_device *dev = intel_dig_port->base.base.dev;
	int ret;

	intel_dp->can_mst = true;
	intel_dp->mst_mgr.cbs = &mst_cbs;

	/* create encoders */
	intel_dp_create_fake_mst_encoders(intel_dig_port);
597 598
	ret = drm_dp_mst_topology_mgr_init(&intel_dp->mst_mgr, dev,
					   &intel_dp->aux, 16, 3, conn_base_id);
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616
	if (ret) {
		intel_dp->can_mst = false;
		return ret;
	}
	return 0;
}

void
intel_dp_mst_encoder_cleanup(struct intel_digital_port *intel_dig_port)
{
	struct intel_dp *intel_dp = &intel_dig_port->dp;

	if (!intel_dp->can_mst)
		return;

	drm_dp_mst_topology_mgr_destroy(&intel_dp->mst_mgr);
	/* encoders will get killed by normal cleanup */
}