Skip to content

Commit 545ae66

Browse files
committed
Merge tag 'leds-5.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/pavel/linux-leds
Pull LED updates from Pavel Machek: - New driver for TI TPS6105X - Add managed API to get a LED from a device driver - Misc fixes and updates * tag 'leds-5.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/pavel/linux-leds: (22 commits) leds: lm3692x: Disable chip on brightness 0 leds: lm3692x: Split out lm3692x_leds_disable leds: lm3692x: Move lm3692x_init and rename to lm3692x_leds_enable leds: lm3692x: Make sure we don't exceed the maximum LED current dt: bindings: lm3692x: Add led-max-microamp property leds: lm3692x: Allow to configure over voltage protection dt: bindings: lm3692x: Add ti,ovp-microvolt property leds: populate the device's of_node leds: Add managed API to get a LED from a device driver leds: Add of_led_get() and led_put() leds: lm3532: add pointer to documentation and fix typo leds: lm3532: use extended registration so that LED can be used for backlight leds: lm3642: remove warnings for bad strtol, cleanup gotos leds: rb532: cleanup whitespace ledtrig-pattern: fix email address quoting in MODULE_AUTHOR() dt-bindings: mfd: update TI tps6105x chip bindings leds: tps6105x: add driver for MFD chip LED mode led: max77650: add of_match table leds: bd2802: Convert to use GPIO descriptors leds: pca963x: Fix open-drain initialization ...
2 parents 15f8e73 + 260718b commit 545ae66

File tree

13 files changed

+425
-94
lines changed

13 files changed

+425
-94
lines changed

Documentation/devicetree/bindings/leds/leds-lm3692x.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ Required properties:
1818
Optional properties:
1919
- enable-gpios : gpio pin to enable/disable the device.
2020
- vled-supply : LED supply
21+
- ti,ovp-microvolt: Overvoltage protection in
22+
micro-volt, can be 17000000, 21000000, 25000000 or
23+
29000000. If ti,ovp-microvolt is not specified it
24+
defaults to 29000000.
2125

2226
Required child properties:
2327
- reg : 0 - Will enable all LED sync paths
@@ -31,6 +35,8 @@ Optional child properties:
3135
- label : see Documentation/devicetree/bindings/leds/common.txt (deprecated)
3236
- linux,default-trigger :
3337
see Documentation/devicetree/bindings/leds/common.txt
38+
- led-max-microamp :
39+
see Documentation/devicetree/bindings/leds/common.txt
3440

3541
Example:
3642

@@ -44,12 +50,14 @@ led-controller@36 {
4450

4551
enable-gpios = <&gpio1 28 GPIO_ACTIVE_HIGH>;
4652
vled-supply = <&vbatt>;
53+
ti,ovp-microvolt = <29000000>;
4754

4855
led@0 {
4956
reg = <0>;
5057
function = LED_FUNCTION_BACKLIGHT;
5158
color = <LED_COLOR_ID_WHITE>;
5259
linux,default-trigger = "backlight";
60+
led-max-microamp = <20000>;
5361
};
5462
}
5563

Documentation/devicetree/bindings/mfd/tps6105x.txt

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,56 @@ Required properties:
77
- compatible: "ti,tps61050" or "ti,tps61052"
88
- reg: Specifies the I2C slave address
99

10-
Example:
10+
Optional sub-node:
11+
12+
This subnode selects the chip's operational mode.
13+
There can be at most one single available subnode.
14+
15+
- regulator: presence of this sub-node puts the chip in regulator mode.
16+
see ../regulator/regulator.yaml
17+
18+
- led: presence of this sub-node puts the chip in led mode.
19+
Optional properties:
20+
- function : see ../leds/common.txt
21+
- color : see ../leds/common.txt
22+
- label : see ../leds/common.txt
23+
(deprecated)
24+
25+
Example (GPIO operation only):
26+
27+
i2c0 {
28+
tps61052@33 {
29+
compatible = "ti,tps61052";
30+
reg = <0x33>;
31+
};
32+
};
33+
34+
Example (GPIO + regulator operation):
1135

