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

嵌入式Linux

开发平台:

Unix_Linux

  1. /*
  2.  * linux/arch/arm/mach-sa1100/leds-brutus.c
  3.  *
  4.  * Copyright (C) 2000 Nicolas Pitre
  5.  *
  6.  * Brutus uses the LEDs as follows:
  7.  *   - D3 (Green, GPIO9) - toggles state every 50 timer interrupts
  8.  *   - D17 (Red, GPIO20) - on if system is not idle
  9.  *   - D4 (Green, GPIO8) - misc function
  10.  */
  11. #include <linux/config.h>
  12. #include <linux/init.h>
  13. #include <asm/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_D3 GPIO_GPIO(9)
  22. #define LED_D4 GPIO_GPIO(8)
  23. #define LED_D17 GPIO_GPIO(20)
  24. #define LED_MASK (LED_D3|LED_D4|LED_D17)
  25. void brutus_leds_event(led_event_t evt)
  26. {
  27. unsigned long flags;
  28. local_irq_save(flags);
  29. switch (evt) {
  30. case led_start:
  31. hw_led_state = LED_MASK;
  32. led_state = LED_STATE_ENABLED;
  33. break;
  34. case led_stop:
  35. led_state &= ~LED_STATE_ENABLED;
  36. break;
  37. case led_claim:
  38. led_state |= LED_STATE_CLAIMED;
  39. hw_led_state = LED_MASK;
  40. break;
  41. case led_release:
  42. led_state &= ~LED_STATE_CLAIMED;
  43. hw_led_state = LED_MASK;
  44. break;
  45. #ifdef CONFIG_LEDS_TIMER
  46. case led_timer:
  47. if (!(led_state & LED_STATE_CLAIMED))
  48. hw_led_state ^= LED_D3;
  49. break;
  50. #endif
  51. #ifdef CONFIG_LEDS_CPU
  52. case led_idle_start:
  53. if (!(led_state & LED_STATE_CLAIMED))
  54. hw_led_state |= LED_D17;
  55. break;
  56. case led_idle_end:
  57. if (!(led_state & LED_STATE_CLAIMED))
  58. hw_led_state &= ~LED_D17;
  59. break;
  60. #endif
  61. case led_green_on:
  62. hw_led_state &= ~LED_D4;
  63. break;
  64. case led_green_off:
  65. hw_led_state |= LED_D4;
  66. break;
  67. case led_amber_on:
  68. break;
  69. case led_amber_off:
  70. break;
  71. case led_red_on:
  72. if (led_state & LED_STATE_CLAIMED)
  73. hw_led_state &= ~LED_D17;
  74. break;
  75. case led_red_off:
  76. if (led_state & LED_STATE_CLAIMED)
  77. hw_led_state |= LED_D17;
  78. break;
  79. default:
  80. break;
  81. }
  82. if  (led_state & LED_STATE_ENABLED) {
  83. GPSR = hw_led_state;
  84. GPCR = hw_led_state ^ LED_MASK;
  85. }
  86. local_irq_restore(flags);
  87. }