Skip to contentSkip to conversation

leds: class: Add new optional brightness_hw_changed

PATCH In review Hans de Goede 5 participants 16 messages Jan 25, 2017 – Jan 28, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v6 1/4 leds: class: Add new optional brightness_hw_changed

Hi,

Here is v6 of my patch(es) to allow userspace to get notified about hw initiated brightness changes.

As agreed upon before the API has been changed to introduce a new hw_brightness_changed attribute for this.

This has been tested on a Dell XPS 15, I'm travelling atm so I've not tested the new version of the thinkpad patch.

The platform patches here are included mostly as an example of users of the new API, they are currently not intended for merging as we first need to have the LED class API for this merged.

Regards,

Hans

#1 lore raw

PATCH v6 1/4 leds: class: Add new optional brightness_hw_changed attribute

Some LEDs may have their brightness level changed autonomously (outside of kernel control) by hardware / firmware. This commit adds support for an optional brightness_hw_changed attribute to signal such changes to userspace (if a driver can detect them):

What: /sys/class/leds/<led>/brightness_hw_changed
Date: January 2017
KernelVersion: 4.11
Description:
Last hardware set brightness level for this LED. Some LEDs may be changed autonomously by hardware/firmware. Only LEDs where this happens and the driver can detect this, will have this file.

This file supports poll() to detect when the hardware changes the brightness.

Reading this file will return the last brightness level set by the hardware, this may be different from the current brightness.

Drivers which want to support this, simply add LED_BRIGHT_HW_CHANGED to their flags field and call led_classdev_notify_brightness_hw_changed() with the hardware set brightness when they detect a hardware / firmware triggered brightness change.

---
Changes in v6:
-New patch in v6 of this set, replacing previous trigger based API

---
 Documentation/ABI/testing/sysfs-class-led | 16 +++++++++
 drivers/leds/led-class.c                  | 57 +++++++++++++++++++++++++++++++
 include/linux/leds.h                      |  8 +++++
 3 files changed, 81 insertions(+)
Documentation/ABI/testing/sysfs-class-led +16 -0
index 491cdee..9f6e75d 100644
@@ -23,6 +23,22 @@ Description:
 		If the LED does not support different brightness levels, this
 		should be 1.
 
+What:		/sys/class/leds/<led>/brightness_hw_changed
+Date:		January 2017
+KernelVersion:	4.11
+Description:
+		Last hardware set brightness level for this LED. Some LEDs
+		may be changed autonomously by hardware/firmware. Only LEDs
+		where this happens and the driver can detect this, will have
+		this file.
+
+		This file supports poll() to detect when the hardware changes
+		the brightness.
+
+		Reading this file will return the last brightness level set
+		by the hardware, this may be different from the current
+		brightness.
+
 What:		/sys/class/leds/<led>/trigger
 Date:		March 2006
 KernelVersion:	2.6.17
drivers/leds/led-class.c +57 -0

75 lines not on this page · raw message

include/linux/leds.h +8 -0
index 569cb53..aa452c8 100644
@@ -13,6 +13,7 @@
 #define __LINUX_LEDS_H_INCLUDED
 
 #include <linux/device.h>
+#include <linux/kernfs.h>
 #include <linux/list.h>
 #include <linux/mutex.h>
 #include <linux/rwsem.h>
