* [RFC PATCH 1/2] backlight: Rename duplicated devices to support dual-backlight setups
@ 2025-05-25 10:40 Pengyu Luo
2025-05-25 10:40 ` [RFC PATCH 2/2] backlight: Improve support for dual backlight with primary/secondary linkage Pengyu Luo
2025-05-26 8:53 ` [RFC PATCH 1/2] backlight: Rename duplicated devices to support dual-backlight setups Jani Nikula
0 siblings, 2 replies; 4+ messages in thread
From: Pengyu Luo @ 2025-05-25 10:40 UTC (permalink / raw)
To: Lee Jones, Daniel Thompson, Jingoo Han, Helge Deller
Cc: dri-devel, linux-fbdev, linux-kernel, Pengyu Luo
When registering a backlight device, if a device with the same name
already exists, append "-secondary" to the new device's name. This is
useful for platforms with dual backlight drivers (e.g. some panels use
dual ktz8866), where both instances need to coexist.
For now, only one secondary instance is supported. If more instances
are needed, this logic can be extended with auto-increment or a more
flexible naming scheme.
Suggested-by: Daniel Thompson <danielt@kernel.org>
Signed-off-by: Pengyu Luo <mitltlatltl@gmail.com>
---
drivers/video/backlight/backlight.c | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c
index 9dc93c5e4..991702f5d 100644
--- a/drivers/video/backlight/backlight.c
+++ b/drivers/video/backlight/backlight.c
@@ -365,7 +365,8 @@ struct backlight_device *backlight_device_register(const char *name,
struct device *parent, void *devdata, const struct backlight_ops *ops,
const struct backlight_properties *props)
{
- struct backlight_device *new_bd;
+ struct backlight_device *new_bd, *prev_bd;
+ const char *new_name = NULL;
int rc;
pr_debug("backlight_device_register: name=%s\n", name);
@@ -377,10 +378,23 @@ struct backlight_device *backlight_device_register(const char *name,
mutex_init(&new_bd->update_lock);
mutex_init(&new_bd->ops_lock);
+ /*
+ * If there is an instance with the same name already, then rename it.
+ * We also can use an auto-increment field, but it seems that there is
+ * no triple or quad case.
+ */
+ prev_bd = backlight_device_get_by_name(name);
+ if (!IS_ERR_OR_NULL(prev_bd)) {
+ new_name = kasprintf(GFP_KERNEL, "%s-secondary", name);
+ if (!new_name)
+ return ERR_PTR(-ENOMEM);
+ put_device(&prev_bd->dev);
+ }
+
new_bd->dev.class = &backlight_class;
new_bd->dev.parent = parent;
new_bd->dev.release = bl_device_release;
- dev_set_name(&new_bd->dev, "%s", name);
+ dev_set_name(&new_bd->dev, "%s", new_name ? new_name : name);
dev_set_drvdata(&new_bd->dev, devdata);
/* Set default properties */
@@ -414,6 +428,8 @@ struct backlight_device *backlight_device_register(const char *name,
list_add(&new_bd->entry, &backlight_dev_list);
mutex_unlock(&backlight_dev_list_mutex);
+ kfree(new_name);
+
return new_bd;
}
EXPORT_SYMBOL(backlight_device_register);
--
2.49.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [RFC PATCH 2/2] backlight: Improve support for dual backlight with primary/secondary linkage
2025-05-25 10:40 [RFC PATCH 1/2] backlight: Rename duplicated devices to support dual-backlight setups Pengyu Luo
@ 2025-05-25 10:40 ` Pengyu Luo
2025-05-26 8:53 ` [RFC PATCH 1/2] backlight: Rename duplicated devices to support dual-backlight setups Jani Nikula
1 sibling, 0 replies; 4+ messages in thread
From: Pengyu Luo @ 2025-05-25 10:40 UTC (permalink / raw)
To: Lee Jones, Daniel Thompson, Jingoo Han, Helge Deller
Cc: dri-devel, linux-fbdev, linux-kernel, Pengyu Luo
This patch enhances dual-backlight handling by explicitly linking
primary and secondary backlight devices using new fields:
- `is_secondary`: Marks if a device is secondary in a pair
- `secondary`: Points to the associated secondary device (if any)
- `primary`: Points to the primary device (for secondary devices)
It also update `backlight_update_status()` to ensure that both primary
and secondary devices are updated together during brightness changes.
This provides a consistent update mechanism in dual-backlight case.
Suggested-by: Daniel Thompson <danielt@kernel.org>
Signed-off-by: Pengyu Luo <mitltlatltl@gmail.com>
---
drivers/video/backlight/backlight.c | 9 +++++-
include/linux/backlight.h | 50 +++++++++++++++++++++++++++--
2 files changed, 56 insertions(+), 3 deletions(-)
diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c
index 991702f5d..2e7b179bc 100644
--- a/drivers/video/backlight/backlight.c
+++ b/drivers/video/backlight/backlight.c
@@ -388,7 +388,6 @@ struct backlight_device *backlight_device_register(const char *name,
new_name = kasprintf(GFP_KERNEL, "%s-secondary", name);
if (!new_name)
return ERR_PTR(-ENOMEM);
- put_device(&prev_bd->dev);
}
new_bd->dev.class = &backlight_class;
@@ -428,6 +427,14 @@ struct backlight_device *backlight_device_register(const char *name,
list_add(&new_bd->entry, &backlight_dev_list);
mutex_unlock(&backlight_dev_list_mutex);
+ /* set them until the secondary device is available */
+ if (prev_bd) {
+ prev_bd->secondary = new_bd;
+ new_bd->primary = prev_bd;
+ new_bd->is_secondary = true;
+ put_device(&prev_bd->dev);
+ }
+
kfree(new_name);
return new_bd;
diff --git a/include/linux/backlight.h b/include/linux/backlight.h
index 10e626db7..cde992e10 100644
--- a/include/linux/backlight.h
+++ b/include/linux/backlight.h
@@ -291,13 +291,42 @@ struct backlight_device {
* @use_count: The number of unblanked displays.
*/
int use_count;
+
+ /**
+ * @is_secondary: Indicates whether this backlight device is secondary.
+ */
+ bool is_secondary;
+
+ /**
+ * @secondary: Pointer to the secondary backlight device.
+ */
+ struct backlight_device *secondary;
+
+ /**
+ * @primary: Pointer to the primary backlight device.
+ *
+ * Non-NULL only for secondary devices.
+ */
+ struct backlight_device *primary;
};
+static inline struct backlight_device *
+to_primary_backlight_device(struct backlight_device *bd)
+{
+ return bd->is_secondary ? bd->primary : bd;
+}
+
+static inline struct backlight_device *
+to_secondary_backlight_device(struct backlight_device *bd)
+{
+ return bd->is_secondary ? bd : bd->secondary;
+}
+
/**
- * backlight_update_status - force an update of the backlight device status
+ * backlight_update_status_single - force an update of the backlight device status
* @bd: the backlight device
*/
-static inline int backlight_update_status(struct backlight_device *bd)
+static inline int backlight_update_status_single(struct backlight_device *bd)
{
int ret = -ENOENT;
@@ -309,6 +338,23 @@ static inline int backlight_update_status(struct backlight_device *bd)
return ret;
}
+/**
+ * backlight_update_status - update primary and secondary backlight devices
+ * @bd: the backlight device
+ */
+static inline int backlight_update_status(struct backlight_device *bd)
+{
+ struct backlight_device *primary = to_primary_backlight_device(bd);
+ struct backlight_device *secondary = to_secondary_backlight_device(bd);
+ int ret;
+
+ ret = backlight_update_status_single(primary);
+ if (!secondary || ret)
+ return ret;
+
+ return backlight_update_status_single(secondary);
+}
+
/**
* backlight_enable - Enable backlight
* @bd: the backlight device to enable
--
2.49.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [RFC PATCH 1/2] backlight: Rename duplicated devices to support dual-backlight setups
2025-05-25 10:40 [RFC PATCH 1/2] backlight: Rename duplicated devices to support dual-backlight setups Pengyu Luo
2025-05-25 10:40 ` [RFC PATCH 2/2] backlight: Improve support for dual backlight with primary/secondary linkage Pengyu Luo
@ 2025-05-26 8:53 ` Jani Nikula
2025-06-02 13:45 ` Pengyu Luo
1 sibling, 1 reply; 4+ messages in thread
From: Jani Nikula @ 2025-05-26 8:53 UTC (permalink / raw)
To: Pengyu Luo, Lee Jones, Daniel Thompson, Jingoo Han, Helge Deller
Cc: dri-devel, linux-fbdev, linux-kernel, Pengyu Luo
On Sun, 25 May 2025, Pengyu Luo <mitltlatltl@gmail.com> wrote:
> When registering a backlight device, if a device with the same name
> already exists, append "-secondary" to the new device's name. This is
> useful for platforms with dual backlight drivers (e.g. some panels use
> dual ktz8866), where both instances need to coexist.
>
> For now, only one secondary instance is supported. If more instances
> are needed, this logic can be extended with auto-increment or a more
> flexible naming scheme.
I think for both patches you should consider adding a new interface for
creating dual backlight scenarios.
For example, this patch turns a driver error (registering two or more
backlights with the same name) into a special use case, patch 2
magically connecting the two, and hiding the problem.
With i915, you could have multiple devices, each with multiple
independent panels with independent backlights. I think accidentally
trying to register more than one backlight with the same name should
remain an error, *unless* you want the special case of combined
backlights.
Similarly, what if you encounter a device with two panels, and two
*independent* ktz8866?
Please be explicit rather than implicit.
BR,
Jani.
>
> Suggested-by: Daniel Thompson <danielt@kernel.org>
> Signed-off-by: Pengyu Luo <mitltlatltl@gmail.com>
> ---
> drivers/video/backlight/backlight.c | 20 ++++++++++++++++++--
> 1 file changed, 18 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c
> index 9dc93c5e4..991702f5d 100644
> --- a/drivers/video/backlight/backlight.c
> +++ b/drivers/video/backlight/backlight.c
> @@ -365,7 +365,8 @@ struct backlight_device *backlight_device_register(const char *name,
> struct device *parent, void *devdata, const struct backlight_ops *ops,
> const struct backlight_properties *props)
> {
> - struct backlight_device *new_bd;
> + struct backlight_device *new_bd, *prev_bd;
> + const char *new_name = NULL;
> int rc;
>
> pr_debug("backlight_device_register: name=%s\n", name);
> @@ -377,10 +378,23 @@ struct backlight_device *backlight_device_register(const char *name,
> mutex_init(&new_bd->update_lock);
> mutex_init(&new_bd->ops_lock);
>
> + /*
> + * If there is an instance with the same name already, then rename it.
> + * We also can use an auto-increment field, but it seems that there is
> + * no triple or quad case.
> + */
> + prev_bd = backlight_device_get_by_name(name);
> + if (!IS_ERR_OR_NULL(prev_bd)) {
> + new_name = kasprintf(GFP_KERNEL, "%s-secondary", name);
> + if (!new_name)
> + return ERR_PTR(-ENOMEM);
> + put_device(&prev_bd->dev);
> + }
> +
> new_bd->dev.class = &backlight_class;
> new_bd->dev.parent = parent;
> new_bd->dev.release = bl_device_release;
> - dev_set_name(&new_bd->dev, "%s", name);
> + dev_set_name(&new_bd->dev, "%s", new_name ? new_name : name);
> dev_set_drvdata(&new_bd->dev, devdata);
>
> /* Set default properties */
> @@ -414,6 +428,8 @@ struct backlight_device *backlight_device_register(const char *name,
> list_add(&new_bd->entry, &backlight_dev_list);
> mutex_unlock(&backlight_dev_list_mutex);
>
> + kfree(new_name);
> +
> return new_bd;
> }
> EXPORT_SYMBOL(backlight_device_register);
--
Jani Nikula, Intel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFC PATCH 1/2] backlight: Rename duplicated devices to support dual-backlight setups
2025-05-26 8:53 ` [RFC PATCH 1/2] backlight: Rename duplicated devices to support dual-backlight setups Jani Nikula
@ 2025-06-02 13:45 ` Pengyu Luo
0 siblings, 0 replies; 4+ messages in thread
From: Pengyu Luo @ 2025-06-02 13:45 UTC (permalink / raw)
To: jani.nikula
Cc: danielt, deller, dri-devel, jingoohan1, lee, linux-fbdev,
linux-kernel, mitltlatltl
On Mon, May 26, 2025 at 4:53 PM Jani Nikula <jani.nikula@linux.intel.com> wrote:
> On Sun, 25 May 2025, Pengyu Luo <mitltlatltl@gmail.com> wrote:
> > When registering a backlight device, if a device with the same name
> > already exists, append "-secondary" to the new device's name. This is
> > useful for platforms with dual backlight drivers (e.g. some panels use
> > dual ktz8866), where both instances need to coexist.
> >
> > For now, only one secondary instance is supported. If more instances
> > are needed, this logic can be extended with auto-increment or a more
> > flexible naming scheme.
>
> I think for both patches you should consider adding a new interface for
> creating dual backlight scenarios.
>
> For example, this patch turns a driver error (registering two or more
> backlights with the same name) into a special use case, patch 2
> magically connecting the two, and hiding the problem.
>
> With i915, you could have multiple devices, each with multiple
> independent panels with independent backlights. I think accidentally
> trying to register more than one backlight with the same name should
> remain an error, *unless* you want the special case of combined
> backlights.
>
> Similarly, what if you encounter a device with two panels, and two
> *independent* ktz8866?
>
> Please be explicit rather than implicit.
>
For i915, I noticed that it renamed the device internally, so I tried
to rename it in the backlight driver.
Indeed, patch 2 may combine independent panels, I was playing with
android tablet, and I ignored it, you had well explained it. Thanks
for pointing out, I will consider adding a new interface.
Best wishes,
Pengyu
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-06-02 13:45 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-25 10:40 [RFC PATCH 1/2] backlight: Rename duplicated devices to support dual-backlight setups Pengyu Luo
2025-05-25 10:40 ` [RFC PATCH 2/2] backlight: Improve support for dual backlight with primary/secondary linkage Pengyu Luo
2025-05-26 8:53 ` [RFC PATCH 1/2] backlight: Rename duplicated devices to support dual-backlight setups Jani Nikula
2025-06-02 13:45 ` Pengyu Luo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).