vt: vt_ioctl: fix VT_DISALLOCATE freeing in-use virtual console
[linux/fpc-iii.git] / drivers / gpu / drm / gma500 / cdv_intel_lvds.c
blob9c8446184b177a5eebd488153ec127eac071a08a
1 /*
2 * Copyright © 2006-2011 Intel Corporation
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
17 * Authors:
18 * Eric Anholt <eric@anholt.net>
19 * Dave Airlie <airlied@linux.ie>
20 * Jesse Barnes <jesse.barnes@intel.com>
23 #include <linux/i2c.h>
24 #include <linux/dmi.h>
25 #include <drm/drmP.h>
27 #include "intel_bios.h"
28 #include "psb_drv.h"
29 #include "psb_intel_drv.h"
30 #include "psb_intel_reg.h"
31 #include "power.h"
32 #include <linux/pm_runtime.h>
33 #include "cdv_device.h"
35 /**
36 * LVDS I2C backlight control macros
38 #define BRIGHTNESS_MAX_LEVEL 100
39 #define BRIGHTNESS_MASK 0xFF
40 #define BLC_I2C_TYPE 0x01
41 #define BLC_PWM_TYPT 0x02
43 #define BLC_POLARITY_NORMAL 0
44 #define BLC_POLARITY_INVERSE 1
46 #define PSB_BLC_MAX_PWM_REG_FREQ (0xFFFE)
47 #define PSB_BLC_MIN_PWM_REG_FREQ (0x2)
48 #define PSB_BLC_PWM_PRECISION_FACTOR (10)
49 #define PSB_BACKLIGHT_PWM_CTL_SHIFT (16)
50 #define PSB_BACKLIGHT_PWM_POLARITY_BIT_CLEAR (0xFFFE)
52 struct cdv_intel_lvds_priv {
53 /**
54 * Saved LVDO output states
56 uint32_t savePP_ON;
57 uint32_t savePP_OFF;
58 uint32_t saveLVDS;
59 uint32_t savePP_CONTROL;
60 uint32_t savePP_CYCLE;
61 uint32_t savePFIT_CONTROL;
62 uint32_t savePFIT_PGM_RATIOS;
63 uint32_t saveBLC_PWM_CTL;
67 * Returns the maximum level of the backlight duty cycle field.
69 static u32 cdv_intel_lvds_get_max_backlight(struct drm_device *dev)
71 struct drm_psb_private *dev_priv = dev->dev_private;
72 u32 retval;
74 if (gma_power_begin(dev, false)) {
75 retval = ((REG_READ(BLC_PWM_CTL) &
76 BACKLIGHT_MODULATION_FREQ_MASK) >>
77 BACKLIGHT_MODULATION_FREQ_SHIFT) * 2;
79 gma_power_end(dev);
80 } else
81 retval = ((dev_priv->regs.saveBLC_PWM_CTL &
82 BACKLIGHT_MODULATION_FREQ_MASK) >>
83 BACKLIGHT_MODULATION_FREQ_SHIFT) * 2;
85 return retval;
88 #if 0
90 * Set LVDS backlight level by I2C command
92 static int cdv_lvds_i2c_set_brightness(struct drm_device *dev,
93 unsigned int level)
95 struct drm_psb_private *dev_priv = dev->dev_private;
96 struct psb_intel_i2c_chan *lvds_i2c_bus = dev_priv->lvds_i2c_bus;
97 u8 out_buf[2];
98 unsigned int blc_i2c_brightness;
100 struct i2c_msg msgs[] = {
102 .addr = lvds_i2c_bus->slave_addr,
103 .flags = 0,
104 .len = 2,
105 .buf = out_buf,
109 blc_i2c_brightness = BRIGHTNESS_MASK & ((unsigned int)level *
110 BRIGHTNESS_MASK /
111 BRIGHTNESS_MAX_LEVEL);
113 if (dev_priv->lvds_bl->pol == BLC_POLARITY_INVERSE)
114 blc_i2c_brightness = BRIGHTNESS_MASK - blc_i2c_brightness;
116 out_buf[0] = dev_priv->lvds_bl->brightnesscmd;
117 out_buf[1] = (u8)blc_i2c_brightness;
119 if (i2c_transfer(&lvds_i2c_bus->adapter, msgs, 1) == 1)
120 return 0;
122 DRM_ERROR("I2C transfer error\n");
123 return -1;
127 static int cdv_lvds_pwm_set_brightness(struct drm_device *dev, int level)
129 struct drm_psb_private *dev_priv = dev->dev_private;
131 u32 max_pwm_blc;
132 u32 blc_pwm_duty_cycle;
134 max_pwm_blc = cdv_intel_lvds_get_max_backlight(dev);
136 /*BLC_PWM_CTL Should be initiated while backlight device init*/
137 BUG_ON((max_pwm_blc & PSB_BLC_MAX_PWM_REG_FREQ) == 0);
139 blc_pwm_duty_cycle = level * max_pwm_blc / BRIGHTNESS_MAX_LEVEL;
141 if (dev_priv->lvds_bl->pol == BLC_POLARITY_INVERSE)
142 blc_pwm_duty_cycle = max_pwm_blc - blc_pwm_duty_cycle;
144 blc_pwm_duty_cycle &= PSB_BACKLIGHT_PWM_POLARITY_BIT_CLEAR;
145 REG_WRITE(BLC_PWM_CTL,
146 (max_pwm_blc << PSB_BACKLIGHT_PWM_CTL_SHIFT) |
147 (blc_pwm_duty_cycle));
149 return 0;
153 * Set LVDS backlight level either by I2C or PWM
155 void cdv_intel_lvds_set_brightness(struct drm_device *dev, int level)
157 struct drm_psb_private *dev_priv = dev->dev_private;
159 if (!dev_priv->lvds_bl) {
160 DRM_ERROR("NO LVDS Backlight Info\n");
161 return;
164 if (dev_priv->lvds_bl->type == BLC_I2C_TYPE)
165 cdv_lvds_i2c_set_brightness(dev, level);
166 else
167 cdv_lvds_pwm_set_brightness(dev, level);
169 #endif
172 * Sets the backlight level.
174 * level backlight level, from 0 to cdv_intel_lvds_get_max_backlight().
176 static void cdv_intel_lvds_set_backlight(struct drm_device *dev, int level)
178 struct drm_psb_private *dev_priv = dev->dev_private;
179 u32 blc_pwm_ctl;
181 if (gma_power_begin(dev, false)) {
182 blc_pwm_ctl =
183 REG_READ(BLC_PWM_CTL) & ~BACKLIGHT_DUTY_CYCLE_MASK;
184 REG_WRITE(BLC_PWM_CTL,
185 (blc_pwm_ctl |
186 (level << BACKLIGHT_DUTY_CYCLE_SHIFT)));
187 gma_power_end(dev);
188 } else {
189 blc_pwm_ctl = dev_priv->regs.saveBLC_PWM_CTL &
190 ~BACKLIGHT_DUTY_CYCLE_MASK;
191 dev_priv->regs.saveBLC_PWM_CTL = (blc_pwm_ctl |
192 (level << BACKLIGHT_DUTY_CYCLE_SHIFT));
197 * Sets the power state for the panel.
199 static void cdv_intel_lvds_set_power(struct drm_device *dev,
200 struct drm_encoder *encoder, bool on)
202 struct drm_psb_private *dev_priv = dev->dev_private;
203 u32 pp_status;
205 if (!gma_power_begin(dev, true))
206 return;
208 if (on) {
209 REG_WRITE(PP_CONTROL, REG_READ(PP_CONTROL) |
210 POWER_TARGET_ON);
211 do {
212 pp_status = REG_READ(PP_STATUS);
213 } while ((pp_status & PP_ON) == 0);
215 cdv_intel_lvds_set_backlight(dev,
216 dev_priv->mode_dev.backlight_duty_cycle);
217 } else {
218 cdv_intel_lvds_set_backlight(dev, 0);
220 REG_WRITE(PP_CONTROL, REG_READ(PP_CONTROL) &
221 ~POWER_TARGET_ON);
222 do {
223 pp_status = REG_READ(PP_STATUS);
224 } while (pp_status & PP_ON);
226 gma_power_end(dev);
229 static void cdv_intel_lvds_encoder_dpms(struct drm_encoder *encoder, int mode)
231 struct drm_device *dev = encoder->dev;
232 if (mode == DRM_MODE_DPMS_ON)
233 cdv_intel_lvds_set_power(dev, encoder, true);
234 else
235 cdv_intel_lvds_set_power(dev, encoder, false);
236 /* XXX: We never power down the LVDS pairs. */
239 static void cdv_intel_lvds_save(struct drm_connector *connector)
243 static void cdv_intel_lvds_restore(struct drm_connector *connector)
247 static enum drm_mode_status cdv_intel_lvds_mode_valid(struct drm_connector *connector,
248 struct drm_display_mode *mode)
250 struct drm_device *dev = connector->dev;
251 struct drm_psb_private *dev_priv = dev->dev_private;
252 struct drm_display_mode *fixed_mode =
253 dev_priv->mode_dev.panel_fixed_mode;
255 /* just in case */
256 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
257 return MODE_NO_DBLESCAN;
259 /* just in case */
260 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
261 return MODE_NO_INTERLACE;
263 if (fixed_mode) {
264 if (mode->hdisplay > fixed_mode->hdisplay)
265 return MODE_PANEL;
266 if (mode->vdisplay > fixed_mode->vdisplay)
267 return MODE_PANEL;
269 return MODE_OK;
272 static bool cdv_intel_lvds_mode_fixup(struct drm_encoder *encoder,
273 const struct drm_display_mode *mode,
274 struct drm_display_mode *adjusted_mode)
276 struct drm_device *dev = encoder->dev;
277 struct drm_psb_private *dev_priv = dev->dev_private;
278 struct psb_intel_mode_device *mode_dev = &dev_priv->mode_dev;
279 struct drm_encoder *tmp_encoder;
280 struct drm_display_mode *panel_fixed_mode = mode_dev->panel_fixed_mode;
282 /* Should never happen!! */
283 list_for_each_entry(tmp_encoder, &dev->mode_config.encoder_list,
284 head) {
285 if (tmp_encoder != encoder
286 && tmp_encoder->crtc == encoder->crtc) {
287 pr_err("Can't enable LVDS and another encoder on the same pipe\n");
288 return false;
293 * If we have timings from the BIOS for the panel, put them in
294 * to the adjusted mode. The CRTC will be set up for this mode,
295 * with the panel scaling set up to source from the H/VDisplay
296 * of the original mode.
298 if (panel_fixed_mode != NULL) {
299 adjusted_mode->hdisplay = panel_fixed_mode->hdisplay;
300 adjusted_mode->hsync_start = panel_fixed_mode->hsync_start;
301 adjusted_mode->hsync_end = panel_fixed_mode->hsync_end;
302 adjusted_mode->htotal = panel_fixed_mode->htotal;
303 adjusted_mode->vdisplay = panel_fixed_mode->vdisplay;
304 adjusted_mode->vsync_start = panel_fixed_mode->vsync_start;
305 adjusted_mode->vsync_end = panel_fixed_mode->vsync_end;
306 adjusted_mode->vtotal = panel_fixed_mode->vtotal;
307 adjusted_mode->clock = panel_fixed_mode->clock;
308 drm_mode_set_crtcinfo(adjusted_mode,
309 CRTC_INTERLACE_HALVE_V);
313 * XXX: It would be nice to support lower refresh rates on the
314 * panels to reduce power consumption, and perhaps match the
315 * user's requested refresh rate.
318 return true;
321 static void cdv_intel_lvds_prepare(struct drm_encoder *encoder)
323 struct drm_device *dev = encoder->dev;
324 struct drm_psb_private *dev_priv = dev->dev_private;
325 struct psb_intel_mode_device *mode_dev = &dev_priv->mode_dev;
327 if (!gma_power_begin(dev, true))
328 return;
330 mode_dev->saveBLC_PWM_CTL = REG_READ(BLC_PWM_CTL);
331 mode_dev->backlight_duty_cycle = (mode_dev->saveBLC_PWM_CTL &
332 BACKLIGHT_DUTY_CYCLE_MASK);
334 cdv_intel_lvds_set_power(dev, encoder, false);
336 gma_power_end(dev);
339 static void cdv_intel_lvds_commit(struct drm_encoder *encoder)
341 struct drm_device *dev = encoder->dev;
342 struct drm_psb_private *dev_priv = dev->dev_private;
343 struct psb_intel_mode_device *mode_dev = &dev_priv->mode_dev;
345 if (mode_dev->backlight_duty_cycle == 0)
346 mode_dev->backlight_duty_cycle =
347 cdv_intel_lvds_get_max_backlight(dev);
349 cdv_intel_lvds_set_power(dev, encoder, true);
352 static void cdv_intel_lvds_mode_set(struct drm_encoder *encoder,
353 struct drm_display_mode *mode,
354 struct drm_display_mode *adjusted_mode)
356 struct drm_device *dev = encoder->dev;
357 struct drm_psb_private *dev_priv = dev->dev_private;
358 struct gma_crtc *gma_crtc = to_gma_crtc(encoder->crtc);
359 u32 pfit_control;
362 * The LVDS pin pair will already have been turned on in the
363 * cdv_intel_crtc_mode_set since it has a large impact on the DPLL
364 * settings.
368 * Enable automatic panel scaling so that non-native modes fill the
369 * screen. Should be enabled before the pipe is enabled, according to
370 * register description and PRM.
372 if (mode->hdisplay != adjusted_mode->hdisplay ||
373 mode->vdisplay != adjusted_mode->vdisplay)
374 pfit_control = (PFIT_ENABLE | VERT_AUTO_SCALE |
375 HORIZ_AUTO_SCALE | VERT_INTERP_BILINEAR |
376 HORIZ_INTERP_BILINEAR);
377 else
378 pfit_control = 0;
380 pfit_control |= gma_crtc->pipe << PFIT_PIPE_SHIFT;
382 if (dev_priv->lvds_dither)
383 pfit_control |= PANEL_8TO6_DITHER_ENABLE;
385 REG_WRITE(PFIT_CONTROL, pfit_control);
389 * Return the list of DDC modes if available, or the BIOS fixed mode otherwise.
391 static int cdv_intel_lvds_get_modes(struct drm_connector *connector)
393 struct drm_device *dev = connector->dev;
394 struct drm_psb_private *dev_priv = dev->dev_private;
395 struct gma_encoder *gma_encoder = gma_attached_encoder(connector);
396 struct psb_intel_mode_device *mode_dev = &dev_priv->mode_dev;
397 int ret;
399 ret = psb_intel_ddc_get_modes(connector, &gma_encoder->i2c_bus->adapter);
401 if (ret)
402 return ret;
404 if (mode_dev->panel_fixed_mode != NULL) {
405 struct drm_display_mode *mode =
406 drm_mode_duplicate(dev, mode_dev->panel_fixed_mode);
407 drm_mode_probed_add(connector, mode);
408 return 1;
411 return 0;
415 * cdv_intel_lvds_destroy - unregister and free LVDS structures
416 * @connector: connector to free
418 * Unregister the DDC bus for this connector then free the driver private
419 * structure.
421 static void cdv_intel_lvds_destroy(struct drm_connector *connector)
423 struct gma_encoder *gma_encoder = gma_attached_encoder(connector);
425 psb_intel_i2c_destroy(gma_encoder->i2c_bus);
426 drm_connector_unregister(connector);
427 drm_connector_cleanup(connector);
428 kfree(connector);
431 static int cdv_intel_lvds_set_property(struct drm_connector *connector,
432 struct drm_property *property,
433 uint64_t value)
435 struct drm_encoder *encoder = connector->encoder;
437 if (!strcmp(property->name, "scaling mode") && encoder) {
438 struct gma_crtc *crtc = to_gma_crtc(encoder->crtc);
439 uint64_t curValue;
441 if (!crtc)
442 return -1;
444 switch (value) {
445 case DRM_MODE_SCALE_FULLSCREEN:
446 break;
447 case DRM_MODE_SCALE_NO_SCALE:
448 break;
449 case DRM_MODE_SCALE_ASPECT:
450 break;
451 default:
452 return -1;
455 if (drm_object_property_get_value(&connector->base,
456 property,
457 &curValue))
458 return -1;
460 if (curValue == value)
461 return 0;
463 if (drm_object_property_set_value(&connector->base,
464 property,
465 value))
466 return -1;
468 if (crtc->saved_mode.hdisplay != 0 &&
469 crtc->saved_mode.vdisplay != 0) {
470 if (!drm_crtc_helper_set_mode(encoder->crtc,
471 &crtc->saved_mode,
472 encoder->crtc->x,
473 encoder->crtc->y,
474 encoder->crtc->primary->fb))
475 return -1;
477 } else if (!strcmp(property->name, "backlight") && encoder) {
478 if (drm_object_property_set_value(&connector->base,
479 property,
480 value))
481 return -1;
482 else
483 gma_backlight_set(encoder->dev, value);
484 } else if (!strcmp(property->name, "DPMS") && encoder) {
485 const struct drm_encoder_helper_funcs *helpers =
486 encoder->helper_private;
487 helpers->dpms(encoder, value);
489 return 0;
492 static const struct drm_encoder_helper_funcs
493 cdv_intel_lvds_helper_funcs = {
494 .dpms = cdv_intel_lvds_encoder_dpms,
495 .mode_fixup = cdv_intel_lvds_mode_fixup,
496 .prepare = cdv_intel_lvds_prepare,
497 .mode_set = cdv_intel_lvds_mode_set,
498 .commit = cdv_intel_lvds_commit,
501 static const struct drm_connector_helper_funcs
502 cdv_intel_lvds_connector_helper_funcs = {
503 .get_modes = cdv_intel_lvds_get_modes,
504 .mode_valid = cdv_intel_lvds_mode_valid,
505 .best_encoder = gma_best_encoder,
508 static const struct drm_connector_funcs cdv_intel_lvds_connector_funcs = {
509 .dpms = drm_helper_connector_dpms,
510 .fill_modes = drm_helper_probe_single_connector_modes,
511 .set_property = cdv_intel_lvds_set_property,
512 .destroy = cdv_intel_lvds_destroy,
516 static void cdv_intel_lvds_enc_destroy(struct drm_encoder *encoder)
518 drm_encoder_cleanup(encoder);
521 static const struct drm_encoder_funcs cdv_intel_lvds_enc_funcs = {
522 .destroy = cdv_intel_lvds_enc_destroy,
526 * Enumerate the child dev array parsed from VBT to check whether
527 * the LVDS is present.
528 * If it is present, return 1.
529 * If it is not present, return false.
530 * If no child dev is parsed from VBT, it assumes that the LVDS is present.
532 static bool lvds_is_present_in_vbt(struct drm_device *dev,
533 u8 *i2c_pin)
535 struct drm_psb_private *dev_priv = dev->dev_private;
536 int i;
538 if (!dev_priv->child_dev_num)
539 return true;
541 for (i = 0; i < dev_priv->child_dev_num; i++) {
542 struct child_device_config *child = dev_priv->child_dev + i;
544 /* If the device type is not LFP, continue.
545 * We have to check both the new identifiers as well as the
546 * old for compatibility with some BIOSes.
548 if (child->device_type != DEVICE_TYPE_INT_LFP &&
549 child->device_type != DEVICE_TYPE_LFP)
550 continue;
552 if (child->i2c_pin)
553 *i2c_pin = child->i2c_pin;
555 /* However, we cannot trust the BIOS writers to populate
556 * the VBT correctly. Since LVDS requires additional
557 * information from AIM blocks, a non-zero addin offset is
558 * a good indicator that the LVDS is actually present.
560 if (child->addin_offset)
561 return true;
563 /* But even then some BIOS writers perform some black magic
564 * and instantiate the device without reference to any
565 * additional data. Trust that if the VBT was written into
566 * the OpRegion then they have validated the LVDS's existence.
568 if (dev_priv->opregion.vbt)
569 return true;
572 return false;
576 * cdv_intel_lvds_init - setup LVDS connectors on this device
577 * @dev: drm device
579 * Create the connector, register the LVDS DDC bus, and try to figure out what
580 * modes we can display on the LVDS panel (if present).
582 void cdv_intel_lvds_init(struct drm_device *dev,
583 struct psb_intel_mode_device *mode_dev)
585 struct gma_encoder *gma_encoder;
586 struct gma_connector *gma_connector;
587 struct cdv_intel_lvds_priv *lvds_priv;
588 struct drm_connector *connector;
589 struct drm_encoder *encoder;
590 struct drm_display_mode *scan;
591 struct drm_crtc *crtc;
592 struct drm_psb_private *dev_priv = dev->dev_private;
593 u32 lvds;
594 int pipe;
595 u8 pin;
597 if (!dev_priv->lvds_enabled_in_vbt)
598 return;
600 pin = GMBUS_PORT_PANEL;
601 if (!lvds_is_present_in_vbt(dev, &pin)) {
602 DRM_DEBUG_KMS("LVDS is not present in VBT\n");
603 return;
606 gma_encoder = kzalloc(sizeof(struct gma_encoder),
607 GFP_KERNEL);
608 if (!gma_encoder)
609 return;
611 gma_connector = kzalloc(sizeof(struct gma_connector),
612 GFP_KERNEL);
613 if (!gma_connector)
614 goto failed_connector;
616 lvds_priv = kzalloc(sizeof(struct cdv_intel_lvds_priv), GFP_KERNEL);
617 if (!lvds_priv)
618 goto failed_lvds_priv;
620 gma_encoder->dev_priv = lvds_priv;
622 connector = &gma_connector->base;
623 gma_connector->save = cdv_intel_lvds_save;
624 gma_connector->restore = cdv_intel_lvds_restore;
625 encoder = &gma_encoder->base;
628 drm_connector_init(dev, connector,
629 &cdv_intel_lvds_connector_funcs,
630 DRM_MODE_CONNECTOR_LVDS);
632 drm_encoder_init(dev, encoder,
633 &cdv_intel_lvds_enc_funcs,
634 DRM_MODE_ENCODER_LVDS, NULL);
637 gma_connector_attach_encoder(gma_connector, gma_encoder);
638 gma_encoder->type = INTEL_OUTPUT_LVDS;
640 drm_encoder_helper_add(encoder, &cdv_intel_lvds_helper_funcs);
641 drm_connector_helper_add(connector,
642 &cdv_intel_lvds_connector_helper_funcs);
643 connector->display_info.subpixel_order = SubPixelHorizontalRGB;
644 connector->interlace_allowed = false;
645 connector->doublescan_allowed = false;
647 /*Attach connector properties*/
648 drm_object_attach_property(&connector->base,
649 dev->mode_config.scaling_mode_property,
650 DRM_MODE_SCALE_FULLSCREEN);
651 drm_object_attach_property(&connector->base,
652 dev_priv->backlight_property,
653 BRIGHTNESS_MAX_LEVEL);
656 * Set up I2C bus
657 * FIXME: distroy i2c_bus when exit
659 gma_encoder->i2c_bus = psb_intel_i2c_create(dev,
660 GPIOB,
661 "LVDSBLC_B");
662 if (!gma_encoder->i2c_bus) {
663 dev_printk(KERN_ERR,
664 &dev->pdev->dev, "I2C bus registration failed.\n");
665 goto failed_blc_i2c;
667 gma_encoder->i2c_bus->slave_addr = 0x2C;
668 dev_priv->lvds_i2c_bus = gma_encoder->i2c_bus;
671 * LVDS discovery:
672 * 1) check for EDID on DDC
673 * 2) check for VBT data
674 * 3) check to see if LVDS is already on
675 * if none of the above, no panel
676 * 4) make sure lid is open
677 * if closed, act like it's not there for now
680 /* Set up the DDC bus. */
681 gma_encoder->ddc_bus = psb_intel_i2c_create(dev,
682 GPIOC,
683 "LVDSDDC_C");
684 if (!gma_encoder->ddc_bus) {
685 dev_printk(KERN_ERR, &dev->pdev->dev,
686 "DDC bus registration " "failed.\n");
687 goto failed_ddc;
691 * Attempt to get the fixed panel mode from DDC. Assume that the
692 * preferred mode is the right one.
694 mutex_lock(&dev->mode_config.mutex);
695 psb_intel_ddc_get_modes(connector,
696 &gma_encoder->ddc_bus->adapter);
697 list_for_each_entry(scan, &connector->probed_modes, head) {
698 if (scan->type & DRM_MODE_TYPE_PREFERRED) {
699 mode_dev->panel_fixed_mode =
700 drm_mode_duplicate(dev, scan);
701 goto out; /* FIXME: check for quirks */
705 /* Failed to get EDID, what about VBT? do we need this?*/
706 if (dev_priv->lfp_lvds_vbt_mode) {
707 mode_dev->panel_fixed_mode =
708 drm_mode_duplicate(dev, dev_priv->lfp_lvds_vbt_mode);
709 if (mode_dev->panel_fixed_mode) {
710 mode_dev->panel_fixed_mode->type |=
711 DRM_MODE_TYPE_PREFERRED;
712 goto out; /* FIXME: check for quirks */
716 * If we didn't get EDID, try checking if the panel is already turned
717 * on. If so, assume that whatever is currently programmed is the
718 * correct mode.
720 lvds = REG_READ(LVDS);
721 pipe = (lvds & LVDS_PIPEB_SELECT) ? 1 : 0;
722 crtc = psb_intel_get_crtc_from_pipe(dev, pipe);
724 if (crtc && (lvds & LVDS_PORT_EN)) {
725 mode_dev->panel_fixed_mode =
726 cdv_intel_crtc_mode_get(dev, crtc);
727 if (mode_dev->panel_fixed_mode) {
728 mode_dev->panel_fixed_mode->type |=
729 DRM_MODE_TYPE_PREFERRED;
730 goto out; /* FIXME: check for quirks */
734 /* If we still don't have a mode after all that, give up. */
735 if (!mode_dev->panel_fixed_mode) {
736 DRM_DEBUG
737 ("Found no modes on the lvds, ignoring the LVDS\n");
738 goto failed_find;
741 /* setup PWM */
743 u32 pwm;
745 pwm = REG_READ(BLC_PWM_CTL2);
746 if (pipe == 1)
747 pwm |= PWM_PIPE_B;
748 else
749 pwm &= ~PWM_PIPE_B;
750 pwm |= PWM_ENABLE;
751 REG_WRITE(BLC_PWM_CTL2, pwm);
754 out:
755 mutex_unlock(&dev->mode_config.mutex);
756 drm_connector_register(connector);
757 return;
759 failed_find:
760 mutex_unlock(&dev->mode_config.mutex);
761 pr_err("Failed find\n");
762 psb_intel_i2c_destroy(gma_encoder->ddc_bus);
763 failed_ddc:
764 pr_err("Failed DDC\n");
765 psb_intel_i2c_destroy(gma_encoder->i2c_bus);
766 failed_blc_i2c:
767 pr_err("Failed BLC\n");
768 drm_encoder_cleanup(encoder);
769 drm_connector_cleanup(connector);
770 kfree(lvds_priv);
771 failed_lvds_priv:
772 kfree(gma_connector);
773 failed_connector:
774 kfree(gma_encoder);