1236
i2c0 {
1337
tps61052@33 {
1438
compatible = "ti,tps61052";
1539
reg = <0x33>;
40+
41+
regulator {
42+
regulator-min-microvolt = <5000000>;
43+
regulator-max-microvolt = <5000000>;
44+
regulator-always-on;
45+
};
46+
};
47+
};
48+
49+
Example (GPIO + led operation):
50+
51+
#include <dt-bindings/leds/common.h>
52+
53+
i2c0 {
54+
tps61052@33 {
55+
compatible = "ti,tps61052";
56+
reg = <0x33>;
57+
58+
led {
59+
color = <LED_COLOR_ID_WHITE>;
60+
};
1661
};
1762
};

drivers/leds/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,16 @@ config LEDS_LM36274
836836
Say Y to enable the LM36274 LED driver for TI LMU devices.
837837
This supports the LED device LM36274.
838838

839+
config LEDS_TPS6105X
840+
tristate "LED support for TI TPS6105X"
841+
depends on LEDS_CLASS
842+
depends on TPS6105X
843+
default y if TPS6105X
844+
help
845+
This driver supports TPS61050/TPS61052 LED chips.
846+
It is a single boost converter primarily for white LEDs and
847+
audio amplifiers.
848+
839849
comment "LED Triggers"
840850
source "drivers/leds/trigger/Kconfig"
841851

drivers/leds/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ obj-$(CONFIG_LEDS_LM3601X) += leds-lm3601x.o
8585
obj-$(CONFIG_LEDS_TI_LMU_COMMON) += leds-ti-lmu-common.o
8686
obj-$(CONFIG_LEDS_LM3697) += leds-lm3697.o
8787
obj-$(CONFIG_LEDS_LM36274) += leds-lm36274.o
88+
obj-$(CONFIG_LEDS_TPS6105X) += leds-tps6105x.o
8889

8990
# LED SPI Drivers
9091
obj-$(CONFIG_LEDS_CR0014114) += leds-cr0014114.o

drivers/leds/led-class.c

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/spinlock.h>
2020
#include <linux/timer.h>
2121
#include <uapi/linux/uleds.h>
22+
#include <linux/of.h>
2223
#include "leds.h"
2324

2425
static struct class *leds_class;
@@ -214,6 +215,98 @@ static int led_resume(struct device *dev)
214215

215216
static SIMPLE_DEV_PM_OPS(leds_class_dev_pm_ops, led_suspend, led_resume);
216217

