intel_hdmi.c 34.5 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 29
/*
 * Copyright 2006 Dave Airlie <airlied@linux.ie>
 * Copyright © 2006-2009 Intel Corporation
 *
 * 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.
 *
 * Authors:
 *	Eric Anholt <eric@anholt.net>
 *	Jesse Barnes <jesse.barnes@intel.com>
 */

#include <linux/i2c.h>
30
#include <linux/slab.h>
31
#include <linux/delay.h>
32 33 34
#include <drm/drmP.h>
#include <drm/drm_crtc.h>
#include <drm/drm_edid.h>
35
#include "intel_drv.h"
36
#include <drm/i915_drm.h>
37 38
#include "i915_drv.h"

39 40
static struct drm_device *intel_hdmi_to_dev(struct intel_hdmi *intel_hdmi)
{
41
	return hdmi_to_dig_port(intel_hdmi)->base.base.dev;
42 43
}

44 45 46
static void
assert_hdmi_port_disabled(struct intel_hdmi *intel_hdmi)
{
47
	struct drm_device *dev = intel_hdmi_to_dev(intel_hdmi);
48 49 50
	struct drm_i915_private *dev_priv = dev->dev_private;
	uint32_t enabled_bits;

P
Paulo Zanoni 已提交
51
	enabled_bits = HAS_DDI(dev) ? DDI_BUF_CTL_ENABLE : SDVO_ENABLE;
52

53
	WARN(I915_READ(intel_hdmi->hdmi_reg) & enabled_bits,
54 55 56
	     "HDMI port enabled, expecting disabled\n");
}

57
struct intel_hdmi *enc_to_intel_hdmi(struct drm_encoder *encoder)
C
Chris Wilson 已提交
58
{
59 60 61
	struct intel_digital_port *intel_dig_port =
		container_of(encoder, struct intel_digital_port, base.base);
	return &intel_dig_port->hdmi;
C
Chris Wilson 已提交
62 63
}

64 65
static struct intel_hdmi *intel_attached_hdmi(struct drm_connector *connector)
{
66
	return enc_to_intel_hdmi(&intel_attached_encoder(connector)->base);
67 68
}

69
void intel_dip_infoframe_csum(struct dip_infoframe *frame)
70
{
71
	uint8_t *data = (uint8_t *)frame;
72 73 74
	uint8_t sum = 0;
	unsigned i;

75 76
	frame->checksum = 0;
	frame->ecc = 0;
77

78
	for (i = 0; i < frame->len + DIP_HEADER_SIZE; i++)
79 80
		sum += data[i];

81
	frame->checksum = 0x100 - sum;
82 83
}

84
static u32 g4x_infoframe_index(struct dip_infoframe *frame)
85
{
86 87
	switch (frame->type) {
	case DIP_TYPE_AVI:
88
		return VIDEO_DIP_SELECT_AVI;
89
	case DIP_TYPE_SPD:
90
		return VIDEO_DIP_SELECT_SPD;
91 92
	default:
		DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type);
93
		return 0;
94 95 96
	}
}

97
static u32 g4x_infoframe_enable(struct dip_infoframe *frame)
98 99 100
{
	switch (frame->type) {
	case DIP_TYPE_AVI:
101
		return VIDEO_DIP_ENABLE_AVI;
102
	case DIP_TYPE_SPD:
103
		return VIDEO_DIP_ENABLE_SPD;
104 105
	default:
		DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type);
106
		return 0;
107 108 109
	}
}

110 111 112 113 114 115 116 117 118 119 120 121 122
static u32 hsw_infoframe_enable(struct dip_infoframe *frame)
{
	switch (frame->type) {
	case DIP_TYPE_AVI:
		return VIDEO_DIP_ENABLE_AVI_HSW;
	case DIP_TYPE_SPD:
		return VIDEO_DIP_ENABLE_SPD_HSW;
	default:
		DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type);
		return 0;
	}
}

123 124
static u32 hsw_infoframe_data_reg(struct dip_infoframe *frame,
				  enum transcoder cpu_transcoder)
125 126 127
{
	switch (frame->type) {
	case DIP_TYPE_AVI:
128
		return HSW_TVIDEO_DIP_AVI_DATA(cpu_transcoder);
129
	case DIP_TYPE_SPD:
130
		return HSW_TVIDEO_DIP_SPD_DATA(cpu_transcoder);
131 132 133 134 135 136
	default:
		DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type);
		return 0;
	}
}

137 138
static void g4x_write_infoframe(struct drm_encoder *encoder,
				struct dip_infoframe *frame)
139 140
{
	uint32_t *data = (uint32_t *)frame;
141 142
	struct drm_device *dev = encoder->dev;
	struct drm_i915_private *dev_priv = dev->dev_private;
143
	u32 val = I915_READ(VIDEO_DIP_CTL);
144
	unsigned i, len = DIP_HEADER_SIZE + frame->len;
145

146 147
	WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");

148
	val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
149
	val |= g4x_infoframe_index(frame);
150

151
	val &= ~g4x_infoframe_enable(frame);
152

153
	I915_WRITE(VIDEO_DIP_CTL, val);
154

155
	mmiowb();
156
	for (i = 0; i < len; i += 4) {
157 158 159
		I915_WRITE(VIDEO_DIP_DATA, *data);
		data++;
	}
160 161 162
	/* Write every possible data byte to force correct ECC calculation. */
	for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
		I915_WRITE(VIDEO_DIP_DATA, 0);
163
	mmiowb();
164

165
	val |= g4x_infoframe_enable(frame);
166
	val &= ~VIDEO_DIP_FREQ_MASK;
167
	val |= VIDEO_DIP_FREQ_VSYNC;
168

169
	I915_WRITE(VIDEO_DIP_CTL, val);
170
	POSTING_READ(VIDEO_DIP_CTL);
171 172
}

