v4l2-flash-led-class.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * V4L2 flash LED sub-device registration helpers.
  4. *
  5. * Copyright (C) 2015 Samsung Electronics Co., Ltd
  6. * Author: Jacek Anaszewski <[email protected]>
  7. */
  8. #ifndef _V4L2_FLASH_H
  9. #define _V4L2_FLASH_H
  10. #include <media/v4l2-ctrls.h>
  11. #include <media/v4l2-subdev.h>
  12. struct led_classdev_flash;
  13. struct led_classdev;
  14. struct v4l2_flash;
  15. enum led_brightness;
  16. /**
  17. * struct v4l2_flash_ctrl_data - flash control initialization data, filled
  18. * basing on the features declared by the LED flash
  19. * class driver in the v4l2_flash_config
  20. * @config: initialization data for a control
  21. * @cid: contains v4l2 flash control id if the config
  22. * field was initialized, 0 otherwise
  23. */
  24. struct v4l2_flash_ctrl_data {
  25. struct v4l2_ctrl_config config;
  26. u32 cid;
  27. };
  28. /**
  29. * struct v4l2_flash_ops - V4L2 flash operations
  30. *
  31. * @external_strobe_set: Setup strobing the flash by hardware pin state
  32. * assertion.
  33. * @intensity_to_led_brightness: Convert intensity to brightness in a device
  34. * specific manner
  35. * @led_brightness_to_intensity: convert brightness to intensity in a device
  36. * specific manner.
  37. */
  38. struct v4l2_flash_ops {
  39. int (*external_strobe_set)(struct v4l2_flash *v4l2_flash,
  40. bool enable);
  41. enum led_brightness (*intensity_to_led_brightness)
  42. (struct v4l2_flash *v4l2_flash, s32 intensity);
  43. s32 (*led_brightness_to_intensity)
  44. (struct v4l2_flash *v4l2_flash, enum led_brightness);
  45. };
  46. /**
  47. * struct v4l2_flash_config - V4L2 Flash sub-device initialization data
  48. * @dev_name: the name of the media entity,
  49. * unique in the system
  50. * @intensity: non-flash strobe constraints for the LED
  51. * @flash_faults: bitmask of flash faults that the LED flash class
  52. * device can report; corresponding LED_FAULT* bit
  53. * definitions are available in the header file
  54. * <linux/led-class-flash.h>
  55. * @has_external_strobe: external strobe capability
  56. */
  57. struct v4l2_flash_config {
  58. char dev_name[32];
  59. struct led_flash_setting intensity;
  60. u32 flash_faults;
  61. unsigned int has_external_strobe:1;
  62. };
  63. /**
  64. * struct v4l2_flash - Flash sub-device context
  65. * @fled_cdev: LED flash class device controlled by this sub-device
  66. * @iled_cdev: LED class device representing indicator LED associated
  67. * with the LED flash class device
  68. * @ops: V4L2 specific flash ops
  69. * @sd: V4L2 sub-device
  70. * @hdl: flash controls handler
  71. * @ctrls: array of pointers to controls, whose values define
  72. * the sub-device state
  73. */
  74. struct v4l2_flash {
  75. struct led_classdev_flash *fled_cdev;
  76. struct led_classdev *iled_cdev;
  77. const struct v4l2_flash_ops *ops;
  78. struct v4l2_subdev sd;
  79. struct v4l2_ctrl_handler hdl;
  80. struct v4l2_ctrl **ctrls;
  81. };
  82. /**
  83. * v4l2_subdev_to_v4l2_flash - Returns a &struct v4l2_flash from the
  84. * &struct v4l2_subdev embedded on it.
  85. *
  86. * @sd: pointer to &struct v4l2_subdev
  87. */
  88. static inline struct v4l2_flash *v4l2_subdev_to_v4l2_flash(
  89. struct v4l2_subdev *sd)
  90. {
  91. return container_of(sd, struct v4l2_flash, sd);
  92. }
  93. /**
  94. * v4l2_ctrl_to_v4l2_flash - Returns a &struct v4l2_flash from the
  95. * &struct v4l2_ctrl embedded on it.
  96. *
  97. * @c: pointer to &struct v4l2_ctrl
  98. */
  99. static inline struct v4l2_flash *v4l2_ctrl_to_v4l2_flash(struct v4l2_ctrl *c)
  100. {
  101. return container_of(c->handler, struct v4l2_flash, hdl);
  102. }
  103. #if IS_ENABLED(CONFIG_V4L2_FLASH_LED_CLASS)
  104. /**
  105. * v4l2_flash_init - initialize V4L2 flash led sub-device
  106. * @dev: flash device, e.g. an I2C device
  107. * @fwn: fwnode_handle of the LED, may be NULL if the same as device's
  108. * @fled_cdev: LED flash class device to wrap
  109. * @ops: V4L2 Flash device ops
  110. * @config: initialization data for V4L2 Flash sub-device
  111. *
  112. * Create V4L2 Flash sub-device wrapping given LED subsystem device.
  113. * The ops pointer is stored by the V4L2 flash framework. No
  114. * references are held to config nor its contents once this function
  115. * has returned.
  116. *
  117. * Returns: A valid pointer, or, when an error occurs, the return
  118. * value is encoded using ERR_PTR(). Use IS_ERR() to check and
  119. * PTR_ERR() to obtain the numeric return value.
  120. */
  121. struct v4l2_flash *v4l2_flash_init(
  122. struct device *dev, struct fwnode_handle *fwn,
  123. struct led_classdev_flash *fled_cdev,
  124. const struct v4l2_flash_ops *ops, struct v4l2_flash_config *config);
  125. /**
  126. * v4l2_flash_indicator_init - initialize V4L2 indicator sub-device
  127. * @dev: flash device, e.g. an I2C device
  128. * @fwn: fwnode_handle of the LED, may be NULL if the same as device's
  129. * @iled_cdev: LED flash class device representing the indicator LED
  130. * @config: initialization data for V4L2 Flash sub-device
  131. *
  132. * Create V4L2 Flash sub-device wrapping given LED subsystem device.
  133. * The ops pointer is stored by the V4L2 flash framework. No
  134. * references are held to config nor its contents once this function
  135. * has returned.
  136. *
  137. * Returns: A valid pointer, or, when an error occurs, the return
  138. * value is encoded using ERR_PTR(). Use IS_ERR() to check and
  139. * PTR_ERR() to obtain the numeric return value.
  140. */
  141. struct v4l2_flash *v4l2_flash_indicator_init(
  142. struct device *dev, struct fwnode_handle *fwn,
  143. struct led_classdev *iled_cdev, struct v4l2_flash_config *config);
  144. /**
  145. * v4l2_flash_release - release V4L2 Flash sub-device
  146. * @v4l2_flash: the V4L2 Flash sub-device to release
  147. *
  148. * Release V4L2 Flash sub-device.
  149. */
  150. void v4l2_flash_release(struct v4l2_flash *v4l2_flash);
  151. #else
  152. static inline struct v4l2_flash *v4l2_flash_init(
  153. struct device *dev, struct fwnode_handle *fwn,
  154. struct led_classdev_flash *fled_cdev,
  155. const struct v4l2_flash_ops *ops, struct v4l2_flash_config *config)
  156. {
  157. return NULL;
  158. }
  159. static inline struct v4l2_flash *v4l2_flash_indicator_init(
  160. struct device *dev, struct fwnode_handle *fwn,
  161. struct led_classdev *iled_cdev, struct v4l2_flash_config *config)
  162. {
  163. return NULL;
  164. }
  165. static inline void v4l2_flash_release(struct v4l2_flash *v4l2_flash)
  166. {
  167. }
  168. #endif /* CONFIG_V4L2_FLASH_LED_CLASS */
  169. #endif /* _V4L2_FLASH_H */