blob: f22e6efbe6a3268ec8a1750ebcf1290482eef266 [file] [log] [blame]
Jesse Barnes79e53942008-11-07 14:24:08 -08001/*
2 * Copyright © 2006-2007 Intel Corporation
3 * Copyright (c) 2006 Dave Airlie <airlied@linux.ie>
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 * Authors:
25 * Eric Anholt <eric@anholt.net>
26 * Dave Airlie <airlied@linux.ie>
27 * Jesse Barnes <jesse.barnes@intel.com>
28 */
29
Paul Collins565dcd42009-02-04 23:05:41 +130030#include <linux/dmi.h>
Jesse Barnes79e53942008-11-07 14:24:08 -080031#include <linux/i2c.h>
32#include "drmP.h"
33#include "drm.h"
34#include "drm_crtc.h"
35#include "drm_edid.h"
36#include "intel_drv.h"
37#include "i915_drm.h"
38#include "i915_drv.h"
39
yakui_zhao7fb85bf2009-06-02 14:10:49 +080040#define I915_LVDS "i915_lvds"
41
Jesse Barnes79e53942008-11-07 14:24:08 -080042/**
43 * Sets the backlight level.
44 *
45 * \param level backlight level, from 0 to intel_lvds_get_max_backlight().
46 */
47static void intel_lvds_set_backlight(struct drm_device *dev, int level)
48{
49 struct drm_i915_private *dev_priv = dev->dev_private;
Zhenyu Wang541998a2009-06-05 15:38:44 +080050 u32 blc_pwm_ctl, reg;
Jesse Barnes79e53942008-11-07 14:24:08 -080051
Zhenyu Wang541998a2009-06-05 15:38:44 +080052 if (IS_IGDNG(dev))
53 reg = BLC_PWM_CPU_CTL;
54 else
55 reg = BLC_PWM_CTL;
56
57 blc_pwm_ctl = I915_READ(reg) & ~BACKLIGHT_DUTY_CYCLE_MASK;
58 I915_WRITE(reg, (blc_pwm_ctl |
Jesse Barnes79e53942008-11-07 14:24:08 -080059 (level << BACKLIGHT_DUTY_CYCLE_SHIFT)));
60}
61
62/**
63 * Returns the maximum level of the backlight duty cycle field.
64 */
65static u32 intel_lvds_get_max_backlight(struct drm_device *dev)
66{
67 struct drm_i915_private *dev_priv = dev->dev_private;
Zhenyu Wang541998a2009-06-05 15:38:44 +080068 u32 reg;
Jesse Barnes79e53942008-11-07 14:24:08 -080069
Zhenyu Wang541998a2009-06-05 15:38:44 +080070 if (IS_IGDNG(dev))
71 reg = BLC_PWM_PCH_CTL2;
72 else
73 reg = BLC_PWM_CTL;
74
75 return ((I915_READ(reg) & BACKLIGHT_MODULATION_FREQ_MASK) >>
Jesse Barnes79e53942008-11-07 14:24:08 -080076 BACKLIGHT_MODULATION_FREQ_SHIFT) * 2;
77}
78
79/**
80 * Sets the power state for the panel.
81 */
82static void intel_lvds_set_power(struct drm_device *dev, bool on)
83{
84 struct drm_i915_private *dev_priv = dev->dev_private;
Zhenyu Wang541998a2009-06-05 15:38:44 +080085 u32 pp_status, ctl_reg, status_reg;
86
87 if (IS_IGDNG(dev)) {
88 ctl_reg = PCH_PP_CONTROL;
89 status_reg = PCH_PP_STATUS;
90 } else {
91 ctl_reg = PP_CONTROL;
92 status_reg = PP_STATUS;
93 }
Jesse Barnes79e53942008-11-07 14:24:08 -080094
95 if (on) {
Zhenyu Wang541998a2009-06-05 15:38:44 +080096 I915_WRITE(ctl_reg, I915_READ(ctl_reg) |
Jesse Barnes79e53942008-11-07 14:24:08 -080097 POWER_TARGET_ON);
98 do {
Zhenyu Wang541998a2009-06-05 15:38:44 +080099 pp_status = I915_READ(status_reg);
Jesse Barnes79e53942008-11-07 14:24:08 -0800100 } while ((pp_status & PP_ON) == 0);
101
102 intel_lvds_set_backlight(dev, dev_priv->backlight_duty_cycle);
103 } else {
104 intel_lvds_set_backlight(dev, 0);
105
Zhenyu Wang541998a2009-06-05 15:38:44 +0800106 I915_WRITE(ctl_reg, I915_READ(ctl_reg) &
Jesse Barnes79e53942008-11-07 14:24:08 -0800107 ~POWER_TARGET_ON);
108 do {
Zhenyu Wang541998a2009-06-05 15:38:44 +0800109 pp_status = I915_READ(status_reg);
Jesse Barnes79e53942008-11-07 14:24:08 -0800110 } while (pp_status & PP_ON);
111 }
112}
113
114static void intel_lvds_dpms(struct drm_encoder *encoder, int mode)
115{
116 struct drm_device *dev = encoder->dev;
117
118 if (mode == DRM_MODE_DPMS_ON)
119 intel_lvds_set_power(dev, true);
120 else
121 intel_lvds_set_power(dev, false);
122
123 /* XXX: We never power down the LVDS pairs. */
124}
125
126static void intel_lvds_save(struct drm_connector *connector)
127{
128 struct drm_device *dev = connector->dev;
129 struct drm_i915_private *dev_priv = dev->dev_private;
Zhenyu Wang541998a2009-06-05 15:38:44 +0800130 u32 pp_on_reg, pp_off_reg, pp_ctl_reg, pp_div_reg;
131 u32 pwm_ctl_reg;
Jesse Barnes79e53942008-11-07 14:24:08 -0800132
Zhenyu Wang541998a2009-06-05 15:38:44 +0800133 if (IS_IGDNG(dev)) {
134 pp_on_reg = PCH_PP_ON_DELAYS;
135 pp_off_reg = PCH_PP_OFF_DELAYS;
136 pp_ctl_reg = PCH_PP_CONTROL;
137 pp_div_reg = PCH_PP_DIVISOR;
138 pwm_ctl_reg = BLC_PWM_CPU_CTL;
139 } else {
140 pp_on_reg = PP_ON_DELAYS;
141 pp_off_reg = PP_OFF_DELAYS;
142 pp_ctl_reg = PP_CONTROL;
143 pp_div_reg = PP_DIVISOR;
144 pwm_ctl_reg = BLC_PWM_CTL;
145 }
146
147 dev_priv->savePP_ON = I915_READ(pp_on_reg);
148 dev_priv->savePP_OFF = I915_READ(pp_off_reg);
149 dev_priv->savePP_CONTROL = I915_READ(pp_ctl_reg);
150 dev_priv->savePP_DIVISOR = I915_READ(pp_div_reg);
151 dev_priv->saveBLC_PWM_CTL = I915_READ(pwm_ctl_reg);
Jesse Barnes79e53942008-11-07 14:24:08 -0800152 dev_priv->backlight_duty_cycle = (dev_priv->saveBLC_PWM_CTL &
153 BACKLIGHT_DUTY_CYCLE_MASK);
154
155 /*
156 * If the light is off at server startup, just make it full brightness
157 */
158 if (dev_priv->backlight_duty_cycle == 0)
159 dev_priv->backlight_duty_cycle =
160 intel_lvds_get_max_backlight(dev);
161}
162
163static void intel_lvds_restore(struct drm_connector *connector)
164{
165 struct drm_device *dev = connector->dev;
166 struct drm_i915_private *dev_priv = dev->dev_private;
Zhenyu Wang541998a2009-06-05 15:38:44 +0800167 u32 pp_on_reg, pp_off_reg, pp_ctl_reg, pp_div_reg;
168 u32 pwm_ctl_reg;
Jesse Barnes79e53942008-11-07 14:24:08 -0800169
Zhenyu Wang541998a2009-06-05 15:38:44 +0800170 if (IS_IGDNG(dev)) {
171 pp_on_reg = PCH_PP_ON_DELAYS;
172 pp_off_reg = PCH_PP_OFF_DELAYS;
173 pp_ctl_reg = PCH_PP_CONTROL;
174 pp_div_reg = PCH_PP_DIVISOR;
175 pwm_ctl_reg = BLC_PWM_CPU_CTL;
176 } else {
177 pp_on_reg = PP_ON_DELAYS;
178 pp_off_reg = PP_OFF_DELAYS;
179 pp_ctl_reg = PP_CONTROL;
180 pp_div_reg = PP_DIVISOR;
181 pwm_ctl_reg = BLC_PWM_CTL;
182 }
183
184 I915_WRITE(pwm_ctl_reg, dev_priv->saveBLC_PWM_CTL);
185 I915_WRITE(pp_on_reg, dev_priv->savePP_ON);
186 I915_WRITE(pp_off_reg, dev_priv->savePP_OFF);
187 I915_WRITE(pp_div_reg, dev_priv->savePP_DIVISOR);
188 I915_WRITE(pp_ctl_reg, dev_priv->savePP_CONTROL);
Jesse Barnes79e53942008-11-07 14:24:08 -0800189 if (dev_priv->savePP_CONTROL & POWER_TARGET_ON)
190 intel_lvds_set_power(dev, true);
191 else
192 intel_lvds_set_power(dev, false);
193}
194
195static int intel_lvds_mode_valid(struct drm_connector *connector,
196 struct drm_display_mode *mode)
197{
198 struct drm_device *dev = connector->dev;
199 struct drm_i915_private *dev_priv = dev->dev_private;
200 struct drm_display_mode *fixed_mode = dev_priv->panel_fixed_mode;
201
202 if (fixed_mode) {
203 if (mode->hdisplay > fixed_mode->hdisplay)
204 return MODE_PANEL;
205 if (mode->vdisplay > fixed_mode->vdisplay)
206 return MODE_PANEL;
207 }
208
209 return MODE_OK;
210}
211
212static bool intel_lvds_mode_fixup(struct drm_encoder *encoder,
213 struct drm_display_mode *mode,
214 struct drm_display_mode *adjusted_mode)
215{
216 struct drm_device *dev = encoder->dev;
217 struct drm_i915_private *dev_priv = dev->dev_private;
218 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
219 struct drm_encoder *tmp_encoder;
220
221 /* Should never happen!! */
222 if (!IS_I965G(dev) && intel_crtc->pipe == 0) {
223 printk(KERN_ERR "Can't support LVDS on pipe A\n");
224 return false;
225 }
226
227 /* Should never happen!! */
228 list_for_each_entry(tmp_encoder, &dev->mode_config.encoder_list, head) {
229 if (tmp_encoder != encoder && tmp_encoder->crtc == encoder->crtc) {
230 printk(KERN_ERR "Can't enable LVDS and another "
231 "encoder on the same pipe\n");
232 return false;
233 }
234 }
235
236 /*
237 * If we have timings from the BIOS for the panel, put them in
238 * to the adjusted mode. The CRTC will be set up for this mode,
239 * with the panel scaling set up to source from the H/VDisplay
240 * of the original mode.
241 */
242 if (dev_priv->panel_fixed_mode != NULL) {
243 adjusted_mode->hdisplay = dev_priv->panel_fixed_mode->hdisplay;
244 adjusted_mode->hsync_start =
245 dev_priv->panel_fixed_mode->hsync_start;
246 adjusted_mode->hsync_end =
247 dev_priv->panel_fixed_mode->hsync_end;
248 adjusted_mode->htotal = dev_priv->panel_fixed_mode->htotal;
249 adjusted_mode->vdisplay = dev_priv->panel_fixed_mode->vdisplay;
250 adjusted_mode->vsync_start =
251 dev_priv->panel_fixed_mode->vsync_start;
252 adjusted_mode->vsync_end =
253 dev_priv->panel_fixed_mode->vsync_end;
254 adjusted_mode->vtotal = dev_priv->panel_fixed_mode->vtotal;
255 adjusted_mode->clock = dev_priv->panel_fixed_mode->clock;
256 drm_mode_set_crtcinfo(adjusted_mode, CRTC_INTERLACE_HALVE_V);
257 }
258
259 /*
260 * XXX: It would be nice to support lower refresh rates on the
261 * panels to reduce power consumption, and perhaps match the
262 * user's requested refresh rate.
263 */
264
265 return true;
266}
267
268static void intel_lvds_prepare(struct drm_encoder *encoder)
269{
270 struct drm_device *dev = encoder->dev;
271 struct drm_i915_private *dev_priv = dev->dev_private;
Zhenyu Wang541998a2009-06-05 15:38:44 +0800272 u32 reg;
Jesse Barnes79e53942008-11-07 14:24:08 -0800273
Zhenyu Wang541998a2009-06-05 15:38:44 +0800274 if (IS_IGDNG(dev))
275 reg = BLC_PWM_CPU_CTL;
276 else
277 reg = BLC_PWM_CTL;
278
279 dev_priv->saveBLC_PWM_CTL = I915_READ(reg);
Jesse Barnes79e53942008-11-07 14:24:08 -0800280 dev_priv->backlight_duty_cycle = (dev_priv->saveBLC_PWM_CTL &
281 BACKLIGHT_DUTY_CYCLE_MASK);
282
283 intel_lvds_set_power(dev, false);
284}
285
286static void intel_lvds_commit( struct drm_encoder *encoder)
287{
288 struct drm_device *dev = encoder->dev;
289 struct drm_i915_private *dev_priv = dev->dev_private;
290
291 if (dev_priv->backlight_duty_cycle == 0)
292 dev_priv->backlight_duty_cycle =
293 intel_lvds_get_max_backlight(dev);
294
295 intel_lvds_set_power(dev, true);
296}
297
298static void intel_lvds_mode_set(struct drm_encoder *encoder,
299 struct drm_display_mode *mode,
300 struct drm_display_mode *adjusted_mode)
301{
302 struct drm_device *dev = encoder->dev;
303 struct drm_i915_private *dev_priv = dev->dev_private;
304 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
305 u32 pfit_control;
306
307 /*
308 * The LVDS pin pair will already have been turned on in the
309 * intel_crtc_mode_set since it has a large impact on the DPLL
310 * settings.
311 */
312
Zhenyu Wang541998a2009-06-05 15:38:44 +0800313 /* No panel fitting yet, fixme */
314 if (IS_IGDNG(dev))
315 return;
316
Jesse Barnes79e53942008-11-07 14:24:08 -0800317 /*
318 * Enable automatic panel scaling so that non-native modes fill the
319 * screen. Should be enabled before the pipe is enabled, according to
320 * register description and PRM.
321 */
322 if (mode->hdisplay != adjusted_mode->hdisplay ||
323 mode->vdisplay != adjusted_mode->vdisplay)
324 pfit_control = (PFIT_ENABLE | VERT_AUTO_SCALE |
325 HORIZ_AUTO_SCALE | VERT_INTERP_BILINEAR |
326 HORIZ_INTERP_BILINEAR);
327 else
328 pfit_control = 0;
329
330 if (!IS_I965G(dev)) {
Li Peng2b5cde22009-03-13 10:25:07 +0800331 if (dev_priv->panel_wants_dither || dev_priv->lvds_dither)
Jesse Barnes79e53942008-11-07 14:24:08 -0800332 pfit_control |= PANEL_8TO6_DITHER_ENABLE;
333 }
334 else
335 pfit_control |= intel_crtc->pipe << PFIT_PIPE_SHIFT;
336
337 I915_WRITE(PFIT_CONTROL, pfit_control);
338}
339
340/**
341 * Detect the LVDS connection.
342 *
343 * This always returns CONNECTOR_STATUS_CONNECTED. This connector should only have
344 * been set up if the LVDS was actually connected anyway.
345 */
346static enum drm_connector_status intel_lvds_detect(struct drm_connector *connector)
347{
348 return connector_status_connected;
349}
350
351/**
352 * Return the list of DDC modes if available, or the BIOS fixed mode otherwise.
353 */
354static int intel_lvds_get_modes(struct drm_connector *connector)
355{
356 struct drm_device *dev = connector->dev;
357 struct intel_output *intel_output = to_intel_output(connector);
358 struct drm_i915_private *dev_priv = dev->dev_private;
359 int ret = 0;
360
361 ret = intel_ddc_get_modes(intel_output);
362
363 if (ret)
364 return ret;
365
366 /* Didn't get an EDID, so
367 * Set wide sync ranges so we get all modes
368 * handed to valid_mode for checking
369 */
370 connector->display_info.min_vfreq = 0;
371 connector->display_info.max_vfreq = 200;
372 connector->display_info.min_hfreq = 0;
373 connector->display_info.max_hfreq = 200;
374
375 if (dev_priv->panel_fixed_mode != NULL) {
376 struct drm_display_mode *mode;
377
Jesse Barnes79e53942008-11-07 14:24:08 -0800378 mode = drm_mode_duplicate(dev, dev_priv->panel_fixed_mode);
379 drm_mode_probed_add(connector, mode);
Jesse Barnes79e53942008-11-07 14:24:08 -0800380
381 return 1;
382 }
383
384 return 0;
385}
386
387/**
388 * intel_lvds_destroy - unregister and free LVDS structures
389 * @connector: connector to free
390 *
391 * Unregister the DDC bus for this connector then free the driver private
392 * structure.
393 */
394static void intel_lvds_destroy(struct drm_connector *connector)
395{
396 struct intel_output *intel_output = to_intel_output(connector);
397
398 if (intel_output->ddc_bus)
399 intel_i2c_destroy(intel_output->ddc_bus);
400 drm_sysfs_connector_remove(connector);
401 drm_connector_cleanup(connector);
402 kfree(connector);
403}
404
Jesse Barnes335041e2009-01-22 22:22:06 +1000405static int intel_lvds_set_property(struct drm_connector *connector,
406 struct drm_property *property,
407 uint64_t value)
408{
409 struct drm_device *dev = connector->dev;
410
411 if (property == dev->mode_config.dpms_property && connector->encoder)
412 intel_lvds_dpms(connector->encoder, (uint32_t)(value & 0xf));
413
414 return 0;
415}
416
Jesse Barnes79e53942008-11-07 14:24:08 -0800417static const struct drm_encoder_helper_funcs intel_lvds_helper_funcs = {
418 .dpms = intel_lvds_dpms,
419 .mode_fixup = intel_lvds_mode_fixup,
420 .prepare = intel_lvds_prepare,
421 .mode_set = intel_lvds_mode_set,
422 .commit = intel_lvds_commit,
423};
424
425static const struct drm_connector_helper_funcs intel_lvds_connector_helper_funcs = {
426 .get_modes = intel_lvds_get_modes,
427 .mode_valid = intel_lvds_mode_valid,
428 .best_encoder = intel_best_encoder,
429};
430
431static const struct drm_connector_funcs intel_lvds_connector_funcs = {
432 .save = intel_lvds_save,
433 .restore = intel_lvds_restore,
434 .detect = intel_lvds_detect,
435 .fill_modes = drm_helper_probe_single_connector_modes,
Jesse Barnes335041e2009-01-22 22:22:06 +1000436 .set_property = intel_lvds_set_property,
Jesse Barnes79e53942008-11-07 14:24:08 -0800437 .destroy = intel_lvds_destroy,
438};
439
440
441static void intel_lvds_enc_destroy(struct drm_encoder *encoder)
442{
443 drm_encoder_cleanup(encoder);
444}
445
446static const struct drm_encoder_funcs intel_lvds_enc_funcs = {
447 .destroy = intel_lvds_enc_destroy,
448};
449
Jarod Wilson425d2442009-05-05 10:00:25 -0400450static int __init intel_no_lvds_dmi_callback(const struct dmi_system_id *id)
451{
yakui_zhao7fb85bf2009-06-02 14:10:49 +0800452 DRM_DEBUG_KMS(I915_LVDS,
453 "Skipping LVDS initialization for %s\n", id->ident);
Jarod Wilson425d2442009-05-05 10:00:25 -0400454 return 1;
455}
Jesse Barnes79e53942008-11-07 14:24:08 -0800456
Jarod Wilson425d2442009-05-05 10:00:25 -0400457/* These systems claim to have LVDS, but really don't */
458static const struct dmi_system_id __initdata intel_no_lvds[] = {
459 {
460 .callback = intel_no_lvds_dmi_callback,
461 .ident = "Apple Mac Mini (Core series)",
462 .matches = {
463 DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
464 DMI_MATCH(DMI_PRODUCT_NAME, "Macmini1,1"),
465 },
466 },
467 {
468 .callback = intel_no_lvds_dmi_callback,
469 .ident = "Apple Mac Mini (Core 2 series)",
470 .matches = {
471 DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
472 DMI_MATCH(DMI_PRODUCT_NAME, "Macmini2,1"),
473 },
474 },
475 {
476 .callback = intel_no_lvds_dmi_callback,
477 .ident = "MSI IM-945GSE-A",
478 .matches = {
479 DMI_MATCH(DMI_SYS_VENDOR, "MSI"),
480 DMI_MATCH(DMI_PRODUCT_NAME, "A9830IMS"),
481 },
482 },
483 {
484 .callback = intel_no_lvds_dmi_callback,
485 .ident = "Dell Studio Hybrid",
486 .matches = {
487 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
488 DMI_MATCH(DMI_PRODUCT_NAME, "Studio Hybrid 140g"),
489 },
490 },
Jarod Wilson70aa96c2009-05-27 17:20:39 -0400491 {
492 .callback = intel_no_lvds_dmi_callback,
493 .ident = "AOpen Mini PC",
494 .matches = {
495 DMI_MATCH(DMI_SYS_VENDOR, "AOpen"),
496 DMI_MATCH(DMI_PRODUCT_NAME, "i965GMx-IF"),
497 },
498 },
Michael Cousinfa0864b2009-06-05 21:16:22 +0200499 {
500 .callback = intel_no_lvds_dmi_callback,
501 .ident = "Aopen i945GTt-VFA",
502 .matches = {
503 DMI_MATCH(DMI_PRODUCT_VERSION, "AO00001JW"),
504 },
505 },
Jarod Wilson425d2442009-05-05 10:00:25 -0400506
507 { } /* terminating entry */
508};
Jesse Barnes79e53942008-11-07 14:24:08 -0800509
510/**
511 * intel_lvds_init - setup LVDS connectors on this device
512 * @dev: drm device
513 *
514 * Create the connector, register the LVDS DDC bus, and try to figure out what
515 * modes we can display on the LVDS panel (if present).
516 */
517void intel_lvds_init(struct drm_device *dev)
518{
519 struct drm_i915_private *dev_priv = dev->dev_private;
520 struct intel_output *intel_output;
521 struct drm_connector *connector;
522 struct drm_encoder *encoder;
523 struct drm_display_mode *scan; /* *modes, *bios_mode; */
524 struct drm_crtc *crtc;
525 u32 lvds;
Zhenyu Wang541998a2009-06-05 15:38:44 +0800526 int pipe, gpio = GPIOC;
Jesse Barnes79e53942008-11-07 14:24:08 -0800527
Jarod Wilson425d2442009-05-05 10:00:25 -0400528 /* Skip init on machines we know falsely report LVDS */
529 if (dmi_check_system(intel_no_lvds))
Paul Collins565dcd42009-02-04 23:05:41 +1300530 return;
Paul Collins565dcd42009-02-04 23:05:41 +1300531
Zhenyu Wang541998a2009-06-05 15:38:44 +0800532 if (IS_IGDNG(dev)) {
533 if ((I915_READ(PCH_LVDS) & LVDS_DETECTED) == 0)
534 return;
535 gpio = PCH_GPIOC;
536 }
537
Jesse Barnes79e53942008-11-07 14:24:08 -0800538 intel_output = kzalloc(sizeof(struct intel_output), GFP_KERNEL);
539 if (!intel_output) {
540 return;
541 }
542
543 connector = &intel_output->base;
544 encoder = &intel_output->enc;
545 drm_connector_init(dev, &intel_output->base, &intel_lvds_connector_funcs,
546 DRM_MODE_CONNECTOR_LVDS);
547
548 drm_encoder_init(dev, &intel_output->enc, &intel_lvds_enc_funcs,
549 DRM_MODE_ENCODER_LVDS);
550
551 drm_mode_connector_attach_encoder(&intel_output->base, &intel_output->enc);
552 intel_output->type = INTEL_OUTPUT_LVDS;
553
554 drm_encoder_helper_add(encoder, &intel_lvds_helper_funcs);
555 drm_connector_helper_add(connector, &intel_lvds_connector_helper_funcs);
556 connector->display_info.subpixel_order = SubPixelHorizontalRGB;
557 connector->interlace_allowed = false;
558 connector->doublescan_allowed = false;
559
560
561 /*
562 * LVDS discovery:
563 * 1) check for EDID on DDC
564 * 2) check for VBT data
565 * 3) check to see if LVDS is already on
566 * if none of the above, no panel
567 * 4) make sure lid is open
568 * if closed, act like it's not there for now
569 */
570
571 /* Set up the DDC bus. */
Zhenyu Wang541998a2009-06-05 15:38:44 +0800572 intel_output->ddc_bus = intel_i2c_create(dev, gpio, "LVDSDDC_C");
Jesse Barnes79e53942008-11-07 14:24:08 -0800573 if (!intel_output->ddc_bus) {
574 dev_printk(KERN_ERR, &dev->pdev->dev, "DDC bus registration "
575 "failed.\n");
576 goto failed;
577 }
578
579 /*
580 * Attempt to get the fixed panel mode from DDC. Assume that the
581 * preferred mode is the right one.
582 */
583 intel_ddc_get_modes(intel_output);
584
585 list_for_each_entry(scan, &connector->probed_modes, head) {
586 mutex_lock(&dev->mode_config.mutex);
587 if (scan->type & DRM_MODE_TYPE_PREFERRED) {
588 dev_priv->panel_fixed_mode =
589 drm_mode_duplicate(dev, scan);
590 mutex_unlock(&dev->mode_config.mutex);
Paul Collins565dcd42009-02-04 23:05:41 +1300591 goto out;
Jesse Barnes79e53942008-11-07 14:24:08 -0800592 }
593 mutex_unlock(&dev->mode_config.mutex);
594 }
595
596 /* Failed to get EDID, what about VBT? */
Ma Ling88631702009-05-13 11:19:55 +0800597 if (dev_priv->lfp_lvds_vbt_mode) {
Jesse Barnes79e53942008-11-07 14:24:08 -0800598 mutex_lock(&dev->mode_config.mutex);
599 dev_priv->panel_fixed_mode =
Ma Ling88631702009-05-13 11:19:55 +0800600 drm_mode_duplicate(dev, dev_priv->lfp_lvds_vbt_mode);
Jesse Barnes79e53942008-11-07 14:24:08 -0800601 mutex_unlock(&dev->mode_config.mutex);
Jesse Barnese285f3c2009-01-14 10:53:36 -0800602 if (dev_priv->panel_fixed_mode) {
603 dev_priv->panel_fixed_mode->type |=
604 DRM_MODE_TYPE_PREFERRED;
Jesse Barnese285f3c2009-01-14 10:53:36 -0800605 goto out;
606 }
Jesse Barnes79e53942008-11-07 14:24:08 -0800607 }
608
609 /*
610 * If we didn't get EDID, try checking if the panel is already turned
611 * on. If so, assume that whatever is currently programmed is the
612 * correct mode.
613 */
Zhenyu Wang541998a2009-06-05 15:38:44 +0800614
615 /* IGDNG: FIXME if still fail, not try pipe mode now */
616 if (IS_IGDNG(dev))
617 goto failed;
618
Jesse Barnes79e53942008-11-07 14:24:08 -0800619 lvds = I915_READ(LVDS);
620 pipe = (lvds & LVDS_PIPEB_SELECT) ? 1 : 0;
621 crtc = intel_get_crtc_from_pipe(dev, pipe);
622
623 if (crtc && (lvds & LVDS_PORT_EN)) {
624 dev_priv->panel_fixed_mode = intel_crtc_mode_get(dev, crtc);
625 if (dev_priv->panel_fixed_mode) {
626 dev_priv->panel_fixed_mode->type |=
627 DRM_MODE_TYPE_PREFERRED;
Paul Collins565dcd42009-02-04 23:05:41 +1300628 goto out;
Jesse Barnes79e53942008-11-07 14:24:08 -0800629 }
630 }
631
632 /* If we still don't have a mode after all that, give up. */
633 if (!dev_priv->panel_fixed_mode)
634 goto failed;
635
Jesse Barnes79e53942008-11-07 14:24:08 -0800636out:
Zhenyu Wang541998a2009-06-05 15:38:44 +0800637 if (IS_IGDNG(dev)) {
638 u32 pwm;
639 /* make sure PWM is enabled */
640 pwm = I915_READ(BLC_PWM_CPU_CTL2);
641 pwm |= (PWM_ENABLE | PWM_PIPE_B);
642 I915_WRITE(BLC_PWM_CPU_CTL2, pwm);
643
644 pwm = I915_READ(BLC_PWM_PCH_CTL1);
645 pwm |= PWM_PCH_ENABLE;
646 I915_WRITE(BLC_PWM_PCH_CTL1, pwm);
647 }
Jesse Barnes79e53942008-11-07 14:24:08 -0800648 drm_sysfs_connector_add(connector);
649 return;
650
651failed:
yakui_zhao7fb85bf2009-06-02 14:10:49 +0800652 DRM_DEBUG_KMS(I915_LVDS, "No LVDS modes found, disabling.\n");
Jesse Barnes79e53942008-11-07 14:24:08 -0800653 if (intel_output->ddc_bus)
654 intel_i2c_destroy(intel_output->ddc_bus);
655 drm_connector_cleanup(connector);
656 kfree(connector);
657}