This patch set adds a new led trigger which emulates the backlight
behaviour: the leds are turned off and on each time the display blanks
and unblacks.
Since backlights are usually implemented with leds this patch set is
useful for those drivers whose manage leds controller used as
backlight controller.
The driver simply registers itself into the led subsystem and then the
user may get backlight emulation by setting the "backlight"
trigger. Moreover a driver, which usually manages more than one led,
can use some leds as "led" and the others as "backlights" at user
request.
Rodolfo
---
CHANGELOG:
V2 ---> V3:
* Avoid that two consecutive blank commands as follow:
echo 1 > /sys/class/graphics/fb0/blank
echo 1 > /sys/class/graphics/fb0/blank
may vanish unblank led intensity status.
From: Rodolfo Giometti <[email protected]>
This allows LEDs to be controlled as a backlight device: they turn off
and on when the display is blanked and unblanked.
Signed-off-by: Rodolfo Giometti <[email protected]>
---
drivers/leds/Kconfig | 9 +++
drivers/leds/Makefile | 1 +
drivers/leds/ledtrig-backlight.c | 110 ++++++++++++++++++++++++++++++++++++++
3 files changed, 120 insertions(+), 0 deletions(-)
create mode 100644 drivers/leds/ledtrig-backlight.c
diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index 9556262..7f2294c 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -199,6 +199,15 @@ config LEDS_TRIGGER_HEARTBEAT
load average.
If unsure, say Y.
+config LEDS_TRIGGER_BACKLIGHT
+ tristate "LED backlight Trigger"
+ depends on LEDS_TRIGGERS
+ help
+ This allows LEDs to be controlled as a backlight device: they
+ turn off and on when the display is blanked and unblanked.
+
+ If unsure, say N.
+
config LEDS_TRIGGER_DEFAULT_ON
tristate "LED Default ON Trigger"
depends on LEDS_TRIGGERS
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index ff7982b..78d07ba 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -28,4 +28,5 @@ obj-$(CONFIG_LEDS_PCA955X) += leds-pca955x.o
obj-$(CONFIG_LEDS_TRIGGER_TIMER) += ledtrig-timer.o
obj-$(CONFIG_LEDS_TRIGGER_IDE_DISK) += ledtrig-ide-disk.o
obj-$(CONFIG_LEDS_TRIGGER_HEARTBEAT) += ledtrig-heartbeat.o
+obj-$(CONFIG_LEDS_TRIGGER_BACKLIGHT) += ledtrig-backlight.o
obj-$(CONFIG_LEDS_TRIGGER_DEFAULT_ON) += ledtrig-default-on.o
diff --git a/drivers/leds/ledtrig-backlight.c b/drivers/leds/ledtrig-backlight.c
new file mode 100644
index 0000000..d3dfcfb
--- /dev/null
+++ b/drivers/leds/ledtrig-backlight.c
@@ -0,0 +1,110 @@
+/*
+ * Backlight emulation LED trigger
+ *
+ * Copyright 2008 (C) Rodolfo Giometti <[email protected]>
+ * Copyright 2008 (C) Eurotech S.p.A. <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/fb.h>
+#include <linux/leds.h>
+#include "leds.h"
+
+#define BLANK 1
+#define UNBLANK 0
+
+struct bl_trig_notifier {
+ struct led_classdev *led;
+ int brightness;
+ int old_status;
+ struct notifier_block notifier;
+};
+
+static int fb_notifier_callback(struct notifier_block *p,
+ unsigned long event, void *data)
+{
+ struct bl_trig_notifier *n = container_of(p,
+ struct bl_trig_notifier, notifier);
+ struct led_classdev *led = n->led;
+ struct fb_event *fb_event = data;
+ int *blank = fb_event->data;
+
+ switch (event) {
+ case FB_EVENT_BLANK :
+ if (*blank && n->old_status == UNBLANK) {
+ n->brightness = led->brightness;
+ led_set_brightness(led, LED_OFF);
+ n->old_status = BLANK;
+ } else if (!*blank && n->old_status == BLANK) {
+ led_set_brightness(led, n->brightness);
+ n->old_status = UNBLANK;
+ }
+ break;
+ }
+
+ return 0;
+}
+
+static void bl_trig_activate(struct led_classdev *led)
+{
+ int ret;
+
+ struct bl_trig_notifier *n;
+
+ n = kzalloc(sizeof(struct bl_trig_notifier), GFP_KERNEL);
+ led->trigger_data = n;
+ if (!n) {
+ dev_err(led->dev, "unable to allocate backlight trigger\n");
+ return;
+ }
+
+ n->led = led;
+ n->brightness = led->brightness;
+ n->old_status = UNBLANK;
+ n->notifier.notifier_call = fb_notifier_callback;
+
+ ret = fb_register_client(&n->notifier);
+ if (ret)
+ dev_err(led->dev, "unable to register backlight trigger\n");
+}
+
+static void bl_trig_deactivate(struct led_classdev *led)
+{
+ struct bl_trig_notifier *n =
+ (struct bl_trig_notifier *) led->trigger_data;
+
+ if (n) {
+ fb_unregister_client(&n->notifier);
+ kfree(n);
+ }
+}
+
+static struct led_trigger bl_led_trigger = {
+ .name = "backlight",
+ .activate = bl_trig_activate,
+ .deactivate = bl_trig_deactivate
+};
+
+static int __init bl_trig_init(void)
+{
+ return led_trigger_register(&bl_led_trigger);
+}
+
+static void __exit bl_trig_exit(void)
+{
+ led_trigger_unregister(&bl_led_trigger);
+}
+
+module_init(bl_trig_init);
+module_exit(bl_trig_exit);
+
+MODULE_AUTHOR("Rodolfo Giometti <[email protected]>");
+MODULE_DESCRIPTION("Backlight emulation LED trigger");
+MODULE_LICENSE("GPL v2");
--
1.5.4.3
Hi!
> This patch set adds a new led trigger which emulates the backlight
> behaviour: the leds are turned off and on each time the display blanks
> and unblacks.
>
> Since backlights are usually implemented with leds this patch set is
> useful for those drivers whose manage leds controller used as
> backlight controller.
>
> The driver simply registers itself into the led subsystem and then the
> user may get backlight emulation by setting the "backlight"
> trigger. Moreover a driver, which usually manages more than one led,
> can use some leds as "led" and the others as "backlights" at user
> request.
We already have backlight subsystem, it can also handle display
brightness. Why not use that?
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
On Tue, Oct 07, 2008 at 03:54:20PM +0200, Pavel Machek wrote:
> Hi!
>
> > This patch set adds a new led trigger which emulates the backlight
> > behaviour: the leds are turned off and on each time the display blanks
> > and unblacks.
> >
> > Since backlights are usually implemented with leds this patch set is
> > useful for those drivers whose manage leds controller used as
> > backlight controller.
> >
> > The driver simply registers itself into the led subsystem and then the
> > user may get backlight emulation by setting the "backlight"
> > trigger. Moreover a driver, which usually manages more than one led,
> > can use some leds as "led" and the others as "backlights" at user
> > request.
>
> We already have backlight subsystem, it can also handle display
> brightness. Why not use that?
Just to use a led as "led" or as "backlight" at user request. You can
do it by using:
echo none > /sys/class/leds/lcd/trigger
echo backlight > /sys/class/leds/lcd/trigger
and the led will work accordingly.
Also a led used as "backlight" is just a normal led (you can set the
brightness as a normal led) but it switchs off automatically when the
LCD blanks.
Ciao,
Rodolfo
--
GNU/Linux Solutions e-mail: [email protected]
Linux Device Driver [email protected]
Embedded Systems phone: +39 349 2432127
UNIX programming skype: rodolfo.giometti
On Tue 2008-10-07 17:20:32, Rodolfo Giometti wrote:
> On Tue, Oct 07, 2008 at 03:54:20PM +0200, Pavel Machek wrote:
> > Hi!
> >
> > > This patch set adds a new led trigger which emulates the backlight
> > > behaviour: the leds are turned off and on each time the display blanks
> > > and unblacks.
> > >
> > > Since backlights are usually implemented with leds this patch set is
> > > useful for those drivers whose manage leds controller used as
> > > backlight controller.
> > >
> > > The driver simply registers itself into the led subsystem and then the
> > > user may get backlight emulation by setting the "backlight"
> > > trigger. Moreover a driver, which usually manages more than one led,
> > > can use some leds as "led" and the others as "backlights" at user
> > > request.
> >
> > We already have backlight subsystem, it can also handle display
> > brightness. Why not use that?
>
> Just to use a led as "led" or as "backlight" at user request. You can
> do it by using:
>
> echo none > /sys/class/leds/lcd/trigger
> echo backlight > /sys/class/leds/lcd/trigger
>
> and the led will work accordingly.
>
> Also a led used as "backlight" is just a normal led (you can set the
> brightness as a normal led) but it switchs off automatically when the
> LCD blanks.
Ok, what is it good for? So I have backlight, charging led and hdd led
on my zaurus. Now I can set charging led to indicate backlight... but
why is it useful?
Pavel
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
On Tue, Oct 07, 2008 at 08:58:46PM +0200, Pavel Machek wrote:
>
> Ok, what is it good for? So I have backlight, charging led and hdd led
> on my zaurus. Now I can set charging led to indicate backlight... but
> why is it useful?
On my board, for example, I have a led for each "special" buttons and
others to indicate to the user some "special" conditions of machine
internals. All these leds should be switched off each time the LCD
blanks and they should get their old brightness status when the LCD
unblanks.
Ciao,
Rodolfo
--
GNU/Linux Solutions e-mail: [email protected]
Linux Device Driver [email protected]
Embedded Systems phone: +39 349 2432127
UNIX programming skype: rodolfo.giometti
On Tue 2008-10-07 21:21:12, Rodolfo Giometti wrote:
> On Tue, Oct 07, 2008 at 08:58:46PM +0200, Pavel Machek wrote:
> >
> > Ok, what is it good for? So I have backlight, charging led and hdd led
> > on my zaurus. Now I can set charging led to indicate backlight... but
> > why is it useful?
>
> On my board, for example, I have a led for each "special" buttons and
> others to indicate to the user some "special" conditions of machine
> internals. All these leds should be switched off each time the LCD
> blanks and they should get their old brightness status when the LCD
> unblanks.
Hmm, what's "your board"?
But ok, I guess that makes some sense, additionally it would be useful
for keyboard backlight...
In fact, thinkpad light should probably behave like that, too...
Pavel
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
On Tue, Oct 07, 2008 at 09:56:48PM +0200, Pavel Machek wrote:
> On Tue 2008-10-07 21:21:12, Rodolfo Giometti wrote:
> > On my board, for example, I have a led for each "special" buttons and
> > others to indicate to the user some "special" conditions of machine
> > internals. All these leds should be switched off each time the LCD
> > blanks and they should get their old brightness status when the LCD
> > unblanks.
>
> Hmm, what's "your board"?
Sorry, I meant "my custom board". :) It's PXA270 based but it's not
into Linux main tree.
> But ok, I guess that makes some sense, additionally it would be useful
> for keyboard backlight...
>
> In fact, thinkpad light should probably behave like that, too...
:)
Ciao,
Rodolfo
--
GNU/Linux Solutions e-mail: [email protected]
Linux Device Driver [email protected]
Embedded Systems phone: +39 349 2432127
UNIX programming skype: rodolfo.giometti
On Tue, Oct 07, 2008 at 10:19:54PM +0200, Rodolfo Giometti wrote:
> On Tue, Oct 07, 2008 at 09:56:48PM +0200, Pavel Machek wrote:
> > Hmm, what's "your board"?
> Sorry, I meant "my custom board". :) It's PXA270 based but it's not
> into Linux main tree.
Another example, support for which should be coming shortly, is the LED
driver provided by the WM8350: this is a PMIC capable of producing outputs
to drive LEDs, potentially strings of very bright LEDs. This is frequently
used to illuminate displays but the actual function depends entirely on how
the system has been wired up.
The implementation is identical no matter what the LEDs are doing but the
current out of tree drivers have two drivers for this bit of the hardware,
one for use in the normal LED case and one for when used as a backlight,
which is redundnant. With the driver Rodolfo has written this should no
longer be required and the backlight trigger can be used to share the
hardware interface code.
On Tue, 07 Oct 2008, Pavel Machek wrote:
> In fact, thinkpad light should probably behave like that, too...
It is supposed to, and actually does so in my T43 without any extra help :-)
But if it doesn't in your ThinkPad, thinkpad-acpi does export a LED
interface for the ThinkLight and this new tigger will fix it for you right
away :p
--
"One disk to rule them all, One disk to find them. One disk to bring
them all and in the darkness grind them. In the Land of Redmond
where the shadows lie." -- The Silicon Valley Tarot
Henrique Holschuh
On Tue 2008-10-07 21:39:46, Mark Brown wrote:
> On Tue, Oct 07, 2008 at 10:19:54PM +0200, Rodolfo Giometti wrote:
> > On Tue, Oct 07, 2008 at 09:56:48PM +0200, Pavel Machek wrote:
>
> > > Hmm, what's "your board"?
>
> > Sorry, I meant "my custom board". :) It's PXA270 based but it's not
> > into Linux main tree.
>
> Another example, support for which should be coming shortly, is the LED
> driver provided by the WM8350: this is a PMIC capable of producing outputs
> to drive LEDs, potentially strings of very bright LEDs. This is frequently
> used to illuminate displays but the actual function depends entirely on how
> the system has been wired up.
>
> The implementation is identical no matter what the LEDs are doing but the
> current out of tree drivers have two drivers for this bit of the hardware,
> one for use in the normal LED case and one for when used as a backlight,
> which is redundnant. With the driver Rodolfo has written this should no
> longer be required and the backlight trigger can be used to share the
> hardware interface code.
Well, Rodolfo's patch will not allow you to set backlight brightness,
only on/off, right?
So if your leds are really a backlight, you still should use backlight
class directly...
Pavel
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
On Tue, Oct 07, 2008 at 11:19:17PM +0200, Pavel Machek wrote:
> Well, Rodolfo's patch will not allow you to set backlight brightness,
> only on/off, right?
No, you can set the backlight brightness, but when the LCD blanks it
is set to zero and it get back to its previous status when the LCD
unblanks.
Ciao,
Rodolfo
--
GNU/Linux Solutions e-mail: [email protected]
Linux Device Driver [email protected]
Embedded Systems phone: +39 349 2432127
UNIX programming skype: rodolfo.giometti
On Tue, 2008-10-07 at 12:10 +0200, Rodolfo Giometti wrote:
> This allows LEDs to be controlled as a backlight device: they turn off
> and on when the display is blanked and unblanked.
>
> Signed-off-by: Rodolfo Giometti <[email protected]>
Added to the LEDs tree, thanks.
Richard