Skip to contentSkip to conversation

LED / flash API integration

PATCH Superseded Jacek Anaszewski 7 participants 53 messages Nov 28, 2014 – Jan 29, 2015 1 message not in the archive

Subsystems (8)

v8 of 13 Superseded Latest is v13 →

lore
Share & tools
lore
#0 lore raw

v8 cover LED / flash API integration

This patch set is a follow-up of the LED / flash API integration series [1].

========================
Changes since version 7:
========================

- removed explicit support for indicator leds from LED Flash class - indicator leds will be registered as a separate LED Flash class devices
- added flash_sync_strobe sysfs attribute and related V4L2_CID_FLASH_SYNC_STROBE control
- changed the way of matching V4L2 Flash sub-devices in a media device, which entailed modification in v4l2-async driver
- modified max77693 DT bindings documentation
- applied various fixes an cleanups

========================
Changes since version 6:
========================

- removed addition of public LED subsystem API for setting torch brightness in favour of internal API for synchronous and asynchronous led brightness level setting
- fixed possible race condition upon creating LED Flash class related sysfs attributes

========================
Changes since version 5:
========================

- removed flash manager framework - its implementation needs further thorough discussion.
- removed external strobe facilities from the LED Flash Class and provided external_strobe_set op in v4l2-flash. LED subsystem should be strobe provider agnostic.

Thanks,
Jacek Anaszewski

[1] https://lkml.org/lkml/2014/7/11/914

Jacek Anaszewski (14):
leds: Add LED Flash class extension to the LED subsystem
Documentation: leds: Add description of LED Flash class extension
Documentation: leds: Add description of v4l2-flash sub-device
v4l2-async: change custom.match callback argument type
v4l2-ctrls: Add V4L2_CID_FLASH_SYNC_STROBE control
media: Add registration helpers for V4L2 flash sub-devices
exynos4-is: Add support for v4l2-flash subdevs
DT: Add documentation for exynos4-is 'flashes' property
mfd: max77693: adjust max77693_led_platform_data
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

 Documentation/DocBook/media/v4l/controls.xml       |    9 +
 .../devicetree/bindings/leds/leds-aat1290.txt      |   17 +
 .../devicetree/bindings/media/samsung-fimc.txt     |    7 +
 Documentation/devicetree/bindings/mfd/max77693.txt |   74 ++
 .../devicetree/bindings/vendor-prefixes.txt        |    1 +
 Documentation/leds/leds-class-flash.txt            |   61 ++
 drivers/leds/Kconfig                               |   27 +
 drivers/leds/Makefile                              |    3 +
 drivers/leds/led-class-flash.c                     |  446 ++++++++
 drivers/leds/led-class.c                           |    4 +
 drivers/leds/leds-aat1290.c                        |  472 ++++++++
 drivers/leds/leds-max77693.c                       | 1152 ++++++++++++++++++++
 drivers/media/platform/exynos4-is/media-dev.c      |   65 +-
 drivers/media/platform/exynos4-is/media-dev.h      |   13 +-
 drivers/media/v4l2-core/Kconfig                    |   11 +
 drivers/media/v4l2-core/Makefile                   |    2 +
 drivers/media/v4l2-core/v4l2-async.c               |   16 +-
 drivers/media/v4l2-core/v4l2-ctrls.c               |    2 +
 drivers/media/v4l2-core/v4l2-flash.c               |  516 +++++++++
 include/linux/led-class-flash.h                    |  198 ++++
 include/linux/leds.h                               |    3 +
 include/linux/mfd/max77693.h                       |    3 +-
 include/media/v4l2-async.h                         |    2 +-
 include/media/v4l2-flash.h                         |  138 +++
 include/uapi/linux/v4l2-controls.h                 |    1 +
 25 files changed, 3230 insertions(+), 13 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/leds/leds-aat1290.txt
 create mode 100644 Documentation/leds/leds-class-flash.txt
 create mode 100644 drivers/leds/led-class-flash.c
 create mode 100644 drivers/leds/leds-aat1290.c
 create mode 100644 drivers/leds/leds-max77693.c
 create mode 100644 drivers/media/v4l2-core/v4l2-flash.c
 create mode 100644 include/linux/led-class-flash.h
 create mode 100644 include/media/v4l2-flash.h
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH v8 1/14 leds: Add LED Flash class extension to the LED subsystem

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 and flash_sync_strobe. All the flash related features are placed in a separate module. Torch mode is supported by the LED class interface.

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            |   10 +
 drivers/leds/Makefile           |    1 +
 drivers/leds/led-class-flash.c  |  446 +++++++++++++++++++++++++++++++++++++++
 drivers/leds/led-class.c        |    4 +
 include/linux/led-class-flash.h |  198 +++++++++++++++++
 include/linux/leds.h            |    3 +
 6 files changed, 662 insertions(+)
 create mode 100644 drivers/leds/led-class-flash.c
 create mode 100644 include/linux/led-class-flash.h
drivers/leds/Kconfig +10 -0
index b3c0d8a..fa8021e 100644
@@ -19,6 +19,16 @@ 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
+	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. 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 +1 -0
index 1c65a19..cbba921 100644
@@ -2,6 +2,7 @@
 # LED Core
 obj-$(CONFIG_NEW_LEDS)			+= led-core.o
 obj-$(CONFIG_LEDS_CLASS)		+= led-class.o
+obj-$(CONFIG_LEDS_CLASS_FLASH)		+= led-class-flash.o
 obj-$(CONFIG_LEDS_TRIGGERS)		+= led-triggers.o
 
 # LED Platform Drivers
drivers/leds/led-class-flash.c new file +446 -0

446 lines not on this page · raw message

drivers/leds/led-class.c +4 -0
index dbeebac..02564c5 100644
@@ -179,6 +179,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);
include/linux/led-class-flash.h new file +198 -0

198 lines not on this page · raw message

