Skip to contentSkip to conversation

LED / flash API integration

PATCH Superseded Jacek Anaszewski 5 participants 55 messages Jul 11, 2014 – Aug 21, 2014

Subsystems (8)

v4 of 13 Superseded Latest is v13 →

lore
Share & tools
lore
#0 lore raw

v4 cover LED / flash API integration

This is is the fourth version of the patch series being a follow up of the discussion on Media summit 2013-10-23, related to the LED / flash API integration (the notes from the discussion were enclosed in the message [1], paragraph 5).
The series is based on linux-next-20140707

Description of the proposed modifications according to
the kernel components they are relevant to:
- LED subsystem modifications
* added led_flash module which, when enabled in the config, registers flash specific sysfs attributes, if the driver declares related features:
- flash_brightness
- max_flash_brightness
- indicator_brightness
- max_indicator_brightness
- flash_timeout
- max_flash_timeout
- flash_strobe
- external_strobe
- flash_fault
and exposes kernel internal API:
- led_classdev_flash_register
- led_classdev_flash_unregister
- led_set_flash_strobe
- led_get_flash_strobe
- led_set_flash_brightness
- led_update_flash_brightness
- led_set_indicator_brightness
- led_update_indicator_brightness
- led_set_flash_timeout
- led_get_flash_fault
- led_set_external_strobe
- led_sysfs_lock
- led_sysfs_unlock
* added Flash Manager functionality, available when led_flash module is enable in the config;
if the device tree node of a flash led device contains relevant subnodes, it registers following sysfs attributes:
- strobe_provider
- strobe_providerN
- blocking_strobe
following kernel internal API is exposed by the flash manager:
- led_flash_manager_register_flash
- led_flash_manager_unregister_flash
- led_flash_manager_setup_strobe
- led_flash_manager_bind_async_mux
- led_flash_manager_unbind_async_mux
- Addition of a V4L2 Flash sub-device registration helpers
* added v4l2-flash.c and v4l2-flash.h files with helper functions that facilitate registration/unregistration of a subdevice, which wrapps a LED subsystem device and exposes V4L2 Flash control interface
- Addition of a LED Flash Class driver for the flash cell of the MAX77693 mfd
- Addition of a LED Flash Class driver for the AAT1290 current regulator for flash leds along with its DT binding for the exynos4412-trats2 board, where standalone multiplexer is used for modifying strobe signal routing - either from the SoC GPIO or from a camera sensor. This arrangment is handled by the newly introduced Flash Manager functionality.
- Update of the max77693.txt DT bindings documentation
- Update of the common leds DT bindings documentation

================
Changes since v2
================

- refactored the code so that it is possible to build led-core without led-flash module
- added v4l2-flash ops which slackens dependency from the led-flash module
- implemented led_clamp_align_val function and led_ctrl structure which allows to align led control values in the manner compatible with V4L2 Flash controls; the flash brightness and timeout units have been defined as microamperes and microseconds respectively to properly support devices which define current and time levels as fractions of 1/1000.
- added support for the flash privacy leds
- modified LED sysfs locking mechanism - now it locks/unlocks the interface on V4L2 Flash sub-device file open/close
- changed hw_triggered attribute name to external_strobe, which maps on the V4L2_FLASH_STROBE_SOURCE_EXTERNAL name more intuitively
- made external_strobe and indicator related sysfs attributes created optionally only if related features are declared by the led device driver
- removed from the series patches modifying exynos4-is media controller - a proposal for "flash manager" which will take care of flash devices registration is due to be submitted
- removed modifications to the LED class devices documentation, it will be covered after the whole functionality is accepted

================
Changes since v3
================

- added Flash Manager feature
- added generic LED Flash Class gpio mux driver
- added sample async mux driver
- added of helpers for parsing Flash Manager related device tree data
- added V4L2_CID_FLASH_STROBE_PROVIDER control
- introduced struct led_classdev_flash, which wrapps struct led_classdev
- made all flash ops, except strobe_set, optional; if an op is absent the related sysfs attribute isn't created
- added LED_DEV_CAP* flags
- modified v4l2-flash helpers to create v4l2_device for v4l2_flash subdevices to register in it
- modified max77693-flash driver and its DT bindings to allow for registering either one or two LED Flash Class devices, depending on the device tree settings.
- added new API for setting torch_brightness
- extended leds common DT binding documentation

Issues:

1) Who should register V4L2 Flash sub-device?

LED Flash Class devices, after introduction of the Flash Manager, are not tightly coupled with any media controller. They are maintained by the Flash Manager and made available for dynamic assignment to any media system they are connected to through multiplexing devices.

In the proposed rough solution, when support for V4L2 Flash sub-devices is enabled, there is a v4l2_device created for them to register in. This however implies that V4L2 Flash device will not be available in any media controller, which calls its existence into question.

Therefore I'd like to consult possible ways of solving this issue. The option I see is implementing a mechanism for moving V4L2 Flash sub-devices between media controllers. A V4L2 Flash sub-device would initially be assigned to one media system in the relevant device tree binding, but it could be dynamically reassigned to the other one. However I'm not sure if media controller design is prepared for dynamic modifications of its graph and how many modifications in the existing drivers this solution would require.

2) Consequences of locking the Flash Manager during flash strobe

In case a LED Flash Class device depends on muxes involved in routing the other LED Flash Class device's strobe signals, the Flash Manager must be locked for the time of strobing to prevent reconfiguration of the strobe signal routing by the other device.

A blocking_strobe sysfs attribute was added to indicate whether this is the case for the device.

Nonetheless, this modifies behaviour of led_set_external_strobe API, which also must block the caller for the time of strobing to protect the strobe signal routing while the external strobe signal provider asserts the flash_en pin.

Use case for user space application would be following in this case:
- spawn a new thread in which external strobe is activated
- in the parent thread instruct the external strobe provider to strobe the flash

As an improvement there could be an op added for notifying
the application that the strobe signal routing has been
set up. It would have to be called from the function led_flash_manager_setup_strobe after led_flash_manager_set_external_strobe returns.

The blocking_strobe attribute would have to be also mapped to a new V4L2 Flash control. Unfortunately it poses a problem for the existing users of the V4L2 Flash API which are not aware that setting V4L2_CID_FLASH_STROBE_SOURCE may be blocking.

As a solution led_set_external_strobe API could be extended by a parameter telling whether the caller is prepared for the blocking call. led_flash_manager_setup_strobe should be extended accordingly then.
In V4L2 "V4L2_FLASH_STROBE_SOURCE_EXTERNAL_BLOCKING" menu item could be added to handle this.
With existing V4L2_FLASH_STROBE_SOURCE_EXTERNAL the flash manager wouldn't protect muxes against reconfiguration.

TODO:
- switch to using V4L2 array controls
- add s_power op to the LED Flash Class

I will be off-line for three weeks from now on and will respond to any questions after getting back.

Thanks,
Jacek Anaszewski

Jacek Anaszewski (21):
leds: make brightness type consistent across whole subsystem
leds: implement sysfs interface locking mechanism
leds: Improve and export led_update_brightness
leds: Reorder include directives
leds: avoid using deprecated DEVICE_ATTR macro
leds: add API for setting torch brightness
of: add of_node_ncmp wrapper
leds: Add sysfs and kernel internal API for flash LEDs
Documentation: leds: Add description of LED Flash Class extension
Documentation: leds: add exemplary asynchronous mux driver
DT: leds: Add flash led devices related properties
DT: Add documentation for LED Class Flash Manger
v4l2-device: add v4l2_device_register_subdev_node API
v4l2-ctrls: add control for flash strobe signal providers
media: Add registration helpers for V4L2 flash
leds: Add support for max77693 mfd flash cell
DT: Add documentation for the mfd Maxim max77693
leds: Add driver for AAT1290 current regulator
of: Add Skyworks Solutions, Inc. vendor prefix
DT: Add documentation for the Skyworks AAT1290
ARM: dts: add aat1290 current regulator device node

 Documentation/DocBook/media/v4l/controls.xml       |   11 +
 Documentation/devicetree/bindings/leds/common.txt  |   16 +
 .../devicetree/bindings/leds/leds-aat1290.txt      |   17 +
 .../bindings/leds/leds-flash-manager.txt           |  165 +++
 Documentation/devicetree/bindings/mfd/max77693.txt |   62 ++
 .../devicetree/bindings/vendor-prefixes.txt        |    1 +
 Documentation/leds/leds-async-mux.c                |   65 ++
 Documentation/leds/leds-class-flash.txt            |  126 +++
 arch/arm/boot/dts/exynos4412-trats2.dts            |   24 +
 drivers/leds/Kconfig                               |   28 +
 drivers/leds/Makefile                              |    7 +
 drivers/leds/led-class-flash.c                     |  715 +++++++++++++
 drivers/leds/led-class.c                           |   58 +-
 drivers/leds/led-core.c                            |   51 +-
 drivers/leds/led-flash-gpio-mux.c                  |  102 ++
 drivers/leds/led-flash-manager.c                   |  698 +++++++++++++
 drivers/leds/led-triggers.c                        |   16 +-
 drivers/leds/leds-aat1290.c                        |  455 +++++++++
 drivers/leds/leds-max77693.c                       | 1070 ++++++++++++++++++++
 drivers/leds/of_led_flash_manager.c                |  155 +++
 drivers/media/v4l2-core/Kconfig                    |   11 +
 drivers/media/v4l2-core/Makefile                   |    2 +
 drivers/media/v4l2-core/v4l2-ctrls.c               |    2 +
 drivers/media/v4l2-core/v4l2-device.c              |   63 +-
 drivers/media/v4l2-core/v4l2-flash.c               |  580 +++++++++++
 drivers/mfd/max77693.c                             |    5 +-
 include/linux/led-class-flash.h                    |  290 ++++++
 include/linux/led-flash-gpio-mux.h                 |   68 ++
 include/linux/led-flash-manager.h                  |  121 +++
 include/linux/leds.h                               |   73 +-
 include/linux/mfd/max77693.h                       |   40 +
 include/linux/of.h                                 |    1 +
 include/linux/of_led_flash_manager.h               |   80 ++
 include/media/v4l2-device.h                        |    7 +
 include/media/v4l2-flash.h                         |  137 +++
 include/uapi/linux/v4l2-controls.h                 |    2 +
 36 files changed, 5272 insertions(+), 52 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/leds/leds-aat1290.txt
 create mode 100644 Documentation/devicetree/bindings/leds/leds-flash-manager.txt
 create mode 100644 Documentation/leds/leds-async-mux.c
 create mode 100644 Documentation/leds/leds-class-flash.txt
 create mode 100644 drivers/leds/led-class-flash.c
 create mode 100644 drivers/leds/led-flash-gpio-mux.c
 create mode 100644 drivers/leds/led-flash-manager.c
 create mode 100644 drivers/leds/leds-aat1290.c
 create mode 100644 drivers/leds/leds-max77693.c
 create mode 100644 drivers/leds/of_led_flash_manager.c
 create mode 100644 drivers/media/v4l2-core/v4l2-flash.c
 create mode 100644 include/linux/led-class-flash.h
 create mode 100644 include/linux/led-flash-gpio-mux.h
 create mode 100644 include/linux/led-flash-manager.h
 create mode 100644 include/linux/of_led_flash_manager.h
 create mode 100644 include/media/v4l2-flash.h
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH v4 1/21 leds: make brightness type consistent across whole subsystem

Documentations states that brightness units type is enum led_brightness and this is the type used by the led API functions. Adjust the type of brightness variables in the struct led_classdev accordingly.

---
 include/linux/leds.h |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/leds.h +2 -2
