dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Mario Limonciello (AMD)" <superm1@kernel.org>
To: dri-devel@lists.freedesktop.org
Cc: Mario Limonciello <mario.limonciello@amd.com>,
	harry.wentland@amd.com, Louis Chauvet <louis.chauvet@bootlin.com>,
	Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>,
	"Mario Limonciello (AMD)" <superm1@kernel.org>,
	David Herrmann <dh.herrmann@gmail.com>,
	Marta Lofstedt <marta.lofstedt@intel.com>
Subject: [PATCH v4 2/9] backlight: add kernel-internal backlight API
Date: Thu, 28 May 2026 00:49:04 -0500	[thread overview]
Message-ID: <20260528054911.1513208-3-superm1@kernel.org> (raw)
In-Reply-To: <20260528054911.1513208-1-superm1@kernel.org>

So far backlights have only been controlled via sysfs. However, sysfs is
not a proper user-space API for runtime modifications, and never was
intended to provide such. The DRM drivers are now prepared to provide
such a backlight link so user-space can control backlight via DRM
connector properties. This allows us to employ the same access-management
we use for mode-setting.

This patch adds few kernel-internal backlight helpers so we can modify
backlights from within DRM.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>

V2: Marta Lofstedt <marta.lofstedt@intel.com>
- rebase
- minor edit for checkpatch warning

Signed-off-by: Marta Lofstedt <marta.lofstedt@intel.com>

V3: Mario Limonciello (AMD) <superm1@kernel.org>
 - rebase
 - Use guard(mutex)

V4: Mario Limonciello (AMD) <superm1@kernel.org>
 - Adjust return type for backlight_set_brightness() to return errors
 - Stop clamping in backlight_set_brightness()
 - Drop backlight_device_lookup()

Signed-off-by: Mario Limonciello (AMD) <superm1@kernel.org>
---
 drivers/video/backlight/backlight.c | 33 +++++++++++++++++++++++++++++
 include/linux/backlight.h           | 15 +++++++++++++
 2 files changed, 48 insertions(+)

diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c
index ff2c2084c73a..661243afc877 100644
--- a/drivers/video/backlight/backlight.c
+++ b/drivers/video/backlight/backlight.c
@@ -514,6 +514,39 @@ static int devm_backlight_device_match(struct device *dev, void *res,
 	return *r == data;
 }
 
+/**
+ * backlight_set_brightness - set brightness on a backlight device
+ * @bd: backlight device to operate on
+ * @value: brightness value to set on the device
+ * @reason: backlight-change reason to use for notifications
+ *
+ * This is the in-kernel API equivalent of writing into the 'brightness' sysfs
+ * file. It calls into the underlying backlight driver to change the brightness
+ * value.
+ * A uevent notification is sent with the reason set to @reason.
+ * Return: 0 if successfully notified, -EINVAL for invalid values
+ */
+int backlight_set_brightness(struct backlight_device *bd, unsigned int value,
+			      enum backlight_update_reason reason)
+{
+	int rc = 0;
+
+	guard(mutex)(&bd->ops_lock);
+	if (bd->ops) {
+		if (value > bd->props.max_brightness)
+			return -EINVAL;
+
+		dev_dbg(&bd->dev, "set brightness to %u\n", value);
+		bd->props.brightness = value;
+		rc = backlight_update_status(bd);
+	}
+	if (rc == 0)
+		backlight_generate_event(bd, reason);
+
+	return rc;
+}
+EXPORT_SYMBOL_GPL(backlight_set_brightness);
+
 /**
  * backlight_register_notifier - get notified of backlight (un)registration
  * @nb: notifier block with the notifier to call on backlight (un)registration
diff --git a/include/linux/backlight.h b/include/linux/backlight.h
index d905173c7f73..204eea9256fd 100644
--- a/include/linux/backlight.h
+++ b/include/linux/backlight.h
@@ -429,6 +429,21 @@ static inline void backlight_notify_blank_all(struct device *display_dev,
 { }
 #endif
 
+int backlight_set_brightness(struct backlight_device *bd, unsigned int value,
+			      enum backlight_update_reason reason);
+
+static inline void backlight_device_ref(struct backlight_device *bd)
+{
+	if (bd)
+		get_device(&bd->dev);
+}
+
+static inline void backlight_device_unref(struct backlight_device *bd)
+{
+	if (bd)
+		put_device(&bd->dev);
+}
+
 #define to_backlight_device(obj) container_of(obj, struct backlight_device, dev)
 
 /**
-- 
2.54.0


  parent reply	other threads:[~2026-05-28  5:50 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-28  5:49 [PATCH v4 0/9] Add support for a DRM backlight capability Mario Limonciello (AMD)
2026-05-28  5:49 ` [PATCH v4 1/9] Revert "backlight: Remove notifier" Mario Limonciello (AMD)
2026-05-28  5:49 ` Mario Limonciello (AMD) [this message]
2026-05-28  5:49 ` [PATCH v4 3/9] drm: link connectors to backlight devices Mario Limonciello (AMD)
2026-05-29  9:56   ` Dmitry Baryshkov
2026-05-29  9:58     ` Mario Limonciello
2026-05-28  5:49 ` [PATCH v4 4/9] DRM: Add support for client and driver indicating support for luminance Mario Limonciello (AMD)
2026-05-29  9:53   ` Dmitry Baryshkov
2026-05-28  5:49 ` [PATCH v4 5/9] drm/amd/display: Pass up errors reading actual brightness Mario Limonciello (AMD)
2026-05-28  5:49 ` [PATCH v4 6/9] drm/amd: Indicate driver supports luminance Mario Limonciello (AMD)
2026-05-28  5:49 ` [PATCH v4 7/9] drm/amd/display: Allow backlight registration to fail Mario Limonciello (AMD)
2026-05-28  5:49 ` [PATCH v4 8/9] drm/amd/display: use drm backlight Mario Limonciello (AMD)
2026-05-28  5:49 ` [PATCH v4 9/9] drm/bridge: auto-link panel backlight in bridge connector Mario Limonciello (AMD)
2026-05-29  9:52   ` Dmitry Baryshkov
2026-05-29 15:13 ` [PATCH v4 0/9] Add support for a DRM backlight capability Simon Ser

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260528054911.1513208-3-superm1@kernel.org \
    --to=superm1@kernel.org \
    --cc=dh.herrmann@gmail.com \
    --cc=dmitry.baryshkov@oss.qualcomm.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=harry.wentland@amd.com \
    --cc=louis.chauvet@bootlin.com \
    --cc=mario.limonciello@amd.com \
    --cc=marta.lofstedt@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox