2 * Copyright 2006 Dave Airlie <airlied@linux.ie>
3 * Copyright © 2006-2009 Intel Corporation
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:
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
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.
25 * Eric Anholt <eric@anholt.net>
26 * Jesse Barnes <jesse.barnes@intel.com>
29 #include <linux/i2c.h>
30 #include <linux/slab.h>
31 #include <linux/delay.h>
32 #include <linux/hdmi.h>
34 #include <drm/drm_atomic_helper.h>
35 #include <drm/drm_crtc.h>
36 #include <drm/drm_edid.h>
37 #include "intel_drv.h"
38 #include <drm/i915_drm.h>
39 #include <drm/intel_lpe_audio.h>
42 static struct drm_device *intel_hdmi_to_dev(struct intel_hdmi *intel_hdmi)
44 return hdmi_to_dig_port(intel_hdmi)->base.base.dev;
48 assert_hdmi_port_disabled(struct intel_hdmi *intel_hdmi)
50 struct drm_device *dev = intel_hdmi_to_dev(intel_hdmi);
51 struct drm_i915_private *dev_priv = to_i915(dev);
52 uint32_t enabled_bits;
54 enabled_bits = HAS_DDI(dev_priv) ? DDI_BUF_CTL_ENABLE : SDVO_ENABLE;
56 WARN(I915_READ(intel_hdmi->hdmi_reg) & enabled_bits,
57 "HDMI port enabled, expecting disabled\n");
60 struct intel_hdmi *enc_to_intel_hdmi(struct drm_encoder *encoder)
62 struct intel_digital_port *intel_dig_port =
63 container_of(encoder, struct intel_digital_port, base.base);
64 return &intel_dig_port->hdmi;
67 static struct intel_hdmi *intel_attached_hdmi(struct drm_connector *connector)
69 return enc_to_intel_hdmi(&intel_attached_encoder(connector)->base);
72 static u32 g4x_infoframe_index(enum hdmi_infoframe_type type)
75 case HDMI_INFOFRAME_TYPE_AVI:
76 return VIDEO_DIP_SELECT_AVI;
77 case HDMI_INFOFRAME_TYPE_SPD:
78 return VIDEO_DIP_SELECT_SPD;
79 case HDMI_INFOFRAME_TYPE_VENDOR:
80 return VIDEO_DIP_SELECT_VENDOR;
87 static u32 g4x_infoframe_enable(enum hdmi_infoframe_type type)
90 case HDMI_INFOFRAME_TYPE_AVI:
91 return VIDEO_DIP_ENABLE_AVI;
92 case HDMI_INFOFRAME_TYPE_SPD:
93 return VIDEO_DIP_ENABLE_SPD;
94 case HDMI_INFOFRAME_TYPE_VENDOR:
95 return VIDEO_DIP_ENABLE_VENDOR;
102 static u32 hsw_infoframe_enable(enum hdmi_infoframe_type type)
105 case HDMI_INFOFRAME_TYPE_AVI:
106 return VIDEO_DIP_ENABLE_AVI_HSW;
107 case HDMI_INFOFRAME_TYPE_SPD:
108 return VIDEO_DIP_ENABLE_SPD_HSW;
109 case HDMI_INFOFRAME_TYPE_VENDOR:
110 return VIDEO_DIP_ENABLE_VS_HSW;
118 hsw_dip_data_reg(struct drm_i915_private *dev_priv,
119 enum transcoder cpu_transcoder,
120 enum hdmi_infoframe_type type,
124 case HDMI_INFOFRAME_TYPE_AVI:
125 return HSW_TVIDEO_DIP_AVI_DATA(cpu_transcoder, i);
126 case HDMI_INFOFRAME_TYPE_SPD:
127 return HSW_TVIDEO_DIP_SPD_DATA(cpu_transcoder, i);
128 case HDMI_INFOFRAME_TYPE_VENDOR:
129 return HSW_TVIDEO_DIP_VS_DATA(cpu_transcoder, i);
132 return INVALID_MMIO_REG;
136 static void g4x_write_infoframe(struct drm_encoder *encoder,
137 enum hdmi_infoframe_type type,
138 const void *frame, ssize_t len)
140 const uint32_t *data = frame;
141 struct drm_device *dev = encoder->dev;
142 struct drm_i915_private *dev_priv = to_i915(dev);
143 u32 val = I915_READ(VIDEO_DIP_CTL);
146 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(type);
151 val &= ~g4x_infoframe_enable(type);
153 I915_WRITE(VIDEO_DIP_CTL, val);
156 for (i = 0; i < len; i += 4) {
157 I915_WRITE(VIDEO_DIP_DATA, *data);
160 /* Write every possible data byte to force correct ECC calculation. */
161 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
162 I915_WRITE(VIDEO_DIP_DATA, 0);
165 val |= g4x_infoframe_enable(type);
166 val &= ~VIDEO_DIP_FREQ_MASK;
167 val |= VIDEO_DIP_FREQ_VSYNC;
169 I915_WRITE(VIDEO_DIP_CTL, val);
170 POSTING_READ(VIDEO_DIP_CTL);
173 static bool g4x_infoframe_enabled(struct drm_encoder *encoder,
174 const struct intel_crtc_state *pipe_config)
176 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
177 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
178 u32 val = I915_READ(VIDEO_DIP_CTL);
180 if ((val & VIDEO_DIP_ENABLE) == 0)
183 if ((val & VIDEO_DIP_PORT_MASK) != VIDEO_DIP_PORT(intel_dig_port->port))
186 return val & (VIDEO_DIP_ENABLE_AVI |
187 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_SPD);
190 static void ibx_write_infoframe(struct drm_encoder *encoder,
191 enum hdmi_infoframe_type type,
192 const void *frame, ssize_t len)
194 const uint32_t *data = frame;
195 struct drm_device *dev = encoder->dev;
196 struct drm_i915_private *dev_priv = to_i915(dev);
197 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
198 i915_reg_t reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
199 u32 val = I915_READ(reg);
202 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
204 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
205 val |= g4x_infoframe_index(type);
207 val &= ~g4x_infoframe_enable(type);
209 I915_WRITE(reg, val);
212 for (i = 0; i < len; i += 4) {
213 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
216 /* Write every possible data byte to force correct ECC calculation. */
217 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
218 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), 0);
221 val |= g4x_infoframe_enable(type);
222 val &= ~VIDEO_DIP_FREQ_MASK;
223 val |= VIDEO_DIP_FREQ_VSYNC;
225 I915_WRITE(reg, val);
229 static bool ibx_infoframe_enabled(struct drm_encoder *encoder,
230 const struct intel_crtc_state *pipe_config)
232 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
233 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
234 enum pipe pipe = to_intel_crtc(pipe_config->base.crtc)->pipe;
235 i915_reg_t reg = TVIDEO_DIP_CTL(pipe);
236 u32 val = I915_READ(reg);
238 if ((val & VIDEO_DIP_ENABLE) == 0)
241 if ((val & VIDEO_DIP_PORT_MASK) != VIDEO_DIP_PORT(intel_dig_port->port))
244 return val & (VIDEO_DIP_ENABLE_AVI |
245 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
246 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
249 static void cpt_write_infoframe(struct drm_encoder *encoder,
250 enum hdmi_infoframe_type type,
251 const void *frame, ssize_t len)
253 const uint32_t *data = frame;
254 struct drm_device *dev = encoder->dev;
255 struct drm_i915_private *dev_priv = to_i915(dev);
256 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
257 i915_reg_t reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
258 u32 val = I915_READ(reg);
261 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
263 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
264 val |= g4x_infoframe_index(type);
266 /* The DIP control register spec says that we need to update the AVI
267 * infoframe without clearing its enable bit */
268 if (type != HDMI_INFOFRAME_TYPE_AVI)
269 val &= ~g4x_infoframe_enable(type);
271 I915_WRITE(reg, val);
274 for (i = 0; i < len; i += 4) {
275 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
278 /* Write every possible data byte to force correct ECC calculation. */
279 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
280 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), 0);
283 val |= g4x_infoframe_enable(type);
284 val &= ~VIDEO_DIP_FREQ_MASK;
285 val |= VIDEO_DIP_FREQ_VSYNC;
287 I915_WRITE(reg, val);
291 static bool cpt_infoframe_enabled(struct drm_encoder *encoder,
292 const struct intel_crtc_state *pipe_config)
294 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
295 enum pipe pipe = to_intel_crtc(pipe_config->base.crtc)->pipe;
296 u32 val = I915_READ(TVIDEO_DIP_CTL(pipe));
298 if ((val & VIDEO_DIP_ENABLE) == 0)
301 return val & (VIDEO_DIP_ENABLE_AVI |
302 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
303 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
306 static void vlv_write_infoframe(struct drm_encoder *encoder,
307 enum hdmi_infoframe_type type,
308 const void *frame, ssize_t len)
310 const uint32_t *data = frame;
311 struct drm_device *dev = encoder->dev;
312 struct drm_i915_private *dev_priv = to_i915(dev);
313 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
314 i915_reg_t reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
315 u32 val = I915_READ(reg);
318 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
320 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
321 val |= g4x_infoframe_index(type);
323 val &= ~g4x_infoframe_enable(type);
325 I915_WRITE(reg, val);
328 for (i = 0; i < len; i += 4) {
329 I915_WRITE(VLV_TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
332 /* Write every possible data byte to force correct ECC calculation. */
333 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
334 I915_WRITE(VLV_TVIDEO_DIP_DATA(intel_crtc->pipe), 0);
337 val |= g4x_infoframe_enable(type);
338 val &= ~VIDEO_DIP_FREQ_MASK;
339 val |= VIDEO_DIP_FREQ_VSYNC;
341 I915_WRITE(reg, val);
345 static bool vlv_infoframe_enabled(struct drm_encoder *encoder,
346 const struct intel_crtc_state *pipe_config)
348 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
349 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
350 enum pipe pipe = to_intel_crtc(pipe_config->base.crtc)->pipe;
351 u32 val = I915_READ(VLV_TVIDEO_DIP_CTL(pipe));
353 if ((val & VIDEO_DIP_ENABLE) == 0)
356 if ((val & VIDEO_DIP_PORT_MASK) != VIDEO_DIP_PORT(intel_dig_port->port))
359 return val & (VIDEO_DIP_ENABLE_AVI |
360 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
361 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
364 static void hsw_write_infoframe(struct drm_encoder *encoder,
365 enum hdmi_infoframe_type type,
366 const void *frame, ssize_t len)
368 const uint32_t *data = frame;
369 struct drm_device *dev = encoder->dev;
370 struct drm_i915_private *dev_priv = to_i915(dev);
371 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
372 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
373 i915_reg_t ctl_reg = HSW_TVIDEO_DIP_CTL(cpu_transcoder);
376 u32 val = I915_READ(ctl_reg);
378 data_reg = hsw_dip_data_reg(dev_priv, cpu_transcoder, type, 0);
380 val &= ~hsw_infoframe_enable(type);
381 I915_WRITE(ctl_reg, val);
384 for (i = 0; i < len; i += 4) {
385 I915_WRITE(hsw_dip_data_reg(dev_priv, cpu_transcoder,
386 type, i >> 2), *data);
389 /* Write every possible data byte to force correct ECC calculation. */
390 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
391 I915_WRITE(hsw_dip_data_reg(dev_priv, cpu_transcoder,
395 val |= hsw_infoframe_enable(type);
396 I915_WRITE(ctl_reg, val);
397 POSTING_READ(ctl_reg);
400 static bool hsw_infoframe_enabled(struct drm_encoder *encoder,
401 const struct intel_crtc_state *pipe_config)
403 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
404 u32 val = I915_READ(HSW_TVIDEO_DIP_CTL(pipe_config->cpu_transcoder));
406 return val & (VIDEO_DIP_ENABLE_VSC_HSW | VIDEO_DIP_ENABLE_AVI_HSW |
407 VIDEO_DIP_ENABLE_GCP_HSW | VIDEO_DIP_ENABLE_VS_HSW |
408 VIDEO_DIP_ENABLE_GMP_HSW | VIDEO_DIP_ENABLE_SPD_HSW);
412 * The data we write to the DIP data buffer registers is 1 byte bigger than the
413 * HDMI infoframe size because of an ECC/reserved byte at position 3 (starting
414 * at 0). It's also a byte used by DisplayPort so the same DIP registers can be
415 * used for both technologies.
417 * DW0: Reserved/ECC/DP | HB2 | HB1 | HB0
418 * DW1: DB3 | DB2 | DB1 | DB0
419 * DW2: DB7 | DB6 | DB5 | DB4
422 * (HB is Header Byte, DB is Data Byte)
424 * The hdmi pack() functions don't know about that hardware specific hole so we
425 * trick them by giving an offset into the buffer and moving back the header
428 static void intel_write_infoframe(struct drm_encoder *encoder,
429 union hdmi_infoframe *frame)
431 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
432 uint8_t buffer[VIDEO_DIP_DATA_SIZE];
435 /* see comment above for the reason for this offset */
436 len = hdmi_infoframe_pack(frame, buffer + 1, sizeof(buffer) - 1);
440 /* Insert the 'hole' (see big comment above) at position 3 */
441 buffer[0] = buffer[1];
442 buffer[1] = buffer[2];
443 buffer[2] = buffer[3];
447 intel_hdmi->write_infoframe(encoder, frame->any.type, buffer, len);
450 static void intel_hdmi_set_avi_infoframe(struct drm_encoder *encoder,
451 const struct drm_display_mode *adjusted_mode)
453 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
454 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
455 union hdmi_infoframe frame;
458 ret = drm_hdmi_avi_infoframe_from_display_mode(&frame.avi,
461 DRM_ERROR("couldn't fill AVI infoframe\n");
465 if (intel_hdmi->rgb_quant_range_selectable) {
466 if (intel_crtc->config->limited_color_range)
467 frame.avi.quantization_range =
468 HDMI_QUANTIZATION_RANGE_LIMITED;
470 frame.avi.quantization_range =
471 HDMI_QUANTIZATION_RANGE_FULL;
474 intel_write_infoframe(encoder, &frame);
477 static void intel_hdmi_set_spd_infoframe(struct drm_encoder *encoder)
479 union hdmi_infoframe frame;
482 ret = hdmi_spd_infoframe_init(&frame.spd, "Intel", "Integrated gfx");
484 DRM_ERROR("couldn't fill SPD infoframe\n");
488 frame.spd.sdi = HDMI_SPD_SDI_PC;
490 intel_write_infoframe(encoder, &frame);
494 intel_hdmi_set_hdmi_infoframe(struct drm_encoder *encoder,
495 const struct drm_display_mode *adjusted_mode)
497 union hdmi_infoframe frame;
500 ret = drm_hdmi_vendor_infoframe_from_display_mode(&frame.vendor.hdmi,
505 intel_write_infoframe(encoder, &frame);
508 static void g4x_set_infoframes(struct drm_encoder *encoder,
510 const struct drm_display_mode *adjusted_mode)
512 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
513 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
514 struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
515 i915_reg_t reg = VIDEO_DIP_CTL;
516 u32 val = I915_READ(reg);
517 u32 port = VIDEO_DIP_PORT(intel_dig_port->port);
519 assert_hdmi_port_disabled(intel_hdmi);
521 /* If the registers were not initialized yet, they might be zeroes,
522 * which means we're selecting the AVI DIP and we're setting its
523 * frequency to once. This seems to really confuse the HW and make
524 * things stop working (the register spec says the AVI always needs to
525 * be sent every VSync). So here we avoid writing to the register more
526 * than we need and also explicitly select the AVI DIP and explicitly
527 * set its frequency to every VSync. Avoiding to write it twice seems to
528 * be enough to solve the problem, but being defensive shouldn't hurt us
530 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
533 if (!(val & VIDEO_DIP_ENABLE))
535 if (port != (val & VIDEO_DIP_PORT_MASK)) {
536 DRM_DEBUG_KMS("video DIP still enabled on port %c\n",
537 (val & VIDEO_DIP_PORT_MASK) >> 29);
540 val &= ~(VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI |
541 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_SPD);
542 I915_WRITE(reg, val);
547 if (port != (val & VIDEO_DIP_PORT_MASK)) {
548 if (val & VIDEO_DIP_ENABLE) {
549 DRM_DEBUG_KMS("video DIP already enabled on port %c\n",
550 (val & VIDEO_DIP_PORT_MASK) >> 29);
553 val &= ~VIDEO_DIP_PORT_MASK;
557 val |= VIDEO_DIP_ENABLE;
558 val &= ~(VIDEO_DIP_ENABLE_AVI |
559 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_SPD);
561 I915_WRITE(reg, val);
564 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
565 intel_hdmi_set_spd_infoframe(encoder);
566 intel_hdmi_set_hdmi_infoframe(encoder, adjusted_mode);
569 static bool hdmi_sink_is_deep_color(struct drm_encoder *encoder)
571 struct drm_device *dev = encoder->dev;
572 struct drm_connector *connector;
574 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
577 * HDMI cloning is only supported on g4x which doesn't
578 * support deep color or GCP infoframes anyway so no
579 * need to worry about multiple HDMI sinks here.
581 list_for_each_entry(connector, &dev->mode_config.connector_list, head)
582 if (connector->encoder == encoder)
583 return connector->display_info.bpc > 8;
589 * Determine if default_phase=1 can be indicated in the GCP infoframe.
591 * From HDMI specification 1.4a:
592 * - The first pixel of each Video Data Period shall always have a pixel packing phase of 0
593 * - The first pixel following each Video Data Period shall have a pixel packing phase of 0
594 * - The PP bits shall be constant for all GCPs and will be equal to the last packing phase
595 * - The first pixel following every transition of HSYNC or VSYNC shall have a pixel packing
598 static bool gcp_default_phase_possible(int pipe_bpp,
599 const struct drm_display_mode *mode)
601 unsigned int pixels_per_group;
605 /* 4 pixels in 5 clocks */
606 pixels_per_group = 4;
609 /* 2 pixels in 3 clocks */
610 pixels_per_group = 2;
613 /* 1 pixel in 2 clocks */
614 pixels_per_group = 1;
617 /* phase information not relevant for 8bpc */
621 return mode->crtc_hdisplay % pixels_per_group == 0 &&
622 mode->crtc_htotal % pixels_per_group == 0 &&
623 mode->crtc_hblank_start % pixels_per_group == 0 &&
624 mode->crtc_hblank_end % pixels_per_group == 0 &&
625 mode->crtc_hsync_start % pixels_per_group == 0 &&
626 mode->crtc_hsync_end % pixels_per_group == 0 &&
627 ((mode->flags & DRM_MODE_FLAG_INTERLACE) == 0 ||
628 mode->crtc_htotal/2 % pixels_per_group == 0);
631 static bool intel_hdmi_set_gcp_infoframe(struct drm_encoder *encoder)
633 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
634 struct intel_crtc *crtc = to_intel_crtc(encoder->crtc);
638 if (HAS_DDI(dev_priv))
639 reg = HSW_TVIDEO_DIP_GCP(crtc->config->cpu_transcoder);
640 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
641 reg = VLV_TVIDEO_DIP_GCP(crtc->pipe);
642 else if (HAS_PCH_SPLIT(dev_priv))
643 reg = TVIDEO_DIP_GCP(crtc->pipe);
647 /* Indicate color depth whenever the sink supports deep color */
648 if (hdmi_sink_is_deep_color(encoder))
649 val |= GCP_COLOR_INDICATION;
651 /* Enable default_phase whenever the display mode is suitably aligned */
652 if (gcp_default_phase_possible(crtc->config->pipe_bpp,
653 &crtc->config->base.adjusted_mode))
654 val |= GCP_DEFAULT_PHASE_ENABLE;
656 I915_WRITE(reg, val);
661 static void ibx_set_infoframes(struct drm_encoder *encoder,
663 const struct drm_display_mode *adjusted_mode)
665 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
666 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
667 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
668 struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
669 i915_reg_t reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
670 u32 val = I915_READ(reg);
671 u32 port = VIDEO_DIP_PORT(intel_dig_port->port);
673 assert_hdmi_port_disabled(intel_hdmi);
675 /* See the big comment in g4x_set_infoframes() */
676 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
679 if (!(val & VIDEO_DIP_ENABLE))
681 val &= ~(VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI |
682 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
683 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
684 I915_WRITE(reg, val);
689 if (port != (val & VIDEO_DIP_PORT_MASK)) {
690 WARN(val & VIDEO_DIP_ENABLE,
691 "DIP already enabled on port %c\n",
692 (val & VIDEO_DIP_PORT_MASK) >> 29);
693 val &= ~VIDEO_DIP_PORT_MASK;
697 val |= VIDEO_DIP_ENABLE;
698 val &= ~(VIDEO_DIP_ENABLE_AVI |
699 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
700 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
702 if (intel_hdmi_set_gcp_infoframe(encoder))
703 val |= VIDEO_DIP_ENABLE_GCP;
705 I915_WRITE(reg, val);
708 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
709 intel_hdmi_set_spd_infoframe(encoder);
710 intel_hdmi_set_hdmi_infoframe(encoder, adjusted_mode);
713 static void cpt_set_infoframes(struct drm_encoder *encoder,
715 const struct drm_display_mode *adjusted_mode)
717 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
718 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
719 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
720 i915_reg_t reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
721 u32 val = I915_READ(reg);
723 assert_hdmi_port_disabled(intel_hdmi);
725 /* See the big comment in g4x_set_infoframes() */
726 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
729 if (!(val & VIDEO_DIP_ENABLE))
731 val &= ~(VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI |
732 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
733 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
734 I915_WRITE(reg, val);
739 /* Set both together, unset both together: see the spec. */
740 val |= VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI;
741 val &= ~(VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
742 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
744 if (intel_hdmi_set_gcp_infoframe(encoder))
745 val |= VIDEO_DIP_ENABLE_GCP;
747 I915_WRITE(reg, val);
750 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
751 intel_hdmi_set_spd_infoframe(encoder);
752 intel_hdmi_set_hdmi_infoframe(encoder, adjusted_mode);
755 static void vlv_set_infoframes(struct drm_encoder *encoder,
757 const struct drm_display_mode *adjusted_mode)
759 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
760 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
761 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
762 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
763 i915_reg_t reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
764 u32 val = I915_READ(reg);
765 u32 port = VIDEO_DIP_PORT(intel_dig_port->port);
767 assert_hdmi_port_disabled(intel_hdmi);
769 /* See the big comment in g4x_set_infoframes() */
770 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
773 if (!(val & VIDEO_DIP_ENABLE))
775 val &= ~(VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI |
776 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
777 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
778 I915_WRITE(reg, val);
783 if (port != (val & VIDEO_DIP_PORT_MASK)) {
784 WARN(val & VIDEO_DIP_ENABLE,
785 "DIP already enabled on port %c\n",
786 (val & VIDEO_DIP_PORT_MASK) >> 29);
787 val &= ~VIDEO_DIP_PORT_MASK;
791 val |= VIDEO_DIP_ENABLE;
792 val &= ~(VIDEO_DIP_ENABLE_AVI |
793 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
794 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
796 if (intel_hdmi_set_gcp_infoframe(encoder))
797 val |= VIDEO_DIP_ENABLE_GCP;
799 I915_WRITE(reg, val);
802 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
803 intel_hdmi_set_spd_infoframe(encoder);
804 intel_hdmi_set_hdmi_infoframe(encoder, adjusted_mode);
807 static void hsw_set_infoframes(struct drm_encoder *encoder,
809 const struct drm_display_mode *adjusted_mode)
811 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
812 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
813 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
814 i915_reg_t reg = HSW_TVIDEO_DIP_CTL(intel_crtc->config->cpu_transcoder);
815 u32 val = I915_READ(reg);
817 assert_hdmi_port_disabled(intel_hdmi);
819 val &= ~(VIDEO_DIP_ENABLE_VSC_HSW | VIDEO_DIP_ENABLE_AVI_HSW |
820 VIDEO_DIP_ENABLE_GCP_HSW | VIDEO_DIP_ENABLE_VS_HSW |
821 VIDEO_DIP_ENABLE_GMP_HSW | VIDEO_DIP_ENABLE_SPD_HSW);
824 I915_WRITE(reg, val);
829 if (intel_hdmi_set_gcp_infoframe(encoder))
830 val |= VIDEO_DIP_ENABLE_GCP_HSW;
832 I915_WRITE(reg, val);
835 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
836 intel_hdmi_set_spd_infoframe(encoder);
837 intel_hdmi_set_hdmi_infoframe(encoder, adjusted_mode);
840 void intel_dp_dual_mode_set_tmds_output(struct intel_hdmi *hdmi, bool enable)
842 struct drm_i915_private *dev_priv = to_i915(intel_hdmi_to_dev(hdmi));
843 struct i2c_adapter *adapter =
844 intel_gmbus_get_adapter(dev_priv, hdmi->ddc_bus);
846 if (hdmi->dp_dual_mode.type < DRM_DP_DUAL_MODE_TYPE2_DVI)
849 DRM_DEBUG_KMS("%s DP dual mode adaptor TMDS output\n",
850 enable ? "Enabling" : "Disabling");
852 drm_dp_dual_mode_set_tmds_output(hdmi->dp_dual_mode.type,
856 static void intel_hdmi_prepare(struct intel_encoder *encoder)
858 struct drm_device *dev = encoder->base.dev;
859 struct drm_i915_private *dev_priv = to_i915(dev);
860 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
861 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
862 const struct drm_display_mode *adjusted_mode = &crtc->config->base.adjusted_mode;
865 intel_dp_dual_mode_set_tmds_output(intel_hdmi, true);
867 hdmi_val = SDVO_ENCODING_HDMI;
868 if (!HAS_PCH_SPLIT(dev_priv) && crtc->config->limited_color_range)
869 hdmi_val |= HDMI_COLOR_RANGE_16_235;
870 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
871 hdmi_val |= SDVO_VSYNC_ACTIVE_HIGH;
872 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
873 hdmi_val |= SDVO_HSYNC_ACTIVE_HIGH;
875 if (crtc->config->pipe_bpp > 24)
876 hdmi_val |= HDMI_COLOR_FORMAT_12bpc;
878 hdmi_val |= SDVO_COLOR_FORMAT_8bpc;
880 if (crtc->config->has_hdmi_sink)
881 hdmi_val |= HDMI_MODE_SELECT_HDMI;
883 if (HAS_PCH_CPT(dev_priv))
884 hdmi_val |= SDVO_PIPE_SEL_CPT(crtc->pipe);
885 else if (IS_CHERRYVIEW(dev_priv))
886 hdmi_val |= SDVO_PIPE_SEL_CHV(crtc->pipe);
888 hdmi_val |= SDVO_PIPE_SEL(crtc->pipe);
890 I915_WRITE(intel_hdmi->hdmi_reg, hdmi_val);
891 POSTING_READ(intel_hdmi->hdmi_reg);
894 static bool intel_hdmi_get_hw_state(struct intel_encoder *encoder,
897 struct drm_device *dev = encoder->base.dev;
898 struct drm_i915_private *dev_priv = to_i915(dev);
899 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
900 enum intel_display_power_domain power_domain;
904 power_domain = intel_display_port_power_domain(encoder);
905 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
910 tmp = I915_READ(intel_hdmi->hdmi_reg);
912 if (!(tmp & SDVO_ENABLE))
915 if (HAS_PCH_CPT(dev_priv))
916 *pipe = PORT_TO_PIPE_CPT(tmp);
917 else if (IS_CHERRYVIEW(dev_priv))
918 *pipe = SDVO_PORT_TO_PIPE_CHV(tmp);
920 *pipe = PORT_TO_PIPE(tmp);
925 intel_display_power_put(dev_priv, power_domain);
930 static void intel_hdmi_get_config(struct intel_encoder *encoder,
931 struct intel_crtc_state *pipe_config)
933 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
934 struct drm_device *dev = encoder->base.dev;
935 struct drm_i915_private *dev_priv = to_i915(dev);
939 tmp = I915_READ(intel_hdmi->hdmi_reg);
941 if (tmp & SDVO_HSYNC_ACTIVE_HIGH)
942 flags |= DRM_MODE_FLAG_PHSYNC;
944 flags |= DRM_MODE_FLAG_NHSYNC;
946 if (tmp & SDVO_VSYNC_ACTIVE_HIGH)
947 flags |= DRM_MODE_FLAG_PVSYNC;
949 flags |= DRM_MODE_FLAG_NVSYNC;
951 if (tmp & HDMI_MODE_SELECT_HDMI)
952 pipe_config->has_hdmi_sink = true;
954 if (intel_hdmi->infoframe_enabled(&encoder->base, pipe_config))
955 pipe_config->has_infoframe = true;
957 if (tmp & SDVO_AUDIO_ENABLE)
958 pipe_config->has_audio = true;
960 if (!HAS_PCH_SPLIT(dev_priv) &&
961 tmp & HDMI_COLOR_RANGE_16_235)
962 pipe_config->limited_color_range = true;
964 pipe_config->base.adjusted_mode.flags |= flags;
966 if ((tmp & SDVO_COLOR_FORMAT_MASK) == HDMI_COLOR_FORMAT_12bpc)
967 dotclock = pipe_config->port_clock * 2 / 3;
969 dotclock = pipe_config->port_clock;
971 if (pipe_config->pixel_multiplier)
972 dotclock /= pipe_config->pixel_multiplier;
974 pipe_config->base.adjusted_mode.crtc_clock = dotclock;
976 pipe_config->lane_count = 4;
979 static void intel_enable_hdmi_audio(struct intel_encoder *encoder,
980 struct intel_crtc_state *pipe_config,
981 struct drm_connector_state *conn_state)
983 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
985 WARN_ON(!crtc->config->has_hdmi_sink);
986 DRM_DEBUG_DRIVER("Enabling HDMI audio on pipe %c\n",
987 pipe_name(crtc->pipe));
988 intel_audio_codec_enable(encoder, pipe_config, conn_state);
991 static void g4x_enable_hdmi(struct intel_encoder *encoder,
992 struct intel_crtc_state *pipe_config,
993 struct drm_connector_state *conn_state)
995 struct drm_device *dev = encoder->base.dev;
996 struct drm_i915_private *dev_priv = to_i915(dev);
997 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
1000 temp = I915_READ(intel_hdmi->hdmi_reg);
1002 temp |= SDVO_ENABLE;
1003 if (pipe_config->has_audio)
1004 temp |= SDVO_AUDIO_ENABLE;
1006 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1007 POSTING_READ(intel_hdmi->hdmi_reg);
1009 if (pipe_config->has_audio)
1010 intel_enable_hdmi_audio(encoder, pipe_config, conn_state);
1013 static void ibx_enable_hdmi(struct intel_encoder *encoder,
1014 struct intel_crtc_state *pipe_config,
1015 struct drm_connector_state *conn_state)
1017 struct drm_device *dev = encoder->base.dev;
1018 struct drm_i915_private *dev_priv = to_i915(dev);
1019 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
1020 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
1023 temp = I915_READ(intel_hdmi->hdmi_reg);
1025 temp |= SDVO_ENABLE;
1026 if (crtc->config->has_audio)
1027 temp |= SDVO_AUDIO_ENABLE;
1030 * HW workaround, need to write this twice for issue
1031 * that may result in first write getting masked.
1033 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1034 POSTING_READ(intel_hdmi->hdmi_reg);
1035 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1036 POSTING_READ(intel_hdmi->hdmi_reg);
1039 * HW workaround, need to toggle enable bit off and on
1040 * for 12bpc with pixel repeat.
1042 * FIXME: BSpec says this should be done at the end of
1043 * of the modeset sequence, so not sure if this isn't too soon.
1045 if (pipe_config->pipe_bpp > 24 &&
1046 pipe_config->pixel_multiplier > 1) {
1047 I915_WRITE(intel_hdmi->hdmi_reg, temp & ~SDVO_ENABLE);
1048 POSTING_READ(intel_hdmi->hdmi_reg);
1051 * HW workaround, need to write this twice for issue
1052 * that may result in first write getting masked.
1054 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1055 POSTING_READ(intel_hdmi->hdmi_reg);
1056 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1057 POSTING_READ(intel_hdmi->hdmi_reg);
1060 if (pipe_config->has_audio)
1061 intel_enable_hdmi_audio(encoder, pipe_config, conn_state);
1064 static void cpt_enable_hdmi(struct intel_encoder *encoder,
1065 struct intel_crtc_state *pipe_config,
1066 struct drm_connector_state *conn_state)
1068 struct drm_device *dev = encoder->base.dev;
1069 struct drm_i915_private *dev_priv = to_i915(dev);
1070 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
1071 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
1072 enum pipe pipe = crtc->pipe;
1075 temp = I915_READ(intel_hdmi->hdmi_reg);
1077 temp |= SDVO_ENABLE;
1078 if (pipe_config->has_audio)
1079 temp |= SDVO_AUDIO_ENABLE;
1082 * WaEnableHDMI8bpcBefore12bpc:snb,ivb
1084 * The procedure for 12bpc is as follows:
1085 * 1. disable HDMI clock gating
1086 * 2. enable HDMI with 8bpc
1087 * 3. enable HDMI with 12bpc
1088 * 4. enable HDMI clock gating
1091 if (pipe_config->pipe_bpp > 24) {
1092 I915_WRITE(TRANS_CHICKEN1(pipe),
1093 I915_READ(TRANS_CHICKEN1(pipe)) |
1094 TRANS_CHICKEN1_HDMIUNIT_GC_DISABLE);
1096 temp &= ~SDVO_COLOR_FORMAT_MASK;
1097 temp |= SDVO_COLOR_FORMAT_8bpc;
1100 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1101 POSTING_READ(intel_hdmi->hdmi_reg);
1103 if (pipe_config->pipe_bpp > 24) {
1104 temp &= ~SDVO_COLOR_FORMAT_MASK;
1105 temp |= HDMI_COLOR_FORMAT_12bpc;
1107 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1108 POSTING_READ(intel_hdmi->hdmi_reg);
1110 I915_WRITE(TRANS_CHICKEN1(pipe),
1111 I915_READ(TRANS_CHICKEN1(pipe)) &
1112 ~TRANS_CHICKEN1_HDMIUNIT_GC_DISABLE);
1115 if (pipe_config->has_audio)
1116 intel_enable_hdmi_audio(encoder, pipe_config, conn_state);
1119 static void vlv_enable_hdmi(struct intel_encoder *encoder,
1120 struct intel_crtc_state *pipe_config,
1121 struct drm_connector_state *conn_state)
1125 static void intel_disable_hdmi(struct intel_encoder *encoder,
1126 struct intel_crtc_state *old_crtc_state,
1127 struct drm_connector_state *old_conn_state)
1129 struct drm_device *dev = encoder->base.dev;
1130 struct drm_i915_private *dev_priv = to_i915(dev);
1131 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
1132 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
1135 temp = I915_READ(intel_hdmi->hdmi_reg);
1137 temp &= ~(SDVO_ENABLE | SDVO_AUDIO_ENABLE);
1138 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1139 POSTING_READ(intel_hdmi->hdmi_reg);
1142 * HW workaround for IBX, we need to move the port
1143 * to transcoder A after disabling it to allow the
1144 * matching DP port to be enabled on transcoder A.
1146 if (HAS_PCH_IBX(dev_priv) && crtc->pipe == PIPE_B) {
1148 * We get CPU/PCH FIFO underruns on the other pipe when
1149 * doing the workaround. Sweep them under the rug.
1151 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
1152 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
1154 temp &= ~SDVO_PIPE_B_SELECT;
1155 temp |= SDVO_ENABLE;
1157 * HW workaround, need to write this twice for issue
1158 * that may result in first write getting masked.
1160 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1161 POSTING_READ(intel_hdmi->hdmi_reg);
1162 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1163 POSTING_READ(intel_hdmi->hdmi_reg);
1165 temp &= ~SDVO_ENABLE;
1166 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1167 POSTING_READ(intel_hdmi->hdmi_reg);
1169 intel_wait_for_vblank_if_active(dev_priv, PIPE_A);
1170 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
1171 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
1174 intel_hdmi->set_infoframes(&encoder->base, false, NULL);
1176 intel_dp_dual_mode_set_tmds_output(intel_hdmi, false);
1179 static void g4x_disable_hdmi(struct intel_encoder *encoder,
1180 struct intel_crtc_state *old_crtc_state,
1181 struct drm_connector_state *old_conn_state)
1183 if (old_crtc_state->has_audio)
1184 intel_audio_codec_disable(encoder);
1186 intel_disable_hdmi(encoder, old_crtc_state, old_conn_state);
1189 static void pch_disable_hdmi(struct intel_encoder *encoder,
1190 struct intel_crtc_state *old_crtc_state,
1191 struct drm_connector_state *old_conn_state)
1193 if (old_crtc_state->has_audio)
1194 intel_audio_codec_disable(encoder);
1197 static void pch_post_disable_hdmi(struct intel_encoder *encoder,
1198 struct intel_crtc_state *old_crtc_state,
1199 struct drm_connector_state *old_conn_state)
1201 intel_disable_hdmi(encoder, old_crtc_state, old_conn_state);
1204 static int intel_hdmi_source_max_tmds_clock(struct drm_i915_private *dev_priv)
1206 if (IS_G4X(dev_priv))
1208 else if (IS_HASWELL(dev_priv) || INTEL_INFO(dev_priv)->gen >= 8)
1214 static int hdmi_port_clock_limit(struct intel_hdmi *hdmi,
1215 bool respect_downstream_limits)
1217 struct drm_device *dev = intel_hdmi_to_dev(hdmi);
1218 int max_tmds_clock = intel_hdmi_source_max_tmds_clock(to_i915(dev));
1220 if (respect_downstream_limits) {
1221 struct intel_connector *connector = hdmi->attached_connector;
1222 const struct drm_display_info *info = &connector->base.display_info;
1224 if (hdmi->dp_dual_mode.max_tmds_clock)
1225 max_tmds_clock = min(max_tmds_clock,
1226 hdmi->dp_dual_mode.max_tmds_clock);
1228 if (info->max_tmds_clock)
1229 max_tmds_clock = min(max_tmds_clock,
1230 info->max_tmds_clock);
1231 else if (!hdmi->has_hdmi_sink)
1232 max_tmds_clock = min(max_tmds_clock, 165000);
1235 return max_tmds_clock;
1238 static enum drm_mode_status
1239 hdmi_port_clock_valid(struct intel_hdmi *hdmi,
1240 int clock, bool respect_downstream_limits)
1242 struct drm_i915_private *dev_priv = to_i915(intel_hdmi_to_dev(hdmi));
1245 return MODE_CLOCK_LOW;
1246 if (clock > hdmi_port_clock_limit(hdmi, respect_downstream_limits))
1247 return MODE_CLOCK_HIGH;
1249 /* BXT DPLL can't generate 223-240 MHz */
1250 if (IS_BROXTON(dev_priv) && clock > 223333 && clock < 240000)
1251 return MODE_CLOCK_RANGE;
1253 /* CHV DPLL can't generate 216-240 MHz */
1254 if (IS_CHERRYVIEW(dev_priv) && clock > 216000 && clock < 240000)
1255 return MODE_CLOCK_RANGE;
1260 static enum drm_mode_status
1261 intel_hdmi_mode_valid(struct drm_connector *connector,
1262 struct drm_display_mode *mode)
1264 struct intel_hdmi *hdmi = intel_attached_hdmi(connector);
1265 struct drm_device *dev = intel_hdmi_to_dev(hdmi);
1266 struct drm_i915_private *dev_priv = to_i915(dev);
1267 enum drm_mode_status status;
1269 int max_dotclk = to_i915(connector->dev)->max_dotclk_freq;
1271 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
1272 return MODE_NO_DBLESCAN;
1274 clock = mode->clock;
1276 if ((mode->flags & DRM_MODE_FLAG_3D_MASK) == DRM_MODE_FLAG_3D_FRAME_PACKING)
1279 if (clock > max_dotclk)
1280 return MODE_CLOCK_HIGH;
1282 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
1285 /* check if we can do 8bpc */
1286 status = hdmi_port_clock_valid(hdmi, clock, true);
1288 /* if we can't do 8bpc we may still be able to do 12bpc */
1289 if (!HAS_GMCH_DISPLAY(dev_priv) && status != MODE_OK)
1290 status = hdmi_port_clock_valid(hdmi, clock * 3 / 2, true);
1295 static bool hdmi_12bpc_possible(struct intel_crtc_state *crtc_state)
1297 struct drm_device *dev = crtc_state->base.crtc->dev;
1299 if (HAS_GMCH_DISPLAY(to_i915(dev)))
1303 * HDMI 12bpc affects the clocks, so it's only possible
1304 * when not cloning with other encoder types.
1306 return crtc_state->output_types == 1 << INTEL_OUTPUT_HDMI;
1309 bool intel_hdmi_compute_config(struct intel_encoder *encoder,
1310 struct intel_crtc_state *pipe_config,
1311 struct drm_connector_state *conn_state)
1313 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
1314 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1315 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
1316 int clock_8bpc = pipe_config->base.adjusted_mode.crtc_clock;
1317 int clock_12bpc = clock_8bpc * 3 / 2;
1320 pipe_config->has_hdmi_sink = intel_hdmi->has_hdmi_sink;
1322 if (pipe_config->has_hdmi_sink)
1323 pipe_config->has_infoframe = true;
1325 if (intel_hdmi->color_range_auto) {
1326 /* See CEA-861-E - 5.1 Default Encoding Parameters */
1327 pipe_config->limited_color_range =
1328 pipe_config->has_hdmi_sink &&
1329 drm_match_cea_mode(adjusted_mode) > 1;
1331 pipe_config->limited_color_range =
1332 intel_hdmi->limited_color_range;
1335 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK) {
1336 pipe_config->pixel_multiplier = 2;
1341 if (HAS_PCH_SPLIT(dev_priv) && !HAS_DDI(dev_priv))
1342 pipe_config->has_pch_encoder = true;
1344 if (pipe_config->has_hdmi_sink && intel_hdmi->has_audio)
1345 pipe_config->has_audio = true;
1348 * HDMI is either 12 or 8, so if the display lets 10bpc sneak
1349 * through, clamp it down. Note that g4x/vlv don't support 12bpc hdmi
1350 * outputs. We also need to check that the higher clock still fits
1353 if (pipe_config->pipe_bpp > 8*3 && pipe_config->has_hdmi_sink &&
1354 hdmi_port_clock_valid(intel_hdmi, clock_12bpc, true) == MODE_OK &&
1355 hdmi_12bpc_possible(pipe_config)) {
1356 DRM_DEBUG_KMS("picking bpc to 12 for HDMI output\n");
1359 /* Need to adjust the port link by 1.5x for 12bpc. */
1360 pipe_config->port_clock = clock_12bpc;
1362 DRM_DEBUG_KMS("picking bpc to 8 for HDMI output\n");
1365 pipe_config->port_clock = clock_8bpc;
1368 if (!pipe_config->bw_constrained) {
1369 DRM_DEBUG_KMS("forcing pipe bpc to %i for HDMI\n", desired_bpp);
1370 pipe_config->pipe_bpp = desired_bpp;
1373 if (hdmi_port_clock_valid(intel_hdmi, pipe_config->port_clock,
1374 false) != MODE_OK) {
1375 DRM_DEBUG_KMS("unsupported HDMI clock, rejecting mode\n");
1379 /* Set user selected PAR to incoming mode's member */
1380 adjusted_mode->picture_aspect_ratio = intel_hdmi->aspect_ratio;
1382 pipe_config->lane_count = 4;
1388 intel_hdmi_unset_edid(struct drm_connector *connector)
1390 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
1392 intel_hdmi->has_hdmi_sink = false;
1393 intel_hdmi->has_audio = false;
1394 intel_hdmi->rgb_quant_range_selectable = false;
1396 intel_hdmi->dp_dual_mode.type = DRM_DP_DUAL_MODE_NONE;
1397 intel_hdmi->dp_dual_mode.max_tmds_clock = 0;
1399 kfree(to_intel_connector(connector)->detect_edid);
1400 to_intel_connector(connector)->detect_edid = NULL;
1404 intel_hdmi_dp_dual_mode_detect(struct drm_connector *connector, bool has_edid)
1406 struct drm_i915_private *dev_priv = to_i915(connector->dev);
1407 struct intel_hdmi *hdmi = intel_attached_hdmi(connector);
1408 enum port port = hdmi_to_dig_port(hdmi)->port;
1409 struct i2c_adapter *adapter =
1410 intel_gmbus_get_adapter(dev_priv, hdmi->ddc_bus);
1411 enum drm_dp_dual_mode_type type = drm_dp_dual_mode_detect(adapter);
1414 * Type 1 DVI adaptors are not required to implement any
1415 * registers, so we can't always detect their presence.
1416 * Ideally we should be able to check the state of the
1417 * CONFIG1 pin, but no such luck on our hardware.
1419 * The only method left to us is to check the VBT to see
1420 * if the port is a dual mode capable DP port. But let's
1421 * only do that when we sucesfully read the EDID, to avoid
1422 * confusing log messages about DP dual mode adaptors when
1423 * there's nothing connected to the port.
1425 if (type == DRM_DP_DUAL_MODE_UNKNOWN) {
1427 intel_bios_is_port_dp_dual_mode(dev_priv, port)) {
1428 DRM_DEBUG_KMS("Assuming DP dual mode adaptor presence based on VBT\n");
1429 type = DRM_DP_DUAL_MODE_TYPE1_DVI;
1431 type = DRM_DP_DUAL_MODE_NONE;
1435 if (type == DRM_DP_DUAL_MODE_NONE)
1438 hdmi->dp_dual_mode.type = type;
1439 hdmi->dp_dual_mode.max_tmds_clock =
1440 drm_dp_dual_mode_max_tmds_clock(type, adapter);
1442 DRM_DEBUG_KMS("DP dual mode adaptor (%s) detected (max TMDS clock: %d kHz)\n",
1443 drm_dp_get_dual_mode_type_name(type),
1444 hdmi->dp_dual_mode.max_tmds_clock);
1448 intel_hdmi_set_edid(struct drm_connector *connector)
1450 struct drm_i915_private *dev_priv = to_i915(connector->dev);
1451 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
1453 bool connected = false;
1455 intel_display_power_get(dev_priv, POWER_DOMAIN_GMBUS);
1457 edid = drm_get_edid(connector,
1458 intel_gmbus_get_adapter(dev_priv,
1459 intel_hdmi->ddc_bus));
1461 intel_hdmi_dp_dual_mode_detect(connector, edid != NULL);
1463 intel_display_power_put(dev_priv, POWER_DOMAIN_GMBUS);
1465 to_intel_connector(connector)->detect_edid = edid;
1466 if (edid && edid->input & DRM_EDID_INPUT_DIGITAL) {
1467 intel_hdmi->rgb_quant_range_selectable =
1468 drm_rgb_quant_range_selectable(edid);
1470 intel_hdmi->has_audio = drm_detect_monitor_audio(edid);
1471 if (intel_hdmi->force_audio != HDMI_AUDIO_AUTO)
1472 intel_hdmi->has_audio =
1473 intel_hdmi->force_audio == HDMI_AUDIO_ON;
1475 if (intel_hdmi->force_audio != HDMI_AUDIO_OFF_DVI)
1476 intel_hdmi->has_hdmi_sink =
1477 drm_detect_hdmi_monitor(edid);
1485 static enum drm_connector_status
1486 intel_hdmi_detect(struct drm_connector *connector, bool force)
1488 enum drm_connector_status status;
1489 struct drm_i915_private *dev_priv = to_i915(connector->dev);
1491 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
1492 connector->base.id, connector->name);
1494 intel_display_power_get(dev_priv, POWER_DOMAIN_GMBUS);
1496 intel_hdmi_unset_edid(connector);
1498 if (intel_hdmi_set_edid(connector)) {
1499 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
1501 hdmi_to_dig_port(intel_hdmi)->base.type = INTEL_OUTPUT_HDMI;
1502 status = connector_status_connected;
1504 status = connector_status_disconnected;
1506 intel_display_power_put(dev_priv, POWER_DOMAIN_GMBUS);
1512 intel_hdmi_force(struct drm_connector *connector)
1514 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
1516 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
1517 connector->base.id, connector->name);
1519 intel_hdmi_unset_edid(connector);
1521 if (connector->status != connector_status_connected)
1524 intel_hdmi_set_edid(connector);
1525 hdmi_to_dig_port(intel_hdmi)->base.type = INTEL_OUTPUT_HDMI;
1528 static int intel_hdmi_get_modes(struct drm_connector *connector)
1532 edid = to_intel_connector(connector)->detect_edid;
1536 return intel_connector_update_modes(connector, edid);
1540 intel_hdmi_detect_audio(struct drm_connector *connector)
1542 bool has_audio = false;
1545 edid = to_intel_connector(connector)->detect_edid;
1546 if (edid && edid->input & DRM_EDID_INPUT_DIGITAL)
1547 has_audio = drm_detect_monitor_audio(edid);
1553 intel_hdmi_set_property(struct drm_connector *connector,
1554 struct drm_property *property,
1557 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
1558 struct intel_digital_port *intel_dig_port =
1559 hdmi_to_dig_port(intel_hdmi);
1560 struct drm_i915_private *dev_priv = to_i915(connector->dev);
1563 ret = drm_object_property_set_value(&connector->base, property, val);
1567 if (property == dev_priv->force_audio_property) {
1568 enum hdmi_force_audio i = val;
1571 if (i == intel_hdmi->force_audio)
1574 intel_hdmi->force_audio = i;
1576 if (i == HDMI_AUDIO_AUTO)
1577 has_audio = intel_hdmi_detect_audio(connector);
1579 has_audio = (i == HDMI_AUDIO_ON);
1581 if (i == HDMI_AUDIO_OFF_DVI)
1582 intel_hdmi->has_hdmi_sink = 0;
1584 intel_hdmi->has_audio = has_audio;
1588 if (property == dev_priv->broadcast_rgb_property) {
1589 bool old_auto = intel_hdmi->color_range_auto;
1590 bool old_range = intel_hdmi->limited_color_range;
1593 case INTEL_BROADCAST_RGB_AUTO:
1594 intel_hdmi->color_range_auto = true;
1596 case INTEL_BROADCAST_RGB_FULL:
1597 intel_hdmi->color_range_auto = false;
1598 intel_hdmi->limited_color_range = false;
1600 case INTEL_BROADCAST_RGB_LIMITED:
1601 intel_hdmi->color_range_auto = false;
1602 intel_hdmi->limited_color_range = true;
1608 if (old_auto == intel_hdmi->color_range_auto &&
1609 old_range == intel_hdmi->limited_color_range)
1615 if (property == connector->dev->mode_config.aspect_ratio_property) {
1617 case DRM_MODE_PICTURE_ASPECT_NONE:
1618 intel_hdmi->aspect_ratio = HDMI_PICTURE_ASPECT_NONE;
1620 case DRM_MODE_PICTURE_ASPECT_4_3:
1621 intel_hdmi->aspect_ratio = HDMI_PICTURE_ASPECT_4_3;
1623 case DRM_MODE_PICTURE_ASPECT_16_9:
1624 intel_hdmi->aspect_ratio = HDMI_PICTURE_ASPECT_16_9;
1635 if (intel_dig_port->base.base.crtc)
1636 intel_crtc_restore_mode(intel_dig_port->base.base.crtc);
1641 static void intel_hdmi_pre_enable(struct intel_encoder *encoder,
1642 struct intel_crtc_state *pipe_config,
1643 struct drm_connector_state *conn_state)
1645 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
1646 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
1648 intel_hdmi_prepare(encoder);
1650 intel_hdmi->set_infoframes(&encoder->base,
1651 pipe_config->has_hdmi_sink,
1655 static void vlv_hdmi_pre_enable(struct intel_encoder *encoder,
1656 struct intel_crtc_state *pipe_config,
1657 struct drm_connector_state *conn_state)
1659 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
1660 struct intel_hdmi *intel_hdmi = &dport->hdmi;
1661 struct drm_device *dev = encoder->base.dev;
1662 struct drm_i915_private *dev_priv = to_i915(dev);
1663 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
1665 vlv_phy_pre_encoder_enable(encoder);
1668 vlv_set_phy_signal_level(encoder, 0x2b245f5f, 0x00002000, 0x5578b83a,
1671 intel_hdmi->set_infoframes(&encoder->base,
1672 pipe_config->has_hdmi_sink,
1675 g4x_enable_hdmi(encoder, pipe_config, conn_state);
1677 vlv_wait_port_ready(dev_priv, dport, 0x0);
1680 static void vlv_hdmi_pre_pll_enable(struct intel_encoder *encoder,
1681 struct intel_crtc_state *pipe_config,
1682 struct drm_connector_state *conn_state)
1684 intel_hdmi_prepare(encoder);
1686 vlv_phy_pre_pll_enable(encoder);
1689 static void chv_hdmi_pre_pll_enable(struct intel_encoder *encoder,
1690 struct intel_crtc_state *pipe_config,
1691 struct drm_connector_state *conn_state)
1693 intel_hdmi_prepare(encoder);
1695 chv_phy_pre_pll_enable(encoder);
1698 static void chv_hdmi_post_pll_disable(struct intel_encoder *encoder,
1699 struct intel_crtc_state *old_crtc_state,
1700 struct drm_connector_state *old_conn_state)
1702 chv_phy_post_pll_disable(encoder);
1705 static void vlv_hdmi_post_disable(struct intel_encoder *encoder,
1706 struct intel_crtc_state *old_crtc_state,
1707 struct drm_connector_state *old_conn_state)
1709 /* Reset lanes to avoid HDMI flicker (VLV w/a) */
1710 vlv_phy_reset_lanes(encoder);
1713 static void chv_hdmi_post_disable(struct intel_encoder *encoder,
1714 struct intel_crtc_state *old_crtc_state,
1715 struct drm_connector_state *old_conn_state)
1717 struct drm_device *dev = encoder->base.dev;
1718 struct drm_i915_private *dev_priv = to_i915(dev);
1720 mutex_lock(&dev_priv->sb_lock);
1722 /* Assert data lane reset */
1723 chv_data_lane_soft_reset(encoder, true);
1725 mutex_unlock(&dev_priv->sb_lock);
1728 static void chv_hdmi_pre_enable(struct intel_encoder *encoder,
1729 struct intel_crtc_state *pipe_config,
1730 struct drm_connector_state *conn_state)
1732 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
1733 struct intel_hdmi *intel_hdmi = &dport->hdmi;
1734 struct drm_device *dev = encoder->base.dev;
1735 struct drm_i915_private *dev_priv = to_i915(dev);
1736 struct intel_crtc *intel_crtc =
1737 to_intel_crtc(encoder->base.crtc);
1738 const struct drm_display_mode *adjusted_mode = &intel_crtc->config->base.adjusted_mode;
1740 chv_phy_pre_encoder_enable(encoder);
1742 /* FIXME: Program the support xxx V-dB */
1744 chv_set_phy_signal_level(encoder, 128, 102, false);
1746 intel_hdmi->set_infoframes(&encoder->base,
1747 intel_crtc->config->has_hdmi_sink,
1750 g4x_enable_hdmi(encoder, pipe_config, conn_state);
1752 vlv_wait_port_ready(dev_priv, dport, 0x0);
1754 /* Second common lane will stay alive on its own now */
1755 chv_phy_release_cl2_override(encoder);
1758 static void intel_hdmi_destroy(struct drm_connector *connector)
1760 kfree(to_intel_connector(connector)->detect_edid);
1761 drm_connector_cleanup(connector);
1765 static const struct drm_connector_funcs intel_hdmi_connector_funcs = {
1766 .dpms = drm_atomic_helper_connector_dpms,
1767 .detect = intel_hdmi_detect,
1768 .force = intel_hdmi_force,
1769 .fill_modes = drm_helper_probe_single_connector_modes,
1770 .set_property = intel_hdmi_set_property,
1771 .atomic_get_property = intel_connector_atomic_get_property,
1772 .late_register = intel_connector_register,
1773 .early_unregister = intel_connector_unregister,
1774 .destroy = intel_hdmi_destroy,
1775 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
1776 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
1779 static const struct drm_connector_helper_funcs intel_hdmi_connector_helper_funcs = {
1780 .get_modes = intel_hdmi_get_modes,
1781 .mode_valid = intel_hdmi_mode_valid,
1784 static const struct drm_encoder_funcs intel_hdmi_enc_funcs = {
1785 .destroy = intel_encoder_destroy,
1789 intel_hdmi_add_properties(struct intel_hdmi *intel_hdmi, struct drm_connector *connector)
1791 intel_attach_force_audio_property(connector);
1792 intel_attach_broadcast_rgb_property(connector);
1793 intel_hdmi->color_range_auto = true;
1794 intel_attach_aspect_ratio_property(connector);
1795 intel_hdmi->aspect_ratio = HDMI_PICTURE_ASPECT_NONE;
1798 static u8 intel_hdmi_ddc_pin(struct drm_i915_private *dev_priv,
1801 const struct ddi_vbt_port_info *info =
1802 &dev_priv->vbt.ddi_port_info[port];
1805 if (info->alternate_ddc_pin) {
1806 DRM_DEBUG_KMS("Using DDC pin 0x%x for port %c (VBT)\n",
1807 info->alternate_ddc_pin, port_name(port));
1808 return info->alternate_ddc_pin;
1813 if (IS_BROXTON(dev_priv))
1814 ddc_pin = GMBUS_PIN_1_BXT;
1816 ddc_pin = GMBUS_PIN_DPB;
1819 if (IS_BROXTON(dev_priv))
1820 ddc_pin = GMBUS_PIN_2_BXT;
1822 ddc_pin = GMBUS_PIN_DPC;
1825 if (IS_CHERRYVIEW(dev_priv))
1826 ddc_pin = GMBUS_PIN_DPD_CHV;
1828 ddc_pin = GMBUS_PIN_DPD;
1832 ddc_pin = GMBUS_PIN_DPB;
1836 DRM_DEBUG_KMS("Using DDC pin 0x%x for port %c (platform default)\n",
1837 ddc_pin, port_name(port));
1842 void intel_hdmi_init_connector(struct intel_digital_port *intel_dig_port,
1843 struct intel_connector *intel_connector)
1845 struct drm_connector *connector = &intel_connector->base;
1846 struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
1847 struct intel_encoder *intel_encoder = &intel_dig_port->base;
1848 struct drm_device *dev = intel_encoder->base.dev;
1849 struct drm_i915_private *dev_priv = to_i915(dev);
1850 enum port port = intel_dig_port->port;
1852 DRM_DEBUG_KMS("Adding HDMI connector on port %c\n",
1855 if (WARN(intel_dig_port->max_lanes < 4,
1856 "Not enough lanes (%d) for HDMI on port %c\n",
1857 intel_dig_port->max_lanes, port_name(port)))
1860 drm_connector_init(dev, connector, &intel_hdmi_connector_funcs,
1861 DRM_MODE_CONNECTOR_HDMIA);
1862 drm_connector_helper_add(connector, &intel_hdmi_connector_helper_funcs);
1864 connector->interlace_allowed = 1;
1865 connector->doublescan_allowed = 0;
1866 connector->stereo_allowed = 1;
1868 intel_hdmi->ddc_bus = intel_hdmi_ddc_pin(dev_priv, port);
1873 * On BXT A0/A1, sw needs to activate DDIA HPD logic and
1874 * interrupts to check the external panel connection.
1876 if (IS_BXT_REVID(dev_priv, 0, BXT_REVID_A1))
1877 intel_encoder->hpd_pin = HPD_PORT_A;
1879 intel_encoder->hpd_pin = HPD_PORT_B;
1882 intel_encoder->hpd_pin = HPD_PORT_C;
1885 intel_encoder->hpd_pin = HPD_PORT_D;
1888 intel_encoder->hpd_pin = HPD_PORT_E;
1895 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
1896 intel_hdmi->write_infoframe = vlv_write_infoframe;
1897 intel_hdmi->set_infoframes = vlv_set_infoframes;
1898 intel_hdmi->infoframe_enabled = vlv_infoframe_enabled;
1899 } else if (IS_G4X(dev_priv)) {
1900 intel_hdmi->write_infoframe = g4x_write_infoframe;
1901 intel_hdmi->set_infoframes = g4x_set_infoframes;
1902 intel_hdmi->infoframe_enabled = g4x_infoframe_enabled;
1903 } else if (HAS_DDI(dev_priv)) {
1904 intel_hdmi->write_infoframe = hsw_write_infoframe;
1905 intel_hdmi->set_infoframes = hsw_set_infoframes;
1906 intel_hdmi->infoframe_enabled = hsw_infoframe_enabled;
1907 } else if (HAS_PCH_IBX(dev_priv)) {
1908 intel_hdmi->write_infoframe = ibx_write_infoframe;
1909 intel_hdmi->set_infoframes = ibx_set_infoframes;
1910 intel_hdmi->infoframe_enabled = ibx_infoframe_enabled;
1912 intel_hdmi->write_infoframe = cpt_write_infoframe;
1913 intel_hdmi->set_infoframes = cpt_set_infoframes;
1914 intel_hdmi->infoframe_enabled = cpt_infoframe_enabled;
1917 if (HAS_DDI(dev_priv))
1918 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
1920 intel_connector->get_hw_state = intel_connector_get_hw_state;
1922 intel_hdmi_add_properties(intel_hdmi, connector);
1924 intel_connector_attach_encoder(intel_connector, intel_encoder);
1925 intel_hdmi->attached_connector = intel_connector;
1927 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
1928 * 0xd. Failure to do so will result in spurious interrupts being
1929 * generated on the port when a cable is not attached.
1931 if (IS_G4X(dev_priv) && !IS_GM45(dev_priv)) {
1932 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
1933 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
1937 void intel_hdmi_init(struct drm_device *dev,
1938 i915_reg_t hdmi_reg, enum port port)
1940 struct drm_i915_private *dev_priv = to_i915(dev);
1941 struct intel_digital_port *intel_dig_port;
1942 struct intel_encoder *intel_encoder;
1943 struct intel_connector *intel_connector;
1945 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
1946 if (!intel_dig_port)
1949 intel_connector = intel_connector_alloc();
1950 if (!intel_connector) {
1951 kfree(intel_dig_port);
1955 intel_encoder = &intel_dig_port->base;
1957 drm_encoder_init(dev, &intel_encoder->base, &intel_hdmi_enc_funcs,
1958 DRM_MODE_ENCODER_TMDS, "HDMI %c", port_name(port));
1960 intel_encoder->compute_config = intel_hdmi_compute_config;
1961 if (HAS_PCH_SPLIT(dev_priv)) {
1962 intel_encoder->disable = pch_disable_hdmi;
1963 intel_encoder->post_disable = pch_post_disable_hdmi;
1965 intel_encoder->disable = g4x_disable_hdmi;
1967 intel_encoder->get_hw_state = intel_hdmi_get_hw_state;
1968 intel_encoder->get_config = intel_hdmi_get_config;
1969 if (IS_CHERRYVIEW(dev_priv)) {
1970 intel_encoder->pre_pll_enable = chv_hdmi_pre_pll_enable;
1971 intel_encoder->pre_enable = chv_hdmi_pre_enable;
1972 intel_encoder->enable = vlv_enable_hdmi;
1973 intel_encoder->post_disable = chv_hdmi_post_disable;
1974 intel_encoder->post_pll_disable = chv_hdmi_post_pll_disable;
1975 } else if (IS_VALLEYVIEW(dev_priv)) {
1976 intel_encoder->pre_pll_enable = vlv_hdmi_pre_pll_enable;
1977 intel_encoder->pre_enable = vlv_hdmi_pre_enable;
1978 intel_encoder->enable = vlv_enable_hdmi;
1979 intel_encoder->post_disable = vlv_hdmi_post_disable;
1981 intel_encoder->pre_enable = intel_hdmi_pre_enable;
1982 if (HAS_PCH_CPT(dev_priv))
1983 intel_encoder->enable = cpt_enable_hdmi;
1984 else if (HAS_PCH_IBX(dev_priv))
1985 intel_encoder->enable = ibx_enable_hdmi;
1987 intel_encoder->enable = g4x_enable_hdmi;
1990 intel_encoder->type = INTEL_OUTPUT_HDMI;
1991 intel_encoder->port = port;
1992 if (IS_CHERRYVIEW(dev_priv)) {
1994 intel_encoder->crtc_mask = 1 << 2;
1996 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
1998 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
2000 intel_encoder->cloneable = 1 << INTEL_OUTPUT_ANALOG;
2002 * BSpec is unclear about HDMI+HDMI cloning on g4x, but it seems
2003 * to work on real hardware. And since g4x can send infoframes to
2004 * only one port anyway, nothing is lost by allowing it.
2006 if (IS_G4X(dev_priv))
2007 intel_encoder->cloneable |= 1 << INTEL_OUTPUT_HDMI;
2009 intel_dig_port->port = port;
2010 intel_dig_port->hdmi.hdmi_reg = hdmi_reg;
2011 intel_dig_port->dp.output_reg = INVALID_MMIO_REG;
2012 intel_dig_port->max_lanes = 4;
2014 intel_hdmi_init_connector(intel_dig_port, intel_connector);