led.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * linux/arch/sh/overdrive/led.c
  3. *
  4. * Copyright (C) 1999 Stuart Menefy <stuart.menefy@st.com>
  5. *
  6. * May be copied or modified under the terms of the GNU General Public
  7. * License. See linux/COPYING for more information.
  8. *
  9. * This file contains an Overdrive specific LED feature.
  10. */
  11. #include <asm/system.h>
  12. #include <asm/io.h>
  13. #include <asm/overdrive/overdrive.h>
  14. static void mach_led(int position, int value)
  15. {
  16. unsigned long flags;
  17. unsigned long reg;
  18. local_irq_save(flags);
  19. reg = readl(OVERDRIVE_CTRL);
  20. if (value) {
  21. reg |= (1<<3);
  22. } else {
  23. reg &= ~(1<<3);
  24. }
  25. writel(reg, OVERDRIVE_CTRL);
  26. local_irq_restore(flags);
  27. }
  28. #ifdef CONFIG_HEARTBEAT
  29. #include <linux/sched.h>
  30. /* acts like an actual heart beat -- ie thump-thump-pause... */
  31. void heartbeat_od(void)
  32. {
  33. static unsigned cnt = 0, period = 0, dist = 0;
  34. if (cnt == 0 || cnt == dist)
  35. mach_led( -1, 1);
  36. else if (cnt == 7 || cnt == dist+7)
  37. mach_led( -1, 0);
  38. if (++cnt > period) {
  39. cnt = 0;
  40. /* The hyperbolic function below modifies the heartbeat period
  41. * length in dependency of the current (5min) load. It goes
  42. * through the points f(0)=126, f(1)=86, f(5)=51,
  43. * f(inf)->30. */
  44. period = ((672<<FSHIFT)/(5*avenrun[0]+(7<<FSHIFT))) + 30;
  45. dist = period / 4;
  46. }
  47. }
  48. #endif /* CONFIG_HEARTBEAT */