Commit 721e82c0 authored by Aaron Lu's avatar Aaron Lu Committed by Jani Nikula

drm/i915: restore backlight precision when converting from ACPI

When we set backlight on behalf of ACPI opregion, we will convert the
backlight value in the 0-255 range defined in opregion to the actual
hardware level. Commit 22505b82 (drm/i915: avoid brightness overflow
when doing scale) is meant to fix the overflow problem when doing the
conversion, but it also caused a problem that the converted hardware
level doesn't quite represent the intended value: say user wants maximum
backlight level(255 in opregion's range), then we will calculate the
actual hardware level to be: level = freq / max * level, where freq is
the hardware's max backlight level(937 on an user's box), and max and
level are all 255. The converted value should be 937 but the above
calculation will yield 765.

To fix this issue, just use 64 bits to do the calculation to keep the
precision and avoid overflow at the same time.

Buglink: https://bugzilla.kernel.org/show_bug.cgi?id=72491Reported-by: default avatarNico Schottelius <nico-bugzilla.kernel.org@schottelius.org>
Reviewed-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Cc: stable@vger.kernel.org
Signed-off-by: default avatarAaron Lu <aaron.lu@intel.com>
Signed-off-by: default avatarJani Nikula <jani.nikula@intel.com>
parent afba0b5a
...@@ -492,6 +492,7 @@ void intel_panel_set_backlight(struct intel_connector *connector, u32 level, ...@@ -492,6 +492,7 @@ void intel_panel_set_backlight(struct intel_connector *connector, u32 level,
enum pipe pipe = intel_get_pipe_from_connector(connector); enum pipe pipe = intel_get_pipe_from_connector(connector);
u32 freq; u32 freq;
unsigned long flags; unsigned long flags;
u64 n;
if (!panel->backlight.present || pipe == INVALID_PIPE) if (!panel->backlight.present || pipe == INVALID_PIPE)
return; return;
...@@ -502,10 +503,9 @@ void intel_panel_set_backlight(struct intel_connector *connector, u32 level, ...@@ -502,10 +503,9 @@ void intel_panel_set_backlight(struct intel_connector *connector, u32 level,
/* scale to hardware max, but be careful to not overflow */ /* scale to hardware max, but be careful to not overflow */
freq = panel->backlight.max; freq = panel->backlight.max;
if (freq < max) n = (u64)level * freq;
level = level * freq / max; do_div(n, max);
else level = n;
level = freq / max * level;
panel->backlight.level = level; panel->backlight.level = level;
if (panel->backlight.device) if (panel->backlight.device)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment