mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 0/2] Backlight control improvements for loongson_laptop
@ 2025-06-05  5:48 Yao Zi
  2025-06-05  5:48 ` [PATCH v2 1/2] platform/loongarch: laptop: Get brightness setting from EC on probe Yao Zi
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Yao Zi @ 2025-06-05  5:48 UTC (permalink / raw)
  To: Huacai Chen, Jianmin Lv, WANG Xuerui
  Cc: linux-kernel, loongarch, Mingcong Bai, Kexy Biscuit, Yao Zi

I've observed strange screen brightness changes on TongFang L860-T2
3A5000 laptop after resumption. It's found that a brightness value that
doesn't match the hardware state before suspension is "restored" for the
EC, causing the strange behavior.

This series fixes the behavior by obtaining EC's brightness setting
instead of using a constant as current brightness on probe.

While digging through the code, I've found some unused,
power-control-related functions in the driver. They're cleaned up and
used to support power control of backlight in the second patch as well.

Changed from v1:
- Reword commit message of PATCH 1
- PATCH 2
  - Always issue a power-on command on probe to ensure the backlight has
    been powered, matching our expectation
  - Cache backlight state in the driver to reduce interaction with EC
- Link to v1: https://lore.kernel.org/loongarch/20250531113851.21426-1-ziyao@disroot.org/

Yao Zi (2):
  platform/loongarch: laptop: Get brightness setting from EC on probe
  platform/loongarch: laptop: Support backlight power control

 drivers/platform/loongarch/loongson-laptop.c | 78 ++++++++++----------
 1 file changed, 39 insertions(+), 39 deletions(-)

-- 
2.49.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 1/2] platform/loongarch: laptop: Get brightness setting from EC on probe
  2025-06-05  5:48 [PATCH v2 0/2] Backlight control improvements for loongson_laptop Yao Zi
@ 2025-06-05  5:48 ` Yao Zi
  2025-06-05  5:48 ` [PATCH v2 2/2] platform/loongarch: laptop: Support backlight power control Yao Zi
  2025-06-06 13:11 ` [PATCH v2 0/2] Backlight control improvements for loongson_laptop Huacai Chen
  2 siblings, 0 replies; 4+ messages in thread
From: Yao Zi @ 2025-06-05  5:48 UTC (permalink / raw)
  To: Huacai Chen, Jianmin Lv, WANG Xuerui
  Cc: linux-kernel, loongarch, Mingcong Bai, Kexy Biscuit, Yao Zi, stable

Previously during probe, 1 is unconditionally taken as current
brightness value and set to props.brightness, which will be considered
as the brightness before suspend and restored to EC on resume. Since a
brightness value of 1 almost never matches EC's state on coldboot (my
laptop's EC defaults to 80), this causes surprising changes of screen
brightness on the first time of resume after coldboot.

Let's get brightness from EC and take it as the current brightness on
probe of the laptop driver to avoid the surprising behavior. Tested on
TongFang L860-T2 3A5000 laptop.

Cc: stable@vger.kernel.org
Fixes: 6246ed09111f ("LoongArch: Add ACPI-based generic laptop driver")
Signed-off-by: Yao Zi <ziyao@disroot.org>
---
 drivers/platform/loongarch/loongson-laptop.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/platform/loongarch/loongson-laptop.c b/drivers/platform/loongarch/loongson-laptop.c
index 99203584949d..828bd62e3596 100644
--- a/drivers/platform/loongarch/loongson-laptop.c
+++ b/drivers/platform/loongarch/loongson-laptop.c
@@ -392,7 +392,7 @@ static int laptop_backlight_register(void)
 	if (!acpi_evalf(hotkey_handle, &status, "ECLL", "d"))
 		return -EIO;
 
-	props.brightness = 1;
+	props.brightness = ec_get_brightness();
 	props.max_brightness = status;
 	props.type = BACKLIGHT_PLATFORM;
 