173 174 175 176 177 178
static void ibx_write_infoframe(struct drm_encoder *encoder,
				struct dip_infoframe *frame)
{
	uint32_t *data = (uint32_t *)frame;
	struct drm_device *dev = encoder->dev;
	struct drm_i915_private *dev_priv = dev->dev_private;
179
	struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
180 181 182 183
	int reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
	unsigned i, len = DIP_HEADER_SIZE + frame->len;
	u32 val = I915_READ(reg);

184 185
	WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");

186
	val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
187
	val |= g4x_infoframe_index(frame);
188

189
	val &= ~g4x_infoframe_enable(frame);
190 191 192

	I915_WRITE(reg, val);

193
	mmiowb();
194 195 196 197
	for (i = 0; i < len; i += 4) {
		I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
		data++;
	}
198 199 200
	/* Write every possible data byte to force correct ECC calculation. */
	for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
		I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), 0);
201
	mmiowb();
202

203
	val |= g4x_infoframe_enable(frame);
204
	val &= ~VIDEO_DIP_FREQ_MASK;
205
	val |= VIDEO_DIP_FREQ_VSYNC;
206 207

	I915_WRITE(reg, val);
208
	POSTING_READ(reg);
209 210 211 212
}

static void cpt_write_infoframe(struct drm_encoder *encoder,
				struct dip_infoframe *frame)
213
{
214
	uint32_t *data = (uint32_t *)frame;
215 216
	struct drm_device *dev = encoder->dev;
	struct drm_i915_private *dev_priv = dev->dev_private;
217
	struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
218
	int reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
219
	unsigned i, len = DIP_HEADER_SIZE + frame->len;
220
	u32 val = I915_READ(reg);
221

222 223
	WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");

224
	val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
225
	val |= g4x_infoframe_index(frame);
226

227 228
	/* The DIP control register spec says that we need to update the AVI
	 * infoframe without clearing its enable bit */
229
	if (frame->type != DIP_TYPE_AVI)
230
		val &= ~g4x_infoframe_enable(frame);
231

232
	I915_WRITE(reg, val);
233

234
	mmiowb();
235
	for (i = 0; i < len; i += 4) {
236 237 238
		I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
		data++;
	}
239 240 241
	/* Write every possible data byte to force correct ECC calculation. */
	for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
		I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), 0);
242
	mmiowb();
243

244
	val |= g4x_infoframe_enable(frame);
245
	val &= ~VIDEO_DIP_FREQ_MASK;
246
	val |= VIDEO_DIP_FREQ_VSYNC;
247

248
	I915_WRITE(reg, val);
249
	POSTING_READ(reg);
250
}
251 252 253 254 255 256 257

static void vlv_write_infoframe(struct drm_encoder *encoder,
				     struct dip_infoframe *frame)
{
	uint32_t *data = (uint32_t *)frame;
	struct drm_device *dev = encoder->dev;
	struct drm_i915_private *dev_priv = dev->dev_private;
258
	struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
259 260
	int reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
	unsigned i, len = DIP_HEADER_SIZE + frame->len;
261
	u32 val = I915_READ(reg);
262

263 264
	WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");

265
	val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
266
	val |= g4x_infoframe_index(frame);
267

268
	val &= ~g4x_infoframe_enable(frame);
269

270
	I915_WRITE(reg, val);
271

272
	mmiowb();
273 274 275 276
	for (i = 0; i < len; i += 4) {
		I915_WRITE(VLV_TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
		data++;
	}
277 278 279
	/* Write every possible data byte to force correct ECC calculation. */
	for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
		I915_WRITE(VLV_TVIDEO_DIP_DATA(intel_crtc->pipe), 0);
280
	mmiowb();
281

282
	val |= g4x_infoframe_enable(frame);
283
	val &= ~VIDEO_DIP_FREQ_MASK;
284
	val |= VIDEO_DIP_FREQ_VSYNC;
285

286
	I915_WRITE(reg, val);
287
	POSTING_READ(reg);
288 289
}

290
static void hsw_write_infoframe(struct drm_encoder *encoder,
291
				struct dip_infoframe *frame)
292
{
293 294 295 296
	uint32_t *data = (uint32_t *)frame;
	struct drm_device *dev = encoder->dev;
	struct drm_i915_private *dev_priv = dev->dev_private;
	struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
297 298
	u32 ctl_reg = HSW_TVIDEO_DIP_CTL(intel_crtc->config.cpu_transcoder);
	u32 data_reg = hsw_infoframe_data_reg(frame, intel_crtc->config.cpu_transcoder);
299 300
	unsigned int i, len = DIP_HEADER_SIZE + frame->len;
	u32 val = I915_READ(ctl_reg);
301

302 303 304 305 306 307
	if (data_reg == 0)
		return;

	val &= ~hsw_infoframe_enable(frame);
	I915_WRITE(ctl_reg, val);

308
	mmiowb();
309 310 311 312
	for (i = 0; i < len; i += 4) {
		I915_WRITE(data_reg + i, *data);
		data++;
	}
313 314 315
	/* Write every possible data byte to force correct ECC calculation. */
	for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
		I915_WRITE(data_reg + i, 0);
316
	mmiowb();
317

318 319
	val |= hsw_infoframe_enable(frame);
	I915_WRITE(ctl_reg, val);
320
	POSTING_READ(ctl_reg);
321 322
}

323 324 325 326 327 328 329 330 331
static void intel_set_infoframe(struct drm_encoder *encoder,
				struct dip_infoframe *frame)
{
	struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);

	intel_dip_infoframe_csum(frame);
	intel_hdmi->write_infoframe(encoder, frame);
}

332
static void intel_hdmi_set_avi_infoframe(struct drm_encoder *encoder,
P
Paulo Zanoni 已提交
333
					 struct drm_display_mode *adjusted_mode)
