Skip to contentSkip to conversation

leds: Add KTD20xx RGB LEDs driver from Kinetic

PATCH In review Florian Eckert 3 participants 6 messages Nov 23, 2021 – Dec 20, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover leds: Add KTD20xx RGB LEDs driver from Kinetic

Introduce the KTD2061/58/59/60 RGB LEDs driver. The difference in these parts are the address number on the I2C bus the device is listen on.

All KT20xx device could control up to 12 LEDs. The chip can be operated in two variants.

v2: fix kbuild ci warnings

Florian Eckert (2):
leds: ktd20xx: Add the KTD20xx family of the RGB LEDs driver from
Kinetic
dt: bindings: KTD20xx: Introduce the ktd20xx family of RGB drivers

 .../bindings/leds/leds-ktd20xx.yaml           | 123 +++
 MAINTAINERS                                   |   7 +
 drivers/leds/Kconfig                          |  13 +
 drivers/leds/Makefile                         |   1 +
 drivers/leds/leds-ktd20xx.c                   | 792 ++++++++++++++++++
 5 files changed, 936 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/leds/leds-ktd20xx.yaml
 create mode 100644 drivers/leds/leds-ktd20xx.c
Signature · 1 line
2.20.1
#1 lore raw

PATCH v2 1/2 leds: ktd20xx: Add the KTD20xx family of the RGB LEDs driver from Kinetic

Introduce the KTD2061/58/59/60 RGB LEDs driver. The difference in these parts are the address number on the I2C bus the device is listen on.

All KT20xx device could control up to 12 LEDs. The chip can be operated in two variants.

Variant 1:
The device has the ability to group LED outputs into two banks so that the two LED banks can be controlled with the same color. This could not be done via the LEDs 'sysfs' entry because of the limitation on the color register count. The color of the two banks can be configured via device 'sysfs' entry for all LEDs at once [current_color0|current_color1]. Which color the LED is to be used can be set via the 'sysfs' of the individual LEDs via the 'multi_intensity' file. Valid values for the colors (RGB) are 0 | 1. The value 0 selects the color register 0 and the value 1 selects the color register 1.

Variant 2:
The device can also set the LED color independently. Since the chip only has two color registers, but we want to control the 12 LEDs independently via the 'led-class-multicolour' sysfs entry,
the full RGB color depth cannot be used. Due to this limitation, only 7 colors and the color black (off) can be set. To use this mode the color registers must be preset via the device tree or the device 'sysfs'. The color registers 0 must be preset with 0x00 (Red=0x00 Green=0x00 Blue=0x00). The color register1 should be preset all with the same value. This value depends on which light intensity is to be used in the setup.

---
 MAINTAINERS                 |   6 +
 drivers/leds/Kconfig        |  13 +
 drivers/leds/Makefile       |   1 +
 drivers/leds/leds-ktd20xx.c | 792 ++++++++++++++++++++++++++++++++++++
 4 files changed, 812 insertions(+)
 create mode 100644 drivers/leds/leds-ktd20xx.c
MAINTAINERS +6 -0
index 9096c64d8d09..736d564f7e93 100644
@@ -10603,6 +10603,12 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/leds/backlight/kinetic,ktd253.yaml
 F:	drivers/video/backlight/ktd253-backlight.c
 
+KTD20XX LED CONTROLLER DRIVER
+M:	Florian Eckert <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/leds/leds-ktd20xx.c
+
 KTEST
 M:	Steven Rostedt <[email protected]>
 M:	John Hawley <[email protected]>
drivers/leds/Kconfig +13 -0
index ed800f5da7d8..b313b5c6a445 100644
@@ -157,6 +157,19 @@ config LEDS_EL15203000
 	  To compile this driver as a module, choose M here: the module
 	  will be called leds-el15203000.
 
+config LEDS_KTD20XX
+	tristate "LED Support for KTD2061/58/59/60 LED driver chip"
+	depends on LEDS_CLASS && I2C
+	depends on LEDS_CLASS_MULTICOLOR || !LEDS_CLASS_MULTICOLOR
+	depends on OF
+	select REGMAP_I2C
+	help
+	  If you say yes here you get support for the Kinetic
+	  KTD2061, KTD2058, KTD2059 and KTD2060 LED driver.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called leds-ktd20xx.
+
 config LEDS_TURRIS_OMNIA
 	tristate "LED support for CZ.NIC's Turris Omnia"
 	depends on LEDS_CLASS_MULTICOLOR
