From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 67A56C433E1 for ; Sun, 23 Aug 2020 10:46:00 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3C5482072D for ; Sun, 23 Aug 2020 10:46:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Rru0BjCK" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3C5482072D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ravnborg.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 63D8B6E49C; Sun, 23 Aug 2020 10:45:59 +0000 (UTC) Received: from mail-lj1-x244.google.com (mail-lj1-x244.google.com [IPv6:2a00:1450:4864:20::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0DF1E6E497 for ; Sun, 23 Aug 2020 10:45:58 +0000 (UTC) Received: by mail-lj1-x244.google.com with SMTP id w14so6447200ljj.4 for ; Sun, 23 Aug 2020 03:45:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oazd1K/DiFoxSE0eXUpKTqDSP+znXZoQQbXi3awQMDA=; b=Rru0BjCKHKyWpAHFO2f/f2Pd8xnvFEa2pwInIvBs9THJk8ZX4NzC104gwiP0oHpv/R quBGebfbUApEevsHXGdCL1kcsLcIfTl2auvbDOoJktPxDOdVseUyvOPI67+EpDDZIGGS YgBgfcZCdVwNJ9kBOq4rLF2c+gg98kR9pNcdMUsU7DHD2DYhAchG2S2jAyq1ipnbZGZR 5Qbpa9SHubjKdFa9Hqm1mn6NuSW4b7AGDiac5GMy1pL8IXAS0kYXeD7GGHL/wnJW/Kk+ pisW8GDWgDGZXpVaDx1FY6YKE401bKX/UxmmF7xR00is6XfsuG8QmTtOVIenWKfR21rd eUdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=oazd1K/DiFoxSE0eXUpKTqDSP+znXZoQQbXi3awQMDA=; b=iq+Dh7sA1Av3JpTkplSvUak2RlffoP4N1h7SAEuvk19+Umrm3shwJYuPrhrhdGAtxZ nEHnNgGrPYS+U/QbBIFMhUKQGXlgYaj1n0Q4iszmpltIIUq6ux//8i7Lph6UTYrz1k6d PKtD6GdCGQSD97uVjR+6g82b7Z0mTgfJqSunnJiSzvSrbSkqfLAd9jZ9J3U9R3/aEYKf oD60yTVSppi179k2+EKVo/Z7QdB14tw2BxSZu4mFWJ4JdnwTyjQ1gTTFtr0pfoKtRFDA UQL+GHEDC5f5vPn9BIiR64ydPiuP8XC9goAUxgIhM3BGtINEUZGGGqRm/LlFJ4Y08rex yboA== X-Gm-Message-State: AOAM531cdKjXiJt+0QMJJxhMYb8eKveMrDuYgGKda/aWuZAFkOmpSgPv xufYgw/vDrkTSJE4j7NU3/+DMYOm7+jS9A== X-Google-Smtp-Source: ABdhPJy4J6Y/eBN3OPr+gS/QAr0i8CDOuTHuWFLiwFDo3T218w/+gtXEzS/5FVieK9P2PqM2jYpD5A== X-Received: by 2002:a2e:9bc1:: with SMTP id w1mr396509ljj.79.1598179556272; Sun, 23 Aug 2020 03:45:56 -0700 (PDT) Received: from saturn.localdomain ([2a00:fd00:805f:db00:2509:20d7:e461:9c16]) by smtp.gmail.com with ESMTPSA id h13sm1516301lji.134.2020.08.23.03.45.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Aug 2020 03:45:55 -0700 (PDT) From: Sam Ravnborg To: dri-devel@lists.freedesktop.org, Jingoo Han , Lee Jones , Daniel Thompson Subject: [PATCH v2 03/24] backlight: Add get/set operations for brightness properties Date: Sun, 23 Aug 2020 12:45:11 +0200 Message-Id: <20200823104532.1024798-4-sam@ravnborg.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200823104532.1024798-1-sam@ravnborg.org> References: <20200823104532.1024798-1-sam@ravnborg.org> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Vetter , Sam Ravnborg Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Add get and set operations to incapsualte access to backlight brightness. One easy win is that the get/set operations can be used when backlight is not included in the configuration, resulting in simpler code with less ifdef's and thus more readable code. The backlight_enable_brightness() update the brightness and enable the backlight. The backlight_update_brightness() force the brightness update and typical usage is to set brightness after registering a backlight device. Signed-off-by: Sam Ravnborg Cc: Lee Jones Cc: Daniel Thompson Cc: Jingoo Han --- include/linux/backlight.h | 74 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/include/linux/backlight.h b/include/linux/backlight.h index 93a47a6cf681..e390444bed13 100644 --- a/include/linux/backlight.h +++ b/include/linux/backlight.h @@ -492,6 +492,80 @@ static inline int backlight_get_brightness(const struct backlight_device *bd) return bd->props.brightness; } +/** + * backlight_get_actual_brightness - Returns the actual brightness + * + * On failure a negative error code is returned. + */ +static inline int backlight_get_actual_brightness(struct backlight_device *bd) +{ + if (bd && bd->ops && bd->ops->get_brightness) + return bd->ops->get_brightness(bd); + else + return -EINVAL; +} + +/** + * backlight_get_max_brightness - Returns maximum brightness + * + * This helper operation is preferred over direct access to + * &backlight_properties.max_brightness + * + * Returns 0 if backlight_device is NULL + */ + +static inline int backlight_get_max_brightness(const struct backlight_device *bd) +{ + if (bd) + return bd->props.max_brightness; + else + return 0; +} + +/** + * backlight_set_brightness - Set the brightness to the specified value + * + * This helper operation is preferred over direct assignment to + * &backlight_properties.brightness. + * + * If backlight_device is NULL then silently exit. + */ +static inline void backlight_set_brightness(struct backlight_device *bd, int brightness) +{ + if (bd) + bd->props.brightness = brightness; +} + +/** + * backlight_update_brightness - Update the brightness to the specified value + * + * Update brightness and force an update. + * + * If backlight_device is NULL then silently exit. + */ +static inline void backlight_update_brightness(struct backlight_device *bd, int brightness) +{ + if (bd) { + bd->props.brightness = brightness; + backlight_update_status(bd); + } +} + +/** + * backlight_enable_brightness - Enable backligt using specified brightness + * + * Enable brightness using the specified brightness. + * + * If backlight_device is NULL then silently exit. + */ +static inline void backlight_enable_brightness(struct backlight_device *bd, int brightness) +{ + if (bd) { + bd->props.brightness = brightness; + backlight_enable(bd); + } +} + struct backlight_device * backlight_device_register(const char *name, struct device *dev, void *devdata, const struct backlight_ops *ops, -- 2.25.1 _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel