ledtrig-ide-disk.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. /* INT_MAX will set each LED to its maximum brightness */
  36. led_trigger_event(ledtrig_ide, INT_MAX);
  37. mod_timer(&ledtrig_ide_timer, jiffies + msecs_to_jiffies(10));
  38. } else {
  39. led_trigger_event(ledtrig_ide, LED_OFF);
  40. }
  41. }
  42. static int __init ledtrig_ide_init(void)
  43. {
  44. led_trigger_register_simple("ide-disk", &ledtrig_ide);
  45. return 0;
  46. }
  47. static void __exit ledtrig_ide_exit(void)
  48. {
  49. led_trigger_unregister_simple(ledtrig_ide);
  50. }
  51. module_init(ledtrig_ide_init);
  52. module_exit(ledtrig_ide_exit);
  53. MODULE_AUTHOR("Richard Purdie <rpurdie@openedhand.com>");
  54. MODULE_DESCRIPTION("LED IDE Disk Activity Trigger");
  55. MODULE_LICENSE("GPL");