dp.c 15.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
/*
 * Copyright 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 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: Ben Skeggs
 */
#include "dp.h"
#include "conn.h"
26
#include "ior.h"
27 28 29 30 31 32 33 34 35
#include "nv50.h"

#include <subdev/bios.h>
#include <subdev/bios/init.h>
#include <subdev/i2c.h>

#include <nvif/event.h>

struct lt_state {
36
	struct nvkm_dp *dp;
37 38 39 40 41 42 43 44 45 46
	u8  stat[6];
	u8  conf[4];
	bool pc2;
	u8  pc2stat;
	u8  pc2conf[2];
};

static int
nvkm_dp_train_sense(struct lt_state *lt, bool pc, u32 delay)
{
47
	struct nvkm_dp *dp = lt->dp;
48 49
	int ret;

50 51
	if (dp->dpcd[DPCD_RC0E_AUX_RD_INTERVAL])
		mdelay(dp->dpcd[DPCD_RC0E_AUX_RD_INTERVAL] * 4);
52 53 54
	else
		udelay(delay);

55
	ret = nvkm_rdaux(dp->aux, DPCD_LS02, lt->stat, 6);
56 57 58 59
	if (ret)
		return ret;

	if (pc) {
60
		ret = nvkm_rdaux(dp->aux, DPCD_LS0C, &lt->pc2stat, 1);
61 62
		if (ret)
			lt->pc2stat = 0x00;
63 64
		OUTP_TRACE(&dp->outp, "status %6ph pc2 %02x",
			   lt->stat, lt->pc2stat);
65
	} else {
66
		OUTP_TRACE(&dp->outp, "status %6ph", lt->stat);
67 68 69 70 71 72 73 74
	}

	return 0;
}

static int
nvkm_dp_train_drive(struct lt_state *lt, bool pc)
{
75
	struct nvkm_dp *dp = lt->dp;
76 77
	int ret, i;

78
	for (i = 0; i < dp->outp.ior->dp.nr; i++) {
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
		u8 lane = (lt->stat[4 + (i >> 1)] >> ((i & 1) * 4)) & 0xf;
		u8 lpc2 = (lt->pc2stat >> (i * 2)) & 0x3;
		u8 lpre = (lane & 0x0c) >> 2;
		u8 lvsw = (lane & 0x03) >> 0;
		u8 hivs = 3 - lpre;
		u8 hipe = 3;
		u8 hipc = 3;

		if (lpc2 >= hipc)
			lpc2 = hipc | DPCD_LC0F_LANE0_MAX_POST_CURSOR2_REACHED;
		if (lpre >= hipe) {
			lpre = hipe | DPCD_LC03_MAX_SWING_REACHED; /* yes. */
			lvsw = hivs = 3 - (lpre & 3);
		} else
		if (lvsw >= hivs) {
			lvsw = hivs | DPCD_LC03_MAX_SWING_REACHED;
		}

		lt->conf[i] = (lpre << 3) | lvsw;
		lt->pc2conf[i >> 1] |= lpc2 << ((i & 1) * 4);

100 101 102
		OUTP_TRACE(&dp->outp, "config lane %d %02x %02x",
			   i, lt->conf[i], lpc2);
		dp->func->drv_ctl(dp, i, lvsw & 3, lpre & 3, lpc2 & 3);
103 104
	}

105
	ret = nvkm_wraux(dp->aux, DPCD_LC03(0), lt->conf, 4);
106 107 108 109
	if (ret)
		return ret;

	if (pc) {
110
		ret = nvkm_wraux(dp->aux, DPCD_LC0F, lt->pc2conf, 2);
111 112 113 114 115 116 117 118 119 120
		if (ret)
			return ret;
	}

	return 0;
}

static void
nvkm_dp_train_pattern(struct lt_state *lt, u8 pattern)
{
121
	struct nvkm_dp *dp = lt->dp;
122 123
	u8 sink_tp;

124 125
	OUTP_TRACE(&dp->outp, "training pattern %d", pattern);
	dp->func->pattern(dp, pattern);
126

127
	nvkm_rdaux(dp->aux, DPCD_LC02, &sink_tp, 1);
128 129
	sink_tp &= ~DPCD_LC02_TRAINING_PATTERN_SET;
	sink_tp |= pattern;
130
	nvkm_wraux(dp->aux, DPCD_LC02, &sink_tp, 1);
131 132 133 134 135 136 137 138
}

