2 * Copyright © 2006-2007 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 * Eric Anholt <eric@anholt.net>
27 #include <linux/dmi.h>
28 #include <linux/i2c.h>
29 #include <linux/slab.h>
31 #include <drm/drm_crtc.h>
32 #include <drm/drm_crtc_helper.h>
33 #include <drm/drm_edid.h>
34 #include "intel_drv.h"
35 #include <drm/i915_drm.h>
38 /* Here's the desired hotplug mode */
39 #define ADPA_HOTPLUG_BITS (ADPA_CRT_HOTPLUG_PERIOD_128 | \
40 ADPA_CRT_HOTPLUG_WARMUP_10MS | \
41 ADPA_CRT_HOTPLUG_SAMPLE_4S | \
42 ADPA_CRT_HOTPLUG_VOLTAGE_50 | \
43 ADPA_CRT_HOTPLUG_VOLREF_325MV | \
44 ADPA_CRT_HOTPLUG_ENABLE)
47 struct intel_encoder base
;
48 /* DPMS state is stored in the connector, which we need in the
49 * encoder's enable/disable callbacks */
50 struct intel_connector
*connector
;
51 bool force_hotplug_required
;
55 static struct intel_crt
*intel_encoder_to_crt(struct intel_encoder
*encoder
)
57 return container_of(encoder
, struct intel_crt
, base
);
60 static struct intel_crt
*intel_attached_crt(struct drm_connector
*connector
)
62 return intel_encoder_to_crt(intel_attached_encoder(connector
));
65 static bool intel_crt_get_hw_state(struct intel_encoder
*encoder
,
68 struct drm_device
*dev
= encoder
->base
.dev
;
69 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
70 struct intel_crt
*crt
= intel_encoder_to_crt(encoder
);
73 tmp
= I915_READ(crt
->adpa_reg
);
75 if (!(tmp
& ADPA_DAC_ENABLE
))
79 *pipe
= PORT_TO_PIPE_CPT(tmp
);
81 *pipe
= PORT_TO_PIPE(tmp
);
86 static unsigned int intel_crt_get_flags(struct intel_encoder
*encoder
)
88 struct drm_i915_private
*dev_priv
= encoder
->base
.dev
->dev_private
;
89 struct intel_crt
*crt
= intel_encoder_to_crt(encoder
);
92 tmp
= I915_READ(crt
->adpa_reg
);
94 if (tmp
& ADPA_HSYNC_ACTIVE_HIGH
)
95 flags
|= DRM_MODE_FLAG_PHSYNC
;
97 flags
|= DRM_MODE_FLAG_NHSYNC
;
99 if (tmp
& ADPA_VSYNC_ACTIVE_HIGH
)
100 flags
|= DRM_MODE_FLAG_PVSYNC
;
102 flags
|= DRM_MODE_FLAG_NVSYNC
;
107 static void intel_crt_get_config(struct intel_encoder
*encoder
,
108 struct intel_crtc_config
*pipe_config
)
110 pipe_config
->adjusted_mode
.flags
|= intel_crt_get_flags(encoder
);
113 static void hsw_crt_get_config(struct intel_encoder
*encoder
,
114 struct intel_crtc_config
*pipe_config
)
116 intel_ddi_get_config(encoder
, pipe_config
);
118 pipe_config
->adjusted_mode
.flags
&= ~(DRM_MODE_FLAG_PHSYNC
|
119 DRM_MODE_FLAG_NHSYNC
|
120 DRM_MODE_FLAG_PVSYNC
|
121 DRM_MODE_FLAG_NVSYNC
);
122 pipe_config
->adjusted_mode
.flags
|= intel_crt_get_flags(encoder
);
125 /* Note: The caller is required to filter out dpms modes not supported by the
127 static void intel_crt_set_dpms(struct intel_encoder
*encoder
, int mode
)
129 struct drm_device
*dev
= encoder
->base
.dev
;
130 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
131 struct intel_crt
*crt
= intel_encoder_to_crt(encoder
);
134 temp
= I915_READ(crt
->adpa_reg
);
135 temp
&= ~(ADPA_HSYNC_CNTL_DISABLE
| ADPA_VSYNC_CNTL_DISABLE
);
136 temp
&= ~ADPA_DAC_ENABLE
;
139 case DRM_MODE_DPMS_ON
:
140 temp
|= ADPA_DAC_ENABLE
;
142 case DRM_MODE_DPMS_STANDBY
:
143 temp
|= ADPA_DAC_ENABLE
| ADPA_HSYNC_CNTL_DISABLE
;
145 case DRM_MODE_DPMS_SUSPEND
:
146 temp
|= ADPA_DAC_ENABLE
| ADPA_VSYNC_CNTL_DISABLE
;
148 case DRM_MODE_DPMS_OFF
:
149 temp
|= ADPA_HSYNC_CNTL_DISABLE
| ADPA_VSYNC_CNTL_DISABLE
;
153 I915_WRITE(crt
->adpa_reg
, temp
);
156 static void intel_disable_crt(struct intel_encoder
*encoder
)
158 intel_crt_set_dpms(encoder
, DRM_MODE_DPMS_OFF
);
161 static void intel_enable_crt(struct intel_encoder
*encoder
)
163 struct intel_crt
*crt
= intel_encoder_to_crt(encoder
);
165 intel_crt_set_dpms(encoder
, crt
->connector
->base
.dpms
);
168 /* Special dpms function to support cloning between dvo/sdvo/crt. */
169 static void intel_crt_dpms(struct drm_connector
*connector
, int mode
)
171 struct drm_device
*dev
= connector
->dev
;
172 struct intel_encoder
*encoder
= intel_attached_encoder(connector
);
173 struct drm_crtc
*crtc
;
176 /* PCH platforms and VLV only support on/off. */
177 if (INTEL_INFO(dev
)->gen
>= 5 && mode
!= DRM_MODE_DPMS_ON
)
178 mode
= DRM_MODE_DPMS_OFF
;
180 if (mode
== connector
->dpms
)
183 old_dpms
= connector
->dpms
;
184 connector
->dpms
= mode
;
186 /* Only need to change hw state when actually enabled */
187 crtc
= encoder
->base
.crtc
;
189 encoder
->connectors_active
= false;
193 /* We need the pipe to run for anything but OFF. */
194 if (mode
== DRM_MODE_DPMS_OFF
)
195 encoder
->connectors_active
= false;
197 encoder
->connectors_active
= true;
199 /* We call connector dpms manually below in case pipe dpms doesn't
200 * change due to cloning. */
201 if (mode
< old_dpms
) {
202 /* From off to on, enable the pipe first. */
203 intel_crtc_update_dpms(crtc
);
205 intel_crt_set_dpms(encoder
, mode
);
207 intel_crt_set_dpms(encoder
, mode
);
209 intel_crtc_update_dpms(crtc
);
212 intel_modeset_check_state(connector
->dev
);
215 static int intel_crt_mode_valid(struct drm_connector
*connector
,
216 struct drm_display_mode
*mode
)
218 struct drm_device
*dev
= connector
->dev
;
221 if (mode
->flags
& DRM_MODE_FLAG_DBLSCAN
)
222 return MODE_NO_DBLESCAN
;
224 if (mode
->clock
< 25000)
225 return MODE_CLOCK_LOW
;
231 if (mode
->clock
> max_clock
)
232 return MODE_CLOCK_HIGH
;
234 /* The FDI receiver on LPT only supports 8bpc and only has 2 lanes. */
235 if (HAS_PCH_LPT(dev
) &&
236 (ironlake_get_lanes_required(mode
->clock
, 270000, 24) > 2))
237 return MODE_CLOCK_HIGH
;
242 static bool intel_crt_compute_config(struct intel_encoder
*encoder
,
243 struct intel_crtc_config
*pipe_config
)
245 struct drm_device
*dev
= encoder
->base
.dev
;
247 if (HAS_PCH_SPLIT(dev
))
248 pipe_config
->has_pch_encoder
= true;
250 /* LPT FDI RX only supports 8bpc. */
251 if (HAS_PCH_LPT(dev
))
252 pipe_config
->pipe_bpp
= 24;
257 static void intel_crt_mode_set(struct intel_encoder
*encoder
)
260 struct drm_device
*dev
= encoder
->base
.dev
;
261 struct intel_crt
*crt
= intel_encoder_to_crt(encoder
);
262 struct intel_crtc
*crtc
= to_intel_crtc(encoder
->base
.crtc
);
263 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
264 struct drm_display_mode
*adjusted_mode
= &crtc
->config
.adjusted_mode
;
267 if (HAS_PCH_SPLIT(dev
))
268 adpa
= ADPA_HOTPLUG_BITS
;
272 if (adjusted_mode
->flags
& DRM_MODE_FLAG_PHSYNC
)
273 adpa
|= ADPA_HSYNC_ACTIVE_HIGH
;
274 if (adjusted_mode
->flags
& DRM_MODE_FLAG_PVSYNC
)
275 adpa
|= ADPA_VSYNC_ACTIVE_HIGH
;
277 /* For CPT allow 3 pipe config, for others just use A or B */
278 if (HAS_PCH_LPT(dev
))
279 ; /* Those bits don't exist here */
280 else if (HAS_PCH_CPT(dev
))
281 adpa
|= PORT_TRANS_SEL_CPT(crtc
->pipe
);
282 else if (crtc
->pipe
== 0)
283 adpa
|= ADPA_PIPE_A_SELECT
;
285 adpa
|= ADPA_PIPE_B_SELECT
;
287 if (!HAS_PCH_SPLIT(dev
))
288 I915_WRITE(BCLRPAT(crtc
->pipe
), 0);
290 I915_WRITE(crt
->adpa_reg
, adpa
);
293 static bool intel_ironlake_crt_detect_hotplug(struct drm_connector
*connector
)
295 struct drm_device
*dev
= connector
->dev
;
296 struct intel_crt
*crt
= intel_attached_crt(connector
);
297 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
301 /* The first time through, trigger an explicit detection cycle */
302 if (crt
->force_hotplug_required
) {
303 bool turn_off_dac
= HAS_PCH_SPLIT(dev
);
306 crt
->force_hotplug_required
= 0;
308 save_adpa
= adpa
= I915_READ(crt
->adpa_reg
);
309 DRM_DEBUG_KMS("trigger hotplug detect cycle: adpa=0x%x\n", adpa
);
311 adpa
|= ADPA_CRT_HOTPLUG_FORCE_TRIGGER
;
313 adpa
&= ~ADPA_DAC_ENABLE
;
315 I915_WRITE(crt
->adpa_reg
, adpa
);
317 if (wait_for((I915_READ(crt
->adpa_reg
) & ADPA_CRT_HOTPLUG_FORCE_TRIGGER
) == 0,
319 DRM_DEBUG_KMS("timed out waiting for FORCE_TRIGGER");
322 I915_WRITE(crt
->adpa_reg
, save_adpa
);
323 POSTING_READ(crt
->adpa_reg
);
327 /* Check the status to see if both blue and green are on now */
328 adpa
= I915_READ(crt
->adpa_reg
);
329 if ((adpa
& ADPA_CRT_HOTPLUG_MONITOR_MASK
) != 0)
333 DRM_DEBUG_KMS("ironlake hotplug adpa=0x%x, result %d\n", adpa
, ret
);
338 static bool valleyview_crt_detect_hotplug(struct drm_connector
*connector
)
340 struct drm_device
*dev
= connector
->dev
;
341 struct intel_crt
*crt
= intel_attached_crt(connector
);
342 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
347 save_adpa
= adpa
= I915_READ(crt
->adpa_reg
);
348 DRM_DEBUG_KMS("trigger hotplug detect cycle: adpa=0x%x\n", adpa
);
350 adpa
|= ADPA_CRT_HOTPLUG_FORCE_TRIGGER
;
352 I915_WRITE(crt
->adpa_reg
, adpa
);
354 if (wait_for((I915_READ(crt
->adpa_reg
) & ADPA_CRT_HOTPLUG_FORCE_TRIGGER
) == 0,
356 DRM_DEBUG_KMS("timed out waiting for FORCE_TRIGGER");
357 I915_WRITE(crt
->adpa_reg
, save_adpa
);
360 /* Check the status to see if both blue and green are on now */
361 adpa
= I915_READ(crt
->adpa_reg
);
362 if ((adpa
& ADPA_CRT_HOTPLUG_MONITOR_MASK
) != 0)
367 DRM_DEBUG_KMS("valleyview hotplug adpa=0x%x, result %d\n", adpa
, ret
);
369 /* FIXME: debug force function and remove */
376 * Uses CRT_HOTPLUG_EN and CRT_HOTPLUG_STAT to detect CRT presence.
378 * Not for i915G/i915GM
380 * \return true if CRT is connected.
381 * \return false if CRT is disconnected.
383 static bool intel_crt_detect_hotplug(struct drm_connector
*connector
)
385 struct drm_device
*dev
= connector
->dev
;
386 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
387 u32 hotplug_en
, orig
, stat
;
391 if (HAS_PCH_SPLIT(dev
))
392 return intel_ironlake_crt_detect_hotplug(connector
);
394 if (IS_VALLEYVIEW(dev
))
395 return valleyview_crt_detect_hotplug(connector
);
398 * On 4 series desktop, CRT detect sequence need to be done twice
399 * to get a reliable result.
402 if (IS_G4X(dev
) && !IS_GM45(dev
))
406 hotplug_en
= orig
= I915_READ(PORT_HOTPLUG_EN
);
407 hotplug_en
|= CRT_HOTPLUG_FORCE_DETECT
;
409 for (i
= 0; i
< tries
; i
++) {
410 /* turn on the FORCE_DETECT */
411 I915_WRITE(PORT_HOTPLUG_EN
, hotplug_en
);
412 /* wait for FORCE_DETECT to go off */
413 if (wait_for((I915_READ(PORT_HOTPLUG_EN
) &
414 CRT_HOTPLUG_FORCE_DETECT
) == 0,
416 DRM_DEBUG_KMS("timed out waiting for FORCE_DETECT to go off");
419 stat
= I915_READ(PORT_HOTPLUG_STAT
);
420 if ((stat
& CRT_HOTPLUG_MONITOR_MASK
) != CRT_HOTPLUG_MONITOR_NONE
)
423 /* clear the interrupt we just generated, if any */
424 I915_WRITE(PORT_HOTPLUG_STAT
, CRT_HOTPLUG_INT_STATUS
);
426 /* and put the bits back */
427 I915_WRITE(PORT_HOTPLUG_EN
, orig
);
432 static struct edid
*intel_crt_get_edid(struct drm_connector
*connector
,
433 struct i2c_adapter
*i2c
)
437 edid
= drm_get_edid(connector
, i2c
);
439 if (!edid
&& !intel_gmbus_is_forced_bit(i2c
)) {
440 DRM_DEBUG_KMS("CRT GMBUS EDID read failed, retry using GPIO bit-banging\n");
441 intel_gmbus_force_bit(i2c
, true);
442 edid
= drm_get_edid(connector
, i2c
);
443 intel_gmbus_force_bit(i2c
, false);
449 /* local version of intel_ddc_get_modes() to use intel_crt_get_edid() */
450 static int intel_crt_ddc_get_modes(struct drm_connector
*connector
,
451 struct i2c_adapter
*adapter
)
456 edid
= intel_crt_get_edid(connector
, adapter
);
460 ret
= intel_connector_update_modes(connector
, edid
);
466 static bool intel_crt_detect_ddc(struct drm_connector
*connector
)
468 struct intel_crt
*crt
= intel_attached_crt(connector
);
469 struct drm_i915_private
*dev_priv
= crt
->base
.base
.dev
->dev_private
;
471 struct i2c_adapter
*i2c
;
473 BUG_ON(crt
->base
.type
!= INTEL_OUTPUT_ANALOG
);
475 i2c
= intel_gmbus_get_adapter(dev_priv
, dev_priv
->vbt
.crt_ddc_pin
);
476 edid
= intel_crt_get_edid(connector
, i2c
);
479 bool is_digital
= edid
->input
& DRM_EDID_INPUT_DIGITAL
;
482 * This may be a DVI-I connector with a shared DDC
483 * link between analog and digital outputs, so we
484 * have to check the EDID input spec of the attached device.
487 DRM_DEBUG_KMS("CRT detected via DDC:0x50 [EDID]\n");
491 DRM_DEBUG_KMS("CRT not detected via DDC:0x50 [EDID reports a digital panel]\n");
493 DRM_DEBUG_KMS("CRT not detected via DDC:0x50 [no valid EDID found]\n");
501 static enum drm_connector_status
502 intel_crt_load_detect(struct intel_crt
*crt
)
504 struct drm_device
*dev
= crt
->base
.base
.dev
;
505 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
506 uint32_t pipe
= to_intel_crtc(crt
->base
.base
.crtc
)->pipe
;
507 uint32_t save_bclrpat
;
508 uint32_t save_vtotal
;
509 uint32_t vtotal
, vactive
;
511 uint32_t vblank
, vblank_start
, vblank_end
;
513 uint32_t bclrpat_reg
;
517 uint32_t pipeconf_reg
;
518 uint32_t pipe_dsl_reg
;
520 enum drm_connector_status status
;
522 DRM_DEBUG_KMS("starting load-detect on CRT\n");
524 bclrpat_reg
= BCLRPAT(pipe
);
525 vtotal_reg
= VTOTAL(pipe
);
526 vblank_reg
= VBLANK(pipe
);
527 vsync_reg
= VSYNC(pipe
);
528 pipeconf_reg
= PIPECONF(pipe
);
529 pipe_dsl_reg
= PIPEDSL(pipe
);
531 save_bclrpat
= I915_READ(bclrpat_reg
);
532 save_vtotal
= I915_READ(vtotal_reg
);
533 vblank
= I915_READ(vblank_reg
);
535 vtotal
= ((save_vtotal
>> 16) & 0xfff) + 1;
536 vactive
= (save_vtotal
& 0x7ff) + 1;
538 vblank_start
= (vblank
& 0xfff) + 1;
539 vblank_end
= ((vblank
>> 16) & 0xfff) + 1;
541 /* Set the border color to purple. */
542 I915_WRITE(bclrpat_reg
, 0x500050);
545 uint32_t pipeconf
= I915_READ(pipeconf_reg
);
546 I915_WRITE(pipeconf_reg
, pipeconf
| PIPECONF_FORCE_BORDER
);
547 POSTING_READ(pipeconf_reg
);
548 /* Wait for next Vblank to substitue
549 * border color for Color info */
550 intel_wait_for_vblank(dev
, pipe
);
551 st00
= I915_READ8(VGA_MSR_WRITE
);
552 status
= ((st00
& (1 << 4)) != 0) ?
553 connector_status_connected
:
554 connector_status_disconnected
;
556 I915_WRITE(pipeconf_reg
, pipeconf
);
558 bool restore_vblank
= false;
562 * If there isn't any border, add some.
563 * Yes, this will flicker
565 if (vblank_start
<= vactive
&& vblank_end
>= vtotal
) {
566 uint32_t vsync
= I915_READ(vsync_reg
);
567 uint32_t vsync_start
= (vsync
& 0xffff) + 1;
569 vblank_start
= vsync_start
;
570 I915_WRITE(vblank_reg
,
572 ((vblank_end
- 1) << 16));
573 restore_vblank
= true;
575 /* sample in the vertical border, selecting the larger one */
576 if (vblank_start
- vactive
>= vtotal
- vblank_end
)
577 vsample
= (vblank_start
+ vactive
) >> 1;
579 vsample
= (vtotal
+ vblank_end
) >> 1;
582 * Wait for the border to be displayed
584 while (I915_READ(pipe_dsl_reg
) >= vactive
)
586 while ((dsl
= I915_READ(pipe_dsl_reg
)) <= vsample
)
589 * Watch ST00 for an entire scanline
595 /* Read the ST00 VGA status register */
596 st00
= I915_READ8(VGA_MSR_WRITE
);
599 } while ((I915_READ(pipe_dsl_reg
) == dsl
));
601 /* restore vblank if necessary */
603 I915_WRITE(vblank_reg
, vblank
);
605 * If more than 3/4 of the scanline detected a monitor,
606 * then it is assumed to be present. This works even on i830,
607 * where there isn't any way to force the border color across
610 status
= detect
* 4 > count
* 3 ?
611 connector_status_connected
:
612 connector_status_disconnected
;
615 /* Restore previous settings */
616 I915_WRITE(bclrpat_reg
, save_bclrpat
);
621 static enum drm_connector_status
622 intel_crt_detect(struct drm_connector
*connector
, bool force
)
624 struct drm_device
*dev
= connector
->dev
;
625 struct intel_crt
*crt
= intel_attached_crt(connector
);
626 enum drm_connector_status status
;
627 struct intel_load_detect_pipe tmp
;
629 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] force=%d\n",
630 connector
->base
.id
, drm_get_connector_name(connector
),
633 if (I915_HAS_HOTPLUG(dev
)) {
634 /* We can not rely on the HPD pin always being correctly wired
635 * up, for example many KVM do not pass it through, and so
636 * only trust an assertion that the monitor is connected.
638 if (intel_crt_detect_hotplug(connector
)) {
639 DRM_DEBUG_KMS("CRT detected via hotplug\n");
640 return connector_status_connected
;
642 DRM_DEBUG_KMS("CRT not detected via hotplug\n");
645 if (intel_crt_detect_ddc(connector
))
646 return connector_status_connected
;
648 /* Load detection is broken on HPD capable machines. Whoever wants a
649 * broken monitor (without edid) to work behind a broken kvm (that fails
650 * to have the right resistors for HP detection) needs to fix this up.
651 * For now just bail out. */
652 if (I915_HAS_HOTPLUG(dev
))
653 return connector_status_disconnected
;
656 return connector
->status
;
658 /* for pre-945g platforms use load detect */
659 if (intel_get_load_detect_pipe(connector
, NULL
, &tmp
)) {
660 if (intel_crt_detect_ddc(connector
))
661 status
= connector_status_connected
;
663 status
= intel_crt_load_detect(crt
);
664 intel_release_load_detect_pipe(connector
, &tmp
);
666 status
= connector_status_unknown
;
671 static void intel_crt_destroy(struct drm_connector
*connector
)
673 drm_sysfs_connector_remove(connector
);
674 drm_connector_cleanup(connector
);
678 static int intel_crt_get_modes(struct drm_connector
*connector
)
680 struct drm_device
*dev
= connector
->dev
;
681 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
683 struct i2c_adapter
*i2c
;
685 i2c
= intel_gmbus_get_adapter(dev_priv
, dev_priv
->vbt
.crt_ddc_pin
);
686 ret
= intel_crt_ddc_get_modes(connector
, i2c
);
687 if (ret
|| !IS_G4X(dev
))
690 /* Try to probe digital port for output in DVI-I -> VGA mode. */
691 i2c
= intel_gmbus_get_adapter(dev_priv
, GMBUS_PORT_DPB
);
692 return intel_crt_ddc_get_modes(connector
, i2c
);
695 static int intel_crt_set_property(struct drm_connector
*connector
,
696 struct drm_property
*property
,
702 static void intel_crt_reset(struct drm_connector
*connector
)
704 struct drm_device
*dev
= connector
->dev
;
705 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
706 struct intel_crt
*crt
= intel_attached_crt(connector
);
708 if (INTEL_INFO(dev
)->gen
>= 5) {
711 adpa
= I915_READ(crt
->adpa_reg
);
712 adpa
&= ~ADPA_CRT_HOTPLUG_MASK
;
713 adpa
|= ADPA_HOTPLUG_BITS
;
714 I915_WRITE(crt
->adpa_reg
, adpa
);
715 POSTING_READ(crt
->adpa_reg
);
717 DRM_DEBUG_KMS("pch crt adpa set to 0x%x\n", adpa
);
718 crt
->force_hotplug_required
= 1;
724 * Routines for controlling stuff on the analog port
727 static const struct drm_connector_funcs intel_crt_connector_funcs
= {
728 .reset
= intel_crt_reset
,
729 .dpms
= intel_crt_dpms
,
730 .detect
= intel_crt_detect
,
731 .fill_modes
= drm_helper_probe_single_connector_modes
,
732 .destroy
= intel_crt_destroy
,
733 .set_property
= intel_crt_set_property
,
736 static const struct drm_connector_helper_funcs intel_crt_connector_helper_funcs
= {
737 .mode_valid
= intel_crt_mode_valid
,
738 .get_modes
= intel_crt_get_modes
,
739 .best_encoder
= intel_best_encoder
,
742 static const struct drm_encoder_funcs intel_crt_enc_funcs
= {
743 .destroy
= intel_encoder_destroy
,
746 static int __init
intel_no_crt_dmi_callback(const struct dmi_system_id
*id
)
748 DRM_INFO("Skipping CRT initialization for %s\n", id
->ident
);
752 static const struct dmi_system_id intel_no_crt
[] = {
754 .callback
= intel_no_crt_dmi_callback
,
757 DMI_MATCH(DMI_SYS_VENDOR
, "ACER"),
758 DMI_MATCH(DMI_PRODUCT_NAME
, "ZGB"),
762 .callback
= intel_no_crt_dmi_callback
,
763 .ident
= "DELL XPS 8700",
765 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
766 DMI_MATCH(DMI_PRODUCT_NAME
, "XPS 8700"),
772 void intel_crt_init(struct drm_device
*dev
)
774 struct drm_connector
*connector
;
775 struct intel_crt
*crt
;
776 struct intel_connector
*intel_connector
;
777 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
779 /* Skip machines without VGA that falsely report hotplug events */
780 if (dmi_check_system(intel_no_crt
))
783 crt
= kzalloc(sizeof(struct intel_crt
), GFP_KERNEL
);
787 intel_connector
= kzalloc(sizeof(struct intel_connector
), GFP_KERNEL
);
788 if (!intel_connector
) {
793 connector
= &intel_connector
->base
;
794 crt
->connector
= intel_connector
;
795 drm_connector_init(dev
, &intel_connector
->base
,
796 &intel_crt_connector_funcs
, DRM_MODE_CONNECTOR_VGA
);
798 drm_encoder_init(dev
, &crt
->base
.base
, &intel_crt_enc_funcs
,
799 DRM_MODE_ENCODER_DAC
);
801 intel_connector_attach_encoder(intel_connector
, &crt
->base
);
803 crt
->base
.type
= INTEL_OUTPUT_ANALOG
;
804 crt
->base
.cloneable
= true;
806 crt
->base
.crtc_mask
= (1 << 0);
808 crt
->base
.crtc_mask
= (1 << 0) | (1 << 1) | (1 << 2);
811 connector
->interlace_allowed
= 0;
813 connector
->interlace_allowed
= 1;
814 connector
->doublescan_allowed
= 0;
816 if (HAS_PCH_SPLIT(dev
))
817 crt
->adpa_reg
= PCH_ADPA
;
818 else if (IS_VALLEYVIEW(dev
))
819 crt
->adpa_reg
= VLV_ADPA
;
821 crt
->adpa_reg
= ADPA
;
823 crt
->base
.compute_config
= intel_crt_compute_config
;
824 crt
->base
.mode_set
= intel_crt_mode_set
;
825 crt
->base
.disable
= intel_disable_crt
;
826 crt
->base
.enable
= intel_enable_crt
;
828 crt
->base
.get_config
= hsw_crt_get_config
;
830 crt
->base
.get_config
= intel_crt_get_config
;
831 if (I915_HAS_HOTPLUG(dev
))
832 crt
->base
.hpd_pin
= HPD_CRT
;
834 crt
->base
.get_hw_state
= intel_ddi_get_hw_state
;
836 crt
->base
.get_hw_state
= intel_crt_get_hw_state
;
837 intel_connector
->get_hw_state
= intel_connector_get_hw_state
;
839 drm_connector_helper_add(connector
, &intel_crt_connector_helper_funcs
);
841 drm_sysfs_connector_add(connector
);
843 if (!I915_HAS_HOTPLUG(dev
))
844 intel_connector
->polled
= DRM_CONNECTOR_POLL_CONNECT
;
847 * Configure the automatic hotplug detection stuff
849 crt
->force_hotplug_required
= 0;
852 * TODO: find a proper way to discover whether we need to set the the
853 * polarity and link reversal bits or not, instead of relying on the
856 if (HAS_PCH_LPT(dev
)) {
857 u32 fdi_config
= FDI_RX_POLARITY_REVERSED_LPT
|
858 FDI_RX_LINK_REVERSAL_OVERRIDE
;
860 dev_priv
->fdi_rx_config
= I915_READ(_FDI_RXA_CTL
) & fdi_config
;