drm/i915: rename AVI InfoFrame field 'PR' to 'YQ_CN_PR'
[linux-2.6-block.git] / drivers / gpu / drm / i915 / intel_hdmi.c
CommitLineData
7d57382e
EA
1/*
2 * Copyright 2006 Dave Airlie <airlied@linux.ie>
3 * Copyright © 2006-2009 Intel Corporation
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 * Authors:
25 * Eric Anholt <eric@anholt.net>
26 * Jesse Barnes <jesse.barnes@intel.com>
27 */
28
29#include <linux/i2c.h>
5a0e3ad6 30#include <linux/slab.h>
7d57382e
EA
31#include <linux/delay.h>
32#include "drmP.h"
33#include "drm.h"
34#include "drm_crtc.h"
aa93d632 35#include "drm_edid.h"
7d57382e
EA
36#include "intel_drv.h"
37#include "i915_drm.h"
38#include "i915_drv.h"
39
ea5b213a
CW
40struct intel_hdmi {
41 struct intel_encoder base;
7d57382e 42 u32 sdvox_reg;
f899fc64 43 int ddc_bus;
e953fd7b 44 uint32_t color_range;
9dff6af8 45 bool has_hdmi_sink;
2e3d6006 46 bool has_audio;
b1d7e4b4 47 enum hdmi_force_audio force_audio;
45187ace
JB
48 void (*write_infoframe)(struct drm_encoder *encoder,
49 struct dip_infoframe *frame);
7d57382e
EA
50};
51
ea5b213a
CW
52static struct intel_hdmi *enc_to_intel_hdmi(struct drm_encoder *encoder)
53{
4ef69c7a 54 return container_of(encoder, struct intel_hdmi, base.base);
ea5b213a
CW
55}
56
df0e9248
CW
57static struct intel_hdmi *intel_attached_hdmi(struct drm_connector *connector)
58{
59 return container_of(intel_attached_encoder(connector),
60 struct intel_hdmi, base);
61}
62
45187ace 63void intel_dip_infoframe_csum(struct dip_infoframe *frame)
3c17fe4b 64{
45187ace 65 uint8_t *data = (uint8_t *)frame;
3c17fe4b
DH
66 uint8_t sum = 0;
67 unsigned i;
68
45187ace
JB
69 frame->checksum = 0;
70 frame->ecc = 0;
3c17fe4b 71
64a8fc01 72 for (i = 0; i < frame->len + DIP_HEADER_SIZE; i++)
3c17fe4b
DH
73 sum += data[i];
74
45187ace 75 frame->checksum = 0x100 - sum;
3c17fe4b
DH
76}
77
45187ace 78static u32 intel_infoframe_index(struct dip_infoframe *frame)
3c17fe4b 79{
45187ace
JB
80 u32 flags = 0;
81
82 switch (frame->type) {
83 case DIP_TYPE_AVI:
84 flags |= VIDEO_DIP_SELECT_AVI;
85 break;
86 case DIP_TYPE_SPD:
87 flags |= VIDEO_DIP_SELECT_SPD;
88 break;
89 default:
90 DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type);
91 break;
92 }
93
94 return flags;
95}
96
97static u32 intel_infoframe_flags(struct dip_infoframe *frame)
98{
99 u32 flags = 0;
100
101 switch (frame->type) {
102 case DIP_TYPE_AVI:
103 flags |= VIDEO_DIP_ENABLE_AVI | VIDEO_DIP_FREQ_VSYNC;
104 break;
105 case DIP_TYPE_SPD:
64a8fc01 106 flags |= VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_FREQ_VSYNC;
45187ace
JB
107 break;
108 default:
109 DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type);
110 break;
111 }
112
113 return flags;
114}
115
116static void i9xx_write_infoframe(struct drm_encoder *encoder,
117 struct dip_infoframe *frame)
118{
119 uint32_t *data = (uint32_t *)frame;
3c17fe4b
DH
120 struct drm_device *dev = encoder->dev;
121 struct drm_i915_private *dev_priv = dev->dev_private;
122 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
45187ace
JB
123 u32 port, flags, val = I915_READ(VIDEO_DIP_CTL);
124 unsigned i, len = DIP_HEADER_SIZE + frame->len;
3c17fe4b 125
3c17fe4b
DH
126
127 /* XXX first guess at handling video port, is this corrent? */
128 if (intel_hdmi->sdvox_reg == SDVOB)
129 port = VIDEO_DIP_PORT_B;
130 else if (intel_hdmi->sdvox_reg == SDVOC)
131 port = VIDEO_DIP_PORT_C;
132 else
133 return;
134
45187ace
JB
135 flags = intel_infoframe_index(frame);
136
137 val &= ~VIDEO_DIP_SELECT_MASK;
138
139 I915_WRITE(VIDEO_DIP_CTL, val | port | flags);
3c17fe4b 140
45187ace 141 for (i = 0; i < len; i += 4) {
3c17fe4b
DH
142 I915_WRITE(VIDEO_DIP_DATA, *data);
143 data++;
144 }
145
45187ace
JB
146 flags |= intel_infoframe_flags(frame);
147
148 I915_WRITE(VIDEO_DIP_CTL, VIDEO_DIP_ENABLE | val | port | flags);
3c17fe4b
DH
149}
150
45187ace
JB
151static void ironlake_write_infoframe(struct drm_encoder *encoder,
152 struct dip_infoframe *frame)
b055c8f3 153{
45187ace 154 uint32_t *data = (uint32_t *)frame;
b055c8f3
JB
155 struct drm_device *dev = encoder->dev;
156 struct drm_i915_private *dev_priv = dev->dev_private;
b055c8f3
JB
157 struct drm_crtc *crtc = encoder->crtc;
158 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
159 int reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
45187ace
JB
160 unsigned i, len = DIP_HEADER_SIZE + frame->len;
161 u32 flags, val = I915_READ(reg);
b055c8f3
JB
162
163 intel_wait_for_vblank(dev, intel_crtc->pipe);
164
45187ace 165 flags = intel_infoframe_index(frame);
b055c8f3 166
64a8fc01 167 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
45187ace 168
64a8fc01 169 I915_WRITE(reg, VIDEO_DIP_ENABLE | val | flags);
45187ace
JB
170
171 for (i = 0; i < len; i += 4) {
b055c8f3
JB
172 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
173 data++;
174 }
175
45187ace
JB
176 flags |= intel_infoframe_flags(frame);
177
178 I915_WRITE(reg, VIDEO_DIP_ENABLE | val | flags);
179}
90b107c8
SK
180
181static void vlv_write_infoframe(struct drm_encoder *encoder,
182 struct dip_infoframe *frame)
183{
184 uint32_t *data = (uint32_t *)frame;
185 struct drm_device *dev = encoder->dev;
186 struct drm_i915_private *dev_priv = dev->dev_private;
187 struct drm_crtc *crtc = encoder->crtc;
188 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
189 int reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
190 unsigned i, len = DIP_HEADER_SIZE + frame->len;
191 u32 flags, val = I915_READ(reg);
192
193 intel_wait_for_vblank(dev, intel_crtc->pipe);
194
195 flags = intel_infoframe_index(frame);
196
197 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
198
199 I915_WRITE(reg, VIDEO_DIP_ENABLE | val | flags);
200
201 for (i = 0; i < len; i += 4) {
202 I915_WRITE(VLV_TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
203 data++;
204 }
205
206 flags |= intel_infoframe_flags(frame);
207
208 I915_WRITE(reg, VIDEO_DIP_ENABLE | val | flags);
209}
210
45187ace
JB
211static void intel_set_infoframe(struct drm_encoder *encoder,
212 struct dip_infoframe *frame)
213{
214 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
215
216 if (!intel_hdmi->has_hdmi_sink)
217 return;
218
219 intel_dip_infoframe_csum(frame);
220 intel_hdmi->write_infoframe(encoder, frame);
221}
222
223static void intel_hdmi_set_avi_infoframe(struct drm_encoder *encoder)
224{
225 struct dip_infoframe avi_if = {
226 .type = DIP_TYPE_AVI,
227 .ver = DIP_VERSION_AVI,
228 .len = DIP_LEN_AVI,
229 };
230
231 intel_set_infoframe(encoder, &avi_if);
b055c8f3
JB
232}
233
c0864cb3
JB
234static void intel_hdmi_set_spd_infoframe(struct drm_encoder *encoder)
235{
236 struct dip_infoframe spd_if;
237
238 memset(&spd_if, 0, sizeof(spd_if));
239 spd_if.type = DIP_TYPE_SPD;
240 spd_if.ver = DIP_VERSION_SPD;
241 spd_if.len = DIP_LEN_SPD;
242 strcpy(spd_if.body.spd.vn, "Intel");
243 strcpy(spd_if.body.spd.pd, "Integrated gfx");
244 spd_if.body.spd.sdi = DIP_SPD_PC;
245
246 intel_set_infoframe(encoder, &spd_if);
247}
248
7d57382e
EA
249static void intel_hdmi_mode_set(struct drm_encoder *encoder,
250 struct drm_display_mode *mode,
251 struct drm_display_mode *adjusted_mode)
252{
253 struct drm_device *dev = encoder->dev;
254 struct drm_i915_private *dev_priv = dev->dev_private;
255 struct drm_crtc *crtc = encoder->crtc;
256 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
ea5b213a 257 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
7d57382e
EA
258 u32 sdvox;
259
b599c0bc 260 sdvox = SDVO_ENCODING_HDMI | SDVO_BORDER_ENABLE;
5d4fac97
JB
261 if (!HAS_PCH_SPLIT(dev))
262 sdvox |= intel_hdmi->color_range;
b599c0bc
AJ
263 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
264 sdvox |= SDVO_VSYNC_ACTIVE_HIGH;
265 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
266 sdvox |= SDVO_HSYNC_ACTIVE_HIGH;
7d57382e 267
020f6704
JB
268 if (intel_crtc->bpp > 24)
269 sdvox |= COLOR_FORMAT_12bpc;
270 else
271 sdvox |= COLOR_FORMAT_8bpc;
272
2e3d6006
ZW
273 /* Required on CPT */
274 if (intel_hdmi->has_hdmi_sink && HAS_PCH_CPT(dev))
275 sdvox |= HDMI_MODE_SELECT;
276
3c17fe4b 277 if (intel_hdmi->has_audio) {
e0dac65e
WF
278 DRM_DEBUG_DRIVER("Enabling HDMI audio on pipe %c\n",
279 pipe_name(intel_crtc->pipe));
7d57382e 280 sdvox |= SDVO_AUDIO_ENABLE;
3c17fe4b 281 sdvox |= SDVO_NULL_PACKETS_DURING_VSYNC;
e0dac65e 282 intel_write_eld(encoder, adjusted_mode);
3c17fe4b 283 }
7d57382e 284
75770564
JB
285 if (HAS_PCH_CPT(dev))
286 sdvox |= PORT_TRANS_SEL_CPT(intel_crtc->pipe);
287 else if (intel_crtc->pipe == 1)
288 sdvox |= SDVO_PIPE_B_SELECT;
7d57382e 289
ea5b213a
CW
290 I915_WRITE(intel_hdmi->sdvox_reg, sdvox);
291 POSTING_READ(intel_hdmi->sdvox_reg);
3c17fe4b 292
45187ace 293 intel_hdmi_set_avi_infoframe(encoder);
c0864cb3 294 intel_hdmi_set_spd_infoframe(encoder);
7d57382e
EA
295}
296
297static void intel_hdmi_dpms(struct drm_encoder *encoder, int mode)
298{
299 struct drm_device *dev = encoder->dev;
300 struct drm_i915_private *dev_priv = dev->dev_private;
ea5b213a 301 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
7d57382e 302 u32 temp;
2deed761
WF
303 u32 enable_bits = SDVO_ENABLE;
304
305 if (intel_hdmi->has_audio)
306 enable_bits |= SDVO_AUDIO_ENABLE;
7d57382e 307
ea5b213a 308 temp = I915_READ(intel_hdmi->sdvox_reg);
d8a2d0e0
ZW
309
310 /* HW workaround, need to toggle enable bit off and on for 12bpc, but
311 * we do this anyway which shows more stable in testing.
312 */
c619eed4 313 if (HAS_PCH_SPLIT(dev)) {
ea5b213a
CW
314 I915_WRITE(intel_hdmi->sdvox_reg, temp & ~SDVO_ENABLE);
315 POSTING_READ(intel_hdmi->sdvox_reg);
d8a2d0e0
ZW
316 }
317
318 if (mode != DRM_MODE_DPMS_ON) {
2deed761 319 temp &= ~enable_bits;
7d57382e 320 } else {
2deed761 321 temp |= enable_bits;
7d57382e 322 }
d8a2d0e0 323
ea5b213a
CW
324 I915_WRITE(intel_hdmi->sdvox_reg, temp);
325 POSTING_READ(intel_hdmi->sdvox_reg);
d8a2d0e0
ZW
326
327 /* HW workaround, need to write this twice for issue that may result
328 * in first write getting masked.
329 */
c619eed4 330 if (HAS_PCH_SPLIT(dev)) {
ea5b213a
CW
331 I915_WRITE(intel_hdmi->sdvox_reg, temp);
332 POSTING_READ(intel_hdmi->sdvox_reg);
d8a2d0e0 333 }
7d57382e
EA
334}
335
7d57382e
EA
336static int intel_hdmi_mode_valid(struct drm_connector *connector,
337 struct drm_display_mode *mode)
338{
339 if (mode->clock > 165000)
340 return MODE_CLOCK_HIGH;
341 if (mode->clock < 20000)
5cbba41d 342 return MODE_CLOCK_LOW;
7d57382e
EA
343
344 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
345 return MODE_NO_DBLESCAN;
346
347 return MODE_OK;
348}
349
350static bool intel_hdmi_mode_fixup(struct drm_encoder *encoder,
351 struct drm_display_mode *mode,
352 struct drm_display_mode *adjusted_mode)
353{
354 return true;
355}
356
aa93d632 357static enum drm_connector_status
930a9e28 358intel_hdmi_detect(struct drm_connector *connector, bool force)
9dff6af8 359{
df0e9248 360 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
f899fc64
CW
361 struct drm_i915_private *dev_priv = connector->dev->dev_private;
362 struct edid *edid;
aa93d632 363 enum drm_connector_status status = connector_status_disconnected;
9dff6af8 364
ea5b213a 365 intel_hdmi->has_hdmi_sink = false;
2e3d6006 366 intel_hdmi->has_audio = false;
f899fc64 367 edid = drm_get_edid(connector,
3bd7d909
DK
368 intel_gmbus_get_adapter(dev_priv,
369 intel_hdmi->ddc_bus));
2ded9e27 370
aa93d632 371 if (edid) {
be9f1c4f 372 if (edid->input & DRM_EDID_INPUT_DIGITAL) {
aa93d632 373 status = connector_status_connected;
b1d7e4b4
WF
374 if (intel_hdmi->force_audio != HDMI_AUDIO_OFF_DVI)
375 intel_hdmi->has_hdmi_sink =
376 drm_detect_hdmi_monitor(edid);
2e3d6006 377 intel_hdmi->has_audio = drm_detect_monitor_audio(edid);
aa93d632 378 }
674e2d08 379 connector->display_info.raw_edid = NULL;
aa93d632 380 kfree(edid);
9dff6af8 381 }
30ad48b7 382
55b7d6e8 383 if (status == connector_status_connected) {
b1d7e4b4
WF
384 if (intel_hdmi->force_audio != HDMI_AUDIO_AUTO)
385 intel_hdmi->has_audio =
386 (intel_hdmi->force_audio == HDMI_AUDIO_ON);
55b7d6e8
CW
387 }
388
2ded9e27 389 return status;
7d57382e
EA
390}
391
392static int intel_hdmi_get_modes(struct drm_connector *connector)
393{
df0e9248 394 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
f899fc64 395 struct drm_i915_private *dev_priv = connector->dev->dev_private;
7d57382e
EA
396
397 /* We should parse the EDID data and find out if it's an HDMI sink so
398 * we can send audio to it.
399 */
400
f899fc64 401 return intel_ddc_get_modes(connector,
3bd7d909
DK
402 intel_gmbus_get_adapter(dev_priv,
403 intel_hdmi->ddc_bus));
7d57382e
EA
404}
405
1aad7ac0
CW
406static bool
407intel_hdmi_detect_audio(struct drm_connector *connector)
408{
409 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
410 struct drm_i915_private *dev_priv = connector->dev->dev_private;
411 struct edid *edid;
412 bool has_audio = false;
413
414 edid = drm_get_edid(connector,
3bd7d909
DK
415 intel_gmbus_get_adapter(dev_priv,
416 intel_hdmi->ddc_bus));
1aad7ac0
CW
417 if (edid) {
418 if (edid->input & DRM_EDID_INPUT_DIGITAL)
419 has_audio = drm_detect_monitor_audio(edid);
420
421 connector->display_info.raw_edid = NULL;
422 kfree(edid);
423 }
424
425 return has_audio;
426}
427
55b7d6e8
CW
428static int
429intel_hdmi_set_property(struct drm_connector *connector,
430 struct drm_property *property,
431 uint64_t val)
432{
433 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
e953fd7b 434 struct drm_i915_private *dev_priv = connector->dev->dev_private;
55b7d6e8
CW
435 int ret;
436
437 ret = drm_connector_property_set_value(connector, property, val);
438 if (ret)
439 return ret;
440
3f43c48d 441 if (property == dev_priv->force_audio_property) {
b1d7e4b4 442 enum hdmi_force_audio i = val;
1aad7ac0
CW
443 bool has_audio;
444
445 if (i == intel_hdmi->force_audio)
55b7d6e8
CW
446 return 0;
447
1aad7ac0 448 intel_hdmi->force_audio = i;
55b7d6e8 449
b1d7e4b4 450 if (i == HDMI_AUDIO_AUTO)
1aad7ac0
CW
451 has_audio = intel_hdmi_detect_audio(connector);
452 else
b1d7e4b4 453 has_audio = (i == HDMI_AUDIO_ON);
1aad7ac0 454
b1d7e4b4
WF
455 if (i == HDMI_AUDIO_OFF_DVI)
456 intel_hdmi->has_hdmi_sink = 0;
55b7d6e8 457
1aad7ac0 458 intel_hdmi->has_audio = has_audio;
55b7d6e8
CW
459 goto done;
460 }
461
e953fd7b
CW
462 if (property == dev_priv->broadcast_rgb_property) {
463 if (val == !!intel_hdmi->color_range)
464 return 0;
465
466 intel_hdmi->color_range = val ? SDVO_COLOR_RANGE_16_235 : 0;
467 goto done;
468 }
469
55b7d6e8
CW
470 return -EINVAL;
471
472done:
473 if (intel_hdmi->base.base.crtc) {
474 struct drm_crtc *crtc = intel_hdmi->base.base.crtc;
475 drm_crtc_helper_set_mode(crtc, &crtc->mode,
476 crtc->x, crtc->y,
477 crtc->fb);
478 }
479
480 return 0;
481}
482
7d57382e
EA
483static void intel_hdmi_destroy(struct drm_connector *connector)
484{
7d57382e
EA
485 drm_sysfs_connector_remove(connector);
486 drm_connector_cleanup(connector);
674e2d08 487 kfree(connector);
7d57382e
EA
488}
489
490static const struct drm_encoder_helper_funcs intel_hdmi_helper_funcs = {
491 .dpms = intel_hdmi_dpms,
492 .mode_fixup = intel_hdmi_mode_fixup,
493 .prepare = intel_encoder_prepare,
494 .mode_set = intel_hdmi_mode_set,
495 .commit = intel_encoder_commit,
496};
497
498static const struct drm_connector_funcs intel_hdmi_connector_funcs = {
c9fb15f6 499 .dpms = drm_helper_connector_dpms,
7d57382e
EA
500 .detect = intel_hdmi_detect,
501 .fill_modes = drm_helper_probe_single_connector_modes,
55b7d6e8 502 .set_property = intel_hdmi_set_property,
7d57382e
EA
503 .destroy = intel_hdmi_destroy,
504};
505
506static const struct drm_connector_helper_funcs intel_hdmi_connector_helper_funcs = {
507 .get_modes = intel_hdmi_get_modes,
508 .mode_valid = intel_hdmi_mode_valid,
df0e9248 509 .best_encoder = intel_best_encoder,
7d57382e
EA
510};
511
7d57382e 512static const struct drm_encoder_funcs intel_hdmi_enc_funcs = {
ea5b213a 513 .destroy = intel_encoder_destroy,
7d57382e
EA
514};
515
55b7d6e8
CW
516static void
517intel_hdmi_add_properties(struct intel_hdmi *intel_hdmi, struct drm_connector *connector)
518{
3f43c48d 519 intel_attach_force_audio_property(connector);
e953fd7b 520 intel_attach_broadcast_rgb_property(connector);
55b7d6e8
CW
521}
522
7d57382e
EA
523void intel_hdmi_init(struct drm_device *dev, int sdvox_reg)
524{
525 struct drm_i915_private *dev_priv = dev->dev_private;
526 struct drm_connector *connector;
21d40d37 527 struct intel_encoder *intel_encoder;
674e2d08 528 struct intel_connector *intel_connector;
ea5b213a 529 struct intel_hdmi *intel_hdmi;
64a8fc01 530 int i;
7d57382e 531
ea5b213a
CW
532 intel_hdmi = kzalloc(sizeof(struct intel_hdmi), GFP_KERNEL);
533 if (!intel_hdmi)
7d57382e 534 return;
674e2d08
ZW
535
536 intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL);
537 if (!intel_connector) {
ea5b213a 538 kfree(intel_hdmi);
674e2d08
ZW
539 return;
540 }
541
ea5b213a 542 intel_encoder = &intel_hdmi->base;
373a3cf7
CW
543 drm_encoder_init(dev, &intel_encoder->base, &intel_hdmi_enc_funcs,
544 DRM_MODE_ENCODER_TMDS);
545
674e2d08 546 connector = &intel_connector->base;
7d57382e 547 drm_connector_init(dev, connector, &intel_hdmi_connector_funcs,
8d91104a 548 DRM_MODE_CONNECTOR_HDMIA);
7d57382e
EA
549 drm_connector_helper_add(connector, &intel_hdmi_connector_helper_funcs);
550
21d40d37 551 intel_encoder->type = INTEL_OUTPUT_HDMI;
7d57382e 552
eb1f8e4f 553 connector->polled = DRM_CONNECTOR_POLL_HPD;
c3febcc4 554 connector->interlace_allowed = 1;
7d57382e 555 connector->doublescan_allowed = 0;
27f8227b 556 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
7d57382e
EA
557
558 /* Set up the DDC bus. */
f8aed700 559 if (sdvox_reg == SDVOB) {
21d40d37 560 intel_encoder->clone_mask = (1 << INTEL_HDMIB_CLONE_BIT);
f899fc64 561 intel_hdmi->ddc_bus = GMBUS_PORT_DPB;
b01f2c3a 562 dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS;
f8aed700 563 } else if (sdvox_reg == SDVOC) {
21d40d37 564 intel_encoder->clone_mask = (1 << INTEL_HDMIC_CLONE_BIT);
f899fc64 565 intel_hdmi->ddc_bus = GMBUS_PORT_DPC;
b01f2c3a 566 dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS;
f8aed700 567 } else if (sdvox_reg == HDMIB) {
21d40d37 568 intel_encoder->clone_mask = (1 << INTEL_HDMID_CLONE_BIT);
f899fc64 569 intel_hdmi->ddc_bus = GMBUS_PORT_DPB;
b01f2c3a 570 dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS;
f8aed700 571 } else if (sdvox_reg == HDMIC) {
21d40d37 572 intel_encoder->clone_mask = (1 << INTEL_HDMIE_CLONE_BIT);
f899fc64 573 intel_hdmi->ddc_bus = GMBUS_PORT_DPC;
b01f2c3a 574 dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS;
f8aed700 575 } else if (sdvox_reg == HDMID) {
21d40d37 576 intel_encoder->clone_mask = (1 << INTEL_HDMIF_CLONE_BIT);
f899fc64 577 intel_hdmi->ddc_bus = GMBUS_PORT_DPD;
b01f2c3a 578 dev_priv->hotplug_supported_mask |= HDMID_HOTPLUG_INT_STATUS;
f8aed700 579 }
7d57382e 580
ea5b213a 581 intel_hdmi->sdvox_reg = sdvox_reg;
7d57382e 582
64a8fc01 583 if (!HAS_PCH_SPLIT(dev)) {
45187ace 584 intel_hdmi->write_infoframe = i9xx_write_infoframe;
64a8fc01 585 I915_WRITE(VIDEO_DIP_CTL, 0);
90b107c8
SK
586 } else if (IS_VALLEYVIEW(dev)) {
587 intel_hdmi->write_infoframe = vlv_write_infoframe;
588 for_each_pipe(i)
589 I915_WRITE(VLV_TVIDEO_DIP_CTL(i), 0);
590 } else {
45187ace 591 intel_hdmi->write_infoframe = ironlake_write_infoframe;
64a8fc01
JB
592 for_each_pipe(i)
593 I915_WRITE(TVIDEO_DIP_CTL(i), 0);
594 }
45187ace 595
4ef69c7a 596 drm_encoder_helper_add(&intel_encoder->base, &intel_hdmi_helper_funcs);
7d57382e 597
55b7d6e8
CW
598 intel_hdmi_add_properties(intel_hdmi, connector);
599
df0e9248 600 intel_connector_attach_encoder(intel_connector, intel_encoder);
7d57382e
EA
601 drm_sysfs_connector_add(connector);
602
603 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
604 * 0xd. Failure to do so will result in spurious interrupts being
605 * generated on the port when a cable is not attached.
606 */
607 if (IS_G4X(dev) && !IS_GM45(dev)) {
608 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
609 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
610 }
7d57382e 611}