Release 4.7 drivers/leds/leds-gpio.c
/*
* LEDs driver for GPIOs
*
* Copyright (C) 2007 8D Technologies inc.
* Raphael Assenat <raph@8d.com>
* Copyright (C) 2008 Freescale Semiconductor, Inc.
*
* 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/err.h>
#include <linux/gpio.h>
#include <linux/gpio/consumer.h>
#include <linux/kernel.h>
#include <linux/leds.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/property.h>
#include <linux/slab.h>
struct gpio_led_data {
struct led_classdev cdev;
struct gpio_desc *gpiod;
u8 can_sleep;
u8 blinking;
int (*platform_gpio_blink_set)(struct gpio_desc *desc, int state,
unsigned long *delay_on, unsigned long *delay_off);
};
static void gpio_led_set(struct led_classdev *led_cdev,
enum led_brightness value)
{
struct gpio_led_data *led_dat =
container_of(led_cdev, struct gpio_led_data, cdev);
int level;
if (value == LED_OFF)
level = 0;
else
level = 1;
if (led_dat->blinking) {
led_dat->platform_gpio_blink_set(led_dat->gpiod, level,
NULL, NULL);
led_dat->blinking = 0;
} else {
if (led_dat->can_sleep)
gpiod_set_value_cansleep(led_dat->gpiod, level);
else
gpiod_set_value(led_dat->gpiod, level);
}
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
raphael assenat | raphael assenat | 55 | 52.38% | 1 | 20.00% |
benjamin herrenschmidt | benjamin herrenschmidt | 29 | 27.62% | 1 | 20.00% |
jacek anaszewski | jacek anaszewski | 17 | 16.19% | 1 | 20.00% |
mika westerberg | mika westerberg | 4 | 3.81% | 2 | 40.00% |
| Total | 105 | 100.00% | 5 | 100.00% |
static int gpio_led_set_blocking(struct led_classdev *led_cdev,
enum led_brightness value)
{
gpio_led_set(led_cdev, value);
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
jacek anaszewski | jacek anaszewski | 25 | 100.00% | 1 | 100.00% |
| Total | 25 | 100.00% | 1 | 100.00% |
static int gpio_blink_set(struct led_classdev *led_cdev,
unsigned long *delay_on, unsigned long *delay_off)
{
struct gpio_led_data *led_dat =
container_of(led_cdev, struct gpio_led_data, cdev);
led_dat->blinking = 1;
return led_dat->platform_gpio_blink_set(led_dat->gpiod, GPIO_LED_BLINK,
delay_on, delay_off);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
herbert valerio riedel | herbert valerio riedel | 47 | 81.03% | 1 | 33.33% |
benjamin herrenschmidt | benjamin herrenschmidt | 8 | 13.79% | 1 | 33.33% |
mika westerberg | mika westerberg | 3 | 5.17% | 1 | 33.33% |
| Total | 58 | 100.00% | 3 | 100.00% |
static int create_gpio_led(const struct gpio_led *template,
struct gpio_led_data *led_dat, struct device *parent,
int (*blink_set)(struct gpio_desc *, int, unsigned long *,
unsigned long *))
{
int ret, state;
led_dat->gpiod = template->gpiod;
if (!led_dat->gpiod) {
/*
* This is the legacy code path for platform code that
* still uses GPIO numbers. Ultimately we would like to get
* rid of this block completely.
*/
unsigned long flags = GPIOF_OUT_INIT_LOW;
/* skip leds that aren't available */
if (!gpio_is_valid(template->gpio)) {
dev_info(parent, "Skipping unavailable LED gpio %d (%s)\n",
template->gpio, template->name);
return 0;
}
if (template->active_low)
flags |= GPIOF_ACTIVE_LOW;
ret = devm_gpio_request_one(parent, template->gpio, flags,
template->name);
if (ret < 0)
return ret;
led_dat->gpiod = gpio_to_desc(template->gpio);
if (!led_dat->gpiod)
return -EINVAL;
}
led_dat->cdev.name = template->name;
led_dat->cdev.default_trigger = template->default_trigger;
led_dat->can_sleep = gpiod_cansleep(led_dat->gpiod);
if (!led_dat->can_sleep)
led_dat->cdev.brightness_set = gpio_led_set;
else
led_dat->cdev.brightness_set_blocking = gpio_led_set_blocking;
led_dat->blinking = 0;
if (blink_set) {
led_dat->platform_gpio_blink_set = blink_set;
led_dat->cdev.blink_set = gpio_blink_set;
}
if (template->default_state == LEDS_GPIO_DEFSTATE_KEEP)
state = !!gpiod_get_value_cansleep(led_dat->gpiod);
else
state = (template->default_state == LEDS_GPIO_DEFSTATE_ON);
led_dat->cdev.brightness = state ? LED_FULL : LED_OFF;
if (!template->retain_state_suspended)
led_dat->cdev.flags |= LED_CORE_SUSPENDRESUME;
if (template->panic_indicator)
led_dat->cdev.flags |= LED_PANIC_INDICATOR;
ret = gpiod_direction_output(led_dat->gpiod, state);
if (ret < 0)
return ret;
return led_classdev_register(parent, &led_dat->cdev);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
trent piepho | trent piepho | 75 | 21.80% | 2 | 9.09% |
raphael assenat | raphael assenat | 56 | 16.28% | 1 | 4.55% |
mika westerberg | mika westerberg | 55 | 15.99% | 2 | 9.09% |
david brownell | david brownell | 35 | 10.17% | 3 | 13.64% |
jacek anaszewski | jacek anaszewski | 24 | 6.98% | 1 | 4.55% |
timo teras | timo teras | 24 | 6.98% | 1 | 4.55% |
herbert valerio riedel | herbert valerio riedel | 18 | 5.23% | 1 | 4.55% |
richard purdie | richard purdie | 15 | 4.36% | 2 | 9.09% |
ezequiel garcia | ezequiel garcia | 14 | 4.07% | 1 | 4.55% |
geert uytterhoeven | geert uytterhoeven | 11 | 3.20% | 2 | 9.09% |
benjamin herrenschmidt | benjamin herrenschmidt | 6 | 1.74% | 1 | 4.55% |
wei yongjun | wei yongjun | 3 | 0.87% | 1 | 4.55% |
jingoo han | jingoo han | 3 | 0.87% | 1 | 4.55% |
sachin kamat | sachin kamat | 3 | 0.87% | 1 | 4.55% |
michal simek | michal simek | 1 | 0.29% | 1 | 4.55% |
dmitry eremin-baryshkov | dmitry eremin-baryshkov | 1 | 0.29% | 1 | 4.55% |
| Total | 344 | 100.00% | 22 | 100.00% |
struct gpio_leds_priv {
int num_leds;
struct gpio_led_data leds[];
};
static inline int sizeof_gpio_leds_priv(int num_leds)
{
return sizeof(struct gpio_leds_priv) +
(sizeof(struct gpio_led_data) * num_leds);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
grant likely | grant likely | 27 | 100.00% | 1 | 100.00% |
| Total | 27 | 100.00% | 1 | 100.00% |
static struct gpio_leds_priv *gpio_leds_create(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct fwnode_handle *child;
struct gpio_leds_priv *priv;
int count, ret;
struct device_node *np;
count = device_get_child_node_count(dev);
if (!count)
return ERR_PTR(-ENODEV);
priv = devm_kzalloc(dev, sizeof_gpio_leds_priv(count), GFP_KERNEL);
if (!priv)
return ERR_PTR(-ENOMEM);
device_for_each_child_node(dev, child) {
struct gpio_led led = {};
const char *state = NULL;
led.gpiod = devm_get_gpiod_from_child(dev, NULL, child);
if (IS_ERR(led.gpiod)) {
fwnode_handle_put(child);
ret = PTR_ERR(led.gpiod);
goto err;
}
np = to_of_node(child);
if (fwnode_property_present(child, "label")) {
fwnode_property_read_string(child, "label", &led.name);
} else {
if (IS_ENABLED(CONFIG_OF) && !led.name && np)
led.name = np->name;
if (!led.name) {
ret = -EINVAL;
goto err;
}
}
fwnode_property_read_string(child, "linux,default-trigger",
&led.default_trigger);
if (!fwnode_property_read_string(child, "default-state",
&state)) {
if (!strcmp(state, "keep"))
led.default_state = LEDS_GPIO_DEFSTATE_KEEP;
else if (!strcmp(state, "on"))
led.default_state = LEDS_GPIO_DEFSTATE_ON;
else
led.default_state = LEDS_GPIO_DEFSTATE_OFF;
}
if (fwnode_property_present(child, "retain-state-suspended"))
led.retain_state_suspended = 1;
if (fwnode_property_present(child, "panic-indicator"))
led.panic_indicator = 1;
ret = create_gpio_led(&led, &priv->leds[priv->num_leds],
dev, NULL);
if (ret < 0) {
fwnode_handle_put(child);
goto err;
}
priv->num_leds++;
}
return priv;
err:
for (count = priv->num_leds - 1; count >= 0; count--)
led_classdev_unregister(&priv->leds[count].cdev);
return ERR_PTR(ret);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
grant likely | grant likely | 144 | 35.73% | 1 | 5.56% |
fabio estevam | fabio estevam | 57 | 14.14% | 2 | 11.11% |
rafael j. wysocki | rafael j. wysocki | 51 | 12.66% | 1 | 5.56% |
trent piepho | trent piepho | 35 | 8.68% | 1 | 5.56% |
raphael assenat | raphael assenat | 34 | 8.44% | 1 | 5.56% |
ezequiel garcia | ezequiel garcia | 15 | 3.72% | 1 | 5.56% |
robin gong | robin gong | 14 | 3.47% | 1 | 5.56% |
roland stigge | roland stigge | 14 | 3.47% | 1 | 5.56% |
jacek anaszewski | jacek anaszewski | 11 | 2.73% | 2 | 11.11% |
soren brinkmann | soren brinkmann | 10 | 2.48% | 1 | 5.56% |
sebastian hesselbarth | sebastian hesselbarth | 6 | 1.49% | 1 | 5.56% |
david brownell | david brownell | 4 | 0.99% | 1 | 5.56% |
sachin kamat | sachin kamat | 3 | 0.74% | 1 | 5.56% |
tobias klauser | tobias klauser | 2 | 0.50% | 1 | 5.56% |
oliver schinagl | oliver schinagl | 2 | 0.50% | 1 | 5.56% |
alexander sverdlin | alexander sverdlin | 1 | 0.25% | 1 | 5.56% |
| Total | 403 | 100.00% | 18 | 100.00% |
static const struct of_device_id of_gpio_leds_match[] = {
{ .compatible = "gpio-leds", },
{},
};
MODULE_DEVICE_TABLE(of, of_gpio_leds_match);
static int gpio_led_probe(struct platform_device *pdev)
{
struct gpio_led_platform_data *pdata = dev_get_platdata(&pdev->dev);
struct gpio_leds_priv *priv;
int i, ret = 0;
if (pdata && pdata->num_leds) {
priv = devm_kzalloc(&pdev->dev,
sizeof_gpio_leds_priv(pdata->num_leds),
GFP_KERNEL);
if (!priv)
return -ENOMEM;
priv->num_leds = pdata->num_leds;
for (i = 0; i < priv->num_leds; i++) {
ret = create_gpio_led(&pdata->leds[i],
&priv->leds[i],
&pdev->dev, pdata->gpio_blink_set);
if (ret < 0) {
/* On failure: unwind the led creations */
for (i = i - 1; i >= 0; i--)
led_classdev_unregister(
&priv->leds[i].cdev);
return ret;
}
}
} else {
priv = gpio_leds_create(pdev);
if (IS_ERR(priv))
return PTR_ERR(priv);
}
platform_set_drvdata(pdev, priv);
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
grant likely | grant likely | 99 | 49.01% | 3 | 30.00% |
trent piepho | trent piepho | 82 | 40.59% | 2 | 20.00% |
roland stigge | roland stigge | 7 | 3.47% | 1 | 10.00% |
sachin kamat | sachin kamat | 6 | 2.97% | 1 | 10.00% |
jingoo han | jingoo han | 4 | 1.98% | 1 | 10.00% |
jacek anaszewski | jacek anaszewski | 3 | 1.49% | 1 | 10.00% |
rafael j. wysocki | rafael j. wysocki | 1 | 0.50% | 1 | 10.00% |
| Total | 202 | 100.00% | 10 | 100.00% |
static int gpio_led_remove(struct platform_device *pdev)
{
struct gpio_leds_priv *priv = platform_get_drvdata(pdev);
int i;
for (i = 0; i < priv->num_leds; i++)
led_classdev_unregister(&priv->leds[i].cdev);
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
trent piepho | trent piepho | 42 | 76.36% | 1 | 20.00% |
grant likely | grant likely | 9 | 16.36% | 2 | 40.00% |
jacek anaszewski | jacek anaszewski | 3 | 5.45% | 1 | 20.00% |
tobias klauser | tobias klauser | 1 | 1.82% | 1 | 20.00% |
| Total | 55 | 100.00% | 5 | 100.00% |
static void gpio_led_shutdown(struct platform_device *pdev)
{
struct gpio_leds_priv *priv = platform_get_drvdata(pdev);
int i;
for (i = 0; i < priv->num_leds; i++) {
struct gpio_led_data *led = &priv->leds[i];
gpio_led_set(&led->cdev, LED_OFF);
}
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
heiko schocher | heiko schocher | 64 | 100.00% | 1 | 100.00% |
| Total | 64 | 100.00% | 1 | 100.00% |
static struct platform_driver gpio_led_driver = {
.probe = gpio_led_probe,
.remove = gpio_led_remove,
.shutdown = gpio_led_shutdown,
.driver = {
.name = "leds-gpio",
.of_match_table = of_gpio_leds_match,
},
};
module_platform_driver(gpio_led_driver);
MODULE_AUTHOR("Raphael Assenat <raph@8d.com>, Trent Piepho <tpiepho@freescale.com>");
MODULE_DESCRIPTION("GPIO LED driver");
MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:leds-gpio");
Overall Contributors
| Person | Tokens | Prop | Commits | CommitProp |
grant likely | grant likely | 312 | 21.38% | 4 | 7.84% |
trent piepho | trent piepho | 268 | 18.37% | 2 | 3.92% |
raphael assenat | raphael assenat | 174 | 11.93% | 1 | 1.96% |
jacek anaszewski | jacek anaszewski | 83 | 5.69% | 2 | 3.92% |
herbert valerio riedel | herbert valerio riedel | 83 | 5.69% | 1 | 1.96% |
mika westerberg | mika westerberg | 73 | 5.00% | 2 | 3.92% |
heiko schocher | heiko schocher | 69 | 4.73% | 1 | 1.96% |
fabio estevam | fabio estevam | 57 | 3.91% | 2 | 3.92% |
rafael j. wysocki | rafael j. wysocki | 54 | 3.70% | 1 | 1.96% |
benjamin herrenschmidt | benjamin herrenschmidt | 49 | 3.36% | 1 | 1.96% |
david brownell | david brownell | 44 | 3.02% | 4 | 7.84% |
ezequiel garcia | ezequiel garcia | 29 | 1.99% | 1 | 1.96% |
timo teras | timo teras | 24 | 1.64% | 1 | 1.96% |
roland stigge | roland stigge | 21 | 1.44% | 1 | 1.96% |
richard purdie | richard purdie | 19 | 1.30% | 3 | 5.88% |
geert uytterhoeven | geert uytterhoeven | 14 | 0.96% | 3 | 5.88% |
robin gong | robin gong | 14 | 0.96% | 1 | 1.96% |
sachin kamat | sachin kamat | 14 | 0.96% | 3 | 5.88% |
soren brinkmann | soren brinkmann | 10 | 0.69% | 1 | 1.96% |
paolo pisati | paolo pisati | 7 | 0.48% | 1 | 1.96% |
jingoo han | jingoo han | 7 | 0.48% | 2 | 3.92% |
sebastian hesselbarth | sebastian hesselbarth | 6 | 0.41% | 1 | 1.96% |
axel lin | axel lin | 6 | 0.41% | 1 | 1.96% |
xiubo li | xiubo li | 5 | 0.34% | 1 | 1.96% |
wei yongjun | wei yongjun | 3 | 0.21% | 1 | 1.96% |
tobias klauser | tobias klauser | 3 | 0.21% | 2 | 3.92% |
oliver schinagl | oliver schinagl | 2 | 0.14% | 1 | 1.96% |
tejun heo | tejun heo | 2 | 0.14% | 1 | 1.96% |
kay sievers | kay sievers | 2 | 0.14% | 1 | 1.96% |
mark brown | mark brown | 2 | 0.14% | 1 | 1.96% |
michal simek | michal simek | 1 | 0.07% | 1 | 1.96% |
alexander sverdlin | alexander sverdlin | 1 | 0.07% | 1 | 1.96% |
dmitry eremin-baryshkov | dmitry eremin-baryshkov | 1 | 0.07% | 1 | 1.96% |
| Total | 1459 | 100.00% | 51 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.