Skip to contentSkip to conversation

acpi-video: Filter the BCL table for duplicate brightness values

PATCH In review Hans de Goede 3 participants 9 messages Feb 13, 2014 – Feb 15, 2014 ACPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 acpi-video: Filter the BCL table for duplicate brightness values

Some devices have duplicate entries in there brightness levels table, ie on my Dell Latitude E6430 the table looks like this:

[    3.686060] acpi backlight index   0, val 80
[    3.686095] acpi backlight index   1, val 50
[    3.686122] acpi backlight index   2, val 5
[    3.686147] acpi backlight index   3, val 5
[    3.686172] acpi backlight index   4, val 5
[    3.686197] acpi backlight index   5, val 5
[    3.686223] acpi backlight index   6, val 5
[    3.686248] acpi backlight index   7, val 5
[    3.686273] acpi backlight index   8, val 6
[    3.686332] acpi backlight index   9, val 7
[    3.686356] acpi backlight index  10, val 8
[    3.686380] acpi backlight index  11, val 9

etc.

Notice that brightness values 0-5 are all mapped to 5. This means that if userspace writes any value between 0 and 5 to the brightness sysfs attribute and then reads it, it will always return 0, which is somewhat unexpected.

This is a problem for ie gnome-settings-daemon, which uses read-modify-write logic when the users presses the brightness up or down keys. This is done this way to take brightness changes from other sources into account.

On this specific laptop what happens once the brightness has been set to 0, is that gsd reads 0, adds 5, writes 5, and on the next brightness up key press again reads 0, so things get stuck at the lowest brightness setting.

Filtering out the duplicate table entries, makes any write to brightness read back as the written value as one would expect, fixing this.

---
 drivers/acpi/video.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/acpi/video.c +7 -1
index b727d10..ea9d914 100644
@@ -685,6 +685,7 @@ acpi_video_init_brightness(struct acpi_video_device *device)
 	union acpi_object *o;
 	struct acpi_video_device_brightness *br = NULL;
 	int result = -EINVAL;
+	u32 value;
 
 	if (!ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
 		ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available "
@@ -715,7 +716,12 @@ acpi_video_init_brightness(struct acpi_video_device *device)
 			printk(KERN_ERR PREFIX "Invalid data\n");
 			continue;
 		}
-		br->levels[count] = (u32) o->integer.value;
+		value = (u32) o->integer.value;
+		/* Skip duplicate entries */
+		if (count > 2 && br->levels[count - 1] == value)
+			continue;
+
+		br->levels[count] = value;
 
 		if (br->levels[count] > max_level)
 			max_level = br->levels[count];
Signature · 1 line
1.8.5.3
#1 lore raw
Quoted 25 lines · Hans de Goede

Some devices have duplicate entries in there brightness levels table, ie on my Dell Latitude E6430 the table looks like this:

[    3.686060] acpi backlight index   0, val 80
[    3.686095] acpi backlight index   1, val 50
[    3.686122] acpi backlight index   2, val 5
[    3.686147] acpi backlight index   3, val 5
[    3.686172] acpi backlight index   4, val 5
[    3.686197] acpi backlight index   5, val 5
[    3.686223] acpi backlight index   6, val 5
[    3.686248] acpi backlight index   7, val 5
[    3.686273] acpi backlight index   8, val 6
[    3.686332] acpi backlight index   9, val 7
[    3.686356] acpi backlight index  10, val 8
[    3.686380] acpi backlight index  11, val 9

etc.

Notice that brightness values 0-5 are all mapped to 5. This means that if userspace writes any value between 0 and 5 to the brightness sysfs attribute and then reads it, it will always return 0, which is somewhat unexpected.

This is a problem for ie gnome-settings-daemon, which uses read-modify-write logic when the users presses the brightness up or down keys. This is done this way to take brightness changes from other sources into account.

Quoted 8 lines

On this specific laptop what happens once the brightness has been set to 0, is that gsd reads 0, adds 5, writes 5, and on the next brightness up key press again reads 0, so things get stuck at the lowest brightness setting.