334
{
335
	struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
336
	struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
337 338 339 340 341 342
	struct dip_infoframe avi_if = {
		.type = DIP_TYPE_AVI,
		.ver = DIP_VERSION_AVI,
		.len = DIP_LEN_AVI,
	};

P
Paulo Zanoni 已提交
343 344 345
	if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
		avi_if.body.avi.YQ_CN_PR |= DIP_AVI_PR_2;

346
	if (intel_hdmi->rgb_quant_range_selectable) {
347
		if (intel_crtc->config.limited_color_range)
348 349 350 351 352
			avi_if.body.avi.ITC_EC_Q_SC |= DIP_AVI_RGB_QUANT_RANGE_LIMITED;
		else
			avi_if.body.avi.ITC_EC_Q_SC |= DIP_AVI_RGB_QUANT_RANGE_FULL;
	}

353
	avi_if.body.avi.VIC = drm_match_cea_mode(adjusted_mode);
354

355
	intel_set_infoframe(encoder, &avi_if);
356 357
}

358
static void intel_hdmi_set_spd_infoframe(struct drm_encoder *encoder)
359 360 361 362 363 364 365 366 367 368 369 370 371 372
{
	struct dip_infoframe spd_if;

	memset(&spd_if, 0, sizeof(spd_if));
	spd_if.type = DIP_TYPE_SPD;
	spd_if.ver = DIP_VERSION_SPD;
	spd_if.len = DIP_LEN_SPD;
	strcpy(spd_if.body.spd.vn, "Intel");
	strcpy(spd_if.body.spd.pd, "Integrated gfx");
	spd_if.body.spd.sdi = DIP_SPD_PC;

	intel_set_infoframe(encoder, &spd_if);
}

373 374 375
static void g4x_set_infoframes(struct drm_encoder *encoder,
			       struct drm_display_mode *adjusted_mode)
{
376
	struct drm_i915_private *dev_priv = encoder->dev->dev_private;
377 378
	struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
	struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
379 380
	u32 reg = VIDEO_DIP_CTL;
	u32 val = I915_READ(reg);
381
	u32 port;
382

383 384
	assert_hdmi_port_disabled(intel_hdmi);

385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
	/* If the registers were not initialized yet, they might be zeroes,
	 * which means we're selecting the AVI DIP and we're setting its
	 * frequency to once. This seems to really confuse the HW and make
	 * things stop working (the register spec says the AVI always needs to
	 * be sent every VSync). So here we avoid writing to the register more
	 * than we need and also explicitly select the AVI DIP and explicitly
	 * set its frequency to every VSync. Avoiding to write it twice seems to
	 * be enough to solve the problem, but being defensive shouldn't hurt us
	 * either. */
	val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;

	if (!intel_hdmi->has_hdmi_sink) {
		if (!(val & VIDEO_DIP_ENABLE))
			return;
		val &= ~VIDEO_DIP_ENABLE;
		I915_WRITE(reg, val);
401
		POSTING_READ(reg);
402 403 404
		return;
	}

405 406
	switch (intel_dig_port->port) {
	case PORT_B:
407
		port = VIDEO_DIP_PORT_B;
408
		break;
409
	case PORT_C:
410
		port = VIDEO_DIP_PORT_C;
411 412
		break;
	default:
413
		BUG();
414 415 416
		return;
	}

417 418 419 420
	if (port != (val & VIDEO_DIP_PORT_MASK)) {
		if (val & VIDEO_DIP_ENABLE) {
			val &= ~VIDEO_DIP_ENABLE;
			I915_WRITE(reg, val);
421
			POSTING_READ(reg);
422 423 424 425 426
		}
		val &= ~VIDEO_DIP_PORT_MASK;
		val |= port;
	}

427
	val |= VIDEO_DIP_ENABLE;
428
	val &= ~VIDEO_DIP_ENABLE_VENDOR;
429

430
	I915_WRITE(reg, val);
431
	POSTING_READ(reg);
432

433 434 435 436 437 438 439
	intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
	intel_hdmi_set_spd_infoframe(encoder);
}

static void ibx_set_infoframes(struct drm_encoder *encoder,
			       struct drm_display_mode *adjusted_mode)
{
440 441
	struct drm_i915_private *dev_priv = encoder->dev->dev_private;
	struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
442 443
	struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
	struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
444 445
	u32 reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
	u32 val = I915_READ(reg);
446
	u32 port;
447

448 449
	assert_hdmi_port_disabled(intel_hdmi);

450 451 452 453 454 455 456 457
	/* See the big comment in g4x_set_infoframes() */
	val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;

	if (!intel_hdmi->has_hdmi_sink) {
		if (!(val & VIDEO_DIP_ENABLE))
			return;
		val &= ~VIDEO_DIP_ENABLE;
		I915_WRITE(reg, val);
458
		POSTING_READ(reg);
459 460 461
		return;
	}

462 463
	switch (intel_dig_port->port) {
	case PORT_B:
464
		port = VIDEO_DIP_PORT_B;
465
		break;
466
	case PORT_C:
467
		port = VIDEO_DIP_PORT_C;
468
		break;
469
	case PORT_D:
470
		port = VIDEO_DIP_PORT_D;
471 472
		break;
	default:
473
		BUG();
474 475 476
		return;
	}

477 478 479 480
	if (port != (val & VIDEO_DIP_PORT_MASK)) {
		if (val & VIDEO_DIP_ENABLE) {
			val &= ~VIDEO_DIP_ENABLE;
			I915_WRITE(reg, val);
481
			POSTING_READ(reg);
482 483 484 485 486
		}
		val &= ~VIDEO_DIP_PORT_MASK;
		val |= port;
	}

487
	val |= VIDEO_DIP_ENABLE;
488 489
	val &= ~(VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
		 VIDEO_DIP_ENABLE_GCP);
490

491
	I915_WRITE(reg, val);
492
	POSTING_READ(reg);
493

494 495 496 497 498 499 500
	intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
	intel_hdmi_set_spd_infoframe(encoder);
}

static void cpt_set_infoframes(struct drm_encoder *encoder,
			       struct drm_display_mode *adjusted_mode)
{
501 502 503 504 505 506
	struct drm_i915_private *dev_priv = encoder->dev->dev_private;
	struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
	struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
	u32 reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
	u32 val = I915_READ(reg);

507 508
	assert_hdmi_port_disabled(intel_hdmi);

509 510 511 512 513 514 515 516
	/* See the big comment in g4x_set_infoframes() */
	val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;

