From 0e6f608d5ea1debe08b09344ce13c2f4b46daa75 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Thu, 13 Jan 2011 12:30:19 +0000 Subject: [PATCH] drm/i915: Fix application of legacy backlight value Remove the spurious division by two in getting the current value, and if the legacy value is 0xff it is unused. And whilst setting the value, fix the rounding. Reported-by: Nick Bowler Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=31803 Signed-off-by: Chris Wilson --- drivers/gpu/drm/i915/intel_panel.c | 14 ++++++++++---- 1 files changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/i915/intel_panel.c b/drivers/gpu/drm/i915/intel_panel.c index c65992d..b77abda 100644 --- a/drivers/gpu/drm/i915/intel_panel.c +++ b/drivers/gpu/drm/i915/intel_panel.c @@ -205,10 +205,11 @@ u32 intel_panel_get_backlight(struct drm_device *dev) if (is_backlight_combination_mode(dev)){ u8 lbpc; - val &= ~1; pci_read_config_byte(dev->pdev, PCI_LBPC, &lbpc); + /* Report the value in [0:max] i.e. always multiplied + * by lbpc even if the hardware does not (0xff). + */ val *= lbpc; - val >>= 1; } } @@ -237,9 +238,14 @@ void intel_panel_set_backlight(struct drm_device *dev, u32 level) u32 max = intel_panel_get_max_backlight(dev); u8 lpbc; - lpbc = level * 0xfe / max + 1; - level /= lpbc; + lpbc = (level * 0xfe + max-1) / max + 1; pci_write_config_byte(dev->pdev, PCI_LBPC, lpbc); + + /* The hardware is tricksy and treats lpbc == 0xff specially */ + if (lpbc != 0xff) + lpbc *= 0xff; + + level = (level + lpbc-1) / lpbc; } tmp = I915_READ(BLC_PWM_CTL); -- 1.7.2.3