-- 
2.49.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 2/2] platform/loongarch: laptop: Support backlight power control
  2025-06-05  5:48 [PATCH v2 0/2] Backlight control improvements for loongson_laptop Yao Zi
  2025-06-05  5:48 ` [PATCH v2 1/2] platform/loongarch: laptop: Get brightness setting from EC on probe Yao Zi
@ 2025-06-05  5:48 ` Yao Zi
  2025-06-06 13:11 ` [PATCH v2 0/2] Backlight control improvements for loongson_laptop Huacai Chen
  2 siblings, 0 replies; 4+ messages in thread
From: Yao Zi @ 2025-06-05  5:48 UTC (permalink / raw)
  To: Huacai Chen, Jianmin Lv, WANG Xuerui
  Cc: linux-kernel, loongarch, Mingcong Bai, Kexy Biscuit, Yao Zi

loongson_laptop_turn_{on,off}_backlight() are designed for controlling
power of the backlight, but they aren't really used in the driver
previously.

Unify these two functions since they only differ in arguments passed to
ACPI method, and wire up loongson_laptop_backlight_update() to update
power state of the backlight as well. Tested on TongFang L860-T2 3A5000
laptop.

Signed-off-by: Yao Zi <ziyao@disroot.org>
---
 drivers/platform/loongarch/loongson-laptop.c | 76 ++++++++++----------
 1 file changed, 38 insertions(+), 38 deletions(-)

diff --git a/drivers/platform/loongarch/loongson-laptop.c b/drivers/platform/loongarch/loongson-laptop.c
index 828bd62e3596..fe3f5b24c0a1 100644
--- a/drivers/platform/loongarch/loongson-laptop.c
+++ b/drivers/platform/loongarch/loongson-laptop.c
@@ -56,9 +56,8 @@ static struct input_dev *generic_inputdev;
 static acpi_handle hotkey_handle;
 static struct key_entry hotkey_keycode_map[GENERIC_HOTKEY_MAP_MAX];
 
-int loongson_laptop_turn_on_backlight(void);
-int loongson_laptop_turn_off_backlight(void);
 static int loongson_laptop_backlight_update(struct backlight_device *bd);
+static bool bl_powered;
 
 /* 2. ACPI Helpers and device model */
 
@@ -354,16 +353,41 @@ static int ec_backlight_level(u8 level)
 	return level;
 }
 
+static int ec_backlight_set_power(bool state)
+{
+	int status;
+	union acpi_object arg0 = { ACPI_TYPE_INTEGER };
+	struct acpi_object_list args = { 1, &arg0 };
+
+	arg0.integer.value = state;
+	status = acpi_evaluate_object(NULL, "\\BLSW", &args, NULL);
+	if (ACPI_FAILURE(status)) {
+		pr_info("Loongson lvds error: 0x%x\n", status);
+		return -EIO;
+	}
+
+	return 0;
+}
+
 static int loongson_laptop_backlight_update(struct backlight_device *bd)
 {
-	int lvl = ec_backlight_level(bd->props.brightness);
+	int ret = 0, lvl = ec_backlight_level(bd->props.brightness);
+	bool target_powered = !backlight_is_blank(bd);
 
 	if (lvl < 0)
 		return -EIO;
-	if (ec_set_brightness(lvl))
-		return -EIO;
 
-	return 0;
+	if (target_powered != bl_powered) {
+		ret = ec_backlight_set_power(target_powered);
+		if (ret)
+			return ret;
+
+		bl_powered = target_powered;
+	} else {
+		ret = ec_set_brightness(lvl);
+	}
+
+	return ret;
 }
 
 static int loongson_laptop_get_brightness(struct backlight_device *bd)
@@ -384,7 +408,7 @@ static const struct backlight_ops backlight_laptop_ops = {
 
 static int laptop_backlight_register(void)
 {
-	int status = 0;
+	int status = 0, ret;
 	struct backlight_properties props;
 
 	memset(&props, 0, sizeof(props));
@@ -392,44 +416,20 @@ static int laptop_backlight_register(void)
 	if (!acpi_evalf(hotkey_handle, &status, "ECLL", "d"))
 		return -EIO;
 
+	ret = ec_backlight_set_power(true);
+	if (ret)
+		return ret;
+
+	bl_powered = true;
+
 	props.brightness = ec_get_brightness();
 	props.max_brightness = status;
+	props.power = BACKLIGHT_POWER_ON;
 	props.type = BACKLIGHT_PLATFORM;
 
 	backlight_device_register("loongson_laptop",
 				NULL, NULL, &backlight_laptop_ops, &props);
 
-	return 0;
-}
-
-int loongson_laptop_turn_on_backlight(void)
-{
-	int status;
-	union acpi_object arg0 = { ACPI_TYPE_INTEGER };
-	struct acpi_object_list args = { 1, &arg0 };
-
-	arg0.integer.value = 1;
-	status = acpi_evaluate_object(NULL, "\\BLSW", &args, NULL);
-	if (ACPI_FAILURE(status)) {
-		pr_info("Loongson lvds error: 0x%x\n", status);
-		return -ENODEV;
-	}
-
-	return 0;
-}
-
-int loongson_laptop_turn_off_backlight(void)
-{
-	int status;
-	union acpi_object arg0 = { ACPI_TYPE_INTEGER };
-	struct acpi_object_list args = { 1, &arg0 };
-
-	arg0.integer.value = 0;
-	status = acpi_evaluate_object(NULL, "\\BLSW", &args, NULL);
-	if (ACPI_FAILURE(status)) {
-		pr_info("Loongson lvds error: 0x%x\n", status);
-		return -ENODEV;
-	}
 
 	return 0;
 }
-- 
2.49.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 0/2] Backlight control improvements for loongson_laptop
  2025-06-05  5:48 [PATCH v2 0/2] Backlight control improvements for loongson_laptop Yao Zi
  2025-06-05  5:48 ` [PATCH v2 1/2] platform/loongarch: laptop: Get brightness setting from EC on probe Yao Zi
  2025-06-05  5:48 ` [PATCH v2 2/2] platform/loongarch: laptop: Support backlight power control Yao Zi
@ 2025-06-06 13:11 ` Huacai Chen
  2 siblings, 0 replies; 4+ messages in thread
