intel_hdmi.c 20.1 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
32
33
34
#include <linux/delay.h>
#include "drmP.h"
#include "drm.h"
#include "drm_crtc.h"
35
#include "drm_edid.h"
36
37
38
39
#include "intel_drv.h"
#include "i915_drm.h"
#include "i915_drv.h"

40
41
struct intel_hdmi {
	struct intel_encoder base;
42
	u32 sdvox_reg;
43
	int ddc_bus;
44
	int ddi_port;
45
	uint32_t color_range;
46
	bool has_hdmi_sink;
47
	bool has_audio;
48
	enum hdmi_force_audio force_audio;
49
50
	void (*write_infoframe)(struct drm_encoder *encoder,
				struct dip_infoframe *frame);
51
52
};

53
54
static struct intel_hdmi *enc_to_intel_hdmi(struct drm_encoder *encoder)
{
55
	return container_of(encoder, struct intel_hdmi, base.base);
56
57
}

58
59
60
61
62
63
static struct intel_hdmi *intel_attached_hdmi(struct drm_connector *connector)
{
	return container_of(intel_attached_encoder(connector),
			    struct intel_hdmi, base);
}

64
void intel_dip_infoframe_csum(struct dip_infoframe *frame)
65
{
66
	uint8_t *data = (uint8_t *)frame;
67
68
69
	uint8_t sum = 0;
	unsigned i;

70
71
	frame->checksum = 0;
	frame->ecc = 0;
72

73
	for (i = 0; i < frame->len + DIP_HEADER_SIZE; i++)
74
75
		sum += data[i];

76
	frame->checksum = 0x100 - sum;
77
78
}

79
static u32 g4x_infoframe_index(struct dip_infoframe *frame)
80
{
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
	u32 flags = 0;

	switch (frame->type) {
	case DIP_TYPE_AVI:
		flags |= VIDEO_DIP_SELECT_AVI;
		break;
	case DIP_TYPE_SPD:
		flags |= VIDEO_DIP_SELECT_SPD;
		break;
	default:
		DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type);
		break;
	}

	return flags;
}

98
static u32 g4x_infoframe_enable(struct dip_infoframe *frame)
99
100
101
102
103
{
	u32 flags = 0;

	switch (frame->type) {
	case DIP_TYPE_AVI:
104
		flags |= VIDEO_DIP_ENABLE_AVI;
105
106
		break;
	case DIP_TYPE_SPD:
107
108
109
110
111
112
113
114
115
116
		flags |= VIDEO_DIP_ENABLE_SPD;
		break;
	default:
		DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type);
		break;
	}

	return flags;
}

117
118
static void g4x_write_infoframe(struct drm_encoder *encoder,
				struct dip_infoframe *frame)
119
120
{
	uint32_t *data = (uint32_t *)frame;
121
122
123
	struct drm_device *dev = encoder->dev;
	struct drm_i915_private *dev_priv = dev->dev_private;
	struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
124
	u32 val = I915_READ(VIDEO_DIP_CTL);
125
	unsigned i, len = DIP_HEADER_SIZE + frame->len;
126
127
128


	/* XXX first guess at handling video port, is this corrent? */
129
	val &= ~VIDEO_DIP_PORT_MASK;
130
	if (intel_hdmi->sdvox_reg == SDVOB)
131
		val |= VIDEO_DIP_PORT_B;
132
	else if (intel_hdmi->sdvox_reg == SDVOC)
133
		val |= VIDEO_DIP_PORT_C;
134
135
136
	else
		return;

137
	val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
138
	val |= g4x_infoframe_index(frame);
139

140
	val &= ~g4x_infoframe_enable(frame);
141
	val |= VIDEO_DIP_ENABLE;
142

143
	I915_WRITE(VIDEO_DIP_CTL, val);
144

145
	for (i = 0; i < len; i += 4) {
146
147
148
149
		I915_WRITE(VIDEO_DIP_DATA, *data);
		data++;
	}

150
	val |= g4x_infoframe_enable(frame);
151
	val &= ~VIDEO_DIP_FREQ_MASK;
152
	val |= VIDEO_DIP_FREQ_VSYNC;
153

154
	I915_WRITE(VIDEO_DIP_CTL, val);
155
156
}

