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>
36 #include "intel_drv.h"
41 assert_hdmi_port_disabled(struct intel_hdmi
*intel_hdmi
)
43 struct drm_device
*dev
= intel_hdmi
->base
.base
.dev
;
44 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
45 uint32_t enabled_bits
;
47 enabled_bits
= IS_HASWELL(dev
) ? DDI_BUF_CTL_ENABLE
: SDVO_ENABLE
;
49 WARN(I915_READ(intel_hdmi
->sdvox_reg
) & enabled_bits
,
50 "HDMI port enabled, expecting disabled\n");
53 struct intel_hdmi
*enc_to_intel_hdmi(struct drm_encoder
*encoder
)
55 return container_of(encoder
, struct intel_hdmi
, base
.base
);
58 static struct intel_hdmi
*intel_attached_hdmi(struct drm_connector
*connector
)
60 return container_of(intel_attached_encoder(connector
),
61 struct intel_hdmi
, base
);
64 void intel_dip_infoframe_csum(struct dip_infoframe
*frame
)
66 uint8_t *data
= (uint8_t *)frame
;
73 for (i
= 0; i
< frame
->len
+ DIP_HEADER_SIZE
; i
++)
76 frame
->checksum
= 0x100 - sum
;
79 static u32
g4x_infoframe_index(struct dip_infoframe
*frame
)
81 switch (frame
->type
) {
83 return VIDEO_DIP_SELECT_AVI
;
85 return VIDEO_DIP_SELECT_SPD
;
87 DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame
->type
);
92 static u32
g4x_infoframe_enable(struct dip_infoframe
*frame
)
94 switch (frame
->type
) {
96 return VIDEO_DIP_ENABLE_AVI
;
98 return VIDEO_DIP_ENABLE_SPD
;
100 DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame
->type
);
105 static u32
hsw_infoframe_enable(struct dip_infoframe
*frame
)
107 switch (frame
->type
) {
109 return VIDEO_DIP_ENABLE_AVI_HSW
;
111 return VIDEO_DIP_ENABLE_SPD_HSW
;
113 DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame
->type
);
118 static u32
hsw_infoframe_data_reg(struct dip_infoframe
*frame
, enum pipe pipe
)
120 switch (frame
->type
) {
122 return HSW_TVIDEO_DIP_AVI_DATA(pipe
);
124 return HSW_TVIDEO_DIP_SPD_DATA(pipe
);
126 DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame
->type
);
131 static void g4x_write_infoframe(struct drm_encoder
*encoder
,
132 struct dip_infoframe
*frame
)
134 uint32_t *data
= (uint32_t *)frame
;
135 struct drm_device
*dev
= encoder
->dev
;
136 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
137 u32 val
= I915_READ(VIDEO_DIP_CTL
);
138 unsigned i
, len
= DIP_HEADER_SIZE
+ frame
->len
;
140 WARN(!(val
& VIDEO_DIP_ENABLE
), "Writing DIP with CTL reg disabled\n");
142 val
&= ~(VIDEO_DIP_SELECT_MASK
| 0xf); /* clear DIP data offset */
143 val
|= g4x_infoframe_index(frame
);
145 val
&= ~g4x_infoframe_enable(frame
);
147 I915_WRITE(VIDEO_DIP_CTL
, val
);
150 for (i
= 0; i
< len
; i
+= 4) {
151 I915_WRITE(VIDEO_DIP_DATA
, *data
);
154 /* Write every possible data byte to force correct ECC calculation. */
155 for (; i
< VIDEO_DIP_DATA_SIZE
; i
+= 4)
156 I915_WRITE(VIDEO_DIP_DATA
, 0);
159 val
|= g4x_infoframe_enable(frame
);
160 val
&= ~VIDEO_DIP_FREQ_MASK
;
161 val
|= VIDEO_DIP_FREQ_VSYNC
;
163 I915_WRITE(VIDEO_DIP_CTL
, val
);
164 POSTING_READ(VIDEO_DIP_CTL
);
167 static void ibx_write_infoframe(struct drm_encoder
*encoder
,
168 struct dip_infoframe
*frame
)
170 uint32_t *data
= (uint32_t *)frame
;
171 struct drm_device
*dev
= encoder
->dev
;
172 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
173 struct intel_crtc
*intel_crtc
= to_intel_crtc(encoder
->crtc
);
174 int reg
= TVIDEO_DIP_CTL(intel_crtc
->pipe
);
175 unsigned i
, len
= DIP_HEADER_SIZE
+ frame
->len
;
176 u32 val
= I915_READ(reg
);
178 WARN(!(val
& VIDEO_DIP_ENABLE
), "Writing DIP with CTL reg disabled\n");
180 val
&= ~(VIDEO_DIP_SELECT_MASK
| 0xf); /* clear DIP data offset */
181 val
|= g4x_infoframe_index(frame
);
183 val
&= ~g4x_infoframe_enable(frame
);
185 I915_WRITE(reg
, val
);
188 for (i
= 0; i
< len
; i
+= 4) {
189 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc
->pipe
), *data
);
192 /* Write every possible data byte to force correct ECC calculation. */
193 for (; i
< VIDEO_DIP_DATA_SIZE
; i
+= 4)
194 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc
->pipe
), 0);
197 val
|= g4x_infoframe_enable(frame
);
198 val
&= ~VIDEO_DIP_FREQ_MASK
;
199 val
|= VIDEO_DIP_FREQ_VSYNC
;
201 I915_WRITE(reg
, val
);
205 static void cpt_write_infoframe(struct drm_encoder
*encoder
,
206 struct dip_infoframe
*frame
)
208 uint32_t *data
= (uint32_t *)frame
;
209 struct drm_device
*dev
= encoder
->dev
;
210 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
211 struct intel_crtc
*intel_crtc
= to_intel_crtc(encoder
->crtc
);
212 int reg
= TVIDEO_DIP_CTL(intel_crtc
->pipe
);
213 unsigned i
, len
= DIP_HEADER_SIZE
+ frame
->len
;
214 u32 val
= I915_READ(reg
);
216 WARN(!(val
& VIDEO_DIP_ENABLE
), "Writing DIP with CTL reg disabled\n");
218 val
&= ~(VIDEO_DIP_SELECT_MASK
| 0xf); /* clear DIP data offset */
219 val
|= g4x_infoframe_index(frame
);
221 /* The DIP control register spec says that we need to update the AVI
222 * infoframe without clearing its enable bit */
223 if (frame
->type
!= DIP_TYPE_AVI
)
224 val
&= ~g4x_infoframe_enable(frame
);
226 I915_WRITE(reg
, val
);
229 for (i
= 0; i
< len
; i
+= 4) {
230 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc
->pipe
), *data
);
233 /* Write every possible data byte to force correct ECC calculation. */
234 for (; i
< VIDEO_DIP_DATA_SIZE
; i
+= 4)
235 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc
->pipe
), 0);
238 val
|= g4x_infoframe_enable(frame
);
239 val
&= ~VIDEO_DIP_FREQ_MASK
;
240 val
|= VIDEO_DIP_FREQ_VSYNC
;
242 I915_WRITE(reg
, val
);
246 static void vlv_write_infoframe(struct drm_encoder
*encoder
,
247 struct dip_infoframe
*frame
)
249 uint32_t *data
= (uint32_t *)frame
;
250 struct drm_device
*dev
= encoder
->dev
;
251 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
252 struct intel_crtc
*intel_crtc
= to_intel_crtc(encoder
->crtc
);
253 int reg
= VLV_TVIDEO_DIP_CTL(intel_crtc
->pipe
);
254 unsigned i
, len
= DIP_HEADER_SIZE
+ frame
->len
;
255 u32 val
= I915_READ(reg
);
257 WARN(!(val
& VIDEO_DIP_ENABLE
), "Writing DIP with CTL reg disabled\n");
259 val
&= ~(VIDEO_DIP_SELECT_MASK
| 0xf); /* clear DIP data offset */
260 val
|= g4x_infoframe_index(frame
);
262 val
&= ~g4x_infoframe_enable(frame
);
264 I915_WRITE(reg
, val
);
267 for (i
= 0; i
< len
; i
+= 4) {
268 I915_WRITE(VLV_TVIDEO_DIP_DATA(intel_crtc
->pipe
), *data
);
271 /* Write every possible data byte to force correct ECC calculation. */
272 for (; i
< VIDEO_DIP_DATA_SIZE
; i
+= 4)
273 I915_WRITE(VLV_TVIDEO_DIP_DATA(intel_crtc
->pipe
), 0);
276 val
|= g4x_infoframe_enable(frame
);
277 val
&= ~VIDEO_DIP_FREQ_MASK
;
278 val
|= VIDEO_DIP_FREQ_VSYNC
;
280 I915_WRITE(reg
, val
);
284 static void hsw_write_infoframe(struct drm_encoder
*encoder
,
285 struct dip_infoframe
*frame
)
287 uint32_t *data
= (uint32_t *)frame
;
288 struct drm_device
*dev
= encoder
->dev
;
289 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
290 struct intel_crtc
*intel_crtc
= to_intel_crtc(encoder
->crtc
);
291 u32 ctl_reg
= HSW_TVIDEO_DIP_CTL(intel_crtc
->pipe
);
292 u32 data_reg
= hsw_infoframe_data_reg(frame
, intel_crtc
->pipe
);
293 unsigned int i
, len
= DIP_HEADER_SIZE
+ frame
->len
;
294 u32 val
= I915_READ(ctl_reg
);
299 val
&= ~hsw_infoframe_enable(frame
);
300 I915_WRITE(ctl_reg
, val
);
303 for (i
= 0; i
< len
; i
+= 4) {
304 I915_WRITE(data_reg
+ i
, *data
);
307 /* Write every possible data byte to force correct ECC calculation. */
308 for (; i
< VIDEO_DIP_DATA_SIZE
; i
+= 4)
309 I915_WRITE(data_reg
+ i
, 0);
312 val
|= hsw_infoframe_enable(frame
);
313 I915_WRITE(ctl_reg
, val
);
314 POSTING_READ(ctl_reg
);
317 static void intel_set_infoframe(struct drm_encoder
*encoder
,
318 struct dip_infoframe
*frame
)
320 struct intel_hdmi
*intel_hdmi
= enc_to_intel_hdmi(encoder
);
322 intel_dip_infoframe_csum(frame
);
323 intel_hdmi
->write_infoframe(encoder
, frame
);
326 static void intel_hdmi_set_avi_infoframe(struct drm_encoder
*encoder
,
327 struct drm_display_mode
*adjusted_mode
)
329 struct dip_infoframe avi_if
= {
330 .type
= DIP_TYPE_AVI
,
331 .ver
= DIP_VERSION_AVI
,
335 if (adjusted_mode
->flags
& DRM_MODE_FLAG_DBLCLK
)
336 avi_if
.body
.avi
.YQ_CN_PR
|= DIP_AVI_PR_2
;
338 intel_set_infoframe(encoder
, &avi_if
);
341 static void intel_hdmi_set_spd_infoframe(struct drm_encoder
*encoder
)
343 struct dip_infoframe spd_if
;
345 memset(&spd_if
, 0, sizeof(spd_if
));
346 spd_if
.type
= DIP_TYPE_SPD
;
347 spd_if
.ver
= DIP_VERSION_SPD
;
348 spd_if
.len
= DIP_LEN_SPD
;
349 strcpy(spd_if
.body
.spd
.vn
, "Intel");
350 strcpy(spd_if
.body
.spd
.pd
, "Integrated gfx");
351 spd_if
.body
.spd
.sdi
= DIP_SPD_PC
;
353 intel_set_infoframe(encoder
, &spd_if
);
356 static void g4x_set_infoframes(struct drm_encoder
*encoder
,
357 struct drm_display_mode
*adjusted_mode
)
359 struct drm_i915_private
*dev_priv
= encoder
->dev
->dev_private
;
360 struct intel_hdmi
*intel_hdmi
= enc_to_intel_hdmi(encoder
);
361 u32 reg
= VIDEO_DIP_CTL
;
362 u32 val
= I915_READ(reg
);
365 assert_hdmi_port_disabled(intel_hdmi
);
367 /* If the registers were not initialized yet, they might be zeroes,
368 * which means we're selecting the AVI DIP and we're setting its
369 * frequency to once. This seems to really confuse the HW and make
370 * things stop working (the register spec says the AVI always needs to
371 * be sent every VSync). So here we avoid writing to the register more
372 * than we need and also explicitly select the AVI DIP and explicitly
373 * set its frequency to every VSync. Avoiding to write it twice seems to
374 * be enough to solve the problem, but being defensive shouldn't hurt us
376 val
|= VIDEO_DIP_SELECT_AVI
| VIDEO_DIP_FREQ_VSYNC
;
378 if (!intel_hdmi
->has_hdmi_sink
) {
379 if (!(val
& VIDEO_DIP_ENABLE
))
381 val
&= ~VIDEO_DIP_ENABLE
;
382 I915_WRITE(reg
, val
);
387 switch (intel_hdmi
->sdvox_reg
) {
389 port
= VIDEO_DIP_PORT_B
;
392 port
= VIDEO_DIP_PORT_C
;
398 if (port
!= (val
& VIDEO_DIP_PORT_MASK
)) {
399 if (val
& VIDEO_DIP_ENABLE
) {
400 val
&= ~VIDEO_DIP_ENABLE
;
401 I915_WRITE(reg
, val
);
404 val
&= ~VIDEO_DIP_PORT_MASK
;
408 val
|= VIDEO_DIP_ENABLE
;
409 val
&= ~VIDEO_DIP_ENABLE_VENDOR
;
411 I915_WRITE(reg
, val
);
414 intel_hdmi_set_avi_infoframe(encoder
, adjusted_mode
);
415 intel_hdmi_set_spd_infoframe(encoder
);
418 static void ibx_set_infoframes(struct drm_encoder
*encoder
,
419 struct drm_display_mode
*adjusted_mode
)
421 struct drm_i915_private
*dev_priv
= encoder
->dev
->dev_private
;
422 struct intel_crtc
*intel_crtc
= to_intel_crtc(encoder
->crtc
);
423 struct intel_hdmi
*intel_hdmi
= enc_to_intel_hdmi(encoder
);
424 u32 reg
= TVIDEO_DIP_CTL(intel_crtc
->pipe
);
425 u32 val
= I915_READ(reg
);
428 assert_hdmi_port_disabled(intel_hdmi
);
430 /* See the big comment in g4x_set_infoframes() */
431 val
|= VIDEO_DIP_SELECT_AVI
| VIDEO_DIP_FREQ_VSYNC
;
433 if (!intel_hdmi
->has_hdmi_sink
) {
434 if (!(val
& VIDEO_DIP_ENABLE
))
436 val
&= ~VIDEO_DIP_ENABLE
;
437 I915_WRITE(reg
, val
);
442 switch (intel_hdmi
->sdvox_reg
) {
444 port
= VIDEO_DIP_PORT_B
;
447 port
= VIDEO_DIP_PORT_C
;
450 port
= VIDEO_DIP_PORT_D
;
456 if (port
!= (val
& VIDEO_DIP_PORT_MASK
)) {
457 if (val
& VIDEO_DIP_ENABLE
) {
458 val
&= ~VIDEO_DIP_ENABLE
;
459 I915_WRITE(reg
, val
);
462 val
&= ~VIDEO_DIP_PORT_MASK
;
466 val
|= VIDEO_DIP_ENABLE
;
467 val
&= ~(VIDEO_DIP_ENABLE_VENDOR
| VIDEO_DIP_ENABLE_GAMUT
|
468 VIDEO_DIP_ENABLE_GCP
);
470 I915_WRITE(reg
, val
);
473 intel_hdmi_set_avi_infoframe(encoder
, adjusted_mode
);
474 intel_hdmi_set_spd_infoframe(encoder
);
477 static void cpt_set_infoframes(struct drm_encoder
*encoder
,
478 struct drm_display_mode
*adjusted_mode
)
480 struct drm_i915_private
*dev_priv
= encoder
->dev
->dev_private
;
481 struct intel_crtc
*intel_crtc
= to_intel_crtc(encoder
->crtc
);
482 struct intel_hdmi
*intel_hdmi
= enc_to_intel_hdmi(encoder
);
483 u32 reg
= TVIDEO_DIP_CTL(intel_crtc
->pipe
);
484 u32 val
= I915_READ(reg
);
486 assert_hdmi_port_disabled(intel_hdmi
);
488 /* See the big comment in g4x_set_infoframes() */
489 val
|= VIDEO_DIP_SELECT_AVI
| VIDEO_DIP_FREQ_VSYNC
;
491 if (!intel_hdmi
->has_hdmi_sink
) {
492 if (!(val
& VIDEO_DIP_ENABLE
))
494 val
&= ~(VIDEO_DIP_ENABLE
| VIDEO_DIP_ENABLE_AVI
);
495 I915_WRITE(reg
, val
);
500 /* Set both together, unset both together: see the spec. */
501 val
|= VIDEO_DIP_ENABLE
| VIDEO_DIP_ENABLE_AVI
;
502 val
&= ~(VIDEO_DIP_ENABLE_VENDOR
| VIDEO_DIP_ENABLE_GAMUT
|
503 VIDEO_DIP_ENABLE_GCP
);
505 I915_WRITE(reg
, val
);
508 intel_hdmi_set_avi_infoframe(encoder
, adjusted_mode
);
509 intel_hdmi_set_spd_infoframe(encoder
);
512 static void vlv_set_infoframes(struct drm_encoder
*encoder
,
513 struct drm_display_mode
*adjusted_mode
)
515 struct drm_i915_private
*dev_priv
= encoder
->dev
->dev_private
;
516 struct intel_crtc
*intel_crtc
= to_intel_crtc(encoder
->crtc
);
517 struct intel_hdmi
*intel_hdmi
= enc_to_intel_hdmi(encoder
);
518 u32 reg
= VLV_TVIDEO_DIP_CTL(intel_crtc
->pipe
);
519 u32 val
= I915_READ(reg
);
521 assert_hdmi_port_disabled(intel_hdmi
);
523 /* See the big comment in g4x_set_infoframes() */
524 val
|= VIDEO_DIP_SELECT_AVI
| VIDEO_DIP_FREQ_VSYNC
;
526 if (!intel_hdmi
->has_hdmi_sink
) {
527 if (!(val
& VIDEO_DIP_ENABLE
))
529 val
&= ~VIDEO_DIP_ENABLE
;
530 I915_WRITE(reg
, val
);
535 val
|= VIDEO_DIP_ENABLE
;
536 val
&= ~(VIDEO_DIP_ENABLE_VENDOR
| VIDEO_DIP_ENABLE_GAMUT
|
537 VIDEO_DIP_ENABLE_GCP
);
539 I915_WRITE(reg
, val
);
542 intel_hdmi_set_avi_infoframe(encoder
, adjusted_mode
);
543 intel_hdmi_set_spd_infoframe(encoder
);
546 static void hsw_set_infoframes(struct drm_encoder
*encoder
,
547 struct drm_display_mode
*adjusted_mode
)
549 struct drm_i915_private
*dev_priv
= encoder
->dev
->dev_private
;
550 struct intel_crtc
*intel_crtc
= to_intel_crtc(encoder
->crtc
);
551 struct intel_hdmi
*intel_hdmi
= enc_to_intel_hdmi(encoder
);
552 u32 reg
= HSW_TVIDEO_DIP_CTL(intel_crtc
->pipe
);
553 u32 val
= I915_READ(reg
);
555 assert_hdmi_port_disabled(intel_hdmi
);
557 if (!intel_hdmi
->has_hdmi_sink
) {
563 val
&= ~(VIDEO_DIP_ENABLE_VSC_HSW
| VIDEO_DIP_ENABLE_GCP_HSW
|
564 VIDEO_DIP_ENABLE_VS_HSW
| VIDEO_DIP_ENABLE_GMP_HSW
);
566 I915_WRITE(reg
, val
);
569 intel_hdmi_set_avi_infoframe(encoder
, adjusted_mode
);
570 intel_hdmi_set_spd_infoframe(encoder
);
573 static void intel_hdmi_mode_set(struct drm_encoder
*encoder
,
574 struct drm_display_mode
*mode
,
575 struct drm_display_mode
*adjusted_mode
)
577 struct drm_device
*dev
= encoder
->dev
;
578 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
579 struct intel_crtc
*intel_crtc
= to_intel_crtc(encoder
->crtc
);
580 struct intel_hdmi
*intel_hdmi
= enc_to_intel_hdmi(encoder
);
583 sdvox
= SDVO_ENCODING_HDMI
;
584 if (!HAS_PCH_SPLIT(dev
))
585 sdvox
|= intel_hdmi
->color_range
;
586 if (adjusted_mode
->flags
& DRM_MODE_FLAG_PVSYNC
)
587 sdvox
|= SDVO_VSYNC_ACTIVE_HIGH
;
588 if (adjusted_mode
->flags
& DRM_MODE_FLAG_PHSYNC
)
589 sdvox
|= SDVO_HSYNC_ACTIVE_HIGH
;
591 if (intel_crtc
->bpp
> 24)
592 sdvox
|= COLOR_FORMAT_12bpc
;
594 sdvox
|= COLOR_FORMAT_8bpc
;
596 /* Required on CPT */
597 if (intel_hdmi
->has_hdmi_sink
&& HAS_PCH_CPT(dev
))
598 sdvox
|= HDMI_MODE_SELECT
;
600 if (intel_hdmi
->has_audio
) {
601 DRM_DEBUG_DRIVER("Enabling HDMI audio on pipe %c\n",
602 pipe_name(intel_crtc
->pipe
));
603 sdvox
|= SDVO_AUDIO_ENABLE
;
604 sdvox
|= SDVO_NULL_PACKETS_DURING_VSYNC
;
605 intel_write_eld(encoder
, adjusted_mode
);
608 if (HAS_PCH_CPT(dev
))
609 sdvox
|= PORT_TRANS_SEL_CPT(intel_crtc
->pipe
);
610 else if (intel_crtc
->pipe
== PIPE_B
)
611 sdvox
|= SDVO_PIPE_B_SELECT
;
613 I915_WRITE(intel_hdmi
->sdvox_reg
, sdvox
);
614 POSTING_READ(intel_hdmi
->sdvox_reg
);
616 intel_hdmi
->set_infoframes(encoder
, adjusted_mode
);
619 static void intel_hdmi_dpms(struct drm_encoder
*encoder
, int mode
)
621 struct drm_device
*dev
= encoder
->dev
;
622 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
623 struct intel_hdmi
*intel_hdmi
= enc_to_intel_hdmi(encoder
);
625 u32 enable_bits
= SDVO_ENABLE
;
627 if (intel_hdmi
->has_audio
|| mode
!= DRM_MODE_DPMS_ON
)
628 enable_bits
|= SDVO_AUDIO_ENABLE
;
630 temp
= I915_READ(intel_hdmi
->sdvox_reg
);
632 /* HW workaround for IBX, we need to move the port to transcoder A
633 * before disabling it. */
634 if (HAS_PCH_IBX(dev
)) {
635 struct drm_crtc
*crtc
= encoder
->crtc
;
636 int pipe
= crtc
? to_intel_crtc(crtc
)->pipe
: -1;
638 if (mode
!= DRM_MODE_DPMS_ON
) {
639 if (temp
& SDVO_PIPE_B_SELECT
) {
640 temp
&= ~SDVO_PIPE_B_SELECT
;
641 I915_WRITE(intel_hdmi
->sdvox_reg
, temp
);
642 POSTING_READ(intel_hdmi
->sdvox_reg
);
644 /* Again we need to write this twice. */
645 I915_WRITE(intel_hdmi
->sdvox_reg
, temp
);
646 POSTING_READ(intel_hdmi
->sdvox_reg
);
648 /* Transcoder selection bits only update
649 * effectively on vblank. */
651 intel_wait_for_vblank(dev
, pipe
);
656 /* Restore the transcoder select bit. */
658 enable_bits
|= SDVO_PIPE_B_SELECT
;
662 /* HW workaround, need to toggle enable bit off and on for 12bpc, but
663 * we do this anyway which shows more stable in testing.
665 if (HAS_PCH_SPLIT(dev
)) {
666 I915_WRITE(intel_hdmi
->sdvox_reg
, temp
& ~SDVO_ENABLE
);
667 POSTING_READ(intel_hdmi
->sdvox_reg
);
670 if (mode
!= DRM_MODE_DPMS_ON
) {
671 temp
&= ~enable_bits
;
676 I915_WRITE(intel_hdmi
->sdvox_reg
, temp
);
677 POSTING_READ(intel_hdmi
->sdvox_reg
);
679 /* HW workaround, need to write this twice for issue that may result
680 * in first write getting masked.
682 if (HAS_PCH_SPLIT(dev
)) {
683 I915_WRITE(intel_hdmi
->sdvox_reg
, temp
);
684 POSTING_READ(intel_hdmi
->sdvox_reg
);
688 static int intel_hdmi_mode_valid(struct drm_connector
*connector
,
689 struct drm_display_mode
*mode
)
691 if (mode
->clock
> 165000)
692 return MODE_CLOCK_HIGH
;
693 if (mode
->clock
< 20000)
694 return MODE_CLOCK_LOW
;
696 if (mode
->flags
& DRM_MODE_FLAG_DBLSCAN
)
697 return MODE_NO_DBLESCAN
;
702 static bool intel_hdmi_mode_fixup(struct drm_encoder
*encoder
,
703 const struct drm_display_mode
*mode
,
704 struct drm_display_mode
*adjusted_mode
)
709 static bool g4x_hdmi_connected(struct intel_hdmi
*intel_hdmi
)
711 struct drm_device
*dev
= intel_hdmi
->base
.base
.dev
;
712 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
715 switch (intel_hdmi
->sdvox_reg
) {
717 bit
= HDMIB_HOTPLUG_LIVE_STATUS
;
720 bit
= HDMIC_HOTPLUG_LIVE_STATUS
;
727 return I915_READ(PORT_HOTPLUG_STAT
) & bit
;
730 static enum drm_connector_status
731 intel_hdmi_detect(struct drm_connector
*connector
, bool force
)
733 struct intel_hdmi
*intel_hdmi
= intel_attached_hdmi(connector
);
734 struct drm_i915_private
*dev_priv
= connector
->dev
->dev_private
;
736 enum drm_connector_status status
= connector_status_disconnected
;
738 if (IS_G4X(connector
->dev
) && !g4x_hdmi_connected(intel_hdmi
))
741 intel_hdmi
->has_hdmi_sink
= false;
742 intel_hdmi
->has_audio
= false;
743 edid
= drm_get_edid(connector
,
744 intel_gmbus_get_adapter(dev_priv
,
745 intel_hdmi
->ddc_bus
));
748 if (edid
->input
& DRM_EDID_INPUT_DIGITAL
) {
749 status
= connector_status_connected
;
750 if (intel_hdmi
->force_audio
!= HDMI_AUDIO_OFF_DVI
)
751 intel_hdmi
->has_hdmi_sink
=
752 drm_detect_hdmi_monitor(edid
);
753 intel_hdmi
->has_audio
= drm_detect_monitor_audio(edid
);
755 connector
->display_info
.raw_edid
= NULL
;
759 if (status
== connector_status_connected
) {
760 if (intel_hdmi
->force_audio
!= HDMI_AUDIO_AUTO
)
761 intel_hdmi
->has_audio
=
762 (intel_hdmi
->force_audio
== HDMI_AUDIO_ON
);
768 static int intel_hdmi_get_modes(struct drm_connector
*connector
)
770 struct intel_hdmi
*intel_hdmi
= intel_attached_hdmi(connector
);
771 struct drm_i915_private
*dev_priv
= connector
->dev
->dev_private
;
773 /* We should parse the EDID data and find out if it's an HDMI sink so
774 * we can send audio to it.
777 return intel_ddc_get_modes(connector
,
778 intel_gmbus_get_adapter(dev_priv
,
779 intel_hdmi
->ddc_bus
));
783 intel_hdmi_detect_audio(struct drm_connector
*connector
)
785 struct intel_hdmi
*intel_hdmi
= intel_attached_hdmi(connector
);
786 struct drm_i915_private
*dev_priv
= connector
->dev
->dev_private
;
788 bool has_audio
= false;
790 edid
= drm_get_edid(connector
,
791 intel_gmbus_get_adapter(dev_priv
,
792 intel_hdmi
->ddc_bus
));
794 if (edid
->input
& DRM_EDID_INPUT_DIGITAL
)
795 has_audio
= drm_detect_monitor_audio(edid
);
797 connector
->display_info
.raw_edid
= NULL
;
805 intel_hdmi_set_property(struct drm_connector
*connector
,
806 struct drm_property
*property
,
809 struct intel_hdmi
*intel_hdmi
= intel_attached_hdmi(connector
);
810 struct drm_i915_private
*dev_priv
= connector
->dev
->dev_private
;
813 ret
= drm_connector_property_set_value(connector
, property
, val
);
817 if (property
== dev_priv
->force_audio_property
) {
818 enum hdmi_force_audio i
= val
;
821 if (i
== intel_hdmi
->force_audio
)
824 intel_hdmi
->force_audio
= i
;
826 if (i
== HDMI_AUDIO_AUTO
)
827 has_audio
= intel_hdmi_detect_audio(connector
);
829 has_audio
= (i
== HDMI_AUDIO_ON
);
831 if (i
== HDMI_AUDIO_OFF_DVI
)
832 intel_hdmi
->has_hdmi_sink
= 0;
834 intel_hdmi
->has_audio
= has_audio
;
838 if (property
== dev_priv
->broadcast_rgb_property
) {
839 if (val
== !!intel_hdmi
->color_range
)
842 intel_hdmi
->color_range
= val
? SDVO_COLOR_RANGE_16_235
: 0;
849 if (intel_hdmi
->base
.base
.crtc
) {
850 struct drm_crtc
*crtc
= intel_hdmi
->base
.base
.crtc
;
851 drm_crtc_helper_set_mode(crtc
, &crtc
->mode
,
859 static void intel_hdmi_destroy(struct drm_connector
*connector
)
861 drm_sysfs_connector_remove(connector
);
862 drm_connector_cleanup(connector
);
866 static const struct drm_encoder_helper_funcs intel_hdmi_helper_funcs_hsw
= {
867 .dpms
= intel_ddi_dpms
,
868 .mode_fixup
= intel_hdmi_mode_fixup
,
869 .prepare
= intel_encoder_prepare
,
870 .mode_set
= intel_ddi_mode_set
,
871 .commit
= intel_encoder_commit
,
874 static const struct drm_encoder_helper_funcs intel_hdmi_helper_funcs
= {
875 .dpms
= intel_hdmi_dpms
,
876 .mode_fixup
= intel_hdmi_mode_fixup
,
877 .prepare
= intel_encoder_prepare
,
878 .mode_set
= intel_hdmi_mode_set
,
879 .commit
= intel_encoder_commit
,
882 static const struct drm_connector_funcs intel_hdmi_connector_funcs
= {
883 .dpms
= drm_helper_connector_dpms
,
884 .detect
= intel_hdmi_detect
,
885 .fill_modes
= drm_helper_probe_single_connector_modes
,
886 .set_property
= intel_hdmi_set_property
,
887 .destroy
= intel_hdmi_destroy
,
890 static const struct drm_connector_helper_funcs intel_hdmi_connector_helper_funcs
= {
891 .get_modes
= intel_hdmi_get_modes
,
892 .mode_valid
= intel_hdmi_mode_valid
,
893 .best_encoder
= intel_best_encoder
,
896 static const struct drm_encoder_funcs intel_hdmi_enc_funcs
= {
897 .destroy
= intel_encoder_destroy
,
901 intel_hdmi_add_properties(struct intel_hdmi
*intel_hdmi
, struct drm_connector
*connector
)
903 intel_attach_force_audio_property(connector
);
904 intel_attach_broadcast_rgb_property(connector
);
907 void intel_hdmi_init(struct drm_device
*dev
, int sdvox_reg
)
909 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
910 struct drm_connector
*connector
;
911 struct intel_encoder
*intel_encoder
;
912 struct intel_connector
*intel_connector
;
913 struct intel_hdmi
*intel_hdmi
;
915 intel_hdmi
= kzalloc(sizeof(struct intel_hdmi
), GFP_KERNEL
);
919 intel_connector
= kzalloc(sizeof(struct intel_connector
), GFP_KERNEL
);
920 if (!intel_connector
) {
925 intel_encoder
= &intel_hdmi
->base
;
926 drm_encoder_init(dev
, &intel_encoder
->base
, &intel_hdmi_enc_funcs
,
927 DRM_MODE_ENCODER_TMDS
);
929 connector
= &intel_connector
->base
;
930 drm_connector_init(dev
, connector
, &intel_hdmi_connector_funcs
,
931 DRM_MODE_CONNECTOR_HDMIA
);
932 drm_connector_helper_add(connector
, &intel_hdmi_connector_helper_funcs
);
934 intel_encoder
->type
= INTEL_OUTPUT_HDMI
;
936 connector
->polled
= DRM_CONNECTOR_POLL_HPD
;
937 connector
->interlace_allowed
= 1;
938 connector
->doublescan_allowed
= 0;
939 intel_encoder
->crtc_mask
= (1 << 0) | (1 << 1) | (1 << 2);
941 /* Set up the DDC bus. */
942 if (sdvox_reg
== SDVOB
) {
943 intel_encoder
->clone_mask
= (1 << INTEL_HDMIB_CLONE_BIT
);
944 intel_hdmi
->ddc_bus
= GMBUS_PORT_DPB
;
945 dev_priv
->hotplug_supported_mask
|= HDMIB_HOTPLUG_INT_STATUS
;
946 } else if (sdvox_reg
== SDVOC
) {
947 intel_encoder
->clone_mask
= (1 << INTEL_HDMIC_CLONE_BIT
);
948 intel_hdmi
->ddc_bus
= GMBUS_PORT_DPC
;
949 dev_priv
->hotplug_supported_mask
|= HDMIC_HOTPLUG_INT_STATUS
;
950 } else if (sdvox_reg
== HDMIB
) {
951 intel_encoder
->clone_mask
= (1 << INTEL_HDMID_CLONE_BIT
);
952 intel_hdmi
->ddc_bus
= GMBUS_PORT_DPB
;
953 dev_priv
->hotplug_supported_mask
|= HDMIB_HOTPLUG_INT_STATUS
;
954 } else if (sdvox_reg
== HDMIC
) {
955 intel_encoder
->clone_mask
= (1 << INTEL_HDMIE_CLONE_BIT
);
956 intel_hdmi
->ddc_bus
= GMBUS_PORT_DPC
;
957 dev_priv
->hotplug_supported_mask
|= HDMIC_HOTPLUG_INT_STATUS
;
958 } else if (sdvox_reg
== HDMID
) {
959 intel_encoder
->clone_mask
= (1 << INTEL_HDMIF_CLONE_BIT
);
960 intel_hdmi
->ddc_bus
= GMBUS_PORT_DPD
;
961 dev_priv
->hotplug_supported_mask
|= HDMID_HOTPLUG_INT_STATUS
;
962 } else if (sdvox_reg
== DDI_BUF_CTL(PORT_B
)) {
963 DRM_DEBUG_DRIVER("LPT: detected output on DDI B\n");
964 intel_encoder
->clone_mask
= (1 << INTEL_HDMIB_CLONE_BIT
);
965 intel_hdmi
->ddc_bus
= GMBUS_PORT_DPB
;
966 intel_hdmi
->ddi_port
= PORT_B
;
967 dev_priv
->hotplug_supported_mask
|= HDMIB_HOTPLUG_INT_STATUS
;
968 } else if (sdvox_reg
== DDI_BUF_CTL(PORT_C
)) {
969 DRM_DEBUG_DRIVER("LPT: detected output on DDI C\n");
970 intel_encoder
->clone_mask
= (1 << INTEL_HDMIC_CLONE_BIT
);
971 intel_hdmi
->ddc_bus
= GMBUS_PORT_DPC
;
972 intel_hdmi
->ddi_port
= PORT_C
;
973 dev_priv
->hotplug_supported_mask
|= HDMIC_HOTPLUG_INT_STATUS
;
974 } else if (sdvox_reg
== DDI_BUF_CTL(PORT_D
)) {
975 DRM_DEBUG_DRIVER("LPT: detected output on DDI D\n");
976 intel_encoder
->clone_mask
= (1 << INTEL_HDMID_CLONE_BIT
);
977 intel_hdmi
->ddc_bus
= GMBUS_PORT_DPD
;
978 intel_hdmi
->ddi_port
= PORT_D
;
979 dev_priv
->hotplug_supported_mask
|= HDMID_HOTPLUG_INT_STATUS
;
981 /* If we got an unknown sdvox_reg, things are pretty much broken
982 * in a way that we should let the kernel know about it */
986 intel_hdmi
->sdvox_reg
= sdvox_reg
;
988 if (!HAS_PCH_SPLIT(dev
)) {
989 intel_hdmi
->write_infoframe
= g4x_write_infoframe
;
990 intel_hdmi
->set_infoframes
= g4x_set_infoframes
;
991 } else if (IS_VALLEYVIEW(dev
)) {
992 intel_hdmi
->write_infoframe
= vlv_write_infoframe
;
993 intel_hdmi
->set_infoframes
= vlv_set_infoframes
;
994 } else if (IS_HASWELL(dev
)) {
995 intel_hdmi
->write_infoframe
= hsw_write_infoframe
;
996 intel_hdmi
->set_infoframes
= hsw_set_infoframes
;
997 } else if (HAS_PCH_IBX(dev
)) {
998 intel_hdmi
->write_infoframe
= ibx_write_infoframe
;
999 intel_hdmi
->set_infoframes
= ibx_set_infoframes
;
1001 intel_hdmi
->write_infoframe
= cpt_write_infoframe
;
1002 intel_hdmi
->set_infoframes
= cpt_set_infoframes
;
1005 if (IS_HASWELL(dev
))
1006 drm_encoder_helper_add(&intel_encoder
->base
, &intel_hdmi_helper_funcs_hsw
);
1008 drm_encoder_helper_add(&intel_encoder
->base
, &intel_hdmi_helper_funcs
);
1010 intel_hdmi_add_properties(intel_hdmi
, connector
);
1012 intel_connector_attach_encoder(intel_connector
, intel_encoder
);
1013 drm_sysfs_connector_add(connector
);
1015 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
1016 * 0xd. Failure to do so will result in spurious interrupts being
1017 * generated on the port when a cable is not attached.
1019 if (IS_G4X(dev
) && !IS_GM45(dev
)) {
1020 u32 temp
= I915_READ(PEG_BAND_GAP_DATA
);
1021 I915_WRITE(PEG_BAND_GAP_DATA
, (temp
& ~0xf) | 0xd);