Skip to contentSkip to conversation

Add support for a DRM backlight capability

PATCH Superseded Mario Limonciello 5 participants 26 messages Apr 24 – May 25

Subsystems (6)

v3 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v3 cover Add support for a DRM backlight capability

From: Mario Limonciello (AMD) <[email protected]>

At Display Next Hackfest 2025 we discussed the renewed need for moving brightness control into the DRM connector properties. I've taken the previous efforts from David and Marta, rebased and adjusted for the current kernel.

The legacy sysfs interface is synchronized with the DRM connector (although the scale may be different as DRM connector property is u16).

Later after this has been adopted by enough userspace, it may make sense to configure the legacy sysfs interface to be configurable so that only DRM master controls backlight.

I've done a first implementation with amdgpu with eDP connectors; but conceivably this can be extended to other connectors like DP for displays that can be controlled via DDC as well later.

I have also used DRM review prompts to review this series and fix some bugs which were caught with two different Claude models. The fixes are squashed into the patches.

Assisted-by Claude Opus
Assisted-by Claude Sonnet

For ease of testing; this series is also available on this branch:
https://git.kernel.org/pub/scm/linux/kernel/git/superm1/linux.git/log/?h=superm1/backlight-property-v3

David Rheinsberg (1):
backlight: add kernel-internal backlight API

Mario Limonciello (6):
drm: link connectors to backlight devices
DRM: Add support for client and driver indicating support for
luminance
drm/amd/display: Pass up errors reading actual brightness drm/amd: Indicate driver supports luminance drm/amd/display: Allow backlight registration to fail drm/amd/display: use drm backlight

Marta Lofstedt (1):
backlight: expose the current brightness in the new kernel API

 drivers/gpu/drm/Kconfig                       |   1 +
 drivers/gpu/drm/Makefile                      |   2 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c       |   1 +
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c |  88 +++-
 drivers/gpu/drm/drm_atomic_uapi.c             |  24 ++
 drivers/gpu/drm/drm_backlight.c               | 406 ++++++++++++++++++
 drivers/gpu/drm/drm_connector.c               |  12 +
 drivers/gpu/drm/drm_drv.c                     |   8 +
 drivers/gpu/drm/drm_ioctl.c                   |  10 +
 drivers/gpu/drm/drm_mode_config.c             |   7 +
 drivers/gpu/drm/drm_mode_object.c             |  66 ++-
 drivers/gpu/drm/drm_sysfs.c                   |  54 +++
 drivers/video/backlight/backlight.c           |  83 ++++
 include/drm/drm_backlight.h                   |  45 ++
 include/drm/drm_connector.h                   |   8 +
 include/drm/drm_drv.h                         |   7 +
 include/drm/drm_file.h                        |   8 +
 include/drm/drm_mode_config.h                 |   5 +
 include/linux/backlight.h                     |  30 ++
 include/uapi/drm/drm.h                        |  10 +
 20 files changed, 852 insertions(+), 23 deletions(-)
 create mode 100644 drivers/gpu/drm/drm_backlight.c
 create mode 100644 include/drm/drm_backlight.h
Signature · 1 line
2.53.0
#1 lore raw

PATCH v3 1/8 backlight: add kernel-internal backlight API

From: David Herrmann <[email protected]>

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.

V2: Marta Lofstedt <[email protected]>
- rebase
- minor edit for checkpatch warning

V3: Mario Limonciello <[email protected]>
- rebase
- Use guard(mutex)

---
 drivers/video/backlight/backlight.c | 60 +++++++++++++++++++++++++++++
 include/linux/backlight.h           | 16 ++++++++
 2 files changed, 76 insertions(+)
drivers/video/backlight/backlight.c +60 -0
index ab87a5e3dbf70..c3673bee6d9cf 100644
@@ -513,6 +513,66 @@ static int devm_backlight_device_match(struct device *dev, void *res,
 	return *r == data;
 }
 