157
158
159
160
161
162
163
164
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;
	struct drm_crtc *crtc = encoder->crtc;
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
165
	struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
166
167
168
169
	int reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
	unsigned i, len = DIP_HEADER_SIZE + frame->len;
	u32 val = I915_READ(reg);

170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
	val &= ~VIDEO_DIP_PORT_MASK;
	switch (intel_hdmi->sdvox_reg) {
	case HDMIB:
		val |= VIDEO_DIP_PORT_B;
		break;
	case HDMIC:
		val |= VIDEO_DIP_PORT_C;
		break;
	case HDMID:
		val |= VIDEO_DIP_PORT_D;
		break;
	default:
		return;
	}

185
186
187
	intel_wait_for_vblank(dev, intel_crtc->pipe);

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

190
	val &= ~g4x_infoframe_enable(frame);
191
192
193
194
195
196
197
198
199
	val |= VIDEO_DIP_ENABLE;

	I915_WRITE(reg, val);

	for (i = 0; i < len; i += 4) {
		I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
		data++;
	}

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

	I915_WRITE(reg, val);
}

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

	intel_wait_for_vblank(dev, intel_crtc->pipe);

221
	val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
222
	val |= g4x_infoframe_index(frame);
223

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

231
232
233
	val |= VIDEO_DIP_ENABLE;

	I915_WRITE(reg, val);
234
235

	for (i = 0; i < len; i += 4) {
236
237
238
239
		I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
		data++;
	}

240
	val |= g4x_infoframe_enable(frame);
241
	val &= ~VIDEO_DIP_FREQ_MASK;
242
	val |= VIDEO_DIP_FREQ_VSYNC;
243

244
	I915_WRITE(reg, val);
245
}
246
247
248
249
250
251
252
253
254
255
256

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;
	struct drm_crtc *crtc = encoder->crtc;
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
	int reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
	unsigned i, len = DIP_HEADER_SIZE + frame->len;
257
	u32 val = I915_READ(reg);
258
259
260
261

	intel_wait_for_vblank(dev, intel_crtc->pipe);

	val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
262
	val |= g4x_infoframe_index(frame);
263

264
	val &= ~g4x_infoframe_enable(frame);
265
	val |= VIDEO_DIP_ENABLE;
266

267
	I915_WRITE(reg, val);
268
269
270
271
272
273

	for (i = 0; i < len; i += 4) {
		I915_WRITE(VLV_TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
		data++;
	}

274
	val |= g4x_infoframe_enable(frame);
275
	val &= ~VIDEO_DIP_FREQ_MASK;
276
	val |= VIDEO_DIP_FREQ_VSYNC;
277

278
	I915_WRITE(reg, val);
279
280
}

281
282
283
284
285
286
287
288
289
290
291
292
static void hsw_write_infoframe(struct drm_encoder *encoder,
				     struct dip_infoframe *frame)
{
	/* Not implemented yet, so avoid doing anything at all.
	 * This is the placeholder for Paulo Zanoni's infoframe writing patch
	 */
	DRM_DEBUG_DRIVER("Attempting to write infoframe on Haswell, this is not implemented yet.\n");

	return;

}

293
294
295
296
297
298
299
300
301
302
303
304
static void intel_set_infoframe(struct drm_encoder *encoder,
				struct dip_infoframe *frame)
{
	struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);

	if (!intel_hdmi->has_hdmi_sink)
		return;

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

305
306
static void intel_hdmi_set_avi_infoframe(struct drm_encoder *encoder,
					 struct drm_display_mode *adjusted_mode)
