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