cregit-Linux how code gets into the kernel

Release 4.7 drivers/leds/leds-gpio.c

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

PersonTokensPropCommitsCommitProp
raphael assenatraphael assenat5552.38%120.00%
benjamin herrenschmidtbenjamin herrenschmidt2927.62%120.00%
jacek anaszewskijacek anaszewski1716.19%120.00%
mika westerbergmika westerberg43.81%240.00%
Total105100.00%5100.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

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

PersonTokensPropCommitsCommitProp
herbert valerio riedelherbert valerio riedel4781.03%133.33%
benjamin herrenschmidtbenjamin herrenschmidt813.79%133.33%
mika westerbergmika westerberg35.17%133.33%
Total58100.00%3100.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

PersonTokensPropCommitsCommitProp
trent piephotrent piepho7521.80%29.09%
raphael assenatraphael assenat5616.28%14.55%
mika westerbergmika westerberg5515.99%29.09%
david brownelldavid brownell3510.17%313.64%
jacek anaszewskijacek anaszewski246.98%14.55%
timo terastimo teras246.98%14.55%
herbert valerio riedelherbert valerio riedel185.23%14.55%
richard purdierichard purdie154.36%29.09%
ezequiel garciaezequiel garcia144.07%14.55%
geert uytterhoevengeert uytterhoeven113.20%29.09%
benjamin herrenschmidtbenjamin herrenschmidt61.74%14.55%
wei yongjunwei yongjun30.87%14.55%
jingoo hanjingoo han30.87%14.55%
sachin kamatsachin kamat30.87%14.55%
michal simekmichal simek10.29%14.55%
dmitry eremin-baryshkovdmitry eremin-baryshkov10.29%14.55%
Total344100.00%22100.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

PersonTokensPropCommitsCommitProp
grant likelygrant likely27100.00%1100.00%
Total27100.00%1100.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

PersonTokensPropCommitsCommitProp
grant likelygrant likely14435.73%15.56%
fabio estevamfabio estevam5714.14%211.11%
rafael j. wysockirafael j. wysocki5112.66%15.56%
trent piephotrent piepho358.68%15.56%
raphael assenatraphael assenat348.44%15.56%
ezequiel garciaezequiel garcia153.72%15.56%
robin gongrobin gong143.47%15.56%
roland stiggeroland stigge143.47%15.56%
jacek anaszewskijacek anaszewski112.73%211.11%
soren brinkmannsoren brinkmann102.48%15.56%
sebastian hesselbarthsebastian hesselbarth61.49%15.56%
david brownelldavid brownell40.99%15.56%
sachin kamatsachin kamat30.74%15.56%
tobias klausertobias klauser20.50%15.56%
oliver schinagloliver schinagl20.50%15.56%
alexander sverdlinalexander sverdlin10.25%15.56%
Total403100.00%18100.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

PersonTokensPropCommitsCommitProp
grant likelygrant likely9949.01%330.00%
trent piephotrent piepho8240.59%220.00%
roland stiggeroland stigge73.47%110.00%
sachin kamatsachin kamat62.97%110.00%
jingoo hanjingoo han41.98%110.00%
jacek anaszewskijacek anaszewski31.49%110.00%
rafael j. wysockirafael j. wysocki10.50%110.00%
Total202100.00%10100.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

PersonTokensPropCommitsCommitProp
trent piephotrent piepho4276.36%120.00%
grant likelygrant likely916.36%240.00%
jacek anaszewskijacek anaszewski35.45%120.00%
tobias klausertobias klauser11.82%120.00%
Total55100.00%5100.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

PersonTokensPropCommitsCommitProp
heiko schocherheiko schocher64100.00%1100.00%
Total64100.00%1100.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

PersonTokensPropCommitsCommitProp
grant likelygrant likely31221.38%47.84%
trent piephotrent piepho26818.37%23.92%
raphael assenatraphael assenat17411.93%11.96%
jacek anaszewskijacek anaszewski835.69%23.92%
herbert valerio riedelherbert valerio riedel835.69%11.96%
mika westerbergmika westerberg735.00%23.92%
heiko schocherheiko schocher694.73%11.96%
fabio estevamfabio estevam573.91%23.92%
rafael j. wysockirafael j. wysocki543.70%11.96%
benjamin herrenschmidtbenjamin herrenschmidt493.36%11.96%
david brownelldavid brownell443.02%47.84%
ezequiel garciaezequiel garcia291.99%11.96%
timo terastimo teras241.64%11.96%
roland stiggeroland stigge211.44%11.96%
richard purdierichard purdie191.30%35.88%
geert uytterhoevengeert uytterhoeven140.96%35.88%
robin gongrobin gong140.96%11.96%
sachin kamatsachin kamat140.96%35.88%
soren brinkmannsoren brinkmann100.69%11.96%
paolo pisatipaolo pisati70.48%11.96%
jingoo hanjingoo han70.48%23.92%
sebastian hesselbarthsebastian hesselbarth60.41%11.96%
axel linaxel lin60.41%11.96%
xiubo lixiubo li50.34%11.96%
wei yongjunwei yongjun30.21%11.96%
tobias klausertobias klauser30.21%23.92%
oliver schinagloliver schinagl20.14%11.96%
tejun heotejun heo20.14%11.96%
kay sieverskay sievers20.14%11.96%
mark brownmark brown20.14%11.96%
michal simekmichal simek10.07%11.96%
alexander sverdlinalexander sverdlin10.07%11.96%
dmitry eremin-baryshkovdmitry eremin-baryshkov10.07%11.96%
Total1459100.00%51100.00%
Directory: drivers/leds
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
{% endraw %}