Skip to contentSkip to conversation

New multiple GPIOs LED driver

PATCH Superseded Hermes Zhang 5 participants 14 messages Mar 24, 2021 – Mar 28, 2021

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover New multiple GPIOs LED driver

From: Hermes Zhang <[email protected]>

*** BLURB HERE ***

New multiple GPIOs LED driver

Hermes Zhang (2):
leds: leds-multi-gpio: Add multiple GPIOs LED driver
dt-binding: leds: Document leds-multi-gpio bindings

 .../bindings/leds/leds-multi-gpio.yaml        |  50 +++++++
 drivers/leds/Kconfig                          |  12 ++
 drivers/leds/Makefile                         |   1 +
 drivers/leds/leds-multi-gpio.c                | 140 ++++++++++++++++++
 4 files changed, 203 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/leds/leds-multi-gpio.yaml
 create mode 100644 drivers/leds/leds-multi-gpio.c
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/2 leds: leds-multi-gpio: Add multiple GPIOs LED driver

From: Hermes Zhang <[email protected]>

Introduce a new multiple GPIOs LED driver. This LED will made of multiple GPIOs (up to 8) and will map different brightness to different GPIOs states which defined in dts file.

---
 drivers/leds/Kconfig           |  12 +++
 drivers/leds/Makefile          |   1 +
 drivers/leds/leds-multi-gpio.c | 140 +++++++++++++++++++++++++++++++++
 3 files changed, 153 insertions(+)
 create mode 100644 drivers/leds/leds-multi-gpio.c
drivers/leds/Kconfig +12 -0
index b6742b4231bf..e3ff84080192 100644
@@ -370,6 +370,18 @@ config LEDS_GPIO
 	  defined as platform devices and/or OpenFirmware platform devices.
 	  The code to use these bindings can be selected below.
 
+config LEDS_MULTI_GPIO
+	tristate "LED Support for multiple GPIOs LED"
+	depends on LEDS_CLASS
+	depends on GPIOLIB
+	help
+	  This option enables support for a multiple GPIOs LED. Such LED is made
+	  of multiple GPIOs and could change the brightness by setting different
+	  states of the GPIOs.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called leds-multi-gpio.
+
 config LEDS_LP3944
 	tristate "LED Support for N.S. LP3944 (Fun Light) I2C chip"
 	depends on LEDS_CLASS
drivers/leds/Makefile +1 -0
index 2a698df9da57..984201ec5375 100644
@@ -30,6 +30,7 @@ obj-$(CONFIG_LEDS_DA903X)		+= leds-da903x.o
 obj-$(CONFIG_LEDS_DA9052)		+= leds-da9052.o
 obj-$(CONFIG_LEDS_FSG)			+= leds-fsg.o
 obj-$(CONFIG_LEDS_GPIO)			+= leds-gpio.o
+obj-$(CONFIG_LEDS_MULTI_GPIO)		+= leds-multi-gpio.o
 obj-$(CONFIG_LEDS_GPIO_REGISTER)	+= leds-gpio-register.o
 obj-$(CONFIG_LEDS_HP6XX)		+= leds-hp6xx.o
 obj-$(CONFIG_LEDS_INTEL_SS4200)		+= leds-ss4200.o
drivers/leds/leds-multi-gpio.c new file +140 -0

140 lines not on this page · raw message

Signature · 1 line
2.20.1
#2 lore raw

Re: [PATCH 1/2] leds: leds-multi-gpio: Add multiple GPIOs LED driver

Quoted 5 lines · On Wed, 24 Mar 2021 15:56:30 +0800 Hermes Zhang <[email protected]> wrote:

From: Hermes Zhang <[email protected]>

Introduce a new multiple GPIOs LED driver. This LED will made of multiple GPIOs (up to 8) and will map different brightness to different GPIOs states which defined in dts file.

I wonder how many boards have such LEDs.

Also if it wouldn't be better to expand the original leds-gpio driver. Probably depends on how much larger would such expansion make the leds-gpio driver.

drivers/leds/leds-multi-gpio.c line 16

