Re: [PATCH/RFC v8 06/14] media: Add registration helpers for V4L2 flash sub-devices
On 11/28/2014 10:17 AM, Jacek Anaszewski wrote: This patch adds helper functions for registering/unregistering LED Flash class devices as V4L2 sub-devices. The functions should be called from the LED subsystem device driver. In case the support for V4L2 Flash sub-devices is disabled in the kernel config the functions' empty versions will be used. Signed-off-by: Jacek Anaszewski j.anaszew...@samsung.com Acked-by: Kyungmin Park kyungmin.p...@samsung.com Cc: Sakari Ailus sakari.ai...@iki.fi Cc: Hans Verkuil hans.verk...@cisco.com --- drivers/media/v4l2-core/Kconfig | 11 + drivers/media/v4l2-core/Makefile |2 + drivers/media/v4l2-core/v4l2-flash.c | 516 ++ include/media/v4l2-flash.h | 138 + 4 files changed, 667 insertions(+) create mode 100644 drivers/media/v4l2-core/v4l2-flash.c create mode 100644 include/media/v4l2-flash.h diff --git a/drivers/media/v4l2-core/Kconfig b/drivers/media/v4l2-core/Kconfig index ba7e21a..f034f1a 100644 --- a/drivers/media/v4l2-core/Kconfig +++ b/drivers/media/v4l2-core/Kconfig @@ -44,6 +44,17 @@ config V4L2_MEM2MEM_DEV tristate depends on VIDEOBUF2_CORE +# Used by LED subsystem flash drivers +config V4L2_FLASH_LED_CLASS + tristate Enable support for Flash sub-devices + depends on VIDEO_V4L2_SUBDEV_API + depends on LEDS_CLASS_FLASH + ---help--- + Say Y here to enable support for Flash sub-devices, which allow + to control LED class devices with use of V4L2 Flash controls. + + When in doubt, say N. + # Used by drivers that need Videobuf modules config VIDEOBUF_GEN tristate diff --git a/drivers/media/v4l2-core/Makefile b/drivers/media/v4l2-core/Makefile index 63d29f2..44e858c 100644 --- a/drivers/media/v4l2-core/Makefile +++ b/drivers/media/v4l2-core/Makefile @@ -22,6 +22,8 @@ obj-$(CONFIG_VIDEO_TUNER) += tuner.o obj-$(CONFIG_V4L2_MEM2MEM_DEV) += v4l2-mem2mem.o +obj-$(CONFIG_V4L2_FLASH_LED_CLASS) += v4l2-flash.o + obj-$(CONFIG_VIDEOBUF_GEN) += videobuf-core.o obj-$(CONFIG_VIDEOBUF_DMA_SG) += videobuf-dma-sg.o obj-$(CONFIG_VIDEOBUF_DMA_CONTIG) += videobuf-dma-contig.o diff --git a/drivers/media/v4l2-core/v4l2-flash.c b/drivers/media/v4l2-core/v4l2-flash.c new file mode 100644 index 000..f5075b0 --- /dev/null +++ b/drivers/media/v4l2-core/v4l2-flash.c @@ -0,0 +1,516 @@ +/* + * V4L2 Flash LED sub-device registration helpers. + * + * Copyright (C) 2014 Samsung Electronics Co., Ltd + * Author: Jacek Anaszewski j.anaszew...@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. + */ + +#include linux/led-class-flash.h +#include linux/module.h +#include linux/mutex.h +#include linux/slab.h +#include linux/types.h +#include media/v4l2-flash.h + +#define has_flash_op(v4l2_flash, op) \ + (v4l2_flash v4l2_flash-ops-op) + +#define call_flash_op(v4l2_flash, op, args...) \ + (has_flash_op(v4l2_flash, op) ? \ + v4l2_flash-ops-op(args) : \ + -EINVAL) + +static inline enum led_brightness v4l2_flash_intensity_to_led_brightness( + struct v4l2_ctrl *ctrl, + s32 intensity) +{ + s64 __intensity = intensity - ctrl-minimum; + + do_div(__intensity, ctrl-step); + + return __intensity + 1; +} + +static inline s32 v4l2_flash_led_brightness_to_intensity( + struct v4l2_ctrl *ctrl, + enum led_brightness brightness) +{ + return ((brightness - 1) * ctrl-step) + ctrl-minimum; +} + +static int v4l2_flash_g_volatile_ctrl(struct v4l2_ctrl *c) +{ + struct v4l2_flash *v4l2_flash = v4l2_ctrl_to_v4l2_flash(c); + struct led_classdev_flash *flash = v4l2_flash-flash; + struct led_classdev *led_cdev = flash-led_cdev; + struct v4l2_ctrl **ctrls = v4l2_flash-ctrls; + bool is_strobing; + int ret; + + switch (c-id) { + case V4L2_CID_FLASH_TORCH_INTENSITY: + /* +* Update torch brightness only if in TORCH_MODE. +* In other modes torch led is turned off, which +* would spuriously inform the user space that +* V4L2_CID_FLASH_TORCH_INTENSITY control setting +* has changed. +*/ + if (ctrls[LED_MODE]-val == V4L2_FLASH_LED_MODE_TORCH) { + ret = led_update_brightness(led_cdev); + if (ret 0) + return ret; + c-val = v4l2_flash_led_brightness_to_intensity( + ctrls[TORCH_INTENSITY], +
[PATCH/RFC v8 06/14] media: Add registration helpers for V4L2 flash sub-devices
This patch adds helper functions for registering/unregistering LED Flash class devices as V4L2 sub-devices. The functions should be called from the LED subsystem device driver. In case the support for V4L2 Flash sub-devices is disabled in the kernel config the functions' empty versions will be used. Signed-off-by: Jacek Anaszewski j.anaszew...@samsung.com Acked-by: Kyungmin Park kyungmin.p...@samsung.com Cc: Sakari Ailus sakari.ai...@iki.fi Cc: Hans Verkuil hans.verk...@cisco.com --- drivers/media/v4l2-core/Kconfig | 11 + drivers/media/v4l2-core/Makefile |2 + drivers/media/v4l2-core/v4l2-flash.c | 516 ++ include/media/v4l2-flash.h | 138 + 4 files changed, 667 insertions(+) create mode 100644 drivers/media/v4l2-core/v4l2-flash.c create mode 100644 include/media/v4l2-flash.h diff --git a/drivers/media/v4l2-core/Kconfig b/drivers/media/v4l2-core/Kconfig index ba7e21a..f034f1a 100644 --- a/drivers/media/v4l2-core/Kconfig +++ b/drivers/media/v4l2-core/Kconfig @@ -44,6 +44,17 @@ config V4L2_MEM2MEM_DEV tristate depends on VIDEOBUF2_CORE +# Used by LED subsystem flash drivers +config V4L2_FLASH_LED_CLASS + tristate Enable support for Flash sub-devices + depends on VIDEO_V4L2_SUBDEV_API + depends on LEDS_CLASS_FLASH + ---help--- + Say Y here to enable support for Flash sub-devices, which allow + to control LED class devices with use of V4L2 Flash controls. + + When in doubt, say N. + # Used by drivers that need Videobuf modules config VIDEOBUF_GEN tristate diff --git a/drivers/media/v4l2-core/Makefile b/drivers/media/v4l2-core/Makefile index 63d29f2..44e858c 100644 --- a/drivers/media/v4l2-core/Makefile +++ b/drivers/media/v4l2-core/Makefile @@ -22,6 +22,8 @@ obj-$(CONFIG_VIDEO_TUNER) += tuner.o obj-$(CONFIG_V4L2_MEM2MEM_DEV) += v4l2-mem2mem.o +obj-$(CONFIG_V4L2_FLASH_LED_CLASS) += v4l2-flash.o + obj-$(CONFIG_VIDEOBUF_GEN) += videobuf-core.o obj-$(CONFIG_VIDEOBUF_DMA_SG) += videobuf-dma-sg.o obj-$(CONFIG_VIDEOBUF_DMA_CONTIG) += videobuf-dma-contig.o diff --git a/drivers/media/v4l2-core/v4l2-flash.c b/drivers/media/v4l2-core/v4l2-flash.c new file mode 100644 index 000..f5075b0 --- /dev/null +++ b/drivers/media/v4l2-core/v4l2-flash.c @@ -0,0 +1,516 @@ +/* + * V4L2 Flash LED sub-device registration helpers. + * + * Copyright (C) 2014 Samsung Electronics Co., Ltd + * Author: Jacek Anaszewski j.anaszew...@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. + */ + +#include linux/led-class-flash.h +#include linux/module.h +#include linux/mutex.h +#include linux/slab.h +#include linux/types.h +#include media/v4l2-flash.h + +#define has_flash_op(v4l2_flash, op) \ + (v4l2_flash v4l2_flash-ops-op) + +#define call_flash_op(v4l2_flash, op, args...) \ + (has_flash_op(v4l2_flash, op) ? \ + v4l2_flash-ops-op(args) : \ + -EINVAL) + +static inline enum led_brightness v4l2_flash_intensity_to_led_brightness( + struct v4l2_ctrl *ctrl, + s32 intensity) +{ + s64 __intensity = intensity - ctrl-minimum; + + do_div(__intensity, ctrl-step); + + return __intensity + 1; +} + +static inline s32 v4l2_flash_led_brightness_to_intensity( + struct v4l2_ctrl *ctrl, + enum led_brightness brightness) +{ + return ((brightness - 1) * ctrl-step) + ctrl-minimum; +} + +static int v4l2_flash_g_volatile_ctrl(struct v4l2_ctrl *c) +{ + struct v4l2_flash *v4l2_flash = v4l2_ctrl_to_v4l2_flash(c); + struct led_classdev_flash *flash = v4l2_flash-flash; + struct led_classdev *led_cdev = flash-led_cdev; + struct v4l2_ctrl **ctrls = v4l2_flash-ctrls; + bool is_strobing; + int ret; + + switch (c-id) { + case V4L2_CID_FLASH_TORCH_INTENSITY: + /* +* Update torch brightness only if in TORCH_MODE. +* In other modes torch led is turned off, which +* would spuriously inform the user space that +* V4L2_CID_FLASH_TORCH_INTENSITY control setting +* has changed. +*/ + if (ctrls[LED_MODE]-val == V4L2_FLASH_LED_MODE_TORCH) { + ret = led_update_brightness(led_cdev); + if (ret 0) + return ret; + c-val = v4l2_flash_led_brightness_to_intensity( + ctrls[TORCH_INTENSITY], + led_cdev-brightness); + } +