Filtering out the duplicate table entries, makes any write to brightness read back as the written value as one would expect, fixing this.

Aaron, can you please have a look at this?

Quoted 31 lines
---
 drivers/acpi/video.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/acpi/video.c +7 -1
index b727d10..ea9d914 100644
@@ -685,6 +685,7 @@ acpi_video_init_brightness(struct acpi_video_device *device)
 	union acpi_object *o;
 	struct acpi_video_device_brightness *br = NULL;
 	int result = -EINVAL;
+	u32 value;
 
 	if (!ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
 		ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available "
@@ -715,7 +716,12 @@ acpi_video_init_brightness(struct acpi_video_device *device)
 			printk(KERN_ERR PREFIX "Invalid data\n");
 			continue;
 		}
-		br->levels[count] = (u32) o->integer.value;
+		value = (u32) o->integer.value;
+		/* Skip duplicate entries */
+		if (count > 2 && br->levels[count - 1] == value)
+			continue;
+
+		br->levels[count] = value;
 
 		if (br->levels[count] > max_level)
 			max_level = br->levels[count];
Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
#2 lore raw
In reply to Hans de Goede
Quoted 2 lines · Hans de Goede

Some devices have duplicate entries in there brightness levels table, ie on my Dell Latitude E6430 the table looks like this:

For reference's purpose, can you please file a bug in kernel bugzilla under the ACPI/Power-Video category and attach the acpidump there? Thanks.

-Aaron

Quoted 62 lines
[    3.686060] acpi backlight index   0, val 80
[    3.686095] acpi backlight index   1, val 50
[    3.686122] acpi backlight index   2, val 5
[    3.686147] acpi backlight index   3, val 5
[    3.686172] acpi backlight index   4, val 5
[    3.686197] acpi backlight index   5, val 5
[    3.686223] acpi backlight index   6, val 5
[    3.686248] acpi backlight index   7, val 5
[    3.686273] acpi backlight index   8, val 6
[    3.686332] acpi backlight index   9, val 7
[    3.686356] acpi backlight index  10, val 8
[    3.686380] acpi backlight index  11, val 9

etc.

Notice that brightness values 0-5 are all mapped to 5. This means that if userspace writes any value between 0 and 5 to the brightness sysfs attribute and then reads it, it will always return 0, which is somewhat unexpected.

This is a problem for ie gnome-settings-daemon, which uses read-modify-write logic when the users presses the brightness up or down keys. This is done this way to take brightness changes from other sources into account.

On this specific laptop what happens once the brightness has been set to 0, is that gsd reads 0, adds 5, writes 5, and on the next brightness up key press again reads 0, so things get stuck at the lowest brightness setting.

Filtering out the duplicate table entries, makes any write to brightness read back as the written value as one would expect, fixing this.

---
 drivers/acpi/video.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/acpi/video.c +7 -1
index b727d10..ea9d914 100644
@@ -685,6 +685,7 @@ acpi_video_init_brightness(struct acpi_video_device *device)
 	union acpi_object *o;
 	struct acpi_video_device_brightness *br = NULL;
 	int result = -EINVAL;
+	u32 value;
 
 	if (!ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
 		ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available "
@@ -715,7 +716,12 @@ acpi_video_init_brightness(struct acpi_video_device *device)
 			printk(KERN_ERR PREFIX "Invalid data\n");
 			continue;
 		}
-		br->levels[count] = (u32) o->integer.value;
+		value = (u32) o->integer.value;
+		/* Skip duplicate entries */
+		if (count > 2 && br->levels[count - 1] == value)
+			continue;
+
+		br->levels[count] = value;
 
 		if (br->levels[count] > max_level)
 			max_level = br->levels[count];
#3 lore raw

Hi,

Quoted 6 lines · Aaron Lu
Quoted 2 lines · Hans de Goede

Some devices have duplicate entries in there brightness levels table, ie on my Dell Latitude E6430 the table looks like this:

For reference's purpose, can you please file a bug in kernel bugzilla under the ACPI/Power-Video category and attach the acpidump there? Thanks.

