Linux LED subsystem development
 help / color / mirror / Atom feed
* [PATCH v3] leds: led-triggers: Improvements for default trigger
@ 2025-03-13 23:56 Craig McQueen
  2025-03-14  7:54 ` Lee Jones
  0 siblings, 1 reply; 3+ messages in thread
From: Craig McQueen @ 2025-03-13 23:56 UTC (permalink / raw)
  To: linux-leds; +Cc: Craig McQueen

Accept "default" written to sysfs trigger attr.
If the text "default" is written to the LED's sysfs 'trigger' attr, then
call led_trigger_set_default() to set the LED to its default trigger.

If the default trigger is set to "none", then led_trigger_set_default()
will remove a trigger. This is in contrast to the default trigger being
unset, in which case led_trigger_set_default() does nothing.
---
 Documentation/ABI/testing/sysfs-class-led |  6 ++++++
 drivers/leds/led-triggers.c               | 13 +++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-class-led b/Documentation/ABI/testing/sysfs-class-led
index 2e24ac3bd7ef..0313b82644f2 100644
--- a/Documentation/ABI/testing/sysfs-class-led
+++ b/Documentation/ABI/testing/sysfs-class-led
@@ -72,6 +72,12 @@ Description:
 		/sys/class/leds/<led> once a given trigger is selected. For
 		their documentation see `sysfs-class-led-trigger-*`.
 
+		Writing "none" removes the trigger for this LED.
+
+		Writing "default" sets the trigger to the LED's default trigger
+		(which would often be configured in the device tree for the
+		hardware).
+
 What:		/sys/class/leds/<led>/inverted
 Date:		January 2011
 KernelVersion:	2.6.38
diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c
index b2d40f87a5ff..3799dcc1cf07 100644
--- a/drivers/leds/led-triggers.c
+++ b/drivers/leds/led-triggers.c
@@ -54,6 +54,11 @@ ssize_t led_trigger_write(struct file *filp, struct kobject *kobj,
 		goto unlock;
 	}
 
+	if (sysfs_streq(buf, "default")) {
+		led_trigger_set_default(led_cdev);
+		goto unlock;
+	}
+
 	down_read(&triggers_list_lock);
 	list_for_each_entry(trig, &trigger_list, next_trig) {
 		if (sysfs_streq(buf, trig->name) && trigger_relevant(led_cdev, trig)) {
@@ -98,6 +103,9 @@ static int led_trigger_format(char *buf, size_t size,
 	int len = led_trigger_snprintf(buf, size, "%s",
 				       led_cdev->trigger ? "none" : "[none]");
 
+	if (led_cdev->default_trigger)
+		len += led_trigger_snprintf(buf + len, size - len, " default");
+
 	list_for_each_entry(trig, &trigger_list, next_trig) {
 		bool hit;
 
@@ -281,6 +289,11 @@ void led_trigger_set_default(struct led_classdev *led_cdev)
 	if (!led_cdev->default_trigger)
 		return;
 
+	if (!strcmp(led_cdev->default_trigger, "none")) {
+		led_trigger_remove(led_cdev);
+		return;
+	}
+
 	down_read(&triggers_list_lock);
 	down_write(&led_cdev->trigger_lock);
 	list_for_each_entry(trig, &trigger_list, next_trig) {
-- 
2.48.1


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

* Re: [PATCH v3] leds: led-triggers: Improvements for default trigger
  2025-03-13 23:56 [PATCH v3] leds: led-triggers: Improvements for default trigger Craig McQueen
@ 2025-03-14  7:54 ` Lee Jones
  2025-03-17 18:56   ` Jacek Anaszewski
  0 siblings, 1 reply; 3+ messages in thread
From: Lee Jones @ 2025-03-14  7:54 UTC (permalink / raw)
  To: Craig McQueen; +Cc: linux-leds, jacek.anaszewski

On Fri, 14 Mar 2025, Craig McQueen wrote:

> Accept "default" written to sysfs trigger attr.
> If the text "default" is written to the LED's sysfs 'trigger' attr, then
> call led_trigger_set_default() to set the LED to its default trigger.
> 
> If the default trigger is set to "none", then led_trigger_set_default()
> will remove a trigger. This is in contrast to the default trigger being
> unset, in which case led_trigger_set_default() does nothing.

I can't take this without a SoB.

It would be nice to have Jacek's Reviewed-by at this point too.

> ---
>  Documentation/ABI/testing/sysfs-class-led |  6 ++++++
>  drivers/leds/led-triggers.c               | 13 +++++++++++++
>  2 files changed, 19 insertions(+)
> 
> diff --git a/Documentation/ABI/testing/sysfs-class-led b/Documentation/ABI/testing/sysfs-class-led
> index 2e24ac3bd7ef..0313b82644f2 100644
> --- a/Documentation/ABI/testing/sysfs-class-led
> +++ b/Documentation/ABI/testing/sysfs-class-led
> @@ -72,6 +72,12 @@ Description:
>  		/sys/class/leds/<led> once a given trigger is selected. For
>  		their documentation see `sysfs-class-led-trigger-*`.
>  
> +		Writing "none" removes the trigger for this LED.
> +
> +		Writing "default" sets the trigger to the LED's default trigger
> +		(which would often be configured in the device tree for the
> +		hardware).
> +
>  What:		/sys/class/leds/<led>/inverted
>  Date:		January 2011
>  KernelVersion:	2.6.38
> diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c
> index b2d40f87a5ff..3799dcc1cf07 100644
> --- a/drivers/leds/led-triggers.c
> +++ b/drivers/leds/led-triggers.c
> @@ -54,6 +54,11 @@ ssize_t led_trigger_write(struct file *filp, struct kobject *kobj,
>  		goto unlock;
>  	}
>  
> +	if (sysfs_streq(buf, "default")) {
> +		led_trigger_set_default(led_cdev);
> +		goto unlock;
> +	}
> +
>  	down_read(&triggers_list_lock);
>  	list_for_each_entry(trig, &trigger_list, next_trig) {
>  		if (sysfs_streq(buf, trig->name) && trigger_relevant(led_cdev, trig)) {
> @@ -98,6 +103,9 @@ static int led_trigger_format(char *buf, size_t size,
>  	int len = led_trigger_snprintf(buf, size, "%s",
>  				       led_cdev->trigger ? "none" : "[none]");
>  
> +	if (led_cdev->default_trigger)
> +		len += led_trigger_snprintf(buf + len, size - len, " default");
> +
>  	list_for_each_entry(trig, &trigger_list, next_trig) {
>  		bool hit;
>  
> @@ -281,6 +289,11 @@ void led_trigger_set_default(struct led_classdev *led_cdev)
>  	if (!led_cdev->default_trigger)
>  		return;
>  
> +	if (!strcmp(led_cdev->default_trigger, "none")) {
> +		led_trigger_remove(led_cdev);
> +		return;
> +	}
> +
>  	down_read(&triggers_list_lock);
>  	down_write(&led_cdev->trigger_lock);
>  	list_for_each_entry(trig, &trigger_list, next_trig) {
> -- 
> 2.48.1
> 
> 

-- 
Lee Jones [李琼斯]

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

* Re: [PATCH v3] leds: led-triggers: Improvements for default trigger
  2025-03-14  7:54 ` Lee Jones