	if (!intel_hdmi->has_hdmi_sink) {
		if (!(val & VIDEO_DIP_ENABLE))
			return;
		val &= ~(VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI);
		I915_WRITE(reg, val);
517
		POSTING_READ(reg);
518 519 520
		return;
	}

521 522
	/* Set both together, unset both together: see the spec. */
	val |= VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI;
523 524
	val &= ~(VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
		 VIDEO_DIP_ENABLE_GCP);
525 526

	I915_WRITE(reg, val);
527
	POSTING_READ(reg);
528

529 530 531 532 533 534 535
	intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
	intel_hdmi_set_spd_infoframe(encoder);
}

static void vlv_set_infoframes(struct drm_encoder *encoder,
			       struct drm_display_mode *adjusted_mode)
{
536 537 538 539 540 541
	struct drm_i915_private *dev_priv = encoder->dev->dev_private;
	struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
	struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
	u32 reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
	u32 val = I915_READ(reg);

542 543
	assert_hdmi_port_disabled(intel_hdmi);

544 545 546 547 548 549 550 551
	/* See the big comment in g4x_set_infoframes() */
	val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;

	if (!intel_hdmi->has_hdmi_sink) {
		if (!(val & VIDEO_DIP_ENABLE))
			return;
		val &= ~VIDEO_DIP_ENABLE;
		I915_WRITE(reg, val);
552
		POSTING_READ(reg);
553 554 555
		return;
	}

556
	val |= VIDEO_DIP_ENABLE;
557 558
	val &= ~(VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
		 VIDEO_DIP_ENABLE_GCP);
559 560

	I915_WRITE(reg, val);
561
	POSTING_READ(reg);
562

563 564 565 566 567 568 569
	intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
	intel_hdmi_set_spd_infoframe(encoder);
}

static void hsw_set_infoframes(struct drm_encoder *encoder,
			       struct drm_display_mode *adjusted_mode)
{
570 571 572
	struct drm_i915_private *dev_priv = encoder->dev->dev_private;
	struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
	struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
573
	u32 reg = HSW_TVIDEO_DIP_CTL(intel_crtc->config.cpu_transcoder);
574
	u32 val = I915_READ(reg);
575

576 577
	assert_hdmi_port_disabled(intel_hdmi);

578 579
	if (!intel_hdmi->has_hdmi_sink) {
		I915_WRITE(reg, 0);
580
		POSTING_READ(reg);
581 582 583
		return;
	}

584 585 586 587
	val &= ~(VIDEO_DIP_ENABLE_VSC_HSW | VIDEO_DIP_ENABLE_GCP_HSW |
		 VIDEO_DIP_ENABLE_VS_HSW | VIDEO_DIP_ENABLE_GMP_HSW);

	I915_WRITE(reg, val);
588
	POSTING_READ(reg);
589

590 591 592 593
	intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
	intel_hdmi_set_spd_infoframe(encoder);
}

594 595 596 597 598 599
static void intel_hdmi_mode_set(struct drm_encoder *encoder,
				struct drm_display_mode *mode,
				struct drm_display_mode *adjusted_mode)
{
	struct drm_device *dev = encoder->dev;
	struct drm_i915_private *dev_priv = dev->dev_private;
600
	struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
C
Chris Wilson 已提交
601
	struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
602
	u32 hdmi_val;
603

604
	hdmi_val = SDVO_ENCODING_HDMI;
605
	if (!HAS_PCH_SPLIT(dev) && !IS_VALLEYVIEW(dev))
606
		hdmi_val |= intel_hdmi->color_range;
607
	if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
608
		hdmi_val |= SDVO_VSYNC_ACTIVE_HIGH;
609
	if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
610
		hdmi_val |= SDVO_HSYNC_ACTIVE_HIGH;
611

612
	if (intel_crtc->config.pipe_bpp > 24)
613
		hdmi_val |= HDMI_COLOR_FORMAT_12bpc;
614
	else
615
		hdmi_val |= SDVO_COLOR_FORMAT_8bpc;
616

617 618
	/* Required on CPT */
	if (intel_hdmi->has_hdmi_sink && HAS_PCH_CPT(dev))
619
		hdmi_val |= HDMI_MODE_SELECT_HDMI;
620

621
	if (intel_hdmi->has_audio) {
622 623
		DRM_DEBUG_DRIVER("Enabling HDMI audio on pipe %c\n",
				 pipe_name(intel_crtc->pipe));
624
		hdmi_val |= SDVO_AUDIO_ENABLE;
625
		hdmi_val |= HDMI_MODE_SELECT_HDMI;
626
		intel_write_eld(encoder, adjusted_mode);
627
	}
628

629
	if (HAS_PCH_CPT(dev))
630 631 632
		hdmi_val |= SDVO_PIPE_SEL_CPT(intel_crtc->pipe);
	else
		hdmi_val |= SDVO_PIPE_SEL(intel_crtc->pipe);
633

634 635
	I915_WRITE(intel_hdmi->hdmi_reg, hdmi_val);
	POSTING_READ(intel_hdmi->hdmi_reg);
636

637
	intel_hdmi->set_infoframes(encoder, adjusted_mode);
638 639
}

640 641
static bool intel_hdmi_get_hw_state(struct intel_encoder *encoder,
				    enum pipe *pipe)
642
{
643
	struct drm_device *dev = encoder->base.dev;
644
	struct drm_i915_private *dev_priv = dev->dev_private;
645 646 647
	struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
	u32 tmp;

648
	tmp = I915_READ(intel_hdmi->hdmi_reg);
649 650 651 652 653 654 655 656 657 658 659 660

	if (!(tmp & SDVO_ENABLE))
		return false;

	if (HAS_PCH_CPT(dev))
		*pipe = PORT_TO_PIPE_CPT(tmp);
	else
		*pipe = PORT_TO_PIPE(tmp);

	return true;
}

