Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp120605ybi; Thu, 13 Jun 2019 12:44:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqx1Z4a0nGLis7lB7KaNkkd57G3Chvg7aQ2asdP/HNy53tZ+cv2IeN2uDX2PSWR0S3rVL6EL X-Received: by 2002:a62:5b81:: with SMTP id p123mr95413640pfb.158.1560455044954; Thu, 13 Jun 2019 12:44:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560455044; cv=none; d=google.com; s=arc-20160816; b=TfwPMWA0ZWVB0SbQeBL6LGyWxcrVESLyWkcVoXXxl5I0wznwEHTvB61XCcM/lsuFZJ KDzwy5GucyMMdq7nql7msqIXnC0hJpChjdT3OgIqDiuwLDUVWf9yPpdroUiNuRweH/Yn 5u9orWuw29fgOA2uQypwkOXOALO27KEtSsD/DXtcV1VaHgfiZnqx/Lxr2IziXdsxDwID I1nE3vy5XBSudmlPjdytjYlWd6v62ZiPxW5GiMXGiau+o/LZqg64bLmu1vjZN9y/2bUA FIN886IMGXLMLIR67hCiytM7GYwuU7fsbX9av6LBfj8SA2kCNuK/qm4WHVYIfZDPLvCa R4HA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=pqXyxTTAbi5aST0rw8BM87gXyR3d1+ROgexg6G5YkyQ=; b=OrCpqVl2SqbdprEtMFuIDIbdkp+fIsr0KXLlFFM0lh1qE67bK9bzVIrC6CvzePTOf0 t+5YQ87DJR+k6kyXgksnPzUb+EqssvPnKMtKe6O5da3SwATrCT9IVH2RDh+57lGPm1uq TIlgaT3QX6F+mQAFUBEb8iUaceW9eIOLSNQ9DH/YGzRUk5VdN6Ju56JL/fc9ij/xlLvZ jH0zwbFhoT+8WGGOZK9+WWEcIvcOe7KwmrUVd7eLLdgMTJzvR2ZxsS7DUaXbdu4qgius +eBH/v/l/yAb8KAiVDucmf9vn1tBpSUOwbnYKO8uVDF42xCE4yD9KrSe+OAulIZnbh7K YhtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=g7PzxI3g; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d19si340728pls.221.2019.06.13.12.43.49; Thu, 13 Jun 2019 12:44:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=g7PzxI3g; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729558AbfFMTnk (ORCPT + 99 others); Thu, 13 Jun 2019 15:43:40 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:35674 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729528AbfFMTni (ORCPT ); Thu, 13 Jun 2019 15:43:38 -0400 Received: by mail-pf1-f193.google.com with SMTP id d126so12461299pfd.2 for ; Thu, 13 Jun 2019 12:43:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pqXyxTTAbi5aST0rw8BM87gXyR3d1+ROgexg6G5YkyQ=; b=g7PzxI3g42K7LJ1ywDPo6EXnhLkUuGu9zje5jOJWOtwmgEfQQqo/EhoS1ZZt31I04+ fL1PiB7Ex9sJ7fFijAjKJXwHIRQGwUDJKGx1a2snaLaeGJ5l7VIa4Ae5wrAbEPSfcrWL huLjIf47PLe+/0vlbh03Nc3iTlYmithF5Qyts= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pqXyxTTAbi5aST0rw8BM87gXyR3d1+ROgexg6G5YkyQ=; b=MWTwgT0wRGVIonIPk8hPkxctkf2VQKGwFahaRZyOakG6zcpngsj64fXoAzCr0CfruJ pyjwbM/tPVEuK9kh2prRqZ8DnK8TOyq3x9LEQTv6p6zcQH2nJQxGP5Abb8Y8OzvHy8Jo ueaEMBTGNlCnJTuUXyTe+66RBN4OOBtgBy1ab2Y77c+/TKy0ALYeuLBfvxUG8cahqe1r PDXIzVYeWvUQbrPxzBiaM1TmLWafongVjdPKDy9/gGTiBSpSL6UHHsBs8navDUtJP4op C/CKWXKcKMlGkjsDRR1AlgloDDtNF3biiybpjwrtJFL9lXvI36pmC8X1FND0Q6StJDV/ kGMg== X-Gm-Message-State: APjAAAWOXt6MrqGBEyus4+LuMIvQCMNL+g8pTvmdcNLhRArtbhDfkI8d Rbnpj5Of77/12cQAMfLujR2v/w== X-Received: by 2002:a17:90a:898e:: with SMTP id v14mr7218671pjn.119.1560455017445; Thu, 13 Jun 2019 12:43:37 -0700 (PDT) Received: from localhost ([2620:15c:202:1:75a:3f6e:21d:9374]) by smtp.gmail.com with ESMTPSA id 5sm557967pgi.28.2019.06.13.12.43.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Jun 2019 12:43:37 -0700 (PDT) From: Matthias Kaehlcke To: Thierry Reding , Lee Jones , Daniel Thompson , Jingoo Han , Bartlomiej Zolnierkiewicz Cc: linux-pwm@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org, Enric Balletbo i Serra , Douglas Anderson , Brian Norris , Pavel Machek , Jacek Anaszewski , Matthias Kaehlcke Subject: [PATCH 4/4] backlight: pwm_bl: Set scale type for brightness curves specified in the DT Date: Thu, 13 Jun 2019 12:43:26 -0700 Message-Id: <20190613194326.180889-5-mka@chromium.org> X-Mailer: git-send-email 2.22.0.rc2.383.gf4fbbf30c2-goog In-Reply-To: <20190613194326.180889-1-mka@chromium.org> References: <20190613194326.180889-1-mka@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Check if a brightness curve specified in the device tree is linear or not and set the corresponding property accordingly. This makes the scale type available to userspace via the 'scale' sysfs attribute. To determine if a curve is linear it is compared to a interpolated linear curve between min and max brightness. The curve is considered linear if no value deviates more than +/-5% of ${brightness_range} from their interpolated value. Signed-off-by: Matthias Kaehlcke --- drivers/video/backlight/pwm_bl.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c index f067fe7aa35d..912407b6d67f 100644 --- a/drivers/video/backlight/pwm_bl.c +++ b/drivers/video/backlight/pwm_bl.c @@ -404,6 +404,26 @@ int pwm_backlight_brightness_default(struct device *dev, } #endif +static bool pwm_backlight_is_linear(struct platform_pwm_backlight_data *data) +{ + unsigned int nlevels = data->max_brightness + 1; + unsigned int min_val = data->levels[0]; + unsigned int max_val = data->levels[nlevels - 1]; + unsigned int slope = (100 * (max_val - min_val)) / nlevels; + unsigned int margin = (max_val - min_val) / 20; /* 5% */ + int i; + + for (i = 1; i < nlevels; i++) { + unsigned int linear_value = min_val + ((i * slope) / 100); + unsigned int delta = abs(linear_value - data->levels[i]); + + if (delta > margin) + return false; + } + + return true; +} + static int pwm_backlight_initial_power_state(const struct pwm_bl_data *pb) { struct device_node *node = pb->dev->of_node; @@ -567,6 +587,11 @@ static int pwm_backlight_probe(struct platform_device *pdev) pb->levels = data->levels; } + + if (pwm_backlight_is_linear(data)) + props.scale = BACKLIGHT_SCALE_LINEAR; + else + props.scale = BACKLIGHT_SCALE_NON_LINEAR; } else if (!data->max_brightness) { /* * If no brightness levels are provided and max_brightness is -- 2.22.0.rc2.383.gf4fbbf30c2-goog