drivers/leds/Makefile +1 -0
index c636ec069612..7004ec953c87 100644
@@ -35,6 +35,7 @@ obj-$(CONFIG_LEDS_IP30)			+= leds-ip30.o
 obj-$(CONFIG_LEDS_IPAQ_MICRO)		+= leds-ipaq-micro.o
 obj-$(CONFIG_LEDS_IS31FL319X)		+= leds-is31fl319x.o
 obj-$(CONFIG_LEDS_IS31FL32XX)		+= leds-is31fl32xx.o
+obj-${CONFIG_LEDS_KTD20XX}		+= leds-ktd20xx.o
 obj-$(CONFIG_LEDS_LM3530)		+= leds-lm3530.o
 obj-$(CONFIG_LEDS_LM3532)		+= leds-lm3532.o
 obj-$(CONFIG_LEDS_LM3533)		+= leds-lm3533.o
drivers/leds/leds-ktd20xx.c new file +792 -0

792 lines not on this page · raw message

Signature · 1 line
2.20.1
#2 lore raw

Re: [PATCH v2 1/2] leds: ktd20xx: Add the KTD20xx family of the RGB LEDs driver from Kinetic

Hi!

Quoted 17 lines

Introduce the KTD2061/58/59/60 RGB LEDs driver. The difference in these parts are the address number on the I2C bus the device is listen on.

All KT20xx device could control up to 12 LEDs. The chip can be operated in two variants.

Variant 1:
The device has the ability to group LED outputs into two banks so that the two LED banks can be controlled with the same color. This could not be done via the LEDs 'sysfs' entry because of the limitation on the color register count. The color of the two banks can be configured via device 'sysfs' entry for all LEDs at once [current_color0|current_color1]. Which color the LED is to be used can be set via the 'sysfs' of the individual LEDs via the 'multi_intensity' file. Valid values for the colors (RGB) are 0 | 1. The value 0 selects the color register 0 and the value 1 selects the color register 1.

Quoted 10 lines

Variant 2:
The device can also set the LED color independently. Since the chip only has two color registers, but we want to control the 12 LEDs independently via the 'led-class-multicolour' sysfs entry,
the full RGB color depth cannot be used. Due to this limitation, only 7 colors and the color black (off) can be set. To use this mode the color registers must be preset via the device tree or the device 'sysfs'. The color registers 0 must be preset with 0x00 (Red=0x00 Green=0x00 Blue=0x00). The color register1 should be preset all with the same value. This value depends on which light intensity is to be used in the setup.

Summary: some crazy hardware.

drivers/leds/leds-ktd20xx.c line 476

