* [PATCH 1/3] dt-bindings: leds: Add regulator-led binding
@ 2022-02-19 23:56 Linus Walleij
2022-02-25 18:49 ` Rob Herring
0 siblings, 1 reply; 8+ messages in thread
From: Linus Walleij @ 2022-02-19 23:56 UTC (permalink / raw)
To: Pavel Machek; +Cc: linux-leds, Linus Walleij, devicetree, Antonio Ospite
The regulator is a LED connected directly to a regulator and with
its brightness controlled by the voltage of the regulator.
Cc: devicetree@vger.kernel.org
Cc: Antonio Ospite <ao2@ao2.it>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
.../bindings/leds/regulator-led.yaml | 55 +++++++++++++++++++
1 file changed, 55 insertions(+)
create mode 100644 Documentation/devicetree/bindings/leds/regulator-led.yaml
diff --git a/Documentation/devicetree/bindings/leds/regulator-led.yaml b/Documentation/devicetree/bindings/leds/regulator-led.yaml
new file mode 100644
index 000000000000..3e020d700c00
--- /dev/null
+++ b/Documentation/devicetree/bindings/leds/regulator-led.yaml
@@ -0,0 +1,55 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/leds/regulator-led.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Device Tree Bindings for Regulator LEDs
+
+maintainers:
+ - Linus Walleij <linus.walleij@linaro.org>
+
+description: |
+ Regulator LEDs are powered by a single regulator such that they can
+ be turned on or off by enabling or disabling the regulator. The available
+ brightness settings will be inferred from the available voltages on the
+ regulator, and any constraints on the voltage or current will need to be
+ specified on the regulator.
+
+allOf:
+ - $ref: common.yaml#
+
+properties:
+ $nodename:
+ pattern: '^led.*$'
+
+ compatible:
+ const: regulator-led
+
+ vled-supply:
+ description:
+ The regulator controlling the current to the LED.
+
+ function: true
+ color: true
+ linux,default-trigger: true
+ default-state: true
+
+required:
+ - compatible
+ - vled-supply
+
+additionalProperties: false
+
+examples:
+ - |
+ #include <dt-bindings/leds/common.h>
+
+ led-heartbeat {
+ compatible = "regulator-led";
+ vled-supply = <®ulator>;
+ function = LED_FUNCTION_STATUS;
+ color = <LED_COLOR_ID_BLUE>;
+ linux,default-trigger = "heartbeat";
+ };
+...
--
2.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 1/3] dt-bindings: leds: Add regulator-led binding
2022-02-19 23:56 Linus Walleij
@ 2022-02-25 18:49 ` Rob Herring
0 siblings, 0 replies; 8+ messages in thread
From: Rob Herring @ 2022-02-25 18:49 UTC (permalink / raw)
To: Linus Walleij; +Cc: Pavel Machek, Antonio Ospite, linux-leds, devicetree
On Sun, 20 Feb 2022 00:56:05 +0100, Linus Walleij wrote:
> The regulator is a LED connected directly to a regulator and with
> its brightness controlled by the voltage of the regulator.
>
> Cc: devicetree@vger.kernel.org
> Cc: Antonio Ospite <ao2@ao2.it>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> ---
> .../bindings/leds/regulator-led.yaml | 55 +++++++++++++++++++
> 1 file changed, 55 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/leds/regulator-led.yaml
>
Reviewed-by: Rob Herring <robh@kernel.org>
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/3] dt-bindings: leds: Add regulator-led binding
@ 2022-04-04 20:35 Linus Walleij
2022-04-04 20:35 ` [PATCH 2/3] leds: regulator: Add dev helper variable Linus Walleij
` (3 more replies)
0 siblings, 4 replies; 8+ messages in thread
From: Linus Walleij @ 2022-04-04 20:35 UTC (permalink / raw)
To: Pavel Machek
Cc: linux-leds, Linus Walleij, devicetree, Antonio Ospite,
Rob Herring
The regulator is a LED connected directly to a regulator and with
its brightness controlled by the voltage of the regulator.
Cc: devicetree@vger.kernel.org
Cc: Antonio Ospite <ao2@ao2.it>
Reviewed-by: Rob Herring <robh@kernel.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
ChangeLog v1->v2:
- Collect Rob's ACK
- Rebase on v5.18-rc1
---
.../bindings/leds/regulator-led.yaml | 55 +++++++++++++++++++
1 file changed, 55 insertions(+)
create mode 100644 Documentation/devicetree/bindings/leds/regulator-led.yaml
diff --git a/Documentation/devicetree/bindings/leds/regulator-led.yaml b/Documentation/devicetree/bindings/leds/regulator-led.yaml
new file mode 100644
index 000000000000..3e020d700c00
--- /dev/null
+++ b/Documentation/devicetree/bindings/leds/regulator-led.yaml
@@ -0,0 +1,55 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/leds/regulator-led.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Device Tree Bindings for Regulator LEDs
+
+maintainers:
+ - Linus Walleij <linus.walleij@linaro.org>
+
+description: |
+ Regulator LEDs are powered by a single regulator such that they can
+ be turned on or off by enabling or disabling the regulator. The available
+ brightness settings will be inferred from the available voltages on the
+ regulator, and any constraints on the voltage or current will need to be
+ specified on the regulator.
+
+allOf:
+ - $ref: common.yaml#
+
+properties:
+ $nodename:
+ pattern: '^led.*$'
+
+ compatible:
+ const: regulator-led
+
+ vled-supply:
+ description:
+ The regulator controlling the current to the LED.
+
+ function: true
+ color: true
+ linux,default-trigger: true
+ default-state: true
+
+required:
+ - compatible
+ - vled-supply
+
+additionalProperties: false
+
+examples:
+ - |
+ #include <dt-bindings/leds/common.h>
+
+ led-heartbeat {
+ compatible = "regulator-led";
+ vled-supply = <®ulator>;
+ function = LED_FUNCTION_STATUS;
+ color = <LED_COLOR_ID_BLUE>;
+ linux,default-trigger = "heartbeat";
+ };
+...
--
2.35.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/3] leds: regulator: Add dev helper variable
2022-04-04 20:35 [PATCH 1/3] dt-bindings: leds: Add regulator-led binding Linus Walleij
@ 2022-04-04 20:35 ` Linus Walleij
2022-04-04 20:35 ` [PATCH 3/3] leds: regulator: Make probeable from device tree Linus Walleij
` (2 subsequent siblings)
3 siblings, 0 replies; 8+ messages in thread
From: Linus Walleij @ 2022-04-04 20:35 UTC (permalink / raw)
To: Pavel Machek; +Cc: linux-leds, Linus Walleij, Antonio Ospite
Instead of repeating the hard to read &pdev->dev just create a
local struct device *dev in probe().
Cc: Antonio Ospite <ao2@ao2.it>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
ChangeLog v1->v2:
- Rebase on v5.18-rc1
---
drivers/leds/leds-regulator.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/drivers/leds/leds-regulator.c b/drivers/leds/leds-regulator.c
index 208c98918433..87b9f46e572b 100644
--- a/drivers/leds/leds-regulator.c
+++ b/drivers/leds/leds-regulator.c
@@ -123,28 +123,29 @@ static int regulator_led_probe(struct platform_device *pdev)
{
struct led_regulator_platform_data *pdata =
dev_get_platdata(&pdev->dev);
+ struct device *dev = &pdev->dev;
struct regulator_led *led;
struct regulator *vcc;
int ret = 0;
if (pdata == NULL) {
- dev_err(&pdev->dev, "no platform data\n");
+ dev_err(dev, "no platform data\n");
return -ENODEV;
}
- vcc = devm_regulator_get_exclusive(&pdev->dev, "vled");
+ vcc = devm_regulator_get_exclusive(dev, "vled");
if (IS_ERR(vcc)) {
- dev_err(&pdev->dev, "Cannot get vcc for %s\n", pdata->name);
+ dev_err(dev, "Cannot get vcc for %s\n", pdata->name);
return PTR_ERR(vcc);
}
- led = devm_kzalloc(&pdev->dev, sizeof(*led), GFP_KERNEL);
+ led = devm_kzalloc(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",
+ dev_err(dev, "Invalid default brightness %d\n",
pdata->brightness);
return -EINVAL;
}
@@ -162,7 +163,7 @@ static int regulator_led_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, led);
- ret = led_classdev_register(&pdev->dev, &led->cdev);
+ ret = led_classdev_register(dev, &led->cdev);
if (ret < 0)
return ret;
--
2.35.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/3] leds: regulator: Make probeable from device tree
2022-04-04 20:35 [PATCH 1/3] dt-bindings: leds: Add regulator-led binding Linus Walleij
2022-04-04 20:35 ` [PATCH 2/3] leds: regulator: Add dev helper variable Linus Walleij
@ 2022-04-04 20:35 ` Linus Walleij
2022-05-02 21:25 ` [PATCH 1/3] dt-bindings: leds: Add regulator-led binding Linus Walleij
2022-05-04 17:42 ` Pavel Machek
3 siblings, 0 replies; 8+ messages in thread
From: Linus Walleij @ 2022-04-04 20:35 UTC (permalink / raw)
To: Pavel Machek; +Cc: linux-leds, Linus Walleij, Antonio Ospite
The regulator LED can easily be adapted to probe from the
device tree.
We switch led_classdev_register() to led_classdev_register_ext()
passing some struct led_init_data init_data that we leave NULL
save the fwnode if platform data isn't present so that it will be
populated from the device tree.
If we have platform data we set up the name from the platform
data but using init_data instead.
Cc: Antonio Ospite <ao2@ao2.it>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
ChangeLog v1->v2:
- Rebase on v5.18-rc1
---
drivers/leds/leds-regulator.c | 42 +++++++++++++++++++----------------
1 file changed, 23 insertions(+), 19 deletions(-)
diff --git a/drivers/leds/leds-regulator.c b/drivers/leds/leds-regulator.c
index 87b9f46e572b..8a8b73b4e358 100644
--- a/drivers/leds/leds-regulator.c
+++ b/drivers/leds/leds-regulator.c
@@ -8,6 +8,7 @@
*/
#include <linux/module.h>
+#include <linux/mod_devicetable.h>
#include <linux/err.h>
#include <linux/slab.h>
#include <linux/leds.h>
@@ -124,18 +125,14 @@ static int regulator_led_probe(struct platform_device *pdev)
struct led_regulator_platform_data *pdata =
dev_get_platdata(&pdev->dev);
struct device *dev = &pdev->dev;
+ struct led_init_data init_data = {};
struct regulator_led *led;
struct regulator *vcc;
int ret = 0;
- if (pdata == NULL) {
- dev_err(dev, "no platform data\n");
- return -ENODEV;
- }
-
vcc = devm_regulator_get_exclusive(dev, "vled");
if (IS_ERR(vcc)) {
- dev_err(dev, "Cannot get vcc for %s\n", pdata->name);
+ dev_err(dev, "Cannot get vcc\n");
return PTR_ERR(vcc);
}
@@ -143,15 +140,21 @@ static int regulator_led_probe(struct platform_device *pdev)
if (led == NULL)
return -ENOMEM;
+ init_data.fwnode = dev->fwnode;
+
led->cdev.max_brightness = led_regulator_get_max_brightness(vcc);
- if (pdata->brightness > led->cdev.max_brightness) {
- dev_err(dev, "Invalid default brightness %d\n",
+ /* Legacy platform data label assignment */
+ if (pdata) {
+ if (pdata->brightness > led->cdev.max_brightness) {
+ dev_err(dev, "Invalid default brightness %d\n",
pdata->brightness);
- return -EINVAL;
+ return -EINVAL;
+ }
+ led->cdev.brightness = pdata->brightness;
+ init_data.default_label = pdata->name;
}
led->cdev.brightness_set_blocking = regulator_led_brightness_set;
- led->cdev.name = pdata->name;
led->cdev.flags |= LED_CORE_SUSPENDRESUME;
led->vcc = vcc;
@@ -163,16 +166,10 @@ static int regulator_led_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, led);
- ret = led_classdev_register(dev, &led->cdev);
+ ret = led_classdev_register_ext(dev, &led->cdev, &init_data);
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;
}
@@ -185,10 +182,17 @@ static int regulator_led_remove(struct platform_device *pdev)
return 0;
}
+static const struct of_device_id regulator_led_of_match[] = {
+ { .compatible = "regulator-led", },
+ {}
+};
+MODULE_DEVICE_TABLE(of, regulator_led_of_match);
+
static struct platform_driver regulator_led_driver = {
.driver = {
- .name = "leds-regulator",
- },
+ .name = "leds-regulator",
+ .of_match_table = regulator_led_of_match,
+ },
.probe = regulator_led_probe,
.remove = regulator_led_remove,
};
--
2.35.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 1/3] dt-bindings: leds: Add regulator-led binding
2022-04-04 20:35 [PATCH 1/3] dt-bindings: leds: Add regulator-led binding Linus Walleij
2022-04-04 20:35 ` [PATCH 2/3] leds: regulator: Add dev helper variable Linus Walleij
2022-04-04 20:35 ` [PATCH 3/3] leds: regulator: Make probeable from device tree Linus Walleij
@ 2022-05-02 21:25 ` Linus Walleij
2022-05-04 17:42 ` Pavel Machek
3 siblings, 0 replies; 8+ messages in thread
From: Linus Walleij @ 2022-05-02 21:25 UTC (permalink / raw)
To: Pavel Machek; +Cc: linux-leds, devicetree, Antonio Ospite, Rob Herring
Hi Pavel,
On Mon, Apr 4, 2022 at 10:37 PM Linus Walleij <linus.walleij@linaro.org> wrote:
> The regulator is a LED connected directly to a regulator and with
> its brightness controlled by the voltage of the regulator.
>
> Cc: devicetree@vger.kernel.org
> Cc: Antonio Ospite <ao2@ao2.it>
> Reviewed-by: Rob Herring <robh@kernel.org>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> ---
> ChangeLog v1->v2:
> - Collect Rob's ACK
> - Rebase on v5.18-rc1
can we merge this patch set?
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/3] dt-bindings: leds: Add regulator-led binding
2022-04-04 20:35 [PATCH 1/3] dt-bindings: leds: Add regulator-led binding Linus Walleij
` (2 preceding siblings ...)
2022-05-02 21:25 ` [PATCH 1/3] dt-bindings: leds: Add regulator-led binding Linus Walleij
@ 2022-05-04 17:42 ` Pavel Machek
2022-05-05 7:06 ` Antonio Ospite
3 siblings, 1 reply; 8+ messages in thread
From: Pavel Machek @ 2022-05-04 17:42 UTC (permalink / raw)
To: Linus Walleij; +Cc: linux-leds, devicetree, Antonio Ospite, Rob Herring
[-- Attachment #1: Type: text/plain, Size: 318 bytes --]
On Mon 2022-04-04 22:35:20, Linus Walleij wrote:
> The regulator is a LED connected directly to a regulator and with
> its brightness controlled by the voltage of the regulator.
Thank you, applied.
Best regards,
Pavel
--
People of Russia, stop Putin before his war on Ukraine escalates.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/3] dt-bindings: leds: Add regulator-led binding
2022-05-04 17:42 ` Pavel Machek
@ 2022-05-05 7:06 ` Antonio Ospite
0 siblings, 0 replies; 8+ messages in thread
From: Antonio Ospite @ 2022-05-05 7:06 UTC (permalink / raw)
To: Pavel Machek; +Cc: Linus Walleij, linux-leds, devicetree, Rob Herring
On Wed, 4 May 2022 19:42:29 +0200
Pavel Machek <pavel@ucw.cz> wrote:
> On Mon 2022-04-04 22:35:20, Linus Walleij wrote:
> > The regulator is a LED connected directly to a regulator and with
> > its brightness controlled by the voltage of the regulator.
>
> Thank you, applied.
>
Thank you all for keeping this driver up to date :)
Ciao,
Antonio
--
Antonio Ospite
https://ao2.it
https://twitter.com/ao2it
A: Because it messes up the order in which people normally read text.
See http://en.wikipedia.org/wiki/Posting_style
Q: Why is top-posting such a bad thing?
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2022-05-05 7:41 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-04 20:35 [PATCH 1/3] dt-bindings: leds: Add regulator-led binding Linus Walleij
2022-04-04 20:35 ` [PATCH 2/3] leds: regulator: Add dev helper variable Linus Walleij
2022-04-04 20:35 ` [PATCH 3/3] leds: regulator: Make probeable from device tree Linus Walleij
2022-05-02 21:25 ` [PATCH 1/3] dt-bindings: leds: Add regulator-led binding Linus Walleij
2022-05-04 17:42 ` Pavel Machek
2022-05-05 7:06 ` Antonio Ospite
-- strict thread matches above, loose matches on Subject: below --
2022-02-19 23:56 Linus Walleij
2022-02-25 18:49 ` Rob Herring
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox