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