static int
nvkm_dp_train_eq(struct lt_state *lt)
{
	bool eq_done = false, cr_done = true;
	int tries = 0, i;

139
	if (lt->dp->dpcd[DPCD_RC02] & DPCD_RC02_TPS3_SUPPORTED)
140 141 142 143 144 145 146 147 148 149 150
		nvkm_dp_train_pattern(lt, 3);
	else
		nvkm_dp_train_pattern(lt, 2);

	do {
		if ((tries &&
		    nvkm_dp_train_drive(lt, lt->pc2)) ||
		    nvkm_dp_train_sense(lt, lt->pc2, 400))
			break;

		eq_done = !!(lt->stat[2] & DPCD_LS04_INTERLANE_ALIGN_DONE);
151
		for (i = 0; i < lt->dp->outp.ior->dp.nr && eq_done; i++) {
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
			u8 lane = (lt->stat[i >> 1] >> ((i & 1) * 4)) & 0xf;
			if (!(lane & DPCD_LS02_LANE0_CR_DONE))
				cr_done = false;
			if (!(lane & DPCD_LS02_LANE0_CHANNEL_EQ_DONE) ||
			    !(lane & DPCD_LS02_LANE0_SYMBOL_LOCKED))
				eq_done = false;
		}
	} while (!eq_done && cr_done && ++tries <= 5);

	return eq_done ? 0 : -1;
}

static int
nvkm_dp_train_cr(struct lt_state *lt)
{
	bool cr_done = false, abort = false;
	int voltage = lt->conf[0] & DPCD_LC03_VOLTAGE_SWING_SET;
	int tries = 0, i;

	nvkm_dp_train_pattern(lt, 1);

	do {
		if (nvkm_dp_train_drive(lt, false) ||
		    nvkm_dp_train_sense(lt, false, 100))
			break;

		cr_done = true;
179
		for (i = 0; i < lt->dp->outp.ior->dp.nr; i++) {
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
			u8 lane = (lt->stat[i >> 1] >> ((i & 1) * 4)) & 0xf;
			if (!(lane & DPCD_LS02_LANE0_CR_DONE)) {
				cr_done = false;
				if (lt->conf[i] & DPCD_LC03_MAX_SWING_REACHED)
					abort = true;
				break;
			}
		}

		if ((lt->conf[0] & DPCD_LC03_VOLTAGE_SWING_SET) != voltage) {
			voltage = lt->conf[0] & DPCD_LC03_VOLTAGE_SWING_SET;
			tries = 0;
		}
	} while (!cr_done && !abort && ++tries < 5);

	return cr_done ? 0 : -1;
}