@ 2025-03-17 18:56   ` Jacek Anaszewski
  0 siblings, 0 replies; 3+ messages in thread
From: Jacek Anaszewski @ 2025-03-17 18:56 UTC (permalink / raw)
  To: Lee Jones, Craig McQueen; +Cc: linux-leds

On 3/14/25 08:54, Lee Jones wrote:
> On Fri, 14 Mar 2025, Craig McQueen wrote:
> 
>> Accept "default" written to sysfs trigger attr.
>> If the text "default" is written to the LED's sysfs 'trigger' attr, then
>> call led_trigger_set_default() to set the LED to its default trigger.
>>
>> If the default trigger is set to "none", then led_trigger_set_default()
>> will remove a trigger. This is in contrast to the default trigger being
>> unset, in which case led_trigger_set_default() does nothing.
> 
> I can't take this without a SoB.
> 
> It would be nice to have Jacek's Reviewed-by at this point too.
> 
>> ---
>>   Documentation/ABI/testing/sysfs-class-led |  6 ++++++
>>   drivers/leds/led-triggers.c               | 13 +++++++++++++
>>   2 files changed, 19 insertions(+)
>>
>> diff --git a/Documentation/ABI/testing/sysfs-class-led b/Documentation/ABI/testing/sysfs-class-led
>> index 2e24ac3bd7ef..0313b82644f2 100644
>> --- a/Documentation/ABI/testing/sysfs-class-led
>> +++ b/Documentation/ABI/testing/sysfs-class-led
>> @@ -72,6 +72,12 @@ Description:
>>   		/sys/class/leds/<led> once a given trigger is selected. For
>>   		their documentation see `sysfs-class-led-trigger-*`.
>>   
>> +		Writing "none" removes the trigger for this LED.
>> +
>> +		Writing "default" sets the trigger to the LED's default trigger
>> +		(which would often be configured in the device tree for the
>> +		hardware).
>> +
>>   What:		/sys/class/leds/<led>/inverted
>>   Date:		January 2011
>>   KernelVersion:	2.6.38
>> diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c
>> index b2d40f87a5ff..3799dcc1cf07 100644
>> --- a/drivers/leds/led-triggers.c
>> +++ b/drivers/leds/led-triggers.c
>> @@ -54,6 +54,11 @@ ssize_t led_trigger_write(struct file *filp, struct kobject *kobj,
>>   		goto unlock;
>>   	}
>>   
>> +	if (sysfs_streq(buf, "default")) {
>> +		led_trigger_set_default(led_cdev);
>> +		goto unlock;
>> +	}
>> +
>>   	down_read(&triggers_list_lock);
>>   	list_for_each_entry(trig, &trigger_list, next_trig) {
>>   		if (sysfs_streq(buf, trig->name) && trigger_relevant(led_cdev, trig)) {
>> @@ -98,6 +103,9 @@ static int led_trigger_format(char *buf, size_t size,
>>   	int len = led_trigger_snprintf(buf, size, "%s",
>>   				       led_cdev->trigger ? "none" : "[none]");
>>   
>> +	if (led_cdev->default_trigger)
>> +		len += led_trigger_snprintf(buf + len, size - len, " default");
>> +
>>   	list_for_each_entry(trig, &trigger_list, next_trig) {
>>   		bool hit;
>>   
>> @@ -281,6 +289,11 @@ void led_trigger_set_default(struct led_classdev *led_cdev)
>>   	if (!led_cdev->default_trigger)
>>   		return;
>>   
>> +	if (!strcmp(led_cdev->default_trigger, "none")) {
>> +		led_trigger_remove(led_cdev);
>> +		return;
>> +	}
>> +
>>   	down_read(&triggers_list_lock);
>>   	down_write(&led_cdev->trigger_lock);
>>   	list_for_each_entry(trig, &trigger_list, next_trig) {
>> -- 
>> 2.48.1
>>
>>

Reviewed-by: Jacek Anaszewski <jacek.anaszewski@gmail.com>

-- 
Best regards,
Jacek Anaszewski


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

end of thread, other threads:[~2025-03-17 18:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-13 23:56 [PATCH v3] leds: led-triggers: Improvements for default trigger Craig McQueen
2025-03-14  7:54 ` Lee Jones
2025-03-17 18:56   ` Jacek Anaszewski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox