提交 9aba9d3a 编写于 作者: A Alan Cox 提交者: Dave Airlie

gma500: implement backlight functionality for Cedartrail devices

Basically a straight cut/paste from the reference driver code then
cleaned up a spot.
Signed-off-by: NAlan Cox <alan@linux.intel.com>
Signed-off-by: NDave Airlie <airlied@redhat.com>
上级 bb849779
...@@ -57,8 +57,7 @@ static int cdv_output_init(struct drm_device *dev) ...@@ -57,8 +57,7 @@ static int cdv_output_init(struct drm_device *dev)
cdv_intel_crt_init(dev, &dev_priv->mode_dev); cdv_intel_crt_init(dev, &dev_priv->mode_dev);
cdv_intel_lvds_init(dev, &dev_priv->mode_dev); cdv_intel_lvds_init(dev, &dev_priv->mode_dev);
/* These bits indicate HDMI not SDVO on CDV, but we don't yet support /* These bits indicate HDMI not SDVO on CDV */
the HDMI interface */
if (REG_READ(SDVOB) & SDVO_DETECTED) if (REG_READ(SDVOB) & SDVO_DETECTED)
cdv_hdmi_init(dev, &dev_priv->mode_dev, SDVOB); cdv_hdmi_init(dev, &dev_priv->mode_dev, SDVOB);
if (REG_READ(SDVOC) & SDVO_DETECTED) if (REG_READ(SDVOC) & SDVO_DETECTED)
...@@ -69,76 +68,71 @@ static int cdv_output_init(struct drm_device *dev) ...@@ -69,76 +68,71 @@ static int cdv_output_init(struct drm_device *dev)
#ifdef CONFIG_BACKLIGHT_CLASS_DEVICE #ifdef CONFIG_BACKLIGHT_CLASS_DEVICE
/* /*
* Poulsbo Backlight Interfaces * Cedartrail Backlght Interfaces
*/ */
#define BLC_PWM_PRECISION_FACTOR 100 /* 10000000 */
#define BLC_PWM_FREQ_CALC_CONSTANT 32
#define MHz 1000000
#define PSB_BLC_PWM_PRECISION_FACTOR 10
#define PSB_BLC_MAX_PWM_REG_FREQ 0xFFFE
#define PSB_BLC_MIN_PWM_REG_FREQ 0x2
#define PSB_BACKLIGHT_PWM_POLARITY_BIT_CLEAR (0xFFFE)
#define PSB_BACKLIGHT_PWM_CTL_SHIFT (16)
static int cdv_brightness;
static struct backlight_device *cdv_backlight_device; static struct backlight_device *cdv_backlight_device;
static int cdv_get_brightness(struct backlight_device *bd) static int cdv_backlight_combination_mode(struct drm_device *dev)
{ {
/* return locally cached var instead of HW read (due to DPST etc.) */ return REG_READ(BLC_PWM_CTL2) & PWM_LEGACY_MODE;
/* FIXME: ideally return actual value in case firmware fiddled with
it */
return cdv_brightness;
} }
static int cdv_get_brightness(struct backlight_device *bd)
static int cdv_backlight_setup(struct drm_device *dev)
{ {
struct drm_psb_private *dev_priv = dev->dev_private; struct drm_device *dev = bl_get_data(bd);
unsigned long core_clock; u32 val = REG_READ(BLC_PWM_CTL) & BACKLIGHT_DUTY_CYCLE_MASK;
/* u32 bl_max_freq; */
/* unsigned long value; */
u16 bl_max_freq;
uint32_t value;
uint32_t blc_pwm_precision_factor;
/* get bl_max_freq and pol from dev_priv*/
if (!dev_priv->lvds_bl) {
dev_err(dev->dev, "Has no valid LVDS backlight info\n");
return -ENOENT;
}
bl_max_freq = dev_priv->lvds_bl->freq;
blc_pwm_precision_factor = PSB_BLC_PWM_PRECISION_FACTOR;
core_clock = dev_priv->core_freq; if (cdv_backlight_combination_mode(dev)) {
u8 lbpc;
val &= ~1;
pci_read_config_byte(dev->pdev, 0xF4, &lbpc);
val *= lbpc;
}
return val;
}
value = (core_clock * MHz) / BLC_PWM_FREQ_CALC_CONSTANT; static u32 cdv_get_max_backlight(struct drm_device *dev)
value *= blc_pwm_precision_factor; {
value /= bl_max_freq; u32 max = REG_READ(BLC_PWM_CTL);
value /= blc_pwm_precision_factor;
if (value > (unsigned long long)PSB_BLC_MAX_PWM_REG_FREQ || if (max == 0) {
value < (unsigned long long)PSB_BLC_MIN_PWM_REG_FREQ) DRM_DEBUG_KMS("LVDS Panel PWM value is 0!\n");
return -ERANGE; /* i915 does this, I believe which means that we should not
else { * smash PWM control as firmware will take control of it. */
/* FIXME */ return 1;
} }
return 0;
max >>= 16;
if (cdv_backlight_combination_mode(dev))
max *= 0xff;
return max;
} }
static int cdv_set_brightness(struct backlight_device *bd) static int cdv_set_brightness(struct backlight_device *bd)
{ {
struct drm_device *dev = bl_get_data(bd);
int level = bd->props.brightness; int level = bd->props.brightness;
u32 blc_pwm_ctl;
/* Percentage 1-100% being valid */ /* Percentage 1-100% being valid */
if (level < 1) if (level < 1)
level = 1; level = 1;
/*cdv_intel_lvds_set_brightness(dev, level); FIXME */ if (cdv_backlight_combination_mode(dev)) {
cdv_brightness = level; u32 max = cdv_get_max_backlight(dev);
u8 lbpc;
lbpc = level * 0xfe / max + 1;
level /= lbpc;
pci_write_config_byte(dev->pdev, 0xF4, lbpc);
}
blc_pwm_ctl = REG_READ(BLC_PWM_CTL) & ~BACKLIGHT_DUTY_CYCLE_MASK;
REG_WRITE(BLC_PWM_CTL, (blc_pwm_ctl |
(level << BACKLIGHT_DUTY_CYCLE_SHIFT)));
return 0; return 0;
} }
...@@ -150,7 +144,6 @@ static const struct backlight_ops cdv_ops = { ...@@ -150,7 +144,6 @@ static const struct backlight_ops cdv_ops = {
static int cdv_backlight_init(struct drm_device *dev) static int cdv_backlight_init(struct drm_device *dev)
{ {
struct drm_psb_private *dev_priv = dev->dev_private; struct drm_psb_private *dev_priv = dev->dev_private;
int ret;
struct backlight_properties props; struct backlight_properties props;
memset(&props, 0, sizeof(struct backlight_properties)); memset(&props, 0, sizeof(struct backlight_properties));
...@@ -162,14 +155,9 @@ static int cdv_backlight_init(struct drm_device *dev) ...@@ -162,14 +155,9 @@ static int cdv_backlight_init(struct drm_device *dev)
if (IS_ERR(cdv_backlight_device)) if (IS_ERR(cdv_backlight_device))
return PTR_ERR(cdv_backlight_device); return PTR_ERR(cdv_backlight_device);
ret = cdv_backlight_setup(dev); cdv_backlight_device->props.brightness =
if (ret < 0) { cdv_get_brightness(cdv_backlight_device);
backlight_device_unregister(cdv_backlight_device); cdv_backlight_device->props.max_brightness = cdv_get_max_brightness;
cdv_backlight_device = NULL;
return ret;
}
cdv_backlight_device->props.brightness = 100;
cdv_backlight_device->props.max_brightness = 100;
backlight_update_status(cdv_backlight_device); backlight_update_status(cdv_backlight_device);
dev_priv->backlight_device = cdv_backlight_device; dev_priv->backlight_device = cdv_backlight_device;
return 0; return 0;
...@@ -244,11 +232,12 @@ static void cdv_init_pm(struct drm_device *dev) ...@@ -244,11 +232,12 @@ static void cdv_init_pm(struct drm_device *dev)
static void cdv_errata(struct drm_device *dev) static void cdv_errata(struct drm_device *dev)
{ {
/* Disable bonus launch. /* Disable bonus launch.
* CPU and GPU competes for memory and display misses updates and flickers. * CPU and GPU competes for memory and display misses updates and
* Worst with dual core, dual displays. * flickers. Worst with dual core, dual displays.
* *
* Fixes were done to Win 7 gfx driver to disable a feature called Bonus * Fixes were done to Win 7 gfx driver to disable a feature called
* Launch to work around the issue, by degrading performance. * Bonus Launch to work around the issue, by degrading
* performance.
*/ */
CDV_MSG_WRITE32(3, 0x30, 0x08027108); CDV_MSG_WRITE32(3, 0x30, 0x08027108);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册