static int
199
nvkm_dp_train_links(struct nvkm_dp *dp)
200
{
201
	struct nvkm_ior *ior = dp->outp.ior;
202
	struct nvkm_disp *disp = dp->outp.disp;
203 204 205 206 207 208
	struct nvkm_subdev *subdev = &disp->engine.subdev;
	struct nvkm_bios *bios = subdev->device->bios;
	struct nvbios_init init = {
		.subdev = subdev,
		.bios = bios,
		.offset = 0x0000,
209
		.outp = &dp->outp.info,
210 211 212
		.crtc = -1,
		.execute = 1,
	};
213 214 215
	struct lt_state lt = {
		.dp = dp,
	};
216 217 218 219
	u32 lnkcmp;
	u8 sink[2];
	int ret;

220 221
	OUTP_DBG(&dp->outp, "training %d x %d MB/s",
		 ior->dp.nr, ior->dp.bw * 27);
222 223 224

	/* Intersect misc. capabilities of the OR and sink. */
	if (disp->engine.subdev.device->chipset < 0xd0)
225 226
		dp->dpcd[DPCD_RC02] &= ~DPCD_RC02_TPS3_SUPPORTED;
	lt.pc2 = dp->dpcd[DPCD_RC02] & DPCD_RC02_TPS3_SUPPORTED;
227 228

	/* Set desired link configuration on the source. */
229
	if ((lnkcmp = lt.dp->info.lnkcmp)) {
230
		if (dp->version < 0x30) {
231
			while ((ior->dp.bw * 2700) < nvbios_rd16(bios, lnkcmp))
232 233 234
				lnkcmp += 4;
			init.offset = nvbios_rd16(bios, lnkcmp + 2);
		} else {
235
			while (ior->dp.bw < nvbios_rd08(bios, lnkcmp))
236 237 238 239 240 241 242
				lnkcmp += 3;
			init.offset = nvbios_rd16(bios, lnkcmp + 1);
		}

		nvbios_exec(&init);
	}

243
	ret = dp->func->lnk_ctl(dp, ior->dp.nr, ior->dp.bw, ior->dp.ef);
244 245
	if (ret) {
		if (ret < 0)
246
			OUTP_ERR(&dp->outp, "lnk_ctl failed with %d", ret);
247 248 249
		return ret;
	}

250
	dp->func->lnk_pwr(dp, ior->dp.nr);
251 252

	/* Set desired link configuration on the sink. */
253 254 255
	sink[0] = ior->dp.bw;
	sink[1] = ior->dp.nr;
	if (ior->dp.ef)
256 257
		sink[1] |= DPCD_LC01_ENHANCED_FRAME_EN;

258 259 260 261 262 263 264 265 266 267 268
	ret = nvkm_wraux(dp->aux, DPCD_LC00_LINK_BW_SET, sink, 2);
	if (ret)
		return ret;

	/* Attempt to train the link in this configuration. */
	memset(lt.stat, 0x00, sizeof(lt.stat));
	ret = nvkm_dp_train_cr(&lt);
	if (ret == 0)
		ret = nvkm_dp_train_eq(&lt);
	nvkm_dp_train_pattern(&lt, 0);
	return ret;
269 270 271
}

static void
272
nvkm_dp_train_fini(struct nvkm_dp *dp)
273
{
274
	struct nvkm_subdev *subdev = &dp->outp.disp->engine.subdev;
275 276 277
	struct nvbios_init init = {
		.subdev = subdev,
		.bios = subdev->device->bios,
278
		.outp = &dp->outp.info,
279 280 281 282 283
		.crtc = -1,
		.execute = 1,
	};

	/* Execute AfterLinkTraining script from DP Info table. */
284
	init.offset = dp->info.script[1],
285 286 287 288
	nvbios_exec(&init);
}

static void
289
nvkm_dp_train_init(struct nvkm_dp *dp)
290
{
291
	struct nvkm_subdev *subdev = &dp->outp.disp->engine.subdev;
292 293 294
	struct nvbios_init init = {
		.subdev = subdev,
		.bios = subdev->device->bios,
295
		.outp = &dp->outp.info,
296 297 298 299 300
		.crtc = -1,
		.execute = 1,
	};

	/* Execute EnableSpread/DisableSpread script from DP Info table. */
301
	if (dp->dpcd[DPCD_RC03] & DPCD_RC03_MAX_DOWNSPREAD)
302
		init.offset = dp->info.script[2];
303
	else
304
		init.offset = dp->info.script[3];
305 306
	nvbios_exec(&init);

307 308
	/* Execute BeforeLinkTraining script from DP Info table. */
	init.offset = dp->info.script[0];
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
	nvbios_exec(&init);
}

static const struct dp_rates {
	u32 rate;
	u8  bw;
	u8  nr;
} nvkm_dp_rates[] = {
	{ 2160000, 0x14, 4 },
	{ 1080000, 0x0a, 4 },
	{ 1080000, 0x14, 2 },
	{  648000, 0x06, 4 },
	{  540000, 0x0a, 2 },
	{  540000, 0x14, 1 },
	{  324000, 0x06, 2 },
	{  270000, 0x0a, 1 },
	{  162000, 0x06, 1 },
	{}
};

