leds: introduce generic LED level meter driver
Subsystems (2)
v2 cover leds: introduce 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]/
* v2
- Use proper subject line for dt-binding patch.
- Swap the patch order.
- Various fixes noticed by Rob and Dan.
- Update example usage for brightness-weights property
- Use unified device proerty interface as much as possible.
- Support linux,default-trigger and default-state properties.
Akinobu Mita (2):
dt-bindings: leds: Add leds-meter binding
leds: Add generic LED level meter driver
.../devicetree/bindings/leds/leds-meter.yaml | 67 +++++++++ drivers/leds/Kconfig | 10 ++ drivers/leds/Makefile | 1 + drivers/leds/leds-meter.c | 151 +++++++++++++++++++++ 4 files changed, 229 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/leds-meter.yaml create mode 100644 drivers/leds/leds-meter.c
Signature · 1 line
2.7.4
PATCH v2 1/2 dt-bindings: leds: Add leds-meter binding
Add DT binding for generic LED level meter which consists of multiple LED devices by different drivers.
--- .../devicetree/bindings/leds/leds-meter.yaml | 67 ++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/leds-meter.yaml
Documentation/devicetree/bindings/leds/leds-meter.yaml new file +67 -0
@@ -0,0 +1,67 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%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: + $nodename: + pattern: "^meter-leds(@.*)?" + + compatible: + const: meter-leds + + leds: + allOf: + - $ref: /schemas/types.yaml#/definitions/phandle-array + description: List of phandles to LED node that are members of a level meter. + + brightness-weights: + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32-array + description: | + By default, the brightness of the LED level meter is proportional to the + number of actual LEDs that are turned on. We can optionally specify + the contribution ratio for each LED within a level meter by this + property. The example below shows how to setup an exponential + relationship between the number of LEDs turned on and the brightness of + meter-leds. + +required: + - compatible + - leds + +additionalProperties: false + +examples: + - | + // Example 1: LED level meter with four LEDs + meter-leds { + compatible = "meter-leds"; + leds = <&led0>, <&led1>, <&led2>, <&led3>; + }; + + // Example 2: Exponential relationship between the number of LEDs turned on + // and the brightness of meter-leds + // + // When the maximum brightness is 255 + // - No LEDs are turned on if brightness == 0 + // - led0 is turned on if 0 < brightness <= 32 + // - led0 and led1 are turned on if 32 < brightness <= 64 + // - led0, led1, and led2 are turned on if 64 < brightness <= 128 + // - All LEDs are turned on if 128 < brightness <= 255 + meter-leds { + compatible = "meter-leds"; + leds = <&led0>, <&led1>, <&led2>, <&led3>; + brightness-weights = <32 32 64 127>; + }; + +...
Signature · 1 line
2.7.4
Re: [PATCH v2 1/2] dt-bindings: leds: Add leds-meter binding
Akinobu
Quoted 80 lines · Akinobu Mita
Add DT binding for generic LED level meter which consists of multiple LED devices by different drivers.
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]>Signed-off-by Akinobu Mita <[email protected]>--- .../devicetree/bindings/leds/leds-meter.yaml | 67 ++++++++++++++++++++++ 1 file changed, 67 insertions(+)create mode 100644
Documentation/devicetree/bindings/leds/leds-meter.yamlDocumentation/devicetree/bindings/leds/leds-meter.yaml new file +57
-0@@ -0,0 +1,67 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%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: + $nodename: + pattern: "^meter-leds(@.*)?" + + compatible: + const: meter-leds + + leds: + allOf: + - $ref: /schemas/types.yaml#/definitions/phandle-array + description: List of phandles to LED node that are members of a level meter. + + brightness-weights: + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32-array + description: | + By default, the brightness of the LED level meter is proportional to the + number of actual LEDs that are turned on. We can optionally specify + the contribution ratio for each LED within a level meter by this + property. The example below shows how to setup an exponential + relationship between the number of LEDs turned on and the brightness of + meter-leds. + +required: + - compatible + - leds + +additionalProperties: false + +examples: + - | + // Example 1: LED level meter with four LEDs + meter-leds { + compatible = "meter-leds"; + leds = <&led0>, <&led1>, <&led2>, <&led3>; + }; + + // Example 2: Exponential relationship between the number of LEDs turned on + // and the brightness of meter-leds + // + // When the maximum brightness is 255 + // - No LEDs are turned on if brightness == 0 + // - led0 is turned on if 0 < brightness <= 32
Documentation/devicetree/bindings/leds/leds-meter.yaml line 67
Quoted 10 lines
Documentation/devicetree/bindings/leds/leds-meter.yaml new file +10
-0+ // - led0 and led1 are turned on if 32 < brightness <= 64 + // - led0, led1, and led2 are turned on if 64 < brightness <= 128 + // - All LEDs are turned on if 128 < brightness <= 255 + meter-leds { + compatible = "meter-leds"; + leds = <&led0>, <&led1>, <&led2>, <&led3>; + brightness-weights = <32 32 64 127>; + }; + +...
Fails binding check
Documentation/devicetree/bindings/leds/leds-meter.example.dts:32.20-36.11: ERROR (duplicate_node_names): /example-0/meter-leds: Duplicate node name
ERROR: Input tree has errors, aborting (use -f to force output)scripts/Makefile.lib:314: recipe for target 'Documentation/devicetree/bindings/leds/leds-meter.example.dt.yaml' failed make[1]: *** [Documentation/devicetree/bindings/leds/leds-meter.example.dt.yaml] Error 2
Makefile:1284: recipe for target 'dt_binding_check' failed
make: *** [dt_binding_check] Error 2
Re: [PATCH v2 1/2] dt-bindings: leds: Add leds-meter binding
2019年10月29日(火) 21:06 Dan Murphy <[email protected]>:
Quoted 97 lines
Akinobu
Quoted 80 lines · Akinobu Mita
Add DT binding for generic LED level meter which consists of multiple LED devices by different drivers.
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]>Signed-off-by Akinobu Mita <[email protected]>--- .../devicetree/bindings/leds/leds-meter.yaml | 67 ++++++++++++++++++++++ 1 file changed, 67 insertions(+)create mode 100644
Documentation/devicetree/bindings/leds/leds-meter.yamlDocumentation/devicetree/bindings/leds/leds-meter.yaml new file +57
-0@@ -0,0 +1,67 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%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: + $nodename: + pattern: "^meter-leds(@.*)?" + + compatible: + const: meter-leds + + leds: + allOf: + - $ref: /schemas/types.yaml#/definitions/phandle-array + description: List of phandles to LED node that are members of a level meter. + + brightness-weights: + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32-array + description: | + By default, the brightness of the LED level meter is proportional to the + number of actual LEDs that are turned on. We can optionally specify + the contribution ratio for each LED within a level meter by this + property. The example below shows how to setup an exponential + relationship between the number of LEDs turned on and the brightness of + meter-leds. + +required: + - compatible + - leds + +additionalProperties: false + +examples: + - | + // Example 1: LED level meter with four LEDs + meter-leds { + compatible = "meter-leds"; + leds = <&led0>, <&led1>, <&led2>, <&led3>; + }; + + // Example 2: Exponential relationship between the number of LEDs turned on + // and the brightness of meter-leds + // + // When the maximum brightness is 255 + // - No LEDs are turned on if brightness == 0 + // - led0 is turned on if 0 < brightness <= 32Documentation/devicetree/bindings/leds/leds-meter.yaml line 67
Quoted 10 lines
Documentation/devicetree/bindings/leds/leds-meter.yaml new file +10
-0+ // - led0 and led1 are turned on if 32 < brightness <= 64 + // - led0, led1, and led2 are turned on if 64 < brightness <= 128 + // - All LEDs are turned on if 128 < brightness <= 255 + meter-leds { + compatible = "meter-leds"; + leds = <&led0>, <&led1>, <&led2>, <&led3>; + brightness-weights = <32 32 64 127>; + }; + +...Fails binding check
Quoted 10 lines
Documentation/devicetree/bindings/leds/leds-meter.example.dts:32.20-36.11:
ERROR (duplicate_node_names): /example-0/meter-leds: Duplicate node name
ERROR: Input tree has errors, aborting (use -f to force output)scripts/Makefile.lib:314: recipe for target 'Documentation/devicetree/bindings/leds/leds-meter.example.dt.yaml' failed make[1]: *** [Documentation/devicetree/bindings/leds/leds-meter.example.dt.yaml] Error 2 Makefile:1284: recipe for target 'dt_binding_check' failed
make: *** [dt_binding_check] Error 2
Thanks for reporting. This is because the two examples have the same node name, so we need a '- |' line between the two examples.
And I noticed that current implementation doesn't follow the common leds properties described in Documentation/devicetree/bindings/leds/common.txt.
i.e. when we define two level meters in the system, we need to describe them like below.
meter-leds-4seg {
compatible = "meter-leds";
leds = <&led0>, <&led1>, <&led2>, <&led3>;
};
meter-leds-2seg {
compatible = "meter-leds";
leds = <&led4>, <&led5>;
};But, the description should be like this:
led-controller@0 {
compatible = "meter-leds"; meter-leds-4seg {
leds = <&led0>, <&led1>, <&led2>, <&led3>;
};
meter-leds-2seg {
leds = <&led4>, <&led5>;
};};
Rob Herring
maintainerRe: [PATCH v2 1/2] dt-bindings: leds: Add leds-meter binding
In reply to Akinobu MitaQuoted 2 lines · Akinobu Mita
Add DT binding for generic LED level meter which consists of multiple LED devices by different drivers.
Do you have some pointers to actual h/w?
Quoted 23 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]>Signed-off-by Akinobu Mita <[email protected]>--- .../devicetree/bindings/leds/leds-meter.yaml | 67 ++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/leds-meter.yamlDocumentation/devicetree/bindings/leds/leds-meter.yaml new file +3
-0@@ -0,0 +1,67 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +---
Documentation/devicetree/bindings/leds/leds-meter.yaml line 13
Quoted 10 lines
Documentation/devicetree/bindings/leds/leds-meter.yaml new file +10
-0+$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.
Googling this, the only thing I see is audio level meters though those are all just a voltage level input, so it could be any source I guess.
Quoted 13 lines
Documentation/devicetree/bindings/leds/leds-meter.yaml new file +13
-0+ +properties: + $nodename: + pattern: "^meter-leds(@.*)?" + + compatible: + const: meter-leds + + leds: + allOf: + - $ref: /schemas/types.yaml#/definitions/phandle-array + description: List of phandles to LED node that are members of a level meter. +
Documentation/devicetree/bindings/leds/leds-meter.yaml line 36
Quoted 10 lines
Documentation/devicetree/bindings/leds/leds-meter.yaml new file +10
-0+ brightness-weights: + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32-array + description: | + By default, the brightness of the LED level meter is proportional to the + number of actual LEDs that are turned on. We can optionally specify + the contribution ratio for each LED within a level meter by this + property. The example below shows how to setup an exponential + relationship between the number of LEDs turned on and the brightness of + meter-leds.
This seems oddly named if this is a bar graph. Yes, more LEDs on is brighter, but it's really a piecewise linear graph you want.
Each LED could have variable brightness, so you could also ramp the brightness for an individual LED.
Rob
Re: [PATCH v2 1/2] dt-bindings: leds: Add leds-meter binding
2019年10月30日(水) 23:24 Rob Herring <[email protected]>:
Quoted 6 lines · Akinobu Mita
Quoted 2 lines
Add DT binding for generic LED level meter which consists of multiple LED devices by different drivers.
Do you have some pointers to actual h/w?
This doesn't require a specific hardware.
If there are more than two LEDs that can be described by devicetree, it can be an LED level meter by bundling them up with this binding.
Quoted 55 lines
Quoted 23 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]>Signed-off-by Akinobu Mita <[email protected]>--- .../devicetree/bindings/leds/leds-meter.yaml | 67 ++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/leds-meter.yamlDocumentation/devicetree/bindings/leds/leds-meter.yaml new file +3
-0@@ -0,0 +1,67 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +---Documentation/devicetree/bindings/leds/leds-meter.yaml line 13
Quoted 10 lines
Documentation/devicetree/bindings/leds/leds-meter.yaml new file +10
-0+$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.Googling this, the only thing I see is audio level meters though those are all just a voltage level input, so it could be any source I guess.
Quoted 18 lines
Documentation/devicetree/bindings/leds/leds-meter.yaml new file +18
-0+ +properties: + $nodename: + pattern: "^meter-leds(@.*)?" + + compatible: + const: meter-leds + + leds: + allOf: + - $ref: /schemas/types.yaml#/definitions/phandle-array + description: List of phandles to LED node that are members of a level meter. + + brightness-weights: + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32-array + description: | + By default, the brightness of the LED level meter is proportional to the
Quoted 8 lines
Documentation/devicetree/bindings/leds/leds-meter.yaml line 36
Quoted 5 lines
Documentation/devicetree/bindings/leds/leds-meter.yaml new file +5
-0+ number of actual LEDs that are turned on. We can optionally specify + the contribution ratio for each LED within a level meter by this + property. The example below shows how to setup an exponential + relationship between the number of LEDs turned on and the brightness of + meter-leds.This seems oddly named if this is a bar graph. Yes, more LEDs on is brighter, but it's really a piecewise linear graph you want.
OK. I'll rewrite the description.
Quoted 2 lines
Each LED could have variable brightness, so you could also ramp the brightness for an individual LED.
For now, each LED is set to 0 or max brightness. Maybe we should set middle brightness value for an LED on the border line.
Rob Herring
maintainerRe: [PATCH v2 1/2] dt-bindings: leds: Add leds-meter binding
Quoted 10 lines · Akinobu Mita
2019年10月30日(水) 23:24 Rob Herring <[email protected]>:
Quoted 6 lines · Akinobu Mita
Quoted 2 lines
Add DT binding for generic LED level meter which consists of multiple LED devices by different drivers.
Do you have some pointers to actual h/w?
This doesn't require a specific hardware.
But I do for my understanding. If I don't understand it, then my default answer is: no, we don't do "generic" bindings because the h/w is never generic.
Quoted 2 lines
If there are more than two LEDs that can be described by devicetree, it can be an LED level meter by bundling them up with this binding.
Depends on the physical locations too? If you just want to group any random LEDs, then do that from userspace because it's more flexible.
Rob
Re: [PATCH v2 1/2] dt-bindings: leds: Add leds-meter binding
2019年10月31日(木) 3:29 Rob Herring <[email protected]>:
Quoted 9 lines · Akinobu Mita
Quoted 7 lines
2019年10月30日(水) 23:24 Rob Herring <[email protected]>:
Quoted 5 lines · Akinobu Mita
Quoted 2 lines
Add DT binding for generic LED level meter which consists of multiple LED devices by different drivers.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Do you have some pointers to actual h/w?
This doesn't require a specific hardware.
But I do for my understanding. If I don't understand it, then my default answer is: no, we don't do "generic" bindings because the h/w is never generic.
For example, https://www.switch-science.com/catalog/2677/
The LEDs on this board are controlled by NXP PCA9956B. The driver is under development by Bjorn Andersson.
But the LED level meter doesn't depend on the actual LED controller driver, so I call it "generic" LED level meter driver.
Quoted 5 lines
Quoted 2 lines
If there are more than two LEDs that can be described by devicetree, it can be an LED level meter by bundling them up with this binding.
Depends on the physical locations too? If you just want to group any random LEDs, then do that from userspace because it's more flexible.
Yes. I assume that the level meter's LEDs are mounted in a line, or matrix. I plan to rename it to 'leds-array' because 'leds-meter' is unclear.
PATCH v2 2/2 leds: Add generic LED level meter driver
In reply to Akinobu MitaThis 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 within a level meter by specifying the contribution ratio for each LED with the brightness-weights proporty.
For example, the following brightness-weights proporty provides an exponential relationship between the number of LEDs turned on and the brightness of meter-leds.
meter-leds {
compatible = "meter-leds";
leds = <&led0>, <&led1>, <&led2>, <&led3>;
brightness-weights = <32 32 64 127>;
};- No LEDs are turned on if brightness == 0
- led0 is turned on if 0 < brightness <= 32
- led0 and led1 are turned on if 32 < brightness <= 64
- led0, led1, and led2 are turned on if 64 < brightness <= 128
- All LEDs are turned on if 128 < brightness <= 255
--- drivers/leds/Kconfig | 10 +++ drivers/leds/Makefile | 1 + drivers/leds/leds-meter.c | 151 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 162 insertions(+) create mode 100644 drivers/leds/leds-meter.c
drivers/leds/Kconfig +10 -0
@@ -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
@@ -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 +151 -0
151 lines not on this page · raw message
Signature · 1 line
2.7.4