28 #include <linux/i2c.h>
29 #include <linux/slab.h>
35 #include <drm/i915_drm.h>
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)
63 static bool intel_crt_get_hw_state(
struct intel_encoder *encoder,
68 struct intel_crt *crt = intel_encoder_to_crt(encoder);
87 struct intel_crt *crt = intel_encoder_to_crt(encoder);
92 temp &= ~ADPA_DAC_ENABLE;
99 struct intel_crt *crt = intel_encoder_to_crt(encoder);
113 struct intel_crt *crt = intel_encoder_to_crt(encoder);
118 temp &= ~ADPA_DAC_ENABLE;
141 struct intel_encoder *encoder = intel_attached_encoder(connector);
149 if (mode == connector->
dpms)
152 old_dpms = connector->
dpms;
156 crtc = encoder->
base.crtc;
168 if (mode < old_dpms) {
172 intel_crt_set_dpms(encoder, mode);
174 intel_crt_set_dpms(encoder, mode);
182 static int intel_crt_mode_valid(
struct drm_connector *connector,
191 if (mode->
clock < 25000)
198 if (mode->
clock > max_clock)
204 static bool intel_crt_mode_fixup(
struct drm_encoder *encoder,
211 static void intel_crt_mode_set(
struct drm_encoder *encoder,
233 else if (intel_crtc->
pipe == 0)
244 static bool intel_ironlake_crt_detect_hotplug(
struct drm_connector *connector)
247 struct intel_crt *crt = intel_attached_crt(connector);
260 DRM_DEBUG_KMS(
"trigger hotplug detect cycle: adpa=0x%x\n", adpa);
264 adpa &= ~ADPA_DAC_ENABLE;
270 DRM_DEBUG_KMS(
"timed out waiting for FORCE_TRIGGER");
284 DRM_DEBUG_KMS(
"ironlake hotplug adpa=0x%x, result %d\n", adpa, ret);
289 static bool valleyview_crt_detect_hotplug(
struct drm_connector *connector)
298 DRM_DEBUG_KMS(
"trigger hotplug detect cycle: adpa=0x%x\n", adpa);
306 DRM_DEBUG_KMS(
"timed out waiting for FORCE_TRIGGER");
317 DRM_DEBUG_KMS(
"valleyview hotplug adpa=0x%x, result %d\n", adpa, ret);
333 static bool intel_crt_detect_hotplug(
struct drm_connector *connector)
342 return intel_ironlake_crt_detect_hotplug(connector);
345 return valleyview_crt_detect_hotplug(connector);
359 for (i = 0; i < tries ; i++) {
366 DRM_DEBUG_KMS(
"timed out waiting for FORCE_DETECT to go off");
390 DRM_DEBUG_KMS(
"CRT GMBUS EDID read failed, retry using GPIO bit-banging\n");
400 static int intel_crt_ddc_get_modes(
struct drm_connector *connector,
405 edid = intel_crt_get_edid(connector, adapter);
412 static bool intel_crt_detect_ddc(
struct drm_connector *connector)
414 struct intel_crt *crt = intel_attached_crt(connector);
422 edid = intel_crt_get_edid(connector, i2c);
433 DRM_DEBUG_KMS(
"CRT detected via DDC:0x50 [EDID]\n");
437 DRM_DEBUG_KMS(
"CRT not detected via DDC:0x50 [EDID reports a digital panel]\n");
439 DRM_DEBUG_KMS(
"CRT not detected via DDC:0x50 [no valid EDID found]\n");
448 intel_crt_load_detect(
struct intel_crt *crt)
457 uint32_t vblank, vblank_start, vblank_end;
468 DRM_DEBUG_KMS(
"starting load-detect on CRT\n");
471 vtotal_reg =
VTOTAL(pipe);
472 vblank_reg =
VBLANK(pipe);
473 vsync_reg =
VSYNC(pipe);
481 vtotal = ((save_vtotal >> 16) & 0xfff) + 1;
482 vactive = (save_vtotal & 0x7ff) + 1;
484 vblank_start = (vblank & 0xfff) + 1;
485 vblank_end = ((vblank >> 16) & 0xfff) + 1;
498 status = ((st00 & (1 << 4)) != 0) ?
504 bool restore_vblank =
false;
511 if (vblank_start <= vactive && vblank_end >= vtotal) {
513 uint32_t vsync_start = (vsync & 0xffff) + 1;
515 vblank_start = vsync_start;
518 ((vblank_end - 1) << 16));
519 restore_vblank =
true;
522 if (vblank_start - vactive >= vtotal - vblank_end)
523 vsample = (vblank_start + vactive) >> 1;
525 vsample = (vtotal + vblank_end) >> 1;
530 while (
I915_READ(pipe_dsl_reg) >= vactive)
532 while ((dsl =
I915_READ(pipe_dsl_reg)) <= vsample)
545 }
while ((
I915_READ(pipe_dsl_reg) == dsl));
556 status = detect * 4 > count * 3 ?
571 struct intel_crt *crt = intel_attached_crt(connector);
580 if (intel_crt_detect_hotplug(connector)) {
581 DRM_DEBUG_KMS(
"CRT detected via hotplug\n");
584 DRM_DEBUG_KMS(
"CRT not detected via hotplug\n");
587 if (intel_crt_detect_ddc(connector))
602 if (intel_crt_detect_ddc(connector))
605 status = intel_crt_load_detect(crt);
613 static void intel_crt_destroy(
struct drm_connector *connector)
620 static int intel_crt_get_modes(
struct drm_connector *connector)
628 ret = intel_crt_ddc_get_modes(connector, i2c);
634 return intel_crt_ddc_get_modes(connector, i2c);
637 static int intel_crt_set_property(
struct drm_connector *connector,
647 struct intel_crt *crt = intel_attached_crt(connector);
658 .mode_fixup = intel_crt_mode_fixup,
659 .mode_set = intel_crt_mode_set,
664 .reset = intel_crt_reset,
665 .dpms = intel_crt_dpms,
666 .detect = intel_crt_detect,
668 .destroy = intel_crt_destroy,
669 .set_property = intel_crt_set_property,
673 .mode_valid = intel_crt_mode_valid,
674 .get_modes = intel_crt_get_modes,
684 DRM_INFO(
"Skipping CRT initialization for %s\n", id->
ident);
690 .callback = intel_no_crt_dmi_callback,
715 intel_connector = kzalloc(
sizeof(
struct intel_connector),
GFP_KERNEL);
716 if (!intel_connector) {
721 connector = &intel_connector->
base;
731 crt->
base.cloneable =
true;
733 crt->
base.crtc_mask = (1 << 0);
735 crt->
base.crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
750 crt->
base.disable = intel_disable_crt;
751 crt->
base.enable = intel_enable_crt;
752 crt->
base.get_hw_state = intel_crt_get_hw_state;
755 drm_encoder_helper_add(&crt->
base.base, &crt_encoder_funcs);
756 drm_connector_helper_add(connector, &intel_crt_connector_helper_funcs);
778 DRM_DEBUG_KMS(
"pch crt adpa set to 0x%x\n", adpa);