307
308
309
310
311
312
313
{
	struct dip_infoframe avi_if = {
		.type = DIP_TYPE_AVI,
		.ver = DIP_VERSION_AVI,
		.len = DIP_LEN_AVI,
	};

314
315
316
	if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
		avi_if.body.avi.YQ_CN_PR |= DIP_AVI_PR_2;

317
	intel_set_infoframe(encoder, &avi_if);
318
319
}

320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
static void intel_hdmi_set_spd_infoframe(struct drm_encoder *encoder)
{
	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);
}

335
336
337
338
339
340
341
342
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;
	struct drm_crtc *crtc = encoder->crtc;
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
343
	struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
344
345
	u32 sdvox;

346
	sdvox = SDVO_ENCODING_HDMI | SDVO_BORDER_ENABLE;
347
348
	if (!HAS_PCH_SPLIT(dev))
		sdvox |= intel_hdmi->color_range;
349
350
351
352
	if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
		sdvox |= SDVO_VSYNC_ACTIVE_HIGH;
	if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
		sdvox |= SDVO_HSYNC_ACTIVE_HIGH;
353

354
355
356
357
358
	if (intel_crtc->bpp > 24)
		sdvox |= COLOR_FORMAT_12bpc;
	else
		sdvox |= COLOR_FORMAT_8bpc;

359
360
361
362
	/* Required on CPT */
	if (intel_hdmi->has_hdmi_sink && HAS_PCH_CPT(dev))
		sdvox |= HDMI_MODE_SELECT;

363
	if (intel_hdmi->has_audio) {
364
365
		DRM_DEBUG_DRIVER("Enabling HDMI audio on pipe %c\n",
				 pipe_name(intel_crtc->pipe));
366
		sdvox |= SDVO_AUDIO_ENABLE;
367
		sdvox |= SDVO_NULL_PACKETS_DURING_VSYNC;
368
		intel_write_eld(encoder, adjusted_mode);
369
	}
370

371
372
373
374
	if (HAS_PCH_CPT(dev))
		sdvox |= PORT_TRANS_SEL_CPT(intel_crtc->pipe);
	else if (intel_crtc->pipe == 1)
		sdvox |= SDVO_PIPE_B_SELECT;
375

376
377
	I915_WRITE(intel_hdmi->sdvox_reg, sdvox);
	POSTING_READ(intel_hdmi->sdvox_reg);
378

379
	intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
380
	intel_hdmi_set_spd_infoframe(encoder);
381
382
383
384
385
386
}

static void intel_hdmi_dpms(struct drm_encoder *encoder, int mode)
{
	struct drm_device *dev = encoder->dev;
	struct drm_i915_private *dev_priv = dev->dev_private;
387
	struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
388
	u32 temp;
389
390
391
392
	u32 enable_bits = SDVO_ENABLE;

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

394
	temp = I915_READ(intel_hdmi->sdvox_reg);
395
396
397
398

	/* HW workaround, need to toggle enable bit off and on for 12bpc, but
	 * we do this anyway which shows more stable in testing.
	 */
399
	if (HAS_PCH_SPLIT(dev)) {
400
401
		I915_WRITE(intel_hdmi->sdvox_reg, temp & ~SDVO_ENABLE);
		POSTING_READ(intel_hdmi->sdvox_reg);
402
403
404
	}

	if (mode != DRM_MODE_DPMS_ON) {
405
		temp &= ~enable_bits;
406
	} else {
407
		temp |= enable_bits;
408
	}
409

410
411
	I915_WRITE(intel_hdmi->sdvox_reg, temp);
	POSTING_READ(intel_hdmi->sdvox_reg);
412
413
414
415

	/* HW workaround, need to write this twice for issue that may result
	 * in first write getting masked.
	 */
416
	if (HAS_PCH_SPLIT(dev)) {
417
418
		I915_WRITE(intel_hdmi->sdvox_reg, temp);
		POSTING_READ(intel_hdmi->sdvox_reg);
419
	}
420
421
422
423
424
425
426
427
}

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)
428
		return MODE_CLOCK_LOW;
429
430
431
432
433
434
435
436
437
438
439
440
441
442

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

	return MODE_OK;
}

