led.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * linux/arch/sh/kernel/led_bigsur.c
  3. *
  4. * By Dustin McIntire (dustin@sensoria.com) (c)2001
  5. * Derived from led_se.c and led.c, which bore the message:
  6. * Copyright (C) 2000 Stuart Menefy <stuart.menefy@st.com>
  7. *
  8. * May be copied or modified under the terms of the GNU General Public
  9. * License. See linux/COPYING for more information.
  10. *
  11. * This file contains Big Sur specific LED code.
  12. */
  13. #include <linux/config.h>
  14. #include <asm/io.h>
  15. #include <asm/bigsur/bigsur.h>
  16. static void mach_led(int position, int value)
  17. {
  18. int word;
  19. word = bigsur_inl(BIGSUR_CSLR);
  20. if (value) {
  21. bigsur_outl(word & ~BIGSUR_LED, BIGSUR_CSLR);
  22. } else {
  23. bigsur_outl(word | BIGSUR_LED, BIGSUR_CSLR);
  24. }
  25. }
  26. #ifdef CONFIG_HEARTBEAT
  27. #include <linux/sched.h>
  28. /* Cycle the LED on/off */
  29. void heartbeat_bigsur(void)
  30. {
  31. static unsigned cnt = 0, period = 0, dist = 0;
  32. if (cnt == 0 || cnt == dist)
  33. mach_led( -1, 1);
  34. else if (cnt == 7 || cnt == dist+7)
  35. mach_led( -1, 0);
  36. if (++cnt > period) {
  37. cnt = 0;
  38. /* The hyperbolic function below modifies the heartbeat period
  39. * length in dependency of the current (5min) load. It goes
  40. * through the points f(0)=126, f(1)=86, f(5)=51,
  41. * f(inf)->30. */
  42. period = ((672<<FSHIFT)/(5*avenrun[0]+(7<<FSHIFT))) + 30;
  43. dist = period / 4;
  44. }
  45. }
  46. #endif /* CONFIG_HEARTBEAT */