[Intel-gfx] [PATCH v5] drm/i915: Set backlight class max to 100 and respect the VBT minimum again.

Shih-Yuan Lee (FourDollars) sylee at canonical.com
Wed Nov 11 06:10:10 PST 2015


There was a wonderful period after

commit 6dda730e55f412a6dfb181cae6784822ba463847
Author: Jani Nikula <jani.nikula at intel.com>
Date:   Tue Jun 24 18:27:40 2014 +0300

    drm/i915: respect the VBT minimum backlight brightness

However everything is changed after

commit e6755fb78e8f20ecadf2a4080084121336624ad9
Author: Jani Nikula <jani.nikula at intel.com>
Date:   Tue Aug 12 17:11:42 2014 +0300

    drm/i915: switch off backlight for backlight class 0 brightness

Take Dell XPS 13 (2015) as an example.
"VBT backlight PWM modulation frequency 200 Hz, active high, min brightness 10,
level 255" means the VBT min is 10 out of [0..255] and the PWM max is 937 from
other place so the PWM min should be 37 (10 * 937 / 256).

Originally backlight class 0 brightness means the PWM min and it does
not turn off the backlight. After kernel 3.18, backlight class 0
brightness is used to turn off the backlight and the PWM min is missing.

This commit makes that backlight class 1 brightness means the PWM min
and backlight class 100 brightness means the PWM max.

Signed-off-by: Shih-Yuan Lee (FourDollars) <sylee at canonical.com>
---
 drivers/gpu/drm/i915/intel_panel.c | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/i915/intel_panel.c b/drivers/gpu/drm/i915/intel_panel.c
index a24df35..31ba151 100644
--- a/drivers/gpu/drm/i915/intel_panel.c
+++ b/drivers/gpu/drm/i915/intel_panel.c
@@ -1207,11 +1207,8 @@ static int intel_backlight_device_register(struct intel_connector *connector)
 	memset(&props, 0, sizeof(props));
 	props.type = BACKLIGHT_RAW;
 
-	/*
-	 * Note: Everything should work even if the backlight device max
-	 * presented to the userspace is arbitrarily chosen.
-	 */
-	props.max_brightness = panel->backlight.max;
+	/* Set brightness maximum to a fixed value 100. */
+	props.max_brightness = 100;
 	props.brightness = scale_hw_to_user(connector,
 					    panel->backlight.level,
 					    props.max_brightness);
@@ -1414,6 +1411,8 @@ static u32 get_backlight_min_vbt(struct intel_connector *connector)
 	struct drm_device *dev = connector->base.dev;
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct intel_panel *panel = &connector->panel;
+	u32 pwm_min;
+	u32 pwm_step;
 	int min;
 
 	WARN_ON(panel->backlight.max == 0);
@@ -1432,7 +1431,20 @@ static u32 get_backlight_min_vbt(struct intel_connector *connector)
 	}
 
 	/* vbt value is a coefficient in range [0..255] */
-	return scale(min, 0, 255, 0, panel->backlight.max);
+	pwm_min = scale(min, 0, 255, 0, panel->backlight.max);
+
+	/* Calculate the PWM step */
+	pwm_step = scale(1, 0, 99, 0, panel->backlight.max - pwm_min);
+
+	/*
+	 * Because backlight class brightness 0 is used to turn off the backlight, we
+	 * need to step down a little bit here to make backlight class brightness 1
+	 * match the PWM min.
+	 */
+	if (pwm_min >= pwm_step)
+		return pwm_min - pwm_step;
+
+	return pwm_min;
 }
 
 static int lpt_setup_backlight(struct intel_connector *connector, enum pipe unused)
-- 
1.9.1



More information about the Intel-gfx mailing list