index e436864..995f933 100644
@@ -31,8 +31,8 @@ enum led_brightness {
 
 struct led_classdev {
 	const char		*name;
-	int			 brightness;
-	int			 max_brightness;
+	enum led_brightness	 brightness;
+	enum led_brightness	 max_brightness;
 	int			 flags;
 
 	/* Lower 16 bits reflect status */
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH v4 2/21 leds: implement sysfs interface locking mechanism

In reply to Jacek Anaszewski

Add mechanism for locking LED subsystem sysfs interface. This patch prepares ground for addition of LED Flash Class extension.

---
 drivers/leds/led-class.c    |   13 +++++++++++--
 drivers/leds/led-core.c     |   18 ++++++++++++++++++
 drivers/leds/led-triggers.c |   11 ++++++++---
 include/linux/leds.h        |   31 +++++++++++++++++++++++++++++++
 4 files changed, 68 insertions(+), 5 deletions(-)
drivers/leds/led-class.c +11 -2
index aa29198..ea04891 100644
@@ -45,17 +45,23 @@ static ssize_t brightness_store(struct device *dev,
 {
 	struct led_classdev *led_cdev = dev_get_drvdata(dev);
 	unsigned long state;
-	ssize_t ret = -EINVAL;
+	ssize_t ret;
+
+	mutex_lock(&led_cdev->led_lock);
 
 	ret = kstrtoul(buf, 10, &state);
 	if (ret)
-		return ret;
+		goto unlock;
 
 	if (state == LED_OFF)
 		led_trigger_remove(led_cdev);
 	__led_set_brightness(led_cdev, state);
 
 	return size;
+	ret = size;
+unlock:
+	mutex_unlock(&led_cdev->led_lock);
+	return ret;
 }
 static DEVICE_ATTR_RW(brightness);
 
@@ -219,6 +225,7 @@ int led_classdev_register(struct device *parent, struct led_classdev *led_cdev)
 #ifdef CONFIG_LEDS_TRIGGERS
 	init_rwsem(&led_cdev->trigger_lock);
 #endif
+	mutex_init(&led_cdev->led_lock);
 	/* add to the list of leds */
 	down_write(&leds_list_lock);
 	list_add_tail(&led_cdev->node, &leds_list);
@@ -272,6 +279,8 @@ void led_classdev_unregister(struct led_classdev *led_cdev)
 	down_write(&leds_list_lock);
 	list_del(&led_cdev->node);
 	up_write(&leds_list_lock);
+
+	mutex_destroy(&led_cdev->led_lock);
 }
 EXPORT_SYMBOL_GPL(led_classdev_unregister);
 
drivers/leds/led-core.c +18 -0
index 71b40d3..4d7cb31 100644
@@ -126,3 +126,21 @@ void led_set_brightness(struct led_classdev *led_cdev,
 	__led_set_brightness(led_cdev, brightness);
 }
 EXPORT_SYMBOL(led_set_brightness);
+
+/* Caller must ensure led_cdev->led_lock held */
+void led_sysfs_lock(struct led_classdev *led_cdev)
+{
+	WARN_ON(!mutex_is_locked(&led_cdev->led_lock));
+
+	led_cdev->flags |= LED_SYSFS_LOCK;
+}
+EXPORT_SYMBOL_GPL(led_sysfs_lock);
+
+/* Caller must ensure led_cdev->led_lock held */
+void led_sysfs_unlock(struct led_classdev *led_cdev)
+{
+	WARN_ON(!mutex_is_locked(&led_cdev->led_lock));
+
+	led_cdev->flags &= ~LED_SYSFS_LOCK;
+}
+EXPORT_SYMBOL_GPL(led_sysfs_unlock);
drivers/leds/led-triggers.c +8 -3
index c3734f1..0545530 100644
@@ -37,6 +37,9 @@ ssize_t led_trigger_store(struct device *dev, struct device_attribute *attr,
 	char trigger_name[TRIG_NAME_MAX];
 	struct led_trigger *trig;
 	size_t len;
+	int ret = count;
+
+	mutex_lock(&led_cdev->led_lock);
 
 	trigger_name[sizeof(trigger_name) - 1] = '\0';
 	strncpy(trigger_name, buf, sizeof(trigger_name) - 1);
@@ -47,7 +50,7 @@ ssize_t led_trigger_store(struct device *dev, struct device_attribute *attr,
 
 	if (!strcmp(trigger_name, "none")) {
 		led_trigger_remove(led_cdev);
-		return count;
+		goto exit_unlock;
 	}
 
 	down_read(&triggers_list_lock);
@@ -58,12 +61,14 @@ ssize_t led_trigger_store(struct device *dev, struct device_attribute *attr,
 			up_write(&led_cdev->trigger_lock);
 
 			up_read(&triggers_list_lock);
-			return count;
+			goto exit_unlock;
 		}
 	}
 	up_read(&triggers_list_lock);
 
-	return -EINVAL;
+exit_unlock:
+	mutex_unlock(&led_cdev->led_lock);
+	return ret;
 }
 EXPORT_SYMBOL_GPL(led_trigger_store);
 
include/linux/leds.h +31 -0
index 995f933..da7c6b5 100644
@@ -13,6 +13,7 @@
 #define __LINUX_LEDS_H_INCLUDED
 
 #include <linux/list.h>
+#include <linux/mutex.h>
 #include <linux/spinlock.h>
 #include <linux/rwsem.h>
 #include <linux/timer.h>
@@ -42,6 +43,7 @@ struct led_classdev {
 #define LED_BLINK_ONESHOT	(1 << 17)
 #define LED_BLINK_ONESHOT_STOP	(1 << 18)
 #define LED_BLINK_INVERT	(1 << 19)
+#define LED_SYSFS_LOCK		(1 << 20)
 
 	/* Set LED brightness level */
 	/* Must not sleep, use a workqueue if needed */
@@ -85,6 +87,9 @@ struct led_classdev {
 	/* true if activated - deactivate routine uses it to do cleanup */
 	bool			activated;
 #endif
+
+	/* Ensures consistent access to the LED Flash Class device */
+	struct mutex		led_lock;
 };
 
 extern int led_classdev_register(struct device *parent,
@@ -140,6 +145,32 @@ extern void led_blink_set_oneshot(struct led_classdev *led_cdev,
  */
 extern void led_set_brightness(struct led_classdev *led_cdev,
 			       enum led_brightness brightness);
+/**
+ * led_sysfs_lock - lock LED sysfs interface
+ * @led_cdev: the LED to set
+ *
+ * Lock the LED's sysfs interface
+ */
+extern void led_sysfs_lock(struct led_classdev *led_cdev);
+
+/**
+ * led_sysfs_unlock - unlock LED sysfs interface
+ * @led_cdev: the LED to set
+ *
+ * Unlock the LED's sysfs interface
+ */
+extern void led_sysfs_unlock(struct led_classdev *led_cdev);
+
+/**
+ * led_sysfs_is_locked
+ * @led_cdev: the LED to query
+ *
+ * Returns: true if the sysfs interface of the led is locked
+ */
+static inline bool led_sysfs_is_locked(struct led_classdev *led_cdev)
+{
+	return led_cdev->flags & LED_SYSFS_LOCK;
+}
 
 /*
  * LED Triggers
Signature · 1 line
1.7.9.5
#4 lore raw

PATCH v4 3/21 leds: Improve and export led_update_brightness

In reply to Jacek Anaszewski

led_update_brightness helper function used to be exploited only locally in the led-class.c module, where its result was being passed to the brightness_show sysfs callback. With the introduction of v4l2-flash subdevice the same functionality became required for reading current brightness from a LED device. This patch adds checking of return value of the brightness_get callback and moves the led_update_brightness() function to the LED subsystem public API.

---
 drivers/leds/led-class.c |    6 ------
 drivers/leds/led-core.c  |   15 +++++++++++++++
 include/linux/leds.h     |   10 ++++++++++
 3 files changed, 25 insertions(+), 6 deletions(-)
drivers/leds/led-class.c +0 -6
index ea04891..da79bbb 100644
@@ -23,12 +23,6 @@
 
 static struct class *leds_class;
 
-static void led_update_brightness(struct led_classdev *led_cdev)
-{
-	if (led_cdev->brightness_get)
-		led_cdev->brightness = led_cdev->brightness_get(led_cdev);
-}
-
 static ssize_t brightness_show(struct device *dev,
 		struct device_attribute *attr, char *buf)
 {
drivers/leds/led-core.c +15 -0
index 4d7cb31..0ac06ed 100644
@@ -127,6 +127,21 @@ void led_set_brightness(struct led_classdev *led_cdev,
 }
 EXPORT_SYMBOL(led_set_brightness);
 
+int led_update_brightness(struct led_classdev *led_cdev)
+{
+	int ret = 0;
+
+	if (led_cdev->brightness_get) {
+		ret = led_cdev->brightness_get(led_cdev);
+		if (ret >= 0) {
+			led_cdev->brightness = ret;
+			return 0;
+		}
+	}
+
+	return ret;
+}
+EXPORT_SYMBOL(led_update_brightness);
 /* Caller must ensure led_cdev->led_lock held */
 void led_sysfs_lock(struct led_classdev *led_cdev)
 {
include/linux/leds.h +10 -0
index da7c6b5..e9b025d 100644
@@ -146,6 +146,16 @@ extern void led_blink_set_oneshot(struct led_classdev *led_cdev,
 extern void led_set_brightness(struct led_classdev *led_cdev,
 			       enum led_brightness brightness);
 /**
+ * led_update_brightness - update LED brightness
+ * @led_cdev: the LED to query
+ *
+ * Get an LED's current brightness and update led_cdev->brightness
+ * member with the obtained value.
+ *
+ * Returns: 0 on success or negative error value on failure
+ */
+extern int led_update_brightness(struct led_classdev *led_cdev);
+
  * led_sysfs_lock - lock LED sysfs interface
  * @led_cdev: the LED to set
  *
Signature · 1 line
1.7.9.5
#5 lore raw

PATCH v4 4/21 leds: Reorder include directives

In reply to Jacek Anaszewski

Reorder include directives so that they are arranged in alphabetical order.

---
 drivers/leds/led-class.c |   13 +++++++------
 drivers/leds/led-core.c  |    3 ++-
 include/linux/leds.h     |    2 +-
 3 files changed, 10 insertions(+), 8 deletions(-)
drivers/leds/led-class.c +7 -6
index da79bbb..0127783 100644
@@ -9,16 +9,17 @@
  * published by the Free Software Foundation.
  */
 
-#include <linux/module.h>
-#include <linux/kernel.h>
+#include <linux/ctype.h>
+#include <linux/device.h>
+#include <linux/err.h>
 #include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/leds.h>
 #include <linux/list.h>
+#include <linux/module.h>
+#include <linux/slab.h>
 #include <linux/spinlock.h>
-#include <linux/device.h>
 #include <linux/timer.h>
-#include <linux/err.h>
-#include <linux/ctype.h>
-#include <linux/leds.h>
 #include "leds.h"
 
 static struct class *leds_class;
drivers/leds/led-core.c +2 -1
index 0ac06ed..d156fb6 100644
@@ -12,10 +12,11 @@
  */
 
 #include <linux/kernel.h>
+#include <linux/leds.h>
 #include <linux/list.h>
 #include <linux/module.h>
+#include <linux/mutex.h>
 #include <linux/rwsem.h>
-#include <linux/leds.h>
 #include "leds.h"
 
 DECLARE_RWSEM(leds_list_lock);
include/linux/leds.h +1 -1
index e9b025d..1a130cc 100644
@@ -14,8 +14,8 @@
 
 #include <linux/list.h>
 #include <linux/mutex.h>
-#include <linux/spinlock.h>
 #include <linux/rwsem.h>
+#include <linux/spinlock.h>
 #include <linux/timer.h>
 #include <linux/workqueue.h>
 
Signature · 1 line
1.7.9.5
#7 lore raw

PATCH v4 5/21 leds: avoid using deprecated DEVICE_ATTR macro

In reply to Jacek Anaszewski

Make the sysfs attributes definition consistent in the whole file. The modification entails change of the function name:
led_max_brightness_show -> max_brightness_show

---
 drivers/leds/led-class.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/leds/led-class.c +2 -2
index 0127783..a96a1a7 100644
@@ -60,14 +60,14 @@ unlock:
 }
 static DEVICE_ATTR_RW(brightness);
 
-static ssize_t led_max_brightness_show(struct device *dev,
+static ssize_t max_brightness_show(struct device *dev,
 		struct device_attribute *attr, char *buf)
 {
 	struct led_classdev *led_cdev = dev_get_drvdata(dev);
 
 	return sprintf(buf, "%u\n", led_cdev->max_brightness);
 }
-static DEVICE_ATTR(max_brightness, 0444, led_max_brightness_show, NULL);
+static DEVICE_ATTR_RO(max_brightness);
 
 #ifdef CONFIG_LEDS_TRIGGERS
 static DEVICE_ATTR(trigger, 0644, led_trigger_show, led_trigger_store);
Signature · 1 line
1.7.9.5
#9 lore raw

PATCH v4 6/21 leds: add API for setting torch brightness

In reply to Jacek Anaszewski

This patch prepares ground for addition of LED Flash Class extension to the LED subsystem. Since turning the torch on must have guaranteed immediate effect the brightness_set op can't be used for it. Drivers must schedule a work queue task in this op to be compatible with led-triggers, which call brightess_set from timer irqs. In order to address this limitiation a torch_brightness_set op and led_set_torch_brightness API is introduced. Setting brightness sysfs attribute will result in calling brightness_set op for LED Class decices and torch_brightness_set op for LED Flash Class devices, whereas triggers will still call brightness op in both cases.

---
 drivers/leds/led-class.c |   18 ++++++++++++++++--
 drivers/leds/led-core.c  |   15 +++++++++++++++
 include/linux/leds.h     |   22 ++++++++++++++++++++++
 3 files changed, 53 insertions(+), 2 deletions(-)
drivers/leds/led-class.c +16 -2
index a96a1a7..c17dda0 100644
@@ -44,15 +44,29 @@ static ssize_t brightness_store(struct device *dev,
 
 	mutex_lock(&led_cdev->led_lock);
 
+	/*
+	 * Having LED_DEV_CAP_TORCH implies this is LED Flash Class
+	 * device and we need to check sysfs accessibility.
+	 */
+	if (led_cdev->flags & LED_DEV_CAP_TORCH) {
+		if (led_sysfs_is_locked(led_cdev)) {
+			ret = -EBUSY;
+			goto unlock;
+		}
+	}
+
 	ret = kstrtoul(buf, 10, &state);
 	if (ret)
 		goto unlock;
 
 	if (state == LED_OFF)
 		led_trigger_remove(led_cdev);
-	__led_set_brightness(led_cdev, state);
 
-	return size;
+	if (led_cdev->flags & LED_DEV_CAP_TORCH)
+		ret = led_set_torch_brightness(led_cdev, state);
+	else
+		__led_set_brightness(led_cdev, state);
+
 	ret = size;
 unlock:
 	mutex_unlock(&led_cdev->led_lock);
drivers/leds/led-core.c +15 -0
index d156fb6..0ce087a 100644
@@ -143,6 +143,21 @@ int led_update_brightness(struct led_classdev *led_cdev)
 	return ret;
 }
 EXPORT_SYMBOL(led_update_brightness);
+
+int led_set_torch_brightness(struct led_classdev *led_cdev,
+				enum led_brightness brightness)
+{
+	int ret = 0;
+
+	led_cdev->brightness = min(brightness, led_cdev->max_brightness);
+
+	if (!(led_cdev->flags & LED_SUSPENDED))
+		ret = led_cdev->torch_brightness_set(led_cdev,
+						     led_cdev->brightness);
+	return ret;
+}
+EXPORT_SYMBOL_GPL(led_set_torch_brightness);
+
 /* Caller must ensure led_cdev->led_lock held */
 void led_sysfs_lock(struct led_classdev *led_cdev)
 {
include/linux/leds.h +22 -0
index 1a130cc..9bea9e6 100644
@@ -44,11 +44,21 @@ struct led_classdev {
 #define LED_BLINK_ONESHOT_STOP	(1 << 18)
 #define LED_BLINK_INVERT	(1 << 19)
 #define LED_SYSFS_LOCK		(1 << 20)
+#define LED_DEV_CAP_TORCH	(1 << 21)
 
 	/* Set LED brightness level */
 	/* Must not sleep, use a workqueue if needed */
 	void		(*brightness_set)(struct led_classdev *led_cdev,
 					  enum led_brightness brightness);
+	/*
+	 * Set LED brightness immediately - it is required for flash led
+	 * devices as they require setting torch brightness to have immediate
+	 * effect. brightness_set op cannot be used for this purpose because
+	 * the led drivers schedule a work queue task in it to allow for
+	 * being called from led-triggers, i.e. from the timer irq context.
+	 */
+	int		(*torch_brightness_set)(struct led_classdev *led_cdev,
+					enum led_brightness brightness);
 	/* Get LED brightness level */
 	enum led_brightness (*brightness_get)(struct led_classdev *led_cdev);
 
@@ -156,6 +166,18 @@ extern void led_set_brightness(struct led_classdev *led_cdev,
  */
 extern int led_update_brightness(struct led_classdev *led_cdev);
 
+/**
+ * led_set_torch_brightness - set torch LED brightness
+ * @led_cdev: the LED to set
+ * @brightness: the brightness to set it to
+ *
+ * Returns: 0 on success or negative error value on failure
+ *
+ * Set a torch LED's brightness.
+ */
+extern int led_set_torch_brightness(struct led_classdev *led_cdev,
+					enum led_brightness brightness);
+/**
  * led_sysfs_lock - lock LED sysfs interface
  * @led_cdev: the LED to set
  *
Signature · 1 line
1.7.9.5
#17 lore raw

PATCH v4 7/21 of: add of_node_ncmp wrapper

In reply to Jacek Anaszewski

The wrapper for strnicmp is required for checking whether a node has expected prefix.

Cc Grant Likely <[email protected]>
Cc Benjamin Herrenschmidt <[email protected]>
Cc Michal Simek <[email protected]>
---
 include/linux/of.h |    1 +
 1 file changed, 1 insertion(+)
include/linux/of.h +1 -0
index 692b56c..9a53eea 100644
@@ -199,6 +199,7 @@ static inline unsigned long of_read_ulong(const __be32 *cell, int size)
 #define of_compat_cmp(s1, s2, l)	strcasecmp((s1), (s2))
 #define of_prop_cmp(s1, s2)		strcmp((s1), (s2))
 #define of_node_cmp(s1, s2)		strcasecmp((s1), (s2))
+#define of_node_ncmp(s1, s2, n)		strnicmp((s1), (s2), (n))
 #endif
 
 /* flag descriptions */
Signature · 1 line
1.7.9.5
#20 lore raw

PATCH v4 8/21 leds: Add sysfs and kernel internal API for flash LEDs

In reply to Jacek Anaszewski

Some LED devices support two operation modes - torch and flash. This patch provides support for flash LED devices in the LED subsystem by introducing new sysfs attributes and kernel internal interface. The attributes being introduced are: flash_brightness, flash_strobe, flash_timeout, max_flash_timeout, max_flash_brightness, flash_fault, external_strobe, indicator_brightness, max_indicator_brightness, strobe_provider, strobe_providerN, blocking_strobe. All the flash related features are placed in a separate module.

The modifications aim to be compatible with V4L2 framework requirements related to the flash devices management. The design assumes that V4L2 sub-device can take of the LED class device control and communicate with it through the kernel internal interface. When V4L2 Flash sub-device file is opened, the LED class device sysfs interface is made unavailable.

---
 drivers/leds/Kconfig                 |   13 +
 drivers/leds/Makefile                |    5 +
 drivers/leds/led-class-flash.c       |  715 ++++++++++++++++++++++++++++++++++
 drivers/leds/led-class.c             |    4 +
 drivers/leds/led-flash-gpio-mux.c    |  102 +++++
 drivers/leds/led-flash-manager.c     |  698 +++++++++++++++++++++++++++++++++
 drivers/leds/led-triggers.c          |    5 +
 drivers/leds/of_led_flash_manager.c  |  155 ++++++++
 include/linux/led-class-flash.h      |  290 ++++++++++++++
 include/linux/led-flash-gpio-mux.h   |   68 ++++
 include/linux/led-flash-manager.h    |  121 ++++++
 include/linux/leds.h                 |    4 +
 include/linux/of_led_flash_manager.h |   80 ++++
 13 files changed, 2260 insertions(+)
 create mode 100644 drivers/leds/led-class-flash.c
 create mode 100644 drivers/leds/led-flash-gpio-mux.c
 create mode 100644 drivers/leds/led-flash-manager.c
 create mode 100644 drivers/leds/of_led_flash_manager.c
 create mode 100644 include/linux/led-class-flash.h
 create mode 100644 include/linux/led-flash-gpio-mux.h
 create mode 100644 include/linux/led-flash-manager.h
 create mode 100644 include/linux/of_led_flash_manager.h
drivers/leds/Kconfig +13 -0
index 6784c17..5032c6f 100644
@@ -19,6 +19,19 @@ config LEDS_CLASS
 	  This option enables the led sysfs class in /sys/class/leds.  You'll
 	  need this to do anything useful with LEDs.  If unsure, say N.
 
+config LEDS_CLASS_FLASH
+	tristate "LED Flash Class Support"
+	depends on LEDS_CLASS
+	depends on OF
+	help
+	  This option enables the flash led sysfs class in /sys/class/leds.
+	  It wrapps LED Class and adds flash LEDs specific sysfs attributes
+	  and kernel internal API to it. It allows also for dynamic routing
+	  of external strobe signals basing on the information provided
+	  in the Device Tree binding. You'll need this to provide support
+	  for the flash related features of a LED device. It can be built
+	  as a module.
+
 comment "LED drivers"
 
 config LEDS_88PM860X
drivers/leds/Makefile +5 -0
index 79c5155..237c5ba 100644
@@ -2,6 +2,11 @@
 # LED Core
 obj-$(CONFIG_NEW_LEDS)			+= led-core.o
 obj-$(CONFIG_LEDS_CLASS)		+= led-class.o
+obj-$(CONFIG_LEDS_CLASS_FLASH)		+= led-flash.o
+led-flash-objs				:= led-class-flash.o \
+					   led-flash-manager.o \
+					   led-flash-gpio-mux.o \
+					   of_led_flash_manager.o
 obj-$(CONFIG_LEDS_TRIGGERS)		+= led-triggers.o
 
 # LED Platform Drivers
drivers/leds/led-class-flash.c new file +715 -0

715 lines not on this page · raw message

drivers/leds/led-class.c +4 -0
index c17dda0..165a1fb 100644
@@ -189,6 +189,10 @@ EXPORT_SYMBOL_GPL(led_classdev_suspend);
 void led_classdev_resume(struct led_classdev *led_cdev)
 {
 	led_cdev->brightness_set(led_cdev, led_cdev->brightness);
+
+	if (led_cdev->flash_resume)
+		led_cdev->flash_resume(led_cdev);
+
 	led_cdev->flags &= ~LED_SUSPENDED;
 }
 EXPORT_SYMBOL_GPL(led_classdev_resume);
drivers/leds/led-flash-gpio-mux.c new file +102 -0

102 lines not on this page · raw message

drivers/leds/led-flash-manager.c new file +698 -0

698 lines not on this page · raw message

drivers/leds/led-triggers.c +5 -0
index 0545530..e8380bb 100644
@@ -41,6 +41,11 @@ ssize_t led_trigger_store(struct device *dev, struct device_attribute *attr,
 
 	mutex_lock(&led_cdev->led_lock);
 
+	if (led_sysfs_is_locked(led_cdev)) {
+		ret = -EBUSY;
+		goto exit_unlock;
+	}
+
 	trigger_name[sizeof(trigger_name) - 1] = '\0';
 	strncpy(trigger_name, buf, sizeof(trigger_name) - 1);
 	len = strlen(trigger_name);
drivers/leds/of_led_flash_manager.c new file +155 -0

155 lines not on this page · raw message

include/linux/led-class-flash.h new file +290 -0

290 lines not on this page · raw message

include/linux/led-flash-gpio-mux.h new file +68 -0

68 lines not on this page · raw message

include/linux/led-flash-manager.h new file +121 -0

121 lines not on this page · raw message

include/linux/leds.h +4 -0
index 9bea9e6..1f12d36 100644
@@ -45,6 +45,9 @@ struct led_classdev {
 #define LED_BLINK_INVERT	(1 << 19)
 #define LED_SYSFS_LOCK		(1 << 20)
 #define LED_DEV_CAP_TORCH	(1 << 21)
+#define LED_DEV_CAP_FLASH	(1 << 22)
+#define LED_DEV_CAP_INDICATOR	(1 << 23)
+#define LED_DEV_CAP_FL_MANAGER	(1 << 24)
 
 	/* Set LED brightness level */
 	/* Must not sleep, use a workqueue if needed */
@@ -83,6 +86,7 @@ struct led_classdev {
 	unsigned long		 blink_delay_on, blink_delay_off;
 	struct timer_list	 blink_timer;
 	int			 blink_brightness;
+	void			(*flash_resume)(struct led_classdev *led_cdev);
 
 	struct work_struct	set_brightness_work;
 	int			delayed_set_value;
include/linux/of_led_flash_manager.h new file +80 -0

80 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#21 lore raw

PATCH v4 9/21 Documentation: leds: Add description of LED Flash Class extension

In reply to Jacek Anaszewski

The documentation being added contains overall description of the LED Flash Class and the related sysfs attributes. There are also chapters devoted specifically to the Flash Manager feature.

---
 Documentation/leds/leds-class-flash.txt |  126 +++++++++++++++++++++++++++++++
 1 file changed, 126 insertions(+)
 create mode 100644 Documentation/leds/leds-class-flash.txt
Documentation/leds/leds-class-flash.txt new file +126 -0
new file mode 100644
index 0000000..0927804
@@ -0,0 +1,126 @@
+
+Flash LED handling under Linux
+==============================
+
+Some LED devices support two modes - torch and flash. In order to enable
+support for flash LEDs the CONFIG_LEDS_CLASS_FLASH symbol must be defined
+in the kernel config. A flash LED driver must register in the LED subsystem
+with led_classdev_flash_register to gain flash capabilities.
+
+Following sysfs attributes are exposed for controlling flash led devices:
+
+	- flash_brightness - flash LED brightness in microamperes (RW)
+	- max_flash_brightness - maximum available flash LED brightness (RO)
+	- indicator_brightness - privacy LED brightness in microamperes (RW)
+	- max_indicator_brightness - maximum privacy LED brightness in
+				     microamperes (RO)
+	- flash_timeout - flash strobe duration in microseconds (RW)
+	- max_flash_timeout - maximum available flash strobe duration (RO)
+	- flash_strobe - flash strobe state (RW)
+	- external_strobe - some devices expose dedicated hardware pins for
+			    triggering a flash LED - this attribute allows to
+			    set this mode (RW)
+	- flash_fault - bitmask of flash faults that may have occurred,
+			possible flags are:
+		* 0x01 - flash controller voltage to the flash LED has exceeded
+			 the limit specific to the flash controller
+		* 0x02 - the flash strobe was still on when the timeout set by
+			 the user has expired; not all flash controllers may
+			 set this in all such conditions
+		* 0x04 - the flash controller has overheated
+		* 0x08 - the short circuit protection of the flash controller
+			 has been triggered
+		* 0x10 - current in the LED power supply has exceeded the limit
+			 specific to the flash controller
+		* 0x40 - flash controller voltage to the flash LED has been
+			 below the minimum limit specific to the flash
+		* 0x80 - the input voltage of the flash controller is below
+			 the limit under which strobing the flash at full
+			 current will not be possible. The condition persists
+			 until this flag is no longer set
+		* 0x100 - the temperature of the LED has exceeded its allowed
+			  upper limit
+
+The LED subsystem driver can be controlled also from the level of VideoForLinux2
+subsystem. In order to enable this the CONFIG_V4L2_FLASH_LED_CLASS symbol has to
+be defined in the kernel config. The driver must call v4l2_flash_init function
+to get registered in the V4L2 subsystem. On remove v4l2_flash_release function
+has to be called (see <media/v4l2-flash.h>).
+
+After proper initialization V4L2 Flash sub-device is created. The sub-device
+exposes a number of V4L2 controls. When the V4L2_CID_FLASH_LED_MODE control
+is set to V4L2_FLASH_LED_MODE_TORCH or V4L2_FLASH_LED_MODE_FLASH the
+LED subsystem sysfs interface becomes unavailable. The interface can be unlocked
+by setting the mode back to V4L2_FLASH_LED_MODE_NONE.
+
+
+Flash Manager
+=============
+
+Flash LED devices often provide two ways of strobing the flash: software
+(e.g. by setting a bit in a register) and hardware, by asserting dedicated pin,
+which is usually connected to a camera sensor device. There are also flash led
+devices which support only hardware strobing - in such cases a multiplexer
+device is employed to route the flash strobe signal either from the SoC GPIO or
+from the external strobe signal provider, e.g. camera sensor.
+Use of multiplexers allows also to change the flash-sensor connection
+dynamically if there is more than one flash or external strobe signal provider
+available on the board.
+
+In order to address the aforementioned cases the Flash Manager functionality
+has been introduced. Flash Manager is a part of LED Flash Class. It maintains
+information about flashes, software and external strobe signal providers and
+multiplexers that route strobe signals among them.
+
+To register a LED Flash Class device in the flash manager the device_node
+of a flash device has to be passed as the third argument to the
+led_classdev_flash_register function. The device_node is expected to include one
+gate-software-strobe subnode and at least one gate-external-strobeN subnode.
+Besides that there must defined a flash_muxes node aggregating all the
+multiplexers that can be referenced to by the flash led devices.
+(for mote details see Documentation/devicetree/bindings/leds/
+leds-flash-manager.txt).
+
+Flash manager adds following sysfs attributes to the LED Flash Clash
+device sysfs interface:
+
+	- strobe_provider - id of the external strobe signal provider associated
+                            with the flash led device. It is created only if
+			    there is more than one external strobe signal
+			    provider defined (RW).
+	- strobe_providerN - names of the strobe signal providers available
+			     for the flash led device, where N is the
+			     identifier of a strobe signal provider (RO)
+	- blocking_strobe - informs if enabling either software or external
+			    strobe will block the caller for the expected
+			    time of strobing (1 - true, 0 - false). The call
+			    needs to be blocking if the multiplexers involved
+			    in the strobe signal routing are connected to more
+			    than one flash led device. In such a case flash
+			    manager becomes locked for the expected time of
+			    strobing to prevent reconfigurarion of multiplexers
+			    by the other flash led devices willing to strobe
+			    in the same time (RO).
+
+
+LED Flash Class multiplexers
+============================
+
+Multiplexers are an indispensable part of the Flash Manager. Flash Manager has
+its own led_flash_gpio_mux* helpers for creating, releasing and operating on
+the simple gpio driven multiplexers (the ones whose lines are selected by
+changing the state of its selector pins) and the user doesn't have to bother
+with it.
+
+It is however possible that a more advanced device will be used for routing
+strobe signals. This kind of devices are known to the Flash Manager as
+"asynchronous muxes" and can be registered in runtime with use of
+led_flash_manager_bind_async_mux API and unregistered with
+led_flash_manager_unbind_async_mux. (see Documentation/leds/leds-async-mux.c
+for the exemplary implementation of the async mux driver).
+
+If a LED Flash Class device declares dependency on an async mux, then strobing
+the flash, or setting external strobe, will succeed only wnen the async mux
+has been bound to the Flash Manager. Async mux module, once bound, can be
+removed only after all LED Flash Class devices depending on it are unregistered
+from the Flash Manager.
Signature · 1 line
1.7.9.5
#22 lore raw

PATCH v4 10/21 Documentation: leds: add exemplary asynchronous mux driver

In reply to Jacek Anaszewski

Exemplary driver showing usage of the Flash Manager API for registering/unregistering asynchronous multiplexers

---
 Documentation/leds/leds-async-mux.c |   65 +++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)
 create mode 100644 Documentation/leds/leds-async-mux.c
Documentation/leds/leds-async-mux.c new file +65 -0
new file mode 100644
index 0000000..ee35d2f
@@ -0,0 +1,65 @@
+/*
+ * Exemplary driver showing usage of the Flash Manager API
+ * for registering/unregistering asynchronous multiplexers.
+ *
+ *	Copyright (C) 2014, 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/platform_device.h>
+#include <linux/module.h>
+#include <linux/led-class-flash.h>
+#include <linux/led-flash-manager.h>
+#include <linux/leds.h>
+#include <linux/of.h>
+
+static int led_async_mux_select_line(u32 line_id, void *mux)
+{
+	pr_info("led_async_mux_select_line line_id: %d\n", line_id);
+	return 0;
+}
+
+struct led_flash_mux_ops mux_ops = {
+	.select_line = led_async_mux_select_line,
+};
+
+static int led_async_mux_probe(struct platform_device *pdev)
+{
+	struct led_flash_mux mux;
+
+	mux.ops = &mux_ops;
+	mux.owner = THIS_MODULE;
+	mux.node = pdev->dev->of_node;
+
+	return led_flash_manager_bind_async_mux(&mux);
+}
+
+static int led_async_mux_remove(struct platform_device *pdev)
+{
+	return led_flash_manager_unbind_async_mux(pdev->dev->of_node);
+}
+
+static struct of_device_id led_async_mux_dt_match[] = {
+	{.compatible = "led-async-mux"},
+	{},
+};
+
+static struct platform_driver led_async_mux_driver = {
+	.probe		= led_async_mux_probe,
+	.remove		= led_async_mux_remove,
+	.driver		= {
+		.name		= "led-async-mux",
+		.owner		= THIS_MODULE,
+		.of_match_table = led_async_mux_dt_match,
+	},
+};
+
+module_platform_driver(led_async_mux_driver);
+
+MODULE_AUTHOR("Jacek Anaszewski <[email protected]>");
+MODULE_DESCRIPTION("LED async mux");
+MODULE_LICENSE("GPL");
Signature · 1 line
1.7.9.5
#23 lore raw

PATCH v4 11/21 DT: leds: Add flash led devices related properties

In reply to Jacek Anaszewski

Addition of a LED Flash Class extension entails the need for flash led specific device tree properties. The properties being added are:
iout-torch, iout-flash, iout-indicator and flash-timeout.

Cc Stephen Warren <[email protected]>
Cc Grant Likely <[email protected]>
Cc Rob Herring <[email protected]>
Cc Pawel Moll <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Kumar Gala <[email protected]>
---
 Documentation/devicetree/bindings/leds/common.txt |   16 ++++++++++++++++
 1 file changed, 16 insertions(+)
Documentation/devicetree/bindings/leds/common.txt +16 -0
index 2d88816..40f4b9a 100644
@@ -3,6 +3,17 @@ Common leds properties.
 Optional properties for child nodes:
 - label : The label for this LED.  If omitted, the label is
   taken from the node name (excluding the unit address).
+- iout-torch : Array of maximum intensities in microamperes of the torch
+	led currents in order from sub-led 0 to N-1, where N is the number
+	of torch sub-leds exposed by the device
+- iout-flash : Array of maximum intensities in microamperes of the flash
+	led currents in order from sub-led 0 to N-1, where N is the number
+	of flash sub-leds exposed by the device
+- iout-indicator : Array of maximum intensities in microamperes of
+	the indicator led currents in order from sub-led 0 to N-1,
+	where N is the number of indicator sub-leds exposed by the device
+- flash-timeout : timeout in microseconds after which flash led
+	is turned off
 
 - linux,default-trigger :  This parameter, if present, is a
     string defining the trigger assigned to the LED.  Current triggers are:
@@ -19,5 +30,10 @@ Examples:
 system-status {
 	label = "Status";
 	linux,default-trigger = "heartbeat";
+	iout-torch = <500 500>;
+	iout-flash = <1000 1000>;
+	iout-indicator = <100 100>;
+	flash-timeout = <1000>;
+
 	...
 };
Signature · 1 line
1.7.9.5
#24 lore raw

PATCH v4 12/21 DT: Add documentation for LED Class Flash Manger

In reply to Jacek Anaszewski

This patch documents LED Class Flash Manager
related bindings.

Cc Bryan Wu <[email protected]>
Cc Richard Purdie <[email protected]>
Cc Rob Herring <[email protected]>
Cc Pawel Moll <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Kumar Gala <[email protected]>
---
 .../bindings/leds/leds-flash-manager.txt           |  165 ++++++++++++++++++++
 1 file changed, 165 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/leds/leds-flash-manager.txt
Documentation/devicetree/bindings/leds/leds-flash-manager.txt new file +165 -0
new file mode 100644
index 0000000..c98ee2e
@@ -0,0 +1,165 @@
+* LED Flash Manager
+
+Flash manager is a part of LED Flash Class. It maintains
+all the flash led devices which have their external strobe
+signals routed through multiplexing devices.
+The multiplexers are aggregated in the standalone 'flash_muxes'
+node as subnodes which are referenced by the flash led devices.
+
+
+flash_muxes node
+----------------
+
+muxN subnode
+------------
+
+There must be at least one muxN subnode, where N is the identifier
+of the node, present in the flash_muxes node. One muxN node
+represents one multiplexer.
+
+Required properties (mutually exclusive):
+- gpios		: specifies the gpio pins used to set the states
+		  of mux selectors, LSB first
+- mux-async	: phandle to the node of the multiplexing device
+
+
+
+flash led device node
+---------------------
+
+Following subnodes must be added to the LED Flash Class device
+tree node described in Documentation/devicetree/bindings/leds/common.txt.
+
+
+gate-software-strobe subnode
+----------------------------
+
+The node defines configuration of multiplexers that needs
+to be applied to route software strobe signal to the flash
+led device.
+
+Required properties:
+- mux		: phandle to the muxN node defined
+		  in the flash_muxes node
+- mux-line-id	: mux line identifier
+
+Optional subnodes:
+- gate-software-strobe : if there are many multiplexers to configure,
+			 they can be recursively nested.
+
+
+gate-external-strobeN subnode
+-----------------------------
+
+The node defines configuration of multiplexers that needs
+to be applied to route external strobe signal to the flash
+led device. A flash led device can have many external strobe
+signal sources.
+
+Required properties:
+- mux			: phandle to the muxN node defined
+			  in the flash_muxes node
+- mux-line-id		: mux line identifier
+Optional properties:
+- strobe-provider	: phandle to the device providing the
+			  strobe signal. It is expected only
+			  on the first level node. The referenced
+			  node is expected to have 'compatible'
+			  property, as providers are labelled
+			  with it in the LED subsystem
+
+Optional subnodes:
+- gate-external-strobeN	: if there are many multiplexers to configure,
+			  they can be recursively nested.
+
+
+Example:
+
+Following board configuration is assumed in this example:
+
+    ---------- ----------
+    | FLASH1 | | FLASH2 |
+    ---------- ----------
+           \(0)   /(1)
+          ----------
+          |  MUX1  |
+          ----------
+              |
+          ----------
+          |  MUX2  |
+          ----------
+           /(0)   \(1)
+      ----------  --------------------
+      |  MUX3  |  | SOC FLASHEN GPIO |
+      ----------  --------------------
+       /(0)   \(1)
+----------- -----------
+| SENSOR1 | | SENSOR2 |
+----------- -----------
+
+
+dummy_mux: led_mux {
+	compatible = "led-async-mux";
+};
+
+flash_muxes {
+	flash_mux1: mux1 {
+                gpios = <&gpj1 1 0>, <&gpj1 2 0>;
+	};
+
+	flash_mux2: mux2 {
+		mux-async = <&dummy_mux>;
+	};
+
+	flash_mux3: mux3 {
+                gpios = <&gpl1 1 0>, <&gpl1 2 0>;
+	};
+};
+
+max77693-flash {
+	compatible = "maxim,max77693-flash";
+
+	//other device specific properties here
+
+	gate-software-strobe {
+		mux = <&flash_mux1>;
+		mux-line-id = <0>;
+
+		gate-software-strobe {
+			mux = <&flash_mux2>;
+			mux-line-id = <1>;
+		};
+	};
+
+	gate-external-strobe1 {
+		strobe-provider = <&s5c73m3_spi>;
+		mux = <&flash_mux1>;
+		mux-line-id = <0>;
+
+		gate-external-strobe1 {
+			mux = <&flash_mux2>;
+			mux-line-id = <0>;
+
+			gate-external-strobe1 {
+				mux = <&flash_mux3>;
+				mux-line-id = <0>;
+			};
+		};
+	};
+
+	gate-external-strobe2 {
+		strobe-provider = <&s5k6a3>;
+		mux = <&flash_mux1>;
+		mux-line-id = <0>;
+
+		gate-external-strobe2 {
+			mux = <&flash_mux2>;
+			mux-line-id = <0>;
+
+			gate-external-strobe2 {
+				mux = <&flash_mux3>;
+				mux-line-id = <1>;
+			};
+		};
+	};
+};
Signature · 1 line
1.7.9.5
#25 lore raw

PATCH v4 13/21 v4l2-device: add v4l2_device_register_subdev_node API

In reply to Jacek Anaszewski

Extract the code executed for each entry of the subdev list and put it to the separate function. Export it as a public API. It allows for registering single sub-device at a time.

---
 drivers/media/v4l2-core/v4l2-device.c |   63 +++++++++++++++++++--------------
 include/media/v4l2-device.h           |    7 ++++
 2 files changed, 44 insertions(+), 26 deletions(-)
drivers/media/v4l2-core/v4l2-device.c +37 -26
index 015f92a..0e91ef7 100644
@@ -216,9 +216,43 @@ static void v4l2_device_release_subdev_node(struct video_device *vdev)
 	kfree(vdev);
 }
 
-int v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev)
+int v4l2_device_register_subdev_node(struct v4l2_subdev *sd,
+				     struct v4l2_device *v4l2_dev)
 {
 	struct video_device *vdev;
+	int err;
+
+	if (!(sd->flags & V4L2_SUBDEV_FL_HAS_DEVNODE))
+		return 0;
+
+	vdev = kzalloc(sizeof(*vdev), GFP_KERNEL);
+	if (!vdev)
+		return -ENOMEM;
+
+	video_set_drvdata(vdev, sd);
+	strlcpy(vdev->name, sd->name, sizeof(vdev->name));
+	vdev->v4l2_dev = v4l2_dev;
+	vdev->fops = &v4l2_subdev_fops;
+	vdev->release = v4l2_device_release_subdev_node;
+	vdev->ctrl_handler = sd->ctrl_handler;
+	err = __video_register_device(vdev, VFL_TYPE_SUBDEV, -1, 1,
+				      sd->owner);
+	if (err < 0) {
+		kfree(vdev);
+		return err;
+	}
+#if defined(CONFIG_MEDIA_CONTROLLER)
+	sd->entity.info.v4l.major = VIDEO_MAJOR;
+	sd->entity.info.v4l.minor = vdev->minor;
+#endif
+	sd->devnode = vdev;
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(v4l2_device_register_subdev_node);
+
+int v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev)
+{
 	struct v4l2_subdev *sd;
 	int err;
 
@@ -226,32 +260,9 @@ int v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev)
 	 * V4L2_SUBDEV_FL_HAS_DEVNODE flag.
 	 */
 	list_for_each_entry(sd, &v4l2_dev->subdevs, list) {
-		if (!(sd->flags & V4L2_SUBDEV_FL_HAS_DEVNODE))
-			continue;
-
-		vdev = kzalloc(sizeof(*vdev), GFP_KERNEL);
-		if (!vdev) {
-			err = -ENOMEM;
-			goto clean_up;
-		}
-
-		video_set_drvdata(vdev, sd);
-		strlcpy(vdev->name, sd->name, sizeof(vdev->name));
-		vdev->v4l2_dev = v4l2_dev;
-		vdev->fops = &v4l2_subdev_fops;
-		vdev->release = v4l2_device_release_subdev_node;
-		vdev->ctrl_handler = sd->ctrl_handler;
-		err = __video_register_device(vdev, VFL_TYPE_SUBDEV, -1, 1,
-					      sd->owner);
-		if (err < 0) {
-			kfree(vdev);
+		err = v4l2_device_register_subdev_node(sd, v4l2_dev);
+		if (err < 0)
 			goto clean_up;
-		}
-#if defined(CONFIG_MEDIA_CONTROLLER)
-		sd->entity.info.v4l.major = VIDEO_MAJOR;
-		sd->entity.info.v4l.minor = vdev->minor;
-#endif
-		sd->devnode = vdev;
 	}
 	return 0;
 
include/media/v4l2-device.h +7 -0
index ffb69da..76594fc 100644
@@ -114,6 +114,13 @@ int __must_check v4l2_device_register_subdev(struct v4l2_device *v4l2_dev,
    wasn't registered. In that case it will do nothing. */
 void v4l2_device_unregister_subdev(struct v4l2_subdev *sd);
 
+/* Register device node for the subdev of the v4l2 device if it is marked with
+ * the V4L2_SUBDEV_FL_HAS_DEVNODE flag.
+ */
+int __must_check
+v4l2_device_register_subdev_node(struct v4l2_subdev *sd,
+					struct v4l2_device *v4l2_dev);
+
 /* Register device nodes for all subdev of the v4l2 device that are marked with
  * the V4L2_SUBDEV_FL_HAS_DEVNODE flag.
  */
Signature · 1 line
1.7.9.5
#26 lore raw

PATCH v4 14/21 v4l2-ctrls: add control for flash strobe signal providers

In reply to Jacek Anaszewski

Add V4L2_CID_STROBE_PROVIDER of type menu, which allows for enumerating of available external flash strobe signal providers and setting the active one.

---
 Documentation/DocBook/media/v4l/controls.xml |   11 +++++++++++
 drivers/media/v4l2-core/v4l2-ctrls.c         |    2 ++
 include/uapi/linux/v4l2-controls.h           |    2 ++
 3 files changed, 15 insertions(+)
Documentation/DocBook/media/v4l/controls.xml +11 -0
index 47198ee..d9f6c3f 100644
@@ -4300,6 +4300,17 @@ interface and may change in the future.</para>
     	    is strobing at the moment or not. This is a read-only
     	    control.</entry>
     	  </row>
+          <row>
+            <entry spanname="id"><constant>V4L2_CID_FLASH_STROBE_PROVIDER</constant></entry>
+            <entry>menu</entry>
+          </row>
+          <row>
+            <entry spanname="descr">Provider of the external strobe signal. If a flash
+            device declares more than one available external strobe signal provider then
+            this control allows to select the active one. &VIDIOC-QUERYCTRL; has to be
+            used to get the list of available strobe providers.
+            </entry>
+          </row>
     	  <row>
     	    <entry spanname="id"><constant>V4L2_CID_FLASH_TIMEOUT</constant></entry>
     	    <entry>integer</entry>
drivers/media/v4l2-core/v4l2-ctrls.c +2 -0
index 55c6832..f298f7e 100644
@@ -825,6 +825,7 @@ const char *v4l2_ctrl_get_name(u32 id)
 	case V4L2_CID_FLASH_FAULT:		return "Faults";
 	case V4L2_CID_FLASH_CHARGE:		return "Charge";
 	case V4L2_CID_FLASH_READY:		return "Ready to Strobe";
+	case V4L2_CID_FLASH_STROBE_PROVIDER:	return "Strobe Provider";
 
 	/* JPEG encoder controls */
 	/* Keep the order of the 'case's the same as in videodev2.h! */
@@ -988,6 +989,7 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
 	case V4L2_CID_TEST_PATTERN:
 	case V4L2_CID_TUNE_DEEMPHASIS:
 	case V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_SEL:
+	case V4L2_CID_FLASH_STROBE_PROVIDER:
 		*type = V4L2_CTRL_TYPE_MENU;
 		break;
 	case V4L2_CID_LINK_FREQ:
include/uapi/linux/v4l2-controls.h +2 -0
index 2ac5597..1f05c7c 100644
@@ -822,6 +822,8 @@ enum v4l2_flash_strobe_source {
 #define V4L2_CID_FLASH_CHARGE			(V4L2_CID_FLASH_CLASS_BASE + 11)
 #define V4L2_CID_FLASH_READY			(V4L2_CID_FLASH_CLASS_BASE + 12)
 
+#define V4L2_CID_FLASH_STROBE_PROVIDER		(V4L2_CID_FLASH_CLASS_BASE + 13)
+
 
 /* JPEG-class control IDs */
 
Signature · 1 line
1.7.9.5
#27 lore raw

PATCH v4 15/21 media: Add registration helpers for V4L2 flash

In reply to 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.

---
 drivers/media/v4l2-core/Kconfig      |   11 +
 drivers/media/v4l2-core/Makefile     |    2 +
 drivers/media/v4l2-core/v4l2-flash.c |  580 ++++++++++++++++++++++++++++++++++
 include/media/v4l2-flash.h           |  137 ++++++++
 4 files changed, 730 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
index 9ca0f8d..3ae3f0f 100644
@@ -35,6 +35,17 @@ config V4L2_MEM2MEM_DEV
         tristate
         depends on VIDEOBUF2_CORE
 
+# Used by LED subsystem flash drivers
+config V4L2_FLASH_LED_CLASS
+	bool "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
index 63d29f2..44e858c 100644
@@ -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 +580 -0

580 lines not on this page · raw message

include/media/v4l2-flash.h new file +137 -0

137 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#37 lore raw

PATCH v4 16/21 leds: Add support for max77693 mfd flash cell

In reply to Jacek Anaszewski

This patch adds led-flash support to Maxim max77693 chipset. A device can be exposed to user space through LED subsystem sysfs interface or through V4L2 subdevice when the support for V4L2 Flash sub-devices is enabled. Device supports up to two leds which can work in flash and torch mode. Leds can be triggered externally or by software.

---
 drivers/leds/Kconfig         |    9 +
 drivers/leds/Makefile        |    1 +
 drivers/leds/leds-max77693.c | 1070 ++++++++++++++++++++++++++++++++++++++++++
 drivers/mfd/max77693.c       |    5 +-
 include/linux/mfd/max77693.h |   40 ++
 5 files changed, 1124 insertions(+), 1 deletion(-)
 create mode 100644 drivers/leds/leds-max77693.c
drivers/leds/Kconfig +9 -0
index 5032c6f..794055e 100644
@@ -457,6 +457,15 @@ config LEDS_TCA6507
 	  LED driver chips accessed via the I2C bus.
 	  Driver support brightness control and hardware-assisted blinking.
 
+config LEDS_MAX77693
+	tristate "LED support for MAX77693 Flash"
+	depends on LEDS_CLASS_FLASH
+	depends on MFD_MAX77693
+	help
+	  This option enables support for the flash part of the MAX77693
+	  multifunction device. It has build in control for two leds in flash
+	  and torch mode.
+
 config LEDS_MAX8997
 	tristate "LED support for MAX8997 PMIC"
 	depends on LEDS_CLASS && MFD_MAX8997
drivers/leds/Makefile +1 -0
index 237c5ba..da1a4ba 100644
@@ -55,6 +55,7 @@ obj-$(CONFIG_LEDS_MC13783)		+= leds-mc13783.o
 obj-$(CONFIG_LEDS_NS2)			+= leds-ns2.o
 obj-$(CONFIG_LEDS_NETXBIG)		+= leds-netxbig.o
 obj-$(CONFIG_LEDS_ASIC3)		+= leds-asic3.o
+obj-$(CONFIG_LEDS_MAX77693)		+= leds-max77693.o
 obj-$(CONFIG_LEDS_MAX8997)		+= leds-max8997.o
 obj-$(CONFIG_LEDS_LM355x)		+= leds-lm355x.o
 obj-$(CONFIG_LEDS_BLINKM)		+= leds-blinkm.o
drivers/leds/leds-max77693.c new file +1070 -0

1,070 lines not on this page · raw message

drivers/mfd/max77693.c +4 -1
index 249c139..cf008f4 100644
@@ -44,9 +44,12 @@
 static const struct mfd_cell max77693_devs[] = {
 	{ .name = "max77693-pmic", },
 	{ .name = "max77693-charger", },
-	{ .name = "max77693-flash", },
 	{ .name = "max77693-muic", },
 	{ .name = "max77693-haptic", },
+	{
+		.name = "max77693-flash",
+		.of_compatible = "maxim,max77693-flash",
+	},
 };
 
 static const struct regmap_config max77693_regmap_config = {
include/linux/mfd/max77693.h +40 -0
index 3f3dc45..f0b6585 100644
@@ -63,6 +63,45 @@ struct max77693_muic_platform_data {
 	int path_uart;
 };
 
+/* MAX77693 led flash */
+
+/* triggers */
+enum max77693_led_trigger {
+	MAX77693_LED_TRIG_OFF,
+	MAX77693_LED_TRIG_FLASH,
+	MAX77693_LED_TRIG_TORCH,
+	MAX77693_LED_TRIG_EXT,
+	MAX77693_LED_TRIG_SOFT,
+};
+
+/* trigger types */
+enum max77693_led_trigger_type {
+	MAX77693_LED_TRIG_TYPE_EDGE,
+	MAX77693_LED_TRIG_TYPE_LEVEL,
+};
+
+/* boost modes */
+enum max77693_led_boost_mode {
+	MAX77693_LED_BOOST_NONE,
+	MAX77693_LED_BOOST_ADAPTIVE,
+	MAX77693_LED_BOOST_FIXED,
+};
+
+struct max77693_led_platform_data {
+	u32 fleds[2];
+	u32 iout_torch[2];
+	u32 iout_flash[2];
+	u32 trigger[2];
+	u32 trigger_type[2];
+	u32 num_leds;
+	u32 boost_mode;
+	u32 flash_timeout;
+	u32 boost_vout;
+	u32 low_vsys;
+};
+
+/* MAX77693 */
+
 struct max77693_platform_data {
 	/* regulator data */
 	struct max77693_regulator_data *regulators;
@@ -70,5 +109,6 @@ struct max77693_platform_data {
 
 	/* muic data */
 	struct max77693_muic_platform_data *muic_data;
+	struct max77693_led_platform_data *led_data;
 };
 #endif	/* __LINUX_MFD_MAX77693_H */
Signature · 1 line
1.7.9.5
#39 lore raw

PATCH v4 17/21 DT: Add documentation for the mfd Maxim max77693

In reply to Jacek Anaszewski

This patch adds device tree binding documentation for the flash cell of the Maxim max77693 multifunctional device.

Cc Rob Herring <[email protected]>
Cc Pawel Moll <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Kumar Gala <[email protected]>
---
 Documentation/devicetree/bindings/mfd/max77693.txt |   62 ++++++++++++++++++++
 1 file changed, 62 insertions(+)
Documentation/devicetree/bindings/mfd/max77693.txt +62 -0
index 11921cc..0c3db3d 100644
@@ -27,6 +27,55 @@ Optional properties:
 
 	[*] refer Documentation/devicetree/bindings/regulator/regulator.txt
 
+Optional node:
+- led-flash : the LED submodule device node
+
+Required properties of "led-flash" node:
+- compatible : must be "maxim,max77693-flash"
+- maxim,num-leds : number of connected leds
+	Possible values: 1 or 2.
+- maxim,fleds : array of current outputs in order: fled1, fled2
+	Note: both current outputs can be connected to a single led
+	Possible values:
+		0 - the output is left disconnected,
+		1 - a diode is connected to the output.
+
+Optional properties of "led-flash" node:
+- maxim,boost-mode :
+	In boost mode the device can produce up to 1.2A of total current
+	on both outputs. The maximum current on each output is reduced
+	to 625mA then. If maxim,num-leds == <2> boost must be enabled
+	(it defaults to 1 if not set):
+	Possible values:
+		0 - no boost,
+		1 - adaptive mode,
+		2 - fixed mode.
+- iout-torch : Array of maximum intensities in microamperes of the torch
+	led currents in order: fled1, fled2.
+		15625 - 250000
+- iout-flash : Array of maximum intensities in microamperes of the flash
+	led currents in order: fled1, fled2.
+	Range:
+		15625 - 1000000 (max 625000 if boost mode is enabled)
+- flash-timeout : timeout in microseconds after which flash led
+		  is turned off
+	Range:
+		62500 - 1000000
+- maxim,trigger : Array of flags indicating which trigger can activate given led
+	in order: fled1, fled2
+	Possible flag values (can be combined):
+		1 - FLASH pin of the chip,
+		2 - TORCH pin of the chip,
+		4 - software via I2C command.
+- maxim,trigger-type : Array of trigger types in order: flash, torch.
+	Possible trigger types:
+		0 - Rising edge of the signal triggers the flash/torch,
+		1 - Signal level controls duration of the flash/torch.
+- maxim,boost-vout : Output voltage of the boost module in millivolts.
+- maxim,vsys-min : Low input voltage level in millivolts. Flash is not fired
+	if chip estimates that system voltage could drop below this level due
+	to flash power consumption.
+
 Example:
 	max77693@66 {
 		compatible = "maxim,max77693";
@@ -52,4 +101,17 @@ Example:
 					regulator-boot-on;
 			};
 		};
+		led_flash: led-flash {
+			compatible = "maxim,max77693-flash";
+			iout-torch = <500000 0>;
+			iout-flash = <1250000 0>;
+			flash-timeout = <1000000 1000000>;
+			maxim,num-leds = <1>;
+			maxim,fleds = <1 1>;
+			maxim,trigger = <7 7>;
+			maxim,trigger-type = <0 1>;
+			maxim,boost-mode = <1>;
+			maxim,boost-vout = <5000>;
+			maxim,vsys-min = <2400>;
+		};
 	};
Signature · 1 line
1.7.9.5
#40 lore raw

PATCH v4 18/21 leds: Add driver for AAT1290 current regulator

In reply to Jacek Anaszewski

This patch adds a driver for the 1.5A Step-Up Current Regulator for Flash LEDs. The device is programmed through a Skyworks' proprietary AS2Cwire serial digital interface.

---
 drivers/leds/Kconfig        |    6 +
 drivers/leds/Makefile       |    1 +
 drivers/leds/leds-aat1290.c |  455 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 462 insertions(+)
 create mode 100644 drivers/leds/leds-aat1290.c
drivers/leds/Kconfig +6 -0
index 794055e..ef774fd 100644
@@ -42,6 +42,12 @@ config LEDS_88PM860X
 	  This option enables support for on-chip LED drivers found on Marvell
 	  Semiconductor 88PM8606 PMIC.
 
+config LEDS_AAT1290
+	tristate "LED support for the AAT1290"
+	depends on LEDS_CLASS_FLASH
+	help
+	 This option enables support for the LEDs on the AAT1290.
+
 config LEDS_ATMEL_PWM
 	tristate "LED Support using Atmel PWM outputs"
 	depends on LEDS_CLASS
drivers/leds/Makefile +1 -0
index da1a4ba..41911aa 100644
@@ -11,6 +11,7 @@ obj-$(CONFIG_LEDS_TRIGGERS)		+= led-triggers.o
 
 # LED Platform Drivers
 obj-$(CONFIG_LEDS_88PM860X)		+= leds-88pm860x.o
+obj-$(CONFIG_LEDS_AAT1290)		+= leds-aat1290.o
 obj-$(CONFIG_LEDS_ATMEL_PWM)		+= leds-atmel-pwm.o
 obj-$(CONFIG_LEDS_BD2802)		+= leds-bd2802.o
 obj-$(CONFIG_LEDS_LOCOMO)		+= leds-locomo.o
drivers/leds/leds-aat1290.c new file +455 -0

455 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#41 lore raw

PATCH v4 19/21 of: Add Skyworks Solutions, Inc. vendor prefix

In reply to Jacek Anaszewski

Use "skyworks" as the vendor prefix for the
Skyworks Solutions, Inc.

Cc Rob Herring <[email protected]>
Cc Pawel Moll <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Kumar Gala <[email protected]>
---
 .../devicetree/bindings/vendor-prefixes.txt        |    1 +
 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/vendor-prefixes.txt +1 -0
index 5d27e5a..8d0df4e 100644
@@ -113,6 +113,7 @@ renesas	Renesas Electronics Corporation
 ricoh	Ricoh Co. Ltd.
 rockchip	Fuzhou Rockchip Electronics Co., Ltd
 samsung	Samsung Semiconductor
+skyworks	Skyworks Solutions, Inc.
 sbs	Smart Battery System
 schindler	Schindler
 seagate	Seagate Technology PLC
Signature · 1 line
1.7.9.5
#42 lore raw

PATCH v4 20/21 DT: Add documentation for the Skyworks AAT1290

In reply to Jacek Anaszewski

This patch adds device tree binding documentation for 1.5A Step-Up Current Regulator for Flash LEDs.

Cc Rob Herring <[email protected]>
Cc Pawel Moll <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Kumar Gala <[email protected]>
---
 .../devicetree/bindings/leds/leds-aat1290.txt      |   17 +++++++++++++++++
 1 file changed, 17 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/leds/leds-aat1290.txt
Documentation/devicetree/bindings/leds/leds-aat1290.txt new file +17 -0
new file mode 100644
index 0000000..9a9ad15
@@ -0,0 +1,17 @@
+* Skyworks Solutions, Inc. AAT1290 Current Regulator for Flash LEDs
+
+Required properties:
+
+- compatible : should be "skyworks,aat1290"
+- gpios : two gpio pins in order FLEN, EN/SET
+- skyworks,flash-timeout : maximum flash timeout in microseconds -
+			   it can be calculated using following formula:
+			   T = 8.82 * 10^9 * Ct
+
+Example:
+
+flash_led: flash-led {
+	compatible = "skyworks,aat1290";
+	gpios = <&gpj1 1 0>, <&gpj1 2 0>;
+	flash-timeout = <1940000>;
+}
Signature · 1 line
1.7.9.5
#43 lore raw

PATCH v4 21/21 ARM: dts: add aat1290 current regulator device node

In reply to Jacek Anaszewski

Add device node for AAT1290 1.5A Step-Up Current Regulator for Flash LEDs along with flash_muxes node containing information about a multiplexer that is used for switching between software and external strobe signal source.

---
 arch/arm/boot/dts/exynos4412-trats2.dts |   24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
arch/arm/boot/dts/exynos4412-trats2.dts +24 -0
index 7787844..cbb76ba 100644
@@ -785,4 +785,28 @@
 		pulldown-ohm = <100000>; /* 100K */
 		io-channels = <&adc 2>;  /* Battery temperature */
 	};
+
+	flash_muxes {
+		flash_mux1: mux1 {
+			gpios = <&gpj1 0 0>;
+		};
+	};
+
+	aat1290 {
+		compatible = "skyworks,aat1290";
+		gpios = <&gpj1 1 0>, <&gpj1 2 0>;
+		flash-timeout = <1940000>;
+		status = "okay";
+
+		gate-software-strobe {
+			mux = <&flash_mux1>;
+			mux-line-id = <0>;
+		};
+
+		gate-external-strobe {
+			strobe-provider = <&s5c73m3_spi>;
+			mux = <&flash_mux1>;
+			mux-line-id = <1>;
+		};
+	};
 };
Signature · 1 line
1.7.9.5
#3 lore raw

Re: [PATCH/RFC v4 02/21] leds: implement sysfs interface locking mechanism

In reply to Jacek Anaszewski

Hi Jacek,

Thank you for the update!

Jacek Anaszewski wrote:
...

drivers/leds/led-core.c void led_set_brightness(struct led_classdev *led_cdev, · line 133

Quoted 13 lines
drivers/leds/led-core.c +5 -0
index 71b40d3..4d7cb31 100644
@@ -126,3 +126,21 @@ void led_set_brightness(struct led_classdev *led_cdev,
  	__led_set_brightness(led_cdev, brightness);
  }
  EXPORT_SYMBOL(led_set_brightness);
+
+/* Caller must ensure led_cdev->led_lock held */
+void led_sysfs_lock(struct led_classdev *led_cdev)
+{
+	WARN_ON(!mutex_is_locked(&led_cdev->led_lock));

How about lockdep_assert_held() instead?

Signature · 2 lines
Sakari Ailus
e-mail: [email protected]     XMPP: [email protected]
#6 lore raw

Re: [PATCH/RFC v4 04/21] leds: Reorder include directives

In reply to Jacek Anaszewski

Hi Jacek,

Quoted 22 lines · Jacek Anaszewski

Reorder include directives so that they are arranged in alphabetical order.

Cc Bryan Wu <[email protected]>
Cc Richard Purdie <rpurdie-Fm38FmjxZ/[email protected]>
---
  drivers/leds/led-class.c |   13 +++++++------
  drivers/leds/led-core.c  |    3 ++-
  include/linux/leds.h     |    2 +-
  3 files changed, 10 insertions(+), 8 deletions(-)
drivers/leds/led-class.c +0 -1
index da79bbb..0127783 100644
@@ -9,16 +9,17 @@
   * published by the Free Software Foundation.
   */
 
-#include <linux/module.h>

drivers/leds/led-class.c line 20

Quoted 10 lines
drivers/leds/led-class.c +7 -1
-#include <linux/kernel.h>
+#include <linux/ctype.h>
+#include <linux/device.h>
+#include <linux/err.h>
  #include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/leds.h>
  #include <linux/list.h>
+#include <linux/module.h>
+#include <linux/slab.h>

Do you also need slab.h?

Quoted 14 lines
drivers/leds/led-class.c +0 -4
  #include <linux/spinlock.h>
-#include <linux/device.h>
  #include <linux/timer.h>
-#include <linux/err.h>
-#include <linux/ctype.h>
-#include <linux/leds.h>
  #include "leds.h"
 
  static struct class *leds_class;
drivers/leds/led-core.c +0 -0
index 0ac06ed..d156fb6 100644

drivers/leds/led-core.c line 18

Quoted 7 lines
drivers/leds/led-core.c +2 -0
@@ -12,10 +12,11 @@
   */
 
  #include <linux/kernel.h>
+#include <linux/leds.h>
  #include <linux/list.h>
  #include <linux/module.h>
+#include <linux/mutex.h>

And mutex.h here?

With that fixed, if there are some other patches that are essentially cleanups that could go in well before the rest of the set. Some of the patches will take a little longer, I presume.

I'll let you know if/when there's an update regarding the compound controls patchset.

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
Acked-by on v4 5/21
#8 lore raw

Re: [PATCH/RFC v4 05/21] leds: avoid using deprecated DEVICE_ATTR macro

In reply to Jacek Anaszewski

Hi Jacek,

Quoted 3 lines · Jacek Anaszewski

Make the sysfs attributes definition consistent in the whole file. The modification entails change of the function name:
led_max_brightness_show -> max_brightness_show

I'm not sure whether DEVICE_ATTR() is really deprecated but nevertheless this is cleaner.

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
#44 lore raw
In reply to Jacek Anaszewski
Quoted 6 lines · Jacek Anaszewski

This is is the fourth version of the patch series being a follow up of the discussion on Media summit 2013-10-23, related to the LED / flash API integration (the notes from the discussion were enclosed in the message [1], paragraph 5).
The series is based on linux-next-20140707

I really apologize that I missed your discussion email in my Gmail inbox, it was archived some where. Even in this series some of these patches are archived in different tab.

I will start to review and help to push this.

Thanks,
-Bryan

Quoted 272 lines

Description of the proposed modifications according to
the kernel components they are relevant to:
- LED subsystem modifications
* added led_flash module which, when enabled in the config, registers flash specific sysfs attributes, if the driver declares related features:
- flash_brightness
- max_flash_brightness
- indicator_brightness
- max_indicator_brightness
- flash_timeout
- max_flash_timeout
- flash_strobe
- external_strobe
- flash_fault
and exposes kernel internal API:
- led_classdev_flash_register
- led_classdev_flash_unregister
- led_set_flash_strobe
- led_get_flash_strobe
- led_set_flash_brightness
- led_update_flash_brightness
- led_set_indicator_brightness
- led_update_indicator_brightness
- led_set_flash_timeout
- led_get_flash_fault
- led_set_external_strobe
- led_sysfs_lock
- led_sysfs_unlock
* added Flash Manager functionality, available when led_flash module is enable in the config;
if the device tree node of a flash led device contains relevant subnodes, it registers following sysfs attributes:
- strobe_provider
- strobe_providerN
- blocking_strobe
following kernel internal API is exposed by the flash manager:
- led_flash_manager_register_flash
- led_flash_manager_unregister_flash
- led_flash_manager_setup_strobe
- led_flash_manager_bind_async_mux
- led_flash_manager_unbind_async_mux
- Addition of a V4L2 Flash sub-device registration helpers
* added v4l2-flash.c and v4l2-flash.h files with helper functions that facilitate registration/unregistration of a subdevice, which wrapps a LED subsystem device and exposes V4L2 Flash control interface
- Addition of a LED Flash Class driver for the flash cell of the MAX77693 mfd
- Addition of a LED Flash Class driver for the AAT1290 current regulator for flash leds along with its DT binding for the exynos4412-trats2 board, where standalone multiplexer is used for modifying strobe signal routing - either from the SoC GPIO or from a camera sensor. This arrangment is handled by the newly introduced Flash Manager functionality.
- Update of the max77693.txt DT bindings documentation
- Update of the common leds DT bindings documentation

================
Changes since v2
================

- refactored the code so that it is possible to build led-core without led-flash module
- added v4l2-flash ops which slackens dependency from the led-flash module
- implemented led_clamp_align_val function and led_ctrl structure which allows to align led control values in the manner compatible with V4L2 Flash controls; the flash brightness and timeout units have been defined as microamperes and microseconds respectively to properly support devices which define current and time levels as fractions of 1/1000.
- added support for the flash privacy leds
- modified LED sysfs locking mechanism - now it locks/unlocks the interface on V4L2 Flash sub-device file open/close
- changed hw_triggered attribute name to external_strobe, which maps on the V4L2_FLASH_STROBE_SOURCE_EXTERNAL name more intuitively
- made external_strobe and indicator related sysfs attributes created optionally only if related features are declared by the led device driver
- removed from the series patches modifying exynos4-is media controller - a proposal for "flash manager" which will take care of flash devices registration is due to be submitted
- removed modifications to the LED class devices documentation, it will be covered after the whole functionality is accepted

================
Changes since v3
================

- added Flash Manager feature
- added generic LED Flash Class gpio mux driver
- added sample async mux driver
- added of helpers for parsing Flash Manager related device tree data
- added V4L2_CID_FLASH_STROBE_PROVIDER control
- introduced struct led_classdev_flash, which wrapps struct led_classdev
- made all flash ops, except strobe_set, optional; if an op is absent the related sysfs attribute isn't created
- added LED_DEV_CAP* flags
- modified v4l2-flash helpers to create v4l2_device for v4l2_flash subdevices to register in it
- modified max77693-flash driver and its DT bindings to allow for registering either one or two LED Flash Class devices, depending on the device tree settings.
- added new API for setting torch_brightness
- extended leds common DT binding documentation

Issues:

1) Who should register V4L2 Flash sub-device?

LED Flash Class devices, after introduction of the Flash Manager, are not tightly coupled with any media controller. They are maintained by the Flash Manager and made available for dynamic assignment to any media system they are connected to through multiplexing devices.

In the proposed rough solution, when support for V4L2 Flash sub-devices is enabled, there is a v4l2_device created for them to register in. This however implies that V4L2 Flash device will not be available in any media controller, which calls its existence into question.

Therefore I'd like to consult possible ways of solving this issue. The option I see is implementing a mechanism for moving V4L2 Flash sub-devices between media controllers. A V4L2 Flash sub-device would initially be assigned to one media system in the relevant device tree binding, but it could be dynamically reassigned to the other one. However I'm not sure if media controller design is prepared for dynamic modifications of its graph and how many modifications in the existing drivers this solution would require.

2) Consequences of locking the Flash Manager during flash strobe

In case a LED Flash Class device depends on muxes involved in routing the other LED Flash Class device's strobe signals, the Flash Manager must be locked for the time of strobing to prevent reconfiguration of the strobe signal routing by the other device.

A blocking_strobe sysfs attribute was added to indicate whether this is the case for the device.

Nonetheless, this modifies behaviour of led_set_external_strobe API, which also must block the caller for the time of strobing to protect the strobe signal routing while the external strobe signal provider asserts the flash_en pin.

Use case for user space application would be following in this case:
- spawn a new thread in which external strobe is activated
- in the parent thread instruct the external strobe provider to strobe the flash

As an improvement there could be an op added for notifying
the application that the strobe signal routing has been
set up. It would have to be called from the function led_flash_manager_setup_strobe after led_flash_manager_set_external_strobe returns.

The blocking_strobe attribute would have to be also mapped to a new V4L2 Flash control. Unfortunately it poses a problem for the existing users of the V4L2 Flash API which are not aware that setting V4L2_CID_FLASH_STROBE_SOURCE may be blocking.

As a solution led_set_external_strobe API could be extended by a parameter telling whether the caller is prepared for the blocking call. led_flash_manager_setup_strobe should be extended accordingly then.
In V4L2 "V4L2_FLASH_STROBE_SOURCE_EXTERNAL_BLOCKING" menu item could be added to handle this.
With existing V4L2_FLASH_STROBE_SOURCE_EXTERNAL the flash manager wouldn't protect muxes against reconfiguration.

TODO:
- switch to using V4L2 array controls
- add s_power op to the LED Flash Class

I will be off-line for three weeks from now on and will respond to any questions after getting back.

Thanks,
Jacek Anaszewski

Jacek Anaszewski (21):
leds: make brightness type consistent across whole subsystem
leds: implement sysfs interface locking mechanism
leds: Improve and export led_update_brightness
leds: Reorder include directives
leds: avoid using deprecated DEVICE_ATTR macro
leds: add API for setting torch brightness
of: add of_node_ncmp wrapper
leds: Add sysfs and kernel internal API for flash LEDs
Documentation: leds: Add description of LED Flash Class extension
Documentation: leds: add exemplary asynchronous mux driver
DT: leds: Add flash led devices related properties
DT: Add documentation for LED Class Flash Manger
v4l2-device: add v4l2_device_register_subdev_node API
v4l2-ctrls: add control for flash strobe signal providers
media: Add registration helpers for V4L2 flash
leds: Add support for max77693 mfd flash cell
DT: Add documentation for the mfd Maxim max77693
leds: Add driver for AAT1290 current regulator
of: Add Skyworks Solutions, Inc. vendor prefix
DT: Add documentation for the Skyworks AAT1290
ARM: dts: add aat1290 current regulator device node

 Documentation/DocBook/media/v4l/controls.xml       |   11 +
 Documentation/devicetree/bindings/leds/common.txt  |   16 +
 .../devicetree/bindings/leds/leds-aat1290.txt      |   17 +
 .../bindings/leds/leds-flash-manager.txt           |  165 +++
 Documentation/devicetree/bindings/mfd/max77693.txt |   62 ++
 .../devicetree/bindings/vendor-prefixes.txt        |    1 +
 Documentation/leds/leds-async-mux.c                |   65 ++
 Documentation/leds/leds-class-flash.txt            |  126 +++
 arch/arm/boot/dts/exynos4412-trats2.dts            |   24 +
 drivers/leds/Kconfig                               |   28 +
 drivers/leds/Makefile                              |    7 +
 drivers/leds/led-class-flash.c                     |  715 +++++++++++++
 drivers/leds/led-class.c                           |   58 +-
 drivers/leds/led-core.c                            |   51 +-
 drivers/leds/led-flash-gpio-mux.c                  |  102 ++
 drivers/leds/led-flash-manager.c                   |  698 +++++++++++++
 drivers/leds/led-triggers.c                        |   16 +-
 drivers/leds/leds-aat1290.c                        |  455 +++++++++
 drivers/leds/leds-max77693.c                       | 1070 ++++++++++++++++++++
 drivers/leds/of_led_flash_manager.c                |  155 +++
 drivers/media/v4l2-core/Kconfig                    |   11 +
 drivers/media/v4l2-core/Makefile                   |    2 +
 drivers/media/v4l2-core/v4l2-ctrls.c               |    2 +
 drivers/media/v4l2-core/v4l2-device.c              |   63 +-
 drivers/media/v4l2-core/v4l2-flash.c               |  580 +++++++++++
 drivers/mfd/max77693.c                             |    5 +-
 include/linux/led-class-flash.h                    |  290 ++++++
 include/linux/led-flash-gpio-mux.h                 |   68 ++
 include/linux/led-flash-manager.h                  |  121 +++
 include/linux/leds.h                               |   73 +-
 include/linux/mfd/max77693.h                       |   40 +
 include/linux/of.h                                 |    1 +
 include/linux/of_led_flash_manager.h               |   80 ++
 include/media/v4l2-device.h                        |    7 +
 include/media/v4l2-flash.h                         |  137 +++
 include/uapi/linux/v4l2-controls.h                 |    2 +
 36 files changed, 5272 insertions(+), 52 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/leds/leds-aat1290.txt
 create mode 100644 Documentation/devicetree/bindings/leds/leds-flash-manager.txt
 create mode 100644 Documentation/leds/leds-async-mux.c
 create mode 100644 Documentation/leds/leds-class-flash.txt
 create mode 100644 drivers/leds/led-class-flash.c
 create mode 100644 drivers/leds/led-flash-gpio-mux.c
 create mode 100644 drivers/leds/led-flash-manager.c
 create mode 100644 drivers/leds/leds-aat1290.c
 create mode 100644 drivers/leds/leds-max77693.c
 create mode 100644 drivers/leds/of_led_flash_manager.c
 create mode 100644 drivers/media/v4l2-core/v4l2-flash.c
 create mode 100644 include/linux/led-class-flash.h
 create mode 100644 include/linux/led-flash-gpio-mux.h
 create mode 100644 include/linux/led-flash-manager.h
 create mode 100644 include/linux/of_led_flash_manager.h
 create mode 100644 include/media/v4l2-flash.h

--
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#45 lore raw
Quoted 9 lines · Bryan Wu
Quoted 6 lines · Jacek Anaszewski

This is is the fourth version of the patch series being a follow up of the discussion on Media summit 2013-10-23, related to the LED / flash API integration (the notes from the discussion were enclosed in the message [1], paragraph 5).
The series is based on linux-next-20140707

Quoted 6 lines

I really apologize that I missed your discussion email in my Gmail inbox, it was archived some where. Even in this series some of these patches are archived in different tab.

I will start to review and help to push this.

In the mean time, could you please provide an git tree for me to pull? It's much easier for me to review in my git.

-Bryan

Quoted 274 lines
Quoted 274 lines

Description of the proposed modifications according to
the kernel components they are relevant to:
- LED subsystem modifications
* added led_flash module which, when enabled in the config, registers flash specific sysfs attributes, if the driver declares related features:
- flash_brightness
- max_flash_brightness
- indicator_brightness
- max_indicator_brightness
- flash_timeout
- max_flash_timeout
- flash_strobe
- external_strobe
- flash_fault
and exposes kernel internal API:
- led_classdev_flash_register
- led_classdev_flash_unregister
- led_set_flash_strobe
- led_get_flash_strobe
- led_set_flash_brightness
- led_update_flash_brightness
- led_set_indicator_brightness
- led_update_indicator_brightness
- led_set_flash_timeout
- led_get_flash_fault
- led_set_external_strobe
- led_sysfs_lock
- led_sysfs_unlock
* added Flash Manager functionality, available when led_flash module is enable in the config;
if the device tree node of a flash led device contains relevant subnodes, it registers following sysfs attributes:
- strobe_provider
- strobe_providerN
- blocking_strobe
following kernel internal API is exposed by the flash manager:
- led_flash_manager_register_flash
- led_flash_manager_unregister_flash
- led_flash_manager_setup_strobe
- led_flash_manager_bind_async_mux
- led_flash_manager_unbind_async_mux
- Addition of a V4L2 Flash sub-device registration helpers
* added v4l2-flash.c and v4l2-flash.h files with helper functions that facilitate registration/unregistration of a subdevice, which wrapps a LED subsystem device and exposes V4L2 Flash control interface
- Addition of a LED Flash Class driver for the flash cell of the MAX77693 mfd
- Addition of a LED Flash Class driver for the AAT1290 current regulator for flash leds along with its DT binding for the exynos4412-trats2 board, where standalone multiplexer is used for modifying strobe signal routing - either from the SoC GPIO or from a camera sensor. This arrangment is handled by the newly introduced Flash Manager functionality.
- Update of the max77693.txt DT bindings documentation
- Update of the common leds DT bindings documentation

================
Changes since v2
================

- refactored the code so that it is possible to build led-core without led-flash module
- added v4l2-flash ops which slackens dependency from the led-flash module
- implemented led_clamp_align_val function and led_ctrl structure which allows to align led control values in the manner compatible with V4L2 Flash controls; the flash brightness and timeout units have been defined as microamperes and microseconds respectively to properly support devices which define current and time levels as fractions of 1/1000.
- added support for the flash privacy leds
- modified LED sysfs locking mechanism - now it locks/unlocks the interface on V4L2 Flash sub-device file open/close
- changed hw_triggered attribute name to external_strobe, which maps on the V4L2_FLASH_STROBE_SOURCE_EXTERNAL name more intuitively
- made external_strobe and indicator related sysfs attributes created optionally only if related features are declared by the led device driver
- removed from the series patches modifying exynos4-is media controller - a proposal for "flash manager" which will take care of flash devices registration is due to be submitted
- removed modifications to the LED class devices documentation, it will be covered after the whole functionality is accepted

================
Changes since v3
================

- added Flash Manager feature
- added generic LED Flash Class gpio mux driver
- added sample async mux driver
- added of helpers for parsing Flash Manager related device tree data
- added V4L2_CID_FLASH_STROBE_PROVIDER control
- introduced struct led_classdev_flash, which wrapps struct led_classdev
- made all flash ops, except strobe_set, optional; if an op is absent the related sysfs attribute isn't created
- added LED_DEV_CAP* flags
- modified v4l2-flash helpers to create v4l2_device for v4l2_flash subdevices to register in it
- modified max77693-flash driver and its DT bindings to allow for registering either one or two LED Flash Class devices, depending on the device tree settings.
- added new API for setting torch_brightness
- extended leds common DT binding documentation

Issues:

1) Who should register V4L2 Flash sub-device?

LED Flash Class devices, after introduction of the Flash Manager, are not tightly coupled with any media controller. They are maintained by the Flash Manager and made available for dynamic assignment to any media system they are connected to through multiplexing devices.

In the proposed rough solution, when support for V4L2 Flash sub-devices is enabled, there is a v4l2_device created for them to register in. This however implies that V4L2 Flash device will not be available in any media controller, which calls its existence into question.

Therefore I'd like to consult possible ways of solving this issue. The option I see is implementing a mechanism for moving V4L2 Flash sub-devices between media controllers. A V4L2 Flash sub-device would initially be assigned to one media system in the relevant device tree binding, but it could be dynamically reassigned to the other one. However I'm not sure if media controller design is prepared for dynamic modifications of its graph and how many modifications in the existing drivers this solution would require.

2) Consequences of locking the Flash Manager during flash strobe

In case a LED Flash Class device depends on muxes involved in routing the other LED Flash Class device's strobe signals, the Flash Manager must be locked for the time of strobing to prevent reconfiguration of the strobe signal routing by the other device.

A blocking_strobe sysfs attribute was added to indicate whether this is the case for the device.

Nonetheless, this modifies behaviour of led_set_external_strobe API, which also must block the caller for the time of strobing to protect the strobe signal routing while the external strobe signal provider asserts the flash_en pin.

Use case for user space application would be following in this case:
- spawn a new thread in which external strobe is activated
- in the parent thread instruct the external strobe provider to strobe the flash

As an improvement there could be an op added for notifying
the application that the strobe signal routing has been
set up. It would have to be called from the function led_flash_manager_setup_strobe after led_flash_manager_set_external_strobe returns.

The blocking_strobe attribute would have to be also mapped to a new V4L2 Flash control. Unfortunately it poses a problem for the existing users of the V4L2 Flash API which are not aware that setting V4L2_CID_FLASH_STROBE_SOURCE may be blocking.

As a solution led_set_external_strobe API could be extended by a parameter telling whether the caller is prepared for the blocking call. led_flash_manager_setup_strobe should be extended accordingly then.
In V4L2 "V4L2_FLASH_STROBE_SOURCE_EXTERNAL_BLOCKING" menu item could be added to handle this.
With existing V4L2_FLASH_STROBE_SOURCE_EXTERNAL the flash manager wouldn't protect muxes against reconfiguration.

TODO:
- switch to using V4L2 array controls
- add s_power op to the LED Flash Class

I will be off-line for three weeks from now on and will respond to any questions after getting back.

Thanks,
Jacek Anaszewski

Jacek Anaszewski (21):
leds: make brightness type consistent across whole subsystem
leds: implement sysfs interface locking mechanism
leds: Improve and export led_update_brightness
leds: Reorder include directives
leds: avoid using deprecated DEVICE_ATTR macro
leds: add API for setting torch brightness
of: add of_node_ncmp wrapper
leds: Add sysfs and kernel internal API for flash LEDs
Documentation: leds: Add description of LED Flash Class extension
Documentation: leds: add exemplary asynchronous mux driver
DT: leds: Add flash led devices related properties
DT: Add documentation for LED Class Flash Manger
v4l2-device: add v4l2_device_register_subdev_node API
v4l2-ctrls: add control for flash strobe signal providers
media: Add registration helpers for V4L2 flash
leds: Add support for max77693 mfd flash cell
DT: Add documentation for the mfd Maxim max77693
leds: Add driver for AAT1290 current regulator
of: Add Skyworks Solutions, Inc. vendor prefix
DT: Add documentation for the Skyworks AAT1290
ARM: dts: add aat1290 current regulator device node

 Documentation/DocBook/media/v4l/controls.xml       |   11 +
 Documentation/devicetree/bindings/leds/common.txt  |   16 +
 .../devicetree/bindings/leds/leds-aat1290.txt      |   17 +
 .../bindings/leds/leds-flash-manager.txt           |  165 +++
 Documentation/devicetree/bindings/mfd/max77693.txt |   62 ++
 .../devicetree/bindings/vendor-prefixes.txt        |    1 +
 Documentation/leds/leds-async-mux.c                |   65 ++
 Documentation/leds/leds-class-flash.txt            |  126 +++
 arch/arm/boot/dts/exynos4412-trats2.dts            |   24 +
 drivers/leds/Kconfig                               |   28 +
 drivers/leds/Makefile                              |    7 +
 drivers/leds/led-class-flash.c                     |  715 +++++++++++++
 drivers/leds/led-class.c                           |   58 +-
 drivers/leds/led-core.c                            |   51 +-
 drivers/leds/led-flash-gpio-mux.c                  |  102 ++
 drivers/leds/led-flash-manager.c                   |  698 +++++++++++++
 drivers/leds/led-triggers.c                        |   16 +-
 drivers/leds/leds-aat1290.c                        |  455 +++++++++
 drivers/leds/leds-max77693.c                       | 1070 ++++++++++++++++++++
 drivers/leds/of_led_flash_manager.c                |  155 +++
 drivers/media/v4l2-core/Kconfig                    |   11 +
 drivers/media/v4l2-core/Makefile                   |    2 +
 drivers/media/v4l2-core/v4l2-ctrls.c               |    2 +
 drivers/media/v4l2-core/v4l2-device.c              |   63 +-
 drivers/media/v4l2-core/v4l2-flash.c               |  580 +++++++++++
 drivers/mfd/max77693.c                             |    5 +-
 include/linux/led-class-flash.h                    |  290 ++++++
 include/linux/led-flash-gpio-mux.h                 |   68 ++
 include/linux/led-flash-manager.h                  |  121 +++
 include/linux/leds.h                               |   73 +-
 include/linux/mfd/max77693.h                       |   40 +
 include/linux/of.h                                 |    1 +
 include/linux/of_led_flash_manager.h               |   80 ++
 include/media/v4l2-device.h                        |    7 +
 include/media/v4l2-flash.h                         |  137 +++
 include/uapi/linux/v4l2-controls.h                 |    2 +
 36 files changed, 5272 insertions(+), 52 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/leds/leds-aat1290.txt
 create mode 100644 Documentation/devicetree/bindings/leds/leds-flash-manager.txt
 create mode 100644 Documentation/leds/leds-async-mux.c
 create mode 100644 Documentation/leds/leds-class-flash.txt
 create mode 100644 drivers/leds/led-class-flash.c
 create mode 100644 drivers/leds/led-flash-gpio-mux.c
 create mode 100644 drivers/leds/led-flash-manager.c
 create mode 100644 drivers/leds/leds-aat1290.c
 create mode 100644 drivers/leds/leds-max77693.c
 create mode 100644 drivers/leds/of_led_flash_manager.c
 create mode 100644 drivers/media/v4l2-core/v4l2-flash.c
 create mode 100644 include/linux/led-class-flash.h
 create mode 100644 include/linux/led-flash-gpio-mux.h
 create mode 100644 include/linux/led-flash-manager.h
 create mode 100644 include/linux/of_led_flash_manager.h
 create mode 100644 include/media/v4l2-flash.h

--
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#10 lore raw

Re: [PATCH/RFC v4 06/21] leds: add API for setting torch brightness

In reply to Jacek Anaszewski

Hi Jacek,

Jacek Anaszewski wrote:
...

Quoted 11 lines
include/linux/leds.h +1 -0
index 1a130cc..9bea9e6 100644
@@ -44,11 +44,21 @@ struct led_classdev {
  #define LED_BLINK_ONESHOT_STOP	(1 << 18)
  #define LED_BLINK_INVERT	(1 << 19)
  #define LED_SYSFS_LOCK		(1 << 20)
+#define LED_DEV_CAP_TORCH	(1 << 21)
 
  	/* Set LED brightness level */

include/linux/leds.h struct led_classdev { · line 59

Quoted 10 lines
include/linux/leds.h +7 -0
  	/* Must not sleep, use a workqueue if needed */
  	void		(*brightness_set)(struct led_classdev *led_cdev,
  					  enum led_brightness brightness);
+	/*
+	 * Set LED brightness immediately - it is required for flash led
+	 * devices as they require setting torch brightness to have immediate
+	 * effect. brightness_set op cannot be used for this purpose because
+	 * the led drivers schedule a work queue task in it to allow for
+	 * being called from led-triggers, i.e. from the timer irq context.
+	 */

Do we need to classify actual devices based on this? I think it's rather a different API behaviour between the LED and the V4L2 APIs.

On devices that are slow to control, the behaviour should be asynchronous over the LED API and synchronous when accessed through the V4L2 API. How about implementing the work queue, as I have suggested, in the framework, so that individual drivers don't need to care about this and just implement the synchronous variant of this op? A flag could be added to distinguish devices that are fast so that the work queue isn't needed.

It'd be nice to avoid individual drivers having to implement multiple ops to do the same thing, just for differing user space interfacs.

Signature · 4 lines
Kind regards,

Sakari Ailus
e-mail: [email protected]     XMPP: [email protected]
Acked-by on v4 7/21
#18 lore raw

Re: [PATCH/RFC v4 07/21] of: add of_node_ncmp wrapper

In reply to Jacek Anaszewski
Quoted 2 lines · Jacek Anaszewski

The wrapper for strnicmp is required for checking whether a node has expected prefix.

Signature · 6 lines
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
#28 lore raw

Re: [PATCH/RFC v4 15/21] media: Add registration helpers for V4L2 flash

In reply to Jacek Anaszewski

Hi Jacek,

Quoted 202 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.

---
 drivers/media/v4l2-core/Kconfig      |   11 +
 drivers/media/v4l2-core/Makefile     |    2 +
 drivers/media/v4l2-core/v4l2-flash.c |  580 ++++++++++++++++++++++++++++++++++
 include/media/v4l2-flash.h           |  137 ++++++++
 4 files changed, 730 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
index 9ca0f8d..3ae3f0f 100644
@@ -35,6 +35,17 @@ config V4L2_MEM2MEM_DEV
         tristate
         depends on VIDEOBUF2_CORE
 
+# Used by LED subsystem flash drivers
+config V4L2_FLASH_LED_CLASS
+	bool "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
index 63d29f2..44e858c 100644
@@ -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 +142 -0
new file mode 100644
index 0000000..21080c6
@@ -0,0 +1,580 @@
+/*
+ * V4L2 Flash LED sub-device registration helpers.
+ *
+ *	Copyright (C) 2014 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/mutex.h>
+#include <linux/of_led_flash_manager.h>
+#include <linux/slab.h>
+#include <media/v4l2-flash.h>
+
+#define call_flash_op(v4l2_flash, op, args...)			\
+		(v4l2_flash->ops->op  ?				\
+			v4l2_flash->ops->op(args) :		\
+			-EINVAL)
+
+static struct v4l2_device *v4l2_dev;
+static int registered_flashes;
+
+static inline enum led_brightness v4l2_flash_intensity_to_led_brightness(
+					struct v4l2_ctrl_config *config,
+					s32 intensity)
+{
+	return ((intensity - config->min) / config->step) + 1;
+}
+
+static inline s32 v4l2_flash_led_brightness_to_intensity(
+					struct v4l2_ctrl_config *config,
+					enum led_brightness brightness)
+{
+	return ((brightness - 1) * config->step) + config->min;
+}
+
+static int v4l2_flash_g_volatile_ctrl(struct v4l2_ctrl *c)
+
+{
+	struct v4l2_flash *v4l2_flash = v4l2_ctrl_to_v4l2_flash(c);
+	struct led_classdev_flash *flash = v4l2_flash->flash;
+	struct led_classdev *led_cdev = &flash->led_cdev;
+	struct v4l2_flash_ctrl_config *config = &v4l2_flash->config;
+	struct v4l2_flash_ctrl *ctrl = &v4l2_flash->ctrl;
+	bool is_strobing;
+	int ret;
+
+	switch (c->id) {
+	case V4L2_CID_FLASH_TORCH_INTENSITY:
+		/*
+		 * Update torch brightness only if in TORCH_MODE,
+		 * as otherwise brightness_update op returns 0,
+		 * which would spuriously inform user space that
+		 * V4L2_CID_FLASH_TORCH_INTENSITY control value
+		 * has changed.
+		 */
+		if (ctrl->led_mode->val == V4L2_FLASH_LED_MODE_TORCH) {
+			ret = call_flash_op(v4l2_flash, torch_brightness_update,
+							led_cdev);
+			if (ret < 0)
+				return ret;
+			ctrl->torch_intensity->val =
+				v4l2_flash_led_brightness_to_intensity(
+						&config->torch_intensity,
+						led_cdev->brightness);
+		}
+		return 0;
+	case V4L2_CID_FLASH_INTENSITY:
+		ret = call_flash_op(v4l2_flash, flash_brightness_update,
+					flash);
+		if (ret < 0)
+			return ret;
+		/* no conversion is needed */
+		c->val = flash->brightness.val;
+		return 0;
+	case V4L2_CID_FLASH_INDICATOR_INTENSITY:
+		ret = call_flash_op(v4l2_flash, indicator_brightness_update,
+						flash);
+		if (ret < 0)
+			return ret;
+		/* no conversion is needed */
+		c->val = flash->indicator_brightness->val;
+		return 0;
+	case V4L2_CID_FLASH_STROBE_STATUS:
+		ret = call_flash_op(v4l2_flash, strobe_get, flash,
+							&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 */
+		ret = call_flash_op(v4l2_flash, fault_get, flash, &c->val);
+		return ret;
+	case V4L2_CID_FLASH_STROBE_SOURCE:
+		c->val = flash->external_strobe;
+		return 0;
+	case V4L2_CID_FLASH_STROBE_PROVIDER:
+		c->val = flash->strobe_provider_id;
+		return 0;
+	default:
+		return -EINVAL;
+	}
+}
+
+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 *flash = v4l2_flash->flash;
+	struct v4l2_flash_ctrl *ctrl = &v4l2_flash->ctrl;
+	struct v4l2_flash_ctrl_config *config = &v4l2_flash->config;
+	enum led_brightness torch_brightness;
+	bool external_strobe;
+	int ret;
+
+	switch (c->id) {
+	case V4L2_CID_FLASH_LED_MODE:
+		switch (c->val) {
+		case V4L2_FLASH_LED_MODE_NONE:
+			call_flash_op(v4l2_flash, torch_brightness_set,
+							&flash->led_cdev, 0);
+			return call_flash_op(v4l2_flash, strobe_set, flash,
+							false);
+		case V4L2_FLASH_LED_MODE_FLASH:
+			/* Turn off torch LED */
+			call_flash_op(v4l2_flash, torch_brightness_set,
+							&flash->led_cdev, 0);
+			external_strobe = (ctrl->source->val ==
+					V4L2_FLASH_STROBE_SOURCE_EXTERNAL);
+			return call_flash_op(v4l2_flash, external_strobe_set,
+						flash, external_strobe);
+		case V4L2_FLASH_LED_MODE_TORCH:
+			/* Stop flash strobing */
+			ret = call_flash_op(v4l2_flash, strobe_set, flash,
+							false);
+			if (ret)
+				return ret;
+
+			torch_brightness =

drivers/media/v4l2-core/v4l2-flash.c line 152

Quoted 10 lines
drivers/media/v4l2-core/v4l2-flash.c new file +10 -0
+				v4l2_flash_intensity_to_led_brightness(
+						&config->torch_intensity,
+						ctrl->torch_intensity->val);
+			call_flash_op(v4l2_flash, torch_brightness_set,
+					&flash->led_cdev, torch_brightness);
+			return ret;
+		}
+		break;
+	case V4L2_CID_FLASH_STROBE_SOURCE:
+		external_strobe = (c->val == V4L2_FLASH_STROBE_SOURCE_EXTERNAL);

Is the external_strobe argument match exactly to the strobe source control? You seem to assume that in g_volatile_ctrl() above. I think having it the either way is fine but not both. :-)

drivers/media/v4l2-core/v4l2-flash.c line 161

Quoted 8 lines
drivers/media/v4l2-core/v4l2-flash.c new file +8 -0
+		return call_flash_op(v4l2_flash, external_strobe_set, flash,
+							external_strobe);
+	case V4L2_CID_FLASH_STROBE:
+		if (ctrl->led_mode->val != V4L2_FLASH_LED_MODE_FLASH ||
+		    ctrl->source->val != V4L2_FLASH_STROBE_SOURCE_SOFTWARE)
+			return -EINVAL;
+		return call_flash_op(v4l2_flash, strobe_set, flash, true);
+	case V4L2_CID_FLASH_STROBE_STOP:

Should we check the flash mode here? I guess so. How about strobe source as well?

Quoted 150 lines
drivers/media/v4l2-core/v4l2-flash.c new file +150 -0
+		return call_flash_op(v4l2_flash, strobe_set, flash, false);
+	case V4L2_CID_FLASH_TIMEOUT:
+		return call_flash_op(v4l2_flash, timeout_set, flash, c->val);
+	case V4L2_CID_FLASH_INTENSITY:
+		/* no conversion is needed */
+		return call_flash_op(v4l2_flash, flash_brightness_set, flash,
+								c->val);
+	case V4L2_CID_FLASH_INDICATOR_INTENSITY:
+		/* no conversion is needed */
+		return call_flash_op(v4l2_flash, indicator_brightness_set,
+						flash, c->val);
+	case V4L2_CID_FLASH_TORCH_INTENSITY:
+		/*
+		 * If not in MODE_TORCH don't call led-class brightness_set
+		 * op, as it would result in turning the torch led on.
+		 * Instead the value is cached only and will be written
+		 * to the device upon transition to MODE_TORCH.
+		 */
+		if (ctrl->led_mode->val == V4L2_FLASH_LED_MODE_TORCH) {
+			torch_brightness =
+				v4l2_flash_intensity_to_led_brightness(
+						&config->torch_intensity,
+						ctrl->torch_intensity->val);
+			call_flash_op(v4l2_flash, torch_brightness_set,
+					&flash->led_cdev, torch_brightness);
+		}
+		return 0;
+	case V4L2_CID_FLASH_STROBE_PROVIDER:
+		flash->strobe_provider_id = c->val;
+		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 int v4l2_flash_init_strobe_providers_menu(struct v4l2_flash *v4l2_flash)
+{
+	struct led_classdev_flash *flash = v4l2_flash->flash;
+	struct led_flash_strobe_provider *provider;
+	struct v4l2_ctrl *ctrl;
+	int i = 0;
+
+	v4l2_flash->strobe_providers_menu =
+			kzalloc(sizeof(char *) * (flash->num_strobe_providers),
+					GFP_KERNEL);
+	if (!v4l2_flash->strobe_providers_menu)
+		return -ENOMEM;
+
+	list_for_each_entry(provider, &flash->strobe_providers, list)
+		v4l2_flash->strobe_providers_menu[i++] =
+						(char *) provider->name;
+
+	ctrl = v4l2_ctrl_new_std_menu_items(
+		&v4l2_flash->hdl, &v4l2_flash_ctrl_ops,
+		V4L2_CID_FLASH_STROBE_PROVIDER,
+		flash->num_strobe_providers - 1,
+		0, 0,
+		(const char * const *) v4l2_flash->strobe_providers_menu);
+
+	if (ctrl)
+		ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;
+
+	return 0;
+}
+
+static int v4l2_flash_init_controls(struct v4l2_flash *v4l2_flash)
+
+{
+	struct led_classdev_flash *flash = v4l2_flash->flash;
+	const struct led_flash_ops *flash_ops = flash->ops;
+	struct led_classdev *led_cdev = &flash->led_cdev;
+	struct v4l2_flash_ctrl_config *config = &v4l2_flash->config;
+	struct v4l2_ctrl *ctrl;
+	struct v4l2_ctrl_config *ctrl_cfg;
+	bool has_flash = led_cdev->flags & LED_DEV_CAP_FLASH;
+	bool has_indicator = led_cdev->flags & LED_DEV_CAP_INDICATOR;
+	bool has_strobe_providers = (flash->num_strobe_providers > 1);
+	unsigned int mask;
+	int ret, max, num_ctrls;
+
+	num_ctrls = has_flash ? 5 : 2;
+	if (has_flash) {
+		if (flash_ops->flash_brightness_set)
+			++num_ctrls;
+		if (flash_ops->timeout_set)
+			++num_ctrls;
+		if (flash_ops->strobe_get)
+			++num_ctrls;
+		if (has_indicator)
+			++num_ctrls;
+		if (config->flash_faults)
+			++num_ctrls;
+		if (has_strobe_providers)
+			++num_ctrls;
+	}
+
+	v4l2_ctrl_handler_init(&v4l2_flash->hdl, num_ctrls);
+
+	mask = 1 << V4L2_FLASH_LED_MODE_NONE |
+	       1 << V4L2_FLASH_LED_MODE_TORCH;
+	if (flash)
+		mask |= 1 << V4L2_FLASH_LED_MODE_FLASH;
+
+	/* Configure FLASH_LED_MODE ctrl */
+	v4l2_flash->ctrl.led_mode = v4l2_ctrl_new_std_menu(
+			&v4l2_flash->hdl,
+			&v4l2_flash_ctrl_ops, V4L2_CID_FLASH_LED_MODE,
+			V4L2_FLASH_LED_MODE_TORCH, ~mask,
+			V4L2_FLASH_LED_MODE_NONE);
+
+	/* Configure TORCH_INTENSITY ctrl */
+	ctrl_cfg = &config->torch_intensity;
+	ctrl = v4l2_ctrl_new_std(&v4l2_flash->hdl, &v4l2_flash_ctrl_ops,
+				 V4L2_CID_FLASH_TORCH_INTENSITY,
+				 ctrl_cfg->min, ctrl_cfg->max,
+				 ctrl_cfg->step, ctrl_cfg->def);
+	if (ctrl)
+		ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;
+	v4l2_flash->ctrl.torch_intensity = ctrl;
+
+	if (has_flash) {
+		/* Configure FLASH_STROBE_SOURCE ctrl */
+		mask = 1 << V4L2_FLASH_STROBE_SOURCE_SOFTWARE;
+
+		if (flash->has_external_strobe) {
+			mask |= 1 << V4L2_FLASH_STROBE_SOURCE_EXTERNAL;
+			max = V4L2_FLASH_STROBE_SOURCE_EXTERNAL;
+		} else {
+			max = V4L2_FLASH_STROBE_SOURCE_SOFTWARE;
+		}
+
+		v4l2_flash->ctrl.source = v4l2_ctrl_new_std_menu(
+					&v4l2_flash->hdl,
+					&v4l2_flash_ctrl_ops,
+					V4L2_CID_FLASH_STROBE_SOURCE,
+					max,
+					~mask,
+					V4L2_FLASH_STROBE_SOURCE_SOFTWARE);
+		if (v4l2_flash->ctrl.source)
+			v4l2_flash->ctrl.source->flags |=
+						V4L2_CTRL_FLAG_VOLATILE;
+
+		/* Configure FLASH_STROBE ctrl */
+		ctrl = v4l2_ctrl_new_std(&v4l2_flash->hdl, &v4l2_flash_ctrl_ops,
+					  V4L2_CID_FLASH_STROBE, 0, 1, 1, 0);

drivers/media/v4l2-core/v4l2-flash.c line 321

Quoted 10 lines
drivers/media/v4l2-core/v4l2-flash.c new file +10 -0
+
+		/* Configure FLASH_STROBE_STOP ctrl */
+		ctrl = v4l2_ctrl_new_std(&v4l2_flash->hdl, &v4l2_flash_ctrl_ops,
+					  V4L2_CID_FLASH_STROBE_STOP,
+					  0, 1, 1, 0);
+
+		/* Configure FLASH_STROBE_STATUS ctrl */
+		ctrl = v4l2_ctrl_new_std(&v4l2_flash->hdl, &v4l2_flash_ctrl_ops,
+					 V4L2_CID_FLASH_STROBE_STATUS,
+					 0, 1, 1, 1);

I think you only should implement the strobe status control if you really can know it, i.e. have strobe_get().

Quoted 42 lines
drivers/media/v4l2-core/v4l2-flash.c new file +42 -0
+		if (flash_ops->strobe_get)
+			if (ctrl)
+				ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE |
+					       V4L2_CTRL_FLAG_READ_ONLY;
+
+		if (flash_ops->timeout_set) {
+			/* Configure FLASH_TIMEOUT ctrl */
+			ctrl_cfg = &config->flash_timeout;
+			ctrl = v4l2_ctrl_new_std(
+					&v4l2_flash->hdl, &v4l2_flash_ctrl_ops,
+					V4L2_CID_FLASH_TIMEOUT, ctrl_cfg->min,
+					ctrl_cfg->max, ctrl_cfg->step,
+					ctrl_cfg->def);
+			if (ctrl)
+				ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;
+		}
+
+		if (flash_ops->flash_brightness_set) {
+			/* Configure FLASH_INTENSITY ctrl */
+			ctrl_cfg = &config->flash_intensity;
+			ctrl = v4l2_ctrl_new_std(
+					&v4l2_flash->hdl,
+					&v4l2_flash_ctrl_ops,
+					V4L2_CID_FLASH_INTENSITY,
+					ctrl_cfg->min, ctrl_cfg->max,
+					ctrl_cfg->step, ctrl_cfg->def);
+			if (ctrl)
+				ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;
+		}
+
+		if (config->flash_faults) {
+			/* Configure FLASH_FAULT ctrl */
+			ctrl = v4l2_ctrl_new_std(&v4l2_flash->hdl,
+						 &v4l2_flash_ctrl_ops,
+						 V4L2_CID_FLASH_FAULT, 0,
+						 config->flash_faults,
+						 0, 0);
+			if (ctrl)
+				ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE |
+					       V4L2_CTRL_FLAG_READ_ONLY;
+		}
+		if (has_indicator) {

drivers/media/v4l2-core/v4l2-flash.c line 374

Quoted 10 lines
drivers/media/v4l2-core/v4l2-flash.c new file +10 -0
+			/* Configure FLASH_INDICATOR_INTENSITY ctrl */
+			ctrl_cfg = &config->indicator_intensity;
+			ctrl = v4l2_ctrl_new_std(
+					&v4l2_flash->hdl, &v4l2_flash_ctrl_ops,
+					V4L2_CID_FLASH_INDICATOR_INTENSITY,
+					ctrl_cfg->min, ctrl_cfg->max,
+					ctrl_cfg->step, ctrl_cfg->def);
+			if (ctrl)
+				ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;
+		}

Could you implement the above in a loop? You're essentially repeating the same but with different parameters.

Quoted 28 lines
drivers/media/v4l2-core/v4l2-flash.c new file +28 -0
+		if (has_strobe_providers) {
+			/* Configure V4L2_CID_FLASH_STROBE_PROVIDERS ctrl */
+			ret = v4l2_flash_init_strobe_providers_menu(v4l2_flash);
+			if (ret < 0)
+				goto error_free_handler;
+		}
+	}
+
+	if (v4l2_flash->hdl.error) {
+		ret = v4l2_flash->hdl.error;
+		goto error_free_handler;
+	}
+
+	ret = v4l2_ctrl_handler_setup(&v4l2_flash->hdl);
+	if (ret < 0)
+		goto error_free_handler;
+
+	v4l2_flash->sd.ctrl_handler = &v4l2_flash->hdl;
+
+	return 0;
+
+error_free_handler:
+	v4l2_ctrl_handler_free(&v4l2_flash->hdl);
+	return ret;
+}
+
+/*
+ * V4L2 subdev internal operations

drivers/media/v4l2-core/v4l2-flash.c line 413

Quoted 10 lines
drivers/media/v4l2-core/v4l2-flash.c new file +10 -0
+ */
+
+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 *flash = v4l2_flash->flash;
+	struct led_classdev *led_cdev = &flash->led_cdev;
+
+	mutex_lock(&led_cdev->led_lock);
+	call_flash_op(v4l2_flash, sysfs_lock, led_cdev);

What if you have the device open through multiple file handles? I believe v4l2_subdev_fh_is_singular(&fh->vfh) would prove helpful here.

Quoted 9 lines
drivers/media/v4l2-core/v4l2-flash.c new file +9 -0
+	mutex_unlock(&led_cdev->led_lock);
+
+	return 0;
+}
+
+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 *flash = v4l2_flash->flash;

drivers/media/v4l2-core/v4l2-flash.c line 432

Quoted 10 lines
drivers/media/v4l2-core/v4l2-flash.c new file +10 -0
+	struct led_classdev *led_cdev = &flash->led_cdev;
+
+	mutex_lock(&led_cdev->led_lock);
+	call_flash_op(v4l2_flash, sysfs_unlock, led_cdev);
+	mutex_unlock(&led_cdev->led_lock);
+
+	return 0;
+}
+
+int v4l2_flash_register(struct v4l2_flash *v4l2_flash)

Do you expect to call this from elsewhere than this file?

Quoted 23 lines
drivers/media/v4l2-core/v4l2-flash.c new file +23 -0
+{
+	struct led_classdev_flash *flash = v4l2_flash->flash;
+	struct led_classdev *led_cdev = &flash->led_cdev;
+	int ret;
+
+	if (!v4l2_dev) {
+		v4l2_dev = kzalloc(sizeof(*v4l2_dev), GFP_KERNEL);
+		if (!v4l2_dev)
+			return -ENOMEM;
+
+		strlcpy(v4l2_dev->name, "v4l2-flash-manager",
+						sizeof(v4l2_dev->name));
+		ret = v4l2_device_register(NULL, v4l2_dev);
+		if (ret < 0) {
+			dev_err(led_cdev->dev->parent,
+				 "Failed to register v4l2_device: %d\n", ret);
+			goto err_v4l2_device_register;
+		}
+	}
+
+	ret = v4l2_device_register_subdev(v4l2_dev, &v4l2_flash->sd);
+	if (ret < 0) {
+		dev_err(led_cdev->dev->parent,

drivers/media/v4l2-core/v4l2-flash.c line 465

Quoted 10 lines
drivers/media/v4l2-core/v4l2-flash.c new file +10 -0
+			 "Failed to register v4l2_subdev: %d\n", ret);
+		goto err_v4l2_device_register;
+	}
+
+	ret = v4l2_device_register_subdev_node(&v4l2_flash->sd, v4l2_dev);
+	if (ret < 0) {
+		dev_err(led_cdev->dev->parent,
+			 "Failed to register v4l2_subdev node: %d\n", ret);
+		goto err_register_subdev_node;
+	}

This way you can create a V4L2 sub-device node. However, flash devices are seldom alone in the system. They are physically close to a sensor, and this connection is shown in the Media controller interface. This means that the flash sub-device (entity) should be part of the Media device created by the driver in control of it. This can be achieved by the master driver creating the sub-device. You should register an async sub-device here.

This results in the sub-device not being registered if there's no such master driver, but I wouldn't expect that to be an issue since the V4L2 flash API is mostly relevant in such cases.

Quoted 79 lines
drivers/media/v4l2-core/v4l2-flash.c new file +79 -0
+	++registered_flashes;
+
+	return 0;
+
+err_register_subdev_node:
+	v4l2_device_unregister_subdev(&v4l2_flash->sd);
+err_v4l2_device_register:
+	kfree(v4l2_flash->strobe_providers_menu);
+	if (v4l2_dev && registered_flashes == 0) {
+		v4l2_device_unregister(v4l2_dev);
+		kfree(v4l2_dev);
+		v4l2_dev = NULL;
+	}
+
+	return ret;
+}
+
+static void v4l2_flash_unregister(struct v4l2_flash *v4l2_flash)
+{
+	if (registered_flashes == 0)
+		return;
+
+	v4l2_device_unregister_subdev(&v4l2_flash->sd);
+
+	--registered_flashes;
+
+	if (registered_flashes == 0) {
+		v4l2_device_unregister(v4l2_dev);
+		kfree(v4l2_dev);
+		v4l2_dev = NULL;
+	}
+}
+
+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,
+};
+
+int v4l2_flash_init(struct led_classdev_flash *flash,
+		    struct v4l2_flash_ctrl_config *config,
+		    const struct v4l2_flash_ops *flash_ops,
+		    struct v4l2_flash **out_flash)
+{
+	struct v4l2_flash *v4l2_flash;
+	struct led_classdev *led_cdev = &flash->led_cdev;
+	struct v4l2_subdev *sd;
+	int ret;
+
+	if (!flash || !config || !out_flash)
+		return -EINVAL;
+
+	v4l2_flash = kzalloc(sizeof(*v4l2_flash), GFP_KERNEL);
+	if (!v4l2_flash)
+		return -ENOMEM;
+
+	sd = &v4l2_flash->sd;
+	v4l2_flash->flash = flash;
+	v4l2_flash->ops = flash_ops;
+	sd->dev = led_cdev->dev->parent;
+	v4l2_subdev_init(sd, &v4l2_flash_subdev_ops);
+	sd->internal_ops = &v4l2_flash_subdev_internal_ops;
+	sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
+	snprintf(sd->name, sizeof(sd->name), led_cdev->name);
+
+	v4l2_flash->config = *config;
+	ret = v4l2_flash_init_controls(v4l2_flash);
+	if (ret < 0)
+		goto err_init_controls;
+
+	ret = media_entity_init(&sd->entity, 0, NULL, 0);

drivers/media/v4l2-core/v4l2-flash.c line 555

Quoted 10 lines
drivers/media/v4l2-core/v4l2-flash.c new file +10 -0
+	if (ret < 0)
+		goto err_init_entity;
+
+	sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV_FLASH;
+
+	ret = v4l2_flash_register(v4l2_flash);
+	if (ret < 0)
+		goto err_init_entity;
+
+	*out_flash = v4l2_flash;

How about returning the pointer instead?

Quoted 62 lines
drivers/media/v4l2-core/v4l2-flash.c new file +24 -0
+	return 0;
+
+err_init_entity:
+	media_entity_cleanup(&sd->entity);
+err_init_controls:
+	v4l2_ctrl_handler_free(sd->ctrl_handler);
+	kfree(v4l2_flash);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(v4l2_flash_init);
+
+void v4l2_flash_release(struct v4l2_flash *v4l2_flash)
+{
+	if (!v4l2_flash)
+		return;
+
+	v4l2_flash_unregister(v4l2_flash);
+	v4l2_ctrl_handler_free(v4l2_flash->sd.ctrl_handler);
+	media_entity_cleanup(&v4l2_flash->sd.entity);
+	kfree(v4l2_flash->strobe_providers_menu);
+	kfree(v4l2_flash);
+}
+EXPORT_SYMBOL_GPL(v4l2_flash_release);
include/media/v4l2-flash.h new file +32 -0
new file mode 100644
index 0000000..effa46b
@@ -0,0 +1,137 @@
+/*
+ * V4L2 Flash LED sub-device registration helpers.
+ *
+ *	Copyright (C) 2014 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."
+ */
+
+#ifndef _V4L2_FLASH_H
+#define _V4L2_FLASH_H
+
+#include <media/v4l2-ctrls.h>
+#include <media/v4l2-device.h>
+#include <media/v4l2-dev.h>
+#include <media/v4l2-event.h>
+#include <media/v4l2-ioctl.h>
+
+struct led_classdev_flash;
+struct led_classdev;
+enum led_brightness;
+
+struct v4l2_flash_ops {
+	int (*torch_brightness_set)(struct led_classdev *led_cdev,
+					enum led_brightness brightness);
+	int (*torch_brightness_update)(struct led_classdev *led_cdev);
+	int (*flash_brightness_set)(struct led_classdev_flash *flash,
+					u32 brightness);
+	int (*flash_brightness_update)(struct led_classdev_flash *flash);
+	int (*strobe_set)(struct led_classdev_flash *flash, bool state);

include/media/v4l2-flash.h line 42

Quoted 10 lines
include/media/v4l2-flash.h new file +10 -0
+	int (*strobe_get)(struct led_classdev_flash *flash, bool *state);
+	int (*timeout_set)(struct led_classdev_flash *flash, u32 timeout);
+	int (*indicator_brightness_set)(struct led_classdev_flash *flash,
+					u32 brightness);
+	int (*indicator_brightness_update)(struct led_classdev_flash *flash);
+	int (*external_strobe_set)(struct led_classdev_flash *flash,
+					bool enable);
+	int (*fault_get)(struct led_classdev_flash *flash, u32 *fault);
+	void (*sysfs_lock)(struct led_classdev *led_cdev);
+	void (*sysfs_unlock)(struct led_classdev *led_cdev);

These functions are not driver specific and there's going to be just one implementation (I suppose). Could you refresh my memory regarding why the LED framework functions aren't called directly?

Quoted 96 lines
include/media/v4l2-flash.h new file +95 -0
+};
+
+/**
+ * struct v4l2_flash_ctrl - controls that define the sub-dev's state
+ * @source:		V4L2_CID_FLASH_STROBE_SOURCE control
+ * @led_mode:		V4L2_CID_FLASH_LED_MODE control
+ * @torch_intensity:	V4L2_CID_FLASH_TORCH_INTENSITY control
+ */
+struct v4l2_flash_ctrl {
+	struct v4l2_ctrl *source;
+	struct v4l2_ctrl *led_mode;
+	struct v4l2_ctrl *torch_intensity;
+};
+
+/**
+ * struct v4l2_flash_ctrl_config - V4L2 Flash controls initialization data
+ * @torch_intensity:		V4L2_CID_FLASH_TORCH_INTENSITY constraints
+ * @flash_intensity:		V4L2_CID_FLASH_INTENSITY constraints
+ * @indicator_intensity:	V4L2_CID_FLASH_INDICATOR_INTENSITY constraints
+ * @flash_timeout:		V4L2_CID_FLASH_TIMEOUT constraints
+ * @flash_fault:		possible flash faults
+ */
+struct v4l2_flash_ctrl_config {
+	struct v4l2_ctrl_config torch_intensity;
+	struct v4l2_ctrl_config flash_intensity;
+	struct v4l2_ctrl_config indicator_intensity;
+	struct v4l2_ctrl_config flash_timeout;
+	u32 flash_faults;
+};
+
+/**
+ * struct v4l2_flash - Flash sub-device context
+ * @flash:		LED Flash Class device controlled by this sub-device
+ * @ops:		LED Flash Class device ops
+ * @sd:			V4L2 sub-device
+ * @hdl:		flash controls handler
+ * @ctrl:		state defining controls
+ * @config:		V4L2 Flash controlsrconfiguration data
+ * @software_strobe_gates: route to the software strobe signal
+ * @external_strobe_gates: route to the external strobe signal
+ * @sensors:		available external strobe sources
+ */
+struct v4l2_flash {
+	struct led_classdev_flash *flash;
+	const struct v4l2_flash_ops *ops;
+
+	struct v4l2_subdev sd;
+	struct v4l2_ctrl_handler hdl;
+	struct v4l2_flash_ctrl ctrl;
+	struct v4l2_flash_ctrl_config config;
+	char **strobe_providers_menu;
+};
+
+static inline struct v4l2_flash *v4l2_subdev_to_v4l2_flash(
+							struct v4l2_subdev *sd)
+{
+	return container_of(sd, struct v4l2_flash, sd);
+}
+
+static inline struct v4l2_flash *v4l2_ctrl_to_v4l2_flash(struct v4l2_ctrl *c)
+{
+	return container_of(c->handler, struct v4l2_flash, hdl);
+}
+
+#ifdef CONFIG_V4L2_FLASH_LED_CLASS
+/**
+ * v4l2_flash_init - initialize V4L2 flash led sub-device
+ * @led_fdev:	the LED Flash Class device to wrap
+ * @config:	initialization data for V4L2 Flash controls
+ * @flash_ops:	V4L2 Flash device ops
+ * @out_flash:	handler to the new V4L2 Flash device
+ *
+ * Create V4L2 subdev wrapping given LED subsystem device.
+
+ * Returns: 0 on success or negative error value on failure
+ */
+int v4l2_flash_init(struct led_classdev_flash *led_fdev,
+		    struct v4l2_flash_ctrl_config *config,
+		    const struct v4l2_flash_ops *flash_ops,
+		    struct v4l2_flash **out_flash);
+
+/**
+ * v4l2_flash_release - release V4L2 Flash sub-device
+ * @flash: the V4L2 Flash device to release
+ *
+ * Release V4L2 flash led subdev.
+ */
+void v4l2_flash_release(struct v4l2_flash *v4l2_flash);
+
+#else
+#define v4l2_flash_init(led_cdev, config, flash_ops, out_flash) (0)
+#define v4l2_flash_release(v4l2_flash)
+#endif /* CONFIG_V4L2_FLASH_LED_CLASS */
+
+#endif /* _V4L2_FLASH_H */
Signature · 4 lines
Kind regards,

Sakari Ailus
[email protected]
#38 lore raw

Re: [PATCH/RFC v4 16/21] leds: Add support for max77693 mfd flash cell

In reply to Jacek Anaszewski

Hi Jacek,

Thanks for the patchset.

Quoted 95 lines · Jacek Anaszewski

This patch adds led-flash support to Maxim max77693 chipset. A device can be exposed to user space through LED subsystem sysfs interface or through V4L2 subdevice when the support for V4L2 Flash sub-devices is enabled. Device supports up to two leds which can work in flash and torch mode. Leds can be triggered externally or by software.

---
 drivers/leds/Kconfig         |    9 +
 drivers/leds/Makefile        |    1 +
 drivers/leds/leds-max77693.c | 1070 ++++++++++++++++++++++++++++++++++++++++++
 drivers/mfd/max77693.c       |    5 +-
 include/linux/mfd/max77693.h |   40 ++
 5 files changed, 1124 insertions(+), 1 deletion(-)
 create mode 100644 drivers/leds/leds-max77693.c
drivers/leds/Kconfig +9 -0
index 5032c6f..794055e 100644
@@ -457,6 +457,15 @@ config LEDS_TCA6507
 	  LED driver chips accessed via the I2C bus.
 	  Driver support brightness control and hardware-assisted blinking.
 
+config LEDS_MAX77693
+	tristate "LED support for MAX77693 Flash"
+	depends on LEDS_CLASS_FLASH
+	depends on MFD_MAX77693
+	help
+	  This option enables support for the flash part of the MAX77693
+	  multifunction device. It has build in control for two leds in flash
+	  and torch mode.
+
 config LEDS_MAX8997
 	tristate "LED support for MAX8997 PMIC"
 	depends on LEDS_CLASS && MFD_MAX8997
drivers/leds/Makefile +1 -0
index 237c5ba..da1a4ba 100644
@@ -55,6 +55,7 @@ obj-$(CONFIG_LEDS_MC13783)		+= leds-mc13783.o
 obj-$(CONFIG_LEDS_NS2)			+= leds-ns2.o
 obj-$(CONFIG_LEDS_NETXBIG)		+= leds-netxbig.o
 obj-$(CONFIG_LEDS_ASIC3)		+= leds-asic3.o
+obj-$(CONFIG_LEDS_MAX77693)		+= leds-max77693.o
 obj-$(CONFIG_LEDS_MAX8997)		+= leds-max8997.o
 obj-$(CONFIG_LEDS_LM355x)		+= leds-lm355x.o
 obj-$(CONFIG_LEDS_BLINKM)		+= leds-blinkm.o
drivers/leds/leds-max77693.c new file +33 -0
new file mode 100644
index 0000000..38a2398
@@ -0,0 +1,1070 @@
+/*
+ * LED Flash Class driver for the flash cell of max77693 mfd.
+ *
+ *	Copyright (C) 2014, Samsung Electronics Co., Ltd.
+ *
+ *	Authors: Jacek Anaszewski <[email protected]>
+ *		 Andrzej Hajda <[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 <asm/div64.h>
+#include <linux/led-class-flash.h>
+#include <linux/led-flash-manager.h>
+#include <linux/mfd/max77693.h>
+#include <linux/mfd/max77693-private.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+#include <linux/slab.h>
+#include <linux/workqueue.h>
+#include <media/v4l2-flash.h>
+
+#define MAX77693_LED_NAME_1		"max77693-flash_1"
+#define MAX77693_LED_NAME_2		"max77693-flash_2"
+
+#define MAX77693_TORCH_IOUT_BITS	4
+
+#define MAX77693_TORCH_NO_TIMER		0x40
+#define MAX77693_FLASH_TIMER_LEVEL	0x80

drivers/leds/leds-max77693.c line 43

Quoted 10 lines
drivers/leds/leds-max77693.c new file +10 -0
+
+#define MAX77693_FLASH_EN_OFF		0
+#define MAX77693_FLASH_EN_FLASH		1
+#define MAX77693_FLASH_EN_TORCH		2
+#define MAX77693_FLASH_EN_ON		3
+
+#define MAX77693_FLASH_EN1_SHIFT	6
+#define MAX77693_FLASH_EN2_SHIFT	4
+#define MAX77693_TORCH_EN1_SHIFT	2
+#define MAX77693_TORCH_EN2_SHIFT	0

Which registers are these definitions related to? Could they be defined next to the registers instead?

You could parameterise these macros, e.g.

#define MAX77693_FLASH_EN_SHIFT(a) (6 - ((a) - 1) * 2)

Quoted 65 lines
drivers/leds/leds-max77693.c new file +65 -0
+#define MAX77693_FLASH_LOW_BATTERY_EN	0x80
+
+#define MAX77693_FLASH_BOOST_FIXED	0x04
+#define MAX77693_FLASH_BOOST_LEDNUM_2	0x80
+
+#define MAX77693_FLASH_TIMEOUT_MIN	62500
+#define MAX77693_FLASH_TIMEOUT_MAX	1000000
+#define MAX77693_FLASH_TIMEOUT_STEP	62500
+
+#define MAX77693_TORCH_TIMEOUT_MIN	262000
+#define MAX77693_TORCH_TIMEOUT_MAX	15728000
+
+#define MAX77693_FLASH_IOUT_MIN		15625
+#define MAX77693_FLASH_IOUT_MAX_1LED	1000000
+#define MAX77693_FLASH_IOUT_MAX_2LEDS	625000
+#define MAX77693_FLASH_IOUT_STEP	15625
+
+#define MAX77693_TORCH_IOUT_MIN		15625
+#define MAX77693_TORCH_IOUT_MAX		250000
+#define MAX77693_TORCH_IOUT_STEP	15625
+
+#define MAX77693_FLASH_VSYS_MIN		2400
+#define MAX77693_FLASH_VSYS_MAX		3400
+#define MAX77693_FLASH_VSYS_STEP	33
+
+#define MAX77693_FLASH_VOUT_MIN		3300
+#define MAX77693_FLASH_VOUT_MAX		5500
+#define MAX77693_FLASH_VOUT_STEP	25
+#define MAX77693_FLASH_VOUT_RMIN	0x0c
+
+#define MAX77693_LED_STATUS_FLASH_ON	(1 << 3)
+#define MAX77693_LED_STATUS_TORCH_ON	(1 << 2)
+
+#define MAX77693_LED_FLASH_INT_FLED2_OPEN	(1 << 0)
+#define MAX77693_LED_FLASH_INT_FLED2_SHORT	(1 << 1)
+#define MAX77693_LED_FLASH_INT_FLED1_OPEN	(1 << 2)
+#define MAX77693_LED_FLASH_INT_FLED1_SHORT	(1 << 3)
+#define MAX77693_LED_FLASH_INT_OVER_CURRENT	(1 << 4)
+
+#define MAX77693_MODE_OFF			0
+#define MAX77693_MODE_FLASH1			(1 << 0)
+#define MAX77693_MODE_FLASH2			(1 << 1)
+#define MAX77693_MODE_TORCH1			(1 << 2)
+#define MAX77693_MODE_TORCH2			(1 << 3)
+#define MAX77693_MODE_FLASH_EXTERNAL1		(1 << 4)
+#define MAX77693_MODE_FLASH_EXTERNAL2		(1 << 5)
+
+enum {
+	FLED1,
+	FLED2
+};
+
+enum {
+	FLASH,
+	TORCH
+};
+
+struct max77693_led {
+	struct regmap *regmap;
+	struct platform_device *pdev;
+	struct max77693_led_platform_data *pdata;
+	struct mutex lock;
+
+	struct led_classdev_flash ldev1;
+	struct work_struct work1_brightness_set;

drivers/leds/leds-max77693.c line 119

Quoted 10 lines
drivers/leds/leds-max77693.c new file +10 -0
+	struct v4l2_flash *v4l2_flash1;
+
+	struct led_classdev_flash ldev2;
+	struct work_struct work2_brightness_set;
+	struct v4l2_flash *v4l2_flash2;
+
+	unsigned int torch1_brightness;
+	unsigned int torch2_brightness;
+	unsigned int flash1_timeout;
+	unsigned int flash2_timeout;

Could you use e.g. an array of structs instead? You could remove a lot of redundant code operating on the other led.

Quoted 5 lines
drivers/leds/leds-max77693.c new file +5 -0
+	unsigned int current_flash_timeout;
+	unsigned int mode_flags;
+	u8 torch_iout_reg;
+	bool iout_joint;
+};

...

Quoted 18 lines
drivers/leds/leds-max77693.c new file +18 -0
+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 *led;
+	struct max77693_led_platform_data *p;
+	int ret;
+
+	led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL);
+	if (!led)
+		return -ENOMEM;
+
+	led->pdev = pdev;
+	led->regmap = iodev->regmap;
+	platform_set_drvdata(pdev, led);
+	ret = max77693_led_get_platform_data(led);
+	if (ret < 0)
+		return -EINVAL;

drivers/leds/leds-max77693.c line 1003

Quoted 10 lines
drivers/leds/leds-max77693.c new file +10 -0
+
+	p = led->pdata;
+	mutex_init(&led->lock);
+
+	if (p->num_leds == 1 && p->fleds[FLED1] && p->fleds[FLED2])
+		led->iout_joint = true;
+
+	ret = max77693_setup(led);
+	if (ret < 0)
+		return ret;

goto err_register_led1;

Quoted 24 lines
drivers/leds/leds-max77693.c new file +24 -0
+	if (led->iout_joint || p->fleds[FLED1]) {
+		ret = max77693_register_led1(led);
+		if (ret < 0)
+			goto err_register_led1;
+	}
+
+	if (!led->iout_joint && p->fleds[FLED2]) {
+		ret = max77693_register_led2(led);
+		if (ret < 0)
+			goto err_register_led2;
+	}
+
+	return 0;
+
+err_register_led2:
+	if (!p->fleds[FLED1])
+		goto err_register_led1;
+	v4l2_flash_release(led->v4l2_flash1);
+	led_classdev_flash_unregister(&led->ldev1);
+err_register_led1:
+	mutex_destroy(&led->lock);
+
+	return ret;
+}

...

Signature · 4 lines
Kind regards,

Sakari Ailus
[email protected]
#19 lore raw

Re: [PATCH/RFC v4 07/21] of: add of_node_ncmp wrapper

In reply to Jacek Anaszewski
Quoted 17 lines · Jacek Anaszewski

The wrapper for strnicmp is required for checking whether a node has expected prefix.

Cc Grant Likely <[email protected]>
Cc Benjamin Herrenschmidt <[email protected]>
Cc Michal Simek <[email protected]>
---
 include/linux/of.h |    1 +
 1 file changed, 1 insertion(+)
include/linux/of.h +0 -0
index 692b56c..9a53eea 100644

include/linux/of.h static inline unsigned long of_read_ulong(const __be32 *cell, int size) · line 203

Quoted 5 lines
include/linux/of.h +1 -0
@@ -199,6 +199,7 @@ static inline unsigned long of_read_ulong(const __be32 *cell, int size)
 #define of_compat_cmp(s1, s2, l)	strcasecmp((s1), (s2))
 #define of_prop_cmp(s1, s2)		strcmp((s1), (s2))
 #define of_node_cmp(s1, s2)		strcasecmp((s1), (s2))
+#define of_node_ncmp(s1, s2, n)		strnicmp((s1), (s2), (n))
 #endif

Don't forget to add an of_node_ncmp() define to arch/sparc/include/asm/prom.h. Sparc has its own rules.

g.

#11 lore raw

Re: [PATCH/RFC v4 06/21] leds: add API for setting torch brightness

In reply to Sakari Ailus

Hi Sakari,

Quoted 40 lines · Sakari Ailus

Hi Jacek,

Jacek Anaszewski wrote:
...

Quoted 18 lines
include/linux/leds.h +4 -0
index 1a130cc..9bea9e6 100644
@@ -44,11 +44,21 @@ struct led_classdev {
  #define LED_BLINK_ONESHOT_STOP    (1 << 18)
  #define LED_BLINK_INVERT    (1 << 19)
  #define LED_SYSFS_LOCK        (1 << 20)
+#define LED_DEV_CAP_TORCH    (1 << 21)
 
      /* Set LED brightness level */
      /* Must not sleep, use a workqueue if needed */
      void        (*brightness_set)(struct led_classdev *led_cdev,
                        enum led_brightness brightness);
+    /*
+     * Set LED brightness immediately - it is required for flash led
+     * devices as they require setting torch brightness to have

immediate

include/linux/leds.h struct led_classdev { · line 59

Quoted 4 lines
include/linux/leds.h +4 -0
+     * effect. brightness_set op cannot be used for this purpose because
+     * the led drivers schedule a work queue task in it to allow for
+     * being called from led-triggers, i.e. from the timer irq context.
+     */

Do we need to classify actual devices based on this? I think it's rather a different API behaviour between the LED and the V4L2 APIs.

On devices that are slow to control, the behaviour should be asynchronous over the LED API and synchronous when accessed through the V4L2 API. How about implementing the work queue, as I have suggested, in the framework, so
that individual drivers don't need to care about this and just implement the
synchronous variant of this op? A flag could be added to distinguish devices
that are fast so that the work queue isn't needed.

Quoted 4 lines

It'd be nice to avoid individual drivers having to implement multiple ops to
do the same thing, just for differing user space interfacs.

It is not only the matter of a device controller speed. If a flash device is to be made accessible from the LED subsystem, then it should be also compatible with led-triggers. Some of led-triggers call brightness_set op from the timer irq context and thus no locking in the callback can occur. This requirement cannot be met i.e. if i2c bus is to be used. This is probably the primary reason for scheduling work queue tasks in brightness_set op.

Having the above in mind, setting a brightness in a work queue task must be possible for all LED Class Flash drivers, regardless whether related devices have fast or slow controller.

Let's recap the cost of possible solutions then:

1) Moving the work queues to the LED framework

- it would probably require extending led_set_brightness and __led_set_brightness functions by a parameter indicating whether it should call brightness_set op in the work queue task or directly;
- all existing triggers would have to be updated accordingly;
- work queues would have to be removed from all the LED drivers;

2) adding led_set_torch_brightness API

- no modifications in existing drivers and triggers would be required
- instead, only the modifications from the discussed patch would be required

Solution 1 looks cleaner but requires much more modifications.

Best Regards,
Jacek Anaszewski

#12 lore raw

Re: [PATCH/RFC v4 06/21] leds: add API for setting torch brightness

Hi Jacek,

Thank you for your continued efforts on this!

Quoted 68 lines · Jacek Anaszewski
Quoted 40 lines · Sakari Ailus

Hi Jacek,

Jacek Anaszewski wrote:
...

Quoted 18 lines
include/linux/leds.h +4 -0
index 1a130cc..9bea9e6 100644
@@ -44,11 +44,21 @@ struct led_classdev {
 #define LED_BLINK_ONESHOT_STOP    (1 << 18)
 #define LED_BLINK_INVERT    (1 << 19)
 #define LED_SYSFS_LOCK        (1 << 20)
+#define LED_DEV_CAP_TORCH    (1 << 21)
 
     /* Set LED brightness level */
     /* Must not sleep, use a workqueue if needed */
     void        (*brightness_set)(struct led_classdev *led_cdev,
                       enum led_brightness brightness);
+    /*
+     * Set LED brightness immediately - it is required for flash led
+     * devices as they require setting torch brightness to have

immediate

include/linux/leds.h struct led_classdev { · line 59

Quoted 4 lines
include/linux/leds.h +4 -0
+     * effect. brightness_set op cannot be used for this purpose because
+     * the led drivers schedule a work queue task in it to allow for
+     * being called from led-triggers, i.e. from the timer irq context.
+     */

Do we need to classify actual devices based on this? I think it's rather a different API behaviour between the LED and the V4L2 APIs.

On devices that are slow to control, the behaviour should be asynchronous over the LED API and synchronous when accessed through the V4L2 API. How about implementing the work queue, as I have suggested, in the framework, so
that individual drivers don't need to care about this and just implement the
synchronous variant of this op? A flag could be added to distinguish devices
that are fast so that the work queue isn't needed.

Quoted 4 lines

It'd be nice to avoid individual drivers having to implement multiple ops to
do the same thing, just for differing user space interfacs.

It is not only the matter of a device controller speed. If a flash device is to be made accessible from the LED subsystem, then it should be also compatible with led-triggers. Some of led-triggers call brightness_set op from the timer irq context and thus no locking in the callback can occur. This requirement cannot be met i.e. if i2c bus is to be used. This is probably the primary reason for scheduling work queue tasks in brightness_set op.

Having the above in mind, setting a brightness in a work queue task must be possible for all LED Class Flash drivers, regardless whether related devices have fast or slow controller.

Let's recap the cost of possible solutions then:

1) Moving the work queues to the LED framework

- it would probably require extending led_set_brightness and __led_set_brightness functions by a parameter indicating whether it should call brightness_set op in the work queue task or directly;
- all existing triggers would have to be updated accordingly;
- work queues would have to be removed from all the LED drivers;

Quoted 7 lines

2) adding led_set_torch_brightness API

- no modifications in existing drivers and triggers would be required
- instead, only the modifications from the discussed patch would be required

Solution 1 looks cleaner but requires much more modifications.

How about a combination of the two, i.e. option 1 with the old op remaining there for compatibility with the old drivers (with a comment telling it's deprecated)?

This way new drivers will benefit from having to implement this just once, and modifications to the existing drivers could be left for later. The downside is that any old drivers wouldn't get V4L2 flash API but that's entirely acceptable in my opinion since these would hardly be needed in use cases that would benefit from V4L2 flash API.

Signature · 4 lines
Kind regards,

Sakari Ailus
e-mail: [email protected]	XMPP: [email protected]
#29 lore raw

Re: [PATCH/RFC v4 15/21] media: Add registration helpers for V4L2 flash

In reply to Sakari Ailus

Hi Sakari,

Thanks for the review.

Quoted 211 lines · Sakari Ailus

Hi Jacek,

Quoted 208 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.

---
  drivers/media/v4l2-core/Kconfig      |   11 +
  drivers/media/v4l2-core/Makefile     |    2 +
  drivers/media/v4l2-core/v4l2-flash.c |  580 ++++++++++++++++++++++++++++++++++
  include/media/v4l2-flash.h           |  137 ++++++++
  4 files changed, 730 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
index 9ca0f8d..3ae3f0f 100644
@@ -35,6 +35,17 @@ config V4L2_MEM2MEM_DEV
          tristate
          depends on VIDEOBUF2_CORE
 
+# Used by LED subsystem flash drivers
+config V4L2_FLASH_LED_CLASS
+	bool "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
index 63d29f2..44e858c 100644
@@ -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 +148 -0
new file mode 100644
index 0000000..21080c6
@@ -0,0 +1,580 @@
+/*
+ * V4L2 Flash LED sub-device registration helpers.
+ *
+ *	Copyright (C) 2014 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/mutex.h>
+#include <linux/of_led_flash_manager.h>
+#include <linux/slab.h>
+#include <media/v4l2-flash.h>
+
+#define call_flash_op(v4l2_flash, op, args...)			\
+		(v4l2_flash->ops->op  ?				\
+			v4l2_flash->ops->op(args) :		\
+			-EINVAL)
+
+static struct v4l2_device *v4l2_dev;
+static int registered_flashes;
+
+static inline enum led_brightness v4l2_flash_intensity_to_led_brightness(
+					struct v4l2_ctrl_config *config,
+					s32 intensity)
+{
+	return ((intensity - config->min) / config->step) + 1;
+}
+
+static inline s32 v4l2_flash_led_brightness_to_intensity(
+					struct v4l2_ctrl_config *config,
+					enum led_brightness brightness)
+{
+	return ((brightness - 1) * config->step) + config->min;
+}
+
+static int v4l2_flash_g_volatile_ctrl(struct v4l2_ctrl *c)
+
+{
+	struct v4l2_flash *v4l2_flash = v4l2_ctrl_to_v4l2_flash(c);
+	struct led_classdev_flash *flash = v4l2_flash->flash;
+	struct led_classdev *led_cdev = &flash->led_cdev;
+	struct v4l2_flash_ctrl_config *config = &v4l2_flash->config;
+	struct v4l2_flash_ctrl *ctrl = &v4l2_flash->ctrl;
+	bool is_strobing;
+	int ret;
+
+	switch (c->id) {
+	case V4L2_CID_FLASH_TORCH_INTENSITY:
+		/*
+		 * Update torch brightness only if in TORCH_MODE,
+		 * as otherwise brightness_update op returns 0,
+		 * which would spuriously inform user space that
+		 * V4L2_CID_FLASH_TORCH_INTENSITY control value
+		 * has changed.
+		 */
+		if (ctrl->led_mode->val == V4L2_FLASH_LED_MODE_TORCH) {
+			ret = call_flash_op(v4l2_flash, torch_brightness_update,
+							led_cdev);
+			if (ret < 0)
+				return ret;
+			ctrl->torch_intensity->val =
+				v4l2_flash_led_brightness_to_intensity(
+						&config->torch_intensity,
+						led_cdev->brightness);
+		}
+		return 0;
+	case V4L2_CID_FLASH_INTENSITY:
+		ret = call_flash_op(v4l2_flash, flash_brightness_update,
+					flash);
+		if (ret < 0)
+			return ret;
+		/* no conversion is needed */
+		c->val = flash->brightness.val;
+		return 0;
+	case V4L2_CID_FLASH_INDICATOR_INTENSITY:
+		ret = call_flash_op(v4l2_flash, indicator_brightness_update,
+						flash);
+		if (ret < 0)
+			return ret;
+		/* no conversion is needed */
+		c->val = flash->indicator_brightness->val;
+		return 0;
+	case V4L2_CID_FLASH_STROBE_STATUS:
+		ret = call_flash_op(v4l2_flash, strobe_get, flash,
+							&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 */
+		ret = call_flash_op(v4l2_flash, fault_get, flash, &c->val);
+		return ret;
+	case V4L2_CID_FLASH_STROBE_SOURCE:
+		c->val = flash->external_strobe;
+		return 0;
+	case V4L2_CID_FLASH_STROBE_PROVIDER:
+		c->val = flash->strobe_provider_id;
+		return 0;
+	default:
+		return -EINVAL;
+	}
+}
+
+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 *flash = v4l2_flash->flash;
+	struct v4l2_flash_ctrl *ctrl = &v4l2_flash->ctrl;
+	struct v4l2_flash_ctrl_config *config = &v4l2_flash->config;
+	enum led_brightness torch_brightness;
+	bool external_strobe;
+	int ret;
+
+	switch (c->id) {
+	case V4L2_CID_FLASH_LED_MODE:
+		switch (c->val) {
+		case V4L2_FLASH_LED_MODE_NONE:
+			call_flash_op(v4l2_flash, torch_brightness_set,
+							&flash->led_cdev, 0);
+			return call_flash_op(v4l2_flash, strobe_set, flash,
+							false);
+		case V4L2_FLASH_LED_MODE_FLASH:
+			/* Turn off torch LED */
+			call_flash_op(v4l2_flash, torch_brightness_set,
+							&flash->led_cdev, 0);
+			external_strobe = (ctrl->source->val ==
+					V4L2_FLASH_STROBE_SOURCE_EXTERNAL);
+			return call_flash_op(v4l2_flash, external_strobe_set,
+						flash, external_strobe);
+		case V4L2_FLASH_LED_MODE_TORCH:
+			/* Stop flash strobing */
+			ret = call_flash_op(v4l2_flash, strobe_set, flash,
+							false);
+			if (ret)
+				return ret;
+
+			torch_brightness =
+				v4l2_flash_intensity_to_led_brightness(
+						&config->torch_intensity,
+						ctrl->torch_intensity->val);
+			call_flash_op(v4l2_flash, torch_brightness_set,
+					&flash->led_cdev, torch_brightness);
+			return ret;
Quoted 8 lines

drivers/media/v4l2-core/v4l2-flash.c line 152

Quoted 4 lines
drivers/media/v4l2-core/v4l2-flash.c new file +4 -0
+		}
+		break;
+	case V4L2_CID_FLASH_STROBE_SOURCE:
+		external_strobe = (c->val == V4L2_FLASH_STROBE_SOURCE_EXTERNAL);

Is the external_strobe argument match exactly to the strobe source control? You seem to assume that in g_volatile_ctrl() above. I think having it the either way is fine but not both. :-)

The STROBE_SOURCE_EXTERNAL control state is volatile if a flash device depends on muxes that route strobe signals to more then one flash device. In such a case it behaves similarly to FLASH_STROBE control, i.e. it activates external strobe only for the flash timeout period. I touched this issue in the cover letter of this patch series, paragraph 2.

Quoted 12 lines

drivers/media/v4l2-core/v4l2-flash.c line 161

Quoted 9 lines
drivers/media/v4l2-core/v4l2-flash.c new file +8 -0
+		return call_flash_op(v4l2_flash, external_strobe_set, flash,
+							external_strobe);
+	case V4L2_CID_FLASH_STROBE:
+		if (ctrl->led_mode->val != V4L2_FLASH_LED_MODE_FLASH ||
+		    ctrl->source->val != V4L2_FLASH_STROBE_SOURCE_SOFTWARE)
+			return -EINVAL;
+		return call_flash_op(v4l2_flash, strobe_set, flash, true);
+	case V4L2_CID_FLASH_STROBE_STOP:

Should we check the flash mode here? I guess so. How about strobe source as well?

Good point.

Quoted 155 lines
Quoted 155 lines
drivers/media/v4l2-core/v4l2-flash.c new file +155 -0
+		return call_flash_op(v4l2_flash, strobe_set, flash, false);
+	case V4L2_CID_FLASH_TIMEOUT:
+		return call_flash_op(v4l2_flash, timeout_set, flash, c->val);
+	case V4L2_CID_FLASH_INTENSITY:
+		/* no conversion is needed */
+		return call_flash_op(v4l2_flash, flash_brightness_set, flash,
+								c->val);
+	case V4L2_CID_FLASH_INDICATOR_INTENSITY:
+		/* no conversion is needed */
+		return call_flash_op(v4l2_flash, indicator_brightness_set,
+						flash, c->val);
+	case V4L2_CID_FLASH_TORCH_INTENSITY:
+		/*
+		 * If not in MODE_TORCH don't call led-class brightness_set
+		 * op, as it would result in turning the torch led on.
+		 * Instead the value is cached only and will be written
+		 * to the device upon transition to MODE_TORCH.
+		 */
+		if (ctrl->led_mode->val == V4L2_FLASH_LED_MODE_TORCH) {
+			torch_brightness =
+				v4l2_flash_intensity_to_led_brightness(
+						&config->torch_intensity,
+						ctrl->torch_intensity->val);
+			call_flash_op(v4l2_flash, torch_brightness_set,
+					&flash->led_cdev, torch_brightness);
+		}
+		return 0;
+	case V4L2_CID_FLASH_STROBE_PROVIDER:
+		flash->strobe_provider_id = c->val;
+		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 int v4l2_flash_init_strobe_providers_menu(struct v4l2_flash *v4l2_flash)
+{
+	struct led_classdev_flash *flash = v4l2_flash->flash;
+	struct led_flash_strobe_provider *provider;
+	struct v4l2_ctrl *ctrl;
+	int i = 0;
+
+	v4l2_flash->strobe_providers_menu =
+			kzalloc(sizeof(char *) * (flash->num_strobe_providers),
+					GFP_KERNEL);
+	if (!v4l2_flash->strobe_providers_menu)
+		return -ENOMEM;
+
+	list_for_each_entry(provider, &flash->strobe_providers, list)
+		v4l2_flash->strobe_providers_menu[i++] =
+						(char *) provider->name;
+
+	ctrl = v4l2_ctrl_new_std_menu_items(
+		&v4l2_flash->hdl, &v4l2_flash_ctrl_ops,
+		V4L2_CID_FLASH_STROBE_PROVIDER,
+		flash->num_strobe_providers - 1,
+		0, 0,
+		(const char * const *) v4l2_flash->strobe_providers_menu);
+
+	if (ctrl)
+		ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;
+
+	return 0;
+}
+
+static int v4l2_flash_init_controls(struct v4l2_flash *v4l2_flash)
+
+{
+	struct led_classdev_flash *flash = v4l2_flash->flash;
+	const struct led_flash_ops *flash_ops = flash->ops;
+	struct led_classdev *led_cdev = &flash->led_cdev;
+	struct v4l2_flash_ctrl_config *config = &v4l2_flash->config;
+	struct v4l2_ctrl *ctrl;
+	struct v4l2_ctrl_config *ctrl_cfg;
+	bool has_flash = led_cdev->flags & LED_DEV_CAP_FLASH;
+	bool has_indicator = led_cdev->flags & LED_DEV_CAP_INDICATOR;
+	bool has_strobe_providers = (flash->num_strobe_providers > 1);
+	unsigned int mask;
+	int ret, max, num_ctrls;
+
+	num_ctrls = has_flash ? 5 : 2;
+	if (has_flash) {
+		if (flash_ops->flash_brightness_set)
+			++num_ctrls;
+		if (flash_ops->timeout_set)
+			++num_ctrls;
+		if (flash_ops->strobe_get)
+			++num_ctrls;
+		if (has_indicator)
+			++num_ctrls;
+		if (config->flash_faults)
+			++num_ctrls;
+		if (has_strobe_providers)
+			++num_ctrls;
+	}
+
+	v4l2_ctrl_handler_init(&v4l2_flash->hdl, num_ctrls);
+
+	mask = 1 << V4L2_FLASH_LED_MODE_NONE |
+	       1 << V4L2_FLASH_LED_MODE_TORCH;
+	if (flash)
+		mask |= 1 << V4L2_FLASH_LED_MODE_FLASH;
+
+	/* Configure FLASH_LED_MODE ctrl */
+	v4l2_flash->ctrl.led_mode = v4l2_ctrl_new_std_menu(
+			&v4l2_flash->hdl,
+			&v4l2_flash_ctrl_ops, V4L2_CID_FLASH_LED_MODE,
+			V4L2_FLASH_LED_MODE_TORCH, ~mask,
+			V4L2_FLASH_LED_MODE_NONE);
+
+	/* Configure TORCH_INTENSITY ctrl */
+	ctrl_cfg = &config->torch_intensity;
+	ctrl = v4l2_ctrl_new_std(&v4l2_flash->hdl, &v4l2_flash_ctrl_ops,
+				 V4L2_CID_FLASH_TORCH_INTENSITY,
+				 ctrl_cfg->min, ctrl_cfg->max,
+				 ctrl_cfg->step, ctrl_cfg->def);
+	if (ctrl)
+		ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;
+	v4l2_flash->ctrl.torch_intensity = ctrl;
+
+	if (has_flash) {
+		/* Configure FLASH_STROBE_SOURCE ctrl */
+		mask = 1 << V4L2_FLASH_STROBE_SOURCE_SOFTWARE;
+
+		if (flash->has_external_strobe) {
+			mask |= 1 << V4L2_FLASH_STROBE_SOURCE_EXTERNAL;
+			max = V4L2_FLASH_STROBE_SOURCE_EXTERNAL;
+		} else {
+			max = V4L2_FLASH_STROBE_SOURCE_SOFTWARE;
+		}
+
+		v4l2_flash->ctrl.source = v4l2_ctrl_new_std_menu(
+					&v4l2_flash->hdl,
+					&v4l2_flash_ctrl_ops,
+					V4L2_CID_FLASH_STROBE_SOURCE,
+					max,
+					~mask,
+					V4L2_FLASH_STROBE_SOURCE_SOFTWARE);
+		if (v4l2_flash->ctrl.source)
+			v4l2_flash->ctrl.source->flags |=
+						V4L2_CTRL_FLAG_VOLATILE;
+
+		/* Configure FLASH_STROBE ctrl */
+		ctrl = v4l2_ctrl_new_std(&v4l2_flash->hdl, &v4l2_flash_ctrl_ops,
+					  V4L2_CID_FLASH_STROBE, 0, 1, 1, 0);
+
+		/* Configure FLASH_STROBE_STOP ctrl */
+		ctrl = v4l2_ctrl_new_std(&v4l2_flash->hdl, &v4l2_flash_ctrl_ops,
+					  V4L2_CID_FLASH_STROBE_STOP,
+					  0, 1, 1, 0);
Quoted 8 lines

drivers/media/v4l2-core/v4l2-flash.c line 321

Quoted 5 lines
drivers/media/v4l2-core/v4l2-flash.c new file +5 -0
+
+		/* Configure FLASH_STROBE_STATUS ctrl */
+		ctrl = v4l2_ctrl_new_std(&v4l2_flash->hdl, &v4l2_flash_ctrl_ops,
+					 V4L2_CID_FLASH_STROBE_STATUS,
+					 0, 1, 1, 1);

I think you only should implement the strobe status control if you really can know it, i.e. have strobe_get().

Of course, thanks.

Quoted 47 lines
Quoted 47 lines
drivers/media/v4l2-core/v4l2-flash.c new file +47 -0
+		if (flash_ops->strobe_get)
+			if (ctrl)
+				ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE |
+					       V4L2_CTRL_FLAG_READ_ONLY;
+
+		if (flash_ops->timeout_set) {
+			/* Configure FLASH_TIMEOUT ctrl */
+			ctrl_cfg = &config->flash_timeout;
+			ctrl = v4l2_ctrl_new_std(
+					&v4l2_flash->hdl, &v4l2_flash_ctrl_ops,
+					V4L2_CID_FLASH_TIMEOUT, ctrl_cfg->min,
+					ctrl_cfg->max, ctrl_cfg->step,
+					ctrl_cfg->def);
+			if (ctrl)
+				ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;
+		}
+
+		if (flash_ops->flash_brightness_set) {
+			/* Configure FLASH_INTENSITY ctrl */
+			ctrl_cfg = &config->flash_intensity;
+			ctrl = v4l2_ctrl_new_std(
+					&v4l2_flash->hdl,
+					&v4l2_flash_ctrl_ops,
+					V4L2_CID_FLASH_INTENSITY,
+					ctrl_cfg->min, ctrl_cfg->max,
+					ctrl_cfg->step, ctrl_cfg->def);
+			if (ctrl)
+				ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;
+		}
+
+		if (config->flash_faults) {
+			/* Configure FLASH_FAULT ctrl */
+			ctrl = v4l2_ctrl_new_std(&v4l2_flash->hdl,
+						 &v4l2_flash_ctrl_ops,
+						 V4L2_CID_FLASH_FAULT, 0,
+						 config->flash_faults,
+						 0, 0);
+			if (ctrl)
+				ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE |
+					       V4L2_CTRL_FLAG_READ_ONLY;
+		}
+		if (has_indicator) {
+			/* Configure FLASH_INDICATOR_INTENSITY ctrl */
+			ctrl_cfg = &config->indicator_intensity;
+			ctrl = v4l2_ctrl_new_std(
+					&v4l2_flash->hdl, &v4l2_flash_ctrl_ops,
+					V4L2_CID_FLASH_INDICATOR_INTENSITY,
Quoted 8 lines

drivers/media/v4l2-core/v4l2-flash.c line 296

Quoted 5 lines
drivers/media/v4l2-core/v4l2-flash.c new file +5 -0
+					ctrl_cfg->min, ctrl_cfg->max,
+					ctrl_cfg->step, ctrl_cfg->def);
+			if (ctrl)
+				ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;
+		}

Could you implement the above in a loop? You're essentially repeating the same but with different parameters.

Sure.

Quoted 33 lines
Quoted 33 lines
drivers/media/v4l2-core/v4l2-flash.c new file +33 -0
+		if (has_strobe_providers) {
+			/* Configure V4L2_CID_FLASH_STROBE_PROVIDERS ctrl */
+			ret = v4l2_flash_init_strobe_providers_menu(v4l2_flash);
+			if (ret < 0)
+				goto error_free_handler;
+		}
+	}
+
+	if (v4l2_flash->hdl.error) {
+		ret = v4l2_flash->hdl.error;
+		goto error_free_handler;
+	}
+
+	ret = v4l2_ctrl_handler_setup(&v4l2_flash->hdl);
+	if (ret < 0)
+		goto error_free_handler;
+
+	v4l2_flash->sd.ctrl_handler = &v4l2_flash->hdl;
+
+	return 0;
+
+error_free_handler:
+	v4l2_ctrl_handler_free(&v4l2_flash->hdl);
+	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);
Quoted 8 lines

drivers/media/v4l2-core/v4l2-flash.c line 413

Quoted 5 lines
drivers/media/v4l2-core/v4l2-flash.c new file +5 -0
+	struct led_classdev_flash *flash = v4l2_flash->flash;
+	struct led_classdev *led_cdev = &flash->led_cdev;
+
+	mutex_lock(&led_cdev->led_lock);
+	call_flash_op(v4l2_flash, sysfs_lock, led_cdev);

What if you have the device open through multiple file handles? I believe v4l2_subdev_fh_is_singular(&fh->vfh) would prove helpful here.

I assume you propose to implement such a function? I don't see it in the mainline kernel.

Quoted 13 lines
Quoted 13 lines
drivers/media/v4l2-core/v4l2-flash.c new file +13 -0
+	mutex_unlock(&led_cdev->led_lock);
+
+	return 0;
+}
+
+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 *flash = v4l2_flash->flash;
+	struct led_classdev *led_cdev = &flash->led_cdev;
+
+	mutex_lock(&led_cdev->led_lock);
+	call_flash_op(v4l2_flash, sysfs_unlock, led_cdev);
Quoted 8 lines

drivers/media/v4l2-core/v4l2-flash.c line 432

Quoted 6 lines
drivers/media/v4l2-core/v4l2-flash.c new file +6 -0
+	mutex_unlock(&led_cdev->led_lock);
+
+	return 0;
+}
+
+int v4l2_flash_register(struct v4l2_flash *v4l2_flash)

Do you expect to call this from elsewhere than this file?

No, I just forgot about 'static' keyword here :)

Quoted 42 lines
Quoted 23 lines
drivers/media/v4l2-core/v4l2-flash.c new file +23 -0
+{
+	struct led_classdev_flash *flash = v4l2_flash->flash;
+	struct led_classdev *led_cdev = &flash->led_cdev;
+	int ret;
+
+	if (!v4l2_dev) {
+		v4l2_dev = kzalloc(sizeof(*v4l2_dev), GFP_KERNEL);
+		if (!v4l2_dev)
+			return -ENOMEM;
+
+		strlcpy(v4l2_dev->name, "v4l2-flash-manager",
+						sizeof(v4l2_dev->name));
+		ret = v4l2_device_register(NULL, v4l2_dev);
+		if (ret < 0) {
+			dev_err(led_cdev->dev->parent,
+				 "Failed to register v4l2_device: %d\n", ret);
+			goto err_v4l2_device_register;
+		}
+	}
+
+	ret = v4l2_device_register_subdev(v4l2_dev, &v4l2_flash->sd);
+	if (ret < 0) {
+		dev_err(led_cdev->dev->parent,

drivers/media/v4l2-core/v4l2-flash.c line 465

Quoted 10 lines
drivers/media/v4l2-core/v4l2-flash.c new file +10 -0
+			 "Failed to register v4l2_subdev: %d\n", ret);
+		goto err_v4l2_device_register;
+	}
+
+	ret = v4l2_device_register_subdev_node(&v4l2_flash->sd, v4l2_dev);
+	if (ret < 0) {
+		dev_err(led_cdev->dev->parent,
+			 "Failed to register v4l2_subdev node: %d\n", ret);
+		goto err_register_subdev_node;
+	}

This way you can create a V4L2 sub-device node. However, flash devices are seldom alone in the system. They are physically close to a sensor, and this connection is shown in the Media controller interface. This means that the flash sub-device (entity) should be part of the Media device created by the driver in control of it. This can be achieved by the master driver creating the sub-device. You should register an async sub-device here.

Quoted 3 lines

This results in the sub-device not being registered if there's no such master driver, but I wouldn't expect that to be an issue since the V4L2 flash API is mostly relevant in such cases.

I addressed this issue in the cover letter of this patch series, paragraph 1. If strobe signals are routed to a flash device through a multiplexer then assignment of the related V4L2 Flash sub-device to a particular media controller may dynamically change in time. Actually, if a flash device can be shared between media systems (i.e. it can be configured to react on strobe signals from different camera sensors, basing on muxes configuration), than it becomes bound to a particular media system only for the time of strobing. Please refer to [1].

Quoted 83 lines
Quoted 83 lines
drivers/media/v4l2-core/v4l2-flash.c new file +83 -0
+	++registered_flashes;
+
+	return 0;
+
+err_register_subdev_node:
+	v4l2_device_unregister_subdev(&v4l2_flash->sd);
+err_v4l2_device_register:
+	kfree(v4l2_flash->strobe_providers_menu);
+	if (v4l2_dev && registered_flashes == 0) {
+		v4l2_device_unregister(v4l2_dev);
+		kfree(v4l2_dev);
+		v4l2_dev = NULL;
+	}
+
+	return ret;
+}
+
+static void v4l2_flash_unregister(struct v4l2_flash *v4l2_flash)
+{
+	if (registered_flashes == 0)
+		return;
+
+	v4l2_device_unregister_subdev(&v4l2_flash->sd);
+
+	--registered_flashes;
+
+	if (registered_flashes == 0) {
+		v4l2_device_unregister(v4l2_dev);
+		kfree(v4l2_dev);
+		v4l2_dev = NULL;
+	}
+}
+
+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,
+};
+
+int v4l2_flash_init(struct led_classdev_flash *flash,
+		    struct v4l2_flash_ctrl_config *config,
+		    const struct v4l2_flash_ops *flash_ops,
+		    struct v4l2_flash **out_flash)
+{
+	struct v4l2_flash *v4l2_flash;
+	struct led_classdev *led_cdev = &flash->led_cdev;
+	struct v4l2_subdev *sd;
+	int ret;
+
+	if (!flash || !config || !out_flash)
+		return -EINVAL;
+
+	v4l2_flash = kzalloc(sizeof(*v4l2_flash), GFP_KERNEL);
+	if (!v4l2_flash)
+		return -ENOMEM;
+
+	sd = &v4l2_flash->sd;
+	v4l2_flash->flash = flash;
+	v4l2_flash->ops = flash_ops;
+	sd->dev = led_cdev->dev->parent;
+	v4l2_subdev_init(sd, &v4l2_flash_subdev_ops);
+	sd->internal_ops = &v4l2_flash_subdev_internal_ops;
+	sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
+	snprintf(sd->name, sizeof(sd->name), led_cdev->name);
+
+	v4l2_flash->config = *config;
+	ret = v4l2_flash_init_controls(v4l2_flash);
+	if (ret < 0)
+		goto err_init_controls;
+
+	ret = media_entity_init(&sd->entity, 0, NULL, 0);
+	if (ret < 0)
+		goto err_init_entity;
+
+	sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV_FLASH;
Quoted 8 lines

drivers/media/v4l2-core/v4l2-flash.c line 555

Quoted 6 lines
drivers/media/v4l2-core/v4l2-flash.c new file +6 -0
+
+	ret = v4l2_flash_register(v4l2_flash);
+	if (ret < 0)
+		goto err_init_entity;
+
+	*out_flash = v4l2_flash;

How about returning the pointer instead?

OK.

Quoted 68 lines
Quoted 68 lines
drivers/media/v4l2-core/v4l2-flash.c new file +24 -0
+	return 0;
+
+err_init_entity:
+	media_entity_cleanup(&sd->entity);
+err_init_controls:
+	v4l2_ctrl_handler_free(sd->ctrl_handler);
+	kfree(v4l2_flash);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(v4l2_flash_init);
+
+void v4l2_flash_release(struct v4l2_flash *v4l2_flash)
+{
+	if (!v4l2_flash)
+		return;
+
+	v4l2_flash_unregister(v4l2_flash);
+	v4l2_ctrl_handler_free(v4l2_flash->sd.ctrl_handler);
+	media_entity_cleanup(&v4l2_flash->sd.entity);
+	kfree(v4l2_flash->strobe_providers_menu);
+	kfree(v4l2_flash);
+}
+EXPORT_SYMBOL_GPL(v4l2_flash_release);
include/media/v4l2-flash.h new file +38 -0
new file mode 100644
index 0000000..effa46b
@@ -0,0 +1,137 @@
+/*
+ * V4L2 Flash LED sub-device registration helpers.
+ *
+ *	Copyright (C) 2014 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."
+ */
+
+#ifndef _V4L2_FLASH_H
+#define _V4L2_FLASH_H
+
+#include <media/v4l2-ctrls.h>
+#include <media/v4l2-device.h>
+#include <media/v4l2-dev.h>
+#include <media/v4l2-event.h>
+#include <media/v4l2-ioctl.h>
+
+struct led_classdev_flash;
+struct led_classdev;
+enum led_brightness;
+
+struct v4l2_flash_ops {
+	int (*torch_brightness_set)(struct led_classdev *led_cdev,
+					enum led_brightness brightness);
+	int (*torch_brightness_update)(struct led_classdev *led_cdev);
+	int (*flash_brightness_set)(struct led_classdev_flash *flash,
+					u32 brightness);
+	int (*flash_brightness_update)(struct led_classdev_flash *flash);
+	int (*strobe_set)(struct led_classdev_flash *flash, bool state);
+	int (*strobe_get)(struct led_classdev_flash *flash, bool *state);
+	int (*timeout_set)(struct led_classdev_flash *flash, u32 timeout);
+	int (*indicator_brightness_set)(struct led_classdev_flash *flash,
+					u32 brightness);
+	int (*indicator_brightness_update)(struct led_classdev_flash *flash);
+	int (*external_strobe_set)(struct led_classdev_flash *flash,
Quoted 8 lines

include/media/v4l2-flash.h line 42

Quoted 4 lines
include/media/v4l2-flash.h new file +4 -0
+					bool enable);
+	int (*fault_get)(struct led_classdev_flash *flash, u32 *fault);
+	void (*sysfs_lock)(struct led_classdev *led_cdev);
+	void (*sysfs_unlock)(struct led_classdev *led_cdev);

These functions are not driver specific and there's going to be just one implementation (I suppose). Could you refresh my memory regarding why the LED framework functions aren't called directly?

These ops are required to make possible building led-class-flash as a kernel module.

Quoted 88 lines
Quoted 88 lines
include/media/v4l2-flash.h new file +88 -0
+};
+
+/**
+ * struct v4l2_flash_ctrl - controls that define the sub-dev's state
+ * @source:		V4L2_CID_FLASH_STROBE_SOURCE control
+ * @led_mode:		V4L2_CID_FLASH_LED_MODE control
+ * @torch_intensity:	V4L2_CID_FLASH_TORCH_INTENSITY control
+ */
+struct v4l2_flash_ctrl {
+	struct v4l2_ctrl *source;
+	struct v4l2_ctrl *led_mode;
+	struct v4l2_ctrl *torch_intensity;
+};
+
+/**
+ * struct v4l2_flash_ctrl_config - V4L2 Flash controls initialization data
+ * @torch_intensity:		V4L2_CID_FLASH_TORCH_INTENSITY constraints
+ * @flash_intensity:		V4L2_CID_FLASH_INTENSITY constraints
+ * @indicator_intensity:	V4L2_CID_FLASH_INDICATOR_INTENSITY constraints
+ * @flash_timeout:		V4L2_CID_FLASH_TIMEOUT constraints
+ * @flash_fault:		possible flash faults
+ */
+struct v4l2_flash_ctrl_config {
+	struct v4l2_ctrl_config torch_intensity;
+	struct v4l2_ctrl_config flash_intensity;
+	struct v4l2_ctrl_config indicator_intensity;
+	struct v4l2_ctrl_config flash_timeout;
+	u32 flash_faults;
+};
+
+/**
+ * struct v4l2_flash - Flash sub-device context
+ * @flash:		LED Flash Class device controlled by this sub-device
+ * @ops:		LED Flash Class device ops
+ * @sd:			V4L2 sub-device
+ * @hdl:		flash controls handler
+ * @ctrl:		state defining controls
+ * @config:		V4L2 Flash controlsrconfiguration data
+ * @software_strobe_gates: route to the software strobe signal
+ * @external_strobe_gates: route to the external strobe signal
+ * @sensors:		available external strobe sources
+ */
+struct v4l2_flash {
+	struct led_classdev_flash *flash;
+	const struct v4l2_flash_ops *ops;
+
+	struct v4l2_subdev sd;
+	struct v4l2_ctrl_handler hdl;
+	struct v4l2_flash_ctrl ctrl;
+	struct v4l2_flash_ctrl_config config;
+	char **strobe_providers_menu;
+};
+
+static inline struct v4l2_flash *v4l2_subdev_to_v4l2_flash(
+							struct v4l2_subdev *sd)
+{
+	return container_of(sd, struct v4l2_flash, sd);
+}
+
+static inline struct v4l2_flash *v4l2_ctrl_to_v4l2_flash(struct v4l2_ctrl *c)
+{
+	return container_of(c->handler, struct v4l2_flash, hdl);
+}
+
+#ifdef CONFIG_V4L2_FLASH_LED_CLASS
+/**
+ * v4l2_flash_init - initialize V4L2 flash led sub-device
+ * @led_fdev:	the LED Flash Class device to wrap
+ * @config:	initialization data for V4L2 Flash controls
+ * @flash_ops:	V4L2 Flash device ops
+ * @out_flash:	handler to the new V4L2 Flash device
+ *
+ * Create V4L2 subdev wrapping given LED subsystem device.
+
+ * Returns: 0 on success or negative error value on failure
+ */
+int v4l2_flash_init(struct led_classdev_flash *led_fdev,
+		    struct v4l2_flash_ctrl_config *config,
+		    const struct v4l2_flash_ops *flash_ops,
+		    struct v4l2_flash **out_flash);
+
+/**
+ * v4l2_flash_release - release V4L2 Flash sub-device
+ * @flash: the V4L2 Flash device to release
+ *
+ * Release V4L2 flash led subdev.
+ */
+void v4l2_flash_release(struct v4l2_flash *v4l2_flash);
Quoted 9 lines

include/media/v4l2-flash.h line 137

Quoted 8 lines
include/media/v4l2-flash.h new file +7 -0
+
+#else
+#define v4l2_flash_init(led_cdev, config, flash_ops, out_flash) (0)
+#define v4l2_flash_release(v4l2_flash)
+#endif /* CONFIG_V4L2_FLASH_LED_CLASS */
+
+#endif /* _V4L2_FLASH_H */

Best Regards,
Jacek Anaszewski

[1] - https://lkml.org/lkml/2014/7/11/942
--
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

#49 lore raw
In reply to Jacek Anaszewski

Hi Jacek,

On Fri, Jul 11, 2014 at 04:04:03PM +0200, Jacek Anaszewski wrote:
...

Quoted 12 lines

1) Who should register V4L2 Flash sub-device?

LED Flash Class devices, after introduction of the Flash Manager, are not tightly coupled with any media controller. They are maintained by the Flash Manager and made available for dynamic assignment to any media system they are connected to through multiplexing devices.

In the proposed rough solution, when support for V4L2 Flash sub-devices is enabled, there is a v4l2_device created for them to register in. This however implies that V4L2 Flash device will not be available in any media controller, which calls its existence into question.

Quoted 8 lines

Therefore I'd like to consult possible ways of solving this issue. The option I see is implementing a mechanism for moving V4L2 Flash sub-devices between media controllers. A V4L2 Flash sub-device would initially be assigned to one media system in the relevant device tree binding, but it could be dynamically reassigned to the other one. However I'm not sure if media controller design is prepared for dynamic modifications of its graph and how many modifications in the existing drivers this solution would require.

Do you have a use case where you would need to strobe a flash from multiple media devices at different times, or is this entirely theoretical? Typically flash controllers are connected to a single source of hardware strobe (if there's one) since the flash LEDs are in fact mounted next to a specific camera sensor.

If this is a real issue the way to solve it would be to have a single media device instead of many.

Quoted 7 lines

2) Consequences of locking the Flash Manager during flash strobe

In case a LED Flash Class device depends on muxes involved in routing the other LED Flash Class device's strobe signals, the Flash Manager must be locked for the time of strobing to prevent reconfiguration of the strobe signal routing by the other device.

I wouldn't be concerned of this in particular. It's more important we do actully have V4L2 flash API supported by LED flash drivers and that they do implement the API correctly.

It's at least debatable whether you should try to prevent user space from doing silly things or not. With complex devices it may relatively easily lead to wrecking havoc with actual use cases which we certainly do not want.

In this case, if you just prevent changing the routing (do you have a use case for it?) while strobing, someone else could still change the routing just before you strobe.

Signature · 4 lines
Kind regards,

Sakari Ailus
e-mail: [email protected]	XMPP: [email protected]
#50 lore raw

Hi Sakari,

Quoted 25 lines · Sakari Ailus

Hi Jacek,

On Fri, Jul 11, 2014 at 04:04:03PM +0200, Jacek Anaszewski wrote:
...

Quoted 12 lines

1) Who should register V4L2 Flash sub-device?

LED Flash Class devices, after introduction of the Flash Manager, are not tightly coupled with any media controller. They are maintained by the Flash Manager and made available for dynamic assignment to any media system they are connected to through multiplexing devices.

In the proposed rough solution, when support for V4L2 Flash sub-devices is enabled, there is a v4l2_device created for them to register in. This however implies that V4L2 Flash device will not be available in any media controller, which calls its existence into question.

Quoted 8 lines

Therefore I'd like to consult possible ways of solving this issue. The option I see is implementing a mechanism for moving V4L2 Flash sub-devices between media controllers. A V4L2 Flash sub-device would initially be assigned to one media system in the relevant device tree binding, but it could be dynamically reassigned to the other one. However I'm not sure if media controller design is prepared for dynamic modifications of its graph and how many modifications in the existing drivers this solution would require.

Quoted 5 lines

Do you have a use case where you would need to strobe a flash from multiple media devices at different times, or is this entirely theoretical? Typically flash controllers are connected to a single source of hardware strobe (if there's one) since the flash LEDs are in fact mounted next to a specific camera sensor.

I took into account such arrangements in response to your message [1], where you were considering configurations like "one flash but two cameras", "one camera and two flashes". And you also called for proposing generic solution.

One flash and two (or more) cameras case is easily conceivable - You even mentioned stereo cameras. One camera and many flashes arrangement might be useful in case of some professional devices which might be designed so that they would be able to apply different scene lighting. I haven't heard about such devices, but as you said such a configuration isn't unthinkable.

Quoted 2 lines

If this is a real issue the way to solve it would be to have a single media device instead of many.

I was considering adding media device, that would be a representation
of a flash manager, gathering all the registered flashes. Nonetheless,
finally I came to conclusion that a v4l2-device alone should suffice,
just to provide a Flash Manager representation allowing for v4l2-flash sub-devices to register in. All the features provided by the media device are useless in case
of a set of V4L2 Flash sub-devices. They couldn't have any linkage
in such a device. The only benefit from having media device gathering
V4L2 Flash devices would be possibility of listing them.

Quoted 12 lines
Quoted 7 lines

2) Consequences of locking the Flash Manager during flash strobe

In case a LED Flash Class device depends on muxes involved in routing the other LED Flash Class device's strobe signals, the Flash Manager must be locked for the time of strobing to prevent reconfiguration of the strobe signal routing by the other device.

I wouldn't be concerned of this in particular. It's more important we do actully have V4L2 flash API supported by LED flash drivers and that they do implement the API correctly.

Quoted 7 lines

It's at least debatable whether you should try to prevent user space from doing silly things or not. With complex devices it may relatively easily lead to wrecking havoc with actual use cases which we certainly do not want.

In this case, if you just prevent changing the routing (do you have a use case for it?) while strobing, someone else could still change the routing just before you strobe.

Originally I started to implementing this so that strobe signal routing
was altered upon setting strobe source. With such an implementation the use case would be as follows:

1. Process 1 sets strobe source to external
2. Process 2 sets strobe source to software
3. Process 1 strobes the flash, unaware that strobe source setting has been changed

To avoid such problems I changed the implementation so that the routing is set in the led_flash_manager_setup_strobe function called from led_set_flash_strobe and led_set_external_strobe functions. led_flash_manager_setup_strobe sets strobe signal routing and strobes the flash under lock and holds it for the flash timeout period, which prevents spurious reconfiguration.

Nonetheless, I agree that trying to handle this problem is troublesome, and would affect current V4L2 Flash SPI semantics. If you don't share my concerns I am happy to leave this locking solution out :)

Best Regards,
Jacek Anaszewski

[1] http://www.spinics.net/lists/linux-leds/msg01617.html

#51 lore raw
Quoted 84 lines · Jacek Anaszewski

Hi Sakari,

Quoted 25 lines · Sakari Ailus

Hi Jacek,

On Fri, Jul 11, 2014 at 04:04:03PM +0200, Jacek Anaszewski wrote:
...

Quoted 12 lines

1) Who should register V4L2 Flash sub-device?

