From patchwork Mon May 12 08:55:45 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Lu X-Patchwork-Id: 4158411 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id F0E2CC0ACC for ; Mon, 12 May 2014 10:56:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 24DEC20274 for ; Mon, 12 May 2014 10:56:25 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 1C7AE202AE for ; Mon, 12 May 2014 10:56:24 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 405316E6F5; Mon, 12 May 2014 03:56:21 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by gabe.freedesktop.org (Postfix) with ESMTP id BECB86E497; Mon, 12 May 2014 01:55:58 -0700 (PDT) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP; 12 May 2014 01:50:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="4.97,1033,1389772800"; d="scan'208"; a="538782597" Received: from aaronlu.sh.intel.com ([10.239.37.63]) by orsmga002.jf.intel.com with ESMTP; 12 May 2014 01:55:45 -0700 Message-ID: <53708C91.7030601@intel.com> Date: Mon, 12 May 2014 16:55:45 +0800 From: Aaron Lu MIME-Version: 1.0 To: Chris Wilson , Daniel Vetter , Nico Schottelius , "intel-gfx@lists.freedesktop.org" , "dri-devel@lists.freedesktop.org" Subject: [PATCH v3] drm/i915: restore backlight precision when converting from opregion References: <535DC8C1.5090407@intel.com> <20140428134147.GB32404@phenom.ffwll.local> <5365E935.4020703@intel.com> <20140504072232.GA22557@nuc-i3427.alporthouse.com> In-Reply-To: <20140504072232.GA22557@nuc-i3427.alporthouse.com> X-Mailman-Approved-At: Mon, 12 May 2014 03:56:20 -0700 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On 05/04/2014 03:22 PM, Chris Wilson wrote: > 32b * 32b = 32b > > n = (u64)level * freq; to avoid overflow as you claim. Updated patch to fix this problem is here, thanks! From a0f41a92d949c814c203672ff7efe219a90ca6df Mon Sep 17 00:00:00 2001 From: Aaron Lu Date: Mon, 28 Apr 2014 11:02:52 +0800 Subject: [PATCH] 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 22505b82a2 (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=72491 Reported-by: Nico Schottelius Signed-off-by: Aaron Lu --- drivers/gpu/drm/i915/intel_panel.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/i915/intel_panel.c b/drivers/gpu/drm/i915/intel_panel.c index 0eead16aeda7..cb8cfb7e0974 100644 --- a/drivers/gpu/drm/i915/intel_panel.c +++ b/drivers/gpu/drm/i915/intel_panel.c @@ -492,6 +492,7 @@ void intel_panel_set_backlight(struct intel_connector *connector, u32 level, enum pipe pipe = intel_get_pipe_from_connector(connector); u32 freq; unsigned long flags; + u64 n; if (!panel->backlight.present || pipe == INVALID_PIPE) return; @@ -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 */ freq = panel->backlight.max; - if (freq < max) - level = level * freq / max; - else - level = freq / max * level; + n = (u64)level * freq; + do_div(n, max); + level = n; panel->backlight.level = level; if (panel->backlight.device)