All of lore.kernel.org
 help / color / mirror / Atom feed
From: chaochao2021666@163.com
To: pavel@ucw.cz
Cc: linux-leds@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, jan.kiszk@siemens.com,
	464759471@qq.com, chao zeng <chao.zeng@siemens.com>
Subject: [PATCH 1/3] leds:triggers:Extend the kernel panic LED trigger
Date: Mon,  6 Sep 2021 21:53:18 +0800	[thread overview]
Message-ID: <20210906135320.23134-1-chaochao2021666@163.com> (raw)

From: chao zeng <chao.zeng@siemens.com>

This commit extend panic trigger, add two new panic trigger
"panic_on" and "panic_off" and keep the "panic" compatible with
"panic_blink".

All the led on the "panic_on" would light and on
the "panic_off" would turn off

Expand the panic state of led to meet more requirements

Signed-off-by: chao zeng <chao.zeng@siemens.com>
---
 drivers/leds/trigger/ledtrig-panic.c | 39 ++++++++++++++++++++++------
 1 file changed, 31 insertions(+), 8 deletions(-)

diff --git a/drivers/leds/trigger/ledtrig-panic.c b/drivers/leds/trigger/ledtrig-panic.c
index 64abf2e91608..1274bc94b5dd 100644
--- a/drivers/leds/trigger/ledtrig-panic.c
+++ b/drivers/leds/trigger/ledtrig-panic.c
@@ -12,19 +12,26 @@
 #include <linux/leds.h>
 #include "../leds.h"
 
-static struct led_trigger *trigger;
+enum led_display_type {
+	ON,
+	OFF,
+	BLINK,
+	DISPLAY_TYPE_COUNT,
+};
+
+static struct led_trigger *panic_trigger[DISPLAY_TYPE_COUNT];
 
 /*
  * This is called in a special context by the atomic panic
  * notifier. This means the trigger can be changed without
  * worrying about locking.
  */
-static void led_trigger_set_panic(struct led_classdev *led_cdev)
+static void led_trigger_set_panic(struct led_classdev *led_cdev, const char *type)
 {
 	struct led_trigger *trig;
 
 	list_for_each_entry(trig, &trigger_list, next_trig) {
-		if (strcmp("panic", trig->name))
+		if (strcmp(type, trig->name))
 			continue;
 		if (led_cdev->trigger)
 			list_del(&led_cdev->trig_list);
@@ -37,6 +44,10 @@ static void led_trigger_set_panic(struct led_classdev *led_cdev)
 		led_cdev->trigger = trig;
 		if (trig->activate)
 			trig->activate(led_cdev);
+
+		/*Clear current brightness work*/
+		led_cdev->work_flags = 0;
+
 		break;
 	}
 }
@@ -48,7 +59,12 @@ static int led_trigger_panic_notifier(struct notifier_block *nb,
 
 	list_for_each_entry(led_cdev, &leds_list, node)
 		if (led_cdev->flags & LED_PANIC_INDICATOR)
-			led_trigger_set_panic(led_cdev);
+			led_trigger_set_panic(led_cdev, "panic");
+		else if (led_cdev->flags & LED_PANIC_INDICATOR_ON)
+			led_trigger_set_panic(led_cdev, "panic_on");
+		else if (led_cdev->flags & LED_PANIC_INDICATOR_OFF)
+			led_trigger_set_panic(led_cdev, "panic_off");
+
 	return NOTIFY_DONE;
 }
 
@@ -56,9 +72,12 @@ static struct notifier_block led_trigger_panic_nb = {
 	.notifier_call = led_trigger_panic_notifier,
 };
 
-static long led_panic_blink(int state)
+static long led_panic_activity(int state)
 {
-	led_trigger_event(trigger, state ? LED_FULL : LED_OFF);
+	led_trigger_event(panic_trigger[BLINK], state ? LED_FULL : LED_OFF);
+	led_trigger_event(panic_trigger[ON], LED_FULL);
+	led_trigger_event(panic_trigger[OFF], LED_OFF);
+
 	return 0;
 }
 
@@ -67,8 +86,12 @@ static int __init ledtrig_panic_init(void)
 	atomic_notifier_chain_register(&panic_notifier_list,
 				       &led_trigger_panic_nb);
 
-	led_trigger_register_simple("panic", &trigger);
-	panic_blink = led_panic_blink;
+	led_trigger_register_simple("panic", &panic_trigger[BLINK]);
+	led_trigger_register_simple("panic_on", &panic_trigger[ON]);
+	led_trigger_register_simple("panic_off", &panic_trigger[OFF]);
+
+	panic_blink = led_panic_activity;
+
 	return 0;
 }
 device_initcall(ledtrig_panic_init);
-- 
2.17.1



             reply	other threads:[~2021-09-06 13:55 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-06 13:53 chaochao2021666 [this message]
2021-09-06 13:53 ` [PATCH 2/3] leds:gpio:Add the support for "panic-indicator-on" and "panic-indicator-off" chaochao2021666
2021-09-06 13:53 ` [PATCH 3/3] dt-bindings:leds:Extend panic led state chaochao2021666
2021-09-07 12:20 ` [PATCH 1/3] leds:triggers:Extend the kernel panic LED trigger Marek Behún
     [not found]   ` <12734c2f.116c.17bc3147806.Coremail.chaochao2021666@163.com>
2021-09-08  5:29     ` Jan Kiszka

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210906135320.23134-1-chaochao2021666@163.com \
    --to=chaochao2021666@163.com \
    --cc=464759471@qq.com \
    --cc=chao.zeng@siemens.com \
    --cc=devicetree@vger.kernel.org \
    --cc=jan.kiszk@siemens.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=pavel@ucw.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.