mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Pengyu Luo <mitltlatltl@gmail.com>
To: Lee Jones <lee@kernel.org>, Daniel Thompson <danielt@kernel.org>,
	Jingoo Han <jingoohan1@gmail.com>, Helge Deller <deller@gmx.de>
Cc: dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, Pengyu Luo <mitltlatltl@gmail.com>
Subject: [RFC PATCH 2/2] backlight: Improve support for dual backlight with primary/secondary linkage
Date: Sun, 25 May 2025 18:40:22 +0800	[thread overview]
Message-ID: <20250525104022.1326997-2-mitltlatltl@gmail.com> (raw)
In-Reply-To: <20250525104022.1326997-1-mitltlatltl@gmail.com>

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


  reply	other threads:[~2025-05-25 10:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2025-05-26  8:53 ` Jani Nikula
2025-06-02 13:45   ` Pengyu Luo

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=20250525104022.1326997-2-mitltlatltl@gmail.com \
    --to=mitltlatltl@gmail.com \
    --cc=danielt@kernel.org \
    --cc=deller@gmx.de \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jingoohan1@gmail.com \
    --cc=lee@kernel.org \
    --cc=linux-fbdev@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®