static bool intel_hdmi_mode_fixup(struct drm_encoder *encoder,
				  struct drm_display_mode *mode,
				  struct drm_display_mode *adjusted_mode)
{
	return true;
}

443
static enum drm_connector_status
444
intel_hdmi_detect(struct drm_connector *connector, bool force)
445
{
446
	struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
447
448
	struct drm_i915_private *dev_priv = connector->dev->dev_private;
	struct edid *edid;
449
	enum drm_connector_status status = connector_status_disconnected;
450

451
	intel_hdmi->has_hdmi_sink = false;
452
	intel_hdmi->has_audio = false;
453
	edid = drm_get_edid(connector,
454
455
			    intel_gmbus_get_adapter(dev_priv,
						    intel_hdmi->ddc_bus));
456

457
	if (edid) {
458
		if (edid->input & DRM_EDID_INPUT_DIGITAL) {
459
			status = connector_status_connected;
460
461
462
			if (intel_hdmi->force_audio != HDMI_AUDIO_OFF_DVI)
				intel_hdmi->has_hdmi_sink =
						drm_detect_hdmi_monitor(edid);
463
			intel_hdmi->has_audio = drm_detect_monitor_audio(edid);
464
		}
465
		connector->display_info.raw_edid = NULL;
466
		kfree(edid);
467
	}
468

469
	if (status == connector_status_connected) {
470
471
472
		if (intel_hdmi->force_audio != HDMI_AUDIO_AUTO)
			intel_hdmi->has_audio =
				(intel_hdmi->force_audio == HDMI_AUDIO_ON);
473
474
	}

475
	return status;
476
477
478
479
}

static int intel_hdmi_get_modes(struct drm_connector *connector)
{
480
	struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
481
	struct drm_i915_private *dev_priv = connector->dev->dev_private;
482
483
484
485
486

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

487
	return intel_ddc_get_modes(connector,
488
489
				   intel_gmbus_get_adapter(dev_priv,
							   intel_hdmi->ddc_bus));
490
491
}

492
493
494
495
496
497
498
499
500
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,
501
502
			    intel_gmbus_get_adapter(dev_priv,
						    intel_hdmi->ddc_bus));
503
504
505
506
507
508
509
510
511
512
513
	if (edid) {
		if (edid->input & DRM_EDID_INPUT_DIGITAL)
			has_audio = drm_detect_monitor_audio(edid);

		connector->display_info.raw_edid = NULL;
		kfree(edid);
	}

	return has_audio;
}

514
515
516
517
518
519
static int
intel_hdmi_set_property(struct drm_connector *connector,
		      struct drm_property *property,
		      uint64_t val)
{
	struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
520
	struct drm_i915_private *dev_priv = connector->dev->dev_private;
521
522
523
524
525
526
	int ret;

	ret = drm_connector_property_set_value(connector, property, val);
	if (ret)
		return ret;

527
	if (property == dev_priv->force_audio_property) {
528
		enum hdmi_force_audio i = val;
529
530
531
		bool has_audio;

		if (i == intel_hdmi->force_audio)
532
533
			return 0;

534
		intel_hdmi->force_audio = i;
535

536
		if (i == HDMI_AUDIO_AUTO)
537
538
			has_audio = intel_hdmi_detect_audio(connector);
		else
539
			has_audio = (i == HDMI_AUDIO_ON);
540

541
542
		if (i == HDMI_AUDIO_OFF_DVI)
			intel_hdmi->has_hdmi_sink = 0;
543

544
		intel_hdmi->has_audio = has_audio;
545
546
547
		goto done;
	}

548
549
550
551
552
553
554
555
	if (property == dev_priv->broadcast_rgb_property) {
		if (val == !!intel_hdmi->color_range)
			return 0;

		intel_hdmi->color_range = val ? SDVO_COLOR_RANGE_16_235 : 0;
		goto done;
	}

556
557
558
559
560
561
562
563
564
565
566
567
568
	return -EINVAL;

done:
	if (intel_hdmi->base.base.crtc) {
		struct drm_crtc *crtc = intel_hdmi->base.base.crtc;
		drm_crtc_helper_set_mode(crtc, &crtc->mode,
					 crtc->x, crtc->y,
					 crtc->fb);
	}

	return 0;
}

