Skip to contentSkip to conversation

leds: add generic LED level meter driver

PATCH Superseded Akinobu Mita 4 participants 7 messages Oct 22, 2019 – Dec 4, 2019

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover leds: add generic LED level meter driver

This introduces a new LED driver that enables us to create a virtual LED level meter device that consists of multiple LED devices by different drivers.

Previously I developed the level meter feature for leds-gpio ("leds: gpio:
support multi-level brightness") [1]. Then I got a feedback from Bjorn Andersson and made more generic new driver. This driver is also inspired by led-backlight driver patchset [2] and actually requires devm_of_led_get() function provided by the patchset.

[1] https://lore.kernel.org/linux-leds/[email protected]/
[2] https://lore.kernel.org/linux-leds/[email protected]/

Akinobu Mita (2):
leds: add LED level meter driver
leds: meter: add leds-meter binding

 .../devicetree/bindings/leds/leds-meter.yaml       |  42 +++++++
 drivers/leds/Kconfig                               |  10 ++
 drivers/leds/Makefile                              |   1 +
 drivers/leds/leds-meter.c                          | 134 +++++++++++++++++++++
 4 files changed, 187 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/leds/leds-meter.yaml
 create mode 100644 drivers/leds/leds-meter.c
Cc Rob Herring <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Bjorn Andersson <[email protected]>
Cc Tomi Valkeinen <[email protected]>
Cc Jean-Jacques Hiblot <[email protected]>
Cc Jacek Anaszewski <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Dan Murphy <[email protected]>
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/2 leds: add LED level meter driver

This introduces a new LED driver that enables us to create a virtual LED level meter device that consists of multiple LED devices by different drivers.

The brightness of the LED level meter is proportional to the number of actual LEDs that are turned on.

For example, the LED level meter with four LEDs can be described by the following DT node.

    meter-leds {
        compatible = "meter-leds";
        leds = <&led0>, <&led1>, <&led2>, <&led3>;
    };

When the brightness of meter-leds is LED_HALF, the brightness of the led0 and led1 is set to maximum brightness and the brightness of led2 and led3 is set to zero.

We can optionally control the proportionality by overvaluing some of LEDs with the brightness-weights proporty.

For example, when we assign the weight of led0 to the total weigt of the rest, only the led0 is turned on if the brightness of meter-leds is within the range of [1, LED_HALD].

    meter-leds {
        compatible = "meter-leds";
        leds = <&led0>, <&led1>, <&led2>, <&led3>;
        brightness-weights = <3 1 1 1>;
    };
Cc Rob Herring <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Bjorn Andersson <[email protected]>
Cc Tomi Valkeinen <[email protected]>
Cc Jean-Jacques Hiblot <[email protected]>
Cc Jacek Anaszewski <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Dan Murphy <[email protected]>
---
 drivers/leds/Kconfig      |  10 ++++
 drivers/leds/Makefile     |   1 +
 drivers/leds/leds-meter.c | 134 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 145 insertions(+)
 create mode 100644 drivers/leds/leds-meter.c
drivers/leds/Kconfig +10 -0
index 1988de1..feecd2e 100644
@@ -823,6 +823,16 @@ config LEDS_LM36274
 	  Say Y to enable the LM36274 LED driver for TI LMU devices.
 	  This supports the LED device LM36274.
 
+config LEDS_METER
+	tristate "LED support for generic level meter driver"
+	depends on LEDS_CLASS
+	help
+	  This option enables support for generic LED level meter that
+	  consists of multiple LED devices.
+
+	  To compile this driver as a module, choose M here: the module will
+	  be called leds-meter.
+
 comment "LED Triggers"
 source "drivers/leds/trigger/Kconfig"
 
drivers/leds/Makefile +1 -0
index 41fb073..0fe2a28 100644
@@ -85,6 +85,7 @@ obj-$(CONFIG_LEDS_LM3601X)		+= leds-lm3601x.o
 obj-$(CONFIG_LEDS_TI_LMU_COMMON)	+= leds-ti-lmu-common.o
 obj-$(CONFIG_LEDS_LM3697)		+= leds-lm3697.o
 obj-$(CONFIG_LEDS_LM36274)		+= leds-lm36274.o
+obj-$(CONFIG_LEDS_METER)		+= leds-meter.o
 
 # LED SPI Drivers
 obj-$(CONFIG_LEDS_CR0014114)		+= leds-cr0014114.o
drivers/leds/leds-meter.c new file +134 -0

134 lines not on this page · raw message

Signature · 1 line
2.7.4
#2 lore raw

PATCH 2/2 leds: meter: add leds-meter binding

In reply to Akinobu Mita

Add DT binding for leds-meter.

Cc Rob Herring <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Bjorn Andersson <[email protected]>
Cc Tomi Valkeinen <[email protected]>
Cc Jean-Jacques Hiblot <[email protected]>
Cc Jacek Anaszewski <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Dan Murphy <[email protected]>
---
 .../devicetree/bindings/leds/leds-meter.yaml       | 42 ++++++++++++++++++++++
 1 file changed, 42 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/leds/leds-meter.yaml
Documentation/devicetree/bindings/leds/leds-meter.yaml new file +42 -0
new file mode 100644
index 0000000..d5dfa261
@@ -0,0 +1,42 @@
+# SPDX-License-Identifier: GPL-2.0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/leds/leds-meter.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Generic LED level meter
+
+maintainers:
+  - Akinobu Mita <[email protected]>
+
+description:
+  Generic LED level meter consists of multiple LED devices by different drivers.
+
+properties:
+  compatible:
+    const: meter-leds
+
+  leds:
+    $ref: /schemas/types.yaml#/definitions/phandle-array
+    minItems: 1
+    description: List of phandles to LED node that are members of a level meter.
+
+  brightness-weights:
+    $ref: /schemas/types.yaml#/definitions/uint32-array
+    minItems: 1
+    description: Each integer represents a contribution ratio within a level
+      meter.
+
+required:
+ - compatible
+ - leds
+
+examples:
+  - |
+    leds {
+        compatible = "meter-leds";
+        leds = <&led0>, <&led1>, <&led2>, <&led3>;
+        brightness-weights = <3 1 1 1>;
+    };
+
+...
Signature · 1 line
2.7.4
#3 lore raw

Re: [PATCH 2/2] leds: meter: add leds-meter binding

Akinobu

Quoted 1 line · Akinobu Mita

Add DT binding for leds-meter.

$subject should be

 dt-bindings: leds: Add leds-meter binding

And this patch should be first in the series

Quoted 29 lines
Cc Rob Herring <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Bjorn Andersson <[email protected]>
Cc Tomi Valkeinen <[email protected]>
Cc Jean-Jacques Hiblot <[email protected]>
Cc Jacek Anaszewski <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Dan Murphy <[email protected]>
---
  .../devicetree/bindings/leds/leds-meter.yaml       | 42 ++++++++++++++++++++++
  1 file changed, 42 insertions(+)

create mode 100644 Documentation/devicetree/bindings/leds/leds-meter.yaml

Documentation/devicetree/bindings/leds/leds-meter.yaml new file +9 -0
new file mode 100644
index 0000000..d5dfa261
@@ -0,0 +1,42 @@
+# SPDX-License-Identifier: GPL-2.0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/leds/leds-meter.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Generic LED level meter
+
+maintainers:

Documentation/devicetree/bindings/leds/leds-meter.yaml line 19

Quoted 10 lines
Documentation/devicetree/bindings/leds/leds-meter.yaml new file +10 -0
+  - Akinobu Mita <[email protected]>
+
+description:
+  Generic LED level meter consists of multiple LED devices by different drivers.
+
+properties:
+  compatible:
+    const: meter-leds
+
+  leds:

This seems a bit generic for the property name

Documentation/devicetree/bindings/leds/leds-meter.yaml line 28

Quoted 9 lines
Documentation/devicetree/bindings/leds/leds-meter.yaml new file +9 -0
+    $ref: /schemas/types.yaml#/definitions/phandle-array
+    minItems: 1
+    description: List of phandles to LED node that are members of a level meter.
+
+  brightness-weights:
+    $ref: /schemas/types.yaml#/definitions/uint32-array
+    minItems: 1
+    description: Each integer represents a contribution ratio within a level
+      meter.

This description is a bit vague I would not be sure what I would set this to.

Dan

Quoted 14 lines
Documentation/devicetree/bindings/leds/leds-meter.yaml new file +14 -0
+
+required:
+ - compatible
+ - leds
+
+examples:
+  - |
+    leds {
+        compatible = "meter-leds";
+        leds = <&led0>, <&led1>, <&led2>, <&led3>;
+        brightness-weights = <3 1 1 1>;
+    };
+
+...
#4 lore raw

Re: [PATCH 2/2] leds: meter: add leds-meter binding

2019年10月23日(水) 21:35 Dan Murphy <[email protected]>:

Quoted 11 lines

Akinobu

Quoted 1 line · Akinobu Mita

Add DT binding for leds-meter.

$subject should be

dt-bindings: leds: Add leds-meter binding

And this patch should be first in the series

OK.

Quoted 33 lines
Quoted 33 lines
Cc Rob Herring <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Bjorn Andersson <[email protected]>
Cc Tomi Valkeinen <[email protected]>
Cc Jean-Jacques Hiblot <[email protected]>
Cc Jacek Anaszewski <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Dan Murphy <[email protected]>
---
  .../devicetree/bindings/leds/leds-meter.yaml       | 42 ++++++++++++++++++++++
  1 file changed, 42 insertions(+)

create mode 100644 Documentation/devicetree/bindings/leds/leds-meter.yaml

Documentation/devicetree/bindings/leds/leds-meter.yaml new file +13 -0
new file mode 100644
index 0000000..d5dfa261
@@ -0,0 +1,42 @@
+# SPDX-License-Identifier: GPL-2.0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/leds/leds-meter.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Generic LED level meter
+
+maintainers:
+  - Akinobu Mita <[email protected]>
+
+description:
+  Generic LED level meter consists of multiple LED devices by different drivers.
Quoted 8 lines

Documentation/devicetree/bindings/leds/leds-meter.yaml line 19

Quoted 6 lines
Documentation/devicetree/bindings/leds/leds-meter.yaml new file +6 -0
+
+properties:
+  compatible:
+    const: meter-leds
+
+  leds:

This seems a bit generic for the property name

I have no problem with changing to more descriptive name like "meter-leds". But this property is parsed by of_led_get(), so we need to change of_led_get() to take additional 'prefix' parameter. I would like to hear led-backlight authors' opinion.

Quoted 10 lines

Documentation/devicetree/bindings/leds/leds-meter.yaml line 28

Quoted 9 lines
Documentation/devicetree/bindings/leds/leds-meter.yaml new file +9 -0
+    $ref: /schemas/types.yaml#/definitions/phandle-array
+    minItems: 1
+    description: List of phandles to LED node that are members of a level meter.
+
+  brightness-weights:
+    $ref: /schemas/types.yaml#/definitions/uint32-array
+    minItems: 1
+    description: Each integer represents a contribution ratio within a level
+      meter.
Quoted 2 lines

This description is a bit vague I would not be sure what I would set this to.

OK. I'll add some description and examples like I wrote in the commit message for patch 1/2.

#5 lore raw

Re: [PATCH 2/2] leds: meter: add leds-meter binding

In reply to Akinobu Mita
Quoted 2 lines · Akinobu Mita

Add DT binding for leds-meter.

What's an leds meter? Need a better explanation to understand if this makes sense at all, but some comments on the schema below.

Quoted 20 lines
Cc Rob Herring <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Bjorn Andersson <[email protected]>
Cc Tomi Valkeinen <[email protected]>
Cc Jean-Jacques Hiblot <[email protected]>
Cc Jacek Anaszewski <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Dan Murphy <[email protected]>
---
 .../devicetree/bindings/leds/leds-meter.yaml       | 42 ++++++++++++++++++++++
 1 file changed, 42 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/leds/leds-meter.yaml
Documentation/devicetree/bindings/leds/leds-meter.yaml new file +0 -0
new file mode 100644
index 0000000..d5dfa261

Documentation/devicetree/bindings/leds/leds-meter.yaml line 1

Quoted 1 line
Documentation/devicetree/bindings/leds/leds-meter.yaml new file +1 -0
@@ -0,0 +1,42 @@
+# SPDX-License-Identifier: GPL-2.0

(GPL-2.0-only OR BSD-2-Clause) for new bindings.

Quoted 10 lines
Documentation/devicetree/bindings/leds/leds-meter.yaml new file +10 -0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/leds/leds-meter.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Generic LED level meter
+
+maintainers:
+  - Akinobu Mita <[email protected]>
+

Documentation/devicetree/bindings/leds/leds-meter.yaml line 21

Quoted 10 lines
Documentation/devicetree/bindings/leds/leds-meter.yaml new file +10 -0
+description:
+  Generic LED level meter consists of multiple LED devices by different drivers.
+
+properties:
+  compatible:
+    const: meter-leds
+
+  leds:
+    $ref: /schemas/types.yaml#/definitions/phandle-array
+    minItems: 1

No need for this as the minimum for arrays is already 1. And it doesn't work either. You'd need the $ref under an 'allOf'.

Documentation/devicetree/bindings/leds/leds-meter.yaml line 32

Quoted 11 lines
Documentation/devicetree/bindings/leds/leds-meter.yaml new file +11 -0
+    description: List of phandles to LED node that are members of a level meter.
+
+  brightness-weights:
+    $ref: /schemas/types.yaml#/definitions/uint32-array
+    minItems: 1
+    description: Each integer represents a contribution ratio within a level
+      meter.
+
+required:
+ - compatible
+ - leds

Add a:

additionalProperties: false

Documentation/devicetree/bindings/leds/leds-meter.yaml line 36

Quoted 4 lines
Documentation/devicetree/bindings/leds/leds-meter.yaml new file +4 -0
+
+examples:
+  - |
+    leds {

Needs to be a name that's not also a property name. 'leds-meter' or 'meter-leds' perhaps. And define the name above under a $nodename property.

Quoted 9 lines
Documentation/devicetree/bindings/leds/leds-meter.yaml new file +6 -1
+        compatible = "meter-leds";
+        leds = <&led0>, <&led1>, <&led2>, <&led3>;
+        brightness-weights = <3 1 1 1>;
+    };
+
+...
--

2.7.4

#6 lore raw

Re: [PATCH 2/2] leds: meter: add leds-meter binding

Quoted 6 lines · Rob Herring
Quoted 2 lines · Akinobu Mita

Add DT binding for leds-meter.

What's an leds meter? Need a better explanation to understand if this makes sense at all, but some comments on the schema below.

It groups several LEDs into one "virtual" LED.

I'm not sure I like it. What is it good for?

We do not have many triggers that dim the LEDs, and if it is only used from userspace, it can stay in userspace...?

Best regards,
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html