LED Flash Class devices, after introduction of the Flash Manager, are not tightly coupled with any media controller. They are maintained by the Flash Manager and made available for dynamic assignment to any media system they are connected to through multiplexing devices.

In the proposed rough solution, when support for V4L2 Flash sub-devices is enabled, there is a v4l2_device created for them to register in. This however implies that V4L2 Flash device will not be available in any media controller, which calls its existence into question.

Quoted 8 lines

Therefore I'd like to consult possible ways of solving this issue. The option I see is implementing a mechanism for moving V4L2 Flash sub-devices between media controllers. A V4L2 Flash sub-device would initially be assigned to one media system in the relevant device tree binding, but it could be dynamically reassigned to the other one. However I'm not sure if media controller design is prepared for dynamic modifications of its graph and how many modifications in the existing drivers this solution would require.

Quoted 7 lines

Do you have a use case where you would need to strobe a flash from multiple
media devices at different times, or is this entirely theoretical? Typically
flash controllers are connected to a single source of hardware strobe (if there's one) since the flash LEDs are in fact mounted next to a specific camera sensor.

I took into account such arrangements in response to your message [1], where you were considering configurations like "one flash but two cameras", "one camera and two flashes". And you also called for proposing generic solution.

One flash and two (or more) cameras case is easily conceivable - You even mentioned stereo cameras. One camera and many flashes arrangement might be useful in case of some professional devices which might be designed so that they would be able to apply different scene lighting. I haven't heard about such devices, but as you said such a configuration isn't unthinkable.

Quoted 3 lines

If this is a real issue the way to solve it would be to have a single media
device instead of many.

I was considering adding media device, that would be a representation of a flash manager, gathering all the registered flashes. Nonetheless, finally I came to conclusion that a v4l2-device alone should suffice, just to provide a Flash Manager representation allowing for v4l2-flash sub-devices to register in.
All the features provided by the media device are useless in case of a set of V4L2 Flash sub-devices. They couldn't have any linkage in such a device. The only benefit from having media device gathering V4L2 Flash devices would be possibility of listing them.

Quoted 13 lines
Quoted 7 lines

2) Consequences of locking the Flash Manager during flash strobe

