diff options
Diffstat (limited to 'drivers/leds')
-rw-r--r-- | drivers/leds/Kconfig | 9 | ||||
-rw-r--r-- | drivers/leds/Makefile | 1 | ||||
-rw-r--r-- | drivers/leds/ledtrig-heartbeat.c | 118 |
3 files changed, 128 insertions, 0 deletions
diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index f573d5af0b1f..96509989e921 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig | |||
@@ -93,5 +93,14 @@ config LEDS_TRIGGER_IDE_DISK | |||
93 | This allows LEDs to be controlled by IDE disk activity. | 93 | This allows LEDs to be controlled by IDE disk activity. |
94 | If unsure, say Y. | 94 | If unsure, say Y. |
95 | 95 | ||
96 | config LEDS_TRIGGER_HEARTBEAT | ||
97 | tristate "LED Heartbeat Trigger" | ||
98 | depends LEDS_TRIGGERS | ||
99 | help | ||
100 | This allows LEDs to be controlled by a CPU load average. | ||
101 | The flash frequency is a hyperbolic function of the 1-minute | ||
102 | load average. | ||
103 | If unsure, say Y. | ||
104 | |||
96 | endmenu | 105 | endmenu |
97 | 106 | ||
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index dcea1001faa4..88d3b6eaa6a2 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile | |||
@@ -16,3 +16,4 @@ obj-$(CONFIG_LEDS_AMS_DELTA) += leds-ams-delta.o | |||
16 | # LED Triggers | 16 | # LED Triggers |
17 | obj-$(CONFIG_LEDS_TRIGGER_TIMER) += ledtrig-timer.o | 17 | obj-$(CONFIG_LEDS_TRIGGER_TIMER) += ledtrig-timer.o |
18 | obj-$(CONFIG_LEDS_TRIGGER_IDE_DISK) += ledtrig-ide-disk.o | 18 | obj-$(CONFIG_LEDS_TRIGGER_IDE_DISK) += ledtrig-ide-disk.o |
19 | obj-$(CONFIG_LEDS_TRIGGER_HEARTBEAT) += ledtrig-heartbeat.o | ||
diff --git a/drivers/leds/ledtrig-heartbeat.c b/drivers/leds/ledtrig-heartbeat.c new file mode 100644 index 000000000000..4bf8cec8b8c1 --- /dev/null +++ b/drivers/leds/ledtrig-heartbeat.c | |||
@@ -0,0 +1,118 @@ | |||
1 | /* | ||
2 | * LED Heartbeat Trigger | ||
3 | * | ||
4 | * Copyright (C) 2006 Atsushi Nemoto <anemo@mba.ocn.ne.jp> | ||
5 | * | ||
6 | * Based on Richard Purdie's ledtrig-timer.c and some arch's | ||
7 | * CONFIG_HEARTBEAT code. | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License version 2 as | ||
11 | * published by the Free Software Foundation. | ||
12 | * | ||
13 | */ | ||
14 | #include <linux/module.h> | ||
15 | #include <linux/kernel.h> | ||
16 | #include <linux/init.h> | ||
17 | #include <linux/timer.h> | ||
18 | #include <linux/sched.h> | ||
19 | #include <linux/leds.h> | ||
20 | #include "leds.h" | ||
21 | |||
22 | struct heartbeat_trig_data { | ||
23 | unsigned int phase; | ||
24 | unsigned int period; | ||
25 | struct timer_list timer; | ||
26 | }; | ||
27 | |||
28 | static void led_heartbeat_function(unsigned long data) | ||
29 | { | ||
30 | struct led_classdev *led_cdev = (struct led_classdev *) data; | ||
31 | struct heartbeat_trig_data *heartbeat_data = led_cdev->trigger_data; | ||
32 | unsigned long brightness = LED_OFF; | ||
33 | unsigned long delay = 0; | ||
34 | |||
35 | /* acts like an actual heart beat -- ie thump-thump-pause... */ | ||
36 | switch (heartbeat_data->phase) { | ||
37 | case 0: | ||
38 | /* | ||
39 | * The hyperbolic function below modifies the | ||
40 | * heartbeat period length in dependency of the | ||
41 | * current (1min) load. It goes through the points | ||
42 | * f(0)=1260, f(1)=860, f(5)=510, f(inf)->300. | ||
43 | */ | ||
44 | heartbeat_data->period = 300 + | ||
45 | (6720 << FSHIFT) / (5 * avenrun[0] + (7 << FSHIFT)); | ||
46 | heartbeat_data->period = | ||
47 | msecs_to_jiffies(heartbeat_data->period); | ||
48 | delay = msecs_to_jiffies(70); | ||
49 | heartbeat_data->phase++; | ||
50 | brightness = LED_FULL; | ||
51 | break; | ||
52 | case 1: | ||
53 | delay = heartbeat_data->period / 4 - msecs_to_jiffies(70); | ||
54 | heartbeat_data->phase++; | ||
55 | break; | ||
56 | case 2: | ||
57 | delay = msecs_to_jiffies(70); | ||
58 | heartbeat_data->phase++; | ||
59 | brightness = LED_FULL; | ||
60 | break; | ||
61 | default: | ||
62 | delay = heartbeat_data->period - heartbeat_data->period / 4 - | ||
63 | msecs_to_jiffies(70); | ||
64 | heartbeat_data->phase = 0; | ||
65 | break; | ||
66 | } | ||
67 | |||
68 | led_set_brightness(led_cdev, brightness); | ||
69 | mod_timer(&heartbeat_data->timer, jiffies + delay); | ||
70 | } | ||
71 | |||
72 | static void heartbeat_trig_activate(struct led_classdev *led_cdev) | ||
73 | { | ||
74 | struct heartbeat_trig_data *heartbeat_data; | ||
75 | |||
76 | heartbeat_data = kzalloc(sizeof(*heartbeat_data), GFP_KERNEL); | ||
77 | if (!heartbeat_data) | ||
78 | return; | ||
79 | |||
80 | led_cdev->trigger_data = heartbeat_data; | ||
81 | setup_timer(&heartbeat_data->timer, | ||
82 | led_heartbeat_function, (unsigned long) led_cdev); | ||
83 | heartbeat_data->phase = 0; | ||
84 | led_heartbeat_function(heartbeat_data->timer.data); | ||
85 | } | ||
86 | |||
87 | static void heartbeat_trig_deactivate(struct led_classdev *led_cdev) | ||
88 | { | ||
89 | struct heartbeat_trig_data *heartbeat_data = led_cdev->trigger_data; | ||
90 | |||
91 | if (heartbeat_data) { | ||
92 | del_timer_sync(&heartbeat_data->timer); | ||
93 | kfree(heartbeat_data); | ||
94 | } | ||
95 | } | ||
96 | |||
97 | static struct led_trigger heartbeat_led_trigger = { | ||
98 | .name = "heartbeat", | ||
99 | .activate = heartbeat_trig_activate, | ||
100 | .deactivate = heartbeat_trig_deactivate, | ||
101 | }; | ||
102 | |||
103 | static int __init heartbeat_trig_init(void) | ||
104 | { | ||
105 | return led_trigger_register(&heartbeat_led_trigger); | ||
106 | } | ||
107 | |||
108 | static void __exit heartbeat_trig_exit(void) | ||
109 | { | ||
110 | led_trigger_unregister(&heartbeat_led_trigger); | ||
111 | } | ||
112 | |||
113 | module_init(heartbeat_trig_init); | ||
114 | module_exit(heartbeat_trig_exit); | ||
115 | |||
116 | MODULE_AUTHOR("Atsushi Nemoto <anemo@mba.ocn.ne.jp>"); | ||
117 | MODULE_DESCRIPTION("Heartbeat LED trigger"); | ||
118 | MODULE_LICENSE("GPL"); | ||