23 #include <linux/i2c.h>
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)
80 ret = dev_priv->
regs.saveBLC_PWM_CTL;
88 dev_err(dev->dev,
"BL bug: Reg %08x save %08X\n",
99 static int psb_lvds_i2c_set_brightness(
struct drm_device *dev,
107 unsigned int blc_i2c_brightness;
125 out_buf[0] =
dev_priv->lvds_bl->brightnesscmd;
126 out_buf[1] = (
u8)blc_i2c_brightness;
129 dev_dbg(
dev->dev,
"I2C set brightness.(command, value) (%d, %d)\n",
146 u32 blc_pwm_duty_cycle;
148 max_pwm_blc = psb_intel_lvds_get_max_backlight(dev);
156 blc_pwm_duty_cycle = max_pwm_blc - blc_pwm_duty_cycle;
161 (blc_pwm_duty_cycle));
163 dev_info(dev->dev,
"Backlight lvds set brightness %08x\n",
165 (blc_pwm_duty_cycle));
177 dev_dbg(dev->dev,
"backlight level is %d\n", level);
180 dev_err(dev->dev,
"NO LVDS backlight info\n");
185 psb_lvds_i2c_set_brightness(dev, level);
187 psb_lvds_pwm_set_brightness(dev, level);
195 static void psb_intel_lvds_set_backlight(
struct drm_device *dev,
int level)
206 dev_priv->
regs.saveBLC_PWM_CTL = (blc_pwm_ctl |
210 blc_pwm_ctl = dev_priv->
regs.saveBLC_PWM_CTL &
212 dev_priv->
regs.saveBLC_PWM_CTL = (blc_pwm_ctl |
220 static void psb_intel_lvds_set_power(
struct drm_device *dev,
bool on)
227 dev_err(dev->dev,
"set power, chip off!\n");
236 }
while ((pp_status &
PP_ON) == 0);
238 psb_intel_lvds_set_backlight(dev,
241 psb_intel_lvds_set_backlight(dev, 0);
247 }
while (pp_status &
PP_ON);
253 static void psb_intel_lvds_encoder_dpms(
struct drm_encoder *encoder,
int mode)
258 psb_intel_lvds_set_power(dev,
true);
260 psb_intel_lvds_set_power(dev,
false);
271 psb_intel_attached_encoder(connector);
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",
306 static void psb_intel_lvds_restore(
struct drm_connector *connector)
311 psb_intel_attached_encoder(connector);
315 dev_dbg(dev->dev,
"(0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x)\n",
338 }
while ((pp_status &
PP_ON) == 0);
344 }
while (pp_status &
PP_ON);
352 struct psb_intel_encoder *psb_intel_encoder =
353 psb_intel_attached_encoder(connector);
355 dev_priv->
mode_dev.panel_fixed_mode;
358 fixed_mode = dev_priv->
mode_dev.panel_fixed_mode2;
388 struct psb_intel_encoder *psb_intel_encoder =
406 if (tmp_encoder != encoder
407 && tmp_encoder->
crtc == encoder->
crtc) {
409 "encoder on the same pipe\n");
420 if (panel_fixed_mode !=
NULL) {
429 adjusted_mode->
clock = panel_fixed_mode->
clock;
443 static void psb_intel_lvds_prepare(
struct drm_encoder *encoder)
456 psb_intel_lvds_set_power(dev,
false);
461 static void psb_intel_lvds_commit(
struct drm_encoder *encoder)
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,
515 *connector,
bool force)
523 static int psb_intel_lvds_get_modes(
struct drm_connector *connector)
528 struct psb_intel_encoder *psb_intel_encoder =
529 psb_intel_attached_encoder(connector);
567 struct psb_intel_encoder *psb_intel_encoder =
568 psb_intel_attached_encoder(connector);
587 if (!
strcmp(property->
name,
"scaling mode")) {
628 }
else if (!
strcmp(property->
name,
"backlight")) {
638 hfuncs->
dpms(encoder, value);
648 .dpms = psb_intel_lvds_encoder_dpms,
650 .prepare = psb_intel_lvds_prepare,
651 .mode_set = psb_intel_lvds_mode_set,
652 .commit = psb_intel_lvds_commit,
657 .get_modes = psb_intel_lvds_get_modes,
664 .save = psb_intel_lvds_save,
665 .restore = psb_intel_lvds_restore,
666 .detect = psb_intel_lvds_detect,
673 static void psb_intel_lvds_enc_destroy(
struct drm_encoder *encoder)
679 .destroy = psb_intel_lvds_enc_destroy,
694 struct psb_intel_encoder *psb_intel_encoder;
706 kzalloc(
sizeof(
struct psb_intel_encoder),
GFP_KERNEL);
707 if (!psb_intel_encoder) {
708 dev_err(dev->dev,
"psb_intel_encoder allocation error\n");
712 psb_intel_connector =
713 kzalloc(
sizeof(
struct psb_intel_connector),
GFP_KERNEL);
714 if (!psb_intel_connector) {
715 dev_err(dev->dev,
"psb_intel_connector allocation error\n");
721 dev_err(dev->dev,
"LVDS private allocation error\n");
722 goto failed_connector;
725 psb_intel_encoder->
dev_priv = lvds_priv;
727 connector = &psb_intel_connector->
base;
728 encoder = &psb_intel_encoder->
base;
730 &psb_intel_lvds_connector_funcs,
734 &psb_intel_lvds_enc_funcs,
741 drm_encoder_helper_add(encoder, &psb_intel_lvds_helper_funcs);
742 drm_connector_helper_add(connector,
743 &psb_intel_lvds_connector_helper_funcs);
750 dev->mode_config.scaling_mode_property,
763 &dev->pdev->dev,
"I2C bus registration failed.\n");
766 lvds_priv->
i2c_bus->slave_addr = 0x2C;
782 dev_printk(
KERN_ERR, &dev->pdev->dev,
783 "DDC bus registration " "failed.\n");
832 dev_err(dev->dev,
"Found no modes on the lvds, ignoring the LVDS\n");
854 kfree(psb_intel_connector);
856 kfree(psb_intel_encoder);