In case a LED Flash Class device depends on muxes involved in routing the other LED Flash Class device's strobe signals, the Flash Manager must be locked for the time of strobing to prevent reconfiguration of the strobe signal routing by the other device.

I wouldn't be concerned of this in particular. It's more important we do actully have V4L2 flash API supported by LED flash drivers and that they do
implement the API correctly.

Quoted 8 lines

It's at least debatable whether you should try to prevent user space from doing silly things or not. With complex devices it may relatively easily lead to wrecking havoc with actual use cases which we certainly do not want.

In this case, if you just prevent changing the routing (do you have a use case for it?) while strobing, someone else could still change the routing just before you strobe.

Quoted 8 lines

Originally I started to implementing this so that strobe signal routing was altered upon setting strobe source. With such an implementation the use case would be as follows:

1. Process 1 sets strobe source to external
2. Process 2 sets strobe source to software
3. Process 1 strobes the flash, unaware that strobe source setting has been changed

It is of course too generic use case. The more specific one could be the situation when there are many users in the system that want to take the picture in the same time. It is not valid in case of mobile devices though.

Quoted 15 lines

To avoid such problems I changed the implementation so that the routing is set in the led_flash_manager_setup_strobe function called from led_set_flash_strobe and led_set_external_strobe functions. led_flash_manager_setup_strobe sets strobe signal routing and strobes the flash under lock and holds it for the flash timeout period, which prevents spurious reconfiguration.