@@ -35,6 +36,7 @@ struct led_classdev {
 	const char		*name;
 	enum led_brightness	 brightness;
 	enum led_brightness	 max_brightness;
+	enum led_brightness	 brightness_hw_changed;
 	int			 flags;
 
 	/* Lower 16 bits reflect status */
@@ -46,6 +48,7 @@ struct led_classdev {
 #define LED_DEV_CAP_FLASH	(1 << 18)
 #define LED_HW_PLUGGABLE	(1 << 19)
 #define LED_PANIC_INDICATOR	(1 << 20)
+#define LED_BRIGHT_HW_CHANGED	(1 << 21)
 
 	/* set_brightness_work / blink_timer flags, atomic, private. */
 	unsigned long		work_flags;
@@ -99,6 +102,9 @@ struct led_classdev {
 	struct work_struct	set_brightness_work;
 	int			delayed_set_value;
 
+	/* For LEDs with brightness_hw_changed sysfs attribute */
+	struct kernfs_node	*brightness_hw_changed_kn;
+
 #ifdef CONFIG_LEDS_TRIGGERS
 	/* Protects the trigger data below */
 	struct rw_semaphore	 trigger_lock;
@@ -123,6 +129,8 @@ extern void devm_led_classdev_unregister(struct device *parent,
 					 struct led_classdev *led_cdev);
 extern void led_classdev_suspend(struct led_classdev *led_cdev);
 extern void led_classdev_resume(struct led_classdev *led_cdev);
+extern void led_classdev_notify_brightness_hw_changed(
+	struct led_classdev *led_cdev, enum led_brightness brightness);
 
 /**
  * led_blink_set - set blinking with software fallback
Signature · 1 line
2.9.3
#2 lore raw

Re: [PATCH v6 1/4] leds: class: Add new optional brightness_hw_changed attribute

Quoted 21 lines · On Wednesday 25 January 2017 17:11:27 Hans de Goede wrote:

Some LEDs may have their brightness level changed autonomously (outside of kernel control) by hardware / firmware. This commit adds support for an optional brightness_hw_changed attribute to signal such changes to userspace (if a driver can detect them):

What: /sys/class/leds/<led>/brightness_hw_changed
Date: January 2017
KernelVersion: 4.11
Description:
Last hardware set brightness level for this LED. Some LEDs may be changed autonomously by hardware/firmware. Only LEDs where this happens and the driver can detect this, will have this file.

This file supports poll() to detect when the hardware changes the brightness.

Reading this file will return the last brightness level set by the hardware, this may be different from the current brightness.

Quoted 6 lines

Drivers which want to support this, simply add LED_BRIGHT_HW_CHANGED to their flags field and call led_classdev_notify_brightness_hw_changed() with the hardware set brightness when they detect a hardware / firmware triggered brightness change.

Just speculation: What about using name 'actual_brightness'? It provides same output on read as actual_brightness from /sys/class/backlight/.

Signature · 2 lines
Pali Rohár
[email protected]
#3 lore raw

Re: [PATCH v6 1/4] leds: class: Add new optional brightness_hw_changed attribute

Quoted 27 lines · Pali Rohár
Quoted 26 lines · On Wednesday 25 January 2017 17:11:27 Hans de Goede wrote:

Some LEDs may have their brightness level changed autonomously (outside of kernel control) by hardware / firmware. This commit adds support for an optional brightness_hw_changed attribute to signal such changes to userspace (if a driver can detect them):

What: /sys/class/leds/<led>/brightness_hw_changed
Date: January 2017
KernelVersion: 4.11
Description:
Last hardware set brightness level for this LED. Some LEDs may be changed autonomously by hardware/firmware. Only LEDs where this happens and the driver can detect this, will have this file.

This file supports poll() to detect when the hardware changes the brightness.

Reading this file will return the last brightness level set by the hardware, this may be different from the current brightness.

Drivers which want to support this, simply add LED_BRIGHT_HW_CHANGED to their flags field and call led_classdev_notify_brightness_hw_changed() with the hardware set brightness when they detect a hardware / firmware triggered brightness change.

Quoted 4 lines
Quoted 1 line

Just speculation: What about using name 'actual_brightness'? It provides same output on read as actual_brightness from /sys/class/backlight/.

This name is ambiguous. Propagating it to the LED subsystem only because it exists in backlight is not sufficient argument IMHO.

Signature · 2 lines
Best regards,
Jacek Anaszewski
#4 lore raw

Re: [PATCH v6 1/4] leds: class: Add new optional brightness_hw_changed attribute

Quoted 16 lines · On Wednesday 25 January 2017 22:35:53 Jacek Anaszewski wrote:
Quoted 15 lines · Pali Rohár
Quoted 14 lines · On Wednesday 25 January 2017 17:11:27 Hans de Goede wrote:

Some LEDs may have their brightness level changed autonomously (outside of kernel control) by hardware / firmware. This commit adds support for an optional brightness_hw_changed attribute to signal such changes to userspace (if a driver can detect them):

What: /sys/class/leds/<led>/brightness_hw_changed
Date: January 2017
KernelVersion: 4.11
Description:
Last hardware set brightness level for this LED. Some LEDs may be changed autonomously by hardware/firmware. Only LEDs where this happens and the driver can detect this, will have this file.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

This file supports poll() to detect when the hardware changes the brightness.

Reading this file will return the last brightness level set by the hardware, this may be different from the current brightness.

In which situation this attribute may be different?

I think some information should be present in this description...

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Drivers which want to support this, simply add LED_BRIGHT_HW_CHANGED to their flags field and call led_classdev_notify_brightness_hw_changed() with the hardware set brightness when they detect a hardware / firmware triggered brightness change.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Just speculation: What about using name 'actual_brightness'? It provides same output on read as actual_brightness from /sys/class/backlight/.

This name is ambiguous. Propagating it to the LED subsystem only because it exists in backlight is not sufficient argument IMHO.

I thought that having same name could help userspace and also to have consistency between similar subsystems. But ok, that was just my speculation.

I have just one small suggestion in current name "brightness_hw_changed". As it provides regular read() capability I would suggest to not indicate "activity" (changed) in name...

Signature · 2 lines
Pali Rohár
[email protected]
#5 lore raw

Re: [PATCH v6 1/4] leds: class: Add new optional brightness_hw_changed attribute

Quoted 20 lines · Pali Rohár
Quoted 19 lines · On Wednesday 25 January 2017 22:35:53 Jacek Anaszewski wrote:
Quoted 18 lines · Pali Rohár
Quoted 17 lines · On Wednesday 25 January 2017 17:11:27 Hans de Goede wrote:

Some LEDs may have their brightness level changed autonomously (outside of kernel control) by hardware / firmware. This commit adds support for an optional brightness_hw_changed attribute to signal such changes to userspace (if a driver can detect them):

What: /sys/class/leds/<led>/brightness_hw_changed
Date: January 2017
KernelVersion: 4.11
Description:
Last hardware set brightness level for this LED. Some LEDs may be changed autonomously by hardware/firmware. Only LEDs where this happens and the driver can detect this, will have this file.

This file supports poll() to detect when the hardware changes the brightness.

Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Reading this file will return the last brightness level set by the hardware, this may be different from the current brightness.

In which situation this attribute may be different?

I think some information should be present in this description...

The first sentence in description says:

"Last hardware set brightness level for this LED" - i.e. it may be different from the _actual_ brightness, which could have been set by LED class driver.

Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 6 lines

Drivers which want to support this, simply add LED_BRIGHT_HW_CHANGED to their flags field and call led_classdev_notify_brightness_hw_changed() with the hardware set brightness when they detect a hardware / firmware triggered brightness change.

Just speculation: What about using name 'actual_brightness'? It provides same output on read as actual_brightness from /sys/class/backlight/.

Quoted 6 lines
Quoted 2 lines

This name is ambiguous. Propagating it to the LED subsystem only because it exists in backlight is not sufficient argument IMHO.

I thought that having same name could help userspace and also to have consistency between similar subsystems. But ok, that was just my speculation.

Please also note the "actual" would be ambiguous especially in view of my above explanation.

Quoted 3 lines

I have just one small suggestion in current name "brightness_hw_changed". As it provides regular read() capability I would suggest to not indicate "activity" (changed) in name...

Without "changed" one could think that brightness file (the one we have currently) doesn't reflect hardware state.

Signature · 2 lines
Best regards,
Jacek Anaszewski
#6 lore raw

Re: [PATCH v6 1/4] leds: class: Add new optional brightness_hw_changed attribute

Quoted 55 lines · Jacek Anaszewski
Quoted 20 lines · Pali Rohár
Quoted 19 lines · On Wednesday 25 January 2017 22:35:53 Jacek Anaszewski wrote:
Quoted 18 lines · Pali Rohár
Quoted 17 lines · On Wednesday 25 January 2017 17:11:27 Hans de Goede wrote:

Some LEDs may have their brightness level changed autonomously (outside of kernel control) by hardware / firmware. This commit adds support for an optional brightness_hw_changed attribute to signal such changes to userspace (if a driver can detect them):

What: /sys/class/leds/<led>/brightness_hw_changed
Date: January 2017
KernelVersion: 4.11
Description:
Last hardware set brightness level for this LED. Some LEDs may be changed autonomously by hardware/firmware. Only LEDs where this happens and the driver can detect this, will have this file.

This file supports poll() to detect when the hardware changes the brightness.

Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Reading this file will return the last brightness level set by the hardware, this may be different from the current brightness.

In which situation this attribute may be different?

I think some information should be present in this description...

The first sentence in description says:

"Last hardware set brightness level for this LED" - i.e. it may be different from the _actual_ brightness, which could have been set by LED class driver.

Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 6 lines

Drivers which want to support this, simply add LED_BRIGHT_HW_CHANGED to their flags field and call led_classdev_notify_brightness_hw_changed() with the hardware set brightness when they detect a hardware / firmware triggered brightness change.

Just speculation: What about using name 'actual_brightness'? It provides same output on read as actual_brightness from /sys/class/backlight/.

Quoted 6 lines
Quoted 2 lines

This name is ambiguous. Propagating it to the LED subsystem only because it exists in backlight is not sufficient argument IMHO.

I thought that having same name could help userspace and also to have consistency between similar subsystems. But ok, that was just my speculation.

Please also note the "actual" would be ambiguous especially in view of my above explanation.

Quoted 6 lines
Quoted 3 lines

I have just one small suggestion in current name "brightness_hw_changed". As it provides regular read() capability I would suggest to not indicate "activity" (changed) in name...

Without "changed" one could think that brightness file (the one we have currently) doesn't reflect hardware state.

A new, possibly better name has just come to my mind. Since the file has two purposes: to notify about brightness changes made by hardware and caching last such a change, then we could call it hw_brightness_cache. Now there is no activity in the file name.

Signature · 2 lines
Best regards,
Jacek Anaszewski
#7 lore raw

Re: [PATCH v6 1/4] leds: class: Add new optional brightness_hw_changed attribute

Hi,

Quoted 60 lines · Jacek Anaszewski
Quoted 59 lines · Jacek Anaszewski
Quoted 20 lines · Pali Rohár
Quoted 19 lines · On Wednesday 25 January 2017 22:35:53 Jacek Anaszewski wrote:
Quoted 18 lines · Pali Rohár
Quoted 17 lines · On Wednesday 25 January 2017 17:11:27 Hans de Goede wrote:

Some LEDs may have their brightness level changed autonomously (outside of kernel control) by hardware / firmware. This commit adds support for an optional brightness_hw_changed attribute to signal such changes to userspace (if a driver can detect them):

What: /sys/class/leds/<led>/brightness_hw_changed
Date: January 2017
KernelVersion: 4.11
Description:
Last hardware set brightness level for this LED. Some LEDs may be changed autonomously by hardware/firmware. Only LEDs where this happens and the driver can detect this, will have this file.

This file supports poll() to detect when the hardware changes the brightness.

Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Reading this file will return the last brightness level set by the hardware, this may be different from the current brightness.

In which situation this attribute may be different?

I think some information should be present in this description...

The first sentence in description says:

"Last hardware set brightness level for this LED" - i.e. it may be different from the _actual_ brightness, which could have been set by LED class driver.

Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 6 lines

Drivers which want to support this, simply add LED_BRIGHT_HW_CHANGED to their flags field and call led_classdev_notify_brightness_hw_changed() with the hardware set brightness when they detect a hardware / firmware triggered brightness change.

Just speculation: What about using name 'actual_brightness'? It provides same output on read as actual_brightness from /sys/class/backlight/.

Quoted 6 lines
Quoted 2 lines

This name is ambiguous. Propagating it to the LED subsystem only because it exists in backlight is not sufficient argument IMHO.

I thought that having same name could help userspace and also to have consistency between similar subsystems. But ok, that was just my speculation.

Please also note the "actual" would be ambiguous especially in view of my above explanation.

Quoted 3 lines

I have just one small suggestion in current name "brightness_hw_changed". As it provides regular read() capability I would suggest to not indicate "activity" (changed) in name...

Quoted 7 lines
Quoted 2 lines

Without "changed" one could think that brightness file (the one we have currently) doesn't reflect hardware state.

A new, possibly better name has just come to my mind. Since the file has two purposes: to notify about brightness changes made by hardware and caching last such a change, then we could call it hw_brightness_cache. Now there is no activity in the file name.

I must say I don't like that name the "cache" bit suggests that the hardware is caching system, which is not the case. As for having an acivity in the name, there is no rule against that.

Regards,

Hans

Quoted 1 line
#8 lore raw

Re: [PATCH v6 1/4] leds: class: Add new optional brightness_hw_changed attribute

In reply to Hans de Goede

H Hans,

Thanks for the patch. I have a few comments below.

Quoted 49 lines · Hans de Goede

Some LEDs may have their brightness level changed autonomously (outside of kernel control) by hardware / firmware. This commit adds support for an optional brightness_hw_changed attribute to signal such changes to userspace (if a driver can detect them):

What: /sys/class/leds/<led>/brightness_hw_changed
Date: January 2017
KernelVersion: 4.11
Description:
Last hardware set brightness level for this LED. Some LEDs may be changed autonomously by hardware/firmware. Only LEDs where this happens and the driver can detect this, will have this file.

This file supports poll() to detect when the hardware changes the brightness.

Reading this file will return the last brightness level set by the hardware, this may be different from the current brightness.

Drivers which want to support this, simply add LED_BRIGHT_HW_CHANGED to their flags field and call led_classdev_notify_brightness_hw_changed() with the hardware set brightness when they detect a hardware / firmware triggered brightness change.

---
Changes in v6:

(quoted diff) +0 -2
-New patch in v6 of this set, replacing previous trigger based API
---
 Documentation/ABI/testing/sysfs-class-led | 16 +++++++++
 drivers/leds/led-class.c                  | 57 +++++++++++++++++++++++++++++++
 include/linux/leds.h                      |  8 +++++
 3 files changed, 81 insertions(+)
Documentation/ABI/testing/sysfs-class-led +5 -0
index 491cdee..9f6e75d 100644
@@ -23,6 +23,22 @@ Description:
 		If the LED does not support different brightness levels, this
 		should be 1.
 
+What:		/sys/class/leds/<led>/brightness_hw_changed
+Date:		January 2017
+KernelVersion:	4.11
+Description:
+		Last hardware set brightness level for this LED. Some LEDs

Documentation/ABI/testing/sysfs-class-led Description: · line 40

Quoted 10 lines
Documentation/ABI/testing/sysfs-class-led +10 -0
+		may be changed autonomously by hardware/firmware. Only LEDs
+		where this happens and the driver can detect this, will have
+		this file.
+
+		This file supports poll() to detect when the hardware changes
+		the brightness.
+
+		Reading this file will return the last brightness level set
+		by the hardware, this may be different from the current
+		brightness.

Let's return -ENODATA when no such an event occurred till the moment of file reading.

Quoted 99 lines
Documentation/ABI/testing/sysfs-class-led +1 -0
+
 What:		/sys/class/leds/<led>/trigger
 Date:		March 2006
 KernelVersion:	2.6.17
drivers/leds/led-class.c +56 -0
index 326ee6e..27aa7b6 100644
@@ -103,6 +103,52 @@ static const struct attribute_group *led_groups[] = {
 	NULL,
 };
 
+static ssize_t brightness_hw_changed_show(struct device *dev,
+		struct device_attribute *attr, char *buf)
+{
+	struct led_classdev *led_cdev = dev_get_drvdata(dev);
+
+	return sprintf(buf, "%u\n", led_cdev->brightness_hw_changed);
+}
+
+static DEVICE_ATTR_RO(brightness_hw_changed);
+
+static int led_add_brightness_hw_changed(struct led_classdev *led_cdev)
+{
+	struct device *dev = led_cdev->dev;
+	int ret;
+
+	ret = device_create_file(dev, &dev_attr_brightness_hw_changed);
+	if (ret) {
+		dev_err(dev, "Error creating brightness_hw_changed\n");
+		return ret;
+	}
+
+	led_cdev->brightness_hw_changed_kn =
+		sysfs_get_dirent(dev->kobj.sd, "brightness_hw_changed");
+	if (!led_cdev->brightness_hw_changed_kn) {
+		dev_err(dev, "Error getting brightness_hw_changed kn\n");
+		device_remove_file(dev, &dev_attr_brightness_hw_changed);
+		return -ENXIO;
+	}
+
+	return 0;
+}
+
+static void led_remove_brightness_hw_changed(struct led_classdev *led_cdev)
+{
+	sysfs_put(led_cdev->brightness_hw_changed_kn);
+	device_remove_file(led_cdev->dev, &dev_attr_brightness_hw_changed);
+}
+
+void led_classdev_notify_brightness_hw_changed(struct led_classdev *led_cdev,
+					       enum led_brightness brightness)
+{
+	led_cdev->brightness_hw_changed = brightness;
+	sysfs_notify_dirent(led_cdev->brightness_hw_changed_kn);
+}
+EXPORT_SYMBOL_GPL(led_classdev_notify_brightness_hw_changed);
 
 /**
  * led_classdev_suspend - suspend an led_classdev.
  * @led_cdev: the led_classdev to suspend.
@@ -204,6 +250,14 @@ int led_classdev_register(struct device *parent, struct led_classdev *led_cdev)
 		dev_warn(parent, "Led %s renamed to %s due to name collision",
 				led_cdev->name, dev_name(led_cdev->dev));
 
+	if (led_cdev->flags & LED_BRIGHT_HW_CHANGED) {
+		ret = led_add_brightness_hw_changed(led_cdev);
+		if (ret) {
+			device_unregister(led_cdev->dev);
+			return ret;
+		}
+	}
+
 	led_cdev->work_flags = 0;
 #ifdef CONFIG_LEDS_TRIGGERS
 	init_rwsem(&led_cdev->trigger_lock);
@@ -256,6 +310,9 @@ void led_classdev_unregister(struct led_classdev *led_cdev)
 
 	flush_work(&led_cdev->set_brightness_work);
 
+	if (led_cdev->flags & LED_BRIGHT_HW_CHANGED)
+		led_remove_brightness_hw_changed(led_cdev);
+
 	device_unregister(led_cdev->dev);
 
 	down_write(&leds_list_lock);
include/linux/leds.h +1 -0
index 569cb53..aa452c8 100644
@@ -13,6 +13,7 @@
 #define __LINUX_LEDS_H_INCLUDED
 
 #include <linux/device.h>
+#include <linux/kernfs.h>
 #include <linux/list.h>
 #include <linux/mutex.h>
 #include <linux/rwsem.h>

include/linux/leds.h struct led_classdev { · line 39

Quoted 4 lines
include/linux/leds.h +1 -0
@@ -35,6 +36,7 @@ struct led_classdev {
 	const char		*name;
 	enum led_brightness	 brightness;
 	enum led_brightness	 max_brightness;
+	enum led_brightness	 brightness_hw_changed;

Could we add Kconfig option for this feature and build the whole infrastructure only if enabled?

Quoted 31 lines
include/linux/leds.h +6 -0
 	int			 flags;
 
 	/* Lower 16 bits reflect status */
@@ -46,6 +48,7 @@ struct led_classdev {
 #define LED_DEV_CAP_FLASH	(1 << 18)
 #define LED_HW_PLUGGABLE	(1 << 19)
 #define LED_PANIC_INDICATOR	(1 << 20)
+#define LED_BRIGHT_HW_CHANGED	(1 << 21)
 
 	/* set_brightness_work / blink_timer flags, atomic, private. */
 	unsigned long		work_flags;
@@ -99,6 +102,9 @@ struct led_classdev {
 	struct work_struct	set_brightness_work;
 	int			delayed_set_value;
 
+	/* For LEDs with brightness_hw_changed sysfs attribute */
+	struct kernfs_node	*brightness_hw_changed_kn;
+
 #ifdef CONFIG_LEDS_TRIGGERS
 	/* Protects the trigger data below */
 	struct rw_semaphore	 trigger_lock;
@@ -123,6 +129,8 @@ extern void devm_led_classdev_unregister(struct device *parent,
 					 struct led_classdev *led_cdev);
 extern void led_classdev_suspend(struct led_classdev *led_cdev);
 extern void led_classdev_resume(struct led_classdev *led_cdev);
+extern void led_classdev_notify_brightness_hw_changed(
+	struct led_classdev *led_cdev, enum led_brightness brightness);
 
 /**
  * led_blink_set - set blinking with software fallback
Signature · 2 lines
Best regards,
Jacek Anaszewski
#9 lore raw

Re: [PATCH v6 1/4] leds: class: Add new optional brightness_hw_changed attribute

Hi!

Quoted 57 lines

Thanks for the patch. I have a few comments below.

Quoted 54 lines · Hans de Goede

Some LEDs may have their brightness level changed autonomously (outside of kernel control) by hardware / firmware. This commit adds support for an optional brightness_hw_changed attribute to signal such changes to userspace (if a driver can detect them):

What: /sys/class/leds/<led>/brightness_hw_changed
Date: January 2017
KernelVersion: 4.11
Description:
Last hardware set brightness level for this LED. Some LEDs may be changed autonomously by hardware/firmware. Only LEDs where this happens and the driver can detect this, will have this file.

This file supports poll() to detect when the hardware changes the brightness.

Reading this file will return the last brightness level set by the hardware, this may be different from the current brightness.

Drivers which want to support this, simply add LED_BRIGHT_HW_CHANGED to their flags field and call led_classdev_notify_brightness_hw_changed() with the hardware set brightness when they detect a hardware / firmware triggered brightness change.

---
Changes in v6:

(quoted diff) +0 -2
-New patch in v6 of this set, replacing previous trigger based API
---
 Documentation/ABI/testing/sysfs-class-led | 16 +++++++++
 drivers/leds/led-class.c                  | 57 +++++++++++++++++++++++++++++++
 include/linux/leds.h                      |  8 +++++
 3 files changed, 81 insertions(+)
Documentation/ABI/testing/sysfs-class-led +10 -0
index 491cdee..9f6e75d 100644
@@ -23,6 +23,22 @@ Description:
 		If the LED does not support different brightness levels, this
 		should be 1.
 
+What:		/sys/class/leds/<led>/brightness_hw_changed
+Date:		January 2017
+KernelVersion:	4.11
+Description:
+		Last hardware set brightness level for this LED. Some LEDs
+		may be changed autonomously by hardware/firmware. Only LEDs
+		where this happens and the driver can detect this, will have
+		this file.
+
+		This file supports poll() to detect when the hardware changes
Quoted 8 lines

Documentation/ABI/testing/sysfs-class-led Description: · line 40

Quoted 5 lines
Documentation/ABI/testing/sysfs-class-led +5 -0
+		the brightness.
+
+		Reading this file will return the last brightness level set
+		by the hardware, this may be different from the current
+		brightness.

Let's return -ENODATA when no such an event occurred till the moment of file reading.

I'd do that.

Actually, maybe we should make this undefined behaviour. "Reading this file will return the last brightness level set by the hardware. If the software changed the brightness in the meantime, maybe due to active trigger, the result is undefined, and it may return error."

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#10 lore raw

Re: [PATCH v6 1/4] leds: class: Add new optional brightness_hw_changed attribute

Hi,

Quoted 68 lines · Pavel Machek

Hi!

Quoted 57 lines

Thanks for the patch. I have a few comments below.

Quoted 54 lines · Hans de Goede

Some LEDs may have their brightness level changed autonomously (outside of kernel control) by hardware / firmware. This commit adds support for an optional brightness_hw_changed attribute to signal such changes to userspace (if a driver can detect them):

What: /sys/class/leds/<led>/brightness_hw_changed
Date: January 2017
KernelVersion: 4.11
Description:
Last hardware set brightness level for this LED. Some LEDs may be changed autonomously by hardware/firmware. Only LEDs where this happens and the driver can detect this, will have this file.

This file supports poll() to detect when the hardware changes the brightness.

Reading this file will return the last brightness level set by the hardware, this may be different from the current brightness.

Drivers which want to support this, simply add LED_BRIGHT_HW_CHANGED to their flags field and call led_classdev_notify_brightness_hw_changed() with the hardware set brightness when they detect a hardware / firmware triggered brightness change.

---
Changes in v6:

(quoted diff) +0 -2
-New patch in v6 of this set, replacing previous trigger based API
---
 Documentation/ABI/testing/sysfs-class-led | 16 +++++++++
 drivers/leds/led-class.c                  | 57 +++++++++++++++++++++++++++++++
 include/linux/leds.h                      |  8 +++++
 3 files changed, 81 insertions(+)
Documentation/ABI/testing/sysfs-class-led +10 -0
index 491cdee..9f6e75d 100644
@@ -23,6 +23,22 @@ Description:
 		If the LED does not support different brightness levels, this
 		should be 1.
 
+What:		/sys/class/leds/<led>/brightness_hw_changed
+Date:		January 2017
+KernelVersion:	4.11
+Description:
+		Last hardware set brightness level for this LED. Some LEDs
+		may be changed autonomously by hardware/firmware. Only LEDs
+		where this happens and the driver can detect this, will have
+		this file.
+
+		This file supports poll() to detect when the hardware changes
Quoted 8 lines

Documentation/ABI/testing/sysfs-class-led Description: · line 40

Quoted 5 lines
Documentation/ABI/testing/sysfs-class-led +5 -0
+		the brightness.
+
+		Reading this file will return the last brightness level set
+		by the hardware, this may be different from the current
+		brightness.

Let's return -ENODATA when no such an event occurred till the moment of file reading.

Quoted 6 lines

I'd do that.

Actually, maybe we should make this undefined behaviour. "Reading this file will return the last brightness level set by the hardware. If the software changed the brightness in the meantime, maybe due to active trigger, the result is undefined, and it may return error."

As Jacek has said before in the case of software changed brightness between the poll() waking up and reading the file, we should return the brightness as set by the last hardware triggered change.

I've added the -ENODATA error (and documented it) for the v7 I'm about to send.

Regards,

Hans

Quoted 3 lines

Pavel

#11 lore raw

PATCH v6 2/4 platform/x86/thinkpad: Call led_classdev_notify_brightness_hw_changed on kbd brightness change

In reply to Hans de Goede

Make thinkpad_acpi call led_classdev_notify_brightness_hw_changed on the kbd_led led_classdev registered by thinkpad_acpi when the kbd backlight brightness is changed through the hotkey.

This will allow userspace to monitor (poll) for brightness changes on these LEDs caused by the hotkey.

---
Changes in v3:
-This is a new patch in v3 of this patch-set
Changes in v4:
-No changes
Changes in v5:
-Switch to new led-trigger based API for notifying userspace about
keyboard backlight brightness changes.
-Also call ledtrig_kbd_backlight() for laptops with a thinklight -Rename the hotkey defines from THINKLIGHT to KBD_LIGHT since they
are shared between the thinklight and the keyboard backlight
Changes in v6:
-Switch to new brightness_hw_changed LED class API

---
 drivers/platform/x86/thinkpad_acpi.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/platform/x86/thinkpad_acpi.c +10 -2
index cacb43f..6249292 100644
@@ -163,6 +163,7 @@ enum tpacpi_hkey_event_t {
 	TP_HKEY_EV_HOTKEY_BASE		= 0x1001, /* first hotkey (FN+F1) */
 	TP_HKEY_EV_BRGHT_UP		= 0x1010, /* Brightness up */
 	TP_HKEY_EV_BRGHT_DOWN		= 0x1011, /* Brightness down */
+	TP_HKEY_EV_KBD_LIGHT		= 0x1012, /* Thinklight/kbd backlight */
 	TP_HKEY_EV_VOL_UP		= 0x1015, /* Volume up or unmute */
 	TP_HKEY_EV_VOL_DOWN		= 0x1016, /* Volume down or unmute */
 	TP_HKEY_EV_VOL_MUTE		= 0x1017, /* Mixer output mute */
@@ -1959,7 +1960,7 @@ enum {	/* Positions of some of the keys in hotkey masks */
 	TP_ACPI_HKEY_HIBERNATE_MASK	= 1 << TP_ACPI_HOTKEYSCAN_FNF12,
 	TP_ACPI_HKEY_BRGHTUP_MASK	= 1 << TP_ACPI_HOTKEYSCAN_FNHOME,
 	TP_ACPI_HKEY_BRGHTDWN_MASK	= 1 << TP_ACPI_HOTKEYSCAN_FNEND,
-	TP_ACPI_HKEY_THNKLGHT_MASK	= 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP,
+	TP_ACPI_HKEY_KBD_LIGHT_MASK	= 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP,
 	TP_ACPI_HKEY_ZOOM_MASK		= 1 << TP_ACPI_HOTKEYSCAN_FNSPACE,
 	TP_ACPI_HKEY_VOLUP_MASK		= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP,
 	TP_ACPI_HKEY_VOLDWN_MASK	= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN,
@@ -2344,7 +2345,7 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
 		n->display_toggle = !!(d & TP_NVRAM_MASK_HKT_DISPLAY);
 		n->hibernate_toggle = !!(d & TP_NVRAM_MASK_HKT_HIBERNATE);
 	}
-	if (m & TP_ACPI_HKEY_THNKLGHT_MASK) {
+	if (m & TP_ACPI_HKEY_KBD_LIGHT_MASK) {
 		d = nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT);
 		n->thinklight_toggle = !!(d & TP_NVRAM_MASK_THINKLIGHT);
 	}
@@ -5193,6 +5194,7 @@ static struct tpacpi_led_classdev tpacpi_led_kbdlight = {
 	.led_classdev = {
 		.name		= "tpacpi::kbd_backlight",
 		.max_brightness	= 2,
+		.flags		= LED_BRIGHT_HW_CHANGED,
 		.brightness_set	= &kbdlight_sysfs_set,
 		.brightness_get	= &kbdlight_sysfs_get,
 	}
@@ -5222,6 +5224,8 @@ static int __init kbdlight_init(struct ibm_init_struct *iibm)
 		return rc;
 	}
 
+	tpacpi_hotkey_driver_mask_set(hotkey_driver_mask |
+				      TP_ACPI_HKEY_KBD_LIGHT_MASK);
 	return 0;
 }
 
@@ -9169,6 +9173,10 @@ static void tpacpi_driver_event(const unsigned int hkey_event)
 			volume_alsa_notify_change();
 		}
 	}
+	if (tp_features.kbdlight && hkey_event == TP_HKEY_EV_KBD_LIGHT)
+		led_classdev_notify_brightness_hw_changed(
+			&tpacpi_led_kbdlight.led_classdev,
+			kbdlight_sysfs_get(NULL));
 }
 
 static void hotkey_driver_event(const unsigned int scancode)
Signature · 1 line
2.9.3
#12 lore raw

Re: [PATCH v6 2/4] platform/x86/thinkpad: Call led_classdev_notify_brightness_hw_changed on kbd brightness change

Quoted 8 lines · Hans de Goede

Make thinkpad_acpi call led_classdev_notify_brightness_hw_changed on the kbd_led led_classdev registered by thinkpad_acpi when the kbd backlight brightness is changed through the hotkey.

This will allow userspace to monitor (poll) for brightness changes on these LEDs caused by the hotkey.

I didn't see v7 of this and consequent patches. What's going on?

Quoted 78 lines

---
Changes in v3:
-This is a new patch in v3 of this patch-set
Changes in v4:
-No changes
Changes in v5:

(quoted diff) +0 -3
-Switch to new led-trigger based API for notifying userspace about
 keyboard backlight brightness changes.
-Also call ledtrig_kbd_backlight() for laptops with a thinklight
-Rename the hotkey defines from THINKLIGHT to KBD_LIGHT since they
 are shared between the thinklight and the keyboard backlight

Changes in v6:

(quoted diff) +0 -2
-Switch to new brightness_hw_changed LED class API
---
 drivers/platform/x86/thinkpad_acpi.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/platform/x86/thinkpad_acpi.c +10 -3
index cacb43f..6249292 100644
@@ -163,6 +163,7 @@ enum tpacpi_hkey_event_t {
        TP_HKEY_EV_HOTKEY_BASE          = 0x1001, /* first hotkey (FN+F1) */
        TP_HKEY_EV_BRGHT_UP             = 0x1010, /* Brightness up */
        TP_HKEY_EV_BRGHT_DOWN           = 0x1011, /* Brightness down */
+       TP_HKEY_EV_KBD_LIGHT            = 0x1012, /* Thinklight/kbd backlight */
        TP_HKEY_EV_VOL_UP               = 0x1015, /* Volume up or unmute */
        TP_HKEY_EV_VOL_DOWN             = 0x1016, /* Volume down or unmute */
        TP_HKEY_EV_VOL_MUTE             = 0x1017, /* Mixer output mute */
@@ -1959,7 +1960,7 @@ enum {    /* Positions of some of the keys in hotkey masks */
        TP_ACPI_HKEY_HIBERNATE_MASK     = 1 << TP_ACPI_HOTKEYSCAN_FNF12,
        TP_ACPI_HKEY_BRGHTUP_MASK       = 1 << TP_ACPI_HOTKEYSCAN_FNHOME,
        TP_ACPI_HKEY_BRGHTDWN_MASK      = 1 << TP_ACPI_HOTKEYSCAN_FNEND,
-       TP_ACPI_HKEY_THNKLGHT_MASK      = 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP,
+       TP_ACPI_HKEY_KBD_LIGHT_MASK     = 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP,
        TP_ACPI_HKEY_ZOOM_MASK          = 1 << TP_ACPI_HOTKEYSCAN_FNSPACE,
        TP_ACPI_HKEY_VOLUP_MASK         = 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP,
        TP_ACPI_HKEY_VOLDWN_MASK        = 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN,
@@ -2344,7 +2345,7 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
                n->display_toggle = !!(d & TP_NVRAM_MASK_HKT_DISPLAY);
                n->hibernate_toggle = !!(d & TP_NVRAM_MASK_HKT_HIBERNATE);
        }
-       if (m & TP_ACPI_HKEY_THNKLGHT_MASK) {
+       if (m & TP_ACPI_HKEY_KBD_LIGHT_MASK) {
                d = nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT);
                n->thinklight_toggle = !!(d & TP_NVRAM_MASK_THINKLIGHT);
        }
@@ -5193,6 +5194,7 @@ static struct tpacpi_led_classdev tpacpi_led_kbdlight = {
        .led_classdev = {
                .name           = "tpacpi::kbd_backlight",
                .max_brightness = 2,
+               .flags          = LED_BRIGHT_HW_CHANGED,
                .brightness_set = &kbdlight_sysfs_set,
                .brightness_get = &kbdlight_sysfs_get,
        }
@@ -5222,6 +5224,8 @@ static int __init kbdlight_init(struct ibm_init_struct *iibm)
                return rc;
        }
 
+       tpacpi_hotkey_driver_mask_set(hotkey_driver_mask |
+                                     TP_ACPI_HKEY_KBD_LIGHT_MASK);
        return 0;
 }
 
@@ -9169,6 +9173,10 @@ static void tpacpi_driver_event(const unsigned int hkey_event)
                        volume_alsa_notify_change();
                }
        }
