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 u32 PWMControlRegFreq
;
37 * LVDS I2C backlight control macros
39 #define BRIGHTNESS_MAX_LEVEL 100
40 #define BRIGHTNESS_MASK 0xFF
41 #define BLC_I2C_TYPE 0x01
42 #define BLC_PWM_TYPT 0x02
44 #define BLC_POLARITY_NORMAL 0
45 #define BLC_POLARITY_INVERSE 1
47 #define PSB_BLC_MAX_PWM_REG_FREQ (0xFFFE)
48 #define PSB_BLC_MIN_PWM_REG_FREQ (0x2)
49 #define PSB_BLC_PWM_PRECISION_FACTOR (10)
50 #define PSB_BACKLIGHT_PWM_CTL_SHIFT (16)
51 #define PSB_BACKLIGHT_PWM_POLARITY_BIT_CLEAR (0xFFFE)
53 struct psb_intel_lvds_priv
{
55 * Saved LVDO output states
60 uint32_t savePP_CONTROL
;
61 uint32_t savePP_CYCLE
;
62 uint32_t savePFIT_CONTROL
;
63 uint32_t savePFIT_PGM_RATIOS
;
64 uint32_t saveBLC_PWM_CTL
;
67 /* MRST defines end */
70 * Returns the maximum level of the backlight duty cycle field.
72 static u32
psb_intel_lvds_get_max_backlight(struct drm_device
*dev
)
74 struct drm_psb_private
*dev_priv
= dev
->dev_private
;
77 if (gma_power_begin(dev
, false)) {
78 retVal
= ((REG_READ(BLC_PWM_CTL
) &
79 BACKLIGHT_MODULATION_FREQ_MASK
) >>
80 BACKLIGHT_MODULATION_FREQ_SHIFT
) * 2;
84 retVal
= ((dev_priv
->saveBLC_PWM_CTL
&
85 BACKLIGHT_MODULATION_FREQ_MASK
) >>
86 BACKLIGHT_MODULATION_FREQ_SHIFT
) * 2;
92 * Set LVDS backlight level by I2C command
94 * FIXME: at some point we need to both track this for PM and also
95 * disable runtime pm on MRST if the brightness is nil (ie blanked)
97 static int psb_lvds_i2c_set_brightness(struct drm_device
*dev
,
100 struct drm_psb_private
*dev_priv
=
101 (struct drm_psb_private
*)dev
->dev_private
;
103 struct psb_intel_i2c_chan
*lvds_i2c_bus
= dev_priv
->lvds_i2c_bus
;
105 unsigned int blc_i2c_brightness
;
107 struct i2c_msg msgs
[] = {
109 .addr
= lvds_i2c_bus
->slave_addr
,
116 blc_i2c_brightness
= BRIGHTNESS_MASK
& ((unsigned int)level
*
118 BRIGHTNESS_MAX_LEVEL
);
120 if (dev_priv
->lvds_bl
->pol
== BLC_POLARITY_INVERSE
)
121 blc_i2c_brightness
= BRIGHTNESS_MASK
- blc_i2c_brightness
;
123 out_buf
[0] = dev_priv
->lvds_bl
->brightnesscmd
;
124 out_buf
[1] = (u8
)blc_i2c_brightness
;
126 if (i2c_transfer(&lvds_i2c_bus
->adapter
, msgs
, 1) == 1) {
127 dev_dbg(dev
->dev
, "I2C set brightness.(command, value) (%d, %d)\n",
128 dev_priv
->lvds_bl
->brightnesscmd
,
133 dev_err(dev
->dev
, "I2C transfer error\n");
138 static int psb_lvds_pwm_set_brightness(struct drm_device
*dev
, int level
)
140 struct drm_psb_private
*dev_priv
=
141 (struct drm_psb_private
*)dev
->dev_private
;
144 u32 blc_pwm_duty_cycle
;
146 max_pwm_blc
= psb_intel_lvds_get_max_backlight(dev
);
148 /*BLC_PWM_CTL Should be initiated while backlight device init*/
149 BUG_ON((max_pwm_blc
& PSB_BLC_MAX_PWM_REG_FREQ
) == 0);
151 blc_pwm_duty_cycle
= level
* max_pwm_blc
/ BRIGHTNESS_MAX_LEVEL
;
153 if (dev_priv
->lvds_bl
->pol
== BLC_POLARITY_INVERSE
)
154 blc_pwm_duty_cycle
= max_pwm_blc
- blc_pwm_duty_cycle
;
156 blc_pwm_duty_cycle
&= PSB_BACKLIGHT_PWM_POLARITY_BIT_CLEAR
;
157 REG_WRITE(BLC_PWM_CTL
,
158 (max_pwm_blc
<< PSB_BACKLIGHT_PWM_CTL_SHIFT
) |
159 (blc_pwm_duty_cycle
));
165 * Set LVDS backlight level either by I2C or PWM
167 void psb_intel_lvds_set_brightness(struct drm_device
*dev
, int level
)
170 struct drm_psb_private
*dev_priv
=
171 (struct drm_psb_private
*)dev
->dev_private
;
173 dev_dbg(dev
->dev
, "backlight level is %d\n", level
);
175 if (!dev_priv
->lvds_bl
) {
176 dev_err(dev
->dev
, "NO LVDS Backlight Info\n");
180 if (dev_priv
->lvds_bl
->type
== BLC_I2C_TYPE
)
181 psb_lvds_i2c_set_brightness(dev
, level
);
183 psb_lvds_pwm_set_brightness(dev
, level
);
187 * Sets the backlight level.
189 * \param level backlight level, from 0 to psb_intel_lvds_get_max_backlight().
191 static void psb_intel_lvds_set_backlight(struct drm_device
*dev
, int level
)
193 struct drm_psb_private
*dev_priv
= dev
->dev_private
;
196 if (gma_power_begin(dev
, false)) {
198 REG_READ(BLC_PWM_CTL
) & ~BACKLIGHT_DUTY_CYCLE_MASK
;
199 REG_WRITE(BLC_PWM_CTL
,
201 (level
<< BACKLIGHT_DUTY_CYCLE_SHIFT
)));
204 blc_pwm_ctl
= dev_priv
->saveBLC_PWM_CTL
&
205 ~BACKLIGHT_DUTY_CYCLE_MASK
;
206 dev_priv
->saveBLC_PWM_CTL
= (blc_pwm_ctl
|
207 (level
<< BACKLIGHT_DUTY_CYCLE_SHIFT
));
212 * Sets the power state for the panel.
214 static void psb_intel_lvds_set_power(struct drm_device
*dev
,
215 struct psb_intel_output
*output
, bool on
)
219 if (!gma_power_begin(dev
, true))
223 REG_WRITE(PP_CONTROL
, REG_READ(PP_CONTROL
) |
226 pp_status
= REG_READ(PP_STATUS
);
227 } while ((pp_status
& PP_ON
) == 0);
229 psb_intel_lvds_set_backlight(dev
,
231 mode_dev
->backlight_duty_cycle
);
233 psb_intel_lvds_set_backlight(dev
, 0);
235 REG_WRITE(PP_CONTROL
, REG_READ(PP_CONTROL
) &
238 pp_status
= REG_READ(PP_STATUS
);
239 } while (pp_status
& PP_ON
);
245 static void psb_intel_lvds_encoder_dpms(struct drm_encoder
*encoder
, int mode
)
247 struct drm_device
*dev
= encoder
->dev
;
248 struct psb_intel_output
*output
= enc_to_psb_intel_output(encoder
);
250 if (mode
== DRM_MODE_DPMS_ON
)
251 psb_intel_lvds_set_power(dev
, output
, true);
253 psb_intel_lvds_set_power(dev
, output
, false);
255 /* XXX: We never power down the LVDS pairs. */
258 static void psb_intel_lvds_save(struct drm_connector
*connector
)
260 struct drm_device
*dev
= connector
->dev
;
261 struct drm_psb_private
*dev_priv
=
262 (struct drm_psb_private
*)dev
->dev_private
;
263 struct psb_intel_output
*psb_intel_output
=
264 to_psb_intel_output(connector
);
265 struct psb_intel_lvds_priv
*lvds_priv
=
266 (struct psb_intel_lvds_priv
*)psb_intel_output
->dev_priv
;
268 lvds_priv
->savePP_ON
= REG_READ(LVDSPP_ON
);
269 lvds_priv
->savePP_OFF
= REG_READ(LVDSPP_OFF
);
270 lvds_priv
->saveLVDS
= REG_READ(LVDS
);
271 lvds_priv
->savePP_CONTROL
= REG_READ(PP_CONTROL
);
272 lvds_priv
->savePP_CYCLE
= REG_READ(PP_CYCLE
);
273 /*lvds_priv->savePP_DIVISOR = REG_READ(PP_DIVISOR);*/
274 lvds_priv
->saveBLC_PWM_CTL
= REG_READ(BLC_PWM_CTL
);
275 lvds_priv
->savePFIT_CONTROL
= REG_READ(PFIT_CONTROL
);
276 lvds_priv
->savePFIT_PGM_RATIOS
= REG_READ(PFIT_PGM_RATIOS
);
278 /*TODO: move backlight_duty_cycle to psb_intel_lvds_priv*/
279 dev_priv
->backlight_duty_cycle
= (dev_priv
->saveBLC_PWM_CTL
&
280 BACKLIGHT_DUTY_CYCLE_MASK
);
283 * If the light is off at server startup,
284 * just make it full brightness
286 if (dev_priv
->backlight_duty_cycle
== 0)
287 dev_priv
->backlight_duty_cycle
=
288 psb_intel_lvds_get_max_backlight(dev
);
290 dev_dbg(dev
->dev
, "(0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x)\n",
291 lvds_priv
->savePP_ON
,
292 lvds_priv
->savePP_OFF
,
294 lvds_priv
->savePP_CONTROL
,
295 lvds_priv
->savePP_CYCLE
,
296 lvds_priv
->saveBLC_PWM_CTL
);
299 static void psb_intel_lvds_restore(struct drm_connector
*connector
)
301 struct drm_device
*dev
= connector
->dev
;
304 /*struct drm_psb_private *dev_priv =
305 (struct drm_psb_private *)dev->dev_private;*/
306 struct psb_intel_output
*psb_intel_output
=
307 to_psb_intel_output(connector
);
308 struct psb_intel_lvds_priv
*lvds_priv
=
309 (struct psb_intel_lvds_priv
*)psb_intel_output
->dev_priv
;
311 dev_dbg(dev
->dev
, "(0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x)\n",
312 lvds_priv
->savePP_ON
,
313 lvds_priv
->savePP_OFF
,
315 lvds_priv
->savePP_CONTROL
,
316 lvds_priv
->savePP_CYCLE
,
317 lvds_priv
->saveBLC_PWM_CTL
);
319 REG_WRITE(BLC_PWM_CTL
, lvds_priv
->saveBLC_PWM_CTL
);
320 REG_WRITE(PFIT_CONTROL
, lvds_priv
->savePFIT_CONTROL
);
321 REG_WRITE(PFIT_PGM_RATIOS
, lvds_priv
->savePFIT_PGM_RATIOS
);
322 REG_WRITE(LVDSPP_ON
, lvds_priv
->savePP_ON
);
323 REG_WRITE(LVDSPP_OFF
, lvds_priv
->savePP_OFF
);
324 /*REG_WRITE(PP_DIVISOR, lvds_priv->savePP_DIVISOR);*/
325 REG_WRITE(PP_CYCLE
, lvds_priv
->savePP_CYCLE
);
326 REG_WRITE(PP_CONTROL
, lvds_priv
->savePP_CONTROL
);
327 REG_WRITE(LVDS
, lvds_priv
->saveLVDS
);
329 if (lvds_priv
->savePP_CONTROL
& POWER_TARGET_ON
) {
330 REG_WRITE(PP_CONTROL
, REG_READ(PP_CONTROL
) |
333 pp_status
= REG_READ(PP_STATUS
);
334 } while ((pp_status
& PP_ON
) == 0);
336 REG_WRITE(PP_CONTROL
, REG_READ(PP_CONTROL
) &
339 pp_status
= REG_READ(PP_STATUS
);
340 } while (pp_status
& PP_ON
);
344 int psb_intel_lvds_mode_valid(struct drm_connector
*connector
,
345 struct drm_display_mode
*mode
)
347 struct psb_intel_output
*psb_intel_output
=
348 to_psb_intel_output(connector
);
349 struct drm_display_mode
*fixed_mode
=
350 psb_intel_output
->mode_dev
->panel_fixed_mode
;
352 if (psb_intel_output
->type
== INTEL_OUTPUT_MIPI2
)
353 fixed_mode
= psb_intel_output
->mode_dev
->panel_fixed_mode2
;
356 if (mode
->flags
& DRM_MODE_FLAG_DBLSCAN
)
357 return MODE_NO_DBLESCAN
;
360 if (mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
361 return MODE_NO_INTERLACE
;
364 if (mode
->hdisplay
> fixed_mode
->hdisplay
)
366 if (mode
->vdisplay
> fixed_mode
->vdisplay
)
372 bool psb_intel_lvds_mode_fixup(struct drm_encoder
*encoder
,
373 struct drm_display_mode
*mode
,
374 struct drm_display_mode
*adjusted_mode
)
376 struct psb_intel_mode_device
*mode_dev
=
377 enc_to_psb_intel_output(encoder
)->mode_dev
;
378 struct drm_device
*dev
= encoder
->dev
;
379 struct psb_intel_crtc
*psb_intel_crtc
=
380 to_psb_intel_crtc(encoder
->crtc
);
381 struct drm_encoder
*tmp_encoder
;
382 struct drm_display_mode
*panel_fixed_mode
= mode_dev
->panel_fixed_mode
;
383 struct psb_intel_output
*psb_intel_output
=
384 enc_to_psb_intel_output(encoder
);
386 if (psb_intel_output
->type
== INTEL_OUTPUT_MIPI2
)
387 panel_fixed_mode
= mode_dev
->panel_fixed_mode2
;
389 /* FIXME: review for Medfield */
390 /* PSB requires the LVDS is on pipe B, MRST has only one pipe anyway */
391 if (!IS_MRST(dev
) && psb_intel_crtc
->pipe
== 0) {
392 printk(KERN_ERR
"Can't support LVDS on pipe A\n");
395 if (IS_MRST(dev
) && psb_intel_crtc
->pipe
!= 0) {
396 printk(KERN_ERR
"Must use PIPE A\n");
399 /* Should never happen!! */
400 list_for_each_entry(tmp_encoder
, &dev
->mode_config
.encoder_list
,
402 if (tmp_encoder
!= encoder
403 && tmp_encoder
->crtc
== encoder
->crtc
) {
404 printk(KERN_ERR
"Can't enable LVDS and another "
405 "encoder on the same pipe\n");
411 * If we have timings from the BIOS for the panel, put them in
412 * to the adjusted mode. The CRTC will be set up for this mode,
413 * with the panel scaling set up to source from the H/VDisplay
414 * of the original mode.
416 if (panel_fixed_mode
!= NULL
) {
417 adjusted_mode
->hdisplay
= panel_fixed_mode
->hdisplay
;
418 adjusted_mode
->hsync_start
= panel_fixed_mode
->hsync_start
;
419 adjusted_mode
->hsync_end
= panel_fixed_mode
->hsync_end
;
420 adjusted_mode
->htotal
= panel_fixed_mode
->htotal
;
421 adjusted_mode
->vdisplay
= panel_fixed_mode
->vdisplay
;
422 adjusted_mode
->vsync_start
= panel_fixed_mode
->vsync_start
;
423 adjusted_mode
->vsync_end
= panel_fixed_mode
->vsync_end
;
424 adjusted_mode
->vtotal
= panel_fixed_mode
->vtotal
;
425 adjusted_mode
->clock
= panel_fixed_mode
->clock
;
426 drm_mode_set_crtcinfo(adjusted_mode
,
427 CRTC_INTERLACE_HALVE_V
);
431 * XXX: It would be nice to support lower refresh rates on the
432 * panels to reduce power consumption, and perhaps match the
433 * user's requested refresh rate.
439 void psb_intel_lvds_prepare(struct drm_encoder
*encoder
)
441 struct drm_device
*dev
= encoder
->dev
;
442 struct psb_intel_output
*output
= enc_to_psb_intel_output(encoder
);
443 struct psb_intel_mode_device
*mode_dev
= output
->mode_dev
;
445 if (!gma_power_begin(dev
, true))
448 mode_dev
->saveBLC_PWM_CTL
= REG_READ(BLC_PWM_CTL
);
449 mode_dev
->backlight_duty_cycle
= (mode_dev
->saveBLC_PWM_CTL
&
450 BACKLIGHT_DUTY_CYCLE_MASK
);
452 psb_intel_lvds_set_power(dev
, output
, false);
457 void psb_intel_lvds_commit(struct drm_encoder
*encoder
)
459 struct drm_device
*dev
= encoder
->dev
;
460 struct psb_intel_output
*output
= enc_to_psb_intel_output(encoder
);
461 struct psb_intel_mode_device
*mode_dev
= output
->mode_dev
;
463 if (mode_dev
->backlight_duty_cycle
== 0)
464 mode_dev
->backlight_duty_cycle
=
465 psb_intel_lvds_get_max_backlight(dev
);
467 psb_intel_lvds_set_power(dev
, output
, true);
470 static void psb_intel_lvds_mode_set(struct drm_encoder
*encoder
,
471 struct drm_display_mode
*mode
,
472 struct drm_display_mode
*adjusted_mode
)
474 struct psb_intel_mode_device
*mode_dev
=
475 enc_to_psb_intel_output(encoder
)->mode_dev
;
476 struct drm_device
*dev
= encoder
->dev
;
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 (mode_dev
->panel_wants_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
;
529 ret
= psb_intel_ddc_get_modes(psb_intel_output
);
534 /* Didn't get an EDID, so
535 * Set wide sync ranges so we get all modes
536 * handed to valid_mode for checking
538 connector
->display_info
.min_vfreq
= 0;
539 connector
->display_info
.max_vfreq
= 200;
540 connector
->display_info
.min_hfreq
= 0;
541 connector
->display_info
.max_hfreq
= 200;
543 if (mode_dev
->panel_fixed_mode
!= NULL
) {
544 struct drm_display_mode
*mode
=
545 drm_mode_duplicate(dev
, mode_dev
->panel_fixed_mode
);
546 drm_mode_probed_add(connector
, mode
);
554 * psb_intel_lvds_destroy - unregister and free LVDS structures
555 * @connector: connector to free
557 * Unregister the DDC bus for this connector then free the driver private
560 void psb_intel_lvds_destroy(struct drm_connector
*connector
)
562 struct psb_intel_output
*psb_intel_output
=
563 to_psb_intel_output(connector
);
565 if (psb_intel_output
->ddc_bus
)
566 psb_intel_i2c_destroy(psb_intel_output
->ddc_bus
);
567 drm_sysfs_connector_remove(connector
);
568 drm_connector_cleanup(connector
);
572 int psb_intel_lvds_set_property(struct drm_connector
*connector
,
573 struct drm_property
*property
,
576 struct drm_encoder
*encoder
= connector
->encoder
;
577 struct drm_psb_private
*dev_priv
= encoder
->dev
->dev_private
;
579 if (!strcmp(property
->name
, "scaling mode") && encoder
) {
580 struct psb_intel_crtc
*pPsbCrtc
=
581 to_psb_intel_crtc(encoder
->crtc
);
588 case DRM_MODE_SCALE_FULLSCREEN
:
590 case DRM_MODE_SCALE_NO_SCALE
:
592 case DRM_MODE_SCALE_ASPECT
:
598 if (drm_connector_property_get_value(connector
,
603 if (curValue
== value
)
606 if (drm_connector_property_set_value(connector
,
611 if (pPsbCrtc
->saved_mode
.hdisplay
!= 0 &&
612 pPsbCrtc
->saved_mode
.vdisplay
!= 0) {
613 if (!drm_crtc_helper_set_mode(encoder
->crtc
,
614 &pPsbCrtc
->saved_mode
,
620 } else if (!strcmp(property
->name
, "backlight") && encoder
) {
621 if (drm_connector_property_set_value(connector
,
626 #ifdef CONFIG_BACKLIGHT_CLASS_DEVICE
627 struct backlight_device
*bd
= dev_priv
->backlight_device
;
629 bd
->props
.brightness
= value
;
630 backlight_update_status(bd
);
634 } else if (!strcmp(property
->name
, "DPMS") && encoder
) {
635 struct drm_encoder_helper_funcs
*pEncHFuncs
636 = encoder
->helper_private
;
637 pEncHFuncs
->dpms(encoder
, value
);
646 static const struct drm_encoder_helper_funcs psb_intel_lvds_helper_funcs
= {
647 .dpms
= psb_intel_lvds_encoder_dpms
,
648 .mode_fixup
= psb_intel_lvds_mode_fixup
,
649 .prepare
= psb_intel_lvds_prepare
,
650 .mode_set
= psb_intel_lvds_mode_set
,
651 .commit
= psb_intel_lvds_commit
,
654 const struct drm_connector_helper_funcs
655 psb_intel_lvds_connector_helper_funcs
= {
656 .get_modes
= psb_intel_lvds_get_modes
,
657 .mode_valid
= psb_intel_lvds_mode_valid
,
658 .best_encoder
= psb_intel_best_encoder
,
661 const struct drm_connector_funcs psb_intel_lvds_connector_funcs
= {
662 .dpms
= drm_helper_connector_dpms
,
663 .save
= psb_intel_lvds_save
,
664 .restore
= psb_intel_lvds_restore
,
665 .detect
= psb_intel_lvds_detect
,
666 .fill_modes
= drm_helper_probe_single_connector_modes
,
667 .set_property
= psb_intel_lvds_set_property
,
668 .destroy
= psb_intel_lvds_destroy
,
672 static void psb_intel_lvds_enc_destroy(struct drm_encoder
*encoder
)
674 drm_encoder_cleanup(encoder
);
677 const struct drm_encoder_funcs psb_intel_lvds_enc_funcs
= {
678 .destroy
= psb_intel_lvds_enc_destroy
,
684 * psb_intel_lvds_init - setup LVDS connectors on this device
687 * Create the connector, register the LVDS DDC bus, and try to figure out what
688 * modes we can display on the LVDS panel (if present).
690 void psb_intel_lvds_init(struct drm_device
*dev
,
691 struct psb_intel_mode_device
*mode_dev
)
693 struct psb_intel_output
*psb_intel_output
;
694 struct psb_intel_lvds_priv
*lvds_priv
;
695 struct drm_connector
*connector
;
696 struct drm_encoder
*encoder
;
697 struct drm_display_mode
*scan
; /* *modes, *bios_mode; */
698 struct drm_crtc
*crtc
;
699 struct drm_psb_private
*dev_priv
=
700 (struct drm_psb_private
*)dev
->dev_private
;
704 psb_intel_output
= kzalloc(sizeof(struct psb_intel_output
), GFP_KERNEL
);
705 if (!psb_intel_output
)
708 lvds_priv
= kzalloc(sizeof(struct psb_intel_lvds_priv
), GFP_KERNEL
);
710 kfree(psb_intel_output
);
711 dev_err(dev
->dev
, "LVDS private allocation error\n");
715 psb_intel_output
->dev_priv
= lvds_priv
;
717 psb_intel_output
->mode_dev
= mode_dev
;
718 connector
= &psb_intel_output
->base
;
719 encoder
= &psb_intel_output
->enc
;
720 drm_connector_init(dev
, &psb_intel_output
->base
,
721 &psb_intel_lvds_connector_funcs
,
722 DRM_MODE_CONNECTOR_LVDS
);
724 drm_encoder_init(dev
, &psb_intel_output
->enc
,
725 &psb_intel_lvds_enc_funcs
,
726 DRM_MODE_ENCODER_LVDS
);
728 drm_mode_connector_attach_encoder(&psb_intel_output
->base
,
729 &psb_intel_output
->enc
);
730 psb_intel_output
->type
= INTEL_OUTPUT_LVDS
;
732 drm_encoder_helper_add(encoder
, &psb_intel_lvds_helper_funcs
);
733 drm_connector_helper_add(connector
,
734 &psb_intel_lvds_connector_helper_funcs
);
735 connector
->display_info
.subpixel_order
= SubPixelHorizontalRGB
;
736 connector
->interlace_allowed
= false;
737 connector
->doublescan_allowed
= false;
739 /*Attach connector properties*/
740 drm_connector_attach_property(connector
,
741 dev
->mode_config
.scaling_mode_property
,
742 DRM_MODE_SCALE_FULLSCREEN
);
743 drm_connector_attach_property(connector
,
744 dev_priv
->backlight_property
,
745 BRIGHTNESS_MAX_LEVEL
);
749 * FIXME: distroy i2c_bus when exit
751 psb_intel_output
->i2c_bus
= psb_intel_i2c_create(dev
,
754 if (!psb_intel_output
->i2c_bus
) {
756 &dev
->pdev
->dev
, "I2C bus registration failed.\n");
759 psb_intel_output
->i2c_bus
->slave_addr
= 0x2C;
760 dev_priv
->lvds_i2c_bus
= psb_intel_output
->i2c_bus
;
764 * 1) check for EDID on DDC
765 * 2) check for VBT data
766 * 3) check to see if LVDS is already on
767 * if none of the above, no panel
768 * 4) make sure lid is open
769 * if closed, act like it's not there for now
772 /* Set up the DDC bus. */
773 psb_intel_output
->ddc_bus
= psb_intel_i2c_create(dev
,
776 if (!psb_intel_output
->ddc_bus
) {
777 dev_printk(KERN_ERR
, &dev
->pdev
->dev
,
778 "DDC bus registration " "failed.\n");
783 * Attempt to get the fixed panel mode from DDC. Assume that the
784 * preferred mode is the right one.
786 psb_intel_ddc_get_modes(psb_intel_output
);
787 list_for_each_entry(scan
, &connector
->probed_modes
, head
) {
788 if (scan
->type
& DRM_MODE_TYPE_PREFERRED
) {
789 mode_dev
->panel_fixed_mode
=
790 drm_mode_duplicate(dev
, scan
);
791 goto out
; /* FIXME: check for quirks */
795 /* Failed to get EDID, what about VBT? do we need this?*/
796 if (mode_dev
->vbt_mode
)
797 mode_dev
->panel_fixed_mode
=
798 drm_mode_duplicate(dev
, mode_dev
->vbt_mode
);
800 if (!mode_dev
->panel_fixed_mode
)
801 if (dev_priv
->lfp_lvds_vbt_mode
)
802 mode_dev
->panel_fixed_mode
=
803 drm_mode_duplicate(dev
,
804 dev_priv
->lfp_lvds_vbt_mode
);
807 * If we didn't get EDID, try checking if the panel is already turned
808 * on. If so, assume that whatever is currently programmed is the
811 lvds
= REG_READ(LVDS
);
812 pipe
= (lvds
& LVDS_PIPEB_SELECT
) ? 1 : 0;
813 crtc
= psb_intel_get_crtc_from_pipe(dev
, pipe
);
815 if (crtc
&& (lvds
& LVDS_PORT_EN
)) {
816 mode_dev
->panel_fixed_mode
=
817 psb_intel_crtc_mode_get(dev
, crtc
);
818 if (mode_dev
->panel_fixed_mode
) {
819 mode_dev
->panel_fixed_mode
->type
|=
820 DRM_MODE_TYPE_PREFERRED
;
821 goto out
; /* FIXME: check for quirks */
825 /* If we still don't have a mode after all that, give up. */
826 if (!mode_dev
->panel_fixed_mode
) {
827 dev_err(dev
->dev
, "Found no modes on the lvds, ignoring the LVDS\n");
832 * Blacklist machines with BIOSes that list an LVDS panel without
833 * actually having one.
836 drm_sysfs_connector_add(connector
);
840 if (psb_intel_output
->ddc_bus
)
841 psb_intel_i2c_destroy(psb_intel_output
->ddc_bus
);
843 if (psb_intel_output
->i2c_bus
)
844 psb_intel_i2c_destroy(psb_intel_output
->i2c_bus
);
846 drm_encoder_cleanup(encoder
);
847 drm_connector_cleanup(connector
);