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