329
static int
330
nvkm_dp_train(struct nvkm_dp *dp, u32 dataKBps)
331
{
332
	struct nv50_disp *disp = nv50_disp(dp->outp.disp);
333 334 335 336 337
	struct nvkm_ior *ior = dp->outp.ior;
	const u8 sink_nr = dp->dpcd[DPCD_RC02] & DPCD_RC02_MAX_LANE_COUNT;
	const u8 sink_bw = dp->dpcd[DPCD_RC01_MAX_LINK_RATE];
	const u8 outp_nr = dp->outp.info.dpconf.link_nr;
	const u8 outp_bw = dp->outp.info.dpconf.link_bw;
338 339
	const struct dp_rates *failsafe = NULL, *cfg;
	int ret = -EINVAL;
340 341
	u8  pwr;

342 343
	if (!dp->outp.info.location && disp->func->sor.magic)
		disp->func->sor.magic(&dp->outp);
344

345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
	/* Find the lowest configuration of the OR that can support
	 * the required link rate.
	 *
	 * We will refuse to program the OR to lower rates, even if
	 * link training fails at higher rates (or even if the sink
	 * can't support the rate at all, though the DD is supposed
	 * to prevent such situations from happening).
	 *
	 * Attempting to do so can cause the entire display to hang,
	 * and it's better to have a failed modeset than that.
	 */
	for (cfg = nvkm_dp_rates; cfg->rate; cfg++) {
		if (cfg->nr <= outp_nr && cfg->nr <= outp_bw)
			failsafe = cfg;
		if (failsafe && cfg[1].rate < dataKBps)
			break;
	}

	if (WARN_ON(!failsafe))
		return ret;

366
	/* Ensure sink is not in a low-power state. */
367
	if (!nvkm_rdaux(dp->aux, DPCD_SC00, &pwr, 1)) {
368 369 370
		if ((pwr & DPCD_SC00_SET_POWER) != DPCD_SC00_SET_POWER_D0) {
			pwr &= ~DPCD_SC00_SET_POWER;
			pwr |=  DPCD_SC00_SET_POWER_D0;
371
			nvkm_wraux(dp->aux, DPCD_SC00, &pwr, 1);
372 373 374 375
		}
	}

	/* Link training. */
376 377
	OUTP_DBG(&dp->outp, "training (min: %d x %d MB/s)",
		 failsafe->nr, failsafe->bw * 27);
378
	nvkm_dp_train_init(dp);
379
	for (cfg = nvkm_dp_rates; ret < 0 && cfg <= failsafe; cfg++) {
380
		/* Skip configurations not supported by both OR and sink. */
381 382 383 384 385 386
		if ((cfg->nr > outp_nr || cfg->bw > outp_bw ||
		     cfg->nr > sink_nr || cfg->bw > sink_bw)) {
			if (cfg != failsafe)
				continue;
			OUTP_ERR(&dp->outp, "link rate unsupported by sink");
		}
387 388 389 390
		ior->dp.mst = dp->lt.mst;
		ior->dp.ef = dp->dpcd[DPCD_RC02] & DPCD_RC02_ENHANCED_FRAME_CAP;
		ior->dp.bw = cfg->bw;
		ior->dp.nr = cfg->nr;
391 392

		/* Program selected link configuration. */
393
		ret = nvkm_dp_train_links(dp);
394
	}
395
	nvkm_dp_train_fini(dp);
396
	if (ret < 0)
397
		OUTP_ERR(&dp->outp, "training failed");
398 399
	else
		OUTP_DBG(&dp->outp, "training done");
400
	atomic_set(&dp->lt.done, 1);
401
	return ret;
402 403 404
}

