LED / flash API integration
Subsystems (5)
v9 cover LED / flash API integration
This is ninth non-RFC version of LED / flash API integration series [1]. It is based on linux_next-20150519 with patch [2].
================
Changes since v8
================
- switched from samsung,flash-leds to samsun,camera-flashes DT property
- improved async sub-devices matching for exynos4-is media device
- modified v4l2-flash-led-class wrapper to incorporate indicator LED class deviecs
================
Changes since v7
================
- Merged patches from Sakari for v4l2-flash-led-class and V4L2 related patches for leds-max77693 and leds-aat1290 drivers
- applied minor modifications to the both led drivers related patches
- modified exynos4-is media device to parse new samsung,flash-led property, instead of 'flashes' array
- added DT documentation for samsung,flash-led property
================
Changes since v5
================
- renamed v4l2-flash module to v4l2-flash-led-class and applied other related modifications spotted by Sakari
- fixed not released of_node reference in max77693-led driver
================
Changes since v4
================
- adapted leds-max77693 and leds-aat1290 drivers to the recent modifications in leds/common.txt bindings documentation and changed the behaviour when properties are missing
- modified DT bindings documenation for the aforementioned drivers
- removed unjustified use of goto in the leds-aat1290 driver
- fixed lack of of_node_put in leds-aat1290 driver, after parsing DT child node
- removed patch adding 'skyworks' vendor prefix, as the entry has been recently added
================
Changes since v2
================
- improved leds/common DT bindings documentation
- improved max77693-led DT documentation
- fixed validation of DT confguration for leds-max77693 by minimal values in joint iouts case
- removed trigger-type property from leds-max77693 bindings and adjusted the driver accordingly
- improved LED Flash class documentation related to v4l2-flash sub-device initialization
- excluded from leds-aat1290 DT bindings documentation the part related to handling external strobe sources
================
Changes since v1
================
- excluded exynos4-is media device related patches, as there is consenus required related to flash devices handling in media device DT bindings
- modifications around LED Flash class settings and v4l2 flash config initialization in LED Flash class drivers and v4l2-flash wrapper
- switched to using DT node name as a device name for leds-max77693 and leds-aat1290 drivers, in case DT 'label' property is absent
- dropped OF dependecy for v4l2-flash wrapper
- moved LED_FAULTS definitions from led-class-flash.h to uapi/linux/leds.h
- allowed for multiple clients of v4l2-flash sub-device
======================
Changes since RFC v13:
======================
- reduced number of patches - some of them have been merged
- slightly modified max77693-led device naming
- fixed issues in v4l2-flash helpers detected with yavta
- cleaned up AAT1290 device tree documentation
- added GPIOLIB dependecy to AAT1290 related entry in Kconfig
Thanks,
Jacek Anaszewski
[1] http://www.spinics.net/lists/kernel/msg1944538.html
[2] http://www.spinics.net/lists/linux-media/msg89839.html
Jacek Anaszewski (8):
Documentation: leds: Add description of v4l2-flash sub-device
media: Add registration helpers for V4L2 flash sub-devices
leds: max77693: add support for V4L2 Flash sub-device
DT: aat1290: Document handling external strobe sources
leds: aat1290: add support for V4L2 Flash sub-device
exynos4-is: Improve the mechanism of async subdevs verification
DT: Add documentation for exynos4-is 'flashes' property
exynos4-is: Add support for v4l2-flash subdevs
.../devicetree/bindings/leds/leds-aat1290.txt | 36 +- .../devicetree/bindings/media/samsung-fimc.txt | 10 + Documentation/leds/leds-class-flash.txt | 50 ++ drivers/leds/Kconfig | 1 + drivers/leds/leds-aat1290.c | 137 +++- drivers/leds/leds-max77693.c | 129 +++- drivers/media/platform/exynos4-is/media-dev.c | 94 ++- drivers/media/platform/exynos4-is/media-dev.h | 12 +- drivers/media/v4l2-core/Kconfig | 11 + drivers/media/v4l2-core/Makefile | 2 + drivers/media/v4l2-core/v4l2-flash-led-class.c | 671 ++++++++++++++++++++ include/media/v4l2-flash-led-class.h | 148 +++++ 12 files changed, 1277 insertions(+), 24 deletions(-) create mode 100644 drivers/media/v4l2-core/v4l2-flash-led-class.c create mode 100644 include/media/v4l2-flash-led-class.h
Signature · 1 line
1.7.9.5
PATCH v9 1/8 Documentation: leds: Add description of v4l2-flash sub-device
This patch extends LED Flash class documention by the description of interactions with v4l2-flash sub-device.
--- Documentation/leds/leds-class-flash.txt | 50 +++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+)
Documentation/leds/leds-class-flash.txt +50 -0
@@ -20,3 +20,53 @@ Following sysfs attributes are exposed for controlling flash LED devices: - max_flash_timeout - flash_strobe - flash_fault + + +V4L2 flash wrapper for flash LEDs +================================= + +A LED subsystem driver can be controlled also from the level of VideoForLinux2 +subsystem. In order to enable this CONFIG_V4L2_FLASH_LED_CLASS symbol has to +be defined in the kernel config. + +The driver must call the v4l2_flash_init function to get registered in the +V4L2 subsystem. The function takes six arguments: +- dev : flash device, e.g. an I2C device +- of_node : of_node of the LED, may be NULL if the same as device's +- fled_cdev : LED flash class device to wrap +- iled_cdev : LED class device representing indicator LED associated with + the LED flash class device, may be NULL +- ops : V4L2 specific ops + * external_strobe_set - defines the source of the flash LED strobe - + V4L2_CID_FLASH_STROBE control or external source, typically + a sensor, which makes it possible to synchronise the flash + strobe start with exposure start, + * intensity_to_led_brightness and led_brightness_to_intensity - perform + enum led_brightness <-> V4L2 intensity conversion in a device + specific manner - they can be used for devices with non-linear + LED current scale. +- config : configuration for V4L2 Flash sub-device + * dev_name - the name of the media entity, unique in the system, + * flash_faults - bitmask of flash faults that the LED flash class + device can report; corresponding LED_FAULT* bit definitions are + available in <linux/led-class-flash.h>, + * torch_intensity - constraints for the LED in TORCH mode + in microamperes, + * indicator_intensity - constraints for the indicator LED + in microamperes, + * has_external_strobe - determines whether the flash strobe source + can be switched to external. + +On remove the v4l2_flash_release function has to be called, which takes one +argument - struct v4l2_flash pointer returned previously by v4l2_flash_init. + +Please refer to drivers/leds/leds-max77693.c for an exemplary usage of the +v4l2 flash wrapper. + +Once the V4L2 sub-device is registered by the driver which created the Media +controller device, the sub-device node acts just as a node of a native V4L2 +flash API device would. The calls are simply routed to the LED flash API. + +Opening the V4L2 flash sub-device makes the LED subsystem sysfs interface +unavailable. The interface is re-enabled after the V4L2 flash sub-device +is closed.
Signature · 1 line
1.7.9.5
Re: [PATCH v9 1/8] Documentation: leds: Add description of v4l2-flash sub-device
Hi Jacek,
Documentation/leds/leds-class-flash.txt Following sysfs attributes are exposed for controlling flash LED devices: · line 61
Quoted 2 lines · Jacek Anaszewski
Documentation/leds/leds-class-flash.txt +2
-0+On remove the v4l2_flash_release function has to be called, which takes one +argument - struct v4l2_flash pointer returned previously by v4l2_flash_init.
You might want to add this function can be safely called with NULL or error pointer argument.
Signature · 4 lines
Kind regards, Sakari Ailus e-mail: [email protected] XMPP: [email protected]
PATCH v9 2/8 media: Add registration helpers for V4L2 flash sub-devices
In reply to Jacek AnaszewskiThis 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.
--- drivers/media/v4l2-core/Kconfig | 11 + drivers/media/v4l2-core/Makefile | 2 + drivers/media/v4l2-core/v4l2-flash-led-class.c | 671 ++++++++++++++++++++++++ include/media/v4l2-flash-led-class.h | 148 ++++++ 4 files changed, 832 insertions(+) create mode 100644 drivers/media/v4l2-core/v4l2-flash-led-class.c create mode 100644 include/media/v4l2-flash-led-class.h
drivers/media/v4l2-core/Kconfig +11 -0
@@ -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 "V4L2 flash API for LED flash class devices" + depends on VIDEO_V4L2_SUBDEV_API + depends on LEDS_CLASS_FLASH + ---help--- + Say Y here to enable V4L2 flash API support for LED flash + class drivers. + + When in doubt, say N. + # Used by drivers that need Videobuf modules config VIDEOBUF_GEN tristate
drivers/media/v4l2-core/Makefile +2 -0
@@ -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-led-class.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
drivers/media/v4l2-core/v4l2-flash-led-class.c new file +671 -0
671 lines not on this page · raw message
include/media/v4l2-flash-led-class.h new file +148 -0
148 lines not on this page · raw message
Signature · 1 line
1.7.9.5
Re: [PATCH v9 2/8] media: Add registration helpers for V4L2 flash sub-devices
Hi Jacek,
Quoted 10 lines · Jacek Anaszewski
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 <[email protected]>Acked-by Kyungmin Park <[email protected]>Cc Sakari Ailus <[email protected]>Cc Hans Verkuil <[email protected]>
Thanks for adding indicator support!
Signature · 4 lines
Regards, Sakari Ailus e-mail: [email protected] XMPP: [email protected]
Re: [PATCH v9 2/8] media: Add registration helpers for V4L2 flash sub-devices
Hi Sakari,
Quoted 9 lines · Sakari Ailus
Hi Jacek,
Quoted 6 lines · Jacek Anaszewski
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.
Quoted 9 lines
Quoted 4 lines
Signed-off-by Jacek Anaszewski <[email protected]>Acked-by Kyungmin Park <[email protected]>Cc Sakari Ailus <[email protected]>Cc Hans Verkuil <[email protected]>Thanks for adding indicator support!
Acked-by Sakari Ailus <[email protected]>
I missed one thing - sysfs interface of the indicator LED class also has to be disabled/enabled of v4l2_flash_open/close.
I am planning to reimplement the functions as follows, please let me know if you see any issues here:
static int v4l2_flash_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
{
struct v4l2_flash *v4l2_flash = v4l2_subdev_to_v4l2_flash(sd);
struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev;
struct led_classdev *led_cdev = &fled_cdev->led_cdev;
struct led_classdev_flash *iled_cdev = v4l2_flash->iled_cdev;
struct led_classdev *led_cdev_ind;
int ret = 0;
mutex_lock(&led_cdev->led_access);
if (!v4l2_fh_is_singular(&fh->vfh))
goto unlock;
led_sysfs_disable(led_cdev);
led_trigger_remove(led_cdev);
if (iled_cdev) {
led_cdev_ind = &iled_cdev->led_cdev;
mutex_lock(&led_cdev_ind->led_access);
led_sysfs_disable(led_cdev_ind);
led_trigger_remove(led_cdev_ind);
mutex_unlock(&led_cdev_ind->led_access);
}
ret = __sync_device_with_v4l2_controls(v4l2_flash); unlock:
mutex_unlock(&led_cdev->led_access);
return ret; }
static int v4l2_flash_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
{
struct v4l2_flash *v4l2_flash = v4l2_subdev_to_v4l2_flash(sd);
struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev;
struct led_classdev *led_cdev = &fled_cdev->led_cdev;
struct led_classdev_flash *iled_cdev = v4l2_flash->iled_cdev;
struct led_classdev *led_cdev_ind;
int ret = 0;
mutex_lock(&led_cdev->led_access);
if (v4l2_fh_is_singular(&fh->vfh)) {
if (v4l2_flash->ctrls[STROBE_SOURCE])
ret = v4l2_ctrl_s_ctrl(v4l2_flash->ctrls[STROBE_SV4L2_FLASH_STROBE_SOURCE_SOFTWARE);
led_sysfs_enable(led_cdev);
if (iled_cdev) {
led_cdev_ind = &iled_cdev->led_cdev;
mutex_lock(&led_cdev_ind->led_access);
led_sysfs_enable(led_cdev_ind);
mutex_unlock(&led_cdev_ind->led_access);
}
}
mutex_unlock(&led_cdev->led_access);
return ret; }
Signature · 2 lines
Best Regards, Jacek Anaszewski
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH v9 2/8] media: Add registration helpers for V4L2 flash sub-devices
Hi, Jacek!
Quoted 17 lines · Jacek Anaszewski
Hi Sakari,
Quoted 14 lines · Sakari Ailus
Hi Jacek,
Quoted 10 lines · Jacek Anaszewski
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 <[email protected]>Acked-by Kyungmin Park <[email protected]>Cc Sakari Ailus <[email protected]>Cc Hans Verkuil <[email protected]>
Quoted 7 lines
Quoted 4 lines
Thanks for adding indicator support!
I missed one thing - sysfs interface of the indicator LED class also has to be disabled/enabled of v4l2_flash_open/close.
Good catch.
Quoted 6 lines
I am planning to reimplement the functions as follows, please let me know if you see any issues here:
static int
v4l2_flash_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
Quoted 11 lines
{
struct v4l2_flash *v4l2_flash = v4l2_subdev_to_v4l2_flash(sd);
struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev;
struct led_classdev *led_cdev = &fled_cdev->led_cdev;
struct led_classdev_flash *iled_cdev = v4l2_flash->iled_cdev;
struct led_classdev *led_cdev_ind;
int ret = 0;I think you could spare some newlines above (and below as well).
Quoted 16 lines
mutex_lock(&led_cdev->led_access);
if (!v4l2_fh_is_singular(&fh->vfh))
goto unlock;
led_sysfs_disable(led_cdev);
led_trigger_remove(led_cdev);
if (iled_cdev) {
led_cdev_ind = &iled_cdev->led_cdev;You can also declare led_cdev_ind here as you don't need it outside the basic block.
Quoted 10 lines
mutex_lock(&led_cdev_ind->led_access);
led_sysfs_disable(led_cdev_ind);
led_trigger_remove(led_cdev_ind);
mutex_unlock(&led_cdev_ind->led_access);Please don't acquire the indicator mutex while holding the flash mutex. I don't think there's a need to do so, thus creating a dependency between the two. Just remember to check for v4l2_fh_is_singular() in both cases.
Quoted 5 lines
}
ret = __sync_device_with_v4l2_controls(v4l2_flash);If ret is < 0 here, you end up disabling the sysfs interface while open() fails (and v4l2_flash_close() will not be run). Shouldn't you handle that?
Quoted 32 lines
unlock:
mutex_unlock(&led_cdev->led_access); return ret;}
static int
v4l2_flash_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh){ struct v4l2_flash *v4l2_flash = v4l2_subdev_to_v4l2_flash(sd); struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev; struct led_classdev *led_cdev = &fled_cdev->led_cdev; struct led_classdev_flash *iled_cdev = v4l2_flash->iled_cdev; struct led_classdev *led_cdev_ind; int ret = 0; mutex_lock(&led_cdev->led_access); if (v4l2_fh_is_singular(&fh->vfh)) { if (v4l2_flash->ctrls[STROBE_SOURCE]) ret = v4l2_ctrl_s_ctrl(v4l2_flash->ctrls[STROBE_SV4L2_FLASH_STROBE_SOURCE_SOFTWARE);
Quoted 8 lines
led_sysfs_enable(led_cdev);
if (iled_cdev) {
led_cdev_ind = &iled_cdev->led_cdev;
mutex_lock(&led_cdev_ind->led_access);Ditto.
Quoted 21 lines
led_sysfs_enable(led_cdev_ind); mutex_unlock(&led_cdev_ind->led_access); } } mutex_unlock(&led_cdev->led_access); return ret;}
Signature · 8 lines
Kind regards, Sakari Ailus e-mail: [email protected] XMPP: [email protected] -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v9 2/8] media: Add registration helpers for V4L2 flash sub-devices
Hi Sakari,
Quoted 41 lines · Sakari Ailus
Hi, Jacek!
Quoted 17 lines · Jacek Anaszewski
Hi Sakari,
Quoted 14 lines · Sakari Ailus
Hi Jacek,
Quoted 10 lines · Jacek Anaszewski
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 <[email protected]>Acked-by Kyungmin Park <[email protected]>Cc Sakari Ailus <[email protected]>Cc Hans Verkuil <[email protected]>Quoted 7 lines
Quoted 4 lines
Thanks for adding indicator support!
Acked-by Sakari Ailus <[email protected]>I missed one thing - sysfs interface of the indicator LED class also has to be disabled/enabled of v4l2_flash_open/close.
Good catch.
Quoted 11 lines
I am planning to reimplement the functions as follows, please let me know if you see any issues here:
static int
v4l2_flash_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh){ struct v4l2_flash *v4l2_flash = v4l2_subdev_to_v4l2_flash(sd); struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev;
Quoted 8 lines
Quoted 6 lines
struct led_classdev *led_cdev = &fled_cdev->led_cdev; struct led_classdev_flash *iled_cdev = v4l2_flash->iled_cdev; struct led_classdev *led_cdev_ind; int ret = 0;I think you could spare some newlines above (and below as well).
There must have been some issue on thunderbird side, originally there were no newlines above.
Quoted 14 lines
Quoted 14 lines
mutex_lock(&led_cdev->led_access); if (!v4l2_fh_is_singular(&fh->vfh)) goto unlock; led_sysfs_disable(led_cdev); led_trigger_remove(led_cdev);
Quoted 5 lines
Quoted 2 lines
if (iled_cdev) { led_cdev_ind = &iled_cdev->led_cdev;You can also declare
led_cdev_indhere as you don't need it outside the basic block.
With new approach it will be required also in error path.
Quoted 9 lines
Quoted 9 lines
mutex_lock(&led_cdev_ind->led_access); led_sysfs_disable(led_cdev_ind); led_trigger_remove(led_cdev_ind);
Quoted 5 lines
Quoted 1 line
mutex_unlock(&led_cdev_ind->led_access);Please don't acquire the indicator mutex while holding the flash mutex. I don't think there's a need to do so, thus creating a dependency between the two.Just remember to check for
v4l2_fh_is_singular()in both cases.
I thought that the code would be simpler this way. Nevertheless I produced a new version by following your advise.
Quoted 9 lines
Quoted 6 lines
} ret = __sync_device_with_v4l2_controls(v4l2_flash);If ret is < 0 here, you end up disabling the sysfs interface while
open()fails (andv4l2_flash_close()will not be run). Shouldn't you handle that?
Good point.
Please find the new version of v4l2_flash{open|close} functions below:
static int v4l2_flash_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
{
struct v4l2_flash *v4l2_flash = v4l2_subdev_to_v4l2_flash(sd);
struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev;
struct led_classdev *led_cdev = &fled_cdev->led_cdev;
struct led_classdev_flash *iled_cdev = v4l2_flash->iled_cdev;
struct led_classdev *led_cdev_ind = NULL;
int ret = 0;
mutex_lock(&led_cdev->led_access);
if (!v4l2_fh_is_singular(&fh->vfh)) {
mutex_unlock(&led_cdev->led_access);
return 0;
}
led_sysfs_disable(led_cdev);
led_trigger_remove(led_cdev);
mutex_unlock(&led_cdev->led_access);
if (iled_cdev) {
led_cdev_ind = &iled_cdev->led_cdev;
mutex_lock(&led_cdev_ind->led_access);
if (!v4l2_fh_is_singular(&fh->vfh)) {
mutex_unlock(&led_cdev_ind->led_access);
return 0;
}
led_sysfs_disable(led_cdev_ind);
led_trigger_remove(led_cdev_ind);
mutex_unlock(&led_cdev_ind->led_access);
}
ret = __sync_device_with_v4l2_controls(v4l2_flash);
if (ret < 0)
goto out_sync_device;
return 0;
out_sync_device:
mutex_lock(&led_cdev->led_access);
if (v4l2_fh_is_singular(&fh->vfh))
led_sysfs_enable(led_cdev);
mutex_unlock(&led_cdev->led_access);
if (led_cdev_ind) {
mutex_lock(&led_cdev_ind->led_access);
if (v4l2_fh_is_singular(&fh->vfh))
led_sysfs_enable(led_cdev_ind);
mutex_unlock(&led_cdev_ind->led_access);
}
return ret;
}static int v4l2_flash_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
{
struct v4l2_flash *v4l2_flash = v4l2_subdev_to_v4l2_flash(sd);
struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev;
struct led_classdev *led_cdev = &fled_cdev->led_cdev;
struct led_classdev_flash *iled_cdev = v4l2_flash->iled_cdev;
int ret = 0;
mutex_lock(&led_cdev->led_access);
if (v4l2_fh_is_singular(&fh->vfh)) {
if (v4l2_flash->ctrls[STROBE_SOURCE])
ret =
v4l2_ctrl_s_ctrl(v4l2_flash->ctrls[STROBE_SOURCE],
V4L2_FLASH_STROBE_SOURCE_SOFTWARE);
led_sysfs_enable(led_cdev);
}
mutex_unlock(&led_cdev->led_access);
if (iled_cdev) {
struct led_classdev *led_cdev_ind = &iled_cdev->led_cdev;
mutex_lock(&led_cdev_ind->led_access);
if (v4l2_fh_is_singular(&fh->vfh))
led_sysfs_enable(led_cdev_ind);
mutex_unlock(&led_cdev_ind->led_access);
}
return ret;
}Signature · 2 lines
Best Regards, Jacek Anaszewski
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH v9 2/8] media: Add registration helpers for V4L2 flash sub-devices
Hi Jacek,
Quoted 47 lines · Jacek Anaszewski
Hi Sakari,
Quoted 44 lines · Sakari Ailus
Hi, Jacek!
Quoted 17 lines · Jacek Anaszewski
Hi Sakari,
Quoted 14 lines · Sakari Ailus
Hi Jacek,
Quoted 10 lines · Jacek Anaszewski
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 <[email protected]>Acked-by Kyungmin Park <[email protected]>Cc Sakari Ailus <[email protected]>Cc Hans Verkuil <[email protected]>Quoted 7 lines
Quoted 4 lines
Thanks for adding indicator support!
I missed one thing - sysfs interface of the indicator LED class also has to be disabled/enabled of v4l2_flash_open/close.
Good catch.
Quoted 14 lines
I am planning to reimplement the functions as follows, please let me know if you see any issues here:
static int
v4l2_flash_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh){ struct v4l2_flash *v4l2_flash = v4l2_subdev_to_v4l2_flash(sd); struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev; struct led_classdev *led_cdev = &fled_cdev->led_cdev; struct led_classdev_flash *iled_cdev = v4l2_flash->iled_cdev;
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
struct led_classdev *led_cdev_ind; int ret = 0;I think you could spare some newlines above (and below as well).
There must have been some issue on thunderbird side, originally there were no newlines above.
Ok. I've used Seamonkey, I believe it uses the same editor. Some bugs were unintroduced a few years ago, and since that I've mostly used a different editor (and MUA) when replying to patches.
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
mutex_lock(&led_cdev->led_access); if (!v4l2_fh_is_singular(&fh->vfh)) goto unlock; led_sysfs_disable(led_cdev); led_trigger_remove(led_cdev);
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
if (iled_cdev) { led_cdev_ind = &iled_cdev->led_cdev;You can also declare
led_cdev_indhere as you don't need it outside the basic block.With new approach it will be required also in error path.
True.
Quoted 34 lines
Quoted 9 lines
Quoted 9 lines
mutex_lock(&led_cdev_ind->led_access); led_sysfs_disable(led_cdev_ind); led_trigger_remove(led_cdev_ind);Quoted 5 lines
Quoted 1 line
mutex_unlock(&led_cdev_ind->led_access);Please don't acquire the indicator mutex while holding the flash mutex. I don't think there's a need to do so, thus creating a dependency between the two.Just remember to check for
v4l2_fh_is_singular()in both cases.I thought that the code would be simpler this way. Nevertheless I produced a new version by following your advise.
Quoted 9 lines
Quoted 6 lines
} ret = __sync_device_with_v4l2_controls(v4l2_flash);If ret is < 0 here, you end up disabling the sysfs interface while
open()fails (andv4l2_flash_close()will not be run). Shouldn't you handle that?Good point.
Please find the new version of v4l2_flash{open|close} functions below:
static int
v4l2_flash_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
Quoted 11 lines
{
struct v4l2_flash *v4l2_flash = v4l2_subdev_to_v4l2_flash(sd);
struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev;
struct led_classdev *led_cdev = &fled_cdev->led_cdev;
struct led_classdev_flash *iled_cdev = v4l2_flash->iled_cdev;
struct led_classdev *led_cdev_ind = NULL;
int ret = 0;
mutex_lock(&led_cdev->led_access);
if (!v4l2_fh_is_singular(&fh->vfh)) {Hmm. I just realised that this might be a bit broken --- v4l2_fh_is_singular() should return the same value independently of where in subdev's open() handler it is called.
But adding file handles to the list and checking how many there are of them is not properly serialised, i.e. another process could change the list in between. I'll try to submit a patch for that. No need to wait for that though.
So please ignore my earlier request to check for v4l2_fh_is_singular() for multiple times, it won't help. Once is enough, albeit more than that won't hurt.
Quoted 82 lines
mutex_unlock(&led_cdev->led_access); return 0; } led_sysfs_disable(led_cdev); led_trigger_remove(led_cdev); mutex_unlock(&led_cdev->led_access); if (iled_cdev) { led_cdev_ind = &iled_cdev->led_cdev; mutex_lock(&led_cdev_ind->led_access); if (!v4l2_fh_is_singular(&fh->vfh)) { mutex_unlock(&led_cdev_ind->led_access); return 0; } led_sysfs_disable(led_cdev_ind); led_trigger_remove(led_cdev_ind); mutex_unlock(&led_cdev_ind->led_access); } ret = __sync_device_with_v4l2_controls(v4l2_flash); if (ret < 0) goto out_sync_device; return 0; out_sync_device: mutex_lock(&led_cdev->led_access); if (v4l2_fh_is_singular(&fh->vfh)) led_sysfs_enable(led_cdev); mutex_unlock(&led_cdev->led_access); if (led_cdev_ind) { mutex_lock(&led_cdev_ind->led_access); if (v4l2_fh_is_singular(&fh->vfh)) led_sysfs_enable(led_cdev_ind); mutex_unlock(&led_cdev_ind->led_access); } return ret; }static int
v4l2_flash_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh){ struct v4l2_flash *v4l2_flash = v4l2_subdev_to_v4l2_flash(sd); struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev; struct led_classdev *led_cdev = &fled_cdev->led_cdev; struct led_classdev_flash *iled_cdev = v4l2_flash->iled_cdev; int ret = 0; mutex_lock(&led_cdev->led_access); if (v4l2_fh_is_singular(&fh->vfh)) { if (v4l2_flash->ctrls[STROBE_SOURCE]) ret = v4l2_ctrl_s_ctrl(v4l2_flash->ctrls[STROBE_SOURCE], V4L2_FLASH_STROBE_SOURCE_SOFTWARE); led_sysfs_enable(led_cdev); } mutex_unlock(&led_cdev->led_access); if (iled_cdev) { struct led_classdev *led_cdev_ind = &iled_cdev->led_cdev; mutex_lock(&led_cdev_ind->led_access); if (v4l2_fh_is_singular(&fh->vfh)) led_sysfs_enable(led_cdev_ind); mutex_unlock(&led_cdev_ind->led_access); } return ret; }
Signature · 8 lines
Kind regards, Sakari Ailus e-mail: [email protected] XMPP: [email protected] -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v9 2/8] media: Add registration helpers for V4L2 flash sub-devices
Hi Sakari,
Quoted 137 lines · Sakari Ailus
Hi Jacek,
Quoted 47 lines · Jacek Anaszewski
Hi Sakari,
Quoted 44 lines · Sakari Ailus
Hi, Jacek!
Quoted 17 lines · Jacek Anaszewski
Hi Sakari,
Quoted 14 lines · Sakari Ailus
Hi Jacek,
Quoted 10 lines · Jacek Anaszewski
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 <[email protected]>Acked-by Kyungmin Park <[email protected]>Cc Sakari Ailus <[email protected]>Cc Hans Verkuil <[email protected]>Quoted 7 lines
Quoted 4 lines
Thanks for adding indicator support!
Acked-by Sakari Ailus <[email protected]>I missed one thing - sysfs interface of the indicator LED class also has to be disabled/enabled of v4l2_flash_open/close.
Good catch.
Quoted 14 lines
I am planning to reimplement the functions as follows, please let me know if you see any issues here:
static int
v4l2_flash_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh){ struct v4l2_flash *v4l2_flash = v4l2_subdev_to_v4l2_flash(sd); struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev; struct led_classdev *led_cdev = &fled_cdev->led_cdev; struct led_classdev_flash *iled_cdev = v4l2_flash->iled_cdev;Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
struct led_classdev *led_cdev_ind; int ret = 0;I think you could spare some newlines above (and below as well).
There must have been some issue on thunderbird side, originally there were no newlines above.
Ok. I've used Seamonkey, I believe it uses the same editor. Some bugs were unintroduced a few years ago, and since that I've mostly used a different editor (and MUA) when replying to patches.
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
mutex_lock(&led_cdev->led_access); if (!v4l2_fh_is_singular(&fh->vfh)) goto unlock; led_sysfs_disable(led_cdev); led_trigger_remove(led_cdev);Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
if (iled_cdev) { led_cdev_ind = &iled_cdev->led_cdev;You can also declare
led_cdev_indhere as you don't need it outside the basic block.With new approach it will be required also in error path.
True.
Quoted 34 lines
Quoted 9 lines
Quoted 9 lines
mutex_lock(&led_cdev_ind->led_access); led_sysfs_disable(led_cdev_ind); led_trigger_remove(led_cdev_ind);Quoted 5 lines
Quoted 1 line
mutex_unlock(&led_cdev_ind->led_access);Please don't acquire the indicator mutex while holding the flash mutex. I don't think there's a need to do so, thus creating a dependency between the two.Just remember to check for
v4l2_fh_is_singular()in both cases.I thought that the code would be simpler this way. Nevertheless I produced a new version by following your advise.
Quoted 9 lines
Quoted 6 lines
} ret = __sync_device_with_v4l2_controls(v4l2_flash);If ret is < 0 here, you end up disabling the sysfs interface while
open()fails (andv4l2_flash_close()will not be run). Shouldn't you handle that?Good point.
Please find the new version of v4l2_flash{open|close} functions below:
static int
v4l2_flash_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)Quoted 11 lines
{ struct v4l2_flash *v4l2_flash = v4l2_subdev_to_v4l2_flash(sd); struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev; struct led_classdev *led_cdev = &fled_cdev->led_cdev; struct led_classdev_flash *iled_cdev = v4l2_flash->iled_cdev; struct led_classdev *led_cdev_ind = NULL; int ret = 0; mutex_lock(&led_cdev->led_access); if (!v4l2_fh_is_singular(&fh->vfh)) {Hmm. I just realised that this might be a bit broken ---
v4l2_fh_is_singular()should return the same value independently of where in subdev'sopen()handler it is called.
Quoted 8 lines
But adding file handles to the list and checking how many there are of them is not properly serialised, i.e. another process could change the list in between. I'll try to submit a patch for that. No need to wait for that though.
So please ignore my earlier request to check for
v4l2_fh_is_singular()for multiple times, it won't help. Once is enough, albeit more than that won't hurt.
Let's agree on the new shape of the functions then:
tatic int v4l2_flash_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
{
struct v4l2_flash *v4l2_flash = v4l2_subdev_to_v4l2_flash(sd);
struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev;
struct led_classdev *led_cdev = &fled_cdev->led_cdev;
struct led_classdev_flash *iled_cdev = v4l2_flash->iled_cdev;
struct led_classdev *led_cdev_ind = NULL;
int ret = 0;
if (!v4l2_fh_is_singular(&fh->vfh))
return 0;
mutex_lock(&led_cdev->led_access);
led_sysfs_disable(led_cdev);
led_trigger_remove(led_cdev);
mutex_unlock(&led_cdev->led_access);
if (iled_cdev) {
led_cdev_ind = &iled_cdev->led_cdev;
mutex_lock(&led_cdev_ind->led_access);
led_sysfs_disable(led_cdev_ind);
led_trigger_remove(led_cdev_ind);
mutex_unlock(&led_cdev_ind->led_access);
}
ret = __sync_device_with_v4l2_controls(v4l2_flash);
if (ret < 0)
goto out_sync_device;
return 0;
out_sync_device:
mutex_lock(&led_cdev->led_access);
led_sysfs_enable(led_cdev);
mutex_unlock(&led_cdev->led_access);
if (led_cdev_ind) {
mutex_lock(&led_cdev_ind->led_access);
led_sysfs_enable(led_cdev_ind);
mutex_unlock(&led_cdev_ind->led_access);
}
return ret;
}static int v4l2_flash_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
{
struct v4l2_flash *v4l2_flash = v4l2_subdev_to_v4l2_flash(sd);
struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev;
struct led_classdev *led_cdev = &fled_cdev->led_cdev;
struct led_classdev_flash *iled_cdev = v4l2_flash->iled_cdev;
int ret = 0;
if (!v4l2_fh_is_singular(&fh->vfh))
return 0;
mutex_lock(&led_cdev->led_access);
if (v4l2_flash->ctrls[STROBE_SOURCE])
ret = v4l2_ctrl_s_ctrl(v4l2_flash->ctrls[STROBE_SOURCE],
V4L2_FLASH_STROBE_SOURCE_SOFTWARE);
led_sysfs_enable(led_cdev);
mutex_unlock(&led_cdev->led_access);
if (iled_cdev) {
struct led_classdev *led_cdev_ind = &iled_cdev->led_cdev;
mutex_lock(&led_cdev_ind->led_access);
led_sysfs_enable(led_cdev_ind);
mutex_unlock(&led_cdev_ind->led_access);
}
return ret;
}Signature · 2 lines
Best Regards, Jacek Anaszewski
Re: [PATCH v9 2/8] media: Add registration helpers for V4L2 flash sub-devices
Hi Jacek,
Quoted 145 lines · Jacek Anaszewski
Hi Sakari,
Quoted 142 lines · Sakari Ailus
Hi Jacek,
Quoted 47 lines · Jacek Anaszewski
Hi Sakari,
Quoted 44 lines · Sakari Ailus
Hi, Jacek!
Quoted 17 lines · Jacek Anaszewski
Hi Sakari,
Quoted 14 lines · Sakari Ailus
Hi Jacek,
Quoted 10 lines · Jacek Anaszewski
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 <[email protected]>Acked-by Kyungmin Park <[email protected]>Cc Sakari Ailus <[email protected]>Cc Hans Verkuil <[email protected]>Quoted 7 lines
Quoted 4 lines
Thanks for adding indicator support!
Acked-by Sakari Ailus <[email protected]>I missed one thing - sysfs interface of the indicator LED class also has to be disabled/enabled of v4l2_flash_open/close.
Good catch.
Quoted 14 lines
I am planning to reimplement the functions as follows, please let me know if you see any issues here:
static int
v4l2_flash_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh){ struct v4l2_flash *v4l2_flash = v4l2_subdev_to_v4l2_flash(sd); struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev; struct led_classdev *led_cdev = &fled_cdev->led_cdev; struct led_classdev_flash *iled_cdev = v4l2_flash->iled_cdev;Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
struct led_classdev *led_cdev_ind; int ret = 0;I think you could spare some newlines above (and below as well).
There must have been some issue on thunderbird side, originally there were no newlines above.
Ok. I've used Seamonkey, I believe it uses the same editor. Some bugs were unintroduced a few years ago, and since that I've mostly used a different editor (and MUA) when replying to patches.
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
mutex_lock(&led_cdev->led_access); if (!v4l2_fh_is_singular(&fh->vfh)) goto unlock; led_sysfs_disable(led_cdev); led_trigger_remove(led_cdev);Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
if (iled_cdev) { led_cdev_ind = &iled_cdev->led_cdev;You can also declare
led_cdev_indhere as you don't need it outside the basic block.With new approach it will be required also in error path.
True.
Quoted 34 lines
Quoted 9 lines
Quoted 9 lines
mutex_lock(&led_cdev_ind->led_access); led_sysfs_disable(led_cdev_ind); led_trigger_remove(led_cdev_ind);Quoted 5 lines
Quoted 1 line
mutex_unlock(&led_cdev_ind->led_access);Please don't acquire the indicator mutex while holding the flash mutex. I don't think there's a need to do so, thus creating a dependency between the two.Just remember to check for
v4l2_fh_is_singular()in both cases.I thought that the code would be simpler this way. Nevertheless I produced a new version by following your advise.
Quoted 9 lines
Quoted 6 lines
} ret = __sync_device_with_v4l2_controls(v4l2_flash);If ret is < 0 here, you end up disabling the sysfs interface while
open()fails (andv4l2_flash_close()will not be run). Shouldn't you handle that?Good point.
Please find the new version of v4l2_flash{open|close} functions below:
static int
v4l2_flash_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)Quoted 11 lines
{ struct v4l2_flash *v4l2_flash = v4l2_subdev_to_v4l2_flash(sd); struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev; struct led_classdev *led_cdev = &fled_cdev->led_cdev; struct led_classdev_flash *iled_cdev = v4l2_flash->iled_cdev; struct led_classdev *led_cdev_ind = NULL; int ret = 0; mutex_lock(&led_cdev->led_access); if (!v4l2_fh_is_singular(&fh->vfh)) {Hmm. I just realised that this might be a bit broken ---
v4l2_fh_is_singular()should return the same value independently of where in subdev'sopen()handler it is called.But adding file handles to the list and checking how many there are of them is not properly serialised, i.e. another process could change the list in between. I'll try to submit a patch for that. No need to wait for that though.
Quoted 5 lines
Quoted 3 lines
So please ignore my earlier request to check for
v4l2_fh_is_singular()for multiple times, it won't help. Once is enough, albeit more than that won't hurt.Let's agree on the new shape of the functions then:
Looks good to me. Could you resend once more, please?
Quoted 82 lines
tatic int
v4l2_flash_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh){ struct v4l2_flash *v4l2_flash = v4l2_subdev_to_v4l2_flash(sd); struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev; struct led_classdev *led_cdev = &fled_cdev->led_cdev; struct led_classdev_flash *iled_cdev = v4l2_flash->iled_cdev; struct led_classdev *led_cdev_ind = NULL; int ret = 0; if (!v4l2_fh_is_singular(&fh->vfh)) return 0; mutex_lock(&led_cdev->led_access); led_sysfs_disable(led_cdev); led_trigger_remove(led_cdev); mutex_unlock(&led_cdev->led_access); if (iled_cdev) { led_cdev_ind = &iled_cdev->led_cdev; mutex_lock(&led_cdev_ind->led_access); led_sysfs_disable(led_cdev_ind); led_trigger_remove(led_cdev_ind); mutex_unlock(&led_cdev_ind->led_access); } ret = __sync_device_with_v4l2_controls(v4l2_flash); if (ret < 0) goto out_sync_device; return 0; out_sync_device: mutex_lock(&led_cdev->led_access); led_sysfs_enable(led_cdev); mutex_unlock(&led_cdev->led_access); if (led_cdev_ind) { mutex_lock(&led_cdev_ind->led_access); led_sysfs_enable(led_cdev_ind); mutex_unlock(&led_cdev_ind->led_access); } return ret; }static int
v4l2_flash_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh){ struct v4l2_flash *v4l2_flash = v4l2_subdev_to_v4l2_flash(sd); struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev; struct led_classdev *led_cdev = &fled_cdev->led_cdev; struct led_classdev_flash *iled_cdev = v4l2_flash->iled_cdev; int ret = 0; if (!v4l2_fh_is_singular(&fh->vfh)) return 0; mutex_lock(&led_cdev->led_access); if (v4l2_flash->ctrls[STROBE_SOURCE]) ret = v4l2_ctrl_s_ctrl(v4l2_flash->ctrls[STROBE_SOURCE], V4L2_FLASH_STROBE_SOURCE_SOFTWARE); led_sysfs_enable(led_cdev); mutex_unlock(&led_cdev->led_access); if (iled_cdev) { struct led_classdev *led_cdev_ind = &iled_cdev->led_cdev; mutex_lock(&led_cdev_ind->led_access); led_sysfs_enable(led_cdev_ind); mutex_unlock(&led_cdev_ind->led_access); } return ret; }
Signature · 4 lines
Kind regards, Sakari Ailus e-mail: [email protected] XMPP: [email protected]
Re: [PATCH v9 2/8] media: Add registration helpers for V4L2 flash sub-devices
Quoted 148 lines · Sakari Ailus
Hi Jacek,
Quoted 145 lines · Jacek Anaszewski
Hi Sakari,
Quoted 142 lines · Sakari Ailus
Hi Jacek,
Quoted 47 lines · Jacek Anaszewski
Hi Sakari,
Quoted 44 lines · Sakari Ailus
Hi, Jacek!
Quoted 17 lines · Jacek Anaszewski
Hi Sakari,
Quoted 14 lines · Sakari Ailus
Hi Jacek,
Quoted 10 lines · Jacek Anaszewski
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 <[email protected]>Acked-by Kyungmin Park <[email protected]>Cc Sakari Ailus <[email protected]>Cc Hans Verkuil <[email protected]>Quoted 7 lines
Quoted 4 lines
Thanks for adding indicator support!
Acked-by Sakari Ailus <[email protected]>I missed one thing - sysfs interface of the indicator LED class also has to be disabled/enabled of v4l2_flash_open/close.
Good catch.
Quoted 14 lines
I am planning to reimplement the functions as follows, please let me know if you see any issues here:
static int
v4l2_flash_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh){ struct v4l2_flash *v4l2_flash = v4l2_subdev_to_v4l2_flash(sd); struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev; struct led_classdev *led_cdev = &fled_cdev->led_cdev; struct led_classdev_flash *iled_cdev = v4l2_flash->iled_cdev;Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
struct led_classdev *led_cdev_ind; int ret = 0;I think you could spare some newlines above (and below as well).
There must have been some issue on thunderbird side, originally there were no newlines above.
Ok. I've used Seamonkey, I believe it uses the same editor. Some bugs were unintroduced a few years ago, and since that I've mostly used a different editor (and MUA) when replying to patches.
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
mutex_lock(&led_cdev->led_access); if (!v4l2_fh_is_singular(&fh->vfh)) goto unlock; led_sysfs_disable(led_cdev); led_trigger_remove(led_cdev);Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
if (iled_cdev) { led_cdev_ind = &iled_cdev->led_cdev;You can also declare
led_cdev_indhere as you don't need it outside the basic block.With new approach it will be required also in error path.
True.
Quoted 34 lines
Quoted 9 lines
Quoted 9 lines
mutex_lock(&led_cdev_ind->led_access); led_sysfs_disable(led_cdev_ind); led_trigger_remove(led_cdev_ind);Quoted 5 lines
Quoted 1 line
mutex_unlock(&led_cdev_ind->led_access);Please don't acquire the indicator mutex while holding the flash mutex. I don't think there's a need to do so, thus creating a dependency between the two.Just remember to check for
v4l2_fh_is_singular()in both cases.I thought that the code would be simpler this way. Nevertheless I produced a new version by following your advise.
Quoted 9 lines
Quoted 6 lines
} ret = __sync_device_with_v4l2_controls(v4l2_flash);If ret is < 0 here, you end up disabling the sysfs interface while
open()fails (andv4l2_flash_close()will not be run). Shouldn't you handle that?Good point.
Please find the new version of v4l2_flash{open|close} functions below:
static int
v4l2_flash_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)Quoted 11 lines
{ struct v4l2_flash *v4l2_flash = v4l2_subdev_to_v4l2_flash(sd); struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev; struct led_classdev *led_cdev = &fled_cdev->led_cdev; struct led_classdev_flash *iled_cdev = v4l2_flash->iled_cdev; struct led_classdev *led_cdev_ind = NULL; int ret = 0; mutex_lock(&led_cdev->led_access); if (!v4l2_fh_is_singular(&fh->vfh)) {Hmm. I just realised that this might be a bit broken ---
v4l2_fh_is_singular()should return the same value independently of where in subdev'sopen()handler it is called.But adding file handles to the list and checking how many there are of them is not properly serialised, i.e. another process could change the list in between. I'll try to submit a patch for that. No need to wait for that though.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
So please ignore my earlier request to check for
v4l2_fh_is_singular()for multiple times, it won't help. Once is enough, albeit more than that won't hurt.Let's agree on the new shape of the functions then:
Looks good to me. Could you resend once more, please?
Of course, there will be also minor modifications in the other patches of the patch set.
Quoted 83 lines
Quoted 82 lines
tatic int
v4l2_flash_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh){ struct v4l2_flash *v4l2_flash = v4l2_subdev_to_v4l2_flash(sd); struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev; struct led_classdev *led_cdev = &fled_cdev->led_cdev; struct led_classdev_flash *iled_cdev = v4l2_flash->iled_cdev; struct led_classdev *led_cdev_ind = NULL; int ret = 0; if (!v4l2_fh_is_singular(&fh->vfh)) return 0; mutex_lock(&led_cdev->led_access); led_sysfs_disable(led_cdev); led_trigger_remove(led_cdev); mutex_unlock(&led_cdev->led_access); if (iled_cdev) { led_cdev_ind = &iled_cdev->led_cdev; mutex_lock(&led_cdev_ind->led_access); led_sysfs_disable(led_cdev_ind); led_trigger_remove(led_cdev_ind); mutex_unlock(&led_cdev_ind->led_access); } ret = __sync_device_with_v4l2_controls(v4l2_flash); if (ret < 0) goto out_sync_device; return 0; out_sync_device: mutex_lock(&led_cdev->led_access); led_sysfs_enable(led_cdev); mutex_unlock(&led_cdev->led_access); if (led_cdev_ind) { mutex_lock(&led_cdev_ind->led_access); led_sysfs_enable(led_cdev_ind); mutex_unlock(&led_cdev_ind->led_access); } return ret; }static int
v4l2_flash_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh){ struct v4l2_flash *v4l2_flash = v4l2_subdev_to_v4l2_flash(sd); struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev; struct led_classdev *led_cdev = &fled_cdev->led_cdev; struct led_classdev_flash *iled_cdev = v4l2_flash->iled_cdev; int ret = 0; if (!v4l2_fh_is_singular(&fh->vfh)) return 0; mutex_lock(&led_cdev->led_access); if (v4l2_flash->ctrls[STROBE_SOURCE]) ret = v4l2_ctrl_s_ctrl(v4l2_flash->ctrls[STROBE_SOURCE], V4L2_FLASH_STROBE_SOURCE_SOFTWARE); led_sysfs_enable(led_cdev); mutex_unlock(&led_cdev->led_access); if (iled_cdev) { struct led_classdev *led_cdev_ind = &iled_cdev->led_cdev; mutex_lock(&led_cdev_ind->led_access); led_sysfs_enable(led_cdev_ind); mutex_unlock(&led_cdev_ind->led_access); } return ret; }
Signature · 2 lines
Best Regards, Jacek Anaszewski
A message that is not in the archive (sent off-list or not yet received): 1432566843-6391-3-git-send-email-j.anaszewski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org
Re: [PATCH v9 2/8] media: Add registration helpers for V4L2 flash sub-devices
Hi Jacek,
Quoted 648 lines · Jacek Anaszewski
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 <[email protected]>Acked-by Kyungmin Park <[email protected]>Cc Sakari Ailus <[email protected]>Cc Hans Verkuil <[email protected]>--- drivers/media/v4l2-core/Kconfig | 11 + drivers/media/v4l2-core/Makefile | 2 + drivers/media/v4l2-core/v4l2-flash-led-class.c | 671 ++++++++++++++++++++++++ include/media/v4l2-flash-led-class.h | 148 ++++++ 4 files changed, 832 insertions(+) create mode 100644 drivers/media/v4l2-core/v4l2-flash-led-class.c create mode 100644 include/media/v4l2-flash-led-class.hdrivers/media/v4l2-core/Kconfig +11
-0@@ -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 "V4L2 flash API for LED flash class devices" + depends on VIDEO_V4L2_SUBDEV_API + depends on LEDS_CLASS_FLASH + ---help--- + Say Y here to enable V4L2 flash API support for LED flash + class drivers. + + When in doubt, say N. + # Used by drivers that need Videobuf modules config VIDEOBUF_GEN tristatedrivers/media/v4l2-core/Makefile +2
-0@@ -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-led-class.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.odrivers/media/v4l2-core/v4l2-flash-led-class.c new file +588
-0@@ -0,0 +1,671 @@ +/* +* V4L2 flash LED sub-device registration helpers. +* +* Copyright (C) 2015 Samsung Electronics Co., Ltd +* Author: Jacek Anaszewski <[email protected]> +* +* 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/of.h> +#include <linux/slab.h> +#include <linux/types.h> +#include <media/v4l2-flash-led-class.h> + +#define has_flash_op (v4l2_flash, op) \ + (v4l2_flash && v4l2_flash->ops->op) + +#define call_flash_op (v4l2_flash, op, arg) \ + (has_flash_op(v4l2_flash, op) ? \ + v4l2_flash->ops->op(v4l2_flash, arg) : \ + -EINVAL) + +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 + brightness =__intensity_to_led_brightness (ctrl, ctrl->val); +/* +* In case a LED Flash class driver provides ops for custom +* brightness <-> intensity conversion, it also must have defined +* related v4l2 control step == 1. In such a case a backward conversion +* from led brightness to v4l2 intensity is required to find out the +* the aligned intensity value. +*/ +if (has_flash_op (v4l2_flash, led_brightness_to_intensity)) + ctrl->val =call_flash_op (v4l2_flash, + led_brightness_to_intensity, + brightness); + +if (ctrl == ctrls[TORCH_INTENSITY ]) { +if (ctrls[LED_MODE ]->val !=V4L2_FLASH_LED_MODE_TORCH ) +return ; + +led_set_brightness (&v4l2_flash->fled_cdev->led_cdev, + brightness); + }else { +led_set_brightness (&v4l2_flash->iled_cdev->led_cdev, + brightness); + } +} + +static int v4l2_flash_update_led_brightness (struct v4l2_flash *v4l2_flash, +struct v4l2_ctrl *ctrl) +{ +struct v4l2_ctrl **ctrls = v4l2_flash->ctrls; +struct led_classdev *led_cdev; +int ret; + +if (ctrl == ctrls[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 value +* has changed to 0. +*/ +if (ctrls[LED_MODE ]->val !=V4L2_FLASH_LED_MODE_TORCH ) +return 0 ; + led_cdev = &v4l2_flash->fled_cdev->led_cdev; + }else { + led_cdev = &v4l2_flash->iled_cdev->led_cdev; + } + + ret =led_update_brightness (led_cdev); +if (ret <0 ) +return ret; + +if (has_flash_op (v4l2_flash, led_brightness_to_intensity)) + ctrl->val =call_flash_op (v4l2_flash, + led_brightness_to_intensity, + led_cdev->brightness); +else + ctrl->val =__led_brightness_to_intensity (ctrl, + led_cdev->brightness); + +return 0 ; +} + +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 *fled_cdev = v4l2_flash->fled_cdev; +bool is_strobing; +int ret; + +switch (c->id) { +case V4L2_CID_FLASH_TORCH_INTENSITY : +case V4L2_CID_FLASH_INDICATOR_INTENSITY : +return v4l2_flash_update_led_brightness (v4l2_flash, c); +case V4L2_CID_FLASH_INTENSITY : + ret =led_update_flash_brightness (fled_cdev); +if (ret <0 ) +return ret; +/* +* No conversion is needed as LED Flash class also uses +* microamperes for flash intensity units. +*/ + c->val = fled_cdev->brightness.val; +return 0 ; +case V4L2_CID_FLASH_STROBE_STATUS : + ret =led_get_flash_strobe (fled_cdev, &is_strobing); +if (ret <0 ) +return ret; + c->val = is_strobing; +return 0 ; +case V4L2_CID_FLASH_FAULT : +/* LED faults map directly to V4L2 flash faults */ +return led_get_flash_fault (fled_cdev, &c->val); +default : +return -EINVAL ; + } +} + +static bool __software_strobe_mode_inactive (struct v4l2_ctrl **ctrls) +{ +return ((ctrls[LED_MODE ]->val !=V4L2_FLASH_LED_MODE_FLASH ) || + (ctrls[STROBE_SOURCE ] && (ctrls[STROBE_SOURCE ]->val != +V4L2_FLASH_STROBE_SOURCE_SOFTWARE ))); +} + +static int v4l2_flash_s_ctrl (struct v4l2_ctrl *c) +{ +struct v4l2_flash *v4l2_flash =v4l2_ctrl_to_v4l2_flash (c); +struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev; +struct led_classdev *led_cdev = &fled_cdev->led_cdev; +struct v4l2_ctrl **ctrls = v4l2_flash->ctrls; +bool external_strobe; +int ret =0 ; + +switch (c->id) { +case V4L2_CID_FLASH_LED_MODE : +switch (c->val) { +case V4L2_FLASH_LED_MODE_NONE : +led_set_brightness (led_cdev,LED_OFF ); +return led_set_flash_strobe (fled_cdev, false); +case V4L2_FLASH_LED_MODE_FLASH : +/* Turn the torch LED off */ +led_set_brightness (led_cdev,LED_OFF ); +if (ctrls[STROBE_SOURCE ]) { + external_strobe = (ctrls[STROBE_SOURCE ]->val == +V4L2_FLASH_STROBE_SOURCE_EXTERNAL ); + + ret =call_flash_op (v4l2_flash, + external_strobe_set, + external_strobe); + } +return ret; +case V4L2_FLASH_LED_MODE_TORCH : +if (ctrls[STROBE_SOURCE ]) { + ret =call_flash_op (v4l2_flash, + external_strobe_set, + false); +if (ret <0 ) +return ret; + } +/* Stop flash strobing */ + ret =led_set_flash_strobe (fled_cdev, false); +if (ret <0 ) +return ret; + +v4l2_flash_set_led_brightness (v4l2_flash, + ctrls[TORCH_INTENSITY ]); +return 0 ; + } +break ; +case V4L2_CID_FLASH_STROBE_SOURCE : + external_strobe = (c->val ==V4L2_FLASH_STROBE_SOURCE_EXTERNAL ); +/* +* For some hardware arrangements setting strobe source may +* affect torch mode. Therefore, if not in the flash mode, +* cache only this setting. It will be applied upon switching +* to flash mode. +*/ +if (ctrls[LED_MODE ]->val !=V4L2_FLASH_LED_MODE_FLASH ) +return 0 ; + +return call_flash_op (v4l2_flash, external_strobe_set, + external_strobe); +case V4L2_CID_FLASH_STROBE : +if (__software_strobe_mode_inactive (ctrls)) +return -EBUSY ; +return led_set_flash_strobe (fled_cdev, true); +case V4L2_CID_FLASH_STROBE_STOP : +if (__software_strobe_mode_inactive (ctrls)) +return -EBUSY ; +return led_set_flash_strobe (fled_cdev, false); +case V4L2_CID_FLASH_TIMEOUT : +/* +* No conversion is needed as LED Flash class also uses +* microseconds for flash timeout units. +*/ +return led_set_flash_timeout (fled_cdev, c->val); +case V4L2_CID_FLASH_INTENSITY : +/* +* No conversion is needed as LED Flash class also uses +* microamperes for flash intensity units. +*/ +return led_set_flash_brightness (fled_cdev, c->val); +case V4L2_CID_FLASH_TORCH_INTENSITY : +case V4L2_CID_FLASH_INDICATOR_INTENSITY : +v4l2_flash_set_led_brightness (v4l2_flash, c); +return 0 ; + } + +return -EINVAL ; +} + +static const struct v4l2_ctrl_ops v4l2_flash_ctrl_ops = { + .g_volatile_ctrl = v4l2_flash_g_volatile_ctrl, + .s_ctrl = v4l2_flash_s_ctrl, +}; + +static void __lfs_to_v4l2_ctrl_config (struct led_flash_setting *s, +struct v4l2_ctrl_config *c) +{ + c->min = s->min; + c->max = s->max; + c->step = s->step; + c->def = s->val; +} + +static void __fill_ctrl_init_data (struct v4l2_flash *v4l2_flash, +struct v4l2_flash_config *flash_cfg, +struct v4l2_flash_ctrl_data *ctrl_init_data) +{ +struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev; +const struct led_flash_ops *fled_cdev_ops = fled_cdev->ops; +struct led_classdev *led_cdev = &fled_cdev->led_cdev; +struct v4l2_ctrl_config *ctrl_cfg; +u32 mask; + +/* Init FLASH_FAULT ctrl data */ +if (flash_cfg->flash_faults) { + ctrl_init_data[FLASH_FAULT ].cid =V4L2_CID_FLASH_FAULT ; + ctrl_cfg = &ctrl_init_data[FLASH_FAULT ].config; + ctrl_cfg->id =V4L2_CID_FLASH_FAULT ; + ctrl_cfg->max = flash_cfg->flash_faults; + ctrl_cfg->flags =V4L2_CTRL_FLAG_VOLATILE | +V4L2_CTRL_FLAG_READ_ONLY ; + } + +/* Init FLASH_LED_MODE ctrl data */ + mask =1 <<V4L2_FLASH_LED_MODE_NONE | +1 <<V4L2_FLASH_LED_MODE_TORCH ; +if (led_cdev->flags &LED_DEV_CAP_FLASH ) + mask |=1 <<V4L2_FLASH_LED_MODE_FLASH ; + + ctrl_init_data[LED_MODE ].cid =V4L2_CID_FLASH_LED_MODE ; + ctrl_cfg = &ctrl_init_data[LED_MODE ].config; + ctrl_cfg->id =V4L2_CID_FLASH_LED_MODE ; + ctrl_cfg->max =V4L2_FLASH_LED_MODE_TORCH ; + ctrl_cfg->menu_skip_mask = ~mask; + ctrl_cfg->def =V4L2_FLASH_LED_MODE_NONE ; + ctrl_cfg->flags =0 ; + +/* Init TORCH_INTENSITY ctrl data */ + ctrl_init_data[TORCH_INTENSITY ].cid =V4L2_CID_FLASH_TORCH_INTENSITY ; + ctrl_cfg = &ctrl_init_data[TORCH_INTENSITY ].config; +__lfs_to_v4l2_ctrl_config (&flash_cfg->torch_intensity, ctrl_cfg); + ctrl_cfg->id =V4L2_CID_FLASH_TORCH_INTENSITY ; + ctrl_cfg->flags =V4L2_CTRL_FLAG_VOLATILE | +V4L2_CTRL_FLAG_EXECUTE_ON_WRITE ; + +/* Init INDICATOR_INTENSITY ctrl data */ +if (v4l2_flash->iled_cdev) { + ctrl_init_data[INDICATOR_INTENSITY ].cid = +V4L2_CID_FLASH_INDICATOR_INTENSITY ; + ctrl_cfg = &ctrl_init_data[INDICATOR_INTENSITY ].config; +__lfs_to_v4l2_ctrl_config (&flash_cfg->indicator_intensity, + ctrl_cfg); + ctrl_cfg->id =V4L2_CID_FLASH_INDICATOR_INTENSITY ; + ctrl_cfg->min =0 ; + ctrl_cfg->flags =V4L2_CTRL_FLAG_VOLATILE | +V4L2_CTRL_FLAG_EXECUTE_ON_WRITE ; + } + +if (!(led_cdev->flags &LED_DEV_CAP_FLASH )) +return ; + +/* Init FLASH_STROBE ctrl data */ + ctrl_init_data[FLASH_STROBE ].cid =V4L2_CID_FLASH_STROBE ; + ctrl_cfg = &ctrl_init_data[FLASH_STROBE ].config; + ctrl_cfg->id =V4L2_CID_FLASH_STROBE ; + +/* Init STROBE_STOP ctrl data */ + ctrl_init_data[STROBE_STOP ].cid =V4L2_CID_FLASH_STROBE_STOP ; + ctrl_cfg = &ctrl_init_data[STROBE_STOP ].config; + ctrl_cfg->id =V4L2_CID_FLASH_STROBE_STOP ; + +/* Init FLASH_STROBE_SOURCE ctrl data */ +if (flash_cfg->has_external_strobe) { + mask = (1 <<V4L2_FLASH_STROBE_SOURCE_SOFTWARE ) | + (1 <<V4L2_FLASH_STROBE_SOURCE_EXTERNAL ); + ctrl_init_data[STROBE_SOURCE ].cid = +V4L2_CID_FLASH_STROBE_SOURCE ; + ctrl_cfg = &ctrl_init_data[STROBE_SOURCE ].config; + ctrl_cfg->id =V4L2_CID_FLASH_STROBE_SOURCE ; + ctrl_cfg->max =V4L2_FLASH_STROBE_SOURCE_EXTERNAL ; + ctrl_cfg->menu_skip_mask = ~mask; + ctrl_cfg->def =V4L2_FLASH_STROBE_SOURCE_SOFTWARE ; + } + +/* Init STROBE_STATUS ctrl data */ +if (fled_cdev_ops->strobe_get) { + ctrl_init_data[STROBE_STATUS ].cid = +V4L2_CID_FLASH_STROBE_STATUS ; + ctrl_cfg = &ctrl_init_data[STROBE_STATUS ].config; + ctrl_cfg->id =V4L2_CID_FLASH_STROBE_STATUS ; + ctrl_cfg->flags =V4L2_CTRL_FLAG_VOLATILE | +V4L2_CTRL_FLAG_READ_ONLY ; + } + +/* Init FLASH_TIMEOUT ctrl data */ +if (fled_cdev_ops->timeout_set) { + ctrl_init_data[FLASH_TIMEOUT ].cid =V4L2_CID_FLASH_TIMEOUT ; + ctrl_cfg = &ctrl_init_data[FLASH_TIMEOUT ].config; +__lfs_to_v4l2_ctrl_config (&fled_cdev->timeout, ctrl_cfg); + ctrl_cfg->id =V4L2_CID_FLASH_TIMEOUT ; + } + +/* Init FLASH_INTENSITY ctrl data */ +if (fled_cdev_ops->flash_brightness_set) { + ctrl_init_data[FLASH_INTENSITY ].cid =V4L2_CID_FLASH_INTENSITY ; + ctrl_cfg = &ctrl_init_data[FLASH_INTENSITY ].config; +__lfs_to_v4l2_ctrl_config (&fled_cdev->brightness, ctrl_cfg); + ctrl_cfg->id =V4L2_CID_FLASH_INTENSITY ; + ctrl_cfg->flags =V4L2_CTRL_FLAG_VOLATILE | +V4L2_CTRL_FLAG_EXECUTE_ON_WRITE ; + } +} + +static int v4l2_flash_init_controls (struct v4l2_flash *v4l2_flash, +struct v4l2_flash_config *flash_cfg) + +{ +struct v4l2_flash_ctrl_data *ctrl_init_data; +struct v4l2_ctrl *ctrl; +struct v4l2_ctrl_config *ctrl_cfg; +int i, ret, num_ctrls =0 ; + + v4l2_flash->ctrls =devm_kzalloc (v4l2_flash->sd.dev, +sizeof (*v4l2_flash->ctrls) * + (STROBE_SOURCE +1 ),GFP_KERNEL ); +if (!v4l2_flash->ctrls) +return -ENOMEM ; + +/* allocate memory dynamically so as not to exceed stack frame size */ + ctrl_init_data =kcalloc (NUM_FLASH_CTRLS ,sizeof (*ctrl_init_data), +GFP_KERNEL ); +if (!ctrl_init_data) +return -ENOMEM ; + +__fill_ctrl_init_data (v4l2_flash, flash_cfg, ctrl_init_data); + +for (i =0 ; i <NUM_FLASH_CTRLS ; ++i) +if (ctrl_init_data[i].cid) + ++num_ctrls; + +v4l2_ctrl_handler_init (&v4l2_flash->hdl, num_ctrls); + +for (i =0 ; i <NUM_FLASH_CTRLS ; ++i) { + ctrl_cfg = &ctrl_init_data[i].config; +if (!ctrl_init_data[i].cid) +continue ; + +if (ctrl_cfg->id ==V4L2_CID_FLASH_LED_MODE || + ctrl_cfg->id ==V4L2_CID_FLASH_STROBE_SOURCE ) + ctrl =v4l2_ctrl_new_std_menu (&v4l2_flash->hdl, + &v4l2_flash_ctrl_ops, + ctrl_cfg->id, + ctrl_cfg->max, + ctrl_cfg->menu_skip_mask, + ctrl_cfg->def); +else + ctrl =v4l2_ctrl_new_std (&v4l2_flash->hdl, + &v4l2_flash_ctrl_ops, + ctrl_cfg->id, + ctrl_cfg->min, + ctrl_cfg->max, + ctrl_cfg->step, + ctrl_cfg->def); + +if (ctrl) + ctrl->flags |= ctrl_cfg->flags; + +if (i <=STROBE_SOURCE ) + v4l2_flash->ctrls[i] = ctrl; + } + +kfree (ctrl_init_data); + +if (v4l2_flash->hdl.error) { + ret = v4l2_flash->hdl.error; + goto error_free_handler; + } + +v4l2_ctrl_handler_setup (&v4l2_flash->hdl); + + v4l2_flash->sd.ctrl_handler = &v4l2_flash->hdl; + +return 0 ; + +error_free_handler: +v4l2_ctrl_handler_free (&v4l2_flash->hdl); +return ret; +} + +static int __sync_device_with_v4l2_controls (struct v4l2_flash *v4l2_flash) +{ +struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev; +struct v4l2_ctrl **ctrls = v4l2_flash->ctrls; +int ret =0 ; + +v4l2_flash_set_led_brightness (v4l2_flash, ctrls[TORCH_INTENSITY ]); + +if (ctrls[INDICATOR_INTENSITY ]) +v4l2_flash_set_led_brightness (v4l2_flash, + ctrls[INDICATOR_INTENSITY ]); + +if (ctrls[FLASH_TIMEOUT ]) { + ret =led_set_flash_timeout (fled_cdev, + ctrls[FLASH_TIMEOUT ]->val); +if (ret <0 ) +return ret; + } + +if (ctrls[FLASH_INTENSITY ]) { + ret =led_set_flash_brightness (fled_cdev, + ctrls[FLASH_INTENSITY ]->val); +if (ret <0 ) +return ret; + } + +/* +* For some hardware arrangements setting strobe source may affect +* torch mode. Synchronize strobe source setting only if not in torch +* mode. For torch mode case it will get synchronized upon switching +* to flash mode. +*/ +if (ctrls[STROBE_SOURCE ] && + ctrls[LED_MODE ]->val !=V4L2_FLASH_LED_MODE_TORCH ) + ret =call_flash_op (v4l2_flash, external_strobe_set, + ctrls[STROBE_SOURCE ]->val); + +return ret; +} + +/* +* V4L2 subdev internal operations +*/ + +static int v4l2_flash_open (struct v4l2_subdev *sd,struct v4l2_subdev_fh *fh) +{ +struct v4l2_flash *v4l2_flash =v4l2_subdev_to_v4l2_flash (sd); +struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev; +struct led_classdev *led_cdev = &fled_cdev->led_cdev; +int ret =0 ; + +mutex_lock (&led_cdev->led_access); + +if (!v4l2_fh_is_singular (&fh->vfh)) + goto unlock; + +led_sysfs_disable (led_cdev); +led_trigger_remove (led_cdev); + + ret =__sync_device_with_v4l2_controls (v4l2_flash); + +unlock: +mutex_unlock (&led_cdev->led_access); +return ret; +} + +static int v4l2_flash_close (struct v4l2_subdev *sd,struct v4l2_subdev_fh *fh) +{ +struct v4l2_flash *v4l2_flash =v4l2_subdev_to_v4l2_flash (sd); +struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev; +struct led_classdev *led_cdev = &fled_cdev->led_cdev; +int ret =0 ; + +mutex_lock (&led_cdev->led_access); + +if (v4l2_fh_is_singular (&fh->vfh)) { +if (v4l2_flash->ctrls[STROBE_SOURCE ]) + ret =v4l2_ctrl_s_ctrl (v4l2_flash->ctrls[STROBE_SOURCE ], +V4L2_FLASH_STROBE_SOURCE_SOFTWARE ); +led_sysfs_enable (led_cdev); + } + +mutex_unlock (&led_cdev->led_access); + +return ret; +} + +static const struct v4l2_subdev_internal_ops v4l2_flash_subdev_internal_ops = { + .open = v4l2_flash_open, + .close = v4l2_flash_close, +}; + +static const struct v4l2_subdev_core_ops v4l2_flash_core_ops = { + .queryctrl = v4l2_subdev_queryctrl, + .querymenu = v4l2_subdev_querymenu, +}; + +static const struct v4l2_subdev_ops v4l2_flash_subdev_ops = { + .core = &v4l2_flash_core_ops, +}; + +struct v4l2_flash *v4l2_flash_init( + struct device *dev, struct device_node *of_node, + struct led_classdev_flash *fled_cdev, + struct led_classdev_flash *iled_cdev, + const struct v4l2_flash_ops *ops,
drivers/media/v4l2-core/v4l2-flash-led-class.c line 597
Quoted 10 lines
drivers/media/v4l2-core/v4l2-flash-led-class.c new file +9
-0+ struct v4l2_flash_config *config) +{ +struct v4l2_flash *v4l2_flash; +struct led_classdev *led_cdev = &fled_cdev->led_cdev; +struct v4l2_subdev *sd; +int ret; + +if (!fled_cdev || !ops || !config) +return ERR_PTR (-EINVAL );
Could you please if it is correct? You're checking fled_cdev but four lines above you're using fled_cdev and taking led_cdev pointer from there. Maybe it's better to move calculation of led_cdev down and place after if-check?
Best regards,
Alexey Klimov
Signature · 5 lines
Best regards, Klimov Alexey -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v9 2/8] media: Add registration helpers for V4L2 flash sub-devices
Hi Alexey,
Quoted 22 lines · Alexey Klimov
Hi Jacek,
Quoted 18 lines · Jacek Anaszewski
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 <[email protected]>Acked-by Kyungmin Park <[email protected]>Cc Sakari Ailus <[email protected]>Cc Hans Verkuil <[email protected]>--- drivers/media/v4l2-core/Kconfig | 11 + drivers/media/v4l2-core/Makefile | 2 + drivers/media/v4l2-core/v4l2-flash-led-class.c | 671 ++++++++++++++++++++++++ include/media/v4l2-flash-led-class.h | 148 ++++++ 4 files changed, 832 insertions(+)create mode 100644
drivers/media/v4l2-core/v4l2-flash-led-class.ccreate mode 100644include/media/v4l2-flash-led-class.h
[...]
Quoted 16 lines
Quoted 5 lines
drivers/media/v4l2-core/v4l2-flash-led-class.c new file +5
-0+struct v4l2_flash *v4l2_flash_init( + struct device *dev, struct device_node *of_node, + struct led_classdev_flash *fled_cdev, + struct led_classdev_flash *iled_cdev, + const struct v4l2_flash_ops *ops,drivers/media/v4l2-core/v4l2-flash-led-class.c line 597
Quoted 10 lines
drivers/media/v4l2-core/v4l2-flash-led-class.c new file +9
-0+ struct v4l2_flash_config *config) +{ +struct v4l2_flash *v4l2_flash; +struct led_classdev *led_cdev = &fled_cdev->led_cdev; +struct v4l2_subdev *sd; +int ret; + +if (!fled_cdev || !ops || !config) +return ERR_PTR (-EINVAL );
Quoted 4 lines
Could you please if it is correct? You're checking
fled_cdevbut four lines above you're usingfled_cdevand takingled_cdevpointer from there. Maybe it's better to move calculation ofled_cdevdown and place after if-check?
Thanks for spotting this. I'll submit fixed version soon.
Signature · 2 lines
Best Regards, Jacek Anaszewski
PATCH v9 3/8 leds: max77693: add support for V4L2 Flash sub-device
In reply to Jacek AnaszewskiAdd support for V4L2 Flash sub-device to the max77693 LED Flash class driver. The support allows for V4L2 Flash sub-device to take the control of the LED Flash class device.
--- drivers/leds/leds-max77693.c | 129 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 123 insertions(+), 6 deletions(-)
drivers/leds/leds-max77693.c +123 -6
@@ -20,6 +20,7 @@#include <linux/regmap.h> #include <linux/slab.h> #include <linux/workqueue.h> +#include <media/v4l2-flash-led-class.h> #define MODE_OFF 0#define MODE_FLASH (a) (1 << (a))
@@ -62,6 +63,8 @@ struct max77693_sub_led {struct led_classdev_flash fled_cdev;/* assures led-triggers compatibility */ struct work_struct work_brightness_set; +/* V4L2 Flash device */ +struct v4l2_flash *v4l2_flash;/* brightness cache */ unsigned int torch_brightness;
@@ -627,7 +630,8 @@ static int max77693_led_flash_timeout_set( }static int max77693_led_parse_dt (struct max77693_led_device *led, -struct max77693_led_config_data *cfg) +struct max77693_led_config_data *cfg, +struct device_node **sub_nodes) {struct device *dev = &led->pdev->dev;struct max77693_sub_led *sub_leds = led->sub_leds;
@@ -674,6 +678,13 @@ static int max77693_led_parse_dt(struct max77693_led_device *led,return -EINVAL ; } +if (sub_nodes[fled_id]) { +dev_err (dev, +"Conflicting \"led-sources\" DT properties\n" ); +return -EINVAL ; + } + + sub_nodes[fled_id] = child_node; sub_leds[fled_id].fled_id = fled_id; cfg->label[fled_id] =
@@ -786,11 +797,12 @@ static void max77693_led_validate_configuration(struct max77693_led_device *led, }static int max77693_led_get_configuration (struct max77693_led_device *led, -struct max77693_led_config_data *cfg) +struct max77693_led_config_data *cfg, +struct device_node **sub_nodes) {int ret; - ret =max77693_led_parse_dt (led, cfg); + ret =max77693_led_parse_dt (led, cfg, sub_nodes);if (ret <0 )return ret;
@@ -838,6 +850,71 @@ static void max77693_init_flash_settings(struct max77693_sub_led *sub_led, setting->val = setting->max; } +#if IS_ENABLED (CONFIG_V4L2_FLASH_LED_CLASS ) + +static int max77693_led_external_strobe_set ( +struct v4l2_flash *v4l2_flash, +bool enable) +{ +struct max77693_sub_led *sub_led = +flcdev_to_sub_led (v4l2_flash->fled_cdev); +struct max77693_led_device *led =sub_led_to_led (sub_led); +int fled_id = sub_led->fled_id; +int ret; + +mutex_lock (&led->lock); + +if (enable) + ret =max77693_add_mode (led,MODE_FLASH_EXTERNAL (fled_id)); +else + ret =max77693_clear_mode (led,MODE_FLASH_EXTERNAL (fled_id)); + +mutex_unlock (&led->lock); + +return ret; +} + +static void max77693_init_v4l2_flash_config (struct max77693_sub_led *sub_led, +struct max77693_led_config_data *led_cfg, +struct v4l2_flash_config *v4l2_sd_cfg) +{ +struct max77693_led_device *led =sub_led_to_led (sub_led); +struct device *dev = &led->pdev->dev; +struct max77693_dev *iodev =dev_get_drvdata (dev->parent); +struct i2c_client *i2c = iodev->i2c; +struct led_flash_setting *s; + +snprintf (v4l2_sd_cfg->dev_name,sizeof (v4l2_sd_cfg->dev_name), +"%s %d-%04x" , sub_led->fled_cdev.led_cdev.name, +i2c_adapter_id (i2c->adapter), i2c->addr); + + s = &v4l2_sd_cfg->torch_intensity; + s->min =TORCH_IOUT_MIN ; + s->max = sub_led->fled_cdev.led_cdev.max_brightness *TORCH_IOUT_STEP ; + s->step =TORCH_IOUT_STEP ; + s->val = s->max; + +/* Init flash faults config */ + v4l2_sd_cfg->flash_faults =LED_FAULT_OVER_VOLTAGE | +LED_FAULT_SHORT_CIRCUIT | +LED_FAULT_OVER_CURRENT ; + + v4l2_sd_cfg->has_external_strobe = true; +} + +static const struct v4l2_flash_ops v4l2_flash_ops = { + .external_strobe_set = max77693_led_external_strobe_set, +}; +#else +static inline void max77693_init_v4l2_flash_config ( +struct max77693_sub_led *sub_led, +struct max77693_led_config_data *led_cfg, +struct v4l2_flash_config *v4l2_sd_cfg) +{ +} +static const struct v4l2_flash_ops v4l2_flash_ops; +#endif +static void max77693_init_fled_cdev (struct max77693_sub_led *sub_led,struct max77693_led_config_data *led_cfg) {
@@ -870,12 +947,45 @@ static void max77693_init_fled_cdev(struct max77693_sub_led *sub_led, sub_led->flash_timeout = fled_cdev->timeout.val; } +static int max77693_register_led (struct max77693_sub_led *sub_led, +struct max77693_led_config_data *led_cfg, +struct device_node *sub_node) +{ +struct max77693_led_device *led =sub_led_to_led (sub_led); +struct led_classdev_flash *fled_cdev = &sub_led->fled_cdev; +struct device *dev = &led->pdev->dev; +struct v4l2_flash_config v4l2_sd_cfg = {}; +int ret; + +/* Register in the LED subsystem */ + ret =led_classdev_flash_register (dev, fled_cdev); +if (ret <0 ) +return ret; + +max77693_init_v4l2_flash_config (sub_led, led_cfg, &v4l2_sd_cfg); + +/* Register in the V4L2 subsystem. */ + sub_led->v4l2_flash =v4l2_flash_init (dev, sub_node, fled_cdev,NULL , + &v4l2_flash_ops, &v4l2_sd_cfg); +if (IS_ERR (sub_led->v4l2_flash)) { + ret =PTR_ERR (sub_led->v4l2_flash); + goto err_v4l2_flash_init; + } + +return 0 ; + +err_v4l2_flash_init: +led_classdev_flash_unregister (fled_cdev); +return ret; +} +static int max77693_led_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev;struct max77693_dev *iodev =dev_get_drvdata (dev->parent);struct max77693_led_device *led;struct max77693_sub_led *sub_leds; +struct device_node *sub_nodes[2 ] = {};struct max77693_led_config_data led_cfg = {};int init_fled_cdev[2 ], i, ret;
@@ -889,7 +999,7 @@ static int max77693_led_probe(struct platform_device *pdev) sub_leds = led->sub_leds;platform_set_drvdata (pdev, led); - ret =max77693_led_get_configuration (led, &led_cfg); + ret =max77693_led_get_configuration (led, &led_cfg, sub_nodes);if (ret <0 )return ret;
@@ -911,8 +1021,12 @@ static int max77693_led_probe(struct platform_device *pdev)/* Initialize LED Flash class device */ max77693_init_fled_cdev (&sub_leds[i], &led_cfg); -/* Register LED Flash class device */ - ret =led_classdev_flash_register (dev, &sub_leds[i].fled_cdev); +/* +* Register LED Flash class device and corresponding +* V4L2 Flash device. +*/ + ret =max77693_register_led (&sub_leds[i], &led_cfg, + sub_nodes[i]);if (ret <0 ) {/* * At this moment FLED1 might have been already
@@ -931,6 +1045,7 @@ err_register_led2:/* It is possible than only FLED2 was to be registered */ if (!init_fled_cdev[FLED1 ]) goto err_register_led1; +v4l2_flash_release (sub_leds[FLED1 ].v4l2_flash);led_classdev_flash_unregister (&sub_leds[FLED1 ].fled_cdev); err_register_led1:mutex_destroy (&led->lock);
@@ -944,11 +1059,13 @@ static int max77693_led_remove(struct platform_device *pdev)struct max77693_sub_led *sub_leds = led->sub_leds;if (led->iout_joint ||max77693_fled_used (led,FLED1 )) { +v4l2_flash_release (sub_leds[FLED1 ].v4l2_flash);led_classdev_flash_unregister (&sub_leds[FLED1 ].fled_cdev);cancel_work_sync (&sub_leds[FLED1 ].work_brightness_set); }if (!led->iout_joint &&max77693_fled_used (led,FLED2 )) { +v4l2_flash_release (sub_leds[FLED2 ].v4l2_flash);led_classdev_flash_unregister (&sub_leds[FLED2 ].fled_cdev);cancel_work_sync (&sub_leds[FLED2 ].work_brightness_set); }
Signature · 1 line
1.7.9.5
Re: [PATCH v9 3/8] leds: max77693: add support for V4L2 Flash sub-device
Hi Jacek,
Quoted 9 lines · Jacek Anaszewski
Add support for V4L2 Flash sub-device to the max77693 LED Flash class driver. The support allows for V4L2 Flash sub-device to take the control of the LED Flash class device.
Signed-off-by Jacek Anaszewski <[email protected]>Acked-by Kyungmin Park <[email protected]>Cc Bryan Wu <[email protected]>Cc Richard Purdie <[email protected]>Cc Sakari Ailus <[email protected]>
For this and the rest in the set:
Many thanks to you for your efforts on this! It's great to see it in this state after all the review rounds. :-)
Signature · 4 lines
Kind regards, Sakari Ailus e-mail: [email protected] XMPP: [email protected]
PATCH v9 4/8 DT: aat1290: Document handling external strobe sources
In reply to Jacek AnaszewskiThis patch adds documentation for a pinctrl-names property. The property, when present, is used for switching the source of the strobe signal for the device.
--- .../devicetree/bindings/leds/leds-aat1290.txt | 36 ++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/leds/leds-aat1290.txt +34 -2
@@ -2,7 +2,9 @@ The device is controlled through two pins: FL_EN and EN_SET. The pins when, asserted high, enable flash strobe and movie mode (max 1/2 of flash current) -respectively. +respectively. In order to add a capability of selecting the strobe signal source +(e.g. CPU or camera sensor) there is an additional switch required, independent +of the flash chip. The switch is controlled with pin control. Required properties:
@@ -10,6 +12,13 @@ Required properties: - flen-gpios : Must be device tree identifier of the flash device FL_EN pin. - enset-gpios : Must be device tree identifier of the flash device EN_SET pin. +Optional properties: +- pinctrl-names : Must contain entries: "default", "host", "isp". Entries + "default" and "host" must refer to the same pin configuration + node, which sets the host as a strobe signal provider. Entry + "isp" must refer to the pin configuration node, which sets the + ISP as a strobe signal provider. + A discrete LED element connected to the device must be represented by a child node - see Documentation/devicetree/bindings/leds/common.txt.
@@ -25,13 +34,22 @@ Required properties of the LED child node: Optional properties of the LED child node: - label : see Documentation/devicetree/bindings/leds/common.txt -Example (by Ct = 220nF, Rset = 160kohm): +Example (by Ct = 220nF, Rset = 160kohm and exynos4412-trats2 board with +a switch that allows for routing strobe signal either from the host or from +the camera sensor): + +#include "exynos4412.dtsi" aat1290 { compatible = "skyworks,aat1290"; flen-gpios = <&gpj1 1 GPIO_ACTIVE_HIGH>; enset-gpios = <&gpj1 2 GPIO_ACTIVE_HIGH>; + pinctrl-names = "default", "host", "isp"; + pinctrl-0 = <&camera_flash_host>; + pinctrl-1 = <&camera_flash_host>; + pinctrl-2 = <&camera_flash_isp>; + camera_flash: flash-led { label = "aat1290-flash"; led-max-microamp = <520833>;
@@ -39,3 +57,17 @@ aat1290 { flash-timeout-us = <1940000>; }; }; + +&pinctrl_0 { + camera_flash_host: camera-flash-host { + samsung,pins = "gpj1-0"; + samsung,pin-function = <1>; + samsung,pin-val = <0>; + }; + + camera_flash_isp: camera-flash-isp { + samsung,pins = "gpj1-0"; + samsung,pin-function = <1>; + samsung,pin-val = <1>; + }; +};
Signature · 1 line
1.7.9.5
PATCH v9 5/8 leds: aat1290: add support for V4L2 Flash sub-device
In reply to Jacek AnaszewskiAdd support for V4L2 Flash sub-device to the aat1290 LED Flash class driver. The support allows for V4L2 Flash sub-device to take the control of the LED Flash class device.
--- drivers/leds/Kconfig | 1 + drivers/leds/leds-aat1290.c | 137 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 132 insertions(+), 6 deletions(-)
drivers/leds/Kconfig +1 -0
@@ -47,6 +47,7 @@ config LEDS_AAT1290 depends on LEDS_CLASS_FLASH depends on GPIOLIB depends on OF + depends on PINCTRL help This option enables support for the LEDs on the AAT1290.
drivers/leds/leds-aat1290.c +131 -6
237 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH v9 6/8 exynos4-is: Improve the mechanism of async subdevs verification
In reply to Jacek AnaszewskiAvoid verifying bound async sensor sub-devices by their of_nodes, which duplicates v4l2-async functionality, in favour of matching them by the corresponding struct v4l2_async_subdev. The structures are now being aggregated in the newly introduced struct fimc_async_subdevs which allows for categorizing async sub-devices by their type upon DT node parsing and recognizing the type easily when they're being bound.
--- drivers/media/platform/exynos4-is/media-dev.c | 34 +++++++++++++++++++------ drivers/media/platform/exynos4-is/media-dev.h | 8 ++++-- 2 files changed, 32 insertions(+), 10 deletions(-)
drivers/media/platform/exynos4-is/media-dev.c +26 -8
@@ -331,6 +331,8 @@ static int fimc_md_parse_port_node(struct fimc_md *fmd, unsigned int index) {struct fimc_source_info *pd = &fmd->sensor[index].pdata; +struct v4l2_async_notifier *notifier = &fmd->subdev_notifier; +struct v4l2_async_subdev *asd;struct device_node *rem, *ep, *np;struct v4l2_of_endpoint endpoint;
@@ -387,9 +389,11 @@ static int fimc_md_parse_port_node(struct fimc_md *fmd,if (WARN_ON (index >=ARRAY_SIZE (fmd->sensor)))return -EINVAL ; - fmd->sensor[index].asd.match_type =V4L2_ASYNC_MATCH_OF ; - fmd->sensor[index].asd.match.of.node = rem; - fmd->async_subdevs[index] = &fmd->sensor[index].asd; + asd = &fmd->async_subdevs.sensors[index]; + asd->match_type =V4L2_ASYNC_MATCH_OF ; + asd->match.of.node = rem; + notifier->subdevs[notifier->num_subdevs++] = asd; + fmd->sensor[index].asd = asd; fmd->num_sensors++;
@@ -1272,12 +1276,13 @@ static int subdev_notifier_bound(struct v4l2_async_notifier *notifier, struct v4l2_async_subdev *asd) {struct fimc_md *fmd =notifier_to_fimc_md (notifier); +struct fimc_async_subdevs *async_subdevs = &fmd->async_subdevs;struct fimc_sensor_info *si =NULL ;int i;/* Find platform data for this sensor subdev */ -for (i =0 ; i <ARRAY_SIZE (fmd->sensor); i++) -if (fmd->sensor[i].asd.match.of.node == subdev->dev->of_node) +for (i =0 ; i <ARRAY_SIZE (async_subdevs->sensors); i++) +if (fmd->sensor[i].asd == asd) si = &fmd->sensor[i];if (si ==NULL )
@@ -1317,6 +1322,19 @@ unlock:return ret; } +static int fimc_md_register_async_entities (struct fimc_md *fmd) +{ +struct device *dev = fmd->media_dev.dev; +struct v4l2_async_notifier *notifier = &fmd->subdev_notifier; + + notifier->subdevs =devm_kcalloc (dev,FIMC_MAX_SENSORS , +sizeof (*notifier->subdevs),GFP_KERNEL ); +if (!notifier->subdevs) +return -ENOMEM ; + +return fimc_md_register_sensor_entities (fmd); +} +static int fimc_md_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev;
@@ -1379,7 +1397,7 @@ static int fimc_md_probe(struct platform_device *pdev) goto err_clk; } - ret =fimc_md_register_sensor_entities (fmd); + ret =fimc_md_register_async_entities (fmd);if (ret) {mutex_unlock (&fmd->media_dev.graph_mutex); goto err_m_ent;
@@ -1402,8 +1420,6 @@ static int fimc_md_probe(struct platform_device *pdev) }if (fmd->num_sensors >0 ) { - fmd->subdev_notifier.subdevs = fmd->async_subdevs; - fmd->subdev_notifier.num_subdevs = fmd->num_sensors; fmd->subdev_notifier.bound = subdev_notifier_bound; fmd->subdev_notifier.complete = subdev_notifier_complete; fmd->num_sensors =0 ;
@@ -1412,6 +1428,8 @@ static int fimc_md_probe(struct platform_device *pdev) &fmd->subdev_notifier);if (ret) goto err_clk_p; + }else { +devm_kfree (dev, fmd->subdev_notifier.subdevs); }return 0 ;
drivers/media/platform/exynos4-is/media-dev.h +6 -2
@@ -88,11 +88,15 @@ struct fimc_camclk_info {*/ struct fimc_sensor_info {struct fimc_source_info pdata; -struct v4l2_async_subdev asd; +struct v4l2_async_subdev *asd;struct v4l2_subdev *subdev;struct fimc_dev *host; }; +struct fimc_async_subdevs { +struct v4l2_async_subdev sensors[FIMC_MAX_SENSORS ]; +}; +struct cam_clk {struct clk_hw hw;struct fimc_md *fmd;
@@ -149,7 +153,7 @@ struct fimc_md { } clk_provider;struct v4l2_async_notifier subdev_notifier; -struct v4l2_async_subdev *async_subdevs[FIMC_MAX_SENSORS ]; +struct fimc_async_subdevs async_subdevs;bool user_subdev_api;spinlock_t slock;
Signature · 1 line
1.7.9.5
PATCH v9 7/8 DT: Add documentation for exynos4-is 'flashes' property
In reply to Jacek AnaszewskiThis patch adds a description of 'samsung,camera-flashes' property to the samsung-fimc.txt.
--- .../devicetree/bindings/media/samsung-fimc.txt | 10 ++++++++++ 1 file changed, 10 insertions(+)
Documentation/devicetree/bindings/media/samsung-fimc.txt +10 -0
@@ -40,6 +40,14 @@ should be inactive. For the "active-a" state the camera port A must be activated and the port B deactivated and for the state "active-b" it should be the other way around. +Optional properties: + +- samsung,camera-flashes - Array of pairs of phandles to the camera sensor + devices and flash LEDs respectively. The pairs must reflect the board + configuration, i.e. a sensor has to be able to strobe a flash LED by + hardware. Flash LED is represented by a child node of a flash LED + device (see Documentation/devicetree/bindings/leds/common.txt). + The 'camera' node must include at least one 'fimc' child node.
@@ -166,6 +174,8 @@ Example: clock-output-names = "cam_a_clkout", "cam_b_clkout"; pinctrl-names = "default"; pinctrl-0 = <&cam_port_a_clk_active>; + samsung,camera-flashes = <&rear_camera &rear_flash>, + <&front_camera &front_flash>; status = "okay"; #address-cells = <1>; #size-cells = <1>;
Signature · 1 line
1.7.9.5
PATCH v9 8/8 exynos4-is: Add support for v4l2-flash subdevs
In reply to Jacek AnaszewskiThis patch adds support for external v4l2-flash devices. The support includes parsing "camera-flashes" DT property and asynchronous sub-device registration.
--- drivers/media/platform/exynos4-is/media-dev.c | 64 ++++++++++++++++++++++++- drivers/media/platform/exynos4-is/media-dev.h | 4 ++ 2 files changed, 66 insertions(+), 2 deletions(-)
drivers/media/platform/exynos4-is/media-dev.c +62 -2
@@ -455,6 +455,52 @@ rpm_put:return ret; } +static int fimc_md_register_flash_entities (struct fimc_md *fmd) +{ +struct device_node *parent = fmd->pdev->dev.of_node, *np_sensor, + *np_flash; +struct v4l2_async_notifier *notifier = &fmd->subdev_notifier; +struct v4l2_async_subdev *asd; +int i, j, num_flashes =0 , num_elems; + + num_elems =of_property_count_elems_of_size (parent, +"samsung,camera-flashes" ,sizeof (np_flash)); +/* samsung,camera-flashes property is optional */ +if (num_elems <0 ) +return 0 ; + +/* samsung,camera-flashes array must have even number of elements */ +if ((num_elems &1 ) || (num_elems >FIMC_MAX_SENSORS *2 )) +return -EINVAL ; + +for (i =0 ; i < num_elems; i +=2 ) { + np_sensor =of_parse_phandle (parent, +"samsung,camera-flashes" , i); + +for (j =0 ; j < fmd->num_sensors; j++) +if (fmd->async_subdevs.sensors[j].match.of.node == + np_sensor) +break ; + +of_node_put (np_sensor); + +if (j == fmd->num_sensors) +continue ; + + np_flash =of_parse_phandle (parent,"samsung,camera-flashes" , + i +1 ); + + asd = &fmd->async_subdevs.flashes[num_flashes++]; + asd->match_type =V4L2_ASYNC_MATCH_OF ; + asd->match.of.node = np_flash; + notifier->subdevs[notifier->num_subdevs++] = asd; + +of_node_put (np_flash); + } + +return 0 ; +} +static int __of_get_csis_id (struct device_node *np) {u32 reg =0 ;
@@ -1280,6 +1326,15 @@ static int subdev_notifier_bound(struct v4l2_async_notifier *notifier,struct fimc_sensor_info *si =NULL ;int i; +/* +* Flash sub-devices are controlled independently of ISP, and thus +* verify only that the sub-device being matched was previously +* registered. +*/ +for (i =0 ; i <ARRAY_SIZE (async_subdevs->flashes); i++) +if (&async_subdevs->flashes[i] == asd) +return 0 ; +/* Find platform data for this sensor subdev */ for (i =0 ; i <ARRAY_SIZE (async_subdevs->sensors); i++)if (fmd->sensor[i].asd == asd)
@@ -1326,13 +1381,18 @@ static int fimc_md_register_async_entities(struct fimc_md *fmd) {struct device *dev = fmd->media_dev.dev;struct v4l2_async_notifier *notifier = &fmd->subdev_notifier; +int ret; - notifier->subdevs =devm_kcalloc (dev,FIMC_MAX_SENSORS , + notifier->subdevs =devm_kcalloc (dev,FIMC_MAX_ASYNC_ENTITIES ,sizeof (*notifier->subdevs),GFP_KERNEL );if (!notifier->subdevs)return -ENOMEM ; -return fimc_md_register_sensor_entities (fmd); + ret =fimc_md_register_sensor_entities (fmd); +if (ret) +return -EINVAL ; + +return fimc_md_register_flash_entities (fmd); }static int fimc_md_probe (struct platform_device *pdev)
drivers/media/platform/exynos4-is/media-dev.h +4 -0
@@ -33,7 +33,10 @@#define PINCTRL_STATE_IDLE "idle"#define FIMC_MAX_SENSORS 4 +#define FIMC_MAX_FLASHES 4 +#define FIMC_MAX_ASYNC_ENTITIES (FIMC_MAX_SENSORS + FIMC_MAX_FLASHES)#define FIMC_MAX_CAMCLKS 2 +#define DEFAULT_SENSOR_CLK_FREQ 24000000U/* LCD/ISP Writeback clocks (PIXELASYNCMx) */
@@ -95,6 +98,7 @@ struct fimc_sensor_info {struct fimc_async_subdevs {struct v4l2_async_subdev sensors[FIMC_MAX_SENSORS ]; +struct v4l2_async_subdev flashes[FIMC_MAX_FLASHES ]; };struct cam_clk {
Signature · 1 line
1.7.9.5
Re: [PATCH v9 8/8] exynos4-is: Add support for v4l2-flash subdevs
Quoted 2 lines · Jacek Anaszewski
This patch adds support for external v4l2-flash devices. The support includes parsing "camera-flashes" DT property
"samsung,camera-flashes" ?
drivers/media/platform/exynos4-is/media-dev.c rpm_put: · line 467
Quoted 12 lines
and asynchronous sub-device registration.
drivers/media/platform/exynos4-is/media-dev.c +10
-0+static int fimc_md_register_flash_entities (struct fimc_md *fmd) +{ +struct device_node *parent = fmd->pdev->dev.of_node, *np_sensor, + *np_flash; +struct v4l2_async_notifier *notifier = &fmd->subdev_notifier; +struct v4l2_async_subdev *asd; +int i, j, num_flashes =0 , num_elems; + + num_elems =of_property_count_elems_of_size (parent, +"samsung,camera-flashes" ,sizeof (np_flash));
I think this should be of_property_count_u32_elems(), phandle is always a 32-bit value [1], while size of a pointer depends on the architecture.
Quoted 8 lines
drivers/media/platform/exynos4-is/media-dev.c +8
-0+/* samsung,camera-flashes property is optional */ +if (num_elems <0 ) +return 0 ; + +/* samsung,camera-flashes array must have even number of elements */ +if ((num_elems &1 ) || (num_elems >FIMC_MAX_SENSORS *2 )) +return -EINVAL ; +
drivers/media/platform/exynos4-is/media-dev.c rpm_put: · line 485
Quoted 10 lines
drivers/media/platform/exynos4-is/media-dev.c +10
-0+for (i =0 ; i < num_elems; i +=2 ) { + np_sensor =of_parse_phandle (parent, +"samsung,camera-flashes" , i); + +for (j =0 ; j < fmd->num_sensors; j++) +if (fmd->async_subdevs.sensors[j].match.of.node == + np_sensor) +break ; + +of_node_put (np_sensor);
Would be good to add some comment here, why is the sensor required. It's just a DT correctness check? Couldn't we carry on with the flash registration after just emitting some warning?
Quoted 6 lines
drivers/media/platform/exynos4-is/media-dev.c +6
-0+if (j == fmd->num_sensors) +continue ; + + np_flash =of_parse_phandle (parent,"samsung,camera-flashes" , + i +1 ); +
drivers/media/platform/exynos4-is/media-dev.c rpm_put: · line 502
Quoted 10 lines
drivers/media/platform/exynos4-is/media-dev.c +10
-0+ asd = &fmd->async_subdevs.flashes[num_flashes++]; + asd->match_type =V4L2_ASYNC_MATCH_OF ; + asd->match.of.node = np_flash; + notifier->subdevs[notifier->num_subdevs++] = asd; + +of_node_put (np_flash); + } + +return 0 ; +}
Otherwise looks good to me.
Signature · 5 lines
Thanks, Sylwester [1] http://lxr.free-electrons.com/source/Documentation/devicetree/booting-without-of.txt#L545
Re: [PATCH v9 8/8] exynos4-is: Add support for v4l2-flash subdevs
Hi Sylwester,
Thanks for the review.
Quoted 5 lines · Sylwester Nawrocki
Quoted 2 lines · Jacek Anaszewski
This patch adds support for external v4l2-flash devices. The support includes parsing "camera-flashes" DT property
"samsung,camera-flashes" ?
Right.
Quoted 15 lines
drivers/media/platform/exynos4-is/media-dev.c rpm_put: · line 467
Quoted 12 lines
and asynchronous sub-device registration.
drivers/media/platform/exynos4-is/media-dev.c +10
-0+static int fimc_md_register_flash_entities (struct fimc_md *fmd) +{ +struct device_node *parent = fmd->pdev->dev.of_node, *np_sensor, + *np_flash; +struct v4l2_async_notifier *notifier = &fmd->subdev_notifier; +struct v4l2_async_subdev *asd; +int i, j, num_flashes =0 , num_elems; + + num_elems =of_property_count_elems_of_size (parent, +"samsung,camera-flashes" ,sizeof (np_flash));I think this should be
of_property_count_u32_elems(), phandle is always a 32-bit value [1], while size of a pointer depends on the architecture.
Thanks for spotting this.
Quoted 14 lines
Quoted 14 lines
drivers/media/platform/exynos4-is/media-dev.c +13
-0+/* samsung,camera-flashes property is optional */ +if (num_elems <0 ) +return 0 ; + +/* samsung,camera-flashes array must have even number of elements */ +if ((num_elems &1 ) || (num_elems >FIMC_MAX_SENSORS *2 )) +return -EINVAL ; + +for (i =0 ; i < num_elems; i +=2 ) { + np_sensor =of_parse_phandle (parent, +"samsung,camera-flashes" , i); + +for (j =0 ; j < fmd->num_sensors; j++)
Quoted 8 lines
drivers/media/platform/exynos4-is/media-dev.c rpm_put: · line 485
Quoted 5 lines
drivers/media/platform/exynos4-is/media-dev.c +5
-0+if (fmd->async_subdevs.sensors[j].match.of.node == + np_sensor) +break ; + +of_node_put (np_sensor);Would be good to add some comment here, why is the sensor required. It's just a DT correctness check?
Yes, it checks whether the phandle points to the sensor node which was previously registered.
Quoted 2 lines
Couldn't we carry on with the flash
registration after just emitting some warning?
Hmm, I've just realized that with this code the flash phandle associated with the sensor phandle that hasn't been previously registered would be silently ignored.
I agree that we should register the flash and emit warning in case sensor phandle doesn't point the known sensor.
Quoted 19 lines
Quoted 6 lines
drivers/media/platform/exynos4-is/media-dev.c +6
-0+if (j == fmd->num_sensors) +continue ; + + np_flash =of_parse_phandle (parent,"samsung,camera-flashes" , + i +1 ); +drivers/media/platform/exynos4-is/media-dev.c rpm_put: · line 502
Quoted 10 lines
drivers/media/platform/exynos4-is/media-dev.c +10
-0+ asd = &fmd->async_subdevs.flashes[num_flashes++]; + asd->match_type =V4L2_ASYNC_MATCH_OF ; + asd->match.of.node = np_flash; + notifier->subdevs[notifier->num_subdevs++] = asd; + +of_node_put (np_flash); + } + +return 0 ; +}Otherwise looks good to me.
Signature · 2 lines
Best Regards, Jacek Anaszewski