Skip to contentSkip to conversation

leds: add support for apa102c leds

RFC PATCH Superseded Nicolas Belin 3 participants 9 messages Feb 26, 2020 – Mar 3, 2020

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover leds: add support for apa102c leds

This patch series adds the driver and its related documentation for the APA102C RGB Leds. It is based on the Multicolor Framework and must be applied on top of the Multicolor framework patches located at
https://lore.kernel.org/patchwork/project/lkml/list/?series=427513 .

Patch 1 adds the APA102C led manufacturer to the vendor-prefixes list.

Patch 2 Documents the APA102C led driver.

Patch 3 contains the actual driver code and modifications in the Kconfig and the Makefile.

Updates since v1:
- Moved the apa102c line in the Makefile to the LED SPI Drivers part
- The driver is now based on the Multicolor Framework.

Nicolas Belin (3):
dt-bindings: Document shiji vendor-prefix
dt-bindings: leds: Shiji Lighting APA102C LED driver
drivers: leds: add support for apa102c leds

 .../devicetree/bindings/leds/leds-apa102c.yaml     | 154 +++++++++++
 .../devicetree/bindings/vendor-prefixes.yaml       |   2 +
 drivers/leds/Kconfig                               |   7 +
 drivers/leds/Makefile                              |   1 +
 drivers/leds/leds-apa102c.c                        | 291 +++++++++++++++++++++
 5 files changed, 455 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/leds/leds-apa102c.yaml
 create mode 100644 drivers/leds/leds-apa102c.c
Signature · 1 line
2.7.4
#1 lore raw

RFC PATCH v2 1/3 dt-bindings: Document shiji vendor-prefix

Shenzhen Shiji Lighting Co.,Ltd is a LED manufacturer.

---
 Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++
 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/vendor-prefixes.yaml +2 -0
index 9e67944bec9c..a463286c3960 100644
@@ -863,6 +863,8 @@ patternProperties:
     description: SGX Sensortech
   "^sharp,.*":
     description: Sharp Corporation
+  "^shiji,.*":
+    description: Shenzhen Shiji Lighting Co.,Ltd
   "^shimafuji,.*":
     description: Shimafuji Electric, Inc.
   "^si-en,.*":
Signature · 1 line
2.7.4
#3 lore raw

RFC PATCH v2 2/3 dt-bindings: leds: Shiji Lighting APA102C LED driver

In reply to Nicolas Belin

Document Shiji Lighting APA102C LED driver device tree bindings.

---
 .../devicetree/bindings/leds/leds-apa102c.yaml     | 154 +++++++++++++++++++++
 1 file changed, 154 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/leds/leds-apa102c.yaml
