Re: [PATCH/RFC v6 3/3] leds: Add LED Flash Class wrapper to LED subsystem
Hi Bryan, Thanks for a review. On 11/04/2014 02:34 AM, Bryan Wu wrote: On Mon, Sep 22, 2014 at 8:21 AM, Jacek Anaszewski j.anaszew...@samsung.com wrote: Some LED devices support two operation modes - torch and flash. I got several terms here: flash, torch and indicator. And we have 3 CAPs CAP_TORCH CAP_FLASH CAP_INDICATOR I assume flash == indicator but it doesn't from the code. So what's the difference between flash and indicator. Indicator is a so-called privacy led, that can be used to indicate when a person is being photographed or filmed. V4L2 API defines only an API for setting its intensity. Adding Sakari. 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, indicator_brightness and max_indicator_brightness. All the flash related features are placed in a separate module. There is no torch interface? only flash and indicator. LED Class interface is used for torch. 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. Signed-off-by: Jacek Anaszewski j.anaszew...@samsung.com Acked-by: Kyungmin Park kyungmin.p...@samsung.com Cc: Bryan Wu coolo...@gmail.com Cc: Richard Purdie rpur...@rpsys.net --- drivers/leds/Kconfig| 11 + drivers/leds/Makefile |1 + drivers/leds/led-class-flash.c | 557 +++ drivers/leds/led-class.c|4 + include/linux/led-class-flash.h | 238 + include/linux/leds.h|3 + 6 files changed, 814 insertions(+) create mode 100644 drivers/leds/led-class-flash.c create mode 100644 include/linux/led-class-flash.h diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 8c96e2d..3c58021 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -22,6 +22,17 @@ config LEDS_CLASS This option enables the led sysfs class in /sys/class/leds. You'll need this to do anything useful with LEDs. If unsure, say N. +config LEDS_CLASS_FLASH + tristate LED Flash Class Support + depends on LEDS_CLASS + depends on OF + help + This option enables the flash led sysfs class in /sys/class/leds. + It wrapps LED Class and adds flash LEDs specific sysfs attributes + and kernel internal API to it. 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 diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index d8cc5f2..9238b8a 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -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 diff --git a/drivers/leds/led-class-flash.c b/drivers/leds/led-class-flash.c new file mode 100644 index 000..f1ba539 --- /dev/null +++ b/drivers/leds/led-class-flash.c @@ -0,0 +1,557 @@ +/* + * LED Flash Class interface + * + * Copyright (C) 2014 Samsung Electronics Co., Ltd. + * Author: Jacek Anaszewski j.anaszew...@samsung.com + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include linux/device.h +#include linux/init.h +#include linux/leds.h +#include linux/led-class-flash.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 =
Re: [PATCH/RFC v6 3/3] leds: Add LED Flash Class wrapper to LED subsystem
On Mon, Sep 22, 2014 at 8:21 AM, Jacek Anaszewski j.anaszew...@samsung.com wrote: Some LED devices support two operation modes - torch and flash. I got several terms here: flash, torch and indicator. And we have 3 CAPs CAP_TORCH CAP_FLASH CAP_INDICATOR I assume flash == indicator but it doesn't from the code. So what's the difference between flash and indicator. 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, indicator_brightness and max_indicator_brightness. All the flash related features are placed in a separate module. There is no torch interface? only flash and indicator. 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. Signed-off-by: Jacek Anaszewski j.anaszew...@samsung.com Acked-by: Kyungmin Park kyungmin.p...@samsung.com Cc: Bryan Wu coolo...@gmail.com Cc: Richard Purdie rpur...@rpsys.net --- drivers/leds/Kconfig| 11 + drivers/leds/Makefile |1 + drivers/leds/led-class-flash.c | 557 +++ drivers/leds/led-class.c|4 + include/linux/led-class-flash.h | 238 + include/linux/leds.h|3 + 6 files changed, 814 insertions(+) create mode 100644 drivers/leds/led-class-flash.c create mode 100644 include/linux/led-class-flash.h diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 8c96e2d..3c58021 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -22,6 +22,17 @@ config LEDS_CLASS This option enables the led sysfs class in /sys/class/leds. You'll need this to do anything useful with LEDs. If unsure, say N. +config LEDS_CLASS_FLASH + tristate LED Flash Class Support + depends on LEDS_CLASS + depends on OF + help + This option enables the flash led sysfs class in /sys/class/leds. + It wrapps LED Class and adds flash LEDs specific sysfs attributes + and kernel internal API to it. 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 diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index d8cc5f2..9238b8a 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -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 diff --git a/drivers/leds/led-class-flash.c b/drivers/leds/led-class-flash.c new file mode 100644 index 000..f1ba539 --- /dev/null +++ b/drivers/leds/led-class-flash.c @@ -0,0 +1,557 @@ +/* + * LED Flash Class interface + * + * Copyright (C) 2014 Samsung Electronics Co., Ltd. + * Author: Jacek Anaszewski j.anaszew...@samsung.com + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include linux/device.h +#include linux/init.h +#include linux/leds.h +#include linux/led-class-flash.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
[PATCH/RFC v6 3/3] leds: Add LED Flash Class wrapper to 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, indicator_brightness and max_indicator_brightness. All the flash related features are placed in a separate module. The modifications aim to be compatible with V4L2 framework requirements related to the flash devices management. The design assumes that V4L2 sub-device can take of the LED class device control and communicate with it through the kernel internal interface. When V4L2 Flash sub-device file is opened, the LED class device sysfs interface is made unavailable. Signed-off-by: Jacek Anaszewski j.anaszew...@samsung.com Acked-by: Kyungmin Park kyungmin.p...@samsung.com Cc: Bryan Wu coolo...@gmail.com Cc: Richard Purdie rpur...@rpsys.net --- drivers/leds/Kconfig| 11 + drivers/leds/Makefile |1 + drivers/leds/led-class-flash.c | 557 +++ drivers/leds/led-class.c|4 + include/linux/led-class-flash.h | 238 + include/linux/leds.h|3 + 6 files changed, 814 insertions(+) create mode 100644 drivers/leds/led-class-flash.c create mode 100644 include/linux/led-class-flash.h diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 8c96e2d..3c58021 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -22,6 +22,17 @@ config LEDS_CLASS This option enables the led sysfs class in /sys/class/leds. You'll need this to do anything useful with LEDs. If unsure, say N. +config LEDS_CLASS_FLASH + tristate LED Flash Class Support + depends on LEDS_CLASS + depends on OF + help + This option enables the flash led sysfs class in /sys/class/leds. + It wrapps LED Class and adds flash LEDs specific sysfs attributes + and kernel internal API to it. 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 diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index d8cc5f2..9238b8a 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -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 diff --git a/drivers/leds/led-class-flash.c b/drivers/leds/led-class-flash.c new file mode 100644 index 000..f1ba539 --- /dev/null +++ b/drivers/leds/led-class-flash.c @@ -0,0 +1,557 @@ +/* + * LED Flash Class interface + * + * Copyright (C) 2014 Samsung Electronics Co., Ltd. + * Author: Jacek Anaszewski j.anaszew...@samsung.com + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include linux/device.h +#include linux/init.h +#include linux/leds.h +#include linux/led-class-flash.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, +