661
static void intel_enable_hdmi(struct intel_encoder *encoder)
662
{
663
	struct drm_device *dev = encoder->base.dev;
664
	struct drm_i915_private *dev_priv = dev->dev_private;
665
	struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
666
	struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
667
	u32 temp;
668 669 670 671
	u32 enable_bits = SDVO_ENABLE;

	if (intel_hdmi->has_audio)
		enable_bits |= SDVO_AUDIO_ENABLE;
672

673
	temp = I915_READ(intel_hdmi->hdmi_reg);
674

675
	/* HW workaround for IBX, we need to move the port to transcoder A
676 677 678
	 * before disabling it, so restore the transcoder select bit here. */
	if (HAS_PCH_IBX(dev))
		enable_bits |= SDVO_PIPE_SEL(intel_crtc->pipe);
679

680 681 682
	/* HW workaround, need to toggle enable bit off and on for 12bpc, but
	 * we do this anyway which shows more stable in testing.
	 */
683
	if (HAS_PCH_SPLIT(dev)) {
684 685
		I915_WRITE(intel_hdmi->hdmi_reg, temp & ~SDVO_ENABLE);
		POSTING_READ(intel_hdmi->hdmi_reg);
686 687
	}

688 689
	temp |= enable_bits;

690 691
	I915_WRITE(intel_hdmi->hdmi_reg, temp);
	POSTING_READ(intel_hdmi->hdmi_reg);
692 693 694 695 696

	/* HW workaround, need to write this twice for issue that may result
	 * in first write getting masked.
	 */
	if (HAS_PCH_SPLIT(dev)) {
697 698
		I915_WRITE(intel_hdmi->hdmi_reg, temp);
		POSTING_READ(intel_hdmi->hdmi_reg);
699
	}
700 701 702 703 704 705 706 707

	if (IS_VALLEYVIEW(dev)) {
		struct intel_digital_port *dport =
			enc_to_dig_port(&encoder->base);
		int channel = vlv_dport_to_channel(dport);

		vlv_wait_port_ready(dev_priv, channel);
	}
708 709 710 711 712 713 714 715
}

static void intel_disable_hdmi(struct intel_encoder *encoder)
{
	struct drm_device *dev = encoder->base.dev;
	struct drm_i915_private *dev_priv = dev->dev_private;
	struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
	u32 temp;
716
	u32 enable_bits = SDVO_ENABLE | SDVO_AUDIO_ENABLE;
717

718
	temp = I915_READ(intel_hdmi->hdmi_reg);
719 720 721 722 723 724 725 726 727

	/* HW workaround for IBX, we need to move the port to transcoder A
	 * before disabling it. */
	if (HAS_PCH_IBX(dev)) {
		struct drm_crtc *crtc = encoder->base.crtc;
		int pipe = crtc ? to_intel_crtc(crtc)->pipe : -1;

		if (temp & SDVO_PIPE_B_SELECT) {
			temp &= ~SDVO_PIPE_B_SELECT;
728 729
			I915_WRITE(intel_hdmi->hdmi_reg, temp);
			POSTING_READ(intel_hdmi->hdmi_reg);
730 731

			/* Again we need to write this twice. */
732 733
			I915_WRITE(intel_hdmi->hdmi_reg, temp);
			POSTING_READ(intel_hdmi->hdmi_reg);
734 735 736 737 738 739 740 741

			/* Transcoder selection bits only update
			 * effectively on vblank. */
			if (crtc)
				intel_wait_for_vblank(dev, pipe);
			else
				msleep(50);
		}
742
	}
743

744 745 746 747
	/* HW workaround, need to toggle enable bit off and on for 12bpc, but
	 * we do this anyway which shows more stable in testing.
	 */
	if (HAS_PCH_SPLIT(dev)) {
748 749
		I915_WRITE(intel_hdmi->hdmi_reg, temp & ~SDVO_ENABLE);
		POSTING_READ(intel_hdmi->hdmi_reg);
750 751 752
	}

	temp &= ~enable_bits;
753

754 755
	I915_WRITE(intel_hdmi->hdmi_reg, temp);
	POSTING_READ(intel_hdmi->hdmi_reg);
756 757 758 759

	/* HW workaround, need to write this twice for issue that may result
	 * in first write getting masked.
	 */
760
	if (HAS_PCH_SPLIT(dev)) {
761 762
		I915_WRITE(intel_hdmi->hdmi_reg, temp);
		POSTING_READ(intel_hdmi->hdmi_reg);
763
	}
764 765 766 767 768 769 770 771
}

static int intel_hdmi_mode_valid(struct drm_connector *connector,
				 struct drm_display_mode *mode)
{
	if (mode->clock > 165000)
		return MODE_CLOCK_HIGH;
	if (mode->clock < 20000)
772
		return MODE_CLOCK_LOW;
773 774 775 776 777 778 779

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

	return MODE_OK;
}

780 781
bool intel_hdmi_compute_config(struct intel_encoder *encoder,
			       struct intel_crtc_config *pipe_config)