Documentation/devicetree/bindings/leds/leds-apa102c.yaml new file +154 -0
new file mode 100644
index 000000000000..90c827ab5a5a
@@ -0,0 +1,154 @@
+# SPDX-License-Identifier: GPL-2.0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/leds/leds-apa102c.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: LED driver for Shiji Lighting - APA102C
+
+maintainers:
+  - Nicolas Belin <[email protected]>
+
+description:
+  Each RGB LED is represented as a multi-led sub-node of the leds-apa102c
+  device.  Each LED
+  is a three color rgb LED with 32 levels brightness adjustment that can be
+  cascaded so that multiple LEDs can be set with a single command.
+
+properties:
+  compatible:
+    const: shiji,apa102c
+
+  reg:
+    maxItems: 1
+
+  spi-max-frequency:
+    maximum: 1000000
+
+  "#address-cells":
+    const: 1
+
+  "#size-cells":
+    const: 0
+
+patternProperties:
+  "^multi-led@[0-9]+$":
+    type: object
+    description: |
+      Properties for an array of connected LEDs.
+
+    properties:
+      reg:
+        description: |
+          This property corresponds to the led index. It has to be between 0
+          and the number of managed leds minus 1
+        maxItems: 1
+
+      label:
+        description: |
+          This property corresponds to the name of the led. If not set,
+          the led index will be used to create the led name instead
+        maxItems: 1
+
+      color:
+        const: 8
+
+      linux,default-trigger: true
+
+      "#address-cells":
+        const: 1
+
+      "#size-cells":
+        const: 0
+
+    patternProperties:
+      "^led@[0-9]+$":
+        type: object
+        description: |
+          Properties for the LED color components.
+
+        properties:
+          reg:
+            maxItems: 1
+
+          color:
+            oneOf:
+              - enum: [ 1, 2, 3 ]
+
+        required:
+          - reg
+          - color
+
+    required:
+      - reg
+      - color
+      - '#address-cells'
+      - '#size-cells'
+
+required:
+  - compatible
+  - reg
+  - spi-max-frequency
+  - '#address-cells'
+  - '#size-cells'
+
+examples:
+  - |
+
+    #include <dt-bindings/leds/common.h>
+
+    spi {
+        #address-cells = <1>;
+        #size-cells = <0>;
+        led-controller@0 {
+            compatible = "shiji,apa102c";
+            reg = <0>;
+            spi-max-frequency = <1000000>;
+            #address-cells = <1>;
+            #size-cells = <0>;
+            multi-led@0 {
+                #address-cells = <1>;
+                #size-cells = <0>;
+                reg = <0>;
+                color = <LED_COLOR_ID_MULTI>;
+                label = "rgb_led1";
+
+                led@0 {
+                reg = <0>;
+                color = <LED_COLOR_ID_RED>;
+                };
+
+                led@1 {
+                reg = <1>;
+                color = <LED_COLOR_ID_GREEN>;
+                };
+
+                led@2 {
+                reg = <2>;
+                color = <LED_COLOR_ID_BLUE>;
+                };
+            };
+            multi-led@1 {
+                #address-cells = <1>;
+                #size-cells = <0>;
+                reg = <1>;
+                color = <LED_COLOR_ID_MULTI>;
+                label = "rgb_led2";
+
+                led@3 {
+                reg = <3>;
+                color = <LED_COLOR_ID_RED>;
+                };
+
+                led@4 {
+                reg = <4>;
+                color = <LED_COLOR_ID_GREEN>;
+                };
+
+                led@5 {
+                reg = <5>;
+                color = <LED_COLOR_ID_BLUE>;
+                };
+            };
+        };
+    };
Signature · 1 line
2.7.4
maintainer
#4 lore raw

Re: [PATCH RFC v2 2/3] dt-bindings: leds: Shiji Lighting APA102C LED driver

Quoted 8 lines · Nicolas Belin

Document Shiji Lighting APA102C LED driver device tree bindings.

---
 .../devicetree/bindings/leds/leds-apa102c.yaml     | 154 +++++++++++++++++++++
 1 file changed, 154 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/leds/leds-apa102c.yaml

My bot found errors running 'make dt_binding_check' on your patch:

Documentation/devicetree/bindings/display/simple-framebuffer.example.dts:21.16-37.11: Warning (chosen_node_is_root): /example-0/chosen: chosen node must be at root node
Error: Documentation/devicetree/bindings/leds/leds-apa102c.example.dts:33.30-31 syntax error
FATAL ERROR: Unable to parse input tree
scripts/Makefile.lib:300: recipe for target 'Documentation/devicetree/bindings/leds/leds-apa102c.example.dt.yaml' failed
make[1]: *** [Documentation/devicetree/bindings/leds/leds-apa102c.example.dt.yaml] Error 1
Makefile:1263: recipe for target 'dt_binding_check' failed
make: *** [dt_binding_check] Error 2

See https://patchwork.ozlabs.org/patch/1245095
Please check and re-submit.

#5 lore raw

RFC PATCH v2 3/3 drivers: leds: add support for apa102c leds

In reply to Nicolas Belin

Initilial commit in order to support the apa102c RGB leds. This is based on the Multicolor Framework.

---
 drivers/leds/Kconfig        |   7 ++
 drivers/leds/Makefile       |   1 +
 drivers/leds/leds-apa102c.c | 291 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 299 insertions(+)
 create mode 100644 drivers/leds/leds-apa102c.c
drivers/leds/Kconfig +7 -0
index 5dc6535a88ef..71e29727c6ec 100644
@@ -79,6 +79,13 @@ config LEDS_AN30259A
 	  To compile this driver as a module, choose M here: the module
 	  will be called leds-an30259a.
 