int
405
nvkm_output_dp_train(struct nvkm_outp *outp, u32 datakbps)
406
{
407
	struct nvkm_dp *dp = nvkm_dp(outp);
408
	struct nvkm_ior *ior = dp->outp.ior;
409
	bool retrain = true;
410 411 412
	u32 linkKBps;
	u32 dataKBps;
	u8  stat[3];
413 414
	int ret, i;

415
	mutex_lock(&dp->mutex);
416

417 418 419 420 421
	/* Check that link configuration meets current requirements. */
	linkKBps = ior->dp.bw * 27000 * ior->dp.nr;
	dataKBps = DIV_ROUND_UP(datakbps, 8);
	if (linkKBps < dataKBps) {
		OUTP_DBG(&dp->outp, "link requirements changed");
422 423 424
		goto done;
	}

425
	/* Check that link is still trained. */
426
	ret = nvkm_rdaux(dp->aux, DPCD_LS02, stat, 3);
427
	if (ret) {
428
		OUTP_DBG(&dp->outp,
429 430 431 432 433
			 "failed to read link status, assuming no sink");
		goto done;
	}

	if (stat[2] & DPCD_LS04_INTERLANE_ALIGN_DONE) {
434
		for (i = 0; i < ior->dp.nr; i++) {
435 436 437 438
			u8 lane = (stat[i >> 1] >> ((i & 1) * 4)) & 0x0f;
			if (!(lane & DPCD_LS02_LANE0_CR_DONE) ||
			    !(lane & DPCD_LS02_LANE0_CHANNEL_EQ_DONE) ||
			    !(lane & DPCD_LS02_LANE0_SYMBOL_LOCKED)) {
439
				OUTP_DBG(&dp->outp,
440 441 442 443 444 445
					 "lane %d not equalised", lane);
				goto done;
			}
		}
		retrain = false;
	} else {
446
		OUTP_DBG(&dp->outp, "no inter-lane alignment");
447 448 449
	}

done:
450 451
	if (retrain || !atomic_read(&dp->lt.done))
		ret = nvkm_dp_train(dp, dataKBps);
452
	mutex_unlock(&dp->mutex);
453 454 455 456
	return ret;
}

static void
457
nvkm_dp_enable(struct nvkm_dp *dp, bool enable)
458
{
459
	struct nvkm_i2c_aux *aux = dp->aux;
460 461

	if (enable) {
462 463
		if (!dp->present) {
			OUTP_DBG(&dp->outp, "aux power -> always");
464
			nvkm_i2c_aux_monitor(aux, true);
465
			dp->present = true;
466 467
		}

468 469 470
		if (!nvkm_rdaux(aux, DPCD_RC00_DPCD_REV, dp->dpcd,
				sizeof(dp->dpcd))) {
			nvkm_output_dp_train(&dp->outp, 0);
471 472 473 474
			return;
		}
	}

475 476
	if (dp->present) {
		OUTP_DBG(&dp->outp, "aux power -> demand");
477
		nvkm_i2c_aux_monitor(aux, false);
478
		dp->present = false;
479 480
	}

481
	atomic_set(&dp->lt.done, 0);
482 483 484
}

static int
485
nvkm_dp_hpd(struct nvkm_notify *notify)
486 487
{
	const struct nvkm_i2c_ntfy_rep *line = notify->data;
488
	struct nvkm_dp *dp = container_of(notify, typeof(*dp), hpd);
489
	struct nvkm_conn *conn = dp->outp.conn;
490
	struct nvkm_disp *disp = dp->outp.disp;
491 492
	struct nvif_notify_conn_rep_v0 rep = {};

493
	OUTP_DBG(&dp->outp, "HPD: %d", line->mask);
494 495 496 497 498 499 500
	if (line->mask & NVKM_I2C_IRQ) {
		if (atomic_read(&dp->lt.done))
			nvkm_output_dp_train(&dp->outp, 0);
		rep.mask |= NVIF_NOTIFY_CONN_V0_IRQ;
	} else {
		nvkm_dp_enable(dp, true);
	}
501 502 503 504 505 506 507 508 509 510 511

	if (line->mask & NVKM_I2C_UNPLUG)
		rep.mask |= NVIF_NOTIFY_CONN_V0_UNPLUG;
	if (line->mask & NVKM_I2C_PLUG)
		rep.mask |= NVIF_NOTIFY_CONN_V0_PLUG;

	nvkm_event_send(&disp->hpd, rep.mask, conn->index, &rep, sizeof(rep));
	return NVKM_NOTIFY_KEEP;
}

static void
512
nvkm_dp_fini(struct nvkm_outp *outp)
513
{
514 515 516
	struct nvkm_dp *dp = nvkm_dp(outp);
	nvkm_notify_put(&dp->hpd);
	nvkm_dp_enable(dp, false);
517 518 519
}

