Release 4.11 drivers/leds/led-core.c
/*
* LED Class Core
*
* Copyright 2005-2006 Openedhand Ltd.
*
* Author: Richard Purdie <rpurdie@openedhand.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/kernel.h>
#include <linux/leds.h>
#include <linux/list.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/rwsem.h>
#include "leds.h"
DECLARE_RWSEM(leds_list_lock);
EXPORT_SYMBOL_GPL(leds_list_lock);
LIST_HEAD(leds_list);
EXPORT_SYMBOL_GPL(leds_list);
static int __led_set_brightness(struct led_classdev *led_cdev,
enum led_brightness value)
{
if (!led_cdev->brightness_set)
return -ENOTSUPP;
led_cdev->brightness_set(led_cdev, value);
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Heiner Kallweit | 38 | 100.00% | 1 | 100.00% |
Total | 38 | 100.00% | 1 | 100.00% |
static int __led_set_brightness_blocking(struct led_classdev *led_cdev,
enum led_brightness value)
{
if (!led_cdev->brightness_set_blocking)
return -ENOTSUPP;
return led_cdev->brightness_set_blocking(led_cdev, value);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Heiner Kallweit | 36 | 100.00% | 1 | 100.00% |
Total | 36 | 100.00% | 1 | 100.00% |
static void led_timer_function(unsigned long data)
{
struct led_classdev *led_cdev = (void *)data;
unsigned long brightness;
unsigned long delay;
if (!led_cdev->blink_delay_on || !led_cdev->blink_delay_off) {
led_set_brightness_nosleep(led_cdev, LED_OFF);
clear_bit(LED_BLINK_SW, &led_cdev->work_flags);
return;
}
if (test_and_clear_bit(LED_BLINK_ONESHOT_STOP,
&led_cdev->work_flags)) {
clear_bit(LED_BLINK_SW, &led_cdev->work_flags);
return;
}
brightness = led_get_brightness(led_cdev);
if (!brightness) {
/* Time to switch the LED on. */
if (test_and_clear_bit(LED_BLINK_BRIGHTNESS_CHANGE,
&led_cdev->work_flags))
brightness = led_cdev->new_blink_brightness;
else
brightness = led_cdev->blink_brightness;
delay = led_cdev->blink_delay_on;
} else {
/* Store the current brightness value to be able
* to restore it when the delay_off period is over.
*/
led_cdev->blink_brightness = brightness;
brightness = LED_OFF;
delay = led_cdev->blink_delay_off;
}
led_set_brightness_nosleep(led_cdev, brightness);
/* Return in next iteration if led is in one-shot mode and we are in
* the final blink state so that the led is toggled each delay_on +
* delay_off milliseconds in worst case.
*/
if (test_bit(LED_BLINK_ONESHOT, &led_cdev->work_flags)) {
if (test_bit(LED_BLINK_INVERT, &led_cdev->work_flags)) {
if (brightness)
set_bit(LED_BLINK_ONESHOT_STOP,
&led_cdev->work_flags);
} else {
if (!brightness)
set_bit(LED_BLINK_ONESHOT_STOP,
&led_cdev->work_flags);
}
}
mod_timer(&led_cdev->blink_timer, jiffies + msecs_to_jiffies(delay));
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Jacek Anaszewski | 163 | 69.36% | 2 | 40.00% |
Hans de Goede | 69 | 29.36% | 2 | 40.00% |
Tony Makkiel | 3 | 1.28% | 1 | 20.00% |
Total | 235 | 100.00% | 5 | 100.00% |
static void set_brightness_delayed(struct work_struct *ws)
{
struct led_classdev *led_cdev =
container_of(ws, struct led_classdev, set_brightness_work);
int ret = 0;
if (test_and_clear_bit(LED_BLINK_DISABLE, &led_cdev->work_flags)) {
led_cdev->delayed_set_value = LED_OFF;
led_stop_software_blink(led_cdev);
}
ret = __led_set_brightness(led_cdev, led_cdev->delayed_set_value);
if (ret == -ENOTSUPP)
ret = __led_set_brightness_blocking(led_cdev,
led_cdev->delayed_set_value);
if (ret < 0 &&
/* LED HW might have been unplugged, therefore don't warn */
!(ret == -ENODEV && (led_cdev->flags & LED_UNREGISTERING) &&
(led_cdev->flags & LED_HW_PLUGGABLE)))
dev_err(led_cdev->dev,
"Setting an LED's brightness failed (%d)\n", ret);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Jacek Anaszewski | 87 | 68.50% | 3 | 50.00% |
Heiner Kallweit | 33 | 25.98% | 2 | 33.33% |
Hans de Goede | 7 | 5.51% | 1 | 16.67% |
Total | 127 | 100.00% | 6 | 100.00% |
static void led_set_software_blink(struct led_classdev *led_cdev,
unsigned long delay_on,
unsigned long delay_off)
{
int current_brightness;
current_brightness = led_get_brightness(led_cdev);
if (current_brightness)
led_cdev->blink_brightness = current_brightness;
if (!led_cdev->blink_brightness)
led_cdev->blink_brightness = led_cdev->max_brightness;
led_cdev->blink_delay_on = delay_on;
led_cdev->blink_delay_off = delay_off;
/* never on - just set to off */
if (!delay_on) {
led_set_brightness_nosleep(led_cdev, LED_OFF);
return;
}
/* never off - just set to brightness */
if (!delay_off) {
led_set_brightness_nosleep(led_cdev,
led_cdev->blink_brightness);
return;
}
set_bit(LED_BLINK_SW, &led_cdev->work_flags);
mod_timer(&led_cdev->blink_timer, jiffies + 1);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Bryan Wu | 97 | 79.51% | 1 | 16.67% |
Stefan Sörensen | 9 | 7.38% | 1 | 16.67% |
Hans de Goede | 7 | 5.74% | 1 | 16.67% |
Jiri Kosina | 4 | 3.28% | 1 | 16.67% |
Tony Makkiel | 3 | 2.46% | 1 | 16.67% |
Jacek Anaszewski | 2 | 1.64% | 1 | 16.67% |
Total | 122 | 100.00% | 6 | 100.00% |
static void led_blink_setup(struct led_classdev *led_cdev,
unsigned long *delay_on,
unsigned long *delay_off)
{
if (!test_bit(LED_BLINK_ONESHOT, &led_cdev->work_flags) &&
led_cdev->blink_set &&
!led_cdev->blink_set(led_cdev, delay_on, delay_off))
return;
/* blink with 1 Hz as default if nothing specified */
if (!*delay_on && !*delay_off)
*delay_on = *delay_off = 500;
led_set_software_blink(led_cdev, *delay_on, *delay_off);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Bryan Wu | 69 | 85.19% | 2 | 50.00% |
Hans de Goede | 7 | 8.64% | 1 | 25.00% |
Fabio Baltieri | 5 | 6.17% | 1 | 25.00% |
Total | 81 | 100.00% | 4 | 100.00% |
void led_init_core(struct led_classdev *led_cdev)
{
INIT_WORK(&led_cdev->set_brightness_work, set_brightness_delayed);
setup_timer(&led_cdev->blink_timer, led_timer_function,
(unsigned long)led_cdev);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Jacek Anaszewski | 36 | 100.00% | 1 | 100.00% |
Total | 36 | 100.00% | 1 | 100.00% |
EXPORT_SYMBOL_GPL(led_init_core);
void led_blink_set(struct led_classdev *led_cdev,
unsigned long *delay_on,
unsigned long *delay_off)
{
del_timer_sync(&led_cdev->blink_timer);
clear_bit(LED_BLINK_ONESHOT, &led_cdev->work_flags);
clear_bit(LED_BLINK_ONESHOT_STOP, &led_cdev->work_flags);
led_blink_setup(led_cdev, delay_on, delay_off);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Fabio Baltieri | 41 | 71.93% | 1 | 33.33% |
Hans de Goede | 14 | 24.56% | 1 | 33.33% |
Jiri Kosina | 2 | 3.51% | 1 | 33.33% |
Total | 57 | 100.00% | 3 | 100.00% |
EXPORT_SYMBOL_GPL(led_blink_set);
void led_blink_set_oneshot(struct led_classdev *led_cdev,
unsigned long *delay_on,
unsigned long *delay_off,
int invert)
{
if (test_bit(LED_BLINK_ONESHOT, &led_cdev->work_flags) &&
timer_pending(&led_cdev->blink_timer))
return;
set_bit(LED_BLINK_ONESHOT, &led_cdev->work_flags);
clear_bit(LED_BLINK_ONESHOT_STOP, &led_cdev->work_flags);
if (invert)
set_bit(LED_BLINK_INVERT, &led_cdev->work_flags);
else
clear_bit(LED_BLINK_INVERT, &led_cdev->work_flags);
led_blink_setup(led_cdev, delay_on, delay_off);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Fabio Baltieri | 61 | 62.24% | 1 | 33.33% |
Hans de Goede | 35 | 35.71% | 1 | 33.33% |
Jiri Kosina | 2 | 2.04% | 1 | 33.33% |
Total | 98 | 100.00% | 3 | 100.00% |
EXPORT_SYMBOL_GPL(led_blink_set_oneshot);
void led_stop_software_blink(struct led_classdev *led_cdev)
{
del_timer_sync(&led_cdev->blink_timer);
led_cdev->blink_delay_on = 0;
led_cdev->blink_delay_off = 0;
clear_bit(LED_BLINK_SW, &led_cdev->work_flags);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Bryan Wu | 14 | 35.00% | 1 | 16.67% |
Fabio Baltieri | 14 | 35.00% | 2 | 33.33% |
Hans de Goede | 7 | 17.50% | 1 | 16.67% |
Tony Makkiel | 3 | 7.50% | 1 | 16.67% |
Jiri Kosina | 2 | 5.00% | 1 | 16.67% |
Total | 40 | 100.00% | 6 | 100.00% |
EXPORT_SYMBOL_GPL(led_stop_software_blink);
void led_set_brightness(struct led_classdev *led_cdev,
enum led_brightness brightness)
{
/*
* If software blink is active, delay brightness setting
* until the next timer tick.
*/
if (test_bit(LED_BLINK_SW, &led_cdev->work_flags)) {
/*
* If we need to disable soft blinking delegate this to the
* work queue task to avoid problems in case we are called
* from hard irq context.
*/
if (brightness == LED_OFF) {
set_bit(LED_BLINK_DISABLE, &led_cdev->work_flags);
schedule_work(&led_cdev->set_brightness_work);
} else {
set_bit(LED_BLINK_BRIGHTNESS_CHANGE,
&led_cdev->work_flags);
led_cdev->new_blink_brightness = brightness;
}
return;
}
led_set_brightness_nosleep(led_cdev, brightness);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Fabio Baltieri | 29 | 34.94% | 1 | 12.50% |
Hans de Goede | 22 | 26.51% | 2 | 25.00% |
Jacek Anaszewski | 18 | 21.69% | 2 | 25.00% |
Bryan Wu | 7 | 8.43% | 1 | 12.50% |
Stas Sergeev | 6 | 7.23% | 1 | 12.50% |
Tony Makkiel | 1 | 1.20% | 1 | 12.50% |
Total | 83 | 100.00% | 8 | 100.00% |
EXPORT_SYMBOL_GPL(led_set_brightness);
void led_set_brightness_nopm(struct led_classdev *led_cdev,
enum led_brightness value)
{
/* Use brightness_set op if available, it is guaranteed not to sleep */
if (!__led_set_brightness(led_cdev, value))
return;
/* If brightness setting can sleep, delegate it to a work queue task */
led_cdev->delayed_set_value = value;
schedule_work(&led_cdev->set_brightness_work);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Jacek Anaszewski | 38 | 92.68% | 1 | 50.00% |
Heiner Kallweit | 3 | 7.32% | 1 | 50.00% |
Total | 41 | 100.00% | 2 | 100.00% |
EXPORT_SYMBOL_GPL(led_set_brightness_nopm);
void led_set_brightness_nosleep(struct led_classdev *led_cdev,
enum led_brightness value)
{
led_cdev->brightness = min(value, led_cdev->max_brightness);
if (led_cdev->flags & LED_SUSPENDED)
return;
led_set_brightness_nopm(led_cdev, led_cdev->brightness);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Jacek Anaszewski | 45 | 100.00% | 1 | 100.00% |
Total | 45 | 100.00% | 1 | 100.00% |
EXPORT_SYMBOL_GPL(led_set_brightness_nosleep);
int led_set_brightness_sync(struct led_classdev *led_cdev,
enum led_brightness value)
{
if (led_cdev->blink_delay_on || led_cdev->blink_delay_off)
return -EBUSY;
led_cdev->brightness = min(value, led_cdev->max_brightness);
if (led_cdev->flags & LED_SUSPENDED)
return 0;
return __led_set_brightness_blocking(led_cdev, led_cdev->brightness);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Jacek Anaszewski | 61 | 98.39% | 1 | 50.00% |
Heiner Kallweit | 1 | 1.61% | 1 | 50.00% |
Total | 62 | 100.00% | 2 | 100.00% |
EXPORT_SYMBOL_GPL(led_set_brightness_sync);
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;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Jacek Anaszewski | 52 | 100.00% | 1 | 100.00% |
Total | 52 | 100.00% | 1 | 100.00% |
EXPORT_SYMBOL_GPL(led_update_brightness);
/* Caller must ensure led_cdev->led_access held */
void led_sysfs_disable(struct led_classdev *led_cdev)
{
lockdep_assert_held(&led_cdev->led_access);
led_cdev->flags |= LED_SYSFS_DISABLE;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Jacek Anaszewski | 24 | 100.00% | 1 | 100.00% |
Total | 24 | 100.00% | 1 | 100.00% |
EXPORT_SYMBOL_GPL(led_sysfs_disable);
/* Caller must ensure led_cdev->led_access held */
void led_sysfs_enable(struct led_classdev *led_cdev)
{
lockdep_assert_held(&led_cdev->led_access);
led_cdev->flags &= ~LED_SYSFS_DISABLE;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Jacek Anaszewski | 25 | 100.00% | 1 | 100.00% |
Total | 25 | 100.00% | 1 | 100.00% |
EXPORT_SYMBOL_GPL(led_sysfs_enable);
Overall Contributors
Person | Tokens | Prop | Commits | CommitProp |
Jacek Anaszewski | 596 | 45.81% | 9 | 33.33% |
Bryan Wu | 194 | 14.91% | 2 | 7.41% |
Hans de Goede | 168 | 12.91% | 2 | 7.41% |
Fabio Baltieri | 159 | 12.22% | 3 | 11.11% |
Heiner Kallweit | 111 | 8.53% | 2 | 7.41% |
Richard Purdie | 30 | 2.31% | 2 | 7.41% |
Jiri Kosina | 10 | 0.77% | 1 | 3.70% |
Tony Makkiel | 10 | 0.77% | 1 | 3.70% |
Stefan Sörensen | 9 | 0.69% | 1 | 3.70% |
Stas Sergeev | 6 | 0.46% | 1 | 3.70% |
Márton Németh | 4 | 0.31% | 1 | 3.70% |
Ingo Molnar | 3 | 0.23% | 1 | 3.70% |
Shuah Khan | 1 | 0.08% | 1 | 3.70% |
Total | 1301 | 100.00% | 27 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.