All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Shih-Yuan Lee (FourDollars)" <sylee@canonical.com>
To: intel-gfx@lists.freedesktop.org
Subject: [PATCH v6] drm/i915: respect the VBT minimum backlight brightness again
Date: Thu, 12 Nov 2015 13:43:59 +0800	[thread overview]
Message-ID: <1447307039-11147-1-git-send-email-sylee@canonical.com> (raw)
In-Reply-To: <1447051331-11829-1-git-send-email-sylee@canonical.com>

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

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

Because of

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

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

When we set backlight class 0 brightness, the backlight is turned off.
Althought the PWM value is 37 when the backlight is off but it is
useless. When we set set backlight class 1 brightness, the backlight is
on but the PWM value is 38 and it doesn't match the corresponding PWM
min of the VBT minimum backlight.

And it has another minor issue that there are some backlight class
brightness values are mapped to the same PWM value because the backlight
class brightness range is larger than the valid PWM brightness range.

The backlight class brightness range [0..937]
The valid PWM brightness range [37..937]

This commit makes that backlight class 1 brightness means the PWM min
and backlight class max_brightness means the PWM max, and the ranges
become

The backlight class brightness range [0..901]
The valid PWM brightness range [36..937]

That's no backlight class brightness value mapped to the same PWM value.

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

diff --git a/drivers/gpu/drm/i915/intel_panel.c b/drivers/gpu/drm/i915/intel_panel.c
index b05c6d9..8efa199 100644
--- a/drivers/gpu/drm/i915/intel_panel.c
+++ b/drivers/gpu/drm/i915/intel_panel.c
@@ -1194,10 +1194,9 @@ static int intel_backlight_device_register(struct intel_connector *connector)
 	props.type = BACKLIGHT_RAW;
 
 	/*
-	 * Note: Everything should work even if the backlight device max
-	 * presented to the userspace is arbitrarily chosen.
+	 * Expose the whole valid PWM brightness range to the backlight class.
 	 */
-	props.max_brightness = panel->backlight.max;
+	props.max_brightness = panel->backlight.max - panel->backlight.min;
 	props.brightness = scale_hw_to_user(connector,
 					    panel->backlight.level,
 					    props.max_brightness);
@@ -1400,7 +1399,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;
-	int min;
+	int vbt_min;
+	u32 pwm_min;
 
 	WARN_ON(panel->backlight.max == 0);
 
@@ -1411,14 +1411,24 @@ static u32 get_backlight_min_vbt(struct intel_connector *connector)
 	 * against this by letting the minimum be at most (arbitrarily chosen)
 	 * 25% of the max.
 	 */
-	min = clamp_t(int, dev_priv->vbt.backlight.min_brightness, 0, 64);
-	if (min != dev_priv->vbt.backlight.min_brightness) {
+	vbt_min = clamp_t(int, dev_priv->vbt.backlight.min_brightness, 0, 64);
+	if (vbt_min != dev_priv->vbt.backlight.min_brightness) {
 		DRM_DEBUG_KMS("clamping VBT min backlight %d/255 to %d/255\n",
-			      dev_priv->vbt.backlight.min_brightness, min);
+			      dev_priv->vbt.backlight.min_brightness, vbt_min);
 	}
 
 	/* vbt value is a coefficient in range [0..255] */
-	return scale(min, 0, 255, 0, panel->backlight.max);
+	pwm_min = scale(vbt_min, 0, 255, 0, panel->backlight.max);
+
+	/*
+	 * 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 real PWM min.
+	 */
+	if (pwm_min > 0)
+		return pwm_min - 1;
+	else
+		return 0;
 }
 
 static int lpt_setup_backlight(struct intel_connector *connector, enum pipe unused)
-- 
1.9.1

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

  parent reply	other threads:[~2015-11-12  5:44 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-09  6:42 [PATCH] drm/i915: A better maximum brightness for users Shih-Yuan Lee (FourDollars)
2015-11-09 10:17 ` Jani Nikula
2015-11-09 10:30   ` Shih-Yuan Lee (FourDollars)
2015-11-09 10:51     ` Jani Nikula
2015-11-09 11:54       ` Shih-Yuan Lee (FourDollars)
2015-11-09 12:58         ` Jani Nikula
2015-11-09 14:02           ` Shih-Yuan Lee (FourDollars)
2015-11-09 15:25             ` Ville Syrjälä
2015-11-09 16:02   ` Paulo Zanoni
2015-11-09 16:57     ` Jani Nikula
2015-11-10  1:59       ` Shih-Yuan Lee (FourDollars)
2015-11-10  8:01 ` [PATCH v2] drm/i915: Respect the brightness range from VBT Shih-Yuan Lee (FourDollars)
2015-11-10 10:15   ` Jani Nikula
2015-11-10 11:26     ` Shih-Yuan Lee (FourDollars)
2015-11-10 12:57       ` Jani Nikula
2015-11-10 16:11         ` Shih-Yuan Lee (FourDollars)
2015-11-11  4:11   ` [PATCH v3] drm/i915: Set brightness maximum to a fixed value 100 Shih-Yuan Lee (FourDollars)
2015-11-11  4:57     ` kbuild test robot
2015-11-11  7:31 ` [PATCH v4] " Shih-Yuan Lee (FourDollars)
2015-11-11 12:05   ` Jani Nikula
2015-11-11 13:09     ` Shih-Yuan Lee (FourDollars)
2015-11-11 14:10 ` [PATCH v5] drm/i915: Set backlight class max to 100 and respect the VBT minimum again Shih-Yuan Lee (FourDollars)
2015-11-12  5:43 ` Shih-Yuan Lee (FourDollars) [this message]
2015-11-12  8:08   ` [PATCH v6] drm/i915: respect the VBT minimum backlight brightness again Stéphane ANCELOT
2015-11-12  8:28     ` Shih-Yuan Lee (FourDollars)
2015-11-12  8:40       ` Stéphane ANCELOT
2015-11-12  8:57         ` Shih-Yuan Lee (FourDollars)
2015-11-12  9:05           ` Stéphane ANCELOT
2015-11-12 10:01             ` Shih-Yuan Lee (FourDollars)
2015-11-18  9:06               ` Stéphane ANCELOT
2015-11-18  9:11                 ` Shih-Yuan Lee (FourDollars)
2015-11-12 13:44     ` Jani Nikula
2015-11-13  3:50 ` [PATCH v7] drm/i915: A better backlight class brightness range Shih-Yuan Lee (FourDollars)
2015-11-13  3:50   ` Shih-Yuan Lee (FourDollars)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1447307039-11147-1-git-send-email-sylee@canonical.com \
    --to=sylee@canonical.com \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.