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;
63 struct psb_intel_i2c_chan *i2c_bus;
64 struct psb_intel_i2c_chan *ddc_bus;
69 * Returns the maximum level of the backlight duty cycle field.
71 static u32 psb_intel_lvds_get_max_backlight(struct drm_device *dev)
73 struct drm_psb_private *dev_priv = dev->dev_private;
76 if (gma_power_begin(dev, false)) {
77 ret = REG_READ(BLC_PWM_CTL);
79 } else /* Powered off, use the saved value */
80 ret = dev_priv->regs.saveBLC_PWM_CTL;
82 /* Top 15bits hold the frequency mask */
83 ret = (ret & BACKLIGHT_MODULATION_FREQ_MASK) >>
84 BACKLIGHT_MODULATION_FREQ_SHIFT;
86 ret *= 2; /* Return a 16bit range as needed for setting */
88 dev_err(dev->dev, "BL bug: Reg %08x save %08X\n",
89 REG_READ(BLC_PWM_CTL), dev_priv->regs.saveBLC_PWM_CTL);
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 dev_dbg(dev->dev, "I2C set brightness.(command, value) (%d, %d)\n",
130 dev_priv->lvds_bl->brightnesscmd,
135 dev_err(dev->dev, "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 == 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));
163 dev_info(dev->dev, "Backlight lvds set brightness %08x\n",
164 (max_pwm_blc << PSB_BACKLIGHT_PWM_CTL_SHIFT) |
165 (blc_pwm_duty_cycle));
171 * Set LVDS backlight level either by I2C or PWM
173 void psb_intel_lvds_set_brightness(struct drm_device *dev, int level)
175 struct drm_psb_private *dev_priv = dev->dev_private;
177 dev_dbg(dev->dev, "backlight level is %d\n", level);
179 if (!dev_priv->lvds_bl) {
180 dev_err(dev->dev, "NO LVDS backlight info\n");
184 if (dev_priv->lvds_bl->type == BLC_I2C_TYPE)
185 psb_lvds_i2c_set_brightness(dev, level);
187 psb_lvds_pwm_set_brightness(dev, level);
191 * Sets the backlight level.
193 * level: backlight level, from 0 to psb_intel_lvds_get_max_backlight().
195 static void psb_intel_lvds_set_backlight(struct drm_device *dev, int level)
197 struct drm_psb_private *dev_priv = dev->dev_private;
200 if (gma_power_begin(dev, false)) {
201 blc_pwm_ctl = REG_READ(BLC_PWM_CTL);
202 blc_pwm_ctl &= ~BACKLIGHT_DUTY_CYCLE_MASK;
203 REG_WRITE(BLC_PWM_CTL,
205 (level << BACKLIGHT_DUTY_CYCLE_SHIFT)));
206 dev_priv->regs.saveBLC_PWM_CTL = (blc_pwm_ctl |
207 (level << BACKLIGHT_DUTY_CYCLE_SHIFT));
210 blc_pwm_ctl = dev_priv->regs.saveBLC_PWM_CTL &
211 ~BACKLIGHT_DUTY_CYCLE_MASK;
212 dev_priv->regs.saveBLC_PWM_CTL = (blc_pwm_ctl |
213 (level << BACKLIGHT_DUTY_CYCLE_SHIFT));
218 * Sets the power state for the panel.
220 static void psb_intel_lvds_set_power(struct drm_device *dev, bool on)
222 struct drm_psb_private *dev_priv = dev->dev_private;
223 struct psb_intel_mode_device *mode_dev = &dev_priv->mode_dev;
226 if (!gma_power_begin(dev, true)) {
227 dev_err(dev->dev, "set power, chip off!\n");
232 REG_WRITE(PP_CONTROL, REG_READ(PP_CONTROL) |
235 pp_status = REG_READ(PP_STATUS);
236 } while ((pp_status & PP_ON) == 0);
238 psb_intel_lvds_set_backlight(dev,
239 mode_dev->backlight_duty_cycle);
241 psb_intel_lvds_set_backlight(dev, 0);
243 REG_WRITE(PP_CONTROL, REG_READ(PP_CONTROL) &
246 pp_status = REG_READ(PP_STATUS);
247 } while (pp_status & PP_ON);
253 static void psb_intel_lvds_encoder_dpms(struct drm_encoder *encoder, int mode)
255 struct drm_device *dev = encoder->dev;
257 if (mode == DRM_MODE_DPMS_ON)
258 psb_intel_lvds_set_power(dev, true);
260 psb_intel_lvds_set_power(dev, false);
262 /* XXX: We never power down the LVDS pairs. */
265 static void psb_intel_lvds_save(struct drm_connector *connector)
267 struct drm_device *dev = connector->dev;
268 struct drm_psb_private *dev_priv =
269 (struct drm_psb_private *)dev->dev_private;
270 struct psb_intel_encoder *psb_intel_encoder =
271 psb_intel_attached_encoder(connector);
272 struct psb_intel_lvds_priv *lvds_priv =
273 (struct psb_intel_lvds_priv *)psb_intel_encoder->dev_priv;
275 lvds_priv->savePP_ON = REG_READ(LVDSPP_ON);
276 lvds_priv->savePP_OFF = REG_READ(LVDSPP_OFF);
277 lvds_priv->saveLVDS = REG_READ(LVDS);
278 lvds_priv->savePP_CONTROL = REG_READ(PP_CONTROL);
279 lvds_priv->savePP_CYCLE = REG_READ(PP_CYCLE);
280 /*lvds_priv->savePP_DIVISOR = REG_READ(PP_DIVISOR);*/
281 lvds_priv->saveBLC_PWM_CTL = REG_READ(BLC_PWM_CTL);
282 lvds_priv->savePFIT_CONTROL = REG_READ(PFIT_CONTROL);
283 lvds_priv->savePFIT_PGM_RATIOS = REG_READ(PFIT_PGM_RATIOS);
285 /*TODO: move backlight_duty_cycle to psb_intel_lvds_priv*/
286 dev_priv->backlight_duty_cycle = (dev_priv->regs.saveBLC_PWM_CTL &
287 BACKLIGHT_DUTY_CYCLE_MASK);
290 * If the light is off at server startup,
291 * just make it full brightness
293 if (dev_priv->backlight_duty_cycle == 0)
294 dev_priv->backlight_duty_cycle =
295 psb_intel_lvds_get_max_backlight(dev);
297 dev_dbg(dev->dev, "(0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x)\n",
298 lvds_priv->savePP_ON,
299 lvds_priv->savePP_OFF,
301 lvds_priv->savePP_CONTROL,
302 lvds_priv->savePP_CYCLE,
303 lvds_priv->saveBLC_PWM_CTL);
306 static void psb_intel_lvds_restore(struct drm_connector *connector)
308 struct drm_device *dev = connector->dev;
310 struct psb_intel_encoder *psb_intel_encoder =
311 psb_intel_attached_encoder(connector);
312 struct psb_intel_lvds_priv *lvds_priv =
313 (struct psb_intel_lvds_priv *)psb_intel_encoder->dev_priv;
315 dev_dbg(dev->dev, "(0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x)\n",
316 lvds_priv->savePP_ON,
317 lvds_priv->savePP_OFF,
319 lvds_priv->savePP_CONTROL,
320 lvds_priv->savePP_CYCLE,
321 lvds_priv->saveBLC_PWM_CTL);
323 REG_WRITE(BLC_PWM_CTL, lvds_priv->saveBLC_PWM_CTL);
324 REG_WRITE(PFIT_CONTROL, lvds_priv->savePFIT_CONTROL);
325 REG_WRITE(PFIT_PGM_RATIOS, lvds_priv->savePFIT_PGM_RATIOS);
326 REG_WRITE(LVDSPP_ON, lvds_priv->savePP_ON);
327 REG_WRITE(LVDSPP_OFF, lvds_priv->savePP_OFF);
328 /*REG_WRITE(PP_DIVISOR, lvds_priv->savePP_DIVISOR);*/
329 REG_WRITE(PP_CYCLE, lvds_priv->savePP_CYCLE);
330 REG_WRITE(PP_CONTROL, lvds_priv->savePP_CONTROL);
331 REG_WRITE(LVDS, lvds_priv->saveLVDS);
333 if (lvds_priv->savePP_CONTROL & POWER_TARGET_ON) {
334 REG_WRITE(PP_CONTROL, REG_READ(PP_CONTROL) |
337 pp_status = REG_READ(PP_STATUS);
338 } while ((pp_status & PP_ON) == 0);
340 REG_WRITE(PP_CONTROL, REG_READ(PP_CONTROL) &
343 pp_status = REG_READ(PP_STATUS);
344 } while (pp_status & PP_ON);
348 int psb_intel_lvds_mode_valid(struct drm_connector *connector,
349 struct drm_display_mode *mode)
351 struct drm_psb_private *dev_priv = connector->dev->dev_private;
352 struct psb_intel_encoder *psb_intel_encoder =
353 psb_intel_attached_encoder(connector);
354 struct drm_display_mode *fixed_mode =
355 dev_priv->mode_dev.panel_fixed_mode;
357 if (psb_intel_encoder->type == INTEL_OUTPUT_MIPI2)
358 fixed_mode = dev_priv->mode_dev.panel_fixed_mode2;
361 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
362 return MODE_NO_DBLESCAN;
365 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
366 return MODE_NO_INTERLACE;
369 if (mode->hdisplay > fixed_mode->hdisplay)
371 if (mode->vdisplay > fixed_mode->vdisplay)
377 bool psb_intel_lvds_mode_fixup(struct drm_encoder *encoder,
378 const struct drm_display_mode *mode,
379 struct drm_display_mode *adjusted_mode)
381 struct drm_device *dev = encoder->dev;
382 struct drm_psb_private *dev_priv = dev->dev_private;
383 struct psb_intel_mode_device *mode_dev = &dev_priv->mode_dev;
384 struct psb_intel_crtc *psb_intel_crtc =
385 to_psb_intel_crtc(encoder->crtc);
386 struct drm_encoder *tmp_encoder;
387 struct drm_display_mode *panel_fixed_mode = mode_dev->panel_fixed_mode;
388 struct psb_intel_encoder *psb_intel_encoder =
389 to_psb_intel_encoder(encoder);
391 if (psb_intel_encoder->type == INTEL_OUTPUT_MIPI2)
392 panel_fixed_mode = mode_dev->panel_fixed_mode2;
394 /* PSB requires the LVDS is on pipe B, MRST has only one pipe anyway */
395 if (!IS_MRST(dev) && psb_intel_crtc->pipe == 0) {
396 printk(KERN_ERR "Can't support LVDS on pipe A\n");
399 if (IS_MRST(dev) && psb_intel_crtc->pipe != 0) {
400 printk(KERN_ERR "Must use PIPE A\n");
403 /* Should never happen!! */
404 list_for_each_entry(tmp_encoder, &dev->mode_config.encoder_list,
406 if (tmp_encoder != encoder
407 && tmp_encoder->crtc == encoder->crtc) {
408 printk(KERN_ERR "Can't enable LVDS and another "
409 "encoder on the same pipe\n");
415 * If we have timings from the BIOS for the panel, put them in
416 * to the adjusted mode. The CRTC will be set up for this mode,
417 * with the panel scaling set up to source from the H/VDisplay
418 * of the original mode.
420 if (panel_fixed_mode != NULL) {
421 adjusted_mode->hdisplay = panel_fixed_mode->hdisplay;
422 adjusted_mode->hsync_start = panel_fixed_mode->hsync_start;
423 adjusted_mode->hsync_end = panel_fixed_mode->hsync_end;
424 adjusted_mode->htotal = panel_fixed_mode->htotal;
425 adjusted_mode->vdisplay = panel_fixed_mode->vdisplay;
426 adjusted_mode->vsync_start = panel_fixed_mode->vsync_start;
427 adjusted_mode->vsync_end = panel_fixed_mode->vsync_end;
428 adjusted_mode->vtotal = panel_fixed_mode->vtotal;
429 adjusted_mode->clock = panel_fixed_mode->clock;
430 drm_mode_set_crtcinfo(adjusted_mode,
431 CRTC_INTERLACE_HALVE_V);
435 * XXX: It would be nice to support lower refresh rates on the
436 * panels to reduce power consumption, and perhaps match the
437 * user's requested refresh rate.
443 static void psb_intel_lvds_prepare(struct drm_encoder *encoder)
445 struct drm_device *dev = encoder->dev;
446 struct drm_psb_private *dev_priv = dev->dev_private;
447 struct psb_intel_mode_device *mode_dev = &dev_priv->mode_dev;
449 if (!gma_power_begin(dev, true))
452 mode_dev->saveBLC_PWM_CTL = REG_READ(BLC_PWM_CTL);
453 mode_dev->backlight_duty_cycle = (mode_dev->saveBLC_PWM_CTL &
454 BACKLIGHT_DUTY_CYCLE_MASK);
456 psb_intel_lvds_set_power(dev, false);
461 static void psb_intel_lvds_commit(struct drm_encoder *encoder)
463 struct drm_device *dev = encoder->dev;
464 struct drm_psb_private *dev_priv = dev->dev_private;
465 struct psb_intel_mode_device *mode_dev = &dev_priv->mode_dev;
467 if (mode_dev->backlight_duty_cycle == 0)
468 mode_dev->backlight_duty_cycle =
469 psb_intel_lvds_get_max_backlight(dev);
471 psb_intel_lvds_set_power(dev, true);
474 static void psb_intel_lvds_mode_set(struct drm_encoder *encoder,
475 struct drm_display_mode *mode,
476 struct drm_display_mode *adjusted_mode)
478 struct drm_device *dev = encoder->dev;
479 struct drm_psb_private *dev_priv = dev->dev_private;
483 * The LVDS pin pair will already have been turned on in the
484 * psb_intel_crtc_mode_set since it has a large impact on the DPLL
489 * Enable automatic panel scaling so that non-native modes fill the
490 * screen. Should be enabled before the pipe is enabled, according to
491 * register description and PRM.
493 if (mode->hdisplay != adjusted_mode->hdisplay ||
494 mode->vdisplay != adjusted_mode->vdisplay)
495 pfit_control = (PFIT_ENABLE | VERT_AUTO_SCALE |
496 HORIZ_AUTO_SCALE | VERT_INTERP_BILINEAR |
497 HORIZ_INTERP_BILINEAR);
501 if (dev_priv->lvds_dither)
502 pfit_control |= PANEL_8TO6_DITHER_ENABLE;
504 REG_WRITE(PFIT_CONTROL, pfit_control);
508 * Detect the LVDS connection.
510 * This always returns CONNECTOR_STATUS_CONNECTED.
511 * This connector should only have
512 * been set up if the LVDS was actually connected anyway.
514 static enum drm_connector_status psb_intel_lvds_detect(struct drm_connector
515 *connector, bool force)
517 return connector_status_connected;
521 * Return the list of DDC modes if available, or the BIOS fixed mode otherwise.
523 static int psb_intel_lvds_get_modes(struct drm_connector *connector)
525 struct drm_device *dev = connector->dev;
526 struct drm_psb_private *dev_priv = dev->dev_private;
527 struct psb_intel_mode_device *mode_dev = &dev_priv->mode_dev;
528 struct psb_intel_encoder *psb_intel_encoder =
529 psb_intel_attached_encoder(connector);
530 struct psb_intel_lvds_priv *lvds_priv = psb_intel_encoder->dev_priv;
534 ret = psb_intel_ddc_get_modes(connector, &lvds_priv->i2c_bus->adapter);
539 /* Didn't get an EDID, so
540 * Set wide sync ranges so we get all modes
541 * handed to valid_mode for checking
543 connector->display_info.min_vfreq = 0;
544 connector->display_info.max_vfreq = 200;
545 connector->display_info.min_hfreq = 0;
546 connector->display_info.max_hfreq = 200;
548 if (mode_dev->panel_fixed_mode != NULL) {
549 struct drm_display_mode *mode =
550 drm_mode_duplicate(dev, mode_dev->panel_fixed_mode);
551 drm_mode_probed_add(connector, mode);
559 * psb_intel_lvds_destroy - unregister and free LVDS structures
560 * @connector: connector to free
562 * Unregister the DDC bus for this connector then free the driver private
565 void psb_intel_lvds_destroy(struct drm_connector *connector)
567 struct psb_intel_encoder *psb_intel_encoder =
568 psb_intel_attached_encoder(connector);
569 struct psb_intel_lvds_priv *lvds_priv = psb_intel_encoder->dev_priv;
571 if (lvds_priv->ddc_bus)
572 psb_intel_i2c_destroy(lvds_priv->ddc_bus);
573 drm_sysfs_connector_remove(connector);
574 drm_connector_cleanup(connector);
578 int psb_intel_lvds_set_property(struct drm_connector *connector,
579 struct drm_property *property,
582 struct drm_encoder *encoder = connector->encoder;
587 if (!strcmp(property->name, "scaling mode")) {
588 struct psb_intel_crtc *crtc =
589 to_psb_intel_crtc(encoder->crtc);
596 case DRM_MODE_SCALE_FULLSCREEN:
598 case DRM_MODE_SCALE_NO_SCALE:
600 case DRM_MODE_SCALE_ASPECT:
606 if (drm_connector_property_get_value(connector,
614 if (drm_connector_property_set_value(connector,
619 if (crtc->saved_mode.hdisplay != 0 &&
620 crtc->saved_mode.vdisplay != 0) {
621 if (!drm_crtc_helper_set_mode(encoder->crtc,
628 } else if (!strcmp(property->name, "backlight")) {
629 if (drm_connector_property_set_value(connector,
634 #ifdef CONFIG_BACKLIGHT_CLASS_DEVICE
635 struct drm_psb_private *devp =
636 encoder->dev->dev_private;
637 struct backlight_device *bd = devp->backlight_device;
639 bd->props.brightness = value;
640 backlight_update_status(bd);
644 } else if (!strcmp(property->name, "DPMS")) {
645 struct drm_encoder_helper_funcs *hfuncs
646 = encoder->helper_private;
647 hfuncs->dpms(encoder, value);
656 static const struct drm_encoder_helper_funcs psb_intel_lvds_helper_funcs = {
657 .dpms = psb_intel_lvds_encoder_dpms,
658 .mode_fixup = psb_intel_lvds_mode_fixup,
659 .prepare = psb_intel_lvds_prepare,
660 .mode_set = psb_intel_lvds_mode_set,
661 .commit = psb_intel_lvds_commit,
664 const struct drm_connector_helper_funcs
665 psb_intel_lvds_connector_helper_funcs = {
666 .get_modes = psb_intel_lvds_get_modes,
667 .mode_valid = psb_intel_lvds_mode_valid,
668 .best_encoder = psb_intel_best_encoder,
671 const struct drm_connector_funcs psb_intel_lvds_connector_funcs = {
672 .dpms = drm_helper_connector_dpms,
673 .save = psb_intel_lvds_save,
674 .restore = psb_intel_lvds_restore,
675 .detect = psb_intel_lvds_detect,
676 .fill_modes = drm_helper_probe_single_connector_modes,
677 .set_property = psb_intel_lvds_set_property,
678 .destroy = psb_intel_lvds_destroy,
682 static void psb_intel_lvds_enc_destroy(struct drm_encoder *encoder)
684 drm_encoder_cleanup(encoder);
687 const struct drm_encoder_funcs psb_intel_lvds_enc_funcs = {
688 .destroy = psb_intel_lvds_enc_destroy,
694 * psb_intel_lvds_init - setup LVDS connectors on this device
697 * Create the connector, register the LVDS DDC bus, and try to figure out what
698 * modes we can display on the LVDS panel (if present).
700 void psb_intel_lvds_init(struct drm_device *dev,
701 struct psb_intel_mode_device *mode_dev)
703 struct psb_intel_encoder *psb_intel_encoder;
704 struct psb_intel_connector *psb_intel_connector;
705 struct psb_intel_lvds_priv *lvds_priv;
706 struct drm_connector *connector;
707 struct drm_encoder *encoder;
708 struct drm_display_mode *scan; /* *modes, *bios_mode; */
709 struct drm_crtc *crtc;
710 struct drm_psb_private *dev_priv = dev->dev_private;
715 kzalloc(sizeof(struct psb_intel_encoder), GFP_KERNEL);
716 if (!psb_intel_encoder) {
717 dev_err(dev->dev, "psb_intel_encoder allocation error\n");
721 psb_intel_connector =
722 kzalloc(sizeof(struct psb_intel_connector), GFP_KERNEL);
723 if (!psb_intel_connector) {
724 dev_err(dev->dev, "psb_intel_connector allocation error\n");
728 lvds_priv = kzalloc(sizeof(struct psb_intel_lvds_priv), GFP_KERNEL);
730 dev_err(dev->dev, "LVDS private allocation error\n");
731 goto failed_connector;
734 psb_intel_encoder->dev_priv = lvds_priv;
736 connector = &psb_intel_connector->base;
737 encoder = &psb_intel_encoder->base;
738 drm_connector_init(dev, connector,
739 &psb_intel_lvds_connector_funcs,
740 DRM_MODE_CONNECTOR_LVDS);
742 drm_encoder_init(dev, encoder,
743 &psb_intel_lvds_enc_funcs,
744 DRM_MODE_ENCODER_LVDS);
746 psb_intel_connector_attach_encoder(psb_intel_connector,
748 psb_intel_encoder->type = INTEL_OUTPUT_LVDS;
750 drm_encoder_helper_add(encoder, &psb_intel_lvds_helper_funcs);
751 drm_connector_helper_add(connector,
752 &psb_intel_lvds_connector_helper_funcs);
753 connector->display_info.subpixel_order = SubPixelHorizontalRGB;
754 connector->interlace_allowed = false;
755 connector->doublescan_allowed = false;
757 /*Attach connector properties*/
758 drm_connector_attach_property(connector,
759 dev->mode_config.scaling_mode_property,
760 DRM_MODE_SCALE_FULLSCREEN);
761 drm_connector_attach_property(connector,
762 dev_priv->backlight_property,
763 BRIGHTNESS_MAX_LEVEL);
767 * FIXME: distroy i2c_bus when exit
769 lvds_priv->i2c_bus = psb_intel_i2c_create(dev, GPIOB, "LVDSBLC_B");
770 if (!lvds_priv->i2c_bus) {
772 &dev->pdev->dev, "I2C bus registration failed.\n");
775 lvds_priv->i2c_bus->slave_addr = 0x2C;
776 dev_priv->lvds_i2c_bus = lvds_priv->i2c_bus;
780 * 1) check for EDID on DDC
781 * 2) check for VBT data
782 * 3) check to see if LVDS is already on
783 * if none of the above, no panel
784 * 4) make sure lid is open
785 * if closed, act like it's not there for now
788 /* Set up the DDC bus. */
789 lvds_priv->ddc_bus = psb_intel_i2c_create(dev, GPIOC, "LVDSDDC_C");
790 if (!lvds_priv->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(connector, &lvds_priv->ddc_bus->adapter);
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) {
841 dev_err(dev->dev, "Found no modes on the lvds, ignoring the LVDS\n");
846 * Blacklist machines with BIOSes that list an LVDS panel without
847 * actually having one.
850 drm_sysfs_connector_add(connector);
854 if (lvds_priv->ddc_bus)
855 psb_intel_i2c_destroy(lvds_priv->ddc_bus);
857 if (lvds_priv->i2c_bus)
858 psb_intel_i2c_destroy(lvds_priv->i2c_bus);
860 drm_encoder_cleanup(encoder);
861 drm_connector_cleanup(connector);
863 kfree(psb_intel_connector);
865 kfree(psb_intel_encoder);