cregit-Linux how code gets into the kernel

Release 4.7 drivers/leds/led-core.c

Directory: drivers/leds
/*
 * 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

PersonTokensPropCommitsCommitProp
heiner kallweitheiner kallweit38100.00%1100.00%
Total38100.00%1100.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

PersonTokensPropCommitsCommitProp
heiner kallweitheiner kallweit36100.00%1100.00%
Total36100.00%1100.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); led_cdev->flags &= ~LED_BLINK_SW; return; } if (led_cdev->flags & LED_BLINK_ONESHOT_STOP) { led_cdev->flags &= ~(LED_BLINK_ONESHOT_STOP | LED_BLINK_SW); return; } brightness = led_get_brightness(led_cdev); if (!brightness) { /* Time to switch the LED on. */ 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. * Do it only if there is no pending blink brightness * change, to avoid overwriting the new value. */ if (!(led_cdev->flags & LED_BLINK_BRIGHTNESS_CHANGE)) led_cdev->blink_brightness = brightness; else led_cdev->flags &= ~LED_BLINK_BRIGHTNESS_CHANGE; 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 (led_cdev->flags & LED_BLINK_ONESHOT) { if (led_cdev->flags & LED_BLINK_INVERT) { if (brightness) led_cdev->flags |= LED_BLINK_ONESHOT_STOP; } else { if (!brightness) led_cdev->flags |= LED_BLINK_ONESHOT_STOP; } } mod_timer(&led_cdev->blink_timer, jiffies + msecs_to_jiffies(delay)); }

Contributors

PersonTokensPropCommitsCommitProp
jacek anaszewskijacek anaszewski20294.84%375.00%
tony makkieltony makkiel115.16%125.00%
Total213100.00%4100.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 (led_cdev->flags & LED_BLINK_DISABLE) { led_cdev->delayed_set_value = LED_OFF; led_stop_software_blink(led_cdev); led_cdev->flags &= ~LED_BLINK_DISABLE; } 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

PersonTokensPropCommitsCommitProp
jacek anaszewskijacek anaszewski9774.62%360.00%
heiner kallweitheiner kallweit3325.38%240.00%
Total130100.00%5100.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; } led_cdev->flags |= LED_BLINK_SW; mod_timer(&led_cdev->blink_timer, jiffies + 1); }

Contributors

PersonTokensPropCommitsCommitProp
bryan wubryan wu9782.20%120.00%
stefan sorensenstefan sorensen97.63%120.00%
tony makkieltony makkiel65.08%120.00%
jiri kosinajiri kosina43.39%120.00%
jacek anaszewskijacek anaszewski21.69%120.00%
Total118100.00%5100.00%


static void led_blink_setup(struct led_classdev *led_cdev, unsigned long *delay_on, unsigned long *delay_off) { if (!(led_cdev->flags & LED_BLINK_ONESHOT) && 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

PersonTokensPropCommitsCommitProp
bryan wubryan wu6987.34%266.67%
fabio baltierifabio baltieri1012.66%133.33%
Total79100.00%3100.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

PersonTokensPropCommitsCommitProp
jacek anaszewskijacek anaszewski36100.00%1100.00%
Total36100.00%1100.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); led_cdev->flags &= ~LED_BLINK_ONESHOT; led_cdev->flags &= ~LED_BLINK_ONESHOT_STOP; led_blink_setup(led_cdev, delay_on, delay_off); }

Contributors

PersonTokensPropCommitsCommitProp
fabio baltierifabio baltieri4996.08%150.00%
jiri kosinajiri kosina23.92%150.00%
Total51100.00%2100.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 ((led_cdev->flags & LED_BLINK_ONESHOT) && timer_pending(&led_cdev->blink_timer)) return; led_cdev->flags |= LED_BLINK_ONESHOT; led_cdev->flags &= ~LED_BLINK_ONESHOT_STOP; if (invert) led_cdev->flags |= LED_BLINK_INVERT; else led_cdev->flags &= ~LED_BLINK_INVERT; led_blink_setup(led_cdev, delay_on, delay_off); }

Contributors

PersonTokensPropCommitsCommitProp
fabio baltierifabio baltieri8097.56%150.00%
jiri kosinajiri kosina22.44%150.00%
Total82100.00%2100.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; led_cdev->flags &= ~LED_BLINK_SW; }

Contributors

PersonTokensPropCommitsCommitProp
fabio baltierifabio baltieri1437.84%240.00%
bryan wubryan wu1437.84%120.00%
tony makkieltony makkiel718.92%120.00%
jiri kosinajiri kosina25.41%120.00%
Total37100.00%5100.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 (led_cdev->flags & LED_BLINK_SW) { /* * 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) { led_cdev->flags |= LED_BLINK_DISABLE; schedule_work(&led_cdev->set_brightness_work); } else { led_cdev->flags |= LED_BLINK_BRIGHTNESS_CHANGE; led_cdev->blink_brightness = brightness; } return; } led_set_brightness_nosleep(led_cdev, brightness); }

Contributors

PersonTokensPropCommitsCommitProp
fabio baltierifabio baltieri2940.85%116.67%
jacek anaszewskijacek anaszewski2535.21%233.33%
bryan wubryan wu79.86%116.67%
stas sergeevstas sergeev68.45%116.67%
tony makkieltony makkiel45.63%116.67%
Total71100.00%6100.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

PersonTokensPropCommitsCommitProp
jacek anaszewskijacek anaszewski3892.68%150.00%
heiner kallweitheiner kallweit37.32%150.00%
Total41100.00%2100.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

PersonTokensPropCommitsCommitProp
jacek anaszewskijacek anaszewski45100.00%1100.00%
Total45100.00%1100.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

PersonTokensPropCommitsCommitProp
jacek anaszewskijacek anaszewski6198.39%150.00%
heiner kallweitheiner kallweit11.61%150.00%
Total62100.00%2100.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

PersonTokensPropCommitsCommitProp
jacek anaszewskijacek anaszewski52100.00%1100.00%
Total52100.00%1100.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

PersonTokensPropCommitsCommitProp
jacek anaszewskijacek anaszewski24100.00%1100.00%
Total24100.00%1100.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

PersonTokensPropCommitsCommitProp
jacek anaszewskijacek anaszewski25100.00%1100.00%
Total25100.00%1100.00%

EXPORT_SYMBOL_GPL(led_sysfs_enable);

Overall Contributors

PersonTokensPropCommitsCommitProp
jacek anaszewskijacek anaszewski65252.62%936.00%
bryan wubryan wu19415.66%28.00%
fabio baltierifabio baltieri19115.42%312.00%
heiner kallweitheiner kallweit1118.96%28.00%
richard purdierichard purdie302.42%28.00%
tony makkieltony makkiel282.26%14.00%
jiri kosinajiri kosina100.81%14.00%
stefan sorensenstefan sorensen90.73%14.00%
stas sergeevstas sergeev60.48%14.00%
marton nemethmarton nemeth40.32%14.00%
ingo molnaringo molnar30.24%14.00%
shuah khanshuah khan10.08%14.00%
Total1239100.00%25100.00%
Directory: drivers/leds
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
{% endraw %}