include/linux/leds.h +3 -0
index cfceef3..c359f35 100644
@@ -46,6 +46,8 @@ struct led_classdev {
 #define LED_SYSFS_DISABLE	(1 << 20)
 #define SET_BRIGHTNESS_ASYNC	(1 << 21)
 #define SET_BRIGHTNESS_SYNC	(1 << 22)
+#define LED_DEV_CAP_FLASH	(1 << 23)
+#define LED_DEV_CAP_COMPOUND	(1 << 24)
 
 	/* Set LED brightness level */
 	/* Must not sleep, use a workqueue if needed */
@@ -81,6 +83,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;
Signature · 1 line
1.7.9.5

A message that is not in the archive (sent off-list or not yet received): CAK5ve-KMdJOLQ0ThKw9OM9u_CcwT87Bx4vcUjnX4fG2+t3pJsw@mail.gmail.com

#3 lore raw

Re: [PATCH/RFC v8 01/14] leds: Add LED Flash class extension to the LED subsystem

Quoted 41 lines · Bryan Wu
Quoted 39 lines · 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 and flash_sync_strobe. All the flash related features are placed in a separate module. Torch mode is supported by the LED class interface.

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            |   10 +
  drivers/leds/Makefile           |    1 +
  drivers/leds/led-class-flash.c  |  446 +++++++++++++++++++++++++++++++++++++++
  drivers/leds/led-class.c        |    4 +
  include/linux/led-class-flash.h |  198 +++++++++++++++++
  include/linux/leds.h            |    3 +
  6 files changed, 662 insertions(+)

create mode 100644 drivers/leds/led-class-flash.c create mode 100644 include/linux/led-class-flash.h

drivers/leds/Kconfig +0 -0
index b3c0d8a..fa8021e 100644
@@ -19,6 +19,16 @@ 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.
 
Quoted 8 lines

drivers/leds/Kconfig config LEDS_CLASS · line 24

Quoted 3 lines
drivers/leds/Kconfig +3 -0
+config LEDS_CLASS_FLASH
+       tristate "LED Flash Class Support"
+       depends on LEDS_CLASS

Looks like it requires V4L2, so probably add depends on V4L2 or similar. But actually I want to see LED Flash class doesn't depends on V4L2. Is that possible to do that?
For example a non-V4L2 application want to control the LED as a flash?

It doesn't require V4L2. It only used v4l2-controls.h for error code macros, but this is also going to be changed.

Quoted 538 lines

Other than this main concern, I'm good with this patch now.

-Bryan

Quoted 519 lines
drivers/leds/Kconfig +7 -0
+       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. 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 +1 -0
index 1c65a19..cbba921 100644
@@ -2,6 +2,7 @@
  # LED Core
  obj-$(CONFIG_NEW_LEDS)                 += led-core.o
  obj-$(CONFIG_LEDS_CLASS)               += led-class.o
+obj-$(CONFIG_LEDS_CLASS_FLASH)         += led-class-flash.o
  obj-$(CONFIG_LEDS_TRIGGERS)            += led-triggers.o
 
  # LED Platform Drivers
drivers/leds/led-class-flash.c new file +446 -0
new file mode 100644
index 0000000..219b414
@@ -0,0 +1,446 @@
+/*
+ * LED Flash class interface
+ *
+ * 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/device.h>
+#include <linux/init.h>
+#include <linux/led-class-flash.h>
+#include <linux/leds.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include "leds.h"
+
+#define has_flash_op(flash, op)                                \
+       (flash && flash->ops->op)
+
+#define call_flash_op(flash, op, args...)              \
+       ((has_flash_op(flash, op)) ?                    \
+                       (flash->ops->op(flash, args)) : \
+                       -EINVAL)
+
+static ssize_t flash_brightness_store(struct device *dev,
+               struct device_attribute *attr, const char *buf, size_t size)
+{
+       struct led_classdev *led_cdev = dev_get_drvdata(dev);
+       struct led_classdev_flash *flash = lcdev_to_flash(led_cdev);
+       unsigned long state;
+       ssize_t ret;
+
+       mutex_lock(&led_cdev->led_access);
+
+       if (led_sysfs_is_disabled(led_cdev)) {
+               ret = -EBUSY;
+               goto unlock;
+       }
+
+       ret = kstrtoul(buf, 10, &state);
+       if (ret)
+               goto unlock;
+
+       ret = led_set_flash_brightness(flash, state);
+       if (ret < 0)
+               goto unlock;
+
+       ret = size;
+unlock:
+       mutex_unlock(&led_cdev->led_access);
+       return ret;
+}
+
+static ssize_t flash_brightness_show(struct device *dev,
+               struct device_attribute *attr, char *buf)
+{
+       struct led_classdev *led_cdev = dev_get_drvdata(dev);
+       struct led_classdev_flash *flash = lcdev_to_flash(led_cdev);
+
+       /* no lock needed for this */
+       led_update_flash_brightness(flash);
+
+       return sprintf(buf, "%u\n", flash->brightness.val);
+}
+static DEVICE_ATTR_RW(flash_brightness);
+
+static ssize_t max_flash_brightness_show(struct device *dev,
+               struct device_attribute *attr, char *buf)
+{
+       struct led_classdev *led_cdev = dev_get_drvdata(dev);
+       struct led_classdev_flash *flash = lcdev_to_flash(led_cdev);
+
+       return sprintf(buf, "%u\n", flash->brightness.max);
+}
+static DEVICE_ATTR_RO(max_flash_brightness);
+
+static ssize_t flash_strobe_store(struct device *dev,
+               struct device_attribute *attr, const char *buf, size_t size)
+{
+       struct led_classdev *led_cdev = dev_get_drvdata(dev);
+       struct led_classdev_flash *flash = lcdev_to_flash(led_cdev);
+       unsigned long state;
+       ssize_t ret = -EINVAL;
+
+       mutex_lock(&led_cdev->led_access);
+
+       if (led_sysfs_is_disabled(led_cdev)) {
+               ret = -EBUSY;
+               goto unlock;
+       }
+
+       ret = kstrtoul(buf, 10, &state);
+       if (ret)
+               goto unlock;
+
+       if (state < 0 || state > 1) {
+               ret = -EINVAL;
+               goto unlock;
+       }
+
+       ret = led_set_flash_strobe(flash, state);
+       if (ret < 0)
+               goto unlock;
+       ret = size;
+unlock:
+       mutex_unlock(&led_cdev->led_access);
+       return ret;
+}
+
+static ssize_t flash_strobe_show(struct device *dev,
+               struct device_attribute *attr, char *buf)
+{
+       struct led_classdev *led_cdev = dev_get_drvdata(dev);
+       struct led_classdev_flash *flash = lcdev_to_flash(led_cdev);
+       bool state;
+       int ret;
+
+       /* no lock needed for this */
+       ret = led_get_flash_strobe(flash, &state);
+       if (ret < 0)
+               return ret;
+
+       return sprintf(buf, "%u\n", state);
+}
+static DEVICE_ATTR_RW(flash_strobe);
+
+static ssize_t flash_timeout_store(struct device *dev,
+               struct device_attribute *attr, const char *buf, size_t size)
+{
+       struct led_classdev *led_cdev = dev_get_drvdata(dev);
+       struct led_classdev_flash *flash = lcdev_to_flash(led_cdev);
+       unsigned long flash_timeout;
+       ssize_t ret;
+
+       mutex_lock(&led_cdev->led_access);
+
+       if (led_sysfs_is_disabled(led_cdev)) {
+               ret = -EBUSY;
+               goto unlock;
+       }
+
+       ret = kstrtoul(buf, 10, &flash_timeout);
+       if (ret)
+               goto unlock;
+
+       ret = led_set_flash_timeout(flash, flash_timeout);
+       if (ret < 0)
+               goto unlock;
+
+       ret = size;
+unlock:
+       mutex_unlock(&led_cdev->led_access);
+       return ret;
+}
+
+static ssize_t flash_timeout_show(struct device *dev,
+               struct device_attribute *attr, char *buf)
+{
+       struct led_classdev *led_cdev = dev_get_drvdata(dev);
+       struct led_classdev_flash *flash = lcdev_to_flash(led_cdev);
+
+       return sprintf(buf, "%u\n", flash->timeout.val);
+}
+static DEVICE_ATTR_RW(flash_timeout);
+
+static ssize_t max_flash_timeout_show(struct device *dev,
+               struct device_attribute *attr, char *buf)
+{
+       struct led_classdev *led_cdev = dev_get_drvdata(dev);
+       struct led_classdev_flash *flash = lcdev_to_flash(led_cdev);
+
+       return sprintf(buf, "%u\n", flash->timeout.max);
+}
+static DEVICE_ATTR_RO(max_flash_timeout);
+
+static ssize_t flash_fault_show(struct device *dev,
+               struct device_attribute *attr, char *buf)
+{
+       struct led_classdev *led_cdev = dev_get_drvdata(dev);
+       struct led_classdev_flash *flash = lcdev_to_flash(led_cdev);
+       u32 fault;
+       int ret;
+
+       ret = led_get_flash_fault(flash, &fault);
+       if (ret < 0)
+               return -EINVAL;
+
+       return sprintf(buf, "0x%8.8x\n", fault);
+}
+static DEVICE_ATTR_RO(flash_fault);
+
+static ssize_t flash_sync_strobe_store(struct device *dev,
+               struct device_attribute *attr, const char *buf, size_t size)
+{
+       struct led_classdev *led_cdev = dev_get_drvdata(dev);
+       struct led_classdev_flash *flash = lcdev_to_flash(led_cdev);
+       unsigned long sync_strobe;
+       ssize_t ret;
+
+       mutex_lock(&led_cdev->led_access);
+
+       if (led_sysfs_is_disabled(led_cdev)) {
+               ret = -EBUSY;
+               goto unlock;
+       }
+
+       ret = kstrtoul(buf, 10, &sync_strobe);
+       if (ret)
+               goto unlock;
+
+       flash->sync_strobe = sync_strobe;
+
+       ret = size;
+unlock:
+       mutex_unlock(&led_cdev->led_access);
+       return ret;
+}
+
+static ssize_t flash_sync_strobe_show(struct device *dev,
+               struct device_attribute *attr, char *buf)
+{
+       struct led_classdev *led_cdev = dev_get_drvdata(dev);
+       struct led_classdev_flash *flash = lcdev_to_flash(led_cdev);
+
+       return sprintf(buf, "%u\n", flash->sync_strobe);
+}
+static DEVICE_ATTR_RW(flash_sync_strobe);
+
+static struct attribute *led_flash_strobe_attrs[] = {
+       &dev_attr_flash_strobe.attr,
+       NULL,
+};
+
+static struct attribute *led_flash_timeout_attrs[] = {
+       &dev_attr_flash_timeout.attr,
+       &dev_attr_max_flash_timeout.attr,
+       NULL,
+};
+
+static struct attribute *led_flash_brightness_attrs[] = {
+       &dev_attr_flash_brightness.attr,
+       &dev_attr_max_flash_brightness.attr,
+       NULL,
+};
+
+static struct attribute *led_flash_fault_attrs[] = {
+       &dev_attr_flash_fault.attr,
+       NULL,
+};
+
+static struct attribute *led_flash_sync_strobe_attrs[] = {
+       &dev_attr_flash_sync_strobe.attr,
+       NULL,
+};
+
+static const struct attribute_group led_flash_strobe_group = {
+       .attrs = led_flash_strobe_attrs,
+};
+
+static const struct attribute_group led_flash_timeout_group = {
+       .attrs = led_flash_timeout_attrs,
+};
+
+static const struct attribute_group led_flash_brightness_group = {
+       .attrs = led_flash_brightness_attrs,
+};
+
+static const struct attribute_group led_flash_fault_group = {
+       .attrs = led_flash_fault_attrs,
+};
+
+static const struct attribute_group led_flash_sync_strobe_group = {
+       .attrs = led_flash_sync_strobe_attrs,
+};
+
+static const struct attribute_group *flash_groups[] = {
+       &led_flash_strobe_group,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL
+};
+
+static void led_flash_resume(struct led_classdev *led_cdev)
+{
+       struct led_classdev_flash *flash = lcdev_to_flash(led_cdev);
+
+       call_flash_op(flash, flash_brightness_set, flash->brightness.val);
+       call_flash_op(flash, timeout_set, flash->timeout.val);
+}
+
+static void led_flash_init_sysfs_groups(struct led_classdev_flash *flash)
+{
+       struct led_classdev *led_cdev = &flash->led_cdev;
+       const struct led_flash_ops *ops = flash->ops;
+       int num_sysfs_groups = 1;
+
+       if (ops->flash_brightness_set)
+               flash_groups[num_sysfs_groups++] = &led_flash_brightness_group;
+
+       if (ops->timeout_set)
+               flash_groups[num_sysfs_groups++] = &led_flash_timeout_group;
+
+       if (ops->fault_get)
+               flash_groups[num_sysfs_groups++] = &led_flash_fault_group;
+
+       if (led_cdev->flags & LED_DEV_CAP_COMPOUND)
+               flash_groups[num_sysfs_groups++] = &led_flash_sync_strobe_group;
+
+       led_cdev->groups = flash_groups;
+}
+
+int led_classdev_flash_register(struct device *parent,
+                               struct led_classdev_flash *flash)
+{
+       struct led_classdev *led_cdev;
+       const struct led_flash_ops *ops;
+       int ret;
+
+       if (!flash)
+               return -EINVAL;
+
+       led_cdev = &flash->led_cdev;
+
+       if (led_cdev->flags & LED_DEV_CAP_FLASH) {
+               if (!led_cdev->brightness_set_sync)
+                       return -EINVAL;
+
+               ops = flash->ops;
+               if (!ops || !ops->strobe_set)
+                       return -EINVAL;
+
+               led_cdev->flash_resume = led_flash_resume;
+
+               /* Select the sysfs attributes to be created for the device */
+               led_flash_init_sysfs_groups(flash);
+       }
+
+       /* Register led class device */
+       ret = led_classdev_register(parent, led_cdev);
+       if (ret < 0)
+               return ret;
+
+       /* Setting a torch brightness needs to have immediate effect */
+       led_cdev->flags &= ~SET_BRIGHTNESS_ASYNC;
+       led_cdev->flags |= SET_BRIGHTNESS_SYNC;
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(led_classdev_flash_register);
+
+void led_classdev_flash_unregister(struct led_classdev_flash *flash)
+{
+       if (!flash)
+               return;
+
+       led_classdev_unregister(&flash->led_cdev);
+}
+EXPORT_SYMBOL_GPL(led_classdev_flash_unregister);
+
+int led_set_flash_strobe(struct led_classdev_flash *flash, bool state)
+{
+       return call_flash_op(flash, strobe_set, state);
+}
+EXPORT_SYMBOL_GPL(led_set_flash_strobe);
+
+int led_get_flash_strobe(struct led_classdev_flash *flash, bool *state)
+{
+       return call_flash_op(flash, strobe_get, state);
+}
+EXPORT_SYMBOL_GPL(led_get_flash_strobe);
+
+static void led_clamp_align(struct led_flash_setting *s)
+{
+       u32 v, offset;
+
+       v = s->val + s->step / 2;
+       v = clamp(v, s->min, s->max);
+       offset = v - s->min;
+       offset = s->step * (offset / s->step);
+       s->val = s->min + offset;
+}
+
+int led_set_flash_timeout(struct led_classdev_flash *flash, u32 timeout)
+{
+       struct led_classdev *led_cdev = &flash->led_cdev;
+       struct led_flash_setting *s = &flash->timeout;
+
+       s->val = timeout;
+       led_clamp_align(s);
+
+       if (!(led_cdev->flags & LED_SUSPENDED))
+               return call_flash_op(flash, timeout_set, s->val);
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(led_set_flash_timeout);
+
+int led_get_flash_fault(struct led_classdev_flash *flash, u32 *fault)
+{
+       return call_flash_op(flash, fault_get, fault);
+}
+EXPORT_SYMBOL_GPL(led_get_flash_fault);
+
+int led_set_flash_brightness(struct led_classdev_flash *flash,
+                               u32 brightness)
+{
+       struct led_classdev *led_cdev = &flash->led_cdev;
+       struct led_flash_setting *s = &flash->brightness;
+
+       s->val = brightness;
+       led_clamp_align(s);
+
+       if (!(led_cdev->flags & LED_SUSPENDED))
+               return call_flash_op(flash, flash_brightness_set, s->val);
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(led_set_flash_brightness);
+
+int led_update_flash_brightness(struct led_classdev_flash *flash)
+{
+       struct led_flash_setting *s = &flash->brightness;
+       u32 brightness;
+
+       if (has_flash_op(flash, flash_brightness_get)) {
+               int ret = call_flash_op(flash, flash_brightness_get,
+                                               &brightness);
+               if (ret < 0)
+                       return ret;
+
+               s->val = brightness;
+       }
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(led_update_flash_brightness);
+
+MODULE_AUTHOR("Jacek Anaszewski <[email protected]>");
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("LED Flash class Interface");
drivers/leds/led-class.c +4 -0
index dbeebac..02564c5 100644
@@ -179,6 +179,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);
include/linux/led-class-flash.h new file +24 -0
new file mode 100644
index 0000000..5188d9fd
@@ -0,0 +1,198 @@
+/*
+ * LED Flash class interface
+ *
+ * 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 __LINUX_FLASH_LEDS_H_INCLUDED
+#define __LINUX_FLASH_LEDS_H_INCLUDED
+
+#include <linux/leds.h>
+#include <uapi/linux/v4l2-controls.h>
+
+struct device_node;
+struct led_classdev_flash;
+
+/*
+ * Supported led fault bits - must be kept in synch
+ * with V4L2_FLASH_FAULT bits.
+ */

include/linux/led-class-flash.h line 34

Quoted 10 lines
include/linux/led-class-flash.h new file +10 -0
+#define LED_FAULT_OVER_VOLTAGE          V4L2_FLASH_FAULT_OVER_VOLTAGE
+#define LED_FAULT_TIMEOUT               V4L2_FLASH_FAULT_TIMEOUT
+#define LED_FAULT_OVER_TEMPERATURE      V4L2_FLASH_FAULT_OVER_TEMPERATURE
+#define LED_FAULT_SHORT_CIRCUIT                 V4L2_FLASH_FAULT_SHORT_CIRCUIT
+#define LED_FAULT_OVER_CURRENT          V4L2_FLASH_FAULT_OVER_CURRENT
+#define LED_FAULT_INDICATOR             V4L2_FLASH_FAULT_INDICATOR
+#define LED_FAULT_UNDER_VOLTAGE                 V4L2_FLASH_FAULT_UNDER_VOLTAGE
+#define LED_FAULT_INPUT_VOLTAGE                 V4L2_FLASH_FAULT_INPUT_VOLTAGE
+#define LED_FAULT_LED_OVER_TEMPERATURE  V4L2_FLASH_OVER_TEMPERATURE
+

I suggest we move those V4L2_FLASH_FAULT_* to our LED subsystem as LED_FAULT_*. Then V4L2 Flash control code should include that LED header file and #define V4L2_FLASH_FAULT_* LED_FAULT_*

Quoted 3 lines

Because this flash fault feature is for LED actually not for V4L2.

Then we can decouple V4L2 and LED Flash class driver here.

I'm OK with it. Sakari, what do you think about spinning it the other way round - V4L2 will use LED Flash class fault definitions?

Quoted 168 lines
Quoted 168 lines
include/linux/led-class-flash.h new file +164 -0
+struct led_flash_ops {
+       /* set flash brightness */
+       int (*flash_brightness_set)(struct led_classdev_flash *flash,
+                                       u32 brightness);
+       /* get flash brightness */
+       int (*flash_brightness_get)(struct led_classdev_flash *flash,
+                                       u32 *brightness);
+       /* set flash strobe state */
+       int (*strobe_set)(struct led_classdev_flash *flash, bool state);
+       /* get flash strobe state */
+       int (*strobe_get)(struct led_classdev_flash *flash, bool *state);
+       /* set flash timeout */
+       int (*timeout_set)(struct led_classdev_flash *flash, u32 timeout);
+       /* get the flash LED fault */
+       int (*fault_get)(struct led_classdev_flash *flash, u32 *fault);
+};
+
+/*
+ * Current value of a flash setting along
+ * with its constraints.
+ */
+struct led_flash_setting {
+       /* maximum allowed value */
+       u32 min;
+       /* maximum allowed value */
+       u32 max;
+       /* step value */
+       u32 step;
+       /* current value */
+       u32 val;
+};
+
+/*
+ * Aggregated flash settings - designed for ease
+ * of passing initialization data to the clients
+ * wrapping a LED Flash class device.
+ */
+struct led_flash_config {
+       struct led_flash_setting torch_brightness;
+       struct led_flash_setting flash_brightness;
+       struct led_flash_setting flash_timeout;
+       u32 flash_faults;
+};
+
+struct led_classdev_flash {
+       /* led class device */
+       struct led_classdev led_cdev;
+
+       /* flash led specific ops */
+       const struct led_flash_ops *ops;
+
+       /* flash brightness value in microamperes along with its constraints */
+       struct led_flash_setting brightness;
+
+       /* flash timeout value in microseconds along with its constraints */
+       struct led_flash_setting timeout;
+
+       /*
+        * Indicates whether the flash sub-led should strobe
+        * upon strobe activation on any of the remaining sub-leds.
+        */
+       bool sync_strobe:1;
+};
+
+static inline struct led_classdev_flash *lcdev_to_flash(
+                                               struct led_classdev *lcdev)
+{
+       return container_of(lcdev, struct led_classdev_flash, led_cdev);
+}
+
+/**
+ * led_classdev_flash_register - register a new object of led_classdev class
+ *                              with support for flash LEDs
+ * @parent: the flash LED to register
+ * @flash: the led_classdev_flash structure for this device
+ *
+ * Returns: 0 on success or negative error value on failure
+ */
+int led_classdev_flash_register(struct device *parent,
+                               struct led_classdev_flash *flash);
+
+/**
+ * led_classdev_flash_unregister - unregisters an object of led_classdev class
+ *                                with support for flash LEDs
+ * @flash: the flash LED to unregister
+ *
+ * Unregister a previously registered via led_classdev_flash_register object
+ */
+void led_classdev_flash_unregister(struct led_classdev_flash *flash);
+
+/**
+ * led_set_flash_strobe - setup flash strobe
+ * @flash: the flash LED to set strobe on
+ * @state: 1 - strobe flash, 0 - stop flash strobe
+ *
+ * Strobe the flash LED.
+ *
+ * Returns: 0 on success or negative error value on failure
+ */
+extern int led_set_flash_strobe(struct led_classdev_flash *flash,
+                               bool state);
+
+/**
+ * led_get_flash_strobe - get flash strobe status
+ * @flash: the flash LED to query
+ * @state: 1 - flash is strobing, 0 - flash is off
+ *
+ * Check whether the flash is strobing at the moment.
+ *
+ * Returns: 0 on success or negative error value on failure
+ */
+extern int led_get_flash_strobe(struct led_classdev_flash *flash,
+                               bool *state);
+
+/**
+ * led_set_flash_brightness - set flash LED brightness
+ * @flash: the flash LED to set
+ * @brightness: the brightness to set it to
+ *
+ * Set a flash LED's brightness.
+ *
+ * Returns: 0 on success or negative error value on failure
+ */
+extern int led_set_flash_brightness(struct led_classdev_flash *flash,
+                                       u32 brightness);
+
+/**
+ * led_update_flash_brightness - update flash LED brightness
+ * @flash: the flash LED to query
+ *
+ * Get a flash LED's current brightness and update led_flash->brightness
+ * member with the obtained value.
+ *
+ * Returns: 0 on success or negative error value on failure
+ */
+extern int led_update_flash_brightness(struct led_classdev_flash *flash);
+
+/**
+ * led_set_flash_timeout - set flash LED timeout
+ * @flash: the flash LED to set
+ * @timeout: the flash timeout to set it to
+ *
+ * Set the flash strobe duration. The duration set by the driver
+ * is returned in the timeout argument and may differ from the
+ * one that was originally passed.
+ *
+ * Returns: 0 on success or negative error value on failure
+ */
+extern int led_set_flash_timeout(struct led_classdev_flash *flash,
+                                       u32 timeout);
+
+/**
+ * led_get_flash_fault - get the flash LED fault
+ * @flash: the flash LED to query
+ * @fault: bitmask containing flash faults
+ *
+ * Get the flash LED fault.
+ *
+ * Returns: 0 on success or negative error value on failure
+ */
+extern int led_get_flash_fault(struct led_classdev_flash *flash,
+                                       u32 *fault);
+
+#endif /* __LINUX_FLASH_LEDS_H_INCLUDED */
include/linux/leds.h +0 -0
index cfceef3..c359f35 100644
Quoted 8 lines

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

Quoted 7 lines
include/linux/leds.h +2 -0
@@ -46,6 +46,8 @@ struct led_classdev {
  #define LED_SYSFS_DISABLE      (1 << 20)
  #define SET_BRIGHTNESS_ASYNC   (1 << 21)
  #define SET_BRIGHTNESS_SYNC    (1 << 22)
+#define LED_DEV_CAP_FLASH      (1 << 23)
+#define LED_DEV_CAP_COMPOUND   (1 << 24)
 

What's the use case of CAP_COMPOUND?

It signifies that the device controls many sub-leds and the sub-leds will expose flash_strobe_sync sysfs attribute for strobing the flash synchronously with the other sub-leds. Please see the driver for MAX77693.

Quoted 8 lines
Quoted 8 lines
include/linux/leds.h +1 -0
         /* Set LED brightness level */
         /* Must not sleep, use a workqueue if needed */
@@ -81,6 +83,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);
 
Quoted 6 lines
Quoted 5 lines
include/linux/leds.h +0 -1
         struct work_struct      set_brightness_work;
         int                     delayed_set_value;
--

1.7.9.5

Best Regards,
Jacek Anaszewski

#4 lore raw

PATCH v8 2/14 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.

---
 Documentation/leds/leds-class-flash.txt |   48 +++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)
 create mode 100644 Documentation/leds/leds-class-flash.txt
Documentation/leds/leds-class-flash.txt new file +48 -0
new file mode 100644
index 0000000..d68565c
@@ -0,0 +1,48 @@
+
+Flash LED handling under Linux
+==============================
+
+Some LED devices support two modes - torch and flash. The modes are
+supported by the LED class (see Documentation/leds/leds-class.txt)
+and LED Flash class respectively.
+
+In order to enable support for flash LEDs 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)
+	- flash_sync_strobe - one flash device can control more than one
+			      sub-led; when this atrribute is set to 1
+			      the flash led will be strobed synchronously
+			      with the other ones controlled by the same
+			      device (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
Signature · 1 line
1.7.9.5
#5 lore raw

Re: [PATCH/RFC v8 02/14] Documentation: leds: Add description of LED Flash class extension

Hi!

Quoted 17 lines
Documentation/leds/leds-class-flash.txt new file +17 -0
+Flash LED handling under Linux
+==============================
+
+Some LED devices support two modes - torch and flash. The modes are
+supported by the LED class (see Documentation/leds/leds-class.txt)
+and LED Flash class respectively.
+
+In order to enable support for flash LEDs 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)

Documentation/leds/leds-class-flash.txt line 28

Quoted 10 lines
Documentation/leds/leds-class-flash.txt new file +10 -0
+	- 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)
+	- flash_sync_strobe - one flash device can control more than one
+			      sub-led; when this atrribute is set to 1
+			      the flash led will be strobed synchronously
+			      with the other ones controlled by the same
+			      device (RW)

This is not really clear. Does flash_timeout or flash_brightness need to be set, first?

Do we really want to have separate indicator brightnesses in uA? Should we maybe reuse existing "brightness" parameter for torch and indication, maybe adding single (RO) indicator_brightness attribute?

Quoted 10 lines
Documentation/leds/leds-class-flash.txt new file +10 -0
+	- 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

Documentation/leds/leds-class-flash.txt line 48

Quoted 10 lines
Documentation/leds/leds-class-flash.txt new file +10 -0
+		* 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

How are faults cleared? Should it be list of strings, instead of bitmask? We may want to add new fault modes in future...

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#6 lore raw

Re: [PATCH/RFC v8 02/14] Documentation: leds: Add description of LED Flash class extension

Hi Pavel,

Thanks for a review.

Quoted 24 lines · Pavel Machek

Hi!

Quoted 22 lines
Documentation/leds/leds-class-flash.txt new file +22 -0
+Flash LED handling under Linux
+==============================
+
+Some LED devices support two modes - torch and flash. The modes are
+supported by the LED class (see Documentation/leds/leds-class.txt)
+and LED Flash class respectively.
+
+In order to enable support for flash LEDs 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)
Quoted 8 lines

Documentation/leds/leds-class-flash.txt line 28

Quoted 5 lines
Documentation/leds/leds-class-flash.txt new file +5 -0
+	- flash_sync_strobe - one flash device can control more than one
+			      sub-led; when this atrribute is set to 1
+			      the flash led will be strobed synchronously
+			      with the other ones controlled by the same
+			      device (RW)

This is not really clear. Does flash_timeout or flash_brightness need to be set, first?

I would go for inheriting the settings from the led that is strobed explicitly. Limits regarding current, the ones from device tree node, would have to however be preserved in my opinion.
A consensus is needed here.

Quoted 3 lines

Do we really want to have separate indicator brightnesses in uA? Should we maybe reuse existing "brightness" parameter for torch and indication, maybe adding single (RO) indicator_brightness attribute?

I forgot to remove the indicator related positions. It has been definitely removed from the LED subsystem related patches.

Quoted 15 lines
Quoted 15 lines
Documentation/leds/leds-class-flash.txt new file +15 -0
+	- 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
Quoted 8 lines

Documentation/leds/leds-class-flash.txt line 48

Quoted 5 lines
Documentation/leds/leds-class-flash.txt new file +5 -0
+			 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

How are faults cleared? Should it be list of strings, instead of bitmask? We may want to add new fault modes in future...

Faults are cleared by reading the attribute. I will add this note. There can be more than one fault at a time. I think that the bitmask is a flexible solution. I don't see any troubles related to adding new fault modes in the future, do you?

Best Regards,
Jacek Anaszewski

#7 lore raw

Re: [PATCH/RFC v8 02/14] Documentation: leds: Add description of LED Flash class extension

Hi!

Quoted 7 lines
Quoted 2 lines

How are faults cleared? Should it be list of strings, instead of bitmask? We may want to add new fault modes in future...

Faults are cleared by reading the attribute. I will add this note. There can be more than one fault at a time. I think that the bitmask is a flexible solution. I don't see any troubles related to adding new fault modes in the future, do you?

I do not think that "read attribute to clear" is good idea. Normally, you'd want the error attribute world-readable, but you don't want non-root users to clear the errors.

