leds: add driver for SPI driven WorldSemi WS2812B RGB LEDs
Subsystems (3)
cover leds: add driver for SPI driven WorldSemi WS2812B RGB LEDs
This patch adds support for driving a chain of WS2812B LED chips using SPI bus.
WorldSemi WS2812B is a individually addressable LED chip that can be chained together and controlled individually using a single wire. The chip recognize a long pulse as a bit of 1 and a short pulse as a bit of 0. Host sends a continuous stream of 24-bits color values, each LED chip takes the first 3 byte it receives as its color value and passes the leftover bytes to the next LED on the chain.
This driver simulates this protocol using SPI bus by sending a long pulse as 3'b110 and a short pulse as 3'b100. The SPI frequency needs to be 2.105MHz~2.85MHz for the timing to be correct and the controller needs to transfer all the bytes continuously.
Chuanhong Guo (3):
dt-bindings: vendor-prefixes: add an entry for WorldSemi
dt-bindings: leds: add dt schema for worldsemi,ws2812b-spi
leds: add driver for SPI driven WorldSemi WS2812B RGB LEDs
.../bindings/leds/worldsemi,ws2812b-spi.yaml | 131 +++++++++++ .../devicetree/bindings/vendor-prefixes.yaml | 2 + drivers/leds/rgb/Kconfig | 11 + drivers/leds/rgb/Makefile | 1 + drivers/leds/rgb/leds-ws2812b-spi.c | 222 ++++++++++++++++++ 5 files changed, 367 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml create mode 100644 drivers/leds/rgb/leds-ws2812b-spi.c
Signature · 1 line
2.38.1
PATCH 1/3 dt-bindings: vendor-prefixes: add an entry for WorldSemi
WorldSemi is well-known for their WS2812B individually-addressable RGB LEDs on the market.
Add a vendor prefix for it.
--- Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++ 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/vendor-prefixes.yaml +2 -0
@@ -1462,6 +1462,8 @@ patternProperties: description: Wondermedia Technologies, Inc. "^wobo,.*": description: Wobo + "^worldsemi,.*": + description: WorldSemi Co., Limited "^wanchanglong,.*": description: Wanchanglong Electronics Technology(SHENZHEN)Co.,Ltd. "^x-powers,.*":
Signature · 1 line
2.38.1
Re: [PATCH 1/3] dt-bindings: vendor-prefixes: add an entry for WorldSemi
Quoted 1 line · Chuanhong Guo
WorldSemi is well-known for their WS2812B individually-addressable
Drop marketing. If they were well known, they would be already in vendor prefixes, right?
Add vendor prefix for WorldSemi that makes WS2812B individually-addressable RGB LEDs.
Quoted 14 lines
RGB LEDs on the market.
Add a vendor prefix for it.
Signed-off-by Chuanhong Guo <[email protected]>--- Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++ 1 file changed, 2 insertions(+)Documentation/devicetree/bindings/vendor-prefixes.yaml +0
-0
Documentation/devicetree/bindings/vendor-prefixes.yaml patternProperties: · line 1469
Quoted 8 lines
Documentation/devicetree/bindings/vendor-prefixes.yaml +2
-0@@ -1462,6 +1462,8 @@ patternProperties: description: Wondermedia Technologies, Inc. "^wobo,.*": description: Wobo + "^worldsemi,.*": + description: WorldSemi Co., Limited "^wanchanglong,.*": description: Wanchanglong Electronics Technology(SHENZHEN)Co.,Ltd. "^x-powers,.*":
Best regards,
Krzysztof
Re: [PATCH 1/3] dt-bindings: vendor-prefixes: add an entry for WorldSemi
Hi!
Quoted 10 lines · Krzysztof Kozlowski
Quoted 1 line · Chuanhong Guo
WorldSemi is well-known for their WS2812B individually-addressable
Drop marketing. If they were well known, they would be already in vendor prefixes, right?
Add vendor prefix for WorldSemi that makes WS2812B individually-addressable RGB LEDs.
OK. I'll do so in v2.
Signature · 2 lines
Regards, Chuanhong Guo
PATCH 2/3 dt-bindings: leds: add dt schema for worldsemi,ws2812b-spi
In reply to Chuanhong GuoThis patch adds dt binding schema for WorldSemi WS2812B driven using SPI bus.
--- .../bindings/leds/worldsemi,ws2812b-spi.yaml | 131 ++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml new file +131 -0
@@ -0,0 +1,131 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/leds/worldsemi,ws2812b-spi.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: WS2812B LEDs driven using SPI + +maintainers: + - Chuanhong Guo <[email protected]> + +description: | + WorldSemi WS2812B is a individually addressable LED chip that can be chained + together and controlled individually using a single wire. + This driver simulates the protocol used by this LED chip with SPI bus. + Typical setups includes connecting the data pin of the LED chain to MOSI as + the only device or using CS and MOSI with a tri-state voltage-level shifter + for the data pin. + The SPI frequency needs to be 2.105MHz~2.85MHz for the timing to be correct + and the controller needs to send all the bytes continuously. + +allOf: + - $ref: /schemas/spi/spi-peripheral-props.yaml# + +properties: + compatible: + const: worldsemi,ws2812b-spi + + reg: + description: The chip-select line on the SPI bus + maxItems: 1 + + spi-max-frequency: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + Maximum SPI clocking speed of the device in Hz. + minimum: 2105000 + maximum: 2850000 + + "#address-cells": + const: 1 + + "#size-cells": + const: 0 + +patternProperties: + "^multi-led(@[0-9a-f])?$": + type: object + $ref: leds-class-multicolor.yaml# + + properties: + color-index: + description: | + A 3-item array specifying color of each components in this LED. It + should be one of the LED_COLOR_ID_* prefixed definitions from the + header include/dt-bindings/leds/common.h. Defaults to + <LED_COLOR_ID_GREEN LED_COLOR_ID_RED LED_COLOR_ID_BLUE> + if unspecified. + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 3 + maxItems: 3 + + default-intensity: + description: | + An array of 3 integer specifying the default intensity of each color + components in this LED. <255 255 255> if unspecified. + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 3 + maxItems: 3 + items: + minimum: 0 + maximum: 255 + + reg: + description: | + Which LED this node represents. The reg of the first LED on the chain + is 0. + + required: + - reg + - color + - function + +required: + - compatible + +additionalProperties: false + +examples: + - | + #include <dt-bindings/leds/common.h> + spi { + #address-cells = <1>; + #size-cells = <0>; + + ws2812b@0 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "worldsemi,ws2812b-spi"; + reg = <0>; + spi-max-frequency = <2850000>; + multi-led@0 { + reg = <0>; + color-index = <LED_COLOR_ID_RED LED_COLOR_ID_GREEN LED_COLOR_ID_BLUE>; + default-intensity = <10 50 90>; + color = <LED_COLOR_ID_RGB>; + function = LED_FUNCTION_STATUS; + function-enumerator = <0>; + }; + multi-led@1 { + reg = <1>; + color = <LED_COLOR_ID_RGB>; + function = LED_FUNCTION_STATUS; + function-enumerator = <1>; + }; + multi-led@2 { + reg = <2>; + color = <LED_COLOR_ID_RGB>; + function = LED_FUNCTION_STATUS; + function-enumerator = <2>; + }; + multi-led@3 { + reg = <3>; + color = <LED_COLOR_ID_RGB>; + function = LED_FUNCTION_STATUS; + function-enumerator = <3>; + }; + }; + }; + +...
Signature · 1 line
2.38.1
Re: [PATCH 2/3] dt-bindings: leds: add dt schema for worldsemi,ws2812b-spi
Quoted 20 lines · Chuanhong Guo
This patch adds dt binding schema for WorldSemi WS2812B driven using SPI bus.
Signed-off-by Chuanhong Guo <[email protected]>--- .../bindings/leds/worldsemi,ws2812b-spi.yaml | 131 ++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yamlDocumentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml new file +5
-0@@ -0,0 +1,131 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/leds/worldsemi,ws2812b-spi.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml#
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml line 15
Quoted 10 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml new file +10
-0+ +title: WS2812B LEDs driven using SPI + +maintainers: + - Chuanhong Guo <[email protected]> + +description: | + WorldSemi WS2812B is a individually addressable LED chip that can be chained + together and controlled individually using a single wire. + This driver simulates the protocol used by this LED chip with SPI bus.
Drop references to Linux driver, unless important for the binding.
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml line 27
Quoted 12 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml new file +12
-0+ Typical setups includes connecting the data pin of the LED chain to MOSI as + the only device or using CS and MOSI with a tri-state voltage-level shifter + for the data pin. + The SPI frequency needs to be 2.105MHz~2.85MHz for the timing to be correct + and the controller needs to send all the bytes continuously. + +allOf: + - $ref: /schemas/spi/spi-peripheral-props.yaml# + +properties: + compatible: + const: worldsemi,ws2812b-spi
Drop "-spi". Compatibles are not supposed to include bus information. The same for file name.
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml line 30
Quoted 3 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml new file +3
-0+ + reg: + description: The chip-select line on the SPI bus
Drop description, it's obvious.
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml line 36
Quoted 6 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml new file +6
-0+ maxItems: 1 + + spi-max-frequency: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + Maximum SPI clocking speed of the device in Hz.
No need for ref and description. It comes from spi-peripheral-props.
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml line 47
Quoted 11 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml new file +11
-0+ minimum: 2105000 + maximum: 2850000 + + "#address-cells": + const: 1 + + "#size-cells": + const: 0 + +patternProperties: + "^multi-led(@[0-9a-f])?$":
Why unit address is optional?
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml line 49
Quoted 2 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml new file +2
-0+ type: object + $ref: leds-class-multicolor.yaml#
unevaluatedProperties: false
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml line 60
Quoted 11 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml new file +11
-0+ + properties: + color-index: + description: | + A 3-item array specifying color of each components in this LED. It + should be one of the LED_COLOR_ID_* prefixed definitions from the + header include/dt-bindings/leds/common.h. Defaults to + <LED_COLOR_ID_GREEN LED_COLOR_ID_RED LED_COLOR_ID_BLUE> + if unspecified. + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 3
Drop minItems.... but see comment below:
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml line 61
Quoted 1 line
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml new file +1
-0+ maxItems: 3
Why this is different than other multi-color LEDs? I would expect here children with common.yaml.
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml line 68
Quoted 7 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml new file +7
-0+ + default-intensity: + description: | + An array of 3 integer specifying the default intensity of each color + components in this LED. <255 255 255> if unspecified. + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 3
Drop minItems.... but:
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml line 72
Quoted 4 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml new file +4
-0+ maxItems: 3 + items: + minimum: 0 + maximum: 255
default: 255
What controls the intensity? Don't you have PWM there?
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml line 77
Quoted 5 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml new file +5
-0+ + reg: + description: | + Which LED this node represents. The reg of the first LED on the chain + is 0.
maxItems: 1
Quoted 9 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml new file +9
-0+ + required: + - reg + - color + - function + +required: + - compatible +
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml line 96
Quoted 10 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml new file +10
-0+additionalProperties: false + +examples: + - | + #include <dt-bindings/leds/common.h> + spi { + #address-cells = <1>; + #size-cells = <0>; + + ws2812b@0 {
Node names should be generic.
https://devicetree-specification.readthedocs.io/en/latest/chapter2-devicetree-basics.html#generic-names-recommendation
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml line 100
Quoted 4 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml new file +4
-0+ #address-cells = <1>; + #size-cells = <0>; + compatible = "worldsemi,ws2812b-spi"; + reg = <0>;
compatible is first property, reg is second.
Best regards,
Krzysztof
Re: [PATCH 2/3] dt-bindings: leds: add dt schema for worldsemi,ws2812b-spi
Hi,
Quoted 3 lines · Krzysztof Kozlowski
Quoted 2 lines · Chuanhong Guo
This patch adds dt binding schema for WorldSemi WS2812B driven using SPI bus.
Nice, I have a hobby project for something similar (SK6812, which is basically WS2812 with an extra white channel). I will switch to this work and extend it once it lands :)
[...]
Quoted 7 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml line 68
Quoted 6 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml new file +6
-0+ default-intensity: + description: | + An array of 3 integer specifying the default intensity of each color + components in this LED. <255 255 255> if unspecified. + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 3
Quoted 8 lines
Drop minItems.... but:
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml line 72
Quoted 4 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml new file +4
-0+ maxItems: 3 + items: + minimum: 0 + maximum: 255default: 255
I would argue, that the default should be 0 (off) instead of 255 (full power).
Quoted 1 line
What controls the intensity? Don't you have PWM there?
WS2812 is a RGB led, which contains a small Microcontroller. The µC takes 24 byte intensity data from a serial input and then passes on any following bits to the next LED. SPI clk and chip-select are ignored (chip-select support can be trivially added though).
You can find them everywhere nowadays, since they are quite cheap (a few cents per LED) and need only one MOSI pin to control hundreds of LEDs.
[...]
-- Sebastian
Re: [PATCH 2/3] dt-bindings: leds: add dt schema for worldsemi,ws2812b-spi
Quoted 14 lines · Sebastian Reichel
Quoted 14 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml line 68
Quoted 6 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml new file +6
-0+ default-intensity: + description: | + An array of 3 integer specifying the default intensity of each color + components in this LED. <255 255 255> if unspecified. + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 3Drop minItems.... but:
Quoted 4 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml new file +4
-0+ maxItems: 3 + items: + minimum: 0 + maximum: 255
Quoted 4 lines
Quoted 1 line
default: 255
I would argue, that the default should be 0 (off) instead of 255 (full power).
Yes.
Quoted 11 lines
Quoted 2 lines
What controls the intensity? Don't you have PWM there?
WS2812 is a RGB led, which contains a small Microcontroller. The µC takes 24 byte intensity data from a serial input and then passes on any following bits to the next LED. SPI clk and chip-select are ignored (chip-select support can be trivially added though).
You can find them everywhere nowadays, since they are quite cheap (a few cents per LED) and need only one MOSI pin to control hundreds of LEDs.
OK. This should be anyway existing property, so default-brightness.
Best regards,
Krzysztof
Re: [PATCH 2/3] dt-bindings: leds: add dt schema for worldsemi,ws2812b-spi
Hi!
Quoted 7 lines · Krzysztof Kozlowski
Quoted 7 lines
Quoted 1 line
What controls the intensity? Don't you have PWM there?
WS2812 is a RGB led, which contains a small Microcontroller. The µC takes 24 byte intensity data from a serial input and then passes on any following bits to the next LED. SPI clk and chip-select are ignored (chip-select support can be trivially added though).
Quoted 5 lines
Quoted 3 lines
You can find them everywhere nowadays, since they are quite cheap (a few cents per LED) and need only one MOSI pin to control hundreds of LEDs.
OK. This should be anyway existing property, so default-brightness.
default-intensity is a different property. Intensity controls only the color for a multicolor led. The final brightness is calculated with this intensity value with the single brightness value of the current LED. (See my previous mail.)
Signature · 2 lines
Regards, Chuanhong Guo
Re: [PATCH 2/3] dt-bindings: leds: add dt schema for worldsemi,ws2812b-spi
In reply to Krzysztof KozlowskiHi!
Quoted 6 lines · Krzysztof Kozlowski
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml line 15
Quoted 4 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml new file +4
-0+description: | + WorldSemi WS2812B is a individually addressable LED chip that can be chained + together and controlled individually using a single wire. + This driver simulates the protocol used by this LED chip with SPI bus.Drop references to Linux driver, unless important for the binding.
I think the SPI part is important. (I'll explain it below.) What about:
This binding describes a chain of WS2812B LEDs connected to the SPI MOSI pin.
instead?
Quoted 7 lines
Quoted 7 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml new file +7
-0+ Typical setups includes connecting the data pin of the LED chain to MOSI as + the only device or using CS and MOSI with a tri-state voltage-level shifter + for the data pin. + The SPI frequency needs to be 2.105MHz~2.85MHz for the timing to be correct + and the controller needs to send all the bytes continuously. + +allOf:
Quoted 8 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml line 27
Quoted 5 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml new file +5
-0+ - $ref: /schemas/spi/spi-peripheral-props.yaml# + +properties: + compatible: + const: worldsemi,ws2812b-spiDrop "-spi". Compatibles are not supposed to include bus information. The same for file name.
WS2812B isn't a SPI chip. It's controlled with only a single wire and can be driven
using anything that can produce a long and a short pulse meeting its timing requirement.
This driver uses a SPI bus to send the pulses, but it can also be controlled with
I2S and the PIO pins on a Raspberry Pi Pico.
This spi suffix is to distinguish it from other possible implementations if someone
else submits a support with a different peripheral.
Quoted 6 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml line 30
Quoted 4 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml new file +3
-0+ + reg: + description: The chip-select line on the SPI busDrop description, it's obvious.
OK.
Quoted 9 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml line 36
Quoted 7 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml new file +6
-0+ maxItems: 1 + + spi-max-frequency: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + Maximum SPI clocking speed of the device in Hz.No need for ref and description. It comes from spi-peripheral-props.
OK.
Quoted 14 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml line 47
Quoted 12 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml new file +11
-0+ minimum: 2105000 + maximum: 2850000 + + "#address-cells": + const: 1 + + "#size-cells": + const: 0 + +patternProperties: + "^multi-led(@[0-9a-f])?$":Why unit address is optional?
It isn't. I copy-pasted it from led-class-multicolor.yaml and didn't check the exact regex.
I'll fix it in the next version.
Quoted 5 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml line 49
Quoted 3 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml new file +2
-0+ type: object + $ref: leds-class-multicolor.yaml#unevaluatedProperties: false
OK.
Quoted 12 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml line 60
Quoted 11 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml new file +11
-0+ + properties: + color-index: + description: | + A 3-item array specifying color of each components in this LED. It + should be one of the LED_COLOR_ID_* prefixed definitions from the + header include/dt-bindings/leds/common.h. Defaults to + <LED_COLOR_ID_GREEN LED_COLOR_ID_RED LED_COLOR_ID_BLUE> + if unspecified. + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 3
Quoted 6 lines
Drop minItems.... but see comment below:
Quoted 1 line
+ maxItems: 3
Why this is different than other multi-color LEDs? I would expect here children with
common.yaml.
WS2812B is a single LED package with 3 diodes and a microcontroller. Each LED package has 3 colors. The original chip comes with GRB color while there are some clones with RGB arrangement instead. The LED chain can be really long so I'd like to simplify the binding by using a single property to override the only variable, color, here.
Quoted 11 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml line 68
Quoted 8 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml new file +7
-0+ + default-intensity: + description: | + An array of 3 integer specifying the default intensity of each color + components in this LED. <255 255 255> if unspecified. + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 3Drop minItems.... but:
Quoted 8 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml line 72
Quoted 4 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml new file +4
-0+ maxItems: 3 + items: + minimum: 0 + maximum: 255default: 255
What controls the intensity? Don't you have PWM there?
The LED takes 3-byte brightness value of each color. This property is used to specify the default multi_intensity field for the multi-color LED. The final brightness value is calculated with led_mc_calc_color_components like this:
mcled_cdev->subled_info[i].brightness = brightness * mcled_cdev->subled_info[i].intensity / led_cdev->max_brightness;
The LED chip takes exactly 8 bits for the brightness (max_brightness = 255 which can't be changed.), so according to the formula above the maximum intensity should be 255.
Quoted 8 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml line 77
Quoted 6 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml new file +5
-0+ + reg: + description: | + Which LED this node represents. The reg of the first LED on the chain + is 0.maxItems: 1
OK.
Quoted 15 lines
Quoted 15 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml new file +14
-0+ + required: + - reg + - color + - function + +required: + - compatible + +additionalProperties: false + +examples: + - | + #include <dt-bindings/leds/common.h>
Quoted 8 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml line 96
Quoted 5 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml new file +5
-0+ spi { + #address-cells = <1>; + #size-cells = <0>; + + ws2812b@0 {Node names should be generic.
https://devicetree-specification.readthedocs.io/en/latest/chapter2-devicetree-basics.html#generic-names-recommendation
OK. I'll use leds instead.
Quoted 7 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml line 100
Quoted 5 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml new file +4
-0+ #address-cells = <1>; + #size-cells = <0>; + compatible = "worldsemi,ws2812b-spi"; + reg = <0>;compatible is first property, reg is second.
Got it.
--
Regards,
Chuanhong Guo
Re: [PATCH 2/3] dt-bindings: leds: add dt schema for worldsemi,ws2812b-spi
Quoted 9 lines · Chuanhong Guo
Hi!
Quoted 5 lines · Krzysztof Kozlowski
Quoted 4 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml new file +4
-0+description: | + WorldSemi WS2812B is a individually addressable LED chip that can be chained + together and controlled individually using a single wire. + This driver simulates the protocol used by this LED chip with SPI bus.
Quoted 7 lines
Quoted 1 line
Drop references to Linux driver, unless important for the binding.
I think the SPI part is important. (I'll explain it below.) What about:
This binding describes a chain of WS2812B LEDs connected to the SPI MOSI pin.
instead?
OK
Quoted 17 lines
Quoted 16 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml line 27
Quoted 13 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml new file +12
-0+ Typical setups includes connecting the data pin of the LED chain to MOSI as + the only device or using CS and MOSI with a tri-state voltage-level shifter + for the data pin. + The SPI frequency needs to be 2.105MHz~2.85MHz for the timing to be correct + and the controller needs to send all the bytes continuously. + +allOf: + - $ref: /schemas/spi/spi-peripheral-props.yaml# + +properties: + compatible: + const: worldsemi,ws2812b-spiDrop "-spi". Compatibles are not supposed to include bus information. The same for file name.
Quoted 10 lines
WS2812B isn't a SPI chip. It's controlled with only a single wire and can be driven
using anything that can produce a long and a short pulse meeting its timing requirement.
This driver uses a SPI bus to send the pulses, but it can also be controlled with
I2S and the PIO pins on a Raspberry Pi Pico.
This spi suffix is to distinguish it from other possible implementations if someone
else submits a support with a different peripheral.
And that's exactly what I said - the compatibles should not include bus information. The bus information comes from... the bus!
Quoted 37 lines
Quoted 7 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml line 30
Quoted 5 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml new file +3
-0+ + reg: + description: The chip-select line on the SPI busDrop description, it's obvious.
OK.
Quoted 9 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml line 36
Quoted 7 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml new file +6
-0+ maxItems: 1 + + spi-max-frequency: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + Maximum SPI clocking speed of the device in Hz.No need for ref and description. It comes from spi-peripheral-props.
OK.
Quoted 14 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml line 47
Quoted 12 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml new file +11
-0+ minimum: 2105000 + maximum: 2850000 + + "#address-cells": + const: 1 + + "#size-cells": + const: 0 + +patternProperties: + "^multi-led(@[0-9a-f])?$":Why unit address is optional?
Quoted 3 lines
It isn't. I copy-pasted it from
led-class-multicolor.yamland didn't check the exact regex.
I'll fix it in the next version.
Make it required and matching your case.
Quoted 25 lines
Quoted 6 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml line 49
Quoted 4 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml new file +2
-0+ type: object + $ref: leds-class-multicolor.yaml#unevaluatedProperties: false
OK.
Quoted 16 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml line 60
Quoted 11 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml new file +11
-0+ + properties: + color-index: + description: | + A 3-item array specifying color of each components in this LED. It + should be one of the LED_COLOR_ID_* prefixed definitions from the + header include/dt-bindings/leds/common.h. Defaults to + <LED_COLOR_ID_GREEN LED_COLOR_ID_RED LED_COLOR_ID_BLUE> + if unspecified. + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 3Drop minItems.... but see comment below:
Quoted 1 line
+ maxItems: 3
Quoted 8 lines
Quoted 2 lines
Why this is different than other multi-color LEDs? I would expect here children with
common.yaml.WS2812B is a single LED package with 3 diodes and a microcontroller. Each LED package has 3 colors. The original chip comes with GRB color while there are some clones with RGB arrangement instead. The LED chain can be really long so I'd like to simplify the binding by using a single property to override the only variable, color, here.
OK, that makes sense.
Quoted 25 lines
Quoted 12 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml line 68
Quoted 9 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml new file +7
-0+ + default-intensity: + description: | + An array of 3 integer specifying the default intensity of each color + components in this LED. <255 255 255> if unspecified. + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 3Drop minItems.... but:
Quoted 8 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml line 72
Quoted 4 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml new file +4
-0+ maxItems: 3 + items: + minimum: 0 + maximum: 255default: 255
What controls the intensity? Don't you have PWM there?
The LED takes 3-byte brightness value of each color. This property is used to specify the default
multi_intensityfield for the multi-color LED. The final brightness value is calculated withled_mc_calc_color_componentslike this:
Quoted 6 lines
mcled_cdev->subled_info[i].brightness = brightness * mcled_cdev->subled_info[i].intensity /
led_cdev->max_brightness;The LED chip takes exactly 8 bits for the brightness (
max_brightness= 255 which can't be changed.), so according to the formula above the maximum intensity should be 255.
So this is brightness of each color... why insisting on calling it differently?
Best regards,
Krzysztof
Re: [PATCH 2/3] dt-bindings: leds: add dt schema for worldsemi,ws2812b-spi
Hi!
Quoted 2 lines · Krzysztof Kozlowski
And that's exactly what I said - the compatibles should not include bus information. The bus information comes from... the bus!
Oh. I thought there will be a conflict if there is a SPI driver and , say, an I2C driver with the same compatible string.
Quoted 9 lines
[...]
Quoted 6 lines
Quoted 2 lines
Why unit address is optional?
It isn't. I copy-pasted it from
led-class-multicolor.yamland didn't check the exact regex.
I'll fix it in the next version.Make it required and matching your case.
Got it.
Quoted 9 lines
[...]
Quoted 6 lines
Quoted 6 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml line 68
Quoted 6 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml new file +6
-0+ default-intensity: + description: | + An array of 3 integer specifying the default intensity of each color + components in this LED. <255 255 255> if unspecified. + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 3[...]
So this is brightness of each color...
I don't think so.
See the kernel doc for multicolor LED:
https://docs.kernel.org/leds/leds-class-multicolor.html
This property sets the sysfs file multi_intensity while the actual LED brightness is controlled with another sysfs file called 'brightness'.
Setting multi_intensity alone doesn't change the LED brightness at all.
Signature · 2 lines
Regards, Chuanhong Guo
Re: [PATCH 2/3] dt-bindings: leds: add dt schema for worldsemi,ws2812b-spi
Quoted 9 lines · Chuanhong Guo
Hi!
Quoted 2 lines · Krzysztof Kozlowski
And that's exactly what I said - the compatibles should not include bus information. The bus information comes from... the bus!
Oh. I thought there will be a conflict if there is a SPI driver and , say, an I2C driver with the same compatible string.
We already have such. For example: adi,adxl312
Quoted 23 lines
Quoted 10 lines
[...]
Quoted 6 lines
Quoted 2 lines
Why unit address is optional?
It isn't. I copy-pasted it from
led-class-multicolor.yamland didn't check the exact regex.
I'll fix it in the next version.Make it required and matching your case.
Got it.
Quoted 9 lines
[...]
Quoted 6 lines
Quoted 6 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml line 68
Quoted 6 lines
Documentation/devicetree/bindings/leds/worldsemi,ws2812b-spi.yaml new file +6
-0+ default-intensity: + description: | + An array of 3 integer specifying the default intensity of each color + components in this LED. <255 255 255> if unspecified. + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 3[...]
So this is brightness of each color...
Quoted 8 lines
I don't think so.
See the kernel doc for multicolor LED:
https://docs.kernel.org/leds/leds-class-multicolor.html
This property sets the sysfs filemulti_intensitywhile the actual LED brightness is controlled with another sysfs file called 'brightness'.
Settingmulti_intensityalone doesn't change the LED brightness at all.
If you had brightness, that would be correct. But you do not have brightness, right? Therefore the final brightness is always:
subled[i].brightness = 255 * subled[i].intensity / max_brightness (also 255);
Or your bindings are incomplete...
Best regards,
Krzysztof
Re: [PATCH 2/3] dt-bindings: leds: add dt schema for worldsemi,ws2812b-spi
Hi!
Quoted 12 lines · Krzysztof Kozlowski
Quoted 11 lines
Quoted 2 lines
[...]
So this is brightness of each color...I don't think so.
See the kernel doc for multicolor LED:
https://docs.kernel.org/leds/leds-class-multicolor.html
This property sets the sysfs filemulti_intensitywhile the actual LED brightness is controlled with another sysfs file called 'brightness'.
Settingmulti_intensityalone doesn't change the LED brightness at all.
Quoted 2 lines
If you had brightness, that would be correct. But you do not have brightness, right?
The brightness can be set using sysfs, but I didn't implement a default brightness in my driver.
My original intent for this property is to set a default color for legacy led softwares which can only control the brightness and doesn't support setting the color value yet.
Quoted 6 lines
Therefore the final brightness is always:
subled[i].brightness = 255 * subled[i].intensity /
max_brightness(also 255);Or your bindings are incomplete...
I do agree that adding a default-brightness will make this more useful. I'll add this feature in the next version.
Signature · 2 lines
Regards, Chuanhong Guo
PATCH 3/3 leds: add driver for SPI driven WorldSemi WS2812B RGB LEDs
In reply to Chuanhong GuoThis patch adds support for driving a chain of WS2812B LED chips using SPI bus.
WorldSemi WS2812B is a individually addressable LED chip that can be chained together and controlled individually using a single wire. The chip recognize a long pulse as a bit of 1 and a short pulse as a bit of 0. Host sends a continuous stream of 24-bits color values, each LED chip takes the first 3 byte it receives as its color value and passes the leftover bytes to the next LED on the chain.
This driver simulates this protocol using SPI bus by sending a long pulse as 3'b110 and a short pulse as 3'b100. The SPI frequency needs to be 2.105MHz~2.85MHz for the timing to be correct and the controller needs to transfer all the bytes continuously.
--- drivers/leds/rgb/Kconfig | 11 ++ drivers/leds/rgb/Makefile | 1 + drivers/leds/rgb/leds-ws2812b-spi.c | 222 ++++++++++++++++++++++++++++ 3 files changed, 234 insertions(+) create mode 100644 drivers/leds/rgb/leds-ws2812b-spi.c
drivers/leds/rgb/Kconfig +11 -0
@@ -26,4 +26,15 @@ config LEDS_QCOM_LPG If compiled as a module, the module will be named leds-qcom-lpg. +config LEDS_WS2812B_SPI + tristate "SPI driven WS2812B RGB LED support" + depends on OF + depends on SPI + help + This option enables support for driving daisy-chained WS2812B RGB + LED chips using SPI bus. This driver simulates the single-wire + protocol by sending bits over the SPI MOSI pin. For this to work, + the SPI frequency should be 2.105MHz~2.85MHz and the controller + needs to transfer all the bytes continuously. + endif # LEDS_CLASS_MULTICOLOR
drivers/leds/rgb/Makefile +1 -0
@@ -2,3 +2,4 @@ obj-$(CONFIG_LEDS_PWM_MULTICOLOR) += leds-pwm-multicolor.o obj-$(CONFIG_LEDS_QCOM_LPG) += leds-qcom-lpg.o +obj-$(CONFIG_LEDS_WS2812B_SPI) += leds-ws2812b-spi.o
drivers/leds/rgb/leds-ws2812b-spi.c new file +222 -0
222 lines not on this page · raw message
Signature · 1 line
2.38.1