leds-badge4.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * linux/arch/arm/mach-sa1100/leds-badge4.c
  3. *
  4. * Author: Christopher Hoover <ch@hpl.hp.com>
  5. * Copyright (C) 2002 Hewlett-Packard Company
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. */
  12. #include <linux/init.h>
  13. #include <mach/hardware.h>
  14. #include <asm/leds.h>
  15. #include <asm/system.h>
  16. #include "leds.h"
  17. #define LED_STATE_ENABLED 1
  18. #define LED_STATE_CLAIMED 2
  19. static unsigned int led_state;
  20. static unsigned int hw_led_state;
  21. #define LED_RED GPIO_GPIO(7)
  22. #define LED_GREEN GPIO_GPIO(9)
  23. #define LED_MASK (LED_RED|LED_GREEN)
  24. #define LED_IDLE LED_GREEN
  25. #define LED_TIMER LED_RED
  26. void badge4_leds_event(led_event_t evt)
  27. {
  28. unsigned long flags;
  29. local_irq_save(flags);
  30. switch (evt) {
  31. case led_start:
  32. GPDR |= LED_MASK;
  33. hw_led_state = LED_MASK;
  34. led_state = LED_STATE_ENABLED;
  35. break;
  36. case led_stop:
  37. led_state &= ~LED_STATE_ENABLED;
  38. break;
  39. case led_claim:
  40. led_state |= LED_STATE_CLAIMED;
  41. hw_led_state = LED_MASK;
  42. break;
  43. case led_release:
  44. led_state &= ~LED_STATE_CLAIMED;
  45. hw_led_state = LED_MASK;
  46. break;
  47. #ifdef CONFIG_LEDS_TIMER
  48. case led_timer:
  49. if (!(led_state & LED_STATE_CLAIMED))
  50. hw_led_state ^= LED_TIMER;
  51. break;
  52. #endif
  53. #ifdef CONFIG_LEDS_CPU
  54. case led_idle_start:
  55. /* LED off when system is idle */
  56. if (!(led_state & LED_STATE_CLAIMED))
  57. hw_led_state &= ~LED_IDLE;
  58. break;
  59. case led_idle_end:
  60. if (!(led_state & LED_STATE_CLAIMED))
  61. hw_led_state |= LED_IDLE;
  62. break;
  63. #endif
  64. case led_red_on:
  65. if (!(led_state & LED_STATE_CLAIMED))
  66. hw_led_state &= ~LED_RED;
  67. break;
  68. case led_red_off:
  69. if (!(led_state & LED_STATE_CLAIMED))
  70. hw_led_state |= LED_RED;
  71. break;
  72. case led_green_on:
  73. if (!(led_state & LED_STATE_CLAIMED))
  74. hw_led_state &= ~LED_GREEN;
  75. break;
  76. case led_green_off:
  77. if (!(led_state & LED_STATE_CLAIMED))
  78. hw_led_state |= LED_GREEN;
  79. break;
  80. default:
  81. break;
  82. }
  83. if (led_state & LED_STATE_ENABLED) {
  84. GPSR = hw_led_state;
  85. GPCR = hw_led_state ^ LED_MASK;
  86. }
  87. local_irq_restore(flags);
  88. }