led.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * linux/arch/sh/kernel/led_microdev.c
  3. *
  4. * Copyright (C) 2002 Stuart Menefy <stuart.menefy@st.com>
  5. * Copyright (C) 2003 Richard Curnow (Richard.Curnow@superh.com)
  6. *
  7. * May be copied or modified under the terms of the GNU General Public
  8. * License. See linux/COPYING for more information.
  9. *
  10. */
  11. #include <linux/config.h>
  12. #include <asm/io.h>
  13. #define LED_REGISTER 0xa6104d20
  14. static void mach_led_d9(int value)
  15. {
  16. unsigned long reg;
  17. reg = ctrl_inl(LED_REGISTER);
  18. reg &= ~1;
  19. reg |= (value & 1);
  20. ctrl_outl(reg, LED_REGISTER);
  21. return;
  22. }
  23. static void mach_led_d10(int value)
  24. {
  25. unsigned long reg;
  26. reg = ctrl_inl(LED_REGISTER);
  27. reg &= ~2;
  28. reg |= ((value & 1) << 1);
  29. ctrl_outl(reg, LED_REGISTER);
  30. return;
  31. }
  32. #ifdef CONFIG_HEARTBEAT
  33. #include <linux/sched.h>
  34. static unsigned char banner_table[] = {
  35. 0x11, 0x01, 0x11, 0x01, 0x11, 0x03,
  36. 0x11, 0x01, 0x11, 0x01, 0x13, 0x03,
  37. 0x11, 0x01, 0x13, 0x01, 0x13, 0x01, 0x11, 0x03,
  38. 0x11, 0x03,
  39. 0x11, 0x01, 0x13, 0x01, 0x11, 0x03,
  40. 0x11, 0x01, 0x11, 0x01, 0x11, 0x01, 0x11, 0x07,
  41. 0x13, 0x01, 0x13, 0x03,
  42. 0x11, 0x01, 0x11, 0x03,
  43. 0x13, 0x01, 0x11, 0x01, 0x13, 0x01, 0x11, 0x03,
  44. 0x11, 0x01, 0x13, 0x01, 0x11, 0x03,
  45. 0x13, 0x01, 0x13, 0x01, 0x13, 0x03,
  46. 0x13, 0x01, 0x11, 0x01, 0x11, 0x03,
  47. 0x11, 0x03,
  48. 0x11, 0x01, 0x11, 0x01, 0x11, 0x01, 0x13, 0x07,
  49. 0xff
  50. };
  51. static void banner(void)
  52. {
  53. static int pos = 0;
  54. static int count = 0;
  55. if (count) {
  56. count--;
  57. } else {
  58. int val = banner_table[pos];
  59. if (val == 0xff) {
  60. pos = 0;
  61. val = banner_table[pos];
  62. }
  63. pos++;
  64. mach_led_d10((val >> 4) & 1);
  65. count = 10 * (val & 0xf);
  66. }
  67. }
  68. /* From heartbeat_harp in the stboards directory */
  69. /* acts like an actual heart beat -- ie thump-thump-pause... */
  70. void microdev_heartbeat(void)
  71. {
  72. static unsigned cnt = 0, period = 0, dist = 0;
  73. if (cnt == 0 || cnt == dist)
  74. mach_led_d9(1);
  75. else if (cnt == 7 || cnt == dist+7)
  76. mach_led_d9(0);
  77. if (++cnt > period) {
  78. cnt = 0;
  79. /* The hyperbolic function below modifies the heartbeat period
  80. * length in dependency of the current (5min) load. It goes
  81. * through the points f(0)=126, f(1)=86, f(5)=51,
  82. * f(inf)->30. */
  83. period = ((672<<FSHIFT)/(5*avenrun[0]+(7<<FSHIFT))) + 30;
  84. dist = period / 4;
  85. }
  86. banner();
  87. }
  88. #endif