v4l2-flash-led-class.h 5.9 KB

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