summaryrefslogtreecommitdiff
path: root/drivers/leds/leds-gpio.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/leds/leds-gpio.c')
-rw-r--r--drivers/leds/leds-gpio.c56
1 files changed, 27 insertions, 29 deletions
diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c
index 7bfe40a6bfdd..710c319ad312 100644
--- a/drivers/leds/leds-gpio.c
+++ b/drivers/leds/leds-gpio.c
@@ -6,17 +6,21 @@
* Raphael Assenat <raph@8d.com>
* Copyright (C) 2008 Freescale Semiconductor, Inc.
*/
+#include <linux/container_of.h>
+#include <linux/device.h>
#include <linux/err.h>
#include <linux/gpio.h>
#include <linux/gpio/consumer.h>
-#include <linux/kernel.h>
#include <linux/leds.h>
+#include <linux/mod_devicetable.h>
#include <linux/module.h>
-#include <linux/of.h>
+#include <linux/overflow.h>
#include <linux/pinctrl/consumer.h>
#include <linux/platform_device.h>
#include <linux/property.h>
#include <linux/slab.h>
+#include <linux/types.h>
+
#include "leds.h"
struct gpio_led_data {
@@ -125,16 +129,13 @@ static int create_gpio_led(const struct gpio_led *template,
return ret;
pinctrl = devm_pinctrl_get_select_default(led_dat->cdev.dev);
- if (IS_ERR(pinctrl)) {
- ret = PTR_ERR(pinctrl);
- if (ret != -ENODEV) {
- dev_warn(led_dat->cdev.dev,
- "Failed to select %pOF pinctrl: %d\n",
- to_of_node(fwnode), ret);
- } else {
- /* pinctrl-%d not present, not an error */
- ret = 0;
- }
+ ret = PTR_ERR_OR_ZERO(pinctrl);
+ /* pinctrl-%d not present, not an error */
+ if (ret == -ENODEV)
+ ret = 0;
+ if (ret) {
+ dev_warn(led_dat->cdev.dev, "Failed to select %pfw pinctrl: %d\n",
+ fwnode, ret);
}
return ret;
@@ -142,12 +143,11 @@ static int create_gpio_led(const struct gpio_led *template,
struct gpio_leds_priv {
int num_leds;
- struct gpio_led_data leds[];
+ struct gpio_led_data leds[] __counted_by(num_leds);
};
-static struct gpio_leds_priv *gpio_leds_create(struct platform_device *pdev)
+static struct gpio_leds_priv *gpio_leds_create(struct device *dev)
{
- struct device *dev = &pdev->dev;
struct fwnode_handle *child;
struct gpio_leds_priv *priv;
int count, ret;
@@ -221,13 +221,13 @@ static struct gpio_desc *gpio_led_get_gpiod(struct device *dev, int idx,
* device, this will hit the board file, if any and get
* the GPIO from there.
*/
- gpiod = devm_gpiod_get_index(dev, NULL, idx, GPIOD_OUT_LOW);
- if (!IS_ERR(gpiod)) {
+ gpiod = devm_gpiod_get_index_optional(dev, NULL, idx, GPIOD_OUT_LOW);
+ if (IS_ERR(gpiod))
+ return gpiod;
+ if (gpiod) {
gpiod_set_consumer_name(gpiod, template->name);
return gpiod;
}
- if (PTR_ERR(gpiod) != -ENOENT)
- return gpiod;
/*
* This is the legacy code path for platform code that
@@ -256,13 +256,13 @@ static struct gpio_desc *gpio_led_get_gpiod(struct device *dev, int idx,
static int gpio_led_probe(struct platform_device *pdev)
{
- struct gpio_led_platform_data *pdata = dev_get_platdata(&pdev->dev);
+ struct device *dev = &pdev->dev;
+ struct gpio_led_platform_data *pdata = dev_get_platdata(dev);
struct gpio_leds_priv *priv;
- int i, ret = 0;
+ int i, ret;
if (pdata && pdata->num_leds) {
- priv = devm_kzalloc(&pdev->dev, struct_size(priv, leds, pdata->num_leds),
- GFP_KERNEL);
+ priv = devm_kzalloc(dev, struct_size(priv, leds, pdata->num_leds), GFP_KERNEL);
if (!priv)
return -ENOMEM;
@@ -275,22 +275,20 @@ static int gpio_led_probe(struct platform_device *pdev)
led_dat->gpiod = template->gpiod;
else
led_dat->gpiod =
- gpio_led_get_gpiod(&pdev->dev,
- i, template);
+ gpio_led_get_gpiod(dev, i, template);
if (IS_ERR(led_dat->gpiod)) {
- dev_info(&pdev->dev, "Skipping unavailable LED gpio %d (%s)\n",
+ dev_info(dev, "Skipping unavailable LED gpio %d (%s)\n",
template->gpio, template->name);
continue;
}
- ret = create_gpio_led(template, led_dat,
- &pdev->dev, NULL,
+ ret = create_gpio_led(template, led_dat, dev, NULL,
pdata->gpio_blink_set);
if (ret < 0)
return ret;
}
} else {
- priv = gpio_leds_create(pdev);
+ priv = gpio_leds_create(dev);
if (IS_ERR(priv))
return PTR_ERR(priv);
}