782
{
783 784 785
	struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
	struct drm_device *dev = encoder->base.dev;
	struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
786
	int clock_12bpc = pipe_config->requested_mode.clock * 3 / 2;
787
	int desired_bpp;
788

789 790 791
	if (intel_hdmi->color_range_auto) {
		/* See CEA-861-E - 5.1 Default Encoding Parameters */
		if (intel_hdmi->has_hdmi_sink &&
792
		    drm_match_cea_mode(adjusted_mode) > 1)
793
			intel_hdmi->color_range = HDMI_COLOR_RANGE_16_235;
794 795 796 797
		else
			intel_hdmi->color_range = 0;
	}

798
	if (intel_hdmi->color_range)
799
		pipe_config->limited_color_range = true;
800

801 802 803
	if (HAS_PCH_SPLIT(dev) && !HAS_DDI(dev))
		pipe_config->has_pch_encoder = true;

804 805 806
	/*
	 * HDMI is either 12 or 8, so if the display lets 10bpc sneak
	 * through, clamp it down. Note that g4x/vlv don't support 12bpc hdmi
807 808
	 * outputs. We also need to check that the higher clock still fits
	 * within limits.
809
	 */
810 811
	if (pipe_config->pipe_bpp > 8*3 && clock_12bpc <= 225000
	    && HAS_PCH_SPLIT(dev)) {
812 813
		DRM_DEBUG_KMS("picking bpc to 12 for HDMI output\n");
		desired_bpp = 12*3;
814 815 816 817 818

		/* Need to adjust the port link by 1.5x for 12bpc. */
		adjusted_mode->clock = clock_12bpc;
		pipe_config->pixel_target_clock =
			pipe_config->requested_mode.clock;
819
	} else {
820 821 822 823 824 825 826
		DRM_DEBUG_KMS("picking bpc to 8 for HDMI output\n");
		desired_bpp = 8*3;
	}

	if (!pipe_config->bw_constrained) {
		DRM_DEBUG_KMS("forcing pipe bpc to %i for HDMI\n", desired_bpp);
		pipe_config->pipe_bpp = desired_bpp;
827 828
	}

829 830 831 832 833
	if (adjusted_mode->clock > 225000) {
		DRM_DEBUG_KMS("too high HDMI clock, rejecting mode\n");
		return false;
	}

834 835 836
	return true;
}

837
static enum drm_connector_status
838
intel_hdmi_detect(struct drm_connector *connector, bool force)
839
{
840
	struct drm_device *dev = connector->dev;
841
	struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
842 843 844
	struct intel_digital_port *intel_dig_port =
		hdmi_to_dig_port(intel_hdmi);
	struct intel_encoder *intel_encoder = &intel_dig_port->base;
845
	struct drm_i915_private *dev_priv = dev->dev_private;
846
	struct edid *edid;
847
	enum drm_connector_status status = connector_status_disconnected;
848

C
Chris Wilson 已提交
849
	intel_hdmi->has_hdmi_sink = false;
850
	intel_hdmi->has_audio = false;
851
	intel_hdmi->rgb_quant_range_selectable = false;
852
	edid = drm_get_edid(connector,
853 854
			    intel_gmbus_get_adapter(dev_priv,
						    intel_hdmi->ddc_bus));
855

856
	if (edid) {
857
		if (edid->input & DRM_EDID_INPUT_DIGITAL) {
858
			status = connector_status_connected;
859 860 861
			if (intel_hdmi->force_audio != HDMI_AUDIO_OFF_DVI)
				intel_hdmi->has_hdmi_sink =
						drm_detect_hdmi_monitor(edid);
862
			intel_hdmi->has_audio = drm_detect_monitor_audio(edid);
863 864
			intel_hdmi->rgb_quant_range_selectable =
				drm_rgb_quant_range_selectable(edid);
865 866
		}
		kfree(edid);
867
	}
868

869
	if (status == connector_status_connected) {
870 871 872
		if (intel_hdmi->force_audio != HDMI_AUDIO_AUTO)
			intel_hdmi->has_audio =
				(intel_hdmi->force_audio == HDMI_AUDIO_ON);
873
		intel_encoder->type = INTEL_OUTPUT_HDMI;
874 875
	}

876
	return status;
877 878 879 880
}

static int intel_hdmi_get_modes(struct drm_connector *connector)
{
881
	struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
882
	struct drm_i915_private *dev_priv = connector->dev->dev_private;
883 884 885 886 887

	/* We should parse the EDID data and find out if it's an HDMI sink so
	 * we can send audio to it.
	 */

888
	return intel_ddc_get_modes(connector,
889 890
				   intel_gmbus_get_adapter(dev_priv,
							   intel_hdmi->ddc_bus));
891 892
}

893 894 895 896 897 898 899 900 901
static bool
intel_hdmi_detect_audio(struct drm_connector *connector)
{
	struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
	struct drm_i915_private *dev_priv = connector->dev->dev_private;
	struct edid *edid;
	bool has_audio = false;

	edid = drm_get_edid(connector,
902 903
			    intel_gmbus_get_adapter(dev_priv,
						    intel_hdmi->ddc_bus));
904 905 906 907 908 909 910 911 912
	if (edid) {
		if (edid->input & DRM_EDID_INPUT_DIGITAL)
			has_audio = drm_detect_monitor_audio(edid);
		kfree(edid);
	}

	return has_audio;
}

913 914
static int
intel_hdmi_set_property(struct drm_connector *connector,
915 916
			struct drm_property *property,
			uint64_t val)
917 918
{
	struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
919 920
	struct intel_digital_port *intel_dig_port =
		hdmi_to_dig_port(intel_hdmi);
921
	struct drm_i915_private *dev_priv = connector->dev->dev_private;
922 923
	int ret;

924
	ret = drm_object_property_set_value(&connector->base, property, val);
925 926 927
	if (ret)
		return ret;

928
	if (property == dev_priv->force_audio_property) {
929
		enum hdmi_force_audio i = val;
930 931 932
		bool has_audio;

		if (i == intel_hdmi->force_audio)
933 934
			return 0;

935
		intel_hdmi->force_audio = i;
936

937
		if (i == HDMI_AUDIO_AUTO)
938 939
			has_audio = intel_hdmi_detect_audio(connector);
		else
940
			has_audio = (i == HDMI_AUDIO_ON);
941

942 943
		if (i == HDMI_AUDIO_OFF_DVI)
			intel_hdmi->has_hdmi_sink = 0;
944

945
		intel_hdmi->has_audio = has_audio;
946 947 948
		goto done;
	}

949
	if (property == dev_priv->broadcast_rgb_property) {
950 951 952 953 954 955 956 957 958 959
		switch (val) {
		case INTEL_BROADCAST_RGB_AUTO:
			intel_hdmi->color_range_auto = true;
			break;
		case INTEL_BROADCAST_RGB_FULL:
			intel_hdmi->color_range_auto = false;
			intel_hdmi->color_range = 0;
			break;
		case INTEL_BROADCAST_RGB_LIMITED:
			intel_hdmi->color_range_auto = false;
960
			intel_hdmi->color_range = HDMI_COLOR_RANGE_16_235;
961 962 963 964
			break;
		default:
			return -EINVAL;
		}
965 966 967
		goto done;
	}

968 969 970
	return -EINVAL;

done:
971 972
	if (intel_dig_port->base.base.crtc)
		intel_crtc_restore_mode(intel_dig_port->base.base.crtc);
973 974 975 976

	return 0;
}