I am not sure if bitmask is good solution. I'd return space-separated strings like "overtemp". That way, there's good chance that other LED drivers would be able to use similar interface...

Best regards,
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#8 lore raw

Re: [PATCH/RFC v8 02/14] Documentation: leds: Add description of LED Flash class extension

Hi Pavel,

Quoted 5 lines · Pavel Machek

Hi!

Quoted 3 lines
Quoted 2 lines

How are faults cleared? Should it be list of strings, instead of bitmask? We may want to add new fault modes in future...

Quoted 8 lines
Quoted 4 lines

Faults are cleared by reading the attribute. I will add this note. There can be more than one fault at a time. I think that the bitmask is a flexible solution. I don't see any troubles related to adding new fault modes in the future, do you?

I do not think that "read attribute to clear" is good idea. Normally, you'd want the error attribute world-readable, but you don't want non-root users to clear the errors.

This is also V4L2_CID_FLASH_FAULT control semantics. Moreover many devices clear the errors upon reading register. I don't see anything wrong in the fact that an user can clear an error. If the user has a permission to use a device then it also should be allowed to clear the errors.

Quoted 3 lines

I am not sure if bitmask is good solution. I'd return space-separated strings like "overtemp". That way, there's good chance that other LED drivers would be able to use similar interface...

The format of a sysfs attribute should be concise. The error codes are generic and map directly to the V4L2 Flash error codes.

Best Regards,
Jacek Anaszewski

#9 lore raw

Re: [PATCH/RFC v8 02/14] Documentation: leds: Add description of LED Flash class extension

Hi Jacek and Pavel,

Quoted 17 lines · Jacek Anaszewski

Hi Pavel,

Quoted 5 lines · Pavel Machek

Hi!

Quoted 3 lines
Quoted 2 lines

How are faults cleared? Should it be list of strings, instead of bitmask? We may want to add new fault modes in future...

Quoted 8 lines
Quoted 4 lines

Faults are cleared by reading the attribute. I will add this note. There can be more than one fault at a time. I think that the bitmask is a flexible solution. I don't see any troubles related to adding new fault modes in the future, do you?

I do not think that "read attribute to clear" is good idea. Normally, you'd want the error attribute world-readable, but you don't want non-root users to clear the errors.

Quoted 5 lines

This is also V4L2_CID_FLASH_FAULT control semantics. Moreover many devices clear the errors upon reading register. I don't see anything wrong in the fact that an user can clear an error. If the user has a permission to use a device then it also should be allowed to clear the errors.

I agree. Some of these such as the timeout are not hardware related problems at all, but others may be. I'd keep the same semantics as V4L2 already does.

Quoted 7 lines
Quoted 3 lines

I am not sure if bitmask is good solution. I'd return space-separated strings like "overtemp". That way, there's good chance that other LED drivers would be able to use similar interface...

The format of a sysfs attribute should be concise. The error codes are generic and map directly to the V4L2 Flash error codes.

I'd guess a single application accesses either of the interfaces. From that point of view it doesn't matter what are the bit definitions in V4L2.

The behaviour on sysfs could also be different, e.g. writing the attribute would clear the faults. This would need more functionality from drivers. The V4L2 behaviour mirrors the typical behaviour of flash controllers --- the chips mostly do not operate until the faults have been read, and the interface as well as the interface take no stance to that. So when the user reads the fault control value, the fault register on the chip is cleared as well.

Signature · 4 lines
Kind regards,

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

Re: [PATCH/RFC v8 02/14] Documentation: leds: Add description of LED Flash class extension

In reply to Jacek Anaszewski
Quoted 27 lines · Jacek Anaszewski

Hi Pavel,

Quoted 13 lines · Pavel Machek

Hi!

Quoted 8 lines
Quoted 2 lines

How are faults cleared? Should it be list of strings, instead of bitmask? We may want to add new fault modes in future...

Faults are cleared by reading the attribute. I will add this note. There can be more than one fault at a time. I think that the bitmask is a flexible solution. I don't see any troubles related to adding new fault modes in the future, do you?

Quoted 3 lines

I do not think that "read attribute to clear" is good idea. Normally, you'd want the error attribute world-readable, but you don't want non-root users to clear the errors.

This is also V4L2_CID_FLASH_FAULT control semantics. Moreover many devices clear the errors upon reading register. I don't see anything wrong in the fact that an user can clear an error. If the user has a permission to use a device then it also should be allowed to clear the errors.

Quoted 9 lines
Quoted 3 lines

I am not sure if bitmask is good solution. I'd return space-separated strings like "overtemp". That way, there's good chance that other LED drivers would be able to use similar interface...

The format of a sysfs attribute should be concise. The error codes are generic and map directly to the V4L2 Flash error codes.

Actually I'd like to see those flash fault code defined in LED subsystem. And V4L2 will just include LED flash header file to use it. Because flash fault code is not for V4L2 specific but it's a feature of LED flash devices.

For clearing error code of flash devices, I think it depends on the hardware. If most of our LED flash is using reading to clear error code, we probably can make it simple as this now. But what if some other LED flash devices are using writing to clear error code? we should provide a API to that?

-Bryan

#11 lore raw

Re: [PATCH/RFC v8 02/14] Documentation: leds: Add description of LED Flash class extension

Quoted 11 lines
Quoted 5 lines

The format of a sysfs attribute should be concise. The error codes are generic and map directly to the V4L2 Flash error codes.

Actually I'd like to see those flash fault code defined in LED subsystem. And V4L2 will just include LED flash header file to use it. Because flash fault code is not for V4L2 specific but it's a feature of LED flash devices.

Quoted 5 lines

For clearing error code of flash devices, I think it depends on the hardware. If most of our LED flash is using reading to clear error code, we probably can make it simple as this now. But what if some other LED flash devices are using writing to clear error code? we should provide a API to that?

Actually, we should provide API that makes sense, and that is easy to use by userspace.

I believe "read" is called read because it does not change anything, and it should stay that way in /sysfs. You may want to talk to sysfs maintainers if you plan on doing another semantics.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#12 lore raw

Re: [PATCH/RFC v8 02/14] Documentation: leds: Add description of LED Flash class extension

Quoted 17 lines · Pavel Machek
Quoted 11 lines
Quoted 5 lines

The format of a sysfs attribute should be concise. The error codes are generic and map directly to the V4L2 Flash error codes.

Actually I'd like to see those flash fault code defined in LED subsystem. And V4L2 will just include LED flash header file to use it. Because flash fault code is not for V4L2 specific but it's a feature of LED flash devices.

Quoted 5 lines

For clearing error code of flash devices, I think it depends on the hardware. If most of our LED flash is using reading to clear error code, we probably can make it simple as this now. But what if some other LED flash devices are using writing to clear error code? we should provide a API to that?

Quoted 6 lines

Actually, we should provide API that makes sense, and that is easy to use by userspace.

I believe "read" is called read because it does not change anything, and it should stay that way in /sysfs. You may want to talk to sysfs maintainers if you plan on doing another semantics.

How would you proceed in case of devices which clear their fault register upon I2C readout (e.g. AS3645)? In this case read does have a side effect. For such devices attribute semantics would have to be different than for the devices which don't clear faults on readout.

In case of devices which use writing to clear error code - I'd do that after reading flash_fault attribute, in the same callback.

Best Regards,
Jacek Anaszewski

#13 lore raw

Re: [PATCH/RFC v8 02/14] Documentation: leds: Add description of LED Flash class extension

Quoted 21 lines · Jacek Anaszewski
Quoted 20 lines · Pavel Machek
Quoted 11 lines
Quoted 5 lines

The format of a sysfs attribute should be concise. The error codes are generic and map directly to the V4L2 Flash error codes.

Actually I'd like to see those flash fault code defined in LED subsystem. And V4L2 will just include LED flash header file to use it. Because flash fault code is not for V4L2 specific but it's a feature of LED flash devices.

Quoted 5 lines

For clearing error code of flash devices, I think it depends on the hardware. If most of our LED flash is using reading to clear error code, we probably can make it simple as this now. But what if some other LED flash devices are using writing to clear error code? we should provide a API to that?

Actually, we should provide API that makes sense, and that is easy to use by userspace.

Quoted 8 lines
Quoted 3 lines

I believe "read" is called read because it does not change anything, and it should stay that way in /sysfs. You may want to talk to sysfs maintainers if you plan on doing another semantics.

How would you proceed in case of devices which clear their fault register upon I2C readout (e.g. AS3645)? In this case read does have a side effect. For such devices attribute semantics would have to be different than for the devices which don't clear faults on readout.

No, semantics should be same for all devices.

If device clears fault register during I2C readout, kernel will simply gather faults in an variable, and clear them upon write to sysfs file.

Best regards,
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#14 lore raw

Re: [PATCH/RFC v8 02/14] Documentation: leds: Add description of LED Flash class extension

Hi Pavel,

Quoted 31 lines · Pavel Machek
Quoted 21 lines · Jacek Anaszewski
Quoted 20 lines · Pavel Machek
Quoted 11 lines
Quoted 5 lines

The format of a sysfs attribute should be concise. The error codes are generic and map directly to the V4L2 Flash error codes.

Actually I'd like to see those flash fault code defined in LED subsystem. And V4L2 will just include LED flash header file to use it. Because flash fault code is not for V4L2 specific but it's a feature of LED flash devices.

Quoted 5 lines

For clearing error code of flash devices, I think it depends on the hardware. If most of our LED flash is using reading to clear error code, we probably can make it simple as this now. But what if some other LED flash devices are using writing to clear error code? we should provide a API to that?

Actually, we should provide API that makes sense, and that is easy to use by userspace.

Quoted 8 lines
Quoted 3 lines

I believe "read" is called read because it does not change anything, and it should stay that way in /sysfs. You may want to talk to sysfs maintainers if you plan on doing another semantics.

How would you proceed in case of devices which clear their fault register upon I2C readout (e.g. AS3645)? In this case read does have a side effect. For such devices attribute semantics would have to be different than for the devices which don't clear faults on readout.

Quoted 4 lines

No, semantics should be same for all devices.

If device clears fault register during I2C readout, kernel will simply gather faults in an variable, and clear them upon write to sysfs file.

This approach would require implementing additional mechanisms on both sides: LED Flash class core and a LED Flash class driver. In the former the sysfs attribute write permissions would have to be decided in the runtime and in the latter caching mechanism would have to be implemented per driver. We would have to also consider how to approach the issue in case of sub-leds.

The only reason for this overhead is trying to avoid side effects on reading sysfs attribute. After weighing the pros and cons, I am not sure if it is worthwhile.

Best Regards,
Jacek Anaszewski

#15 lore raw

Re: [PATCH/RFC v8 02/14] Documentation: leds: Add description of LED Flash class extension

Quoted 36 lines · Jacek Anaszewski

Hi Pavel,

Quoted 33 lines · Pavel Machek
Quoted 21 lines · Jacek Anaszewski
Quoted 20 lines · Pavel Machek
Quoted 11 lines
Quoted 5 lines

The format of a sysfs attribute should be concise. The error codes are generic and map directly to the V4L2 Flash error codes.

Actually I'd like to see those flash fault code defined in LED subsystem. And V4L2 will just include LED flash header file to use it. Because flash fault code is not for V4L2 specific but it's a feature of LED flash devices.

Quoted 5 lines

For clearing error code of flash devices, I think it depends on the hardware. If most of our LED flash is using reading to clear error code, we probably can make it simple as this now. But what if some other LED flash devices are using writing to clear error code? we should provide a API to that?

Actually, we should provide API that makes sense, and that is easy to use by userspace.

Quoted 8 lines
Quoted 3 lines

I believe "read" is called read because it does not change anything, and it should stay that way in /sysfs. You may want to talk to sysfs maintainers if you plan on doing another semantics.

How would you proceed in case of devices which clear their fault register upon I2C readout (e.g. AS3645)? In this case read does have a side effect. For such devices attribute semantics would have to be different than for the devices which don't clear faults on readout.

No, semantics should be same for all devices.

Quoted 7 lines
Quoted 2 lines

If device clears fault register during I2C readout, kernel will simply gather faults in an variable, and clear them upon write to sysfs file.

This approach would require implementing additional mechanisms on both sides: LED Flash class core and a LED Flash class driver. In the former the sysfs attribute write permissions would have to be decided in the runtime and in the latter caching mechanism

Write attributes at runtime? Why? We can emulate sane and consistent behaviour for all the controllers: read gives you list of faults, write clears it. We can do it for all the controllers.

Only cost is few lines of code in the drivers where hardware clears faults at read.

Quoted 2 lines

would have to be implemented per driver. We would have to also consider how to approach the issue in case of sub-leds.

Actually.. sub-leds. That is one physical LED being connected to two current sources at the same time, right?

Quoted 3 lines

The only reason for this overhead is trying to avoid side effects on reading sysfs attribute. After weighing the pros and cons, I am not sure if it is worthwhile.

I am pretty sure.

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#16 lore raw

Re: [PATCH/RFC v8 02/14] Documentation: leds: Add description of LED Flash class extension

Quoted 40 lines · Pavel Machek
Quoted 39 lines · Jacek Anaszewski

Hi Pavel,

Quoted 35 lines · Pavel Machek
Quoted 21 lines · Jacek Anaszewski
Quoted 20 lines · Pavel Machek
Quoted 11 lines
Quoted 5 lines

The format of a sysfs attribute should be concise. The error codes are generic and map directly to the V4L2 Flash error codes.

Actually I'd like to see those flash fault code defined in LED subsystem. And V4L2 will just include LED flash header file to use it. Because flash fault code is not for V4L2 specific but it's a feature of LED flash devices.

Quoted 5 lines

For clearing error code of flash devices, I think it depends on the hardware. If most of our LED flash is using reading to clear error code, we probably can make it simple as this now. But what if some other LED flash devices are using writing to clear error code? we should provide a API to that?

Actually, we should provide API that makes sense, and that is easy to use by userspace.

Quoted 8 lines
Quoted 3 lines

I believe "read" is called read because it does not change anything, and it should stay that way in /sysfs. You may want to talk to sysfs maintainers if you plan on doing another semantics.

How would you proceed in case of devices which clear their fault register upon I2C readout (e.g. AS3645)? In this case read does have a side effect. For such devices attribute semantics would have to be different than for the devices which don't clear faults on readout.

No, semantics should be same for all devices.

If device clears fault register during I2C readout, kernel will simply gather faults in an variable, and clear them upon write to sysfs file.

Quoted 8 lines
Quoted 4 lines

This approach would require implementing additional mechanisms on both sides: LED Flash class core and a LED Flash class driver. In the former the sysfs attribute write permissions would have to be decided in the runtime and in the latter caching mechanism

Write attributes at runtime? Why? We can emulate sane and consistent behaviour for all the controllers: read gives you list of faults, write clears it. We can do it for all the controllers.

I don't like the idea of listing the faults in the form of strings. I'd like to see the third opinion :)

Quoted 2 lines

Only cost is few lines of code in the drivers where hardware clears faults at read.

As above - the third opinion would be appreciated.

Quoted 5 lines
Quoted 2 lines

would have to be implemented per driver. We would have to also consider how to approach the issue in case of sub-leds.

Actually.. sub-leds. That is one physical LED being connected to two current sources at the same time, right?

There are possible designs with two separate LEDs.

Signature · 2 lines
Best Regards,
Jacek Anaszewski
#17 lore raw

Re: [PATCH/RFC v8 02/14] Documentation: leds: Add description of LED Flash class extension

Hi!

Quoted 10 lines
Quoted 7 lines
Quoted 3 lines

both sides: LED Flash class core and a LED Flash class driver. In the former the sysfs attribute write permissions would have to be decided in the runtime and in the latter caching mechanism

Write attributes at runtime? Why? We can emulate sane and consistent behaviour for all the controllers: read gives you list of faults, write clears it. We can do it for all the controllers.

I don't like the idea of listing the faults in the form of strings. I'd like to see the third opinion :)

Well, I see that you don't like to change existing code. But "I hacked it this way and I'm going to ask n-th opinion so that I don't have to touch it" is not a way to design interfaces.

Quoted 4 lines
Quoted 2 lines

Only cost is few lines of code in the drivers where hardware clears faults at read.

As above - the third opinion would be appreciated.

Just email Greg if he likes /sys files with sideffects on read.

Or just think. You never do grep in /sys?

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#18 lore raw

Re: [PATCH/RFC v8 02/14] Documentation: leds: Add description of LED Flash class extension

In reply to Pavel Machek

Hi Pavel and Jacek,

Quoted 45 lines · Pavel Machek
Quoted 36 lines · Jacek Anaszewski

Hi Pavel,

Quoted 33 lines · Pavel Machek
Quoted 21 lines · Jacek Anaszewski
Quoted 20 lines · Pavel Machek
Quoted 11 lines
Quoted 5 lines

The format of a sysfs attribute should be concise. The error codes are generic and map directly to the V4L2 Flash error codes.

Actually I'd like to see those flash fault code defined in LED subsystem. And V4L2 will just include LED flash header file to use it. Because flash fault code is not for V4L2 specific but it's a feature of LED flash devices.

Quoted 5 lines

For clearing error code of flash devices, I think it depends on the hardware. If most of our LED flash is using reading to clear error code, we probably can make it simple as this now. But what if some other LED flash devices are using writing to clear error code? we should provide a API to that?

Actually, we should provide API that makes sense, and that is easy to use by userspace.

Quoted 8 lines
Quoted 3 lines

I believe "read" is called read because it does not change anything, and it should stay that way in /sysfs. You may want to talk to sysfs maintainers if you plan on doing another semantics.

How would you proceed in case of devices which clear their fault register upon I2C readout (e.g. AS3645)? In this case read does have a side effect. For such devices attribute semantics would have to be different than for the devices which don't clear faults on readout.

No, semantics should be same for all devices.

Quoted 7 lines
Quoted 2 lines

If device clears fault register during I2C readout, kernel will simply gather faults in an variable, and clear them upon write to sysfs file.

This approach would require implementing additional mechanisms on both sides: LED Flash class core and a LED Flash class driver. In the former the sysfs attribute write permissions would have to be decided in the runtime and in the latter caching mechanism

Quoted 6 lines

Write attributes at runtime? Why? We can emulate sane and consistent behaviour for all the controllers: read gives you list of faults, write clears it. We can do it for all the controllers.