+       if (tp_features.kbdlight && hkey_event == TP_HKEY_EV_KBD_LIGHT)
+               led_classdev_notify_brightness_hw_changed(
+                       &tpacpi_led_kbdlight.led_classdev,
+                       kbdlight_sysfs_get(NULL));
 }
 
 static void hotkey_driver_event(const unsigned int scancode)
--

2.9.3

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#13 lore raw

Re: [PATCH v6 2/4] platform/x86/thinkpad: Call led_classdev_notify_brightness_hw_changed on kbd brightness change

Hi,

Quoted 11 lines · Andy Shevchenko
Quoted 8 lines · Hans de Goede

Make thinkpad_acpi call led_classdev_notify_brightness_hw_changed on the kbd_led led_classdev registered by thinkpad_acpi when the kbd backlight brightness is changed through the hotkey.

This will allow userspace to monitor (poll) for brightness changes on these LEDs caused by the hotkey.

I didn't see v7 of this and consequent patches. What's going on?

As I said in the cover-letter of v6 the platform patches were mainly there to document the usage of the new LED api. Since there were no changes to the api I did not post a v7 of the platform/x86 patches, also I've not yet tested the thinkpad changes as adjusted for the new LED api.

Once the LED side is merged, I'll re-post the platform patches.

Regards,

