summaryrefslogtreecommitdiffstats
path: root/drivers/led
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/led')
-rw-r--r--drivers/led/Kconfig1
-rw-r--r--drivers/led/Makefile1
-rw-r--r--drivers/led/core.c17
-rw-r--r--drivers/led/led-gpio.c29
-rw-r--r--drivers/led/led-pca955x.c106
-rw-r--r--drivers/led/led-pwm.c43
-rw-r--r--drivers/led/led-triggers.c15
7 files changed, 74 insertions, 138 deletions
diff --git a/drivers/led/Kconfig b/drivers/led/Kconfig
index 2a5920a7bd..445393c101 100644
--- a/drivers/led/Kconfig
+++ b/drivers/led/Kconfig
@@ -1,3 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0-only
menuconfig LED
bool "LED support"
select POLLER
diff --git a/drivers/led/Makefile b/drivers/led/Makefile
index 35693a7f6b..dfbcaf783b 100644
--- a/drivers/led/Makefile
+++ b/drivers/led/Makefile
@@ -1,3 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0-only
obj-$(CONFIG_LED) += core.o
obj-$(CONFIG_LED_GPIO) += led-gpio.o
obj-$(CONFIG_LED_PWM) += led-pwm.o
diff --git a/drivers/led/core.c b/drivers/led/core.c
index e727148a24..fe79f75571 100644
--- a/drivers/led/core.c
+++ b/drivers/led/core.c
@@ -1,21 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
/*
* core LED support for barebox
*
* (C) Copyright 2010 Sascha Hauer, Pengutronix
- *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
*/
#include <common.h>
@@ -212,7 +199,7 @@ static struct poller_struct led_poller = {
static int led_blink_init(void)
{
- return poller_register(&led_poller);
+ return poller_register(&led_poller, "led");
}
late_initcall(led_blink_init);
diff --git a/drivers/led/led-gpio.c b/drivers/led/led-gpio.c
index 0590e3fa3e..c0d14256d3 100644
--- a/drivers/led/led-gpio.c
+++ b/drivers/led/led-gpio.c
@@ -1,21 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
/*
* gpio LED support for barebox
*
* (C) Copyright 2010 Sascha Hauer, Pengutronix
- *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
*/
#include <common.h>
#include <init.h>
@@ -205,20 +192,20 @@ void led_gpio_rgb_unregister(struct gpio_rgb_led *led)
#endif /* CONFIG_LED_GPIO_RGB */
#ifdef CONFIG_LED_GPIO_OF
-static int led_gpio_of_probe(struct device_d *dev)
+static int led_gpio_of_probe(struct device *dev)
{
struct device_node *child;
struct gpio_led *leds;
int num_leds;
int ret = 0, n = 0;
- num_leds = of_get_child_count(dev->device_node);
+ num_leds = of_get_child_count(dev->of_node);
if (num_leds <= 0)
return num_leds;
leds = xzalloc(num_leds * sizeof(struct gpio_led));
- for_each_child_of_node(dev->device_node, child) {
+ for_each_child_of_node(dev->of_node, child) {
struct gpio_led *gled = &leds[n];
const char *default_state;
enum of_gpio_flags flags;
@@ -227,10 +214,7 @@ static int led_gpio_of_probe(struct device_d *dev)
gpio = of_get_named_gpio_flags(child, "gpios", 0, &flags);
if (gpio < 0) {
- if (gpio != -EPROBE_DEFER)
- dev_err(dev, "failed to get gpio for %s: %d\n",
- child->full_name, gpio);
- ret = gpio;
+ ret = dev_err_probe(dev, gpio, "getting gpio for %pOF\n", child);
goto err;
}
@@ -270,8 +254,9 @@ static struct of_device_id led_gpio_of_ids[] = {
{ .compatible = "gpio-leds", },
{ }
};
+MODULE_DEVICE_TABLE(of, led_gpio_of_ids);
-static struct driver_d led_gpio_of_driver = {
+static struct driver led_gpio_of_driver = {
.name = "gpio-leds",
.probe = led_gpio_of_probe,
.of_compatible = DRV_OF_COMPAT(led_gpio_of_ids),
diff --git a/drivers/led/led-pca955x.c b/drivers/led/led-pca955x.c
index 27fefce8d5..cad4db3799 100644
--- a/drivers/led/led-pca955x.c
+++ b/drivers/led/led-pca955x.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright 2007-2008 Extreme Engineering Solutions, Inc.
* Author: Nate Case <ncase@xes-inc.com>
@@ -5,16 +6,6 @@
* Copyright (C) 2018 WAGO Kontakttechnik GmbH & Co. KG <http://global.wago.com>
* Author: Oleg Karfich <oleg.karfich@wago.com>
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
* This code was ported from linux-4.18 kernel driver.
* Orginal code with it's copyright info can be found in
* drivers/leds/leds-pca955x.c
@@ -72,53 +63,47 @@ enum led_brightness {
LED_FULL = 255,
};
-enum pca955x_type {
- pca9550,
- pca9551,
- pca9552,
- pca9553,
-};
-
struct pca955x_chipdef {
int bits;
u8 slv_addr; /* 7-bit slave address mask */
int slv_addr_shift; /* Number of bits to ignore */
};
-static struct pca955x_chipdef pca955x_chipdefs[] = {
- [pca9550] = {
- .bits = 2,
- .slv_addr = /* 110000x */ 0x60,
- .slv_addr_shift = 1,
- },
- [pca9551] = {
- .bits = 8,
- .slv_addr = /* 1100xxx */ 0x60,
- .slv_addr_shift = 3,
- },
- [pca9552] = {
- .bits = 16,
- .slv_addr = /* 1100xxx */ 0x60,
- .slv_addr_shift = 3,
- },
- [pca9553] = {
- .bits = 4,
- .slv_addr = /* 110001x */ 0x62,
- .slv_addr_shift = 1,
- },
+static const struct pca955x_chipdef pca9550_chipdef = {
+ .bits = 2,
+ .slv_addr = /* 110000x */ 0x60,
+ .slv_addr_shift = 1,
+};
+
+static const struct pca955x_chipdef pca9551_chipdef = {
+ .bits = 8,
+ .slv_addr = /* 1100xxx */ 0x60,
+ .slv_addr_shift = 3,
+};
+
+static const struct pca955x_chipdef pca9552_chipdef = {
+ .bits = 16,
+ .slv_addr = /* 1100xxx */ 0x60,
+ .slv_addr_shift = 3,
+};
+
+static const struct pca955x_chipdef pca9553_chipdef = {
+ .bits = 4,
+ .slv_addr = /* 110001x */ 0x62,
+ .slv_addr_shift = 1,
};
static const struct platform_device_id led_pca955x_id[] = {
- { "pca9550", pca9550 },
- { "pca9551", pca9551 },
- { "pca9552", pca9552 },
- { "pca9553", pca9553 },
+ { "pca9550", (unsigned long) &pca9550_chipdef },
+ { "pca9551", (unsigned long) &pca9551_chipdef },
+ { "pca9552", (unsigned long) &pca9552_chipdef },
+ { "pca9553", (unsigned long) &pca9553_chipdef },
{ }
};
struct pca955x {
struct pca955x_led *leds;
- struct pca955x_chipdef *chipdef;
+ const struct pca955x_chipdef *chipdef;
struct i2c_client *client;
};
@@ -278,7 +263,7 @@ static struct pca955x_platform_data *
led_pca955x_pdata_of_init(struct device_node *np, struct pca955x *pca955x)
{
struct device_node *child;
- struct pca955x_chipdef *chip = pca955x->chipdef;
+ const struct pca955x_chipdef *chip = pca955x->chipdef;
struct pca955x_platform_data *pdata;
int count, err;
@@ -334,23 +319,27 @@ led_pca955x_pdata_of_init(struct device_node *np, struct pca955x *pca955x)
}
static const struct of_device_id of_pca955x_match[] = {
- { .compatible = "nxp,pca9550", .data = (void *)pca9550 },
- { .compatible = "nxp,pca9551", .data = (void *)pca9551 },
- { .compatible = "nxp,pca9552", .data = (void *)pca9552 },
- { .compatible = "nxp,pca9553", .data = (void *)pca9553 },
+ { .compatible = "nxp,pca9550", .data = &pca9550_chipdef },
+ { .compatible = "nxp,pca9551", .data = &pca9551_chipdef },
+ { .compatible = "nxp,pca9552", .data = &pca9552_chipdef },
+ { .compatible = "nxp,pca9553", .data = &pca9553_chipdef },
{},
};
+MODULE_DEVICE_TABLE(of, of_pca955x_match);
-static int led_pca955x_probe(struct device_d *dev)
+static int led_pca955x_probe(struct device *dev)
{
struct pca955x *pca955x;
struct pca955x_led *pca955x_led;
- struct pca955x_chipdef *chip;
+ const struct pca955x_chipdef *chip;
struct i2c_client *client;
int err;
struct pca955x_platform_data *pdata;
- chip = &pca955x_chipdefs[dev->id_entry->driver_data];
+ chip = device_get_match_data(dev);
+ if (!chip)
+ return -ENODEV;
+
client = to_i2c_client(dev);
/* Make sure the slave address / chip type combo given is possible */
@@ -377,7 +366,7 @@ static int led_pca955x_probe(struct device_d *dev)
pca955x->client = client;
pca955x->chipdef = chip;
- pdata = led_pca955x_pdata_of_init(dev->device_node, pca955x);
+ pdata = led_pca955x_pdata_of_init(dev->of_node, pca955x);
if (IS_ERR(pdata))
return PTR_ERR(pdata);
@@ -399,22 +388,17 @@ static int led_pca955x_probe(struct device_d *dev)
err = pca955x_write_psc(client, 0, 0);
if (err)
return err;
+
err = pca955x_write_psc(client, 1, 0);
- if (err)
- return err;
- return 0;
+ return err;
}
-static struct driver_d led_pca955x_driver = {
+static struct driver led_pca955x_driver = {
.name = "led-pca955x",
.probe = led_pca955x_probe,
.id_table = led_pca955x_id,
.of_compatible = DRV_OF_COMPAT(of_pca955x_match),
};
-static int __init led_pca955x_init(void)
-{
- return i2c_driver_register(&led_pca955x_driver);
-}
-device_initcall(led_pca955x_init);
+device_i2c_driver(led_pca955x_driver);
diff --git a/drivers/led/led-pwm.c b/drivers/led/led-pwm.c
index 8a358dde88..2ffb72e692 100644
--- a/drivers/led/led-pwm.c
+++ b/drivers/led/led-pwm.c
@@ -1,21 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
/*
* pwm LED support for barebox
*
* (C) Copyright 2010 Sascha Hauer, Pengutronix
- *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
*/
#include <common.h>
#include <malloc.h>
@@ -23,36 +10,41 @@
#include <led.h>
#include <pwm.h>
#include <of.h>
-#include <asm-generic/div64.h>
+#include <linux/math64.h>
struct pwmled {
bool active_low;
struct led led;
struct pwm_device *pwm;
- uint32_t period;
};
static void led_pwm_set(struct led *led, unsigned int brightness)
{
struct pwmled *pwmled = container_of(led, struct pwmled, led);
- unsigned long long duty = pwmled->period;
+ unsigned long long duty;
+ struct pwm_state state;
unsigned int max = pwmled->led.max_value;
- duty *= brightness;
+ pwm_get_state(pwmled->pwm, &state);
+
+ duty = state.period_ns * brightness;
do_div(duty, max);
if (pwmled->active_low)
- duty = pwmled->period - duty;
+ duty = state.period_ns - duty;
+
+ state.p_enable = true;
+ state.duty_ns = duty;
- pwm_config(pwmled->pwm, duty, pwmled->period);
+ pwm_apply_state(pwmled->pwm, &state);
}
-static int led_pwm_of_probe(struct device_d *dev)
+static int led_pwm_of_probe(struct device *dev)
{
struct device_node *child;
int ret;
- for_each_child_of_node(dev->device_node, child) {
+ for_each_child_of_node(dev->of_node, child) {
struct pwmled *pwmled;
struct pwm_device *pwm;
@@ -68,13 +60,11 @@ static int led_pwm_of_probe(struct device_d *dev)
if (ret)
return ret;
- pwmled->period = pwm_get_period(pwmled->pwm);
pwmled->active_low = of_property_read_bool(child, "active-low");
pwmled->led.set = led_pwm_set;
- pwm_config(pwmled->pwm, 0, pwmled->period);
- pwm_enable(pwmled->pwm);
+ led_pwm_set(&pwmled->led, 0);
ret = led_register(&pwmled->led);
if (ret)
@@ -90,8 +80,9 @@ static struct of_device_id led_pwm_of_ids[] = {
{ .compatible = "pwm-leds", },
{ }
};
+MODULE_DEVICE_TABLE(of, led_pwm_of_ids);
-static struct driver_d led_pwm_of_driver = {
+static struct driver led_pwm_of_driver = {
.name = "pwm-leds",
.probe = led_pwm_of_probe,
.of_compatible = DRV_OF_COMPAT(led_pwm_of_ids),
diff --git a/drivers/led/led-triggers.c b/drivers/led/led-triggers.c
index 216c8639bc..cba94d5461 100644
--- a/drivers/led/led-triggers.c
+++ b/drivers/led/led-triggers.c
@@ -1,21 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
/*
* LED trigger support for barebox
*
* (C) Copyright 2010 Sascha Hauer, Pengutronix
- *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
*/
#include <common.h>