Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/cooloney/linux-leds

Pull LED update from Bryan Wu:
 "Basically we have some bug fixing and clean up and one big thing is we
  start to merge patch to add support LED Flash class"

* 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/cooloney/linux-leds:
  leds: gpio: cleanup the leds-gpio driver
  led: gpio: Fix possible ZERO_SIZE_PTR pointer dereferencing error.
  led: gpio: Sort include headers alphabetically
  leds: Improve and export led_update_brightness
  leds: trigger: gpio: fix warning in gpio trigger for gpios whose accessor function may sleep
  leds: lp3944: fix sparse warning
  leds: avoid using DEVICE_ATTR macro for max_brightness attribute
  leds: make brightness type consistent across whole subsystem
  leds: Reorder include directives
This commit is contained in:
Linus Torvalds 2014-10-21 08:18:38 -07:00
commit 045aaedab6
7 changed files with 55 additions and 31 deletions

View File

@ -9,26 +9,21 @@
* published by the Free Software Foundation.
*/
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/list.h>
#include <linux/spinlock.h>
#include <linux/device.h>
#include <linux/timer.h>
#include <linux/err.h>
#include <linux/ctype.h>
#include <linux/device.h>
#include <linux/err.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/leds.h>
#include <linux/list.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/spinlock.h>
#include <linux/timer.h>
#include "leds.h"
static struct class *leds_class;
static void led_update_brightness(struct led_classdev *led_cdev)
{
if (led_cdev->brightness_get)
led_cdev->brightness = led_cdev->brightness_get(led_cdev);
}
static ssize_t brightness_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
@ -59,14 +54,14 @@ static ssize_t brightness_store(struct device *dev,
}
static DEVICE_ATTR_RW(brightness);
static ssize_t led_max_brightness_show(struct device *dev,
static ssize_t max_brightness_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct led_classdev *led_cdev = dev_get_drvdata(dev);
return sprintf(buf, "%u\n", led_cdev->max_brightness);
}
static DEVICE_ATTR(max_brightness, 0444, led_max_brightness_show, NULL);
static DEVICE_ATTR_RO(max_brightness);
#ifdef CONFIG_LEDS_TRIGGERS
static DEVICE_ATTR(trigger, 0644, led_trigger_show, led_trigger_store);

View File

@ -12,10 +12,11 @@
*/
#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 <linux/leds.h>
#include "leds.h"
DECLARE_RWSEM(leds_list_lock);
@ -126,3 +127,19 @@ void led_set_brightness(struct led_classdev *led_cdev,
__led_set_brightness(led_cdev, brightness);
}
EXPORT_SYMBOL(led_set_brightness);
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;
}
EXPORT_SYMBOL(led_update_brightness);

View File

@ -7,9 +7,9 @@
* Free Software Foundation.
*/
#include <linux/err.h>
#include <linux/leds.h>
#include <linux/platform_device.h>
#include <linux/slab.h>
#include <linux/leds.h>
/**
* gpio_led_register_device - register a gpio-led device
@ -28,6 +28,9 @@ struct platform_device *__init gpio_led_register_device(
struct platform_device *ret;
struct gpio_led_platform_data _pdata = *pdata;
if (!pdata->num_leds)
return ERR_PTR(-EINVAL);
_pdata.leds = kmemdup(pdata->leds,
pdata->num_leds * sizeof(*pdata->leds), GFP_KERNEL);
if (!_pdata.leds)

View File

@ -10,17 +10,17 @@
* published by the Free Software Foundation.
*
*/
#include <linux/kernel.h>
#include <linux/platform_device.h>
#include <linux/err.h>
#include <linux/gpio.h>
#include <linux/kernel.h>
#include <linux/leds.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_platform.h>
#include <linux/of_gpio.h>
#include <linux/of_platform.h>
#include <linux/platform_device.h>
#include <linux/slab.h>
#include <linux/workqueue.h>
#include <linux/module.h>
#include <linux/err.h>
struct gpio_led_data {
struct led_classdev cdev;
@ -36,7 +36,7 @@ struct gpio_led_data {
static void gpio_led_work(struct work_struct *work)
{
struct gpio_led_data *led_dat =
struct gpio_led_data *led_dat =
container_of(work, struct gpio_led_data, work);
if (led_dat->blinking) {
@ -235,14 +235,12 @@ static struct gpio_leds_priv *gpio_leds_create_of(struct platform_device *pdev)
}
#endif /* CONFIG_OF_GPIO */
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),

View File

@ -335,7 +335,8 @@ static int lp3944_configure(struct i2c_client *client,
}
/* to expose the default value to userspace */
led->ldev.brightness = led->status;
led->ldev.brightness =
(enum led_brightness) led->status;
/* Set the default led status */
err = lp3944_led_set(led, led->status);

View File

@ -48,7 +48,7 @@ static void gpio_trig_work(struct work_struct *work)
if (!gpio_data->gpio)
return;
tmp = gpio_get_value(gpio_data->gpio);
tmp = gpio_get_value_cansleep(gpio_data->gpio);
if (gpio_data->inverted)
tmp = !tmp;

View File

@ -13,8 +13,8 @@
#define __LINUX_LEDS_H_INCLUDED
#include <linux/list.h>
#include <linux/spinlock.h>
#include <linux/rwsem.h>
#include <linux/spinlock.h>
#include <linux/timer.h>
#include <linux/workqueue.h>
@ -31,8 +31,8 @@ enum led_brightness {
struct led_classdev {
const char *name;
int brightness;
int max_brightness;
enum led_brightness brightness;
enum led_brightness max_brightness;
int flags;
/* Lower 16 bits reflect status */
@ -140,6 +140,16 @@ extern void led_blink_set_oneshot(struct led_classdev *led_cdev,
*/
extern void led_set_brightness(struct led_classdev *led_cdev,
enum led_brightness brightness);
/**
* led_update_brightness - update LED brightness
* @led_cdev: the LED to query
*
* Get an LED's current brightness and update led_cdev->brightness
* member with the obtained value.
*
* Returns: 0 on success or negative error value on failure
*/
extern int led_update_brightness(struct led_classdev *led_cdev);
/*
* LED Triggers