v4l2-flash-led-class.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. static inline struct v4l2_flash *v4l2_subdev_to_v4l2_flash(
  86. struct v4l2_subdev *sd)
  87. {
  88. return container_of(sd, struct v4l2_flash, sd);
  89. }
  90. static inline struct v4l2_flash *v4l2_ctrl_to_v4l2_flash(struct v4l2_ctrl *c)
  91. {
  92. return container_of(c->handler, struct v4l2_flash, hdl);
  93. }
  94. #if IS_ENABLED(CONFIG_V4L2_FLASH_LED_CLASS)
  95. /**
  96. * v4l2_flash_init - initialize V4L2 flash led sub-device
  97. * @dev: flash device, e.g. an I2C device
  98. * @fwn: fwnode_handle of the LED, may be NULL if the same as device's
  99. * @fled_cdev: LED flash class device to wrap
  100. * @ops: V4L2 Flash device ops
  101. * @config: initialization data for V4L2 Flash sub-device
  102. *
  103. * Create V4L2 Flash sub-device wrapping given LED subsystem device.
  104. * The ops pointer is stored by the V4L2 flash framework. No
  105. * references are held to config nor its contents once this function
  106. * has returned.
  107. *
  108. * Returns: A valid pointer, or, when an error occurs, the return
  109. * value is encoded using ERR_PTR(). Use IS_ERR() to check and
  110. * PTR_ERR() to obtain the numeric return value.
  111. */
  112. struct v4l2_flash *v4l2_flash_init(
  113. struct device *dev, struct fwnode_handle *fwn,
  114. struct led_classdev_flash *fled_cdev,
  115. const struct v4l2_flash_ops *ops, struct v4l2_flash_config *config);
  116. /**
  117. * v4l2_flash_indicator_init - initialize V4L2 indicator sub-device
  118. * @dev: flash device, e.g. an I2C device
  119. * @fwn: fwnode_handle of the LED, may be NULL if the same as device's
  120. * @iled_cdev: LED flash class device representing the indicator LED
  121. * @config: initialization data for V4L2 Flash sub-device
  122. *
  123. * Create V4L2 Flash sub-device wrapping given LED subsystem device.
  124. * The ops pointer is stored by the V4L2 flash framework. No
  125. * references are held to config nor its contents once this function
  126. * has returned.
  127. *
  128. * Returns: A valid pointer, or, when an error occurs, the return
  129. * value is encoded using ERR_PTR(). Use IS_ERR() to check and
  130. * PTR_ERR() to obtain the numeric return value.
  131. */
  132. struct v4l2_flash *v4l2_flash_indicator_init(
  133. struct device *dev, struct fwnode_handle *fwn,
  134. struct led_classdev *iled_cdev, struct v4l2_flash_config *config);
  135. /**
  136. * v4l2_flash_release - release V4L2 Flash sub-device
  137. * @v4l2_flash: the V4L2 Flash sub-device to release
  138. *
  139. * Release V4L2 Flash sub-device.
  140. */
  141. void v4l2_flash_release(struct v4l2_flash *v4l2_flash);
  142. #else
  143. static inline struct v4l2_flash *v4l2_flash_init(
  144. struct device *dev, struct fwnode_handle *fwn,
  145. struct led_classdev_flash *fled_cdev,
  146. const struct v4l2_flash_ops *ops, struct v4l2_flash_config *config)
  147. {
  148. return NULL;
  149. }
  150. static inline struct v4l2_flash *v4l2_flash_indicator_init(
  151. struct device *dev, struct fwnode_handle *fwn,
  152. struct led_classdev *iled_cdev, struct v4l2_flash_config *config)
  153. {
  154. return NULL;
  155. }
  156. static inline void v4l2_flash_release(struct v4l2_flash *v4l2_flash)
  157. {
  158. }
  159. #endif /* CONFIG_V4L2_FLASH_LED_CLASS */
  160. #endif /* _V4L2_FLASH_H */