2 * Backlight emulation LED trigger
4 * Copyright 2008 (C) Rodolfo Giometti <giometti@linux.it>
5 * Copyright 2008 (C) Eurotech S.p.A. <info@eurotech.it>
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.
13 #include <linux/module.h>
14 #include <linux/kernel.h>
15 #include <linux/init.h>
17 #include <linux/leds.h>
23 struct bl_trig_notifier
{
24 struct led_classdev
*led
;
27 struct notifier_block notifier
;
30 static int fb_notifier_callback(struct notifier_block
*p
,
31 unsigned long event
, void *data
)
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
;
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
;
55 static void bl_trig_activate(struct led_classdev
*led
)
59 struct bl_trig_notifier
*n
;
61 n
= kzalloc(sizeof(struct bl_trig_notifier
), GFP_KERNEL
);
62 led
->trigger_data
= n
;
64 dev_err(led
->dev
, "unable to allocate backlight trigger\n");
69 n
->brightness
= led
->brightness
;
70 n
->old_status
= UNBLANK
;
71 n
->notifier
.notifier_call
= fb_notifier_callback
;
73 ret
= fb_register_client(&n
->notifier
);
75 dev_err(led
->dev
, "unable to register backlight trigger\n");
78 static void bl_trig_deactivate(struct led_classdev
*led
)
80 struct bl_trig_notifier
*n
=
81 (struct bl_trig_notifier
*) led
->trigger_data
;
84 fb_unregister_client(&n
->notifier
);
89 static struct led_trigger bl_led_trigger
= {
91 .activate
= bl_trig_activate
,
92 .deactivate
= bl_trig_deactivate
95 static int __init
bl_trig_init(void)
97 return led_trigger_register(&bl_led_trigger
);
100 static void __exit
bl_trig_exit(void)
102 led_trigger_unregister(&bl_led_trigger
);
105 module_init(bl_trig_init
);
106 module_exit(bl_trig_exit
);
108 MODULE_AUTHOR("Rodolfo Giometti <giometti@linux.it>");
109 MODULE_DESCRIPTION("Backlight emulation LED trigger");
110 MODULE_LICENSE("GPL v2");