leds.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /*
  2. * Driver model for leds and led triggers
  3. *
  4. * Copyright (C) 2005 John Lenz <lenz@cs.wisc.edu>
  5. * Copyright (C) 2005 Richard Purdie <rpurdie@openedhand.com>
  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. #ifndef __LINUX_LEDS_H_INCLUDED
  13. #define __LINUX_LEDS_H_INCLUDED
  14. #include <linux/list.h>
  15. #include <linux/spinlock.h>
  16. #include <linux/rwsem.h>
  17. #include <linux/timer.h>
  18. struct device;
  19. /*
  20. * LED Core
  21. */
  22. enum led_brightness {
  23. LED_OFF = 0,
  24. LED_HALF = 127,
  25. LED_FULL = 255,
  26. };
  27. struct led_classdev {
  28. const char *name;
  29. int brightness;
  30. int max_brightness;
  31. int flags;
  32. /* Lower 16 bits reflect status */
  33. #define LED_SUSPENDED (1 << 0)
  34. /* Upper 16 bits reflect control information */
  35. #define LED_CORE_SUSPENDRESUME (1 << 16)
  36. /* Set LED brightness level */
  37. /* Must not sleep, use a workqueue if needed */
  38. void (*brightness_set)(struct led_classdev *led_cdev,
  39. enum led_brightness brightness);
  40. /* Get LED brightness level */
  41. enum led_brightness (*brightness_get)(struct led_classdev *led_cdev);
  42. /*
  43. * Activate hardware accelerated blink, delays are in milliseconds
  44. * and if both are zero then a sensible default should be chosen.
  45. * The call should adjust the timings in that case and if it can't
  46. * match the values specified exactly.
  47. * Deactivate blinking again when the brightness is set to a fixed
  48. * value via the brightness_set() callback.
  49. */
  50. int (*blink_set)(struct led_classdev *led_cdev,
  51. unsigned long *delay_on,
  52. unsigned long *delay_off);
  53. struct device *dev;
  54. struct list_head node; /* LED Device list */
  55. const char *default_trigger; /* Trigger to use */
  56. unsigned long blink_delay_on, blink_delay_off;
  57. struct timer_list blink_timer;
  58. int blink_brightness;
  59. #ifdef CONFIG_LEDS_TRIGGERS
  60. /* Protects the trigger data below */
  61. struct rw_semaphore trigger_lock;
  62. struct led_trigger *trigger;
  63. struct list_head trig_list;
  64. void *trigger_data;
  65. /* true if activated - deactivate routine uses it to do cleanup */
  66. bool activated;
  67. #endif
  68. };
  69. extern int led_classdev_register(struct device *parent,
  70. struct led_classdev *led_cdev);
  71. extern void led_classdev_unregister(struct led_classdev *led_cdev);
  72. extern void led_classdev_suspend(struct led_classdev *led_cdev);
  73. extern void led_classdev_resume(struct led_classdev *led_cdev);
  74. /**
  75. * led_blink_set - set blinking with software fallback
  76. * @led_cdev: the LED to start blinking
  77. * @delay_on: the time it should be on (in ms)
  78. * @delay_off: the time it should ble off (in ms)
  79. *
  80. * This function makes the LED blink, attempting to use the
  81. * hardware acceleration if possible, but falling back to
  82. * software blinking if there is no hardware blinking or if
  83. * the LED refuses the passed values.
  84. *
  85. * Note that if software blinking is active, simply calling
  86. * led_cdev->brightness_set() will not stop the blinking,
  87. * use led_classdev_brightness_set() instead.
  88. */
  89. extern void led_blink_set(struct led_classdev *led_cdev,
  90. unsigned long *delay_on,
  91. unsigned long *delay_off);
  92. /**
  93. * led_brightness_set - set LED brightness
  94. * @led_cdev: the LED to set
  95. * @brightness: the brightness to set it to
  96. *
  97. * Set an LED's brightness, and, if necessary, cancel the
  98. * software blink timer that implements blinking when the
  99. * hardware doesn't.
  100. */
  101. extern void led_brightness_set(struct led_classdev *led_cdev,
  102. enum led_brightness brightness);
  103. /*
  104. * LED Triggers
  105. */
  106. #ifdef CONFIG_LEDS_TRIGGERS
  107. #define TRIG_NAME_MAX 50
  108. struct led_trigger {
  109. /* Trigger Properties */
  110. const char *name;
  111. void (*activate)(struct led_classdev *led_cdev);
  112. void (*deactivate)(struct led_classdev *led_cdev);
  113. /* LEDs under control by this trigger (for simple triggers) */
  114. rwlock_t leddev_list_lock;
  115. struct list_head led_cdevs;
  116. /* Link to next registered trigger */
  117. struct list_head next_trig;
  118. };
  119. /* Registration functions for complex triggers */
  120. extern int led_trigger_register(struct led_trigger *trigger);
  121. extern void led_trigger_unregister(struct led_trigger *trigger);
  122. /* Registration functions for simple triggers */
  123. #define DEFINE_LED_TRIGGER(x) static struct led_trigger *x;
  124. #define DEFINE_LED_TRIGGER_GLOBAL(x) struct led_trigger *x;
  125. extern void led_trigger_register_simple(const char *name,
  126. struct led_trigger **trigger);
  127. extern void led_trigger_unregister_simple(struct led_trigger *trigger);
  128. extern void led_trigger_event(struct led_trigger *trigger,
  129. enum led_brightness event);
  130. extern void led_trigger_blink(struct led_trigger *trigger,
  131. unsigned long *delay_on,
  132. unsigned long *delay_off);
  133. #else
  134. /* Triggers aren't active - null macros */
  135. #define DEFINE_LED_TRIGGER(x)
  136. #define DEFINE_LED_TRIGGER_GLOBAL(x)
  137. #define led_trigger_register_simple(x, y) do {} while(0)
  138. #define led_trigger_unregister_simple(x) do {} while(0)
  139. #define led_trigger_event(x, y) do {} while(0)
  140. #endif
  141. /* Trigger specific functions */
  142. #ifdef CONFIG_LEDS_TRIGGER_IDE_DISK
  143. extern void ledtrig_ide_activity(void);
  144. #else
  145. #define ledtrig_ide_activity() do {} while(0)
  146. #endif
  147. /*
  148. * Generic LED platform data for describing LED names and default triggers.
  149. */
  150. struct led_info {
  151. const char *name;
  152. const char *default_trigger;
  153. int flags;
  154. };
  155. struct led_platform_data {
  156. int num_leds;
  157. struct led_info *leds;
  158. };
  159. /* For the leds-gpio driver */
  160. struct gpio_led {
  161. const char *name;
  162. const char *default_trigger;
  163. unsigned gpio;
  164. unsigned active_low : 1;
  165. unsigned retain_state_suspended : 1;
  166. unsigned default_state : 2;
  167. /* default_state should be one of LEDS_GPIO_DEFSTATE_(ON|OFF|KEEP) */
  168. };
  169. #define LEDS_GPIO_DEFSTATE_OFF 0
  170. #define LEDS_GPIO_DEFSTATE_ON 1
  171. #define LEDS_GPIO_DEFSTATE_KEEP 2
  172. struct gpio_led_platform_data {
  173. int num_leds;
  174. const struct gpio_led *leds;
  175. #define GPIO_LED_NO_BLINK_LOW 0 /* No blink GPIO state low */
  176. #define GPIO_LED_NO_BLINK_HIGH 1 /* No blink GPIO state high */
  177. #define GPIO_LED_BLINK 2 /* Please, blink */
  178. int (*gpio_blink_set)(unsigned gpio, int state,
  179. unsigned long *delay_on,
  180. unsigned long *delay_off);
  181. };
  182. struct platform_device *gpio_led_register_device(
  183. int id, const struct gpio_led_platform_data *pdata);
  184. #endif /* __LINUX_LEDS_H_INCLUDED */