From: Mario Limonciello <mario.limonciello@amd.com>
To: Louis Chauvet <louis.chauvet@bootlin.com>,
dri-devel@lists.freedesktop.org
Cc: harry.wentland@amd.com, Xaver Hugl <xaver.hugl@gmail.com>,
amd-gfx@lists.freedesktop.org,
David Herrmann <dh.herrmann@gmail.com>,
Marta Lofstedt <marta.lofstedt@intel.com>
Subject: Re: [PATCH v3 1/8] backlight: add kernel-internal backlight API
Date: Mon, 4 May 2026 12:55:26 -0500 [thread overview]
Message-ID: <d2e0852e-006d-4d30-b754-7fe597b9b4f0@amd.com> (raw)
In-Reply-To: <b1a09658-ff19-4331-a184-b1a5457b7f69@bootlin.com>
On 5/4/26 08:55, Louis Chauvet wrote:
> [You don't often get email from louis.chauvet@bootlin.com. Learn why
> this is important at https://aka.ms/LearnAboutSenderIdentification ]
>
> On 4/25/26 00:09, Mario Limonciello wrote:
>> From: David Herrmann <dh.herrmann@gmail.com>
>>
>> So far backlights have only been controlled via sysfs. However, sysfs is
>> not a proper user-space API for runtime modifications, and never was
>> intended to provide such. The DRM drivers are now prepared to provide
>> such a backlight link so user-space can control backlight via DRM
>> connector properties. This allows us to employ the same access-management
>> we use for mode-setting.
>>
>> This patch adds few kernel-internal backlight helpers so we can modify
>> backlights from within DRM.
>>
>> Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
>>
>> V2: Marta Lofstedt <marta.lofstedt@intel.com>
>> - rebase
>> - minor edit for checkpatch warning
>>
>> Signed-off-by: Marta Lofstedt <marta.lofstedt@intel.com>
>>
>> V3: Mario Limonciello <mario.limonciello@amd.com>
>> - rebase
>> - Use guard(mutex)
>>
>> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
>> ---
>> drivers/video/backlight/backlight.c | 60 +++++++++++++++++++++++++++++
>> include/linux/backlight.h | 16 ++++++++
>> 2 files changed, 76 insertions(+)
>>
>> diff --git a/drivers/video/backlight/backlight.c b/drivers/video/
>> backlight/backlight.c
>> index ab87a5e3dbf70..c3673bee6d9cf 100644
>> --- a/drivers/video/backlight/backlight.c
>> +++ b/drivers/video/backlight/backlight.c
>> @@ -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);
>>
>
> Hello,
>
> I think this function can be repalced with backlight_device_get_by_name.
Yes; good call.
>
>> +/**
>> + * 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);
>
> 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?
>> + 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);
> }
OK.
>
>> /**
>> * backlight_register_notifier - get notified of backlight
>> (un)registration
>> * @nb: notifier block with the notifier to call on backlight
>> (un)registration
>> diff --git a/include/linux/backlight.h b/include/linux/backlight.h
>> index d905173c7f73c..7e4fee65fddd9 100644
>> --- a/include/linux/backlight.h
>> +++ b/include/linux/backlight.h
>> @@ -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);
>> +}
>> +
> Most of the kernel use _put and _get functions, I think it could be nice
> to keep the same naming.
OK.
next prev parent reply other threads:[~2026-05-04 17:55 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-24 22:09 [PATCH v3 0/8] Add support for a DRM backlight capability Mario Limonciello
2026-04-24 22:09 ` [PATCH v3 1/8] backlight: add kernel-internal backlight API Mario Limonciello
2026-05-04 13:55 ` Louis Chauvet
2026-05-04 17:55 ` Mario Limonciello [this message]
2026-05-08 0:53 ` Louis Chauvet
2026-04-24 22:09 ` [PATCH v3 2/8] backlight: expose the current brightness in the new kernel API Mario Limonciello
2026-05-04 13:55 ` Louis Chauvet
2026-05-04 17:46 ` Mario Limonciello
2026-04-24 22:09 ` [PATCH v3 3/8] drm: link connectors to backlight devices Mario Limonciello
2026-04-25 12:41 ` Dmitry Baryshkov
2026-04-25 14:40 ` Mario Limonciello
2026-04-25 21:46 ` Dmitry Baryshkov
2026-04-24 22:09 ` [PATCH v3 4/8] DRM: Add support for client and driver indicating support for luminance Mario Limonciello
2026-04-25 12:17 ` Dmitry Baryshkov
2026-04-25 14:45 ` Mario Limonciello
2026-04-25 22:38 ` Dmitry Baryshkov
2026-05-08 0:53 ` Louis Chauvet
2026-04-24 22:09 ` [PATCH v3 5/8] drm/amd/display: Pass up errors reading actual brightness Mario Limonciello
2026-04-24 22:09 ` [PATCH v3 6/8] drm/amd: Indicate driver supports luminance Mario Limonciello
2026-04-24 22:09 ` [PATCH v3 7/8] drm/amd/display: Allow backlight registration to fail Mario Limonciello
2026-04-24 22:09 ` [PATCH v3 8/8] drm/amd/display: use drm backlight Mario Limonciello
2026-05-04 13:55 ` [PATCH v3 0/8] Add support for a DRM backlight capability Louis Chauvet
2026-05-04 18:21 ` Mario Limonciello
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d2e0852e-006d-4d30-b754-7fe597b9b4f0@amd.com \
--to=mario.limonciello@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=dh.herrmann@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=harry.wentland@amd.com \
--cc=louis.chauvet@bootlin.com \
--cc=marta.lofstedt@intel.com \
--cc=xaver.hugl@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox