blob: 1f732ba568f6a7755c871d75b96f8e28f4e7a6e7 [file] [log] [blame]
Jesse Barnes79e53942008-11-07 14:24:08 -08001/*
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/i2c.h>
28#include "drmP.h"
29#include "drm.h"
30#include "drm_crtc.h"
31#include "drm_crtc_helper.h"
32#include "intel_drv.h"
33#include "i915_drm.h"
34#include "i915_drv.h"
35
36static void intel_crt_dpms(struct drm_encoder *encoder, int mode)
37{
38 struct drm_device *dev = encoder->dev;
39 struct drm_i915_private *dev_priv = dev->dev_private;
Zhenyu Wang2c072452009-06-05 15:38:42 +080040 u32 temp, reg;
Jesse Barnes79e53942008-11-07 14:24:08 -080041
Eric Anholtbad720f2009-10-22 16:11:14 -070042 if (HAS_PCH_SPLIT(dev))
Zhenyu Wang2c072452009-06-05 15:38:42 +080043 reg = PCH_ADPA;
44 else
45 reg = ADPA;
46
47 temp = I915_READ(reg);
Jesse Barnes79e53942008-11-07 14:24:08 -080048 temp &= ~(ADPA_HSYNC_CNTL_DISABLE | ADPA_VSYNC_CNTL_DISABLE);
ling.ma@intel.comfebc7692009-06-25 11:55:57 +080049 temp &= ~ADPA_DAC_ENABLE;
Jesse Barnes79e53942008-11-07 14:24:08 -080050
51 switch(mode) {
52 case DRM_MODE_DPMS_ON:
53 temp |= ADPA_DAC_ENABLE;
54 break;
55 case DRM_MODE_DPMS_STANDBY:
56 temp |= ADPA_DAC_ENABLE | ADPA_HSYNC_CNTL_DISABLE;
57 break;
58 case DRM_MODE_DPMS_SUSPEND:
59 temp |= ADPA_DAC_ENABLE | ADPA_VSYNC_CNTL_DISABLE;
60 break;
61 case DRM_MODE_DPMS_OFF:
62 temp |= ADPA_HSYNC_CNTL_DISABLE | ADPA_VSYNC_CNTL_DISABLE;
63 break;
64 }
65
Zhenyu Wang2c072452009-06-05 15:38:42 +080066 I915_WRITE(reg, temp);
Jesse Barnes79e53942008-11-07 14:24:08 -080067}
68
69static int intel_crt_mode_valid(struct drm_connector *connector,
70 struct drm_display_mode *mode)
71{
Zhao Yakui6bcdcd92009-03-03 18:06:42 +080072 struct drm_device *dev = connector->dev;
73
74 int max_clock = 0;
Jesse Barnes79e53942008-11-07 14:24:08 -080075 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
76 return MODE_NO_DBLESCAN;
77
Zhao Yakui6bcdcd92009-03-03 18:06:42 +080078 if (mode->clock < 25000)
79 return MODE_CLOCK_LOW;
80
81 if (!IS_I9XX(dev))
82 max_clock = 350000;
83 else
84 max_clock = 400000;
85 if (mode->clock > max_clock)
86 return MODE_CLOCK_HIGH;
Jesse Barnes79e53942008-11-07 14:24:08 -080087
88 return MODE_OK;
89}
90
91static bool intel_crt_mode_fixup(struct drm_encoder *encoder,
92 struct drm_display_mode *mode,
93 struct drm_display_mode *adjusted_mode)
94{
95 return true;
96}
97
98static void intel_crt_mode_set(struct drm_encoder *encoder,
99 struct drm_display_mode *mode,
100 struct drm_display_mode *adjusted_mode)
101{
102
103 struct drm_device *dev = encoder->dev;
104 struct drm_crtc *crtc = encoder->crtc;
105 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
106 struct drm_i915_private *dev_priv = dev->dev_private;
107 int dpll_md_reg;
108 u32 adpa, dpll_md;
Zhenyu Wang2c072452009-06-05 15:38:42 +0800109 u32 adpa_reg;
Jesse Barnes79e53942008-11-07 14:24:08 -0800110
111 if (intel_crtc->pipe == 0)
112 dpll_md_reg = DPLL_A_MD;
113 else
114 dpll_md_reg = DPLL_B_MD;
115
Eric Anholtbad720f2009-10-22 16:11:14 -0700116 if (HAS_PCH_SPLIT(dev))
Zhenyu Wang2c072452009-06-05 15:38:42 +0800117 adpa_reg = PCH_ADPA;
118 else
119 adpa_reg = ADPA;
120
Jesse Barnes79e53942008-11-07 14:24:08 -0800121 /*
122 * Disable separate mode multiplier used when cloning SDVO to CRT
123 * XXX this needs to be adjusted when we really are cloning
124 */
Eric Anholtbad720f2009-10-22 16:11:14 -0700125 if (IS_I965G(dev) && !HAS_PCH_SPLIT(dev)) {
Jesse Barnes79e53942008-11-07 14:24:08 -0800126 dpll_md = I915_READ(dpll_md_reg);
127 I915_WRITE(dpll_md_reg,
128 dpll_md & ~DPLL_MD_UDI_MULTIPLIER_MASK);
129 }
130
131 adpa = 0;
132 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
133 adpa |= ADPA_HSYNC_ACTIVE_HIGH;
134 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
135 adpa |= ADPA_VSYNC_ACTIVE_HIGH;
136
Zhao Yakui6bcdcd92009-03-03 18:06:42 +0800137 if (intel_crtc->pipe == 0) {
Zhenyu Wang8db9d772010-04-07 16:15:54 +0800138 if (HAS_PCH_CPT(dev))
139 adpa |= PORT_TRANS_A_SEL_CPT;
140 else
141 adpa |= ADPA_PIPE_A_SELECT;
Eric Anholtbad720f2009-10-22 16:11:14 -0700142 if (!HAS_PCH_SPLIT(dev))
Zhenyu Wang2c072452009-06-05 15:38:42 +0800143 I915_WRITE(BCLRPAT_A, 0);
Zhao Yakui6bcdcd92009-03-03 18:06:42 +0800144 } else {
Zhenyu Wang8db9d772010-04-07 16:15:54 +0800145 if (HAS_PCH_CPT(dev))
146 adpa |= PORT_TRANS_B_SEL_CPT;
147 else
148 adpa |= ADPA_PIPE_B_SELECT;
Eric Anholtbad720f2009-10-22 16:11:14 -0700149 if (!HAS_PCH_SPLIT(dev))
Zhenyu Wang2c072452009-06-05 15:38:42 +0800150 I915_WRITE(BCLRPAT_B, 0);
Zhao Yakui6bcdcd92009-03-03 18:06:42 +0800151 }
Jesse Barnes79e53942008-11-07 14:24:08 -0800152
Zhenyu Wang2c072452009-06-05 15:38:42 +0800153 I915_WRITE(adpa_reg, adpa);
154}
155
Adam Jacksonf2b115e2009-12-03 17:14:42 -0500156static bool intel_ironlake_crt_detect_hotplug(struct drm_connector *connector)
Zhenyu Wang2c072452009-06-05 15:38:42 +0800157{
158 struct drm_device *dev = connector->dev;
159 struct drm_i915_private *dev_priv = dev->dev_private;
Zhenyu Wang730915d2009-09-19 14:54:08 +0800160 u32 adpa;
Zhenyu Wang2c072452009-06-05 15:38:42 +0800161 bool ret;
162
Zhenyu Wang730915d2009-09-19 14:54:08 +0800163 adpa = I915_READ(PCH_ADPA);
Zhenyu Wang67941da2009-07-24 01:00:33 +0800164
Zhenyu Wang2c072452009-06-05 15:38:42 +0800165 adpa &= ~ADPA_CRT_HOTPLUG_MASK;
Zhenyu Wangeceb7842010-01-25 10:35:16 +0800166 /* disable HPD first */
167 I915_WRITE(PCH_ADPA, adpa);
168 (void)I915_READ(PCH_ADPA);
Zhenyu Wang2c072452009-06-05 15:38:42 +0800169
170 adpa |= (ADPA_CRT_HOTPLUG_PERIOD_128 |
171 ADPA_CRT_HOTPLUG_WARMUP_10MS |
172 ADPA_CRT_HOTPLUG_SAMPLE_4S |
173 ADPA_CRT_HOTPLUG_VOLTAGE_50 | /* default */
174 ADPA_CRT_HOTPLUG_VOLREF_325MV |
175 ADPA_CRT_HOTPLUG_ENABLE |
176 ADPA_CRT_HOTPLUG_FORCE_TRIGGER);
177
Zhao Yakui28c97732009-10-09 11:39:41 +0800178 DRM_DEBUG_KMS("pch crt adpa 0x%x", adpa);
Zhenyu Wang2c072452009-06-05 15:38:42 +0800179 I915_WRITE(PCH_ADPA, adpa);
180
Zhenyu Wang67941da2009-07-24 01:00:33 +0800181 while ((I915_READ(PCH_ADPA) & ADPA_CRT_HOTPLUG_FORCE_TRIGGER) != 0)
182 ;
Zhenyu Wang2c072452009-06-05 15:38:42 +0800183
184 /* Check the status to see if both blue and green are on now */
185 adpa = I915_READ(PCH_ADPA);
Zhenyu Wang67941da2009-07-24 01:00:33 +0800186 adpa &= ADPA_CRT_HOTPLUG_MONITOR_MASK;
187 if ((adpa == ADPA_CRT_HOTPLUG_MONITOR_COLOR) ||
188 (adpa == ADPA_CRT_HOTPLUG_MONITOR_MONO))
Zhenyu Wang2c072452009-06-05 15:38:42 +0800189 ret = true;
190 else
191 ret = false;
192
Zhenyu Wang2c072452009-06-05 15:38:42 +0800193 return ret;
Jesse Barnes79e53942008-11-07 14:24:08 -0800194}
195
196/**
197 * Uses CRT_HOTPLUG_EN and CRT_HOTPLUG_STAT to detect CRT presence.
198 *
199 * Not for i915G/i915GM
200 *
201 * \return true if CRT is connected.
202 * \return false if CRT is disconnected.
203 */
204static bool intel_crt_detect_hotplug(struct drm_connector *connector)
205{
206 struct drm_device *dev = connector->dev;
207 struct drm_i915_private *dev_priv = dev->dev_private;
Zhao Yakui771cb082009-03-03 18:07:52 +0800208 u32 hotplug_en;
209 int i, tries = 0;
Zhenyu Wang2c072452009-06-05 15:38:42 +0800210
Eric Anholtbad720f2009-10-22 16:11:14 -0700211 if (HAS_PCH_SPLIT(dev))
Adam Jacksonf2b115e2009-12-03 17:14:42 -0500212 return intel_ironlake_crt_detect_hotplug(connector);
Zhenyu Wang2c072452009-06-05 15:38:42 +0800213
Zhao Yakui771cb082009-03-03 18:07:52 +0800214 /*
215 * On 4 series desktop, CRT detect sequence need to be done twice
216 * to get a reliable result.
217 */
Jesse Barnes79e53942008-11-07 14:24:08 -0800218
Zhao Yakui771cb082009-03-03 18:07:52 +0800219 if (IS_G4X(dev) && !IS_GM45(dev))
220 tries = 2;
221 else
222 tries = 1;
223 hotplug_en = I915_READ(PORT_HOTPLUG_EN);
Jesse Barnes5ca58282009-03-31 14:11:15 -0700224 hotplug_en &= CRT_FORCE_HOTPLUG_MASK;
Zhao Yakui771cb082009-03-03 18:07:52 +0800225 hotplug_en |= CRT_HOTPLUG_FORCE_DETECT;
Jesse Barnes79e53942008-11-07 14:24:08 -0800226
Ma Linge92597cf2009-05-13 14:46:12 +0800227 if (IS_G4X(dev))
Zhao Yakui771cb082009-03-03 18:07:52 +0800228 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
Jesse Barnes79e53942008-11-07 14:24:08 -0800229
Zhao Yakui771cb082009-03-03 18:07:52 +0800230 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
Jesse Barnes79e53942008-11-07 14:24:08 -0800231
Zhao Yakui771cb082009-03-03 18:07:52 +0800232 for (i = 0; i < tries ; i++) {
233 unsigned long timeout;
234 /* turn on the FORCE_DETECT */
235 I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
236 timeout = jiffies + msecs_to_jiffies(1000);
237 /* wait for FORCE_DETECT to go off */
238 do {
239 if (!(I915_READ(PORT_HOTPLUG_EN) &
240 CRT_HOTPLUG_FORCE_DETECT))
241 break;
242 msleep(1);
243 } while (time_after(timeout, jiffies));
244 }
Jesse Barnes79e53942008-11-07 14:24:08 -0800245
Zhenyu Wang8e9e0ee2009-11-11 02:30:50 +0000246 if ((I915_READ(PORT_HOTPLUG_STAT) & CRT_HOTPLUG_MONITOR_MASK) !=
247 CRT_HOTPLUG_MONITOR_NONE)
Jesse Barnes79e53942008-11-07 14:24:08 -0800248 return true;
249
250 return false;
251}
252
253static bool intel_crt_detect_ddc(struct drm_connector *connector)
254{
Eric Anholt21d40d32010-03-25 11:11:14 -0700255 struct intel_encoder *intel_encoder = to_intel_encoder(connector);
Jesse Barnes79e53942008-11-07 14:24:08 -0800256
257 /* CRT should always be at 0, but check anyway */
Eric Anholt21d40d32010-03-25 11:11:14 -0700258 if (intel_encoder->type != INTEL_OUTPUT_ANALOG)
Jesse Barnes79e53942008-11-07 14:24:08 -0800259 return false;
260
Eric Anholt21d40d32010-03-25 11:11:14 -0700261 return intel_ddc_probe(intel_encoder);
Jesse Barnes79e53942008-11-07 14:24:08 -0800262}
263
Ma Linge4a5d54f2009-05-26 11:31:00 +0800264static enum drm_connector_status
Eric Anholt21d40d32010-03-25 11:11:14 -0700265intel_crt_load_detect(struct drm_crtc *crtc, struct intel_encoder *intel_encoder)
Ma Linge4a5d54f2009-05-26 11:31:00 +0800266{
Eric Anholt21d40d32010-03-25 11:11:14 -0700267 struct drm_encoder *encoder = &intel_encoder->enc;
Ma Linge4a5d54f2009-05-26 11:31:00 +0800268 struct drm_device *dev = encoder->dev;
269 struct drm_i915_private *dev_priv = dev->dev_private;
270 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
271 uint32_t pipe = intel_crtc->pipe;
272 uint32_t save_bclrpat;
273 uint32_t save_vtotal;
274 uint32_t vtotal, vactive;
275 uint32_t vsample;
276 uint32_t vblank, vblank_start, vblank_end;
277 uint32_t dsl;
278 uint32_t bclrpat_reg;
279 uint32_t vtotal_reg;
280 uint32_t vblank_reg;
281 uint32_t vsync_reg;
282 uint32_t pipeconf_reg;
283 uint32_t pipe_dsl_reg;
284 uint8_t st00;
285 enum drm_connector_status status;
286
287 if (pipe == 0) {
288 bclrpat_reg = BCLRPAT_A;
289 vtotal_reg = VTOTAL_A;
290 vblank_reg = VBLANK_A;
291 vsync_reg = VSYNC_A;
292 pipeconf_reg = PIPEACONF;
293 pipe_dsl_reg = PIPEADSL;
294 } else {
295 bclrpat_reg = BCLRPAT_B;
296 vtotal_reg = VTOTAL_B;
297 vblank_reg = VBLANK_B;
298 vsync_reg = VSYNC_B;
299 pipeconf_reg = PIPEBCONF;
300 pipe_dsl_reg = PIPEBDSL;
301 }
302
303 save_bclrpat = I915_READ(bclrpat_reg);
304 save_vtotal = I915_READ(vtotal_reg);
305 vblank = I915_READ(vblank_reg);
306
307 vtotal = ((save_vtotal >> 16) & 0xfff) + 1;
308 vactive = (save_vtotal & 0x7ff) + 1;
309
310 vblank_start = (vblank & 0xfff) + 1;
311 vblank_end = ((vblank >> 16) & 0xfff) + 1;
312
313 /* Set the border color to purple. */
314 I915_WRITE(bclrpat_reg, 0x500050);
315
316 if (IS_I9XX(dev)) {
317 uint32_t pipeconf = I915_READ(pipeconf_reg);
318 I915_WRITE(pipeconf_reg, pipeconf | PIPECONF_FORCE_BORDER);
319 /* Wait for next Vblank to substitue
320 * border color for Color info */
321 intel_wait_for_vblank(dev);
322 st00 = I915_READ8(VGA_MSR_WRITE);
323 status = ((st00 & (1 << 4)) != 0) ?
324 connector_status_connected :
325 connector_status_disconnected;
326
327 I915_WRITE(pipeconf_reg, pipeconf);
328 } else {
329 bool restore_vblank = false;
330 int count, detect;
331
332 /*
333 * If there isn't any border, add some.
334 * Yes, this will flicker
335 */
336 if (vblank_start <= vactive && vblank_end >= vtotal) {
337 uint32_t vsync = I915_READ(vsync_reg);
338 uint32_t vsync_start = (vsync & 0xffff) + 1;
339
340 vblank_start = vsync_start;
341 I915_WRITE(vblank_reg,
342 (vblank_start - 1) |
343 ((vblank_end - 1) << 16));
344 restore_vblank = true;
345 }
346 /* sample in the vertical border, selecting the larger one */
347 if (vblank_start - vactive >= vtotal - vblank_end)
348 vsample = (vblank_start + vactive) >> 1;
349 else
350 vsample = (vtotal + vblank_end) >> 1;
351
352 /*
353 * Wait for the border to be displayed
354 */
355 while (I915_READ(pipe_dsl_reg) >= vactive)
356 ;
357 while ((dsl = I915_READ(pipe_dsl_reg)) <= vsample)
358 ;
359 /*
360 * Watch ST00 for an entire scanline
361 */
362 detect = 0;
363 count = 0;
364 do {
365 count++;
366 /* Read the ST00 VGA status register */
367 st00 = I915_READ8(VGA_MSR_WRITE);
368 if (st00 & (1 << 4))
369 detect++;
370 } while ((I915_READ(pipe_dsl_reg) == dsl));
371
372 /* restore vblank if necessary */
373 if (restore_vblank)
374 I915_WRITE(vblank_reg, vblank);
375 /*
376 * If more than 3/4 of the scanline detected a monitor,
377 * then it is assumed to be present. This works even on i830,
378 * where there isn't any way to force the border color across
379 * the screen
380 */
381 status = detect * 4 > count * 3 ?
382 connector_status_connected :
383 connector_status_disconnected;
384 }
385
386 /* Restore previous settings */
387 I915_WRITE(bclrpat_reg, save_bclrpat);
388
389 return status;
390}
391
Jesse Barnes79e53942008-11-07 14:24:08 -0800392static enum drm_connector_status intel_crt_detect(struct drm_connector *connector)
393{
394 struct drm_device *dev = connector->dev;
Eric Anholt21d40d32010-03-25 11:11:14 -0700395 struct intel_encoder *intel_encoder = to_intel_encoder(connector);
396 struct drm_encoder *encoder = &intel_encoder->enc;
Ma Linge4a5d54f2009-05-26 11:31:00 +0800397 struct drm_crtc *crtc;
398 int dpms_mode;
399 enum drm_connector_status status;
Jesse Barnes79e53942008-11-07 14:24:08 -0800400
401 if (IS_I9XX(dev) && !IS_I915G(dev) && !IS_I915GM(dev)) {
402 if (intel_crt_detect_hotplug(connector))
403 return connector_status_connected;
404 else
405 return connector_status_disconnected;
406 }
407
408 if (intel_crt_detect_ddc(connector))
409 return connector_status_connected;
410
Ma Linge4a5d54f2009-05-26 11:31:00 +0800411 /* for pre-945g platforms use load detect */
412 if (encoder->crtc && encoder->crtc->enabled) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700413 status = intel_crt_load_detect(encoder->crtc, intel_encoder);
Ma Linge4a5d54f2009-05-26 11:31:00 +0800414 } else {
Zhenyu Wangc1c43972010-03-30 14:39:30 +0800415 crtc = intel_get_load_detect_pipe(intel_encoder, connector,
Ma Linge4a5d54f2009-05-26 11:31:00 +0800416 NULL, &dpms_mode);
417 if (crtc) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700418 status = intel_crt_load_detect(crtc, intel_encoder);
Zhenyu Wangc1c43972010-03-30 14:39:30 +0800419 intel_release_load_detect_pipe(intel_encoder,
420 connector, dpms_mode);
Ma Linge4a5d54f2009-05-26 11:31:00 +0800421 } else
422 status = connector_status_unknown;
423 }
424
425 return status;
Jesse Barnes79e53942008-11-07 14:24:08 -0800426}
427
428static void intel_crt_destroy(struct drm_connector *connector)
429{
Eric Anholt21d40d32010-03-25 11:11:14 -0700430 struct intel_encoder *intel_encoder = to_intel_encoder(connector);
Jesse Barnes79e53942008-11-07 14:24:08 -0800431
Eric Anholt21d40d32010-03-25 11:11:14 -0700432 intel_i2c_destroy(intel_encoder->ddc_bus);
Jesse Barnes79e53942008-11-07 14:24:08 -0800433 drm_sysfs_connector_remove(connector);
434 drm_connector_cleanup(connector);
435 kfree(connector);
436}
437
438static int intel_crt_get_modes(struct drm_connector *connector)
439{
ling.ma@intel.com8e4d36b2009-06-30 11:35:34 +0800440 int ret;
Eric Anholt21d40d32010-03-25 11:11:14 -0700441 struct intel_encoder *intel_encoder = to_intel_encoder(connector);
Zhenyu Wang335af9a2010-03-30 14:39:31 +0800442 struct i2c_adapter *ddc_bus;
ling.ma@intel.com8e4d36b2009-06-30 11:35:34 +0800443 struct drm_device *dev = connector->dev;
444
445
Zhenyu Wang335af9a2010-03-30 14:39:31 +0800446 ret = intel_ddc_get_modes(connector, intel_encoder->ddc_bus);
ling.ma@intel.com8e4d36b2009-06-30 11:35:34 +0800447 if (ret || !IS_G4X(dev))
448 goto end;
449
ling.ma@intel.com8e4d36b2009-06-30 11:35:34 +0800450 /* Try to probe digital port for output in DVI-I -> VGA mode. */
Zhenyu Wang335af9a2010-03-30 14:39:31 +0800451 ddc_bus = intel_i2c_create(connector->dev, GPIOD, "CRTDDC_D");
ling.ma@intel.com8e4d36b2009-06-30 11:35:34 +0800452
Zhenyu Wang335af9a2010-03-30 14:39:31 +0800453 if (!ddc_bus) {
ling.ma@intel.com8e4d36b2009-06-30 11:35:34 +0800454 dev_printk(KERN_ERR, &connector->dev->pdev->dev,
455 "DDC bus registration failed for CRTDDC_D.\n");
456 goto end;
457 }
458 /* Try to get modes by GPIOD port */
Zhenyu Wang335af9a2010-03-30 14:39:31 +0800459 ret = intel_ddc_get_modes(connector, ddc_bus);
460 intel_i2c_destroy(ddc_bus);
ling.ma@intel.com8e4d36b2009-06-30 11:35:34 +0800461
462end:
463 return ret;
464
Jesse Barnes79e53942008-11-07 14:24:08 -0800465}
466
467static int intel_crt_set_property(struct drm_connector *connector,
468 struct drm_property *property,
469 uint64_t value)
470{
Jesse Barnes79e53942008-11-07 14:24:08 -0800471 return 0;
472}
473
474/*
475 * Routines for controlling stuff on the analog port
476 */
477
478static const struct drm_encoder_helper_funcs intel_crt_helper_funcs = {
479 .dpms = intel_crt_dpms,
480 .mode_fixup = intel_crt_mode_fixup,
481 .prepare = intel_encoder_prepare,
482 .commit = intel_encoder_commit,
483 .mode_set = intel_crt_mode_set,
484};
485
486static const struct drm_connector_funcs intel_crt_connector_funcs = {
Keith Packardc9fb15f2009-05-30 20:42:28 -0700487 .dpms = drm_helper_connector_dpms,
Jesse Barnes79e53942008-11-07 14:24:08 -0800488 .detect = intel_crt_detect,
489 .fill_modes = drm_helper_probe_single_connector_modes,
490 .destroy = intel_crt_destroy,
491 .set_property = intel_crt_set_property,
492};
493
494static const struct drm_connector_helper_funcs intel_crt_connector_helper_funcs = {
495 .mode_valid = intel_crt_mode_valid,
496 .get_modes = intel_crt_get_modes,
497 .best_encoder = intel_best_encoder,
498};
499
Hannes Ederb358d0a2008-12-18 21:18:47 +0100500static void intel_crt_enc_destroy(struct drm_encoder *encoder)
Jesse Barnes79e53942008-11-07 14:24:08 -0800501{
502 drm_encoder_cleanup(encoder);
503}
504
505static const struct drm_encoder_funcs intel_crt_enc_funcs = {
506 .destroy = intel_crt_enc_destroy,
507};
508
509void intel_crt_init(struct drm_device *dev)
510{
511 struct drm_connector *connector;
Eric Anholt21d40d32010-03-25 11:11:14 -0700512 struct intel_encoder *intel_encoder;
David Müller (ELSOFT AG)db545012009-08-29 08:54:45 +0200513 struct drm_i915_private *dev_priv = dev->dev_private;
Zhenyu Wang2c072452009-06-05 15:38:42 +0800514 u32 i2c_reg;
Jesse Barnes79e53942008-11-07 14:24:08 -0800515
Eric Anholt21d40d32010-03-25 11:11:14 -0700516 intel_encoder = kzalloc(sizeof(struct intel_encoder), GFP_KERNEL);
517 if (!intel_encoder)
Jesse Barnes79e53942008-11-07 14:24:08 -0800518 return;
519
Eric Anholt21d40d32010-03-25 11:11:14 -0700520 connector = &intel_encoder->base;
521 drm_connector_init(dev, &intel_encoder->base,
Jesse Barnes79e53942008-11-07 14:24:08 -0800522 &intel_crt_connector_funcs, DRM_MODE_CONNECTOR_VGA);
523
Eric Anholt21d40d32010-03-25 11:11:14 -0700524 drm_encoder_init(dev, &intel_encoder->enc, &intel_crt_enc_funcs,
Jesse Barnes79e53942008-11-07 14:24:08 -0800525 DRM_MODE_ENCODER_DAC);
526
Eric Anholt21d40d32010-03-25 11:11:14 -0700527 drm_mode_connector_attach_encoder(&intel_encoder->base,
528 &intel_encoder->enc);
Jesse Barnes79e53942008-11-07 14:24:08 -0800529
530 /* Set up the DDC bus. */
Eric Anholtbad720f2009-10-22 16:11:14 -0700531 if (HAS_PCH_SPLIT(dev))
Zhenyu Wang2c072452009-06-05 15:38:42 +0800532 i2c_reg = PCH_GPIOA;
David Müller (ELSOFT AG)db545012009-08-29 08:54:45 +0200533 else {
Zhenyu Wang2c072452009-06-05 15:38:42 +0800534 i2c_reg = GPIOA;
David Müller (ELSOFT AG)db545012009-08-29 08:54:45 +0200535 /* Use VBT information for CRT DDC if available */
Shaohua Li29874f42009-11-18 15:15:02 +0800536 if (dev_priv->crt_ddc_bus != 0)
David Müller (ELSOFT AG)db545012009-08-29 08:54:45 +0200537 i2c_reg = dev_priv->crt_ddc_bus;
538 }
Eric Anholt21d40d32010-03-25 11:11:14 -0700539 intel_encoder->ddc_bus = intel_i2c_create(dev, i2c_reg, "CRTDDC_A");
540 if (!intel_encoder->ddc_bus) {
Jesse Barnes79e53942008-11-07 14:24:08 -0800541 dev_printk(KERN_ERR, &dev->pdev->dev, "DDC bus registration "
542 "failed.\n");
543 return;
544 }
545
Eric Anholt21d40d32010-03-25 11:11:14 -0700546 intel_encoder->type = INTEL_OUTPUT_ANALOG;
547 intel_encoder->clone_mask = (1 << INTEL_SDVO_NON_TV_CLONE_BIT) |
Ma Lingf8aed702009-08-24 13:50:24 +0800548 (1 << INTEL_ANALOG_CLONE_BIT) |
549 (1 << INTEL_SDVO_LVDS_CLONE_BIT);
Eric Anholt21d40d32010-03-25 11:11:14 -0700550 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
Jesse Barnes79e53942008-11-07 14:24:08 -0800551 connector->interlace_allowed = 0;
552 connector->doublescan_allowed = 0;
553
Eric Anholt21d40d32010-03-25 11:11:14 -0700554 drm_encoder_helper_add(&intel_encoder->enc, &intel_crt_helper_funcs);
Jesse Barnes79e53942008-11-07 14:24:08 -0800555 drm_connector_helper_add(connector, &intel_crt_connector_helper_funcs);
556
557 drm_sysfs_connector_add(connector);
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800558
559 dev_priv->hotplug_supported_mask |= CRT_HOTPLUG_INT_STATUS;
Jesse Barnes79e53942008-11-07 14:24:08 -0800560}