Nonetheless, I agree that trying to handle this problem is troublesome, and would affect current V4L2 Flash SPI semantics. If you don't share my concerns I am happy to leave this locking solution out :)

Best Regards,
Jacek Anaszewski

[1] http://www.spinics.net/lists/linux-leds/msg01617.html

#13 lore raw

Re: [PATCH/RFC v4 06/21] leds: add API for setting torch brightness

In reply to Sakari Ailus

Hi Sakari,

Quoted 79 lines · Sakari Ailus

Hi Jacek,

Thank you for your continued efforts on this!

Quoted 74 lines · Jacek Anaszewski
Quoted 40 lines · Sakari Ailus

Hi Jacek,

Jacek Anaszewski wrote:
...

Quoted 18 lines
include/linux/leds.h +4 -0
index 1a130cc..9bea9e6 100644
@@ -44,11 +44,21 @@ struct led_classdev {
  #define LED_BLINK_ONESHOT_STOP    (1 << 18)
  #define LED_BLINK_INVERT    (1 << 19)
  #define LED_SYSFS_LOCK        (1 << 20)
+#define LED_DEV_CAP_TORCH    (1 << 21)
 
      /* Set LED brightness level */
      /* Must not sleep, use a workqueue if needed */
      void        (*brightness_set)(struct led_classdev *led_cdev,
                        enum led_brightness brightness);
+    /*
+     * Set LED brightness immediately - it is required for flash led
+     * devices as they require setting torch brightness to have

immediate

include/linux/leds.h struct led_classdev { · line 59

Quoted 4 lines
include/linux/leds.h +4 -0
+     * effect. brightness_set op cannot be used for this purpose because
+     * the led drivers schedule a work queue task in it to allow for
+     * being called from led-triggers, i.e. from the timer irq context.
+     */

Do we need to classify actual devices based on this? I think it's rather a different API behaviour between the LED and the V4L2 APIs.

On devices that are slow to control, the behaviour should be asynchronous over the LED API and synchronous when accessed through the V4L2 API. How about implementing the work queue, as I have suggested, in the framework, so
that individual drivers don't need to care about this and just implement the
synchronous variant of this op? A flag could be added to distinguish devices
that are fast so that the work queue isn't needed.

Quoted 4 lines

It'd be nice to avoid individual drivers having to implement multiple ops to
do the same thing, just for differing user space interfacs.

It is not only the matter of a device controller speed. If a flash device is to be made accessible from the LED subsystem, then it should be also compatible with led-triggers. Some of led-triggers call brightness_set op from the timer irq context and thus no locking in the callback can occur. This requirement cannot be met i.e. if i2c bus is to be used. This is probably the primary reason for scheduling work queue tasks in brightness_set op.

Having the above in mind, setting a brightness in a work queue task must be possible for all LED Class Flash drivers, regardless whether related devices have fast or slow controller.

Let's recap the cost of possible solutions then:

1) Moving the work queues to the LED framework

