blob: ec099fcbcb00ecf01c4f8ef4313710230428b15b [file] [log] [blame]
Richard Purdie2bfb6462006-03-31 02:31:16 -08001/*
2 * LED IDE-Disk Activity Trigger
3 *
4 * Copyright 2006 Openedhand Ltd.
5 *
6 * Author: Richard Purdie <rpurdie@openedhand.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 */
13
14#include <linux/module.h>
Al Virof6a57032006-10-18 01:47:25 -040015#include <linux/jiffies.h>
Richard Purdie2bfb6462006-03-31 02:31:16 -080016#include <linux/kernel.h>
17#include <linux/init.h>
18#include <linux/timer.h>
19#include <linux/leds.h>
20
21static void ledtrig_ide_timerfunc(unsigned long data);
22
23DEFINE_LED_TRIGGER(ledtrig_ide);
24static DEFINE_TIMER(ledtrig_ide_timer, ledtrig_ide_timerfunc, 0, 0);
25static int ide_activity;
26static int ide_lastactivity;
27
28void ledtrig_ide_activity(void)
29{
30 ide_activity++;
31 if (!timer_pending(&ledtrig_ide_timer))
32 mod_timer(&ledtrig_ide_timer, jiffies + msecs_to_jiffies(10));
33}
34EXPORT_SYMBOL(ledtrig_ide_activity);
35
36static void ledtrig_ide_timerfunc(unsigned long data)
37{
38 if (ide_lastactivity != ide_activity) {
39 ide_lastactivity = ide_activity;
Guennadi Liakhovetski1bd465e2009-01-10 18:54:39 +000040 /* INT_MAX will set each LED to its maximum brightness */
41 led_trigger_event(ledtrig_ide, INT_MAX);
Németh Márton4d404fd2008-03-09 20:59:57 +000042 mod_timer(&ledtrig_ide_timer, jiffies + msecs_to_jiffies(10));
Richard Purdie2bfb6462006-03-31 02:31:16 -080043 } else {
44 led_trigger_event(ledtrig_ide, LED_OFF);
45 }
46}
47
48static int __init ledtrig_ide_init(void)
49{
50 led_trigger_register_simple("ide-disk", &ledtrig_ide);
51 return 0;
52}
53
54static void __exit ledtrig_ide_exit(void)
55{
56 led_trigger_unregister_simple(ledtrig_ide);
57}
58
59module_init(ledtrig_ide_init);
60module_exit(ledtrig_ide_exit);
61
62MODULE_AUTHOR("Richard Purdie <rpurdie@openedhand.com>");
63MODULE_DESCRIPTION("LED IDE Disk Activity Trigger");
64MODULE_LICENSE("GPL");