Hans

Quoted 82 lines
Quoted 79 lines

---
Changes in v3:
-This is a new patch in v3 of this patch-set
Changes in v4:
-No changes
Changes in v5:

(quoted diff) +0 -3
-Switch to new led-trigger based API for notifying userspace about
 keyboard backlight brightness changes.
-Also call ledtrig_kbd_backlight() for laptops with a thinklight
-Rename the hotkey defines from THINKLIGHT to KBD_LIGHT since they
 are shared between the thinklight and the keyboard backlight

Changes in v6:

(quoted diff) +0 -2
-Switch to new brightness_hw_changed LED class API
---
 drivers/platform/x86/thinkpad_acpi.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/platform/x86/thinkpad_acpi.c +10 -3
index cacb43f..6249292 100644
@@ -163,6 +163,7 @@ enum tpacpi_hkey_event_t {
        TP_HKEY_EV_HOTKEY_BASE          = 0x1001, /* first hotkey (FN+F1) */
        TP_HKEY_EV_BRGHT_UP             = 0x1010, /* Brightness up */
        TP_HKEY_EV_BRGHT_DOWN           = 0x1011, /* Brightness down */
+       TP_HKEY_EV_KBD_LIGHT            = 0x1012, /* Thinklight/kbd backlight */
        TP_HKEY_EV_VOL_UP               = 0x1015, /* Volume up or unmute */
        TP_HKEY_EV_VOL_DOWN             = 0x1016, /* Volume down or unmute */
        TP_HKEY_EV_VOL_MUTE             = 0x1017, /* Mixer output mute */
@@ -1959,7 +1960,7 @@ enum {    /* Positions of some of the keys in hotkey masks */
        TP_ACPI_HKEY_HIBERNATE_MASK     = 1 << TP_ACPI_HOTKEYSCAN_FNF12,
        TP_ACPI_HKEY_BRGHTUP_MASK       = 1 << TP_ACPI_HOTKEYSCAN_FNHOME,
        TP_ACPI_HKEY_BRGHTDWN_MASK      = 1 << TP_ACPI_HOTKEYSCAN_FNEND,
-       TP_ACPI_HKEY_THNKLGHT_MASK      = 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP,
+       TP_ACPI_HKEY_KBD_LIGHT_MASK     = 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP,
        TP_ACPI_HKEY_ZOOM_MASK          = 1 << TP_ACPI_HOTKEYSCAN_FNSPACE,
        TP_ACPI_HKEY_VOLUP_MASK         = 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP,
        TP_ACPI_HKEY_VOLDWN_MASK        = 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN,
@@ -2344,7 +2345,7 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
                n->display_toggle = !!(d & TP_NVRAM_MASK_HKT_DISPLAY);
                n->hibernate_toggle = !!(d & TP_NVRAM_MASK_HKT_HIBERNATE);
        }
-       if (m & TP_ACPI_HKEY_THNKLGHT_MASK) {
+       if (m & TP_ACPI_HKEY_KBD_LIGHT_MASK) {
                d = nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT);
                n->thinklight_toggle = !!(d & TP_NVRAM_MASK_THINKLIGHT);
        }
@@ -5193,6 +5194,7 @@ static struct tpacpi_led_classdev tpacpi_led_kbdlight = {
        .led_classdev = {
                .name           = "tpacpi::kbd_backlight",
                .max_brightness = 2,
+               .flags          = LED_BRIGHT_HW_CHANGED,
                .brightness_set = &kbdlight_sysfs_set,
                .brightness_get = &kbdlight_sysfs_get,
        }
@@ -5222,6 +5224,8 @@ static int __init kbdlight_init(struct ibm_init_struct *iibm)
                return rc;
        }
 
+       tpacpi_hotkey_driver_mask_set(hotkey_driver_mask |
+                                     TP_ACPI_HKEY_KBD_LIGHT_MASK);
        return 0;
 }
 
