Source
x
static const struct v4l2_subdev_internal_ops v4l2_flash_subdev_internal_ops = {
/*
* V4L2 flash LED sub-device registration helpers.
*
* Copyright (C) 2015 Samsung Electronics Co., Ltd
* Author: Jacek Anaszewski <j.anaszewski@samsung.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
enum ctrl_init_data_id {
LED_MODE,
TORCH_INTENSITY,
FLASH_INTENSITY,
INDICATOR_INTENSITY,
FLASH_TIMEOUT,
STROBE_SOURCE,
/*
* Only above values are applicable to
* the 'ctrls' array in the struct v4l2_flash.
*/
FLASH_STROBE,
STROBE_STOP,
STROBE_STATUS,
FLASH_FAULT,
NUM_FLASH_CTRLS,
};
static enum led_brightness __intensity_to_led_brightness(
struct v4l2_ctrl *ctrl, s32 intensity)
{
intensity -= ctrl->minimum;
intensity /= (u32) ctrl->step;
/*
* Indicator LEDs, unlike torch LEDs, are turned on/off basing on
* the state of V4L2_CID_FLASH_INDICATOR_INTENSITY control only.
* Therefore it must be possible to set it to 0 level which in
* the LED subsystem reflects LED_OFF state.
*/
if (ctrl->minimum)
++intensity;
return intensity;
}
static s32 __led_brightness_to_intensity(struct v4l2_ctrl *ctrl,
enum led_brightness brightness)
{
/*
* Indicator LEDs, unlike torch LEDs, are turned on/off basing on
* the state of V4L2_CID_FLASH_INDICATOR_INTENSITY control only.
* Do not decrement brightness read from the LED subsystem for
* indicator LED as it may equal 0. For torch LEDs this function
* is called only when V4L2_FLASH_LED_MODE_TORCH is set and the
* brightness read is guaranteed to be greater than 0. In the mode
* V4L2_FLASH_LED_MODE_NONE the cached torch intensity value is used.
*/
if (ctrl->id != V4L2_CID_FLASH_INDICATOR_INTENSITY)
--brightness;
return (brightness * ctrl->step) + ctrl->minimum;
}
static void v4l2_flash_set_led_brightness(struct v4l2_flash *v4l2_flash,
struct v4l2_ctrl *ctrl)
{
struct v4l2_ctrl **ctrls = v4l2_flash->ctrls;
enum led_brightness brightness;
if (has_flash_op(v4l2_flash, intensity_to_led_brightness))
brightness = call_flash_op(v4l2_flash,
intensity_to_led_brightness,
ctrl->val);
else