static void
520
nvkm_dp_init(struct nvkm_outp *outp)
521
{
522 523 524 525
	struct nvkm_dp *dp = nvkm_dp(outp);
	nvkm_notify_put(&dp->outp.conn->hpd);
	nvkm_dp_enable(dp, true);
	nvkm_notify_get(&dp->hpd);
526 527 528
}

static void *
529
nvkm_dp_dtor(struct nvkm_outp *outp)
530
{
531 532 533
	struct nvkm_dp *dp = nvkm_dp(outp);
	nvkm_notify_fini(&dp->hpd);
	return dp;
534 535
}

536 537 538 539 540
static const struct nvkm_outp_func
nvkm_dp_func = {
	.dtor = nvkm_dp_dtor,
	.init = nvkm_dp_init,
	.fini = nvkm_dp_fini,
541 542
};

543 544 545
static int
nvkm_dp_ctor(struct nvkm_disp *disp, int index, struct dcb_output *dcbE,
	     struct nvkm_i2c_aux *aux, struct nvkm_dp *dp)
546 547 548 549 550 551 552 553
{
	struct nvkm_device *device = disp->engine.subdev.device;
	struct nvkm_bios *bios = device->bios;
	struct nvkm_i2c *i2c = device->i2c;
	u8  hdr, cnt, len;
	u32 data;
	int ret;

554 555 556 557
	ret = nvkm_outp_ctor(&nvkm_dp_func, disp, index, dcbE, &dp->outp);
	if (ret)
		return ret;

558 559 560
	dp->aux = aux;
	if (!dp->aux) {
		OUTP_ERR(&dp->outp, "no aux");
561 562 563 564
		return -ENODEV;
	}

	/* bios data is not optional */
565 566 567
	data = nvbios_dpout_match(bios, dp->outp.info.hasht,
				  dp->outp.info.hashm, &dp->version,
				  &hdr, &cnt, &len, &dp->info);
568
	if (!data) {
569
		OUTP_ERR(&dp->outp, "no bios dp data");
570 571 572
		return -ENODEV;
	}

573 574
	OUTP_DBG(&dp->outp, "bios dp %02x %02x %02x %02x",
		 dp->version, hdr, cnt, len);
575 576

	/* hotplug detect, replaces gpio-based mechanism with aux events */
577
	ret = nvkm_notify_init(NULL, &i2c->event, nvkm_dp_hpd, true,
578
			       &(struct nvkm_i2c_ntfy_req) {
579 580
				.mask = NVKM_I2C_PLUG | NVKM_I2C_UNPLUG |
					NVKM_I2C_IRQ,
581
				.port = dp->aux->id,
582 583 584
			       },
			       sizeof(struct nvkm_i2c_ntfy_req),
			       sizeof(struct nvkm_i2c_ntfy_rep),
585
			       &dp->hpd);
586
	if (ret) {
587
		OUTP_ERR(&dp->outp, "error monitoring aux hpd: %d", ret);
588 589 590
		return ret;
	}

591 592
	mutex_init(&dp->mutex);
	atomic_set(&dp->lt.done, 0);
593 594 595 596 597 598
	return 0;
}

int
nvkm_output_dp_new_(const struct nvkm_output_dp_func *func,
		    struct nvkm_disp *disp, int index, struct dcb_output *dcbE,
599
		    struct nvkm_outp **poutp)
600 601
{
	struct nvkm_i2c *i2c = disp->engine.subdev.device->i2c;
602 603 604 605 606 607 608
	struct nvkm_i2c_aux *aux;
	struct nvkm_dp *dp;

	if (dcbE->location == 0)
		aux = nvkm_i2c_aux_find(i2c, NVKM_I2C_AUX_CCB(dcbE->i2c_index));
	else
		aux = nvkm_i2c_aux_find(i2c, NVKM_I2C_AUX_EXT(dcbE->extdev));
609

610
	if (!(dp = kzalloc(sizeof(*dp), GFP_KERNEL)))
611
		return -ENOMEM;
612 613
	dp->func = func;
	*poutp = &dp->outp;
614

615
	return nvkm_dp_ctor(disp, index, dcbE, aux, dp);
616
}