leds-cerf.c
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:3k
源码类别:

嵌入式Linux

开发平台:

Unix_Linux

  1. /*
  2.  * linux/arch/arm/mach-sa1100/leds-cerf.c
  3.  *
  4.  * Author: ???
  5.  */
  6. #include <linux/config.h>
  7. #include <linux/init.h>
  8. #include <asm/hardware.h>
  9. #include <asm/leds.h>
  10. #include <asm/system.h>
  11. #include "leds.h"
  12. #define LED_STATE_ENABLED 1
  13. #define LED_STATE_CLAIMED 2
  14. static unsigned int led_state;
  15. static unsigned int hw_led_state;
  16. #ifdef CONFIG_SA1100_CERF_CPLD
  17. #define LED_D0 GPIO_GPIO(0)
  18. #define LED_D1 GPIO_GPIO(0)
  19. #define LED_D2 GPIO_GPIO(0)
  20. #define LED_D3 GPIO_GPIO(0)
  21. #define LED_MASK (LED_D0|LED_D1|LED_D2|LED_D3)
  22. #else
  23. #define LED_D0          GPIO_GPIO(0)
  24. #define LED_D1          GPIO_GPIO(1)
  25. #define LED_D2          GPIO_GPIO(2)
  26. #define LED_D3          GPIO_GPIO(3)
  27. #define LED_MASK        (LED_D0|LED_D1|LED_D2|LED_D3)
  28. #endif
  29. void cerf_leds_event(led_event_t evt)
  30. {
  31.         unsigned long flags;
  32. local_irq_save(flags);
  33.         switch (evt) {
  34.         case led_start:
  35.                 hw_led_state = LED_MASK;
  36.                 led_state = LED_STATE_ENABLED;
  37.                 break;
  38.         case led_stop:
  39.                 led_state &= ~LED_STATE_ENABLED;
  40.                 break;
  41.         case led_claim:
  42.                 led_state |= LED_STATE_CLAIMED;
  43.                 hw_led_state = LED_MASK;
  44.                 break;
  45.         case led_release:
  46.                 led_state &= ~LED_STATE_CLAIMED;
  47.                 hw_led_state = LED_MASK;
  48.                 break;
  49. #ifdef CONFIG_LEDS_TIMER
  50.         case led_timer:
  51.                 if (!(led_state & LED_STATE_CLAIMED))
  52.                         hw_led_state ^= LED_D0;
  53.                 break;
  54. #endif
  55. #ifdef CONFIG_LEDS_CPU
  56.         case led_idle_start:
  57.                 if (!(led_state & LED_STATE_CLAIMED))
  58.                         hw_led_state &= ~LED_D1;
  59.                 break;
  60.         case led_idle_end:
  61.                 if (!(led_state & LED_STATE_CLAIMED))
  62.                         hw_led_state |= LED_D1;
  63.                 break;
  64. #endif
  65.         case led_green_on:
  66.                 if (!(led_state & LED_STATE_CLAIMED))
  67.                         hw_led_state &= ~LED_D2;
  68.                 break;
  69.         case led_green_off:
  70.                 if (!(led_state & LED_STATE_CLAIMED))
  71.                         hw_led_state |= LED_D2;
  72.                 break;
  73.         case led_amber_on:
  74.                 if (!(led_state & LED_STATE_CLAIMED))
  75.                         hw_led_state &= ~LED_D3;
  76.                 break;
  77.         case led_amber_off:
  78.                 if (!(led_state & LED_STATE_CLAIMED))
  79.                         hw_led_state |= LED_D3;
  80.                 break;
  81.         case led_red_on:
  82.                 if (!(led_state & LED_STATE_CLAIMED))
  83.                         hw_led_state &= ~LED_D1;
  84.                 break;
  85.         case led_red_off:
  86.                 if (!(led_state & LED_STATE_CLAIMED))
  87.                         hw_led_state |= LED_D1;
  88.                 break;
  89.         default:
  90.                 break;
  91.         }
  92.         if  (led_state & LED_STATE_ENABLED) {
  93.                 GPSR = hw_led_state;
  94.                 GPCR = hw_led_state ^ LED_MASK;
  95.         }
  96. local_irq_restore(flags);
  97. }