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 struct drm_device *dev = encoder->base.dev;
113 pipe_config->adjusted_mode.flags |= intel_crt_get_flags(encoder);
115 dotclock = pipe_config->port_clock;
117 if (HAS_PCH_SPLIT(dev))
118 ironlake_check_encoder_dotclock(pipe_config, dotclock);
120 pipe_config->adjusted_mode.crtc_clock = dotclock;
123 static void hsw_crt_get_config(struct intel_encoder *encoder,
124 struct intel_crtc_config *pipe_config)
126 intel_ddi_get_config(encoder, pipe_config);
128 pipe_config->adjusted_mode.flags &= ~(DRM_MODE_FLAG_PHSYNC |
129 DRM_MODE_FLAG_NHSYNC |
130 DRM_MODE_FLAG_PVSYNC |
131 DRM_MODE_FLAG_NVSYNC);
132 pipe_config->adjusted_mode.flags |= intel_crt_get_flags(encoder);
135 /* Note: The caller is required to filter out dpms modes not supported by the
137 static void intel_crt_set_dpms(struct intel_encoder *encoder, int mode)
139 struct drm_device *dev = encoder->base.dev;
140 struct drm_i915_private *dev_priv = dev->dev_private;
141 struct intel_crt *crt = intel_encoder_to_crt(encoder);
144 temp = I915_READ(crt->adpa_reg);
145 temp &= ~(ADPA_HSYNC_CNTL_DISABLE | ADPA_VSYNC_CNTL_DISABLE);
146 temp &= ~ADPA_DAC_ENABLE;
149 case DRM_MODE_DPMS_ON:
150 temp |= ADPA_DAC_ENABLE;
152 case DRM_MODE_DPMS_STANDBY:
153 temp |= ADPA_DAC_ENABLE | ADPA_HSYNC_CNTL_DISABLE;
155 case DRM_MODE_DPMS_SUSPEND:
156 temp |= ADPA_DAC_ENABLE | ADPA_VSYNC_CNTL_DISABLE;
158 case DRM_MODE_DPMS_OFF:
159 temp |= ADPA_HSYNC_CNTL_DISABLE | ADPA_VSYNC_CNTL_DISABLE;
163 I915_WRITE(crt->adpa_reg, temp);
166 static void intel_disable_crt(struct intel_encoder *encoder)
168 intel_crt_set_dpms(encoder, DRM_MODE_DPMS_OFF);
171 static void intel_enable_crt(struct intel_encoder *encoder)
173 struct intel_crt *crt = intel_encoder_to_crt(encoder);
175 intel_crt_set_dpms(encoder, crt->connector->base.dpms);
178 /* Special dpms function to support cloning between dvo/sdvo/crt. */
179 static void intel_crt_dpms(struct drm_connector *connector, int mode)
181 struct drm_device *dev = connector->dev;
182 struct intel_encoder *encoder = intel_attached_encoder(connector);
183 struct drm_crtc *crtc;
186 /* PCH platforms and VLV only support on/off. */
187 if (INTEL_INFO(dev)->gen >= 5 && mode != DRM_MODE_DPMS_ON)
188 mode = DRM_MODE_DPMS_OFF;
190 if (mode == connector->dpms)
193 old_dpms = connector->dpms;
194 connector->dpms = mode;
196 /* Only need to change hw state when actually enabled */
197 crtc = encoder->base.crtc;
199 encoder->connectors_active = false;
203 /* We need the pipe to run for anything but OFF. */
204 if (mode == DRM_MODE_DPMS_OFF)
205 encoder->connectors_active = false;
207 encoder->connectors_active = true;
209 /* We call connector dpms manually below in case pipe dpms doesn't
210 * change due to cloning. */
211 if (mode < old_dpms) {
212 /* From off to on, enable the pipe first. */
213 intel_crtc_update_dpms(crtc);
215 intel_crt_set_dpms(encoder, mode);
217 intel_crt_set_dpms(encoder, mode);
219 intel_crtc_update_dpms(crtc);
222 intel_modeset_check_state(connector->dev);
225 static enum drm_mode_status
226 intel_crt_mode_valid(struct drm_connector *connector,
227 struct drm_display_mode *mode)
229 struct drm_device *dev = connector->dev;
232 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
233 return MODE_NO_DBLESCAN;
235 if (mode->clock < 25000)
236 return MODE_CLOCK_LOW;
242 if (mode->clock > max_clock)
243 return MODE_CLOCK_HIGH;
245 /* The FDI receiver on LPT only supports 8bpc and only has 2 lanes. */
246 if (HAS_PCH_LPT(dev) &&
247 (ironlake_get_lanes_required(mode->clock, 270000, 24) > 2))
248 return MODE_CLOCK_HIGH;
253 static bool intel_crt_compute_config(struct intel_encoder *encoder,
254 struct intel_crtc_config *pipe_config)
256 struct drm_device *dev = encoder->base.dev;
258 if (HAS_PCH_SPLIT(dev))
259 pipe_config->has_pch_encoder = true;
261 /* LPT FDI RX only supports 8bpc. */
262 if (HAS_PCH_LPT(dev))
263 pipe_config->pipe_bpp = 24;
268 static void intel_crt_mode_set(struct intel_encoder *encoder)
271 struct drm_device *dev = encoder->base.dev;
272 struct intel_crt *crt = intel_encoder_to_crt(encoder);
273 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
274 struct drm_i915_private *dev_priv = dev->dev_private;
275 struct drm_display_mode *adjusted_mode = &crtc->config.adjusted_mode;
278 if (INTEL_INFO(dev)->gen >= 5)
279 adpa = ADPA_HOTPLUG_BITS;
283 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
284 adpa |= ADPA_HSYNC_ACTIVE_HIGH;
285 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
286 adpa |= ADPA_VSYNC_ACTIVE_HIGH;
288 /* For CPT allow 3 pipe config, for others just use A or B */
289 if (HAS_PCH_LPT(dev))
290 ; /* Those bits don't exist here */
291 else if (HAS_PCH_CPT(dev))
292 adpa |= PORT_TRANS_SEL_CPT(crtc->pipe);
293 else if (crtc->pipe == 0)
294 adpa |= ADPA_PIPE_A_SELECT;
296 adpa |= ADPA_PIPE_B_SELECT;
298 if (!HAS_PCH_SPLIT(dev))
299 I915_WRITE(BCLRPAT(crtc->pipe), 0);
301 I915_WRITE(crt->adpa_reg, adpa);
304 static bool intel_ironlake_crt_detect_hotplug(struct drm_connector *connector)
306 struct drm_device *dev = connector->dev;
307 struct intel_crt *crt = intel_attached_crt(connector);
308 struct drm_i915_private *dev_priv = dev->dev_private;
312 /* The first time through, trigger an explicit detection cycle */
313 if (crt->force_hotplug_required) {
314 bool turn_off_dac = HAS_PCH_SPLIT(dev);
317 crt->force_hotplug_required = 0;
319 save_adpa = adpa = I915_READ(crt->adpa_reg);
320 DRM_DEBUG_KMS("trigger hotplug detect cycle: adpa=0x%x\n", adpa);
322 adpa |= ADPA_CRT_HOTPLUG_FORCE_TRIGGER;
324 adpa &= ~ADPA_DAC_ENABLE;
326 I915_WRITE(crt->adpa_reg, adpa);
328 if (wait_for((I915_READ(crt->adpa_reg) & ADPA_CRT_HOTPLUG_FORCE_TRIGGER) == 0,
330 DRM_DEBUG_KMS("timed out waiting for FORCE_TRIGGER");
333 I915_WRITE(crt->adpa_reg, save_adpa);
334 POSTING_READ(crt->adpa_reg);
338 /* Check the status to see if both blue and green are on now */
339 adpa = I915_READ(crt->adpa_reg);
340 if ((adpa & ADPA_CRT_HOTPLUG_MONITOR_MASK) != 0)
344 DRM_DEBUG_KMS("ironlake hotplug adpa=0x%x, result %d\n", adpa, ret);
349 static bool valleyview_crt_detect_hotplug(struct drm_connector *connector)
351 struct drm_device *dev = connector->dev;
352 struct intel_crt *crt = intel_attached_crt(connector);
353 struct drm_i915_private *dev_priv = dev->dev_private;
358 save_adpa = adpa = I915_READ(crt->adpa_reg);
359 DRM_DEBUG_KMS("trigger hotplug detect cycle: adpa=0x%x\n", adpa);
361 adpa |= ADPA_CRT_HOTPLUG_FORCE_TRIGGER;
363 I915_WRITE(crt->adpa_reg, adpa);
365 if (wait_for((I915_READ(crt->adpa_reg) & ADPA_CRT_HOTPLUG_FORCE_TRIGGER) == 0,
367 DRM_DEBUG_KMS("timed out waiting for FORCE_TRIGGER");
368 I915_WRITE(crt->adpa_reg, save_adpa);
371 /* Check the status to see if both blue and green are on now */
372 adpa = I915_READ(crt->adpa_reg);
373 if ((adpa & ADPA_CRT_HOTPLUG_MONITOR_MASK) != 0)
378 DRM_DEBUG_KMS("valleyview hotplug adpa=0x%x, result %d\n", adpa, ret);
384 * Uses CRT_HOTPLUG_EN and CRT_HOTPLUG_STAT to detect CRT presence.
386 * Not for i915G/i915GM
388 * \return true if CRT is connected.
389 * \return false if CRT is disconnected.
391 static bool intel_crt_detect_hotplug(struct drm_connector *connector)
393 struct drm_device *dev = connector->dev;
394 struct drm_i915_private *dev_priv = dev->dev_private;
395 u32 hotplug_en, orig, stat;
399 if (HAS_PCH_SPLIT(dev))
400 return intel_ironlake_crt_detect_hotplug(connector);
402 if (IS_VALLEYVIEW(dev))
403 return valleyview_crt_detect_hotplug(connector);
406 * On 4 series desktop, CRT detect sequence need to be done twice
407 * to get a reliable result.
410 if (IS_G4X(dev) && !IS_GM45(dev))
414 hotplug_en = orig = I915_READ(PORT_HOTPLUG_EN);
415 hotplug_en |= CRT_HOTPLUG_FORCE_DETECT;
417 for (i = 0; i < tries ; i++) {
418 /* turn on the FORCE_DETECT */
419 I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
420 /* wait for FORCE_DETECT to go off */
421 if (wait_for((I915_READ(PORT_HOTPLUG_EN) &
422 CRT_HOTPLUG_FORCE_DETECT) == 0,
424 DRM_DEBUG_KMS("timed out waiting for FORCE_DETECT to go off");
427 stat = I915_READ(PORT_HOTPLUG_STAT);
428 if ((stat & CRT_HOTPLUG_MONITOR_MASK) != CRT_HOTPLUG_MONITOR_NONE)
431 /* clear the interrupt we just generated, if any */
432 I915_WRITE(PORT_HOTPLUG_STAT, CRT_HOTPLUG_INT_STATUS);
434 /* and put the bits back */
435 I915_WRITE(PORT_HOTPLUG_EN, orig);
440 static struct edid *intel_crt_get_edid(struct drm_connector *connector,
441 struct i2c_adapter *i2c)
445 edid = drm_get_edid(connector, i2c);
447 if (!edid && !intel_gmbus_is_forced_bit(i2c)) {
448 DRM_DEBUG_KMS("CRT GMBUS EDID read failed, retry using GPIO bit-banging\n");
449 intel_gmbus_force_bit(i2c, true);
450 edid = drm_get_edid(connector, i2c);
451 intel_gmbus_force_bit(i2c, false);
457 /* local version of intel_ddc_get_modes() to use intel_crt_get_edid() */
458 static int intel_crt_ddc_get_modes(struct drm_connector *connector,
459 struct i2c_adapter *adapter)
464 edid = intel_crt_get_edid(connector, adapter);
468 ret = intel_connector_update_modes(connector, edid);
474 static bool intel_crt_detect_ddc(struct drm_connector *connector)
476 struct intel_crt *crt = intel_attached_crt(connector);
477 struct drm_i915_private *dev_priv = crt->base.base.dev->dev_private;
479 struct i2c_adapter *i2c;
481 BUG_ON(crt->base.type != INTEL_OUTPUT_ANALOG);
483 i2c = intel_gmbus_get_adapter(dev_priv, dev_priv->vbt.crt_ddc_pin);
484 edid = intel_crt_get_edid(connector, i2c);
487 bool is_digital = edid->input & DRM_EDID_INPUT_DIGITAL;
490 * This may be a DVI-I connector with a shared DDC
491 * link between analog and digital outputs, so we
492 * have to check the EDID input spec of the attached device.
495 DRM_DEBUG_KMS("CRT detected via DDC:0x50 [EDID]\n");
499 DRM_DEBUG_KMS("CRT not detected via DDC:0x50 [EDID reports a digital panel]\n");
501 DRM_DEBUG_KMS("CRT not detected via DDC:0x50 [no valid EDID found]\n");
509 static enum drm_connector_status
510 intel_crt_load_detect(struct intel_crt *crt)
512 struct drm_device *dev = crt->base.base.dev;
513 struct drm_i915_private *dev_priv = dev->dev_private;
514 uint32_t pipe = to_intel_crtc(crt->base.base.crtc)->pipe;
515 uint32_t save_bclrpat;
516 uint32_t save_vtotal;
517 uint32_t vtotal, vactive;
519 uint32_t vblank, vblank_start, vblank_end;
521 uint32_t bclrpat_reg;
525 uint32_t pipeconf_reg;
526 uint32_t pipe_dsl_reg;
528 enum drm_connector_status status;
530 DRM_DEBUG_KMS("starting load-detect on CRT\n");
532 bclrpat_reg = BCLRPAT(pipe);
533 vtotal_reg = VTOTAL(pipe);
534 vblank_reg = VBLANK(pipe);
535 vsync_reg = VSYNC(pipe);
536 pipeconf_reg = PIPECONF(pipe);
537 pipe_dsl_reg = PIPEDSL(pipe);
539 save_bclrpat = I915_READ(bclrpat_reg);
540 save_vtotal = I915_READ(vtotal_reg);
541 vblank = I915_READ(vblank_reg);
543 vtotal = ((save_vtotal >> 16) & 0xfff) + 1;
544 vactive = (save_vtotal & 0x7ff) + 1;
546 vblank_start = (vblank & 0xfff) + 1;
547 vblank_end = ((vblank >> 16) & 0xfff) + 1;
549 /* Set the border color to purple. */
550 I915_WRITE(bclrpat_reg, 0x500050);
553 uint32_t pipeconf = I915_READ(pipeconf_reg);
554 I915_WRITE(pipeconf_reg, pipeconf | PIPECONF_FORCE_BORDER);
555 POSTING_READ(pipeconf_reg);
556 /* Wait for next Vblank to substitue
557 * border color for Color info */
558 intel_wait_for_vblank(dev, pipe);
559 st00 = I915_READ8(VGA_MSR_WRITE);
560 status = ((st00 & (1 << 4)) != 0) ?
561 connector_status_connected :
562 connector_status_disconnected;
564 I915_WRITE(pipeconf_reg, pipeconf);
566 bool restore_vblank = false;
570 * If there isn't any border, add some.
571 * Yes, this will flicker
573 if (vblank_start <= vactive && vblank_end >= vtotal) {
574 uint32_t vsync = I915_READ(vsync_reg);
575 uint32_t vsync_start = (vsync & 0xffff) + 1;
577 vblank_start = vsync_start;
578 I915_WRITE(vblank_reg,
580 ((vblank_end - 1) << 16));
581 restore_vblank = true;
583 /* sample in the vertical border, selecting the larger one */
584 if (vblank_start - vactive >= vtotal - vblank_end)
585 vsample = (vblank_start + vactive) >> 1;
587 vsample = (vtotal + vblank_end) >> 1;
590 * Wait for the border to be displayed
592 while (I915_READ(pipe_dsl_reg) >= vactive)
594 while ((dsl = I915_READ(pipe_dsl_reg)) <= vsample)
597 * Watch ST00 for an entire scanline
603 /* Read the ST00 VGA status register */
604 st00 = I915_READ8(VGA_MSR_WRITE);
607 } while ((I915_READ(pipe_dsl_reg) == dsl));
609 /* restore vblank if necessary */
611 I915_WRITE(vblank_reg, vblank);
613 * If more than 3/4 of the scanline detected a monitor,
614 * then it is assumed to be present. This works even on i830,
615 * where there isn't any way to force the border color across
618 status = detect * 4 > count * 3 ?
619 connector_status_connected :
620 connector_status_disconnected;
623 /* Restore previous settings */
624 I915_WRITE(bclrpat_reg, save_bclrpat);
629 static enum drm_connector_status
630 intel_crt_detect(struct drm_connector *connector, bool force)
632 struct drm_device *dev = connector->dev;
633 struct intel_crt *crt = intel_attached_crt(connector);
634 enum drm_connector_status status;
635 struct intel_load_detect_pipe tmp;
637 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] force=%d\n",
638 connector->base.id, drm_get_connector_name(connector),
641 if (I915_HAS_HOTPLUG(dev)) {
642 /* We can not rely on the HPD pin always being correctly wired
643 * up, for example many KVM do not pass it through, and so
644 * only trust an assertion that the monitor is connected.
646 if (intel_crt_detect_hotplug(connector)) {
647 DRM_DEBUG_KMS("CRT detected via hotplug\n");
648 return connector_status_connected;
650 DRM_DEBUG_KMS("CRT not detected via hotplug\n");
653 if (intel_crt_detect_ddc(connector))
654 return connector_status_connected;
656 /* Load detection is broken on HPD capable machines. Whoever wants a
657 * broken monitor (without edid) to work behind a broken kvm (that fails
658 * to have the right resistors for HP detection) needs to fix this up.
659 * For now just bail out. */
660 if (I915_HAS_HOTPLUG(dev))
661 return connector_status_disconnected;
664 return connector->status;
666 /* for pre-945g platforms use load detect */
667 if (intel_get_load_detect_pipe(connector, NULL, &tmp)) {
668 if (intel_crt_detect_ddc(connector))
669 status = connector_status_connected;
671 status = intel_crt_load_detect(crt);
672 intel_release_load_detect_pipe(connector, &tmp);
674 status = connector_status_unknown;
679 static void intel_crt_destroy(struct drm_connector *connector)
681 drm_connector_cleanup(connector);
685 static int intel_crt_get_modes(struct drm_connector *connector)
687 struct drm_device *dev = connector->dev;
688 struct drm_i915_private *dev_priv = dev->dev_private;
690 struct i2c_adapter *i2c;
692 i2c = intel_gmbus_get_adapter(dev_priv, dev_priv->vbt.crt_ddc_pin);
693 ret = intel_crt_ddc_get_modes(connector, i2c);
694 if (ret || !IS_G4X(dev))
697 /* Try to probe digital port for output in DVI-I -> VGA mode. */
698 i2c = intel_gmbus_get_adapter(dev_priv, GMBUS_PORT_DPB);
699 return intel_crt_ddc_get_modes(connector, i2c);
702 static int intel_crt_set_property(struct drm_connector *connector,
703 struct drm_property *property,
709 static void intel_crt_reset(struct drm_connector *connector)
711 struct drm_device *dev = connector->dev;
712 struct drm_i915_private *dev_priv = dev->dev_private;
713 struct intel_crt *crt = intel_attached_crt(connector);
715 if (INTEL_INFO(dev)->gen >= 5) {
718 adpa = I915_READ(crt->adpa_reg);
719 adpa &= ~ADPA_CRT_HOTPLUG_MASK;
720 adpa |= ADPA_HOTPLUG_BITS;
721 I915_WRITE(crt->adpa_reg, adpa);
722 POSTING_READ(crt->adpa_reg);
724 DRM_DEBUG_KMS("pch crt adpa set to 0x%x\n", adpa);
725 crt->force_hotplug_required = 1;
731 * Routines for controlling stuff on the analog port
734 static const struct drm_connector_funcs intel_crt_connector_funcs = {
735 .reset = intel_crt_reset,
736 .dpms = intel_crt_dpms,
737 .detect = intel_crt_detect,
738 .fill_modes = drm_helper_probe_single_connector_modes,
739 .destroy = intel_crt_destroy,
740 .set_property = intel_crt_set_property,
743 static const struct drm_connector_helper_funcs intel_crt_connector_helper_funcs = {
744 .mode_valid = intel_crt_mode_valid,
745 .get_modes = intel_crt_get_modes,
746 .best_encoder = intel_best_encoder,
749 static const struct drm_encoder_funcs intel_crt_enc_funcs = {
750 .destroy = intel_encoder_destroy,
753 static int __init intel_no_crt_dmi_callback(const struct dmi_system_id *id)
755 DRM_INFO("Skipping CRT initialization for %s\n", id->ident);
759 static const struct dmi_system_id intel_no_crt[] = {
761 .callback = intel_no_crt_dmi_callback,
764 DMI_MATCH(DMI_SYS_VENDOR, "ACER"),
765 DMI_MATCH(DMI_PRODUCT_NAME, "ZGB"),
771 void intel_crt_init(struct drm_device *dev)
773 struct drm_connector *connector;
774 struct intel_crt *crt;
775 struct intel_connector *intel_connector;
776 struct drm_i915_private *dev_priv = dev->dev_private;
778 /* Skip machines without VGA that falsely report hotplug events */
779 if (dmi_check_system(intel_no_crt))
782 crt = kzalloc(sizeof(struct intel_crt), GFP_KERNEL);
786 intel_connector = kzalloc(sizeof(*intel_connector), GFP_KERNEL);
787 if (!intel_connector) {
792 connector = &intel_connector->base;
793 crt->connector = intel_connector;
794 drm_connector_init(dev, &intel_connector->base,
795 &intel_crt_connector_funcs, DRM_MODE_CONNECTOR_VGA);
797 drm_encoder_init(dev, &crt->base.base, &intel_crt_enc_funcs,
798 DRM_MODE_ENCODER_DAC);
800 intel_connector_attach_encoder(intel_connector, &crt->base);
802 crt->base.type = INTEL_OUTPUT_ANALOG;
803 crt->base.cloneable = true;
805 crt->base.crtc_mask = (1 << 0);
807 crt->base.crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
810 connector->interlace_allowed = 0;
812 connector->interlace_allowed = 1;
813 connector->doublescan_allowed = 0;
815 if (HAS_PCH_SPLIT(dev))
816 crt->adpa_reg = PCH_ADPA;
817 else if (IS_VALLEYVIEW(dev))
818 crt->adpa_reg = VLV_ADPA;
820 crt->adpa_reg = ADPA;
822 crt->base.compute_config = intel_crt_compute_config;
823 crt->base.mode_set = intel_crt_mode_set;
824 crt->base.disable = intel_disable_crt;
825 crt->base.enable = intel_enable_crt;
826 if (I915_HAS_HOTPLUG(dev))
827 crt->base.hpd_pin = HPD_CRT;
829 crt->base.get_config = hsw_crt_get_config;
830 crt->base.get_hw_state = intel_ddi_get_hw_state;
832 crt->base.get_config = intel_crt_get_config;
833 crt->base.get_hw_state = intel_crt_get_hw_state;
835 intel_connector->get_hw_state = intel_connector_get_hw_state;
837 drm_connector_helper_add(connector, &intel_crt_connector_helper_funcs);
839 drm_sysfs_connector_add(connector);
841 if (!I915_HAS_HOTPLUG(dev))
842 intel_connector->polled = DRM_CONNECTOR_POLL_CONNECT;
845 * Configure the automatic hotplug detection stuff
847 crt->force_hotplug_required = 0;
850 * TODO: find a proper way to discover whether we need to set the the
851 * polarity and link reversal bits or not, instead of relying on the
854 if (HAS_PCH_LPT(dev)) {
855 u32 fdi_config = FDI_RX_POLARITY_REVERSED_LPT |
856 FDI_RX_LINK_REVERSAL_OVERRIDE;
858 dev_priv->fdi_rx_config = I915_READ(_FDI_RXA_CTL) & fdi_config;