569
570
571
572
static void intel_hdmi_destroy(struct drm_connector *connector)
{
	drm_sysfs_connector_remove(connector);
	drm_connector_cleanup(connector);
573
	kfree(connector);
574
575
576
577
578
579
580
581
582
583
584
}

static const struct drm_encoder_helper_funcs intel_hdmi_helper_funcs = {
	.dpms = intel_hdmi_dpms,
	.mode_fixup = intel_hdmi_mode_fixup,
	.prepare = intel_encoder_prepare,
	.mode_set = intel_hdmi_mode_set,
	.commit = intel_encoder_commit,
};

static const struct drm_connector_funcs intel_hdmi_connector_funcs = {
585
	.dpms = drm_helper_connector_dpms,
586
587
	.detect = intel_hdmi_detect,
	.fill_modes = drm_helper_probe_single_connector_modes,
588
	.set_property = intel_hdmi_set_property,
589
590
591
592
593
594
	.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,
595
	.best_encoder = intel_best_encoder,
596
597
598
};

static const struct drm_encoder_funcs intel_hdmi_enc_funcs = {
599
	.destroy = intel_encoder_destroy,
600
601
};

602
603
604
static void
intel_hdmi_add_properties(struct intel_hdmi *intel_hdmi, struct drm_connector *connector)
{
605
	intel_attach_force_audio_property(connector);
606
	intel_attach_broadcast_rgb_property(connector);
607
608
}

609
610
611
612
void intel_hdmi_init(struct drm_device *dev, int sdvox_reg)
{
	struct drm_i915_private *dev_priv = dev->dev_private;
	struct drm_connector *connector;
613
	struct intel_encoder *intel_encoder;
614
	struct intel_connector *intel_connector;
615
	struct intel_hdmi *intel_hdmi;
616
	int i;
617

618
619
	intel_hdmi = kzalloc(sizeof(struct intel_hdmi), GFP_KERNEL);
	if (!intel_hdmi)
620
		return;
621
622
623

	intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL);
	if (!intel_connector) {
624
		kfree(intel_hdmi);
625
626
627
		return;
	}

628
	intel_encoder = &intel_hdmi->base;
629
630
631
	drm_encoder_init(dev, &intel_encoder->base, &intel_hdmi_enc_funcs,
			 DRM_MODE_ENCODER_TMDS);

632
	connector = &intel_connector->base;
633
	drm_connector_init(dev, connector, &intel_hdmi_connector_funcs,
634
			   DRM_MODE_CONNECTOR_HDMIA);
635
636
	drm_connector_helper_add(connector, &intel_hdmi_connector_helper_funcs);

637
	intel_encoder->type = INTEL_OUTPUT_HDMI;
638

639
	connector->polled = DRM_CONNECTOR_POLL_HPD;
640
	connector->interlace_allowed = 1;
641
	connector->doublescan_allowed = 0;
642
	intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
643
644

	/* Set up the DDC bus. */