Only cost is few lines of code in the drivers where hardware clears faults at read.

Please take the time to read this, and consider it.

I'd say the cost is I2C register access, not so much a few lines added to the drivers. The functionality and behaviour between the flash controllers varies. They have different faults, presence of (some) faults may prevent strobing, some support reading the flash status and some don't.

Some of the flash faults are mostly relevant in production testing, some can be used to find hardware issues during use (rare) and some are produced in common use (timeout, for instance).

The V4L2 flash API defines that reading the faults clears them, but does not state whether presence of faults would prevent further use of the flash. This is flash controller chip specific.

I think you *could* force a policy on the level of kernel API, for instance require that the user clears the faults before strobing again rather than relying on the chip requiring this instead.

Most of the time there are no faults. When there are, they may appear at some point of time after the strobing, but how long? Probably roughly after the timeout period the flash should have faults available if there were any --- except if the strobe is external such as a sensor timed strobe. In that case the software running on the CPU has no knowledge when the flash is strobed nor when the faults should be read. So the requirement of checking the faults would probably have to be limited to software strobe only. The user would still have to be able to check the faults for externally strobed pulses. Would it be acceptable that the interface was different there?

So, after the user has strobed, when the user should check the flash faults? After the timeout period has passed? Right before strobing again? If this was a requirement, it adds an additional I2C access to potentially the place which should absolutely have no extra delay --- the flash strobe time. This would be highly unwanted.

The faults seldom happened in regular use, but more recent flash controllers have LED overtemperature or undervoltage faults, the latter of which isn't really a fault, but status information telling that the flash current will be limited. Reading the faults in this case is more important than it has used to be.

Finally, should the LED flash class enforce such a policy, would the V4L2 flash API which is provided to the same devices be changed as well? I'm not against that if we have

1) can come up with a good policy that is understood to be meaningful for all thinkable flash controller implementations and

2) agreement the behaviour can be changed.

Btw. I think I'm slightly leaning towards liking flash faults in form of strings better; that's what much of the sysfs interface already uses. V4L2 is quite a bit different from that; we have a bitmask control for faults with well defined meanings for the bits in the spec. The LED class API is much more usable from the command line, and using strings for flash faults is in line with that. I have no strict stance towards that however; hexadecimal numbers have advantages as well such as being slightly more practicable to check in a C program. The importance of good documentatation increases in that case though, and probably a header file with the bit definitions is needed as well.

Signature · 4 lines
Kind regards,

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

Re: [PATCH/RFC v8 02/14] Documentation: leds: Add description of LED Flash class extension

Hi!

Quoted 19 lines
Quoted 11 lines
Quoted 4 lines

This approach would require implementing additional mechanisms on both sides: LED Flash class core and a LED Flash class driver. In the former the sysfs attribute write permissions would have to be decided in the runtime and in the latter caching mechanism

Write attributes at runtime? Why? We can emulate sane and consistent behaviour for all the controllers: read gives you list of faults, write clears it. We can do it for all the controllers.

Only cost is few lines of code in the drivers where hardware clears faults at read.

Please take the time to read this, and consider it.

I'd say the cost is I2C register access, not so much a few lines added to the drivers. The functionality and behaviour between the flash controllers varies. They have different faults, presence of (some) faults may prevent strobing, some support reading the flash status and some don't.

Quoted 7 lines

Some of the flash faults are mostly relevant in production testing, some can be used to find hardware issues during use (rare) and some are produced in common use (timeout, for instance).

The V4L2 flash API defines that reading the faults clears them, but does not state whether presence of faults would prevent further use of the flash. This is flash controller chip specific.

Yeah, but we are discussing sysfs reads. V4L2 API can just behave differently.

Quoted 3 lines

I think you *could* force a policy on the level of kernel API, for instance require that the user clears the faults before strobing again rather than relying on the chip requiring this instead.

Yes, we could do that.

Quoted 10 lines

Most of the time there are no faults. When there are, they may appear at some point of time after the strobing, but how long? Probably roughly after the timeout period the flash should have faults available if there were any --- except if the strobe is external such as a sensor timed strobe. In that case the software running on the CPU has no knowledge when the flash is strobed nor when the faults should be read. So the requirement of checking the faults would probably have to be limited to software strobe only. The user would still have to be able to check the faults for externally strobed pulses. Would it be acceptable that the interface was different there?

Should the user just read the faults before scheduling next strobe?

Quoted 5 lines

So, after the user has strobed, when the user should check the flash faults? After the timeout period has passed? Right before strobing again? If this was a requirement, it adds an additional I2C access to potentially the place which should absolutely have no extra delay --- the flash strobe time. This would be highly unwanted.

I'd do it before strobing again. Not neccessarily "just" before strobing again (you claim it is slow ... is it really so slow it matters)?

Quoted 8 lines

Finally, should the LED flash class enforce such a policy, would the V4L2 flash API which is provided to the same devices be changed as well? I'm not against that if we have

1) can come up with a good policy that is understood to be meaningful for all thinkable flash controller implementations and

2) agreement the behaviour can be changed.

I am saying that reading from /sys should not have side effects. For V4L2, existing behaviour might be ok.

Each driver should have two operations: read_faults() and clear_faults().

On devices where i2c read clears faults, operations will be:

int my_faults

read_faults()

	my_faults |= read_i2c_faults()
	return my_faults

clear_faults()
my_faults = 0

Best regards,
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#20 lore raw

PATCH v8 3/14 Documentation: leds: Add description of v4l2-flash sub-device

In reply to Jacek Anaszewski

This patch extends LED Flash class documention by the description of interactions with v4l2-flash sub-device.

---
 Documentation/leds/leds-class-flash.txt |   13 +++++++++++++
 1 file changed, 13 insertions(+)
Documentation/leds/leds-class-flash.txt +13 -0
index d68565c..1a611ec 100644
@@ -46,3 +46,16 @@ Following sysfs attributes are exposed for controlling flash led devices:
 			 until this flag is no longer set
 		* 0x100 - the temperature of the LED has exceeded its allowed
 			  upper limit
+
+A LED subsystem driver can be controlled also from the level of VideoForLinux2
+subsystem. In order to enable this CONFIG_V4L2_FLASH_LED_CLASS symbol has to
+be defined in the kernel config. The driver must call the v4l2_flash_init
+function to get registered in the V4L2 subsystem. On remove the
+v4l2_flash_release function has to be called (see <media/v4l2-flash.h>).
+
+After proper initialization a V4L2 Flash sub-device is created. The sub-device
+exposes a number of V4L2 controls, which allow for controlling a LED Flash class
+device with use of its internal kernel API.
+Opening the V4L2 Flash sub-device makes the LED subsystem sysfs interface
+unavailable. The interface is re-enabled after the V4L2 Flash sub-device
+is closed.
Signature · 1 line
1.7.9.5
Acked-by on v8 3/14
#21 lore raw

Re: [PATCH/RFC v8 03/14] Documentation: leds: Add description of v4l2-flash sub-device

Quoted 7 lines · Jacek Anaszewski

This patch extends LED Flash class documention by the description of interactions with v4l2-flash sub-device.

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

Re: [PATCH/RFC v8 03/14] Documentation: leds: Add description of v4l2-flash sub-device

In reply to Jacek Anaszewski
Quoted 8 lines · Jacek Anaszewski

This patch extends LED Flash class documention by the description of interactions with v4l2-flash sub-device.

---

This patch looks good to me. I will take it with other patches!

Thanks,
-Bryan

Quoted 27 lines
 Documentation/leds/leds-class-flash.txt |   13 +++++++++++++
 1 file changed, 13 insertions(+)
Documentation/leds/leds-class-flash.txt +13 -1
index d68565c..1a611ec 100644
@@ -46,3 +46,16 @@ Following sysfs attributes are exposed for controlling flash led devices:
                         until this flag is no longer set
                * 0x100 - the temperature of the LED has exceeded its allowed
                          upper limit
+
+A LED subsystem driver can be controlled also from the level of VideoForLinux2
+subsystem. In order to enable this CONFIG_V4L2_FLASH_LED_CLASS symbol has to
+be defined in the kernel config. The driver must call the v4l2_flash_init
+function to get registered in the V4L2 subsystem. On remove the
+v4l2_flash_release function has to be called (see <media/v4l2-flash.h>).
+
+After proper initialization a V4L2 Flash sub-device is created. The sub-device
+exposes a number of V4L2 controls, which allow for controlling a LED Flash class
+device with use of its internal kernel API.
+Opening the V4L2 Flash sub-device makes the LED subsystem sysfs interface
+unavailable. The interface is re-enabled after the V4L2 Flash sub-device
+is closed.
--

1.7.9.5

#23 lore raw

PATCH v8 4/14 v4l2-async: change custom.match callback argument type

In reply to Jacek Anaszewski

It is useful to have an access to the async sub-device being matched, not only to the related struct device. Change match callback argument from struct device to struct v4l2_subdev. It will allow e.g. for matching a sub-device by its "name" property.

Cc Guennadi Liakhovetski <[email protected]>
Cc Laurent Pinchart <[email protected]>
Cc Hans Verkuil <[email protected]>
---
 drivers/media/v4l2-core/v4l2-async.c |   16 ++++++++--------
 include/media/v4l2-async.h           |    2 +-
 2 files changed, 9 insertions(+), 9 deletions(-)
drivers/media/v4l2-core/v4l2-async.c +8 -8
index 85a6a34..8140992 100644
@@ -22,10 +22,10 @@
 #include <media/v4l2-device.h>
 #include <media/v4l2-subdev.h>
 
-static bool match_i2c(struct device *dev, struct v4l2_async_subdev *asd)
+static bool match_i2c(struct v4l2_subdev *sd, struct v4l2_async_subdev *asd)
 {
 #if IS_ENABLED(CONFIG_I2C)
-	struct i2c_client *client = i2c_verify_client(dev);
+	struct i2c_client *client = i2c_verify_client(sd->dev);
 	return client &&
 		asd->match.i2c.adapter_id == client->adapter->nr &&
 		asd->match.i2c.address == client->addr;
@@ -34,14 +34,14 @@ static bool match_i2c(struct device *dev, struct v4l2_async_subdev *asd)
 #endif
 }
 
-static bool match_devname(struct device *dev, struct v4l2_async_subdev *asd)
+static bool match_devname(struct v4l2_subdev *sd, struct v4l2_async_subdev *asd)
 {
-	return !strcmp(asd->match.device_name.name, dev_name(dev));
+	return !strcmp(asd->match.device_name.name, dev_name(sd->dev));
 }
 
-static bool match_of(struct device *dev, struct v4l2_async_subdev *asd)
+static bool match_of(struct v4l2_subdev *sd, struct v4l2_async_subdev *asd)
 {
-	return dev->of_node == asd->match.of.node;
+	return sd->dev->of_node == asd->match.of.node;
 }
 
 static LIST_HEAD(subdev_list);
