diff options
-rw-r--r-- | drivers/leds/Kconfig | 9 | ||||
-rw-r--r-- | drivers/leds/Makefile | 1 | ||||
-rw-r--r-- | drivers/leds/ledtrig-backlight.c | 110 |
3 files changed, 120 insertions, 0 deletions
diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 14bb57b16593..2a72ce5c6d1f 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig | |||
@@ -200,6 +200,15 @@ config LEDS_TRIGGER_HEARTBEAT | |||
200 | load average. | 200 | load average. |
201 | If unsure, say Y. | 201 | If unsure, say Y. |
202 | 202 | ||
203 | config LEDS_TRIGGER_BACKLIGHT | ||
204 | tristate "LED backlight Trigger" | ||
205 | depends on LEDS_TRIGGERS | ||
206 | help | ||
207 | This allows LEDs to be controlled as a backlight device: they | ||
208 | turn off and on when the display is blanked and unblanked. | ||
209 | |||
210 | If unsure, say N. | ||
211 | |||
203 | config LEDS_TRIGGER_DEFAULT_ON | 212 | config LEDS_TRIGGER_DEFAULT_ON |
204 | tristate "LED Default ON Trigger" | 213 | tristate "LED Default ON Trigger" |
205 | depends on LEDS_TRIGGERS | 214 | depends on LEDS_TRIGGERS |
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index e8714ad3ffff..07d937f4651d 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile | |||
@@ -28,4 +28,5 @@ obj-$(CONFIG_LEDS_DA903X) += leds-da903x.o | |||
28 | obj-$(CONFIG_LEDS_TRIGGER_TIMER) += ledtrig-timer.o | 28 | obj-$(CONFIG_LEDS_TRIGGER_TIMER) += ledtrig-timer.o |
29 | obj-$(CONFIG_LEDS_TRIGGER_IDE_DISK) += ledtrig-ide-disk.o | 29 | obj-$(CONFIG_LEDS_TRIGGER_IDE_DISK) += ledtrig-ide-disk.o |
30 | obj-$(CONFIG_LEDS_TRIGGER_HEARTBEAT) += ledtrig-heartbeat.o | 30 | obj-$(CONFIG_LEDS_TRIGGER_HEARTBEAT) += ledtrig-heartbeat.o |
31 | obj-$(CONFIG_LEDS_TRIGGER_BACKLIGHT) += ledtrig-backlight.o | ||
31 | obj-$(CONFIG_LEDS_TRIGGER_DEFAULT_ON) += ledtrig-default-on.o | 32 | 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 000000000000..d3dfcfb417b8 --- /dev/null +++ b/drivers/leds/ledtrig-backlight.c | |||
@@ -0,0 +1,110 @@ | |||
1 | /* | ||
2 | * Backlight emulation LED trigger | ||
3 | * | ||
4 | * Copyright 2008 (C) Rodolfo Giometti <giometti@linux.it> | ||
5 | * Copyright 2008 (C) Eurotech S.p.A. <info@eurotech.it> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License version 2 as | ||
9 | * published by the Free Software Foundation. | ||
10 | * | ||
11 | */ | ||
12 | |||
13 | #include <linux/module.h> | ||
14 | #include <linux/kernel.h> | ||
15 | #include <linux/init.h> | ||
16 | #include <linux/fb.h> | ||
17 | #include <linux/leds.h> | ||
18 | #include "leds.h" | ||
19 | |||
20 | #define BLANK 1 | ||
21 | #define UNBLANK 0 | ||
22 | |||
23 | struct bl_trig_notifier { | ||
24 | struct led_classdev *led; | ||
25 | int brightness; | ||
26 | int old_status; | ||
27 | struct notifier_block notifier; | ||
28 | }; | ||
29 | |||
30 | static int fb_notifier_callback(struct notifier_block *p, | ||
31 | unsigned long event, void *data) | ||
32 | { | ||
33 | struct bl_trig_notifier *n = container_of(p, | ||
34 | struct bl_trig_notifier, notifier); | ||
35 | struct led_classdev *led = n->led; | ||
36 | struct fb_event *fb_event = data; | ||
37 | int *blank = fb_event->data; | ||
38 | |||
39 | switch (event) { | ||
40 | case FB_EVENT_BLANK : | ||
41 | if (*blank && n->old_status == UNBLANK) { | ||
42 | n->brightness = led->brightness; | ||
43 | led_set_brightness(led, LED_OFF); | ||
44 | n->old_status = BLANK; | ||
45 | } else if (!*blank && n->old_status == BLANK) { | ||
46 | led_set_brightness(led, n->brightness); | ||
47 | n->old_status = UNBLANK; | ||
48 | } | ||
49 | break; | ||
50 | } | ||
51 | |||
52 | return 0; | ||
53 | } | ||
54 | |||
55 | static void bl_trig_activate(struct led_classdev *led) | ||
56 | { | ||
57 | int ret; | ||
58 | |||
59 | struct bl_trig_notifier *n; | ||
60 | |||
61 | n = kzalloc(sizeof(struct bl_trig_notifier), GFP_KERNEL); | ||
62 | led->trigger_data = n; | ||
63 | if (!n) { | ||
64 | dev_err(led->dev, "unable to allocate backlight trigger\n"); | ||
65 | return; | ||
66 | } | ||
67 | |||
68 | n->led = led; | ||
69 | n->brightness = led->brightness; | ||
70 | n->old_status = UNBLANK; | ||
71 | n->notifier.notifier_call = fb_notifier_callback; | ||
72 | |||
73 | ret = fb_register_client(&n->notifier); | ||
74 | if (ret) | ||
75 | dev_err(led->dev, "unable to register backlight trigger\n"); | ||
76 | } | ||
77 | |||
78 | static void bl_trig_deactivate(struct led_classdev *led) | ||
79 | { | ||
80 | struct bl_trig_notifier *n = | ||
81 | (struct bl_trig_notifier *) led->trigger_data; | ||
82 | |||
83 | if (n) { | ||
84 | fb_unregister_client(&n->notifier); | ||
85 | kfree(n); | ||
86 | } | ||
87 | } | ||
88 | |||
89 | static struct led_trigger bl_led_trigger = { | ||
90 | .name = "backlight", | ||
91 | .activate = bl_trig_activate, | ||
92 | .deactivate = bl_trig_deactivate | ||
93 | }; | ||
94 | |||
95 | static int __init bl_trig_init(void) | ||
96 | { | ||
97 | return led_trigger_register(&bl_led_trigger); | ||
98 | } | ||
99 | |||
100 | static void __exit bl_trig_exit(void) | ||
101 | { | ||
102 | led_trigger_unregister(&bl_led_trigger); | ||
103 | } | ||
104 | |||
105 | module_init(bl_trig_init); | ||
106 | module_exit(bl_trig_exit); | ||
107 | |||
108 | MODULE_AUTHOR("Rodolfo Giometti <giometti@linux.it>"); | ||
109 | MODULE_DESCRIPTION("Backlight emulation LED trigger"); | ||
110 | MODULE_LICENSE("GPL v2"); | ||