+config LEDS_APA102C
+	tristate "LED Support for Shiji APA102C"
+	depends on SPI
+	depends on LEDS_CLASS_MULTI_COLOR
+	help
+	  This option enables support for APA102C LEDs.
+
 config LEDS_APU
 	tristate "Front panel LED support for PC Engines APU/APU2/APU3 boards"
 	depends on LEDS_CLASS
drivers/leds/Makefile +1 -0
index b5305b7d43fb..8334cb6dc7e8 100644
@@ -90,6 +90,7 @@ obj-$(CONFIG_LEDS_LM36274)		+= leds-lm36274.o
 obj-$(CONFIG_LEDS_TPS6105X)		+= leds-tps6105x.o
 
 # LED SPI Drivers
+obj-$(CONFIG_LEDS_APA102C)		+= leds-apa102c.o
 obj-$(CONFIG_LEDS_CR0014114)		+= leds-cr0014114.o
 obj-$(CONFIG_LEDS_DAC124S085)		+= leds-dac124s085.o
 obj-$(CONFIG_LEDS_EL15203000)		+= leds-el15203000.o
drivers/leds/leds-apa102c.c new file +291 -0

291 lines not on this page · raw message

Signature · 1 line
2.7.4
#6 lore raw

Re: [PATCH RFC v2 3/3] drivers: leds: add support for apa102c leds

Hi Nicolas,

Regardless of the fact that LED mc framework in current shape will probably not materialize in mainline, I have single remark regarding LED initialization. Please take a look below.

Quoted 32 lines · Nicolas Belin

Initilial commit in order to support the apa102c RGB leds. This is based on the Multicolor Framework.

---
 drivers/leds/Kconfig        |   7 ++
 drivers/leds/Makefile       |   1 +
 drivers/leds/leds-apa102c.c | 291 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 299 insertions(+)
 create mode 100644 drivers/leds/leds-apa102c.c
drivers/leds/Kconfig +7 -0
index 5dc6535a88ef..71e29727c6ec 100644
@@ -79,6 +79,13 @@ config LEDS_AN30259A
 	  To compile this driver as a module, choose M here: the module
 	  will be called leds-an30259a.
 
+config LEDS_APA102C
+	tristate "LED Support for Shiji APA102C"
+	depends on SPI
+	depends on LEDS_CLASS_MULTI_COLOR
+	help
+	  This option enables support for APA102C LEDs.
+
 config LEDS_APU
 	tristate "Front panel LED support for PC Engines APU/APU2/APU3 boards"
 	depends on LEDS_CLASS
drivers/leds/Makefile +0 -0
index b5305b7d43fb..8334cb6dc7e8 100644

[...]

drivers/leds/Makefile

Quoted 9 lines
drivers/leds/Makefile +9 -0
+
+		led->priv			= priv;
+		led->ldev.max_brightness	= MAX_BRIGHTNESS;
+		fwnode_property_read_string(child, "linux,default-trigger",
+					    &led->ldev.default_trigger);
+
+		init_data.fwnode = child;
+		init_data.devicename = APA_DEV_NAME;
+		init_data.default_label = ":";

devicename property should be filled in new drivers only in case devname_mandatory is set to true.
default_label property is for legacy drivers, for backward compatibility with old LED naming convention.

For more information please refer to:
- Documentation/leds/leds-class.rst, "LED Device Naming" section
- struct led_init_data documention in linux/leds.h

In effect you need only fwnode here,

