blob: b0fe4d6f4a5f713d5bbd7651a9f49ccca80cde4f [file] [log] [blame]
Jacek Anaszewski42bd6f52015-06-19 00:31:47 -07001/*
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
Mauro Carvalho Chehab0d560152016-09-08 18:23:35 -030023/**
Jacek Anaszewski42bd6f52015-06-19 00:31:47 -070024 * 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
Mauro Carvalho Chehab0d560152016-09-08 18:23:35 -030036/**
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 */
Jacek Anaszewski42bd6f52015-06-19 00:31:47 -070046struct v4l2_flash_ops {
Jacek Anaszewski42bd6f52015-06-19 00:31:47 -070047 int (*external_strobe_set)(struct v4l2_flash *v4l2_flash,
48 bool enable);
Jacek Anaszewski42bd6f52015-06-19 00:31:47 -070049 enum led_brightness (*intensity_to_led_brightness)
50 (struct v4l2_flash *v4l2_flash, s32 intensity);
Jacek Anaszewski42bd6f52015-06-19 00:31:47 -070051 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,
Mauro Carvalho Chehab62ba6b22015-08-22 05:28:44 -030058 * unique in the system
Jacek Anaszewski42bd6f52015-06-19 00:31:47 -070059 * @torch_intensity: constraints for the LED in torch mode
60 * @indicator_intensity: constraints for the indicator LED
61 * @flash_faults: bitmask of flash faults that the LED flash class
Mauro Carvalho Chehab62ba6b22015-08-22 05:28:44 -030062 * device can report; corresponding LED_FAULT* bit
63 * definitions are available in the header file
64 * <linux/led-class-flash.h>
Jacek Anaszewski42bd6f52015-06-19 00:31:47 -070065 * @has_external_strobe: external strobe capability
66 */
67struct v4l2_flash_config {
68 char dev_name[32];
69 struct led_flash_setting torch_intensity;
70 struct led_flash_setting indicator_intensity;
71 u32 flash_faults;
72 unsigned int has_external_strobe:1;
73};
74
75/**
76 * struct v4l2_flash - Flash sub-device context
77 * @fled_cdev: LED flash class device controlled by this sub-device
78 * @iled_cdev: LED class device representing indicator LED associated
79 * with the LED flash class device
80 * @ops: V4L2 specific flash ops
81 * @sd: V4L2 sub-device
82 * @hdl: flash controls handler
83 * @ctrls: array of pointers to controls, whose values define
84 * the sub-device state
85 */
86struct v4l2_flash {
87 struct led_classdev_flash *fled_cdev;
88 struct led_classdev_flash *iled_cdev;
89 const struct v4l2_flash_ops *ops;
90
91 struct v4l2_subdev sd;
92 struct v4l2_ctrl_handler hdl;
93 struct v4l2_ctrl **ctrls;
94};
95
96static inline struct v4l2_flash *v4l2_subdev_to_v4l2_flash(
97 struct v4l2_subdev *sd)
98{
99 return container_of(sd, struct v4l2_flash, sd);
100}
101
102static 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
107#if IS_ENABLED(CONFIG_V4L2_FLASH_LED_CLASS)
108/**
109 * v4l2_flash_init - initialize V4L2 flash led sub-device
110 * @dev: flash device, e.g. an I2C device
111 * @of_node: of_node of the LED, may be NULL if the same as device's
112 * @fled_cdev: LED flash class device to wrap
113 * @iled_cdev: LED flash class device representing indicator LED associated
114 * with fled_cdev, may be NULL
Mauro Carvalho Chehab62ba6b22015-08-22 05:28:44 -0300115 * @ops: V4L2 Flash device ops
Jacek Anaszewski42bd6f52015-06-19 00:31:47 -0700116 * @config: initialization data for V4L2 Flash sub-device
117 *
118 * Create V4L2 Flash sub-device wrapping given LED subsystem device.
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 */
124struct v4l2_flash *v4l2_flash_init(
125 struct device *dev, struct device_node *of_node,
126 struct led_classdev_flash *fled_cdev,
127 struct led_classdev_flash *iled_cdev,
128 const struct v4l2_flash_ops *ops,
129 struct v4l2_flash_config *config);
130
131/**
132 * v4l2_flash_release - release V4L2 Flash sub-device
Mauro Carvalho Chehab62ba6b22015-08-22 05:28:44 -0300133 * @v4l2_flash: the V4L2 Flash sub-device to release
Jacek Anaszewski42bd6f52015-06-19 00:31:47 -0700134 *
135 * Release V4L2 Flash sub-device.
136 */
137void v4l2_flash_release(struct v4l2_flash *v4l2_flash);
138
139#else
140static inline struct v4l2_flash *v4l2_flash_init(
141 struct device *dev, struct device_node *of_node,
142 struct led_classdev_flash *fled_cdev,
143 struct led_classdev_flash *iled_cdev,
144 const struct v4l2_flash_ops *ops,
145 struct v4l2_flash_config *config)
146{
147 return NULL;
148}
149
150static inline void v4l2_flash_release(struct v4l2_flash *v4l2_flash)
151{
152}
153#endif /* CONFIG_V4L2_FLASH_LED_CLASS */
154
155#endif /* _V4L2_FLASH_H */