led-class-flash.h 6.1 KB

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