Jacek Anaszewski | 42bd6f5 | 2015-06-19 00:31:47 -0700 | [diff] [blame] | 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 | |
| 18 | struct led_classdev_flash; |
| 19 | struct led_classdev; |
| 20 | struct v4l2_flash; |
| 21 | enum led_brightness; |
| 22 | |
Mauro Carvalho Chehab | 0d56015 | 2016-09-08 18:23:35 -0300 | [diff] [blame] | 23 | /** |
Jacek Anaszewski | 42bd6f5 | 2015-06-19 00:31:47 -0700 | [diff] [blame] | 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 | */ |
| 31 | struct v4l2_flash_ctrl_data { |
| 32 | struct v4l2_ctrl_config config; |
| 33 | u32 cid; |
| 34 | }; |
| 35 | |
Mauro Carvalho Chehab | 0d56015 | 2016-09-08 18:23:35 -0300 | [diff] [blame] | 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 | */ |
Jacek Anaszewski | 42bd6f5 | 2015-06-19 00:31:47 -0700 | [diff] [blame] | 46 | struct v4l2_flash_ops { |
Jacek Anaszewski | 42bd6f5 | 2015-06-19 00:31:47 -0700 | [diff] [blame] | 47 | int (*external_strobe_set)(struct v4l2_flash *v4l2_flash, |
| 48 | bool enable); |
Jacek Anaszewski | 42bd6f5 | 2015-06-19 00:31:47 -0700 | [diff] [blame] | 49 | enum led_brightness (*intensity_to_led_brightness) |
| 50 | (struct v4l2_flash *v4l2_flash, s32 intensity); |
Jacek Anaszewski | 42bd6f5 | 2015-06-19 00:31:47 -0700 | [diff] [blame] | 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, |
Mauro Carvalho Chehab | 62ba6b2 | 2015-08-22 05:28:44 -0300 | [diff] [blame] | 58 | * unique in the system |
Sakari Ailus | 503dd28 | 2017-07-18 09:26:59 -0400 | [diff] [blame] | 59 | * @intensity: non-flash strobe constraints for the LED |
Jacek Anaszewski | 42bd6f5 | 2015-06-19 00:31:47 -0700 | [diff] [blame] | 60 | * @flash_faults: bitmask of flash faults that the LED flash class |
Mauro Carvalho Chehab | 62ba6b2 | 2015-08-22 05:28:44 -0300 | [diff] [blame] | 61 | * device can report; corresponding LED_FAULT* bit |
| 62 | * definitions are available in the header file |
| 63 | * <linux/led-class-flash.h> |
Jacek Anaszewski | 42bd6f5 | 2015-06-19 00:31:47 -0700 | [diff] [blame] | 64 | * @has_external_strobe: external strobe capability |
| 65 | */ |
| 66 | struct v4l2_flash_config { |
| 67 | char dev_name[32]; |
Sakari Ailus | 503dd28 | 2017-07-18 09:26:59 -0400 | [diff] [blame] | 68 | struct led_flash_setting intensity; |
Jacek Anaszewski | 42bd6f5 | 2015-06-19 00:31:47 -0700 | [diff] [blame] | 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 | */ |
| 84 | struct v4l2_flash { |
| 85 | struct led_classdev_flash *fled_cdev; |
Sakari Ailus | 85f7ff9 | 2017-06-02 05:30:02 -0400 | [diff] [blame] | 86 | struct led_classdev *iled_cdev; |
Jacek Anaszewski | 42bd6f5 | 2015-06-19 00:31:47 -0700 | [diff] [blame] | 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 | |
Mauro Carvalho Chehab | 716b876 | 2017-09-28 09:41:48 -0400 | [diff] [blame] | 94 | /** |
| 95 | * v4l2_subdev_to_v4l2_flash - Returns a &struct v4l2_flash from the |
| 96 | * &struct v4l2_subdev embedded on it. |
| 97 | * |
| 98 | * @sd: pointer to &struct v4l2_subdev |
| 99 | */ |
Jacek Anaszewski | 42bd6f5 | 2015-06-19 00:31:47 -0700 | [diff] [blame] | 100 | static inline struct v4l2_flash *v4l2_subdev_to_v4l2_flash( |
| 101 | struct v4l2_subdev *sd) |
| 102 | { |
| 103 | return container_of(sd, struct v4l2_flash, sd); |
| 104 | } |
| 105 | |
Mauro Carvalho Chehab | 716b876 | 2017-09-28 09:41:48 -0400 | [diff] [blame] | 106 | /** |
| 107 | * v4l2_ctrl_to_v4l2_flash - Returns a &struct v4l2_flash from the |
| 108 | * &struct v4l2_ctrl embedded on it. |
| 109 | * |
| 110 | * @c: pointer to &struct v4l2_ctrl |
| 111 | */ |
Jacek Anaszewski | 42bd6f5 | 2015-06-19 00:31:47 -0700 | [diff] [blame] | 112 | static inline struct v4l2_flash *v4l2_ctrl_to_v4l2_flash(struct v4l2_ctrl *c) |
| 113 | { |
| 114 | return container_of(c->handler, struct v4l2_flash, hdl); |
| 115 | } |
| 116 | |
| 117 | #if IS_ENABLED(CONFIG_V4L2_FLASH_LED_CLASS) |
| 118 | /** |
| 119 | * v4l2_flash_init - initialize V4L2 flash led sub-device |
| 120 | * @dev: flash device, e.g. an I2C device |
Sakari Ailus | 048ea05 | 2016-08-31 04:28:46 -0300 | [diff] [blame] | 121 | * @fwn: fwnode_handle of the LED, may be NULL if the same as device's |
Jacek Anaszewski | 42bd6f5 | 2015-06-19 00:31:47 -0700 | [diff] [blame] | 122 | * @fled_cdev: LED flash class device to wrap |
Mauro Carvalho Chehab | 62ba6b2 | 2015-08-22 05:28:44 -0300 | [diff] [blame] | 123 | * @ops: V4L2 Flash device ops |
Jacek Anaszewski | 42bd6f5 | 2015-06-19 00:31:47 -0700 | [diff] [blame] | 124 | * @config: initialization data for V4L2 Flash sub-device |
| 125 | * |
| 126 | * Create V4L2 Flash sub-device wrapping given LED subsystem device. |
Sakari Ailus | 40cefff | 2017-07-19 18:38:36 -0400 | [diff] [blame] | 127 | * The ops pointer is stored by the V4L2 flash framework. No |
| 128 | * references are held to config nor its contents once this function |
| 129 | * has returned. |
Jacek Anaszewski | 42bd6f5 | 2015-06-19 00:31:47 -0700 | [diff] [blame] | 130 | * |
| 131 | * Returns: A valid pointer, or, when an error occurs, the return |
| 132 | * value is encoded using ERR_PTR(). Use IS_ERR() to check and |
| 133 | * PTR_ERR() to obtain the numeric return value. |
| 134 | */ |
| 135 | struct v4l2_flash *v4l2_flash_init( |
Sakari Ailus | 048ea05 | 2016-08-31 04:28:46 -0300 | [diff] [blame] | 136 | struct device *dev, struct fwnode_handle *fwn, |
Jacek Anaszewski | 42bd6f5 | 2015-06-19 00:31:47 -0700 | [diff] [blame] | 137 | struct led_classdev_flash *fled_cdev, |
Sakari Ailus | 503dd28 | 2017-07-18 09:26:59 -0400 | [diff] [blame] | 138 | const struct v4l2_flash_ops *ops, struct v4l2_flash_config *config); |
| 139 | |
| 140 | /** |
| 141 | * v4l2_flash_indicator_init - initialize V4L2 indicator sub-device |
| 142 | * @dev: flash device, e.g. an I2C device |
| 143 | * @fwn: fwnode_handle of the LED, may be NULL if the same as device's |
| 144 | * @iled_cdev: LED flash class device representing the indicator LED |
| 145 | * @config: initialization data for V4L2 Flash sub-device |
| 146 | * |
| 147 | * Create V4L2 Flash sub-device wrapping given LED subsystem device. |
Sakari Ailus | 40cefff | 2017-07-19 18:38:36 -0400 | [diff] [blame] | 148 | * The ops pointer is stored by the V4L2 flash framework. No |
| 149 | * references are held to config nor its contents once this function |
| 150 | * has returned. |
Sakari Ailus | 503dd28 | 2017-07-18 09:26:59 -0400 | [diff] [blame] | 151 | * |
| 152 | * Returns: A valid pointer, or, when an error occurs, the return |
| 153 | * value is encoded using ERR_PTR(). Use IS_ERR() to check and |
| 154 | * PTR_ERR() to obtain the numeric return value. |
| 155 | */ |
| 156 | struct v4l2_flash *v4l2_flash_indicator_init( |
| 157 | struct device *dev, struct fwnode_handle *fwn, |
| 158 | struct led_classdev *iled_cdev, struct v4l2_flash_config *config); |
Jacek Anaszewski | 42bd6f5 | 2015-06-19 00:31:47 -0700 | [diff] [blame] | 159 | |
| 160 | /** |
| 161 | * v4l2_flash_release - release V4L2 Flash sub-device |
Mauro Carvalho Chehab | 62ba6b2 | 2015-08-22 05:28:44 -0300 | [diff] [blame] | 162 | * @v4l2_flash: the V4L2 Flash sub-device to release |
Jacek Anaszewski | 42bd6f5 | 2015-06-19 00:31:47 -0700 | [diff] [blame] | 163 | * |
| 164 | * Release V4L2 Flash sub-device. |
| 165 | */ |
| 166 | void v4l2_flash_release(struct v4l2_flash *v4l2_flash); |
| 167 | |
| 168 | #else |
| 169 | static inline struct v4l2_flash *v4l2_flash_init( |
Sakari Ailus | 048ea05 | 2016-08-31 04:28:46 -0300 | [diff] [blame] | 170 | struct device *dev, struct fwnode_handle *fwn, |
Jacek Anaszewski | 42bd6f5 | 2015-06-19 00:31:47 -0700 | [diff] [blame] | 171 | struct led_classdev_flash *fled_cdev, |
Sakari Ailus | 503dd28 | 2017-07-18 09:26:59 -0400 | [diff] [blame] | 172 | const struct v4l2_flash_ops *ops, struct v4l2_flash_config *config) |
| 173 | { |
| 174 | return NULL; |
| 175 | } |
| 176 | |
| 177 | static inline struct v4l2_flash *v4l2_flash_indicator_init( |
| 178 | struct device *dev, struct fwnode_handle *fwn, |
| 179 | struct led_classdev *iled_cdev, struct v4l2_flash_config *config) |
Jacek Anaszewski | 42bd6f5 | 2015-06-19 00:31:47 -0700 | [diff] [blame] | 180 | { |
| 181 | return NULL; |
| 182 | } |
| 183 | |
| 184 | static inline void v4l2_flash_release(struct v4l2_flash *v4l2_flash) |
| 185 | { |
| 186 | } |
| 187 | #endif /* CONFIG_V4L2_FLASH_LED_CLASS */ |
| 188 | |
| 189 | #endif /* _V4L2_FLASH_H */ |