- it would probably require extending led_set_brightness and __led_set_brightness functions by a parameter indicating whether it should call brightness_set op in the work queue task or directly;
- all existing triggers would have to be updated accordingly;
- work queues would have to be removed from all the LED drivers;

2) adding led_set_torch_brightness API

- no modifications in existing drivers and triggers would be required
- instead, only the modifications from the discussed patch would be required

Quoted 8 lines
Quoted 1 line

Solution 1 looks cleaner but requires much more modifications.

How about a combination of the two, i.e. option 1 with the old op remaining there for compatibility with the old drivers (with a comment telling it's deprecated)?

This way new drivers will benefit from having to implement this just once, and modifications to the existing drivers could be left for later.

It's OK for me, but the opinion from the LED side guys is needed here as well.

Quoted 3 lines

The downside is that any old drivers wouldn't get V4L2 flash API but that's entirely acceptable in my opinion since these would hardly be needed in use cases that would benefit from V4L2 flash API.

In the version 4 of the patch set I changed the implementation, so that a flash led driver must call led_classdev_flash_register to get registered as a LED Flash Class device and v4l2_flash_init to get V4L2 Flash API. In effect old drivers will have no chance to get V4L2 Flash API either way.

Best Regards,
Jacek Anaszewski

#46 lore raw
In reply to Bryan Wu

Hi Bryan,

Quoted 14 lines · Bryan Wu
Quoted 13 lines · Bryan Wu
Quoted 6 lines · Jacek Anaszewski

This is is the fourth version of the patch series being a follow up of the discussion on Media summit 2013-10-23, related to the LED / flash API integration (the notes from the discussion were enclosed in the message [1], paragraph 5).
The series is based on linux-next-20140707

I really apologize that I missed your discussion email in my Gmail inbox, it was archived some where. Even in this series some of these patches are archived in different tab.

Quoted 5 lines
Quoted 2 lines

I will start to review and help to push this.

In the mean time, could you please provide an git tree for me to pull? It's much easier for me to review in my git.

Few days ago I sent to your private email the path to the git repository to pull, but I am resending it through the lists to make sure that it will not get filtered somehow again.

git://linuxtv.org/snawrocki/samsung.git
branch: led_flash_integration_v4

gitweb:
http://git.linuxtv.org/cgit.cgi/snawrocki/samsung.git/log/?h=led_flash_integration_v4

Best Regards,
Jacek Anaszewski

#47 lore raw
Quoted 33 lines · Jacek Anaszewski

Hi Bryan,

Quoted 17 lines · Bryan Wu
Quoted 15 lines · Bryan Wu
Quoted 7 lines · Jacek Anaszewski

This is is the fourth version of the patch series being a follow up of the discussion on Media summit 2013-10-23, related to the LED / flash API integration (the notes from the discussion were enclosed in the message [1], paragraph 5).
The series is based on linux-next-20140707

I really apologize that I missed your discussion email in my Gmail inbox, it was archived some where. Even in this series some of these patches are archived in different tab.

Quoted 5 lines
Quoted 2 lines

I will start to review and help to push this.

In the mean time, could you please provide an git tree for me to pull? It's much easier for me to review in my git.

Few days ago I sent to your private email the path to the git repository to pull, but I am resending it through the lists to make sure that it will not get filtered somehow again.

Quoted 6 lines

git://linuxtv.org/snawrocki/samsung.git
branch: led_flash_integration_v4

gitweb:
http://git.linuxtv.org/cgit.cgi/snawrocki/samsung.git/log/?h=led_flash_integration_v4

Yes, I got it. I merged some leds core fixing patches from you recently. So could you please split these big patchset into several small parts which should be easier for reviewing and discussion.
- led core fixing
- led flash core patches
- led flash manager patches
- v4l2 led patches
- Documentations

My plan is to review these and merge them to my -devel branch. Then invite people for testing.

Thanks,
-Bryan

#30 lore raw

Re: [PATCH/RFC v4 15/21] media: Add registration helpers for V4L2 flash

In reply to Jacek Anaszewski

Hi Jacek,

Quoted 3 lines · Jacek Anaszewski

Hi Sakari,

Thanks for the review.

You're welcome! :)

Quoted 221 lines · Sakari Ailus
Quoted 211 lines

Hi Jacek,

Quoted 208 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.

---
 drivers/media/v4l2-core/Kconfig      |   11 +
 drivers/media/v4l2-core/Makefile     |    2 +
 drivers/media/v4l2-core/v4l2-flash.c |  580 ++++++++++++++++++++++++++++++++++
 include/media/v4l2-flash.h           |  137 ++++++++
 4 files changed, 730 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
index 9ca0f8d..3ae3f0f 100644
@@ -35,6 +35,17 @@ config V4L2_MEM2MEM_DEV
         tristate
         depends on VIDEOBUF2_CORE
 
+# Used by LED subsystem flash drivers
+config V4L2_FLASH_LED_CLASS
+	bool "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
index 63d29f2..44e858c 100644
@@ -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 +148 -0
new file mode 100644
index 0000000..21080c6
@@ -0,0 +1,580 @@
+/*
+ * V4L2 Flash LED sub-device registration helpers.
+ *
+ *	Copyright (C) 2014 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/mutex.h>
+#include <linux/of_led_flash_manager.h>
+#include <linux/slab.h>
+#include <media/v4l2-flash.h>
+
+#define call_flash_op(v4l2_flash, op, args...)			\
+		(v4l2_flash->ops->op  ?				\
+			v4l2_flash->ops->op(args) :		\
+			-EINVAL)
+
+static struct v4l2_device *v4l2_dev;
+static int registered_flashes;
+
+static inline enum led_brightness v4l2_flash_intensity_to_led_brightness(
+					struct v4l2_ctrl_config *config,
+					s32 intensity)
+{
+	return ((intensity - config->min) / config->step) + 1;
+}
+
+static inline s32 v4l2_flash_led_brightness_to_intensity(
+					struct v4l2_ctrl_config *config,
+					enum led_brightness brightness)
+{
+	return ((brightness - 1) * config->step) + config->min;
+}
+
+static int v4l2_flash_g_volatile_ctrl(struct v4l2_ctrl *c)
+
+{
+	struct v4l2_flash *v4l2_flash = v4l2_ctrl_to_v4l2_flash(c);
+	struct led_classdev_flash *flash = v4l2_flash->flash;
+	struct led_classdev *led_cdev = &flash->led_cdev;
+	struct v4l2_flash_ctrl_config *config = &v4l2_flash->config;
+	struct v4l2_flash_ctrl *ctrl = &v4l2_flash->ctrl;
+	bool is_strobing;
+	int ret;
+
+	switch (c->id) {
+	case V4L2_CID_FLASH_TORCH_INTENSITY:
+		/*
+		 * Update torch brightness only if in TORCH_MODE,
+		 * as otherwise brightness_update op returns 0,
+		 * which would spuriously inform user space that
+		 * V4L2_CID_FLASH_TORCH_INTENSITY control value
+		 * has changed.
+		 */
+		if (ctrl->led_mode->val == V4L2_FLASH_LED_MODE_TORCH) {
+			ret = call_flash_op(v4l2_flash, torch_brightness_update,
+							led_cdev);
+			if (ret < 0)
+				return ret;
+			ctrl->torch_intensity->val =
+				v4l2_flash_led_brightness_to_intensity(
+						&config->torch_intensity,
+						led_cdev->brightness);
+		}
+		return 0;
+	case V4L2_CID_FLASH_INTENSITY:
+		ret = call_flash_op(v4l2_flash, flash_brightness_update,
+					flash);
+		if (ret < 0)
+			return ret;
+		/* no conversion is needed */
+		c->val = flash->brightness.val;
+		return 0;
+	case V4L2_CID_FLASH_INDICATOR_INTENSITY:
+		ret = call_flash_op(v4l2_flash, indicator_brightness_update,
+						flash);
+		if (ret < 0)
+			return ret;
+		/* no conversion is needed */
+		c->val = flash->indicator_brightness->val;
+		return 0;
+	case V4L2_CID_FLASH_STROBE_STATUS:
+		ret = call_flash_op(v4l2_flash, strobe_get, flash,
+							&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 */
+		ret = call_flash_op(v4l2_flash, fault_get, flash, &c->val);
+		return ret;
+	case V4L2_CID_FLASH_STROBE_SOURCE:
+		c->val = flash->external_strobe;
+		return 0;
+	case V4L2_CID_FLASH_STROBE_PROVIDER:
+		c->val = flash->strobe_provider_id;
+		return 0;
+	default:
+		return -EINVAL;
+	}
+}
+
+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 *flash = v4l2_flash->flash;
+	struct v4l2_flash_ctrl *ctrl = &v4l2_flash->ctrl;
+	struct v4l2_flash_ctrl_config *config = &v4l2_flash->config;
+	enum led_brightness torch_brightness;
+	bool external_strobe;
+	int ret;
+
+	switch (c->id) {
+	case V4L2_CID_FLASH_LED_MODE:
+		switch (c->val) {
+		case V4L2_FLASH_LED_MODE_NONE:
+			call_flash_op(v4l2_flash, torch_brightness_set,
+							&flash->led_cdev, 0);
+			return call_flash_op(v4l2_flash, strobe_set, flash,
+							false);
+		case V4L2_FLASH_LED_MODE_FLASH:
+			/* Turn off torch LED */
+			call_flash_op(v4l2_flash, torch_brightness_set,
+							&flash->led_cdev, 0);
+			external_strobe = (ctrl->source->val ==
+					V4L2_FLASH_STROBE_SOURCE_EXTERNAL);
+			return call_flash_op(v4l2_flash, external_strobe_set,
+						flash, external_strobe);
+		case V4L2_FLASH_LED_MODE_TORCH:
+			/* Stop flash strobing */
+			ret = call_flash_op(v4l2_flash, strobe_set, flash,
+							false);
+			if (ret)
+				return ret;
+
+			torch_brightness =
+				v4l2_flash_intensity_to_led_brightness(
+						&config->torch_intensity,
+						ctrl->torch_intensity->val);
+			call_flash_op(v4l2_flash, torch_brightness_set,
+					&flash->led_cdev, torch_brightness);
+			return ret;
Quoted 8 lines

drivers/media/v4l2-core/v4l2-flash.c line 152

Quoted 4 lines
drivers/media/v4l2-core/v4l2-flash.c new file +4 -0
+		}
+		break;
+	case V4L2_CID_FLASH_STROBE_SOURCE:
+		external_strobe = (c->val == V4L2_FLASH_STROBE_SOURCE_EXTERNAL);

Is the external_strobe argument match exactly to the strobe source control? You seem to assume that in g_volatile_ctrl() above. I think having it the either way is fine but not both. :-)

