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 <drm/drm_scdc_helper.h>
38 #include "intel_drv.h"
39 #include <drm/i915_drm.h>
40 #include <drm/intel_lpe_audio.h>
43 static struct drm_device *intel_hdmi_to_dev(struct intel_hdmi *intel_hdmi)
45 return hdmi_to_dig_port(intel_hdmi)->base.base.dev;
49 assert_hdmi_port_disabled(struct intel_hdmi *intel_hdmi)
51 struct drm_device *dev = intel_hdmi_to_dev(intel_hdmi);
52 struct drm_i915_private *dev_priv = to_i915(dev);
53 uint32_t enabled_bits;
55 enabled_bits = HAS_DDI(dev_priv) ? DDI_BUF_CTL_ENABLE : SDVO_ENABLE;
57 WARN(I915_READ(intel_hdmi->hdmi_reg) & enabled_bits,
58 "HDMI port enabled, expecting disabled\n");
61 struct intel_hdmi *enc_to_intel_hdmi(struct drm_encoder *encoder)
63 struct intel_digital_port *intel_dig_port =
64 container_of(encoder, struct intel_digital_port, base.base);
65 return &intel_dig_port->hdmi;
68 static struct intel_hdmi *intel_attached_hdmi(struct drm_connector *connector)
70 return enc_to_intel_hdmi(&intel_attached_encoder(connector)->base);
73 static u32 g4x_infoframe_index(unsigned int type)
76 case HDMI_INFOFRAME_TYPE_AVI:
77 return VIDEO_DIP_SELECT_AVI;
78 case HDMI_INFOFRAME_TYPE_SPD:
79 return VIDEO_DIP_SELECT_SPD;
80 case HDMI_INFOFRAME_TYPE_VENDOR:
81 return VIDEO_DIP_SELECT_VENDOR;
88 static u32 g4x_infoframe_enable(unsigned int type)
91 case HDMI_INFOFRAME_TYPE_AVI:
92 return VIDEO_DIP_ENABLE_AVI;
93 case HDMI_INFOFRAME_TYPE_SPD:
94 return VIDEO_DIP_ENABLE_SPD;
95 case HDMI_INFOFRAME_TYPE_VENDOR:
96 return VIDEO_DIP_ENABLE_VENDOR;
103 static u32 hsw_infoframe_enable(unsigned int type)
107 return VIDEO_DIP_ENABLE_VSC_HSW;
108 case HDMI_INFOFRAME_TYPE_AVI:
109 return VIDEO_DIP_ENABLE_AVI_HSW;
110 case HDMI_INFOFRAME_TYPE_SPD:
111 return VIDEO_DIP_ENABLE_SPD_HSW;
112 case HDMI_INFOFRAME_TYPE_VENDOR:
113 return VIDEO_DIP_ENABLE_VS_HSW;
121 hsw_dip_data_reg(struct drm_i915_private *dev_priv,
122 enum transcoder cpu_transcoder,
128 return HSW_TVIDEO_DIP_VSC_DATA(cpu_transcoder, i);
129 case HDMI_INFOFRAME_TYPE_AVI:
130 return HSW_TVIDEO_DIP_AVI_DATA(cpu_transcoder, i);
131 case HDMI_INFOFRAME_TYPE_SPD:
132 return HSW_TVIDEO_DIP_SPD_DATA(cpu_transcoder, i);
133 case HDMI_INFOFRAME_TYPE_VENDOR:
134 return HSW_TVIDEO_DIP_VS_DATA(cpu_transcoder, i);
137 return INVALID_MMIO_REG;
141 static void g4x_write_infoframe(struct drm_encoder *encoder,
142 const struct intel_crtc_state *crtc_state,
144 const void *frame, ssize_t len)
146 const uint32_t *data = frame;
147 struct drm_device *dev = encoder->dev;
148 struct drm_i915_private *dev_priv = to_i915(dev);
149 u32 val = I915_READ(VIDEO_DIP_CTL);
152 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
154 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
155 val |= g4x_infoframe_index(type);
157 val &= ~g4x_infoframe_enable(type);
159 I915_WRITE(VIDEO_DIP_CTL, val);
162 for (i = 0; i < len; i += 4) {
163 I915_WRITE(VIDEO_DIP_DATA, *data);
166 /* Write every possible data byte to force correct ECC calculation. */
167 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
168 I915_WRITE(VIDEO_DIP_DATA, 0);
171 val |= g4x_infoframe_enable(type);
172 val &= ~VIDEO_DIP_FREQ_MASK;
173 val |= VIDEO_DIP_FREQ_VSYNC;
175 I915_WRITE(VIDEO_DIP_CTL, val);
176 POSTING_READ(VIDEO_DIP_CTL);
179 static bool g4x_infoframe_enabled(struct drm_encoder *encoder,
180 const struct intel_crtc_state *pipe_config)
182 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
183 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
184 u32 val = I915_READ(VIDEO_DIP_CTL);
186 if ((val & VIDEO_DIP_ENABLE) == 0)
189 if ((val & VIDEO_DIP_PORT_MASK) != VIDEO_DIP_PORT(intel_dig_port->port))
192 return val & (VIDEO_DIP_ENABLE_AVI |
193 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_SPD);
196 static void ibx_write_infoframe(struct drm_encoder *encoder,
197 const struct intel_crtc_state *crtc_state,
199 const void *frame, ssize_t len)
201 const uint32_t *data = frame;
202 struct drm_device *dev = encoder->dev;
203 struct drm_i915_private *dev_priv = to_i915(dev);
204 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
205 i915_reg_t reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
206 u32 val = I915_READ(reg);
209 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
211 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
212 val |= g4x_infoframe_index(type);
214 val &= ~g4x_infoframe_enable(type);
216 I915_WRITE(reg, val);
219 for (i = 0; i < len; i += 4) {
220 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
223 /* Write every possible data byte to force correct ECC calculation. */
224 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
225 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), 0);
228 val |= g4x_infoframe_enable(type);
229 val &= ~VIDEO_DIP_FREQ_MASK;
230 val |= VIDEO_DIP_FREQ_VSYNC;
232 I915_WRITE(reg, val);
236 static bool ibx_infoframe_enabled(struct drm_encoder *encoder,
237 const struct intel_crtc_state *pipe_config)
239 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
240 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
241 enum pipe pipe = to_intel_crtc(pipe_config->base.crtc)->pipe;
242 i915_reg_t reg = TVIDEO_DIP_CTL(pipe);
243 u32 val = I915_READ(reg);
245 if ((val & VIDEO_DIP_ENABLE) == 0)
248 if ((val & VIDEO_DIP_PORT_MASK) != VIDEO_DIP_PORT(intel_dig_port->port))
251 return val & (VIDEO_DIP_ENABLE_AVI |
252 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
253 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
256 static void cpt_write_infoframe(struct drm_encoder *encoder,
257 const struct intel_crtc_state *crtc_state,
259 const void *frame, ssize_t len)
261 const uint32_t *data = frame;
262 struct drm_device *dev = encoder->dev;
263 struct drm_i915_private *dev_priv = to_i915(dev);
264 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
265 i915_reg_t reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
266 u32 val = I915_READ(reg);
269 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
271 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
272 val |= g4x_infoframe_index(type);
274 /* The DIP control register spec says that we need to update the AVI
275 * infoframe without clearing its enable bit */
276 if (type != HDMI_INFOFRAME_TYPE_AVI)
277 val &= ~g4x_infoframe_enable(type);
279 I915_WRITE(reg, val);
282 for (i = 0; i < len; i += 4) {
283 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
286 /* Write every possible data byte to force correct ECC calculation. */
287 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
288 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), 0);
291 val |= g4x_infoframe_enable(type);
292 val &= ~VIDEO_DIP_FREQ_MASK;
293 val |= VIDEO_DIP_FREQ_VSYNC;
295 I915_WRITE(reg, val);
299 static bool cpt_infoframe_enabled(struct drm_encoder *encoder,
300 const struct intel_crtc_state *pipe_config)
302 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
303 enum pipe pipe = to_intel_crtc(pipe_config->base.crtc)->pipe;
304 u32 val = I915_READ(TVIDEO_DIP_CTL(pipe));
306 if ((val & VIDEO_DIP_ENABLE) == 0)
309 return val & (VIDEO_DIP_ENABLE_AVI |
310 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
311 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
314 static void vlv_write_infoframe(struct drm_encoder *encoder,
315 const struct intel_crtc_state *crtc_state,
317 const void *frame, ssize_t len)
319 const uint32_t *data = frame;
320 struct drm_device *dev = encoder->dev;
321 struct drm_i915_private *dev_priv = to_i915(dev);
322 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
323 i915_reg_t reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
324 u32 val = I915_READ(reg);
327 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
329 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
330 val |= g4x_infoframe_index(type);
332 val &= ~g4x_infoframe_enable(type);
334 I915_WRITE(reg, val);
337 for (i = 0; i < len; i += 4) {
338 I915_WRITE(VLV_TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
341 /* Write every possible data byte to force correct ECC calculation. */
342 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
343 I915_WRITE(VLV_TVIDEO_DIP_DATA(intel_crtc->pipe), 0);
346 val |= g4x_infoframe_enable(type);
347 val &= ~VIDEO_DIP_FREQ_MASK;
348 val |= VIDEO_DIP_FREQ_VSYNC;
350 I915_WRITE(reg, val);
354 static bool vlv_infoframe_enabled(struct drm_encoder *encoder,
355 const struct intel_crtc_state *pipe_config)
357 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
358 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
359 enum pipe pipe = to_intel_crtc(pipe_config->base.crtc)->pipe;
360 u32 val = I915_READ(VLV_TVIDEO_DIP_CTL(pipe));
362 if ((val & VIDEO_DIP_ENABLE) == 0)
365 if ((val & VIDEO_DIP_PORT_MASK) != VIDEO_DIP_PORT(intel_dig_port->port))
368 return val & (VIDEO_DIP_ENABLE_AVI |
369 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
370 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
373 static void hsw_write_infoframe(struct drm_encoder *encoder,
374 const struct intel_crtc_state *crtc_state,
376 const void *frame, ssize_t len)
378 const uint32_t *data = frame;
379 struct drm_device *dev = encoder->dev;
380 struct drm_i915_private *dev_priv = to_i915(dev);
381 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
382 i915_reg_t ctl_reg = HSW_TVIDEO_DIP_CTL(cpu_transcoder);
384 int data_size = type == DP_SDP_VSC ?
385 VIDEO_DIP_VSC_DATA_SIZE : VIDEO_DIP_DATA_SIZE;
387 u32 val = I915_READ(ctl_reg);
389 data_reg = hsw_dip_data_reg(dev_priv, cpu_transcoder, type, 0);
391 val &= ~hsw_infoframe_enable(type);
392 I915_WRITE(ctl_reg, val);
395 for (i = 0; i < len; i += 4) {
396 I915_WRITE(hsw_dip_data_reg(dev_priv, cpu_transcoder,
397 type, i >> 2), *data);
400 /* Write every possible data byte to force correct ECC calculation. */
401 for (; i < data_size; i += 4)
402 I915_WRITE(hsw_dip_data_reg(dev_priv, cpu_transcoder,
406 val |= hsw_infoframe_enable(type);
407 I915_WRITE(ctl_reg, val);
408 POSTING_READ(ctl_reg);
411 static bool hsw_infoframe_enabled(struct drm_encoder *encoder,
412 const struct intel_crtc_state *pipe_config)
414 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
415 u32 val = I915_READ(HSW_TVIDEO_DIP_CTL(pipe_config->cpu_transcoder));
417 return val & (VIDEO_DIP_ENABLE_VSC_HSW | VIDEO_DIP_ENABLE_AVI_HSW |
418 VIDEO_DIP_ENABLE_GCP_HSW | VIDEO_DIP_ENABLE_VS_HSW |
419 VIDEO_DIP_ENABLE_GMP_HSW | VIDEO_DIP_ENABLE_SPD_HSW);
423 * The data we write to the DIP data buffer registers is 1 byte bigger than the
424 * HDMI infoframe size because of an ECC/reserved byte at position 3 (starting
425 * at 0). It's also a byte used by DisplayPort so the same DIP registers can be
426 * used for both technologies.
428 * DW0: Reserved/ECC/DP | HB2 | HB1 | HB0
429 * DW1: DB3 | DB2 | DB1 | DB0
430 * DW2: DB7 | DB6 | DB5 | DB4
433 * (HB is Header Byte, DB is Data Byte)
435 * The hdmi pack() functions don't know about that hardware specific hole so we
436 * trick them by giving an offset into the buffer and moving back the header
439 static void intel_write_infoframe(struct drm_encoder *encoder,
440 const struct intel_crtc_state *crtc_state,
441 union hdmi_infoframe *frame)
443 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
444 uint8_t buffer[VIDEO_DIP_DATA_SIZE];
447 /* see comment above for the reason for this offset */
448 len = hdmi_infoframe_pack(frame, buffer + 1, sizeof(buffer) - 1);
452 /* Insert the 'hole' (see big comment above) at position 3 */
453 buffer[0] = buffer[1];
454 buffer[1] = buffer[2];
455 buffer[2] = buffer[3];
459 intel_dig_port->write_infoframe(encoder, crtc_state, frame->any.type, buffer, len);
462 static void intel_hdmi_set_avi_infoframe(struct drm_encoder *encoder,
463 const struct intel_crtc_state *crtc_state)
465 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
466 const struct drm_display_mode *adjusted_mode =
467 &crtc_state->base.adjusted_mode;
468 struct drm_connector *connector = &intel_hdmi->attached_connector->base;
469 bool is_hdmi2_sink = connector->display_info.hdmi.scdc.supported;
470 union hdmi_infoframe frame;
473 ret = drm_hdmi_avi_infoframe_from_display_mode(&frame.avi,
477 DRM_ERROR("couldn't fill AVI infoframe\n");
481 if (crtc_state->ycbcr420)
482 frame.avi.colorspace = HDMI_COLORSPACE_YUV420;
484 frame.avi.colorspace = HDMI_COLORSPACE_RGB;
486 drm_hdmi_avi_infoframe_quant_range(&frame.avi, adjusted_mode,
487 crtc_state->limited_color_range ?
488 HDMI_QUANTIZATION_RANGE_LIMITED :
489 HDMI_QUANTIZATION_RANGE_FULL,
490 intel_hdmi->rgb_quant_range_selectable);
492 /* TODO: handle pixel repetition for YCBCR420 outputs */
493 intel_write_infoframe(encoder, crtc_state, &frame);
496 static void intel_hdmi_set_spd_infoframe(struct drm_encoder *encoder,
497 const struct intel_crtc_state *crtc_state)
499 union hdmi_infoframe frame;
502 ret = hdmi_spd_infoframe_init(&frame.spd, "Intel", "Integrated gfx");
504 DRM_ERROR("couldn't fill SPD infoframe\n");
508 frame.spd.sdi = HDMI_SPD_SDI_PC;
510 intel_write_infoframe(encoder, crtc_state, &frame);
514 intel_hdmi_set_hdmi_infoframe(struct drm_encoder *encoder,
515 const struct intel_crtc_state *crtc_state,
516 const struct drm_connector_state *conn_state)
518 union hdmi_infoframe frame;
521 ret = drm_hdmi_vendor_infoframe_from_display_mode(&frame.vendor.hdmi,
522 conn_state->connector,
523 &crtc_state->base.adjusted_mode);
527 intel_write_infoframe(encoder, crtc_state, &frame);
530 static void g4x_set_infoframes(struct drm_encoder *encoder,
532 const struct intel_crtc_state *crtc_state,
533 const struct drm_connector_state *conn_state)
535 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
536 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
537 struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
538 i915_reg_t reg = VIDEO_DIP_CTL;
539 u32 val = I915_READ(reg);
540 u32 port = VIDEO_DIP_PORT(intel_dig_port->port);
542 assert_hdmi_port_disabled(intel_hdmi);
544 /* If the registers were not initialized yet, they might be zeroes,
545 * which means we're selecting the AVI DIP and we're setting its
546 * frequency to once. This seems to really confuse the HW and make
547 * things stop working (the register spec says the AVI always needs to
548 * be sent every VSync). So here we avoid writing to the register more
549 * than we need and also explicitly select the AVI DIP and explicitly
550 * set its frequency to every VSync. Avoiding to write it twice seems to
551 * be enough to solve the problem, but being defensive shouldn't hurt us
553 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
556 if (!(val & VIDEO_DIP_ENABLE))
558 if (port != (val & VIDEO_DIP_PORT_MASK)) {
559 DRM_DEBUG_KMS("video DIP still enabled on port %c\n",
560 (val & VIDEO_DIP_PORT_MASK) >> 29);
563 val &= ~(VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI |
564 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_SPD);
565 I915_WRITE(reg, val);
570 if (port != (val & VIDEO_DIP_PORT_MASK)) {
571 if (val & VIDEO_DIP_ENABLE) {
572 DRM_DEBUG_KMS("video DIP already enabled on port %c\n",
573 (val & VIDEO_DIP_PORT_MASK) >> 29);
576 val &= ~VIDEO_DIP_PORT_MASK;
580 val |= VIDEO_DIP_ENABLE;
581 val &= ~(VIDEO_DIP_ENABLE_AVI |
582 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_SPD);
584 I915_WRITE(reg, val);
587 intel_hdmi_set_avi_infoframe(encoder, crtc_state);
588 intel_hdmi_set_spd_infoframe(encoder, crtc_state);
589 intel_hdmi_set_hdmi_infoframe(encoder, crtc_state, conn_state);
592 static bool hdmi_sink_is_deep_color(const struct drm_connector_state *conn_state)
594 struct drm_connector *connector = conn_state->connector;
597 * HDMI cloning is only supported on g4x which doesn't
598 * support deep color or GCP infoframes anyway so no
599 * need to worry about multiple HDMI sinks here.
602 return connector->display_info.bpc > 8;
606 * Determine if default_phase=1 can be indicated in the GCP infoframe.
608 * From HDMI specification 1.4a:
609 * - The first pixel of each Video Data Period shall always have a pixel packing phase of 0
610 * - The first pixel following each Video Data Period shall have a pixel packing phase of 0
611 * - The PP bits shall be constant for all GCPs and will be equal to the last packing phase
612 * - The first pixel following every transition of HSYNC or VSYNC shall have a pixel packing
615 static bool gcp_default_phase_possible(int pipe_bpp,
616 const struct drm_display_mode *mode)
618 unsigned int pixels_per_group;
622 /* 4 pixels in 5 clocks */
623 pixels_per_group = 4;
626 /* 2 pixels in 3 clocks */
627 pixels_per_group = 2;
630 /* 1 pixel in 2 clocks */
631 pixels_per_group = 1;
634 /* phase information not relevant for 8bpc */
638 return mode->crtc_hdisplay % pixels_per_group == 0 &&
639 mode->crtc_htotal % pixels_per_group == 0 &&
640 mode->crtc_hblank_start % pixels_per_group == 0 &&
641 mode->crtc_hblank_end % pixels_per_group == 0 &&
642 mode->crtc_hsync_start % pixels_per_group == 0 &&
643 mode->crtc_hsync_end % pixels_per_group == 0 &&
644 ((mode->flags & DRM_MODE_FLAG_INTERLACE) == 0 ||
645 mode->crtc_htotal/2 % pixels_per_group == 0);
648 static bool intel_hdmi_set_gcp_infoframe(struct drm_encoder *encoder,
649 const struct intel_crtc_state *crtc_state,
650 const struct drm_connector_state *conn_state)
652 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
653 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
657 if (HAS_DDI(dev_priv))
658 reg = HSW_TVIDEO_DIP_GCP(crtc_state->cpu_transcoder);
659 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
660 reg = VLV_TVIDEO_DIP_GCP(crtc->pipe);
661 else if (HAS_PCH_SPLIT(dev_priv))
662 reg = TVIDEO_DIP_GCP(crtc->pipe);
666 /* Indicate color depth whenever the sink supports deep color */
667 if (hdmi_sink_is_deep_color(conn_state))
668 val |= GCP_COLOR_INDICATION;
670 /* Enable default_phase whenever the display mode is suitably aligned */
671 if (gcp_default_phase_possible(crtc_state->pipe_bpp,
672 &crtc_state->base.adjusted_mode))
673 val |= GCP_DEFAULT_PHASE_ENABLE;
675 I915_WRITE(reg, val);
680 static void ibx_set_infoframes(struct drm_encoder *encoder,
682 const struct intel_crtc_state *crtc_state,
683 const struct drm_connector_state *conn_state)
685 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
686 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
687 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
688 struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
689 i915_reg_t reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
690 u32 val = I915_READ(reg);
691 u32 port = VIDEO_DIP_PORT(intel_dig_port->port);
693 assert_hdmi_port_disabled(intel_hdmi);
695 /* See the big comment in g4x_set_infoframes() */
696 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
699 if (!(val & VIDEO_DIP_ENABLE))
701 val &= ~(VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI |
702 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
703 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
704 I915_WRITE(reg, val);
709 if (port != (val & VIDEO_DIP_PORT_MASK)) {
710 WARN(val & VIDEO_DIP_ENABLE,
711 "DIP already enabled on port %c\n",
712 (val & VIDEO_DIP_PORT_MASK) >> 29);
713 val &= ~VIDEO_DIP_PORT_MASK;
717 val |= VIDEO_DIP_ENABLE;
718 val &= ~(VIDEO_DIP_ENABLE_AVI |
719 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
720 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
722 if (intel_hdmi_set_gcp_infoframe(encoder, crtc_state, conn_state))
723 val |= VIDEO_DIP_ENABLE_GCP;
725 I915_WRITE(reg, val);
728 intel_hdmi_set_avi_infoframe(encoder, crtc_state);
729 intel_hdmi_set_spd_infoframe(encoder, crtc_state);
730 intel_hdmi_set_hdmi_infoframe(encoder, crtc_state, conn_state);
733 static void cpt_set_infoframes(struct drm_encoder *encoder,
735 const struct intel_crtc_state *crtc_state,
736 const struct drm_connector_state *conn_state)
738 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
739 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
740 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
741 i915_reg_t reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
742 u32 val = I915_READ(reg);
744 assert_hdmi_port_disabled(intel_hdmi);
746 /* See the big comment in g4x_set_infoframes() */
747 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
750 if (!(val & VIDEO_DIP_ENABLE))
752 val &= ~(VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI |
753 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
754 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
755 I915_WRITE(reg, val);
760 /* Set both together, unset both together: see the spec. */
761 val |= VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI;
762 val &= ~(VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
763 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
765 if (intel_hdmi_set_gcp_infoframe(encoder, crtc_state, conn_state))
766 val |= VIDEO_DIP_ENABLE_GCP;
768 I915_WRITE(reg, val);
771 intel_hdmi_set_avi_infoframe(encoder, crtc_state);
772 intel_hdmi_set_spd_infoframe(encoder, crtc_state);
773 intel_hdmi_set_hdmi_infoframe(encoder, crtc_state, conn_state);
776 static void vlv_set_infoframes(struct drm_encoder *encoder,
778 const struct intel_crtc_state *crtc_state,
779 const struct drm_connector_state *conn_state)
781 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
782 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
783 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
784 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
785 i915_reg_t reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
786 u32 val = I915_READ(reg);
787 u32 port = VIDEO_DIP_PORT(intel_dig_port->port);
789 assert_hdmi_port_disabled(intel_hdmi);
791 /* See the big comment in g4x_set_infoframes() */
792 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
795 if (!(val & VIDEO_DIP_ENABLE))
797 val &= ~(VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI |
798 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
799 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
800 I915_WRITE(reg, val);
805 if (port != (val & VIDEO_DIP_PORT_MASK)) {
806 WARN(val & VIDEO_DIP_ENABLE,
807 "DIP already enabled on port %c\n",
808 (val & VIDEO_DIP_PORT_MASK) >> 29);
809 val &= ~VIDEO_DIP_PORT_MASK;
813 val |= VIDEO_DIP_ENABLE;
814 val &= ~(VIDEO_DIP_ENABLE_AVI |
815 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
816 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
818 if (intel_hdmi_set_gcp_infoframe(encoder, crtc_state, conn_state))
819 val |= VIDEO_DIP_ENABLE_GCP;
821 I915_WRITE(reg, val);
824 intel_hdmi_set_avi_infoframe(encoder, crtc_state);
825 intel_hdmi_set_spd_infoframe(encoder, crtc_state);
826 intel_hdmi_set_hdmi_infoframe(encoder, crtc_state, conn_state);
829 static void hsw_set_infoframes(struct drm_encoder *encoder,
831 const struct intel_crtc_state *crtc_state,
832 const struct drm_connector_state *conn_state)
834 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
835 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
836 i915_reg_t reg = HSW_TVIDEO_DIP_CTL(crtc_state->cpu_transcoder);
837 u32 val = I915_READ(reg);
839 assert_hdmi_port_disabled(intel_hdmi);
841 val &= ~(VIDEO_DIP_ENABLE_VSC_HSW | VIDEO_DIP_ENABLE_AVI_HSW |
842 VIDEO_DIP_ENABLE_GCP_HSW | VIDEO_DIP_ENABLE_VS_HSW |
843 VIDEO_DIP_ENABLE_GMP_HSW | VIDEO_DIP_ENABLE_SPD_HSW);
846 I915_WRITE(reg, val);
851 if (intel_hdmi_set_gcp_infoframe(encoder, crtc_state, conn_state))
852 val |= VIDEO_DIP_ENABLE_GCP_HSW;
854 I915_WRITE(reg, val);
857 intel_hdmi_set_avi_infoframe(encoder, crtc_state);
858 intel_hdmi_set_spd_infoframe(encoder, crtc_state);
859 intel_hdmi_set_hdmi_infoframe(encoder, crtc_state, conn_state);
862 void intel_dp_dual_mode_set_tmds_output(struct intel_hdmi *hdmi, bool enable)
864 struct drm_i915_private *dev_priv = to_i915(intel_hdmi_to_dev(hdmi));
865 struct i2c_adapter *adapter =
866 intel_gmbus_get_adapter(dev_priv, hdmi->ddc_bus);
868 if (hdmi->dp_dual_mode.type < DRM_DP_DUAL_MODE_TYPE2_DVI)
871 DRM_DEBUG_KMS("%s DP dual mode adaptor TMDS output\n",
872 enable ? "Enabling" : "Disabling");
874 drm_dp_dual_mode_set_tmds_output(hdmi->dp_dual_mode.type,
878 static void intel_hdmi_prepare(struct intel_encoder *encoder,
879 const struct intel_crtc_state *crtc_state)
881 struct drm_device *dev = encoder->base.dev;
882 struct drm_i915_private *dev_priv = to_i915(dev);
883 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
884 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
885 const struct drm_display_mode *adjusted_mode = &crtc_state->base.adjusted_mode;
888 intel_dp_dual_mode_set_tmds_output(intel_hdmi, true);
890 hdmi_val = SDVO_ENCODING_HDMI;
891 if (!HAS_PCH_SPLIT(dev_priv) && crtc_state->limited_color_range)
892 hdmi_val |= HDMI_COLOR_RANGE_16_235;
893 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
894 hdmi_val |= SDVO_VSYNC_ACTIVE_HIGH;
895 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
896 hdmi_val |= SDVO_HSYNC_ACTIVE_HIGH;
898 if (crtc_state->pipe_bpp > 24)
899 hdmi_val |= HDMI_COLOR_FORMAT_12bpc;
901 hdmi_val |= SDVO_COLOR_FORMAT_8bpc;
903 if (crtc_state->has_hdmi_sink)
904 hdmi_val |= HDMI_MODE_SELECT_HDMI;
906 if (HAS_PCH_CPT(dev_priv))
907 hdmi_val |= SDVO_PIPE_SEL_CPT(crtc->pipe);
908 else if (IS_CHERRYVIEW(dev_priv))
909 hdmi_val |= SDVO_PIPE_SEL_CHV(crtc->pipe);
911 hdmi_val |= SDVO_PIPE_SEL(crtc->pipe);
913 I915_WRITE(intel_hdmi->hdmi_reg, hdmi_val);
914 POSTING_READ(intel_hdmi->hdmi_reg);
917 static bool intel_hdmi_get_hw_state(struct intel_encoder *encoder,
920 struct drm_device *dev = encoder->base.dev;
921 struct drm_i915_private *dev_priv = to_i915(dev);
922 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
926 if (!intel_display_power_get_if_enabled(dev_priv,
927 encoder->power_domain))
932 tmp = I915_READ(intel_hdmi->hdmi_reg);
934 if (!(tmp & SDVO_ENABLE))
937 if (HAS_PCH_CPT(dev_priv))
938 *pipe = PORT_TO_PIPE_CPT(tmp);
939 else if (IS_CHERRYVIEW(dev_priv))
940 *pipe = SDVO_PORT_TO_PIPE_CHV(tmp);
942 *pipe = PORT_TO_PIPE(tmp);
947 intel_display_power_put(dev_priv, encoder->power_domain);
952 static void intel_hdmi_get_config(struct intel_encoder *encoder,
953 struct intel_crtc_state *pipe_config)
955 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
956 struct intel_digital_port *intel_dig_port = hdmi_to_dig_port(intel_hdmi);
957 struct drm_device *dev = encoder->base.dev;
958 struct drm_i915_private *dev_priv = to_i915(dev);
962 tmp = I915_READ(intel_hdmi->hdmi_reg);
964 if (tmp & SDVO_HSYNC_ACTIVE_HIGH)
965 flags |= DRM_MODE_FLAG_PHSYNC;
967 flags |= DRM_MODE_FLAG_NHSYNC;
969 if (tmp & SDVO_VSYNC_ACTIVE_HIGH)
970 flags |= DRM_MODE_FLAG_PVSYNC;
972 flags |= DRM_MODE_FLAG_NVSYNC;
974 if (tmp & HDMI_MODE_SELECT_HDMI)
975 pipe_config->has_hdmi_sink = true;
977 if (intel_dig_port->infoframe_enabled(&encoder->base, pipe_config))
978 pipe_config->has_infoframe = true;
980 if (tmp & SDVO_AUDIO_ENABLE)
981 pipe_config->has_audio = true;
983 if (!HAS_PCH_SPLIT(dev_priv) &&
984 tmp & HDMI_COLOR_RANGE_16_235)
985 pipe_config->limited_color_range = true;
987 pipe_config->base.adjusted_mode.flags |= flags;
989 if ((tmp & SDVO_COLOR_FORMAT_MASK) == HDMI_COLOR_FORMAT_12bpc)
990 dotclock = pipe_config->port_clock * 2 / 3;
992 dotclock = pipe_config->port_clock;
994 if (pipe_config->pixel_multiplier)
995 dotclock /= pipe_config->pixel_multiplier;
997 pipe_config->base.adjusted_mode.crtc_clock = dotclock;
999 pipe_config->lane_count = 4;
1002 static void intel_enable_hdmi_audio(struct intel_encoder *encoder,
1003 const struct intel_crtc_state *pipe_config,
1004 const struct drm_connector_state *conn_state)
1006 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
1008 WARN_ON(!pipe_config->has_hdmi_sink);
1009 DRM_DEBUG_DRIVER("Enabling HDMI audio on pipe %c\n",
1010 pipe_name(crtc->pipe));
1011 intel_audio_codec_enable(encoder, pipe_config, conn_state);
1014 static void g4x_enable_hdmi(struct intel_encoder *encoder,
1015 const struct intel_crtc_state *pipe_config,
1016 const struct drm_connector_state *conn_state)
1018 struct drm_device *dev = encoder->base.dev;
1019 struct drm_i915_private *dev_priv = to_i915(dev);
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 (pipe_config->has_audio)
1027 temp |= SDVO_AUDIO_ENABLE;
1029 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1030 POSTING_READ(intel_hdmi->hdmi_reg);
1032 if (pipe_config->has_audio)
1033 intel_enable_hdmi_audio(encoder, pipe_config, conn_state);
1036 static void ibx_enable_hdmi(struct intel_encoder *encoder,
1037 const struct intel_crtc_state *pipe_config,
1038 const struct drm_connector_state *conn_state)
1040 struct drm_device *dev = encoder->base.dev;
1041 struct drm_i915_private *dev_priv = to_i915(dev);
1042 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
1045 temp = I915_READ(intel_hdmi->hdmi_reg);
1047 temp |= SDVO_ENABLE;
1048 if (pipe_config->has_audio)
1049 temp |= SDVO_AUDIO_ENABLE;
1052 * HW workaround, need to write this twice for issue
1053 * that may result in first write getting masked.
1055 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1056 POSTING_READ(intel_hdmi->hdmi_reg);
1057 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1058 POSTING_READ(intel_hdmi->hdmi_reg);
1061 * HW workaround, need to toggle enable bit off and on
1062 * for 12bpc with pixel repeat.
1064 * FIXME: BSpec says this should be done at the end of
1065 * of the modeset sequence, so not sure if this isn't too soon.
1067 if (pipe_config->pipe_bpp > 24 &&
1068 pipe_config->pixel_multiplier > 1) {
1069 I915_WRITE(intel_hdmi->hdmi_reg, temp & ~SDVO_ENABLE);
1070 POSTING_READ(intel_hdmi->hdmi_reg);
1073 * HW workaround, need to write this twice for issue
1074 * that may result in first write getting masked.
1076 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1077 POSTING_READ(intel_hdmi->hdmi_reg);
1078 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1079 POSTING_READ(intel_hdmi->hdmi_reg);
1082 if (pipe_config->has_audio)
1083 intel_enable_hdmi_audio(encoder, pipe_config, conn_state);
1086 static void cpt_enable_hdmi(struct intel_encoder *encoder,
1087 const struct intel_crtc_state *pipe_config,
1088 const struct drm_connector_state *conn_state)
1090 struct drm_device *dev = encoder->base.dev;
1091 struct drm_i915_private *dev_priv = to_i915(dev);
1092 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
1093 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
1094 enum pipe pipe = crtc->pipe;
1097 temp = I915_READ(intel_hdmi->hdmi_reg);
1099 temp |= SDVO_ENABLE;
1100 if (pipe_config->has_audio)
1101 temp |= SDVO_AUDIO_ENABLE;
1104 * WaEnableHDMI8bpcBefore12bpc:snb,ivb
1106 * The procedure for 12bpc is as follows:
1107 * 1. disable HDMI clock gating
1108 * 2. enable HDMI with 8bpc
1109 * 3. enable HDMI with 12bpc
1110 * 4. enable HDMI clock gating
1113 if (pipe_config->pipe_bpp > 24) {
1114 I915_WRITE(TRANS_CHICKEN1(pipe),
1115 I915_READ(TRANS_CHICKEN1(pipe)) |
1116 TRANS_CHICKEN1_HDMIUNIT_GC_DISABLE);
1118 temp &= ~SDVO_COLOR_FORMAT_MASK;
1119 temp |= SDVO_COLOR_FORMAT_8bpc;
1122 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1123 POSTING_READ(intel_hdmi->hdmi_reg);
1125 if (pipe_config->pipe_bpp > 24) {
1126 temp &= ~SDVO_COLOR_FORMAT_MASK;
1127 temp |= HDMI_COLOR_FORMAT_12bpc;
1129 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1130 POSTING_READ(intel_hdmi->hdmi_reg);
1132 I915_WRITE(TRANS_CHICKEN1(pipe),
1133 I915_READ(TRANS_CHICKEN1(pipe)) &
1134 ~TRANS_CHICKEN1_HDMIUNIT_GC_DISABLE);
1137 if (pipe_config->has_audio)
1138 intel_enable_hdmi_audio(encoder, pipe_config, conn_state);
1141 static void vlv_enable_hdmi(struct intel_encoder *encoder,
1142 const struct intel_crtc_state *pipe_config,
1143 const struct drm_connector_state *conn_state)
1147 static void intel_disable_hdmi(struct intel_encoder *encoder,
1148 const struct intel_crtc_state *old_crtc_state,
1149 const struct drm_connector_state *old_conn_state)
1151 struct drm_device *dev = encoder->base.dev;
1152 struct drm_i915_private *dev_priv = to_i915(dev);
1153 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
1154 struct intel_digital_port *intel_dig_port =
1155 hdmi_to_dig_port(intel_hdmi);
1156 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
1159 temp = I915_READ(intel_hdmi->hdmi_reg);
1161 temp &= ~(SDVO_ENABLE | SDVO_AUDIO_ENABLE);
1162 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1163 POSTING_READ(intel_hdmi->hdmi_reg);
1166 * HW workaround for IBX, we need to move the port
1167 * to transcoder A after disabling it to allow the
1168 * matching DP port to be enabled on transcoder A.
1170 if (HAS_PCH_IBX(dev_priv) && crtc->pipe == PIPE_B) {
1172 * We get CPU/PCH FIFO underruns on the other pipe when
1173 * doing the workaround. Sweep them under the rug.
1175 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
1176 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
1178 temp &= ~SDVO_PIPE_B_SELECT;
1179 temp |= SDVO_ENABLE;
1181 * HW workaround, need to write this twice for issue
1182 * that may result in first write getting masked.
1184 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1185 POSTING_READ(intel_hdmi->hdmi_reg);
1186 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1187 POSTING_READ(intel_hdmi->hdmi_reg);
1189 temp &= ~SDVO_ENABLE;
1190 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1191 POSTING_READ(intel_hdmi->hdmi_reg);
1193 intel_wait_for_vblank_if_active(dev_priv, PIPE_A);
1194 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
1195 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
1198 intel_dig_port->set_infoframes(&encoder->base, false,
1199 old_crtc_state, old_conn_state);
1201 intel_dp_dual_mode_set_tmds_output(intel_hdmi, false);
1204 static void g4x_disable_hdmi(struct intel_encoder *encoder,
1205 const struct intel_crtc_state *old_crtc_state,
1206 const struct drm_connector_state *old_conn_state)
1208 if (old_crtc_state->has_audio)
1209 intel_audio_codec_disable(encoder);
1211 intel_disable_hdmi(encoder, old_crtc_state, old_conn_state);
1214 static void pch_disable_hdmi(struct intel_encoder *encoder,
1215 const struct intel_crtc_state *old_crtc_state,
1216 const struct drm_connector_state *old_conn_state)
1218 if (old_crtc_state->has_audio)
1219 intel_audio_codec_disable(encoder);
1222 static void pch_post_disable_hdmi(struct intel_encoder *encoder,
1223 const struct intel_crtc_state *old_crtc_state,
1224 const struct drm_connector_state *old_conn_state)
1226 intel_disable_hdmi(encoder, old_crtc_state, old_conn_state);
1229 static int intel_hdmi_source_max_tmds_clock(struct drm_i915_private *dev_priv)
1231 if (IS_G4X(dev_priv))
1233 else if (IS_GEMINILAKE(dev_priv))
1235 else if (IS_HASWELL(dev_priv) || INTEL_INFO(dev_priv)->gen >= 8)
1241 static int hdmi_port_clock_limit(struct intel_hdmi *hdmi,
1242 bool respect_downstream_limits,
1245 struct drm_device *dev = intel_hdmi_to_dev(hdmi);
1246 int max_tmds_clock = intel_hdmi_source_max_tmds_clock(to_i915(dev));
1248 if (respect_downstream_limits) {
1249 struct intel_connector *connector = hdmi->attached_connector;
1250 const struct drm_display_info *info = &connector->base.display_info;
1252 if (hdmi->dp_dual_mode.max_tmds_clock)
1253 max_tmds_clock = min(max_tmds_clock,
1254 hdmi->dp_dual_mode.max_tmds_clock);
1256 if (info->max_tmds_clock)
1257 max_tmds_clock = min(max_tmds_clock,
1258 info->max_tmds_clock);
1259 else if (!hdmi->has_hdmi_sink || force_dvi)
1260 max_tmds_clock = min(max_tmds_clock, 165000);
1263 return max_tmds_clock;
1266 static enum drm_mode_status
1267 hdmi_port_clock_valid(struct intel_hdmi *hdmi,
1268 int clock, bool respect_downstream_limits,
1271 struct drm_i915_private *dev_priv = to_i915(intel_hdmi_to_dev(hdmi));
1274 return MODE_CLOCK_LOW;
1275 if (clock > hdmi_port_clock_limit(hdmi, respect_downstream_limits, force_dvi))
1276 return MODE_CLOCK_HIGH;
1278 /* BXT DPLL can't generate 223-240 MHz */
1279 if (IS_GEN9_LP(dev_priv) && clock > 223333 && clock < 240000)
1280 return MODE_CLOCK_RANGE;
1282 /* CHV DPLL can't generate 216-240 MHz */
1283 if (IS_CHERRYVIEW(dev_priv) && clock > 216000 && clock < 240000)
1284 return MODE_CLOCK_RANGE;
1289 static enum drm_mode_status
1290 intel_hdmi_mode_valid(struct drm_connector *connector,
1291 struct drm_display_mode *mode)
1293 struct intel_hdmi *hdmi = intel_attached_hdmi(connector);
1294 struct drm_device *dev = intel_hdmi_to_dev(hdmi);
1295 struct drm_i915_private *dev_priv = to_i915(dev);
1296 enum drm_mode_status status;
1298 int max_dotclk = to_i915(connector->dev)->max_dotclk_freq;
1300 READ_ONCE(to_intel_digital_connector_state(connector->state)->force_audio) == HDMI_AUDIO_OFF_DVI;
1302 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
1303 return MODE_NO_DBLESCAN;
1305 clock = mode->clock;
1307 if ((mode->flags & DRM_MODE_FLAG_3D_MASK) == DRM_MODE_FLAG_3D_FRAME_PACKING)
1310 if (clock > max_dotclk)
1311 return MODE_CLOCK_HIGH;
1313 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
1316 if (drm_mode_is_420_only(&connector->display_info, mode))
1319 /* check if we can do 8bpc */
1320 status = hdmi_port_clock_valid(hdmi, clock, true, force_dvi);
1322 /* if we can't do 8bpc we may still be able to do 12bpc */
1323 if (!HAS_GMCH_DISPLAY(dev_priv) && status != MODE_OK && hdmi->has_hdmi_sink && !force_dvi)
1324 status = hdmi_port_clock_valid(hdmi, clock * 3 / 2, true, force_dvi);
1329 static bool hdmi_12bpc_possible(const struct intel_crtc_state *crtc_state)
1331 struct drm_i915_private *dev_priv =
1332 to_i915(crtc_state->base.crtc->dev);
1333 struct drm_atomic_state *state = crtc_state->base.state;
1334 struct drm_connector_state *connector_state;
1335 struct drm_connector *connector;
1338 if (HAS_GMCH_DISPLAY(dev_priv))
1342 * HDMI 12bpc affects the clocks, so it's only possible
1343 * when not cloning with other encoder types.
1345 if (crtc_state->output_types != 1 << INTEL_OUTPUT_HDMI)
1348 for_each_new_connector_in_state(state, connector, connector_state, i) {
1349 const struct drm_display_info *info = &connector->display_info;
1351 if (connector_state->crtc != crtc_state->base.crtc)
1354 if (crtc_state->ycbcr420) {
1355 const struct drm_hdmi_info *hdmi = &info->hdmi;
1357 if (!(hdmi->y420_dc_modes & DRM_EDID_YCBCR420_DC_36))
1360 if (!(info->edid_hdmi_dc_modes & DRM_EDID_HDMI_DC_36))
1365 /* Display Wa #1139 */
1366 if (IS_GLK_REVID(dev_priv, 0, GLK_REVID_A1) &&
1367 crtc_state->base.adjusted_mode.htotal > 5460)
1374 intel_hdmi_ycbcr420_config(struct drm_connector *connector,
1375 struct intel_crtc_state *config,
1376 int *clock_12bpc, int *clock_8bpc)
1378 struct intel_crtc *intel_crtc = to_intel_crtc(config->base.crtc);
1380 if (!connector->ycbcr_420_allowed) {
1381 DRM_ERROR("Platform doesn't support YCBCR420 output\n");
1385 /* YCBCR420 TMDS rate requirement is half the pixel clock */
1386 config->port_clock /= 2;
1389 config->ycbcr420 = true;
1391 /* YCBCR 420 output conversion needs a scaler */
1392 if (skl_update_scaler_crtc(config)) {
1393 DRM_DEBUG_KMS("Scaler allocation for output failed\n");
1397 intel_pch_panel_fitting(intel_crtc, config,
1398 DRM_MODE_SCALE_FULLSCREEN);
1403 bool intel_hdmi_compute_config(struct intel_encoder *encoder,
1404 struct intel_crtc_state *pipe_config,
1405 struct drm_connector_state *conn_state)
1407 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
1408 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1409 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
1410 struct drm_connector *connector = conn_state->connector;
1411 struct drm_scdc *scdc = &connector->display_info.hdmi.scdc;
1412 struct intel_digital_connector_state *intel_conn_state =
1413 to_intel_digital_connector_state(conn_state);
1414 int clock_8bpc = pipe_config->base.adjusted_mode.crtc_clock;
1415 int clock_12bpc = clock_8bpc * 3 / 2;
1417 bool force_dvi = intel_conn_state->force_audio == HDMI_AUDIO_OFF_DVI;
1419 pipe_config->has_hdmi_sink = !force_dvi && intel_hdmi->has_hdmi_sink;
1421 if (pipe_config->has_hdmi_sink)
1422 pipe_config->has_infoframe = true;
1424 if (intel_conn_state->broadcast_rgb == INTEL_BROADCAST_RGB_AUTO) {
1425 /* See CEA-861-E - 5.1 Default Encoding Parameters */
1426 pipe_config->limited_color_range =
1427 pipe_config->has_hdmi_sink &&
1428 drm_default_rgb_quant_range(adjusted_mode) ==
1429 HDMI_QUANTIZATION_RANGE_LIMITED;
1431 pipe_config->limited_color_range =
1432 intel_conn_state->broadcast_rgb == INTEL_BROADCAST_RGB_LIMITED;
1435 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK) {
1436 pipe_config->pixel_multiplier = 2;
1441 if (drm_mode_is_420_only(&connector->display_info, adjusted_mode)) {
1442 if (!intel_hdmi_ycbcr420_config(connector, pipe_config,
1443 &clock_12bpc, &clock_8bpc)) {
1444 DRM_ERROR("Can't support YCBCR420 output\n");
1449 if (HAS_PCH_SPLIT(dev_priv) && !HAS_DDI(dev_priv))
1450 pipe_config->has_pch_encoder = true;
1452 if (pipe_config->has_hdmi_sink) {
1453 if (intel_conn_state->force_audio == HDMI_AUDIO_AUTO)
1454 pipe_config->has_audio = intel_hdmi->has_audio;
1456 pipe_config->has_audio =
1457 intel_conn_state->force_audio == HDMI_AUDIO_ON;
1461 * HDMI is either 12 or 8, so if the display lets 10bpc sneak
1462 * through, clamp it down. Note that g4x/vlv don't support 12bpc hdmi
1463 * outputs. We also need to check that the higher clock still fits
1466 if (pipe_config->pipe_bpp > 8*3 && pipe_config->has_hdmi_sink && !force_dvi &&
1467 hdmi_port_clock_valid(intel_hdmi, clock_12bpc, true, force_dvi) == MODE_OK &&
1468 hdmi_12bpc_possible(pipe_config)) {
1469 DRM_DEBUG_KMS("picking bpc to 12 for HDMI output\n");
1472 /* Need to adjust the port link by 1.5x for 12bpc. */
1473 pipe_config->port_clock = clock_12bpc;
1475 DRM_DEBUG_KMS("picking bpc to 8 for HDMI output\n");
1478 pipe_config->port_clock = clock_8bpc;
1481 if (!pipe_config->bw_constrained) {
1482 DRM_DEBUG_KMS("forcing pipe bpp to %i for HDMI\n", desired_bpp);
1483 pipe_config->pipe_bpp = desired_bpp;
1486 if (hdmi_port_clock_valid(intel_hdmi, pipe_config->port_clock,
1487 false, force_dvi) != MODE_OK) {
1488 DRM_DEBUG_KMS("unsupported HDMI clock, rejecting mode\n");
1492 /* Set user selected PAR to incoming mode's member */
1493 adjusted_mode->picture_aspect_ratio = conn_state->picture_aspect_ratio;
1495 pipe_config->lane_count = 4;
1497 if (scdc->scrambling.supported && IS_GEMINILAKE(dev_priv)) {
1498 if (scdc->scrambling.low_rates)
1499 pipe_config->hdmi_scrambling = true;
1501 if (pipe_config->port_clock > 340000) {
1502 pipe_config->hdmi_scrambling = true;
1503 pipe_config->hdmi_high_tmds_clock_ratio = true;
1511 intel_hdmi_unset_edid(struct drm_connector *connector)
1513 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
1515 intel_hdmi->has_hdmi_sink = false;
1516 intel_hdmi->has_audio = false;
1517 intel_hdmi->rgb_quant_range_selectable = false;
1519 intel_hdmi->dp_dual_mode.type = DRM_DP_DUAL_MODE_NONE;
1520 intel_hdmi->dp_dual_mode.max_tmds_clock = 0;
1522 kfree(to_intel_connector(connector)->detect_edid);
1523 to_intel_connector(connector)->detect_edid = NULL;
1527 intel_hdmi_dp_dual_mode_detect(struct drm_connector *connector, bool has_edid)
1529 struct drm_i915_private *dev_priv = to_i915(connector->dev);
1530 struct intel_hdmi *hdmi = intel_attached_hdmi(connector);
1531 enum port port = hdmi_to_dig_port(hdmi)->port;
1532 struct i2c_adapter *adapter =
1533 intel_gmbus_get_adapter(dev_priv, hdmi->ddc_bus);
1534 enum drm_dp_dual_mode_type type = drm_dp_dual_mode_detect(adapter);
1537 * Type 1 DVI adaptors are not required to implement any
1538 * registers, so we can't always detect their presence.
1539 * Ideally we should be able to check the state of the
1540 * CONFIG1 pin, but no such luck on our hardware.
1542 * The only method left to us is to check the VBT to see
1543 * if the port is a dual mode capable DP port. But let's
1544 * only do that when we sucesfully read the EDID, to avoid
1545 * confusing log messages about DP dual mode adaptors when
1546 * there's nothing connected to the port.
1548 if (type == DRM_DP_DUAL_MODE_UNKNOWN) {
1550 intel_bios_is_port_dp_dual_mode(dev_priv, port)) {
1551 DRM_DEBUG_KMS("Assuming DP dual mode adaptor presence based on VBT\n");
1552 type = DRM_DP_DUAL_MODE_TYPE1_DVI;
1554 type = DRM_DP_DUAL_MODE_NONE;
1558 if (type == DRM_DP_DUAL_MODE_NONE)
1561 hdmi->dp_dual_mode.type = type;
1562 hdmi->dp_dual_mode.max_tmds_clock =
1563 drm_dp_dual_mode_max_tmds_clock(type, adapter);
1565 DRM_DEBUG_KMS("DP dual mode adaptor (%s) detected (max TMDS clock: %d kHz)\n",
1566 drm_dp_get_dual_mode_type_name(type),
1567 hdmi->dp_dual_mode.max_tmds_clock);
1571 intel_hdmi_set_edid(struct drm_connector *connector)
1573 struct drm_i915_private *dev_priv = to_i915(connector->dev);
1574 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
1576 bool connected = false;
1578 intel_display_power_get(dev_priv, POWER_DOMAIN_GMBUS);
1580 edid = drm_get_edid(connector,
1581 intel_gmbus_get_adapter(dev_priv,
1582 intel_hdmi->ddc_bus));
1584 intel_hdmi_dp_dual_mode_detect(connector, edid != NULL);
1586 intel_display_power_put(dev_priv, POWER_DOMAIN_GMBUS);
1588 to_intel_connector(connector)->detect_edid = edid;
1589 if (edid && edid->input & DRM_EDID_INPUT_DIGITAL) {
1590 intel_hdmi->rgb_quant_range_selectable =
1591 drm_rgb_quant_range_selectable(edid);
1593 intel_hdmi->has_audio = drm_detect_monitor_audio(edid);
1594 intel_hdmi->has_hdmi_sink = drm_detect_hdmi_monitor(edid);
1602 static enum drm_connector_status
1603 intel_hdmi_detect(struct drm_connector *connector, bool force)
1605 enum drm_connector_status status;
1606 struct drm_i915_private *dev_priv = to_i915(connector->dev);
1608 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
1609 connector->base.id, connector->name);
1611 intel_display_power_get(dev_priv, POWER_DOMAIN_GMBUS);
1613 intel_hdmi_unset_edid(connector);
1615 if (intel_hdmi_set_edid(connector)) {
1616 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
1618 hdmi_to_dig_port(intel_hdmi)->base.type = INTEL_OUTPUT_HDMI;
1619 status = connector_status_connected;
1621 status = connector_status_disconnected;
1623 intel_display_power_put(dev_priv, POWER_DOMAIN_GMBUS);
1629 intel_hdmi_force(struct drm_connector *connector)
1631 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
1633 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
1634 connector->base.id, connector->name);
1636 intel_hdmi_unset_edid(connector);
1638 if (connector->status != connector_status_connected)
1641 intel_hdmi_set_edid(connector);
1642 hdmi_to_dig_port(intel_hdmi)->base.type = INTEL_OUTPUT_HDMI;
1645 static int intel_hdmi_get_modes(struct drm_connector *connector)
1649 edid = to_intel_connector(connector)->detect_edid;
1653 return intel_connector_update_modes(connector, edid);
1656 static void intel_hdmi_pre_enable(struct intel_encoder *encoder,
1657 const struct intel_crtc_state *pipe_config,
1658 const struct drm_connector_state *conn_state)
1660 struct intel_digital_port *intel_dig_port =
1661 enc_to_dig_port(&encoder->base);
1663 intel_hdmi_prepare(encoder, pipe_config);
1665 intel_dig_port->set_infoframes(&encoder->base,
1666 pipe_config->has_infoframe,
1667 pipe_config, conn_state);
1670 static void vlv_hdmi_pre_enable(struct intel_encoder *encoder,
1671 const struct intel_crtc_state *pipe_config,
1672 const struct drm_connector_state *conn_state)
1674 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
1675 struct drm_device *dev = encoder->base.dev;
1676 struct drm_i915_private *dev_priv = to_i915(dev);
1678 vlv_phy_pre_encoder_enable(encoder);
1681 vlv_set_phy_signal_level(encoder, 0x2b245f5f, 0x00002000, 0x5578b83a,
1684 dport->set_infoframes(&encoder->base,
1685 pipe_config->has_infoframe,
1686 pipe_config, conn_state);
1688 g4x_enable_hdmi(encoder, pipe_config, conn_state);
1690 vlv_wait_port_ready(dev_priv, dport, 0x0);
1693 static void vlv_hdmi_pre_pll_enable(struct intel_encoder *encoder,
1694 const struct intel_crtc_state *pipe_config,
1695 const struct drm_connector_state *conn_state)
1697 intel_hdmi_prepare(encoder, pipe_config);
1699 vlv_phy_pre_pll_enable(encoder);
1702 static void chv_hdmi_pre_pll_enable(struct intel_encoder *encoder,
1703 const struct intel_crtc_state *pipe_config,
1704 const struct drm_connector_state *conn_state)
1706 intel_hdmi_prepare(encoder, pipe_config);
1708 chv_phy_pre_pll_enable(encoder);
1711 static void chv_hdmi_post_pll_disable(struct intel_encoder *encoder,
1712 const struct intel_crtc_state *old_crtc_state,
1713 const struct drm_connector_state *old_conn_state)
1715 chv_phy_post_pll_disable(encoder);
1718 static void vlv_hdmi_post_disable(struct intel_encoder *encoder,
1719 const struct intel_crtc_state *old_crtc_state,
1720 const struct drm_connector_state *old_conn_state)
1722 /* Reset lanes to avoid HDMI flicker (VLV w/a) */
1723 vlv_phy_reset_lanes(encoder);
1726 static void chv_hdmi_post_disable(struct intel_encoder *encoder,
1727 const struct intel_crtc_state *old_crtc_state,
1728 const struct drm_connector_state *old_conn_state)
1730 struct drm_device *dev = encoder->base.dev;
1731 struct drm_i915_private *dev_priv = to_i915(dev);
1733 mutex_lock(&dev_priv->sb_lock);
1735 /* Assert data lane reset */
1736 chv_data_lane_soft_reset(encoder, true);
1738 mutex_unlock(&dev_priv->sb_lock);
1741 static void chv_hdmi_pre_enable(struct intel_encoder *encoder,
1742 const struct intel_crtc_state *pipe_config,
1743 const struct drm_connector_state *conn_state)
1745 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
1746 struct drm_device *dev = encoder->base.dev;
1747 struct drm_i915_private *dev_priv = to_i915(dev);
1749 chv_phy_pre_encoder_enable(encoder);
1751 /* FIXME: Program the support xxx V-dB */
1753 chv_set_phy_signal_level(encoder, 128, 102, false);
1755 dport->set_infoframes(&encoder->base,
1756 pipe_config->has_infoframe,
1757 pipe_config, conn_state);
1759 g4x_enable_hdmi(encoder, pipe_config, conn_state);
1761 vlv_wait_port_ready(dev_priv, dport, 0x0);
1763 /* Second common lane will stay alive on its own now */
1764 chv_phy_release_cl2_override(encoder);
1767 static void intel_hdmi_destroy(struct drm_connector *connector)
1769 kfree(to_intel_connector(connector)->detect_edid);
1770 drm_connector_cleanup(connector);
1774 static const struct drm_connector_funcs intel_hdmi_connector_funcs = {
1775 .detect = intel_hdmi_detect,
1776 .force = intel_hdmi_force,
1777 .fill_modes = drm_helper_probe_single_connector_modes,
1778 .atomic_get_property = intel_digital_connector_atomic_get_property,
1779 .atomic_set_property = intel_digital_connector_atomic_set_property,
1780 .late_register = intel_connector_register,
1781 .early_unregister = intel_connector_unregister,
1782 .destroy = intel_hdmi_destroy,
1783 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
1784 .atomic_duplicate_state = intel_digital_connector_duplicate_state,
1787 static const struct drm_connector_helper_funcs intel_hdmi_connector_helper_funcs = {
1788 .get_modes = intel_hdmi_get_modes,
1789 .mode_valid = intel_hdmi_mode_valid,
1790 .atomic_check = intel_digital_connector_atomic_check,
1793 static const struct drm_encoder_funcs intel_hdmi_enc_funcs = {
1794 .destroy = intel_encoder_destroy,
1798 intel_hdmi_add_properties(struct intel_hdmi *intel_hdmi, struct drm_connector *connector)
1800 intel_attach_force_audio_property(connector);
1801 intel_attach_broadcast_rgb_property(connector);
1802 intel_attach_aspect_ratio_property(connector);
1803 connector->state->picture_aspect_ratio = HDMI_PICTURE_ASPECT_NONE;
1807 * intel_hdmi_handle_sink_scrambling: handle sink scrambling/clock ratio setup
1808 * @encoder: intel_encoder
1809 * @connector: drm_connector
1810 * @high_tmds_clock_ratio = bool to indicate if the function needs to set
1811 * or reset the high tmds clock ratio for scrambling
1812 * @scrambling: bool to Indicate if the function needs to set or reset
1815 * This function handles scrambling on HDMI 2.0 capable sinks.
1816 * If required clock rate is > 340 Mhz && scrambling is supported by sink
1817 * it enables scrambling. This should be called before enabling the HDMI
1818 * 2.0 port, as the sink can choose to disable the scrambling if it doesn't
1819 * detect a scrambled clock within 100 ms.
1821 void intel_hdmi_handle_sink_scrambling(struct intel_encoder *encoder,
1822 struct drm_connector *connector,
1823 bool high_tmds_clock_ratio,
1826 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
1827 struct drm_i915_private *dev_priv = connector->dev->dev_private;
1828 struct drm_scrambling *sink_scrambling =
1829 &connector->display_info.hdmi.scdc.scrambling;
1830 struct i2c_adapter *adptr = intel_gmbus_get_adapter(dev_priv,
1831 intel_hdmi->ddc_bus);
1834 if (!sink_scrambling->supported)
1837 DRM_DEBUG_KMS("Setting sink scrambling for enc:%s connector:%s\n",
1838 encoder->base.name, connector->name);
1840 /* Set TMDS bit clock ratio to 1/40 or 1/10 */
1841 ret = drm_scdc_set_high_tmds_clock_ratio(adptr, high_tmds_clock_ratio);
1843 DRM_ERROR("Set TMDS ratio failed\n");
1847 /* Enable/disable sink scrambling */
1848 ret = drm_scdc_set_scrambling(adptr, scrambling);
1850 DRM_ERROR("Set sink scrambling failed\n");
1854 DRM_DEBUG_KMS("sink scrambling handled\n");
1857 static u8 chv_port_to_ddc_pin(struct drm_i915_private *dev_priv, enum port port)
1863 ddc_pin = GMBUS_PIN_DPB;
1866 ddc_pin = GMBUS_PIN_DPC;
1869 ddc_pin = GMBUS_PIN_DPD_CHV;
1873 ddc_pin = GMBUS_PIN_DPB;
1879 static u8 bxt_port_to_ddc_pin(struct drm_i915_private *dev_priv, enum port port)
1885 ddc_pin = GMBUS_PIN_1_BXT;
1888 ddc_pin = GMBUS_PIN_2_BXT;
1892 ddc_pin = GMBUS_PIN_1_BXT;
1898 static u8 cnp_port_to_ddc_pin(struct drm_i915_private *dev_priv,
1905 ddc_pin = GMBUS_PIN_1_BXT;
1908 ddc_pin = GMBUS_PIN_2_BXT;
1911 ddc_pin = GMBUS_PIN_4_CNP;
1915 ddc_pin = GMBUS_PIN_1_BXT;
1921 static u8 g4x_port_to_ddc_pin(struct drm_i915_private *dev_priv,
1928 ddc_pin = GMBUS_PIN_DPB;
1931 ddc_pin = GMBUS_PIN_DPC;
1934 ddc_pin = GMBUS_PIN_DPD;
1938 ddc_pin = GMBUS_PIN_DPB;
1944 static u8 intel_hdmi_ddc_pin(struct drm_i915_private *dev_priv,
1947 const struct ddi_vbt_port_info *info =
1948 &dev_priv->vbt.ddi_port_info[port];
1951 if (info->alternate_ddc_pin) {
1952 DRM_DEBUG_KMS("Using DDC pin 0x%x for port %c (VBT)\n",
1953 info->alternate_ddc_pin, port_name(port));
1954 return info->alternate_ddc_pin;
1957 if (IS_CHERRYVIEW(dev_priv))
1958 ddc_pin = chv_port_to_ddc_pin(dev_priv, port);
1959 else if (IS_GEN9_LP(dev_priv))
1960 ddc_pin = bxt_port_to_ddc_pin(dev_priv, port);
1961 else if (HAS_PCH_CNP(dev_priv))
1962 ddc_pin = cnp_port_to_ddc_pin(dev_priv, port);
1964 ddc_pin = g4x_port_to_ddc_pin(dev_priv, port);
1966 DRM_DEBUG_KMS("Using DDC pin 0x%x for port %c (platform default)\n",
1967 ddc_pin, port_name(port));
1972 void intel_infoframe_init(struct intel_digital_port *intel_dig_port)
1974 struct drm_i915_private *dev_priv =
1975 to_i915(intel_dig_port->base.base.dev);
1977 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
1978 intel_dig_port->write_infoframe = vlv_write_infoframe;
1979 intel_dig_port->set_infoframes = vlv_set_infoframes;
1980 intel_dig_port->infoframe_enabled = vlv_infoframe_enabled;
1981 } else if (IS_G4X(dev_priv)) {
1982 intel_dig_port->write_infoframe = g4x_write_infoframe;
1983 intel_dig_port->set_infoframes = g4x_set_infoframes;
1984 intel_dig_port->infoframe_enabled = g4x_infoframe_enabled;
1985 } else if (HAS_DDI(dev_priv)) {
1986 intel_dig_port->write_infoframe = hsw_write_infoframe;
1987 intel_dig_port->set_infoframes = hsw_set_infoframes;
1988 intel_dig_port->infoframe_enabled = hsw_infoframe_enabled;
1989 } else if (HAS_PCH_IBX(dev_priv)) {
1990 intel_dig_port->write_infoframe = ibx_write_infoframe;
1991 intel_dig_port->set_infoframes = ibx_set_infoframes;
1992 intel_dig_port->infoframe_enabled = ibx_infoframe_enabled;
1994 intel_dig_port->write_infoframe = cpt_write_infoframe;
1995 intel_dig_port->set_infoframes = cpt_set_infoframes;
1996 intel_dig_port->infoframe_enabled = cpt_infoframe_enabled;
2000 void intel_hdmi_init_connector(struct intel_digital_port *intel_dig_port,
2001 struct intel_connector *intel_connector)
2003 struct drm_connector *connector = &intel_connector->base;
2004 struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
2005 struct intel_encoder *intel_encoder = &intel_dig_port->base;
2006 struct drm_device *dev = intel_encoder->base.dev;
2007 struct drm_i915_private *dev_priv = to_i915(dev);
2008 enum port port = intel_dig_port->port;
2010 DRM_DEBUG_KMS("Adding HDMI connector on port %c\n",
2013 if (WARN(intel_dig_port->max_lanes < 4,
2014 "Not enough lanes (%d) for HDMI on port %c\n",
2015 intel_dig_port->max_lanes, port_name(port)))
2018 drm_connector_init(dev, connector, &intel_hdmi_connector_funcs,
2019 DRM_MODE_CONNECTOR_HDMIA);
2020 drm_connector_helper_add(connector, &intel_hdmi_connector_helper_funcs);
2022 connector->interlace_allowed = 1;
2023 connector->doublescan_allowed = 0;
2024 connector->stereo_allowed = 1;
2026 if (IS_GEMINILAKE(dev_priv))
2027 connector->ycbcr_420_allowed = true;
2029 intel_hdmi->ddc_bus = intel_hdmi_ddc_pin(dev_priv, port);
2031 if (WARN_ON(port == PORT_A))
2033 intel_encoder->hpd_pin = intel_hpd_pin(port);
2035 if (HAS_DDI(dev_priv))
2036 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
2038 intel_connector->get_hw_state = intel_connector_get_hw_state;
2040 intel_hdmi_add_properties(intel_hdmi, connector);
2042 intel_connector_attach_encoder(intel_connector, intel_encoder);
2043 intel_hdmi->attached_connector = intel_connector;
2045 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
2046 * 0xd. Failure to do so will result in spurious interrupts being
2047 * generated on the port when a cable is not attached.
2049 if (IS_G4X(dev_priv) && !IS_GM45(dev_priv)) {
2050 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
2051 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
2055 void intel_hdmi_init(struct drm_i915_private *dev_priv,
2056 i915_reg_t hdmi_reg, enum port port)
2058 struct intel_digital_port *intel_dig_port;
2059 struct intel_encoder *intel_encoder;
2060 struct intel_connector *intel_connector;
2062 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
2063 if (!intel_dig_port)
2066 intel_connector = intel_connector_alloc();
2067 if (!intel_connector) {
2068 kfree(intel_dig_port);
2072 intel_encoder = &intel_dig_port->base;
2074 drm_encoder_init(&dev_priv->drm, &intel_encoder->base,
2075 &intel_hdmi_enc_funcs, DRM_MODE_ENCODER_TMDS,
2076 "HDMI %c", port_name(port));
2078 intel_encoder->compute_config = intel_hdmi_compute_config;
2079 if (HAS_PCH_SPLIT(dev_priv)) {
2080 intel_encoder->disable = pch_disable_hdmi;
2081 intel_encoder->post_disable = pch_post_disable_hdmi;
2083 intel_encoder->disable = g4x_disable_hdmi;
2085 intel_encoder->get_hw_state = intel_hdmi_get_hw_state;
2086 intel_encoder->get_config = intel_hdmi_get_config;
2087 if (IS_CHERRYVIEW(dev_priv)) {
2088 intel_encoder->pre_pll_enable = chv_hdmi_pre_pll_enable;
2089 intel_encoder->pre_enable = chv_hdmi_pre_enable;
2090 intel_encoder->enable = vlv_enable_hdmi;
2091 intel_encoder->post_disable = chv_hdmi_post_disable;
2092 intel_encoder->post_pll_disable = chv_hdmi_post_pll_disable;
2093 } else if (IS_VALLEYVIEW(dev_priv)) {
2094 intel_encoder->pre_pll_enable = vlv_hdmi_pre_pll_enable;
2095 intel_encoder->pre_enable = vlv_hdmi_pre_enable;
2096 intel_encoder->enable = vlv_enable_hdmi;
2097 intel_encoder->post_disable = vlv_hdmi_post_disable;
2099 intel_encoder->pre_enable = intel_hdmi_pre_enable;
2100 if (HAS_PCH_CPT(dev_priv))
2101 intel_encoder->enable = cpt_enable_hdmi;
2102 else if (HAS_PCH_IBX(dev_priv))
2103 intel_encoder->enable = ibx_enable_hdmi;
2105 intel_encoder->enable = g4x_enable_hdmi;
2108 intel_encoder->type = INTEL_OUTPUT_HDMI;
2109 intel_encoder->power_domain = intel_port_to_power_domain(port);
2110 intel_encoder->port = port;
2111 if (IS_CHERRYVIEW(dev_priv)) {
2113 intel_encoder->crtc_mask = 1 << 2;
2115 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
2117 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
2119 intel_encoder->cloneable = 1 << INTEL_OUTPUT_ANALOG;
2121 * BSpec is unclear about HDMI+HDMI cloning on g4x, but it seems
2122 * to work on real hardware. And since g4x can send infoframes to
2123 * only one port anyway, nothing is lost by allowing it.
2125 if (IS_G4X(dev_priv))
2126 intel_encoder->cloneable |= 1 << INTEL_OUTPUT_HDMI;
2128 intel_dig_port->port = port;
2129 intel_dig_port->hdmi.hdmi_reg = hdmi_reg;
2130 intel_dig_port->dp.output_reg = INVALID_MMIO_REG;
2131 intel_dig_port->max_lanes = 4;
2133 intel_infoframe_init(intel_dig_port);
2135 intel_hdmi_init_connector(intel_dig_port, intel_connector);