@@ -52,7 +52,7 @@ static struct v4l2_async_subdev *v4l2_async_belongs(struct v4l2_async_notifier *
 						    struct v4l2_subdev *sd)
 {
 	struct v4l2_async_subdev *asd;
-	bool (*match)(struct device *, struct v4l2_async_subdev *);
+	bool (*match)(struct v4l2_subdev *, struct v4l2_async_subdev *);
 
 	list_for_each_entry(asd, &notifier->waiting, list) {
 		/* bus_type has been verified valid before */
@@ -79,7 +79,7 @@ static struct v4l2_async_subdev *v4l2_async_belongs(struct v4l2_async_notifier *
 		}
 
 		/* match cannot be NULL here */
-		if (match(sd->dev, asd))
+		if (match(sd, asd))
 			return asd;
 	}
 
include/media/v4l2-async.h +1 -1
index 7683569..1c0b586 100644
@@ -51,7 +51,7 @@ struct v4l2_async_subdev {
 			unsigned short address;
 		} i2c;
 		struct {
-			bool (*match)(struct device *,
+			bool (*match)(struct v4l2_subdev *,
 				      struct v4l2_async_subdev *);
 			void *priv;
 		} custom;
Signature · 1 line
1.7.9.5
Acked-by on v8 4/14
#24 lore raw

Re: [PATCH/RFC v8 04/14] v4l2-async: change custom.match callback argument type

Quoted 11 lines · Jacek Anaszewski

It is useful to have an access to the async sub-device being matched, not only to the related struct device. Change match callback argument from struct device to struct v4l2_subdev. It will allow e.g. for matching a sub-device by its "name" property.

Cc Guennadi Liakhovetski <[email protected]>
Cc Laurent Pinchart <[email protected]>
Cc Hans Verkuil <[email protected]>
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#25 lore raw

Re: [PATCH/RFC v8 04/14] v4l2-async: change custom.match callback argument type

In reply to Jacek Anaszewski

Hi Jacek,

Thank you for the patch.

Quoted 5 lines · On Friday 28 November 2014 10:17:56 Jacek Anaszewski wrote:

It is useful to have an access to the async sub-device being matched, not only to the related struct device. Change match callback argument from struct device to struct v4l2_subdev. It will allow e.g. for matching a sub-device by its "name" property.

In principle I agree. However, we will need to reimplement v4l2-async based on the component (drivers/base/component.c) framework at some point. As the component framework is based on struct device, will it still be possible to match on subdev name in that case ? If not, we might need to try to find another approach to the issue.

Quoted 77 lines
Cc Guennadi Liakhovetski <[email protected]>
Cc Laurent Pinchart <[email protected]>
Cc Hans Verkuil <[email protected]>
---
 drivers/media/v4l2-core/v4l2-async.c |   16 ++++++++--------
 include/media/v4l2-async.h           |    2 +-
 2 files changed, 9 insertions(+), 9 deletions(-)
(quoted diff) +0 -0

b/drivers/media/v4l2-core/v4l2-async.c index 85a6a34..8140992 100644

drivers/media/v4l2-core/v4l2-async.c +2 -2
@@ -22,10 +22,10 @@
 #include <media/v4l2-device.h>
 #include <media/v4l2-subdev.h>
 
-static bool match_i2c(struct device *dev, struct v4l2_async_subdev *asd)
+static bool match_i2c(struct v4l2_subdev *sd, struct v4l2_async_subdev
 *asd) {
 #if IS_ENABLED(CONFIG_I2C)
-	struct i2c_client *client = i2c_verify_client(dev);
+	struct i2c_client *client = i2c_verify_client(sd->dev);
 	return client &&
 		asd->match.i2c.adapter_id == client->adapter->nr &&
 		asd->match.i2c.address == client->addr;
@@ -34,14 +34,14 @@ static bool match_i2c(struct device *dev, struct

v4l2_async_subdev *asd) #endif
}

-static bool match_devname(struct device *dev, struct v4l2_async_subdev *asd) +static bool match_devname(struct v4l2_subdev *sd, struct v4l2_async_subdev *asd) {

drivers/media/v4l2-core/v4l2-async.c +2 -2
-	return !strcmp(asd->match.device_name.name, dev_name(dev));
+	return !strcmp(asd->match.device_name.name, dev_name(sd->dev));
 }
 
-static bool match_of(struct device *dev, struct v4l2_async_subdev *asd)
+static bool match_of(struct v4l2_subdev *sd, struct v4l2_async_subdev *asd)

{

drivers/media/v4l2-core/v4l2-async.c +3 -3
-	return dev->of_node == asd->match.of.node;
+	return sd->dev->of_node == asd->match.of.node;
 }
 
 static LIST_HEAD(subdev_list);
@@ -52,7 +52,7 @@ static struct v4l2_async_subdev *v4l2_async_belongs(struct
 v4l2_async_notifier * struct v4l2_subdev *sd)
 {
 	struct v4l2_async_subdev *asd;
-	bool (*match)(struct device *, struct v4l2_async_subdev *);
+	bool (*match)(struct v4l2_subdev *, struct v4l2_async_subdev *);
 
 	list_for_each_entry(asd, &notifier->waiting, list) {
 		/* bus_type has been verified valid before */
@@ -79,7 +79,7 @@ static struct v4l2_async_subdev *v4l2_async_belongs(struct
 v4l2_async_notifier * }
 
 		/* match cannot be NULL here */
-		if (match(sd->dev, asd))
+		if (match(sd, asd))
 			return asd;
 	}
 
include/media/v4l2-async.h +1 -1
index 7683569..1c0b586 100644
@@ -51,7 +51,7 @@ struct v4l2_async_subdev {
 			unsigned short address;
 		} i2c;
 		struct {
-			bool (*match)(struct device *,
+			bool (*match)(struct v4l2_subdev *,
 				      struct v4l2_async_subdev *);
 			void *priv;
 		} custom;
Signature · 3 lines
Regards,

Laurent Pinchart
#26 lore raw

Re: [PATCH/RFC v8 04/14] v4l2-async: change custom.match callback argument type

Hi Laurent,

Quoted 11 lines · Laurent Pinchart

Hi Jacek,

Thank you for the patch.

Quoted 5 lines · On Friday 28 November 2014 10:17:56 Jacek Anaszewski wrote:

It is useful to have an access to the async sub-device being matched, not only to the related struct device. Change match callback argument from struct device to struct v4l2_subdev. It will allow e.g. for matching a sub-device by its "name" property.

Quoted 5 lines

In principle I agree. However, we will need to reimplement v4l2-async based on the component (drivers/base/component.c) framework at some point. As the component framework is based on struct device, will it still be possible to match on subdev name in that case ? If not, we might need to try to find another approach to the issue.

There were reservations raised [1] concerning the way of matching by name, as the labels are not guaranteed to be globally unique across Device Tree. I admit, this issue has to be solved in a different way. Especially in view of prospective transition to using drivers/base/component.c

I propose to add a new structure:

struct v4l2_asd_match{
	bool (*match)(struct v4l2_async_subdev *, void *);
	void *priv;
}

and a function:
v4l2_async_register_subdev_with_match(struct v4l2_subdev *sd, struct v4l2_asd_match*).

This way we could pass DT sub-node related to a sub-led in a priv field of v4l2_asd_match upon registration.

This is similar approach as in case of drivers/base/component.c.

Best Regards,
Jacek Anaszewski

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

#27 lore raw

PATCH v8 5/14 v4l2-ctrls: Add V4L2_CID_FLASH_SYNC_STROBE control

In reply to Jacek Anaszewski

Add V4L2_CID_FLASH_SYNC_STROBE control for determining whether a flash device strobe has to be synchronized with other flash leds controller by the same device.

---
 Documentation/DocBook/media/v4l/controls.xml |    9 +++++++++
 drivers/media/v4l2-core/v4l2-ctrls.c         |    2 ++
 include/uapi/linux/v4l2-controls.h           |    1 +
 3 files changed, 12 insertions(+)
Documentation/DocBook/media/v4l/controls.xml +9 -0
index e013e4b..35e9ea3 100644
@@ -4563,6 +4563,15 @@ interface and may change in the future.</para>
     	    after strobe during which another strobe will not be
     	    possible. This is a read-only control.</entry>
     	  </row>
+    	  <row>
+    	    <entry spanname="id"><constant>V4L2_CID_FLASH_SYNC_STROBE</constant></entry>
+    	    <entry>boolean</entry>
+    	  </row>
+    	  <row>
+    	    <entry spanname="descr">Synchronized strobe: whether the flash
+	    should be strobed synchronously with the other ones controlled
+	    by the same device</entry>
+    	  </row>
     	  <row><entry></entry></row>
     	</tbody>
           </tgroup>
drivers/media/v4l2-core/v4l2-ctrls.c +2 -0
index 45c5b47..a7cca8c 100644
@@ -846,6 +846,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_SYNC_STROBE:	return "Synchronize Strobe";
 
 	/* JPEG encoder controls */
 	/* Keep the order of the 'case's the same as in v4l2-controls.h! */
@@ -949,6 +950,7 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
 	case V4L2_CID_FLASH_STROBE_STATUS:
 	case V4L2_CID_FLASH_CHARGE:
 	case V4L2_CID_FLASH_READY:
+	case V4L2_CID_FLASH_SYNC_STROBE:
 	case V4L2_CID_MPEG_VIDEO_DECODER_MPEG4_DEBLOCK_FILTER:
 	case V4L2_CID_MPEG_VIDEO_DECODER_SLICE_INTERFACE:
 	case V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE:
include/uapi/linux/v4l2-controls.h +1 -0
index 661f119..5bce13d 100644
@@ -833,6 +833,7 @@ 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_SYNC_STROBE		(V4L2_CID_FLASH_CLASS_BASE + 13)
 
 
 /* JPEG-class control IDs */
Signature · 1 line
1.7.9.5
#28 lore raw

PATCH v8 6/14 media: Add registration helpers for V4L2 flash sub-devices

In reply to Jacek Anaszewski

This patch adds helper functions for registering/unregistering LED Flash class devices as V4L2 sub-devices. The functions should be called from the LED subsystem device driver. In case the support for V4L2 Flash sub-devices is disabled in the kernel config the functions' empty versions will be used.

---
 drivers/media/v4l2-core/Kconfig      |   11 +
 drivers/media/v4l2-core/Makefile     |    2 +
 drivers/media/v4l2-core/v4l2-flash.c |  516 ++++++++++++++++++++++++++++++++++
 include/media/v4l2-flash.h           |  138 +++++++++
 4 files changed, 667 insertions(+)
 create mode 100644 drivers/media/v4l2-core/v4l2-flash.c
 create mode 100644 include/media/v4l2-flash.h
drivers/media/v4l2-core/Kconfig +11 -0
index ba7e21a..f034f1a 100644
@@ -44,6 +44,17 @@ config V4L2_MEM2MEM_DEV
         tristate
         depends on VIDEOBUF2_CORE
 
+# Used by LED subsystem flash drivers
+config V4L2_FLASH_LED_CLASS
+	tristate "Enable support for Flash sub-devices"
+	depends on VIDEO_V4L2_SUBDEV_API
+	depends on LEDS_CLASS_FLASH
+	---help---
+	  Say Y here to enable support for Flash sub-devices, which allow
+	  to control LED class devices with use of V4L2 Flash controls.
+
+	  When in doubt, say N.
+
 # Used by drivers that need Videobuf modules
 config VIDEOBUF_GEN
 	tristate
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 +516 -0

516 lines not on this page · raw message

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

138 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#29 lore raw

Re: [PATCH/RFC v8 06/14] media: Add registration helpers for V4L2 flash sub-devices

Quoted 267 lines · Jacek Anaszewski

This patch adds helper functions for registering/unregistering LED Flash class devices as V4L2 sub-devices. The functions should be called from the LED subsystem device driver. In case the support for V4L2 Flash sub-devices is disabled in the kernel config the functions' empty versions will be used.

---
  drivers/media/v4l2-core/Kconfig      |   11 +
  drivers/media/v4l2-core/Makefile     |    2 +
  drivers/media/v4l2-core/v4l2-flash.c |  516 ++++++++++++++++++++++++++++++++++
  include/media/v4l2-flash.h           |  138 +++++++++
  4 files changed, 667 insertions(+)

create mode 100644 drivers/media/v4l2-core/v4l2-flash.c create mode 100644 include/media/v4l2-flash.h

drivers/media/v4l2-core/Kconfig +11 -0
index ba7e21a..f034f1a 100644
@@ -44,6 +44,17 @@ config V4L2_MEM2MEM_DEV
          tristate
          depends on VIDEOBUF2_CORE
 
+# Used by LED subsystem flash drivers
+config V4L2_FLASH_LED_CLASS
+	tristate "Enable support for Flash sub-devices"
+	depends on VIDEO_V4L2_SUBDEV_API
+	depends on LEDS_CLASS_FLASH
+	---help---
+	  Say Y here to enable support for Flash sub-devices, which allow
+	  to control LED class devices with use of V4L2 Flash controls.
+
+	  When in doubt, say N.
+
  # Used by drivers that need Videobuf modules
  config VIDEOBUF_GEN
  	tristate
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 +207 -0
new file mode 100644
index 0000000..f5075b0
@@ -0,0 +1,516 @@
+/*
+ * 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/module.h>
+#include <linux/mutex.h>
+#include <linux/slab.h>
+#include <linux/types.h>
+#include <media/v4l2-flash.h>
+
+#define has_flash_op(v4l2_flash, op)			\
+	(v4l2_flash && v4l2_flash->ops->op)
+
+#define call_flash_op(v4l2_flash, op, args...)		\
+		(has_flash_op(v4l2_flash, op) ?		\
+			v4l2_flash->ops->op(args) :	\
+			-EINVAL)
+
+static inline enum led_brightness v4l2_flash_intensity_to_led_brightness(
+					struct v4l2_ctrl *ctrl,
+					s32 intensity)
+{
+	s64 __intensity = intensity - ctrl->minimum;
+
+	do_div(__intensity, ctrl->step);
+
+	return __intensity + 1;
+}
+
+static inline s32 v4l2_flash_led_brightness_to_intensity(
+					struct v4l2_ctrl *ctrl,
+					enum led_brightness brightness)
+{
+	return ((brightness - 1) * ctrl->step) + ctrl->minimum;
+}
+
+static int v4l2_flash_g_volatile_ctrl(struct v4l2_ctrl *c)
+{
+	struct v4l2_flash *v4l2_flash = v4l2_ctrl_to_v4l2_flash(c);
+	struct led_classdev_flash *flash = v4l2_flash->flash;
+	struct led_classdev *led_cdev = &flash->led_cdev;
+	struct v4l2_ctrl **ctrls = v4l2_flash->ctrls;
+	bool is_strobing;
+	int ret;
+
+	switch (c->id) {
+	case V4L2_CID_FLASH_TORCH_INTENSITY:
+		/*
+		 * Update torch brightness only if in TORCH_MODE.
+		 * In other modes torch led is turned off, which
+		 * would spuriously inform the user space that
+		 * V4L2_CID_FLASH_TORCH_INTENSITY control setting
+		 * has changed.
+		 */
+		if (ctrls[LED_MODE]->val == V4L2_FLASH_LED_MODE_TORCH) {
+			ret = led_update_brightness(led_cdev);
+			if (ret < 0)
+				return ret;
+			c->val = v4l2_flash_led_brightness_to_intensity(
+							ctrls[TORCH_INTENSITY],
+							led_cdev->brightness);
+		}
+		return 0;
+	case V4L2_CID_FLASH_INDICATOR_INTENSITY:
+		ret = led_update_brightness(led_cdev);
+		if (ret < 0)
+			return ret;
+		c->val = v4l2_flash_led_brightness_to_intensity(
+						ctrls[INDICATOR_INTENSITY],
+						led_cdev->brightness);
+		return 0;
+	case V4L2_CID_FLASH_INTENSITY:
+		ret = led_update_flash_brightness(flash);
+		if (ret < 0)
+			return ret;
+		/* no conversion is needed */
+		c->val = flash->brightness.val;
+		return 0;
+	case V4L2_CID_FLASH_STROBE_STATUS:
+		ret = led_get_flash_strobe(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 */
+		return led_get_flash_fault(flash, &c->val);
+	case V4L2_CID_FLASH_SYNC_STROBE:
+		c->val = flash->sync_strobe;
+		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 led_classdev *led_cdev = &flash->led_cdev;
+	struct v4l2_ctrl **ctrls = v4l2_flash->ctrls;
+	enum led_brightness brightness;
+	bool external_strobe;
+	int ret = 0;
+
+	switch (c->id) {
+	case V4L2_CID_FLASH_LED_MODE:
+		switch (c->val) {
+		case V4L2_FLASH_LED_MODE_NONE:
+			led_set_brightness(led_cdev, LED_OFF);
+			return led_set_flash_strobe(flash, false);
+		case V4L2_FLASH_LED_MODE_FLASH:
+			/* Turn the torch LED off */
+			led_set_brightness(led_cdev, LED_OFF);
+			external_strobe = (ctrls[STROBE_SOURCE]->val ==
+					V4L2_FLASH_STROBE_SOURCE_EXTERNAL);
+
+			if (has_flash_op(v4l2_flash, external_strobe_set))
+				ret = call_flash_op(v4l2_flash,
+						external_strobe_set, v4l2_flash,
+						external_strobe);
+			return ret;
+		case V4L2_FLASH_LED_MODE_TORCH:
+			/* Stop flash strobing */
+			ret = led_set_flash_strobe(flash, false);
+			if (ret < 0)
+				return ret;
+
+			brightness =
+				v4l2_flash_intensity_to_led_brightness(
+						ctrls[TORCH_INTENSITY],
+						ctrls[TORCH_INTENSITY]->val);
+			led_set_brightness(led_cdev, brightness);
+			return 0;
+		}
+		break;
+	case V4L2_CID_FLASH_STROBE_SOURCE:
+		external_strobe = (c->val == V4L2_FLASH_STROBE_SOURCE_EXTERNAL);
+
+		return call_flash_op(v4l2_flash, external_strobe_set,
+					v4l2_flash, external_strobe);
+	case V4L2_CID_FLASH_STROBE:
+		if (ctrls[LED_MODE]->val != V4L2_FLASH_LED_MODE_FLASH ||
+		    ctrls[STROBE_SOURCE]->val !=
+					V4L2_FLASH_STROBE_SOURCE_SOFTWARE)
+			return -EINVAL;
+		return led_set_flash_strobe(flash, true);
+	case V4L2_CID_FLASH_STROBE_STOP:
+		if (ctrls[LED_MODE]->val != V4L2_FLASH_LED_MODE_FLASH ||
+		    ctrls[STROBE_SOURCE]->val !=
+					V4L2_FLASH_STROBE_SOURCE_SOFTWARE)
+			return -EINVAL;
+		return led_set_flash_strobe(flash, false);
+	case V4L2_CID_FLASH_TIMEOUT:
+		/* no conversion is needed */
+		return led_set_flash_timeout(flash, c->val);
+	case V4L2_CID_FLASH_INTENSITY:
+		/* no conversion is needed */
+		return led_set_flash_brightness(flash, c->val);
+	case V4L2_CID_FLASH_INDICATOR_INTENSITY:
+		brightness = v4l2_flash_intensity_to_led_brightness(
+						ctrls[INDICATOR_INTENSITY],
+						c->val);
+		led_set_brightness(led_cdev, brightness);
+		return 0;
+	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 (ctrls[LED_MODE]->val == V4L2_FLASH_LED_MODE_TORCH) {
+			brightness =
+				v4l2_flash_intensity_to_led_brightness(
+							ctrls[TORCH_INTENSITY],
+							c->val);
+			led_set_brightness(led_cdev, brightness);
+		}
+		return 0;
+	case V4L2_CID_FLASH_SYNC_STROBE:
+		flash->sync_strobe = 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 void fill_ctrl_init_data(struct v4l2_flash *v4l2_flash,
+			  struct v4l2_flash_ctrl_config *flash_cfg,
+			  struct v4l2_flash_ctrl_data *ctrl_init_data)
+{
+	struct led_classdev_flash *flash = v4l2_flash->flash;
+	const struct led_flash_ops *flash_ops = flash->ops;

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

Quoted 10 lines
drivers/media/v4l2-core/v4l2-flash.c new file +10 -0
+	struct led_classdev *led_cdev = &flash->led_cdev;
+	struct v4l2_ctrl_config *ctrl_cfg;
+	u32 mask;
+	s64 max;
+
+	/* Init FLASH_LED_MODE ctrl data */
+	mask = 1 << V4L2_FLASH_LED_MODE_NONE |
+	       1 << V4L2_FLASH_LED_MODE_TORCH;
+	if (led_cdev->flags & LED_DEV_CAP_FLASH)
+		mask |= 1 << V4L2_FLASH_LED_MODE_FLASH;

I didn't take into account the case when there is no LED_DEV_CAP_FLASH flag set but there is has_indicator flag set in the v4l2_flash_ctrl_config. In fact this is the only valid arrangement in the new approach where the indicator led will have its own LED Flash class device and the related v4l2_subdev.

Actually has_indicator is the residue after previous version of the
patch set. It should be renamed to e.g. indicator_led. Similarly
indicator_intensity should be removed, torch_intensity renamed to
something more generic for both torch and indicator leds e.g. led_intensity or just intensity like in case of proposed new leds/common.txt bindings where the property max-microamp doesn't
have any additional segment and there is flash-max-microamp property
for flash leds. Mode and torch intensity controls also shouldn't be
created for indicator leds.

Summarizing - indicator led should have maximum two controls:
V4L2_CID_FLASH_INDICATOR_INTENSITY and V4L2_CID_FLASH_FAULT

Best Regards,
Jacek Anaszewski

Quoted 443 lines
drivers/media/v4l2-core/v4l2-flash.c new file +298 -0
+	ctrl_init_data[LED_MODE].supported = true;
+	ctrl_cfg = &ctrl_init_data[LED_MODE].config;
+	ctrl_cfg->id = V4L2_CID_FLASH_LED_MODE;
+	ctrl_cfg->max = V4L2_FLASH_LED_MODE_TORCH;
+	ctrl_cfg->menu_skip_mask = ~mask;
+	ctrl_cfg->def = V4L2_FLASH_LED_MODE_NONE;
+	ctrl_cfg->flags = 0;
+
+	/* Init TORCH_INTENSITY ctrl data */
+	ctrl_init_data[TORCH_INTENSITY].supported = true;
+	ctrl_init_data[TORCH_INTENSITY].config = flash_cfg->torch_intensity;
+	ctrl_cfg = &ctrl_init_data[TORCH_INTENSITY].config;
+	ctrl_cfg->id = V4L2_CID_FLASH_TORCH_INTENSITY;
+	ctrl_cfg->flags = V4L2_CTRL_FLAG_VOLATILE;
+
+	if (!(led_cdev->flags & LED_DEV_CAP_FLASH))
+		return;
+
+	/* Init FLASH_STROBE_SOURCE ctrl data */
+	mask = 1 << V4L2_FLASH_STROBE_SOURCE_SOFTWARE;
+	if (flash_cfg->has_external_strobe) {
+		mask |= 1 << V4L2_FLASH_STROBE_SOURCE_EXTERNAL;
+		max = V4L2_FLASH_STROBE_SOURCE_EXTERNAL;
+	} else {
+		max = V4L2_FLASH_STROBE_SOURCE_SOFTWARE;
+	}
+
+	ctrl_init_data[STROBE_SOURCE].supported = true;
+	ctrl_cfg = &ctrl_init_data[STROBE_SOURCE].config;
+	ctrl_cfg->id = V4L2_CID_FLASH_STROBE_SOURCE;
+	ctrl_cfg->max = max;
+	ctrl_cfg->menu_skip_mask = ~mask;
+	ctrl_cfg->def = V4L2_FLASH_STROBE_SOURCE_SOFTWARE;
+
+	/* Init FLASH_STROBE ctrl data */
+	ctrl_init_data[FLASH_STROBE].supported = true;
+	ctrl_cfg = &ctrl_init_data[FLASH_STROBE].config;
+	ctrl_cfg->id = V4L2_CID_FLASH_STROBE;
+
+	/* Init STROBE_STOP ctrl data */
+	ctrl_init_data[STROBE_STOP].supported = true;
+	ctrl_cfg = &ctrl_init_data[STROBE_STOP].config;
+	ctrl_cfg->id = V4L2_CID_FLASH_STROBE_STOP;
+
+	/* Init STROBE_STATUS ctrl data */
+	if (flash_ops->strobe_get) {
+		ctrl_init_data[STROBE_STATUS].supported = true;
+		ctrl_cfg = &ctrl_init_data[STROBE_STATUS].config;
+		ctrl_cfg->id = V4L2_CID_FLASH_STROBE_STATUS;
+		ctrl_cfg->flags = V4L2_CTRL_FLAG_VOLATILE |
+				  V4L2_CTRL_FLAG_READ_ONLY;
+	}
+
+	/* Init FLASH_TIMEOUT ctrl data */
+	if (flash_ops->timeout_set) {
+		ctrl_init_data[FLASH_TIMEOUT].supported = true;
+		ctrl_init_data[FLASH_TIMEOUT].config = flash_cfg->flash_timeout;
+		ctrl_cfg = &ctrl_init_data[FLASH_TIMEOUT].config;
+		ctrl_cfg->id = V4L2_CID_FLASH_TIMEOUT;
+		ctrl_cfg->flags = V4L2_CTRL_FLAG_VOLATILE;
+	}
+
+	/* Init FLASH_INTENSITY ctrl data */
+	if (flash_ops->flash_brightness_set) {
+		ctrl_init_data[FLASH_INTENSITY].supported = true;
+		ctrl_init_data[FLASH_INTENSITY].config =
+					flash_cfg->flash_intensity;
+		ctrl_cfg = &ctrl_init_data[FLASH_INTENSITY].config;
+		ctrl_cfg->id = V4L2_CID_FLASH_INTENSITY;
+		ctrl_cfg->flags = V4L2_CTRL_FLAG_VOLATILE;
+	}
+
+	/* Init INDICATOR_INTENSITY ctrl data */
+	if (flash_cfg->has_indicator) {
+		ctrl_init_data[INDICATOR_INTENSITY].supported = true;
+		ctrl_init_data[INDICATOR_INTENSITY].config =
+					flash_cfg->indicator_intensity;
+		ctrl_cfg = &ctrl_init_data[INDICATOR_INTENSITY].config;
+		ctrl_cfg->id = V4L2_CID_FLASH_INDICATOR_INTENSITY;
+		ctrl_cfg->flags = V4L2_CTRL_FLAG_VOLATILE;
+	}
+
+	/* Init FLASH_FAULT ctrl data */
+	if (flash_cfg->flash_faults) {
+		ctrl_init_data[FLASH_FAULT].supported = true;
+		ctrl_cfg = &ctrl_init_data[FLASH_FAULT].config;
+		ctrl_cfg->id = V4L2_CID_FLASH_FAULT;
+		ctrl_cfg->max = flash_cfg->flash_faults;
+		ctrl_cfg->flags = V4L2_CTRL_FLAG_VOLATILE |
+				  V4L2_CTRL_FLAG_READ_ONLY;
+	}
+
+	if (led_cdev->flags & LED_DEV_CAP_COMPOUND) {
+		ctrl_init_data[SYNC_STROBE].supported = true;
+		ctrl_cfg = &ctrl_init_data[SYNC_STROBE].config;
+		ctrl_cfg->id = V4L2_CID_FLASH_SYNC_STROBE;
+		ctrl_cfg->flags = V4L2_CTRL_FLAG_VOLATILE;
+	}
+}
+
+static int v4l2_flash_init_controls(struct v4l2_flash *v4l2_flash,
+				struct v4l2_flash_ctrl_config *flash_cfg)
+
+{
+	struct v4l2_flash_ctrl_data *ctrl_init_data;
+	struct v4l2_ctrl *ctrl;
+	struct v4l2_ctrl_config *ctrl_cfg;
+	int i, ret, num_ctrls = 0;
+
+	/* allocate memory dynamically so as not to exceed stack frame size */
+	ctrl_init_data = kcalloc(NUM_FLASH_CTRLS, sizeof(*ctrl_init_data),
+					GFP_KERNEL);
+	if (!ctrl_init_data)
+		return -ENOMEM;
+
+	memset(ctrl_init_data, 0, sizeof(*ctrl_init_data));
+
+	fill_ctrl_init_data(v4l2_flash, flash_cfg, ctrl_init_data);
+
+	for (i = 0; i < NUM_FLASH_CTRLS; ++i)
+		if (ctrl_init_data[i].supported)
+			++num_ctrls;
+
+	v4l2_ctrl_handler_init(&v4l2_flash->hdl, num_ctrls);
+
+	for (i = 0; i < NUM_FLASH_CTRLS; ++i) {
+		ctrl_cfg = &ctrl_init_data[i].config;
+		if (!ctrl_init_data[i].supported)
+			continue;
+
+		if (ctrl_cfg->id == V4L2_CID_FLASH_LED_MODE ||
+		    ctrl_cfg->id == V4L2_CID_FLASH_STROBE_SOURCE)
+			ctrl = v4l2_ctrl_new_std_menu(&v4l2_flash->hdl,
+						&v4l2_flash_ctrl_ops,
+						ctrl_cfg->id,
+						ctrl_cfg->max,
+						ctrl_cfg->menu_skip_mask,
+						ctrl_cfg->def);
+		else
+			ctrl = v4l2_ctrl_new_std(&v4l2_flash->hdl,
+						&v4l2_flash_ctrl_ops,
+						ctrl_cfg->id,
+						ctrl_cfg->min,
+						ctrl_cfg->max,
+						ctrl_cfg->step,
+						ctrl_cfg->def);
+
+		if (ctrl)
+			ctrl->flags |= ctrl_cfg->flags;
+
+		if (i <= STROBE_SOURCE)
+			v4l2_flash->ctrls[i] = ctrl;
+	}
+
+	kfree(ctrl_init_data);
+
+	if (v4l2_flash->hdl.error) {
+		ret = v4l2_flash->hdl.error;
+		goto error_free_handler;
+	}
+
+	v4l2_ctrl_handler_setup(&v4l2_flash->hdl);
+
+	v4l2_flash->sd.ctrl_handler = &v4l2_flash->hdl;
+
+	return 0;
+
+error_free_handler:
+	v4l2_ctrl_handler_free(&v4l2_flash->hdl);
+	return ret;
+}
+
+/*
+ * 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;
+	int ret = 0;
+
+	mutex_lock(&led_cdev->led_access);
+
+	if (!v4l2_fh_is_singular(&fh->vfh)) {
+		ret = -EBUSY;
+		goto unlock;
+	}
+
+	led_sysfs_disable(led_cdev);
+
+unlock:
+	mutex_unlock(&led_cdev->led_access);
+	return ret;
+}
+
+static int v4l2_flash_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
+{
+	struct v4l2_flash *v4l2_flash = v4l2_subdev_to_v4l2_flash(sd);
+	struct led_classdev_flash *flash = v4l2_flash->flash;
+	struct led_classdev *led_cdev = &flash->led_cdev;
+	int ret = 0;
+
+	mutex_lock(&led_cdev->led_access);
+
+	if (has_flash_op(v4l2_flash, external_strobe_set))
+		ret = call_flash_op(v4l2_flash, external_strobe_set,
+				v4l2_flash, false);
+	led_sysfs_enable(led_cdev);
+
+	mutex_unlock(&led_cdev->led_access);
+
+	return ret;
+}
+
+static const struct v4l2_subdev_internal_ops v4l2_flash_subdev_internal_ops = {
+	.open = v4l2_flash_open,
+	.close = v4l2_flash_close,
+};
+
+static const struct v4l2_subdev_core_ops v4l2_flash_core_ops = {
+	.queryctrl = v4l2_subdev_queryctrl,
+	.querymenu = v4l2_subdev_querymenu,
+};
+
+static const struct v4l2_subdev_ops v4l2_flash_subdev_ops = {
+	.core = &v4l2_flash_core_ops,
+};
+
+struct v4l2_flash *v4l2_flash_init(struct led_classdev_flash *flash,
+				   const struct v4l2_flash_ops *ops,
+				   struct v4l2_flash_ctrl_config *config)
+{
+	struct v4l2_flash *v4l2_flash;
+	struct led_classdev *led_cdev = &flash->led_cdev;
+	struct v4l2_subdev *sd;
+	int ret;
+
+	if (!flash || !ops || !config)
+		return ERR_PTR(-EINVAL);
+
+	v4l2_flash = kzalloc(sizeof(*v4l2_flash), GFP_KERNEL);
+	if (!v4l2_flash)
+		return ERR_PTR(-ENOMEM);
+
+	sd = &v4l2_flash->sd;
+	v4l2_flash->flash = flash;
+	v4l2_flash->ops = 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);
+
+	ret = v4l2_flash_init_controls(v4l2_flash, config);
+	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;
+
+	ret = v4l2_async_register_subdev(sd);
+	if (ret < 0)
+		goto err_init_entity;
+
+	return v4l2_flash;
+
+err_init_entity:
+	media_entity_cleanup(&sd->entity);
+err_init_controls:
+	v4l2_ctrl_handler_free(sd->ctrl_handler);
+	kfree(v4l2_flash);
+
+	return ERR_PTR(ret);
+}
+EXPORT_SYMBOL_GPL(v4l2_flash_init);
+
+void v4l2_flash_release(struct v4l2_flash *v4l2_flash)
+{
+	struct v4l2_subdev *sd = &v4l2_flash->sd;
+
+	if (!v4l2_flash)
+		return;
+
+	v4l2_async_unregister_subdev(sd);
+	media_entity_cleanup(&sd->entity);
+	v4l2_ctrl_handler_free(sd->ctrl_handler);
+	kfree(v4l2_flash);
+}
+EXPORT_SYMBOL_GPL(v4l2_flash_release);
+
+MODULE_AUTHOR("Jacek Anaszewski <[email protected]>");
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("V4L2 Flash sub-device helpers");
include/media/v4l2-flash.h new file +138 -0
new file mode 100644
index 0000000..1e18df5
@@ -0,0 +1,138 @@
+/*
+ * 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;
+struct v4l2_flash;
+enum led_brightness;
+
+enum ctrl_init_data_id {
+	LED_MODE,
+	TORCH_INTENSITY,
+	STROBE_SOURCE,
+	FLASH_STROBE,
+	STROBE_STOP,
+	STROBE_STATUS,
+	FLASH_TIMEOUT,
+	FLASH_INTENSITY,
+	INDICATOR_INTENSITY,
+	FLASH_FAULT,
+	SYNC_STROBE,
+	NUM_FLASH_CTRLS,
+};
+
+/*
+ * struct v4l2_flash_ctrl_data - flash control initialization data -
+ *				 filled basing on the features declared
+ *				 by the LED Flash class driver
+ * @config:	initialization data for a control
+ * @supported:	indicates whether a control is supported
+ *		by the LED Flash class driver
+ */
+struct v4l2_flash_ctrl_data {
+	struct v4l2_ctrl_config config;
+	bool supported;
+};
+
+struct v4l2_flash_ops {
+	/* setup strobing the flash by hardware pin state assertion */
+	int (*external_strobe_set)(struct v4l2_flash *v4l2_flash,
+					bool enable);
+};
+
+/**
+ * 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
+ * @has_external_strobe:	external strobe capability
+ */
+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;
+	bool has_external_strobe:1;
+	bool has_indicator:1;
+};
+
+/**
+ * struct v4l2_flash - Flash sub-device context
+ * @flash:		LED Flash Class device controlled by this sub-device
+ * @ops:		V4L2 specific flash ops
+ * @sd:			V4L2 sub-device
+ * @hdl:		flash controls handler
+ * @ctrls:		array of pointers to controls, whose values define
+			the sub-device state
+ */
+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_ctrl *ctrls[STROBE_SOURCE + 1];
+};
+
+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);
+}
+
+#if IS_ENABLED(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
+ *
+ * Create V4L2 subdev wrapping given LED subsystem device.
+
+ * Returns: A valid pointer, or, when an error occurs, the return
+ * value is encoded using ERR_PTR(). Use IS_ERR() to check and
+ * PTR_ERR() to obtain the numeric return value.
+ */
+struct v4l2_flash *v4l2_flash_init(struct led_classdev_flash *led_fdev,
+				   const struct v4l2_flash_ops *ops,
+				   struct v4l2_flash_ctrl_config *config);
+
+/**
+ * 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, ops, config) (NULL)
+#define v4l2_flash_release(v4l2_flash)
+#endif /* CONFIG_V4L2_FLASH_LED_CLASS */
+
+#endif /* _V4L2_FLASH_H */
#30 lore raw

PATCH v8 7/14 exynos4-is: Add support for v4l2-flash subdevs

In reply to Jacek Anaszewski

This patch adds suppport for external v4l2-flash devices. The support includes parsing "flashes" Device Tree property and asynchronous subdevice registration.

---
 drivers/media/platform/exynos4-is/media-dev.c |   65 ++++++++++++++++++++++++-
 drivers/media/platform/exynos4-is/media-dev.h |   13 ++++-
 2 files changed, 75 insertions(+), 3 deletions(-)
drivers/media/platform/exynos4-is/media-dev.c +63 -2
index f315ef9..8807730 100644
@@ -451,6 +451,47 @@ rpm_put:
 	return ret;
 }
 
+static bool match_subdev_name(struct v4l2_subdev *sd,
+			      struct v4l2_async_subdev *asd)
+{
+	return !strcmp(sd->name, (char *) asd->match.custom.priv);
+}
+
+static int fimc_md_register_flash_entities(struct fimc_md *fmd)
+{
+	struct device_node *parent = fmd->pdev->dev.of_node;
+	const char *flash_names[FIMC_MAX_FLASHES];
+	int ret, i;
+
+	ret = of_property_count_strings(parent, "flashes");
+	if (ret < 0) {
+		/* the property may not exist - this is valid state */
+		if (ret == -EINVAL)
+			return 0;
+		v4l2_err(&fmd->v4l2_dev, "Failed to retrieve flashes\n");
+		return -EINVAL;
+	}
+
+	fmd->num_flashes = ret;
+
+	if (fmd->num_flashes > FIMC_MAX_FLASHES) {
+		v4l2_err(&fmd->v4l2_dev, "Too many flash leds declared.\n");
+		return -EINVAL;
+	}
+
+	of_property_read_string_array(parent, "flashes", flash_names,
+					fmd->num_flashes);
+
+	for (i = 0; i < fmd->num_flashes; ++i) {
+		fmd->flash[i].asd.match_type = V4L2_ASYNC_MATCH_CUSTOM;
+		fmd->flash[i].asd.match.custom.match = match_subdev_name;
+		fmd->flash[i].asd.match.custom.priv = (void *) flash_names[i];
+		fmd->async_subdevs[fmd->num_sensors + i] = &fmd->flash[i].asd;
+	}
+
+	return 0;
+}
+
 static int __of_get_csis_id(struct device_node *np)
 {
 	u32 reg = 0;
@@ -1275,6 +1316,18 @@ static int subdev_notifier_bound(struct v4l2_async_notifier *notifier,
 	struct fimc_sensor_info *si = NULL;
 	int i;
 
+	/* Register flash subdev if detected any */
+	for (i = 0; i < ARRAY_SIZE(fmd->flash); i++) {
+		if (!fmd->flash[i].asd.match.custom.priv)
+			continue;
+		if (!strcmp(fmd->flash[i].asd.match.custom.priv,
+				subdev->name)) {
+			fmd->flash[i].subdev = subdev;
+			fmd->num_flashes++;
+			return 0;
+		}
+	}
+
 	/* Find platform data for this sensor subdev */
 	for (i = 0; i < ARRAY_SIZE(fmd->sensor); i++)
 		if (fmd->sensor[i].asd.match.of.node == subdev->dev->of_node)
@@ -1385,6 +1438,12 @@ static int fimc_md_probe(struct platform_device *pdev)
 		goto err_m_ent;
 	}
 
+	ret = fimc_md_register_flash_entities(fmd);
+	if (ret < 0) {
+		mutex_unlock(&fmd->media_dev.graph_mutex);
+		goto err_m_ent;
+	}
+
 	mutex_unlock(&fmd->media_dev.graph_mutex);
 
 	ret = device_create_file(&pdev->dev, &dev_attr_subdev_conf_mode);
@@ -1401,12 +1460,14 @@ static int fimc_md_probe(struct platform_device *pdev)
 		goto err_attr;
 	}
 
-	if (fmd->num_sensors > 0) {
+	if (fmd->num_sensors > 0 || fmd->num_flashes > 0) {
 		fmd->subdev_notifier.subdevs = fmd->async_subdevs;
-		fmd->subdev_notifier.num_subdevs = fmd->num_sensors;
+		fmd->subdev_notifier.num_subdevs = fmd->num_sensors +
+						   fmd->num_flashes;
 		fmd->subdev_notifier.bound = subdev_notifier_bound;
 		fmd->subdev_notifier.complete = subdev_notifier_complete;
 		fmd->num_sensors = 0;
+		fmd->num_flashes = 0;
 
 		ret = v4l2_async_notifier_register(&fmd->v4l2_dev,
 						&fmd->subdev_notifier);
drivers/media/platform/exynos4-is/media-dev.h +12 -1
index 0321454..feff9c8 100644
@@ -34,6 +34,8 @@
 
 #define FIMC_MAX_SENSORS	4
 #define FIMC_MAX_CAMCLKS	2
+#define FIMC_MAX_FLASHES	2
+#define FIMC_MAX_ASYNC_SUBDEVS (FIMC_MAX_SENSORS + FIMC_MAX_FLASHES)
 #define DEFAULT_SENSOR_CLK_FREQ	24000000U
 
 /* LCD/ISP Writeback clocks (PIXELASYNCMx) */
@@ -93,6 +95,11 @@ struct fimc_sensor_info {
 	struct fimc_dev *host;
 };
 
+struct fimc_flash_info {
+	struct v4l2_subdev *subdev;
+	struct v4l2_async_subdev asd;
+};
+
 struct cam_clk {
 	struct clk_hw hw;
 	struct fimc_md *fmd;
@@ -104,6 +111,8 @@ struct cam_clk {
  * @csis: MIPI CSIS subdevs data
  * @sensor: array of registered sensor subdevs
  * @num_sensors: actual number of registered sensors
+ * @flash: array of registered flash subdevs
+ * @num_flashes: actual number of registered flashes
  * @camclk: external sensor clock information
  * @fimc: array of registered fimc devices
  * @fimc_is: fimc-is data structure
@@ -123,6 +132,8 @@ struct fimc_md {
 	struct fimc_csis_info csis[CSIS_MAX_ENTITIES];
 	struct fimc_sensor_info sensor[FIMC_MAX_SENSORS];
 	int num_sensors;
+	struct fimc_flash_info flash[FIMC_MAX_FLASHES];
+	int num_flashes;
 	struct fimc_camclk_info camclk[FIMC_MAX_CAMCLKS];
 	struct clk *wbclk[FIMC_MAX_WBCLKS];
 	struct fimc_lite *fimc_lite[FIMC_LITE_MAX_DEVS];
@@ -149,7 +160,7 @@ struct fimc_md {
 	} clk_provider;
 
 	struct v4l2_async_notifier subdev_notifier;
-	struct v4l2_async_subdev *async_subdevs[FIMC_MAX_SENSORS];
+	struct v4l2_async_subdev *async_subdevs[FIMC_MAX_ASYNC_SUBDEVS];
 
 	bool user_subdev_api;
 	spinlock_t slock;
Signature · 1 line
1.7.9.5
Acked-by on v8 7/14
#31 lore raw

Re: [PATCH/RFC v8 07/14] exynos4-is: Add support for v4l2-flash subdevs

Quoted 7 lines · Jacek Anaszewski

This patch adds suppport for external v4l2-flash devices. The support includes parsing "flashes" Device Tree property and asynchronous subdevice registration.

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#32 lore raw

PATCH v8 8/14 DT: Add documentation for exynos4-is 'flashes' property

In reply to Jacek Anaszewski

This patch adds a description of 'flashes' property to the samsung-fimc.txt.

Cc Sylwester Nawrocki <[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]>
---
 .../devicetree/bindings/media/samsung-fimc.txt     |    7 +++++++
 1 file changed, 7 insertions(+)
Documentation/devicetree/bindings/media/samsung-fimc.txt +7 -0
index 922d6f8..4b7ed03 100644
@@ -40,6 +40,12 @@ should be inactive. For the "active-a" state the camera port A must be activated
 and the port B deactivated and for the state "active-b" it should be the other
 way around.
 
+Optional properties:
+
+- flashes - array of strings with flash led names; the name has to
+	    be same with the related led label
+	    (see Documentation/devicetree/bindings/leds/common.txt)
+
 The 'camera' node must include at least one 'fimc' child node.
 
 
@@ -166,6 +172,7 @@ Example:
 		clock-output-names = "cam_a_clkout", "cam_b_clkout";
 		pinctrl-names = "default";
 		pinctrl-0 = <&cam_port_a_clk_active>;
+		flashes = "max77693-flash1", "max77693-flash2";
 		status = "okay";
 		#address-cells = <1>;
 		#size-cells = <1>;
Signature · 1 line
1.7.9.5
#33 lore raw

Re: [PATCH/RFC v8 08/14] DT: Add documentation for exynos4-is 'flashes' property

Quoted 21 lines · Jacek Anaszewski

This patch adds a description of 'flashes' property to the samsung-fimc.txt.

Cc Sylwester Nawrocki <[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]>
---
 .../devicetree/bindings/media/samsung-fimc.txt     |    7 +++++++
 1 file changed, 7 insertions(+)
Documentation/devicetree/bindings/media/samsung-fimc.txt +0 -0
index 922d6f8..4b7ed03 100644

Documentation/devicetree/bindings/media/samsung-fimc.txt should be inactive. For the "active-a" state the camera port A must be activated · line 48

Quoted 9 lines
Documentation/devicetree/bindings/media/samsung-fimc.txt +6 -0
@@ -40,6 +40,12 @@ should be inactive. For the "active-a" state the camera port A must be activated
 and the port B deactivated and for the state "active-b" it should be the other
 way around.
 
+Optional properties:
+
+- flashes - array of strings with flash led names; the name has to
+	    be same with the related led label
+	    (see Documentation/devicetree/bindings/leds/common.txt)
+

Why is this not an array of phandles to the LED nodes? That's much better than strings.

Also, I only seem to have recevied the documentation patches and none of the code -- in future when posting RFC DT patches, please Cc for the code too as it's useful context.

Mark.

Quoted 19 lines
Documentation/devicetree/bindings/media/samsung-fimc.txt +1 -0
 The 'camera' node must include at least one 'fimc' child node.
 
 
@@ -166,6 +172,7 @@ Example:
 		clock-output-names = "cam_a_clkout", "cam_b_clkout";
 		pinctrl-names = "default";
 		pinctrl-0 = <&cam_port_a_clk_active>;
+		flashes = "max77693-flash1", "max77693-flash2";
 		status = "okay";
 		#address-cells = <1>;
 		#size-cells = <1>;
Signature · 6 lines
1.7.9.5

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

Re: [PATCH/RFC v8 08/14] DT: Add documentation for exynos4-is 'flashes' property

Quoted 25 lines · Mark Rutland
Quoted 24 lines · Jacek Anaszewski

This patch adds a description of 'flashes' property to the samsung-fimc.txt.

Cc Sylwester Nawrocki <[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]>
---
  .../devicetree/bindings/media/samsung-fimc.txt     |    7 +++++++
  1 file changed, 7 insertions(+)
Documentation/devicetree/bindings/media/samsung-fimc.txt +0 -0
index 922d6f8..4b7ed03 100644
@@ -40,6 +40,12 @@ should be inactive. For the "active-a" state the camera port A must be activated
  and the port B deactivated and for the state "active-b" it should be the other
  way around.
 
Quoted 9 lines

Documentation/devicetree/bindings/media/samsung-fimc.txt should be inactive. For the "active-a" state the camera port A must be activated · line 48

Quoted 6 lines
Documentation/devicetree/bindings/media/samsung-fimc.txt +6 -0
+Optional properties:
+
+- flashes - array of strings with flash led names; the name has to
+	    be same with the related led label
+	    (see Documentation/devicetree/bindings/leds/common.txt)
+

Why is this not an array of phandles to the LED nodes? That's much better than strings.

This is because a single flash led device can control many sub-leds, which are represented by child nodes in the Device Tree. Every sub-led is registered as a separate LED Flash class device in the LED subsystem, but in fact they share the same struct device and thus have access only to the parent's phandle. The LED Flash class devices are wrapped by V4L2 sub-devices and register asynchronously within a media device. Since the v4l2_subdev structure has a 'name' field, it is convenient to initialize it with parsed 'label' property of a child led node and match the sub-devices in the media device basing on it.

Quoted 3 lines

Also, I only seem to have recevied the documentation patches and none of the code -- in future when posting RFC DT patches, please Cc for the code too as it's useful context.

Of course, I'll keep it in mind.

Regards,
Jacek

#35 lore raw

Re: [PATCH/RFC v8 08/14] DT: Add documentation for exynos4-is 'flashes' property

Quoted 36 lines · Jacek Anaszewski
Quoted 25 lines · Mark Rutland
Quoted 24 lines · Jacek Anaszewski

This patch adds a description of 'flashes' property to the samsung-fimc.txt.

Cc Sylwester Nawrocki <[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]>
---
  .../devicetree/bindings/media/samsung-fimc.txt     |    7 +++++++
  1 file changed, 7 insertions(+)
Documentation/devicetree/bindings/media/samsung-fimc.txt +0 -0
index 922d6f8..4b7ed03 100644
@@ -40,6 +40,12 @@ should be inactive. For the "active-a" state the camera port A must be activated
  and the port B deactivated and for the state "active-b" it should be the other
  way around.
 
Quoted 9 lines

Documentation/devicetree/bindings/media/samsung-fimc.txt should be inactive. For the "active-a" state the camera port A must be activated · line 48

Quoted 6 lines
Documentation/devicetree/bindings/media/samsung-fimc.txt +6 -0
+Optional properties:
+
+- flashes - array of strings with flash led names; the name has to
+	    be same with the related led label
+	    (see Documentation/devicetree/bindings/leds/common.txt)
+

Why is this not an array of phandles to the LED nodes? That's much better than strings.

Quoted 5 lines

This is because a single flash led device can control many sub-leds, which are represented by child nodes in the Device Tree. Every sub-led is registered as a separate LED Flash class device in the LED subsystem, but in fact they share the same struct device and thus have access only to the parent's phandle.

But that's a Linux infrastrcture issue, no? You don't have to use the node from the struct device to find the relevant phandle.

Quoted 6 lines

The LED Flash
class devices are wrapped by V4L2 sub-devices and register asynchronously within a media device. Since the v4l2_subdev structure has a 'name' field, it is convenient to initialize it with parsed 'label' property of a child led node and match the sub-devices in the media device basing on it.

While that might be convenient, I don't think it's fantastic to use that to describe the relationship, as this leaks Linux internals (e.g. I can refer to a name that doesn't exist in the DT but happens to be what Linux used, and it would work). Also, are the labels guaranteed to be globally unique?

Using phandles is much better for the binding. I appreciate that this may require more code, but IMO it's worth that for the safety and uniformity given by the use of phandles for referring to nodes.

Quoted 5 lines
Quoted 3 lines

Also, I only seem to have recevied the documentation patches and none of the code -- in future when posting RFC DT patches, please Cc for the code too as it's useful context.

Of course, I'll keep it in mind.

Thanks!

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

#36 lore raw

Re: [PATCH/RFC v8 08/14] DT: Add documentation for exynos4-is 'flashes' property

Quoted 37 lines · Mark Rutland
Quoted 36 lines · Jacek Anaszewski
Quoted 34 lines · Mark Rutland
Quoted 21 lines · Jacek Anaszewski

This patch adds a description of 'flashes' property to the samsung-fimc.txt.

Cc Sylwester Nawrocki <[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]>
---
   .../devicetree/bindings/media/samsung-fimc.txt     |    7 +++++++
   1 file changed, 7 insertions(+)
Documentation/devicetree/bindings/media/samsung-fimc.txt +0 -0
index 922d6f8..4b7ed03 100644

Documentation/devicetree/bindings/media/samsung-fimc.txt should be inactive. For the "active-a" state the camera port A must be activated · line 48

Quoted 9 lines
Documentation/devicetree/bindings/media/samsung-fimc.txt +6 -0
@@ -40,6 +40,12 @@ should be inactive. For the "active-a" state the camera port A must be activated
   and the port B deactivated and for the state "active-b" it should be the other
   way around.
 
+Optional properties:
+
+- flashes - array of strings with flash led names; the name has to
+	    be same with the related led label
+	    (see Documentation/devicetree/bindings/leds/common.txt)
+

Why is this not an array of phandles to the LED nodes? That's much better than strings.

Quoted 8 lines
Quoted 5 lines

This is because a single flash led device can control many sub-leds, which are represented by child nodes in the Device Tree. Every sub-led is registered as a separate LED Flash class device in the LED subsystem, but in fact they share the same struct device and thus have access only to the parent's phandle.

But that's a Linux infrastrcture issue, no? You don't have to use the node from the struct device to find the relevant phandle.

Right.

Quoted 7 lines
Quoted 6 lines

The LED Flash
class devices are wrapped by V4L2 sub-devices and register asynchronously within a media device. Since the v4l2_subdev structure has a 'name' field, it is convenient to initialize it with parsed 'label' property of a child led node and match the sub-devices in the media device basing on it.

Quoted 5 lines

While that might be convenient, I don't think it's fantastic to use that to describe the relationship, as this leaks Linux internals (e.g. I can refer to a name that doesn't exist in the DT but happens to be what Linux used, and it would work). Also, are the labels guaranteed to be globally unique?

The labels are used for initializing class device name and kernel doesn't allow to initialize two devices with same names. This implies that labels are guaranteed to be globally unique. Unless I am missing something.

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

#37 lore raw

Re: [PATCH/RFC v8 08/14] DT: Add documentation for exynos4-is 'flashes' property

Quoted 62 lines · Jacek Anaszewski
Quoted 37 lines · Mark Rutland
Quoted 36 lines · Jacek Anaszewski
Quoted 34 lines · Mark Rutland
Quoted 21 lines · Jacek Anaszewski

This patch adds a description of 'flashes' property to the samsung-fimc.txt.

Cc Sylwester Nawrocki <[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]>
---
   .../devicetree/bindings/media/samsung-fimc.txt     |    7 +++++++
   1 file changed, 7 insertions(+)
Documentation/devicetree/bindings/media/samsung-fimc.txt +0 -0
index 922d6f8..4b7ed03 100644

Documentation/devicetree/bindings/media/samsung-fimc.txt should be inactive. For the "active-a" state the camera port A must be activated · line 48

Quoted 9 lines
Documentation/devicetree/bindings/media/samsung-fimc.txt +6 -0
@@ -40,6 +40,12 @@ should be inactive. For the "active-a" state the camera port A must be activated
   and the port B deactivated and for the state "active-b" it should be the other
   way around.
 
+Optional properties:
+
+- flashes - array of strings with flash led names; the name has to
+	    be same with the related led label
+	    (see Documentation/devicetree/bindings/leds/common.txt)
+

Why is this not an array of phandles to the LED nodes? That's much better than strings.

Quoted 8 lines
Quoted 5 lines

This is because a single flash led device can control many sub-leds, which are represented by child nodes in the Device Tree. Every sub-led is registered as a separate LED Flash class device in the LED subsystem, but in fact they share the same struct device and thus have access only to the parent's phandle.

But that's a Linux infrastrcture issue, no? You don't have to use the node from the struct device to find the relevant phandle.

Right.

Quoted 7 lines
Quoted 6 lines

The LED Flash
class devices are wrapped by V4L2 sub-devices and register asynchronously within a media device. Since the v4l2_subdev structure has a 'name' field, it is convenient to initialize it with parsed 'label' property of a child led node and match the sub-devices in the media device basing on it.

Quoted 5 lines

While that might be convenient, I don't think it's fantastic to use that to describe the relationship, as this leaks Linux internals (e.g. I can refer to a name that doesn't exist in the DT but happens to be what Linux used, and it would work). Also, are the labels guaranteed to be globally unique?

Quoted 3 lines

The labels are used for initializing class device name and kernel doesn't allow to initialize two devices with same names. This implies that labels are guaranteed to be globally unique.

On Linux, yes, but that's an implementation detail, not a property of the binding·

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

#38 lore raw

PATCH v8 9/14 mfd: max77693: adjust max77693_led_platform_data

In reply to Jacek Anaszewski

Add "label" array for Device Tree strings with the name of a LED device and make flash_timeout
a two element array, for caching the sub-led related flash timeout.

---
 include/linux/mfd/max77693.h |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/linux/mfd/max77693.h +2 -1
index f0b6585..30fa19ea 100644
@@ -88,14 +88,15 @@ enum max77693_led_boost_mode {
 };
 
 struct max77693_led_platform_data {
+	const char *label[2];
 	u32 fleds[2];
 	u32 iout_torch[2];
 	u32 iout_flash[2];
 	u32 trigger[2];
 	u32 trigger_type[2];
+	u32 flash_timeout[2];
 	u32 num_leds;
 	u32 boost_mode;
-	u32 flash_timeout;
 	u32 boost_vout;
 	u32 low_vsys;
 };
Signature · 1 line
1.7.9.5
#39 lore raw

Re: [PATCH/RFC v8 09/14] mfd: max77693: adjust max77693_led_platform_data

Quoted 4 lines · Jacek Anaszewski

Add "label" array for Device Tree strings with the name of a LED device and make flash_timeout
a two element array, for caching the sub-led related flash timeout.

<------------------------------------------------------------------------->

Please use all of the 75 char buffer.

Quoted 21 lines
---
 include/linux/mfd/max77693.h |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/linux/mfd/max77693.h +1 -0
index f0b6585..30fa19ea 100644
@@ -88,14 +88,15 @@ enum max77693_led_boost_mode {
 };
 
 struct max77693_led_platform_data {
+	const char *label[2];
 	u32 fleds[2];
 	u32 iout_torch[2];

include/linux/mfd/max77693.h enum max77693_led_boost_mode { · line 102

Quoted 10 lines
include/linux/mfd/max77693.h +1 -1
 	u32 iout_flash[2];
 	u32 trigger[2];
 	u32 trigger_type[2];
+	u32 flash_timeout[2];
 	u32 num_leds;
 	u32 boost_mode;
-	u32 flash_timeout;
 	u32 boost_vout;
 	u32 low_vsys;
 };

I'm guessing this will effect the other patches in the set?

Signature · 4 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
#40 lore raw

Re: [PATCH/RFC v8 09/14] mfd: max77693: adjust max77693_led_platform_data

Hi Lee,

Thanks for the review.

Quoted 10 lines · Lee Jones
Quoted 4 lines · Jacek Anaszewski

Add "label" array for Device Tree strings with the name of a LED device and make flash_timeout
a two element array, for caching the sub-led related flash timeout.

<------------------------------------------------------------------------->

Please use all of the 75 char buffer.

OK.

Quoted 17 lines
Quoted 17 lines
---
  include/linux/mfd/max77693.h |    3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
include/linux/mfd/max77693.h +0 -0
index f0b6585..30fa19ea 100644
@@ -88,14 +88,15 @@ enum max77693_led_boost_mode {
  };
 
Quoted 17 lines
Quoted 4 lines
include/linux/mfd/max77693.h +1 -0
  struct max77693_led_platform_data {
+	const char *label[2];
  	u32 fleds[2];
  	u32 iout_torch[2];

include/linux/mfd/max77693.h enum max77693_led_boost_mode { · line 102

Quoted 10 lines
include/linux/mfd/max77693.h +1 -1
  	u32 iout_flash[2];
  	u32 trigger[2];
  	u32 trigger_type[2];
+	u32 flash_timeout[2];
  	u32 num_leds;
  	u32 boost_mode;
-	u32 flash_timeout;
  	u32 boost_vout;
  	u32 low_vsys;
  };

I'm guessing this will effect the other patches in the set?

max77692 flash driver depends on it and it has to be in synch with the related DT bindings patch.

Best Regards,
Jacek Anaszewski

Acked-by
#41 lore raw

Re: [PATCH/RFC v8 09/14] mfd: max77693: adjust max77693_led_platform_data

Quoted 8 lines · Jacek Anaszewski
Quoted 4 lines · Lee Jones

On Fri, 28 Nov 2014, Jacek Anaszewski wrote:

I'm guessing this will effect the other patches in the set?

max77692 flash driver depends on it and it has to be in synch with the related DT bindings patch.

Very well. Providing you address the commitlog issues:

Signature · 4 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
#42 lore raw

PATCH v8 10/14 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 sub-device when the support for V4L2 Flash sub-devices is enabled. Device supports up to two leds which can work in flash and torch mode. The leds can be triggered externally or by software.

---
 drivers/leds/Kconfig         |   10 +
 drivers/leds/Makefile        |    1 +
 drivers/leds/leds-max77693.c | 1152 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 1163 insertions(+)
 create mode 100644 drivers/leds/leds-max77693.c
drivers/leds/Kconfig +10 -0
index fa8021e..2e66d55 100644
@@ -463,6 +463,16 @@ 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
+	depends on OF
+	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 cbba921..57ca62b 100644
@@ -52,6 +52,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 +1152 -0

1,152 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#43 lore raw

PATCH v8 11/14 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 Lee Jones <[email protected]>
Cc SangYoung Son <[email protected]>
Cc Samuel Ortiz <sameo-VuQAYsv1563Yd54FQh9/[email protected]>
Cc Bryan Wu <[email protected]>
Cc Richard Purdie <rpurdie-Fm38FmjxZ/[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/mfd/max77693.txt |   74 ++++++++++++++++++++
 1 file changed, 74 insertions(+)
Documentation/devicetree/bindings/mfd/max77693.txt +74 -0
index 01e9f30..50a8dad 100644
@@ -41,6 +41,62 @@ Optional properties:
 	 To get more informations, please refer to documentaion.
 	[*] refer Documentation/devicetree/bindings/pwm/pwm.txt
 
+- led-flash : the LED submodule device node
+
+There are two led outputs available - fled1 and fled2. Each of them can
+control a separate led or they can be connected together to double
+the maximum current for a single connected led. One led is represented
+by one child node.
+
+Required properties:
+- compatible : must be "maxim,max77693-flash"
+
+Optional properties:
+- 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.
+- 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,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,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 there are two child led nodes defined then boost
+	is enabled by default.
+	Possible values:
+		0 - no boost,
+		1 - adaptive mode,
+		2 - fixed mode.
+- 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.
+
+A child node must be defined per sub-led.
+
+Required properties of the LED child node:
+- label : see Documentation/devicetree/bindings/leds/common.txt
+- maxim,fled_id : identifier of the fled output the led is connected to:
+		1 - FLED1,
+		2 - FLED2.
+
+Optional properties of the LED child node:
+- max-microamp : see Documentation/devicetree/bindings/leds/common.txt
+		Range: 15625 - 250000
+- flash-max-microamp : see Documentation/devicetree/bindings/leds/common.txt
+		Range: 15625 - 1000000
+- flash-timeout-microsec : see Documentation/devicetree/bindings/leds/common.txt
+		Range: 62500 - 1000000
+
 Example:
 	max77693@66 {
 		compatible = "maxim,max77693";
@@ -73,4 +129,22 @@ Example:
 			pwms = <&pwm 0 40000 0>;
 			pwm-names = "haptic";
 		};
+
+		led_flash: led-flash {
+			compatible = "maxim,max77693-flash";
+			maxim,fleds = <1 0>;
+			maxim,trigger = <7 0>;
+			maxim,trigger-type = <0 1>;
+			maxim,boost-mode = <0>;
+			maxim,boost-vout = <5000>;
+			maxim,vsys-min = <2400>;
+
+			camera-flash {
+				maxim,fled_id = <1>
+				label = "max77693-flash";
+				max-microamp = <250000>;
+				flash-max-microamp = <1000000>;
+				flash-timeout-microsec = <1000000>;
+			}
+		};
 	};
Signature · 6 lines
1.7.9.5

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

Re: [PATCH/RFC v8 11/14] DT: Add documentation for the mfd Maxim max77693

Hi!

Quoted 14 lines
Documentation/devicetree/bindings/mfd/max77693.txt +6 -0
index 01e9f30..50a8dad 100644
@@ -41,6 +41,62 @@ Optional properties:
 	 To get more informations, please refer to documentaion.
 	[*] refer Documentation/devicetree/bindings/pwm/pwm.txt
 
+- led-flash : the LED submodule device node
+
+There are two led outputs available - fled1 and fled2. Each of them can
+control a separate led or they can be connected together to double
+the maximum current for a single connected led. One led is represented
+by one child node.

Documentation/devicetree/bindings/mfd/max77693.txt Optional properties: · line 59

Quoted 10 lines
Documentation/devicetree/bindings/mfd/max77693.txt +10 -0
+
+Required properties:
+- compatible : must be "maxim,max77693-flash"
+
+Optional properties:
+- 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.

Is this one needed? Just ommit child note if it is not there.

Documentation/devicetree/bindings/mfd/max77693.txt Optional properties: · line 69

Quoted 10 lines
Documentation/devicetree/bindings/mfd/max77693.txt +10 -0
+- 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,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.

Is it good idea to have bitfields like this?

Make these required properties of the subnode?
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#45 lore raw

Re: [PATCH/RFC v8 11/14] DT: Add documentation for the mfd Maxim max77693

Hi Pavel,

Thanks for the review.

Quoted 20 lines · Pavel Machek

Hi!

Quoted 18 lines
Documentation/devicetree/bindings/mfd/max77693.txt +10 -0
index 01e9f30..50a8dad 100644
@@ -41,6 +41,62 @@ Optional properties:
  	 To get more informations, please refer to documentaion.
  	[*] refer Documentation/devicetree/bindings/pwm/pwm.txt
 
+- led-flash : the LED submodule device node
+
+There are two led outputs available - fled1 and fled2. Each of them can
+control a separate led or they can be connected together to double
+the maximum current for a single connected led. One led is represented
+by one child node.
+
+Required properties:
+- compatible : must be "maxim,max77693-flash"
+
Quoted 8 lines

Documentation/devicetree/bindings/mfd/max77693.txt Optional properties: · line 59

Quoted 6 lines
Documentation/devicetree/bindings/mfd/max77693.txt +6 -0
+Optional properties:
+- 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.

Is this one needed? Just ommit child note if it is not there.

It is needed because you can have one led connected two both outputs. This allows to describe such a design.

Quoted 13 lines

Documentation/devicetree/bindings/mfd/max77693.txt Optional properties: · line 69

Quoted 10 lines
Documentation/devicetree/bindings/mfd/max77693.txt +10 -0
+- 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,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.

Is it good idea to have bitfields like this?

Quoted 1 line

Make these required properties of the subnode?

This is related to a single property: trigger. I think that splitting it to three properties would make unnecessary noise in the binding.

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

#46 lore raw

Re: [PATCH/RFC v8 11/14] DT: Add documentation for the mfd Maxim max77693

Hi!

Quoted 4 lines
Quoted 1 line

Is this one needed? Just ommit child note if it is not there.

It is needed because you can have one led connected two both outputs. This allows to describe such a design.

Ok.

Quoted 13 lines
Quoted 13 lines

Documentation/devicetree/bindings/mfd/max77693.txt Optional properties: · line 69

Quoted 10 lines

+- maxim,trigger-type : Array of trigger types in order: flash, torch

Documentation/devicetree/bindings/mfd/max77693.txt +9 -0
+	Possible trigger types:
+		0 - Rising edge of the signal triggers the flash/torch,
+		1 - Signal level controls duration of the flash/torch.
+- 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.

Is it good idea to have bitfields like this?

Quoted 5 lines
Quoted 1 line

Make these required properties of the subnode?

This is related to a single property: trigger. I think that splitting it to three properties would make unnecessary noise in the binding.

Well, maybe it is not that much noise, and you'll have useful names (not a bitfield).

Should these properties move to the LED subnode?
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#47 lore raw

Re: [PATCH/RFC v8 11/14] DT: Add documentation for the mfd Maxim max77693

Hi Pavel,

Quoted 22 lines · Pavel Machek

Hi!

Quoted 4 lines
Quoted 1 line

Is this one needed? Just ommit child note if it is not there.

It is needed because you can have one led connected two both outputs. This allows to describe such a design.

Ok.

Quoted 13 lines
Quoted 13 lines

Documentation/devicetree/bindings/mfd/max77693.txt Optional properties: · line 69

Quoted 10 lines

+- maxim,trigger-type : Array of trigger types in order: flash, torch

Documentation/devicetree/bindings/mfd/max77693.txt +9 -0
+	Possible trigger types:
+		0 - Rising edge of the signal triggers the flash/torch,
+		1 - Signal level controls duration of the flash/torch.
+- 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.

Is it good idea to have bitfields like this?

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Make these required properties of the subnode?

This is related to a single property: trigger. I think that splitting it to three properties would make unnecessary noise in the binding.

Well, maybe it is not that much noise, and you'll have useful names (not a bitfield).

I think we'd need an opinion of at least one more person :)

Quoted 1 line

Should these properties move to the LED subnode?

I would leave them device specific.

Regards,
Jacek

#48 lore raw

Re: [PATCH/RFC v8 11/14] DT: Add documentation for the mfd Maxim max77693

In reply to Jacek Anaszewski
Quoted 17 lines · Jacek Anaszewski

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

Cc Lee Jones <[email protected]>
Cc SangYoung Son <[email protected]>
Cc Samuel Ortiz <[email protected]>
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]>
Quoted 3 lines
---
 Documentation/devicetree/bindings/mfd/max77693.txt |   74 ++++++++++++++++++++
 1 file changed, 74 insertions(+)

This definitely requires a DT Ack.

Quoted 7 lines
Documentation/devicetree/bindings/mfd/max77693.txt +0 -0
index 01e9f30..50a8dad 100644
@@ -41,6 +41,62 @@ Optional properties:
 	 To get more informations, please refer to documentaion.
 	[*] refer Documentation/devicetree/bindings/pwm/pwm.txt

Documentation/devicetree/bindings/mfd/max77693.txt Optional properties: · line 52

Quoted 10 lines
Documentation/devicetree/bindings/mfd/max77693.txt +9 -0
 
+- led-flash : the LED submodule device node
+
+There are two led outputs available - fled1 and fled2. Each of them can
+control a separate led or they can be connected together to double
+the maximum current for a single connected led. One led is represented
+by one child node.
+
+Required properties:
+- compatible : must be "maxim,max77693-flash"

I'm not sure this compatible string is suitable. It looks like NOR/NAND Flash to me. Perhaps 'fled', or just 'led' would be better.

Documentation/devicetree/bindings/mfd/max77693.txt Optional properties: · line 55

Quoted 2 lines
Documentation/devicetree/bindings/mfd/max77693.txt +2 -0
+Optional properties:
+- maxim,fleds : array of current outputs in order: fled1, fled2

Nit: Sentences start with an uppercase character.

This is true for all other occurrences.

Quoted 25 lines
Documentation/devicetree/bindings/mfd/max77693.txt +25 -0
+	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.
+- 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,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,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 there are two child led nodes defined then boost
+	is enabled by default.
+	Possible values:
+		0 - no boost,
+		1 - adaptive mode,
+		2 - fixed mode.
+- maxim,boost-vout : Output voltage of the boost module in millivolts.
+- maxim,vsys-min : Low input voltage level in millivolts. Flash is not fired

Documentation/devicetree/bindings/mfd/max77693.txt Optional properties: · line 90

Quoted 10 lines
Documentation/devicetree/bindings/mfd/max77693.txt +10 -0
+	if chip estimates that system voltage could drop below this level due
+	to flash power consumption.
+
+A child node must be defined per sub-led.
+
+Required properties of the LED child node:
+- label : see Documentation/devicetree/bindings/leds/common.txt
+- maxim,fled_id : identifier of the fled output the led is connected to:
+		1 - FLED1,
+		2 - FLED2.

Better to define all of these random numbers in include/dt-bindings.

Quoted 12 lines
Documentation/devicetree/bindings/mfd/max77693.txt +8 -0
+Optional properties of the LED child node:
+- max-microamp : see Documentation/devicetree/bindings/leds/common.txt
+		Range: 15625 - 250000
+- flash-max-microamp : see Documentation/devicetree/bindings/leds/common.txt
+		Range: 15625 - 1000000
+- flash-timeout-microsec : see Documentation/devicetree/bindings/leds/common.txt
+		Range: 62500 - 1000000
+
 Example:
 	max77693@66 {
 		compatible = "maxim,max77693";

Documentation/devicetree/bindings/mfd/max77693.txt Example: · line 133

Quoted 5 lines
Documentation/devicetree/bindings/mfd/max77693.txt +2 -0
@@ -73,4 +129,22 @@ Example:
 			pwms = <&pwm 0 40000 0>;
 			pwm-names = "haptic";
 		};
+
+		led_flash: led-flash {

Should both be underscore. I believe the second portion here should be more generic "led" for instance.

Documentation/devicetree/bindings/mfd/max77693.txt Example: · line 140

Quoted 7 lines
Documentation/devicetree/bindings/mfd/max77693.txt +7 -0
+			compatible = "maxim,max77693-flash";
+			maxim,fleds = <1 0>;
+			maxim,trigger = <7 0>;
+			maxim,trigger-type = <0 1>;
+			maxim,boost-mode = <0>;
+			maxim,boost-vout = <5000>;
+			maxim,vsys-min = <2400>;

These will all have to be signed off by a DT maintainer.

Documentation/devicetree/bindings/mfd/max77693.txt Example: · line 148

Quoted 7 lines
Documentation/devicetree/bindings/mfd/max77693.txt +7 -0
+			camera-flash {
+				maxim,fled_id = <1>
+				label = "max77693-flash";
+				max-microamp = <250000>;
+				flash-max-microamp = <1000000>;
+				flash-timeout-microsec = <1000000>;
+			}

Missing ';'

You should probably test your example code.

Quoted 2 lines
Documentation/devicetree/bindings/mfd/max77693.txt +1 -0
+		};
 	};
Signature · 4 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
#49 lore raw

PATCH v8 12/14 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        |    7 +
 drivers/leds/Makefile       |    1 +
 drivers/leds/leds-aat1290.c |  472 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 480 insertions(+)
 create mode 100644 drivers/leds/leds-aat1290.c
drivers/leds/Kconfig +7 -0
index 2e66d55..ec4b78c 100644
@@ -39,6 +39,13 @@ 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
+	depends on OF
+	help
+	 This option enables support for the LEDs on the AAT1290.
+
 config LEDS_LM3530
 	tristate "LCD Backlight driver for LM3530"
 	depends on LEDS_CLASS
drivers/leds/Makefile +1 -0
index 57ca62b..b802251 100644
@@ -7,6 +7,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_BD2802)		+= leds-bd2802.o
 obj-$(CONFIG_LEDS_LOCOMO)		+= leds-locomo.o
 obj-$(CONFIG_LEDS_LM3530)		+= leds-lm3530.o
drivers/leds/leds-aat1290.c new file +472 -0

472 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#50 lore raw

Re: [PATCH/RFC v8 12/14] leds: Add driver for AAT1290 current regulator

Hi!

Quoted 20 lines
drivers/leds/leds-aat1290.c new file +18 -0
@@ -0,0 +1,472 @@
+/*
+ *	LED Flash class driver for the AAT1290
+ *	1.5A Step-Up Current Regulator for Flash LEDs
+ *
+ *	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.
+ */
+
 
+#define AAT1290_MM_TO_FL_1_92	1
+#define AAT1290_MM_TO_FL_3_7	2
+#define AAT1290_MM_TO_FL_5_5	3
+#define AAT1290_MM_TO_FL_7_3	4
+#define AAT1290_MM_TO_FL_9	5
+#define AAT1290_MM_TO_FL_10_7	6

drivers/leds/leds-aat1290.c line 54

Quoted 10 lines
drivers/leds/leds-aat1290.c new file +10 -0
+#define AAT1290_MM_TO_FL_12_4	7
+#define AAT1290_MM_TO_FL_14	8
+#define AAT1290_MM_TO_FL_15_9	9
+#define AAT1290_MM_TO_FL_17_5	10
+#define AAT1290_MM_TO_FL_19_1	11
+#define AAT1290_MM_TO_FL_20_8	12
+#define AAT1290_MM_TO_FL_22_4	13
+#define AAT1290_MM_TO_FL_24	14
+#define AAT1290_MM_TO_FL_25_6	15
+#define AAT1290_MM_TO_FL_OFF	16

Only one of these defines is unused.

drivers/leds/leds-aat1290.c line 454

Quoted 3 lines
drivers/leds/leds-aat1290.c new file +2 -0
+static struct of_device_id aat1290_led_dt_match[] = {
 
+	{.compatible = "skyworks,aat1290"},

spaces after { and before } ?

Otherwise looks ok,

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#51 lore raw

Re: [PATCH/RFC v8 12/14] leds: Add driver for AAT1290 current regulator

Hi Pavel,

Thanks for a review.

Quoted 27 lines · Pavel Machek

Hi!

Quoted 24 lines
drivers/leds/leds-aat1290.c new file +22 -0
@@ -0,0 +1,472 @@
+/*
+ *	LED Flash class driver for the AAT1290
+ *	1.5A Step-Up Current Regulator for Flash LEDs
+ *
+ *	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.
+ */
+
 
+#define AAT1290_MM_TO_FL_1_92	1
+#define AAT1290_MM_TO_FL_3_7	2
+#define AAT1290_MM_TO_FL_5_5	3
+#define AAT1290_MM_TO_FL_7_3	4
+#define AAT1290_MM_TO_FL_9	5
+#define AAT1290_MM_TO_FL_10_7	6
+#define AAT1290_MM_TO_FL_12_4	7
+#define AAT1290_MM_TO_FL_14	8
+#define AAT1290_MM_TO_FL_15_9	9
+#define AAT1290_MM_TO_FL_17_5	10
Quoted 8 lines

drivers/leds/leds-aat1290.c line 54

Quoted 6 lines
drivers/leds/leds-aat1290.c new file +6 -0
+#define AAT1290_MM_TO_FL_19_1	11
+#define AAT1290_MM_TO_FL_20_8	12
+#define AAT1290_MM_TO_FL_22_4	13
+#define AAT1290_MM_TO_FL_24	14
+#define AAT1290_MM_TO_FL_25_6	15
+#define AAT1290_MM_TO_FL_OFF	16

Only one of these defines is unused.

The only cost of these macros are lines of code and I think it is worth of having all the possible settings listed in one place.

Quoted 6 lines

drivers/leds/leds-aat1290.c line 454

Quoted 4 lines
drivers/leds/leds-aat1290.c new file +2 -0
+static struct of_device_id aat1290_led_dt_match[] = {
 
+	{.compatible = "skyworks,aat1290"},

spaces after { and before } ?

I see both styles in kernel, but ok, I will add spaces.

Regards,
Jacek

#52 lore raw

PATCH v8 13/14 of: Add Skyworks Solutions, Inc. vendor prefix

In reply to Jacek Anaszewski

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

---
 .../devicetree/bindings/vendor-prefixes.txt        |    1 +
 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/vendor-prefixes.txt +1 -0
index c177cd7..3006825 100644
@@ -137,6 +137,7 @@ ricoh	Ricoh Co. Ltd.
 rockchip	Fuzhou Rockchip Electronics Co., Ltd
 samsung	Samsung Semiconductor
 sandisk	Sandisk Corporation
+skyworks	Skyworks Solutions, Inc.
 sbs	Smart Battery System
 schindler	Schindler
 seagate	Seagate Technology PLC
Signature · 1 line
1.7.9.5
#53 lore raw

PATCH v8 14/14 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 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]>
---
 .../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..8f001dd
@@ -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
+- flash-timeout-microsec : 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-microsec = <1940000>;
+}
Signature · 1 line
1.7.9.5