977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071
static void intel_hdmi_pre_enable(struct intel_encoder *encoder)
{
	struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
	struct drm_device *dev = encoder->base.dev;
	struct drm_i915_private *dev_priv = dev->dev_private;
	struct intel_crtc *intel_crtc =
		to_intel_crtc(encoder->base.crtc);
	int port = vlv_dport_to_channel(dport);
	int pipe = intel_crtc->pipe;
	u32 val;

	if (!IS_VALLEYVIEW(dev))
		return;

	WARN_ON(!mutex_is_locked(&dev_priv->dpio_lock));

	/* Enable clock channels for this port */
	val = intel_dpio_read(dev_priv, DPIO_DATA_LANE_A(port));
	val = 0;
	if (pipe)
		val |= (1<<21);
	else
		val &= ~(1<<21);
	val |= 0x001000c4;
	intel_dpio_write(dev_priv, DPIO_DATA_CHANNEL(port), val);

	/* HDMI 1.0V-2dB */
	intel_dpio_write(dev_priv, DPIO_TX_OCALINIT(port), 0);
	intel_dpio_write(dev_priv, DPIO_TX_SWING_CTL4(port),
			 0x2b245f5f);
	intel_dpio_write(dev_priv, DPIO_TX_SWING_CTL2(port),
			 0x5578b83a);
	intel_dpio_write(dev_priv, DPIO_TX_SWING_CTL3(port),
			 0x0c782040);
	intel_dpio_write(dev_priv, DPIO_TX3_SWING_CTL4(port),
			 0x2b247878);
	intel_dpio_write(dev_priv, DPIO_PCS_STAGGER0(port), 0x00030000);
	intel_dpio_write(dev_priv, DPIO_PCS_CTL_OVER1(port),
			 0x00002000);
	intel_dpio_write(dev_priv, DPIO_TX_OCALINIT(port),
			 DPIO_TX_OCALINIT_EN);

	/* Program lane clock */
	intel_dpio_write(dev_priv, DPIO_PCS_CLOCKBUF0(port),
			 0x00760018);
	intel_dpio_write(dev_priv, DPIO_PCS_CLOCKBUF8(port),
			 0x00400888);
}

static void intel_hdmi_pre_pll_enable(struct intel_encoder *encoder)
{
	struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
	struct drm_device *dev = encoder->base.dev;
	struct drm_i915_private *dev_priv = dev->dev_private;
	int port = vlv_dport_to_channel(dport);

	if (!IS_VALLEYVIEW(dev))
		return;

	WARN_ON(!mutex_is_locked(&dev_priv->dpio_lock));

	/* Program Tx lane resets to default */
	intel_dpio_write(dev_priv, DPIO_PCS_TX(port),
			 DPIO_PCS_TX_LANE2_RESET |
			 DPIO_PCS_TX_LANE1_RESET);
	intel_dpio_write(dev_priv, DPIO_PCS_CLK(port),
			 DPIO_PCS_CLK_CRI_RXEB_EIOS_EN |
			 DPIO_PCS_CLK_CRI_RXDIGFILTSG_EN |
			 (1<<DPIO_PCS_CLK_DATAWIDTH_SHIFT) |
			 DPIO_PCS_CLK_SOFT_RESET);

	/* Fix up inter-pair skew failure */
	intel_dpio_write(dev_priv, DPIO_PCS_STAGGER1(port), 0x00750f00);
	intel_dpio_write(dev_priv, DPIO_TX_CTL(port), 0x00001500);
	intel_dpio_write(dev_priv, DPIO_TX_LANE(port), 0x40400000);

	intel_dpio_write(dev_priv, DPIO_PCS_CTL_OVER1(port),
			 0x00002000);
	intel_dpio_write(dev_priv, DPIO_TX_OCALINIT(port),
			 DPIO_TX_OCALINIT_EN);
}

static void intel_hdmi_post_disable(struct intel_encoder *encoder)
{
	struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
	struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
	int port = vlv_dport_to_channel(dport);

	/* Reset lanes to avoid HDMI flicker (VLV w/a) */
	mutex_lock(&dev_priv->dpio_lock);
	intel_dpio_write(dev_priv, DPIO_PCS_TX(port), 0x00000000);
	intel_dpio_write(dev_priv, DPIO_PCS_CLK(port), 0x00e00060);
	mutex_unlock(&dev_priv->dpio_lock);
}

1072 1073 1074 1075
static void intel_hdmi_destroy(struct drm_connector *connector)
{
	drm_sysfs_connector_remove(connector);
	drm_connector_cleanup(connector);
1076
	kfree(connector);
1077 1078 1079 1080 1081 1082 1083
}

static const struct drm_encoder_helper_funcs intel_hdmi_helper_funcs = {
	.mode_set = intel_hdmi_mode_set,
};

static const struct drm_connector_funcs intel_hdmi_connector_funcs = {
1084
	.dpms = intel_connector_dpms,
1085 1086
	.detect = intel_hdmi_detect,
	.fill_modes = drm_helper_probe_single_connector_modes,
1087
	.set_property = intel_hdmi_set_property,
1088 1089 1090 1091 1092 1093
	.destroy = intel_hdmi_destroy,
};

static const struct drm_connector_helper_funcs intel_hdmi_connector_helper_funcs = {
	.get_modes = intel_hdmi_get_modes,
	.mode_valid = intel_hdmi_mode_valid,
1094
	.best_encoder = intel_best_encoder,
1095 1096 1097
};

