From patchwork Mon Jun 24 20:31:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Kaehlcke X-Patchwork-Id: 11014075 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 29FBA76 for ; Mon, 24 Jun 2019 20:31:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 19E3928B90 for ; Mon, 24 Jun 2019 20:31:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0CE3A28BBE; Mon, 24 Jun 2019 20:31:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 97E1428B90 for ; Mon, 24 Jun 2019 20:31:29 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B319189DC2; Mon, 24 Jun 2019 20:31:28 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3DAAA89DBC for ; Mon, 24 Jun 2019 20:31:22 +0000 (UTC) Received: by mail-pf1-x442.google.com with SMTP id m30so8154713pff.8 for ; Mon, 24 Jun 2019 13:31:22 -0700 (PDT) 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=JP95lZdX+e5+GJVUv6OxKodaA7GTVH/s6o/zZ4o6Yqk=; b=KXhlw+DTX+gwmBLyHIgEs4OjFi8cgEJorsNGx0mNJlnUHll83zYX0vN/hvdyXAvcdz sxILtT4S0cm+rKKsKDZH9QlMXXonoiXpVKNRHoQhcVZVkX0xv7K7ynJToR4K3v7Rvi6X wH3Ia+V+qXUkook7Gvossf4yAG8WCDu97qWvWyHDrKw/4IVbQe3GrzqXdvjxeIX9eG0v PF5LWg6q1/JWjEq8FZkrJPqAXz8ViTBPwN22bEnee2W7dhLFbkqajrEsvZVtUZbmApkN tE38mEdXuNmPZBH451l0ouqk05T8aBsulgka9pEVQYwzwdZitQFchsgZC7t6XBd2Qoyj ubjw== X-Gm-Message-State: APjAAAWgQ3rQu2yZlRmWwvem8HoGHo8WSRXv4tG+LPMYIz2htqokQfSP PQno6YdlrEzFLq85J8cSXFL/cw== X-Google-Smtp-Source: APXvYqw9jBap6wGYgRpzAJeJ6bDMEgATfqj/PCB+aRPwnHh0ax4ayLJ9RddKSYOnMpDP5vtjzzt8pg== X-Received: by 2002:a17:90a:cd04:: with SMTP id d4mr27797860pju.128.1561408281769; Mon, 24 Jun 2019 13:31:21 -0700 (PDT) Received: from localhost ([2620:15c:202:1:75a:3f6e:21d:9374]) by smtp.gmail.com with ESMTPSA id r198sm6217026pfc.149.2019.06.24.13.31.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Jun 2019 13:31:21 -0700 (PDT) From: Matthias Kaehlcke To: Thierry Reding , Lee Jones , Daniel Thompson , Jingoo Han , Bartlomiej Zolnierkiewicz Subject: [PATCH v2 1/4] MAINTAINERS: Add entry for stable backlight sysfs ABI documentation Date: Mon, 24 Jun 2019 13:31:10 -0700 Message-Id: <20190624203114.93277-2-mka@chromium.org> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog In-Reply-To: <20190624203114.93277-1-mka@chromium.org> References: <20190624203114.93277-1-mka@chromium.org> MIME-Version: 1.0 X-Mailman-Original-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=JP95lZdX+e5+GJVUv6OxKodaA7GTVH/s6o/zZ4o6Yqk=; b=GH6GaNaGuD+3/lq/E8qiZgIhrqY4POMDMF6xHbas+S9+1gjPhAdu+raSlGPuBLqD9g BkKsc+XCH1g3Z10BQaTguBLuGNZWvrF/v7D7o9CGRm3XNhjIs+7yeIKYYcTpDmT9I9R8 CIvyVtU+X72CfuHwtLu5CTf7kBuk4/yEwY9wE= X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-pwm@vger.kernel.org, linux-fbdev@vger.kernel.org, Brian Norris , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Douglas Anderson , Matthias Kaehlcke , Jacek Anaszewski , Pavel Machek , Enric Balletbo i Serra Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Add an entry for the stable backlight sysfs ABI to the MAINTAINERS file. Signed-off-by: Matthias Kaehlcke Acked-by: Daniel Thompson --- Changes in v2: - added Daniel's 'Acked-by' tag --- MAINTAINERS | 1 + 1 file changed, 1 insertion(+) diff --git a/MAINTAINERS b/MAINTAINERS index 57f496cff999..d51e74340870 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2857,6 +2857,7 @@ F: drivers/video/backlight/ F: include/linux/backlight.h F: include/linux/pwm_backlight.h F: Documentation/devicetree/bindings/leds/backlight +F: Documentation/ABI/stable/sysfs-class-backlight BATMAN ADVANCED M: Marek Lindner From patchwork Mon Jun 24 20:31:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Kaehlcke X-Patchwork-Id: 11014073 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4EA0A14E5 for ; Mon, 24 Jun 2019 20:31:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3E57728B0D for ; Mon, 24 Jun 2019 20:31:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3258228BC0; Mon, 24 Jun 2019 20:31:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9D27428BBE for ; Mon, 24 Jun 2019 20:31:26 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5936089DB9; Mon, 24 Jun 2019 20:31:25 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by gabe.freedesktop.org (Postfix) with ESMTPS id B388D89DB9 for ; Mon, 24 Jun 2019 20:31:23 +0000 (UTC) Received: by mail-pg1-x544.google.com with SMTP id k13so1541239pgq.9 for ; Mon, 24 Jun 2019 13:31:23 -0700 (PDT) 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=9cvCddzp/rQ9gLoVz2Ohmj6GbBYXrvNQEIWOBydlqbk=; b=hhZITJy4Ls1ztPrA1kgBy853cvWgqw9C+98tXV50Y94iHIMjaWVz+5G/wQ8GhM2W86 7idpdV5I5CEdyxTl3uVbyzTW+0ODylRPhmqPW7iLtj4eiHmRqvum0WbNbQ4m0PxvU/Aq v1ZPVTSKLD3dD+wzpQzH3mrZ4tpiF7VjmnBXU1OvtVmOogAoOBccy6nJ4AzrMuWUKqhL x7aRmS77JU9tuS/q8VubjPkFSsn4IJZQQbGIP2GeZCityIbp+rzZjZY9UAbtqljyEKzi MbcTa7wzaa0BqQ7kt9mU90hbtrwYtNEAxbPYmD7n4o8zOW8zzLi6vEiaTx37+fnk/rUT Ycvg== X-Gm-Message-State: APjAAAXQ+7/m4ChhQpZrVQklyj/mVAydkDSfnIktgJVHECInJlq0mtXU EmmunFlO1Cv90fOvG3duVizboA== X-Google-Smtp-Source: APXvYqztkGD2Zm1lhfUGrYuukC/zkqi/1wiD2UFCDCf7MnzGHMPiBOntzubbs4r7XKjVQ5JRS7vvPw== X-Received: by 2002:a17:90a:206a:: with SMTP id n97mr27137163pjc.10.1561408283171; Mon, 24 Jun 2019 13:31:23 -0700 (PDT) Received: from localhost ([2620:15c:202:1:75a:3f6e:21d:9374]) by smtp.gmail.com with ESMTPSA id c98sm315435pje.1.2019.06.24.13.31.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Jun 2019 13:31:22 -0700 (PDT) From: Matthias Kaehlcke To: Thierry Reding , Lee Jones , Daniel Thompson , Jingoo Han , Bartlomiej Zolnierkiewicz Subject: [PATCH v2 2/4] backlight: Expose brightness curve type through sysfs Date: Mon, 24 Jun 2019 13:31:11 -0700 Message-Id: <20190624203114.93277-3-mka@chromium.org> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog In-Reply-To: <20190624203114.93277-1-mka@chromium.org> References: <20190624203114.93277-1-mka@chromium.org> MIME-Version: 1.0 X-Mailman-Original-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=9cvCddzp/rQ9gLoVz2Ohmj6GbBYXrvNQEIWOBydlqbk=; b=RGTicdS+MgEOYEAHS+smvnz8GlVq6o2y1HVT5Balw5Aa4KWF33hdyuiXxr/N1xo7F+ Cjtl6Fev/1MRaF2vXjK9cwelIWWrUlUxQlbN+bA/ht0z5aX334sPz3PdN4Abm+SWsTsG RpsNTk8Sl4N4t1+uRfbQo6YN+2AA71bqGKxso= X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-pwm@vger.kernel.org, linux-fbdev@vger.kernel.org, Brian Norris , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Douglas Anderson , Matthias Kaehlcke , Jacek Anaszewski , Pavel Machek , Enric Balletbo i Serra Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Backlight brightness curves can have different shapes. The two main types are linear and non-linear curves. The human eye doesn't perceive linearly increasing/decreasing brightness as linear (see also 88ba95bedb79 "backlight: pwm_bl: Compute brightness of LED linearly to human eye"), hence many backlights use non-linear (often logarithmic) brightness curves. The type of curve currently is opaque to userspace, so userspace often uses more or less reliable heuristics (like the number of brightness levels) to decide whether to treat a backlight device as linear or non-linear. Export the type of the brightness curve via the new sysfs attribute 'scale'. The value of the attribute may be a simple string like 'linear' or 'non-linear', or a composite string similar to 'compatible' strings of the device tree. A composite string consists of different elements separated by commas, starting with the most-detailed description and ending with the least-detailed one. An example for a composite string is "cie-1931,perceptual,non-linear" This brightness curve was generated with the CIE 1931 algorithm, it is perceptually linear, but not actually linear in terms of the emitted light. If userspace doesn't know about 'cie-1931' or 'perceptual' it should at least be able to interpret the 'non-linear' part. For devices that don't provide information about the scale of their brightness curve the value of the 'scale' attribute is 'unknown'. Signed-off-by: Matthias Kaehlcke --- Changes in v2: - changed order of brightness scale enums, explicitly make 'unknown' zero - minor update of commit message - deleted excess blank line after 'backlight_scale_types' - s/curves/curve/ in sysfs doc --- .../ABI/testing/sysfs-class-backlight | 32 +++++++++++++++++++ MAINTAINERS | 1 + drivers/video/backlight/backlight.c | 21 ++++++++++++ include/linux/backlight.h | 10 ++++++ 4 files changed, 64 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-class-backlight diff --git a/Documentation/ABI/testing/sysfs-class-backlight b/Documentation/ABI/testing/sysfs-class-backlight new file mode 100644 index 000000000000..da1ce9e5c55a --- /dev/null +++ b/Documentation/ABI/testing/sysfs-class-backlight @@ -0,0 +1,32 @@ +What: /sys/class/backlight//scale +Date: June 2019 +KernelVersion: 5.4 +Contact: Daniel Thompson +Description: + Description of the scale of the brightness curve. The + description consists of one or more elements separated by + commas, from the most detailed to the least detailed + description. + + Possible values are: + + unknown + The scale of the brightness curve is unknown. + + linear + The brightness changes linearly in terms of the emitted + light, changes are perceived as non-linear by the human eye. + + non-linear + The brightness changes non-linearly in terms of the emitted + light, changes might be perceived as linear by the human eye. + + perceptual,non-linear + The brightness changes non-linearly in terms of the emitted + light, changes should be perceived as linear by the human eye. + + cie-1931,perceptual,non-linear + The brightness curve was calculated with the CIE 1931 + algorithm. Brightness changes non-linearly in terms of the + emitted light, changes should be perceived as linear by the + human eye. diff --git a/MAINTAINERS b/MAINTAINERS index d51e74340870..c46812510ba5 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2858,6 +2858,7 @@ F: include/linux/backlight.h F: include/linux/pwm_backlight.h F: Documentation/devicetree/bindings/leds/backlight F: Documentation/ABI/stable/sysfs-class-backlight +F: Documentation/ABI/testing/sysfs-class-backlight BATMAN ADVANCED M: Marek Lindner diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c index 1ef8b6fd62ac..86612ec42ed0 100644 --- a/drivers/video/backlight/backlight.c +++ b/drivers/video/backlight/backlight.c @@ -32,6 +32,14 @@ static const char *const backlight_types[] = { [BACKLIGHT_FIRMWARE] = "firmware", }; +static const char *const backlight_scale_types[] = { + [BACKLIGHT_SCALE_UNKNOWN] = "unknown", + [BACKLIGHT_SCALE_LINEAR] = "linear", + [BACKLIGHT_SCALE_NON_LINEAR] = "non-linear", + [BACKLIGHT_SCALE_PERCEPTUAL] = "perceptual,non-linear", + [BACKLIGHT_SCALE_CIE1931] = "cie-1931,perceptual,non-linear", +}; + #if defined(CONFIG_FB) || (defined(CONFIG_FB_MODULE) && \ defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE)) /* This callback gets called when something important happens inside a @@ -246,6 +254,18 @@ static ssize_t actual_brightness_show(struct device *dev, } static DEVICE_ATTR_RO(actual_brightness); +static ssize_t scale_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct backlight_device *bd = to_backlight_device(dev); + + if (WARN_ON(bd->props.scale > BACKLIGHT_SCALE_NON_LINEAR)) + return sprintf(buf, "unknown\n"); + + return sprintf(buf, "%s\n", backlight_scale_types[bd->props.scale]); +} +static DEVICE_ATTR_RO(scale); + static struct class *backlight_class; #ifdef CONFIG_PM_SLEEP @@ -292,6 +312,7 @@ static struct attribute *bl_device_attrs[] = { &dev_attr_brightness.attr, &dev_attr_actual_brightness.attr, &dev_attr_max_brightness.attr, + &dev_attr_scale.attr, &dev_attr_type.attr, NULL, }; diff --git a/include/linux/backlight.h b/include/linux/backlight.h index 0b5897446dca..94d3559cd968 100644 --- a/include/linux/backlight.h +++ b/include/linux/backlight.h @@ -46,6 +46,14 @@ enum backlight_notification { BACKLIGHT_UNREGISTERED, }; +enum backlight_scale { + BACKLIGHT_SCALE_UNKNOWN = 0, + BACKLIGHT_SCALE_LINEAR, + BACKLIGHT_SCALE_NON_LINEAR, /* needed for backwards compatibility */ + BACKLIGHT_SCALE_PERCEPTUAL, + BACKLIGHT_SCALE_CIE1931, +}; + struct backlight_device; struct fb_info; @@ -80,6 +88,8 @@ struct backlight_properties { enum backlight_type type; /* Flags used to signal drivers of state changes */ unsigned int state; + /* Type of the brightness scale (linear, non-linear, ...) */ + enum backlight_scale scale; #define BL_CORE_SUSPENDED (1 << 0) /* backlight is suspended */ #define BL_CORE_FBBLANK (1 << 1) /* backlight is under an fb blank event */ From patchwork Mon Jun 24 20:31:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Kaehlcke X-Patchwork-Id: 11014085 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3AC6976 for ; Mon, 24 Jun 2019 20:31:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2B6DF28BBB for ; Mon, 24 Jun 2019 20:31:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1EFFF28BB8; Mon, 24 Jun 2019 20:31:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C253728B4A for ; Mon, 24 Jun 2019 20:31:37 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 15A4C89DD2; Mon, 24 Jun 2019 20:31:37 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by gabe.freedesktop.org (Postfix) with ESMTPS id 151C489DB9 for ; Mon, 24 Jun 2019 20:31:25 +0000 (UTC) Received: by mail-pf1-x441.google.com with SMTP id m30so8154772pff.8 for ; Mon, 24 Jun 2019 13:31:24 -0700 (PDT) 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=lSYYVqhHYII5ViyDtFOkp4I/i31+agPnClo/p5CN7rU=; b=o0sv4paPaWKWkxnfuMaGRSzzQzCBcb8x4IFaoDX+I1HnIGbuiVA/yhsykLUn0ZamlL s9KaCrs1U7jRlW4fGjxAcFwTbGzBDfgFYrvGUhD/Uc4kTWuE5y9hzcN2JVAbFX+u6OuO VArvZIpxrhm8/kYuBhT3ZuiCutTshi+FwWtG4gU73wFduIQD0jvjG3gDrPDj4OCj6Dr4 V3KS8SR9Mq5+WzkzONpwZk+AK11ZK2atQCBmXTj1z7uTS/xRasGdtUwAf0hPXEtkgO6p K8g4n1Dyyq8PL+4CqjWZhAYd4V/n6Fr+P8w8fyyyvUxv+xThIWt6ddtP/claVCxpVAsC kAlQ== X-Gm-Message-State: APjAAAVA39yqfA38VpJ5fvUhTTidEOZ5tnn9Lpq0NAV8YSrNcVdbDinT 6IFDgZhxohCvfbM+ZjRtx8cYuA== X-Google-Smtp-Source: APXvYqzbWxM5xrdZvQVssIkJ108K28bRsNta+aYXMp4VczMFyBnMpEFk0/3OUZMH3nt4zl2HLpoBMQ== X-Received: by 2002:a65:62ca:: with SMTP id m10mr34696355pgv.57.1561408284531; Mon, 24 Jun 2019 13:31:24 -0700 (PDT) Received: from localhost ([2620:15c:202:1:75a:3f6e:21d:9374]) by smtp.gmail.com with ESMTPSA id e10sm9833411pfi.153.2019.06.24.13.31.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Jun 2019 13:31:24 -0700 (PDT) From: Matthias Kaehlcke To: Thierry Reding , Lee Jones , Daniel Thompson , Jingoo Han , Bartlomiej Zolnierkiewicz Subject: [PATCH v2 3/4] backlight: pwm_bl: Set scale type for CIE 1931 curves Date: Mon, 24 Jun 2019 13:31:12 -0700 Message-Id: <20190624203114.93277-4-mka@chromium.org> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog In-Reply-To: <20190624203114.93277-1-mka@chromium.org> References: <20190624203114.93277-1-mka@chromium.org> MIME-Version: 1.0 X-Mailman-Original-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=lSYYVqhHYII5ViyDtFOkp4I/i31+agPnClo/p5CN7rU=; b=Mg4fv0I1KvsvYo7P+k+I0/jzY0DpnxpM73UwzZA397nYxCv69Pmx51bd0IZKJQS/T0 e/T2av1TRlRVmfz56FF9Jew1DTrqN5iqbEIH15c5yTcYw4xPo9wLhvaIaKD96sdi5ihi w7DU16/nElyk+XneNHQnooeQwSyLleBKKFhyY= X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-pwm@vger.kernel.org, linux-fbdev@vger.kernel.org, Brian Norris , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Douglas Anderson , Matthias Kaehlcke , Jacek Anaszewski , Pavel Machek , Enric Balletbo i Serra Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP For backlight curves calculated with the CIE 1931 algorithm set the brightness scale type property accordingly. This makes the scale type available to userspace via the 'scale' sysfs attribute. Signed-off-by: Matthias Kaehlcke Tested-by: Enric Balletbo i Serra Acked-by: Daniel Thompson --- Changes in v2: - added Enric's 'Tested-by' tag - added Daniel's 'Acked-by' tag --- drivers/video/backlight/pwm_bl.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c index fb45f866b923..f067fe7aa35d 100644 --- a/drivers/video/backlight/pwm_bl.c +++ b/drivers/video/backlight/pwm_bl.c @@ -553,6 +553,8 @@ static int pwm_backlight_probe(struct platform_device *pdev) goto err_alloc; } + memset(&props, 0, sizeof(struct backlight_properties)); + if (data->levels) { /* * For the DT case, only when brightness levels is defined @@ -591,6 +593,8 @@ static int pwm_backlight_probe(struct platform_device *pdev) pb->levels = data->levels; } + + props.scale = BACKLIGHT_SCALE_CIE1931; } else { /* * That only happens for the non-DT case, where platform data @@ -601,7 +605,6 @@ static int pwm_backlight_probe(struct platform_device *pdev) pb->lth_brightness = data->lth_brightness * (state.period / pb->scale); - memset(&props, 0, sizeof(struct backlight_properties)); props.type = BACKLIGHT_RAW; props.max_brightness = data->max_brightness; bl = backlight_device_register(dev_name(&pdev->dev), &pdev->dev, pb, From patchwork Mon Jun 24 20:31:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Kaehlcke X-Patchwork-Id: 11014081 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4837014BB for ; Mon, 24 Jun 2019 20:31:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3894F28B90 for ; Mon, 24 Jun 2019 20:31:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2C8FA28BBE; Mon, 24 Jun 2019 20:31:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CDA7128B90 for ; Mon, 24 Jun 2019 20:31:31 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5411689DC7; Mon, 24 Jun 2019 20:31:29 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by gabe.freedesktop.org (Postfix) with ESMTPS id 76C5F89DC2 for ; Mon, 24 Jun 2019 20:31:26 +0000 (UTC) Received: by mail-pl1-x641.google.com with SMTP id bi6so7534206plb.12 for ; Mon, 24 Jun 2019 13:31:26 -0700 (PDT) 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=uZKHvCx8L/nRTrUb/ohywx0d3IXX3vcHyiOoGdIF2Vg=; b=NUDgWWxxf4nvayWGVWhtq8ePv6VQ2RCC/FtdllCYiuFJfe0yVRB+8Evc3LfIoOyans VCHVGIsfffBLVCU9xKySMtWlA1I7huAcglFRFnTXJvq1PZ8T1aL8tib2HD4EjBfpTJ1+ 1AuHxRgvweEhjTW9IUd4OnKr4Mrg6FJ/fE/ZDty9caQ5sh/yULjGn5yCzqzfG7hV9qvW kxwGhqDALRCJP1SoGMA5iYdJJJ+PoOXzSIfJGmrT6dAToNhkPgtAROPN6x1R1KA1uAEH O3ytSR6EQux3BbiC/efaUb1916XHXhL8MygAY7ZOxddnXa9KKzbyhv7gPt4ByA/xDzti VmSw== X-Gm-Message-State: APjAAAXNal2q5vPF5KfIj0UahyqXOq8CbGAMYdo/1VaGWNiA0CKC/ei8 dnAid6kAIXsfCwatKxRXP+qDVQ== X-Google-Smtp-Source: APXvYqzY0+srP89wCVDbPca+cx8EHxAJHQuHwUe5lX3IaE2YnttbyJ+9Ii8mxU7OnlFea1FBJZ1y0Q== X-Received: by 2002:a17:902:2006:: with SMTP id n6mr94261265pla.232.1561408286127; Mon, 24 Jun 2019 13:31:26 -0700 (PDT) Received: from localhost ([2620:15c:202:1:75a:3f6e:21d:9374]) by smtp.gmail.com with ESMTPSA id r2sm21887470pfl.67.2019.06.24.13.31.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Jun 2019 13:31:25 -0700 (PDT) From: Matthias Kaehlcke To: Thierry Reding , Lee Jones , Daniel Thompson , Jingoo Han , Bartlomiej Zolnierkiewicz Subject: [PATCH v2 4/4] backlight: pwm_bl: Set scale type for brightness curves specified in the DT Date: Mon, 24 Jun 2019 13:31:13 -0700 Message-Id: <20190624203114.93277-5-mka@chromium.org> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog In-Reply-To: <20190624203114.93277-1-mka@chromium.org> References: <20190624203114.93277-1-mka@chromium.org> MIME-Version: 1.0 X-Mailman-Original-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=uZKHvCx8L/nRTrUb/ohywx0d3IXX3vcHyiOoGdIF2Vg=; b=G/bUhQslRBb9yDeN/Ju1v2H78Jn3pcV6lvi6ZsyGVCuBbzJ+oIhAcvU04QfS10U/4R pdE3J6hWbwxyP4QcHwwtH00UNcd1LgYEz2XOvY5wmOr4tiTSrA/9uD0OATvj9bqrmoPn id+vaY8rgFoQ9n7vUdhFL4XPoNNii/WHKNs9A= X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-pwm@vger.kernel.org, linux-fbdev@vger.kernel.org, Brian Norris , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Douglas Anderson , Matthias Kaehlcke , Jacek Anaszewski , Pavel Machek , Enric Balletbo i Serra Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 Acked-by: Daniel Thompson --- Changes in v2: - use 128 (power of two) instead of 100 as factor for the slope - add comment about max quantization error - added Daniel's 'Acked-by' tag --- drivers/video/backlight/pwm_bl.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c index f067fe7aa35d..2297fb4af49d 100644 --- a/drivers/video/backlight/pwm_bl.c +++ b/drivers/video/backlight/pwm_bl.c @@ -404,6 +404,31 @@ 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]; + /* + * Multiplying by 128 means that even in pathological cases such + * as (max_val - min_val) == nlevels the error at max_val is less + * than 1%. + */ + unsigned int slope = (128 * (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) / 128); + 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 +592,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