From patchwork Sun May 4 07:16:05 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Lu X-Patchwork-Id: 4107361 Return-Path: X-Original-To: patchwork-intel-gfx@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 83BF4BFF02 for ; Sun, 4 May 2014 07:15:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A64FA202E6 for ; Sun, 4 May 2014 07:15:21 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 36AB5202AE for ; Sun, 4 May 2014 07:15:20 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 829C66E337; Sun, 4 May 2014 00:15:18 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by gabe.freedesktop.org (Postfix) with ESMTP id 2F2646E337; Sun, 4 May 2014 00:15:17 -0700 (PDT) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP; 04 May 2014 00:15:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.97,980,1389772800"; d="scan'208";a="533182600" Received: from aaronlu.sh.intel.com ([10.239.37.56]) by fmsmga002.fm.intel.com with ESMTP; 04 May 2014 00:15:14 -0700 Message-ID: <5365E935.4020703@intel.com> Date: Sun, 04 May 2014 15:16:05 +0800 From: Aaron Lu MIME-Version: 1.0 To: Daniel Vetter References: <535DC8C1.5090407@intel.com> <20140428134147.GB32404@phenom.ffwll.local> In-Reply-To: <20140428134147.GB32404@phenom.ffwll.local> Cc: Nico Schottelius , "intel-gfx@lists.freedesktop.org" , "dri-devel@lists.freedesktop.org" Subject: [Intel-gfx] [PATCH v2] drm/i915: restore backlight precision when converting from opregion X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" 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 04/28/2014 09:41 PM, Daniel Vetter wrote: > 64bit divisions won't compile on 32bit. You need one of the DO_DIV macros, > or whatever they're called again. I pain, I know ;-) Thanks for the correction, here is an updated patch :-) From: Aaron Lu Date: Mon, 28 Apr 2014 11:02:52 +0800 Subject: [PATCH v2] 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 --- v2: use do_div as reminded by Daniel. 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 a953b081ee38..8725917a3d0d 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 = level * freq; + do_div(n, max); + level = n; panel->backlight.level = level; if (panel->backlight.device)