Release 4.7 drivers/leds/leds-pwm.c
/*
* linux/drivers/leds-pwm.c
*
* simple PWM based LED control
*
* Copyright 2009 Luotao Fu @ Pengutronix (l.fu@pengutronix.de)
*
* based on leds-gpio.c by Raphael Assenat <raph@8d.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/module.h>
#include <linux/kernel.h>
#include <linux/platform_device.h>
#include <linux/of_platform.h>
#include <linux/fb.h>
#include <linux/leds.h>
#include <linux/err.h>
#include <linux/pwm.h>
#include <linux/leds_pwm.h>
#include <linux/slab.h>
struct led_pwm_data {
struct led_classdev cdev;
struct pwm_device *pwm;
unsigned int active_low;
unsigned int period;
int duty;
bool can_sleep;
};
struct led_pwm_priv {
int num_leds;
struct led_pwm_data leds[0];
};
static void __led_pwm_set(struct led_pwm_data *led_dat)
{
int new_duty = led_dat->duty;
pwm_config(led_dat->pwm, new_duty, led_dat->period);
if (new_duty == 0)
pwm_disable(led_dat->pwm);
else
pwm_enable(led_dat->pwm);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
florian vaussard | florian vaussard | 52 | 100.00% | 1 | 100.00% |
| Total | 52 | 100.00% | 1 | 100.00% |
static void led_pwm_set(struct led_classdev *led_cdev,
enum led_brightness brightness)
{
struct led_pwm_data *led_dat =
container_of(led_cdev, struct led_pwm_data, cdev);
unsigned int max = led_dat->cdev.max_brightness;
unsigned long long duty = led_dat->period;
duty *= brightness;
do_div(duty, max);
if (led_dat->active_low)
duty = led_dat->period - duty;
led_dat->duty = duty;
__led_pwm_set(led_dat);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
luotao fu | luotao fu | 50 | 58.82% | 1 | 16.67% |
xiubo li | xiubo li | 15 | 17.65% | 1 | 16.67% |
russell king | russell king | 14 | 16.47% | 1 | 16.67% |
florian vaussard | florian vaussard | 2 | 2.35% | 1 | 16.67% |
jacek anaszewski | jacek anaszewski | 2 | 2.35% | 1 | 16.67% |
lars-peter clausen | lars-peter clausen | 2 | 2.35% | 1 | 16.67% |
| Total | 85 | 100.00% | 6 | 100.00% |
static int led_pwm_set_blocking(struct led_classdev *led_cdev,
enum led_brightness brightness)
{
led_pwm_set(led_cdev, brightness);
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
jacek anaszewski | jacek anaszewski | 21 | 84.00% | 1 | 50.00% |
luotao fu | luotao fu | 4 | 16.00% | 1 | 50.00% |
| Total | 25 | 100.00% | 2 | 100.00% |
static inline size_t sizeof_pwm_leds_priv(int num_leds)
{
return sizeof(struct led_pwm_priv) +
(sizeof(struct led_pwm_data) * num_leds);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
peter ujfalusi | peter ujfalusi | 27 | 100.00% | 1 | 100.00% |
| Total | 27 | 100.00% | 1 | 100.00% |
static void led_pwm_cleanup(struct led_pwm_priv *priv)
{
while (priv->num_leds--)
led_classdev_unregister(&priv->leds[priv->num_leds].cdev);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
russell king | russell king | 33 | 100.00% | 1 | 100.00% |
| Total | 33 | 100.00% | 1 | 100.00% |
static int led_pwm_add(struct device *dev, struct led_pwm_priv *priv,
struct led_pwm *led, struct device_node *child)
{
struct led_pwm_data *led_data = &priv->leds[priv->num_leds];
struct pwm_args pargs;
int ret;
led_data->active_low = led->active_low;
led_data->cdev.name = led->name;
led_data->cdev.default_trigger = led->default_trigger;
led_data->cdev.brightness = LED_OFF;
led_data->cdev.max_brightness = led->max_brightness;
led_data->cdev.flags = LED_CORE_SUSPENDRESUME;
if (child)
led_data->pwm = devm_of_pwm_get(dev, child, NULL);
else
led_data->pwm = devm_pwm_get(dev, led->name);
if (IS_ERR(led_data->pwm)) {
ret = PTR_ERR(led_data->pwm);
dev_err(dev, "unable to request PWM for %s: %d\n",
led->name, ret);
return ret;
}
led_data->can_sleep = pwm_can_sleep(led_data->pwm);
if (!led_data->can_sleep)
led_data->cdev.brightness_set = led_pwm_set;
else
led_data->cdev.brightness_set_blocking = led_pwm_set_blocking;
/*
* FIXME: pwm_apply_args() should be removed when switching to the
* atomic PWM API.
*/
pwm_apply_args(led_data->pwm);
pwm_get_args(led_data->pwm, &pargs);
led_data->period = pargs.period;
if (!led_data->period && (led->pwm_period_ns > 0))
led_data->period = led->pwm_period_ns;
ret = led_classdev_register(dev, &led_data->cdev);
if (ret == 0) {
priv->num_leds++;
led_pwm_set(&led_data->cdev, led_data->cdev.brightness);
} else {
dev_err(dev, "failed to register PWM led for %s: %d\n",
led->name, ret);
}
return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
russell king | russell king | 113 | 36.33% | 2 | 22.22% |
peter ujfalusi | peter ujfalusi | 100 | 32.15% | 2 | 22.22% |
linus torvalds | linus torvalds | 31 | 9.97% | 1 | 11.11% |
boris brezillon | boris brezillon | 22 | 7.07% | 1 | 11.11% |
florian vaussard | florian vaussard | 16 | 5.14% | 1 | 11.11% |
jacek anaszewski | jacek anaszewski | 15 | 4.82% | 1 | 11.11% |
markus hofstaetter | markus hofstaetter | 14 | 4.50% | 1 | 11.11% |
| Total | 311 | 100.00% | 9 | 100.00% |
static int led_pwm_create_of(struct device *dev, struct led_pwm_priv *priv)
{
struct device_node *child;
struct led_pwm led;
int ret = 0;
memset(&led, 0, sizeof(led));
for_each_child_of_node(dev->of_node, child) {
led.name = of_get_property(child, "label", NULL) ? :
child->name;
led.default_trigger = of_get_property(child,
"linux,default-trigger", NULL);
led.active_low = of_property_read_bool(child, "active-low");
of_property_read_u32(child, "max-brightness",
&led.max_brightness);
ret = led_pwm_add(dev, priv, &led, child);
if (ret) {
of_node_put(child);
break;
}
}
return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
peter ujfalusi | peter ujfalusi | 95 | 70.90% | 2 | 50.00% |
russell king | russell king | 39 | 29.10% | 2 | 50.00% |
| Total | 134 | 100.00% | 4 | 100.00% |
static int led_pwm_probe(struct platform_device *pdev)
{
struct led_pwm_platform_data *pdata = dev_get_platdata(&pdev->dev);
struct led_pwm_priv *priv;
int count, i;
int ret = 0;
if (pdata)
count = pdata->num_leds;
else
count = of_get_child_count(pdev->dev.of_node);
if (!count)
return -EINVAL;
priv = devm_kzalloc(&pdev->dev, sizeof_pwm_leds_priv(count),
GFP_KERNEL);
if (!priv)
return -ENOMEM;
if (pdata) {
for (i = 0; i < count; i++) {
ret = led_pwm_add(&pdev->dev, priv, &pdata->leds[i],
NULL);
if (ret)
break;
}
} else {
ret = led_pwm_create_of(&pdev->dev, priv);
}
if (ret) {
led_pwm_cleanup(priv);
return ret;
}
platform_set_drvdata(pdev, priv);
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
luotao fu | luotao fu | 93 | 50.82% | 1 | 9.09% |
peter ujfalusi | peter ujfalusi | 59 | 32.24% | 3 | 27.27% |
russell king | russell king | 11 | 6.01% | 2 | 18.18% |
sachin kamat | sachin kamat | 6 | 3.28% | 1 | 9.09% |
alexandre belloni | alexandre belloni | 5 | 2.73% | 1 | 9.09% |
jingoo han | jingoo han | 4 | 2.19% | 1 | 9.09% |
florian vaussard | florian vaussard | 3 | 1.64% | 1 | 9.09% |
axel lin | axel lin | 2 | 1.09% | 1 | 9.09% |
| Total | 183 | 100.00% | 11 | 100.00% |
static int led_pwm_remove(struct platform_device *pdev)
{
struct led_pwm_priv *priv = platform_get_drvdata(pdev);
led_pwm_cleanup(priv);
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
luotao fu | luotao fu | 21 | 72.41% | 1 | 25.00% |
florian vaussard | florian vaussard | 4 | 13.79% | 1 | 25.00% |
peter ujfalusi | peter ujfalusi | 3 | 10.34% | 1 | 25.00% |
russell king | russell king | 1 | 3.45% | 1 | 25.00% |
| Total | 29 | 100.00% | 4 | 100.00% |
static const struct of_device_id of_pwm_leds_match[] = {
{ .compatible = "pwm-leds", },
{},
};
MODULE_DEVICE_TABLE(of, of_pwm_leds_match);
static struct platform_driver led_pwm_driver = {
.probe = led_pwm_probe,
.remove = led_pwm_remove,
.driver = {
.name = "leds_pwm",
.of_match_table = of_pwm_leds_match,
},
};
module_platform_driver(led_pwm_driver);
MODULE_AUTHOR("Luotao Fu <l.fu@pengutronix.de>");
MODULE_DESCRIPTION("generic PWM LED driver");
MODULE_LICENSE("GPL v2");
MODULE_ALIAS("platform:leds-pwm");
Overall Contributors
| Person | Tokens | Prop | Commits | CommitProp |
peter ujfalusi | peter ujfalusi | 330 | 31.88% | 3 | 13.04% |
luotao fu | luotao fu | 265 | 25.60% | 1 | 4.35% |
russell king | russell king | 211 | 20.39% | 5 | 21.74% |
florian vaussard | florian vaussard | 83 | 8.02% | 1 | 4.35% |
jacek anaszewski | jacek anaszewski | 38 | 3.67% | 1 | 4.35% |
linus torvalds | linus torvalds | 31 | 3.00% | 1 | 4.35% |
boris brezillon | boris brezillon | 22 | 2.13% | 1 | 4.35% |
xiubo li | xiubo li | 15 | 1.45% | 1 | 4.35% |
markus hofstaetter | markus hofstaetter | 14 | 1.35% | 1 | 4.35% |
sachin kamat | sachin kamat | 6 | 0.58% | 1 | 4.35% |
alexandre belloni | alexandre belloni | 5 | 0.48% | 1 | 4.35% |
jingoo han | jingoo han | 4 | 0.39% | 1 | 4.35% |
axel lin | axel lin | 4 | 0.39% | 2 | 8.70% |
tejun heo | tejun heo | 3 | 0.29% | 1 | 4.35% |
lars-peter clausen | lars-peter clausen | 2 | 0.19% | 1 | 4.35% |
uwe kleine-koenig | uwe kleine-koenig | 2 | 0.19% | 1 | 4.35% |
| Total | 1035 | 100.00% | 23 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.