2 * Copyright © 2006-2007 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
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.
18 * Eric Anholt <eric@anholt.net>
19 * Dave Airlie <airlied@linux.ie>
20 * Jesse Barnes <jesse.barnes@intel.com>
23 #include <linux/i2c.h>
26 #include "intel_bios.h"
28 #include "psb_intel_drv.h"
29 #include "psb_intel_reg.h"
31 #include <linux/pm_runtime.h>
34 * LVDS I2C backlight control macros
36 #define BRIGHTNESS_MAX_LEVEL 100
37 #define BRIGHTNESS_MASK 0xFF
38 #define BLC_I2C_TYPE 0x01
39 #define BLC_PWM_TYPT 0x02
41 #define BLC_POLARITY_NORMAL 0
42 #define BLC_POLARITY_INVERSE 1
44 #define PSB_BLC_MAX_PWM_REG_FREQ (0xFFFE)
45 #define PSB_BLC_MIN_PWM_REG_FREQ (0x2)
46 #define PSB_BLC_PWM_PRECISION_FACTOR (10)
47 #define PSB_BACKLIGHT_PWM_CTL_SHIFT (16)
48 #define PSB_BACKLIGHT_PWM_POLARITY_BIT_CLEAR (0xFFFE)
50 struct psb_intel_lvds_priv {
52 * Saved LVDO output states
57 uint32_t savePP_CONTROL;
58 uint32_t savePP_CYCLE;
59 uint32_t savePFIT_CONTROL;
60 uint32_t savePFIT_PGM_RATIOS;
61 uint32_t saveBLC_PWM_CTL;
66 * Returns the maximum level of the backlight duty cycle field.
68 static u32 psb_intel_lvds_get_max_backlight(struct drm_device *dev)
70 struct drm_psb_private *dev_priv = dev->dev_private;
73 if (gma_power_begin(dev, false)) {
74 ret = REG_READ(BLC_PWM_CTL);
76 } else /* Powered off, use the saved value */
77 ret = dev_priv->saveBLC_PWM_CTL;
79 /* Top 15bits hold the frequency mask */
80 ret = (ret & BACKLIGHT_MODULATION_FREQ_MASK) >>
81 BACKLIGHT_MODULATION_FREQ_SHIFT;
83 ret *= 2; /* Return a 16bit range as needed for setting */
85 dev_err(dev->dev, "BL bug: Reg %08x save %08X\n",
86 REG_READ(BLC_PWM_CTL), dev_priv->saveBLC_PWM_CTL);
91 * Set LVDS backlight level by I2C command
93 * FIXME: at some point we need to both track this for PM and also
94 * disable runtime pm on MRST if the brightness is nil (ie blanked)
96 static int psb_lvds_i2c_set_brightness(struct drm_device *dev,
99 struct drm_psb_private *dev_priv =
100 (struct drm_psb_private *)dev->dev_private;
102 struct psb_intel_i2c_chan *lvds_i2c_bus = dev_priv->lvds_i2c_bus;
104 unsigned int blc_i2c_brightness;
106 struct i2c_msg msgs[] = {
108 .addr = lvds_i2c_bus->slave_addr,
115 blc_i2c_brightness = BRIGHTNESS_MASK & ((unsigned int)level *
117 BRIGHTNESS_MAX_LEVEL);
119 if (dev_priv->lvds_bl->pol == BLC_POLARITY_INVERSE)
120 blc_i2c_brightness = BRIGHTNESS_MASK - blc_i2c_brightness;
122 out_buf[0] = dev_priv->lvds_bl->brightnesscmd;
123 out_buf[1] = (u8)blc_i2c_brightness;
125 if (i2c_transfer(&lvds_i2c_bus->adapter, msgs, 1) == 1) {
126 dev_dbg(dev->dev, "I2C set brightness.(command, value) (%d, %d)\n",
127 dev_priv->lvds_bl->brightnesscmd,
132 dev_err(dev->dev, "I2C transfer error\n");
137 static int psb_lvds_pwm_set_brightness(struct drm_device *dev, int level)
139 struct drm_psb_private *dev_priv =
140 (struct drm_psb_private *)dev->dev_private;
143 u32 blc_pwm_duty_cycle;
145 max_pwm_blc = psb_intel_lvds_get_max_backlight(dev);
147 /*BLC_PWM_CTL Should be initiated while backlight device init*/
148 BUG_ON(max_pwm_blc == 0);
150 blc_pwm_duty_cycle = level * max_pwm_blc / BRIGHTNESS_MAX_LEVEL;
152 if (dev_priv->lvds_bl->pol == BLC_POLARITY_INVERSE)
153 blc_pwm_duty_cycle = max_pwm_blc - blc_pwm_duty_cycle;
155 blc_pwm_duty_cycle &= PSB_BACKLIGHT_PWM_POLARITY_BIT_CLEAR;
156 REG_WRITE(BLC_PWM_CTL,
157 (max_pwm_blc << PSB_BACKLIGHT_PWM_CTL_SHIFT) |
158 (blc_pwm_duty_cycle));
160 dev_info(dev->dev, "Backlight lvds set brightness %08x\n",
161 (max_pwm_blc << PSB_BACKLIGHT_PWM_CTL_SHIFT) |
162 (blc_pwm_duty_cycle));
168 * Set LVDS backlight level either by I2C or PWM
170 void psb_intel_lvds_set_brightness(struct drm_device *dev, int level)
172 struct drm_psb_private *dev_priv = dev->dev_private;
174 dev_dbg(dev->dev, "backlight level is %d\n", level);
176 if (!dev_priv->lvds_bl) {
177 dev_err(dev->dev, "NO LVDS backlight info\n");
181 if (dev_priv->lvds_bl->type == BLC_I2C_TYPE)
182 psb_lvds_i2c_set_brightness(dev, level);
184 psb_lvds_pwm_set_brightness(dev, level);
188 * Sets the backlight level.
190 * level: backlight level, from 0 to psb_intel_lvds_get_max_backlight().
192 static void psb_intel_lvds_set_backlight(struct drm_device *dev, int level)
194 struct drm_psb_private *dev_priv = dev->dev_private;
197 if (gma_power_begin(dev, false)) {
198 blc_pwm_ctl = REG_READ(BLC_PWM_CTL);
199 blc_pwm_ctl &= ~BACKLIGHT_DUTY_CYCLE_MASK;
200 REG_WRITE(BLC_PWM_CTL,
202 (level << BACKLIGHT_DUTY_CYCLE_SHIFT)));
203 dev_priv->saveBLC_PWM_CTL = (blc_pwm_ctl |
204 (level << BACKLIGHT_DUTY_CYCLE_SHIFT));
207 blc_pwm_ctl = dev_priv->saveBLC_PWM_CTL &
208 ~BACKLIGHT_DUTY_CYCLE_MASK;
209 dev_priv->saveBLC_PWM_CTL = (blc_pwm_ctl |
210 (level << BACKLIGHT_DUTY_CYCLE_SHIFT));
215 * Sets the power state for the panel.
217 static void psb_intel_lvds_set_power(struct drm_device *dev,
218 struct psb_intel_output *output, bool on)
222 if (!gma_power_begin(dev, true)) {
223 dev_err(dev->dev, "set power, chip off!\n");
228 REG_WRITE(PP_CONTROL, REG_READ(PP_CONTROL) |
231 pp_status = REG_READ(PP_STATUS);
232 } while ((pp_status & PP_ON) == 0);
234 psb_intel_lvds_set_backlight(dev,
236 mode_dev->backlight_duty_cycle);
238 psb_intel_lvds_set_backlight(dev, 0);
240 REG_WRITE(PP_CONTROL, REG_READ(PP_CONTROL) &
243 pp_status = REG_READ(PP_STATUS);
244 } while (pp_status & PP_ON);
250 static void psb_intel_lvds_encoder_dpms(struct drm_encoder *encoder, int mode)
252 struct drm_device *dev = encoder->dev;
253 struct psb_intel_output *output = enc_to_psb_intel_output(encoder);
255 if (mode == DRM_MODE_DPMS_ON)
256 psb_intel_lvds_set_power(dev, output, true);
258 psb_intel_lvds_set_power(dev, output, false);
260 /* XXX: We never power down the LVDS pairs. */
263 static void psb_intel_lvds_save(struct drm_connector *connector)
265 struct drm_device *dev = connector->dev;
266 struct drm_psb_private *dev_priv =
267 (struct drm_psb_private *)dev->dev_private;
268 struct psb_intel_output *psb_intel_output =
269 to_psb_intel_output(connector);
270 struct psb_intel_lvds_priv *lvds_priv =
271 (struct psb_intel_lvds_priv *)psb_intel_output->dev_priv;
273 lvds_priv->savePP_ON = REG_READ(LVDSPP_ON);
274 lvds_priv->savePP_OFF = REG_READ(LVDSPP_OFF);
275 lvds_priv->saveLVDS = REG_READ(LVDS);
276 lvds_priv->savePP_CONTROL = REG_READ(PP_CONTROL);
277 lvds_priv->savePP_CYCLE = REG_READ(PP_CYCLE);
278 /*lvds_priv->savePP_DIVISOR = REG_READ(PP_DIVISOR);*/
279 lvds_priv->saveBLC_PWM_CTL = REG_READ(BLC_PWM_CTL);
280 lvds_priv->savePFIT_CONTROL = REG_READ(PFIT_CONTROL);
281 lvds_priv->savePFIT_PGM_RATIOS = REG_READ(PFIT_PGM_RATIOS);
283 /*TODO: move backlight_duty_cycle to psb_intel_lvds_priv*/
284 dev_priv->backlight_duty_cycle = (dev_priv->saveBLC_PWM_CTL &
285 BACKLIGHT_DUTY_CYCLE_MASK);
288 * If the light is off at server startup,
289 * just make it full brightness
291 if (dev_priv->backlight_duty_cycle == 0)
292 dev_priv->backlight_duty_cycle =
293 psb_intel_lvds_get_max_backlight(dev);
295 dev_dbg(dev->dev, "(0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x)\n",
296 lvds_priv->savePP_ON,
297 lvds_priv->savePP_OFF,
299 lvds_priv->savePP_CONTROL,
300 lvds_priv->savePP_CYCLE,
301 lvds_priv->saveBLC_PWM_CTL);
304 static void psb_intel_lvds_restore(struct drm_connector *connector)
306 struct drm_device *dev = connector->dev;
308 struct psb_intel_output *psb_intel_output =
309 to_psb_intel_output(connector);
310 struct psb_intel_lvds_priv *lvds_priv =
311 (struct psb_intel_lvds_priv *)psb_intel_output->dev_priv;
313 dev_dbg(dev->dev, "(0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x)\n",
314 lvds_priv->savePP_ON,
315 lvds_priv->savePP_OFF,
317 lvds_priv->savePP_CONTROL,
318 lvds_priv->savePP_CYCLE,
319 lvds_priv->saveBLC_PWM_CTL);
321 REG_WRITE(BLC_PWM_CTL, lvds_priv->saveBLC_PWM_CTL);
322 REG_WRITE(PFIT_CONTROL, lvds_priv->savePFIT_CONTROL);
323 REG_WRITE(PFIT_PGM_RATIOS, lvds_priv->savePFIT_PGM_RATIOS);
324 REG_WRITE(LVDSPP_ON, lvds_priv->savePP_ON);
325 REG_WRITE(LVDSPP_OFF, lvds_priv->savePP_OFF);
326 /*REG_WRITE(PP_DIVISOR, lvds_priv->savePP_DIVISOR);*/
327 REG_WRITE(PP_CYCLE, lvds_priv->savePP_CYCLE);
328 REG_WRITE(PP_CONTROL, lvds_priv->savePP_CONTROL);
329 REG_WRITE(LVDS, lvds_priv->saveLVDS);
331 if (lvds_priv->savePP_CONTROL & POWER_TARGET_ON) {
332 REG_WRITE(PP_CONTROL, REG_READ(PP_CONTROL) |
335 pp_status = REG_READ(PP_STATUS);
336 } while ((pp_status & PP_ON) == 0);
338 REG_WRITE(PP_CONTROL, REG_READ(PP_CONTROL) &
341 pp_status = REG_READ(PP_STATUS);
342 } while (pp_status & PP_ON);
346 int psb_intel_lvds_mode_valid(struct drm_connector *connector,
347 struct drm_display_mode *mode)
349 struct psb_intel_output *psb_intel_output =
350 to_psb_intel_output(connector);
351 struct drm_display_mode *fixed_mode =
352 psb_intel_output->mode_dev->panel_fixed_mode;
354 if (psb_intel_output->type == INTEL_OUTPUT_MIPI2)
355 fixed_mode = psb_intel_output->mode_dev->panel_fixed_mode2;
358 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
359 return MODE_NO_DBLESCAN;
362 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
363 return MODE_NO_INTERLACE;
366 if (mode->hdisplay > fixed_mode->hdisplay)
368 if (mode->vdisplay > fixed_mode->vdisplay)
374 bool psb_intel_lvds_mode_fixup(struct drm_encoder *encoder,
375 struct drm_display_mode *mode,
376 struct drm_display_mode *adjusted_mode)
378 struct psb_intel_mode_device *mode_dev =
379 enc_to_psb_intel_output(encoder)->mode_dev;
380 struct drm_device *dev = encoder->dev;
381 struct psb_intel_crtc *psb_intel_crtc =
382 to_psb_intel_crtc(encoder->crtc);
383 struct drm_encoder *tmp_encoder;
384 struct drm_display_mode *panel_fixed_mode = mode_dev->panel_fixed_mode;
385 struct psb_intel_output *psb_intel_output =
386 enc_to_psb_intel_output(encoder);
388 if (psb_intel_output->type == INTEL_OUTPUT_MIPI2)
389 panel_fixed_mode = mode_dev->panel_fixed_mode2;
391 /* PSB requires the LVDS is on pipe B, MRST has only one pipe anyway */
392 if (!IS_MRST(dev) && psb_intel_crtc->pipe == 0) {
393 printk(KERN_ERR "Can't support LVDS on pipe A\n");
396 if (IS_MRST(dev) && psb_intel_crtc->pipe != 0) {
397 printk(KERN_ERR "Must use PIPE A\n");
400 /* Should never happen!! */
401 list_for_each_entry(tmp_encoder, &dev->mode_config.encoder_list,
403 if (tmp_encoder != encoder
404 && tmp_encoder->crtc == encoder->crtc) {
405 printk(KERN_ERR "Can't enable LVDS and another "
406 "encoder on the same pipe\n");
412 * If we have timings from the BIOS for the panel, put them in
413 * to the adjusted mode. The CRTC will be set up for this mode,
414 * with the panel scaling set up to source from the H/VDisplay
415 * of the original mode.
417 if (panel_fixed_mode != NULL) {
418 adjusted_mode->hdisplay = panel_fixed_mode->hdisplay;
419 adjusted_mode->hsync_start = panel_fixed_mode->hsync_start;
420 adjusted_mode->hsync_end = panel_fixed_mode->hsync_end;
421 adjusted_mode->htotal = panel_fixed_mode->htotal;
422 adjusted_mode->vdisplay = panel_fixed_mode->vdisplay;
423 adjusted_mode->vsync_start = panel_fixed_mode->vsync_start;
424 adjusted_mode->vsync_end = panel_fixed_mode->vsync_end;
425 adjusted_mode->vtotal = panel_fixed_mode->vtotal;
426 adjusted_mode->clock = panel_fixed_mode->clock;
427 drm_mode_set_crtcinfo(adjusted_mode,
428 CRTC_INTERLACE_HALVE_V);
432 * XXX: It would be nice to support lower refresh rates on the
433 * panels to reduce power consumption, and perhaps match the
434 * user's requested refresh rate.
440 static void psb_intel_lvds_prepare(struct drm_encoder *encoder)
442 struct drm_device *dev = encoder->dev;
443 struct psb_intel_output *output = enc_to_psb_intel_output(encoder);
444 struct psb_intel_mode_device *mode_dev = output->mode_dev;
446 if (!gma_power_begin(dev, true))
449 mode_dev->saveBLC_PWM_CTL = REG_READ(BLC_PWM_CTL);
450 mode_dev->backlight_duty_cycle = (mode_dev->saveBLC_PWM_CTL &
451 BACKLIGHT_DUTY_CYCLE_MASK);
453 psb_intel_lvds_set_power(dev, output, false);
458 static void psb_intel_lvds_commit(struct drm_encoder *encoder)
460 struct drm_device *dev = encoder->dev;
461 struct psb_intel_output *output = enc_to_psb_intel_output(encoder);
462 struct psb_intel_mode_device *mode_dev = output->mode_dev;
464 if (mode_dev->backlight_duty_cycle == 0)
465 mode_dev->backlight_duty_cycle =
466 psb_intel_lvds_get_max_backlight(dev);
468 psb_intel_lvds_set_power(dev, output, true);
471 static void psb_intel_lvds_mode_set(struct drm_encoder *encoder,
472 struct drm_display_mode *mode,
473 struct drm_display_mode *adjusted_mode)
475 struct drm_device *dev = encoder->dev;
476 struct drm_psb_private *dev_priv = dev->dev_private;
480 * The LVDS pin pair will already have been turned on in the
481 * psb_intel_crtc_mode_set since it has a large impact on the DPLL
486 * Enable automatic panel scaling so that non-native modes fill the
487 * screen. Should be enabled before the pipe is enabled, according to
488 * register description and PRM.
490 if (mode->hdisplay != adjusted_mode->hdisplay ||
491 mode->vdisplay != adjusted_mode->vdisplay)
492 pfit_control = (PFIT_ENABLE | VERT_AUTO_SCALE |
493 HORIZ_AUTO_SCALE | VERT_INTERP_BILINEAR |
494 HORIZ_INTERP_BILINEAR);
498 if (dev_priv->lvds_dither)
499 pfit_control |= PANEL_8TO6_DITHER_ENABLE;
501 REG_WRITE(PFIT_CONTROL, pfit_control);
505 * Detect the LVDS connection.
507 * This always returns CONNECTOR_STATUS_CONNECTED.
508 * This connector should only have
509 * been set up if the LVDS was actually connected anyway.
511 static enum drm_connector_status psb_intel_lvds_detect(struct drm_connector
512 *connector, bool force)
514 return connector_status_connected;
518 * Return the list of DDC modes if available, or the BIOS fixed mode otherwise.
520 static int psb_intel_lvds_get_modes(struct drm_connector *connector)
522 struct drm_device *dev = connector->dev;
523 struct psb_intel_output *psb_intel_output =
524 to_psb_intel_output(connector);
525 struct psb_intel_mode_device *mode_dev =
526 psb_intel_output->mode_dev;
530 ret = psb_intel_ddc_get_modes(psb_intel_output);
535 /* Didn't get an EDID, so
536 * Set wide sync ranges so we get all modes
537 * handed to valid_mode for checking
539 connector->display_info.min_vfreq = 0;
540 connector->display_info.max_vfreq = 200;
541 connector->display_info.min_hfreq = 0;
542 connector->display_info.max_hfreq = 200;
544 if (mode_dev->panel_fixed_mode != NULL) {
545 struct drm_display_mode *mode =
546 drm_mode_duplicate(dev, mode_dev->panel_fixed_mode);
547 drm_mode_probed_add(connector, mode);
555 * psb_intel_lvds_destroy - unregister and free LVDS structures
556 * @connector: connector to free
558 * Unregister the DDC bus for this connector then free the driver private
561 void psb_intel_lvds_destroy(struct drm_connector *connector)
563 struct psb_intel_output *psb_intel_output =
564 to_psb_intel_output(connector);
566 if (psb_intel_output->ddc_bus)
567 psb_intel_i2c_destroy(psb_intel_output->ddc_bus);
568 drm_sysfs_connector_remove(connector);
569 drm_connector_cleanup(connector);
573 int psb_intel_lvds_set_property(struct drm_connector *connector,
574 struct drm_property *property,
577 struct drm_encoder *encoder = connector->encoder;
582 if (!strcmp(property->name, "scaling mode")) {
583 struct psb_intel_crtc *crtc =
584 to_psb_intel_crtc(encoder->crtc);
591 case DRM_MODE_SCALE_FULLSCREEN:
593 case DRM_MODE_SCALE_NO_SCALE:
595 case DRM_MODE_SCALE_ASPECT:
601 if (drm_connector_property_get_value(connector,
609 if (drm_connector_property_set_value(connector,
614 if (crtc->saved_mode.hdisplay != 0 &&
615 crtc->saved_mode.vdisplay != 0) {
616 if (!drm_crtc_helper_set_mode(encoder->crtc,
623 } else if (!strcmp(property->name, "backlight")) {
624 if (drm_connector_property_set_value(connector,
629 #ifdef CONFIG_BACKLIGHT_CLASS_DEVICE
630 struct drm_psb_private *devp =
631 encoder->dev->dev_private;
632 struct backlight_device *bd = devp->backlight_device;
634 bd->props.brightness = value;
635 backlight_update_status(bd);
639 } else if (!strcmp(property->name, "DPMS")) {
640 struct drm_encoder_helper_funcs *hfuncs
641 = encoder->helper_private;
642 hfuncs->dpms(encoder, value);
651 static const struct drm_encoder_helper_funcs psb_intel_lvds_helper_funcs = {
652 .dpms = psb_intel_lvds_encoder_dpms,
653 .mode_fixup = psb_intel_lvds_mode_fixup,
654 .prepare = psb_intel_lvds_prepare,
655 .mode_set = psb_intel_lvds_mode_set,
656 .commit = psb_intel_lvds_commit,
659 const struct drm_connector_helper_funcs
660 psb_intel_lvds_connector_helper_funcs = {
661 .get_modes = psb_intel_lvds_get_modes,
662 .mode_valid = psb_intel_lvds_mode_valid,
663 .best_encoder = psb_intel_best_encoder,
666 const struct drm_connector_funcs psb_intel_lvds_connector_funcs = {
667 .dpms = drm_helper_connector_dpms,
668 .save = psb_intel_lvds_save,
669 .restore = psb_intel_lvds_restore,
670 .detect = psb_intel_lvds_detect,
671 .fill_modes = drm_helper_probe_single_connector_modes,
672 .set_property = psb_intel_lvds_set_property,
673 .destroy = psb_intel_lvds_destroy,
677 static void psb_intel_lvds_enc_destroy(struct drm_encoder *encoder)
679 drm_encoder_cleanup(encoder);
682 const struct drm_encoder_funcs psb_intel_lvds_enc_funcs = {
683 .destroy = psb_intel_lvds_enc_destroy,
689 * psb_intel_lvds_init - setup LVDS connectors on this device
692 * Create the connector, register the LVDS DDC bus, and try to figure out what
693 * modes we can display on the LVDS panel (if present).
695 void psb_intel_lvds_init(struct drm_device *dev,
696 struct psb_intel_mode_device *mode_dev)
698 struct psb_intel_output *psb_intel_output;
699 struct psb_intel_lvds_priv *lvds_priv;
700 struct drm_connector *connector;
701 struct drm_encoder *encoder;
702 struct drm_display_mode *scan; /* *modes, *bios_mode; */
703 struct drm_crtc *crtc;
704 struct drm_psb_private *dev_priv = dev->dev_private;
708 psb_intel_output = kzalloc(sizeof(struct psb_intel_output), GFP_KERNEL);
709 if (!psb_intel_output)
712 lvds_priv = kzalloc(sizeof(struct psb_intel_lvds_priv), GFP_KERNEL);
714 kfree(psb_intel_output);
715 dev_err(dev->dev, "LVDS private allocation error\n");
719 psb_intel_output->dev_priv = lvds_priv;
720 psb_intel_output->mode_dev = mode_dev;
722 connector = &psb_intel_output->base;
723 encoder = &psb_intel_output->enc;
724 drm_connector_init(dev, &psb_intel_output->base,
725 &psb_intel_lvds_connector_funcs,
726 DRM_MODE_CONNECTOR_LVDS);
728 drm_encoder_init(dev, &psb_intel_output->enc,
729 &psb_intel_lvds_enc_funcs,
730 DRM_MODE_ENCODER_LVDS);
732 drm_mode_connector_attach_encoder(&psb_intel_output->base,
733 &psb_intel_output->enc);
734 psb_intel_output->type = INTEL_OUTPUT_LVDS;
736 drm_encoder_helper_add(encoder, &psb_intel_lvds_helper_funcs);
737 drm_connector_helper_add(connector,
738 &psb_intel_lvds_connector_helper_funcs);
739 connector->display_info.subpixel_order = SubPixelHorizontalRGB;
740 connector->interlace_allowed = false;
741 connector->doublescan_allowed = false;
743 /*Attach connector properties*/
744 drm_connector_attach_property(connector,
745 dev->mode_config.scaling_mode_property,
746 DRM_MODE_SCALE_FULLSCREEN);
747 drm_connector_attach_property(connector,
748 dev_priv->backlight_property,
749 BRIGHTNESS_MAX_LEVEL);
753 * FIXME: distroy i2c_bus when exit
755 psb_intel_output->i2c_bus = psb_intel_i2c_create(dev,
758 if (!psb_intel_output->i2c_bus) {
760 &dev->pdev->dev, "I2C bus registration failed.\n");
763 psb_intel_output->i2c_bus->slave_addr = 0x2C;
764 dev_priv->lvds_i2c_bus = psb_intel_output->i2c_bus;
768 * 1) check for EDID on DDC
769 * 2) check for VBT data
770 * 3) check to see if LVDS is already on
771 * if none of the above, no panel
772 * 4) make sure lid is open
773 * if closed, act like it's not there for now
776 /* Set up the DDC bus. */
777 psb_intel_output->ddc_bus = psb_intel_i2c_create(dev,
780 if (!psb_intel_output->ddc_bus) {
781 dev_printk(KERN_ERR, &dev->pdev->dev,
782 "DDC bus registration " "failed.\n");
787 * Attempt to get the fixed panel mode from DDC. Assume that the
788 * preferred mode is the right one.
790 psb_intel_ddc_get_modes(psb_intel_output);
791 list_for_each_entry(scan, &connector->probed_modes, head) {
792 if (scan->type & DRM_MODE_TYPE_PREFERRED) {
793 mode_dev->panel_fixed_mode =
794 drm_mode_duplicate(dev, scan);
795 goto out; /* FIXME: check for quirks */
799 /* Failed to get EDID, what about VBT? do we need this? */
800 if (mode_dev->vbt_mode)
801 mode_dev->panel_fixed_mode =
802 drm_mode_duplicate(dev, mode_dev->vbt_mode);
804 if (!mode_dev->panel_fixed_mode)
805 if (dev_priv->lfp_lvds_vbt_mode)
806 mode_dev->panel_fixed_mode =
807 drm_mode_duplicate(dev,
808 dev_priv->lfp_lvds_vbt_mode);
811 * If we didn't get EDID, try checking if the panel is already turned
812 * on. If so, assume that whatever is currently programmed is the
815 lvds = REG_READ(LVDS);
816 pipe = (lvds & LVDS_PIPEB_SELECT) ? 1 : 0;
817 crtc = psb_intel_get_crtc_from_pipe(dev, pipe);
819 if (crtc && (lvds & LVDS_PORT_EN)) {
820 mode_dev->panel_fixed_mode =
821 psb_intel_crtc_mode_get(dev, crtc);
822 if (mode_dev->panel_fixed_mode) {
823 mode_dev->panel_fixed_mode->type |=
824 DRM_MODE_TYPE_PREFERRED;
825 goto out; /* FIXME: check for quirks */
829 /* If we still don't have a mode after all that, give up. */
830 if (!mode_dev->panel_fixed_mode) {
831 dev_err(dev->dev, "Found no modes on the lvds, ignoring the LVDS\n");
836 * Blacklist machines with BIOSes that list an LVDS panel without
837 * actually having one.
840 drm_sysfs_connector_add(connector);
844 if (psb_intel_output->ddc_bus)
845 psb_intel_i2c_destroy(psb_intel_output->ddc_bus);
847 if (psb_intel_output->i2c_bus)
848 psb_intel_i2c_destroy(psb_intel_output->i2c_bus);
850 drm_encoder_cleanup(encoder);
851 drm_connector_cleanup(connector);