Quoted 4 lines
drivers/leds/leds-ktd20xx.c new file +4 -0
+static ssize_t current_color0_store(struct device *dev,
+		struct device_attribute *a,
+		const char *buf, size_t size)
+{

And now we have custom interface. Undocumented.

That is not acceptable, sorry.

Find a way to squeeze it into current RGB framework, perhaps with reduced feature set.

AFAICT you could either pretend it is 2-LED driver with full 8bit RGB on each, or you could pretend it is 12-LED driver with 1bit RGB. Select one and implement that.

Best regards,
Pavel

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

Re: [PATCH v2 1/2] leds: ktd20xx: Add the KTD20xx family of the RGB LEDs driver from Kinetic

Hello Pavel,

thanks for your reply.

Quoted 22 lines
Quoted 11 lines

Variant 1:
The device has the ability to group LED outputs into two banks so that the two LED banks can be controlled with the same color. This could not be done via the LEDs 'sysfs' entry because of the limitation on the color register count. The color of the two banks can be configured via device 'sysfs' entry for all LEDs at once [current_color0|current_color1]. Which color the LED is to be used can be set via the 'sysfs' of the individual LEDs via the 'multi_intensity' file. Valid values for the colors (RGB) are 0 | 1. The value 0 selects the color register 0 and the value 1 selects the color register 1.

Quoted 10 lines

Variant 2:
The device can also set the LED color independently. Since the chip only has two color registers, but we want to control the 12 LEDs independently via the 'led-class-multicolour' sysfs entry,
the full RGB color depth cannot be used. Due to this limitation, only 7 colors and the color black (off) can be set. To use this mode the color registers must be preset via the device tree or the device 'sysfs'. The color registers 0 must be preset with 0x00 (Red=0x00 Green=0x00 Blue=0x00). The color register1 should be preset all with the same value. This value depends on which light intensity is to be used in the setup.

Quoted 1 line

Summary: some crazy hardware.

I agree with you completely.
But there was no other hardware to choose it was already on the board.

Quoted 7 lines

drivers/leds/leds-ktd20xx.c line 476

Quoted 5 lines
drivers/leds/leds-ktd20xx.c new file +4 -0
+static ssize_t current_color0_store(struct device *dev,
+		struct device_attribute *a,
+		const char *buf, size_t size)
+{

And now we have custom interface. Undocumented.

I just wanted to implement all possibilities features for the chip and not commit to one. It may be that someone else can use the hardware for something else. If that is the problem, then I can document that.

Quoted 3 lines

That is not acceptable, sorry.
Find a way to squeeze it into current RGB framework, perhaps with reduced feature set.

Ok I'll try and focus on variant 2.

Quoted 3 lines

AFAICT you could either pretend it is 2-LED driver with full 8bit RGB on each, or you could pretend it is 12-LED driver with 1bit RGB. Select one and implement that.

On my board the LED driver is used for 12 LEDs and 1bit RGB colour depth. So I could select 7 colors and (off).
For my understanding, does this mean that I remove variant 1 from the source and send a v3 patchset? Or do I have to take anything else into account when I use variant 2 now?

From my point of view, the driver should fit if I remove variant 1?

Best regards

Florian

#4 lore raw

PATCH v2 2/2 dt: bindings: KTD20xx: Introduce the ktd20xx family of RGB drivers

In reply to Florian Eckert

Introduce the bindings for the Kinetic KTD2061/58/59/60RGB LED device driver. The KTD20xx can control RGB LEDs individually or as part of a control bank group.

---
 .../bindings/leds/leds-ktd20xx.yaml           | 123 ++++++++++++++++++
 MAINTAINERS                                   |   1 +
 2 files changed, 124 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/leds/leds-ktd20xx.yaml
Documentation/devicetree/bindings/leds/leds-ktd20xx.yaml new file +123 -0
new file mode 100644
index 000000000000..b10b5fd507db
@@ -0,0 +1,123 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/leds/leds-ktd20xx.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: LED driver for KTD20xx RGB LED from Kinetic.
+
+maintainers:
+  - Florian Eckert <[email protected]>
+
+description: |
+  The KTD20XX is multi-channel, I2C RGB LED Drivers that can group RGB LEDs into
+  a LED group or control them individually.
+
+  The difference in these RGB LED drivers is I2C address number the device is
+  listen on.
+
+properties:
+  compatible:
+    enum:
+      - kinetic,ktd20xx
+
+  reg:
+    maxItems: 1
+    description:
+      I2C slave address
+      ktd2061/58/59/60 0x68 0x69 0x6A 0x6B
+
+  '#address-cells':
+    const: 1
+
+  '#size-cells':
+    const: 0
+
+  'kinetic,color-current0':
+    description:
+      Specifies the current selection for the RGB color0.
+      Value 1 must be the current value for the color red.
+      Value 2 must be the current value for the color green.
+      Value 3 must be the current value for the color blue.
+      The current setting range is from 0mA to 24mA with 125uA steps.
+    $ref: /schemas/types.yaml#/definitions/uint8-array
+    items:
+      - minItems: 3
+      - maxItems: 3
+
+  'kinetic,color-current1':
+    description:
+      Specifies the current selection for the RGB color0.
+      Value 1 must be the current value for the color red.
+      Value 2 must be the current value for the color green.
+      Value 3 must be the current value for the color blue.
+      The current setting range is from 0mA to 24mA with 125uA steps.
+    $ref: /schemas/types.yaml#/definitions/uint8-array
+    items:
+      - minItems: 3
+      - maxItems: 3
+
+patternProperties:
+  '^multi-led@[0-9a-f]$':
+    type: object
+    allOf:
+      - $ref: leds-class-multicolor.yaml#
+    properties:
+      reg:
+        minItems: 1
+        maxItems: 12
+        description:
+          This property denotes the LED module number(s) that is used on the
+          for the child node.
+      'kinetic,color-selection':
+        description:
+          Specifies the color selection for this LED.
+          Value 1 selects the color register for color red.
+          Value 2 selects the color register for color green.
+          Value 3 selects the color register for color blue.
+          The value can be either 0 or 1. If 0, the current for the color
+          from color register 0 is used. If 1, the current for the color
+          from color register 1 is used.
+     $ref: /schemas/types.yaml#/definitions/uint8-array
+     items:
+       - minItems: 3
+       - maxItems: 3
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+   #include <dt-bindings/leds/common.h>
+
+   i2c {
+       #address-cells = <1>;
+       #size-cells = <0>;
+
+       led-controller@14 {
+           compatible = "ti,lp5009";
+           reg = <0x14>;
+           #address-cells = <1>;
+           #size-cells = <0>;
+           color-current0 = [ 00 00 00 ] // Current for RGB is 0mA
+           color-current1 = [ 28 28 28 ] // Current for RGB is 5mA
+
+           multi-led@0 {
+               reg = <0x0>;
+               color = <LED_COLOR_ID_RGB>;
+               function = LED_FUNCTION_CHARGING;
+                kinetic,color-selection = [ 00 01 00 ]; // Red=0mA Green=5mA Blue=0mA
+          };
+
+          multi-led@2 {
+            reg = <0x2>;
+            color = <LED_COLOR_ID_RGB>;
+            function = LED_FUNCTION_STANDBY;
+         };
+       };
+    };
+
+...
MAINTAINERS +1 -0
index 736d564f7e93..125bae48c2d1 100644
@@ -10607,6 +10607,7 @@ KTD20XX LED CONTROLLER DRIVER
 M:	Florian Eckert <[email protected]>
 L:	[email protected]
 S:	Maintained
+F:	Documentation/devicetree/bindings/leds/leds-ktd20xx.yaml
 F:	drivers/leds/leds-ktd20xx.c
 
 KTEST
Signature · 1 line
2.20.1
maintainer
#5 lore raw

Re: [PATCH v2 2/2] dt: bindings: KTD20xx: Introduce the ktd20xx family of RGB drivers

Quoted 53 lines · Florian Eckert

Introduce the bindings for the Kinetic KTD2061/58/59/60RGB LED device driver. The KTD20xx can control RGB LEDs individually or as part of a control bank group.

---
 .../bindings/leds/leds-ktd20xx.yaml           | 123 ++++++++++++++++++
 MAINTAINERS                                   |   1 +
 2 files changed, 124 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/leds/leds-ktd20xx.yaml
Documentation/devicetree/bindings/leds/leds-ktd20xx.yaml new file +36 -0
new file mode 100644
index 000000000000..b10b5fd507db
@@ -0,0 +1,123 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/leds/leds-ktd20xx.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: LED driver for KTD20xx RGB LED from Kinetic.
+
+maintainers:
+  - Florian Eckert <[email protected]>
+
+description: |
+  The KTD20XX is multi-channel, I2C RGB LED Drivers that can group RGB LEDs into
+  a LED group or control them individually.
+
+  The difference in these RGB LED drivers is I2C address number the device is
+  listen on.
+
+properties:
+  compatible:
+    enum:
+      - kinetic,ktd20xx
+
+  reg:
+    maxItems: 1
+    description:
+      I2C slave address
+      ktd2061/58/59/60 0x68 0x69 0x6A 0x6B
+
+  '#address-cells':
+    const: 1
+
+  '#size-cells':
+    const: 0
+
+  'kinetic,color-current0':

Documentation/devicetree/bindings/leds/leds-ktd20xx.yaml line 46

Quoted 10 lines
Documentation/devicetree/bindings/leds/leds-ktd20xx.yaml new file +10 -0
+    description:
+      Specifies the current selection for the RGB color0.
+      Value 1 must be the current value for the color red.
+      Value 2 must be the current value for the color green.
+      Value 3 must be the current value for the color blue.
+      The current setting range is from 0mA to 24mA with 125uA steps.
+    $ref: /schemas/types.yaml#/definitions/uint8-array
+    items:
+      - minItems: 3
+      - maxItems: 3

You've defined a 2x3 matrix. I think you want something like:

items:
- description: current value for the color red
- description: current value for the color green
- description: current value for the color blue

Documentation/devicetree/bindings/leds/leds-ktd20xx.yaml line 50

Quoted 4 lines
Documentation/devicetree/bindings/leds/leds-ktd20xx.yaml new file +4 -0
+
+  'kinetic,color-current1':
+    description:
+      Specifies the current selection for the RGB color0.

color1?

Documentation/devicetree/bindings/leds/leds-ktd20xx.yaml line 63

Quoted 13 lines
Documentation/devicetree/bindings/leds/leds-ktd20xx.yaml new file +13 -0
+      Value 1 must be the current value for the color red.
+      Value 2 must be the current value for the color green.
+      Value 3 must be the current value for the color blue.
+      The current setting range is from 0mA to 24mA with 125uA steps.
+    $ref: /schemas/types.yaml#/definitions/uint8-array
+    items:
+      - minItems: 3
+      - maxItems: 3
+
+patternProperties:
+  '^multi-led@[0-9a-f]$':
+    type: object
+    allOf:

Don't need 'allOf'.

Documentation/devicetree/bindings/leds/leds-ktd20xx.yaml line 71

Quoted 8 lines
Documentation/devicetree/bindings/leds/leds-ktd20xx.yaml new file +8 -0
+      - $ref: leds-class-multicolor.yaml#
+    properties:
+      reg:
+        minItems: 1
+        maxItems: 12
+        description:
+          This property denotes the LED module number(s) that is used on the
+          for the child node.

blank line.

Documentation/devicetree/bindings/leds/leds-ktd20xx.yaml line 82

Quoted 11 lines
Documentation/devicetree/bindings/leds/leds-ktd20xx.yaml new file +11 -0
+      'kinetic,color-selection':
+        description:
+          Specifies the color selection for this LED.
+          Value 1 selects the color register for color red.
+          Value 2 selects the color register for color green.
+          Value 3 selects the color register for color blue.
+          The value can be either 0 or 1. If 0, the current for the color
+          from color register 0 is used. If 1, the current for the color
+          from color register 1 is used.
+     $ref: /schemas/types.yaml#/definitions/uint8-array
+     items:

Indentation is wrong. That should be an error...

Quoted 9 lines
Documentation/devicetree/bindings/leds/leds-ktd20xx.yaml new file +9 -0
+       - minItems: 3
+       - maxItems: 3
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+

Documentation/devicetree/bindings/leds/leds-ktd20xx.yaml line 101

Quoted 10 lines
Documentation/devicetree/bindings/leds/leds-ktd20xx.yaml new file +10 -0
+examples:
+  - |
+   #include <dt-bindings/leds/common.h>
+
+   i2c {
+       #address-cells = <1>;
+       #size-cells = <0>;
+
+       led-controller@14 {
+           compatible = "ti,lp5009";

Not the right compatible.

Documentation/devicetree/bindings/leds/leds-ktd20xx.yaml line 106

Quoted 5 lines
Documentation/devicetree/bindings/leds/leds-ktd20xx.yaml new file +5 -0
+           reg = <0x14>;
+           #address-cells = <1>;
+           #size-cells = <0>;
+           color-current0 = [ 00 00 00 ] // Current for RGB is 0mA
+           color-current1 = [ 28 28 28 ] // Current for RGB is 5mA

If these are already used for other bindings, then reuse the same property names.

Quoted 4 lines
Documentation/devicetree/bindings/leds/leds-ktd20xx.yaml new file +4 -0
+
+           multi-led@0 {
+               reg = <0x0>;
+               color = <LED_COLOR_ID_RGB>;

Documentation/devicetree/bindings/leds/leds-ktd20xx.yaml line 120

Quoted 10 lines
Documentation/devicetree/bindings/leds/leds-ktd20xx.yaml new file +10 -0
+               function = LED_FUNCTION_CHARGING;
+                kinetic,color-selection = [ 00 01 00 ]; // Red=0mA Green=5mA Blue=0mA
+          };
+
+          multi-led@2 {
+            reg = <0x2>;
+            color = <LED_COLOR_ID_RGB>;
+            function = LED_FUNCTION_STANDBY;
+         };
+       };

Fix the indentation.

Quoted 19 lines
Documentation/devicetree/bindings/leds/leds-ktd20xx.yaml new file +3 -0
+    };
+
+...
MAINTAINERS +1 -0
index 736d564f7e93..125bae48c2d1 100644
@@ -10607,6 +10607,7 @@ KTD20XX LED CONTROLLER DRIVER
 M:	Florian Eckert <[email protected]>
 L:	[email protected]
 S:	Maintained
+F:	Documentation/devicetree/bindings/leds/leds-ktd20xx.yaml
 F:	drivers/leds/leds-ktd20xx.c
 
 KTEST
Signature · 1 line
2.20.1