Module Name:    src
Committed By:   martin
Date:           Thu Jan 20 11:42:22 UTC 2022

Modified Files:
        src/sys/dev/acpi [netbsd-9]: acpi_display.c

Log Message:
Pull up following revision(s) (requested by riastradh in ticket #1399):

        sys/dev/acpi/acpi_display.c: revision 1.21

acpiout(4): Work around firmware that doesn't like some brightnesses.

Instead of just asking for cur - 5 or cur + 5, repeatedly ask for
that increment, check whether we actually made progress in that
direction, and if not keep going with another increment, until we hit
the bounds of brightness levels.

I can't find anything in the ACPI spec about this, but my laptop
seems to have trouble with certain levels: 15, 75, 85, 95.  It goes
in all other increments of 5 from 5 to 100, just not those ones --
acts as if the change just never happened, so with the old logic the
brightness up/down would get stuck unable to move in either
direction.

This should have no impact on machines where the first increment
actually takes.


To generate a diff of this commit:
cvs rdiff -u -r1.16.16.2 -r1.16.16.3 src/sys/dev/acpi/acpi_display.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/acpi_display.c
diff -u src/sys/dev/acpi/acpi_display.c:1.16.16.2 src/sys/dev/acpi/acpi_display.c:1.16.16.3
--- src/sys/dev/acpi/acpi_display.c:1.16.16.2	Tue Jun 30 18:45:18 2020
+++ src/sys/dev/acpi/acpi_display.c	Thu Jan 20 11:42:22 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_display.c,v 1.16.16.2 2020/06/30 18:45:18 martin Exp $	*/
+/*	$NetBSD: acpi_display.c,v 1.16.16.3 2022/01/20 11:42:22 martin Exp $	*/
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_display.c,v 1.16.16.2 2020/06/30 18:45:18 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_display.c,v 1.16.16.3 2022/01/20 11:42:22 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -1010,7 +1010,8 @@ acpidisp_out_increase_brightness_callbac
 {
 	struct acpidisp_out_softc *osc = arg;
 	struct acpidisp_brctl *bc = osc->sc_brctl;
-	uint8_t lo, up;
+	uint8_t max, lo, up;
+	int cur;
 
 	if (bc == NULL) {
 		/* Fallback to pmf(9). */
@@ -1019,16 +1020,21 @@ acpidisp_out_increase_brightness_callbac
 	}
 
 	mutex_enter(osc->sc_mtx);
-
-	(void)acpidisp_get_brightness(osc, &bc->bc_current);
-
-	acpidisp_array_search(bc->bc_level, bc->bc_level_count,
-	    bc->bc_current + ACPI_DISP_BRCTL_STEP, &lo, &up);
-
-	bc->bc_current = up;
-	(void)acpidisp_set_brightness(osc, bc->bc_current);
-
-	mutex_exit(osc->sc_mtx);
+	max = bc->bc_level[bc->bc_level_count - 1];
+	if (acpidisp_get_brightness(osc, &bc->bc_current))
+		goto out;
+	for (cur = bc->bc_current; (cur += ACPI_DISP_BRCTL_STEP) <= max;) {
+		acpidisp_array_search(bc->bc_level, bc->bc_level_count, cur,
+		    &lo, &up);
+		bc->bc_current = up;
+		if (acpidisp_set_brightness(osc, bc->bc_current))
+			goto out;
+		if (acpidisp_get_brightness(osc, &bc->bc_current))
+			goto out;
+		if (bc->bc_current >= cur)
+			break;
+	}
+out:	mutex_exit(osc->sc_mtx);
 }
 
 static void
@@ -1036,7 +1042,8 @@ acpidisp_out_decrease_brightness_callbac
 {
 	struct acpidisp_out_softc *osc = arg;
 	struct acpidisp_brctl *bc = osc->sc_brctl;
-	uint8_t lo, up;
+	uint8_t min, lo, up;
+	int cur;
 
 	if (bc == NULL) {
 		/* Fallback to pmf(9). */
@@ -1045,16 +1052,21 @@ acpidisp_out_decrease_brightness_callbac
 	}
 
 	mutex_enter(osc->sc_mtx);
-
-	(void)acpidisp_get_brightness(osc, &bc->bc_current);
-
-	acpidisp_array_search(bc->bc_level, bc->bc_level_count,
-	    bc->bc_current - ACPI_DISP_BRCTL_STEP, &lo, &up);
-
-	bc->bc_current = lo;
-	(void)acpidisp_set_brightness(osc, bc->bc_current);
-
-	mutex_exit(osc->sc_mtx);
+	min = bc->bc_level[0];
+	if (acpidisp_get_brightness(osc, &bc->bc_current))
+		goto out;
+	for (cur = bc->bc_current; (cur -= ACPI_DISP_BRCTL_STEP) >= min;) {
+		acpidisp_array_search(bc->bc_level, bc->bc_level_count, cur,
+		    &lo, &up);
+		bc->bc_current = lo;
+		if (acpidisp_set_brightness(osc, bc->bc_current))
+			goto out;
+		if (acpidisp_get_brightness(osc, &bc->bc_current))
+			goto out;
+		if (bc->bc_current <= cur)
+			break;
+	}
+out:	mutex_exit(osc->sc_mtx);
 }
 
 static void

Reply via email to