Quoted 30 lines
drivers/leds/Makefile +30 -0
+
+		num_colors = 0;
+		fwnode_for_each_child_node(child, grandchild) {
+			ret = fwnode_property_read_u32(grandchild, "color",
+						       &color_id);
+			if (ret) {
+				dev_err(priv->dev, "Cannot read color\n");
+				goto child_out;
+			}
+
+			set_bit(color_id, &led->mc_cdev.available_colors);
+			num_colors++;
+		}
+
+		if (num_colors != 3) {
+			ret = -EINVAL;
+			dev_err(priv->dev, "There should be 3 colors\n");
+			goto child_out;
+		}
+
+		if (led->mc_cdev.available_colors != IS_RGB) {
+			ret = -EINVAL;
+			dev_err(priv->dev, "The led is expected to be RGB\n");
+			goto child_out;
+		}
+
+		led->mc_cdev.num_leds = num_colors;
+		led->mc_cdev.led_cdev = &led->ldev;
+		led->ldev.brightness_set_blocking = apa102c_brightness_set;
+		ret = devm_led_classdev_multicolor_register_ext(priv->dev,
Signature · 2 lines
Best regards,
Jacek Anaszewski
#7 lore raw

Re: [PATCH RFC v2 3/3] drivers: leds: add support for apa102c leds

Hi Jacek,

That's a shame that it is not going to be upstreamed soon as it making my led driver much nicer :)
So what's the plan with the multicolor framework?
I am happy to send a new version to fix your remark and then adapt my driver to the future changes in the Framework.

Let me know what you think.

Thanks,

Regards,

Nicolas

Quoted 96 lines · Jacek Anaszewski

Hi Nicolas,

Regardless of the fact that LED mc framework in current shape will probably not materialize in mainline, I have single remark regarding LED initialization. Please take a look below.

Quoted 32 lines · Nicolas Belin

Initilial commit in order to support the apa102c RGB leds. This is based on the Multicolor Framework.

---
 drivers/leds/Kconfig        |   7 ++
 drivers/leds/Makefile       |   1 +
 drivers/leds/leds-apa102c.c | 291 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 299 insertions(+)
 create mode 100644 drivers/leds/leds-apa102c.c
drivers/leds/Kconfig +7 -0
index 5dc6535a88ef..71e29727c6ec 100644
@@ -79,6 +79,13 @@ config LEDS_AN30259A
        To compile this driver as a module, choose M here: the module
        will be called leds-an30259a.
 
+config LEDS_APA102C
+     tristate "LED Support for Shiji APA102C"
+     depends on SPI
+     depends on LEDS_CLASS_MULTI_COLOR
+     help
+       This option enables support for APA102C LEDs.
+
 config LEDS_APU
      tristate "Front panel LED support for PC Engines APU/APU2/APU3 boards"
      depends on LEDS_CLASS
drivers/leds/Makefile +0 -0
index b5305b7d43fb..8334cb6dc7e8 100644

[...]

drivers/leds/Makefile

Quoted 9 lines
drivers/leds/Makefile +9 -0
+
+             led->priv                       = priv;
+             led->ldev.max_brightness        = MAX_BRIGHTNESS;
+             fwnode_property_read_string(child, "linux,default-trigger",
+                                         &led->ldev.default_trigger);
+
+             init_data.fwnode = child;
+             init_data.devicename = APA_DEV_NAME;
+             init_data.default_label = ":";

devicename property should be filled in new drivers only in case devname_mandatory is set to true.
default_label property is for legacy drivers, for backward compatibility with old LED naming convention.

For more information please refer to:
- Documentation/leds/leds-class.rst, "LED Device Naming" section
- struct led_init_data documention in linux/leds.h

In effect you need only fwnode here,

Quoted 20 lines
drivers/leds/Makefile +20 -0
+
+             num_colors = 0;
+             fwnode_for_each_child_node(child, grandchild) {
+                     ret = fwnode_property_read_u32(grandchild, "color",
+                                                    &color_id);
+                     if (ret) {
+                             dev_err(priv->dev, "Cannot read color\n");
+                             goto child_out;
+                     }
+
+                     set_bit(color_id, &led->mc_cdev.available_colors);
+                     num_colors++;
+             }
+
+             if (num_colors != 3) {
+                     ret = -EINVAL;
+                     dev_err(priv->dev, "There should be 3 colors\n");
+                     goto child_out;
+             }
+

drivers/leds/Makefile

Quoted 10 lines
drivers/leds/Makefile +10 -0
+             if (led->mc_cdev.available_colors != IS_RGB) {
+                     ret = -EINVAL;
+                     dev_err(priv->dev, "The led is expected to be RGB\n");
+                     goto child_out;
+             }
+
+             led->mc_cdev.num_leds = num_colors;
+             led->mc_cdev.led_cdev = &led->ldev;
+             led->ldev.brightness_set_blocking = apa102c_brightness_set;
+             ret = devm_led_classdev_multicolor_register_ext(priv->dev,

--
Best regards,
Jacek Anaszewski

Signature · 4 lines
Nicolas Belin
Software design engineer
BayLibre
www.baylibre.com
#8 lore raw

Re: [PATCH RFC v2 3/3] drivers: leds: add support for apa102c leds

Hi Nicolas,

Quoted 4 lines · Nicolas Belin

Hi Jacek,

That's a shame that it is not going to be upstreamed soon as it making my led driver much nicer :)

Now when we clarified interface related issues I hope it will be rather weeks than months when it is ready.

Quoted 3 lines

So what's the plan with the multicolor framework?
I am happy to send a new version to fix your remark and then adapt my driver to the future changes in the Framework.

Just rework the driver to create one LED class device per LED color. After LED mc framework is upstream you will be free to add the support for it to your driver.

Best regards,
Jacek Anaszewski

Quoted 109 lines

Let me know what you think.

Thanks,

Regards,

Nicolas

Quoted 96 lines · Jacek Anaszewski

Hi Nicolas,

Regardless of the fact that LED mc framework in current shape will probably not materialize in mainline, I have single remark regarding LED initialization. Please take a look below.

Quoted 32 lines · Nicolas Belin

Initilial commit in order to support the apa102c RGB leds. This is based on the Multicolor Framework.

---
 drivers/leds/Kconfig        |   7 ++
 drivers/leds/Makefile       |   1 +
 drivers/leds/leds-apa102c.c | 291 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 299 insertions(+)
 create mode 100644 drivers/leds/leds-apa102c.c
drivers/leds/Kconfig +7 -0
index 5dc6535a88ef..71e29727c6ec 100644
@@ -79,6 +79,13 @@ config LEDS_AN30259A
        To compile this driver as a module, choose M here: the module
        will be called leds-an30259a.
 
+config LEDS_APA102C
+     tristate "LED Support for Shiji APA102C"
+     depends on SPI
+     depends on LEDS_CLASS_MULTI_COLOR
+     help
+       This option enables support for APA102C LEDs.
+
 config LEDS_APU
      tristate "Front panel LED support for PC Engines APU/APU2/APU3 boards"
      depends on LEDS_CLASS
drivers/leds/Makefile +0 -0
index b5305b7d43fb..8334cb6dc7e8 100644

[...]

drivers/leds/Makefile

Quoted 9 lines
drivers/leds/Makefile +9 -0
+
+             led->priv                       = priv;
+             led->ldev.max_brightness        = MAX_BRIGHTNESS;
+             fwnode_property_read_string(child, "linux,default-trigger",
+                                         &led->ldev.default_trigger);
+
+             init_data.fwnode = child;
+             init_data.devicename = APA_DEV_NAME;
+             init_data.default_label = ":";

devicename property should be filled in new drivers only in case devname_mandatory is set to true.
default_label property is for legacy drivers, for backward compatibility with old LED naming convention.

For more information please refer to:
- Documentation/leds/leds-class.rst, "LED Device Naming" section
- struct led_init_data documention in linux/leds.h

In effect you need only fwnode here,

Quoted 20 lines
drivers/leds/Makefile +20 -0
+
+             num_colors = 0;
+             fwnode_for_each_child_node(child, grandchild) {
+                     ret = fwnode_property_read_u32(grandchild, "color",
+                                                    &color_id);
+                     if (ret) {
+                             dev_err(priv->dev, "Cannot read color\n");
+                             goto child_out;
+                     }
+
+                     set_bit(color_id, &led->mc_cdev.available_colors);
+                     num_colors++;
+             }
+
+             if (num_colors != 3) {
+                     ret = -EINVAL;
+                     dev_err(priv->dev, "There should be 3 colors\n");
+                     goto child_out;
+             }
+

drivers/leds/Makefile

Quoted 10 lines
drivers/leds/Makefile +10 -0
+             if (led->mc_cdev.available_colors != IS_RGB) {
+                     ret = -EINVAL;
+                     dev_err(priv->dev, "The led is expected to be RGB\n");
+                     goto child_out;
+             }
+
+             led->mc_cdev.num_leds = num_colors;
+             led->mc_cdev.led_cdev = &led->ldev;
+             led->ldev.brightness_set_blocking = apa102c_brightness_set;
+             ret = devm_led_classdev_multicolor_register_ext(priv->dev,

--
Best regards,
Jacek Anaszewski