/* SPDX-License-Identifier: GPL-2.0-only */1/*2* V4L2 flash LED sub-device registration helpers.3*4* Copyright (C) 2015 Samsung Electronics Co., Ltd5* Author: Jacek Anaszewski <[email protected]>6*/78#ifndef _V4L2_FLASH_H9#define _V4L2_FLASH_H1011#include <media/v4l2-ctrls.h>12#include <media/v4l2-subdev.h>1314struct led_classdev_flash;15struct led_classdev;16struct v4l2_flash;17enum led_brightness;1819/**20* struct v4l2_flash_ctrl_data - flash control initialization data, filled21* basing on the features declared by the LED flash22* class driver in the v4l2_flash_config23* @config: initialization data for a control24* @cid: contains v4l2 flash control id if the config25* field was initialized, 0 otherwise26*/27struct v4l2_flash_ctrl_data {28struct v4l2_ctrl_config config;29u32 cid;30};3132/**33* struct v4l2_flash_ops - V4L2 flash operations34*35* @external_strobe_set: Setup strobing the flash by hardware pin state36* assertion.37* @intensity_to_led_brightness: Convert intensity to brightness in a device38* specific manner39* @led_brightness_to_intensity: convert brightness to intensity in a device40* specific manner.41*/42struct v4l2_flash_ops {43int (*external_strobe_set)(struct v4l2_flash *v4l2_flash,44bool enable);45enum led_brightness (*intensity_to_led_brightness)46(struct v4l2_flash *v4l2_flash, s32 intensity);47s32 (*led_brightness_to_intensity)48(struct v4l2_flash *v4l2_flash, enum led_brightness);49};5051/**52* struct v4l2_flash_config - V4L2 Flash sub-device initialization data53* @dev_name: the name of the media entity,54* unique in the system55* @intensity: non-flash strobe constraints for the LED56* @flash_faults: bitmask of flash faults that the LED flash class57* device can report; corresponding LED_FAULT* bit58* definitions are available in the header file59* <linux/led-class-flash.h>60* @has_external_strobe: external strobe capability61*/62struct v4l2_flash_config {63char dev_name[32];64struct led_flash_setting intensity;65u32 flash_faults;66unsigned int has_external_strobe:1;67};6869/**70* struct v4l2_flash - Flash sub-device context71* @fled_cdev: LED flash class device controlled by this sub-device72* @iled_cdev: LED class device representing indicator LED associated73* with the LED flash class device74* @ops: V4L2 specific flash ops75* @sd: V4L2 sub-device76* @hdl: flash controls handler77* @ctrls: array of pointers to controls, whose values define78* the sub-device state79*/80struct v4l2_flash {81struct led_classdev_flash *fled_cdev;82struct led_classdev *iled_cdev;83const struct v4l2_flash_ops *ops;8485struct v4l2_subdev sd;86struct v4l2_ctrl_handler hdl;87struct v4l2_ctrl **ctrls;88};8990/**91* v4l2_subdev_to_v4l2_flash - Returns a &struct v4l2_flash from the92* &struct v4l2_subdev embedded on it.93*94* @sd: pointer to &struct v4l2_subdev95*/96static inline struct v4l2_flash *v4l2_subdev_to_v4l2_flash(97struct v4l2_subdev *sd)98{99return container_of(sd, struct v4l2_flash, sd);100}101102/**103* v4l2_ctrl_to_v4l2_flash - Returns a &struct v4l2_flash from the104* &struct v4l2_ctrl embedded on it.105*106* @c: pointer to &struct v4l2_ctrl107*/108static inline struct v4l2_flash *v4l2_ctrl_to_v4l2_flash(struct v4l2_ctrl *c)109{110return container_of(c->handler, struct v4l2_flash, hdl);111}112113#if IS_ENABLED(CONFIG_V4L2_FLASH_LED_CLASS)114/**115* v4l2_flash_init - initialize V4L2 flash led sub-device116* @dev: flash device, e.g. an I2C device117* @fwn: fwnode_handle of the LED, may be NULL if the same as device's118* @fled_cdev: LED flash class device to wrap119* @ops: V4L2 Flash device ops120* @config: initialization data for V4L2 Flash sub-device121*122* Create V4L2 Flash sub-device wrapping given LED subsystem device.123* The ops pointer is stored by the V4L2 flash framework. No124* references are held to config nor its contents once this function125* has returned.126*127* Returns: A valid pointer, or, when an error occurs, the return128* value is encoded using ERR_PTR(). Use IS_ERR() to check and129* PTR_ERR() to obtain the numeric return value.130*/131struct v4l2_flash *v4l2_flash_init(132struct device *dev, struct fwnode_handle *fwn,133struct led_classdev_flash *fled_cdev,134const struct v4l2_flash_ops *ops, struct v4l2_flash_config *config);135136/**137* v4l2_flash_indicator_init - initialize V4L2 indicator sub-device138* @dev: flash device, e.g. an I2C device139* @fwn: fwnode_handle of the LED, may be NULL if the same as device's140* @iled_cdev: LED flash class device representing the indicator LED141* @config: initialization data for V4L2 Flash sub-device142*143* Create V4L2 Flash sub-device wrapping given LED subsystem device.144* The ops pointer is stored by the V4L2 flash framework. No145* references are held to config nor its contents once this function146* has returned.147*148* Returns: A valid pointer, or, when an error occurs, the return149* value is encoded using ERR_PTR(). Use IS_ERR() to check and150* PTR_ERR() to obtain the numeric return value.151*/152struct v4l2_flash *v4l2_flash_indicator_init(153struct device *dev, struct fwnode_handle *fwn,154struct led_classdev *iled_cdev, struct v4l2_flash_config *config);155156/**157* v4l2_flash_release - release V4L2 Flash sub-device158* @v4l2_flash: the V4L2 Flash sub-device to release159*160* Release V4L2 Flash sub-device.161*/162void v4l2_flash_release(struct v4l2_flash *v4l2_flash);163164#else165static inline struct v4l2_flash *v4l2_flash_init(166struct device *dev, struct fwnode_handle *fwn,167struct led_classdev_flash *fled_cdev,168const struct v4l2_flash_ops *ops, struct v4l2_flash_config *config)169{170return NULL;171}172173static inline struct v4l2_flash *v4l2_flash_indicator_init(174struct device *dev, struct fwnode_handle *fwn,175struct led_classdev *iled_cdev, struct v4l2_flash_config *config)176{177return NULL;178}179180static inline void v4l2_flash_release(struct v4l2_flash *v4l2_flash)181{182}183#endif /* CONFIG_V4L2_FLASH_LED_CLASS */184185#endif /* _V4L2_FLASH_H */186187188