static const struct drm_encoder_funcs intel_hdmi_enc_funcs = {
C
Chris Wilson 已提交
1098
	.destroy = intel_encoder_destroy,
1099 1100
};

1101 1102 1103
static void
intel_hdmi_add_properties(struct intel_hdmi *intel_hdmi, struct drm_connector *connector)
{
1104
	intel_attach_force_audio_property(connector);
1105
	intel_attach_broadcast_rgb_property(connector);
1106
	intel_hdmi->color_range_auto = true;
1107 1108
}

P
Paulo Zanoni 已提交
1109 1110
void intel_hdmi_init_connector(struct intel_digital_port *intel_dig_port,
			       struct intel_connector *intel_connector)
1111
{
1112 1113 1114 1115
	struct drm_connector *connector = &intel_connector->base;
	struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
	struct intel_encoder *intel_encoder = &intel_dig_port->base;
	struct drm_device *dev = intel_encoder->base.dev;
1116
	struct drm_i915_private *dev_priv = dev->dev_private;
1117
	enum port port = intel_dig_port->port;
1118

1119
	drm_connector_init(dev, connector, &intel_hdmi_connector_funcs,
1120
			   DRM_MODE_CONNECTOR_HDMIA);
1121 1122
	drm_connector_helper_add(connector, &intel_hdmi_connector_helper_funcs);

1123
	connector->interlace_allowed = 1;
1124
	connector->doublescan_allowed = 0;
1125

1126 1127
	switch (port) {
	case PORT_B:
1128
		intel_hdmi->ddc_bus = GMBUS_PORT_DPB;
1129
		intel_encoder->hpd_pin = HPD_PORT_B;
1130 1131
		break;
	case PORT_C:
1132
		intel_hdmi->ddc_bus = GMBUS_PORT_DPC;
1133
		intel_encoder->hpd_pin = HPD_PORT_C;
1134 1135
		break;
	case PORT_D:
1136
		intel_hdmi->ddc_bus = GMBUS_PORT_DPD;
1137
		intel_encoder->hpd_pin = HPD_PORT_D;
1138 1139
		break;
	case PORT_A:
1140
		intel_encoder->hpd_pin = HPD_PORT_A;
1141 1142
		/* Internal port only for eDP. */
	default:
1143
		BUG();
1144
	}
1145

1146
	if (IS_VALLEYVIEW(dev)) {
1147
		intel_hdmi->write_infoframe = vlv_write_infoframe;
1148
		intel_hdmi->set_infoframes = vlv_set_infoframes;
1149 1150 1151
	} else if (!HAS_PCH_SPLIT(dev)) {
		intel_hdmi->write_infoframe = g4x_write_infoframe;
		intel_hdmi->set_infoframes = g4x_set_infoframes;
1152
	} else if (HAS_DDI(dev)) {
1153
		intel_hdmi->write_infoframe = hsw_write_infoframe;
1154
		intel_hdmi->set_infoframes = hsw_set_infoframes;
1155 1156
	} else if (HAS_PCH_IBX(dev)) {
		intel_hdmi->write_infoframe = ibx_write_infoframe;
1157
		intel_hdmi->set_infoframes = ibx_set_infoframes;
1158 1159
	} else {
		intel_hdmi->write_infoframe = cpt_write_infoframe;
1160
		intel_hdmi->set_infoframes = cpt_set_infoframes;
1161
	}
1162

P
Paulo Zanoni 已提交
1163
	if (HAS_DDI(dev))
1164 1165 1166
		intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
	else
		intel_connector->get_hw_state = intel_connector_get_hw_state;
1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182

	intel_hdmi_add_properties(intel_hdmi, connector);

	intel_connector_attach_encoder(intel_connector, intel_encoder);
	drm_sysfs_connector_add(connector);

	/* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
	 * 0xd.  Failure to do so will result in spurious interrupts being
	 * generated on the port when a cable is not attached.
	 */
	if (IS_G4X(dev) && !IS_GM45(dev)) {
		u32 temp = I915_READ(PEG_BAND_GAP_DATA);
		I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
	}
}

1183
void intel_hdmi_init(struct drm_device *dev, int hdmi_reg, enum port port)
1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204
{
	struct intel_digital_port *intel_dig_port;
	struct intel_encoder *intel_encoder;
	struct drm_encoder *encoder;
	struct intel_connector *intel_connector;

	intel_dig_port = kzalloc(sizeof(struct intel_digital_port), GFP_KERNEL);
	if (!intel_dig_port)
		return;

	intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL);
	if (!intel_connector) {
		kfree(intel_dig_port);
		return;
	}

	intel_encoder = &intel_dig_port->base;
	encoder = &intel_encoder->base;

	drm_encoder_init(dev, &intel_encoder->base, &intel_hdmi_enc_funcs,
			 DRM_MODE_ENCODER_TMDS);
P
Paulo Zanoni 已提交
1205 1206
	drm_encoder_helper_add(&intel_encoder->base, &intel_hdmi_helper_funcs);

1207
	intel_encoder->compute_config = intel_hdmi_compute_config;
P
Paulo Zanoni 已提交
1208 1209 1210
	intel_encoder->enable = intel_enable_hdmi;
	intel_encoder->disable = intel_disable_hdmi;
	intel_encoder->get_hw_state = intel_hdmi_get_hw_state;
1211 1212 1213 1214 1215
	if (IS_VALLEYVIEW(dev)) {
		intel_encoder->pre_enable = intel_hdmi_pre_enable;
		intel_encoder->pre_pll_enable = intel_hdmi_pre_pll_enable;
		intel_encoder->post_disable = intel_hdmi_post_disable;
	}
1216

1217 1218 1219
	intel_encoder->type = INTEL_OUTPUT_HDMI;
	intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
	intel_encoder->cloneable = false;
1220

1221
	intel_dig_port->port = port;
1222
	intel_dig_port->hdmi.hdmi_reg = hdmi_reg;
1223
	intel_dig_port->dp.output_reg = 0;
1224

1225
	intel_hdmi_init_connector(intel_dig_port, intel_connector);
1226
}