218+
/**
219+
* of_led_get() - request a LED device via the LED framework
220+
* @np: device node to get the LED device from
221+
* @index: the index of the LED
222+
*
223+
* Returns the LED device parsed from the phandle specified in the "leds"
224+
* property of a device tree node or a negative error-code on failure.
225+
*/
226+
struct led_classdev *of_led_get(struct device_node *np, int index)
227+
{
228+
struct device *led_dev;
229+
struct led_classdev *led_cdev;
230+
struct device_node *led_node;
231+
232+
led_node = of_parse_phandle(np, "leds", index);
233+
if (!led_node)
234+
return ERR_PTR(-ENOENT);
235+
236+
led_dev = class_find_device_by_of_node(leds_class, led_node);
237+
of_node_put(led_node);
238+
239+
if (!led_dev)
240+
return ERR_PTR(-EPROBE_DEFER);
241+
242+
led_cdev = dev_get_drvdata(led_dev);
243+
244+
if (!try_module_get(led_cdev->dev->parent->driver->owner))
245+
return ERR_PTR(-ENODEV);
246+
247+
return led_cdev;
248+
}
249+
EXPORT_SYMBOL_GPL(of_led_get);
250+
251+
/**
252+
* led_put() - release a LED device
253+
* @led_cdev: LED device
254+
*/
255+
void led_put(struct led_classdev *led_cdev)
256+
{
257+
module_put(led_cdev->dev->parent->driver->owner);
258+
}
259+
EXPORT_SYMBOL_GPL(led_put);
260+
261+
static void devm_led_release(struct device *dev, void *res)
262+
{
263+
struct led_classdev **p = res;
264+
265+
led_put(*p);
266+
}
267+
268+
/**
269+
* devm_of_led_get - Resource-managed request of a LED device
270+
* @dev: LED consumer
271+
* @index: index of the LED to obtain in the consumer
272+
*
273+
* The device node of the device is parse to find the request LED device.
274+
* The LED device returned from this function is automatically released
275+
* on driver detach.
276+
*
277+
* @return a pointer to a LED device or ERR_PTR(errno) on failure.
278+
*/
279+
struct led_classdev *__must_check devm_of_led_get(struct device *dev,
280+
int index)
281+
{
282+
struct led_classdev *led;
283+
struct led_classdev **dr;
284+
285+
if (!dev)
286+
return ERR_PTR(-EINVAL);
287+
288+
/* Not using device tree? */
289+
if (!IS_ENABLED(CONFIG_OF) || !dev->of_node)
290+
return ERR_PTR(-ENOTSUPP);
291+
292+
led = of_led_get(dev->of_node, index);
293+
if (IS_ERR(led))
294+
return led;
295+
296+
dr = devres_alloc(devm_led_release, sizeof(struct led_classdev *),
297+
GFP_KERNEL);
298+
if (!dr) {
299+
led_put(led);
300+
return ERR_PTR(-ENOMEM);
301+
}
302+
303+
*dr = led;
304+
devres_add(dev, dr);
305+
306+
return led;
307+
}
308+
EXPORT_SYMBOL_GPL(devm_of_led_get);
309+
217310
static int led_classdev_next_name(const char *init_name, char *name,
218311
size_t len)
219312
{
@@ -276,8 +369,10 @@ int led_classdev_register_ext(struct device *parent,
276369
mutex_unlock(&led_cdev->led_access);
277370
return PTR_ERR(led_cdev->dev);
278371
}
279-
if (init_data && init_data->fwnode)
372+
if (init_data && init_data->fwnode) {
280373
led_cdev->dev->fwnode = init_data->fwnode;
374+
led_cdev->dev->of_node = to_of_node(init_data->fwnode);
375+
}
281376

282377
if (ret)
283378
dev_warn(parent, "Led %s renamed to %s due to name collision",

drivers/leds/leds-bd2802.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#include <linux/module.h>
1212
#include <linux/i2c.h>
13-
#include <linux/gpio.h>
13+
#include <linux/gpio/consumer.h>
1414
#include <linux/delay.h>
1515
#include <linux/leds.h>
1616
#include <linux/leds-bd2802.h>
@@ -67,6 +67,7 @@ struct led_state {
6767
struct bd2802_led {
6868
struct bd2802_led_platform_data *pdata;
6969
struct i2c_client *client;
70+
struct gpio_desc *reset;
7071
struct rw_semaphore rwsem;
7172

7273
struct led_state led[2];
@@ -200,7 +201,7 @@ static void bd2802_update_state(struct bd2802_led *led, enum led_ids id,
200201
return;
201202

202203
if (bd2802_is_all_off(led) && !led->adf_on) {
203-
gpio_set_value(led->pdata->reset_gpio, 0);
204+
gpiod_set_value(led->reset, 1);
204205
return;
205206
}
206207

@@ -226,7 +227,7 @@ static void bd2802_configure(struct bd2802_led *led)
226227

227228
static void bd2802_reset_cancel(struct bd2802_led *led)
228229
{
229-
gpio_set_value(led->pdata->reset_gpio, 1);
230+
gpiod_set_value(led->reset, 0);
230231
udelay(100);
231232
bd2802_configure(led);
232233
}
@@ -420,7 +421,7 @@ static void bd2802_disable_adv_conf(struct bd2802_led *led)
420421
bd2802_addr_attributes[i]);
421422

422423
if (bd2802_is_all_off(led))
423-
gpio_set_value(led->pdata->reset_gpio, 0);
424+
gpiod_set_value(led->reset, 1);
424425

425426
led->adf_on = 0;
426427
}
@@ -670,8 +671,16 @@ static int bd2802_probe(struct i2c_client *client,
670671
pdata = led->pdata = dev_get_platdata(&client->dev);
671672
i2c_set_clientdata(client, led);
672673

673-
/* Configure RESET GPIO (L: RESET, H: RESET cancel) */
674-
gpio_request_one(pdata->reset_gpio, GPIOF_OUT_INIT_HIGH, "RGB_RESETB");
674+
/*
675+
* Configure RESET GPIO (L: RESET, H: RESET cancel)
676+
*
677+
* We request the reset GPIO as OUT_LOW which means de-asserted,
678+
* board files specifying this GPIO line in a machine descriptor
679+
* table should take care to specify GPIO_ACTIVE_LOW for this line.
680+
*/
681+
led->reset = devm_gpiod_get(&client->dev, "reset", GPIOD_OUT_LOW);
682+
if (IS_ERR(led->reset))
683+
return PTR_ERR(led->reset);
675684

676685
/* Tacss = min 0.1ms */
677686
udelay(100);
@@ -685,7 +694,7 @@ static int bd2802_probe(struct i2c_client *client,
685694
dev_info(&client->dev, "return 0x%02x\n", ret);
686695

687696
/* To save the power, reset BD2802 after detecting */
688-
gpio_set_value(led->pdata->reset_gpio, 0);
697+
gpiod_set_value(led->reset, 1);
689698

690699
/* Default attributes */
691700
led->wave_pattern = BD2802_PATTERN_HALF;
@@ -720,7 +729,7 @@ static int bd2802_remove(struct i2c_client *client)
720729
struct bd2802_led *led = i2c_get_clientdata(client);
721730
int i;
722731

723-
gpio_set_value(led->pdata->reset_gpio, 0);
732+
gpiod_set_value(led->reset, 1);
724733
bd2802_unregister_led_classdev(led);
725734
if (led->adf_on)
726735
bd2802_disable_adv_conf(led);
@@ -750,7 +759,7 @@ static int bd2802_suspend(struct device *dev)
750759
struct i2c_client *client = to_i2c_client(dev);
751760
struct bd2802_led *led = i2c_get_clientdata(client);
752761

753-
gpio_set_value(led->pdata->reset_gpio, 0);
762+
gpiod_set_value(led->reset, 1);
754763

755764
return 0;
756765
}

drivers/leds/leds-lm3532.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,12 @@ static int lm3532_parse_node(struct lm3532_data *priv)
578578
priv->runtime_ramp_down = lm3532_get_ramp_index(ramp_time);
579579

580580
device_for_each_child_node(priv->dev, child) {
581+
struct led_init_data idata = {
582+
.fwnode = child,
583+
.default_label = ":",
584+
.devicename = priv->client->name,
585+
};
586+
581587
led = &priv->leds[i];
582588

583589
ret = fwnode_property_read_u32(child, "reg", &control_bank);
@@ -652,7 +658,7 @@ static int lm3532_parse_node(struct lm3532_data *priv)
652658
led->led_dev.name = led->label;
653659
led->led_dev.brightness_set_blocking = lm3532_brightness_set;
654660

655-
ret = devm_led_classdev_register(priv->dev, &led->led_dev);
661+
ret = devm_led_classdev_register_ext(priv->dev, &led->led_dev, &idata);
656662
if (ret) {
657663
dev_err(&priv->client->dev, "led register err: %d\n",
658664
ret);

0 commit comments

Comments
 (0)