* Synchronized led trigger
@ 2015-08-13 7:37 Sean Nyekjær
2015-08-14 8:40 ` Jacek Anaszewski
0 siblings, 1 reply; 2+ messages in thread
From: Sean Nyekjær @ 2015-08-13 7:37 UTC (permalink / raw)
To: linux-leds@vger.kernel.org
[-- Attachment #1: Type: text/plain, Size: 380 bytes --]
Hi
I couldn't find any synchronized led triggers in the kernel. The timer trigger was blinking in random when I tried to set our 5 leds. :-)
So i created this led trigger, which can blink with a half and one hz.
Is there any place for something like this upstream? I'm prepared to make changes so it can be configured by the dtb or some other way.
Cheers
Sean Nyekjær
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Added-synchronized-ledtrigger-driver-for-half-and-on.patch --]
[-- Type: text/x-diff; name="0001-Added-synchronized-ledtrigger-driver-for-half-and-on.patch", Size: 3440 bytes --]
From 2a20ac5b7bd56958b39e9e385a2a99c4047c9e7d Mon Sep 17 00:00:00 2001
From: Sean Nyekjaer <sean.nyekjaer@prevas.dk>
Date: Wed, 12 Aug 2015 14:54:38 +0200
Subject: [PATCH 1/1] Added synchronized ledtrigger driver for half and one HZ
blinking
---
drivers/leds/trigger/Kconfig | 6 ++++
drivers/leds/trigger/Makefile | 1 +
drivers/leds/trigger/ledtrig-sync.c | 69 +++++++++++++++++++++++++++++++++++++
3 files changed, 76 insertions(+)
create mode 100644 drivers/leds/trigger/ledtrig-sync.c
diff --git a/drivers/leds/trigger/Kconfig b/drivers/leds/trigger/Kconfig
index 49794b4..9021f03 100644
--- a/drivers/leds/trigger/Kconfig
+++ b/drivers/leds/trigger/Kconfig
@@ -108,4 +108,10 @@ config LEDS_TRIGGER_CAMERA
This enables direct flash/torch on/off by the driver, kernel space.
If unsure, say Y.
+config LEDS_TRIGGER_SYNC
+ tristate "LED Synchronized Trigger"
+ depends on LEDS_TRIGGERS
+ help
+ This allows LEDS to be synchronized agains a kernel timer to a half or one HZ.
+
endif # LEDS_TRIGGERS
diff --git a/drivers/leds/trigger/Makefile b/drivers/leds/trigger/Makefile
index 1abf48d..d8f6369 100644
--- a/drivers/leds/trigger/Makefile
+++ b/drivers/leds/trigger/Makefile
@@ -8,3 +8,4 @@ obj-$(CONFIG_LEDS_TRIGGER_CPU) += ledtrig-cpu.o
obj-$(CONFIG_LEDS_TRIGGER_DEFAULT_ON) += ledtrig-default-on.o
obj-$(CONFIG_LEDS_TRIGGER_TRANSIENT) += ledtrig-transient.o
obj-$(CONFIG_LEDS_TRIGGER_CAMERA) += ledtrig-camera.o
+obj-$(CONFIG_LEDS_TRIGGER_SYNC) += ledtrig-sync.o
diff --git a/drivers/leds/trigger/ledtrig-sync.c b/drivers/leds/trigger/ledtrig-sync.c
new file mode 100644
index 0000000..bc0467e
--- /dev/null
+++ b/drivers/leds/trigger/ledtrig-sync.c
@@ -0,0 +1,69 @@
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/leds.h>
+#include <linux/timer.h>
+
+struct sync_led_data {
+ struct led_trigger *onehz;
+ struct led_trigger *halfhz;
+ bool on;
+ char skip;
+} sync_data;
+
+static struct timer_list check_timer;
+
+static void timer_callback(unsigned long data)
+{
+ unsigned long j = jiffies;
+ switch (sync_data.skip) {
+ case 0:
+ led_trigger_event(sync_data.onehz, LED_FULL);
+ led_trigger_event(sync_data.halfhz, LED_FULL);
+ break;
+ case 1:
+ led_trigger_event(sync_data.halfhz, LED_OFF);
+ break;
+ case 2:
+ led_trigger_event(sync_data.onehz, LED_OFF);
+ led_trigger_event(sync_data.halfhz, LED_FULL);
+ break;
+ case 3:
+ led_trigger_event(sync_data.halfhz, LED_OFF);
+ break;
+ default:
+ led_trigger_event(sync_data.onehz, LED_OFF);
+ led_trigger_event(sync_data.halfhz, LED_OFF);
+ }
+ sync_data.skip++;
+ if(sync_data.skip == 4)
+ sync_data.skip = 0;
+ mod_timer(&check_timer, jiffies + msecs_to_jiffies(500) -(jiffies - j) );
+}
+
+static int __init sync_trig_init(void)
+{
+ sync_data.on = false;
+
+ led_trigger_register_simple("halfhz", &sync_data.halfhz);
+ led_trigger_register_simple("onehz", &sync_data.onehz);
+
+ init_timer(&check_timer);
+ setup_timer( &check_timer, timer_callback, 0 );
+ mod_timer(&check_timer, jiffies + msecs_to_jiffies(500) );
+
+ return 0;
+}
+
+static void __exit sync_trig_exit(void)
+{
+ del_timer_sync(&check_timer);
+ led_trigger_unregister_simple(sync_data.halfhz);
+ led_trigger_unregister_simple(sync_data.onehz);
+}
+
+module_init(sync_trig_init);
+module_exit(sync_trig_exit);
+
+MODULE_DESCRIPTION("Half and One HZ timer led trigger");
+MODULE_AUTHOR("Prevas A/S");
+MODULE_LICENSE("GPL");
--
2.5.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: Synchronized led trigger
2015-08-13 7:37 Synchronized led trigger Sean Nyekjær
@ 2015-08-14 8:40 ` Jacek Anaszewski
0 siblings, 0 replies; 2+ messages in thread
From: Jacek Anaszewski @ 2015-08-14 8:40 UTC (permalink / raw)
To: Sean Nyekjær; +Cc: linux-leds@vger.kernel.org
Hi Sean,
On 08/13/2015 09:37 AM, Sean Nyekjær wrote:
> Hi
>
> I couldn't find any synchronized led triggers in the kernel. The timer trigger was blinking in random when I tried to set our 5 leds. :-)
It is impossible to synchronize brightness setting operation for
different devices. It would only make sense for two separate
LED class devices exposed by a driver controlling one hardware
device. Effectively the issue boils down to the problem of
adding an API for synchronizing brightness setting operation
for several LED class devices exposed by a single LED class
driver. We were trying to implement similar functionality
for synchronizing flash strobe for LED flash class devices,
but it has been given up. You could try to pursue the subject
if you want, here are references: [1], [2].
> So i created this led trigger, which can blink with a half and one hz.
>
> Is there any place for something like this upstream? I'm prepared to make changes so it can be configured by the dtb or some other way.
>
> Cheers
> Sean Nyekjær
>
[1] https://lwn.net/Articles/634465/
[2] http://www.spinics.net/lists/linux-leds/msg02995.html
--
Best Regards,
Jacek Anaszewski
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-08-14 8:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-13 7:37 Synchronized led trigger Sean Nyekjær
2015-08-14 8:40 ` Jacek Anaszewski
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.