+/**
+ * backlight_device_lookup - find a backlight device
+ * @name: sysname of the backlight device
+ *
+ * @return Reference to the backlight device, NULL if not found.
+ *
+ * This searches through all registered backlight devices for a device with the
+ * given device name. In case none is found, NULL is returned, otherwise a
+ * new reference to the backlight device is returned. You must drop this
+ * reference via backlight_device_unref() once done.
+ * Note that the devices might get unregistered at any time. You need to lock
+ * around this lookup and inside of your backlight-notifier if you need to know
+ * when a device gets unregistered.
+ *
+ * This function can be safely called from IRQ context.
+ */
+struct backlight_device *backlight_device_lookup(const char *name)
+{
+	struct backlight_device *bd;
+	const char *t;
+
+	guard(mutex)(&backlight_dev_list_mutex);
+	list_for_each_entry(bd, &backlight_dev_list, entry) {
+		t = dev_name(&bd->dev);
+		if (t && !strcmp(t, name)) {
+			backlight_device_ref(bd);
+			return bd;
+		}
+	}
+
+	return NULL;
+}
+EXPORT_SYMBOL_GPL(backlight_device_lookup);
+
+/**
+ * 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. The value is clamped according to device bounds.
+ * A uevent notification is sent with the reason set to @reason.
+ */
+void backlight_set_brightness(struct backlight_device *bd, unsigned int value,
+			      enum backlight_update_reason reason)
+{
+	guard(mutex)(&bd->ops_lock);
+	if (bd->ops) {
+		value = clamp(value, 0U,
+			      (unsigned int)bd->props.max_brightness);
+		dev_dbg(&bd->dev, "set brightness to %u\n", value);
+		bd->props.brightness = value;
+		backlight_update_status(bd);
+	}
+	backlight_generate_event(bd, reason);
+}
+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
include/linux/backlight.h +16 -0
index d905173c7f73c..7e4fee65fddd9 100644
@@ -429,6 +429,22 @@ static inline void backlight_notify_blank_all(struct device *display_dev,
 { }
 #endif
 
+struct backlight_device *backlight_device_lookup(const char *name);
+void 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)
 
 /**
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH v3 1/8] backlight: add kernel-internal backlight API

Quoted 62 lines · Mario Limonciello

From: David Herrmann <[email protected]>

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.

V2: Marta Lofstedt <[email protected]>
- rebase
- minor edit for checkpatch warning

V3: Mario Limonciello <[email protected]>
- rebase
- Use guard(mutex)

---
  drivers/video/backlight/backlight.c | 60 +++++++++++++++++++++++++++++
  include/linux/backlight.h           | 16 ++++++++
  2 files changed, 76 insertions(+)
drivers/video/backlight/backlight.c +24 -0
index ab87a5e3dbf70..c3673bee6d9cf 100644
@@ -513,6 +513,66 @@ static int devm_backlight_device_match(struct device *dev, void *res,
  	return *r == data;
  }
 
+/**
+ * backlight_device_lookup - find a backlight device
+ * @name: sysname of the backlight device
+ *
+ * @return Reference to the backlight device, NULL if not found.
+ *
+ * This searches through all registered backlight devices for a device with the
+ * given device name. In case none is found, NULL is returned, otherwise a
+ * new reference to the backlight device is returned. You must drop this
+ * reference via backlight_device_unref() once done.
+ * Note that the devices might get unregistered at any time. You need to lock
+ * around this lookup and inside of your backlight-notifier if you need to know
+ * when a device gets unregistered.
+ *
+ * This function can be safely called from IRQ context.
+ */
+struct backlight_device *backlight_device_lookup(const char *name)
+{
+	struct backlight_device *bd;
+	const char *t;
+
+	guard(mutex)(&backlight_dev_list_mutex);
+	list_for_each_entry(bd, &backlight_dev_list, entry) {
+		t = dev_name(&bd->dev);

drivers/video/backlight/backlight.c static int devm_backlight_device_match(struct device *dev, void *res, · line 549

Quoted 10 lines
drivers/video/backlight/backlight.c +9 -0
+		if (t && !strcmp(t, name)) {
+			backlight_device_ref(bd);
+			return bd;
+		}
+	}
+
+	return NULL;
+}
+EXPORT_SYMBOL_GPL(backlight_device_lookup);
 

Hello,

I think this function can be repalced with backlight_device_get_by_name.

Quoted 8 lines
drivers/video/backlight/backlight.c +8 -0
+/**
+ * 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

drivers/video/backlight/backlight.c static int devm_backlight_device_match(struct device *dev, void *res, · line 567

Quoted 10 lines
drivers/video/backlight/backlight.c +10 -0
+ * value. The value is clamped according to device bounds.
+ * A uevent notification is sent with the reason set to @reason.
+ */
+void backlight_set_brightness(struct backlight_device *bd, unsigned int value,
+			      enum backlight_update_reason reason)
+{
+	guard(mutex)(&bd->ops_lock);
+	if (bd->ops) {
+		value = clamp(value, 0U,
+			      (unsigned int)bd->props.max_brightness);

Why did you use a clamping here? I think it is better to return error instead.

drivers/video/backlight/backlight.c static int devm_backlight_device_match(struct device *dev, void *res,

Quoted 8 lines
drivers/video/backlight/backlight.c +7 -0
+		dev_dbg(&bd->dev, "set brightness to %u\n", value);
+		bd->props.brightness = value;
+		backlight_update_status(bd);
+	}
+	backlight_generate_event(bd, reason);
+}
+EXPORT_SYMBOL_GPL(backlight_set_brightness);
 

I think this could be nice to update backlight_device_set_brightness to avoid code duplication:

int backlight_device_set_brightness(...) {
	return backlight_set_brightness(..., BACKLIGHT_UPDATE_SYSFS);
}
Quoted 17 lines
drivers/video/backlight/backlight.c +0 -0
  /**
   * backlight_register_notifier - get notified of backlight (un)registration
   * @nb: notifier block with the notifier to call on backlight (un)registration
include/linux/backlight.h +6 -0
index d905173c7f73c..7e4fee65fddd9 100644
@@ -429,6 +429,22 @@ static inline void backlight_notify_blank_all(struct device *display_dev,
  { }
  #endif
 
+struct backlight_device *backlight_device_lookup(const char *name);
+void 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)
+{

include/linux/backlight.h static inline void backlight_notify_blank_all(struct device *display_dev, · line 447

Quoted 10 lines
include/linux/backlight.h +10 -0
+	if (bd)
+		get_device(&bd->dev);
+}
+
+static inline void backlight_device_unref(struct backlight_device *bd)
+{
+	if (bd)
+		put_device(&bd->dev);
+}
+

Most of the kernel use _put and _get functions, I think it could be nice to keep the same naming.

Thanks,
Louis Chauvet

Quoted 3 lines
include/linux/backlight.h +0 -0
  #define to_backlight_device(obj) container_of(obj, struct backlight_device, dev)
 
  /**
#3 lore raw

Re: [PATCH v3 1/8] backlight: add kernel-internal backlight API

Quoted 83 lines · Louis Chauvet

[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

Quoted 67 lines · Mario Limonciello

From: David Herrmann <[email protected]>

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.

V2: Marta Lofstedt <[email protected]>
- rebase
- minor edit for checkpatch warning

V3: Mario Limonciello <[email protected]>
  - rebase
  - Use guard(mutex)

---
  drivers/video/backlight/backlight.c | 60 +++++++++++++++++++++++++++++ include/linux/backlight.h           | 16 ++++++++

  2 files changed, 76 insertions(+)
drivers/video/backlight/backlight.c +7 -0
index ab87a5e3dbf70..c3673bee6d9cf 100644
@@ -513,6 +513,66 @@ static int devm_backlight_device_match(struct 
 device *dev, void *res,
       return *r == data;
   }
 
+/**
+ * backlight_device_lookup - find a backlight device
+ * @name: sysname of the backlight device
+ *
+ * @return Reference to the backlight device, NULL if not found.
+ *
+ * This searches through all registered backlight devices for a 

device with the
+ * given device name. In case none is found, NULL is returned, otherwise a
+ * new reference to the backlight device is returned. You must drop this
+ * reference via backlight_device_unref() once done.
+ * Note that the devices might get unregistered at any time. You need to lock
+ * around this lookup and inside of your backlight-notifier if you need to know
+ * when a device gets unregistered.
+ *
+ * This function can be safely called from IRQ context.
+ */

drivers/video/backlight/backlight.c +7 -0
+struct backlight_device *backlight_device_lookup(const char *name)
+{
+     struct backlight_device *bd;
+     const char *t;
+
+     guard(mutex)(&backlight_dev_list_mutex);
+     list_for_each_entry(bd, &backlight_dev_list, entry) {

drivers/video/backlight/backlight.c static int devm_backlight_device_match(struct device *dev, void *res, · line 548

Quoted 10 lines
drivers/video/backlight/backlight.c +10 -0
+             t = dev_name(&bd->dev);
+             if (t && !strcmp(t, name)) {
+                     backlight_device_ref(bd);
+                     return bd;
+             }
+     }
+
+     return NULL;
+}
+EXPORT_SYMBOL_GPL(backlight_device_lookup);

Hello,

Quoted 1 line

I think this function can be repalced with backlight_device_get_by_name.

Yes; good call.

Quoted 17 lines
Quoted 17 lines

+/**
+ * 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. The value is clamped according to device bounds.
+ * A uevent notification is sent with the reason set to @reason.
+ */
+void backlight_set_brightness(struct backlight_device *bd, unsigned int value,
+                           enum backlight_update_reason reason)

Quoted 9 lines
Quoted 5 lines

+{
+     guard(mutex)(&bd->ops_lock);
+     if (bd->ops) {
+             value = clamp(value, 0U,
+                           (unsigned int)bd->props.max_brightness);

Why did you use a clamping here? I think it is better to return error instead.

This is called from a work queue. This is the call path:

__drm_backlight_worker().
-> __drm_backlight_schedule()
->-> __drm_backlight_prop_changed()
->->-> drm_backlight_set_luminance().

So - I suppose that actually what you are suggesting is to plumb an error all the way from the work queue up to all the callers. That might for a change to make things synchronous that weren't 'intended' to be synchronous.

Maybe a better solution is to try to look at the max brightness 'directly' in drm_backlight_set_luminance() and then reject it before going down the work queue path.

Thoughts?

Quoted 12 lines

drivers/video/backlight/backlight.c

Quoted 8 lines

+             dev_dbg(&bd->dev, "set brightness to %u\n", value); +             bd->props.brightness = value;
+             backlight_update_status(bd);
+     }
+     backlight_generate_event(bd, reason);

drivers/video/backlight/backlight.c +2 -0
+}
+EXPORT_SYMBOL_GPL(backlight_set_brightness);

I think this could be nice to update backlight_device_set_brightness to avoid code duplication:

Quoted 3 lines

int backlight_device_set_brightness(...) {
       return backlight_set_brightness(..., BACKLIGHT_UPDATE_SYSFS);
}

OK.

Quoted 24 lines
Quoted 24 lines

  /**
   * backlight_register_notifier - get notified of backlight (un)registration
   * @nb: notifier block with the notifier to call on backlight (un)registration

include/linux/backlight.h +10 -0
index d905173c7f73c..7e4fee65fddd9 100644
@@ -429,6 +429,22 @@ static inline void 
 backlight_notify_blank_all(struct device *display_dev,
   { }
   #endif
 
+struct backlight_device *backlight_device_lookup(const char *name);
+void 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);
+}
+
Quoted 8 lines

include/linux/backlight.h static inline void backlight_notify_blank_all(struct device *display_dev, · line 447

Quoted 6 lines
include/linux/backlight.h +6 -0
+static inline void backlight_device_unref(struct backlight_device *bd)
+{
+     if (bd)
+             put_device(&bd->dev);
+}
+

Most of the kernel use _put and _get functions, I think it could be nice to keep the same naming.

OK.

#4 lore raw

Re: [PATCH v3 1/8] backlight: add kernel-internal backlight API

Quoted 118 lines · Mario Limonciello
Quoted 84 lines · Louis Chauvet

[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

Quoted 68 lines · Mario Limonciello

From: David Herrmann <[email protected]>

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.

V2: Marta Lofstedt <[email protected]>
- rebase
- minor edit for checkpatch warning

V3: Mario Limonciello <[email protected]>
  - rebase
  - Use guard(mutex)

---
  drivers/video/backlight/backlight.c | 60 +++++++++++++++++++++++++++++ include/linux/backlight.h           | 16 ++++++++

  2 files changed, 76 insertions(+)
drivers/video/backlight/backlight.c +7 -0
index ab87a5e3dbf70..c3673bee6d9cf 100644
@@ -513,6 +513,66 @@ static int devm_backlight_device_match(struct 
 device *dev, void *res,
       return *r == data;
   }
 
+/**
+ * backlight_device_lookup - find a backlight device
+ * @name: sysname of the backlight device
+ *
+ * @return Reference to the backlight device, NULL if not found.
+ *
+ * This searches through all registered backlight devices for a 

device with the
+ * given device name. In case none is found, NULL is returned, otherwise a
+ * new reference to the backlight device is returned. You must drop this
+ * reference via backlight_device_unref() once done.
+ * Note that the devices might get unregistered at any time. You need to lock
+ * around this lookup and inside of your backlight-notifier if you need to know
+ * when a device gets unregistered.
+ *
+ * This function can be safely called from IRQ context.
+ */

drivers/video/backlight/backlight.c +7 -0
+struct backlight_device *backlight_device_lookup(const char *name)
+{
+     struct backlight_device *bd;
+     const char *t;
+
+     guard(mutex)(&backlight_dev_list_mutex);
+     list_for_each_entry(bd, &backlight_dev_list, entry) {

drivers/video/backlight/backlight.c static int devm_backlight_device_match(struct device *dev, void *res, · line 548

Quoted 10 lines
drivers/video/backlight/backlight.c +10 -0
+             t = dev_name(&bd->dev);
+             if (t && !strcmp(t, name)) {
+                     backlight_device_ref(bd);
+                     return bd;
+             }
+     }
+
+     return NULL;
+}
+EXPORT_SYMBOL_GPL(backlight_device_lookup);

Hello,

Quoted 1 line

I think this function can be repalced with backlight_device_get_by_name.

Yes; good call.

Quoted 17 lines
Quoted 17 lines

+/**
+ * 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. The value is clamped according to device bounds.
+ * A uevent notification is sent with the reason set to @reason.
+ */
+void backlight_set_brightness(struct backlight_device *bd, unsigned int value,
+                           enum backlight_update_reason reason)

Quoted 9 lines
Quoted 5 lines

+{
+     guard(mutex)(&bd->ops_lock);
+     if (bd->ops) {
+             value = clamp(value, 0U,
+                           (unsigned int)bd->props.max_brightness);

Why did you use a clamping here? I think it is better to return error instead.

Quoted 8 lines

This is called from a work queue.  This is the call path:

__drm_backlight_worker().
-> __drm_backlight_schedule()
->-> __drm_backlight_prop_changed()
->->-> drm_backlight_set_luminance().

So - I suppose that actually what you are suggesting is to plumb an error all the way from the work queue up to all the callers.  That might for a change to make things synchronous that weren't 'intended' to be synchronous.

You are right, this is not a good idea to make this synchronous.

After looking a bit more at the code, I think you can simply not clamp at all and use a warn. In all cases:
- drm should never ask for a value outside 0..U16_MAX
- the conversion from 0..U16_MAX to 0..bd->props.max_brightness should never be bigger than bd->props.max_brightness

So if you have to clamp, it means there is a bug somewhere in the process.

I imagine something like:

b_set_brightness(value)

	if value > max:
		return -EINVAL
	[...]

__drm_backlight_worker()

	r = b_set_brightness(new_value)
	if r == -EINVAL: # This should never be the case, new_value should be 

clamped to 0..max_value before
WARN("Invalid backlight value requested")
# maybe add a fallback to at least have a coherent on/off state and
avoid complete black screens

		if new_value==0: b_set_brightness(0)
		else: b_set_brightness(max_value)

__drm_backlight_prop_changed(u16 requested_value)
new_value = requested_value * max_value / U16_MAX schedule_work(new_value)

Quoted 3 lines

Maybe a better solution is to try to look at the max brightness 'directly' in drm_backlight_set_luminance() and then reject it before going down the work queue path.

Thoughts?

That also a solution, but I think it is better to have a clear interface for drm_backlight_set_luminance and the backlight property: drm_backlight_set_luminance must get a 0..U16_MAX value, any other value is invalid.

But I have a question for this: is the scale of luminance linear or not? I think this information should be given to userspace. And if lunimance is not linear, I don't think you can easily scale between 0..U16MAX to 0..max_value.

Same thing for backlight=0, IIRC sometimes the backlight driver switch off the light, sometimes it is just the minimum luminosity.

I think that can be a topic for discussion at drm hackfest, but it may also require more precise information / specification from the backlight subsystem / to the userspace interface.

Quoted 12 lines
Quoted 12 lines

drivers/video/backlight/backlight.c

Quoted 8 lines

+             dev_dbg(&bd->dev, "set brightness to %u\n", value); +             bd->props.brightness = value;
+             backlight_update_status(bd);
+     }
+     backlight_generate_event(bd, reason);

drivers/video/backlight/backlight.c +2 -0
+}
+EXPORT_SYMBOL_GPL(backlight_set_brightness);

I think this could be nice to update backlight_device_set_brightness to avoid code duplication:

Quoted 5 lines
Quoted 3 lines

int backlight_device_set_brightness(...) {
        return backlight_set_brightness(..., BACKLIGHT_UPDATE_SYSFS); }

OK.

(note: this is only valid if you don't clamp in backlight_set_brightness, current code return -EINVAL if it is outside the range)

Quoted 35 lines
Quoted 24 lines
Quoted 24 lines

  /**
   * backlight_register_notifier - get notified of backlight (un)registration
   * @nb: notifier block with the notifier to call on backlight (un)registration

include/linux/backlight.h +10 -0
index d905173c7f73c..7e4fee65fddd9 100644
@@ -429,6 +429,22 @@ static inline void 
 backlight_notify_blank_all(struct device *display_dev,
   { }
   #endif
 
+struct backlight_device *backlight_device_lookup(const char *name);
+void 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);
+}
+
Quoted 8 lines

include/linux/backlight.h static inline void backlight_notify_blank_all(struct device *display_dev, · line 447

Quoted 6 lines
include/linux/backlight.h +6 -0
+static inline void backlight_device_unref(struct backlight_device *bd)
+{
+     if (bd)
+             put_device(&bd->dev);
+}
+

Most of the kernel use _put and _get functions, I think it could be nice to keep the same naming.

OK.

#5 lore raw

PATCH v3 2/8 backlight: expose the current brightness in the new kernel API

In reply to Mario Limonciello

From: Marta Lofstedt <[email protected]>

Current brightness needs to be queried from drivers.

v3:
* Rebase
* Add description

---
 drivers/video/backlight/backlight.c | 6 ++++++
 include/linux/backlight.h           | 1 +
 2 files changed, 7 insertions(+)
drivers/video/backlight/backlight.c +6 -0
index c3673bee6d9cf..9bbfc16cf2d74 100644
@@ -206,6 +206,12 @@ int backlight_device_set_brightness(struct backlight_device *bd,
 }
 EXPORT_SYMBOL(backlight_device_set_brightness);
 
+int backlight_device_get_brightness(struct backlight_device *bd)
+{
+	return bd->props.brightness;
+}
+EXPORT_SYMBOL(backlight_device_get_brightness);
+
 static ssize_t brightness_store(struct device *dev,
 		struct device_attribute *attr, const char *buf, size_t count)
 {
include/linux/backlight.h +1 -0
index 7e4fee65fddd9..851570b39d041 100644
@@ -412,6 +412,7 @@ struct backlight_device *backlight_device_get_by_name(const char *name);
 struct backlight_device *backlight_device_get_by_type(enum backlight_type type);
 int backlight_device_set_brightness(struct backlight_device *bd,
 				    unsigned long brightness);
+extern int backlight_device_get_brightness(struct backlight_device *bd);
 
 #if IS_REACHABLE(CONFIG_BACKLIGHT_CLASS_DEVICE)
 void backlight_notify_blank(struct backlight_device *bd,
Signature · 1 line
2.43.0
#6 lore raw

Re: [PATCH v3 2/8] backlight: expose the current brightness in the new kernel API

Quoted 19 lines · Mario Limonciello

From: Marta Lofstedt <[email protected]>

Current brightness needs to be queried from drivers.

v3:
* Rebase
* Add description

---
  drivers/video/backlight/backlight.c | 6 ++++++
  include/linux/backlight.h           | 1 +
  2 files changed, 7 insertions(+)
drivers/video/backlight/backlight.c +0 -0
index c3673bee6d9cf..9bbfc16cf2d74 100644

drivers/video/backlight/backlight.c int backlight_device_set_brightness(struct backlight_device *bd, · line 211

Quoted 6 lines
drivers/video/backlight/backlight.c +3 -0
@@ -206,6 +206,12 @@ int backlight_device_set_brightness(struct backlight_device *bd,
  }
  EXPORT_SYMBOL(backlight_device_set_brightness);
 
+int backlight_device_get_brightness(struct backlight_device *bd)
+{
+	return bd->props.brightness;

Hello,

The function backlight_get_brightness already exists and is already public, maybe you can use the existing function?

Thanks,
Louis Chauvet

Quoted 18 lines
drivers/video/backlight/backlight.c +3 -0
+}
+EXPORT_SYMBOL(backlight_device_get_brightness);
+
  static ssize_t brightness_store(struct device *dev,
  		struct device_attribute *attr, const char *buf, size_t count)
  {
include/linux/backlight.h +1 -0
index 7e4fee65fddd9..851570b39d041 100644
@@ -412,6 +412,7 @@ struct backlight_device *backlight_device_get_by_name(const char *name);
  struct backlight_device *backlight_device_get_by_type(enum backlight_type type);
  int backlight_device_set_brightness(struct backlight_device *bd,
  				    unsigned long brightness);
+extern int backlight_device_get_brightness(struct backlight_device *bd);
 
  #if IS_REACHABLE(CONFIG_BACKLIGHT_CLASS_DEVICE)
  void backlight_notify_blank(struct backlight_device *bd,
#7 lore raw

Re: [PATCH v3 2/8] backlight: expose the current brightness in the new kernel API

Quoted 26 lines · Louis Chauvet

[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

Quoted 23 lines · Mario Limonciello

From: Marta Lofstedt <[email protected]>

Current brightness needs to be queried from drivers.

v3:
  * Rebase
  * Add description

---
  drivers/video/backlight/backlight.c | 6 ++++++
  include/linux/backlight.h           | 1 +

  2 files changed, 7 insertions(+)
drivers/video/backlight/backlight.c +0 -0
index c3673bee6d9cf..9bbfc16cf2d74 100644
@@ -206,6 +206,12 @@ int backlight_device_set_brightness(struct 
 backlight_device *bd,
   }
   EXPORT_SYMBOL(backlight_device_set_brightness);
 
Quoted 9 lines

drivers/video/backlight/backlight.c int backlight_device_set_brightness(struct backlight_device *bd, · line 211

Quoted 3 lines
drivers/video/backlight/backlight.c +3 -0
+int backlight_device_get_brightness(struct backlight_device *bd)
+{
+     return bd->props.brightness;

Hello,

The function backlight_get_brightness already exists and is already public, maybe you can use the existing function?

Thanks for the suggestion. I'll have a try with this.

Quoted 21 lines
Quoted 20 lines
drivers/video/backlight/backlight.c +3 -0
+}
+EXPORT_SYMBOL(backlight_device_get_brightness);
+
   static ssize_t brightness_store(struct device *dev,
               struct device_attribute *attr, const char *buf, size_t count)

  {

include/linux/backlight.h +1 -0
index 7e4fee65fddd9..851570b39d041 100644
@@ -412,6 +412,7 @@ struct backlight_device 
 *backlight_device_get_by_name(const char *name);
   struct backlight_device *backlight_device_get_by_type(enum backlight_type type);
   int backlight_device_set_brightness(struct backlight_device *bd,
                                   unsigned long brightness);
+extern int backlight_device_get_brightness(struct backlight_device *bd);
 
   #if IS_REACHABLE(CONFIG_BACKLIGHT_CLASS_DEVICE)

  void backlight_notify_blank(struct backlight_device *bd,

#8 lore raw

PATCH v3 3/8 drm: link connectors to backlight devices

In reply to Mario Limonciello

This adds generic backlight-device support to DRM connectors. Drivers that need to link backlight devices to DRM connectors can use the new helpers to create a backlight property and link them at runtime.

Also add a brightness changed notification so that sysfs and DRM connector can stay in sync and handle property updates around DPMS.

---
 drivers/gpu/drm/Kconfig             |   1 +
 drivers/gpu/drm/Makefile            |   2 +
 drivers/gpu/drm/drm_backlight.c     | 406 ++++++++++++++++++++++++++++
 drivers/gpu/drm/drm_connector.c     |  12 +
 drivers/gpu/drm/drm_drv.c           |   8 +
 drivers/gpu/drm/drm_mode_config.c   |   7 +
 drivers/gpu/drm/drm_mode_object.c   |  66 ++++-
 drivers/gpu/drm/drm_sysfs.c         |  54 ++++
 drivers/video/backlight/backlight.c |  17 ++
 include/drm/drm_backlight.h         |  45 +++
 include/drm/drm_connector.h         |   3 +
 include/drm/drm_mode_config.h       |   5 +
 include/linux/backlight.h           |  13 +
 13 files changed, 637 insertions(+), 2 deletions(-)
 create mode 100644 drivers/gpu/drm/drm_backlight.c
 create mode 100644 include/drm/drm_backlight.h
drivers/gpu/drm/Kconfig +1 -0
index 8f5a8d3012e41..8c00f534d50b8 100644
@@ -17,6 +17,7 @@ menuconfig DRM
 # device and dmabuf fd. Let's make sure that is available for our userspace.
 	select KCMP
 	select VIDEO
+	select BACKLIGHT_CLASS_DEVICE
 	help
 	  Kernel-level support for the Direct Rendering Infrastructure (DRI)
 	  introduced in XFree86 4.0. If you say Y here, you need to select
drivers/gpu/drm/Makefile +2 -0
index e97faabcd7830..9912306e94950 100644
@@ -78,6 +78,8 @@ drm-$(CONFIG_DRM_CLIENT) += \
 	drm_client_event.o \
 	drm_client_modeset.o \
 	drm_client_sysrq.o
+drm-y += drm_backlight.o
+drm-$(CONFIG_DRM_LIB_RANDOM) += lib/drm_random.o
 drm-$(CONFIG_COMPAT) += drm_ioc32.o
 drm-$(CONFIG_DRM_PANEL) += drm_panel.o
 drm-$(CONFIG_OF) += drm_of.o
drivers/gpu/drm/drm_backlight.c new file +406 -0

406 lines not on this page · raw message

drivers/gpu/drm/drm_connector.c +12 -0
index 47dc53c4a738f..d76878548728a 100644
@@ -21,6 +21,7 @@
  */
 
 #include <drm/drm_auth.h>
+#include <drm/drm_backlight.h>
 #include <drm/drm_connector.h>
 #include <drm/drm_drv.h>
 #include <drm/drm_edid.h>
@@ -760,6 +761,7 @@ void drm_connector_cleanup(struct drm_connector *connector)
 	struct drm_device *dev = connector->dev;
 	struct drm_display_mode *mode, *t;
 
+	drm_backlight_free(connector);
 	/* The connector should have been removed from userspace long before
 	 * it is finally destroyed.
 	 */
@@ -845,6 +847,8 @@ int drm_connector_register(struct drm_connector *connector)
 	if (connector->registration_state != DRM_CONNECTOR_INITIALIZING)
 		goto unlock;
 
+	drm_backlight_register(connector->backlight);
+
 	ret = drm_sysfs_connector_add(connector);
 	if (ret)
 		goto unlock;
@@ -931,6 +935,8 @@ EXPORT_SYMBOL(drm_connector_dynamic_register);
 void drm_connector_unregister(struct drm_connector *connector)
 {
 	mutex_lock(&connector->mutex);
+	drm_backlight_unregister(connector->backlight);
+
 	if (connector->registration_state != DRM_CONNECTOR_REGISTERED) {
 		mutex_unlock(&connector->mutex);
 		return;
@@ -3257,10 +3263,16 @@ int drm_connector_set_obj_prop(struct drm_mode_object *obj,
 {
 	int ret = -EINVAL;
 	struct drm_connector *connector = obj_to_connector(obj);
+	struct drm_mode_config *config = &connector->dev->mode_config;
 
 	/* Do DPMS ourselves */
 	if (property == connector->dev->mode_config.dpms_property) {
 		ret = (*connector->funcs->dpms)(connector, (int)value);
+	} else if (property == config->brightness_property) {
+		if (connector->backlight && connector->dpms == DRM_MODE_DPMS_ON)
+			drm_backlight_set_brightness(connector->backlight,
+						     value);
+		ret = 0;
 	} else if (connector->funcs->set_property)
 		ret = connector->funcs->set_property(connector, property, value);
 
drivers/gpu/drm/drm_drv.c +8 -0
index 985c283cf59fa..4fd8c2590d154 100644
@@ -42,6 +42,7 @@
 #include <linux/xarray.h>
 
 #include <drm/drm_accel.h>
+#include <drm/drm_backlight.h>
 #include <drm/drm_bridge.h>
 #include <drm/drm_cache.h>
 #include <drm/drm_client_event.h>
@@ -1228,6 +1229,7 @@ static void drm_core_exit(void)
 	drm_privacy_screen_lookup_exit();
 	drm_panic_exit();
 	accel_core_exit();
+	drm_backlight_exit();
 	unregister_chrdev(DRM_MAJOR, "drm");
 	drm_debugfs_remove_root();
 	drm_sysfs_destroy();
@@ -1251,6 +1253,12 @@ static int __init drm_core_init(void)
 	drm_debugfs_init_root();
 	drm_debugfs_bridge_params();
 
+	ret = drm_backlight_init();
+	if (ret < 0) {
+		DRM_ERROR("Cannot initialize backlight interface\n");
+		goto error;
+	}
+
 	ret = register_chrdev(DRM_MAJOR, "drm", &drm_stub_fops);
 	if (ret < 0)
 		goto error;
drivers/gpu/drm/drm_mode_config.c +7 -0
index 66f7dc37b5970..585d80e3c1330 100644
@@ -32,6 +32,7 @@
 #include <drm/drm_print.h>
 #include <drm/drm_colorop.h>
 #include <linux/dma-resv.h>
+#include <drm/drm_backlight.h>
 
 #include "drm_crtc_internal.h"
 #include "drm_internal.h"
@@ -407,6 +408,12 @@ static int drm_mode_create_standard_properties(struct drm_device *dev)
 		return -ENOMEM;
 	dev->mode_config.size_hints_property = prop;
 
+	prop = drm_property_create_range(dev, DRM_MODE_PROP_ATOMIC,
+					 "LUMINANCE", 0, U16_MAX);
+	if (!prop)
+		return -ENOMEM;
+	dev->mode_config.luminance_property = prop;
+
 	return 0;
 }
 
drivers/gpu/drm/drm_mode_object.c +64 -2

81 lines not on this page · raw message

drivers/gpu/drm/drm_sysfs.c +54 -0

77 lines not on this page · raw message

drivers/video/backlight/backlight.c +17 -0
index 9bbfc16cf2d74..1557dfb3a3bf3 100644
@@ -125,6 +125,9 @@ static void backlight_generate_event(struct backlight_device *bd,
 	case BACKLIGHT_UPDATE_HOTKEY:
 		envp[0] = "SOURCE=hotkey";
 		break;
+	case BACKLIGHT_UPDATE_DRM:
+		envp[0] = "SOURCE=drm";
+		break;
 	default:
 		envp[0] = "SOURCE=unknown";
 		break;
@@ -613,6 +616,20 @@ int backlight_unregister_notifier(struct notifier_block *nb)
 }
 EXPORT_SYMBOL(backlight_unregister_notifier);
 
+/**
+ * backlight_notify_brightness - notify brightness change to listeners
+ * @bd: backlight device that changed
+ *
+ * Notify registered listeners that the backlight brightness has changed.
+ * This is called automatically after successful brightness updates.
+ */
+void backlight_notify_brightness(struct backlight_device *bd)
+{
+	blocking_notifier_call_chain(&backlight_notifier,
+				     BACKLIGHT_BRIGHTNESS_CHANGED, bd);
+}
+EXPORT_SYMBOL(backlight_notify_brightness);
+
 /**
  * devm_backlight_device_register - register a new backlight device
  * @dev: the device to register
include/drm/drm_backlight.h new file +45 -0

45 lines not on this page · raw message

include/drm/drm_connector.h +3 -0
index f83f28cae2075..10daf088b8f1a 100644
@@ -2410,6 +2410,9 @@ struct drm_connector {
 	 * @cec: CEC-related data.
 	 */
 	struct drm_connector_cec cec;
+
+	/* backlight link */
+	struct drm_backlight *backlight;
 };
 
 #define obj_to_connector(x) container_of(x, struct drm_connector, base)
include/drm/drm_mode_config.h +5 -0
index 687c0ee163d25..b340dc93f8148 100644
@@ -852,6 +852,11 @@ struct drm_mode_config {
 	 * the position of the output on the host's screen.
 	 */
 	struct drm_property *suggested_y_property;
+	/**
+	 * @luminance_property: Default connector property to control the
+	 * connector's backlight luminance.
+	 */
+	struct drm_property *luminance_property;
 
 	/**
 	 * @non_desktop_property: Optional connector property with a hint
include/linux/backlight.h +13 -0
index 851570b39d041..f7f1e18909460 100644
@@ -29,6 +29,7 @@ enum backlight_update_reason {
 	 * @BACKLIGHT_UPDATE_SYSFS: The backlight was updated using sysfs.
 	 */
 	BACKLIGHT_UPDATE_SYSFS,
+	BACKLIGHT_UPDATE_DRM,
 };
 
 /**
@@ -80,6 +81,11 @@ enum backlight_notification {
 	 * @BACKLIGHT_UNREGISTERED: The backlight revice is unregistered.
 	 */
 	BACKLIGHT_UNREGISTERED,
+
+	/**
+	 * @BACKLIGHT_BRIGHTNESS_CHANGED: The backlight brightness has changed.
+	 */
+	BACKLIGHT_BRIGHTNESS_CHANGED,
 };
 
 /** enum backlight_scale - the type of scale used for brightness values
@@ -310,6 +316,9 @@ struct backlight_device {
 	int use_count;
 };
 
+/* Forward declaration for backlight_update_status */
+void backlight_notify_brightness(struct backlight_device *bd);
+
 /**
  * backlight_update_status - force an update of the backlight device status
  * @bd: the backlight device
@@ -323,6 +332,10 @@ static inline int backlight_update_status(struct backlight_device *bd)
 		ret = bd->ops->update_status(bd);
 	mutex_unlock(&bd->update_lock);
 
+	/* Notify DRM and other listeners that brightness changed */
+	if (ret == 0)
+		backlight_notify_brightness(bd);
+
 	return ret;
 }
 
Signature · 1 line
2.43.0
#9 lore raw

Re: [PATCH v3 3/8] drm: link connectors to backlight devices

Quoted 90 lines · Mario Limonciello

This adds generic backlight-device support to DRM connectors. Drivers that need to link backlight devices to DRM connectors can use the new helpers to create a backlight property and link them at runtime.

Also add a brightness changed notification so that sysfs and DRM connector can stay in sync and handle property updates around DPMS.

---
 drivers/gpu/drm/Kconfig             |   1 +
 drivers/gpu/drm/Makefile            |   2 +
 drivers/gpu/drm/drm_backlight.c     | 406 ++++++++++++++++++++++++++++
 drivers/gpu/drm/drm_connector.c     |  12 +
 drivers/gpu/drm/drm_drv.c           |   8 +
 drivers/gpu/drm/drm_mode_config.c   |   7 +
 drivers/gpu/drm/drm_mode_object.c   |  66 ++++-
 drivers/gpu/drm/drm_sysfs.c         |  54 ++++
 drivers/video/backlight/backlight.c |  17 ++
 include/drm/drm_backlight.h         |  45 +++
 include/drm/drm_connector.h         |   3 +
 include/drm/drm_mode_config.h       |   5 +
 include/linux/backlight.h           |  13 +
 13 files changed, 637 insertions(+), 2 deletions(-)
 create mode 100644 drivers/gpu/drm/drm_backlight.c
 create mode 100644 include/drm/drm_backlight.h
drivers/gpu/drm/Kconfig +1 -0
index 8f5a8d3012e41..8c00f534d50b8 100644
@@ -17,6 +17,7 @@ menuconfig DRM
 # device and dmabuf fd. Let's make sure that is available for our userspace.
 	select KCMP
 	select VIDEO
+	select BACKLIGHT_CLASS_DEVICE
 	help
 	  Kernel-level support for the Direct Rendering Infrastructure (DRI)
 	  introduced in XFree86 4.0. If you say Y here, you need to select
drivers/gpu/drm/Makefile +2 -0
index e97faabcd7830..9912306e94950 100644
@@ -78,6 +78,8 @@ drm-$(CONFIG_DRM_CLIENT) += \
 	drm_client_event.o \
 	drm_client_modeset.o \
 	drm_client_sysrq.o
+drm-y += drm_backlight.o
+drm-$(CONFIG_DRM_LIB_RANDOM) += lib/drm_random.o
 drm-$(CONFIG_COMPAT) += drm_ioc32.o
 drm-$(CONFIG_DRM_PANEL) += drm_panel.o
 drm-$(CONFIG_OF) += drm_of.o
drivers/gpu/drm/drm_backlight.c new file +33 -0
new file mode 100644
index 0000000000000..cbc6a855ed332
@@ -0,0 +1,406 @@
+// SPDX-License-Identifier: MIT
+/*
+ * DRM Backlight Helpers
+ * Copyright (c) 2014 David Herrmann
+ * Copyright (c) 2026 Advanced Micro Devices, Inc.
+ */
+
+#include <linux/backlight.h>
+#include <linux/fs.h>
+#include <linux/list.h>
+#include <linux/math64.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/notifier.h>
+#include <linux/slab.h>
+#include <linux/spinlock.h>
+#include <drm/drm_backlight.h>
+#include <drm/drm_connector.h>
+#include <drm/drm_device.h>
+#include <drm/drm_mode_config.h>
+
+/**
+ * DOC: Backlight Devices
+ *
+ * Backlight devices have always been managed as a separate subsystem,
+ * independent of DRM. They are usually controlled via separate hardware
+ * interfaces than the display controller, so the split works out fine.
+ * However, backlight brightness is a property of a display, and thus a
+ * property of a DRM connector. We already manage DPMS states via connector
+ * properties, so it is natural to keep brightness control at the same place.
+ *
+ * This DRM backlight interface implements generic backlight properties on
+ * connectors. It does not handle any hardware backends but simply forwards

drivers/gpu/drm/drm_backlight.c line 43

Quoted 10 lines
drivers/gpu/drm/drm_backlight.c new file +10 -0
+ * the requests to an available and linked backlight device. The links between
+ * connectors and backlight devices have to be established by DRM drivers and
+ * can be modified by user-space via sysfs (and udev rules). The name of the
+ * backlight device can be written to a sysfs attribute called 'backlight'.
+ * The device is looked up and linked to the connector (replacing a possible
+ * previous backlight device). A 'change' uevent is sent whenever a link is
+ * modified.
+ *
+ * Drivers have to call drm_backlight_alloc() after allocating a connector via
+ * drm_connector_init(). This will automatically add a backlight device to the

I'd like to point out another kind of devices which might have been left w/o notice here: the panels. In a plenty of cases the driver creating the drm_connector (frequently through drm_bridge_connector_init()) doesn't even know if there is a panel on the other side of the chain or not. Likewise connector creation doesn't involve any panel-related operation. Some panels provide backlight controls. Others don't and rely on the external backlight controls (see drm_panel_of_backlight() for example).

Can we work towards simplifying possible support for DRM backlights to the setups with drm_panel in place?

drivers/gpu/drm/drm_backlight.c line 46

Quoted 3 lines
drivers/gpu/drm/drm_backlight.c new file +3 -0
+ * given connector. No hardware device is linked to the connector by default.
+ * Drivers can set up a default device via drm_backlight_set_name(), but are
+ * free to leave it empty. User-space will then have to set up the link.

This sounds like a definite no-go. Think about any phone or any laptop. Do we need to involve userspace to let the kernel know that there is a connection between the DRM connector and the backlight present in the system?

What is the usescase for having dynamic connector<->link connections?

Quoted 2 lines
drivers/gpu/drm/drm_backlight.c new file +2 -0
+ */
+
Signature · 2 lines
With best wishes
Dmitry
#10 lore raw

Re: [PATCH v3 3/8] drm: link connectors to backlight devices

Quoted 111 lines · Dmitry Baryshkov
Quoted 90 lines · Mario Limonciello

This adds generic backlight-device support to DRM connectors. Drivers that need to link backlight devices to DRM connectors can use the new helpers to create a backlight property and link them at runtime.

Also add a brightness changed notification so that sysfs and DRM connector can stay in sync and handle property updates around DPMS.

---
  drivers/gpu/drm/Kconfig             |   1 +
  drivers/gpu/drm/Makefile            |   2 +
  drivers/gpu/drm/drm_backlight.c     | 406 ++++++++++++++++++++++++++++
  drivers/gpu/drm/drm_connector.c     |  12 +
  drivers/gpu/drm/drm_drv.c           |   8 +
  drivers/gpu/drm/drm_mode_config.c   |   7 +
  drivers/gpu/drm/drm_mode_object.c   |  66 ++++-
  drivers/gpu/drm/drm_sysfs.c         |  54 ++++
  drivers/video/backlight/backlight.c |  17 ++
  include/drm/drm_backlight.h         |  45 +++
  include/drm/drm_connector.h         |   3 +
  include/drm/drm_mode_config.h       |   5 +
  include/linux/backlight.h           |  13 +
  13 files changed, 637 insertions(+), 2 deletions(-)

create mode 100644 drivers/gpu/drm/drm_backlight.c create mode 100644 include/drm/drm_backlight.h

drivers/gpu/drm/Kconfig +1 -0
index 8f5a8d3012e41..8c00f534d50b8 100644
@@ -17,6 +17,7 @@ menuconfig DRM
  # device and dmabuf fd. Let's make sure that is available for our userspace.
  	select KCMP
  	select VIDEO
+	select BACKLIGHT_CLASS_DEVICE
  	help
  	  Kernel-level support for the Direct Rendering Infrastructure (DRI)
  	  introduced in XFree86 4.0. If you say Y here, you need to select
drivers/gpu/drm/Makefile +2 -0
index e97faabcd7830..9912306e94950 100644
@@ -78,6 +78,8 @@ drm-$(CONFIG_DRM_CLIENT) += \
  	drm_client_event.o \
  	drm_client_modeset.o \
  	drm_client_sysrq.o
+drm-y += drm_backlight.o
+drm-$(CONFIG_DRM_LIB_RANDOM) += lib/drm_random.o
  drm-$(CONFIG_COMPAT) += drm_ioc32.o
  drm-$(CONFIG_DRM_PANEL) += drm_panel.o
  drm-$(CONFIG_OF) += drm_of.o
drivers/gpu/drm/drm_backlight.c new file +33 -0
new file mode 100644
index 0000000000000..cbc6a855ed332
@@ -0,0 +1,406 @@
+// SPDX-License-Identifier: MIT
+/*
+ * DRM Backlight Helpers
+ * Copyright (c) 2014 David Herrmann
+ * Copyright (c) 2026 Advanced Micro Devices, Inc.
+ */
+
+#include <linux/backlight.h>
+#include <linux/fs.h>
+#include <linux/list.h>
+#include <linux/math64.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/notifier.h>
+#include <linux/slab.h>
+#include <linux/spinlock.h>
+#include <drm/drm_backlight.h>
+#include <drm/drm_connector.h>
+#include <drm/drm_device.h>
+#include <drm/drm_mode_config.h>
+
+/**
+ * DOC: Backlight Devices
+ *
+ * Backlight devices have always been managed as a separate subsystem,
+ * independent of DRM. They are usually controlled via separate hardware
+ * interfaces than the display controller, so the split works out fine.
+ * However, backlight brightness is a property of a display, and thus a
+ * property of a DRM connector. We already manage DPMS states via connector
+ * properties, so it is natural to keep brightness control at the same place.
+ *
+ * This DRM backlight interface implements generic backlight properties on
+ * connectors. It does not handle any hardware backends but simply forwards

drivers/gpu/drm/drm_backlight.c line 43

Quoted 10 lines
drivers/gpu/drm/drm_backlight.c new file +10 -0
+ * the requests to an available and linked backlight device. The links between
+ * connectors and backlight devices have to be established by DRM drivers and
+ * can be modified by user-space via sysfs (and udev rules). The name of the
+ * backlight device can be written to a sysfs attribute called 'backlight'.
+ * The device is looked up and linked to the connector (replacing a possible
+ * previous backlight device). A 'change' uevent is sent whenever a link is
+ * modified.
+ *
+ * Drivers have to call drm_backlight_alloc() after allocating a connector via
+ * drm_connector_init(). This will automatically add a backlight device to the

I'd like to point out another kind of devices which might have been left w/o notice here: the panels. In a plenty of cases the driver creating the drm_connector (frequently through drm_bridge_connector_init()) doesn't even know if there is a panel on the other side of the chain or not. Likewise connector creation doesn't involve any panel-related operation. Some panels provide backlight controls. Others don't and rely on the external backlight controls (see drm_panel_of_backlight() for example).

Quoted 2 lines

Can we work towards simplifying possible support for DRM backlights to the setups with drm_panel in place?

But to userspace it would interact with a connector not a panel directly right?

So doesn't the current design work well enough for this? When there is a panel backlight control it could be added; and if there isn't just do nothing.

Quoted 5 lines

drivers/gpu/drm/drm_backlight.c line 46

Quoted 4 lines
drivers/gpu/drm/drm_backlight.c new file +3 -0
+ * given connector. No hardware device is linked to the connector by default.
+ * Drivers can set up a default device via drm_backlight_set_name(), but are
+ * free to leave it empty. User-space will then have to set up the link.
Quoted 7 lines

This sounds like a definite no-go. Think about any phone or any laptop. Do we need to involve userspace to let the kernel know that there is a connection between the DRM connector and the backlight present in the system?

What is the usescase for having dynamic connector<->link connections?

Allowing userspace to setup the link was something in the original series by David and Marta that I left in place. I don't have a problem with dropping that concept and requiring the driver to do the linking.

#11 lore raw

Re: [PATCH v3 3/8] drm: link connectors to backlight devices

Quoted 117 lines · Mario Limonciello
Quoted 111 lines · Dmitry Baryshkov
Quoted 90 lines · Mario Limonciello

This adds generic backlight-device support to DRM connectors. Drivers that need to link backlight devices to DRM connectors can use the new helpers to create a backlight property and link them at runtime.

Also add a brightness changed notification so that sysfs and DRM connector can stay in sync and handle property updates around DPMS.

---
  drivers/gpu/drm/Kconfig             |   1 +
  drivers/gpu/drm/Makefile            |   2 +
  drivers/gpu/drm/drm_backlight.c     | 406 ++++++++++++++++++++++++++++
  drivers/gpu/drm/drm_connector.c     |  12 +
  drivers/gpu/drm/drm_drv.c           |   8 +
  drivers/gpu/drm/drm_mode_config.c   |   7 +
  drivers/gpu/drm/drm_mode_object.c   |  66 ++++-
  drivers/gpu/drm/drm_sysfs.c         |  54 ++++
  drivers/video/backlight/backlight.c |  17 ++
  include/drm/drm_backlight.h         |  45 +++
  include/drm/drm_connector.h         |   3 +
  include/drm/drm_mode_config.h       |   5 +
  include/linux/backlight.h           |  13 +
  13 files changed, 637 insertions(+), 2 deletions(-)

create mode 100644 drivers/gpu/drm/drm_backlight.c create mode 100644 include/drm/drm_backlight.h

drivers/gpu/drm/Kconfig +1 -0
index 8f5a8d3012e41..8c00f534d50b8 100644
@@ -17,6 +17,7 @@ menuconfig DRM
  # device and dmabuf fd. Let's make sure that is available for our userspace.
  	select KCMP
  	select VIDEO
+	select BACKLIGHT_CLASS_DEVICE
  	help
  	  Kernel-level support for the Direct Rendering Infrastructure (DRI)
  	  introduced in XFree86 4.0. If you say Y here, you need to select
drivers/gpu/drm/Makefile +2 -0
index e97faabcd7830..9912306e94950 100644
@@ -78,6 +78,8 @@ drm-$(CONFIG_DRM_CLIENT) += \
  	drm_client_event.o \
  	drm_client_modeset.o \
  	drm_client_sysrq.o
+drm-y += drm_backlight.o
+drm-$(CONFIG_DRM_LIB_RANDOM) += lib/drm_random.o
  drm-$(CONFIG_COMPAT) += drm_ioc32.o
  drm-$(CONFIG_DRM_PANEL) += drm_panel.o
  drm-$(CONFIG_OF) += drm_of.o
drivers/gpu/drm/drm_backlight.c new file +33 -0
new file mode 100644
index 0000000000000..cbc6a855ed332
@@ -0,0 +1,406 @@
+// SPDX-License-Identifier: MIT
+/*
+ * DRM Backlight Helpers
+ * Copyright (c) 2014 David Herrmann
+ * Copyright (c) 2026 Advanced Micro Devices, Inc.
+ */
+
+#include <linux/backlight.h>
+#include <linux/fs.h>
+#include <linux/list.h>
+#include <linux/math64.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/notifier.h>
+#include <linux/slab.h>
+#include <linux/spinlock.h>
+#include <drm/drm_backlight.h>
+#include <drm/drm_connector.h>
+#include <drm/drm_device.h>
+#include <drm/drm_mode_config.h>
+
+/**
+ * DOC: Backlight Devices
+ *
+ * Backlight devices have always been managed as a separate subsystem,
+ * independent of DRM. They are usually controlled via separate hardware
+ * interfaces than the display controller, so the split works out fine.
+ * However, backlight brightness is a property of a display, and thus a
+ * property of a DRM connector. We already manage DPMS states via connector
+ * properties, so it is natural to keep brightness control at the same place.
+ *
+ * This DRM backlight interface implements generic backlight properties on
+ * connectors. It does not handle any hardware backends but simply forwards

drivers/gpu/drm/drm_backlight.c line 43

Quoted 10 lines
drivers/gpu/drm/drm_backlight.c new file +10 -0
+ * the requests to an available and linked backlight device. The links between
+ * connectors and backlight devices have to be established by DRM drivers and
+ * can be modified by user-space via sysfs (and udev rules). The name of the
+ * backlight device can be written to a sysfs attribute called 'backlight'.
+ * The device is looked up and linked to the connector (replacing a possible
+ * previous backlight device). A 'change' uevent is sent whenever a link is
+ * modified.
+ *
+ * Drivers have to call drm_backlight_alloc() after allocating a connector via
+ * drm_connector_init(). This will automatically add a backlight device to the

I'd like to point out another kind of devices which might have been left w/o notice here: the panels. In a plenty of cases the driver creating the drm_connector (frequently through drm_bridge_connector_init()) doesn't even know if there is a panel on the other side of the chain or not. Likewise connector creation doesn't involve any panel-related operation. Some panels provide backlight controls. Others don't and rely on the external backlight controls (see drm_panel_of_backlight() for example).

Quoted 2 lines

Can we work towards simplifying possible support for DRM backlights to the setups with drm_panel in place?

Quoted 6 lines

But to userspace it would interact with a connector not a panel directly right?

So doesn't the current design work well enough for this? When there is a panel backlight control it could be added; and if there isn't just do nothing.

No, I wrote in the other email, why.

Quoted 11 lines
Quoted 11 lines

drivers/gpu/drm/drm_backlight.c line 46

Quoted 5 lines
drivers/gpu/drm/drm_backlight.c new file +3 -0
+ * given connector. No hardware device is linked to the connector by default.
+ * Drivers can set up a default device via drm_backlight_set_name(), but are
+ * free to leave it empty. User-space will then have to set up the link.

This sounds like a definite no-go. Think about any phone or any laptop. Do we need to involve userspace to let the kernel know that there is a connection between the DRM connector and the backlight present in the system?

Quoted 6 lines
Quoted 2 lines

What is the usescase for having dynamic connector<->link connections?

Allowing userspace to setup the link was something in the original series by David and Marta that I left in place. I don't have a problem with dropping that concept and requiring the driver to do the linking.

Well, I don't want to loose something actually useful. That's why I'm trying to understand the usecase.

Signature · 2 lines
With best wishes
Dmitry
#12 lore raw

PATCH v3 4/8 DRM: Add support for client and driver indicating support for luminance

In reply to Mario Limonciello

The legacy backlight control interface can only be disabled when both the client and driver have agreed that the luminance can be set during a modeset. Add capability for the client to register and for the driver to indicate support.

---
 drivers/gpu/drm/drm_atomic_uapi.c | 24 ++++++++++++++++++++++++
 drivers/gpu/drm/drm_connector.c   |  4 ++--
 drivers/gpu/drm/drm_ioctl.c       | 10 ++++++++++
 include/drm/drm_connector.h       |  5 +++++
 include/drm/drm_drv.h             |  7 +++++++
 include/drm/drm_file.h            |  8 ++++++++
 include/uapi/drm/drm.h            | 10 ++++++++++
 7 files changed, 66 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_atomic_uapi.c +24 -0
index 5bd5bf6661df7..de218206cef7e 100644
@@ -30,6 +30,7 @@
 #include <drm/drm_atomic.h>
 #include <drm/drm_atomic_helper.h>
 #include <drm/drm_atomic_uapi.h>
+#include <drm/drm_backlight.h>
 #include <drm/drm_framebuffer.h>
 #include <drm/drm_print.h>
 #include <drm/drm_drv.h>
@@ -935,6 +936,14 @@ static int drm_atomic_connector_set_property(struct drm_connector *connector,
 		state->privacy_screen_sw_state = val;
 	} else if (property == connector->broadcast_rgb_property) {
 		state->hdmi.broadcast_rgb = val;
+	} else if (property == config->luminance_property) {
+		state->luminance = val;
+		/* Update hardware backlight only when DPMS is ON.
+		 * Property value is always updated to remember the user's
+		 * desired brightness.
+		 */
+		if (connector->dpms == DRM_MODE_DPMS_ON)
+			drm_backlight_set_luminance(connector->backlight, val);
 	} else if (connector->funcs->atomic_set_property) {
 		return connector->funcs->atomic_set_property(connector,
 				state, property, val);
@@ -1020,6 +1029,8 @@ drm_atomic_connector_get_property(struct drm_connector *connector,
 		*val = state->privacy_screen_sw_state;
 	} else if (property == connector->broadcast_rgb_property) {
 		*val = state->hdmi.broadcast_rgb;
+	} else if (property == config->luminance_property) {
+		*val = state->luminance;
 	} else if (connector->funcs->atomic_get_property) {
 		return connector->funcs->atomic_get_property(connector,
 				state, property, val);
@@ -1126,8 +1137,21 @@ int drm_atomic_connector_commit_dpms(struct drm_atomic_state *state,
 	if (connector->dpms == mode)
 		goto out;
 
+	/* Handle backlight brightness coordination with DPMS state changes */
+	if (old_mode != DRM_MODE_DPMS_OFF && mode == DRM_MODE_DPMS_OFF) {
+		/* DPMS ON -> OFF: dim backlight to 0 to save power */
+		drm_backlight_set_luminance(connector->backlight, 0);
+	}
+
 	connector->dpms = mode;
 
+	/* DPMS OFF -> ON: restore brightness to property value */
+	if (old_mode == DRM_MODE_DPMS_OFF && mode == DRM_MODE_DPMS_ON &&
+	    connector->state) {
+		drm_backlight_set_luminance(connector->backlight,
+					    connector->state->luminance);
+	}
+
 	crtc = connector->state->crtc;
 	if (!crtc)
 		goto out;
drivers/gpu/drm/drm_connector.c +2 -2
index d76878548728a..5de33fc259b26 100644
@@ -3268,9 +3268,9 @@ int drm_connector_set_obj_prop(struct drm_mode_object *obj,
 	/* Do DPMS ourselves */
 	if (property == connector->dev->mode_config.dpms_property) {
 		ret = (*connector->funcs->dpms)(connector, (int)value);
-	} else if (property == config->brightness_property) {
+	} else if (property == config->luminance_property) {
 		if (connector->backlight && connector->dpms == DRM_MODE_DPMS_ON)
-			drm_backlight_set_brightness(connector->backlight,
+			drm_backlight_set_luminance(connector->backlight,
 						     value);
 		ret = 0;
 	} else if (connector->funcs->set_property)
drivers/gpu/drm/drm_ioctl.c +10 -0
index ff193155129e7..b4435c2bd6091 100644
@@ -28,6 +28,7 @@
  * OTHER DEALINGS IN THE SOFTWARE.
  */
 
+#include "drm/drm.h"
 #include <linux/export.h>
 #include <linux/nospec.h>
 #include <linux/pci.h>
@@ -380,6 +381,15 @@ drm_setclientcap(struct drm_device *dev, void *data, struct drm_file *file_priv)
 			return -EINVAL;
 		file_priv->plane_color_pipeline = req->value;
 		break;
+	case DRM_CLIENT_CAP_LUMINANCE:
+		if (!drm_core_check_feature(dev, DRIVER_CONNECTOR_LUMINANCE))
+			return -EOPNOTSUPP;
+		if (!file_priv->atomic)
+			return -EINVAL;
+		if (req->value > 1)
+			return -EINVAL;
+		file_priv->supports_luminance_control = req->value;
+		break;
 	default:
 		return -EINVAL;
 	}
include/drm/drm_connector.h +5 -0
index 10daf088b8f1a..762a9e2ef6e30 100644
@@ -1209,6 +1209,11 @@ struct drm_connector_state {
 	 * @drm_atomic_helper_connector_hdmi_check().
 	 */
 	struct drm_connector_hdmi_state hdmi;
+
+	/**
+	 * @luminance: Luminance for the connector
+	 */
+	u16 luminance;
 };
 
 struct drm_connector_hdmi_audio_funcs {
include/drm/drm_drv.h +7 -0
index 42fc085f986de..a6b668cb68c5e 100644
@@ -123,6 +123,13 @@ enum drm_driver_feature {
 	 */
 	DRIVER_CURSOR_HOTSPOT           = BIT(9),
 
+	/**
+	 * @DRIVER_CONNECTOR_LUMINANCE:
+	 *
+	 * Driver supports luminance control on a per connector basis.
+	 */
+	DRIVER_CONNECTOR_LUMINANCE           = BIT(10),
+
 	/* IMPORTANT: Below are all the legacy flags, add new ones above. */
 
 	/**
include/drm/drm_file.h +8 -0
index 6ee70ad65e1fd..0bb1e53f36bec 100644
@@ -248,6 +248,14 @@ struct drm_file {
 	 */
 	bool supports_virtualized_cursor_plane;
 
+	/**
+	 * @supports_luminance_control:
+	 *
+	 * This client is capable of setting the luminance for connectors.
+	 *
+	 */
+	bool supports_luminance_control;
+
 	/**
 	 * @master:
 	 *
include/uapi/drm/drm.h +10 -0
index 27cc159c1d275..b5e6d940f2816 100644
@@ -921,6 +921,16 @@ struct drm_get_cap {
  */
 #define DRM_CLIENT_CAP_PLANE_COLOR_PIPELINE	7
 
+/**
+ * DRM_CLIENT_CAP_LUMINANCE
+ *
+ * If set to 1, legacy sysfs interface for controlling backlight brightness will
+ * be disabled.  The client will include luminance values as part of the modeset.
+
+ * This capability is supported starting in kernel 7.2
+ */
+#define DRM_CLIENT_CAP_LUMINANCE		8
+
 /* DRM_IOCTL_SET_CLIENT_CAP ioctl argument type */
 struct drm_set_client_cap {
 	__u64 capability;
Signature · 1 line
2.43.0
#13 lore raw

Re: [PATCH v3 4/8] DRM: Add support for client and driver indicating support for luminance

Quoted 4 lines · Mario Limonciello

The legacy backlight control interface can only be disabled when both the client and driver have agreed that the luminance can be set during a modeset. Add capability for the client to register and for the driver to indicate support.

Please describe, why do we need DRM_CLIENT_CAP_LUMINANCE.

Quoted 16 lines
---
 drivers/gpu/drm/drm_atomic_uapi.c | 24 ++++++++++++++++++++++++
 drivers/gpu/drm/drm_connector.c   |  4 ++--
 drivers/gpu/drm/drm_ioctl.c       | 10 ++++++++++
 include/drm/drm_connector.h       |  5 +++++
 include/drm/drm_drv.h             |  7 +++++++
 include/drm/drm_file.h            |  8 ++++++++
 include/uapi/drm/drm.h            | 10 ++++++++++
 7 files changed, 66 insertions(+), 2 deletions(-)
include/uapi/drm/drm.h +0 -0
index 27cc159c1d275..b5e6d940f2816 100644

include/uapi/drm/drm.h struct drm_get_cap { · line 928

Quoted 8 lines
include/uapi/drm/drm.h +5 -0
@@ -921,6 +921,16 @@ struct drm_get_cap {
  */
 #define DRM_CLIENT_CAP_PLANE_COLOR_PIPELINE	7
 
+/**
+ * DRM_CLIENT_CAP_LUMINANCE
+ *
+ * If set to 1, legacy sysfs interface for controlling backlight brightness will
+ * be disabled.  The client will include luminance values as part of the modeset.

I don't think this is accurate (anymore?). The sysfs doesn't seem to be disabled. Rather the DRM updates it internally. Which might mean that we don't need an extra client cap.

Quoted 11 lines
include/uapi/drm/drm.h +5 -0
+
+ * This capability is supported starting in kernel 7.2
+ */
+#define DRM_CLIENT_CAP_LUMINANCE		8
+
 /* DRM_IOCTL_SET_CLIENT_CAP ioctl argument type */
 struct drm_set_client_cap {
 	__u64 capability;
Signature · 1 line
2.43.0
Signature · 2 lines
With best wishes
Dmitry
#14 lore raw

Re: [PATCH v3 4/8] DRM: Add support for client and driver indicating support for luminance

Quoted 27 lines · Dmitry Baryshkov
Quoted 4 lines · Mario Limonciello

The legacy backlight control interface can only be disabled when both the client and driver have agreed that the luminance can be set during a modeset. Add capability for the client to register and for the driver to indicate support.

Please describe, why do we need DRM_CLIENT_CAP_LUMINANCE.

Quoted 19 lines
---
  drivers/gpu/drm/drm_atomic_uapi.c | 24 ++++++++++++++++++++++++
  drivers/gpu/drm/drm_connector.c   |  4 ++--
  drivers/gpu/drm/drm_ioctl.c       | 10 ++++++++++
  include/drm/drm_connector.h       |  5 +++++
  include/drm/drm_drv.h             |  7 +++++++
  include/drm/drm_file.h            |  8 ++++++++
  include/uapi/drm/drm.h            | 10 ++++++++++
  7 files changed, 66 insertions(+), 2 deletions(-)
include/uapi/drm/drm.h +0 -0
index 27cc159c1d275..b5e6d940f2816 100644
@@ -921,6 +921,16 @@ struct drm_get_cap {
   */
  #define DRM_CLIENT_CAP_PLANE_COLOR_PIPELINE	7
 
Quoted 9 lines

include/uapi/drm/drm.h struct drm_get_cap { · line 928

Quoted 5 lines
include/uapi/drm/drm.h +5 -0
+/**
+ * DRM_CLIENT_CAP_LUMINANCE
+ *
+ * If set to 1, legacy sysfs interface for controlling backlight brightness will
+ * be disabled.  The client will include luminance values as part of the modeset.

I don't think this is accurate (anymore?). The sysfs doesn't seem to be disabled. Rather the DRM updates it internally. Which might mean that we don't need an extra client cap.

I had code in my tree for doing it and decided to defer that (see cover letter) but forgot to drop the cap.

I suppose this is an area that would be good to discuss if it's worth getting some of it done in the same series or should be deferred.

The overally idea I have is:

1) Allow both sysfs and DRM master to do writes initially (allow transitioning and PoC)
2) Userspace changes to DRM master
3) Introduce client cap for it and block off sysfs writes when DRM master indicates it.
4) Move sysfs compat behind a kconfig
5) Drop Kconfig

The timescale between steps 3 and 5 is "many kernel cycles".

Quoted 13 lines
Quoted 12 lines
include/uapi/drm/drm.h +5 -0
+
+ * This capability is supported starting in kernel 7.2
+ */
+#define DRM_CLIENT_CAP_LUMINANCE		8
+
  /* DRM_IOCTL_SET_CLIENT_CAP ioctl argument type */
  struct drm_set_client_cap {
  	__u64 capability;
Signature · 1 line
2.43.0
#15 lore raw

Re: [PATCH v3 4/8] DRM: Add support for client and driver indicating support for luminance

Quoted 55 lines · Mario Limonciello
Quoted 19 lines · Dmitry Baryshkov
Quoted 4 lines · Mario Limonciello

The legacy backlight control interface can only be disabled when both the client and driver have agreed that the luminance can be set during a modeset. Add capability for the client to register and for the driver to indicate support.

Please describe, why do we need DRM_CLIENT_CAP_LUMINANCE.

Quoted 11 lines
---
  drivers/gpu/drm/drm_atomic_uapi.c | 24 ++++++++++++++++++++++++
  drivers/gpu/drm/drm_connector.c   |  4 ++--
  drivers/gpu/drm/drm_ioctl.c       | 10 ++++++++++
  include/drm/drm_connector.h       |  5 +++++
  include/drm/drm_drv.h             |  7 +++++++
  include/drm/drm_file.h            |  8 ++++++++
  include/uapi/drm/drm.h            | 10 ++++++++++
  7 files changed, 66 insertions(+), 2 deletions(-)
Quoted 16 lines

include/uapi/drm/drm.h struct drm_get_cap { · line 927

Quoted 12 lines
include/uapi/drm/drm.h +5 -0
index 27cc159c1d275..b5e6d940f2816 100644
@@ -921,6 +921,16 @@ struct drm_get_cap {
   */
  #define DRM_CLIENT_CAP_PLANE_COLOR_PIPELINE	7
+/**
+ * DRM_CLIENT_CAP_LUMINANCE
+ *
+ * If set to 1, legacy sysfs interface for controlling backlight brightness will
+ * be disabled.  The client will include luminance values as part of the modeset.

I don't think this is accurate (anymore?). The sysfs doesn't seem to be disabled. Rather the DRM updates it internally. Which might mean that we don't need an extra client cap.

I had code in my tree for doing it and decided to defer that (see cover letter) but forgot to drop the cap.

I suppose this is an area that would be good to discuss if it's worth getting some of it done in the same series or should be deferred.

The overally idea I have is:

1) Allow both sysfs and DRM master to do writes initially (allow transitioning and PoC)
2) Userspace changes to DRM master
3) Introduce client cap for it and block off sysfs writes when DRM master indicates it.
4) Move sysfs compat behind a kconfig
5) Drop Kconfig

Quoted 1 line

The timescale between steps 3 and 5 is "many kernel cycles".

I like the idea of controlling the backlight through the connector API, but frankly speaking, I think that the implementation is somewhat strange. After checking the AMD driver, I'd really like to propose the following plan (again, unless I miss something, please feel free to point me to discussions or other patches describing the reasons):

1. Establish a way to link connectors to the backlight devices. For the userspace this might be visible as a symlink in sysfs, for the kernel drivers it should be drm_connector::backlight link to struct backlight_device.

Three major cases. Maybe four.
- Native backlight in the "big" drivers: amdgpu, i915 nouveau, radeon, gma500, gud, solomon.

- ACPI backlight (here the kernel would need to find the mapping. See ACPI DSDT standard and USB-C mapping code for the inspiration)

- backlight supported by the drm_panel

- backlight provided by the separate device and identified via the link in OF.

present around the time the drm_connector is created, maybe right after the connector is created (AMD does it in late_register, which sounds matching this description).

I can help you with the "embedded" systems. Keeping the word in quotes as, for example, I'm currently writing from the Snapdragon laptop (X13s), which uses drm_panel and all the stuff.

2. Find a good way to turn the backlight on and off. I see that you have hooked it into the drm_atomic_connector_commit_dpms(), but the problem is that it is only called when userspace toggles the DPMS property. There are other ways to turn the output off and on.

I _think_ the correct place would be drm_atomic_helper_commit_encoder_bridge_enable(). and corresponding dsiable() function. This is the place where the output chain gets enabled or disabled, no matter why is it happening.

3. Implement the client property. I don't think there is a need for the client capability or anything comples. The major design decision here should be if the property is always from 0 to 65535 or whether it takes backlight's max_brightness into the account and registers only relevant values. I don't have a strong opinion here.

There is no need to store the brightness level, calls to backlight_disable() / backlight_enable() (used in the previous step) should do the trick.

Signature · 2 lines
With best wishes
Dmitry
#16 lore raw

Re: [PATCH v3 4/8] DRM: Add support for client and driver indicating support for luminance

In reply to Mario Limonciello
Quoted 44 lines · Mario Limonciello

The legacy backlight control interface can only be disabled when both the client and driver have agreed that the luminance can be set during a modeset. Add capability for the client to register and for the driver to indicate support.

---
  drivers/gpu/drm/drm_atomic_uapi.c | 24 ++++++++++++++++++++++++
  drivers/gpu/drm/drm_connector.c   |  4 ++--
  drivers/gpu/drm/drm_ioctl.c       | 10 ++++++++++
  include/drm/drm_connector.h       |  5 +++++
  include/drm/drm_drv.h             |  7 +++++++
  include/drm/drm_file.h            |  8 ++++++++
  include/uapi/drm/drm.h            | 10 ++++++++++
  7 files changed, 66 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_atomic_uapi.c +9 -0
index 5bd5bf6661df7..de218206cef7e 100644
@@ -30,6 +30,7 @@
  #include <drm/drm_atomic.h>
  #include <drm/drm_atomic_helper.h>
  #include <drm/drm_atomic_uapi.h>
+#include <drm/drm_backlight.h>
  #include <drm/drm_framebuffer.h>
  #include <drm/drm_print.h>
  #include <drm/drm_drv.h>
@@ -935,6 +936,14 @@ static int drm_atomic_connector_set_property(struct drm_connector *connector,
  		state->privacy_screen_sw_state = val;
  	} else if (property == connector->broadcast_rgb_property) {
  		state->hdmi.broadcast_rgb = val;
+	} else if (property == config->luminance_property) {
+		state->luminance = val;
+		/* Update hardware backlight only when DPMS is ON.
+		 * Property value is always updated to remember the user's
+		 * desired brightness.
+		 */
+		if (connector->dpms == DRM_MODE_DPMS_ON)
+			drm_backlight_set_luminance(connector->backlight, val);
  	} else if (connector->funcs->atomic_set_property) {
  		return connector->funcs->atomic_set_property(connector,
  				state, property, val);

drivers/gpu/drm/drm_atomic_uapi.c drm_atomic_connector_get_property(struct drm_connector *connector, · line 1033

Quoted 5 lines
drivers/gpu/drm/drm_atomic_uapi.c +2 -0
@@ -1020,6 +1029,8 @@ drm_atomic_connector_get_property(struct drm_connector *connector,
  		*val = state->privacy_screen_sw_state;
  	} else if (property == connector->broadcast_rgb_property) {
  		*val = state->hdmi.broadcast_rgb;
+	} else if (property == config->luminance_property) {
+		*val = state->luminance;

I think this is a bad idea to have two "source of truth" for the luminance value. Is there a reason to not get the backlight value directly from the backlight driver?

Quoted 12 lines
drivers/gpu/drm/drm_atomic_uapi.c +5 -0
  	} else if (connector->funcs->atomic_get_property) {
  		return connector->funcs->atomic_get_property(connector,
  				state, property, val);
@@ -1126,8 +1137,21 @@ int drm_atomic_connector_commit_dpms(struct drm_atomic_state *state,
  	if (connector->dpms == mode)
  		goto out;
 
+	/* Handle backlight brightness coordination with DPMS state changes */
+	if (old_mode != DRM_MODE_DPMS_OFF && mode == DRM_MODE_DPMS_OFF) {
+		/* DPMS ON -> OFF: dim backlight to 0 to save power */
+		drm_backlight_set_luminance(connector->backlight, 0);
+	}

drivers/gpu/drm/drm_atomic_uapi.c int drm_atomic_connector_commit_dpms(struct drm_atomic_state *state, · line 1154

Quoted 10 lines
drivers/gpu/drm/drm_atomic_uapi.c +8 -0
+
  	connector->dpms = mode;
 
+	/* DPMS OFF -> ON: restore brightness to property value */
+	if (old_mode == DRM_MODE_DPMS_OFF && mode == DRM_MODE_DPMS_ON &&
+	    connector->state) {
+		drm_backlight_set_luminance(connector->backlight,
+					    connector->state->luminance);
+	}
+

According to the documentation, DPMS is a deprecated property and most of the work should be handled using the crtc->active property.

I think this will not change the backlight of other connector using the same CRTC (CRTC outputs on connector1 and connector2, userspace change DPMS only for connector1, for me it makes sense to change connector1 and connector2).

After looking a bit more, I think you need to keep this code, but:
- add something to also disable backlight of other connector using the same crtc
- handle the backlight when CRTC is disconnected from the connector (i.e when you set CRTC=0 on a connector)

drivers/gpu/drm/drm_connector.c int drm_connector_set_obj_prop(struct drm_mode_object *obj, · line 3271

Quoted 13 lines
drivers/gpu/drm/drm_atomic_uapi.c +0 -0
  	crtc = connector->state->crtc;
  	if (!crtc)
  		goto out;
drivers/gpu/drm/drm_connector.c +1 -1
index d76878548728a..5de33fc259b26 100644
@@ -3268,9 +3268,9 @@ int drm_connector_set_obj_prop(struct drm_mode_object *obj,
  	/* Do DPMS ourselves */
  	if (property == connector->dev->mode_config.dpms_property) {
  		ret = (*connector->funcs->dpms)(connector, (int)value);
-	} else if (property == config->brightness_property) {
+	} else if (property == config->luminance_property) {

Can you directly name it luminance in the previous patch?

Quoted 108 lines
drivers/gpu/drm/drm_connector.c +1 -1
  		if (connector->backlight && connector->dpms == DRM_MODE_DPMS_ON)
-			drm_backlight_set_brightness(connector->backlight,
+			drm_backlight_set_luminance(connector->backlight,
  						     value);
  		ret = 0;
  	} else if (connector->funcs->set_property)
drivers/gpu/drm/drm_ioctl.c +10 -0
index ff193155129e7..b4435c2bd6091 100644
@@ -28,6 +28,7 @@
   * OTHER DEALINGS IN THE SOFTWARE.
   */
 
+#include "drm/drm.h"
  #include <linux/export.h>
  #include <linux/nospec.h>
  #include <linux/pci.h>
@@ -380,6 +381,15 @@ drm_setclientcap(struct drm_device *dev, void *data, struct drm_file *file_priv)
  			return -EINVAL;
  		file_priv->plane_color_pipeline = req->value;
  		break;
+	case DRM_CLIENT_CAP_LUMINANCE:
+		if (!drm_core_check_feature(dev, DRIVER_CONNECTOR_LUMINANCE))
+			return -EOPNOTSUPP;
+		if (!file_priv->atomic)
+			return -EINVAL;
+		if (req->value > 1)
+			return -EINVAL;
+		file_priv->supports_luminance_control = req->value;
+		break;
  	default:
  		return -EINVAL;
  	}
include/drm/drm_connector.h +5 -0
index 10daf088b8f1a..762a9e2ef6e30 100644
@@ -1209,6 +1209,11 @@ struct drm_connector_state {
  	 * @drm_atomic_helper_connector_hdmi_check().
  	 */
  	struct drm_connector_hdmi_state hdmi;
+
+	/**
+	 * @luminance: Luminance for the connector
+	 */
+	u16 luminance;
  };
 
  struct drm_connector_hdmi_audio_funcs {
include/drm/drm_drv.h +7 -0
index 42fc085f986de..a6b668cb68c5e 100644
@@ -123,6 +123,13 @@ enum drm_driver_feature {
  	 */
  	DRIVER_CURSOR_HOTSPOT           = BIT(9),
 
+	/**
+	 * @DRIVER_CONNECTOR_LUMINANCE:
+	 *
+	 * Driver supports luminance control on a per connector basis.
+	 */
+	DRIVER_CONNECTOR_LUMINANCE           = BIT(10),
+
  	/* IMPORTANT: Below are all the legacy flags, add new ones above. */
 
  	/**
include/drm/drm_file.h +8 -0
index 6ee70ad65e1fd..0bb1e53f36bec 100644
@@ -248,6 +248,14 @@ struct drm_file {
  	 */
  	bool supports_virtualized_cursor_plane;
 
+	/**
+	 * @supports_luminance_control:
+	 *
+	 * This client is capable of setting the luminance for connectors.
+	 *
+	 */
+	bool supports_luminance_control;
+
  	/**
  	 * @master:
  	 *
include/uapi/drm/drm.h +10 -0
index 27cc159c1d275..b5e6d940f2816 100644
@@ -921,6 +921,16 @@ struct drm_get_cap {
   */
  #define DRM_CLIENT_CAP_PLANE_COLOR_PIPELINE	7
 
+/**
+ * DRM_CLIENT_CAP_LUMINANCE
+ *
+ * If set to 1, legacy sysfs interface for controlling backlight brightness will
+ * be disabled.  The client will include luminance values as part of the modeset.
+
+ * This capability is supported starting in kernel 7.2
+ */
+#define DRM_CLIENT_CAP_LUMINANCE		8
+
  /* DRM_IOCTL_SET_CLIENT_CAP ioctl argument type */
  struct drm_set_client_cap {
  	__u64 capability;
#17 lore raw

PATCH v3 5/8 drm/amd/display: Pass up errors reading actual brightness

In reply to Mario Limonciello

[Why]
If the DC API fails to return actual brightness when backlight control API requests it, then the wrong value may be returned.

[How]
Change return type of amdgpu_dm_backlight_get_level() to an integer and pass an error code up to the caller.

---
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +10 -5
index 1d9ceb432ec37..5b8a0dd558e76 100644
@@ -5302,7 +5302,7 @@ static int amdgpu_dm_backlight_update_status(struct backlight_device *bd)
 	return 0;
 }
 
-static u32 amdgpu_dm_backlight_get_level(struct amdgpu_display_manager *dm,
+static int amdgpu_dm_backlight_get_level(struct amdgpu_display_manager *dm,
 					 int bl_idx)
 {
 	int ret;
@@ -5316,14 +5316,14 @@ static u32 amdgpu_dm_backlight_get_level(struct amdgpu_display_manager *dm,
 		u32 avg, peak;
 
 		if (!dc_link_get_backlight_level_nits(link, &avg, &peak))
-			return dm->brightness[bl_idx];
+			return -EINVAL;
 		return convert_brightness_to_user(&caps, avg);
 	}
 
 	ret = dc_link_get_backlight_level(link);
 
 	if (ret == DC_ERROR_UNEXPECTED)
-		return dm->brightness[bl_idx];
+		return -EINVAL;
 
 	return convert_brightness_to_user(&caps, ret);
 }
@@ -5331,7 +5331,7 @@ static u32 amdgpu_dm_backlight_get_level(struct amdgpu_display_manager *dm,
 static int amdgpu_dm_backlight_get_brightness(struct backlight_device *bd)
 {
 	struct amdgpu_display_manager *dm = bl_get_data(bd);
-	int i;
+	int i, ret;
 
 	for (i = 0; i < dm->num_of_edps; i++) {
 		if (bd == dm->backlight_dev[i])
@@ -5339,7 +5339,12 @@ static int amdgpu_dm_backlight_get_brightness(struct backlight_device *bd)
 	}
 	if (i >= AMDGPU_DM_MAX_NUM_EDP)
 		i = 0;
-	return amdgpu_dm_backlight_get_level(dm, i);
+
+	ret = amdgpu_dm_backlight_get_level(dm, i);
+	if (ret < 0)
+		return dm->brightness[i];
+
+	return ret;
 }
 
 static const struct backlight_ops amdgpu_dm_backlight_ops = {
Signature · 1 line
2.43.0
#18 lore raw

PATCH v3 6/8 drm/amd: Indicate driver supports luminance

In reply to Mario Limonciello

This will allow the connector to show luminance information for eDP panels.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -0
index e47921e2a9af2..fa38d9f02edf6 100644
@@ -3072,6 +3072,7 @@ static const struct drm_driver amdgpu_kms_driver = {
 	    DRIVER_ATOMIC |
 	    DRIVER_GEM |
 	    DRIVER_RENDER | DRIVER_MODESET | DRIVER_SYNCOBJ |
+	    DRIVER_CONNECTOR_LUMINANCE |
 	    DRIVER_SYNCOBJ_TIMELINE,
 	.open = amdgpu_driver_open_kms,
 	.postclose = amdgpu_driver_postclose_kms,
Signature · 1 line
2.43.0
#19 lore raw

PATCH v3 7/8 drm/amd/display: Allow backlight registration to fail

In reply to Mario Limonciello

[Why]
If backlight registration fails then it's ignored. This could hide a fatal problem to a user.

[How]
Pass error codes up from backlight registration failures.

---
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 41 +++++++++++--------
 1 file changed, 24 insertions(+), 17 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +24 -17
index 5b8a0dd558e76..6b29e5b6b41e7 100644
@@ -5353,7 +5353,7 @@ static const struct backlight_ops amdgpu_dm_backlight_ops = {
 	.update_status	= amdgpu_dm_backlight_update_status,
 };
 
-static void
+static int
 amdgpu_dm_register_backlight_device(struct amdgpu_dm_connector *aconnector)
 {
 	struct drm_device *drm = aconnector->base.dev;
@@ -5364,15 +5364,16 @@ amdgpu_dm_register_backlight_device(struct amdgpu_dm_connector *aconnector)
 	int min, max;
 	int real_brightness;
 	int init_brightness;
+	int r;
 
 	if (aconnector->bl_idx == -1)
-		return;
+		return 0;
 
 	if (!acpi_video_backlight_use_native()) {
 		drm_info(drm, "Skipping amdgpu DM backlight registration\n");
 		/* Try registering an ACPI video backlight device instead. */
 		acpi_video_register_backlight();
-		return;
+		return 0;
 	}
 
 	caps = &dm->backlight_caps[aconnector->bl_idx];
@@ -5406,22 +5407,26 @@ amdgpu_dm_register_backlight_device(struct amdgpu_dm_connector *aconnector)
 	dm->brightness[aconnector->bl_idx] = props.brightness;
 
 	if (IS_ERR(dm->backlight_dev[aconnector->bl_idx])) {
-		drm_err(drm, "DM: Backlight registration failed!\n");
+		r = PTR_ERR(dm->backlight_dev[aconnector->bl_idx]);
+		drm_err(drm, "DM: Backlight registration failed: %d\n", r);
 		dm->backlight_dev[aconnector->bl_idx] = NULL;
-	} else {
-		/*
-		 * dm->brightness[x] can be inconsistent just after startup until
-		 * ops.get_brightness is called.
-		 */
-		real_brightness =
-			amdgpu_dm_backlight_ops.get_brightness(dm->backlight_dev[aconnector->bl_idx]);
+		return r;
+	}
 
-		if (real_brightness != init_brightness) {
-			dm->actual_brightness[aconnector->bl_idx] = real_brightness;
-			dm->brightness[aconnector->bl_idx] = real_brightness;
-		}
-		drm_dbg_driver(drm, "DM: Registered Backlight device: %s\n", bl_name);
+	/*
+	 * dm->brightness[x] can be inconsistent just after startup until
+	 * ops.get_brightness is called.
+	 */
+	real_brightness =
+		amdgpu_dm_backlight_ops.get_brightness(dm->backlight_dev[aconnector->bl_idx]);
+
+	if (real_brightness != init_brightness) {
+		dm->actual_brightness[aconnector->bl_idx] = real_brightness;
+		dm->brightness[aconnector->bl_idx] = real_brightness;
 	}
+	drm_dbg_driver(drm, "DM: Registered Backlight device: %s\n", bl_name);
+
+	return 0;
 }
 
 static int initialize_plane(struct amdgpu_display_manager *dm,
@@ -7953,7 +7958,9 @@ amdgpu_dm_connector_late_register(struct drm_connector *connector)
 			return r;
 	}
 
-	amdgpu_dm_register_backlight_device(amdgpu_dm_connector);
+	r = amdgpu_dm_register_backlight_device(amdgpu_dm_connector);
+	if (r)
+		return r;
 
 	if ((connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort) ||
 	    (connector->connector_type == DRM_MODE_CONNECTOR_eDP)) {
Signature · 1 line
2.43.0
#20 lore raw

PATCH v3 8/8 drm/amd/display: use drm backlight

In reply to Mario Limonciello

Convert AMD display driver to use the new DRM backlight infrastructure. This allows brightness control via DRM connector properties.

Includes fixes for backlight resource lifecycle management.

---
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 36 ++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +35 -1
index 6b29e5b6b41e7..52854abc6bb60 100644
@@ -86,6 +86,7 @@
 #include <drm/drm_atomic.h>
 #include <drm/drm_atomic_uapi.h>
 #include <drm/drm_atomic_helper.h>
+#include <drm/drm_backlight.h>
 #include <drm/drm_blend.h>
 #include <drm/drm_fixed.h>
 #include <drm/drm_fourcc.h>
@@ -5424,9 +5425,32 @@ amdgpu_dm_register_backlight_device(struct amdgpu_dm_connector *aconnector)
 		dm->actual_brightness[aconnector->bl_idx] = real_brightness;
 		dm->brightness[aconnector->bl_idx] = real_brightness;
 	}
-	drm_dbg_driver(drm, "DM: Registered Backlight device: %s\n", bl_name);
+
+	/* Only set backlight name if DRM backlight was allocated successfully.
+	 * drm_backlight_alloc() may have failed earlier in init_helper, leaving
+	 * aconnector->base.backlight as NULL.
+	 */
+	if (aconnector->base.backlight) {
+		r = drm_backlight_set_name(aconnector->base.backlight, bl_name);
+		if (r)
+			goto error_cleanup_backlight;
+
+		drm_dbg_driver(drm, "DM: Registered Backlight device: %s\n", bl_name);
+	} else {
+		drm_warn(drm, "DM: Backlight device registration skipped - DRM backlight not allocated\n");
+	}
 
 	return 0;
+
+error_cleanup_backlight:
+	/* Clean up hardware backlight device if DRM backlight name setting failed */
+	backlight_device_unregister(dm->backlight_dev[aconnector->bl_idx]);
+	dm->backlight_dev[aconnector->bl_idx] = NULL;
+
+	/* Also clean up DRM backlight structure to avoid resource leak */
+	drm_backlight_free(&aconnector->base);
+
+	return r;
 }
 
 static int initialize_plane(struct amdgpu_display_manager *dm,
@@ -7880,6 +7904,10 @@ static void amdgpu_dm_connector_destroy(struct drm_connector *connector)
 	aconnector->dc_sink = NULL;
 
 	drm_dp_cec_unregister_connector(&aconnector->dm_dp_aux.aux);
+	/* DRM core will handle drm_backlight cleanup via:
+	 * drm_connector_unregister() -> drm_backlight_unregister()
+	 * drm_connector_cleanup() -> drm_backlight_free()
+	 */
 	drm_connector_unregister(connector);
 	drm_connector_cleanup(connector);
 	kfree(aconnector->dm_dp_aux.aux.name);
@@ -9129,6 +9157,12 @@ void amdgpu_dm_connector_init_helper(struct amdgpu_display_manager *dm,
 	aconnector->base.state->max_bpc = 16;
 	aconnector->base.state->max_requested_bpc = aconnector->base.state->max_bpc;
 
+	if (connector_type == DRM_MODE_CONNECTOR_eDP) {
+		int r = drm_backlight_alloc(&aconnector->base);
+
+		if (r)
+			drm_err(dm->ddev, "Failed to allocate backlight: %d\n", r);
+	}
 	if (connector_type == DRM_MODE_CONNECTOR_HDMIA) {
 		/* Content Type is currently only implemented for HDMI. */
 		drm_connector_attach_content_type_property(&aconnector->base);
Signature · 1 line
2.43.0
#21 lore raw
In reply to Mario Limonciello
Quoted 22 lines · Mario Limonciello

From: Mario Limonciello (AMD) <[email protected]>

At Display Next Hackfest 2025 we discussed the renewed need for moving brightness control into the DRM connector properties. I've taken the previous efforts from David and Marta, rebased and adjusted for the current kernel.

The legacy sysfs interface is synchronized with the DRM connector (although the scale may be different as DRM connector property is u16).

Later after this has been adopted by enough userspace, it may make sense to configure the legacy sysfs interface to be configurable so that only DRM master controls backlight.

I've done a first implementation with amdgpu with eDP connectors; but conceivably this can be extended to other connectors like DP for displays that can be controlled via DDC as well later.

I have also used DRM review prompts to review this series and fix some bugs which were caught with two different Claude models. The fixes are squashed into the patches.

Quoted 5 lines
Assisted-by Claude Opus
Assisted-by Claude Sonnet

For ease of testing; this series is also available on this branch:
https://git.kernel.org/pub/scm/linux/kernel/git/superm1/linux.git/log/?h=superm1/backlight-property-v3

Hello,

thanks for this work, I am very interested in this progress so I can help you to test / implement more features.

I think you forgot to include the revert of "backlight: Remove notifier" in your series, it can't be applied without it.

I will take a look and see if I can create a VKMS implementation of your work.

Thanks for this work,

Quoted 39 lines

David Rheinsberg (1):
backlight: add kernel-internal backlight API

Mario Limonciello (6):
drm: link connectors to backlight devices
DRM: Add support for client and driver indicating support for
luminance
drm/amd/display: Pass up errors reading actual brightness drm/amd: Indicate driver supports luminance drm/amd/display: Allow backlight registration to fail drm/amd/display: use drm backlight

Marta Lofstedt (1):
backlight: expose the current brightness in the new kernel API

  drivers/gpu/drm/Kconfig                       |   1 +
  drivers/gpu/drm/Makefile                      |   2 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c       |   1 +
  .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c |  88 +++-
  drivers/gpu/drm/drm_atomic_uapi.c             |  24 ++
  drivers/gpu/drm/drm_backlight.c               | 406 ++++++++++++++++++
  drivers/gpu/drm/drm_connector.c               |  12 +
  drivers/gpu/drm/drm_drv.c                     |   8 +
  drivers/gpu/drm/drm_ioctl.c                   |  10 +
  drivers/gpu/drm/drm_mode_config.c             |   7 +
  drivers/gpu/drm/drm_mode_object.c             |  66 ++-
  drivers/gpu/drm/drm_sysfs.c                   |  54 +++
  drivers/video/backlight/backlight.c           |  83 ++++
  include/drm/drm_backlight.h                   |  45 ++
  include/drm/drm_connector.h                   |   8 +
  include/drm/drm_drv.h                         |   7 +
  include/drm/drm_file.h                        |   8 +
  include/drm/drm_mode_config.h                 |   5 +
  include/linux/backlight.h                     |  30 ++
  include/uapi/drm/drm.h                        |  10 +
  20 files changed, 852 insertions(+), 23 deletions(-)

create mode 100644 drivers/gpu/drm/drm_backlight.c create mode 100644 include/drm/drm_backlight.h

#22 lore raw
Quoted 28 lines · Louis Chauvet

[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

Quoted 25 lines · Mario Limonciello

From: Mario Limonciello (AMD) <[email protected]>

At Display Next Hackfest 2025 we discussed the renewed need for moving brightness control into the DRM connector properties.  I've taken the previous efforts from David and Marta, rebased and adjusted for the current kernel.

The legacy sysfs interface is synchronized with the DRM connector (although the scale may be different as DRM connector property is u16).

Later after this has been adopted by enough userspace, it may make sense to configure the legacy sysfs interface to be configurable so that only DRM master controls backlight.

I've done a first implementation with amdgpu with eDP connectors; but conceivably this can be extended to other connectors like DP for displays that can be controlled via DDC as well later.

I have also used DRM review prompts to review this series and fix some bugs which were caught with two different Claude models.  The fixes are squashed into the patches.

Assisted-by Claude Opus
Assisted-by Claude Sonnet
Quoted 7 lines
Quoted 2 lines

For ease of testing; this series is also available on this branch:
https://git.kernel.org/pub/scm/linux/kernel/git/superm1/linux.git/ log/?h=superm1/backlight-property-v3

Hello,

thanks for this work, I am very interested in this progress so I can help you to test / implement more features.

Thanks! I have a few other series I'm juggling in other subsystems, but will try to get another spin this cycle.

Quoted 4 lines

I think you forgot to include the revert of "backlight: Remove notifier" in your series, it can't be applied without it.

Yes - thanks for catching this. It's on my tree at https://git.kernel.org/pub/scm/linux/kernel/git/superm1/linux.git/log/?h=superm1/backlight-property-v3 but I forgot it when I built the series to get that one.

Quoted 2 lines

I will take a look and see if I can create a VKMS implementation of your work.

Cool! Please take a look at the IGT patches I did too if you didn't see them. This should hopefully work once you glue it to VKMS.

https://lore.kernel.org/dri-devel/[email protected]/

Quoted 43 lines

Thanks for this work,

Quoted 39 lines

David Rheinsberg (1):
   backlight: add kernel-internal backlight API

Mario Limonciello (6):
   drm: link connectors to backlight devices
   DRM: Add support for client and driver indicating support for luminance
   drm/amd/display: Pass up errors reading actual brightness drm/amd: Indicate driver supports luminance drm/amd/display: Allow backlight registration to fail drm/amd/display: use drm backlight

Marta Lofstedt (1):
   backlight: expose the current brightness in the new kernel API

  drivers/gpu/drm/Kconfig                       |   1 + drivers/gpu/drm/Makefile                      |   2 + drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c       |   1 + .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c |  88 +++- drivers/gpu/drm/drm_atomic_uapi.c             |  24 ++ drivers/gpu/drm/drm_backlight.c               | 406 ++++++++++++++++++ drivers/gpu/drm/drm_connector.c               |  12 + drivers/gpu/drm/drm_drv.c                     |   8 + drivers/gpu/drm/drm_ioctl.c                   |  10 + drivers/gpu/drm/drm_mode_config.c             |   7 + drivers/gpu/drm/drm_mode_object.c             |  66 ++- drivers/gpu/drm/drm_sysfs.c                   |  54 +++ drivers/video/backlight/backlight.c           |  83 ++++ include/drm/drm_backlight.h                   |  45 ++ include/drm/drm_connector.h                   |   8 + include/drm/drm_drv.h                         |   7 + include/drm/drm_file.h                        |   8 + include/drm/drm_mode_config.h                 |   5 + include/linux/backlight.h                     |  30 ++ include/uapi/drm/drm.h                        |  10 +

  20 files changed, 852 insertions(+), 23 deletions(-)

  create mode 100644 drivers/gpu/drm/drm_backlight.c create mode 100644 include/drm/drm_backlight.h

#23 lore raw
In reply to Mario Limonciello
Quoted 7 lines · Mario Limonciello

From: Mario Limonciello (AMD) <[email protected]>

At Display Next Hackfest 2025 we discussed the renewed need for moving brightness control into the DRM connector properties. I've taken the previous efforts from David and Marta, rebased and adjusted for the current kernel.

Thanks a lot for this!

I've wired it up for mutter but I don't have a machine with AMD graphics and an internal panel, so I can't really test it.

https://gitlab.gnome.org/swick/mutter/-/commits/wip/kms-luminance-prop

I've also noticed a few things while doing so:

1. There isn't a bit of information which tells user space if the property is actually backed by anything
2. A fixed range from 0 to uint16_t max might be problematic for backlights with very few steps

Could maybe fix both of those issues by making the range dynamic to the actual numbers of steps, where zero means that there isn't any backing backlight device.

Quoted 63 lines

The legacy sysfs interface is synchronized with the DRM connector (although the scale may be different as DRM connector property is u16).

Later after this has been adopted by enough userspace, it may make sense to configure the legacy sysfs interface to be configurable so that only DRM master controls backlight.

I've done a first implementation with amdgpu with eDP connectors; but conceivably this can be extended to other connectors like DP for displays that can be controlled via DDC as well later.

I have also used DRM review prompts to review this series and fix some bugs which were caught with two different Claude models. The fixes are squashed into the patches.

Assisted-by Claude Opus
Assisted-by Claude Sonnet

For ease of testing; this series is also available on this branch:
https://git.kernel.org/pub/scm/linux/kernel/git/superm1/linux.git/log/?h=superm1/backlight-property-v3

David Rheinsberg (1):
backlight: add kernel-internal backlight API

Mario Limonciello (6):
drm: link connectors to backlight devices
DRM: Add support for client and driver indicating support for
luminance
drm/amd/display: Pass up errors reading actual brightness drm/amd: Indicate driver supports luminance drm/amd/display: Allow backlight registration to fail drm/amd/display: use drm backlight

Marta Lofstedt (1):
backlight: expose the current brightness in the new kernel API

 drivers/gpu/drm/Kconfig                       |   1 +
 drivers/gpu/drm/Makefile                      |   2 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c       |   1 +
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c |  88 +++-
 drivers/gpu/drm/drm_atomic_uapi.c             |  24 ++
 drivers/gpu/drm/drm_backlight.c               | 406 ++++++++++++++++++
 drivers/gpu/drm/drm_connector.c               |  12 +
 drivers/gpu/drm/drm_drv.c                     |   8 +
 drivers/gpu/drm/drm_ioctl.c                   |  10 +
 drivers/gpu/drm/drm_mode_config.c             |   7 +
 drivers/gpu/drm/drm_mode_object.c             |  66 ++-
 drivers/gpu/drm/drm_sysfs.c                   |  54 +++
 drivers/video/backlight/backlight.c           |  83 ++++
 include/drm/drm_backlight.h                   |  45 ++
 include/drm/drm_connector.h                   |   8 +
 include/drm/drm_drv.h                         |   7 +
 include/drm/drm_file.h                        |   8 +
 include/drm/drm_mode_config.h                 |   5 +
 include/linux/backlight.h                     |  30 ++
 include/uapi/drm/drm.h                        |  10 +
 20 files changed, 852 insertions(+), 23 deletions(-)
 create mode 100644 drivers/gpu/drm/drm_backlight.c
 create mode 100644 include/drm/drm_backlight.h

--
2.53.0

#24 lore raw
Quoted 11 lines · Sebastian Wick
Quoted 7 lines · Mario Limonciello

From: Mario Limonciello (AMD) <[email protected]>

At Display Next Hackfest 2025 we discussed the renewed need for moving brightness control into the DRM connector properties. I've taken the previous efforts from David and Marta, rebased and adjusted for the current kernel.

Thanks a lot for this!

Sure!

Quoted 5 lines

I've wired it up for mutter but I don't have a machine with AMD graphics and an internal panel, so I can't really test it.

https://gitlab.gnome.org/swick/mutter/-/commits/wip/kms-luminance-prop

Awesome! I have been caught up with a few other things so I haven't been able to give this a shot, but wanted to before the hackfest.

But I have never used a dev version of mutter, so can you give me a little hand holding or pointers?

I was able to build/install your branch into /usr/local. I otherwise have GNOME 50 set up on this system. How do I actually "use" the mutter built from your dev branch?

Will picking GNOME session at my login manager pick mutter from /usr/local or do I need to do anything?

Quoted 11 lines

I've also noticed a few things while doing so:

1. There isn't a bit of information which tells user space if the property is actually backed by anything
2. A fixed range from 0 to uint16_t max might be problematic for backlights with very few steps

Could maybe fix both of those issues by making the range dynamic to the actual numbers of steps, where zero means that there isn't any backing backlight device.

I'll play with this idea and see how well it works.

Quoted 66 lines
Quoted 64 lines

The legacy sysfs interface is synchronized with the DRM connector (although the scale may be different as DRM connector property is u16).

Later after this has been adopted by enough userspace, it may make sense to configure the legacy sysfs interface to be configurable so that only DRM master controls backlight.

I've done a first implementation with amdgpu with eDP connectors; but conceivably this can be extended to other connectors like DP for displays that can be controlled via DDC as well later.

I have also used DRM review prompts to review this series and fix some bugs which were caught with two different Claude models. The fixes are squashed into the patches.

Assisted-by Claude Opus
Assisted-by Claude Sonnet

For ease of testing; this series is also available on this branch:
https://git.kernel.org/pub/scm/linux/kernel/git/superm1/linux.git/log/?h=superm1/backlight-property-v3

David Rheinsberg (1):
backlight: add kernel-internal backlight API

Mario Limonciello (6):
drm: link connectors to backlight devices
DRM: Add support for client and driver indicating support for
luminance
drm/amd/display: Pass up errors reading actual brightness drm/amd: Indicate driver supports luminance drm/amd/display: Allow backlight registration to fail drm/amd/display: use drm backlight

Marta Lofstedt (1):
backlight: expose the current brightness in the new kernel API

  drivers/gpu/drm/Kconfig                       |   1 +
  drivers/gpu/drm/Makefile                      |   2 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c       |   1 +
  .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c |  88 +++-
  drivers/gpu/drm/drm_atomic_uapi.c             |  24 ++
  drivers/gpu/drm/drm_backlight.c               | 406 ++++++++++++++++++
  drivers/gpu/drm/drm_connector.c               |  12 +
  drivers/gpu/drm/drm_drv.c                     |   8 +
  drivers/gpu/drm/drm_ioctl.c                   |  10 +
  drivers/gpu/drm/drm_mode_config.c             |   7 +
  drivers/gpu/drm/drm_mode_object.c             |  66 ++-
  drivers/gpu/drm/drm_sysfs.c                   |  54 +++
  drivers/video/backlight/backlight.c           |  83 ++++
  include/drm/drm_backlight.h                   |  45 ++
  include/drm/drm_connector.h                   |   8 +
  include/drm/drm_drv.h                         |   7 +
  include/drm/drm_file.h                        |   8 +
  include/drm/drm_mode_config.h                 |   5 +
  include/linux/backlight.h                     |  30 ++
  include/uapi/drm/drm.h                        |  10 +
  20 files changed, 852 insertions(+), 23 deletions(-)

create mode 100644 drivers/gpu/drm/drm_backlight.c create mode 100644 include/drm/drm_backlight.h

--
2.53.0

#25 lore raw
Quoted 23 lines · Mario Limonciello
Quoted 11 lines · Sebastian Wick
Quoted 7 lines · Mario Limonciello

From: Mario Limonciello (AMD) <[email protected]>

At Display Next Hackfest 2025 we discussed the renewed need for moving brightness control into the DRM connector properties.  I've taken the previous efforts from David and Marta, rebased and adjusted for the current kernel.

Thanks a lot for this!

Sure!

Quoted 5 lines

I've wired it up for mutter but I don't have a machine with AMD graphics and an internal panel, so I can't really test it.

https://gitlab.gnome.org/swick/mutter/-/commits/wip/kms-luminance-prop

Quoted 15 lines

Awesome!  I have been caught up with a few other things so I haven't been able to give this a shot, but wanted to before the hackfest.

But I have never used a dev version of mutter, so can you give me a little hand holding or pointers?

I was able to build/install your branch into /usr/local.  I otherwise have GNOME 50 set up on this system. How do I actually "use" the mutter built from your dev branch?

Will picking GNOME session at my login manager pick mutter from /usr/ local or do I need to do anything?

Quoted 7 lines

I've also noticed a few things while doing so:

1. There isn't a bit of information which tells user space if the property is actually backed by anything
2. A fixed range from 0 to uint16_t max might be problematic for backlights with very few steps

I managed to do this - you tell me if it was an accurate enough test.

1) I built your tree and installed it to /usr/local.
2) I switched to a VT and launched mutter like this.

# dbus-run-session /usr/local/bin/mutter --wayland -- konsole

3) From that konsole session I ran commands like this to change brightness.

# ./tools/gdctl show

I then confirmed the range showed up.

Monitors:

└──Monitor eDP-1 (Built-in display)
   ├──Vendor: BOE
   ├──Product: NE135A1M-NY1
   ├──Serial: 0x00000000
   ├──Current mode
   │   └──[email protected]
   └──Preferences
       └──Backlight:
           ├──active ⇒  True
           ├──min ⇒  655
           ├──max ⇒  65535
           └──value ⇒  22938

Then I did the following to change.

# ./tools/gdctl prefs --monitor "eDP-1" --backlight 12938
# drm_info | grep LUMINANCE
# ./tools/gdctl prefs --monitor "eDP-1" --backlight 22938
# drm_info | grep LUMINANCE

I did observe the brightness visibly changed on the panel as did the value of LUMINANCE in the properties.

Quoted 73 lines
Quoted 4 lines

Could maybe fix both of those issues by making the range dynamic to the actual numbers of steps, where zero means that there isn't any backing backlight device.

I'll play with this idea and see how well it works.

Quoted 66 lines
Quoted 64 lines

The legacy sysfs interface is synchronized with the DRM connector (although the scale may be different as DRM connector property is u16).

Later after this has been adopted by enough userspace, it may make sense to configure the legacy sysfs interface to be configurable so that only DRM master controls backlight.

I've done a first implementation with amdgpu with eDP connectors; but conceivably this can be extended to other connectors like DP for displays that can be controlled via DDC as well later.

I have also used DRM review prompts to review this series and fix some bugs which were caught with two different Claude models.  The fixes are squashed into the patches.

Assisted-by Claude Opus
Assisted-by Claude Sonnet

For ease of testing; this series is also available on this branch:
https://git.kernel.org/pub/scm/linux/kernel/git/superm1/linux.git/ log/?h=superm1/backlight-property-v3

David Rheinsberg (1):
   backlight: add kernel-internal backlight API

Mario Limonciello (6):
   drm: link connectors to backlight devices
   DRM: Add support for client and driver indicating support for luminance
   drm/amd/display: Pass up errors reading actual brightness drm/amd: Indicate driver supports luminance drm/amd/display: Allow backlight registration to fail drm/amd/display: use drm backlight

Marta Lofstedt (1):
   backlight: expose the current brightness in the new kernel API

  drivers/gpu/drm/Kconfig                       |   1 + drivers/gpu/drm/Makefile                      |   2 + drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c       |   1 + .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c |  88 +++- drivers/gpu/drm/drm_atomic_uapi.c             |  24 ++ drivers/gpu/drm/drm_backlight.c               | 406 ++++++++++++++++++ drivers/gpu/drm/drm_connector.c               |  12 + drivers/gpu/drm/drm_drv.c                     |   8 + drivers/gpu/drm/drm_ioctl.c                   |  10 + drivers/gpu/drm/drm_mode_config.c             |   7 + drivers/gpu/drm/drm_mode_object.c             |  66 ++- drivers/gpu/drm/drm_sysfs.c                   |  54 +++ drivers/video/backlight/backlight.c           |  83 ++++ include/drm/drm_backlight.h                   |  45 ++ include/drm/drm_connector.h                   |   8 + include/drm/drm_drv.h                         |   7 + include/drm/drm_file.h                        |   8 + include/drm/drm_mode_config.h                 |   5 + include/linux/backlight.h                     |  30 ++ include/uapi/drm/drm.h                        |  10 +

  20 files changed, 852 insertions(+), 23 deletions(-)

  create mode 100644 drivers/gpu/drm/drm_backlight.c create mode 100644 include/drm/drm_backlight.h

Signature · 1 line
2.53.0