led.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * linux/arch/sh/boards/superh/microdev/led.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 <asm/io.h>
  12. #define LED_REGISTER 0xa6104d20
  13. static void mach_led_d9(int value)
  14. {
  15. unsigned long reg;
  16. reg = ctrl_inl(LED_REGISTER);
  17. reg &= ~1;
  18. reg |= (value & 1);
  19. ctrl_outl(reg, LED_REGISTER);
  20. return;
  21. }
  22. static void mach_led_d10(int value)
  23. {
  24. unsigned long reg;
  25. reg = ctrl_inl(LED_REGISTER);
  26. reg &= ~2;
  27. reg |= ((value & 1) << 1);
  28. ctrl_outl(reg, LED_REGISTER);
  29. return;
  30. }
  31. #ifdef CONFIG_HEARTBEAT
  32. #include <linux/sched.h>
  33. static unsigned char banner_table[] = {
  34. 0x11, 0x01, 0x11, 0x01, 0x11, 0x03,
  35. 0x11, 0x01, 0x11, 0x01, 0x13, 0x03,
  36. 0x11, 0x01, 0x13, 0x01, 0x13, 0x01, 0x11, 0x03,
  37. 0x11, 0x03,
  38. 0x11, 0x01, 0x13, 0x01, 0x11, 0x03,
  39. 0x11, 0x01, 0x11, 0x01, 0x11, 0x01, 0x11, 0x07,
  40. 0x13, 0x01, 0x13, 0x03,
  41. 0x11, 0x01, 0x11, 0x03,
  42. 0x13, 0x01, 0x11, 0x01, 0x13, 0x01, 0x11, 0x03,
  43. 0x11, 0x01, 0x13, 0x01, 0x11, 0x03,
  44. 0x13, 0x01, 0x13, 0x01, 0x13, 0x03,
  45. 0x13, 0x01, 0x11, 0x01, 0x11, 0x03,
  46. 0x11, 0x03,
  47. 0x11, 0x01, 0x11, 0x01, 0x11, 0x01, 0x13, 0x07,
  48. 0xff
  49. };
  50. static void banner(void)
  51. {
  52. static int pos = 0;
  53. static int count = 0;
  54. if (count) {
  55. count--;
  56. } else {
  57. int val = banner_table[pos];
  58. if (val == 0xff) {
  59. pos = 0;
  60. val = banner_table[pos];
  61. }
  62. pos++;
  63. mach_led_d10((val >> 4) & 1);
  64. count = 10 * (val & 0xf);
  65. }
  66. }
  67. /* From heartbeat_harp in the stboards directory */
  68. /* acts like an actual heart beat -- ie thump-thump-pause... */
  69. void microdev_heartbeat(void)
  70. {
  71. static unsigned cnt = 0, period = 0, dist = 0;
  72. if (cnt == 0 || cnt == dist)
  73. mach_led_d9(1);
  74. else if (cnt == 7 || cnt == dist+7)
  75. mach_led_d9(0);
  76. if (++cnt > period) {
  77. cnt = 0;
  78. /* The hyperbolic function below modifies the heartbeat period
  79. * length in dependency of the current (5min) load. It goes
  80. * through the points f(0)=126, f(1)=86, f(5)=51,
  81. * f(inf)->30. */
  82. period = ((672<<FSHIFT)/(5*avenrun[0]+(7<<FSHIFT))) + 30;
  83. dist = period / 4;
  84. }
  85. banner();
  86. }
  87. #endif