LED / flash API integration - V4L2 Flash
Subsystems (3)
v6 cover LED / flash API integration - V4L2 Flash
This patch set is the follow-up of the LED / flash API integration series [1]. For clarity reasons the patchset has been split into four subsets:
- LED Flash Class
- V4L2 Flash
- LED Flash Class drivers
- Documentation
========================
Changes since version 5:
========================
- removed flash manager framework - its implementation needs further thorough discussion.
- removed external strobe facilities from the LED Flash Class and provided external_strobe_set op in v4l2-flash. LED subsystem should be strobe provider agnostic.
Thanks,
Jacek Anaszewski
[1] https://lkml.org/lkml/2014/7/11/914
Jacek Anaszewski (2):
media: Add registration helpers for V4L2 flash
exynos4-is: Add support for v4l2-flash subdevs
drivers/media/platform/exynos4-is/media-dev.c | 36 +- drivers/media/platform/exynos4-is/media-dev.h | 13 +- drivers/media/v4l2-core/Kconfig | 11 + drivers/media/v4l2-core/Makefile | 2 + drivers/media/v4l2-core/v4l2-flash.c | 502 +++++++++++++++++++++++++ include/media/v4l2-flash.h | 135 +++++++ 6 files changed, 696 insertions(+), 3 deletions(-) create mode 100644 drivers/media/v4l2-core/v4l2-flash.c create mode 100644 include/media/v4l2-flash.h
Signature · 1 line
1.7.9.5
PATCH v6 1/2 media: Add registration helpers for V4L2 flash
This patch adds helper functions for registering/unregistering LED class flash devices as V4L2 subdevs. 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.c | 502 ++++++++++++++++++++++++++++++++++ include/media/v4l2-flash.h | 135 +++++++++ 4 files changed, 650 insertions(+) create mode 100644 drivers/media/v4l2-core/v4l2-flash.c create mode 100644 include/media/v4l2-flash.h
drivers/media/v4l2-core/Kconfig +11 -0
@@ -35,6 +35,17 @@ config V4L2_MEM2MEM_DEV tristate depends on VIDEOBUF2_CORE +# Used by LED subsystem flash drivers +config V4L2_FLASH_LED_CLASS + tristate "Enable support for Flash sub-devices" + depends on VIDEO_V4L2_SUBDEV_API + depends on LEDS_CLASS_FLASH + ---help--- + Say Y here to enable support for Flash sub-devices, which allow + to control LED class devices with use of V4L2 Flash controls. + + When in doubt, say N. + # Used by drivers that need Videobuf modules config VIDEOBUF_GEN tristate
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.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.c new file +502 -0
502 lines not on this page · raw message
include/media/v4l2-flash.h new file +135 -0
135 lines not on this page · raw message
Signature · 1 line
1.7.9.5
Re: [PATCH/RFC v6 1/2] media: Add registration helpers for V4L2 flash
Hi Sakari,
Quoted 12 lines · Jacek Anaszewski
This patch adds helper functions for registering/unregistering LED class flash devices as V4L2 subdevs. 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]>Cc Bryan Wu <[email protected]>Cc Richard Purdie <[email protected]>
Quoted 8 lines
--- drivers/media/v4l2-core/Kconfig | 11 + drivers/media/v4l2-core/Makefile | 2 + drivers/media/v4l2-core/v4l2-flash.c | 502 ++++++++++++++++++++++++++++++++++ include/media/v4l2-flash.h | 135 +++++++++ 4 files changed, 650 insertions(+)create mode 100644
drivers/media/v4l2-core/v4l2-flash.ccreate mode 100644include/media/v4l2-flash.h
[...]
After discussing on IRC the way of using compound controls for v4l2-flash sub-device I started to re-implement the patch but encountered subsequent issues, which make my inclination for abiding by the current version of the patch (separate v4l2-flash device for each sub-led) even stronger.
Let's list arguments for both options:
1. Single v4l2-flash sub-device for a flash device that can control several sub-leds:
a) a flash device driver has one related i2c device
b) there exist hardware designs where some registers are shared between sub-leds (e.g. flash timeout, flash status)
2. Separate v4l2-flash sub-device for each sub-led of a flash device
a) LED Flash class drivers create separate LED Flash device for sub-leds (enforced by led-triggers design). This way there is a simple one-to-one "LED Flash device" - "v4l2-flash sub-device" relation.
b) if a single v4l2-flash sub-device was to control several LED Flash devices then array controls would have to be used for accessing the settings of every LED Flash device. This poses following issues:
- the type of each V4L2 Flash control would have to be set to the compound one (e.g. V4L2_CTRL_TYPE_U32), which in turn would make the menu controls unavailable for querying and displaying e.g. in qv4l2. Also the types as bitmask, button would have to be avoided.
- All elements of an array control have to have the same constraints and it would make impossible setting different min, max values (e.g. current, timeout, external strobe) for each sub-led. All the advantageous v4l2-ctrl mechanism related to validating and caching controls would have to be avoided and the user space would only get feedback in the form of failing ioctl when the value to be set is not properly aligned
- it is not possible to set only one element of the control array and thus the settings of each sub-led would have to be cached to avoid superfluous device register access (functionality already secured by non-array v4l2-controls)
- the flash devices supporting single led could be provided with standard non-array controls, but it would produce cumbersome v4l2-flash code and inconsistent user space interface
From the above it looks like the option 2. has much more advantages. The argument 1.a doesn't seem to be so vital in view of the fact that LED subsystem already breaks it. The argument 1.b can be obviated by caching the relevant values in the driver as it is for max77693-led.
I think that choosing option 2. would allow for avoiding much work that is already done in v4l2-ctrls.c. Moreover it would keep the V4L2 Flash controls maintainable with qv4l2.
Best Regards,
Jacek Anaszewski
Re: [PATCH/RFC v6 1/2] media: Add registration helpers for V4L2 flash
Hi Jacek,
Thank you for your thoughtful writing on the subject.
Quoted 44 lines · Jacek Anaszewski
Hi Sakari,
Quoted 19 lines · Jacek Anaszewski
This patch adds helper functions for registering/unregistering LED class flash devices as V4L2 subdevs. 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]>Cc Bryan Wu <[email protected]>Cc Richard Purdie <[email protected]>--- drivers/media/v4l2-core/Kconfig | 11 + drivers/media/v4l2-core/Makefile | 2 + drivers/media/v4l2-core/v4l2-flash.c | 502 ++++++++++++++++++++++++++++++++++ include/media/v4l2-flash.h | 135 +++++++++ 4 files changed, 650 insertions(+)Quoted 2 lines
create mode 100644
drivers/media/v4l2-core/v4l2-flash.ccreate mode 100644include/media/v4l2-flash.h[...]
After discussing on IRC the way of using compound controls for v4l2-flash sub-device I started to re-implement the patch but encountered subsequent issues, which make my inclination for abiding by the current version of the patch (separate v4l2-flash device for each sub-led) even stronger.
Let's list arguments for both options:
1. Single v4l2-flash sub-device for a flash device that can control several sub-leds:
a) a flash device driver has one related i2c device
b) there exist hardware designs where some registers are shared between sub-leds (e.g. flash timeout, flash status)2. Separate v4l2-flash sub-device for each sub-led of a flash device
Quoted 13 lines
a) LED Flash class drivers create separate LED Flash device for sub-leds (enforced by led-triggers design). This way there is a simple one-to-one "LED Flash device" - "v4l2-flash sub-device" relation.
b) if a single v4l2-flash sub-device was to control several LED Flash devices then array controls would have to be used for accessing the settings of every LED Flash device. This poses following issues:
- the type of each V4L2 Flash control would have to be set to the compound one (e.g.V4L2_CTRL_TYPE_U32), which in turn would make the menu controls unavailable for querying and displaying e.g. in qv4l2. Also the types as bitmask, button would have to be avoided.
Good point. Currently the button control type is used for the strobe control. For two leds we'd need an array of two button controls.
Quoted 7 lines
- All elements of an array control have to have the same constraints and it would make impossible setting different min, max values (e.g. current, timeout, external strobe) for each sub-led. All the advantageous v4l2-ctrl mechanism related to validating and caching controls would have to be avoided and the user space would only get feedback in the form of failing ioctl when the value to be set is not properly aligned
True. This is quite unpleasant to the user indeed.
Quoted 4 lines
- it is not possible to set only one element of the control array and thus the settings of each sub-led would have to be cached to avoid superfluous device register access (functionality already secured by non-array v4l2-controls)
Agreed. But this is still a relatively minor nuisance in the implementation.
Quoted 4 lines
- the flash devices supporting single led could be provided with standard non-array controls, but it would produce cumbersome v4l2-flash code and inconsistent user space interface
Quoted 8 lines
From the above it looks like the option 2. has much more advantages. The argument 1.a doesn't seem to be so vital in view of the fact that LED subsystem already breaks it. The argument 1.b can be obviated by caching the relevant values in the driver as it is for max77693-led.
I think that choosing option 2. would allow for avoiding much work that is already done in
v4l2-ctrls.c. Moreover it would keep the V4L2 Flash controls maintainable with qv4l2.
Fair enough.
My remaining concerns in using two sub-devices to expose the LEDs to user space are thus:
- Software strobe synchronisation. This one is important. There's no way to push a button control from two sub-devices at the same time. AFAIR your device lets the user to strobe the LEDs separately, but they are still controlled through a single register. Either we could implement the strobe only for the first LED, and it'd also affect the other. Alternatively we could add one more boolean control to the second LED (while both sub-devices would have the strobe button) to tell the strobe is synchronous with the other sub-device.
- Faults. There's usually just a single set of faults. Do we expose them for both sub-devices, even if they are the same? I think I'd do just that. Reading the faults on either sub-device will reset both.
Signature · 4 lines
Kind regards, Sakari Ailus [email protected]
Re: [PATCH/RFC v6 1/2] media: Add registration helpers for V4L2 flash
Hi Sakari,
Quoted 3 lines · Sakari Ailus
Hi Jacek,
Thank you for your thoughtful writing on the subject.
I am just doing my best to bring it to a successful end :)
Quoted 97 lines
Quoted 44 lines · Jacek Anaszewski
Hi Sakari,
Quoted 19 lines · Jacek Anaszewski
This patch adds helper functions for registering/unregistering LED class flash devices as V4L2 subdevs. 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]>Cc Bryan Wu <[email protected]>Cc Richard Purdie <[email protected]>--- drivers/media/v4l2-core/Kconfig | 11 + drivers/media/v4l2-core/Makefile | 2 + drivers/media/v4l2-core/v4l2-flash.c | 502 ++++++++++++++++++++++++++++++++++ include/media/v4l2-flash.h | 135 +++++++++ 4 files changed, 650 insertions(+)Quoted 2 lines
create mode 100644
drivers/media/v4l2-core/v4l2-flash.ccreate mode 100644include/media/v4l2-flash.h[...]
After discussing on IRC the way of using compound controls for v4l2-flash sub-device I started to re-implement the patch but encountered subsequent issues, which make my inclination for abiding by the current version of the patch (separate v4l2-flash device for each sub-led) even stronger.
Let's list arguments for both options:
1. Single v4l2-flash sub-device for a flash device that can control several sub-leds:
a) a flash device driver has one related i2c device
b) there exist hardware designs where some registers are shared between sub-leds (e.g. flash timeout, flash status)2. Separate v4l2-flash sub-device for each sub-led of a flash device
Quoted 13 lines
a) LED Flash class drivers create separate LED Flash device for sub-leds (enforced by led-triggers design). This way there is a simple one-to-one "LED Flash device" - "v4l2-flash sub-device" relation.
b) if a single v4l2-flash sub-device was to control several LED Flash devices then array controls would have to be used for accessing the settings of every LED Flash device. This poses following issues:
- the type of each V4L2 Flash control would have to be set to the compound one (e.g.V4L2_CTRL_TYPE_U32), which in turn would make the menu controls unavailable for querying and displaying e.g. in qv4l2. Also the types as bitmask, button would have to be avoided.Good point. Currently the button control type is used for the strobe control. For two leds we'd need an array of two button controls.
Quoted 7 lines
- All elements of an array control have to have the same constraints and it would make impossible setting different min, max values (e.g. current, timeout, external strobe) for each sub-led. All the advantageous v4l2-ctrl mechanism related to validating and caching controls would have to be avoided and the user space would only get feedback in the form of failing ioctl when the value to be set is not properly aligned
True. This is quite unpleasant to the user indeed.
Quoted 4 lines
- it is not possible to set only one element of the control array and thus the settings of each sub-led would have to be cached to avoid superfluous device register access (functionality already secured by non-array v4l2-controls)
Agreed. But this is still a relatively minor nuisance in the implementation.
Quoted 4 lines
- the flash devices supporting single led could be provided with standard non-array controls, but it would produce cumbersome v4l2-flash code and inconsistent user space interface
Quoted 8 lines
From the above it looks like the option 2. has much more advantages.
The argument 1.a doesn't seem to be so vital in view of the fact that LED subsystem already breaks it. The argument 1.b can be obviated by caching the relevant values in the driver as it is for max77693-led.I think that choosing option 2. would allow for avoiding much work that is already done in
v4l2-ctrls.c. Moreover it would keep the V4L2 Flash controls maintainable with qv4l2.Fair enough.
My remaining concerns in using two sub-devices to expose the LEDs to user space are thus:
Quoted 8 lines
- Software strobe synchronisation. This one is important. There's no way to push a button control from two sub-devices at the same time. AFAIR your device lets the user to strobe the LEDs separately, but they are still controlled through a single register. Either we could implement the strobe only for the first LED, and it'd also affect the other. Alternatively we could add one more boolean control to the second LED (while both sub-devices would have the strobe button) to tell the strobe is synchronous with the other sub-device.
In the proposed max77693-led DT bindings it is possible to define whether the led iout pins are connected or not. If they are connected, i.e. an anode of a single led is connected to both iout's, the driver creates only one LED Flash class device, and one v4l2-flash sub-device. All the driver logic is prepared for these two options and configures both leds for joint iout's mode, and for separate iout's mode it configures each led separately.
Quoted 3 lines
- Faults. There's usually just a single set of faults. Do we expose them for both sub-devices, even if they are the same? I think I'd do just that. Reading the faults on either sub-device will reset both.
For joint iout's mode there will be a single sub-device
Best Regards,
Jacek Anaszewski
PATCH v6 2/2 exynos4-is: Add support for v4l2-flash subdevs
In reply to Jacek AnaszewskiThis patch adds suppport for external v4l2-flash devices. The support includes parsing camera-flash DT property and asynchronous subdevice registration.
--- drivers/media/platform/exynos4-is/media-dev.c | 36 +++++++++++++++++++++++-- drivers/media/platform/exynos4-is/media-dev.h | 13 ++++++++- 2 files changed, 46 insertions(+), 3 deletions(-)
drivers/media/platform/exynos4-is/media-dev.c +34 -2
@@ -451,6 +451,25 @@ rpm_put:return ret; } +static void fimc_md_register_flash_entities (struct fimc_md *fmd) +{ +struct device_node *parent = fmd->pdev->dev.of_node; +struct device_node *np; +int i =0 ; + +do { + np =of_parse_phandle (parent,"flashes" , i); +if (np) { + fmd->flash[fmd->num_flashes].asd.match_type = +V4L2_ASYNC_MATCH_OF ; + fmd->flash[fmd->num_flashes].asd.match.of.node = np; + fmd->num_flashes++; + fmd->async_subdevs[fmd->num_sensors + i] = + &fmd->flash[i].asd; + } + }while (np && (++i <FIMC_MAX_FLASHES )); +} +static int __of_get_csis_id (struct device_node *np) {u32 reg =0 ;
@@ -1273,6 +1292,15 @@ static int subdev_notifier_bound(struct v4l2_async_notifier *notifier,struct fimc_sensor_info *si =NULL ;int i; +/* Register flash subdev if detected any */ +for (i =0 ; i <ARRAY_SIZE (fmd->flash); i++) { +if (fmd->flash[i].asd.match.of.node == subdev->dev->of_node) { + fmd->flash[i].subdev = subdev; + fmd->num_flashes++; +return 0 ; + } + } +/* 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)
@@ -1383,6 +1411,8 @@ static int fimc_md_probe(struct platform_device *pdev) goto err_m_ent; } +fimc_md_register_flash_entities (fmd); +mutex_unlock (&fmd->media_dev.graph_mutex); ret =device_create_file (&pdev->dev, &dev_attr_subdev_conf_mode);
@@ -1399,12 +1429,14 @@ static int fimc_md_probe(struct platform_device *pdev) goto err_attr; } -if (fmd->num_sensors >0 ) { +if (fmd->num_sensors >0 || fmd->num_flashes >0 ) { fmd->subdev_notifier.subdevs = fmd->async_subdevs; - fmd->subdev_notifier.num_subdevs = fmd->num_sensors; + fmd->subdev_notifier.num_subdevs = fmd->num_sensors + + fmd->num_flashes; fmd->subdev_notifier.bound = subdev_notifier_bound; fmd->subdev_notifier.complete = subdev_notifier_complete; fmd->num_sensors =0 ; + fmd->num_flashes =0 ; ret =v4l2_async_notifier_register (&fmd->v4l2_dev, &fmd->subdev_notifier);
drivers/media/platform/exynos4-is/media-dev.h +12 -1
@@ -34,6 +34,8 @@#define FIMC_MAX_SENSORS 4#define FIMC_MAX_CAMCLKS 2 +#define FIMC_MAX_FLASHES 2 +#define FIMC_MAX_ASYNC_SUBDEVS (FIMC_MAX_SENSORS + FIMC_MAX_FLASHES)#define DEFAULT_SENSOR_CLK_FREQ 24000000U/* LCD/ISP Writeback clocks (PIXELASYNCMx) */
@@ -93,6 +95,11 @@ struct fimc_sensor_info {struct fimc_dev *host; }; +struct fimc_flash_info { +struct v4l2_subdev *subdev; +struct v4l2_async_subdev asd; +}; +struct cam_clk {struct clk_hw hw;struct fimc_md *fmd;
@@ -104,6 +111,8 @@ struct cam_clk {* @csis: MIPI CSIS subdevs data * @sensor: array of registered sensor subdevs * @num_sensors: actual number of registered sensors +* @flash: array of registered flash subdevs +* @num_flashes: actual number of registered flashes * @camclk: external sensor clock information * @fimc: array of registered fimc devices * @fimc_is: fimc-is data structure
@@ -123,6 +132,8 @@ struct fimc_md {struct fimc_csis_info csis[CSIS_MAX_ENTITIES ];struct fimc_sensor_info sensor[FIMC_MAX_SENSORS ];int num_sensors; +struct fimc_flash_info flash[FIMC_MAX_FLASHES ]; +int num_flashes;struct fimc_camclk_info camclk[FIMC_MAX_CAMCLKS ];struct clk *wbclk[FIMC_MAX_WBCLKS ];struct fimc_lite *fimc_lite[FIMC_LITE_MAX_DEVS ];
@@ -149,7 +160,7 @@ struct fimc_md { } clk_provider;struct v4l2_async_notifier subdev_notifier; -struct v4l2_async_subdev *async_subdevs[FIMC_MAX_SENSORS ]; +struct v4l2_async_subdev *async_subdevs[FIMC_MAX_ASYNC_SUBDEVS ];bool user_subdev_api;spinlock_t slock;
Signature · 1 line
1.7.9.5
Quoted 6 lines · Jacek Anaszewski
This patch set is the follow-up of the LED / flash API integration series [1]. For clarity reasons the patchset has been split into four subsets:
- LED Flash Class
- V4L2 Flash
Hi Jacek,
For this series I think you'd better get review by V4L2 core developer. I don't have much experience about this V4L2 APIs. But generally I think you should make sure we merge those 3 patches for LED FLASH class firstly. And this wrapper patchset can be merged later.
-Bryan
Quoted 39 lines
- LED Flash Class drivers
- Documentation========================
Changes since version 5:
========================- removed flash manager framework - its implementation needs further thorough discussion.
- removed external strobe facilities from the LED Flash Class and providedexternal_strobe_setop in v4l2-flash. LED subsystem should be strobe provider agnostic.Thanks,
Jacek Anaszewski[1] https://lkml.org/lkml/2014/7/11/914
Jacek Anaszewski (2):
media: Add registration helpers for V4L2 flash
exynos4-is: Add support for v4l2-flash subdevsdrivers/media/platform/exynos4-is/media-dev.c | 36 +- drivers/media/platform/exynos4-is/media-dev.h | 13 +- drivers/media/v4l2-core/Kconfig | 11 + drivers/media/v4l2-core/Makefile | 2 + drivers/media/v4l2-core/v4l2-flash.c | 502 +++++++++++++++++++++++++ include/media/v4l2-flash.h | 135 +++++++ 6 files changed, 696 insertions(+), 3 deletions(-) create mode 100644 drivers/media/v4l2-core/v4l2-flash.c create mode 100644 include/media/v4l2-flash.h--
1.7.9.5--
To unsubscribe from this list: send the line "unsubscribe linux-leds" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html