All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] leds: triggers: Improve handling of LEDs supporting hw triggers only
@ 2021-07-22 20:16 Heiner Kallweit
  0 siblings, 0 replies; only message in thread
From: Heiner Kallweit @ 2021-07-22 20:16 UTC (permalink / raw)
  To: Pavel Machek; +Cc: linux-leds

A LED supporting HW triggers only (example: network PHY LED indicating
100M link or 1000M link or ..) may have none of the software LED
control callbacks implemented. As of today the software LED control
triggers would be available nevertheless. This doesn't make sense.
If a LED supports HW triggers only, offer only the matching HW triggers.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/leds/led-triggers.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c
index 4e7b78a84..48924bad2 100644
--- a/drivers/leds/led-triggers.c
+++ b/drivers/leds/led-triggers.c
@@ -27,10 +27,23 @@ LIST_HEAD(trigger_list);
 
  /* Used by LED Class */
 
-static inline bool
-trigger_relevant(struct led_classdev *led_cdev, struct led_trigger *trig)
+static bool led_hw_trig_only(struct led_classdev *led_cdev)
 {
-	return !trig->trigger_type || trig->trigger_type == led_cdev->trigger_type;
+	return !led_cdev->brightness_set && !led_cdev->brightness_set_blocking &&
+	       !led_cdev->blink_set && !led_cdev->pattern_set;
+}
+
+static bool trigger_relevant(struct led_classdev *led_cdev,
+			     struct led_trigger *trig)
+{
+	if (trig->trigger_type == led_cdev->trigger_type)
+		return true;
+
+	/* LED supports matching hw triggers only */
+	if (led_hw_trig_only(led_cdev))
+		return false;
+
+	return !trig->trigger_type;
 }
 
 ssize_t led_trigger_write(struct file *filp, struct kobject *kobj,
-- 
2.32.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2021-07-22 20:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-22 20:16 [PATCH] leds: triggers: Improve handling of LEDs supporting hw triggers only Heiner Kallweit

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.