Quoted 6 lines

The STROBE_SOURCE_EXTERNAL control state is volatile if a flash device depends on muxes that route strobe signals to more then one flash device. In such a case it behaves similarly to FLASH_STROBE control, i.e. it activates external strobe only for the flash timeout period. I touched this issue in the cover letter of this patch series, paragraph 2.

I meant that flash->external_strobe is directly used as V4L2_CID_FLASH_STROBE_SOURCE. Are the two guaranteed to be the same?

...

Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
drivers/media/v4l2-core/v4l2-flash.c new file +7 -0
+/*
+ * 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);
Quoted 8 lines

drivers/media/v4l2-core/v4l2-flash.c line 413

Quoted 5 lines
drivers/media/v4l2-core/v4l2-flash.c new file +5 -0
+	struct led_classdev_flash *flash = v4l2_flash->flash;
+	struct led_classdev *led_cdev = &flash->led_cdev;
+
+	mutex_lock(&led_cdev->led_lock);
+	call_flash_op(v4l2_flash, sysfs_lock, led_cdev);

What if you have the device open through multiple file handles? I believe v4l2_subdev_fh_is_singular(&fh->vfh) would prove helpful here.

Quoted 2 lines

I assume you propose to implement such a function? I don't see it in the mainline kernel.

Uh, I thought of v4l2_subdev_fh_is_singular() but what I really meant was v4l2_fh_is_singular(). There's no sub-device variant of it, as the sub-device file handle struct embeds struct v4l2_fh.

...

Quoted 46 lines
Quoted 42 lines
Quoted 23 lines
drivers/media/v4l2-core/v4l2-flash.c new file +23 -0
+{
+	struct led_classdev_flash *flash = v4l2_flash->flash;
+	struct led_classdev *led_cdev = &flash->led_cdev;
+	int ret;
+
+	if (!v4l2_dev) {
+		v4l2_dev = kzalloc(sizeof(*v4l2_dev), GFP_KERNEL);
+		if (!v4l2_dev)
+			return -ENOMEM;
+
+		strlcpy(v4l2_dev->name, "v4l2-flash-manager",
+						sizeof(v4l2_dev->name));
+		ret = v4l2_device_register(NULL, v4l2_dev);
+		if (ret < 0) {
+			dev_err(led_cdev->dev->parent,
+				 "Failed to register v4l2_device: %d\n", ret);
+			goto err_v4l2_device_register;
+		}
+	}
+
+	ret = v4l2_device_register_subdev(v4l2_dev, &v4l2_flash->sd);
+	if (ret < 0) {
+		dev_err(led_cdev->dev->parent,

drivers/media/v4l2-core/v4l2-flash.c line 465

Quoted 10 lines
drivers/media/v4l2-core/v4l2-flash.c new file +10 -0
+			 "Failed to register v4l2_subdev: %d\n", ret);
+		goto err_v4l2_device_register;
+	}
+
+	ret = v4l2_device_register_subdev_node(&v4l2_flash->sd, v4l2_dev);
+	if (ret < 0) {
+		dev_err(led_cdev->dev->parent,
+			 "Failed to register v4l2_subdev node: %d\n", ret);
+		goto err_register_subdev_node;
+	}

This way you can create a V4L2 sub-device node. However, flash devices are seldom alone in the system. They are physically close to a sensor, and this connection is shown in the Media controller interface. This means that the flash sub-device (entity) should be part of the Media device created by the driver in control of it. This can be achieved by the master driver creating the sub-device. You should register an async sub-device here.

Quoted 3 lines

This results in the sub-device not being registered if there's no such master driver, but I wouldn't expect that to be an issue since the V4L2 flash API is mostly relevant in such cases.

Quoted 9 lines

I addressed this issue in the cover letter of this patch series, paragraph 1. If strobe signals are routed to a flash device through a multiplexer then assignment of the related V4L2 Flash sub-device to a particular media controller may dynamically change in time. Actually, if a flash device can be shared between media systems (i.e. it can be configured to react on strobe signals from different camera sensors, basing on muxes configuration), than it becomes bound to a particular media system only for the time of strobing. Please refer to [1].

Replied to the cover letter.

...

Quoted 53 lines
Quoted 44 lines
Quoted 44 lines
include/media/v4l2-flash.h new file +38 -0
new file mode 100644
index 0000000..effa46b
@@ -0,0 +1,137 @@
+/*
+ * V4L2 Flash LED sub-device registration helpers.
+ *
+ *	Copyright (C) 2014 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."
+ */
+
+#ifndef _V4L2_FLASH_H
+#define _V4L2_FLASH_H
+
+#include <media/v4l2-ctrls.h>
+#include <media/v4l2-device.h>
+#include <media/v4l2-dev.h>
+#include <media/v4l2-event.h>
+#include <media/v4l2-ioctl.h>
+
+struct led_classdev_flash;
+struct led_classdev;
+enum led_brightness;
+
+struct v4l2_flash_ops {
+	int (*torch_brightness_set)(struct led_classdev *led_cdev,
+					enum led_brightness brightness);
+	int (*torch_brightness_update)(struct led_classdev *led_cdev);
+	int (*flash_brightness_set)(struct led_classdev_flash *flash,
+					u32 brightness);
+	int (*flash_brightness_update)(struct led_classdev_flash *flash);
+	int (*strobe_set)(struct led_classdev_flash *flash, bool state);
+	int (*strobe_get)(struct led_classdev_flash *flash, bool *state);
+	int (*timeout_set)(struct led_classdev_flash *flash, u32 timeout);
+	int (*indicator_brightness_set)(struct led_classdev_flash *flash,
+					u32 brightness);
+	int (*indicator_brightness_update)(struct led_classdev_flash *flash);
+	int (*external_strobe_set)(struct led_classdev_flash *flash,
Quoted 8 lines

include/media/v4l2-flash.h line 42

Quoted 4 lines
include/media/v4l2-flash.h new file +4 -0
+					bool enable);
+	int (*fault_get)(struct led_classdev_flash *flash, u32 *fault);
+	void (*sysfs_lock)(struct led_classdev *led_cdev);
+	void (*sysfs_unlock)(struct led_classdev *led_cdev);

These functions are not driver specific and there's going to be just one implementation (I suppose). Could you refresh my memory regarding why the LED framework functions aren't called directly?

Quoted 2 lines

These ops are required to make possible building led-class-flash as a kernel module.

Assuming you'd use the actual implementation directly, what would be the dependencies? I don't think the LED flash framework has any callbacks towards the V4L2 (LED) flash framework, does it? Please correct my understanding if I'm missing something. In Makefile format, assume all targets are .PHONY:

led-flash-api: led-api

v4l2-flash: led-flash-api

driver: led-flash-api v4l2-flash

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
#31 lore raw

Re: [PATCH/RFC v4 15/21] media: Add registration helpers for V4L2 flash

Hi Sakari

Quoted 259 lines · Sakari Ailus

Hi Jacek,

Quoted 3 lines · Jacek Anaszewski

Hi Sakari,

Thanks for the review.

You're welcome! :)

Quoted 221 lines · Sakari Ailus
Quoted 211 lines

Hi Jacek,

Quoted 208 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.

---
  drivers/media/v4l2-core/Kconfig      |   11 +
  drivers/media/v4l2-core/Makefile     |    2 +
  drivers/media/v4l2-core/v4l2-flash.c |  580 ++++++++++++++++++++++++++++++++++
  include/media/v4l2-flash.h           |  137 ++++++++
  4 files changed, 730 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
index 9ca0f8d..3ae3f0f 100644
@@ -35,6 +35,17 @@ config V4L2_MEM2MEM_DEV
          tristate
          depends on VIDEOBUF2_CORE
 
+# Used by LED subsystem flash drivers
+config V4L2_FLASH_LED_CLASS
+	bool "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
index 63d29f2..44e858c 100644
@@ -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 +148 -0
new file mode 100644
index 0000000..21080c6
@@ -0,0 +1,580 @@
+/*
+ * V4L2 Flash LED sub-device registration helpers.
+ *
+ *	Copyright (C) 2014 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/mutex.h>
+#include <linux/of_led_flash_manager.h>
+#include <linux/slab.h>
+#include <media/v4l2-flash.h>
+
+#define call_flash_op(v4l2_flash, op, args...)			\
+		(v4l2_flash->ops->op  ?				\
+			v4l2_flash->ops->op(args) :		\
+			-EINVAL)
+
+static struct v4l2_device *v4l2_dev;
+static int registered_flashes;
+
+static inline enum led_brightness v4l2_flash_intensity_to_led_brightness(
+					struct v4l2_ctrl_config *config,
+					s32 intensity)
+{
+	return ((intensity - config->min) / config->step) + 1;
+}
+
+static inline s32 v4l2_flash_led_brightness_to_intensity(
+					struct v4l2_ctrl_config *config,
+					enum led_brightness brightness)
+{
+	return ((brightness - 1) * config->step) + config->min;
+}
+
+static int v4l2_flash_g_volatile_ctrl(struct v4l2_ctrl *c)
+
+{
+	struct v4l2_flash *v4l2_flash = v4l2_ctrl_to_v4l2_flash(c);
+	struct led_classdev_flash *flash = v4l2_flash->flash;
+	struct led_classdev *led_cdev = &flash->led_cdev;
+	struct v4l2_flash_ctrl_config *config = &v4l2_flash->config;
+	struct v4l2_flash_ctrl *ctrl = &v4l2_flash->ctrl;
+	bool is_strobing;
+	int ret;
+
+	switch (c->id) {
+	case V4L2_CID_FLASH_TORCH_INTENSITY:
+		/*
+		 * Update torch brightness only if in TORCH_MODE,
+		 * as otherwise brightness_update op returns 0,
+		 * which would spuriously inform user space that
+		 * V4L2_CID_FLASH_TORCH_INTENSITY control value
+		 * has changed.
+		 */
+		if (ctrl->led_mode->val == V4L2_FLASH_LED_MODE_TORCH) {
+			ret = call_flash_op(v4l2_flash, torch_brightness_update,
+							led_cdev);
+			if (ret < 0)
+				return ret;
+			ctrl->torch_intensity->val =
+				v4l2_flash_led_brightness_to_intensity(
+						&config->torch_intensity,
+						led_cdev->brightness);
+		}
+		return 0;
+	case V4L2_CID_FLASH_INTENSITY:
+		ret = call_flash_op(v4l2_flash, flash_brightness_update,
+					flash);
+		if (ret < 0)
+			return ret;
+		/* no conversion is needed */
+		c->val = flash->brightness.val;
+		return 0;
+	case V4L2_CID_FLASH_INDICATOR_INTENSITY:
+		ret = call_flash_op(v4l2_flash, indicator_brightness_update,
+						flash);
+		if (ret < 0)
+			return ret;
+		/* no conversion is needed */
+		c->val = flash->indicator_brightness->val;
+		return 0;
+	case V4L2_CID_FLASH_STROBE_STATUS:
+		ret = call_flash_op(v4l2_flash, strobe_get, flash,
+							&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 */
+		ret = call_flash_op(v4l2_flash, fault_get, flash, &c->val);
+		return ret;
+	case V4L2_CID_FLASH_STROBE_SOURCE:
+		c->val = flash->external_strobe;
+		return 0;
+	case V4L2_CID_FLASH_STROBE_PROVIDER:
+		c->val = flash->strobe_provider_id;
+		return 0;
+	default:
+		return -EINVAL;
+	}
+}
+
+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 *flash = v4l2_flash->flash;
+	struct v4l2_flash_ctrl *ctrl = &v4l2_flash->ctrl;
+	struct v4l2_flash_ctrl_config *config = &v4l2_flash->config;
+	enum led_brightness torch_brightness;
+	bool external_strobe;
+	int ret;
+
+	switch (c->id) {
+	case V4L2_CID_FLASH_LED_MODE:
+		switch (c->val) {
+		case V4L2_FLASH_LED_MODE_NONE:
+			call_flash_op(v4l2_flash, torch_brightness_set,
+							&flash->led_cdev, 0);
+			return call_flash_op(v4l2_flash, strobe_set, flash,
+							false);
+		case V4L2_FLASH_LED_MODE_FLASH:
+			/* Turn off torch LED */
+			call_flash_op(v4l2_flash, torch_brightness_set,
+							&flash->led_cdev, 0);
+			external_strobe = (ctrl->source->val ==
+					V4L2_FLASH_STROBE_SOURCE_EXTERNAL);
+			return call_flash_op(v4l2_flash, external_strobe_set,
+						flash, external_strobe);
+		case V4L2_FLASH_LED_MODE_TORCH:
+			/* Stop flash strobing */
+			ret = call_flash_op(v4l2_flash, strobe_set, flash,
+							false);
+			if (ret)
+				return ret;
+
+			torch_brightness =
+				v4l2_flash_intensity_to_led_brightness(
+						&config->torch_intensity,
+						ctrl->torch_intensity->val);
+			call_flash_op(v4l2_flash, torch_brightness_set,
+					&flash->led_cdev, torch_brightness);
+			return ret;
Quoted 8 lines

drivers/media/v4l2-core/v4l2-flash.c line 152

Quoted 4 lines
drivers/media/v4l2-core/v4l2-flash.c new file +4 -0
+		}
+		break;
+	case V4L2_CID_FLASH_STROBE_SOURCE:
+		external_strobe = (c->val == V4L2_FLASH_STROBE_SOURCE_EXTERNAL);

Is the external_strobe argument match exactly to the strobe source control? You seem to assume that in g_volatile_ctrl() above. I think having it the either way is fine but not both. :-)

Quoted 6 lines

The STROBE_SOURCE_EXTERNAL control state is volatile if a flash device depends on muxes that route strobe signals to more then one flash device. In such a case it behaves similarly to FLASH_STROBE control, i.e. it activates external strobe only for the flash timeout period. I touched this issue in the cover letter of this patch series, paragraph 2.

I meant that flash->external_strobe is directly used as V4L2_CID_FLASH_STROBE_SOURCE. Are the two guaranteed to be the same?

...

Quoted 16 lines
Quoted 15 lines

drivers/media/v4l2-core/v4l2-flash.c line 413

