v4l2-flash-led-class.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. struct v4l2_flash_ops {
  32. /* setup strobing the flash by hardware pin state assertion */
  33. int (*external_strobe_set)(struct v4l2_flash *v4l2_flash,
  34. bool enable);
  35. /* convert intensity to brightness in a device specific manner */
  36. enum led_brightness (*intensity_to_led_brightness)
  37. (struct v4l2_flash *v4l2_flash, s32 intensity);
  38. /* convert brightness to intensity in a device specific manner */
  39. s32 (*led_brightness_to_intensity)
  40. (struct v4l2_flash *v4l2_flash, enum led_brightness);
  41. };
  42. /**
  43. * struct v4l2_flash_config - V4L2 Flash sub-device initialization data
  44. * @dev_name: the name of the media entity,
  45. unique in the system
  46. * @torch_intensity: constraints for the LED in torch mode
  47. * @indicator_intensity: constraints for the indicator LED
  48. * @flash_faults: bitmask of flash faults that the LED flash class
  49. device can report; corresponding LED_FAULT* bit
  50. definitions are available in the header file
  51. <linux/led-class-flash.h>
  52. * @has_external_strobe: external strobe capability
  53. */
  54. struct v4l2_flash_config {
  55. char dev_name[32];
  56. struct led_flash_setting torch_intensity;
  57. struct led_flash_setting indicator_intensity;
  58. u32 flash_faults;
  59. unsigned int has_external_strobe:1;
  60. };
  61. /**
  62. * struct v4l2_flash - Flash sub-device context
  63. * @fled_cdev: LED flash class device controlled by this sub-device
  64. * @iled_cdev: LED class device representing indicator LED associated
  65. * with the LED flash class device
  66. * @ops: V4L2 specific flash ops
  67. * @sd: V4L2 sub-device
  68. * @hdl: flash controls handler
  69. * @ctrls: array of pointers to controls, whose values define
  70. * the sub-device state
  71. */
  72. struct v4l2_flash {
  73. struct led_classdev_flash *fled_cdev;
  74. struct led_classdev_flash *iled_cdev;
  75. const struct v4l2_flash_ops *ops;
  76. struct v4l2_subdev sd;
  77. struct v4l2_ctrl_handler hdl;
  78. struct v4l2_ctrl **ctrls;
  79. };
  80. static inline struct v4l2_flash *v4l2_subdev_to_v4l2_flash(
  81. struct v4l2_subdev *sd)
  82. {
  83. return container_of(sd, struct v4l2_flash, sd);
  84. }
  85. static inline struct v4l2_flash *v4l2_ctrl_to_v4l2_flash(struct v4l2_ctrl *c)
  86. {
  87. return container_of(c->handler, struct v4l2_flash, hdl);
  88. }
  89. #if IS_ENABLED(CONFIG_V4L2_FLASH_LED_CLASS)
  90. /**
  91. * v4l2_flash_init - initialize V4L2 flash led sub-device
  92. * @dev: flash device, e.g. an I2C device
  93. * @of_node: of_node of the LED, may be NULL if the same as device's
  94. * @fled_cdev: LED flash class device to wrap
  95. * @iled_cdev: LED flash class device representing indicator LED associated
  96. * with fled_cdev, may be NULL
  97. * @flash_ops: V4L2 Flash device ops
  98. * @config: initialization data for V4L2 Flash sub-device
  99. *
  100. * Create V4L2 Flash sub-device wrapping given LED subsystem device.
  101. *
  102. * Returns: A valid pointer, or, when an error occurs, the return
  103. * value is encoded using ERR_PTR(). Use IS_ERR() to check and
  104. * PTR_ERR() to obtain the numeric return value.
  105. */
  106. struct v4l2_flash *v4l2_flash_init(
  107. struct device *dev, struct device_node *of_node,
  108. struct led_classdev_flash *fled_cdev,
  109. struct led_classdev_flash *iled_cdev,
  110. const struct v4l2_flash_ops *ops,
  111. struct v4l2_flash_config *config);
  112. /**
  113. * v4l2_flash_release - release V4L2 Flash sub-device
  114. * @flash: the V4L2 Flash sub-device to release
  115. *
  116. * Release V4L2 Flash sub-device.
  117. */
  118. void v4l2_flash_release(struct v4l2_flash *v4l2_flash);
  119. #else
  120. static inline struct v4l2_flash *v4l2_flash_init(
  121. struct device *dev, struct device_node *of_node,
  122. struct led_classdev_flash *fled_cdev,
  123. struct led_classdev_flash *iled_cdev,
  124. const struct v4l2_flash_ops *ops,
  125. struct v4l2_flash_config *config)
  126. {
  127. return NULL;
  128. }
  129. static inline void v4l2_flash_release(struct v4l2_flash *v4l2_flash)
  130. {
  131. }
  132. #endif /* CONFIG_V4L2_FLASH_LED_CLASS */
  133. #endif /* _V4L2_FLASH_H */