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 retVal
= ((REG_READ(BLC_PWM_CTL
) &
75 BACKLIGHT_MODULATION_FREQ_MASK
) >>
76 BACKLIGHT_MODULATION_FREQ_SHIFT
) * 2;
80 retVal
= ((dev_priv
->saveBLC_PWM_CTL
&
81 BACKLIGHT_MODULATION_FREQ_MASK
) >>
82 BACKLIGHT_MODULATION_FREQ_SHIFT
) * 2;
88 * Set LVDS backlight level by I2C command
90 * FIXME: at some point we need to both track this for PM and also
91 * disable runtime pm on MRST if the brightness is nil (ie blanked)
93 static int psb_lvds_i2c_set_brightness(struct drm_device
*dev
,
96 struct drm_psb_private
*dev_priv
=
97 (struct drm_psb_private
*)dev
->dev_private
;
99 struct psb_intel_i2c_chan
*lvds_i2c_bus
= dev_priv
->lvds_i2c_bus
;
101 unsigned int blc_i2c_brightness
;
103 struct i2c_msg msgs
[] = {
105 .addr
= lvds_i2c_bus
->slave_addr
,
112 blc_i2c_brightness
= BRIGHTNESS_MASK
& ((unsigned int)level
*
114 BRIGHTNESS_MAX_LEVEL
);
116 if (dev_priv
->lvds_bl
->pol
== BLC_POLARITY_INVERSE
)
117 blc_i2c_brightness
= BRIGHTNESS_MASK
- blc_i2c_brightness
;
119 out_buf
[0] = dev_priv
->lvds_bl
->brightnesscmd
;
120 out_buf
[1] = (u8
)blc_i2c_brightness
;
122 if (i2c_transfer(&lvds_i2c_bus
->adapter
, msgs
, 1) == 1) {
123 dev_dbg(dev
->dev
, "I2C set brightness.(command, value) (%d, %d)\n",
124 dev_priv
->lvds_bl
->brightnesscmd
,
129 dev_err(dev
->dev
, "I2C transfer error\n");
134 static int psb_lvds_pwm_set_brightness(struct drm_device
*dev
, int level
)
136 struct drm_psb_private
*dev_priv
=
137 (struct drm_psb_private
*)dev
->dev_private
;
140 u32 blc_pwm_duty_cycle
;
142 max_pwm_blc
= psb_intel_lvds_get_max_backlight(dev
);
144 /*BLC_PWM_CTL Should be initiated while backlight device init*/
145 BUG_ON((max_pwm_blc
& PSB_BLC_MAX_PWM_REG_FREQ
) == 0);
147 blc_pwm_duty_cycle
= level
* max_pwm_blc
/ BRIGHTNESS_MAX_LEVEL
;
149 if (dev_priv
->lvds_bl
->pol
== BLC_POLARITY_INVERSE
)
150 blc_pwm_duty_cycle
= max_pwm_blc
- blc_pwm_duty_cycle
;
152 blc_pwm_duty_cycle
&= PSB_BACKLIGHT_PWM_POLARITY_BIT_CLEAR
;
153 REG_WRITE(BLC_PWM_CTL
,
154 (max_pwm_blc
<< PSB_BACKLIGHT_PWM_CTL_SHIFT
) |
155 (blc_pwm_duty_cycle
));
161 * Set LVDS backlight level either by I2C or PWM
163 void psb_intel_lvds_set_brightness(struct drm_device
*dev
, int level
)
166 struct drm_psb_private
*dev_priv
=
167 (struct drm_psb_private
*)dev
->dev_private
;
169 dev_dbg(dev
->dev
, "backlight level is %d\n", level
);
171 if (!dev_priv
->lvds_bl
) {
172 dev_err(dev
->dev
, "NO LVDS Backlight Info\n");
176 if (dev_priv
->lvds_bl
->type
== BLC_I2C_TYPE
)
177 psb_lvds_i2c_set_brightness(dev
, level
);
179 psb_lvds_pwm_set_brightness(dev
, level
);
183 * Sets the backlight level.
185 * level: backlight level, from 0 to psb_intel_lvds_get_max_backlight().
187 static void psb_intel_lvds_set_backlight(struct drm_device
*dev
, int level
)
189 struct drm_psb_private
*dev_priv
= dev
->dev_private
;
192 if (gma_power_begin(dev
, false)) {
194 REG_READ(BLC_PWM_CTL
) & ~BACKLIGHT_DUTY_CYCLE_MASK
;
195 REG_WRITE(BLC_PWM_CTL
,
197 (level
<< BACKLIGHT_DUTY_CYCLE_SHIFT
)));
200 blc_pwm_ctl
= dev_priv
->saveBLC_PWM_CTL
&
201 ~BACKLIGHT_DUTY_CYCLE_MASK
;
202 dev_priv
->saveBLC_PWM_CTL
= (blc_pwm_ctl
|
203 (level
<< BACKLIGHT_DUTY_CYCLE_SHIFT
));
208 * Sets the power state for the panel.
210 static void psb_intel_lvds_set_power(struct drm_device
*dev
,
211 struct psb_intel_output
*output
, bool on
)
215 if (!gma_power_begin(dev
, true))
219 REG_WRITE(PP_CONTROL
, REG_READ(PP_CONTROL
) |
222 pp_status
= REG_READ(PP_STATUS
);
223 } while ((pp_status
& PP_ON
) == 0);
225 psb_intel_lvds_set_backlight(dev
,
227 mode_dev
->backlight_duty_cycle
);
229 psb_intel_lvds_set_backlight(dev
, 0);
231 REG_WRITE(PP_CONTROL
, REG_READ(PP_CONTROL
) &
234 pp_status
= REG_READ(PP_STATUS
);
235 } while (pp_status
& PP_ON
);
241 static void psb_intel_lvds_encoder_dpms(struct drm_encoder
*encoder
, int mode
)
243 struct drm_device
*dev
= encoder
->dev
;
244 struct psb_intel_output
*output
= enc_to_psb_intel_output(encoder
);
246 if (mode
== DRM_MODE_DPMS_ON
)
247 psb_intel_lvds_set_power(dev
, output
, true);
249 psb_intel_lvds_set_power(dev
, output
, false);
251 /* XXX: We never power down the LVDS pairs. */
254 static void psb_intel_lvds_save(struct drm_connector
*connector
)
256 struct drm_device
*dev
= connector
->dev
;
257 struct drm_psb_private
*dev_priv
=
258 (struct drm_psb_private
*)dev
->dev_private
;
259 struct psb_intel_output
*psb_intel_output
=
260 to_psb_intel_output(connector
);
261 struct psb_intel_lvds_priv
*lvds_priv
=
262 (struct psb_intel_lvds_priv
*)psb_intel_output
->dev_priv
;
264 lvds_priv
->savePP_ON
= REG_READ(LVDSPP_ON
);
265 lvds_priv
->savePP_OFF
= REG_READ(LVDSPP_OFF
);
266 lvds_priv
->saveLVDS
= REG_READ(LVDS
);
267 lvds_priv
->savePP_CONTROL
= REG_READ(PP_CONTROL
);
268 lvds_priv
->savePP_CYCLE
= REG_READ(PP_CYCLE
);
269 /*lvds_priv->savePP_DIVISOR = REG_READ(PP_DIVISOR);*/
270 lvds_priv
->saveBLC_PWM_CTL
= REG_READ(BLC_PWM_CTL
);
271 lvds_priv
->savePFIT_CONTROL
= REG_READ(PFIT_CONTROL
);
272 lvds_priv
->savePFIT_PGM_RATIOS
= REG_READ(PFIT_PGM_RATIOS
);
274 /*TODO: move backlight_duty_cycle to psb_intel_lvds_priv*/
275 dev_priv
->backlight_duty_cycle
= (dev_priv
->saveBLC_PWM_CTL
&
276 BACKLIGHT_DUTY_CYCLE_MASK
);
279 * If the light is off at server startup,
280 * just make it full brightness
282 if (dev_priv
->backlight_duty_cycle
== 0)
283 dev_priv
->backlight_duty_cycle
=
284 psb_intel_lvds_get_max_backlight(dev
);
286 dev_dbg(dev
->dev
, "(0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x)\n",
287 lvds_priv
->savePP_ON
,
288 lvds_priv
->savePP_OFF
,
290 lvds_priv
->savePP_CONTROL
,
291 lvds_priv
->savePP_CYCLE
,
292 lvds_priv
->saveBLC_PWM_CTL
);
295 static void psb_intel_lvds_restore(struct drm_connector
*connector
)
297 struct drm_device
*dev
= connector
->dev
;
300 /*struct drm_psb_private *dev_priv =
301 (struct drm_psb_private *)dev->dev_private;*/
302 struct psb_intel_output
*psb_intel_output
=
303 to_psb_intel_output(connector
);
304 struct psb_intel_lvds_priv
*lvds_priv
=
305 (struct psb_intel_lvds_priv
*)psb_intel_output
->dev_priv
;
307 dev_dbg(dev
->dev
, "(0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x)\n",
308 lvds_priv
->savePP_ON
,
309 lvds_priv
->savePP_OFF
,
311 lvds_priv
->savePP_CONTROL
,
312 lvds_priv
->savePP_CYCLE
,
313 lvds_priv
->saveBLC_PWM_CTL
);
315 REG_WRITE(BLC_PWM_CTL
, lvds_priv
->saveBLC_PWM_CTL
);
316 REG_WRITE(PFIT_CONTROL
, lvds_priv
->savePFIT_CONTROL
);
317 REG_WRITE(PFIT_PGM_RATIOS
, lvds_priv
->savePFIT_PGM_RATIOS
);
318 REG_WRITE(LVDSPP_ON
, lvds_priv
->savePP_ON
);
319 REG_WRITE(LVDSPP_OFF
, lvds_priv
->savePP_OFF
);
320 /*REG_WRITE(PP_DIVISOR, lvds_priv->savePP_DIVISOR);*/
321 REG_WRITE(PP_CYCLE
, lvds_priv
->savePP_CYCLE
);
322 REG_WRITE(PP_CONTROL
, lvds_priv
->savePP_CONTROL
);
323 REG_WRITE(LVDS
, lvds_priv
->saveLVDS
);
325 if (lvds_priv
->savePP_CONTROL
& POWER_TARGET_ON
) {
326 REG_WRITE(PP_CONTROL
, REG_READ(PP_CONTROL
) |
329 pp_status
= REG_READ(PP_STATUS
);
330 } while ((pp_status
& PP_ON
) == 0);
332 REG_WRITE(PP_CONTROL
, REG_READ(PP_CONTROL
) &
335 pp_status
= REG_READ(PP_STATUS
);
336 } while (pp_status
& PP_ON
);
340 int psb_intel_lvds_mode_valid(struct drm_connector
*connector
,
341 struct drm_display_mode
*mode
)
343 struct psb_intel_output
*psb_intel_output
=
344 to_psb_intel_output(connector
);
345 struct drm_display_mode
*fixed_mode
=
346 psb_intel_output
->mode_dev
->panel_fixed_mode
;
348 if (psb_intel_output
->type
== INTEL_OUTPUT_MIPI2
)
349 fixed_mode
= psb_intel_output
->mode_dev
->panel_fixed_mode2
;
352 if (mode
->flags
& DRM_MODE_FLAG_DBLSCAN
)
353 return MODE_NO_DBLESCAN
;
356 if (mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
357 return MODE_NO_INTERLACE
;
360 if (mode
->hdisplay
> fixed_mode
->hdisplay
)
362 if (mode
->vdisplay
> fixed_mode
->vdisplay
)
368 bool psb_intel_lvds_mode_fixup(struct drm_encoder
*encoder
,
369 struct drm_display_mode
*mode
,
370 struct drm_display_mode
*adjusted_mode
)
372 struct psb_intel_mode_device
*mode_dev
=
373 enc_to_psb_intel_output(encoder
)->mode_dev
;
374 struct drm_device
*dev
= encoder
->dev
;
375 struct psb_intel_crtc
*psb_intel_crtc
=
376 to_psb_intel_crtc(encoder
->crtc
);
377 struct drm_encoder
*tmp_encoder
;
378 struct drm_display_mode
*panel_fixed_mode
= mode_dev
->panel_fixed_mode
;
379 struct psb_intel_output
*psb_intel_output
=
380 enc_to_psb_intel_output(encoder
);
382 if (psb_intel_output
->type
== INTEL_OUTPUT_MIPI2
)
383 panel_fixed_mode
= mode_dev
->panel_fixed_mode2
;
385 /* PSB requires the LVDS is on pipe B, MRST has only one pipe anyway */
386 if (!IS_MRST(dev
) && psb_intel_crtc
->pipe
== 0) {
387 printk(KERN_ERR
"Can't support LVDS on pipe A\n");
390 if (IS_MRST(dev
) && psb_intel_crtc
->pipe
!= 0) {
391 printk(KERN_ERR
"Must use PIPE A\n");
394 /* Should never happen!! */
395 list_for_each_entry(tmp_encoder
, &dev
->mode_config
.encoder_list
,
397 if (tmp_encoder
!= encoder
398 && tmp_encoder
->crtc
== encoder
->crtc
) {
399 printk(KERN_ERR
"Can't enable LVDS and another "
400 "encoder on the same pipe\n");
406 * If we have timings from the BIOS for the panel, put them in
407 * to the adjusted mode. The CRTC will be set up for this mode,
408 * with the panel scaling set up to source from the H/VDisplay
409 * of the original mode.
411 if (panel_fixed_mode
!= NULL
) {
412 adjusted_mode
->hdisplay
= panel_fixed_mode
->hdisplay
;
413 adjusted_mode
->hsync_start
= panel_fixed_mode
->hsync_start
;
414 adjusted_mode
->hsync_end
= panel_fixed_mode
->hsync_end
;
415 adjusted_mode
->htotal
= panel_fixed_mode
->htotal
;
416 adjusted_mode
->vdisplay
= panel_fixed_mode
->vdisplay
;
417 adjusted_mode
->vsync_start
= panel_fixed_mode
->vsync_start
;
418 adjusted_mode
->vsync_end
= panel_fixed_mode
->vsync_end
;
419 adjusted_mode
->vtotal
= panel_fixed_mode
->vtotal
;
420 adjusted_mode
->clock
= panel_fixed_mode
->clock
;
421 drm_mode_set_crtcinfo(adjusted_mode
,
422 CRTC_INTERLACE_HALVE_V
);
426 * XXX: It would be nice to support lower refresh rates on the
427 * panels to reduce power consumption, and perhaps match the
428 * user's requested refresh rate.
434 static void psb_intel_lvds_prepare(struct drm_encoder
*encoder
)
436 struct drm_device
*dev
= encoder
->dev
;
437 struct psb_intel_output
*output
= enc_to_psb_intel_output(encoder
);
438 struct psb_intel_mode_device
*mode_dev
= output
->mode_dev
;
440 if (!gma_power_begin(dev
, true))
443 mode_dev
->saveBLC_PWM_CTL
= REG_READ(BLC_PWM_CTL
);
444 mode_dev
->backlight_duty_cycle
= (mode_dev
->saveBLC_PWM_CTL
&
445 BACKLIGHT_DUTY_CYCLE_MASK
);
447 psb_intel_lvds_set_power(dev
, output
, false);
452 static void psb_intel_lvds_commit(struct drm_encoder
*encoder
)
454 struct drm_device
*dev
= encoder
->dev
;
455 struct psb_intel_output
*output
= enc_to_psb_intel_output(encoder
);
456 struct psb_intel_mode_device
*mode_dev
= output
->mode_dev
;
458 if (mode_dev
->backlight_duty_cycle
== 0)
459 mode_dev
->backlight_duty_cycle
=
460 psb_intel_lvds_get_max_backlight(dev
);
462 psb_intel_lvds_set_power(dev
, output
, true);
465 static void psb_intel_lvds_mode_set(struct drm_encoder
*encoder
,
466 struct drm_display_mode
*mode
,
467 struct drm_display_mode
*adjusted_mode
)
469 struct drm_device
*dev
= encoder
->dev
;
470 struct drm_psb_private
*dev_priv
= dev
->dev_private
;
474 * The LVDS pin pair will already have been turned on in the
475 * psb_intel_crtc_mode_set since it has a large impact on the DPLL
480 * Enable automatic panel scaling so that non-native modes fill the
481 * screen. Should be enabled before the pipe is enabled, according to
482 * register description and PRM.
484 if (mode
->hdisplay
!= adjusted_mode
->hdisplay
||
485 mode
->vdisplay
!= adjusted_mode
->vdisplay
)
486 pfit_control
= (PFIT_ENABLE
| VERT_AUTO_SCALE
|
487 HORIZ_AUTO_SCALE
| VERT_INTERP_BILINEAR
|
488 HORIZ_INTERP_BILINEAR
);
492 if (dev_priv
->lvds_dither
)
493 pfit_control
|= PANEL_8TO6_DITHER_ENABLE
;
495 REG_WRITE(PFIT_CONTROL
, pfit_control
);
499 * Detect the LVDS connection.
501 * This always returns CONNECTOR_STATUS_CONNECTED.
502 * This connector should only have
503 * been set up if the LVDS was actually connected anyway.
505 static enum drm_connector_status
psb_intel_lvds_detect(struct drm_connector
506 *connector
, bool force
)
508 return connector_status_connected
;
512 * Return the list of DDC modes if available, or the BIOS fixed mode otherwise.
514 static int psb_intel_lvds_get_modes(struct drm_connector
*connector
)
516 struct drm_device
*dev
= connector
->dev
;
517 struct psb_intel_output
*psb_intel_output
=
518 to_psb_intel_output(connector
);
519 struct psb_intel_mode_device
*mode_dev
=
520 psb_intel_output
->mode_dev
;
524 ret
= psb_intel_ddc_get_modes(psb_intel_output
);
529 /* Didn't get an EDID, so
530 * Set wide sync ranges so we get all modes
531 * handed to valid_mode for checking
533 connector
->display_info
.min_vfreq
= 0;
534 connector
->display_info
.max_vfreq
= 200;
535 connector
->display_info
.min_hfreq
= 0;
536 connector
->display_info
.max_hfreq
= 200;
538 if (mode_dev
->panel_fixed_mode
!= NULL
) {
539 struct drm_display_mode
*mode
=
540 drm_mode_duplicate(dev
, mode_dev
->panel_fixed_mode
);
541 drm_mode_probed_add(connector
, mode
);
549 * psb_intel_lvds_destroy - unregister and free LVDS structures
550 * @connector: connector to free
552 * Unregister the DDC bus for this connector then free the driver private
555 void psb_intel_lvds_destroy(struct drm_connector
*connector
)
557 struct psb_intel_output
*psb_intel_output
=
558 to_psb_intel_output(connector
);
560 if (psb_intel_output
->ddc_bus
)
561 psb_intel_i2c_destroy(psb_intel_output
->ddc_bus
);
562 drm_sysfs_connector_remove(connector
);
563 drm_connector_cleanup(connector
);
567 int psb_intel_lvds_set_property(struct drm_connector
*connector
,
568 struct drm_property
*property
,
571 struct drm_encoder
*encoder
= connector
->encoder
;
576 if (!strcmp(property
->name
, "scaling mode")) {
577 struct psb_intel_crtc
*crtc
=
578 to_psb_intel_crtc(encoder
->crtc
);
585 case DRM_MODE_SCALE_FULLSCREEN
:
587 case DRM_MODE_SCALE_NO_SCALE
:
589 case DRM_MODE_SCALE_ASPECT
:
595 if (drm_connector_property_get_value(connector
,
603 if (drm_connector_property_set_value(connector
,
608 if (crtc
->saved_mode
.hdisplay
!= 0 &&
609 crtc
->saved_mode
.vdisplay
!= 0) {
610 if (!drm_crtc_helper_set_mode(encoder
->crtc
,
617 } else if (!strcmp(property
->name
, "backlight")) {
618 if (drm_connector_property_set_value(connector
,
623 #ifdef CONFIG_BACKLIGHT_CLASS_DEVICE
624 struct drm_psb_private
*devp
= encoder
->dev
->dev_private
;
625 struct backlight_device
*bd
= devp
->backlight_device
;
627 bd
->props
.brightness
= value
;
628 backlight_update_status(bd
);
632 } else if (!strcmp(property
->name
, "DPMS")) {
633 struct drm_encoder_helper_funcs
*hfuncs
634 = encoder
->helper_private
;
635 hfuncs
->dpms(encoder
, value
);
644 static const struct drm_encoder_helper_funcs psb_intel_lvds_helper_funcs
= {
645 .dpms
= psb_intel_lvds_encoder_dpms
,
646 .mode_fixup
= psb_intel_lvds_mode_fixup
,
647 .prepare
= psb_intel_lvds_prepare
,
648 .mode_set
= psb_intel_lvds_mode_set
,
649 .commit
= psb_intel_lvds_commit
,
652 const struct drm_connector_helper_funcs
653 psb_intel_lvds_connector_helper_funcs
= {
654 .get_modes
= psb_intel_lvds_get_modes
,
655 .mode_valid
= psb_intel_lvds_mode_valid
,
656 .best_encoder
= psb_intel_best_encoder
,
659 const struct drm_connector_funcs psb_intel_lvds_connector_funcs
= {
660 .dpms
= drm_helper_connector_dpms
,
661 .save
= psb_intel_lvds_save
,
662 .restore
= psb_intel_lvds_restore
,
663 .detect
= psb_intel_lvds_detect
,
664 .fill_modes
= drm_helper_probe_single_connector_modes
,
665 .set_property
= psb_intel_lvds_set_property
,
666 .destroy
= psb_intel_lvds_destroy
,
670 static void psb_intel_lvds_enc_destroy(struct drm_encoder
*encoder
)
672 drm_encoder_cleanup(encoder
);
675 const struct drm_encoder_funcs psb_intel_lvds_enc_funcs
= {
676 .destroy
= psb_intel_lvds_enc_destroy
,
682 * psb_intel_lvds_init - setup LVDS connectors on this device
685 * Create the connector, register the LVDS DDC bus, and try to figure out what
686 * modes we can display on the LVDS panel (if present).
688 void psb_intel_lvds_init(struct drm_device
*dev
,
689 struct psb_intel_mode_device
*mode_dev
)
691 struct psb_intel_output
*psb_intel_output
;
692 struct psb_intel_lvds_priv
*lvds_priv
;
693 struct drm_connector
*connector
;
694 struct drm_encoder
*encoder
;
695 struct drm_display_mode
*scan
; /* *modes, *bios_mode; */
696 struct drm_crtc
*crtc
;
697 struct drm_psb_private
*dev_priv
=
698 (struct drm_psb_private
*)dev
->dev_private
;
702 psb_intel_output
= kzalloc(sizeof(struct psb_intel_output
), GFP_KERNEL
);
703 if (!psb_intel_output
)
706 lvds_priv
= kzalloc(sizeof(struct psb_intel_lvds_priv
), GFP_KERNEL
);
708 kfree(psb_intel_output
);
709 dev_err(dev
->dev
, "LVDS private allocation error\n");
713 psb_intel_output
->dev_priv
= lvds_priv
;
715 psb_intel_output
->mode_dev
= mode_dev
;
716 connector
= &psb_intel_output
->base
;
717 encoder
= &psb_intel_output
->enc
;
718 drm_connector_init(dev
, &psb_intel_output
->base
,
719 &psb_intel_lvds_connector_funcs
,
720 DRM_MODE_CONNECTOR_LVDS
);
722 drm_encoder_init(dev
, &psb_intel_output
->enc
,
723 &psb_intel_lvds_enc_funcs
,
724 DRM_MODE_ENCODER_LVDS
);
726 drm_mode_connector_attach_encoder(&psb_intel_output
->base
,
727 &psb_intel_output
->enc
);
728 psb_intel_output
->type
= INTEL_OUTPUT_LVDS
;
730 drm_encoder_helper_add(encoder
, &psb_intel_lvds_helper_funcs
);
731 drm_connector_helper_add(connector
,
732 &psb_intel_lvds_connector_helper_funcs
);
733 connector
->display_info
.subpixel_order
= SubPixelHorizontalRGB
;
734 connector
->interlace_allowed
= false;
735 connector
->doublescan_allowed
= false;
737 /*Attach connector properties*/
738 drm_connector_attach_property(connector
,
739 dev
->mode_config
.scaling_mode_property
,
740 DRM_MODE_SCALE_FULLSCREEN
);
741 drm_connector_attach_property(connector
,
742 dev_priv
->backlight_property
,
743 BRIGHTNESS_MAX_LEVEL
);
747 * FIXME: distroy i2c_bus when exit
749 psb_intel_output
->i2c_bus
= psb_intel_i2c_create(dev
,
752 if (!psb_intel_output
->i2c_bus
) {
754 &dev
->pdev
->dev
, "I2C bus registration failed.\n");
757 psb_intel_output
->i2c_bus
->slave_addr
= 0x2C;
758 dev_priv
->lvds_i2c_bus
= psb_intel_output
->i2c_bus
;
762 * 1) check for EDID on DDC
763 * 2) check for VBT data
764 * 3) check to see if LVDS is already on
765 * if none of the above, no panel
766 * 4) make sure lid is open
767 * if closed, act like it's not there for now
770 /* Set up the DDC bus. */
771 psb_intel_output
->ddc_bus
= psb_intel_i2c_create(dev
,
774 if (!psb_intel_output
->ddc_bus
) {
775 dev_printk(KERN_ERR
, &dev
->pdev
->dev
,
776 "DDC bus registration " "failed.\n");
781 * Attempt to get the fixed panel mode from DDC. Assume that the
782 * preferred mode is the right one.
784 psb_intel_ddc_get_modes(psb_intel_output
);
785 list_for_each_entry(scan
, &connector
->probed_modes
, head
) {
786 if (scan
->type
& DRM_MODE_TYPE_PREFERRED
) {
787 mode_dev
->panel_fixed_mode
=
788 drm_mode_duplicate(dev
, scan
);
789 goto out
; /* FIXME: check for quirks */
793 /* Failed to get EDID, what about VBT? do we need this? */
794 if (mode_dev
->vbt_mode
)
795 mode_dev
->panel_fixed_mode
=
796 drm_mode_duplicate(dev
, mode_dev
->vbt_mode
);
798 if (!mode_dev
->panel_fixed_mode
)
799 if (dev_priv
->lfp_lvds_vbt_mode
)
800 mode_dev
->panel_fixed_mode
=
801 drm_mode_duplicate(dev
,
802 dev_priv
->lfp_lvds_vbt_mode
);
805 * If we didn't get EDID, try checking if the panel is already turned
806 * on. If so, assume that whatever is currently programmed is the
809 lvds
= REG_READ(LVDS
);
810 pipe
= (lvds
& LVDS_PIPEB_SELECT
) ? 1 : 0;
811 crtc
= psb_intel_get_crtc_from_pipe(dev
, pipe
);
813 if (crtc
&& (lvds
& LVDS_PORT_EN
)) {
814 mode_dev
->panel_fixed_mode
=
815 psb_intel_crtc_mode_get(dev
, crtc
);
816 if (mode_dev
->panel_fixed_mode
) {
817 mode_dev
->panel_fixed_mode
->type
|=
818 DRM_MODE_TYPE_PREFERRED
;
819 goto out
; /* FIXME: check for quirks */
823 /* If we still don't have a mode after all that, give up. */
824 if (!mode_dev
->panel_fixed_mode
) {
825 dev_err(dev
->dev
, "Found no modes on the lvds, ignoring the LVDS\n");
830 * Blacklist machines with BIOSes that list an LVDS panel without
831 * actually having one.
834 drm_sysfs_connector_add(connector
);
838 if (psb_intel_output
->ddc_bus
)
839 psb_intel_i2c_destroy(psb_intel_output
->ddc_bus
);
841 if (psb_intel_output
->i2c_bus
)
842 psb_intel_i2c_destroy(psb_intel_output
->i2c_bus
);
844 drm_encoder_cleanup(encoder
);
845 drm_connector_cleanup(connector
);