From patchwork Tue Sep 23 22:50:25 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Konno X-Patchwork-Id: 4960541 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 29FDA9F2BB for ; Tue, 23 Sep 2014 22:50:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 67AAC20220 for ; Tue, 23 Sep 2014 22:50:29 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 33ED3201DD for ; Tue, 23 Sep 2014 22:50:28 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BC2816E196; Tue, 23 Sep 2014 15:50:26 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by gabe.freedesktop.org (Postfix) with ESMTP id 450B56E196 for ; Tue, 23 Sep 2014 15:50:25 -0700 (PDT) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP; 23 Sep 2014 15:50:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.04,583,1406617200"; d="scan'208";a="607450009" Received: from jbkonno-beef.jf.intel.com ([10.7.197.52]) by orsmga002.jf.intel.com with ESMTP; 23 Sep 2014 15:50:24 -0700 From: Joe Konno To: intel-gfx@lists.freedesktop.org Date: Tue, 23 Sep 2014 15:50:25 -0700 Message-Id: <1411512625-10657-1-git-send-email-joe.konno@linux.intel.com> X-Mailer: git-send-email 2.1.0 Subject: [Intel-gfx] [PATCH] drm/i915: intel_backlight scale() math WA 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: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Spam-Status: No, score=-4.9 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 From: Joe Konno Improper integer division-- truncated rather than rounded-- in the scale() function causes actual_brightness != brightness. This (partial) work-around should be sufficient for a majority of use-cases, but it is by no means a complete solution. TODO: Determine how best to scale "user" values to "hw" values, and vice-versa, when the ranges are of different sizes. That would be a buggy scenario even with this work-around. The issue was introduced in the following (v3.17-rc1) commit: 6dda730 drm/i915: respect the VBT minimum backlight brightness Signed-off-by: Joe Konno Reviewed-by: U. Artie Eoff --- drivers/gpu/drm/i915/intel_panel.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/i915/intel_panel.c b/drivers/gpu/drm/i915/intel_panel.c index f17ada3..c40f837 100644 --- a/drivers/gpu/drm/i915/intel_panel.c +++ b/drivers/gpu/drm/i915/intel_panel.c @@ -421,7 +421,8 @@ static uint32_t scale(uint32_t source_val, /* avoid overflows */ target_val = (uint64_t)(source_val - source_min) * (target_max - target_min); - do_div(target_val, source_max - source_min); + target_val = (target_val + ((source_max - source_min) / 2)) / + (source_max - source_min); target_val += target_min; return target_val;