led-class-flash.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*
  2. * LED Flash class interface
  3. *
  4. * Copyright (C) 2015 Samsung Electronics Co., Ltd.
  5. * Author: Jacek Anaszewski <j.anaszewski@samsung.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_FLASH_LEDS_H_INCLUDED
  13. #define __LINUX_FLASH_LEDS_H_INCLUDED
  14. #include <linux/leds.h>
  15. struct device_node;
  16. struct led_classdev_flash;
  17. /*
  18. * Supported led fault bits - must be kept in synch
  19. * with V4L2_FLASH_FAULT bits.
  20. */
  21. #define LED_FAULT_OVER_VOLTAGE (1 << 0)
  22. #define LED_FAULT_TIMEOUT (1 << 1)
  23. #define LED_FAULT_OVER_TEMPERATURE (1 << 2)
  24. #define LED_FAULT_SHORT_CIRCUIT (1 << 3)
  25. #define LED_FAULT_OVER_CURRENT (1 << 4)
  26. #define LED_FAULT_INDICATOR (1 << 5)
  27. #define LED_FAULT_UNDER_VOLTAGE (1 << 6)
  28. #define LED_FAULT_INPUT_VOLTAGE (1 << 7)
  29. #define LED_FAULT_LED_OVER_TEMPERATURE (1 << 8)
  30. #define LED_NUM_FLASH_FAULTS 9
  31. #define LED_FLASH_SYSFS_GROUPS_SIZE 5
  32. struct led_flash_ops {
  33. /* set flash brightness */
  34. int (*flash_brightness_set)(struct led_classdev_flash *fled_cdev,
  35. u32 brightness);
  36. /* get flash brightness */
  37. int (*flash_brightness_get)(struct led_classdev_flash *fled_cdev,
  38. u32 *brightness);
  39. /* set flash strobe state */
  40. int (*strobe_set)(struct led_classdev_flash *fled_cdev, bool state);
  41. /* get flash strobe state */
  42. int (*strobe_get)(struct led_classdev_flash *fled_cdev, bool *state);
  43. /* set flash timeout */
  44. int (*timeout_set)(struct led_classdev_flash *fled_cdev, u32 timeout);
  45. /* get the flash LED fault */
  46. int (*fault_get)(struct led_classdev_flash *fled_cdev, u32 *fault);
  47. };
  48. /*
  49. * Current value of a flash setting along
  50. * with its constraints.
  51. */
  52. struct led_flash_setting {
  53. /* maximum allowed value */
  54. u32 min;
  55. /* maximum allowed value */
  56. u32 max;
  57. /* step value */
  58. u32 step;
  59. /* current value */
  60. u32 val;
  61. };
  62. struct led_classdev_flash {
  63. /* led class device */
  64. struct led_classdev led_cdev;
  65. /* flash led specific ops */
  66. const struct led_flash_ops *ops;
  67. /* flash brightness value in microamperes along with its constraints */
  68. struct led_flash_setting brightness;
  69. /* flash timeout value in microseconds along with its constraints */
  70. struct led_flash_setting timeout;
  71. /* LED Flash class sysfs groups */
  72. const struct attribute_group *sysfs_groups[LED_FLASH_SYSFS_GROUPS_SIZE];
  73. };
  74. static inline struct led_classdev_flash *lcdev_to_flcdev(
  75. struct led_classdev *lcdev)
  76. {
  77. return container_of(lcdev, struct led_classdev_flash, led_cdev);
  78. }
  79. /**
  80. * led_classdev_flash_register - register a new object of led_classdev class
  81. * with support for flash LEDs
  82. * @parent: the flash LED to register
  83. * @fled_cdev: the led_classdev_flash structure for this device
  84. *
  85. * Returns: 0 on success or negative error value on failure
  86. */
  87. extern int led_classdev_flash_register(struct device *parent,
  88. struct led_classdev_flash *fled_cdev);
  89. /**
  90. * led_classdev_flash_unregister - unregisters an object of led_classdev class
  91. * with support for flash LEDs
  92. * @fled_cdev: the flash LED to unregister
  93. *
  94. * Unregister a previously registered via led_classdev_flash_register object
  95. */
  96. extern void led_classdev_flash_unregister(struct led_classdev_flash *fled_cdev);
  97. /**
  98. * led_set_flash_strobe - setup flash strobe
  99. * @fled_cdev: the flash LED to set strobe on
  100. * @state: 1 - strobe flash, 0 - stop flash strobe
  101. *
  102. * Strobe the flash LED.
  103. *
  104. * Returns: 0 on success or negative error value on failure
  105. */
  106. static inline int led_set_flash_strobe(struct led_classdev_flash *fled_cdev,
  107. bool state)
  108. {
  109. return fled_cdev->ops->strobe_set(fled_cdev, state);
  110. }
  111. /**
  112. * led_get_flash_strobe - get flash strobe status
  113. * @fled_cdev: the flash LED to query
  114. * @state: 1 - flash is strobing, 0 - flash is off
  115. *
  116. * Check whether the flash is strobing at the moment.
  117. *
  118. * Returns: 0 on success or negative error value on failure
  119. */
  120. static inline int led_get_flash_strobe(struct led_classdev_flash *fled_cdev,
  121. bool *state)
  122. {
  123. if (fled_cdev->ops->strobe_get)
  124. return fled_cdev->ops->strobe_get(fled_cdev, state);
  125. return -EINVAL;
  126. }
  127. /**
  128. * led_set_flash_brightness - set flash LED brightness
  129. * @fled_cdev: the flash LED to set
  130. * @brightness: the brightness to set it to
  131. *
  132. * Set a flash LED's brightness.
  133. *
  134. * Returns: 0 on success or negative error value on failure
  135. */
  136. extern int led_set_flash_brightness(struct led_classdev_flash *fled_cdev,
  137. u32 brightness);
  138. /**
  139. * led_update_flash_brightness - update flash LED brightness
  140. * @fled_cdev: the flash LED to query
  141. *
  142. * Get a flash LED's current brightness and update led_flash->brightness
  143. * member with the obtained value.
  144. *
  145. * Returns: 0 on success or negative error value on failure
  146. */
  147. extern int led_update_flash_brightness(struct led_classdev_flash *fled_cdev);
  148. /**
  149. * led_set_flash_timeout - set flash LED timeout
  150. * @fled_cdev: the flash LED to set
  151. * @timeout: the flash timeout to set it to
  152. *
  153. * Set the flash strobe duration.
  154. *
  155. * Returns: 0 on success or negative error value on failure
  156. */
  157. extern int led_set_flash_timeout(struct led_classdev_flash *fled_cdev,
  158. u32 timeout);
  159. /**
  160. * led_get_flash_fault - get the flash LED fault
  161. * @fled_cdev: the flash LED to query
  162. * @fault: bitmask containing flash faults
  163. *
  164. * Get the flash LED fault.
  165. *
  166. * Returns: 0 on success or negative error value on failure
  167. */
  168. extern int led_get_flash_fault(struct led_classdev_flash *fled_cdev,
  169. u32 *fault);
  170. #endif /* __LINUX_FLASH_LEDS_H_INCLUDED */