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>
24 /* #include <drm/drm_crtc.h> */
25 /* #include <drm/drm_edid.h> */
28 #include "psb_intel_bios.h"
30 #include "psb_intel_drv.h"
31 #include "psb_intel_reg.h"
32 #include "psb_powermgmt.h"
33 #include <linux/pm_runtime.h>
36 u32 PWMControlRegFreq;
39 * LVDS I2C backlight control macros
41 #define BRIGHTNESS_MAX_LEVEL 100
42 #define BRIGHTNESS_MASK 0xFF
43 #define BLC_I2C_TYPE 0x01
44 #define BLC_PWM_TYPT 0x02
46 #define BLC_POLARITY_NORMAL 0
47 #define BLC_POLARITY_INVERSE 1
49 #define PSB_BLC_MAX_PWM_REG_FREQ (0xFFFE)
50 #define PSB_BLC_MIN_PWM_REG_FREQ (0x2)
51 #define PSB_BLC_PWM_PRECISION_FACTOR (10)
52 #define PSB_BACKLIGHT_PWM_CTL_SHIFT (16)
53 #define PSB_BACKLIGHT_PWM_POLARITY_BIT_CLEAR (0xFFFE)
55 struct psb_intel_lvds_priv {
57 * Saved LVDO output states
62 uint32_t savePP_CONTROL;
63 uint32_t savePP_CYCLE;
64 uint32_t savePFIT_CONTROL;
65 uint32_t savePFIT_PGM_RATIOS;
66 uint32_t saveBLC_PWM_CTL;
69 /* MRST defines end */
72 * Returns the maximum level of the backlight duty cycle field.
74 static u32 psb_intel_lvds_get_max_backlight(struct drm_device *dev)
76 struct drm_psb_private *dev_priv = dev->dev_private;
79 if (gma_power_begin(dev, false)) {
80 retVal = ((REG_READ(BLC_PWM_CTL) &
81 BACKLIGHT_MODULATION_FREQ_MASK) >>
82 BACKLIGHT_MODULATION_FREQ_SHIFT) * 2;
86 retVal = ((dev_priv->saveBLC_PWM_CTL &
87 BACKLIGHT_MODULATION_FREQ_MASK) >>
88 BACKLIGHT_MODULATION_FREQ_SHIFT) * 2;
94 * Set LVDS backlight level by I2C command
96 * FIXME: at some point we need to both track this for PM and also
97 * disable runtime pm on MRST if the brightness is nil (ie blanked)
99 static int psb_lvds_i2c_set_brightness(struct drm_device *dev,
102 struct drm_psb_private *dev_priv =
103 (struct drm_psb_private *)dev->dev_private;
105 struct psb_intel_i2c_chan *lvds_i2c_bus = dev_priv->lvds_i2c_bus;
107 unsigned int blc_i2c_brightness;
109 struct i2c_msg msgs[] = {
111 .addr = lvds_i2c_bus->slave_addr,
118 blc_i2c_brightness = BRIGHTNESS_MASK & ((unsigned int)level *
120 BRIGHTNESS_MAX_LEVEL);
122 if (dev_priv->lvds_bl->pol == BLC_POLARITY_INVERSE)
123 blc_i2c_brightness = BRIGHTNESS_MASK - blc_i2c_brightness;
125 out_buf[0] = dev_priv->lvds_bl->brightnesscmd;
126 out_buf[1] = (u8)blc_i2c_brightness;
128 if (i2c_transfer(&lvds_i2c_bus->adapter, msgs, 1) == 1) {
129 DRM_DEBUG("I2C set brightness.(command, value) (%d, %d)\n",
130 dev_priv->lvds_bl->brightnesscmd,
135 DRM_ERROR("I2C transfer error\n");
140 static int psb_lvds_pwm_set_brightness(struct drm_device *dev, int level)
142 struct drm_psb_private *dev_priv =
143 (struct drm_psb_private *)dev->dev_private;
146 u32 blc_pwm_duty_cycle;
148 max_pwm_blc = psb_intel_lvds_get_max_backlight(dev);
150 /*BLC_PWM_CTL Should be initiated while backlight device init*/
151 BUG_ON((max_pwm_blc & PSB_BLC_MAX_PWM_REG_FREQ) == 0);
153 blc_pwm_duty_cycle = level * max_pwm_blc / BRIGHTNESS_MAX_LEVEL;
155 if (dev_priv->lvds_bl->pol == BLC_POLARITY_INVERSE)
156 blc_pwm_duty_cycle = max_pwm_blc - blc_pwm_duty_cycle;
158 blc_pwm_duty_cycle &= PSB_BACKLIGHT_PWM_POLARITY_BIT_CLEAR;
159 REG_WRITE(BLC_PWM_CTL,
160 (max_pwm_blc << PSB_BACKLIGHT_PWM_CTL_SHIFT) |
161 (blc_pwm_duty_cycle));
167 * Set LVDS backlight level either by I2C or PWM
169 void psb_intel_lvds_set_brightness(struct drm_device *dev, int level)
172 struct drm_psb_private *dev_priv =
173 (struct drm_psb_private *)dev->dev_private;
175 DRM_DEBUG("backlight level is %d\n", level);
177 if (!dev_priv->lvds_bl) {
178 DRM_ERROR("NO LVDS Backlight Info\n");
182 if (dev_priv->lvds_bl->type == BLC_I2C_TYPE)
183 psb_lvds_i2c_set_brightness(dev, level);
185 psb_lvds_pwm_set_brightness(dev, level);
189 * Sets the backlight level.
191 * \param level backlight level, from 0 to psb_intel_lvds_get_max_backlight().
193 static void psb_intel_lvds_set_backlight(struct drm_device *dev, int level)
195 struct drm_psb_private *dev_priv = dev->dev_private;
198 if (gma_power_begin(dev, false)) {
200 REG_READ(BLC_PWM_CTL) & ~BACKLIGHT_DUTY_CYCLE_MASK;
201 REG_WRITE(BLC_PWM_CTL,
203 (level << BACKLIGHT_DUTY_CYCLE_SHIFT)));
206 blc_pwm_ctl = dev_priv->saveBLC_PWM_CTL &
207 ~BACKLIGHT_DUTY_CYCLE_MASK;
208 dev_priv->saveBLC_PWM_CTL = (blc_pwm_ctl |
209 (level << BACKLIGHT_DUTY_CYCLE_SHIFT));
214 * Sets the power state for the panel.
216 static void psb_intel_lvds_set_power(struct drm_device *dev,
217 struct psb_intel_output *output, bool on)
221 if (!gma_power_begin(dev, true))
225 REG_WRITE(PP_CONTROL, REG_READ(PP_CONTROL) |
228 pp_status = REG_READ(PP_STATUS);
229 } while ((pp_status & PP_ON) == 0);
231 psb_intel_lvds_set_backlight(dev,
233 mode_dev->backlight_duty_cycle);
235 psb_intel_lvds_set_backlight(dev, 0);
237 REG_WRITE(PP_CONTROL, REG_READ(PP_CONTROL) &
240 pp_status = REG_READ(PP_STATUS);
241 } while (pp_status & PP_ON);
247 static void psb_intel_lvds_encoder_dpms(struct drm_encoder *encoder, int mode)
249 struct drm_device *dev = encoder->dev;
250 struct psb_intel_output *output = enc_to_psb_intel_output(encoder);
252 if (mode == DRM_MODE_DPMS_ON)
253 psb_intel_lvds_set_power(dev, output, true);
255 psb_intel_lvds_set_power(dev, output, false);
257 /* XXX: We never power down the LVDS pairs. */
260 static void psb_intel_lvds_save(struct drm_connector *connector)
262 struct drm_device *dev = connector->dev;
263 struct drm_psb_private *dev_priv =
264 (struct drm_psb_private *)dev->dev_private;
265 struct psb_intel_output *psb_intel_output =
266 to_psb_intel_output(connector);
267 struct psb_intel_lvds_priv *lvds_priv =
268 (struct psb_intel_lvds_priv *)psb_intel_output->dev_priv;
270 lvds_priv->savePP_ON = REG_READ(LVDSPP_ON);
271 lvds_priv->savePP_OFF = REG_READ(LVDSPP_OFF);
272 lvds_priv->saveLVDS = REG_READ(LVDS);
273 lvds_priv->savePP_CONTROL = REG_READ(PP_CONTROL);
274 lvds_priv->savePP_CYCLE = REG_READ(PP_CYCLE);
275 /*lvds_priv->savePP_DIVISOR = REG_READ(PP_DIVISOR);*/
276 lvds_priv->saveBLC_PWM_CTL = REG_READ(BLC_PWM_CTL);
277 lvds_priv->savePFIT_CONTROL = REG_READ(PFIT_CONTROL);
278 lvds_priv->savePFIT_PGM_RATIOS = REG_READ(PFIT_PGM_RATIOS);
280 /*TODO: move backlight_duty_cycle to psb_intel_lvds_priv*/
281 dev_priv->backlight_duty_cycle = (dev_priv->saveBLC_PWM_CTL &
282 BACKLIGHT_DUTY_CYCLE_MASK);
285 * If the light is off at server startup,
286 * just make it full brightness
288 if (dev_priv->backlight_duty_cycle == 0)
289 dev_priv->backlight_duty_cycle =
290 psb_intel_lvds_get_max_backlight(dev);
292 DRM_DEBUG("(0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x)\n",
293 lvds_priv->savePP_ON,
294 lvds_priv->savePP_OFF,
296 lvds_priv->savePP_CONTROL,
297 lvds_priv->savePP_CYCLE,
298 lvds_priv->saveBLC_PWM_CTL);
301 static void psb_intel_lvds_restore(struct drm_connector *connector)
303 struct drm_device *dev = connector->dev;
306 /*struct drm_psb_private *dev_priv =
307 (struct drm_psb_private *)dev->dev_private;*/
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 DRM_DEBUG("(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 PSB_DEBUG_ENTRY("\n");
356 if (psb_intel_output->type == INTEL_OUTPUT_MIPI2)
357 fixed_mode = psb_intel_output->mode_dev->panel_fixed_mode2;
360 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
361 return MODE_NO_DBLESCAN;
364 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
365 return MODE_NO_INTERLACE;
368 if (mode->hdisplay > fixed_mode->hdisplay)
370 if (mode->vdisplay > fixed_mode->vdisplay)
376 bool psb_intel_lvds_mode_fixup(struct drm_encoder *encoder,
377 struct drm_display_mode *mode,
378 struct drm_display_mode *adjusted_mode)
380 struct psb_intel_mode_device *mode_dev =
381 enc_to_psb_intel_output(encoder)->mode_dev;
382 struct drm_device *dev = encoder->dev;
383 struct psb_intel_crtc *psb_intel_crtc =
384 to_psb_intel_crtc(encoder->crtc);
385 struct drm_encoder *tmp_encoder;
386 struct drm_display_mode *panel_fixed_mode = mode_dev->panel_fixed_mode;
387 struct psb_intel_output *psb_intel_output =
388 enc_to_psb_intel_output(encoder);
390 PSB_DEBUG_ENTRY("type = 0x%x, pipe = %d.\n",
391 psb_intel_output->type, psb_intel_crtc->pipe);
393 if (psb_intel_output->type == INTEL_OUTPUT_MIPI2)
394 panel_fixed_mode = mode_dev->panel_fixed_mode2;
396 /* PSB requires the LVDS is on pipe B, MRST has only one pipe anyway */
397 if (!IS_MRST(dev) && psb_intel_crtc->pipe == 0) {
398 printk(KERN_ERR "Can't support LVDS on pipe A\n");
401 if (IS_MRST(dev) && psb_intel_crtc->pipe != 0) {
402 printk(KERN_ERR "Must use PIPE A\n");
405 /* Should never happen!! */
406 list_for_each_entry(tmp_encoder, &dev->mode_config.encoder_list,
408 if (tmp_encoder != encoder
409 && tmp_encoder->crtc == encoder->crtc) {
410 printk(KERN_ERR "Can't enable LVDS and another "
411 "encoder on the same pipe\n");
417 * If we have timings from the BIOS for the panel, put them in
418 * to the adjusted mode. The CRTC will be set up for this mode,
419 * with the panel scaling set up to source from the H/VDisplay
420 * of the original mode.
422 if (panel_fixed_mode != NULL) {
423 adjusted_mode->hdisplay = panel_fixed_mode->hdisplay;
424 adjusted_mode->hsync_start = panel_fixed_mode->hsync_start;
425 adjusted_mode->hsync_end = panel_fixed_mode->hsync_end;
426 adjusted_mode->htotal = panel_fixed_mode->htotal;
427 adjusted_mode->vdisplay = panel_fixed_mode->vdisplay;
428 adjusted_mode->vsync_start = panel_fixed_mode->vsync_start;
429 adjusted_mode->vsync_end = panel_fixed_mode->vsync_end;
430 adjusted_mode->vtotal = panel_fixed_mode->vtotal;
431 adjusted_mode->clock = panel_fixed_mode->clock;
432 drm_mode_set_crtcinfo(adjusted_mode,
433 CRTC_INTERLACE_HALVE_V);
437 * XXX: It would be nice to support lower refresh rates on the
438 * panels to reduce power consumption, and perhaps match the
439 * user's requested refresh rate.
445 void psb_intel_lvds_prepare(struct drm_encoder *encoder)
447 struct drm_device *dev = encoder->dev;
448 struct psb_intel_output *output = enc_to_psb_intel_output(encoder);
449 struct psb_intel_mode_device *mode_dev = output->mode_dev;
451 PSB_DEBUG_ENTRY("\n");
453 if (!gma_power_begin(dev, true))
456 mode_dev->saveBLC_PWM_CTL = REG_READ(BLC_PWM_CTL);
457 mode_dev->backlight_duty_cycle = (mode_dev->saveBLC_PWM_CTL &
458 BACKLIGHT_DUTY_CYCLE_MASK);
460 psb_intel_lvds_set_power(dev, output, false);
465 void psb_intel_lvds_commit(struct drm_encoder *encoder)
467 struct drm_device *dev = encoder->dev;
468 struct psb_intel_output *output = enc_to_psb_intel_output(encoder);
469 struct psb_intel_mode_device *mode_dev = output->mode_dev;
471 PSB_DEBUG_ENTRY("\n");
473 if (mode_dev->backlight_duty_cycle == 0)
474 mode_dev->backlight_duty_cycle =
475 psb_intel_lvds_get_max_backlight(dev);
477 psb_intel_lvds_set_power(dev, output, true);
480 static void psb_intel_lvds_mode_set(struct drm_encoder *encoder,
481 struct drm_display_mode *mode,
482 struct drm_display_mode *adjusted_mode)
484 struct psb_intel_mode_device *mode_dev =
485 enc_to_psb_intel_output(encoder)->mode_dev;
486 struct drm_device *dev = encoder->dev;
490 * The LVDS pin pair will already have been turned on in the
491 * psb_intel_crtc_mode_set since it has a large impact on the DPLL
496 * Enable automatic panel scaling so that non-native modes fill the
497 * screen. Should be enabled before the pipe is enabled, according to
498 * register description and PRM.
500 if (mode->hdisplay != adjusted_mode->hdisplay ||
501 mode->vdisplay != adjusted_mode->vdisplay)
502 pfit_control = (PFIT_ENABLE | VERT_AUTO_SCALE |
503 HORIZ_AUTO_SCALE | VERT_INTERP_BILINEAR |
504 HORIZ_INTERP_BILINEAR);
508 if (mode_dev->panel_wants_dither)
509 pfit_control |= PANEL_8TO6_DITHER_ENABLE;
511 REG_WRITE(PFIT_CONTROL, pfit_control);
515 * Detect the LVDS connection.
517 * This always returns CONNECTOR_STATUS_CONNECTED.
518 * This connector should only have
519 * been set up if the LVDS was actually connected anyway.
521 static enum drm_connector_status psb_intel_lvds_detect(struct drm_connector
522 *connector, bool force)
524 return connector_status_connected;
528 * Return the list of DDC modes if available, or the BIOS fixed mode otherwise.
530 static int psb_intel_lvds_get_modes(struct drm_connector *connector)
532 struct drm_device *dev = connector->dev;
533 struct psb_intel_output *psb_intel_output =
534 to_psb_intel_output(connector);
535 struct psb_intel_mode_device *mode_dev =
536 psb_intel_output->mode_dev;
539 ret = psb_intel_ddc_get_modes(psb_intel_output);
544 /* Didn't get an EDID, so
545 * Set wide sync ranges so we get all modes
546 * handed to valid_mode for checking
548 connector->display_info.min_vfreq = 0;
549 connector->display_info.max_vfreq = 200;
550 connector->display_info.min_hfreq = 0;
551 connector->display_info.max_hfreq = 200;
553 if (mode_dev->panel_fixed_mode != NULL) {
554 struct drm_display_mode *mode =
555 drm_mode_duplicate(dev, mode_dev->panel_fixed_mode);
556 drm_mode_probed_add(connector, mode);
564 * psb_intel_lvds_destroy - unregister and free LVDS structures
565 * @connector: connector to free
567 * Unregister the DDC bus for this connector then free the driver private
570 void psb_intel_lvds_destroy(struct drm_connector *connector)
572 struct psb_intel_output *psb_intel_output =
573 to_psb_intel_output(connector);
575 if (psb_intel_output->ddc_bus)
576 psb_intel_i2c_destroy(psb_intel_output->ddc_bus);
577 drm_sysfs_connector_remove(connector);
578 drm_connector_cleanup(connector);
582 int psb_intel_lvds_set_property(struct drm_connector *connector,
583 struct drm_property *property,
586 struct drm_encoder *pEncoder = connector->encoder;
588 PSB_DEBUG_ENTRY("\n");
590 if (!strcmp(property->name, "scaling mode") && pEncoder) {
591 struct psb_intel_crtc *pPsbCrtc =
592 to_psb_intel_crtc(pEncoder->crtc);
595 PSB_DEBUG_ENTRY("scaling mode\n");
601 case DRM_MODE_SCALE_FULLSCREEN:
603 case DRM_MODE_SCALE_NO_SCALE:
605 case DRM_MODE_SCALE_ASPECT:
611 if (drm_connector_property_get_value(connector,
616 if (curValue == value)
619 if (drm_connector_property_set_value(connector,
624 if (pPsbCrtc->saved_mode.hdisplay != 0 &&
625 pPsbCrtc->saved_mode.vdisplay != 0) {
626 if (!drm_crtc_helper_set_mode(pEncoder->crtc,
627 &pPsbCrtc->saved_mode,
633 } else if (!strcmp(property->name, "backlight") && pEncoder) {
634 PSB_DEBUG_ENTRY("backlight\n");
636 if (drm_connector_property_set_value(connector,
641 #ifdef CONFIG_BACKLIGHT_CLASS_DEVICE
642 struct backlight_device bd;
643 bd.props.brightness = value;
644 psb_set_brightness(&bd);
647 } else if (!strcmp(property->name, "DPMS") && pEncoder) {
648 struct drm_encoder_helper_funcs *pEncHFuncs
649 = pEncoder->helper_private;
650 PSB_DEBUG_ENTRY("DPMS\n");
651 pEncHFuncs->dpms(pEncoder, value);
660 static const struct drm_encoder_helper_funcs psb_intel_lvds_helper_funcs = {
661 .dpms = psb_intel_lvds_encoder_dpms,
662 .mode_fixup = psb_intel_lvds_mode_fixup,
663 .prepare = psb_intel_lvds_prepare,
664 .mode_set = psb_intel_lvds_mode_set,
665 .commit = psb_intel_lvds_commit,
668 const struct drm_connector_helper_funcs
669 psb_intel_lvds_connector_helper_funcs = {
670 .get_modes = psb_intel_lvds_get_modes,
671 .mode_valid = psb_intel_lvds_mode_valid,
672 .best_encoder = psb_intel_best_encoder,
675 const struct drm_connector_funcs psb_intel_lvds_connector_funcs = {
676 .dpms = drm_helper_connector_dpms,
677 .save = psb_intel_lvds_save,
678 .restore = psb_intel_lvds_restore,
679 .detect = psb_intel_lvds_detect,
680 .fill_modes = drm_helper_probe_single_connector_modes,
681 .set_property = psb_intel_lvds_set_property,
682 .destroy = psb_intel_lvds_destroy,
686 static void psb_intel_lvds_enc_destroy(struct drm_encoder *encoder)
688 drm_encoder_cleanup(encoder);
691 const struct drm_encoder_funcs psb_intel_lvds_enc_funcs = {
692 .destroy = psb_intel_lvds_enc_destroy,
698 * psb_intel_lvds_init - setup LVDS connectors on this device
701 * Create the connector, register the LVDS DDC bus, and try to figure out what
702 * modes we can display on the LVDS panel (if present).
704 void psb_intel_lvds_init(struct drm_device *dev,
705 struct psb_intel_mode_device *mode_dev)
707 struct psb_intel_output *psb_intel_output;
708 struct psb_intel_lvds_priv *lvds_priv;
709 struct drm_connector *connector;
710 struct drm_encoder *encoder;
711 struct drm_display_mode *scan; /* *modes, *bios_mode; */
712 struct drm_crtc *crtc;
713 struct drm_psb_private *dev_priv =
714 (struct drm_psb_private *)dev->dev_private;
718 psb_intel_output = kzalloc(sizeof(struct psb_intel_output), GFP_KERNEL);
719 if (!psb_intel_output)
722 lvds_priv = kzalloc(sizeof(struct psb_intel_lvds_priv), GFP_KERNEL);
724 kfree(psb_intel_output);
725 DRM_DEBUG("LVDS private allocation error\n");
729 psb_intel_output->dev_priv = lvds_priv;
731 psb_intel_output->mode_dev = mode_dev;
732 connector = &psb_intel_output->base;
733 encoder = &psb_intel_output->enc;
734 drm_connector_init(dev, &psb_intel_output->base,
735 &psb_intel_lvds_connector_funcs,
736 DRM_MODE_CONNECTOR_LVDS);
738 drm_encoder_init(dev, &psb_intel_output->enc,
739 &psb_intel_lvds_enc_funcs,
740 DRM_MODE_ENCODER_LVDS);
742 drm_mode_connector_attach_encoder(&psb_intel_output->base,
743 &psb_intel_output->enc);
744 psb_intel_output->type = INTEL_OUTPUT_LVDS;
746 drm_encoder_helper_add(encoder, &psb_intel_lvds_helper_funcs);
747 drm_connector_helper_add(connector,
748 &psb_intel_lvds_connector_helper_funcs);
749 connector->display_info.subpixel_order = SubPixelHorizontalRGB;
750 connector->interlace_allowed = false;
751 connector->doublescan_allowed = false;
753 /*Attach connector properties*/
754 drm_connector_attach_property(connector,
755 dev->mode_config.scaling_mode_property,
756 DRM_MODE_SCALE_FULLSCREEN);
757 drm_connector_attach_property(connector,
758 dev_priv->backlight_property,
759 BRIGHTNESS_MAX_LEVEL);
763 * FIXME: distroy i2c_bus when exit
765 psb_intel_output->i2c_bus = psb_intel_i2c_create(dev,
768 if (!psb_intel_output->i2c_bus) {
770 &dev->pdev->dev, "I2C bus registration failed.\n");
773 psb_intel_output->i2c_bus->slave_addr = 0x2C;
774 dev_priv->lvds_i2c_bus = psb_intel_output->i2c_bus;
778 * 1) check for EDID on DDC
779 * 2) check for VBT data
780 * 3) check to see if LVDS is already on
781 * if none of the above, no panel
782 * 4) make sure lid is open
783 * if closed, act like it's not there for now
786 /* Set up the DDC bus. */
787 psb_intel_output->ddc_bus = psb_intel_i2c_create(dev,
790 if (!psb_intel_output->ddc_bus) {
791 dev_printk(KERN_ERR, &dev->pdev->dev,
792 "DDC bus registration " "failed.\n");
797 * Attempt to get the fixed panel mode from DDC. Assume that the
798 * preferred mode is the right one.
800 psb_intel_ddc_get_modes(psb_intel_output);
801 list_for_each_entry(scan, &connector->probed_modes, head) {
802 if (scan->type & DRM_MODE_TYPE_PREFERRED) {
803 mode_dev->panel_fixed_mode =
804 drm_mode_duplicate(dev, scan);
805 goto out; /* FIXME: check for quirks */
809 /* Failed to get EDID, what about VBT? do we need this?*/
810 if (mode_dev->vbt_mode)
811 mode_dev->panel_fixed_mode =
812 drm_mode_duplicate(dev, mode_dev->vbt_mode);
814 if (!mode_dev->panel_fixed_mode)
815 if (dev_priv->lfp_lvds_vbt_mode)
816 mode_dev->panel_fixed_mode =
817 drm_mode_duplicate(dev,
818 dev_priv->lfp_lvds_vbt_mode);
821 * If we didn't get EDID, try checking if the panel is already turned
822 * on. If so, assume that whatever is currently programmed is the
825 lvds = REG_READ(LVDS);
826 pipe = (lvds & LVDS_PIPEB_SELECT) ? 1 : 0;
827 crtc = psb_intel_get_crtc_from_pipe(dev, pipe);
829 if (crtc && (lvds & LVDS_PORT_EN)) {
830 mode_dev->panel_fixed_mode =
831 psb_intel_crtc_mode_get(dev, crtc);
832 if (mode_dev->panel_fixed_mode) {
833 mode_dev->panel_fixed_mode->type |=
834 DRM_MODE_TYPE_PREFERRED;
835 goto out; /* FIXME: check for quirks */
839 /* If we still don't have a mode after all that, give up. */
840 if (!mode_dev->panel_fixed_mode) {
842 ("Found no modes on the lvds, ignoring the LVDS\n");
847 * Blacklist machines with BIOSes that list an LVDS panel without
848 * actually having one.
851 drm_sysfs_connector_add(connector);
853 PSB_DEBUG_ENTRY("hdisplay = %d\n",
854 mode_dev->panel_fixed_mode->hdisplay);
855 PSB_DEBUG_ENTRY(" vdisplay = %d\n",
856 mode_dev->panel_fixed_mode->vdisplay);
857 PSB_DEBUG_ENTRY(" hsync_start = %d\n",
858 mode_dev->panel_fixed_mode->hsync_start);
859 PSB_DEBUG_ENTRY(" hsync_end = %d\n",
860 mode_dev->panel_fixed_mode->hsync_end);
861 PSB_DEBUG_ENTRY(" htotal = %d\n",
862 mode_dev->panel_fixed_mode->htotal);
863 PSB_DEBUG_ENTRY(" vsync_start = %d\n",
864 mode_dev->panel_fixed_mode->vsync_start);
865 PSB_DEBUG_ENTRY(" vsync_end = %d\n",
866 mode_dev->panel_fixed_mode->vsync_end);
867 PSB_DEBUG_ENTRY(" vtotal = %d\n",
868 mode_dev->panel_fixed_mode->vtotal);
869 PSB_DEBUG_ENTRY(" clock = %d\n",
870 mode_dev->panel_fixed_mode->clock);
875 if (psb_intel_output->ddc_bus)
876 psb_intel_i2c_destroy(psb_intel_output->ddc_bus);
878 if (psb_intel_output->i2c_bus)
879 psb_intel_i2c_destroy(psb_intel_output->i2c_bus);
881 drm_encoder_cleanup(encoder);
882 drm_connector_cleanup(connector);