LED / flash API integration - LED Flash Class
Subsystems (2)
v5 cover LED / flash API integration - LED Flash Class
This patch set is the follow-up of the LED / flash API integration series [1]. For clarity reasons the patchset has been split into five subsets:
- LED Flash Class
- Flash Manager
- V4L2 Flash
- LED Flash Class drivers
- Documentation
The series is based on linux-next-20140820.
Thanks,
Jacek Anaszewski
[1] https://lkml.org/lkml/2014/7/11/914
Jacek Anaszewski (4):
leds: Improve and export led_update_brightness
leds: implement sysfs interface locking mechanism
leds: add API for setting torch brightness
leds: Add LED Flash Class wrapper to LED subsystem
drivers/leds/Kconfig | 11 + drivers/leds/Makefile | 1 + drivers/leds/led-class-flash.c | 645 +++++++++++++++++++++++++++++++++++++++ drivers/leds/led-class.c | 40 ++- drivers/leds/led-core.c | 48 +++ drivers/leds/led-triggers.c | 20 +- include/linux/led-class-flash.h | 273 +++++++++++++++++ include/linux/leds.h | 66 ++++ 8 files changed, 1091 insertions(+), 13 deletions(-) create mode 100644 drivers/leds/led-class-flash.c create mode 100644 include/linux/led-class-flash.h
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
PATCH v5 1/4 leds: Improve and export led_update_brightness
led_update_brightness helper function used to be exploited only locally in the led-class.c module, where its result was being passed to the brightness_show sysfs callback. With the introduction of v4l2-flash subdevice the same functionality becomes required for reading current brightness from a LED device. This patch adds checking of return value of the brightness_get callback and moves the led_update_brightness() function to the LED subsystem public API.
--- drivers/leds/led-class.c | 6 ------ drivers/leds/led-core.c | 16 ++++++++++++++++ include/linux/leds.h | 10 ++++++++++ 3 files changed, 26 insertions(+), 6 deletions(-)
drivers/leds/led-class.c +0 -6
@@ -23,12 +23,6 @@static struct class *leds_class; -static void led_update_brightness (struct led_classdev *led_cdev) -{ -if (led_cdev->brightness_get) - led_cdev->brightness = led_cdev->brightness_get (led_cdev); -} -static ssize_t brightness_show (struct device *dev,struct device_attribute *attr,char *buf) {
drivers/leds/led-core.c +16 -0
@@ -127,3 +127,19 @@ void led_set_brightness(struct led_classdev *led_cdev,__led_set_brightness (led_cdev, brightness); }EXPORT_SYMBOL (led_set_brightness); + +int led_update_brightness (struct led_classdev *led_cdev) +{ +int ret =0 ; + +if (led_cdev->brightness_get) { + ret = led_cdev->brightness_get (led_cdev); +if (ret >=0 ) { + led_cdev->brightness = ret; +return 0 ; + } + } + +return ret; +} +EXPORT_SYMBOL (led_update_brightness);
include/linux/leds.h +10 -0
@@ -139,6 +139,16 @@ extern void led_blink_set_oneshot(struct led_classdev *led_cdev,*/ extern void led_set_brightness (struct led_classdev *led_cdev,enum led_brightness brightness); +/** +* led_update_brightness - update LED brightness +* @led_cdev: the LED to query +* +* Get an LED's current brightness and update led_cdev->brightness +* member with the obtained value. +* +* Returns: 0 on success or negative error value on failure +*/ +extern int led_update_brightness (struct led_classdev *led_cdev);/* * LED Triggers
Signature · 1 line
1.7.9.5
Re: [PATCH/RFC v5 1/4] leds: Improve and export led_update_brightness
Quoted 8 lines · Jacek Anaszewski
led_update_brightnesshelper function used to be exploited only locally in theled-class.cmodule, where its result was being passed to thebrightness_showsysfs callback. With the introduction of v4l2-flash subdevice the same functionality becomes required for reading current brightness from a LED device. This patch adds checking of return value of thebrightness_getcallback and moves theled_update_brightness()function to the LED subsystem public API.
This one looks good to me.
Thanks,
-Bryan
Quoted 75 lines
Signed-off-by Jacek Anaszewski <[email protected]>Acked-by Kyungmin Park <[email protected]>Cc Bryan Wu <[email protected]>Cc Richard Purdie <[email protected]>--- drivers/leds/led-class.c | 6 ------ drivers/leds/led-core.c | 16 ++++++++++++++++ include/linux/leds.h | 10 ++++++++++ 3 files changed, 26 insertions(+), 6 deletions(-)drivers/leds/led-class.c +0
-6@@ -23,12 +23,6 @@static struct class *leds_class; -static void led_update_brightness (struct led_classdev *led_cdev) -{ -if (led_cdev->brightness_get) - led_cdev->brightness = led_cdev->brightness_get (led_cdev); -} -static ssize_t brightness_show (struct device *dev,struct device_attribute *attr,char *buf) {drivers/leds/led-core.c +16
-0@@ -127,3 +127,19 @@ void led_set_brightness(struct led_classdev *led_cdev,__led_set_brightness (led_cdev, brightness); }EXPORT_SYMBOL (led_set_brightness); + +int led_update_brightness (struct led_classdev *led_cdev) +{ +int ret =0 ; + +if (led_cdev->brightness_get) { + ret = led_cdev->brightness_get (led_cdev); +if (ret >=0 ) { + led_cdev->brightness = ret; +return 0 ; + } + } + +return ret; +} +EXPORT_SYMBOL (led_update_brightness);include/linux/leds.h +10
-1@@ -139,6 +139,16 @@ extern void led_blink_set_oneshot(struct led_classdev *led_cdev,*/ extern void led_set_brightness (struct led_classdev *led_cdev,enum led_brightness brightness); +/** +* led_update_brightness - update LED brightness +* @led_cdev: the LED to query +* +* Get an LED's current brightness and update led_cdev->brightness +* member with the obtained value. +* +* Returns: 0 on success or negative error value on failure +*/ +extern int led_update_brightness (struct led_classdev *led_cdev);/* * LED Triggers -- 1.7.9.5
Re: [PATCH/RFC v5 1/4] leds: Improve and export led_update_brightness
Quoted 11 lines · Bryan Wu
Quoted 8 lines · Jacek Anaszewski
led_update_brightnesshelper function used to be exploited only locally in theled-class.cmodule, where its result was being passed to thebrightness_showsysfs callback. With the introduction of v4l2-flash subdevice the same functionality becomes required for reading current brightness from a LED device. This patch adds checking of return value of thebrightness_getcallback and moves theled_update_brightness()function to the LED subsystem public API.
Quoted 4 lines
This one looks good to me.
Thanks,
-Bryan
Merged, no need to update this patch then.
-Bryan
Quoted 75 lines
Quoted 75 lines
Signed-off-by Jacek Anaszewski <[email protected]>Acked-by Kyungmin Park <[email protected]>Cc Bryan Wu <[email protected]>Cc Richard Purdie <[email protected]>--- drivers/leds/led-class.c | 6 ------ drivers/leds/led-core.c | 16 ++++++++++++++++ include/linux/leds.h | 10 ++++++++++ 3 files changed, 26 insertions(+), 6 deletions(-)drivers/leds/led-class.c +0
-6@@ -23,12 +23,6 @@static struct class *leds_class; -static void led_update_brightness (struct led_classdev *led_cdev) -{ -if (led_cdev->brightness_get) - led_cdev->brightness = led_cdev->brightness_get (led_cdev); -} -static ssize_t brightness_show (struct device *dev,struct device_attribute *attr,char *buf) {drivers/leds/led-core.c +16
-0@@ -127,3 +127,19 @@ void led_set_brightness(struct led_classdev *led_cdev,__led_set_brightness (led_cdev, brightness); }EXPORT_SYMBOL (led_set_brightness); + +int led_update_brightness (struct led_classdev *led_cdev) +{ +int ret =0 ; + +if (led_cdev->brightness_get) { + ret = led_cdev->brightness_get (led_cdev); +if (ret >=0 ) { + led_cdev->brightness = ret; +return 0 ; + } + } + +return ret; +} +EXPORT_SYMBOL (led_update_brightness);include/linux/leds.h +10
-1@@ -139,6 +139,16 @@ extern void led_blink_set_oneshot(struct led_classdev *led_cdev,*/ extern void led_set_brightness (struct led_classdev *led_cdev,enum led_brightness brightness); +/** +* led_update_brightness - update LED brightness +* @led_cdev: the LED to query +* +* Get an LED's current brightness and update led_cdev->brightness +* member with the obtained value. +* +* Returns: 0 on success or negative error value on failure +*/ +extern int led_update_brightness (struct led_classdev *led_cdev);/* * LED Triggers -- 1.7.9.5
PATCH v5 2/4 leds: implement sysfs interface locking mechanism
In reply to Jacek AnaszewskiAdd a mechanism for locking LED subsystem sysfs interface. This patch prepares ground for addition of LED Flash Class extension, whose API will be integrated with V4L2 Flash API. Such a fusion enforces introducing a locking scheme, which will secure consistent access to the LED Flash Class device.
The mechanism being introduced allows for disabling LED subsystem sysfs interface by calling led_sysfs_lock function and enabling it by calling led_sysfs_unlock. The functions alter the LED_SYSFS_LOCK flag state and must be called under mutex lock. The state of the lock is checked with use of led_sysfs_is_locked function. Such a design allows for providing immediate feedback to the user space on whether the LED Flash Class device is available or is under V4L2 Flash sub-device control.
--- drivers/leds/led-class.c | 23 ++++++++++++++++++++--- drivers/leds/led-core.c | 18 ++++++++++++++++++ drivers/leds/led-triggers.c | 15 ++++++++++++--- include/linux/leds.h | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 82 insertions(+), 6 deletions(-)
drivers/leds/led-class.c +20 -3
@@ -39,17 +39,31 @@ static ssize_t brightness_store(struct device *dev, {struct led_classdev *led_cdev =dev_get_drvdata (dev);unsigned long state; -ssize_t ret = -EINVAL ; +ssize_t ret; + +#ifdef CONFIG_V4L2_FLASH_LED_CLASS +mutex_lock (&led_cdev->led_lock); + +if (led_sysfs_is_locked (led_cdev)) { + ret = -EBUSY ; + goto unlock; + } +#endif ret =kstrtoul (buf,10 , &state);if (ret) -return ret; + goto unlock;if (state ==LED_OFF )led_trigger_remove (led_cdev);__led_set_brightness (led_cdev, state); -return size; + ret = size; +unlock: +#ifdef CONFIG_V4L2_FLASH_LED_CLASS +mutex_unlock (&led_cdev->led_lock); +#endif +return ret; }static DEVICE_ATTR_RW (brightness);
@@ -215,6 +229,7 @@ int led_classdev_register(struct device *parent, struct led_classdev *led_cdev)#ifdef CONFIG_LEDS_TRIGGERS init_rwsem (&led_cdev->trigger_lock);#endif +mutex_init (&led_cdev->led_lock);/* add to the list of leds */ down_write (&leds_list_lock);list_add_tail (&led_cdev->node, &leds_list);
@@ -266,6 +281,8 @@ void led_classdev_unregister(struct led_classdev *led_cdev)down_write (&leds_list_lock);list_del (&led_cdev->node);up_write (&leds_list_lock); + +mutex_destroy (&led_cdev->led_lock); }EXPORT_SYMBOL_GPL (led_classdev_unregister);
drivers/leds/led-core.c +18 -0
@@ -143,3 +143,21 @@ int led_update_brightness(struct led_classdev *led_cdev)return ret; }EXPORT_SYMBOL (led_update_brightness); + +/* Caller must ensure led_cdev->led_lock held */ +void led_sysfs_lock (struct led_classdev *led_cdev) +{ +lockdep_assert_held (&led_cdev->led_lock); + + led_cdev->flags |=LED_SYSFS_LOCK ; +} +EXPORT_SYMBOL_GPL (led_sysfs_lock); + +/* Caller must ensure led_cdev->led_lock held */ +void led_sysfs_unlock (struct led_classdev *led_cdev) +{ +lockdep_assert_held (&led_cdev->led_lock); + + led_cdev->flags &= ~LED_SYSFS_LOCK ; +} +EXPORT_SYMBOL_GPL (led_sysfs_unlock);
drivers/leds/led-triggers.c +12 -3
@@ -37,6 +37,11 @@ ssize_t led_trigger_store(struct device *dev, struct device_attribute *attr,char trigger_name[TRIG_NAME_MAX ];struct led_trigger *trig;size_t len; +int ret = count; + +#ifdef CONFIG_V4L2_FLASH_LED_CLASS +mutex_lock (&led_cdev->led_lock); +#endif trigger_name[sizeof (trigger_name) -1 ] ='\0' ;strncpy (trigger_name, buf,sizeof (trigger_name) -1 );
@@ -47,7 +52,7 @@ ssize_t led_trigger_store(struct device *dev, struct device_attribute *attr,if (!strcmp (trigger_name,"none" )) {led_trigger_remove (led_cdev); -return count; + goto exit_unlock; }down_read (&triggers_list_lock);
@@ -58,12 +63,16 @@ ssize_t led_trigger_store(struct device *dev, struct device_attribute *attr,up_write (&led_cdev->trigger_lock);up_read (&triggers_list_lock); -return count; + goto exit_unlock; } }up_read (&triggers_list_lock); -return -EINVAL ; +exit_unlock: +#ifdef CONFIG_V4L2_FLASH_LED_CLASS +mutex_unlock (&led_cdev->led_lock); +#endif +return ret; }EXPORT_SYMBOL_GPL (led_trigger_store);
include/linux/leds.h +32 -0
@@ -13,6 +13,7 @@#define __LINUX_LEDS_H_INCLUDED#include <linux/list.h> +#include <linux/mutex.h> #include <linux/rwsem.h> #include <linux/spinlock.h> #include <linux/workqueue.h>
@@ -41,6 +42,7 @@ struct led_classdev {#define LED_BLINK_ONESHOT (1 << 17)#define LED_BLINK_ONESHOT_STOP (1 << 18)#define LED_BLINK_INVERT (1 << 19) +#define LED_SYSFS_LOCK (1 << 20)/* Set LED brightness level */ /* Must not sleep, use a workqueue if needed */
@@ -84,6 +86,9 @@ struct led_classdev {/* true if activated - deactivate routine uses it to do cleanup */ bool activated;#endif + +/* Ensures consistent access to the LED Flash Class device */ +struct mutex led_lock; }; extern int led_classdev_register(struct device *parent,
@@ -150,6 +155,33 @@ extern void led_set_brightness(struct led_classdev *led_cdev,*/ extern int led_update_brightness (struct led_classdev *led_cdev); +/** +* led_sysfs_lock - lock LED sysfs interface +* @led_cdev: the LED to set +* +* Lock the LED's sysfs interface +*/ +extern void led_sysfs_lock (struct led_classdev *led_cdev); + +/** +* led_sysfs_unlock - unlock LED sysfs interface +* @led_cdev: the LED to set +* +* Unlock the LED's sysfs interface +*/ +extern void led_sysfs_unlock (struct led_classdev *led_cdev); + +/** +* led_sysfs_is_locked +* @led_cdev: the LED to query +* +* Returns: true if the sysfs interface of the led is locked +*/ +static inline bool led_sysfs_is_locked (struct led_classdev *led_cdev) +{ +return led_cdev->flags &LED_SYSFS_LOCK ; +} +/* * LED Triggers */
Signature · 1 line
1.7.9.5
Re: [PATCH/RFC v5 2/4] leds: implement sysfs interface locking mechanism
Quoted 32 lines · Jacek Anaszewski
Add a mechanism for locking LED subsystem sysfs interface. This patch prepares ground for addition of LED Flash Class extension, whose API will be integrated with V4L2 Flash API. Such a fusion enforces introducing a locking scheme, which will secure consistent access to the LED Flash Class device.
The mechanism being introduced allows for disabling LED subsystem sysfs interface by calling
led_sysfs_lockfunction and enabling it by callingled_sysfs_unlock. The functions alter theLED_SYSFS_LOCKflag state and must be called under mutex lock. The state of the lock is checked with use ofled_sysfs_is_lockedfunction. Such a design allows for providing immediate feedback to the user space on whether the LED Flash Class device is available or is under V4L2 Flash sub-device control.Signed-off-by Jacek Anaszewski <[email protected]>Acked-by Kyungmin Park <[email protected]>Cc Bryan Wu <[email protected]>Cc Richard Purdie <[email protected]>--- drivers/leds/led-class.c | 23 ++++++++++++++++++++--- drivers/leds/led-core.c | 18 ++++++++++++++++++ drivers/leds/led-triggers.c | 15 ++++++++++++--- include/linux/leds.h | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 82 insertions(+), 6 deletions(-)drivers/leds/led-class.c +0
-0
drivers/leds/led-class.c static ssize_t brightness_store(struct device *dev, · line 44
Quoted 7 lines
drivers/leds/led-class.c +3
-1@@ -39,17 +39,31 @@ static ssize_t brightness_store(struct device *dev, {struct led_classdev *led_cdev =dev_get_drvdata (dev);unsigned long state; -ssize_t ret = -EINVAL ; +ssize_t ret; + +#ifdef CONFIG_V4L2_FLASH_LED_CLASS
Can we remove this #ifdef? Following code looks good to the common LED class.
drivers/leds/led-class.c static ssize_t brightness_store(struct device *dev, · line 45
Quoted 1 line
drivers/leds/led-class.c +1
-0+mutex_lock (&led_cdev->led_lock);
Can we choose more meaningful name instead of led_lock here? Then use led_sysfs_enable() instead of led_sysfs_unlock() led_sysfs_disable instead of led_sysfs_lock() led_sysfs_is_disabled instead of led_sysfs_is_locked()
And the flag LED_SYSFS_LOCK -> LED_SYSFS_DISABLE
I was just confused by the name lock and unlock and mutex lock.
The idea looks good to me.
Thanks,
-Bryan
Quoted 180 lines
drivers/leds/led-class.c +16
-2+ +if (led_sysfs_is_locked (led_cdev)) { + ret = -EBUSY ; + goto unlock; + } +#endif ret =kstrtoul (buf,10 , &state);if (ret) -return ret; + goto unlock;if (state ==LED_OFF )led_trigger_remove (led_cdev);__led_set_brightness (led_cdev, state); -return size; + ret = size; +unlock: +#ifdef CONFIG_V4L2_FLASH_LED_CLASS +mutex_unlock (&led_cdev->led_lock); +#endif +return ret; }static DEVICE_ATTR_RW (brightness);@@ -215,6 +229,7 @@ int led_classdev_register(struct device *parent, struct led_classdev *led_cdev)#ifdef CONFIG_LEDS_TRIGGERS init_rwsem (&led_cdev->trigger_lock);#endif +mutex_init (&led_cdev->led_lock);/* add to the list of leds */ down_write (&leds_list_lock);list_add_tail (&led_cdev->node, &leds_list);@@ -266,6 +281,8 @@ void led_classdev_unregister(struct led_classdev *led_cdev)down_write (&leds_list_lock);list_del (&led_cdev->node);up_write (&leds_list_lock); + +mutex_destroy (&led_cdev->led_lock); }EXPORT_SYMBOL_GPL (led_classdev_unregister);drivers/leds/led-core.c +18
-0@@ -143,3 +143,21 @@ int led_update_brightness(struct led_classdev *led_cdev)return ret; }EXPORT_SYMBOL (led_update_brightness); + +/* Caller must ensure led_cdev->led_lock held */ +void led_sysfs_lock (struct led_classdev *led_cdev) +{ +lockdep_assert_held (&led_cdev->led_lock); + + led_cdev->flags |=LED_SYSFS_LOCK ; +} +EXPORT_SYMBOL_GPL (led_sysfs_lock); + +/* Caller must ensure led_cdev->led_lock held */ +void led_sysfs_unlock (struct led_classdev *led_cdev) +{ +lockdep_assert_held (&led_cdev->led_lock); + + led_cdev->flags &= ~LED_SYSFS_LOCK ; +} +EXPORT_SYMBOL_GPL (led_sysfs_unlock);drivers/leds/led-triggers.c +12
-3@@ -37,6 +37,11 @@ ssize_t led_trigger_store(struct device *dev, struct device_attribute *attr,char trigger_name[TRIG_NAME_MAX ];struct led_trigger *trig;size_t len; +int ret = count; + +#ifdef CONFIG_V4L2_FLASH_LED_CLASS +mutex_lock (&led_cdev->led_lock); +#endif trigger_name[sizeof (trigger_name) -1 ] ='\0' ;strncpy (trigger_name, buf,sizeof (trigger_name) -1 );@@ -47,7 +52,7 @@ ssize_t led_trigger_store(struct device *dev, struct device_attribute *attr,if (!strcmp (trigger_name,"none" )) {led_trigger_remove (led_cdev); -return count; + goto exit_unlock; }down_read (&triggers_list_lock);@@ -58,12 +63,16 @@ ssize_t led_trigger_store(struct device *dev, struct device_attribute *attr,up_write (&led_cdev->trigger_lock);up_read (&triggers_list_lock); -return count; + goto exit_unlock; } }up_read (&triggers_list_lock); -return -EINVAL ; +exit_unlock: +#ifdef CONFIG_V4L2_FLASH_LED_CLASS +mutex_unlock (&led_cdev->led_lock); +#endif +return ret; }EXPORT_SYMBOL_GPL (led_trigger_store);include/linux/leds.h +32
-1@@ -13,6 +13,7 @@#define __LINUX_LEDS_H_INCLUDED#include <linux/list.h> +#include <linux/mutex.h> #include <linux/rwsem.h> #include <linux/spinlock.h> #include <linux/workqueue.h> @@ -41,6 +42,7 @@ struct led_classdev {#define LED_BLINK_ONESHOT (1 << 17)#define LED_BLINK_ONESHOT_STOP (1 << 18)#define LED_BLINK_INVERT (1 << 19) +#define LED_SYSFS_LOCK (1 << 20)/* Set LED brightness level */ /* Must not sleep, use a workqueue if needed */ @@ -84,6 +86,9 @@ struct led_classdev {/* true if activated - deactivate routine uses it to do cleanup */ bool activated;#endif + +/* Ensures consistent access to the LED Flash Class device */ +struct mutex led_lock; }; extern int led_classdev_register(struct device *parent,@@ -150,6 +155,33 @@ extern void led_set_brightness(struct led_classdev *led_cdev,*/ extern int led_update_brightness (struct led_classdev *led_cdev); +/** +* led_sysfs_lock - lock LED sysfs interface +* @led_cdev: the LED to set +* +* Lock the LED's sysfs interface +*/ +extern void led_sysfs_lock (struct led_classdev *led_cdev); + +/** +* led_sysfs_unlock - unlock LED sysfs interface +* @led_cdev: the LED to set +* +* Unlock the LED's sysfs interface +*/ +extern void led_sysfs_unlock (struct led_classdev *led_cdev); + +/** +* led_sysfs_is_locked +* @led_cdev: the LED to query +* +* Returns: true if the sysfs interface of the led is locked +*/ +static inline bool led_sysfs_is_locked (struct led_classdev *led_cdev) +{ +return led_cdev->flags &LED_SYSFS_LOCK ; +} +/* * LED Triggers */ --1.7.9.5
Re: [PATCH/RFC v5 2/4] leds: implement sysfs interface locking mechanism
Hi Bryan,
Thanks for a review.
Quoted 29 lines · Bryan Wu
Quoted 27 lines · Jacek Anaszewski
Add a mechanism for locking LED subsystem sysfs interface. This patch prepares ground for addition of LED Flash Class extension, whose API will be integrated with V4L2 Flash API. Such a fusion enforces introducing a locking scheme, which will secure consistent access to the LED Flash Class device.
The mechanism being introduced allows for disabling LED subsystem sysfs interface by calling
led_sysfs_lockfunction and enabling it by callingled_sysfs_unlock. The functions alter theLED_SYSFS_LOCKflag state and must be called under mutex lock. The state of the lock is checked with use ofled_sysfs_is_lockedfunction. Such a design allows for providing immediate feedback to the user space on whether the LED Flash Class device is available or is under V4L2 Flash sub-device control.Signed-off-by Jacek Anaszewski <[email protected]>Acked-by Kyungmin Park <[email protected]>Cc Bryan Wu <[email protected]>Cc Richard Purdie <rpurdie-Fm38FmjxZ/[email protected]>--- drivers/leds/led-class.c | 23 ++++++++++++++++++++--- drivers/leds/led-core.c | 18 ++++++++++++++++++ drivers/leds/led-triggers.c | 15 ++++++++++++--- include/linux/leds.h | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 82 insertions(+), 6 deletions(-)
Quoted 14 lines
drivers/leds/led-class.c static ssize_t brightness_store(struct device *dev, · line 44
Quoted 12 lines
drivers/leds/led-class.c +3
-1@@ -39,17 +39,31 @@ static ssize_t brightness_store(struct device *dev, {struct led_classdev *led_cdev =dev_get_drvdata (dev);unsigned long state; -ssize_t ret = -EINVAL ; +ssize_t ret; + +#ifdef CONFIG_V4L2_FLASH_LED_CLASS Can we remove this #ifdef? Following code looks good to the common LED class.
Sure.
Quoted 7 lines
drivers/leds/led-class.c static ssize_t brightness_store(struct device *dev, · line 45
Quoted 1 line
drivers/leds/led-class.c +1
-0+mutex_lock (&led_cdev->led_lock);Can we choose more meaningful name instead of
led_lockhere? Then useled_sysfs_enable()instead ofled_sysfs_unlock()led_sysfs_disableinstead ofled_sysfs_lock()led_sysfs_is_disabledinstead ofled_sysfs_is_locked()
Quoted 5 lines
And the flag
LED_SYSFS_LOCK->LED_SYSFS_DISABLEI was just confused by the name lock and unlock and mutex lock.
The idea looks good to me.
Indeed, this naming will be more intuitive.
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
PATCH v5 3/4 leds: add API for setting torch brightness
In reply to Jacek AnaszewskiThis patch prepares ground for addition of LED Flash Class extension to the LED subsystem. Since turning the torch on must have guaranteed immediate effect the brightness_set op can't be used for it. Drivers must schedule a work queue task in this op to be compatible with led-triggers, which call brightess_set from timer irqs. In order to address this limitation a torch_brightness_set op and led_set_torch_brightness API is introduced. Setting brightness sysfs attribute will result in calling brightness_set op for LED Class devices and torch_brightness_set op for LED Flash Class devices, whereas triggers will still call brightness op in both cases.
--- drivers/leds/led-class.c | 9 +++++++-- drivers/leds/led-core.c | 14 ++++++++++++++ include/linux/leds.h | 21 +++++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-)
drivers/leds/led-class.c +7 -2
@@ -56,9 +56,14 @@ static ssize_t brightness_store(struct device *dev,if (state ==LED_OFF )led_trigger_remove (led_cdev); -__led_set_brightness (led_cdev, state); - ret = size; +if (led_cdev->flags &LED_DEV_CAP_TORCH ) + ret =led_set_torch_brightness (led_cdev, state); +else +__led_set_brightness (led_cdev, state); + +if (!ret) + ret = size; unlock:#ifdef CONFIG_V4L2_FLASH_LED_CLASS mutex_unlock (&led_cdev->led_lock);
drivers/leds/led-core.c +14 -0
@@ -144,6 +144,20 @@ int led_update_brightness(struct led_classdev *led_cdev) }EXPORT_SYMBOL (led_update_brightness); +int led_set_torch_brightness (struct led_classdev *led_cdev, +enum led_brightness brightness) +{ +int ret =0 ; + + led_cdev->brightness =min (brightness, led_cdev->max_brightness); + +if (!(led_cdev->flags &LED_SUSPENDED )) + ret = led_cdev->torch_brightness_set (led_cdev, + led_cdev->brightness); +return ret; +} +EXPORT_SYMBOL_GPL (led_set_torch_brightness); +/* Caller must ensure led_cdev->led_lock held */ void led_sysfs_lock (struct led_classdev *led_cdev) {
include/linux/leds.h +21 -0
@@ -43,11 +43,21 @@ struct led_classdev {#define LED_BLINK_ONESHOT_STOP (1 << 18)#define LED_BLINK_INVERT (1 << 19)#define LED_SYSFS_LOCK (1 << 20) +#define LED_DEV_CAP_TORCH (1 << 21)/* Set LED brightness level */ /* Must not sleep, use a workqueue if needed */ void (*brightness_set)(struct led_classdev *led_cdev,enum led_brightness brightness); +/* +* Set LED brightness immediately - it is required for flash led +* devices as they require setting torch brightness to have immediate +* effect. brightness_set op cannot be used for this purpose because +* the led drivers schedule a work queue task in it to allow for +* being called from led-triggers, i.e. from the timer irq context. +*/ +int (*torch_brightness_set)(struct led_classdev *led_cdev, +enum led_brightness brightness);/* Get LED brightness level */ enum led_brightness (*brightness_get)(struct led_classdev *led_cdev);
@@ -156,6 +166,17 @@ extern void led_set_brightness(struct led_classdev *led_cdev,extern int led_update_brightness (struct led_classdev *led_cdev);/** +* led_set_torch_brightness - set torch LED brightness +* @led_cdev: the LED to set +* @brightness: the brightness to set it to +* +* Returns: 0 on success or negative error value on failure +* +* Set a torch LED's brightness. +*/ +extern int led_set_torch_brightness (struct led_classdev *led_cdev, +enum led_brightness brightness); +/** * led_sysfs_lock - lock LED sysfs interface * @led_cdev: the LED to set *
Signature · 1 line
1.7.9.5
PATCH v5 4/4 leds: Add LED Flash Class wrapper to LED subsystem
In reply to Jacek AnaszewskiSome LED devices support two operation modes - torch and flash. This patch provides support for flash LED devices in the LED subsystem by introducing new sysfs attributes and kernel internal interface. The attributes being introduced are: flash_brightness, flash_strobe, flash_timeout, max_flash_timeout, max_flash_brightness, flash_fault, external_strobe, indicator_brightness, max_indicator_brightness. All the flash related features are placed in a separate module.
The modifications aim to be compatible with V4L2 framework requirements related to the flash devices management. The design assumes that V4L2 sub-device can take of the LED class device control and communicate with it through the kernel internal interface. When V4L2 Flash sub-device file is opened, the LED class device sysfs interface is made unavailable.
--- drivers/leds/Kconfig | 11 + drivers/leds/Makefile | 1 + drivers/leds/led-class-flash.c | 645 +++++++++++++++++++++++++++++++++++++++ drivers/leds/led-class.c | 4 + drivers/leds/led-triggers.c | 5 + include/linux/led-class-flash.h | 273 +++++++++++++++++ include/linux/leds.h | 3 + 7 files changed, 942 insertions(+) create mode 100644 drivers/leds/led-class-flash.c create mode 100644 include/linux/led-class-flash.h
drivers/leds/Kconfig +11 -0
@@ -19,6 +19,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
drivers/leds/Makefile +1 -0
@@ -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 +645 -0
645 lines not on this page · raw message
drivers/leds/led-class.c +4 -0
@@ -189,6 +189,10 @@ EXPORT_SYMBOL_GPL(led_classdev_suspend);void led_classdev_resume (struct led_classdev *led_cdev) { led_cdev->brightness_set (led_cdev, led_cdev->brightness); + +if (led_cdev->flash_resume) + led_cdev->flash_resume (led_cdev); + led_cdev->flags &= ~LED_SUSPENDED ; }EXPORT_SYMBOL_GPL (led_classdev_resume);
drivers/leds/led-triggers.c +5 -0
@@ -43,6 +43,11 @@ ssize_t led_trigger_store(struct device *dev, struct device_attribute *attr,mutex_lock (&led_cdev->led_lock);#endif +if (led_sysfs_is_locked (led_cdev)) { + ret = -EBUSY ; + goto exit_unlock; + } + trigger_name[sizeof (trigger_name) -1 ] ='\0' ;strncpy (trigger_name, buf,sizeof (trigger_name) -1 ); len =strlen (trigger_name);
include/linux/led-class-flash.h new file +273 -0
273 lines not on this page · raw message
include/linux/leds.h +3 -0
@@ -44,6 +44,8 @@ struct led_classdev {#define LED_BLINK_INVERT (1 << 19)#define LED_SYSFS_LOCK (1 << 20)#define LED_DEV_CAP_TORCH (1 << 21) +#define LED_DEV_CAP_FLASH (1 << 22) +#define LED_DEV_CAP_INDICATOR (1 << 23)/* Set LED brightness level */ /* Must not sleep, use a workqueue if needed */
@@ -82,6 +84,7 @@ struct led_classdev {unsigned long blink_delay_on, blink_delay_off;struct delayed_work blink_work;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