From: Huacai Chen @ 2025-06-06 13:11 UTC (permalink / raw)
  To: Yao Zi
  Cc: Jianmin Lv, WANG Xuerui, linux-kernel, loongarch, Mingcong Bai,
	Kexy Biscuit

Applied, thanks.

Huacai

On Thu, Jun 5, 2025 at 1:48 PM Yao Zi <ziyao@disroot.org> wrote:
>
> I've observed strange screen brightness changes on TongFang L860-T2
> 3A5000 laptop after resumption. It's found that a brightness value that
> doesn't match the hardware state before suspension is "restored" for the
> EC, causing the strange behavior.
>
> This series fixes the behavior by obtaining EC's brightness setting
> instead of using a constant as current brightness on probe.
>
> While digging through the code, I've found some unused,
> power-control-related functions in the driver. They're cleaned up and
> used to support power control of backlight in the second patch as well.
>
> Changed from v1:
> - Reword commit message of PATCH 1
> - PATCH 2
>   - Always issue a power-on command on probe to ensure the backlight has
>     been powered, matching our expectation
>   - Cache backlight state in the driver to reduce interaction with EC
> - Link to v1: https://lore.kernel.org/loongarch/20250531113851.21426-1-ziyao@disroot.org/
>
> Yao Zi (2):
>   platform/loongarch: laptop: Get brightness setting from EC on probe
>   platform/loongarch: laptop: Support backlight power control
>
>  drivers/platform/loongarch/loongson-laptop.c | 78 ++++++++++----------
>  1 file changed, 39 insertions(+), 39 deletions(-)
>
> --
> 2.49.0
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-06-06 13:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-06-05  5:48 [PATCH v2 0/2] Backlight control improvements for loongson_laptop Yao Zi
2025-06-05  5:48 ` [PATCH v2 1/2] platform/loongarch: laptop: Get brightness setting from EC on probe Yao Zi
2025-06-05  5:48 ` [PATCH v2 2/2] platform/loongarch: laptop: Support backlight power control Yao Zi
2025-06-06 13:11 ` [PATCH v2 0/2] Backlight control improvements for loongson_laptop Huacai Chen

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®