23 #include <linux/i2c.h>
38 #define BRIGHTNESS_MAX_LEVEL 100
39 #define BRIGHTNESS_MASK 0xFF
40 #define BLC_I2C_TYPE 0x01
41 #define BLC_PWM_TYPT 0x02
43 #define BLC_POLARITY_NORMAL 0
44 #define BLC_POLARITY_INVERSE 1
46 #define PSB_BLC_MAX_PWM_REG_FREQ (0xFFFE)
47 #define PSB_BLC_MIN_PWM_REG_FREQ (0x2)
48 #define PSB_BLC_PWM_PRECISION_FACTOR (10)
49 #define PSB_BACKLIGHT_PWM_CTL_SHIFT (16)
50 #define PSB_BACKLIGHT_PWM_POLARITY_BIT_CLEAR (0xFFFE)
81 retval = ((dev_priv->
regs.saveBLC_PWM_CTL &
92 static int cdv_lvds_i2c_set_brightness(
struct drm_device *
dev,
98 unsigned int blc_i2c_brightness;
116 out_buf[0] =
dev_priv->lvds_bl->brightnesscmd;
117 out_buf[1] = (
u8)blc_i2c_brightness;
122 DRM_ERROR(
"I2C transfer error\n");
132 u32 blc_pwm_duty_cycle;
134 max_pwm_blc = cdv_intel_lvds_get_max_backlight(dev);
142 blc_pwm_duty_cycle = max_pwm_blc - blc_pwm_duty_cycle;
147 (blc_pwm_duty_cycle));
155 void cdv_intel_lvds_set_brightness(
struct drm_device *dev,
int level)
160 DRM_ERROR(
"NO LVDS Backlight Info\n");
165 cdv_lvds_i2c_set_brightness(dev, level);
167 cdv_lvds_pwm_set_brightness(dev, level);
176 static void cdv_intel_lvds_set_backlight(
struct drm_device *dev,
int level)
189 blc_pwm_ctl = dev_priv->
regs.saveBLC_PWM_CTL &
191 dev_priv->
regs.saveBLC_PWM_CTL = (blc_pwm_ctl |
199 static void cdv_intel_lvds_set_power(
struct drm_device *dev,
213 }
while ((pp_status &
PP_ON) == 0);
215 cdv_intel_lvds_set_backlight(dev,
216 dev_priv->
mode_dev.backlight_duty_cycle);
218 cdv_intel_lvds_set_backlight(dev, 0);
224 }
while (pp_status &
PP_ON);
229 static void cdv_intel_lvds_encoder_dpms(
struct drm_encoder *encoder,
int mode)
233 cdv_intel_lvds_set_power(dev, encoder,
true);
235 cdv_intel_lvds_set_power(dev, encoder,
false);
253 dev_priv->
mode_dev.panel_fixed_mode;
272 static bool cdv_intel_lvds_mode_fixup(
struct drm_encoder *encoder,
285 if (tmp_encoder != encoder
286 && tmp_encoder->
crtc == encoder->
crtc) {
288 "encoder on the same pipe\n");
299 if (panel_fixed_mode !=
NULL) {
308 adjusted_mode->
clock = panel_fixed_mode->
clock;
322 static void cdv_intel_lvds_prepare(
struct drm_encoder *encoder)
335 cdv_intel_lvds_set_power(dev, encoder,
false);
340 static void cdv_intel_lvds_commit(
struct drm_encoder *encoder)
348 cdv_intel_lvds_get_max_backlight(dev);
350 cdv_intel_lvds_set_power(dev, encoder,
true);
353 static void cdv_intel_lvds_mode_set(
struct drm_encoder *encoder,
406 static int cdv_intel_lvds_get_modes(
struct drm_connector *connector)
411 psb_intel_attached_encoder(connector);
445 static void cdv_intel_lvds_destroy(
struct drm_connector *connector)
447 struct psb_intel_encoder *psb_intel_encoder =
448 psb_intel_attached_encoder(connector);
450 if (psb_intel_encoder->
i2c_bus)
457 static int cdv_intel_lvds_set_property(
struct drm_connector *connector,
463 if (!
strcmp(property->
name,
"scaling mode") && encoder) {
464 struct psb_intel_crtc *
crtc =
487 if (curValue == value)
504 }
else if (!
strcmp(property->
name,
"backlight") && encoder) {
511 }
else if (!
strcmp(property->
name,
"DPMS") && encoder) {
514 helpers->
dpms(encoder, value);
520 cdv_intel_lvds_helper_funcs = {
521 .dpms = cdv_intel_lvds_encoder_dpms,
522 .mode_fixup = cdv_intel_lvds_mode_fixup,
523 .prepare = cdv_intel_lvds_prepare,
524 .mode_set = cdv_intel_lvds_mode_set,
525 .commit = cdv_intel_lvds_commit,
529 cdv_intel_lvds_connector_helper_funcs = {
530 .get_modes = cdv_intel_lvds_get_modes,
531 .mode_valid = cdv_intel_lvds_mode_valid,
537 .save = cdv_intel_lvds_save,
538 .restore = cdv_intel_lvds_restore,
539 .detect = cdv_intel_lvds_detect,
541 .set_property = cdv_intel_lvds_set_property,
542 .destroy = cdv_intel_lvds_destroy,
546 static void cdv_intel_lvds_enc_destroy(
struct drm_encoder *encoder)
552 .destroy = cdv_intel_lvds_enc_destroy,
562 static bool lvds_is_present_in_vbt(
struct drm_device *dev,
615 struct psb_intel_encoder *psb_intel_encoder;
628 if (!lvds_is_present_in_vbt(dev, &pin)) {
629 DRM_DEBUG_KMS(
"LVDS is not present in VBT\n");
633 psb_intel_encoder = kzalloc(
sizeof(
struct psb_intel_encoder),
635 if (!psb_intel_encoder)
638 psb_intel_connector = kzalloc(
sizeof(
struct psb_intel_connector),
640 if (!psb_intel_connector)
641 goto failed_connector;
645 goto failed_lvds_priv;
647 psb_intel_encoder->
dev_priv = lvds_priv;
649 connector = &psb_intel_connector->
base;
650 encoder = &psb_intel_encoder->
base;
654 &cdv_intel_lvds_connector_funcs,
658 &cdv_intel_lvds_enc_funcs,
666 drm_encoder_helper_add(encoder, &cdv_intel_lvds_helper_funcs);
667 drm_connector_helper_add(connector,
668 &cdv_intel_lvds_connector_helper_funcs);
675 dev->mode_config.scaling_mode_property,
688 if (!psb_intel_encoder->
i2c_bus) {
690 &dev->pdev->dev,
"I2C bus registration failed.\n");
693 psb_intel_encoder->
i2c_bus->slave_addr = 0x2C;
710 if (!psb_intel_encoder->
ddc_bus) {
711 dev_printk(
KERN_ERR, &dev->pdev->dev,
712 "DDC bus registration " "failed.\n");
721 &psb_intel_encoder->
ddc_bus->adapter);
762 (
"Found no modes on the lvds, ignoring the LVDS\n");
785 if (psb_intel_encoder->
ddc_bus)
789 if (psb_intel_encoder->
i2c_bus)
797 kfree(psb_intel_connector);
799 kfree(psb_intel_encoder);