645
	if (sdvox_reg == SDVOB) {
646
		intel_encoder->clone_mask = (1 << INTEL_HDMIB_CLONE_BIT);
647
		intel_hdmi->ddc_bus = GMBUS_PORT_DPB;
648
		dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS;
649
	} else if (sdvox_reg == SDVOC) {
650
		intel_encoder->clone_mask = (1 << INTEL_HDMIC_CLONE_BIT);
651
		intel_hdmi->ddc_bus = GMBUS_PORT_DPC;
652
		dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS;
653
	} else if (sdvox_reg == HDMIB) {
654
		intel_encoder->clone_mask = (1 << INTEL_HDMID_CLONE_BIT);
655
		intel_hdmi->ddc_bus = GMBUS_PORT_DPB;
656
		dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS;
657
	} else if (sdvox_reg == HDMIC) {
658
		intel_encoder->clone_mask = (1 << INTEL_HDMIE_CLONE_BIT);
659
		intel_hdmi->ddc_bus = GMBUS_PORT_DPC;
660
		dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS;
661
	} else if (sdvox_reg == HDMID) {
662
		intel_encoder->clone_mask = (1 << INTEL_HDMIF_CLONE_BIT);
663
		intel_hdmi->ddc_bus = GMBUS_PORT_DPD;
664
		dev_priv->hotplug_supported_mask |= HDMID_HOTPLUG_INT_STATUS;
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
	} else if (sdvox_reg == DDI_BUF_CTL(PORT_B)) {
		DRM_DEBUG_DRIVER("LPT: detected output on DDI B\n");
		intel_encoder->clone_mask = (1 << INTEL_HDMIB_CLONE_BIT);
		intel_hdmi->ddc_bus = GMBUS_PORT_DPB;
		intel_hdmi->ddi_port = PORT_B;
		dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS;
	} else if (sdvox_reg == DDI_BUF_CTL(PORT_C)) {
		DRM_DEBUG_DRIVER("LPT: detected output on DDI C\n");
		intel_encoder->clone_mask = (1 << INTEL_HDMIC_CLONE_BIT);
		intel_hdmi->ddc_bus = GMBUS_PORT_DPC;
		intel_hdmi->ddi_port = PORT_C;
		dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS;
	} else if (sdvox_reg == DDI_BUF_CTL(PORT_D)) {
		DRM_DEBUG_DRIVER("LPT: detected output on DDI D\n");
		intel_encoder->clone_mask = (1 << INTEL_HDMID_CLONE_BIT);
		intel_hdmi->ddc_bus = GMBUS_PORT_DPD;
		intel_hdmi->ddi_port = PORT_D;
		dev_priv->hotplug_supported_mask |= HDMID_HOTPLUG_INT_STATUS;
683
684
685
686
	} else {
		/* If we got an unknown sdvox_reg, things are pretty much broken
		 * in a way that we should let the kernel know about it */
		BUG();
687
	}
688

689
	intel_hdmi->sdvox_reg = sdvox_reg;
690

691
	if (!HAS_PCH_SPLIT(dev)) {
692
		intel_hdmi->write_infoframe = g4x_write_infoframe;
693
		I915_WRITE(VIDEO_DIP_CTL, 0);
694
695
696
697
	} else if (IS_VALLEYVIEW(dev)) {
		intel_hdmi->write_infoframe = vlv_write_infoframe;
		for_each_pipe(i)
			I915_WRITE(VLV_TVIDEO_DIP_CTL(i), 0);
698
699
700
701
702
703
704
	} else if (IS_HASWELL(dev)) {
		/* FIXME: Haswell has a new set of DIP frame registers, but we are
		 * just doing the minimal required for HDMI to work at this stage.
		 */
		intel_hdmi->write_infoframe = hsw_write_infoframe;
		for_each_pipe(i)
			I915_WRITE(HSW_TVIDEO_DIP_CTL(i), 0);
705
706
707
708
709
710
	} else if (HAS_PCH_IBX(dev)) {
		intel_hdmi->write_infoframe = ibx_write_infoframe;
		for_each_pipe(i)
			I915_WRITE(TVIDEO_DIP_CTL(i), 0);
	} else {
		intel_hdmi->write_infoframe = cpt_write_infoframe;
711
712
713
		for_each_pipe(i)
			I915_WRITE(TVIDEO_DIP_CTL(i), 0);
	}
714

715
	drm_encoder_helper_add(&intel_encoder->base, &intel_hdmi_helper_funcs);
716

717
718
	intel_hdmi_add_properties(intel_hdmi, connector);

719
	intel_connector_attach_encoder(intel_connector, intel_encoder);
720
721
722
723
724
725
726
727
728
729
730
	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);
	}
}