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/slab.h>
16 #include <linux/init.h>
18 #include <linux/leds.h>
24 struct bl_trig_notifier
{
25 struct led_classdev
*led
;
28 struct notifier_block notifier
;
31 static int fb_notifier_callback(struct notifier_block
*p
,
32 unsigned long event
, void *data
)
34 struct bl_trig_notifier
*n
= container_of(p
,
35 struct bl_trig_notifier
, notifier
);
36 struct led_classdev
*led
= n
->led
;
37 struct fb_event
*fb_event
= data
;
38 int *blank
= fb_event
->data
;
42 if (*blank
&& n
->old_status
== UNBLANK
) {
43 n
->brightness
= led
->brightness
;
44 led_set_brightness(led
, LED_OFF
);
45 n
->old_status
= BLANK
;
46 } else if (!*blank
&& n
->old_status
== BLANK
) {
47 led_set_brightness(led
, n
->brightness
);
48 n
->old_status
= UNBLANK
;
56 static void bl_trig_activate(struct led_classdev
*led
)
60 struct bl_trig_notifier
*n
;
62 n
= kzalloc(sizeof(struct bl_trig_notifier
), GFP_KERNEL
);
63 led
->trigger_data
= n
;
65 dev_err(led
->dev
, "unable to allocate backlight trigger\n");
70 n
->brightness
= led
->brightness
;
71 n
->old_status
= UNBLANK
;
72 n
->notifier
.notifier_call
= fb_notifier_callback
;
74 ret
= fb_register_client(&n
->notifier
);
76 dev_err(led
->dev
, "unable to register backlight trigger\n");
79 static void bl_trig_deactivate(struct led_classdev
*led
)
81 struct bl_trig_notifier
*n
=
82 (struct bl_trig_notifier
*) led
->trigger_data
;
85 fb_unregister_client(&n
->notifier
);
90 static struct led_trigger bl_led_trigger
= {
92 .activate
= bl_trig_activate
,
93 .deactivate
= bl_trig_deactivate
96 static int __init
bl_trig_init(void)
98 return led_trigger_register(&bl_led_trigger
);
101 static void __exit
bl_trig_exit(void)
103 led_trigger_unregister(&bl_led_trigger
);
106 module_init(bl_trig_init
);
107 module_exit(bl_trig_exit
);
109 MODULE_AUTHOR("Rodolfo Giometti <giometti@linux.it>");
110 MODULE_DESCRIPTION("Backlight emulation LED trigger");
111 MODULE_LICENSE("GPL v2");