UAPI: (Scripted) Convert #include "..." to #include <path/...> in drivers/gpu/
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / gpu / drm / i915 / intel_crt.c
1 /*
2 * Copyright © 2006-2007 Intel Corporation
3 *
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:
10 *
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
13 * Software.
14 *
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.
22 *
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
25 */
26
27 #include <linux/dmi.h>
28 #include <linux/i2c.h>
29 #include <linux/slab.h>
30 #include <drm/drmP.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>
36 #include "i915_drv.h"
37
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)
45
46 struct intel_crt {
47 struct intel_encoder base;
48 bool force_hotplug_required;
49 };
50
51 static struct intel_crt *intel_attached_crt(struct drm_connector *connector)
52 {
53 return container_of(intel_attached_encoder(connector),
54 struct intel_crt, base);
55 }
56
57 static void pch_crt_dpms(struct drm_encoder *encoder, int mode)
58 {
59 struct drm_device *dev = encoder->dev;
60 struct drm_i915_private *dev_priv = dev->dev_private;
61 u32 temp;
62
63 temp = I915_READ(PCH_ADPA);
64 temp &= ~ADPA_DAC_ENABLE;
65
66 switch (mode) {
67 case DRM_MODE_DPMS_ON:
68 temp |= ADPA_DAC_ENABLE;
69 break;
70 case DRM_MODE_DPMS_STANDBY:
71 case DRM_MODE_DPMS_SUSPEND:
72 case DRM_MODE_DPMS_OFF:
73 /* Just leave port enable cleared */
74 break;
75 }
76
77 I915_WRITE(PCH_ADPA, temp);
78 }
79
80 static void gmch_crt_dpms(struct drm_encoder *encoder, int mode)
81 {
82 struct drm_device *dev = encoder->dev;
83 struct drm_i915_private *dev_priv = dev->dev_private;
84 u32 temp;
85
86 temp = I915_READ(ADPA);
87 temp &= ~(ADPA_HSYNC_CNTL_DISABLE | ADPA_VSYNC_CNTL_DISABLE);
88 temp &= ~ADPA_DAC_ENABLE;
89
90 if (IS_VALLEYVIEW(dev) && mode != DRM_MODE_DPMS_ON)
91 mode = DRM_MODE_DPMS_OFF;
92
93 switch (mode) {
94 case DRM_MODE_DPMS_ON:
95 temp |= ADPA_DAC_ENABLE;
96 break;
97 case DRM_MODE_DPMS_STANDBY:
98 temp |= ADPA_DAC_ENABLE | ADPA_HSYNC_CNTL_DISABLE;
99 break;
100 case DRM_MODE_DPMS_SUSPEND:
101 temp |= ADPA_DAC_ENABLE | ADPA_VSYNC_CNTL_DISABLE;
102 break;
103 case DRM_MODE_DPMS_OFF:
104 temp |= ADPA_HSYNC_CNTL_DISABLE | ADPA_VSYNC_CNTL_DISABLE;
105 break;
106 }
107
108 I915_WRITE(ADPA, temp);
109 }
110
111 static int intel_crt_mode_valid(struct drm_connector *connector,
112 struct drm_display_mode *mode)
113 {
114 struct drm_device *dev = connector->dev;
115
116 int max_clock = 0;
117 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
118 return MODE_NO_DBLESCAN;
119
120 if (mode->clock < 25000)
121 return MODE_CLOCK_LOW;
122
123 if (IS_GEN2(dev))
124 max_clock = 350000;
125 else
126 max_clock = 400000;
127 if (mode->clock > max_clock)
128 return MODE_CLOCK_HIGH;
129
130 return MODE_OK;
131 }
132
133 static bool intel_crt_mode_fixup(struct drm_encoder *encoder,
134 const struct drm_display_mode *mode,
135 struct drm_display_mode *adjusted_mode)
136 {
137 return true;
138 }
139
140 static void intel_crt_mode_set(struct drm_encoder *encoder,
141 struct drm_display_mode *mode,
142 struct drm_display_mode *adjusted_mode)
143 {
144
145 struct drm_device *dev = encoder->dev;
146 struct drm_crtc *crtc = encoder->crtc;
147 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
148 struct drm_i915_private *dev_priv = dev->dev_private;
149 int dpll_md_reg;
150 u32 adpa, dpll_md;
151 u32 adpa_reg;
152
153 dpll_md_reg = DPLL_MD(intel_crtc->pipe);
154
155 if (HAS_PCH_SPLIT(dev))
156 adpa_reg = PCH_ADPA;
157 else
158 adpa_reg = ADPA;
159
160 /*
161 * Disable separate mode multiplier used when cloning SDVO to CRT
162 * XXX this needs to be adjusted when we really are cloning
163 */
164 if (INTEL_INFO(dev)->gen >= 4 && !HAS_PCH_SPLIT(dev)) {
165 dpll_md = I915_READ(dpll_md_reg);
166 I915_WRITE(dpll_md_reg,
167 dpll_md & ~DPLL_MD_UDI_MULTIPLIER_MASK);
168 }
169
170 adpa = ADPA_HOTPLUG_BITS;
171 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
172 adpa |= ADPA_HSYNC_ACTIVE_HIGH;
173 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
174 adpa |= ADPA_VSYNC_ACTIVE_HIGH;
175
176 /* For CPT allow 3 pipe config, for others just use A or B */
177 if (HAS_PCH_CPT(dev))
178 adpa |= PORT_TRANS_SEL_CPT(intel_crtc->pipe);
179 else if (intel_crtc->pipe == 0)
180 adpa |= ADPA_PIPE_A_SELECT;
181 else
182 adpa |= ADPA_PIPE_B_SELECT;
183
184 if (!HAS_PCH_SPLIT(dev))
185 I915_WRITE(BCLRPAT(intel_crtc->pipe), 0);
186
187 I915_WRITE(adpa_reg, adpa);
188 }
189
190 static bool intel_ironlake_crt_detect_hotplug(struct drm_connector *connector)
191 {
192 struct drm_device *dev = connector->dev;
193 struct intel_crt *crt = intel_attached_crt(connector);
194 struct drm_i915_private *dev_priv = dev->dev_private;
195 u32 adpa;
196 bool ret;
197
198 /* The first time through, trigger an explicit detection cycle */
199 if (crt->force_hotplug_required) {
200 bool turn_off_dac = HAS_PCH_SPLIT(dev);
201 u32 save_adpa;
202
203 crt->force_hotplug_required = 0;
204
205 save_adpa = adpa = I915_READ(PCH_ADPA);
206 DRM_DEBUG_KMS("trigger hotplug detect cycle: adpa=0x%x\n", adpa);
207
208 adpa |= ADPA_CRT_HOTPLUG_FORCE_TRIGGER;
209 if (turn_off_dac)
210 adpa &= ~ADPA_DAC_ENABLE;
211
212 I915_WRITE(PCH_ADPA, adpa);
213
214 if (wait_for((I915_READ(PCH_ADPA) & ADPA_CRT_HOTPLUG_FORCE_TRIGGER) == 0,
215 1000))
216 DRM_DEBUG_KMS("timed out waiting for FORCE_TRIGGER");
217
218 if (turn_off_dac) {
219 I915_WRITE(PCH_ADPA, save_adpa);
220 POSTING_READ(PCH_ADPA);
221 }
222 }
223
224 /* Check the status to see if both blue and green are on now */
225 adpa = I915_READ(PCH_ADPA);
226 if ((adpa & ADPA_CRT_HOTPLUG_MONITOR_MASK) != 0)
227 ret = true;
228 else
229 ret = false;
230 DRM_DEBUG_KMS("ironlake hotplug adpa=0x%x, result %d\n", adpa, ret);
231
232 return ret;
233 }
234
235 static bool valleyview_crt_detect_hotplug(struct drm_connector *connector)
236 {
237 struct drm_device *dev = connector->dev;
238 struct drm_i915_private *dev_priv = dev->dev_private;
239 u32 adpa;
240 bool ret;
241 u32 save_adpa;
242
243 save_adpa = adpa = I915_READ(ADPA);
244 DRM_DEBUG_KMS("trigger hotplug detect cycle: adpa=0x%x\n", adpa);
245
246 adpa |= ADPA_CRT_HOTPLUG_FORCE_TRIGGER;
247
248 I915_WRITE(ADPA, adpa);
249
250 if (wait_for((I915_READ(ADPA) & ADPA_CRT_HOTPLUG_FORCE_TRIGGER) == 0,
251 1000)) {
252 DRM_DEBUG_KMS("timed out waiting for FORCE_TRIGGER");
253 I915_WRITE(ADPA, save_adpa);
254 }
255
256 /* Check the status to see if both blue and green are on now */
257 adpa = I915_READ(ADPA);
258 if ((adpa & ADPA_CRT_HOTPLUG_MONITOR_MASK) != 0)
259 ret = true;
260 else
261 ret = false;
262
263 DRM_DEBUG_KMS("valleyview hotplug adpa=0x%x, result %d\n", adpa, ret);
264
265 /* FIXME: debug force function and remove */
266 ret = true;
267
268 return ret;
269 }
270
271 /**
272 * Uses CRT_HOTPLUG_EN and CRT_HOTPLUG_STAT to detect CRT presence.
273 *
274 * Not for i915G/i915GM
275 *
276 * \return true if CRT is connected.
277 * \return false if CRT is disconnected.
278 */
279 static bool intel_crt_detect_hotplug(struct drm_connector *connector)
280 {
281 struct drm_device *dev = connector->dev;
282 struct drm_i915_private *dev_priv = dev->dev_private;
283 u32 hotplug_en, orig, stat;
284 bool ret = false;
285 int i, tries = 0;
286
287 if (HAS_PCH_SPLIT(dev))
288 return intel_ironlake_crt_detect_hotplug(connector);
289
290 if (IS_VALLEYVIEW(dev))
291 return valleyview_crt_detect_hotplug(connector);
292
293 /*
294 * On 4 series desktop, CRT detect sequence need to be done twice
295 * to get a reliable result.
296 */
297
298 if (IS_G4X(dev) && !IS_GM45(dev))
299 tries = 2;
300 else
301 tries = 1;
302 hotplug_en = orig = I915_READ(PORT_HOTPLUG_EN);
303 hotplug_en |= CRT_HOTPLUG_FORCE_DETECT;
304
305 for (i = 0; i < tries ; i++) {
306 /* turn on the FORCE_DETECT */
307 I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
308 /* wait for FORCE_DETECT to go off */
309 if (wait_for((I915_READ(PORT_HOTPLUG_EN) &
310 CRT_HOTPLUG_FORCE_DETECT) == 0,
311 1000))
312 DRM_DEBUG_KMS("timed out waiting for FORCE_DETECT to go off");
313 }
314
315 stat = I915_READ(PORT_HOTPLUG_STAT);
316 if ((stat & CRT_HOTPLUG_MONITOR_MASK) != CRT_HOTPLUG_MONITOR_NONE)
317 ret = true;
318
319 /* clear the interrupt we just generated, if any */
320 I915_WRITE(PORT_HOTPLUG_STAT, CRT_HOTPLUG_INT_STATUS);
321
322 /* and put the bits back */
323 I915_WRITE(PORT_HOTPLUG_EN, orig);
324
325 return ret;
326 }
327
328 static struct edid *intel_crt_get_edid(struct drm_connector *connector,
329 struct i2c_adapter *i2c)
330 {
331 struct edid *edid;
332
333 edid = drm_get_edid(connector, i2c);
334
335 if (!edid && !intel_gmbus_is_forced_bit(i2c)) {
336 DRM_DEBUG_KMS("CRT GMBUS EDID read failed, retry using GPIO bit-banging\n");
337 intel_gmbus_force_bit(i2c, true);
338 edid = drm_get_edid(connector, i2c);
339 intel_gmbus_force_bit(i2c, false);
340 }
341
342 return edid;
343 }
344
345 /* local version of intel_ddc_get_modes() to use intel_crt_get_edid() */
346 static int intel_crt_ddc_get_modes(struct drm_connector *connector,
347 struct i2c_adapter *adapter)
348 {
349 struct edid *edid;
350
351 edid = intel_crt_get_edid(connector, adapter);
352 if (!edid)
353 return 0;
354
355 return intel_connector_update_modes(connector, edid);
356 }
357
358 static bool intel_crt_detect_ddc(struct drm_connector *connector)
359 {
360 struct intel_crt *crt = intel_attached_crt(connector);
361 struct drm_i915_private *dev_priv = crt->base.base.dev->dev_private;
362 struct edid *edid;
363 struct i2c_adapter *i2c;
364
365 BUG_ON(crt->base.type != INTEL_OUTPUT_ANALOG);
366
367 i2c = intel_gmbus_get_adapter(dev_priv, dev_priv->crt_ddc_pin);
368 edid = intel_crt_get_edid(connector, i2c);
369
370 if (edid) {
371 bool is_digital = edid->input & DRM_EDID_INPUT_DIGITAL;
372
373 /*
374 * This may be a DVI-I connector with a shared DDC
375 * link between analog and digital outputs, so we
376 * have to check the EDID input spec of the attached device.
377 */
378 if (!is_digital) {
379 DRM_DEBUG_KMS("CRT detected via DDC:0x50 [EDID]\n");
380 return true;
381 }
382
383 DRM_DEBUG_KMS("CRT not detected via DDC:0x50 [EDID reports a digital panel]\n");
384 } else {
385 DRM_DEBUG_KMS("CRT not detected via DDC:0x50 [no valid EDID found]\n");
386 }
387
388 kfree(edid);
389
390 return false;
391 }
392
393 static enum drm_connector_status
394 intel_crt_load_detect(struct intel_crt *crt)
395 {
396 struct drm_device *dev = crt->base.base.dev;
397 struct drm_i915_private *dev_priv = dev->dev_private;
398 uint32_t pipe = to_intel_crtc(crt->base.base.crtc)->pipe;
399 uint32_t save_bclrpat;
400 uint32_t save_vtotal;
401 uint32_t vtotal, vactive;
402 uint32_t vsample;
403 uint32_t vblank, vblank_start, vblank_end;
404 uint32_t dsl;
405 uint32_t bclrpat_reg;
406 uint32_t vtotal_reg;
407 uint32_t vblank_reg;
408 uint32_t vsync_reg;
409 uint32_t pipeconf_reg;
410 uint32_t pipe_dsl_reg;
411 uint8_t st00;
412 enum drm_connector_status status;
413
414 DRM_DEBUG_KMS("starting load-detect on CRT\n");
415
416 bclrpat_reg = BCLRPAT(pipe);
417 vtotal_reg = VTOTAL(pipe);
418 vblank_reg = VBLANK(pipe);
419 vsync_reg = VSYNC(pipe);
420 pipeconf_reg = PIPECONF(pipe);
421 pipe_dsl_reg = PIPEDSL(pipe);
422
423 save_bclrpat = I915_READ(bclrpat_reg);
424 save_vtotal = I915_READ(vtotal_reg);
425 vblank = I915_READ(vblank_reg);
426
427 vtotal = ((save_vtotal >> 16) & 0xfff) + 1;
428 vactive = (save_vtotal & 0x7ff) + 1;
429
430 vblank_start = (vblank & 0xfff) + 1;
431 vblank_end = ((vblank >> 16) & 0xfff) + 1;
432
433 /* Set the border color to purple. */
434 I915_WRITE(bclrpat_reg, 0x500050);
435
436 if (!IS_GEN2(dev)) {
437 uint32_t pipeconf = I915_READ(pipeconf_reg);
438 I915_WRITE(pipeconf_reg, pipeconf | PIPECONF_FORCE_BORDER);
439 POSTING_READ(pipeconf_reg);
440 /* Wait for next Vblank to substitue
441 * border color for Color info */
442 intel_wait_for_vblank(dev, pipe);
443 st00 = I915_READ8(VGA_MSR_WRITE);
444 status = ((st00 & (1 << 4)) != 0) ?
445 connector_status_connected :
446 connector_status_disconnected;
447
448 I915_WRITE(pipeconf_reg, pipeconf);
449 } else {
450 bool restore_vblank = false;
451 int count, detect;
452
453 /*
454 * If there isn't any border, add some.
455 * Yes, this will flicker
456 */
457 if (vblank_start <= vactive && vblank_end >= vtotal) {
458 uint32_t vsync = I915_READ(vsync_reg);
459 uint32_t vsync_start = (vsync & 0xffff) + 1;
460
461 vblank_start = vsync_start;
462 I915_WRITE(vblank_reg,
463 (vblank_start - 1) |
464 ((vblank_end - 1) << 16));
465 restore_vblank = true;
466 }
467 /* sample in the vertical border, selecting the larger one */
468 if (vblank_start - vactive >= vtotal - vblank_end)
469 vsample = (vblank_start + vactive) >> 1;
470 else
471 vsample = (vtotal + vblank_end) >> 1;
472
473 /*
474 * Wait for the border to be displayed
475 */
476 while (I915_READ(pipe_dsl_reg) >= vactive)
477 ;
478 while ((dsl = I915_READ(pipe_dsl_reg)) <= vsample)
479 ;
480 /*
481 * Watch ST00 for an entire scanline
482 */
483 detect = 0;
484 count = 0;
485 do {
486 count++;
487 /* Read the ST00 VGA status register */
488 st00 = I915_READ8(VGA_MSR_WRITE);
489 if (st00 & (1 << 4))
490 detect++;
491 } while ((I915_READ(pipe_dsl_reg) == dsl));
492
493 /* restore vblank if necessary */
494 if (restore_vblank)
495 I915_WRITE(vblank_reg, vblank);
496 /*
497 * If more than 3/4 of the scanline detected a monitor,
498 * then it is assumed to be present. This works even on i830,
499 * where there isn't any way to force the border color across
500 * the screen
501 */
502 status = detect * 4 > count * 3 ?
503 connector_status_connected :
504 connector_status_disconnected;
505 }
506
507 /* Restore previous settings */
508 I915_WRITE(bclrpat_reg, save_bclrpat);
509
510 return status;
511 }
512
513 static enum drm_connector_status
514 intel_crt_detect(struct drm_connector *connector, bool force)
515 {
516 struct drm_device *dev = connector->dev;
517 struct intel_crt *crt = intel_attached_crt(connector);
518 enum drm_connector_status status;
519 struct intel_load_detect_pipe tmp;
520
521 if (I915_HAS_HOTPLUG(dev)) {
522 /* We can not rely on the HPD pin always being correctly wired
523 * up, for example many KVM do not pass it through, and so
524 * only trust an assertion that the monitor is connected.
525 */
526 if (intel_crt_detect_hotplug(connector)) {
527 DRM_DEBUG_KMS("CRT detected via hotplug\n");
528 return connector_status_connected;
529 } else
530 DRM_DEBUG_KMS("CRT not detected via hotplug\n");
531 }
532
533 if (intel_crt_detect_ddc(connector))
534 return connector_status_connected;
535
536 /* Load detection is broken on HPD capable machines. Whoever wants a
537 * broken monitor (without edid) to work behind a broken kvm (that fails
538 * to have the right resistors for HP detection) needs to fix this up.
539 * For now just bail out. */
540 if (I915_HAS_HOTPLUG(dev))
541 return connector_status_disconnected;
542
543 if (!force)
544 return connector->status;
545
546 /* for pre-945g platforms use load detect */
547 if (intel_get_load_detect_pipe(&crt->base, connector, NULL,
548 &tmp)) {
549 if (intel_crt_detect_ddc(connector))
550 status = connector_status_connected;
551 else
552 status = intel_crt_load_detect(crt);
553 intel_release_load_detect_pipe(&crt->base, connector,
554 &tmp);
555 } else
556 status = connector_status_unknown;
557
558 return status;
559 }
560
561 static void intel_crt_destroy(struct drm_connector *connector)
562 {
563 drm_sysfs_connector_remove(connector);
564 drm_connector_cleanup(connector);
565 kfree(connector);
566 }
567
568 static int intel_crt_get_modes(struct drm_connector *connector)
569 {
570 struct drm_device *dev = connector->dev;
571 struct drm_i915_private *dev_priv = dev->dev_private;
572 int ret;
573 struct i2c_adapter *i2c;
574
575 i2c = intel_gmbus_get_adapter(dev_priv, dev_priv->crt_ddc_pin);
576 ret = intel_crt_ddc_get_modes(connector, i2c);
577 if (ret || !IS_G4X(dev))
578 return ret;
579
580 /* Try to probe digital port for output in DVI-I -> VGA mode. */
581 i2c = intel_gmbus_get_adapter(dev_priv, GMBUS_PORT_DPB);
582 return intel_crt_ddc_get_modes(connector, i2c);
583 }
584
585 static int intel_crt_set_property(struct drm_connector *connector,
586 struct drm_property *property,
587 uint64_t value)
588 {
589 return 0;
590 }
591
592 static void intel_crt_reset(struct drm_connector *connector)
593 {
594 struct drm_device *dev = connector->dev;
595 struct intel_crt *crt = intel_attached_crt(connector);
596
597 if (HAS_PCH_SPLIT(dev))
598 crt->force_hotplug_required = 1;
599 }
600
601 /*
602 * Routines for controlling stuff on the analog port
603 */
604
605 static const struct drm_encoder_helper_funcs pch_encoder_funcs = {
606 .mode_fixup = intel_crt_mode_fixup,
607 .prepare = intel_encoder_prepare,
608 .commit = intel_encoder_commit,
609 .mode_set = intel_crt_mode_set,
610 .dpms = pch_crt_dpms,
611 };
612
613 static const struct drm_encoder_helper_funcs gmch_encoder_funcs = {
614 .mode_fixup = intel_crt_mode_fixup,
615 .prepare = intel_encoder_prepare,
616 .commit = intel_encoder_commit,
617 .mode_set = intel_crt_mode_set,
618 .dpms = gmch_crt_dpms,
619 };
620
621 static const struct drm_connector_funcs intel_crt_connector_funcs = {
622 .reset = intel_crt_reset,
623 .dpms = drm_helper_connector_dpms,
624 .detect = intel_crt_detect,
625 .fill_modes = drm_helper_probe_single_connector_modes,
626 .destroy = intel_crt_destroy,
627 .set_property = intel_crt_set_property,
628 };
629
630 static const struct drm_connector_helper_funcs intel_crt_connector_helper_funcs = {
631 .mode_valid = intel_crt_mode_valid,
632 .get_modes = intel_crt_get_modes,
633 .best_encoder = intel_best_encoder,
634 };
635
636 static const struct drm_encoder_funcs intel_crt_enc_funcs = {
637 .destroy = intel_encoder_destroy,
638 };
639
640 static int __init intel_no_crt_dmi_callback(const struct dmi_system_id *id)
641 {
642 DRM_INFO("Skipping CRT initialization for %s\n", id->ident);
643 return 1;
644 }
645
646 static const struct dmi_system_id intel_no_crt[] = {
647 {
648 .callback = intel_no_crt_dmi_callback,
649 .ident = "ACER ZGB",
650 .matches = {
651 DMI_MATCH(DMI_SYS_VENDOR, "ACER"),
652 DMI_MATCH(DMI_PRODUCT_NAME, "ZGB"),
653 },
654 },
655 { }
656 };
657
658 void intel_crt_init(struct drm_device *dev)
659 {
660 struct drm_connector *connector;
661 struct intel_crt *crt;
662 struct intel_connector *intel_connector;
663 struct drm_i915_private *dev_priv = dev->dev_private;
664 const struct drm_encoder_helper_funcs *encoder_helper_funcs;
665
666 /* Skip machines without VGA that falsely report hotplug events */
667 if (dmi_check_system(intel_no_crt))
668 return;
669
670 crt = kzalloc(sizeof(struct intel_crt), GFP_KERNEL);
671 if (!crt)
672 return;
673
674 intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL);
675 if (!intel_connector) {
676 kfree(crt);
677 return;
678 }
679
680 connector = &intel_connector->base;
681 drm_connector_init(dev, &intel_connector->base,
682 &intel_crt_connector_funcs, DRM_MODE_CONNECTOR_VGA);
683
684 drm_encoder_init(dev, &crt->base.base, &intel_crt_enc_funcs,
685 DRM_MODE_ENCODER_DAC);
686
687 intel_connector_attach_encoder(intel_connector, &crt->base);
688
689 crt->base.type = INTEL_OUTPUT_ANALOG;
690 crt->base.clone_mask = (1 << INTEL_SDVO_NON_TV_CLONE_BIT |
691 1 << INTEL_ANALOG_CLONE_BIT |
692 1 << INTEL_SDVO_LVDS_CLONE_BIT);
693 if (IS_HASWELL(dev))
694 crt->base.crtc_mask = (1 << 0);
695 else
696 crt->base.crtc_mask = (1 << 0) | (1 << 1);
697
698 if (IS_GEN2(dev))
699 connector->interlace_allowed = 0;
700 else
701 connector->interlace_allowed = 1;
702 connector->doublescan_allowed = 0;
703
704 if (HAS_PCH_SPLIT(dev))
705 encoder_helper_funcs = &pch_encoder_funcs;
706 else
707 encoder_helper_funcs = &gmch_encoder_funcs;
708
709 drm_encoder_helper_add(&crt->base.base, encoder_helper_funcs);
710 drm_connector_helper_add(connector, &intel_crt_connector_helper_funcs);
711
712 drm_sysfs_connector_add(connector);
713
714 if (I915_HAS_HOTPLUG(dev))
715 connector->polled = DRM_CONNECTOR_POLL_HPD;
716 else
717 connector->polled = DRM_CONNECTOR_POLL_CONNECT;
718
719 /*
720 * Configure the automatic hotplug detection stuff
721 */
722 crt->force_hotplug_required = 0;
723 if (HAS_PCH_SPLIT(dev)) {
724 u32 adpa;
725
726 adpa = I915_READ(PCH_ADPA);
727 adpa &= ~ADPA_CRT_HOTPLUG_MASK;
728 adpa |= ADPA_HOTPLUG_BITS;
729 I915_WRITE(PCH_ADPA, adpa);
730 POSTING_READ(PCH_ADPA);
731
732 DRM_DEBUG_KMS("pch crt adpa set to 0x%x\n", adpa);
733 crt->force_hotplug_required = 1;
734 }
735
736 dev_priv->hotplug_supported_mask |= CRT_HOTPLUG_INT_STATUS;
737 }