Quoted 12 lines
drivers/media/v4l2-core/v4l2-flash.c new file +12 -0
+/*
+ * 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 *flash = v4l2_flash->flash;
+	struct led_classdev *led_cdev = &flash->led_cdev;
+
+	mutex_lock(&led_cdev->led_lock);
+	call_flash_op(v4l2_flash, sysfs_lock, led_cdev);

What if you have the device open through multiple file handles? I believe v4l2_subdev_fh_is_singular(&fh->vfh) would prove helpful here.

Quoted 6 lines
Quoted 2 lines

I assume you propose to implement such a function? I don't see it in the mainline kernel.

Uh, I thought of v4l2_subdev_fh_is_singular() but what I really meant was v4l2_fh_is_singular(). There's no sub-device variant of it, as the sub-device file handle struct embeds struct v4l2_fh.

OK, I will use it here.

Quoted 58 lines

...

Quoted 46 lines
Quoted 42 lines
Quoted 23 lines
drivers/media/v4l2-core/v4l2-flash.c new file +23 -0
+{
+	struct led_classdev_flash *flash = v4l2_flash->flash;
+	struct led_classdev *led_cdev = &flash->led_cdev;
+	int ret;
+
+	if (!v4l2_dev) {
+		v4l2_dev = kzalloc(sizeof(*v4l2_dev), GFP_KERNEL);
+		if (!v4l2_dev)
+			return -ENOMEM;
+
+		strlcpy(v4l2_dev->name, "v4l2-flash-manager",
+						sizeof(v4l2_dev->name));
+		ret = v4l2_device_register(NULL, v4l2_dev);
+		if (ret < 0) {
+			dev_err(led_cdev->dev->parent,
+				 "Failed to register v4l2_device: %d\n", ret);
+			goto err_v4l2_device_register;
+		}
+	}
+
+	ret = v4l2_device_register_subdev(v4l2_dev, &v4l2_flash->sd);
+	if (ret < 0) {
+		dev_err(led_cdev->dev->parent,

drivers/media/v4l2-core/v4l2-flash.c line 465

Quoted 10 lines
drivers/media/v4l2-core/v4l2-flash.c new file +10 -0
+			 "Failed to register v4l2_subdev: %d\n", ret);
+		goto err_v4l2_device_register;
+	}
+
+	ret = v4l2_device_register_subdev_node(&v4l2_flash->sd, v4l2_dev);
+	if (ret < 0) {
+		dev_err(led_cdev->dev->parent,
+			 "Failed to register v4l2_subdev node: %d\n", ret);
+		goto err_register_subdev_node;
+	}

This way you can create a V4L2 sub-device node. However, flash devices are seldom alone in the system. They are physically close to a sensor, and this connection is shown in the Media controller interface. This means that the flash sub-device (entity) should be part of the Media device created by the driver in control of it. This can be achieved by the master driver creating the sub-device. You should register an async sub-device here.

Quoted 3 lines

This results in the sub-device not being registered if there's no such master driver, but I wouldn't expect that to be an issue since the V4L2 flash API is mostly relevant in such cases.

Quoted 9 lines

I addressed this issue in the cover letter of this patch series, paragraph 1. If strobe signals are routed to a flash device through a multiplexer then assignment of the related V4L2 Flash sub-device to a particular media controller may dynamically change in time. Actually, if a flash device can be shared between media systems (i.e. it can be configured to react on strobe signals from different camera sensors, basing on muxes configuration), than it becomes bound to a particular media system only for the time of strobing. Please refer to [1].

Quoted 1 line

Replied to the cover letter.

Replied to your reply.

Quoted 64 lines

...

Quoted 53 lines
Quoted 44 lines
Quoted 44 lines
include/media/v4l2-flash.h new file +38 -0
new file mode 100644
index 0000000..effa46b
@@ -0,0 +1,137 @@
+/*
+ * V4L2 Flash LED sub-device registration helpers.
+ *
+ *	Copyright (C) 2014 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."
+ */
+
+#ifndef _V4L2_FLASH_H
+#define _V4L2_FLASH_H
+
+#include <media/v4l2-ctrls.h>
+#include <media/v4l2-device.h>
+#include <media/v4l2-dev.h>le
+#include <media/v4l2-event.h>
+#include <media/v4l2-ioctl.h>
+
+struct led_classdev_flash;
+struct led_classdev;
+enum led_brightness;
+
+struct v4l2_flash_ops {
+	int (*torch_brightness_set)(struct led_classdev *led_cdev,
+					enum led_brightness brightness);
+	int (*torch_brightness_update)(struct led_classdev *led_cdev);
+	int (*flash_brightness_set)(struct led_classdev_flash *flash,
+					u32 brightness);
+	int (*flash_brightness_update)(struct led_classdev_flash *flash);
+	int (*strobe_set)(struct led_classdev_flash *flash, bool state);
+	int (*strobe_get)(struct led_classdev_flash *flash, bool *state);
+	int (*timeout_set)(struct led_classdev_flash *flash, u32 timeout);
+	int (*indicator_brightness_set)(struct led_classdev_flash *flash,
+					u32 brightness);
+	int (*indicator_brightness_update)(struct led_classdev_flash *flash);
+	int (*external_strobe_set)(struct led_classdev_flash *flash,
Quoted 8 lines

include/media/v4l2-flash.h line 42

Quoted 4 lines
include/media/v4l2-flash.h new file +4 -0
+					bool enable);
+	int (*fault_get)(struct led_classdev_flash *flash, u32 *fault);
+	void (*sysfs_lock)(struct led_classdev *led_cdev);
+	void (*sysfs_unlock)(struct led_classdev *led_cdev);

These functions are not driver specific and there's going to be just one implementation (I suppose). Could you refresh my memory regarding why the LED framework functions aren't called directly?

Quoted 2 lines

These ops are required to make possible building led-class-flash as a kernel module.

Assuming you'd use the actual implementation directly, what would be the dependencies? I don't think the LED flash framework has any callbacks towards the V4L2 (LED) flash framework, does it? Please correct my understanding if I'm missing something. In Makefile format, assume all targets are .PHONY:

Quoted 5 lines

led-flash-api: led-api

v4l2-flash: led-flash-api

driver: led-flash-api v4l2-flash

LED Class Flash driver gains V4L2 Flash API when CONFIG_V4L2_FLASH_LED_CLASS is defined. This is accomplished in the probe function by either calling v4l2_flash_init function or the macro of this name, when the CONFIG_V4L2_FLASH_LED_CLASS macro isn't defined.

If the v4l2-flash.c was to call the LED API directly, then the led-class-flash module symbols would have to be available at v4l2-flash.o linking time.

This requirement cannot be met if the led-class-flash is built as a module.

Use of function pointers in the v4l2-flash.c allows to compile it into the kernel and enables the possibility of adding the V4L2 Flash support conditionally, during driver probing.

Best Regards,
Jacek Anaszewski
--
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

#32 lore raw

Re: [PATCH/RFC v4 15/21] media: Add registration helpers for V4L2 flash

Quoted 4 lines · Sakari Ailus
Quoted 3 lines

Hi Jacek,

...

Quoted 57 lines
Quoted 57 lines
Quoted 56 lines
Quoted 41 lines
Quoted 41 lines
drivers/media/v4l2-core/v4l2-flash.c new file +41 -0
+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 *flash = v4l2_flash->flash;
+    struct v4l2_flash_ctrl *ctrl = &v4l2_flash->ctrl;
+    struct v4l2_flash_ctrl_config *config = &v4l2_flash->config;
+    enum led_brightness torch_brightness;
+    bool external_strobe;
+    int ret;
+
+    switch (c->id) {
+    case V4L2_CID_FLASH_LED_MODE:
+        switch (c->val) {
+        case V4L2_FLASH_LED_MODE_NONE:
+            call_flash_op(v4l2_flash, torch_brightness_set,
+                            &flash->led_cdev, 0);
+            return call_flash_op(v4l2_flash, strobe_set, flash,
+                            false);
+        case V4L2_FLASH_LED_MODE_FLASH:
+            /* Turn off torch LED */
+            call_flash_op(v4l2_flash, torch_brightness_set,
+                            &flash->led_cdev, 0);
+            external_strobe = (ctrl->source->val ==
+                    V4L2_FLASH_STROBE_SOURCE_EXTERNAL);
+            return call_flash_op(v4l2_flash, external_strobe_set,
+                        flash, external_strobe);
+        case V4L2_FLASH_LED_MODE_TORCH:
+            /* Stop flash strobing */
+            ret = call_flash_op(v4l2_flash, strobe_set, flash,
+                            false);
+            if (ret)
+                return ret;
+
+            torch_brightness =
+                v4l2_flash_intensity_to_led_brightness(
+                        &config->torch_intensity,
+                        ctrl->torch_intensity->val);
+            call_flash_op(v4l2_flash, torch_brightness_set,
+                    &flash->led_cdev, torch_brightness);
+            return ret;
+        }
Quoted 8 lines
Quoted 4 lines
drivers/media/v4l2-core/v4l2-flash.c new file +3 -0
+        break;
+    case V4L2_CID_FLASH_STROBE_SOURCE:
+        external_strobe = (c->val ==

V4L2_FLASH_STROBE_SOURCE_EXTERNAL);

Is the external_strobe argument match exactly to the strobe source control? You seem to assume that in g_volatile_ctrl() above. I think having it the either way is fine but not both. :-)

The STROBE_SOURCE_EXTERNAL control state is volatile if a flash device depends on muxes that route strobe signals to more then one flash device. In such a case it behaves similarly to FLASH_STROBE control, i.e. it activates external strobe only for the flash timeout period. I touched this issue in the cover letter of this patch series, paragraph 2.

Quoted 2 lines
Quoted 2 lines

I meant that flash->external_strobe is directly used as V4L2_CID_FLASH_STROBE_SOURCE. Are the two guaranteed to be the same?

Yes, the external_strobe sysfs attribute is mapped to it.

Best Regards,
Jacek Anaszewski

#48 lore raw
In reply to Bryan Wu

Hi Bryan,

Quoted 51 lines · Bryan Wu
Quoted 33 lines · Jacek Anaszewski

Hi Bryan,

Quoted 17 lines · Bryan Wu
Quoted 15 lines · Bryan Wu
Quoted 7 lines · Jacek Anaszewski

This is is the fourth version of the patch series being a follow up of the discussion on Media summit 2013-10-23, related to the LED / flash API integration (the notes from the discussion were enclosed in the message [1], paragraph 5).
The series is based on linux-next-20140707

I really apologize that I missed your discussion email in my Gmail inbox, it was archived some where. Even in this series some of these patches are archived in different tab.

Quoted 5 lines
Quoted 2 lines

I will start to review and help to push this.

In the mean time, could you please provide an git tree for me to pull? It's much easier for me to review in my git.

Few days ago I sent to your private email the path to the git repository to pull, but I am resending it through the lists to make sure that it will not get filtered somehow again.

Quoted 6 lines

git://linuxtv.org/snawrocki/samsung.git
branch: led_flash_integration_v4

gitweb:
http://git.linuxtv.org/cgit.cgi/snawrocki/samsung.git/log/?h=led_flash_integration_v4

Yes, I got it. I merged some leds core fixing patches from you recently. So could you please split these big patchset into several small parts which should be easier for reviewing and discussion.
- led core fixing
- led flash core patches
- led flash manager patches
- v4l2 led patches
- Documentations

Quoted 2 lines

My plan is to review these and merge them to my -devel branch. Then invite people for testing.

Thanks for merging the fixes. I will come up with a new patch sets, in the form as you requested, but I would like to apply as many improvements, in comparison to the version 4, as possible. Therefore I'd be grateful if you could express your opinion in the discussion [1].

Best Regards,
Jacek Anaszewski

[1] http://www.spinics.net/lists/linux-media/msg79400.html

#33 lore raw

Re: [PATCH/RFC v4 15/21] media: Add registration helpers for V4L2 flash

In reply to Jacek Anaszewski

Hi Jacek,

On Mon, Aug 11, 2014 at 03:27:22PM +0200, Jacek Anaszewski wrote:

...

Quoted 74 lines
Quoted 62 lines
Quoted 53 lines
Quoted 44 lines
Quoted 44 lines
include/media/v4l2-flash.h new file +38 -0
new file mode 100644
index 0000000..effa46b
@@ -0,0 +1,137 @@
+/*
+ * V4L2 Flash LED sub-device registration helpers.
+ *
+ *	Copyright (C) 2014 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."
+ */
+
+#ifndef _V4L2_FLASH_H
+#define _V4L2_FLASH_H
+
+#include <media/v4l2-ctrls.h>
+#include <media/v4l2-device.h>
+#include <media/v4l2-dev.h>le
+#include <media/v4l2-event.h>
+#include <media/v4l2-ioctl.h>
+
+struct led_classdev_flash;
+struct led_classdev;
+enum led_brightness;
+
+struct v4l2_flash_ops {
+	int (*torch_brightness_set)(struct led_classdev *led_cdev,
+					enum led_brightness brightness);
+	int (*torch_brightness_update)(struct led_classdev *led_cdev);
+	int (*flash_brightness_set)(struct led_classdev_flash *flash,
+					u32 brightness);
+	int (*flash_brightness_update)(struct led_classdev_flash *flash);
+	int (*strobe_set)(struct led_classdev_flash *flash, bool state);
+	int (*strobe_get)(struct led_classdev_flash *flash, bool *state);
+	int (*timeout_set)(struct led_classdev_flash *flash, u32 timeout);
+	int (*indicator_brightness_set)(struct led_classdev_flash *flash,
+					u32 brightness);
+	int (*indicator_brightness_update)(struct led_classdev_flash *flash);
+	int (*external_strobe_set)(struct led_classdev_flash *flash,
Quoted 8 lines

include/media/v4l2-flash.h line 42

Quoted 4 lines
include/media/v4l2-flash.h new file +4 -0
+					bool enable);
+	int (*fault_get)(struct led_classdev_flash *flash, u32 *fault);
+	void (*sysfs_lock)(struct led_classdev *led_cdev);
+	void (*sysfs_unlock)(struct led_classdev *led_cdev);

These functions are not driver specific and there's going to be just one implementation (I suppose). Could you refresh my memory regarding why the LED framework functions aren't called directly?

Quoted 2 lines

These ops are required to make possible building led-class-flash as a kernel module.

Assuming you'd use the actual implementation directly, what would be the dependencies? I don't think the LED flash framework has any callbacks towards the V4L2 (LED) flash framework, does it? Please correct my understanding if I'm missing something. In Makefile format, assume all targets are .PHONY:

Quoted 5 lines

led-flash-api: led-api

v4l2-flash: led-flash-api

driver: led-flash-api v4l2-flash

LED Class Flash driver gains V4L2 Flash API when CONFIG_V4L2_FLASH_LED_CLASS is defined. This is accomplished in the probe function by either calling v4l2_flash_init function or the macro of this name, when the CONFIG_V4L2_FLASH_LED_CLASS macro isn't defined.

Quoted 3 lines

If the v4l2-flash.c was to call the LED API directly, then the led-class-flash module symbols would have to be available at v4l2-flash.o linking time.

Is this an issue? EXPORT_SYMBOL_GPL() for the relevant symbols should be enough.

Quoted 6 lines

This requirement cannot be met if the led-class-flash is built as a module.

Use of function pointers in the v4l2-flash.c allows to compile it into the kernel and enables the possibility of adding the V4L2 Flash support conditionally, during driver probing.

I'd simply decide this during kernel compilation time. If you want something, just enable it. v4l2_flash_init() is called directly by the driver in any case, so unless that is also called through a wrapper the driver is still directly dependent on it.

Signature · 4 lines
Kind regards,

Sakari Ailus
e-mail: [email protected]	XMPP: [email protected]
#14 lore raw

Re: [PATCH/RFC v4 06/21] leds: add API for setting torch brightness

In reply to Jacek Anaszewski

Bryan and Richard,

Your opinion would be much appreciated to a question myself and Jacek were pondering. Please see below.

Quoted 88 lines · Jacek Anaszewski

Hi Sakari,

Quoted 85 lines · Sakari Ailus

Hi Jacek,

Thank you for your continued efforts on this!

Quoted 68 lines · Jacek Anaszewski
Quoted 40 lines · Sakari Ailus

Hi Jacek,

Jacek Anaszewski wrote:
...

Quoted 18 lines
include/linux/leds.h +4 -0
index 1a130cc..9bea9e6 100644
@@ -44,11 +44,21 @@ struct led_classdev {
 #define LED_BLINK_ONESHOT_STOP    (1 << 18)
 #define LED_BLINK_INVERT    (1 << 19)
 #define LED_SYSFS_LOCK        (1 << 20)
+#define LED_DEV_CAP_TORCH    (1 << 21)
 
     /* Set LED brightness level */
     /* Must not sleep, use a workqueue if needed */
     void        (*brightness_set)(struct led_classdev *led_cdev,
                       enum led_brightness brightness);
+    /*
+     * Set LED brightness immediately - it is required for flash led
+     * devices as they require setting torch brightness to have

immediate

include/linux/leds.h struct led_classdev { · line 59

Quoted 4 lines
include/linux/leds.h +4 -0
+     * effect. brightness_set op cannot be used for this purpose because
+     * the led drivers schedule a work queue task in it to allow for
+     * being called from led-triggers, i.e. from the timer irq context.
+     */

Do we need to classify actual devices based on this? I think it's rather a different API behaviour between the LED and the V4L2 APIs.

On devices that are slow to control, the behaviour should be asynchronous over the LED API and synchronous when accessed through the V4L2 API. How about implementing the work queue, as I have suggested, in the framework, so
that individual drivers don't need to care about this and just implement the
synchronous variant of this op? A flag could be added to distinguish devices
that are fast so that the work queue isn't needed.

Quoted 4 lines

It'd be nice to avoid individual drivers having to implement multiple ops to
do the same thing, just for differing user space interfacs.

It is not only the matter of a device controller speed. If a flash device is to be made accessible from the LED subsystem, then it should be also compatible with led-triggers. Some of led-triggers call brightness_set op from the timer irq context and thus no locking in the callback can occur. This requirement cannot be met i.e. if i2c bus is to be used. This is probably the primary reason for scheduling work queue tasks in brightness_set op.

Having the above in mind, setting a brightness in a work queue task must be possible for all LED Class Flash drivers, regardless whether related devices have fast or slow controller.

Let's recap the cost of possible solutions then:

1) Moving the work queues to the LED framework

- it would probably require extending led_set_brightness and __led_set_brightness functions by a parameter indicating whether it should call brightness_set op in the work queue task or directly;
- all existing triggers would have to be updated accordingly;
- work queues would have to be removed from all the LED drivers;

Quoted 7 lines

2) adding led_set_torch_brightness API

- no modifications in existing drivers and triggers would be required
- instead, only the modifications from the discussed patch would be required

Solution 1 looks cleaner but requires much more modifications.

How about a combination of the two, i.e. option 1 with the old op remaining there for compatibility with the old drivers (with a comment telling it's deprecated)?

Quoted 5 lines
Quoted 2 lines

This way new drivers will benefit from having to implement this just once, and modifications to the existing drivers could be left for later.

It's OK for me, but the opinion from the LED side guys is needed here as well.

Ping.

Quoted 9 lines
Quoted 3 lines

The downside is that any old drivers wouldn't get V4L2 flash API but that's entirely acceptable in my opinion since these would hardly be needed in use cases that would benefit from V4L2 flash API.

In the version 4 of the patch set I changed the implementation, so that a flash led driver must call led_classdev_flash_register to get registered as a LED Flash Class device and v4l2_flash_init to get V4L2 Flash API. In effect old drivers will have no chance to get V4L2 Flash API either way.

Signature · 4 lines
Kind regards,

Sakari Ailus
e-mail: [email protected]	XMPP: [email protected]
#52 lore raw
In reply to Jacek Anaszewski

Hi Jacek,

Quoted 48 lines · Jacek Anaszewski
Quoted 25 lines · Sakari Ailus

Hi Jacek,

On Fri, Jul 11, 2014 at 04:04:03PM +0200, Jacek Anaszewski wrote:
...

Quoted 12 lines

1) Who should register V4L2 Flash sub-device?

LED Flash Class devices, after introduction of the Flash Manager, are not tightly coupled with any media controller. They are maintained by the Flash Manager and made available for dynamic assignment to any media system they are connected to through multiplexing devices.

In the proposed rough solution, when support for V4L2 Flash sub-devices is enabled, there is a v4l2_device created for them to register in. This however implies that V4L2 Flash device will not be available in any media controller, which calls its existence into question.

Quoted 8 lines

Therefore I'd like to consult possible ways of solving this issue. The option I see is implementing a mechanism for moving V4L2 Flash sub-devices between media controllers. A V4L2 Flash sub-device would initially be assigned to one media system in the relevant device tree binding, but it could be dynamically reassigned to the other one. However I'm not sure if media controller design is prepared for dynamic modifications of its graph and how many modifications in the existing drivers this solution would require.

Quoted 5 lines

Do you have a use case where you would need to strobe a flash from multiple media devices at different times, or is this entirely theoretical? Typically flash controllers are connected to a single source of hardware strobe (if there's one) since the flash LEDs are in fact mounted next to a specific camera sensor.

I took into account such arrangements in response to your message [1], where you were considering configurations like "one flash but two
cameras", "one camera and two flashes". And you also called for proposing generic solution.

One flash and two (or more) cameras case is easily conceivable - You even mentioned stereo cameras. One camera and many flashes arrangement might be useful in case of some professional devices which might be designed so that they would be able to apply different scene lighting. I haven't heard about such devices, but as you said such a configuration isn't unthinkable.

Quoted 2 lines

If this is a real issue the way to solve it would be to have a single media device instead of many.

Quoted 9 lines

I was considering adding media device, that would be a representation of a flash manager, gathering all the registered flashes. Nonetheless, finally I came to conclusion that a v4l2-device alone should suffice, just to provide a Flash Manager representation allowing for v4l2-flash sub-devices to register in.
All the features provided by the media device are useless in case of a set of V4L2 Flash sub-devices. They couldn't have any linkage in such a device. The only benefit from having media device gathering V4L2 Flash devices would be possibility of listing them.

Not quite so. The flash is associated to the sensor (and lens) using the group ID in the Media controller. The user space doesn't need to "know" this association.

More complex use cases such as the above may need extensions to the Media controller API.

Quoted 36 lines
Quoted 12 lines
Quoted 7 lines

2) Consequences of locking the Flash Manager during flash strobe

In case a LED Flash Class device depends on muxes involved in routing the other LED Flash Class device's strobe signals, the Flash Manager must be locked for the time of strobing to prevent reconfiguration of the strobe signal routing by the other device.

I wouldn't be concerned of this in particular. It's more important we do actully have V4L2 flash API supported by LED flash drivers and that they do implement the API correctly.

Quoted 7 lines

It's at least debatable whether you should try to prevent user space from doing silly things or not. With complex devices it may relatively easily lead to wrecking havoc with actual use cases which we certainly do not want.

In this case, if you just prevent changing the routing (do you have a use case for it?) while strobing, someone else could still change the routing just before you strobe.

Originally I started to implementing this so that strobe signal routing was altered upon setting strobe source. With such an implementation the use case would be as follows:

1. Process 1 sets strobe source to external
2. Process 2 sets strobe source to software
3. Process 1 strobes the flash, unaware that strobe source setting has been changed

To avoid such problems I changed the implementation so that the routing is set in the led_flash_manager_setup_strobe function called from led_set_flash_strobe and led_set_external_strobe functions. led_flash_manager_setup_strobe sets strobe signal routing and strobes the flash under lock and holds it for the flash timeout period, which prevents spurious reconfiguration.

Quoted 3 lines

Nonetheless, I agree that trying to handle this problem is troublesome, and would affect current V4L2 Flash SPI semantics. If you don't share my concerns I am happy to leave this locking solution out :)

I do propose leaving it out. If we should have such a thing we should think it in a larger scope than just flash strobing.

Signature · 4 lines
Kind regards,

Sakari Ailus
e-mail: [email protected]	XMPP: [email protected]
#34 lore raw

Re: [PATCH/RFC v4 15/21] media: Add registration helpers for V4L2 flash

In reply to Sakari Ailus
Quoted 80 lines · Sakari Ailus

Hi Jacek,

On Mon, Aug 11, 2014 at 03:27:22PM +0200, Jacek Anaszewski wrote:

...

Quoted 74 lines
Quoted 62 lines
Quoted 53 lines
Quoted 44 lines
Quoted 44 lines
include/media/v4l2-flash.h new file +38 -0
new file mode 100644
index 0000000..effa46b
@@ -0,0 +1,137 @@
+/*
+ * V4L2 Flash LED sub-device registration helpers.
+ *
+ *	Copyright (C) 2014 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."
+ */
+
+#ifndef _V4L2_FLASH_H
+#define _V4L2_FLASH_H
+
+#include <media/v4l2-ctrls.h>
+#include <media/v4l2-device.h>
+#include <media/v4l2-dev.h>le
+#include <media/v4l2-event.h>
+#include <media/v4l2-ioctl.h>
+
+struct led_classdev_flash;
+struct led_classdev;
+enum led_brightness;
+
+struct v4l2_flash_ops {
+	int (*torch_brightness_set)(struct led_classdev *led_cdev,
+					enum led_brightness brightness);
+	int (*torch_brightness_update)(struct led_classdev *led_cdev);
+	int (*flash_brightness_set)(struct led_classdev_flash *flash,
+					u32 brightness);
+	int (*flash_brightness_update)(struct led_classdev_flash *flash);
+	int (*strobe_set)(struct led_classdev_flash *flash, bool state);
+	int (*strobe_get)(struct led_classdev_flash *flash, bool *state);
+	int (*timeout_set)(struct led_classdev_flash *flash, u32 timeout);
+	int (*indicator_brightness_set)(struct led_classdev_flash *flash,
+					u32 brightness);
+	int (*indicator_brightness_update)(struct led_classdev_flash *flash);
+	int (*external_strobe_set)(struct led_classdev_flash *flash,
Quoted 8 lines

include/media/v4l2-flash.h line 42

Quoted 4 lines
include/media/v4l2-flash.h new file +4 -0
+					bool enable);
+	int (*fault_get)(struct led_classdev_flash *flash, u32 *fault);
+	void (*sysfs_lock)(struct led_classdev *led_cdev);
+	void (*sysfs_unlock)(struct led_classdev *led_cdev);

These functions are not driver specific and there's going to be just one implementation (I suppose). Could you refresh my memory regarding why the LED framework functions aren't called directly?

Quoted 2 lines

These ops are required to make possible building led-class-flash as a kernel module.

Assuming you'd use the actual implementation directly, what would be the dependencies? I don't think the LED flash framework has any callbacks towards the V4L2 (LED) flash framework, does it? Please correct my understanding if I'm missing something. In Makefile format, assume all targets are .PHONY:

Quoted 5 lines

led-flash-api: led-api

v4l2-flash: led-flash-api

driver: led-flash-api v4l2-flash

LED Class Flash driver gains V4L2 Flash API when CONFIG_V4L2_FLASH_LED_CLASS is defined. This is accomplished in the probe function by either calling v4l2_flash_init function or the macro of this name, when the CONFIG_V4L2_FLASH_LED_CLASS macro isn't defined.

Quoted 6 lines
Quoted 3 lines

If the v4l2-flash.c was to call the LED API directly, then the led-class-flash module symbols would have to be available at v4l2-flash.o linking time.

Is this an issue? EXPORT_SYMBOL_GPL() for the relevant symbols should be enough.

It isn't enough. If I call e.g. led_set_flash_brightness directly from v4l2-flash.c and configure led-class-flash to be built as a module then I am getting "undefined reference to led_set_flash_brightness" error during linking phase.

It happens because the linker doesn't take into account led-flash-class.ko symbols. It is reasonable because initially the kernel boots up without led-flash-class.ko module and the processor wouldn't know the address to jump to in the result of calling a led API function.
The led-class-flash.ko binary code is loaded into memory not sooner than after executing "insmod led-class-flash.ko".

After linking dynamically with kernel the LED API function addresses are relocated, and the LED Flash Class core can initialize the v4l2_flash_ops structure. Then every LED Flash Class driver can obtain the address of this structure with led_get_v4l2_flash_ops and pass it to the v4l2_flash_init.

Quoted 11 lines
Quoted 6 lines

This requirement cannot be met if the led-class-flash is built as a module.

Use of function pointers in the v4l2-flash.c allows to compile it into the kernel and enables the possibility of adding the V4L2 Flash support conditionally, during driver probing.

I'd simply decide this during kernel compilation time. If you want something, just enable it. v4l2_flash_init() is called directly by the driver in any case, so unless that is also called through a wrapper the driver is still directly dependent on it.

The problem is that v4l2-flash.o would have to depend on led-class-flash.o, which when built as a module isn't available during v4l2-flash.o linking time. In order to avoid v4l2-flash.o linking problem, it would have to be built as a module.

Nevertheless, in this arrangement, the CONFIG_V4L2_FLASH_LED_CLASS macro would be defined only in v4l2-flash.ko module, and a LED Flash Class driver couldn't check whether V4L2 Flash support is enabled. Its dependence on v4l2-flash.o would have to be fixed, which is not what we want.

I have tested all these cases.

Best Regards,
Jacek Anaszewski
--
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

#53 lore raw
In reply to Sakari Ailus
Quoted 61 lines · Sakari Ailus

Hi Jacek,

Quoted 48 lines · Jacek Anaszewski
Quoted 25 lines · Sakari Ailus

Hi Jacek,

On Fri, Jul 11, 2014 at 04:04:03PM +0200, Jacek Anaszewski wrote:
...

Quoted 12 lines

1) Who should register V4L2 Flash sub-device?

LED Flash Class devices, after introduction of the Flash Manager, are not tightly coupled with any media controller. They are maintained by the Flash Manager and made available for dynamic assignment to any media system they are connected to through multiplexing devices.

In the proposed rough solution, when support for V4L2 Flash sub-devices is enabled, there is a v4l2_device created for them to register in. This however implies that V4L2 Flash device will not be available in any media controller, which calls its existence into question.

Quoted 8 lines

Therefore I'd like to consult possible ways of solving this issue. The option I see is implementing a mechanism for moving V4L2 Flash sub-devices between media controllers. A V4L2 Flash sub-device would initially be assigned to one media system in the relevant device tree binding, but it could be dynamically reassigned to the other one. However I'm not sure if media controller design is prepared for dynamic modifications of its graph and how many modifications in the existing drivers this solution would require.

Quoted 5 lines

Do you have a use case where you would need to strobe a flash from multiple media devices at different times, or is this entirely theoretical? Typically flash controllers are connected to a single source of hardware strobe (if there's one) since the flash LEDs are in fact mounted next to a specific camera sensor.

I took into account such arrangements in response to your message [1], where you were considering configurations like "one flash but two
cameras", "one camera and two flashes". And you also called for proposing generic solution.

One flash and two (or more) cameras case is easily conceivable - You even mentioned stereo cameras. One camera and many flashes arrangement might be useful in case of some professional devices which might be designed so that they would be able to apply different scene lighting. I haven't heard about such devices, but as you said such a configuration isn't unthinkable.

Quoted 2 lines

If this is a real issue the way to solve it would be to have a single media device instead of many.

Quoted 9 lines

I was considering adding media device, that would be a representation of a flash manager, gathering all the registered flashes. Nonetheless, finally I came to conclusion that a v4l2-device alone should suffice, just to provide a Flash Manager representation allowing for v4l2-flash sub-devices to register in.
All the features provided by the media device are useless in case of a set of V4L2 Flash sub-devices. They couldn't have any linkage in such a device. The only benefit from having media device gathering V4L2 Flash devices would be possibility of listing them.

Quoted 6 lines

Not quite so. The flash is associated to the sensor (and lens) using the group ID in the Media controller. The user space doesn't need to "know" this association.

More complex use cases such as the above may need extensions to the Media controller API.

I think that I have unnecessarily complicated the issue. Generally there will be always one media controller created for all camera sensors available in the system. If there is a single media controller then we can easily use async subdev registration API. A media-dev driver would have to parse list of flash device phandles from the ISP device's DT node and register them as async sub-devices.

Best Regards,
Jacek Anaszewski

--
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

#54 lore raw
Quoted 69 lines · Jacek Anaszewski
Quoted 61 lines · Sakari Ailus

Hi Jacek,

Quoted 48 lines · Jacek Anaszewski
Quoted 25 lines · Sakari Ailus

Hi Jacek,

On Fri, Jul 11, 2014 at 04:04:03PM +0200, Jacek Anaszewski wrote:
...

Quoted 12 lines

1) Who should register V4L2 Flash sub-device?

LED Flash Class devices, after introduction of the Flash Manager, are not tightly coupled with any media controller. They are maintained by the Flash Manager and made available for dynamic assignment to any media system they are connected to through multiplexing devices.

In the proposed rough solution, when support for V4L2 Flash sub-devices is enabled, there is a v4l2_device created for them to register in. This however implies that V4L2 Flash device will not be available in any media controller, which calls its existence into question.

Quoted 8 lines

Therefore I'd like to consult possible ways of solving this issue. The option I see is implementing a mechanism for moving V4L2 Flash sub-devices between media controllers. A V4L2 Flash sub-device would initially be assigned to one media system in the relevant device tree binding, but it could be dynamically reassigned to the other one. However I'm not sure if media controller design is prepared for dynamic modifications of its graph and how many modifications in the existing drivers this solution would require.

Quoted 5 lines

Do you have a use case where you would need to strobe a flash from multiple media devices at different times, or is this entirely theoretical? Typically flash controllers are connected to a single source of hardware strobe (if there's one) since the flash LEDs are in fact mounted next to a specific camera sensor.

I took into account such arrangements in response to your message [1], where you were considering configurations like "one flash but two
cameras", "one camera and two flashes". And you also called for proposing generic solution.

One flash and two (or more) cameras case is easily conceivable - You even mentioned stereo cameras. One camera and many flashes arrangement might be useful in case of some professional devices which might be designed so that they would be able to apply different scene lighting. I haven't heard about such devices, but as you said such a configuration isn't unthinkable.

Quoted 2 lines

If this is a real issue the way to solve it would be to have a single media device instead of many.

Quoted 9 lines

I was considering adding media device, that would be a representation of a flash manager, gathering all the registered flashes. Nonetheless, finally I came to conclusion that a v4l2-device alone should suffice, just to provide a Flash Manager representation allowing for v4l2-flash sub-devices to register in.
All the features provided by the media device are useless in case of a set of V4L2 Flash sub-devices. They couldn't have any linkage in such a device. The only benefit from having media device gathering V4L2 Flash devices would be possibility of listing them.

Quoted 6 lines

Not quite so. The flash is associated to the sensor (and lens) using the group ID in the Media controller. The user space doesn't need to "know" this association.

More complex use cases such as the above may need extensions to the Media controller API.

Quoted 6 lines

I think that I have unnecessarily complicated the issue. Generally there will be always one media controller created for all camera sensors available in the system. If there is a single media controller then we can easily use async subdev registration API. A media-dev driver would have to parse list of flash device phandles from the ISP device's DT node and register them as async sub-devices.

Currently the media device is created by a driver which is most of the time the ISP driver on embedded systems. This driver is also responsible for registering the flash device (nodes) to the media device. So "will" is the word, I think.

Signature · 2 lines
Sakari Ailus
e-mail: [email protected]	XMPP: [email protected]
#15 lore raw

Re: [PATCH/RFC v4 06/21] leds: add API for setting torch brightness

In reply to Sakari Ailus
Quoted 94 lines · Sakari Ailus

Bryan and Richard,

Your opinion would be much appreciated to a question myself and Jacek were pondering. Please see below.

Quoted 88 lines · Jacek Anaszewski

Hi Sakari,

Quoted 85 lines · Sakari Ailus

Hi Jacek,

Thank you for your continued efforts on this!

Quoted 68 lines · Jacek Anaszewski
Quoted 40 lines · Sakari Ailus

Hi Jacek,

Jacek Anaszewski wrote:
...

Quoted 18 lines
include/linux/leds.h +4 -0
index 1a130cc..9bea9e6 100644
@@ -44,11 +44,21 @@ struct led_classdev {
 #define LED_BLINK_ONESHOT_STOP    (1 << 18)
 #define LED_BLINK_INVERT    (1 << 19)
 #define LED_SYSFS_LOCK        (1 << 20)
+#define LED_DEV_CAP_TORCH    (1 << 21)
 
     /* Set LED brightness level */
     /* Must not sleep, use a workqueue if needed */
     void        (*brightness_set)(struct led_classdev *led_cdev,
                       enum led_brightness brightness);
+    /*
+     * Set LED brightness immediately - it is required for flash led
+     * devices as they require setting torch brightness to have

immediate

include/linux/leds.h struct led_classdev { · line 59

Quoted 4 lines
include/linux/leds.h +4 -0
+     * effect. brightness_set op cannot be used for this purpose because
+     * the led drivers schedule a work queue task in it to allow for
+     * being called from led-triggers, i.e. from the timer irq context.
+     */

Do we need to classify actual devices based on this? I think it's rather a different API behaviour between the LED and the V4L2 APIs.

On devices that are slow to control, the behaviour should be asynchronous over the LED API and synchronous when accessed through the V4L2 API. How about implementing the work queue, as I have suggested, in the framework, so
that individual drivers don't need to care about this and just implement the
synchronous variant of this op? A flag could be added to distinguish devices
that are fast so that the work queue isn't needed.

Quoted 4 lines

It'd be nice to avoid individual drivers having to implement multiple ops to
do the same thing, just for differing user space interfacs.

It is not only the matter of a device controller speed. If a flash device is to be made accessible from the LED subsystem, then it should be also compatible with led-triggers. Some of led-triggers call brightness_set op from the timer irq context and thus no locking in the callback can occur. This requirement cannot be met i.e. if i2c bus is to be used. This is probably the primary reason for scheduling work queue tasks in brightness_set op.

Having the above in mind, setting a brightness in a work queue task must be possible for all LED Class Flash drivers, regardless whether related devices have fast or slow controller.

Let's recap the cost of possible solutions then:

1) Moving the work queues to the LED framework

- it would probably require extending led_set_brightness and __led_set_brightness functions by a parameter indicating whether it should call brightness_set op in the work queue task or directly;
- all existing triggers would have to be updated accordingly;
- work queues would have to be removed from all the LED drivers;

Quoted 7 lines

2) adding led_set_torch_brightness API

- no modifications in existing drivers and triggers would be required
- instead, only the modifications from the discussed patch would be required

Solution 1 looks cleaner but requires much more modifications.

How about a combination of the two, i.e. option 1 with the old op remaining there for compatibility with the old drivers (with a comment telling it's deprecated)?

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

This way new drivers will benefit from having to implement this just once, and modifications to the existing drivers could be left for later.

It's OK for me, but the opinion from the LED side guys is needed here as well.

Ping.

I'm not a fan of forcing everything to the lowest common denominator. At a basic level an LED is a binary on/off so the shear levels of complexity we end up going through is kind of scary. Forcing everything through a workqueue due to their being some hardware out there can can't do it in interrupt context is kind of sad and wasn't where the API set out from.

So personally I'd prefer not to see the API changed like that however I appreciate I've been more distant from the code of late.

Cheers,

Richard

#16 lore raw

Re: [PATCH/RFC v4 06/21] leds: add API for setting torch brightness

Hi Richard,

Quoted 101 lines · Richard Purdie
Quoted 100 lines · Sakari Ailus

Bryan and Richard,

Your opinion would be much appreciated to a question myself and Jacek were pondering. Please see below.

Quoted 93 lines · Jacek Anaszewski

Hi Sakari,

Quoted 79 lines · Sakari Ailus

Hi Jacek,

Thank you for your continued efforts on this!

Quoted 74 lines · Jacek Anaszewski
Quoted 40 lines · Sakari Ailus

Hi Jacek,

Jacek Anaszewski wrote:
...

Quoted 18 lines
include/linux/leds.h +4 -0
index 1a130cc..9bea9e6 100644
@@ -44,11 +44,21 @@ struct led_classdev {
 #define LED_BLINK_ONESHOT_STOP    (1 << 18)
 #define LED_BLINK_INVERT    (1 << 19)
 #define LED_SYSFS_LOCK        (1 << 20)
+#define LED_DEV_CAP_TORCH    (1 << 21)
 
     /* Set LED brightness level */
     /* Must not sleep, use a workqueue if needed */
     void        (*brightness_set)(struct led_classdev *led_cdev,
                       enum led_brightness brightness);
+    /*
+     * Set LED brightness immediately - it is required for flash led
+     * devices as they require setting torch brightness to have

immediate

include/linux/leds.h

Quoted 4 lines
include/linux/leds.h +4 -0
+     * effect. brightness_set op cannot be used for this purpose because
+     * the led drivers schedule a work queue task in it to allow for
+     * being called from led-triggers, i.e. from the timer irq context.
+     */

Do we need to classify actual devices based on this? I think it's rather a different API behaviour between the LED and the V4L2 APIs.

On devices that are slow to control, the behaviour should be asynchronous over the LED API and synchronous when accessed through the V4L2 API. How about implementing the work queue, as I have suggested, in the framework, so
that individual drivers don't need to care about this and just implement the
synchronous variant of this op? A flag could be added to distinguish devices
that are fast so that the work queue isn't needed.

Quoted 4 lines

It'd be nice to avoid individual drivers having to implement multiple ops to
do the same thing, just for differing user space interfacs.

It is not only the matter of a device controller speed. If a flash device is to be made accessible from the LED subsystem, then it should be also compatible with led-triggers. Some of led-triggers call brightness_set op from the timer irq context and thus no locking in the callback can occur. This requirement cannot be met i.e. if i2c bus is to be used. This is probably the primary reason for scheduling work queue tasks in brightness_set op.

Having the above in mind, setting a brightness in a work queue task must be possible for all LED Class Flash drivers, regardless whether related devices have fast or slow controller.

Let's recap the cost of possible solutions then:

1) Moving the work queues to the LED framework

- it would probably require extending led_set_brightness and __led_set_brightness functions by a parameter indicating whether it should call brightness_set op in the work queue task or directly;
- all existing triggers would have to be updated accordingly;
- work queues would have to be removed from all the LED drivers;

2) adding led_set_torch_brightness API

- no modifications in existing drivers and triggers would be required
- instead, only the modifications from the discussed patch would be required

Quoted 8 lines
Quoted 1 line

Solution 1 looks cleaner but requires much more modifications.

How about a combination of the two, i.e. option 1 with the old op remaining there for compatibility with the old drivers (with a comment telling it's deprecated)?

This way new drivers will benefit from having to implement this just once, and modifications to the existing drivers could be left for later.

It's OK for me, but the opinion from the LED side guys is needed here as well.

Quoted 8 lines
Quoted 1 line

Ping.

I'm not a fan of forcing everything to the lowest common denominator. At a basic level an LED is a binary on/off so the shear levels of complexity we end up going through is kind of scary. Forcing everything through a workqueue due to their being some hardware out there can can't do it in interrupt context is kind of sad and wasn't where the API set out from.

The discussion has been centered around devices that do actually need that work queue for sleepless operation. Naturally, if the work queue isn't required by a particular device, it should not be used.

What we'd prefer to avoid here is drivers having to implement two ways (synchronoys and potentially asynchronous) to perform the same actions (for V4L2 and LED API, respectively).

Signature · 4 lines
Kind regards,

Sakari Ailus
[email protected]
#35 lore raw

Re: [PATCH/RFC v4 15/21] media: Add registration helpers for V4L2 flash

In reply to Jacek Anaszewski

Hi Jacek,

Quoted 85 lines · Jacek Anaszewski
Quoted 84 lines · Sakari Ailus

Hi Jacek,

On Mon, Aug 11, 2014 at 03:27:22PM +0200, Jacek Anaszewski wrote:

...

Quoted 77 lines
Quoted 62 lines
Quoted 53 lines
Quoted 44 lines
Quoted 44 lines
include/media/v4l2-flash.h new file +38 -0
new file mode 100644
index 0000000..effa46b
@@ -0,0 +1,137 @@
+/*
+ * V4L2 Flash LED sub-device registration helpers.
+ *
+ *	Copyright (C) 2014 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."
+ */
+
+#ifndef _V4L2_FLASH_H
+#define _V4L2_FLASH_H
+
+#include <media/v4l2-ctrls.h>
+#include <media/v4l2-device.h>
+#include <media/v4l2-dev.h>le
+#include <media/v4l2-event.h>
+#include <media/v4l2-ioctl.h>
+
+struct led_classdev_flash;
+struct led_classdev;
+enum led_brightness;
+
+struct v4l2_flash_ops {
+	int (*torch_brightness_set)(struct led_classdev *led_cdev,
+					enum led_brightness brightness);
+	int (*torch_brightness_update)(struct led_classdev *led_cdev);
+	int (*flash_brightness_set)(struct led_classdev_flash *flash,
+					u32 brightness);
+	int (*flash_brightness_update)(struct led_classdev_flash *flash);
+	int (*strobe_set)(struct led_classdev_flash *flash, bool state);
+	int (*strobe_get)(struct led_classdev_flash *flash, bool *state);
+	int (*timeout_set)(struct led_classdev_flash *flash, u32 timeout);
+	int (*indicator_brightness_set)(struct led_classdev_flash *flash,
+					u32 brightness);
+	int (*indicator_brightness_update)(struct led_classdev_flash *flash);
+	int (*external_strobe_set)(struct led_classdev_flash *flash,
Quoted 8 lines

include/media/v4l2-flash.h line 42

Quoted 4 lines
include/media/v4l2-flash.h new file +4 -0
+					bool enable);
+	int (*fault_get)(struct led_classdev_flash *flash, u32 *fault);
+	void (*sysfs_lock)(struct led_classdev *led_cdev);
+	void (*sysfs_unlock)(struct led_classdev *led_cdev);

These functions are not driver specific and there's going to be just one implementation (I suppose). Could you refresh my memory regarding why the LED framework functions aren't called directly?

Quoted 2 lines

These ops are required to make possible building led-class-flash as a kernel module.

Assuming you'd use the actual implementation directly, what would be the dependencies? I don't think the LED flash framework has any callbacks towards the V4L2 (LED) flash framework, does it? Please correct my understanding if I'm missing something. In Makefile format, assume all targets are .PHONY:

Quoted 5 lines

led-flash-api: led-api

v4l2-flash: led-flash-api

driver: led-flash-api v4l2-flash

LED Class Flash driver gains V4L2 Flash API when CONFIG_V4L2_FLASH_LED_CLASS is defined. This is accomplished in the probe function by either calling v4l2_flash_init function or the macro of this name, when the CONFIG_V4L2_FLASH_LED_CLASS macro isn't defined.

If the v4l2-flash.c was to call the LED API directly, then the led-class-flash module symbols would have to be available at v4l2-flash.o linking time.

Quoted 7 lines
Quoted 2 lines

Is this an issue? EXPORT_SYMBOL_GPL() for the relevant symbols should be enough.

It isn't enough. If I call e.g. led_set_flash_brightness directly from v4l2-flash.c and configure led-class-flash to be built as a module then I am getting "undefined reference to led_set_flash_brightness" error during linking phase.

You should not. You also should change the check as (unless you've changed it already):

#if IS_ENABLED(CONFIG_V4L2_FLASH_LED_CLASS)

This will evaluate to non-zero if the macro arguent or the argument postfixed with "_MODULE" is defined.

Quoted 26 lines

It happens because the linker doesn't take into account led-flash-class.ko symbols. It is reasonable because initially the kernel boots up without led-flash-class.ko module and the processor wouldn't know the address to jump to in the result of calling a led API function.
The led-class-flash.ko binary code is loaded into memory not sooner than after executing "insmod led-class-flash.ko".

After linking dynamically with kernel the LED API function addresses are relocated, and the LED Flash Class core can initialize the v4l2_flash_ops structure. Then every LED Flash Class driver can obtain the address of this structure with led_get_v4l2_flash_ops and pass it to the v4l2_flash_init.

Quoted 11 lines
Quoted 6 lines

This requirement cannot be met if the led-class-flash is built as a module.

Use of function pointers in the v4l2-flash.c allows to compile it into the kernel and enables the possibility of adding the V4L2 Flash support conditionally, during driver probing.

I'd simply decide this during kernel compilation time. If you want something, just enable it. v4l2_flash_init() is called directly by the driver in any case, so unless that is also called through a wrapper the driver is still directly dependent on it.

Quoted 4 lines

The problem is that v4l2-flash.o would have to depend on led-class-flash.o, which when built as a module isn't available during v4l2-flash.o linking time. In order to avoid v4l2-flash.o linking problem, it would have to be built as a module.

Modules can depend on other modules, that's not an issue. All dependencies will themselves be modules as well, i.e. if led-class-flash.o is a module, so will be v4l2-flash.o as well --- as the former depends on the latter.

Quoted 5 lines

Nevertheless, in this arrangement, the CONFIG_V4L2_FLASH_LED_CLASS macro would be defined only in v4l2-flash.ko module, and a LED Flash Class driver couldn't check whether V4L2 Flash support is enabled. Its dependence on v4l2-flash.o would have to be fixed, which is not what we want.

Signature · 4 lines
Kind regards,

Sakari Ailus
e-mail: [email protected]	XMPP: [email protected]
#36 lore raw

Re: [PATCH/RFC v4 15/21] media: Add registration helpers for V4L2 flash

Hi Sakari,

Quoted 1 line · Sakari Ailus

Hi Jacek,

[...]

Quoted 19 lines
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

LED Class Flash driver gains V4L2 Flash API when CONFIG_V4L2_FLASH_LED_CLASS is defined. This is accomplished in the probe function by either calling v4l2_flash_init function or the macro of this name, when the CONFIG_V4L2_FLASH_LED_CLASS macro isn't defined.

If the v4l2-flash.c was to call the LED API directly, then the led-class-flash module symbols would have to be available at v4l2-flash.o linking time.

Quoted 7 lines
Quoted 2 lines

Is this an issue? EXPORT_SYMBOL_GPL() for the relevant symbols should be enough.

It isn't enough. If I call e.g. led_set_flash_brightness directly from v4l2-flash.c and configure led-class-flash to be built as a module then I am getting "undefined reference to led_set_flash_brightness" error during linking phase.

Quoted 7 lines

You should not. You also should change the check as (unless you've changed it already):

#if IS_ENABLED(CONFIG_V4L2_FLASH_LED_CLASS)

This will evaluate to non-zero if the macro arguent or the argument postfixed with "_MODULE" is defined.

I've missed this macro. Indeed, it is possible to avoid the need for ops with it. I will fix it in the next version of the patch set. Thanks for the hint.

Best Regards,
Jacek Anaszewski