Release 4.12 drivers/leds/leds-regulator.c
  
  
  
/*
 * leds-regulator.c - LED class driver for regulator driven LEDs.
 *
 * Copyright (C) 2009 Antonio Ospite <ospite@studenti.unina.it>
 *
 * Inspired by leds-wm8350 driver.
 *
 * 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/err.h>
#include <linux/slab.h>
#include <linux/leds.h>
#include <linux/leds-regulator.h>
#include <linux/platform_device.h>
#include <linux/regulator/consumer.h>
#define to_regulator_led(led_cdev) \
	container_of(led_cdev, struct regulator_led, cdev)
struct regulator_led {
	
struct led_classdev cdev;
	
int enabled;
	
struct mutex mutex;
	
struct regulator *vcc;
};
static inline int led_regulator_get_max_brightness(struct regulator *supply)
{
	int ret;
	int voltage = regulator_list_voltage(supply, 0);
	if (voltage <= 0)
		return 1;
	/* even if regulator can't change voltages,
         * we still assume it can change status
         * and the LED can be turned on and off.
         */
	ret = regulator_set_voltage(supply, voltage, voltage);
	if (ret < 0)
		return 1;
	return regulator_count_voltages(supply);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Antonio Ospite | 61 | 100.00% | 1 | 100.00% | 
| Total | 61 | 100.00% | 1 | 100.00% | 
static int led_regulator_get_voltage(struct regulator *supply,
		enum led_brightness brightness)
{
	if (brightness == 0)
		return -EINVAL;
	return regulator_list_voltage(supply, brightness - 1);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Antonio Ospite | 35 | 100.00% | 1 | 100.00% | 
| Total | 35 | 100.00% | 1 | 100.00% | 
static void regulator_led_enable(struct regulator_led *led)
{
	int ret;
	if (led->enabled)
		return;
	ret = regulator_enable(led->vcc);
	if (ret != 0) {
		dev_err(led->cdev.dev, "Failed to enable vcc: %d\n", ret);
		return;
	}
	led->enabled = 1;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Antonio Ospite | 58 | 100.00% | 1 | 100.00% | 
| Total | 58 | 100.00% | 1 | 100.00% | 
static void regulator_led_disable(struct regulator_led *led)
{
	int ret;
	if (!led->enabled)
		return;
	ret = regulator_disable(led->vcc);
	if (ret != 0) {
		dev_err(led->cdev.dev, "Failed to disable vcc: %d\n", ret);
		return;
	}
	led->enabled = 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Antonio Ospite | 59 | 100.00% | 1 | 100.00% | 
| Total | 59 | 100.00% | 1 | 100.00% | 
static int regulator_led_brightness_set(struct led_classdev *led_cdev,
					 enum led_brightness value)
{
	struct regulator_led *led = to_regulator_led(led_cdev);
	int voltage;
	int ret = 0;
	mutex_lock(&led->mutex);
	if (value == LED_OFF) {
		regulator_led_disable(led);
		goto out;
	}
	if (led->cdev.max_brightness > 1) {
		voltage = led_regulator_get_voltage(led->vcc, value);
		dev_dbg(led->cdev.dev, "brightness: %d voltage: %d\n",
				value, voltage);
		ret = regulator_set_voltage(led->vcc, voltage, voltage);
		if (ret != 0)
			dev_err(led->cdev.dev, "Failed to set voltage %d: %d\n",
				voltage, ret);
	}
	regulator_led_enable(led);
out:
	mutex_unlock(&led->mutex);
	return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Antonio Ospite | 124 | 84.35% | 1 | 50.00% | 
| Andrew Lunn | 23 | 15.65% | 1 | 50.00% | 
| Total | 147 | 100.00% | 2 | 100.00% | 
static int regulator_led_probe(struct platform_device *pdev)
{
	struct led_regulator_platform_data *pdata =
			dev_get_platdata(&pdev->dev);
	struct regulator_led *led;
	struct regulator *vcc;
	int ret = 0;
	if (pdata == NULL) {
		dev_err(&pdev->dev, "no platform data\n");
		return -ENODEV;
	}
	vcc = devm_regulator_get_exclusive(&pdev->dev, "vled");
	if (IS_ERR(vcc)) {
		dev_err(&pdev->dev, "Cannot get vcc for %s\n", pdata->name);
		return PTR_ERR(vcc);
	}
	led = devm_kzalloc(&pdev->dev, sizeof(*led), GFP_KERNEL);
	if (led == NULL)
		return -ENOMEM;
	led->cdev.max_brightness = led_regulator_get_max_brightness(vcc);
	if (pdata->brightness > led->cdev.max_brightness) {
		dev_err(&pdev->dev, "Invalid default brightness %d\n",
				pdata->brightness);
		return -EINVAL;
	}
	led->cdev.brightness_set_blocking = regulator_led_brightness_set;
	led->cdev.name = pdata->name;
	led->cdev.flags |= LED_CORE_SUSPENDRESUME;
	led->vcc = vcc;
	/* to handle correctly an already enabled regulator */
	if (regulator_is_enabled(led->vcc))
		led->enabled = 1;
	mutex_init(&led->mutex);
	platform_set_drvdata(pdev, led);
	ret = led_classdev_register(&pdev->dev, &led->cdev);
	if (ret < 0)
		return ret;
	/* to expose the default value to userspace */
	led->cdev.brightness = pdata->brightness;
	/* Set the default led status */
	regulator_led_brightness_set(&led->cdev, led->cdev.brightness);
	return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Antonio Ospite | 258 | 89.27% | 2 | 33.33% | 
| Andrew Lunn | 13 | 4.50% | 1 | 16.67% | 
| Axel Lin | 8 | 2.77% | 1 | 16.67% | 
| Sachin Kamat | 6 | 2.08% | 1 | 16.67% | 
| Jingoo Han | 4 | 1.38% | 1 | 16.67% | 
| Total | 289 | 100.00% | 6 | 100.00% | 
static int regulator_led_remove(struct platform_device *pdev)
{
	struct regulator_led *led = platform_get_drvdata(pdev);
	led_classdev_unregister(&led->cdev);
	regulator_led_disable(led);
	return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Antonio Ospite | 37 | 100.00% | 1 | 100.00% | 
| Total | 37 | 100.00% | 1 | 100.00% | 
static struct platform_driver regulator_led_driver = {
	.driver = {
		   .name  = "leds-regulator",
                   },
	.probe  = regulator_led_probe,
	.remove = regulator_led_remove,
};
module_platform_driver(regulator_led_driver);
MODULE_AUTHOR("Antonio Ospite <ospite@studenti.unina.it>");
MODULE_DESCRIPTION("Regulator driven LED driver");
MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:leds-regulator");
Overall Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Antonio Ospite | 731 | 92.65% | 2 | 25.00% | 
| Andrew Lunn | 36 | 4.56% | 1 | 12.50% | 
| Axel Lin | 9 | 1.14% | 2 | 25.00% | 
| Sachin Kamat | 6 | 0.76% | 1 | 12.50% | 
| Jingoo Han | 4 | 0.51% | 1 | 12.50% | 
| Tejun Heo | 3 | 0.38% | 1 | 12.50% | 
| Total | 789 | 100.00% | 8 | 100.00% | 
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.