ledtrig-ide-disk.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  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. #include <linux/module.h>
  14. #include <linux/jiffies.h>
  15. #include <linux/kernel.h>
  16. #include <linux/init.h>
  17. #include <linux/timer.h>
  18. #include <linux/leds.h>
  19. static void ledtrig_ide_timerfunc(unsigned long data);
  20. DEFINE_LED_TRIGGER(ledtrig_ide);
  21. static DEFINE_TIMER(ledtrig_ide_timer, ledtrig_ide_timerfunc, 0, 0);
  22. static int ide_activity;
  23. static int ide_lastactivity;
  24. void ledtrig_ide_activity(void)
  25. {
  26. ide_activity++;
  27. if (!timer_pending(&ledtrig_ide_timer))
  28. mod_timer(&ledtrig_ide_timer, jiffies + msecs_to_jiffies(10));
  29. }
  30. EXPORT_SYMBOL(ledtrig_ide_activity);
  31. static void ledtrig_ide_timerfunc(unsigned long data)
  32. {
  33. if (ide_lastactivity != ide_activity) {
  34. ide_lastactivity = ide_activity;
  35. led_trigger_event(ledtrig_ide, LED_FULL);
  36. mod_timer(&ledtrig_ide_timer, jiffies + msecs_to_jiffies(10));
  37. } else {
  38. led_trigger_event(ledtrig_ide, LED_OFF);
  39. }
  40. }
  41. static int __init ledtrig_ide_init(void)
  42. {
  43. led_trigger_register_simple("ide-disk", &ledtrig_ide);
  44. return 0;
  45. }
  46. static void __exit ledtrig_ide_exit(void)
  47. {
  48. led_trigger_unregister_simple(ledtrig_ide);
  49. }
  50. module_init(ledtrig_ide_init);
  51. module_exit(ledtrig_ide_exit);
  52. MODULE_AUTHOR("Richard Purdie <rpurdie@openedhand.com>");
  53. MODULE_DESCRIPTION("LED IDE Disk Activity Trigger");
  54. MODULE_LICENSE("GPL");