@@ -9169,6 +9173,10 @@ static void tpacpi_driver_event(const unsigned int hkey_event)
                        volume_alsa_notify_change();
                }
        }
+       if (tp_features.kbdlight && hkey_event == TP_HKEY_EV_KBD_LIGHT)
+               led_classdev_notify_brightness_hw_changed(
+                       &tpacpi_led_kbdlight.led_classdev,
+                       kbdlight_sysfs_get(NULL));
 }
 
 static void hotkey_driver_event(const unsigned int scancode)
--

2.9.3

#14 lore raw

PATCH v6 3/4 platform/x86/dell-*: Add a generic dell-laptop notifier chain

In reply to Hans de Goede

There are several cases where events handled in one of the dell-* drivers need to be propagated to another dell-* driver.

This commits add 3 generic functions:
dell_laptop_register_notifier()
dell_laptop_unregister_notifier()
dell_laptop_call_notifier()

It currently only defines 1 action:
DELL_LAPTOP_KBD_BACKLIGHT_BRIGHTNESS_CHANGED

Which is intended to propagate kbd_backlight_brightness_changed wmi events from dell-wmi to dell-laptop (which contains the actual kbd backlight driver).

These functions are put in dell-smbios as both dell-wmi and dell-laptop use smbios functions and I do not want to put the notifier head in either driver, as that will make the 2 drivers depend on each other.