Quoted 11 lines
drivers/leds/leds-multi-gpio.c new file +11 -0
+#include <linux/err.h>
+#include <linux/gpio.h>
+#include <linux/gpio/consumer.h>
+#include <linux/kernel.h>
+#include <linux/leds.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_gpio.h>
+#include <linux/platform_device.h>
+#include <linux/property.h>
+#include <linux/slab.h>

Why do you include slab.h?

drivers/leds/leds-multi-gpio.c line 27

Quoted 11 lines
drivers/leds/leds-multi-gpio.c new file +11 -0
+
+#define MAX_GPIO_NUM  8
+
+struct multi_gpio_led_priv {
+	struct led_classdev cdev;
+
+	struct gpio_descs *gpios;
+
+	u8 *states;
+	int nr_states;
+};

Use flexible array members. Allocate with
devm_kzalloc(dev, struct_size(priv, states, priv->nr_states),
GFP_KERNEL)

drivers/leds/leds-multi-gpio.c line 40

Quoted 13 lines
drivers/leds/leds-multi-gpio.c new file +13 -0
+
+
+static void multi_gpio_led_set(struct led_classdev *led_cdev,
+	enum led_brightness value)
+{
+	struct multi_gpio_led_priv *priv;
+	int idx;
+
+	DECLARE_BITMAP(values, MAX_GPIO_NUM);
+
+	priv = container_of(led_cdev, struct multi_gpio_led_priv, cdev);
+
+	idx = (value - LED_OFF) * priv->nr_states / (LED_FULL + 1);

LED_FULL / LED_OFF are deprecated, don't use them.

Quoted 33 lines
drivers/leds/leds-multi-gpio.c new file +33 -0
+
+	values[0] = priv->states[idx];
+
+	gpiod_set_array_value(priv->gpios->ndescs, priv->gpios->desc,
+	    priv->gpios->info, values);
+}
+
+static int multi_gpio_led_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct device_node *node = dev->of_node;
+	struct multi_gpio_led_priv *priv = NULL;
+	int ret;
+	const char *state = NULL;
+	struct led_init_data init_data = {};
+
+	priv = devm_kzalloc(dev, sizeof(struct multi_gpio_led_priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	priv->gpios = devm_gpiod_get_array(dev, "led", GPIOD_OUT_LOW);
+	if (IS_ERR(priv->gpios))
+		return PTR_ERR(priv->gpios);
+
+	if (priv->gpios->ndescs >= MAX_GPIO_NUM) {
+		dev_err(dev, "Too many GPIOs\n");
+		return -EINVAL;
+	}
+
+	ret = of_property_count_u8_elems(node, "led-states");
+	if (ret < 0)
+		return ret;
+

drivers/leds/leds-multi-gpio.c line 83

Quoted 10 lines
drivers/leds/leds-multi-gpio.c new file +10 -0
+	priv->nr_states = ret;
+	priv->states = devm_kzalloc(dev, sizeof(*priv->states) * priv->nr_states, GFP_KERNEL);
+	if (!priv->states)
+		return -ENOMEM;
+
+	ret = of_property_read_u8_array(node, "led-states", priv->states, priv->nr_states);
+	if (ret)
+		return ret;
+
+	priv->cdev.max_brightness = LED_FULL;

???? max_brightness is not 255 (= LED_FULL). max_brightness must be derived from the led-states property.

Quoted 4 lines
drivers/leds/leds-multi-gpio.c new file +4 -0
+	priv->cdev.default_trigger = of_get_property(node, "linux,default-trigger", NULL);
+	priv->cdev.brightness_set = multi_gpio_led_set;
+
+	init_data.fwnode = of_fwnode_handle(node);

drivers/leds/leds-multi-gpio.c line 97

Quoted 10 lines
drivers/leds/leds-multi-gpio.c new file +10 -0
+
+	ret = devm_led_classdev_register_ext(dev, &priv->cdev, &init_data);
+	if (ret < 0)
+		return ret;
+
+	of_property_read_string(node, "default-state", &state);
+	if (!strcmp(state, "on"))
+		multi_gpio_led_set(&priv->cdev, LED_FULL);
+	else
+		multi_gpio_led_set(&priv->cdev, LED_OFF);

Again LED_FULL and LED_OFF...
What about default-state = "keep" ?

Hermes, do you actually have a device that controls LEDs this way? How many brightness options do they have?

Also I think this functionality could be easily incorporated into the existing leds-gpio driver, instead of creating new driver.

Moreover your driver can control only one LED, so it needs to be probed multiple times for multiple LEDs. Meanwhile the leds-gpio driver can register multiple LEDs in one probe...

Marek

#3 lore raw

Re: [PATCH 1/2] leds: leds-multi-gpio: Add multiple GPIOs LED driver

Hi!

Quoted 11 lines
Quoted 5 lines

From: Hermes Zhang <[email protected]>

Introduce a new multiple GPIOs LED driver. This LED will made of multiple GPIOs (up to 8) and will map different brightness to different GPIOs states which defined in dts file.

I wonder how many boards have such LEDs.

Also if it wouldn't be better to expand the original leds-gpio driver. Probably depends on how much larger would such expansion make the leds-gpio driver.

Let's start with separate.

Quoted 3 lines

Use flexible array members. Allocate with
devm_kzalloc(dev, struct_size(priv, states, priv->nr_states),
GFP_KERNEL)

Better yet, assume the brightness is 0..2^(num leds) and avoid this complexity.

Quoted 5 lines

Again LED_FULL and LED_OFF...
What about default-state = "keep" ?

Hermes, do you actually have a device that controls LEDs this way? How many brightness options do they have?

He has two bits.

Quoted 6 lines

Also I think this functionality could be easily incorporated into the existing leds-gpio driver, instead of creating new driver.

Moreover your driver can control only one LED, so it needs to be probed multiple times for multiple LEDs. Meanwhile the leds-gpio driver can register multiple LEDs in one probe...

The current version is mostly fine. Let's not overcomplicate it.

Best regards,
Pavel

Signature · 1 line
http://www.livejournal.com/~pavelmachek
#4 lore raw

Re: [PATCH 1/2] leds: leds-multi-gpio: Add multiple GPIOs LED driver

In reply to Marek Behun

Hi!

Quoted 8 lines

drivers/leds/leds-multi-gpio.c line 97

Quoted 5 lines
drivers/leds/leds-multi-gpio.c new file +5 -0
+	of_property_read_string(node, "default-state", &state);
+	if (!strcmp(state, "on"))
+		multi_gpio_led_set(&priv->cdev, LED_FULL);
+	else
+		multi_gpio_led_set(&priv->cdev, LED_OFF);

Again LED_FULL and LED_OFF...
What about default-state = "keep" ?

Let's not support default-state unless you need it.

Best regards,
Pavel

Signature · 1 line
http://www.livejournal.com/~pavelmachek
#5 lore raw

Re: [PATCH 1/2] leds: leds-multi-gpio: Add multiple GPIOs LED driver

In reply to Marek Behun

Hi Marek,

Quoted 4 lines · Marek Behun
Quoted 4 lines
drivers/leds/leds-multi-gpio.c new file +4 -0
+#include <linux/err.h>
+#include <linux/gpio.h>
+#include <linux/gpio/consumer.h>
+#include <linux/kernel.h>
Quoted 8 lines

drivers/leds/leds-multi-gpio.c line 16

Quoted 7 lines
drivers/leds/leds-multi-gpio.c new file +7 -0
+#include <linux/leds.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_gpio.h>
+#include <linux/platform_device.h>
+#include <linux/property.h>
+#include <linux/slab.h>

Why do you include slab.h?

Yeah, I will clean it in next commit.

Quoted 6 lines
Quoted 6 lines
drivers/leds/leds-multi-gpio.c new file +6 -0
+
+
+static void multi_gpio_led_set(struct led_classdev *led_cdev,
+	enum led_brightness value)
+{
+	struct multi_gpio_led_priv *priv;
Quoted 8 lines

drivers/leds/leds-multi-gpio.c line 40

Quoted 7 lines
drivers/leds/leds-multi-gpio.c new file +7 -0
+	int idx;
+
+	DECLARE_BITMAP(values, MAX_GPIO_NUM);
+
+	priv = container_of(led_cdev, struct multi_gpio_led_priv, cdev);
+
+	idx = (value - LED_OFF) * priv->nr_states / (LED_FULL + 1);

LED_FULL / LED_OFF are deprecated, don't use them.

Then could I use just 0 (instead LED_OFF) and led_cdev->max_brightness

(instead of LED_FULL) here? The idea here is map the states defined in dts

to the full brightness range.

Quoted 11 lines
drivers/leds/leds-multi-gpio.c new file +11 -0
+
+	priv->nr_states = ret;
+	priv->states = devm_kzalloc(dev, sizeof(*priv->states) * priv->nr_states, GFP_KERNEL);
+	if (!priv->states)
+		return -ENOMEM;
+
+	ret = of_property_read_u8_array(node, "led-states", priv->states, priv->nr_states);
+	if (ret)
+		return ret;
+
+	priv->cdev.max_brightness = LED_FULL;
Quoted 2 lines

???? max_brightness is not 255 (= LED_FULL). max_brightness must be derived from the led-states property.

Yeah, I will fix this. the max-brightness should for the whole LED, right? So

it will at same level with led-states.

#6 lore raw

Re: [PATCH 1/2] leds: leds-multi-gpio: Add multiple GPIOs LED driver

Quoted 7 lines · On Thu, 25 Mar 2021 06:04:43 +0000 Hermes Zhang <[email protected]> wrote:
Quoted 1 line

LED_FULL / LED_OFF are deprecated, don't use them.

Then could I use just 0 (instead LED_OFF) and led_cdev->max_brightness

(instead of LED_FULL) here? The idea here is map the states defined in dts

to the full brightness range.

Yes, you can and should use 0 insted of LED_OFF.

Quoted 8 lines
Quoted 3 lines
drivers/leds/leds-multi-gpio.c new file +1 -0
+	priv->cdev.max_brightness = LED_FULL;

???? max_brightness is not 255 (= LED_FULL). max_brightness must be derived from the led-states property.

Yeah, I will fix this. the max-brightness should for the whole LED, right? So

it will at same level with led-states.

max_brightness should be (the number of states - 1). I.e. if you have 4 gpios and the LED supports full 2^4 = 16 states, max brightness should be 15.

Marek

#7 lore raw

Re: [PATCH 1/2] leds: leds-multi-gpio: Add multiple GPIOs LED driver

In reply to Hermes Zhang
Quoted 6 lines · Hermes Zhang

From: Hermes Zhang <[email protected]>

Introduce a new multiple GPIOs LED driver. This LED will made of multiple GPIOs (up to 8) and will map different brightness to different GPIOs states which defined in dts file.

Quoted 7 lines
---
 drivers/leds/Kconfig           |  12 +++
 drivers/leds/Makefile          |   1 +
 drivers/leds/leds-multi-gpio.c | 140 +++++++++++++++++++++++++++++++++
 3 files changed, 153 insertions(+)
 create mode 100644 drivers/leds/leds-multi-gpio.c

Let's put it into drivers/leds/simple. You may need to create it.

Best regards,
Pavel

Signature · 1 line
http://www.livejournal.com/~pavelmachek
#8 lore raw

PATCH 2/2 dt-binding: leds: Document leds-multi-gpio bindings

In reply to Hermes Zhang

From: Hermes Zhang <[email protected]>

Document the device tree bindings of the multiple GPIOs LED driver Documentation/devicetree/bindings/leds/leds-multi-gpio.yaml.

---
 .../bindings/leds/leds-multi-gpio.yaml        | 50 +++++++++++++++++++
 1 file changed, 50 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/leds/leds-multi-gpio.yaml
Documentation/devicetree/bindings/leds/leds-multi-gpio.yaml new file +50 -0
new file mode 100644
index 000000000000..6f2b47487b90
@@ -0,0 +1,50 @@
+# SPDX-License-Identifier: GPL-2.0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/leds/leds-multi-gpio.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Multiple GPIOs LED driver
+
+maintainers:
+  - Hermes Zhang <[email protected]>
+
+description:
+  This will support some LED made of multiple GPIOs and the brightness of the
+  LED could map to different states of the GPIOs.
+
+properties:
+  compatible:
+    const: multi-gpio-led
+
+  led-gpios:
+    description: Array of one or more GPIOs pins used to control the LED.
+    minItems: 1
+    maxItems: 8  # Should be enough
+
+  led-states:
+    description: |
+      The array list the supported states here which will map to brightness
+      from 0 to maximum. Each item in the array will present all the GPIOs
+      value by bit.
+    $ref: /schemas/types.yaml#/definitions/uint8-array
+    minItems: 1
+    maxItems: 16 # Should be enough
+
+required:
+  - compatible
+  - led-gpios
+  - led-states
+
+additionalProperties: false
+
+examples:
+  - |
+    gpios-led {
+      compatible = "multi-gpio-led";
+
+      led-gpios = <&gpio0 23 0x1>,
+                  <&gpio0 24 0x1>;
+      led-states = /bits/ 8 <0x00 0x01 0x02 0x03>;
+    };
+...
Signature · 1 line
2.20.1
#9 lore raw

Re: [PATCH 2/2] dt-binding: leds: Document leds-multi-gpio bindings

Quoted 4 lines · On Wed, 24 Mar 2021 15:56:31 +0800 Hermes Zhang <[email protected]> wrote:

From: Hermes Zhang <[email protected]>

Document the device tree bindings of the multiple GPIOs LED driver Documentation/devicetree/bindings/leds/leds-multi-gpio.yaml.

The dt-binding should come before the actual driver. Otherwise there will be a commit with the driver existing but no documentation for its bindings.

Documentation/devicetree/bindings/leds/leds-multi-gpio.yaml line 14

Quoted 3 lines
Documentation/devicetree/bindings/leds/leds-multi-gpio.yaml new file +3 -0
+description:
+  This will support some LED made of multiple GPIOs and the brightness of the
+  LED could map to different states of the GPIOs.

Don't use future tense. Don't mention drivers in device tree binding documentation, if it can be helped. The device tree binding documentation should describe devices and their nodes... (and I see that I did a similar mistake for the cznic,turris-omnia-leds.yaml binding, I will have to fix that).

Instead the description should be something like this:
This binding represents LED devices which are controller with multiple GPIO lines in order to achieve more than two brightness states.

Quoted 5 lines
Documentation/devicetree/bindings/leds/leds-multi-gpio.yaml new file +5 -0
+
+properties:
+  compatible:
+    const: multi-gpio-led
+

Documentation/devicetree/bindings/leds/leds-multi-gpio.yaml line 29

Quoted 10 lines
Documentation/devicetree/bindings/leds/leds-multi-gpio.yaml new file +10 -0
+  led-gpios:
+    description: Array of one or more GPIOs pins used to control the LED.
+    minItems: 1
+    maxItems: 8  # Should be enough
+
+  led-states:
+    description: |
+      The array list the supported states here which will map to brightness
+      from 0 to maximum. Each item in the array will present all the GPIOs
+      value by bit.

Again future tense...

Quoted 21 lines
Documentation/devicetree/bindings/leds/leds-multi-gpio.yaml new file +21 -0
+    $ref: /schemas/types.yaml#/definitions/uint8-array
+    minItems: 1
+    maxItems: 16 # Should be enough
+
+required:
+  - compatible
+  - led-gpios
+  - led-states
+
+additionalProperties: false
+
+examples:
+  - |
+    gpios-led {
+      compatible = "multi-gpio-led";
+
+      led-gpios = <&gpio0 23 0x1>,
+                  <&gpio0 24 0x1>;
+      led-states = /bits/ 8 <0x00 0x01 0x02 0x03>;
+    };
+...
#10 lore raw

Re: [PATCH 2/2] dt-binding: leds: Document leds-multi-gpio bindings

In reply to Hermes Zhang

Hi,

See below.

Quoted 30 lines · Hermes Zhang

From: Hermes Zhang <[email protected]>

Document the device tree bindings of the multiple GPIOs LED driver Documentation/devicetree/bindings/leds/leds-multi-gpio.yaml.

---
  .../bindings/leds/leds-multi-gpio.yaml        | 50 +++++++++++++++++++
  1 file changed, 50 insertions(+)

create mode 100644 Documentation/devicetree/bindings/leds/leds-multi-gpio.yaml

Documentation/devicetree/bindings/leds/leds-multi-gpio.yaml new file +13 -0
new file mode 100644
index 000000000000..6f2b47487b90
@@ -0,0 +1,50 @@
+# SPDX-License-Identifier: GPL-2.0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/leds/leds-multi-gpio.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Multiple GPIOs LED driver
+
+maintainers:
+  - Hermes Zhang <[email protected]>
+
+description:
+  This will support some LED made of multiple GPIOs and the brightness of the

Documentation/devicetree/bindings/leds/leds-multi-gpio.yaml line 23

Quoted 10 lines
Documentation/devicetree/bindings/leds/leds-multi-gpio.yaml new file +10 -0
+  LED could map to different states of the GPIOs.
+
+properties:
+  compatible:
+    const: multi-gpio-led
+
+  led-gpios:
+    description: Array of one or more GPIOs pins used to control the LED.
+    minItems: 1
+    maxItems: 8  # Should be enough

We also have a case with multi color LEDs (which is probably a more common than multi intensity LED. So I am wondering how these both could co-exist.

From: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/devicetree/bindings/leds/leds-gpio.yaml?h=v5.12-rc4#n58

        led-0 {
            gpios = <&mcu_pio 0 GPIO_ACTIVE_LOW>;
            linux,default-trigger = "disk-activity";
            function = LED_FUNCTION_DISK;
        };

Now 'gpios' (and in LED context) and 'led-gpios' is very close to each other and could easily be confused.

Perhaps this could be something like:

intensity-gpios = ...

or even simplified then just to gpios = <...>

Quoted 18 lines
Documentation/devicetree/bindings/leds/leds-multi-gpio.yaml new file +17 -0
+
+  led-states:
+    description: |
+      The array list the supported states here which will map to brightness
+      from 0 to maximum. Each item in the array will present all the GPIOs
+      value by bit.
+    $ref: /schemas/types.yaml#/definitions/uint8-array
+    minItems: 1
+    maxItems: 16 # Should be enough
+
+required:
+  - compatible
+  - led-gpios
+  - led-states
+
+additionalProperties: false
+

Documentation/devicetree/bindings/leds/leds-multi-gpio.yaml line 50

Quoted 10 lines
Documentation/devicetree/bindings/leds/leds-multi-gpio.yaml new file +10 -0
+examples:
+  - |
+    gpios-led {
+      compatible = "multi-gpio-led";
+
+      led-gpios = <&gpio0 23 0x1>,
+                  <&gpio0 24 0x1>;
+      led-states = /bits/ 8 <0x00 0x01 0x02 0x03>;
+    };
+...

From: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/devicetree/bindings/leds/leds-lp55xx.yaml?h=v5.12-rc4#n196

There is example of multi color LED configuration. In example below I used two-color LED with red and green as an example (which what we seem to have most in use).

Then if try to combine these into something like:

# Multi color LED with single GPIO line per color
multi-led@2 {
compatible = "gpio-leds";
color = <LED_COLOR_ID_MULTICOLOR>;

  led@0 {
    color = <LED_COLOR_ID_GREEN>;
    gpios = <&mcu_pio 0 GPIO_ACTIVE_LOW>;

};

  led@1 {
    color = <LED_COLOR_ID_RED>;
    gpios = <&mcu_pio 1 GPIO_ACTIVE_LOW>;

};
};

# And with intensity GPIOs:
multi-led@2 {
compatible = "gpio-leds";
color = <LED_COLOR_ID_MULTICOLOR>;

  led@0 {
    color = <LED_COLOR_ID_GREEN>;
    gpios = <&gpio0 23 0x1>,
            <&gpio0 24 0x1>;
    ... see below
  };
  led@1 {
    color = <LED_COLOR_ID_RED>;
    gpios = <&gpio0 25 0x1>,
            <&gpio0 26 0x1>;
    ... see below

};
};

# And then single GPIO with intensity GPIOs:
led@2 {
compatible = "gpio-leds";
gpios = <&gpio0 23 0x1>,

          <&gpio0 24 0x1>;

gpios-brightness-levels = <0 1 2 3>
};

I changed 'led-states' to 'gpios-brightness-levels' as it describe more that this is about brightness and not some other state information.

How would this sound?

Thanks,
Vesa Jääskeläinen

#11 lore raw

Re: [PATCH 2/2] dt-binding: leds: Document leds-multi-gpio bindings

Hi!

Quoted 1 line

See below.

Please trim.

Quoted 24 lines

Documentation/devicetree/bindings/leds/leds-multi-gpio.yaml line 23

Quoted 4 lines
Documentation/devicetree/bindings/leds/leds-multi-gpio.yaml new file +4 -0
+  led-gpios:
+    description: Array of one or more GPIOs pins used to control the LED.
+    minItems: 1
+    maxItems: 8  # Should be enough

We also have a case with multi color LEDs (which is probably a more common than multi intensity LED. So I am wondering how these both could co-exist.

From: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/devicetree/bindings/leds/leds-gpio.yaml?h=v5.12-rc4#n58

        led-0 {
            gpios = <&mcu_pio 0 GPIO_ACTIVE_LOW>;
            linux,default-trigger = "disk-activity";
            function = LED_FUNCTION_DISK;
        };

Now 'gpios' (and in LED context) and 'led-gpios' is very close to each other and could easily be confused.

Perhaps this could be something like:

intensity-gpios = ...

or even simplified then just to gpios = <...>

...

Quoted 1 line

How would this sound?

Well, not too bad on a quick look.

Are you willing to implement such multi-color-multi-bit-multi-gpio driver?

Best regards,
Pavel

Signature · 1 line
http://www.livejournal.com/~pavelmachek
#12 lore raw

Re: [PATCH 2/2] dt-binding: leds: Document leds-multi-gpio bindings

Hi,

Quoted 25 lines · Pavel Machek
Quoted 16 lines

Documentation/devicetree/bindings/leds/leds-multi-gpio.yaml line 23

Quoted 4 lines
Documentation/devicetree/bindings/leds/leds-multi-gpio.yaml new file +4 -0
+  led-gpios:
+    description: Array of one or more GPIOs pins used to control the LED.
+    minItems: 1
+    maxItems: 8  # Should be enough

We also have a case with multi color LEDs (which is probably a more common than multi intensity LED. So I am wondering how these both could co-exist.

From: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/devicetree/bindings/leds/leds-gpio.yaml?h=v5.12-rc4#n58

         led-0 {
             gpios = <&mcu_pio 0 GPIO_ACTIVE_LOW>;
             linux,default-trigger = "disk-activity";
             function = LED_FUNCTION_DISK;
         };
Quoted 8 lines

Now 'gpios' (and in LED context) and 'led-gpios' is very close to each other and could easily be confused.

Perhaps this could be something like:

intensity-gpios = ...

or even simplified then just to gpios = <...>

Quoted 7 lines

...

Quoted 1 line

How would this sound?

Well, not too bad on a quick look.

Are you willing to implement such multi-color-multi-bit-multi-gpio driver?

We have a need for multi color GPIO LED support so I can work on that if no one else gets there before me -- I do not have hardware with multiple GPIO lines controlling the brightness so that needs a bit more effort in order to test that out.

At some point of time I could also revive the PWM stuff if no one else beats me to it -- but probably the GPIO variant is easier to get done as binary states are easier.

Thanks,
Vesa Jääskeläinen

#13 lore raw
In reply to Hermes Zhang
Quoted 3 lines · On Wed, 24 Mar 2021 15:56:29 +0800 Hermes Zhang <[email protected]> wrote:

From: Hermes Zhang <[email protected]>

*** BLURB HERE ***

"*** BLURB HERE ***" is meant to be substituted with your text :)

All in all I think you are adding functionality which can be incorporated simply into the existing leds-gpio driver instead of new driver.

Marek