Done:

https://bugzilla.kernel.org/show_bug.cgi?id=70571

Regards,

Hans

Reviewed-by
#4 lore raw
Quoted 7 lines · Hans de Goede

Hi,

Quoted 4 lines · Aaron Lu
Quoted 2 lines · Hans de Goede

Some devices have duplicate entries in there brightness levels table, ie on my Dell Latitude E6430 the table looks like this:

Quoted 6 lines
Quoted 2 lines

For reference's purpose, can you please file a bug in kernel bugzilla under the ACPI/Power-Video category and attach the acpidump there? Thanks.

Done:

https://bugzilla.kernel.org/show_bug.cgi?id=70571

Thanks, and the patch looks good to me.

-Aaron

#5 lore raw
Quoted 11 lines · Aaron Lu
Quoted 10 lines · Hans de Goede

Hi,

Quoted 6 lines · Aaron Lu
Quoted 2 lines · Hans de Goede

Some devices have duplicate entries in there brightness levels table, ie on my Dell Latitude E6430 the table looks like this:

For reference's purpose, can you please file a bug in kernel bugzilla under the ACPI/Power-Video category and attach the acpidump there? Thanks.

Quoted 6 lines
Quoted 3 lines

Done:

https://bugzilla.kernel.org/show_bug.cgi?id=70571

Thanks, and the patch looks good to me.

OK, thanks!

Is this stable material? If so, which stable kernels should it go into?

Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
#6 lore raw

Hi,

Quoted 14 lines · Rafael J. Wysocki
Quoted 13 lines · Aaron Lu
Quoted 12 lines · Hans de Goede

Hi,

Quoted 6 lines · Aaron Lu
Quoted 2 lines · Hans de Goede

Some devices have duplicate entries in there brightness levels table, ie on my Dell Latitude E6430 the table looks like this:

For reference's purpose, can you please file a bug in kernel bugzilla under the ACPI/Power-Video category and attach the acpidump there? Thanks.

Done:

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

https://bugzilla.kernel.org/show_bug.cgi?id=70571

Thanks, and the patch looks good to me.

OK, thanks!

Is this stable material? If so, which stable kernels should it go into?

Not sure if you're asking me or Aaron. I did not think about this before, but I think adding this to stable makes sense. I'll let Aaron judge how far it should be backported.

Regards,

Hans

#7 lore raw
In reply to Rafael J. Wysocki
Quoted 14 lines · Rafael J. Wysocki
Quoted 13 lines · Aaron Lu
Quoted 12 lines · Hans de Goede

Hi,

Quoted 6 lines · Aaron Lu
Quoted 2 lines · Hans de Goede

Some devices have duplicate entries in there brightness levels table, ie on my Dell Latitude E6430 the table looks like this:

For reference's purpose, can you please file a bug in kernel bugzilla under the ACPI/Power-Video category and attach the acpidump there? Thanks.

Done:

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

https://bugzilla.kernel.org/show_bug.cgi?id=70571

Thanks, and the patch looks good to me.

OK, thanks!

Is this stable material? If so, which stable kernels should it go into?

Yes, all stables I think.

Thanks,
Aaron

#8 lore raw
Quoted 17 lines · Aaron Lu
Quoted 16 lines · Rafael J. Wysocki
Quoted 15 lines · Aaron Lu
Quoted 13 lines · Hans de Goede

Hi,

Quoted 6 lines · Aaron Lu
Quoted 2 lines · Hans de Goede

Some devices have duplicate entries in there brightness levels table, ie on my Dell Latitude E6430 the table looks like this:

For reference's purpose, can you please file a bug in kernel bugzilla under the ACPI/Power-Video category and attach the acpidump there? Thanks.

Done:

https://bugzilla.kernel.org/show_bug.cgi?id=70571

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Thanks, and the patch looks good to me.

OK, thanks!

Is this stable material? If so, which stable kernels should it go into?

Yes, all stables I think.

OK, thanks! Queued up for the next PM/ACPI pull request.

Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.