---
Changes in v2:
-This is a new patch in v2 of this patch-set
Changes in v3:
-No changes
Changes in v4:
-Rename functions from dell_smbios_*_notifier to dell_laptop_*_notifier Changes in v5:
-Dropped due to new led-trigger based approach making this unnecessary Changes in v6:
-Re-introduced as led-trigger based approach got nacked

---
 drivers/platform/x86/dell-smbios.c | 20 ++++++++++++++++++++
 drivers/platform/x86/dell-smbios.h | 11 +++++++++++
 2 files changed, 31 insertions(+)
drivers/platform/x86/dell-smbios.c +20 -0
index d2412ab..bceb382 100644
@@ -105,6 +105,26 @@ struct calling_interface_token *dell_smbios_find_token(int tokenid)
 }
 EXPORT_SYMBOL_GPL(dell_smbios_find_token);
 
+static ATOMIC_NOTIFIER_HEAD(dell_laptop_chain_head);
+
+int dell_laptop_register_notifier(struct notifier_block *nb)
+{
+	return atomic_notifier_chain_register(&dell_laptop_chain_head, nb);
+}
+EXPORT_SYMBOL_GPL(dell_laptop_register_notifier);
+
+int dell_laptop_unregister_notifier(struct notifier_block *nb)
+{
+	return atomic_notifier_chain_unregister(&dell_laptop_chain_head, nb);
+}
+EXPORT_SYMBOL_GPL(dell_laptop_unregister_notifier);
+
+void dell_laptop_call_notifier(unsigned long action, void *data)
+{
+	atomic_notifier_call_chain(&dell_laptop_chain_head, action, data);
+}
+EXPORT_SYMBOL_GPL(dell_laptop_call_notifier);
+
 static void __init parse_da_table(const struct dmi_header *dm)
 {
 	/* Final token is a terminator, so we don't want to copy it */
drivers/platform/x86/dell-smbios.h +11 -0
index ec7d40a..45cbc22 100644
@@ -16,6 +16,8 @@
 #ifndef _DELL_SMBIOS_H_
 #define _DELL_SMBIOS_H_
 
+struct notifier_block;
+
 /* This structure will be modified by the firmware when we enter
  * system management mode, hence the volatiles */
 
@@ -43,4 +45,13 @@ void dell_smbios_release_buffer(void);
 void dell_smbios_send_request(int class, int select);
 
 struct calling_interface_token *dell_smbios_find_token(int tokenid);
+
+enum dell_laptop_notifier_actions {
+	DELL_LAPTOP_KBD_BACKLIGHT_BRIGHTNESS_CHANGED,
+};
+
+int dell_laptop_register_notifier(struct notifier_block *nb);
+int dell_laptop_unregister_notifier(struct notifier_block *nb);
+void dell_laptop_call_notifier(unsigned long action, void *data);
+
 #endif
Signature · 1 line
2.9.3
#15 lore raw

PATCH v6 4/4 platform/x86/dell-*: Call led_classdev_notify_brightness_hw_changed on kbd brightness change

In reply to Hans de Goede

Make dell-wmi notify on hotkey kbd brightness changes, listen for this in dell-laptop and call led_classdev_notify_brightness_hw_changed.

This will allow userspace to monitor (poll) for brightness changes on these LEDs caused by the hotkey.

Changes in v2:
-Use the new dell_smbios*notify functionality
Changes in v3:
-Simplify the if condition for calling led_notify_brightness_change Changes in v4:
-Adjust for dell_smbios_*_notifier to dell_laptop_*_notifier rename Changes in v5:
-Switch to new led-trigger based API for notifying userspace about
keyboard backlight brightness changes.
Changes in v6:
-Switch to new brightness_hw_changed LED class API

---
 drivers/platform/x86/dell-laptop.c | 30 +++++++++++++++++++++++++++++-
 drivers/platform/x86/dell-wmi.c    | 14 +++++++++-----
 2 files changed, 38 insertions(+), 6 deletions(-)
drivers/platform/x86/dell-laptop.c +29 -1
index 14392a0..7af485e 100644
@@ -1937,6 +1937,7 @@ static int kbd_led_level_set(struct led_classdev *led_cdev,
 
 static struct led_classdev kbd_led = {
 	.name           = "dell::kbd_backlight",
+	.flags		= LED_BRIGHT_HW_CHANGED,
 	.brightness_set_blocking = kbd_led_level_set,
 	.brightness_get = kbd_led_level_get,
 	.groups         = kbd_led_groups,
@@ -1944,6 +1945,8 @@ static struct led_classdev kbd_led = {
 
 static int __init kbd_led_init(struct device *dev)
 {
+	int ret;
+
 	kbd_init();
 	if (!kbd_led_present)
 		return -ENODEV;
@@ -1955,7 +1958,11 @@ static int __init kbd_led_init(struct device *dev)
 		if (kbd_led.max_brightness)
 			kbd_led.max_brightness--;
 	}
-	return led_classdev_register(dev, &kbd_led);
+	ret = led_classdev_register(dev, &kbd_led);
+	if (ret)
+		kbd_led_present = false;
+
+	return ret;
 }
 
 static void brightness_set_exit(struct led_classdev *led_cdev,
@@ -1972,6 +1979,24 @@ static void kbd_led_exit(void)
 	led_classdev_unregister(&kbd_led);
 }
 
+static int dell_laptop_notifier_call(struct notifier_block *nb,
+				     unsigned long action, void *data)
+{
+	switch (action) {
+	case DELL_LAPTOP_KBD_BACKLIGHT_BRIGHTNESS_CHANGED:
+		if (kbd_led_present)
+			led_classdev_notify_brightness_hw_changed(
+				&kbd_led, kbd_led_level_get(&kbd_led));
+		break;
+	}
+
+	return NOTIFY_OK;
+}
+
+static struct notifier_block dell_laptop_notifier = {
+	.notifier_call = dell_laptop_notifier_call,
+};
+
 static int __init dell_init(void)
 {
 	struct calling_interface_buffer *buffer;
@@ -2015,6 +2040,8 @@ static int __init dell_init(void)
 		debugfs_create_file("rfkill", 0444, dell_laptop_dir, NULL,
 				    &dell_debugfs_fops);
 
+	dell_laptop_register_notifier(&dell_laptop_notifier);
+
 	if (acpi_video_get_backlight_type() != acpi_backlight_vendor)
 		return 0;
 
@@ -2066,6 +2093,7 @@ static int __init dell_init(void)
 
 static void __exit dell_exit(void)
 {
+	dell_laptop_unregister_notifier(&dell_laptop_notifier);
 	debugfs_remove_recursive(dell_laptop_dir);
 	if (quirks && quirks->touchpad_led)
 		touchpad_led_exit();
drivers/platform/x86/dell-wmi.c +9 -5
index 75e6370..15740b5 100644
@@ -297,11 +297,11 @@ static const struct key_entry dell_wmi_keymap_type_0011[] __initconst = {
 	{ KE_IGNORE, 0xfff1, { KEY_RESERVED } },
 
 	/* Keyboard backlight level changed */
-	{ KE_IGNORE, 0x01e1, { KEY_RESERVED } },
-	{ KE_IGNORE, 0x02ea, { KEY_RESERVED } },
-	{ KE_IGNORE, 0x02eb, { KEY_RESERVED } },
-	{ KE_IGNORE, 0x02ec, { KEY_RESERVED } },
-	{ KE_IGNORE, 0x02f6, { KEY_RESERVED } },
+	{ KE_IGNORE, 0x01e1, { KEY_KBDILLUMTOGGLE } },
+	{ KE_IGNORE, 0x02ea, { KEY_KBDILLUMTOGGLE } },
+	{ KE_IGNORE, 0x02eb, { KEY_KBDILLUMTOGGLE } },
+	{ KE_IGNORE, 0x02ec, { KEY_KBDILLUMTOGGLE } },
+	{ KE_IGNORE, 0x02f6, { KEY_KBDILLUMTOGGLE } },
 };
 
 static struct input_dev *dell_wmi_input_dev;
@@ -329,6 +329,10 @@ static void dell_wmi_process_key(int type, int code)
 	if (type == 0x0000 && code == 0xe025 && !wmi_requires_smbios_request)
 		return;
 
+	if (key->keycode == KEY_KBDILLUMTOGGLE)
+		dell_laptop_call_notifier(
+			DELL_LAPTOP_KBD_BACKLIGHT_BRIGHTNESS_CHANGED, NULL);
+
 	sparse_keymap_report_entry(dell_wmi_input_dev, key, 1, true);
 }
 
Signature · 1 line
2.9.3