Skip to contentSkip to conversation

Multicolor Framework

PATCH Superseded Dan Murphy 4 participants 29 messages Oct 1, 2019 – Oct 7, 2019

Subsystems (4)

v10 of 17 Superseded Latest is v17 →

lore
Share & tools
lore
author
#3 lore raw

PATCH v10 3/16 leds: Add multicolor ID to the color ID list

In reply to Dan Murphy

Add a new color ID that is declared as MULTICOLOR as with the multicolor framework declaring a definitive color is not accurate as the node can contain multiple colors.

---
 drivers/leds/led-core.c | 1 +
 1 file changed, 1 insertion(+)
drivers/leds/led-core.c +1 -0
index f1f718dbe0f8..846248a0693d 100644
@@ -34,6 +34,7 @@ const char * const led_colors[LED_COLOR_ID_MAX] = {
 	[LED_COLOR_ID_VIOLET] = "violet",
 	[LED_COLOR_ID_YELLOW] = "yellow",
 	[LED_COLOR_ID_IR] = "ir",
+	[LED_COLOR_ID_MULTI] = "multicolor",
 };
 EXPORT_SYMBOL_GPL(led_colors);
 
Signature · 1 line
2.22.0.214.g8dca754b1e
author
#1 lore raw

PATCH v10 1/16 dt: bindings: Add multicolor class dt bindings documention

In reply to Dan Murphy

Add DT bindings for the LEDs multicolor class framework.

---
 .../bindings/leds/leds-class-multicolor.txt   | 98 +++++++++++++++++++
 1 file changed, 98 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/leds/leds-class-multicolor.txt
Documentation/devicetree/bindings/leds/leds-class-multicolor.txt new file +98 -0
new file mode 100644
index 000000000000..8619c9bf1811
@@ -0,0 +1,98 @@
+* Multicolor LED properties
+
+Bindings for multi color LEDs show how to describe current outputs of
+either integrated multi-color LED elements (like RGB, RGBW, RGBWA-UV
+etc.) or standalone LEDs, to achieve logically grouped multi-color LED
+modules. This is achieved by adding multi-led nodes layer to the
+monochrome LED bindings.
+
+The nodes and properties defined in this document are unique to the multicolor
+LED class.  Common LED nodes and properties are inherited from the common.txt
+within this documentation directory.
+
+Required LED Child properties:
+	- color : For multicolor LED support this property should be defined as
+		  LED_COLOR_ID_MULTI and further definition can be found in
+		  include/linux/leds/common.h.
+
+led-controller@30 {
+	#address-cells = <1>;
+	#size-cells = <0>;
+	compatible = "ti,lp5024";
+	reg = <0x29>;
+
+	multi-led@1 {
+		#address-cells = <1>;
+		#size-cells = <0>;
+		reg = <1>;
+		color = <LED_COLOR_ID_MULTI>;
+		function = LED_FUNCTION_STATUS;
+
+
+		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>;
+		};
+	};
+
+	multi-led@2 {
+		#address-cells = <1>;
+		#size-cells = <0>;
+		color = <LED_COLOR_ID_MULTI>;
+		function = LED_FUNCTION_ACTIVITY;
+		reg = <2>;
+		ti,led-bank = <2 3 5>;
+
+		led@6 {
+			reg = <0x6>;
+			color = <LED_COLOR_ID_RED>;
+			led-sources = <6 9 15>;
+		};
+
+		led@7 {
+			reg = <0x7>;
+			color = <LED_COLOR_ID_GREEN>;
+			led-sources = <7 10 16>;
+		};
+
+		led@8 {
+			reg = <0x8>;
+			color = <LED_COLOR_ID_BLUE>;
+			led-sources = <8 11 17>;
+		};
+	};
+
+	multi-led@4 {
+		#address-cells = <1>;
+		#size-cells = <0>;
+		reg = <4>;
+		color = <LED_COLOR_ID_MULTI>;
+		function = LED_FUNCTION_ACTIVITY;
+
+		led@12 {
+			reg = <12>;
+			color = <LED_COLOR_ID_RED>;
+		};
+
+		led@13 {
+			reg = <13>;
+			color = <LED_COLOR_ID_GREEN>;
+		};
+
+		led@14 {
+			reg = <14>;
+			color = <LED_COLOR_ID_BLUE>;
+		};
+	};
+
+};
Signature · 1 line
2.22.0.214.g8dca754b1e
author
#12 lore raw

PATCH v10 7/16 dt: bindings: lp55xx: Be consistent in the document with LED acronym

In reply to Dan Murphy

Update the document to be consistent in case when using "LED". This acronym should be capital throughout the document.

---
 Documentation/devicetree/bindings/leds/leds-lp55xx.txt | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/leds/leds-lp55xx.txt +3 -3
index 1b66a413fb9d..bfe2805c5534 100644
@@ -1,4 +1,4 @@
-Binding for TI/National Semiconductor LP55xx Led Drivers
+Binding for TI/National Semiconductor LP55xx LED Drivers
 
 Required properties:
 - compatible: one of
@@ -12,8 +12,8 @@ Required properties:
 - clock-mode: Input clock mode, (0: automode, 1: internal, 2: external)
 
 Each child has own specific current settings
-- led-cur: Current setting at each led channel (mA x10, 0 if led is not connected)
-- max-cur: Maximun current at each led channel.
+- led-cur: Current setting at each LED channel (mA x10, 0 if LED is not connected)
+- max-cur: Maximun current at each LED channel.
 
 Optional properties:
 - enable-gpio: GPIO attached to the chip's enable pin
Signature · 1 line
2.22.0.214.g8dca754b1e
author
#14 lore raw

PATCH v10 9/16 ARM: dts: n900: Add reg property to the LP5523 channel node

In reply to Dan Murphy

Add the reg property to each channel node. This update is to accomodate the multicolor framework. In addition to the accomodation this allows the LEDs to be placed on any channel and allow designs to skip channels as opposed to requiring sequential order.

CC Tony Lindgren <[email protected]>
CC "Benoît Cousson" <[email protected]>

k# interactive rebase in progress; onto ae89cc6d4a8c

---
 arch/arm/boot/dts/omap3-n900.dts | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)
arch/arm/boot/dts/omap3-n900.dts +20 -9
index 84a5ade1e865..643f35619246 100644
@@ -607,63 +607,74 @@
 	};
 
 	lp5523: lp5523@32 {
+		#address-cells = <1>;
+		#size-cells = <0>;
 		compatible = "national,lp5523";
 		reg = <0x32>;
 		clock-mode = /bits/ 8 <0>; /* LP55XX_CLOCK_AUTO */
 		enable-gpio = <&gpio2 9 GPIO_ACTIVE_HIGH>; /* 41 */
 
-		chan0 {
+		chan@0 {
 			chan-name = "lp5523:kb1";
 			led-cur = /bits/ 8 <50>;
 			max-cur = /bits/ 8 <100>;
+			reg = <0>;
 		};
 
-		chan1 {
+		chan@1 {
 			chan-name = "lp5523:kb2";
 			led-cur = /bits/ 8 <50>;
 			max-cur = /bits/ 8 <100>;
+			reg = <1>;
 		};
 
-		chan2 {
+		chan@2 {
 			chan-name = "lp5523:kb3";
 			led-cur = /bits/ 8 <50>;
 			max-cur = /bits/ 8 <100>;
+			reg = <2>;
 		};
 
-		chan3 {
+		chan@3 {
 			chan-name = "lp5523:kb4";
 			led-cur = /bits/ 8 <50>;
 			max-cur = /bits/ 8 <100>;
+			reg = <3>;
 		};
 
-		chan4 {
+		chan@4 {
 			chan-name = "lp5523:b";
 			led-cur = /bits/ 8 <50>;
 			max-cur = /bits/ 8 <100>;
+			reg = <4>;
 		};
 
-		chan5 {
+		chan@5 {
 			chan-name = "lp5523:g";
 			led-cur = /bits/ 8 <50>;
 			max-cur = /bits/ 8 <100>;
+			reg = <5>;
 		};
 
-		chan6 {
+		chan@6 {
 			chan-name = "lp5523:r";
 			led-cur = /bits/ 8 <50>;
 			max-cur = /bits/ 8 <100>;
+			reg = <6>;
 		};
 
-		chan7 {
+		chan@7 {
 			chan-name = "lp5523:kb5";
 			led-cur = /bits/ 8 <50>;
 			max-cur = /bits/ 8 <100>;
+			reg = <7>;
 		};
 
-		chan8 {
+		chan@8 {
 			chan-name = "lp5523:kb6";
 			led-cur = /bits/ 8 <50>;
 			max-cur = /bits/ 8 <100>;
+			reg = <8>;
 		};
 	};
 
Signature · 1 line
2.22.0.214.g8dca754b1e
author
#15 lore raw

PATCH v10 10/16 ARM: dts: imx6dl-yapp4: Add reg property to the lp5562 channel node

In reply to Dan Murphy

Add the reg property to each channel node. This update is to accomodate the multicolor framework. In addition to the accomodation this allows the LEDs to be placed on any channel and allow designs to skip channels as opposed to requiring sequential order.

CC Shawn Guo <[email protected]>
CC Sascha Hauer <[email protected]>
CC Pengutronix Kernel Team <[email protected]>
CC Fabio Estevam <[email protected]>
CC NXP Linux Team <[email protected]>
---
 arch/arm/boot/dts/imx6dl-yapp4-common.dtsi | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
arch/arm/boot/dts/imx6dl-yapp4-common.dtsi +10 -4
index e8d800fec637..efc466ed1fea 100644
@@ -257,29 +257,35 @@
 		reg = <0x30>;
 		clock-mode = /bits/ 8 <1>;
 		status = "disabled";
+		#address-cells = <1>;
+		#size-cells = <0>;
 
-		chan0 {
+		chan@0 {
 			chan-name = "R";
 			led-cur = /bits/ 8 <0x20>;
 			max-cur = /bits/ 8 <0x60>;
+			reg = <0>;
 		};
 
-		chan1 {
+		chan@1 {
 			chan-name = "G";
 			led-cur = /bits/ 8 <0x20>;
 			max-cur = /bits/ 8 <0x60>;
+			reg = <1>;
 		};
 
-		chan2 {
+		chan@2 {
 			chan-name = "B";
 			led-cur = /bits/ 8 <0x20>;
 			max-cur = /bits/ 8 <0x60>;
+			reg = <2>;
 		};
 
-		chan3 {
+		chan@3 {
 			chan-name = "W";
 			led-cur = /bits/ 8 <0x0>;
 			max-cur = /bits/ 8 <0x0>;
+			reg = <3>;
 		};
 	};
 
Signature · 1 line
2.22.0.214.g8dca754b1e
author
#13 lore raw

PATCH v10 8/16 dt: bindings: lp55xx: Update binding for Multicolor Framework

In reply to Dan Murphy

Update the DT binding to include the properties to use the multicolor framework for the devices that use the LP55xx framework.

CC Tony Lindgren <[email protected]>
CC "Benoît Cousson" <[email protected]>
CC Linus Walleij <[email protected]>
CC Shawn Guo <[email protected]>
CC Sascha Hauer <[email protected]>
CC Pengutronix Kernel Team <[email protected]>
CC Fabio Estevam <[email protected]>
CC NXP Linux Team <[email protected]>
---
 .../devicetree/bindings/leds/leds-lp55xx.txt  | 149 +++++++++++++++---
 1 file changed, 124 insertions(+), 25 deletions(-)
Documentation/devicetree/bindings/leds/leds-lp55xx.txt +124 -25
index bfe2805c5534..736a2e1538be 100644
@@ -1,6 +1,8 @@
 Binding for TI/National Semiconductor LP55xx LED Drivers
 
 Required properties:
+- #address-cells: 1
+- #size-cells: 0
 - compatible: one of
 	national,lp5521
 	national,lp5523
@@ -14,6 +16,18 @@ Required properties:
 Each child has own specific current settings
 - led-cur: Current setting at each LED channel (mA x10, 0 if LED is not connected)
 - max-cur: Maximun current at each LED channel.
+- reg: Output channel for the LED.  This is zero based channel identifier and
+	the data sheet is a one based channel identifier.
+	reg value to output to LED output number
+	D1 = reg value is 0
+	D2 = reg value is 1
+	D3 = reg value is 2
+	D4 = reg value is 3
+	D5 = reg value is 4
+	D6 = reg value is 5
+	D7 = reg value is 6
+	D8 = reg value is 7
+	D9 = reg value is 8
 
 Optional properties:
 - enable-gpio: GPIO attached to the chip's enable pin
@@ -35,23 +49,28 @@ example 1) LP5521
 on channel 0.
 
 lp5521@32 {
+	#address-cells = <1>;
+	#size-cells = <0>;
 	compatible = "national,lp5521";
 	reg = <0x32>;
 	label = "lp5521_pri";
 	clock-mode = /bits/ 8 <2>;
 
-	chan0 {
+	chan@0 {
+		reg = <0>;
 		led-cur = /bits/ 8 <0x2f>;
 		max-cur = /bits/ 8 <0x5f>;
 		linux,default-trigger = "heartbeat";
 	};
 
-	chan1 {
+	chan@1 {
+		reg = <1>;
 		led-cur = /bits/ 8 <0x2f>;
 		max-cur = /bits/ 8 <0x5f>;
 	};
 
-	chan2 {
+	chan@2 {
+		reg = <2>;
 		led-cur = /bits/ 8 <0x2f>;
 		max-cur = /bits/ 8 <0x5f>;
 	};
@@ -70,59 +89,70 @@ ASEL1    ASEL0    Address
  VEN      VEN       35h
 
 lp5523@32 {
+	#address-cells = <1>;
+	#size-cells = <0>;
 	compatible = "national,lp5523";
 	reg = <0x32>;
 	clock-mode = /bits/ 8 <1>;
 
-	chan0 {
+	chan@0 {
+		reg = <0>;
 		chan-name = "d1";
 		led-cur = /bits/ 8 <0x14>;
 		max-cur = /bits/ 8 <0x20>;
 	};
 
-	chan1 {
+	chan@1 {
+		reg = <1>;
 		chan-name = "d2";
 		led-cur = /bits/ 8 <0x14>;
 		max-cur = /bits/ 8 <0x20>;
 	};
 
-	chan2 {
+	chan@2 {
+		reg = <2>;
 		chan-name = "d3";
 		led-cur = /bits/ 8 <0x14>;
 		max-cur = /bits/ 8 <0x20>;
 	};
 
-	chan3 {
+	chan@3 {
+		reg = <3>;
 		chan-name = "d4";
 		led-cur = /bits/ 8 <0x14>;
 		max-cur = /bits/ 8 <0x20>;
 	};
 
-	chan4 {
+	chan@4 {
+		reg = <4>;
 		chan-name = "d5";
 		led-cur = /bits/ 8 <0x14>;
 		max-cur = /bits/ 8 <0x20>;
 	};
 
-	chan5 {
+	chan@5 {
+		reg = <5>;
 		chan-name = "d6";
 		led-cur = /bits/ 8 <0x14>;
 		max-cur = /bits/ 8 <0x20>;
 	};
 
-	chan6 {
+	chan@6 {
+		reg = <6>;
 		chan-name = "d7";
 		led-cur = /bits/ 8 <0x14>;
 		max-cur = /bits/ 8 <0x20>;
 	};
 
-	chan7 {
+	chan@7 {
+		reg = <7>;
 		chan-name = "d8";
 		led-cur = /bits/ 8 <0x14>;
 		max-cur = /bits/ 8 <0x20>;
 	};
 
-	chan8 {
+	chan@8 {
+		reg = <8>;
 		chan-name = "d9";
 		led-cur = /bits/ 8 <0x14>;
 		max-cur = /bits/ 8 <0x20>;
@@ -133,29 +163,35 @@ example 3) LP5562
 4 channels are defined.
 
 lp5562@30 {
+	#address-cells = <1>;
+	#size-cells = <0>;
 	compatible = "ti,lp5562";
 	reg = <0x30>;
 	clock-mode = /bits/8 <2>;
 
-	chan0 {
+	chan@0 {
+		reg = <0>;
 		chan-name = "R";
 		led-cur = /bits/ 8 <0x20>;
 		max-cur = /bits/ 8 <0x60>;
 	};
 
-	chan1 {
+	chan@1 {
+		reg = <1>;
 		chan-name = "G";
 		led-cur = /bits/ 8 <0x20>;
 		max-cur = /bits/ 8 <0x60>;
 	};
 
-	chan2 {
+	chan@2 {
+		reg = <2>;
 		chan-name = "B";
 		led-cur = /bits/ 8 <0x20>;
 		max-cur = /bits/ 8 <0x60>;
 	};
 
-	chan3 {
+	chan@3 {
+		reg = <3>;
 		chan-name = "W";
 		led-cur = /bits/ 8 <0x20>;
 		max-cur = /bits/ 8 <0x60>;
@@ -167,62 +203,125 @@ example 4) LP8501
 Others are same as LP5523.
 
 lp8501@32 {
+	#address-cells = <1>;
+	#size-cells = <0>;
 	compatible = "ti,lp8501";
 	reg = <0x32>;
 	clock-mode = /bits/ 8 <2>;
 	pwr-sel = /bits/ 8 <3>;	/* D1~9 connected to VOUT */
 
-	chan0 {
+	chan@0 {
+		reg = <0>;
 		chan-name = "d1";
 		led-cur = /bits/ 8 <0x14>;
 		max-cur = /bits/ 8 <0x20>;
 	};
 
-	chan1 {
+	chan@1 {
+		reg = <1>;
 		chan-name = "d2";
 		led-cur = /bits/ 8 <0x14>;
 		max-cur = /bits/ 8 <0x20>;
 	};
 
-	chan2 {
+	chan@2 {
+		reg = <2>;
 		chan-name = "d3";
 		led-cur = /bits/ 8 <0x14>;
 		max-cur = /bits/ 8 <0x20>;
 	};
 
-	chan3 {
+	chan@3 {
+		reg = <3>;
 		chan-name = "d4";
 		led-cur = /bits/ 8 <0x14>;
 		max-cur = /bits/ 8 <0x20>;
 	};
 
-	chan4 {
+	chan@4 {
+		reg = <4>;
 		chan-name = "d5";
 		led-cur = /bits/ 8 <0x14>;
 		max-cur = /bits/ 8 <0x20>;
 	};
 
-	chan5 {
+	chan@5 {
+		reg = <5>;
 		chan-name = "d6";
 		led-cur = /bits/ 8 <0x14>;
 		max-cur = /bits/ 8 <0x20>;
 	};
 
-	chan6 {
+	chan@6 {
+		reg = <6>;
 		chan-name = "d7";
 		led-cur = /bits/ 8 <0x14>;
 		max-cur = /bits/ 8 <0x20>;
 	};
 
-	chan7 {
+	chan@7 {
+		reg = <7>;
 		chan-name = "d8";
 		led-cur = /bits/ 8 <0x14>;
 		max-cur = /bits/ 8 <0x20>;
 	};
 
-	chan8 {
+	chan@8 {
+		reg = <8>;
 		chan-name = "d9";
 		led-cur = /bits/ 8 <0x14>;
 		max-cur = /bits/ 8 <0x20>;
 	};
 };
+
+Multicolor Framework Support
+In addition to the nodes and properties defined above for device support the
+properties below are needed for multicolor framework support as defined in
+Documentation/devicetree/bindings/leds/leds-class-multicolor.txt
+
+Required child properties for multicolor framework
+	- color : Must be LED_COLOR_ID_MULTI
+	- function : see Documentation/devicetree/bindings/leds/common.txt
+
+Required grandchildren properties
+	- reg : This is the LED output of the device
+	- color : see Documentation/devicetree/bindings/leds/common.txt
+
+Multicolor LED example:
+lp5523: lp5523@32 {
+	#address-cells = <1>;
+	#size-cells = <0>;
+	compatible = "national,lp5523";
+	reg = <0x32>;
+	clock-mode = /bits/ 8 <0>; /* LP55XX_CLOCK_AUTO */
+
+	multi-led@2 {
+		#address-cells = <1>;
+		#size-cells = <0>;
+		reg = <2>;
+		color = <LED_COLOR_ID_MULTI>;
+		function = LED_FUNCTION_STANDBY;
+		linux,default-trigger = "heartbeat";
+
+		led@0 {
+			led-cur = /bits/ 8 <50>;
+			max-cur = /bits/ 8 <100>;
+			reg = <0x0>;
+			color = <LED_COLOR_ID_GREEN>;
+		};
+
+		led@1 {
+			led-cur = /bits/ 8 <50>;
+			max-cur = /bits/ 8 <100>;
+			reg = <0x1>;
+			color = <LED_COLOR_ID_BLUE>;
+		};
+
+		led@6 {
+			led-cur = /bits/ 8 <50>;
+			max-cur = /bits/ 8 <100>;
+			reg = <0x6>;
+			color = <LED_COLOR_ID_RED>;
+		};
+	};
+};
Signature · 1 line
2.22.0.214.g8dca754b1e
author
#25 lore raw

PATCH v10 14/16 leds: lp5521: Add multicolor framework intensity support

In reply to Dan Murphy

Add the intensity function call back to support the multicolor framework. This function allows setting a specific brightness on a specific channel.

---
 drivers/leds/leds-lp5521.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/leds/leds-lp5521.c +14 -0
index 6f0272249dc8..9c71f0fe7bf8 100644
@@ -349,6 +349,19 @@ static int lp5521_run_selftest(struct lp55xx_chip *chip, char *buf)
 	return 0;
 }
 
+static int lp5521_led_intensity(struct lp55xx_led *led, int chan_num,
+				int brightness)
+{
+	struct lp55xx_chip *chip = led->chip;
+	int ret;
+
+	mutex_lock(&chip->lock);
+	ret = lp55xx_write(chip, LP5521_REG_LED_PWM_BASE + chan_num,
+			   brightness);
+	mutex_unlock(&chip->lock);
+	return ret;
+}
+
 static int lp5521_led_brightness(struct lp55xx_led *led)
 {
 	struct lp55xx_chip *chip = led->chip;
@@ -490,6 +503,7 @@ static struct lp55xx_device_config lp5521_cfg = {
 	.max_channel  = LP5521_MAX_LEDS,
 	.post_init_device   = lp5521_post_init_device,
 	.brightness_fn      = lp5521_led_brightness,
+	.color_intensity_fn = lp5521_led_intensity,
 	.set_led_current    = lp5521_set_led_current,
 	.firmware_cb        = lp5521_firmware_loaded,
 	.run_engine         = lp5521_run_engine,
Signature · 1 line
2.22.0.214.g8dca754b1e
author
#4 lore raw

PATCH v10 4/16 leds: multicolor: Introduce a multicolor class definition

In reply to Dan Murphy

Introduce a multicolor class that groups colored LEDs within a LED node.

The multi color class groups monochrome LEDs and allows controlling two aspects of the final combined color: hue and lightness. The former is controlled via <color>_intensity files and the latter is controlled via brightness file.

---
 .../ABI/testing/sysfs-class-led-multicolor    |  35 +++
 Documentation/leds/index.rst                  |   1 +
 Documentation/leds/leds-class-multicolor.rst  |  96 +++++++
 drivers/leds/Kconfig                          |  10 +
 drivers/leds/Makefile                         |   1 +
 drivers/leds/led-class-multicolor.c           | 268 ++++++++++++++++++
 include/linux/led-class-multicolor.h          |  88 ++++++
 7 files changed, 499 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-class-led-multicolor
 create mode 100644 Documentation/leds/leds-class-multicolor.rst
 create mode 100644 drivers/leds/led-class-multicolor.c
 create mode 100644 include/linux/led-class-multicolor.h
Documentation/ABI/testing/sysfs-class-led-multicolor new file +35 -0
new file mode 100644
index 000000000000..65cb43de26e6
@@ -0,0 +1,35 @@
+What:		/sys/class/leds/<led>/brightness
+Date:		Sept 2019
+KernelVersion:	5.5
+Contact:	Dan Murphy <[email protected]>
+Description:	read/write
+		Writing to this file will update all LEDs within the group to a
+		calculated percentage of what each color LED intensity is set
+		to. The percentage is calculated via the equation below:
+
+		led_brightness = brightness * <color>_intensity/<color>_max_intensity
+
+		For additional details please refer to
+		Documentation/leds/leds-class-multicolor.rst.
+
+		The value of the color is from 0 to
+		/sys/class/leds/<led>/max_brightness.
+
+What:		/sys/class/leds/<led>/colors/<color>_intensity
+Date:		Sept 2019
+KernelVersion:	5.5
+Contact:	Dan Murphy <[email protected]>
+Description:	read/write
+		The <color>_intensity file is created based on the color
+		defined by the registrar of the class.
+		There is one file per color presented.
+
+		The value of the color is from 0 to
+		/sys/class/leds/<led>/colors/<color>_max_intensity.
+
+What:		/sys/class/leds/<led>/colors/<color>_max_intensity
+Date:		Sept 2019
+KernelVersion:	5.5
+Contact:	Dan Murphy <[email protected]>
+Description:	read only
+		Maximum intensity level for the LED color.
Documentation/leds/index.rst +1 -0
index 060f4e485897..bc70c6aa7138 100644
@@ -9,6 +9,7 @@ LEDs
 
    leds-class
    leds-class-flash
+   leds-class-multicolor
    ledtrig-oneshot
    ledtrig-transient
    ledtrig-usbport
Documentation/leds/leds-class-multicolor.rst new file +96 -0

96 lines not on this page · raw message

drivers/leds/Kconfig +10 -0
index 6e7703fd03d0..cfb1ebb6517f 100644
@@ -30,6 +30,16 @@ config LEDS_CLASS_FLASH
 	  for the flash related features of a LED device. It can be built
 	  as a module.
 
+config LEDS_CLASS_MULTI_COLOR
+	tristate "LED Mulit Color LED Class Support"
+	depends on LEDS_CLASS
+	help
+	  This option enables the multicolor LED sysfs class in /sys/class/leds.
+	  It wraps LED class and adds multicolor LED specific sysfs attributes
+	  and kernel internal API to it. You'll need this to provide support
+	  for multicolor LEDs that are grouped together. This class is not
+	  intended for single color LEDs. It can be built as a module.
+
 config LEDS_BRIGHTNESS_HW_CHANGED
 	bool "LED Class brightness_hw_changed attribute support"
 	depends on LEDS_CLASS
drivers/leds/Makefile +1 -0
index 2da39e896ce8..841038cfe35b 100644
@@ -4,6 +4,7 @@
 obj-$(CONFIG_NEW_LEDS)			+= led-core.o
 obj-$(CONFIG_LEDS_CLASS)		+= led-class.o
 obj-$(CONFIG_LEDS_CLASS_FLASH)		+= led-class-flash.o
+obj-$(CONFIG_LEDS_CLASS_MULTI_COLOR)	+= led-class-multicolor.o
 obj-$(CONFIG_LEDS_TRIGGERS)		+= led-triggers.o
 
 # LED Platform Drivers
drivers/leds/led-class-multicolor.c new file +268 -0

268 lines not on this page · raw message

include/linux/led-class-multicolor.h new file +88 -0

88 lines not on this page · raw message

Signature · 1 line
2.22.0.214.g8dca754b1e
author
#8 lore raw

PATCH v10 6/16 leds: lp50xx: Add the LP50XX family of the RGB LED driver

In reply to Dan Murphy

Introduce the LP5036/30/24/18/12/9 RGB LED driver. The difference in these parts are the number of LED outputs where the:

LP5036 can control 36 LEDs
LP5030 can control 30 LEDs
LP5024 can control 24 LEDs
LP5018 can control 18 LEDs
LP5012 can control 12 LEDs
LP5009 can control 9 LEDs

The device has the ability to group LED output into control banks so that multiple LED banks can be controlled with the same mixing and brightness. Inversely the LEDs can also be controlled independently.

---
 drivers/leds/Kconfig       |  11 +
 drivers/leds/Makefile      |   1 +
 drivers/leds/leds-lp50xx.c | 784 +++++++++++++++++++++++++++++++++++++
 3 files changed, 796 insertions(+)
 create mode 100644 drivers/leds/leds-lp50xx.c
drivers/leds/Kconfig +11 -0
index cfb1ebb6517f..84f60e35c5ee 100644
@@ -363,6 +363,17 @@ config LEDS_LP3952
 	  To compile this driver as a module, choose M here: the
 	  module will be called leds-lp3952.
 
+config LEDS_LP50XX
+	tristate "LED Support for TI LP5036/30/24/18/12/9 LED driver chip"
+	depends on LEDS_CLASS && REGMAP_I2C
+	depends on LEDS_CLASS_MULTI_COLOR
+	help
+	  If you say yes here you get support for the Texas Instruments
+	  LP5036, LP5030, LP5024, LP5018, LP5012 and LP5009 LED driver.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called leds-lp50xx.
+
 config LEDS_LP55XX_COMMON
 	tristate "Common Driver for TI/National LP5521/5523/55231/5562/8501"
 	depends on LEDS_LP5521 || LEDS_LP5523 || LEDS_LP5562 || LEDS_LP8501
drivers/leds/Makefile +1 -0
index 841038cfe35b..7a208a0f7b84 100644
@@ -34,6 +34,7 @@ obj-$(CONFIG_LEDS_GPIO_REGISTER)	+= leds-gpio-register.o
 obj-$(CONFIG_LEDS_GPIO)			+= leds-gpio.o
 obj-$(CONFIG_LEDS_LP3944)		+= leds-lp3944.o
 obj-$(CONFIG_LEDS_LP3952)		+= leds-lp3952.o
+obj-$(CONFIG_LEDS_LP50XX)		+= leds-lp50xx.o
 obj-$(CONFIG_LEDS_LP55XX_COMMON)	+= leds-lp55xx-common.o
 obj-$(CONFIG_LEDS_LP5521)		+= leds-lp5521.o
 obj-$(CONFIG_LEDS_LP5523)		+= leds-lp5523.o
drivers/leds/leds-lp50xx.c new file +784 -0

784 lines not on this page · raw message

Signature · 1 line
2.22.0.214.g8dca754b1e
author
#18 lore raw

PATCH v10 12/16 leds: lp55xx: Add multicolor framework support to lp55xx

In reply to Dan Murphy

Add multicolor framework support for the lp55xx family.

---
 drivers/leds/Kconfig                      |   1 +
 drivers/leds/leds-lp55xx-common.c         | 169 +++++++++++++++++++---
 drivers/leds/leds-lp55xx-common.h         |  11 ++
 include/linux/platform_data/leds-lp55xx.h |   6 +
 4 files changed, 163 insertions(+), 24 deletions(-)
drivers/leds/Kconfig +1 -0
index 84f60e35c5ee..dc3d9f2194cd 100644
@@ -377,6 +377,7 @@ config LEDS_LP50XX
 config LEDS_LP55XX_COMMON
 	tristate "Common Driver for TI/National LP5521/5523/55231/5562/8501"
 	depends on LEDS_LP5521 || LEDS_LP5523 || LEDS_LP5562 || LEDS_LP8501
+	depends on LEDS_CLASS_MULTI_COLOR && OF
 	select FW_LOADER
 	select FW_LOADER_USER_HELPER
 	help
drivers/leds/leds-lp55xx-common.c +145 -24

229 lines not on this page · raw message

drivers/leds/leds-lp55xx-common.h +11 -0
index 783ed5103ce5..5ea2a292a97e 100644
@@ -12,6 +12,10 @@
 #ifndef _LEDS_LP55XX_COMMON_H
 #define _LEDS_LP55XX_COMMON_H
 
+#include <linux/led-class-multicolor.h>
+
+#define LP55XX_MAX_GROUPED_CHAN	4
+
 enum lp55xx_engine_index {
 	LP55XX_ENGINE_INVALID,
 	LP55XX_ENGINE_1,
@@ -109,6 +113,9 @@ struct lp55xx_device_config {
 	/* access brightness register */
 	int (*brightness_fn)(struct lp55xx_led *led);
 
+	/* access specific brightness register */
+	int (*color_intensity_fn)(struct lp55xx_led *led, int chan_num, int brightness);
+
 	/* current setting function */
 	void (*set_led_current) (struct lp55xx_led *led, u8 led_current);
 
@@ -159,6 +166,7 @@ struct lp55xx_chip {
  * struct lp55xx_led
  * @chan_nr         : Channel number
  * @cdev            : LED class device
+ * @mc_cdev	    : Multi color class device
  * @led_current     : Current setting at each led channel
  * @max_current     : Maximun current at each led channel
  * @brightness      : Brightness value
@@ -167,9 +175,12 @@ struct lp55xx_chip {
 struct lp55xx_led {
 	int chan_nr;
 	struct led_classdev cdev;
+	struct led_classdev_mc mc_cdev;
 	u8 led_current;
 	u8 max_current;
 	u8 brightness;
+	int channel_color[LP55XX_MAX_GROUPED_CHAN];
+	int grouped_channels[LP55XX_MAX_GROUPED_CHAN];
 	struct lp55xx_chip *chip;
 };
 
include/linux/platform_data/leds-lp55xx.h +6 -0
index 96a787100fda..0ac29f537ab6 100644
@@ -12,6 +12,8 @@
 #ifndef _LEDS_LP55XX_H
 #define _LEDS_LP55XX_H
 
+#include <linux/led-class-multicolor.h>
+
 /* Clock configuration */
 #define LP55XX_CLOCK_AUTO	0
 #define LP55XX_CLOCK_INT	1
@@ -23,6 +25,10 @@ struct lp55xx_led_config {
 	u8 chan_nr;
 	u8 led_current; /* mA x10, 0 if led is not connected */
 	u8 max_current;
+	int num_colors;
+	unsigned long available_colors;
+	u32 channel_color[LED_COLOR_ID_MAX];
+	int grouped_channels[LED_COLOR_ID_MAX];
 };
 
 struct lp55xx_predef_pattern {
Signature · 1 line
2.22.0.214.g8dca754b1e
author
#27 lore raw

PATCH v10 16/16 leds: lp5523: Fix checkpatch issues in the code

In reply to Dan Murphy

Fix checkpatch errors and warnings for the LP5523.c device driver.

---
 drivers/leds/leds-lp5523.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)
drivers/leds/leds-lp5523.c +10 -9
index 07484fc2f715..039db7e676ab 100644
@@ -23,13 +23,13 @@
 
 #define LP5523_PROGRAM_LENGTH		32	/* bytes */
 /* Memory is used like this:
-   0x00 engine 1 program
-   0x10 engine 2 program
-   0x20 engine 3 program
-   0x30 engine 1 muxing info
-   0x40 engine 2 muxing info
-   0x50 engine 3 muxing info
-*/
+ * 0x00 engine 1 program
+ * 0x10 engine 2 program
+ * 0x20 engine 3 program
+ * 0x30 engine 1 muxing info
+ * 0x40 engine 2 muxing info
+ * 0x50 engine 3 muxing info
+ */
 #define LP5523_MAX_LEDS			9
 
 /* Registers */
@@ -326,7 +326,7 @@ static int lp5523_update_program_memory(struct lp55xx_chip *chip,
 					const u8 *data, size_t size)
 {
 	u8 pattern[LP5523_PROGRAM_LENGTH] = {0};
-	unsigned cmd;
+	unsigned int cmd;
 	char c[3];
 	int nrchars;
 	int ret;
@@ -468,6 +468,7 @@ static int lp5523_mux_parse(const char *buf, u16 *mux, size_t len)
 static void lp5523_mux_to_array(u16 led_mux, char *array)
 {
 	int i, pos = 0;
+
 	for (i = 0; i < LP5523_MAX_LEDS; i++)
 		pos += sprintf(array + pos, "%x", LED_ACTIVE(led_mux, i));
 
@@ -506,7 +507,7 @@ static int lp5523_load_mux(struct lp55xx_chip *chip, u16 mux, int nr)
 	if (ret)
 		return ret;
 
-	ret = lp55xx_write(chip, LP5523_REG_PROG_MEM , (u8)(mux >> 8));
+	ret = lp55xx_write(chip, LP5523_REG_PROG_MEM, (u8)(mux >> 8));
 	if (ret)
 		return ret;
 
Signature · 1 line
2.22.0.214.g8dca754b1e
author
#26 lore raw

PATCH v10 15/16 leds: lp55xx: Fix checkpatch file permissions issues

In reply to Dan Murphy

Fix the checkpatch warnings for the use of the file permission macros. In converting the file permissions to the DEVICE_ATTR_XX macros the call back function names needed to be updated within the code.

This means that the lp55xx_ needed to be dropped in the name to keep in harmony with the ABI documentation.

---
 drivers/leds/leds-lp55xx-common.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)
drivers/leds/leds-lp55xx-common.c +10 -12
index 5de4f1789a44..87bf25795c87 100644
@@ -78,7 +78,7 @@ static int lp55xx_post_init_device(struct lp55xx_chip *chip)
 	return cfg->post_init_device(chip);
 }
 
-static ssize_t lp55xx_show_current(struct device *dev,
+static ssize_t led_current_show(struct device *dev,
 			    struct device_attribute *attr,
 			    char *buf)
 {
@@ -87,7 +87,7 @@ static ssize_t lp55xx_show_current(struct device *dev,
 	return scnprintf(buf, PAGE_SIZE, "%d\n", led->led_current);
 }
 
-static ssize_t lp55xx_store_current(struct device *dev,
+static ssize_t led_current_store(struct device *dev,
 			     struct device_attribute *attr,
 			     const char *buf, size_t len)
 {
@@ -111,7 +111,7 @@ static ssize_t lp55xx_store_current(struct device *dev,
 	return len;
 }
 
-static ssize_t lp55xx_show_max_current(struct device *dev,
+static ssize_t max_current_show(struct device *dev,
 			    struct device_attribute *attr,
 			    char *buf)
 {
@@ -120,9 +120,8 @@ static ssize_t lp55xx_show_max_current(struct device *dev,
 	return scnprintf(buf, PAGE_SIZE, "%d\n", led->max_current);
 }
 
-static DEVICE_ATTR(led_current, S_IRUGO | S_IWUSR, lp55xx_show_current,
-		lp55xx_store_current);
-static DEVICE_ATTR(max_current, S_IRUGO , lp55xx_show_max_current, NULL);
+static DEVICE_ATTR_RW(led_current);
+static DEVICE_ATTR_RO(max_current);
 
 static struct attribute *lp55xx_led_attrs[] = {
 	&dev_attr_led_current.attr,
@@ -281,7 +280,7 @@ static int lp55xx_request_firmware(struct lp55xx_chip *chip)
 				GFP_KERNEL, chip, lp55xx_firmware_loaded);
 }
 
-static ssize_t lp55xx_show_engine_select(struct device *dev,
+static ssize_t select_engine_show(struct device *dev,
 			    struct device_attribute *attr,
 			    char *buf)
 {
@@ -291,7 +290,7 @@ static ssize_t lp55xx_show_engine_select(struct device *dev,
 	return sprintf(buf, "%d\n", chip->engine_idx);
 }
 
-static ssize_t lp55xx_store_engine_select(struct device *dev,
+static ssize_t select_engine_store(struct device *dev,
 			     struct device_attribute *attr,
 			     const char *buf, size_t len)
 {
@@ -333,7 +332,7 @@ static inline void lp55xx_run_engine(struct lp55xx_chip *chip, bool start)
 		chip->cfg->run_engine(chip, start);
 }
 
-static ssize_t lp55xx_store_engine_run(struct device *dev,
+static ssize_t run_engine_store(struct device *dev,
 			     struct device_attribute *attr,
 			     const char *buf, size_t len)
 {
@@ -358,9 +357,8 @@ static ssize_t lp55xx_store_engine_run(struct device *dev,
 	return len;
 }
 
-static DEVICE_ATTR(select_engine, S_IRUGO | S_IWUSR,
-		   lp55xx_show_engine_select, lp55xx_store_engine_select);
-static DEVICE_ATTR(run_engine, S_IWUSR, NULL, lp55xx_store_engine_run);
+static DEVICE_ATTR_RW(select_engine);
+static DEVICE_ATTR_WO(run_engine);
 
 static struct attribute *lp55xx_engine_attributes[] = {
 	&dev_attr_select_engine.attr,
Signature · 1 line
2.22.0.214.g8dca754b1e
author
#24 lore raw

PATCH v10 13/16 leds: lp5523: Update the lp5523 code to add intensity function

In reply to Dan Murphy

Add the intensity function call back to support the multicolor framework. This function allows setting a specific brightness on a specific channel.

---
 drivers/leds/leds-lp5523.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/leds/leds-lp5523.c +14 -0
index d0b931a136b9..07484fc2f715 100644
@@ -791,6 +791,19 @@ static ssize_t store_master_fader_leds(struct device *dev,
 	return ret;
 }
 
+static int lp5523_led_intensity(struct lp55xx_led *led, int chan_num,
+				int brightness)
+{
+	struct lp55xx_chip *chip = led->chip;
+	int ret;
+
+	mutex_lock(&chip->lock);
+	ret = lp55xx_write(chip, LP5523_REG_LED_PWM_BASE + chan_num,
+			   brightness);
+	mutex_unlock(&chip->lock);
+	return ret;
+}
+
 static int lp5523_led_brightness(struct lp55xx_led *led)
 {
 	struct lp55xx_chip *chip = led->chip;
@@ -857,6 +870,7 @@ static struct lp55xx_device_config lp5523_cfg = {
 	.max_channel  = LP5523_MAX_LEDS,
 	.post_init_device   = lp5523_post_init_device,
 	.brightness_fn      = lp5523_led_brightness,
+	.color_intensity_fn = lp5523_led_intensity,
 	.set_led_current    = lp5523_set_led_current,
 	.firmware_cb        = lp5523_firmware_loaded,
 	.run_engine         = lp5523_run_engine,
Signature · 1 line
2.22.0.214.g8dca754b1e
author
#16 lore raw

PATCH v10 11/16 ARM: dts: ste-href: Add reg property to the LP5521 channel nodes

In reply to Dan Murphy

Add the reg property to each channel node. This update is to accomodate the multicolor framework. In addition to the accomodation this allows the LEDs to be placed on any channel and allow designs to skip channels as opposed to requiring sequential order.

CC Linus Walleij <[email protected]>
---
 arch/arm/boot/dts/ste-href.dtsi | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)
arch/arm/boot/dts/ste-href.dtsi +16 -6
index 6422c53f2046..53738edd741d 100644
@@ -56,16 +56,21 @@
 				reg = <0x33>;
 				label = "lp5521_pri";
 				clock-mode = /bits/ 8 <2>;
-				chan0 {
+				#address-cells = <1>;
+				#size-cells = <0>;
+				chan@0 {
+					reg = <0>;
 					led-cur = /bits/ 8 <0x2f>;
 					max-cur = /bits/ 8 <0x5f>;
 					linux,default-trigger = "heartbeat";
 				};
-				chan1 {
+				chan@1 {
+					reg = <1>;
 					led-cur = /bits/ 8 <0x2f>;
 					max-cur = /bits/ 8 <0x5f>;
 				};
-				chan2 {
+				chan@2 {
+					reg = <2>;
 					led-cur = /bits/ 8 <0x2f>;
 					max-cur = /bits/ 8 <0x5f>;
 				};
@@ -75,15 +80,20 @@
 				reg = <0x34>;
 				label = "lp5521_sec";
 				clock-mode = /bits/ 8 <2>;
-				chan0 {
+				#address-cells = <1>;
+				#size-cells = <0>;
+				chan@0 {
+					reg = <0>;
 					led-cur = /bits/ 8 <0x2f>;
 					max-cur = /bits/ 8 <0x5f>;
 				};
-				chan1 {
+				chan@1 {
+					reg = <1>;
 					led-cur = /bits/ 8 <0x2f>;
 					max-cur = /bits/ 8 <0x5f>;
 				};
-				chan2 {
+				chan@2 {
+					reg = <2>;
 					led-cur = /bits/ 8 <0x2f>;
 					max-cur = /bits/ 8 <0x5f>;
 				};
Signature · 1 line
2.22.0.214.g8dca754b1e
author
#7 lore raw

PATCH v10 5/16 dt: bindings: lp50xx: Introduce the lp50xx family of RGB drivers

In reply to Dan Murphy

Introduce the bindings for the Texas Instruments LP5036, LP5030, LP5024, LP5018, LP5012 and LP5009 RGB LED device driver. The LP5036/30/24/18/12/9 can control RGB LEDs individually or as part of a control bank group. These devices have the ability to adjust the mixing control for the RGB LEDs to obtain different colors independent of the overall brightness of the LED grouping.

Datasheet:
http://www.ti.com/lit/ds/symlink/lp5012.pdf
http://www.ti.com/lit/ds/symlink/lp5024.pdf
http://www.ti.com/lit/ds/symlink/lp5036.pdf

---
 .../devicetree/bindings/leds/leds-lp50xx.txt  | 148 ++++++++++++++++++
 1 file changed, 148 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/leds/leds-lp50xx.txt
Documentation/devicetree/bindings/leds/leds-lp50xx.txt new file +148 -0
new file mode 100644
index 000000000000..8a0a21f1056c
@@ -0,0 +1,148 @@
+* Texas Instruments - LP5009/12/18/24/30/36 RGB LED driver
+
+The LP50XX 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 the number of supported RGB modules.
+
+Required parent properties:
+	- compatible:
+		"ti,lp5009"
+		"ti,lp5012"
+		"ti,lp5018"
+		"ti,lp5024"
+		"ti,lp5030"
+		"ti,lp5036"
+	- reg :  I2C slave address
+		lp5009/12 - 0x14, 0x15, 0x16, 0x17
+		lp5018/24 - 0x28, 0x29, 0x2a, 0x2b
+		lp5030/36 - 0x30, 0x31, 0x32, 0x33
+	- #address-cells : 1
+	- #size-cells : 0
+
+Optional parent properties:
+	- enable-gpios : gpio pin to enable/disable the device.
+	- vled-supply : LED supply
+
+Required child properties:
+	- #address-cells : 1
+	- #size-cells : 0
+	- reg : This is the LED module number.
+	- color : Must be LED_COLOR_ID_MULTI
+	- function : see Documentation/devicetree/bindings/leds/common.txt
+
+Required child properties only is LED modules will be banked:
+	- ti,led-bank : This property denotes the LED module numbers that will
+			be controlled as a single RGB cluster.  Each LED module
+			number will be controlled by a single LED class instance.
+			There can only be one instance of the ti,led-bank
+			property for each device node.
+
+Required grandchildren properties:
+	- reg : A single entry denoting the LED output that controls
+		the monochrome LED.
+	- color : see Documentation/devicetree/bindings/leds/common.txt
+	- led-sources : see Documentation/devicetree/bindings/leds/common.txt
+
+The LED outputs associated with the LED modules are defined in Table 1 of the
+corresponding data sheets.
+
+LP5009 - 3 Total RGB cluster LED outputs 0-2
+LP5012 - 4 Total RGB cluster LED outputs 0-3
+LP5018 - 6 Total RGB cluster LED outputs 0-5
+LP5024 - 8 Total RGB cluster LED outputs 0-7
+LP5030 - 10 Total RGB cluster LED outputs 0-9
+LP5036 - 12 Total RGB cluster LED outputs 0-11
+
+Optional child properties:
+	- label : see Documentation/devicetree/bindings/leds/common.txt
+	- linux,default-trigger :
+	   see Documentation/devicetree/bindings/leds/common.txt
+
+Examples:
+led-controller@29 {
+	#address-cells = <1>;
+	#size-cells = <0>;
+	compatible = "ti,lp5024";
+	reg = <0x29>;
+	enable-gpios = <&gpio1 28 GPIO_ACTIVE_HIGH>;
+	vled-supply = <&vmmcsd_fixed>;
+
+	multi-led@1 {
+		#address-cells = <1>;
+		#size-cells = <0>;
+		reg = <1>;
+		color = <LED_COLOR_ID_MULTI>;
+		function = LED_FUNCTION_STATUS;
+
+		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>;
+		};
+	};
+
+	multi-led@2 {
+		#address-cells = <1>;
+		#size-cells = <0>;
+		reg = <2>;
+		color = <LED_COLOR_ID_MULTI>;
+		function = LED_FUNCTION_STANDBY;
+		ti,led-bank = <2 3 5>;
+
+		led@6 {
+			reg = <0x6>;
+			color = <LED_COLOR_ID_RED>;
+			led-sources = <6 9 15>;
+		};
+
+		led@7 {
+			reg = <0x7>;
+			color = <LED_COLOR_ID_GREEN>;
+			led-sources = <7 10 16>;
+		};
+
+		led@8 {
+			reg = <0x8>;
+			color = <LED_COLOR_ID_BLUE>;
+			led-sources = <8 11 17>;
+		};
+	};
+
+	multi-led@4 {
+		#address-cells = <1>;
+		#size-cells = <0>;
+		reg = <4>;
+		color = <LED_COLOR_ID_MULTI>;
+		function = LED_FUNCTION_ACTIVITY;
+
+		led@12 {
+			reg = <12>;
+			color = <LED_COLOR_ID_RED>;
+		};
+
+		led@13 {
+			reg = <13>;
+			color = <LED_COLOR_ID_GREEN>;
+		};
+
+		led@14 {
+			reg = <14>;
+			color = <LED_COLOR_ID_BLUE>;
+		};
+	};
+};
+
+For more product information please see the link below:
+http://www.ti.com/lit/ds/symlink/lp5012.pdf
+http://www.ti.com/lit/ds/symlink/lp5024.pdf
+http://www.ti.com/lit/ds/symlink/lp5036.pdf
Signature · 1 line
2.22.0.214.g8dca754b1e

Dan Murphy

author
#0 lore raw

v10 cover Multicolor Framework

Hello

I have updated the code per v9 review comments
https://lore.kernel.org/patchwork/project/lkml/list/?series=411824

Some notable changes:

MC framework 4/16
- Added a color structure for device drivers to use to associate color IDs with brightness values
- Name of structure may need some work but this is for proof of concept.
- Added back in the devm_* APIs
- Inlined function led_classdev_multicolor_register

LP55xx
- Fixed binding doc to add "@" to nodes [8/16]
- Fixed associated DT file to add the "@" to each node [9,10,11/16]
- Separate the LP5523 code changes from the LP55xx common code change
- Added channel to color ID mapping for LP55xx [12/16]

LP5523
- Separated out this code from LP55xx

LP5521
- New patch adding multicolor framework support for this device

Dan

Dan Murphy (16):
dt: bindings: Add multicolor class dt bindings documention
dt-bindings: leds: Add multicolor ID to the color ID list
leds: Add multicolor ID to the color ID list
leds: multicolor: Introduce a multicolor class definition
dt: bindings: lp50xx: Introduce the lp50xx family of RGB drivers
leds: lp50xx: Add the LP50XX family of the RGB LED driver
dt: bindings: lp55xx: Be consistent in the document with LED acronym
dt: bindings: lp55xx: Update binding for Multicolor Framework
ARM: dts: n900: Add reg property to the LP5523 channel node
ARM: dts: imx6dl-yapp4: Add reg property to the lp5562 channel node
ARM: dts: ste-href: Add reg property to the LP5521 channel nodes
leds: lp55xx: Add multicolor framework support to lp55xx
leds: lp5523: Update the lp5523 code to add intensity function
leds: lp5521: Add multicolor framework intensity support
leds: lp55xx: Fix checkpatch file permissions issues
leds: lp5523: Fix checkpatch issues in the code

 .../ABI/testing/sysfs-class-led-multicolor    |  35 +
 .../bindings/leds/leds-class-multicolor.txt   |  98 +++
 .../devicetree/bindings/leds/leds-lp50xx.txt  | 148 ++++
 .../devicetree/bindings/leds/leds-lp55xx.txt  | 155 +++-
 Documentation/leds/index.rst                  |   1 +
 Documentation/leds/leds-class-multicolor.rst  |  96 +++
 arch/arm/boot/dts/imx6dl-yapp4-common.dtsi    |  14 +-
 arch/arm/boot/dts/omap3-n900.dts              |  29 +-
 arch/arm/boot/dts/ste-href.dtsi               |  22 +-
 drivers/leds/Kconfig                          |  22 +
 drivers/leds/Makefile                         |   2 +
 drivers/leds/led-class-multicolor.c           | 268 ++++++
 drivers/leds/led-core.c                       |   1 +
 drivers/leds/leds-lp50xx.c                    | 784 ++++++++++++++++++
 drivers/leds/leds-lp5521.c                    |  14 +
 drivers/leds/leds-lp5523.c                    |  33 +-
 drivers/leds/leds-lp55xx-common.c             | 191 ++++-
 drivers/leds/leds-lp55xx-common.h             |  11 +
 include/dt-bindings/leds/common.h             |   3 +-
 include/linux/led-class-multicolor.h          |  88 ++
 include/linux/platform_data/leds-lp55xx.h     |   6 +
 21 files changed, 1928 insertions(+), 93 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-class-led-multicolor
 create mode 100644 Documentation/devicetree/bindings/leds/leds-class-multicolor.txt
 create mode 100644 Documentation/devicetree/bindings/leds/leds-lp50xx.txt
 create mode 100644 Documentation/leds/leds-class-multicolor.rst
 create mode 100644 drivers/leds/led-class-multicolor.c
 create mode 100644 drivers/leds/leds-lp50xx.c
 create mode 100644 include/linux/led-class-multicolor.h
Signature · 1 line
2.22.0.214.g8dca754b1e
author
#2 lore raw

PATCH v10 2/16 dt-bindings: leds: Add multicolor ID to the color ID list

Add a new color ID that is declared as MULTICOLOR as with the multicolor framework declaring a definitive color is not accurate as the node can contain multiple colors.

---
 include/dt-bindings/leds/common.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/dt-bindings/leds/common.h +2 -1
index 9e1256a7c1bf..7006d15f71e8 100644
@@ -29,7 +29,8 @@
 #define LED_COLOR_ID_VIOLET	5
 #define LED_COLOR_ID_YELLOW	6
 #define LED_COLOR_ID_IR		7
-#define LED_COLOR_ID_MAX	8
+#define LED_COLOR_ID_MULTI	8
+#define LED_COLOR_ID_MAX	9
 
 /* Standard LED functions */
 #define LED_FUNCTION_ACTIVITY "activity"
Signature · 1 line
2.22.0.214.g8dca754b1e
#9 lore raw

Re: [PATCH v10 06/16] leds: lp50xx: Add the LP50XX family of the RGB LED driver

In reply to Dan Murphy
I love your patch! Yet something to improve:

Hi Dan,

I love your patch! Yet something to improve:

[auto build test ERROR on j.anaszewski-leds/for-next]
[cannot apply to v5.4-rc1 next-20191001]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Dan-Murphy/Multicolor-Framework/20191002-062337
base:   https://git.kernel.org/pub/scm/linux/kernel/git/j.anaszewski/linux-leds.git for-next
config: mips-allmodconfig (attached as .config)
compiler: mips-linux-gcc (GCC) 7.4.0

reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.4.0 make.cross ARCH=mips

If you fix the issue, kindly add following tag

All errors (new ones prefixed by >>):

>> drivers/leds/leds-lp50xx.c:358:27: error: initializer element is not constant
      .lp50xx_regmap_config = lp5012_regmap_config,
                              ^~~~~~~~~~~~~~~~~~~~
   drivers/leds/leds-lp50xx.c:358:27: note: (near initialization for 'lp50xx_chip_info_tbl[0].lp50xx_regmap_config')
   drivers/leds/leds-lp50xx.c:368:27: error: initializer element is not constant
      .lp50xx_regmap_config = lp5012_regmap_config,
                              ^~~~~~~~~~~~~~~~~~~~
   drivers/leds/leds-lp50xx.c:368:27: note: (near initialization for 'lp50xx_chip_info_tbl[1].lp50xx_regmap_config')
   drivers/leds/leds-lp50xx.c:378:27: error: initializer element is not constant
      .lp50xx_regmap_config = lp5024_regmap_config,
                              ^~~~~~~~~~~~~~~~~~~~
   drivers/leds/leds-lp50xx.c:378:27: note: (near initialization for 'lp50xx_chip_info_tbl[2].lp50xx_regmap_config')
   drivers/leds/leds-lp50xx.c:388:27: error: initializer element is not constant
      .lp50xx_regmap_config = lp5024_regmap_config,
                              ^~~~~~~~~~~~~~~~~~~~
   drivers/leds/leds-lp50xx.c:388:27: note: (near initialization for 'lp50xx_chip_info_tbl[3].lp50xx_regmap_config')
   drivers/leds/leds-lp50xx.c:398:27: error: initializer element is not constant
      .lp50xx_regmap_config = lp5036_regmap_config,
                              ^~~~~~~~~~~~~~~~~~~~
   drivers/leds/leds-lp50xx.c:398:27: note: (near initialization for 'lp50xx_chip_info_tbl[4].lp50xx_regmap_config')
   drivers/leds/leds-lp50xx.c:408:27: error: initializer element is not constant
      .lp50xx_regmap_config = lp5036_regmap_config,
                              ^~~~~~~~~~~~~~~~~~~~

drivers/leds/leds-lp50xx.c:408:27: note: (near initialization for 'lp50xx_chip_info_tbl[5].lp50xx_regmap_config')

vim +358 drivers/leds/leds-lp50xx.c

348
349 static const struct lp50xx_chip_info lp50xx_chip_info_tbl[] = {
350 [LP5009] = {
351 .model_id = LP5009,
352 .num_leds = LP5009_MAX_LEDS,
353 .led_brightness0_reg = LP5012_LED0_BRT,
354 .mix_out0_reg = LP5012_OUT0_CLR,
355 .bank_brt_reg = LP5012_BNK_BRT,
356 .bank_mix_reg = LP5012_BNKA_CLR,
357 .reset_reg = LP5012_RESET,

 > 358			.lp50xx_regmap_config = lp5012_regmap_config,

359 },
360 [LP5012] = {
361 .model_id = LP5012,
362 .num_leds = LP5012_MAX_LEDS,
363 .led_brightness0_reg = LP5012_LED0_BRT,
364 .mix_out0_reg = LP5012_OUT0_CLR,
365 .bank_brt_reg = LP5012_BNK_BRT,
366 .bank_mix_reg = LP5012_BNKA_CLR,
367 .reset_reg = LP5012_RESET,
368 .lp50xx_regmap_config = lp5012_regmap_config,
369 },
370 [LP5018] = {
371 .model_id = LP5018,
372 .num_leds = LP5018_MAX_LEDS,
373 .led_brightness0_reg = LP5024_LED0_BRT,
374 .mix_out0_reg = LP5024_OUT0_CLR,
375 .bank_brt_reg = LP5024_BNK_BRT,
376 .bank_mix_reg = LP5024_BNKA_CLR,
377 .reset_reg = LP5024_RESET,
378 .lp50xx_regmap_config = lp5024_regmap_config,
379 },
380 [LP5024] = {
381 .model_id = LP5024,
382 .num_leds = LP5024_MAX_LEDS,
383 .led_brightness0_reg = LP5024_LED0_BRT,
384 .mix_out0_reg = LP5024_OUT0_CLR,
385 .bank_brt_reg = LP5024_BNK_BRT,
386 .bank_mix_reg = LP5024_BNKA_CLR,
387 .reset_reg = LP5024_RESET,
388 .lp50xx_regmap_config = lp5024_regmap_config,
389 },
390 [LP5030] = {
391 .model_id = LP5030,
392 .num_leds = LP5030_MAX_LEDS,
393 .led_brightness0_reg = LP5036_LED0_BRT,
394 .mix_out0_reg = LP5036_OUT0_CLR,
395 .bank_brt_reg = LP5036_BNK_BRT,
396 .bank_mix_reg = LP5036_BNKA_CLR,
397 .reset_reg = LP5036_RESET,
398 .lp50xx_regmap_config = lp5036_regmap_config,
399 },
400 [LP5036] = {
401 .model_id = LP5036,
402 .num_leds = LP5036_MAX_LEDS,
403 .led_brightness0_reg = LP5036_LED0_BRT,
404 .mix_out0_reg = LP5036_OUT0_CLR,
405 .bank_brt_reg = LP5036_BNK_BRT,
406 .bank_mix_reg = LP5036_BNKA_CLR,
407 .reset_reg = LP5036_RESET,
408 .lp50xx_regmap_config = lp5036_regmap_config,
409 },
410 };
411

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#19 lore raw

Re: [PATCH v10 12/16] leds: lp55xx: Add multicolor framework support to lp55xx

In reply to Dan Murphy
I love your patch! Yet something to improve:

Hi Dan,

I love your patch! Yet something to improve:

[auto build test ERROR on j.anaszewski-leds/for-next]
[cannot apply to v5.4-rc1 next-20191001]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Dan-Murphy/Multicolor-Framework/20191002-062337
base:   https://git.kernel.org/pub/scm/linux/kernel/git/j.anaszewski/linux-leds.git for-next
config: x86_64-randconfig-f004-201939 (attached as .config)
compiler: gcc-7 (Debian 7.4.0-13) 7.4.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

If you fix the issue, kindly add following tag

All errors (new ones prefixed by >>):

ld: drivers/leds/leds-lp55xx-common.o: in function `lp55xx_set_brightness':

>> drivers/leds/leds-lp55xx-common.c:158: undefined reference to `led_mc_calc_brightness'
   ld: drivers/leds/leds-lp55xx-common.o: in function `led_classdev_multicolor_register':
>> include/linux/led-class-multicolor.h:64: undefined reference to `led_classdev_multicolor_register_ext'

vim +158 drivers/leds/leds-lp55xx-common.c

147
148 static int lp55xx_set_brightness(struct led_classdev *cdev,
149 enum led_brightness brightness)
150 {
151 struct lp55xx_led *led = cdev_to_lp55xx_led(cdev);
152 struct lp55xx_device_config *cfg = led->chip->cfg;
153 int channel_num;
154 int ret;
155 int i;
156
157 if (led->mc_cdev.num_leds > 1) {

 > 158			led_mc_calc_brightness(&led->mc_cdev, brightness,

159 &color_component[0]);
160
161 for (i = 0; i < led->mc_cdev.num_leds; i++) {
162 channel_num = lp55xx_get_channel(led,
163 color_component[i].color_id);
164 if (channel_num < 0)
165 return channel_num;
166
167 ret = cfg->color_intensity_fn(led, channel_num,
168 color_component[i].brightness);
169 if (ret)
170 return ret;
171 }
172 } else {
173 led->brightness = (u8)brightness;
174 ret = cfg->brightness_fn(led);
175 }
176
177 return ret;
178 }
179

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#20 lore raw

Re: [PATCH v10 12/16] leds: lp55xx: Add multicolor framework support to lp55xx

In reply to Dan Murphy
I love your patch! Yet something to improve:

Hi Dan,

I love your patch! Yet something to improve:

[auto build test ERROR on j.anaszewski-leds/for-next]
[cannot apply to v5.4-rc1 next-20191001]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Dan-Murphy/Multicolor-Framework/20191002-062337
base:   https://git.kernel.org/pub/scm/linux/kernel/git/j.anaszewski/linux-leds.git for-next
config: x86_64-rhel (attached as .config)
compiler: gcc-7 (Debian 7.4.0-13) 7.4.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

If you fix the issue, kindly add following tag

All errors (new ones prefixed by >>):

>> ERROR: "led_classdev_multicolor_register_ext" [drivers/leds/leds-lp55xx-common.ko] undefined!
>> ERROR: "led_mc_calc_brightness" [drivers/leds/leds-lp55xx-common.ko] undefined!

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

author
#28 lore raw
In reply to Dan Murphy

Hello

Quoted 4 lines · Dan Murphy

Hello

I have updated the code per v9 review comments
https://lore.kernel.org/patchwork/project/lkml/list/?series=411824

I have a v11 version ready to go would like to include any v10 comments

So v11 changes include

- Adding inline MC framework functions for devices that do not have a direct dependency on the MC framework (ie LP55xx)

- Update and fixed the devm_* MC framework functions (fixed the struct in match and added the devm_*_ext functions)

- Removed the hard dependency on the MC framework in the Kconfig for the LP55xx_common code.

Dan

Quoted 71 lines

Some notable changes:

MC framework 4/16
- Added a color structure for device drivers to use to associate color IDs with brightness values
- Name of structure may need some work but this is for proof of concept.
- Added back in the devm_* APIs
- Inlined function led_classdev_multicolor_register

LP55xx
- Fixed binding doc to add "@" to nodes [8/16]
- Fixed associated DT file to add the "@" to each node [9,10,11/16]
- Separate the LP5523 code changes from the LP55xx common code change
- Added channel to color ID mapping for LP55xx [12/16]

LP5523
- Separated out this code from LP55xx

LP5521
- New patch adding multicolor framework support for this device

Dan

Dan Murphy (16):
dt: bindings: Add multicolor class dt bindings documention
dt-bindings: leds: Add multicolor ID to the color ID list
leds: Add multicolor ID to the color ID list
leds: multicolor: Introduce a multicolor class definition
dt: bindings: lp50xx: Introduce the lp50xx family of RGB drivers
leds: lp50xx: Add the LP50XX family of the RGB LED driver
dt: bindings: lp55xx: Be consistent in the document with LED acronym
dt: bindings: lp55xx: Update binding for Multicolor Framework
ARM: dts: n900: Add reg property to the LP5523 channel node
ARM: dts: imx6dl-yapp4: Add reg property to the lp5562 channel node
ARM: dts: ste-href: Add reg property to the LP5521 channel nodes
leds: lp55xx: Add multicolor framework support to lp55xx
leds: lp5523: Update the lp5523 code to add intensity function
leds: lp5521: Add multicolor framework intensity support
leds: lp55xx: Fix checkpatch file permissions issues
leds: lp5523: Fix checkpatch issues in the code

  .../ABI/testing/sysfs-class-led-multicolor    |  35 +
  .../bindings/leds/leds-class-multicolor.txt   |  98 +++
  .../devicetree/bindings/leds/leds-lp50xx.txt  | 148 ++++
  .../devicetree/bindings/leds/leds-lp55xx.txt  | 155 +++-
  Documentation/leds/index.rst                  |   1 +
  Documentation/leds/leds-class-multicolor.rst  |  96 +++
  arch/arm/boot/dts/imx6dl-yapp4-common.dtsi    |  14 +-
  arch/arm/boot/dts/omap3-n900.dts              |  29 +-
  arch/arm/boot/dts/ste-href.dtsi               |  22 +-
  drivers/leds/Kconfig                          |  22 +
  drivers/leds/Makefile                         |   2 +
  drivers/leds/led-class-multicolor.c           | 268 ++++++
  drivers/leds/led-core.c                       |   1 +
  drivers/leds/leds-lp50xx.c                    | 784 ++++++++++++++++++
  drivers/leds/leds-lp5521.c                    |  14 +
  drivers/leds/leds-lp5523.c                    |  33 +-
  drivers/leds/leds-lp55xx-common.c             | 191 ++++-
  drivers/leds/leds-lp55xx-common.h             |  11 +
  include/dt-bindings/leds/common.h             |   3 +-
  include/linux/led-class-multicolor.h          |  88 ++
  include/linux/platform_data/leds-lp55xx.h     |   6 +
  21 files changed, 1928 insertions(+), 93 deletions(-)

create mode 100644 Documentation/ABI/testing/sysfs-class-led-multicolor create mode 100644 Documentation/devicetree/bindings/leds/leds-class-multicolor.txt create mode 100644 Documentation/devicetree/bindings/leds/leds-lp50xx.txt create mode 100644 Documentation/leds/leds-class-multicolor.rst create mode 100644 drivers/leds/led-class-multicolor.c
create mode 100644 drivers/leds/leds-lp50xx.c
create mode 100644 include/linux/led-class-multicolor.h

#17 lore raw

Re: [PATCH v10 11/16] ARM: dts: ste-href: Add reg property to the LP5521 channel nodes

In reply to Dan Murphy
Quoted 8 lines · Dan Murphy

Add the reg property to each channel node. This update is to accomodate the multicolor framework. In addition to the accomodation this allows the LEDs to be placed on any channel and allow designs to skip channels as opposed to requiring sequential order.

CC Linus Walleij <[email protected]>

OK I took out the old patch I applied.

Tell me when you feel I should apply this, or if you want some ACK to take it through another tree.

Yours,
Linus Walleij

#5 lore raw

Re: [PATCH v10 04/16] leds: multicolor: Introduce a multicolor class definition

In reply to Dan Murphy

Dan,

Thank you for the update.

Quoted 112 lines · Dan Murphy

Introduce a multicolor class that groups colored LEDs within a LED node.

The multi color class groups monochrome LEDs and allows controlling two aspects of the final combined color: hue and lightness. The former is controlled via <color>_intensity files and the latter is controlled via brightness file.

---
 .../ABI/testing/sysfs-class-led-multicolor    |  35 +++
 Documentation/leds/index.rst                  |   1 +
 Documentation/leds/leds-class-multicolor.rst  |  96 +++++++
 drivers/leds/Kconfig                          |  10 +
 drivers/leds/Makefile                         |   1 +
 drivers/leds/led-class-multicolor.c           | 268 ++++++++++++++++++
 include/linux/led-class-multicolor.h          |  88 ++++++
 7 files changed, 499 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-class-led-multicolor
 create mode 100644 Documentation/leds/leds-class-multicolor.rst
 create mode 100644 drivers/leds/led-class-multicolor.c
 create mode 100644 include/linux/led-class-multicolor.h
Documentation/ABI/testing/sysfs-class-led-multicolor new file +35 -0
new file mode 100644
index 000000000000..65cb43de26e6
@@ -0,0 +1,35 @@
+What:		/sys/class/leds/<led>/brightness
+Date:		Sept 2019
+KernelVersion:	5.5
+Contact:	Dan Murphy <[email protected]>
+Description:	read/write
+		Writing to this file will update all LEDs within the group to a
+		calculated percentage of what each color LED intensity is set
+		to. The percentage is calculated via the equation below:
+
+		led_brightness = brightness * <color>_intensity/<color>_max_intensity
+
+		For additional details please refer to
+		Documentation/leds/leds-class-multicolor.rst.
+
+		The value of the color is from 0 to
+		/sys/class/leds/<led>/max_brightness.
+
+What:		/sys/class/leds/<led>/colors/<color>_intensity
+Date:		Sept 2019
+KernelVersion:	5.5
+Contact:	Dan Murphy <[email protected]>
+Description:	read/write
+		The <color>_intensity file is created based on the color
+		defined by the registrar of the class.
+		There is one file per color presented.
+
+		The value of the color is from 0 to
+		/sys/class/leds/<led>/colors/<color>_max_intensity.
+
+What:		/sys/class/leds/<led>/colors/<color>_max_intensity
+Date:		Sept 2019
+KernelVersion:	5.5
+Contact:	Dan Murphy <[email protected]>
+Description:	read only
+		Maximum intensity level for the LED color.
Documentation/leds/index.rst +1 -0
index 060f4e485897..bc70c6aa7138 100644
@@ -9,6 +9,7 @@ LEDs
 
    leds-class
    leds-class-flash
+   leds-class-multicolor
    ledtrig-oneshot
    ledtrig-transient
    ledtrig-usbport
Documentation/leds/leds-class-multicolor.rst new file +30 -0
new file mode 100644
index 000000000000..87a1588d7619
@@ -0,0 +1,96 @@
+====================================
+Multi Color LED handling under Linux
+====================================
+
+Description
+===========
+The multi color class groups monochrome LEDs and allows controlling two
+aspects of the final combined color: hue and lightness. The former is
+controlled via <color>_intensity files and the latter is controlled
+via brightness file.
+
+For more details on hue and lightness notions please refer to
+https://en.wikipedia.org/wiki/CIECAM02.
+
+Note that intensity files only cache the written value and the actual
+change of hardware state occurs upon writing brightness file. This
+allows for changing many factors of the perceived color in a virtually
+unnoticeable way for the human observer.
+
+Multicolor Class Control
+========================
+The multicolor class presents the LED groups under a directory called "colors".
+This directory is a child under the LED parent node created by the led_class
+framework.  The led_class framework is documented in led-class.rst within this
+documentation directory.
+
+Each colored LED will have two files created under the colors directory
+<color>_intensity and <color>_max_intensity. These files will contain
+one of LED_COLOR_ID_* definitions from the header
+include/dt-bindings/leds/common.h.

Documentation/leds/leds-class-multicolor.rst line 40

Quoted 10 lines
Documentation/leds/leds-class-multicolor.rst new file +10 -0
+
+Directory Layout Example
+========================
+root:/sys/class/leds/rgb:grouped_leds# ls -lR colors/
+-rw-rwxr-- 1 root root 4096 Jul 7 03:10 red_max_intensity
+--w--wx-w- 1 root root 4096 Jul 7 03:10 red_intensity
+-rw-rwxr-- 1 root root 4096 Jul 7 03:10 green_max_intensity
+--w--wx-w- 1 root root 4096 Jul 7 03:10 green_intensity
+-rw-rwxr-- 1 root root 4096 Jul 7 03:10 blue_max_intensity
+--w--wx-w- 1 root root 4096 Jul 7 03:10 blue_intensity

Now when you have fixed file permissions in LED mc core the 'ls -l' should report them correctly, so this needs to be updated.

[...]

Quoted 18 lines
Documentation/leds/leds-class-multicolor.rst new file +18 -0
+int devm_led_classdev_multicolor_register(struct device *parent,
+					  struct led_classdev_mc *mcled_cdev)
+{
+	struct led_classdev_mc **dr;
+	int ret;
+
+	dr = devres_alloc(devm_led_classdev_multicolor_release,
+			  sizeof(*dr), GFP_KERNEL);
+	if (!dr)
+		return -ENOMEM;
+
+	ret = led_classdev_multicolor_register(parent, mcled_cdev);
+	if (ret) {
+		devres_free(dr);
+		return ret;
+	}
+
+	*dr = mcled_cdev;

Documentation/leds/leds-class-multicolor.rst line 68

Quoted 10 lines
Documentation/leds/leds-class-multicolor.rst new file +10 -0
+	devres_add(parent, dr);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(devm_led_classdev_multicolor_register);
+
+static int devm_led_classdev_multicolor_match(struct device *dev,
+					      void *res, void *data)
+{
+	struct mcled_cdev **p = res;

s/mcled_cdev/led_classdev_mc/

Quoted 7 lines
Documentation/leds/leds-class-multicolor.rst new file +7 -0
+
+	if (WARN_ON(!p || !*p))
+		return 0;
+
+	return *p == data;
+}
+

[...]

Signature · 2 lines
Best regards,
Jacek Anaszewski
#10 lore raw

Re: [PATCH v10 06/16] leds: lp50xx: Add the LP50XX family of the RGB LED driver

In reply to Dan Murphy

Dan,

Quoted 58 lines · Dan Murphy

Introduce the LP5036/30/24/18/12/9 RGB LED driver. The difference in these parts are the number of LED outputs where the:

LP5036 can control 36 LEDs
LP5030 can control 30 LEDs
LP5024 can control 24 LEDs
LP5018 can control 18 LEDs
LP5012 can control 12 LEDs
LP5009 can control 9 LEDs

The device has the ability to group LED output into control banks so that multiple LED banks can be controlled with the same mixing and brightness. Inversely the LEDs can also be controlled independently.

---
 drivers/leds/Kconfig       |  11 +
 drivers/leds/Makefile      |   1 +
 drivers/leds/leds-lp50xx.c | 784 +++++++++++++++++++++++++++++++++++++
 3 files changed, 796 insertions(+)
 create mode 100644 drivers/leds/leds-lp50xx.c
drivers/leds/Kconfig +11 -0
index cfb1ebb6517f..84f60e35c5ee 100644
@@ -363,6 +363,17 @@ config LEDS_LP3952
 	  To compile this driver as a module, choose M here: the
 	  module will be called leds-lp3952.
 
+config LEDS_LP50XX
+	tristate "LED Support for TI LP5036/30/24/18/12/9 LED driver chip"
+	depends on LEDS_CLASS && REGMAP_I2C
+	depends on LEDS_CLASS_MULTI_COLOR
+	help
+	  If you say yes here you get support for the Texas Instruments
+	  LP5036, LP5030, LP5024, LP5018, LP5012 and LP5009 LED driver.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called leds-lp50xx.
+
 config LEDS_LP55XX_COMMON
 	tristate "Common Driver for TI/National LP5521/5523/55231/5562/8501"
 	depends on LEDS_LP5521 || LEDS_LP5523 || LEDS_LP5562 || LEDS_LP8501
drivers/leds/Makefile +1 -0
index 841038cfe35b..7a208a0f7b84 100644
@@ -34,6 +34,7 @@ obj-$(CONFIG_LEDS_GPIO_REGISTER)	+= leds-gpio-register.o
 obj-$(CONFIG_LEDS_GPIO)			+= leds-gpio.o
 obj-$(CONFIG_LEDS_LP3944)		+= leds-lp3944.o
 obj-$(CONFIG_LEDS_LP3952)		+= leds-lp3952.o
+obj-$(CONFIG_LEDS_LP50XX)		+= leds-lp50xx.o
 obj-$(CONFIG_LEDS_LP55XX_COMMON)	+= leds-lp55xx-common.o
 obj-$(CONFIG_LEDS_LP5521)		+= leds-lp5521.o
 obj-$(CONFIG_LEDS_LP5523)		+= leds-lp5523.o
drivers/leds/leds-lp50xx.c +0 -0

[...]

Quoted 26 lines
drivers/leds/leds-lp50xx.c +26 -0
+static int lp50xx_probe_dt(struct lp50xx *priv)
+{
+	u32 led_banks[LP5036_MAX_LED_MODULES];
+	struct fwnode_handle *child = NULL;
+	struct fwnode_handle *led_node = NULL;
+	struct led_init_data init_data;
+	struct lp50xx_led *led;
+	int num_colors;
+	u32 color_id;
+	int led_number;
+	size_t i = 0;
+	int ret;
+
+	priv->enable_gpio = devm_gpiod_get_optional(&priv->client->dev,
+						   "enable", GPIOD_OUT_LOW);
+	if (IS_ERR(priv->enable_gpio)) {
+		ret = PTR_ERR(priv->enable_gpio);
+		dev_err(&priv->client->dev, "Failed to get enable gpio: %d\n",
+			ret);
+		return ret;
+	}
+
+	priv->regulator = devm_regulator_get(&priv->client->dev, "vled");
+	if (IS_ERR(priv->regulator))
+		priv->regulator = NULL;
+

drivers/leds/leds-lp50xx.c line 601

Quoted 10 lines
drivers/leds/leds-lp50xx.c +10 -0
+	device_for_each_child_node(&priv->client->dev, child) {
+		led = &priv->leds[i];
+		if (fwnode_property_present(child, "ti,led-bank")) {
+			ret = fwnode_property_read_u32_array(child,
+							     "ti,led-bank",
+							     NULL, 0);
+			ret = fwnode_property_read_u32_array(child,
+							     "ti,led-bank",
+							     led_banks,
+							     ret);

You could check if bank numbers are within a range.

Quoted 11 lines
drivers/leds/leds-lp50xx.c +11 -0
+			if (ret) {
+				dev_err(&priv->client->dev,
+					"led-bank property is missing\n");
+				fwnode_handle_put(child);
+				goto child_out;
+			}
+
+			priv->num_of_banked_leds = ARRAY_SIZE(led_banks);
+
+			ret = lp50xx_set_banks(priv, led_banks);
+			if (ret) {

drivers/leds/leds-lp50xx.c line 622

Quoted 10 lines
drivers/leds/leds-lp50xx.c +10 -0
+				dev_err(&priv->client->dev,
+					"Cannot setup banked LEDs\n");
+				fwnode_handle_put(child);
+				goto child_out;
+			}
+			led->ctrl_bank_enabled = 1;
+
+		} else {
+			ret = fwnode_property_read_u32(child, "reg",
+					       &led_number);

The same applies to the led_number.

Quoted 9 lines
drivers/leds/leds-lp50xx.c +9 -0
+			if (ret) {
+				dev_err(&priv->client->dev,
+					"led reg property missing\n");
+				fwnode_handle_put(child);
+				goto child_out;
+			}
+
+			led->led_number = led_number;
+		}
Signature · 2 lines
Best regards,
Jacek Anaszewski
#21 lore raw

Re: [PATCH v10 12/16] leds: lp55xx: Add multicolor framework support to lp55xx

In reply to Dan Murphy

Dan,

Quoted 27 lines · Dan Murphy

Add multicolor framework support for the lp55xx family.

---
 drivers/leds/Kconfig                      |   1 +
 drivers/leds/leds-lp55xx-common.c         | 169 +++++++++++++++++++---
 drivers/leds/leds-lp55xx-common.h         |  11 ++
 include/linux/platform_data/leds-lp55xx.h |   6 +
 4 files changed, 163 insertions(+), 24 deletions(-)
drivers/leds/Kconfig +1 -0
index 84f60e35c5ee..dc3d9f2194cd 100644
@@ -377,6 +377,7 @@ config LEDS_LP50XX
 config LEDS_LP55XX_COMMON
 	tristate "Common Driver for TI/National LP5521/5523/55231/5562/8501"
 	depends on LEDS_LP5521 || LEDS_LP5523 || LEDS_LP5562 || LEDS_LP8501
+	depends on LEDS_CLASS_MULTI_COLOR && OF
 	select FW_LOADER
 	select FW_LOADER_USER_HELPER
 	help
drivers/leds/leds-lp55xx-common.c +0 -0
index 44ced02b49f9..5de4f1789a44 100644

drivers/leds/leds-lp55xx-common.c static struct attribute *lp55xx_led_attrs[] = { · line 134

Quoted 4 lines
drivers/leds/leds-lp55xx-common.c +1 -0
@@ -131,14 +131,50 @@ static struct attribute *lp55xx_led_attrs[] = {
 };
 ATTRIBUTE_GROUPS(lp55xx_led);
 
+struct led_mc_color_conversion color_component[LP55XX_MAX_GROUPED_CHAN];

Why is this global? Please move it to lp55xx_set_brightness().

Quoted 17 lines
drivers/leds/leds-lp55xx-common.c +13 -0
+
+static int lp55xx_get_channel(struct lp55xx_led *led, int color_id)
+{
+	int i;
+
+	for (i = 0; i < led->mc_cdev.num_leds; i++) {
+		if (led->channel_color[i] == color_id)
+			return led->grouped_channels[i];
+	}
+
+	return -EINVAL;
+}
+
 static int lp55xx_set_brightness(struct led_classdev *cdev,
 			     enum led_brightness brightness)
 {
 	struct lp55xx_led *led = cdev_to_lp55xx_led(cdev);

drivers/leds/leds-lp55xx-common.c static struct attribute *lp55xx_led_attrs[] = { · line 159

Quoted 10 lines
drivers/leds/leds-lp55xx-common.c +6 -2
 	struct lp55xx_device_config *cfg = led->chip->cfg;
+	int channel_num;
+	int ret;
+	int i;
 
-	led->brightness = (u8)brightness;
-	return cfg->brightness_fn(led);
+	if (led->mc_cdev.num_leds > 1) {
+		led_mc_calc_brightness(&led->mc_cdev, brightness,
+				       &color_component[0]);

s/&color_component[0]/color_component/

drivers/leds/leds-lp55xx-common.c static struct attribute *lp55xx_led_attrs[] = { · line 168

Quoted 9 lines
drivers/leds/leds-lp55xx-common.c +9 -0
+
+		for (i = 0; i < led->mc_cdev.num_leds; i++) {
+			channel_num = lp55xx_get_channel(led,
+						color_component[i].color_id);
+			if (channel_num < 0)
+				return channel_num;
+
+			ret = cfg->color_intensity_fn(led, channel_num,
+						 color_component[i].brightness);

If you passed struct led_mc_color_conversion instead of brightness, then in the color_intensity_fn op you could obtain channel numbers by calling lp55xx_get_channel in a loop. And you could setup the whole cluster in a single call.

Quoted 110 lines
drivers/leds/leds-lp55xx-common.c +55 -14
+			if (ret)
+				return ret;
+		}
+	} else {
+		led->brightness = (u8)brightness;
+		ret = cfg->brightness_fn(led);
+	}
+
+	return ret;
 }
 
 static int lp55xx_init_led(struct lp55xx_led *led,
@@ -147,9 +183,9 @@ static int lp55xx_init_led(struct lp55xx_led *led,
 	struct lp55xx_platform_data *pdata = chip->pdata;
 	struct lp55xx_device_config *cfg = chip->cfg;
 	struct device *dev = &chip->cl->dev;
+	int max_channel = cfg->max_channel;
 	char name[32];
 	int ret;
-	int max_channel = cfg->max_channel;
 
 	if (chan >= max_channel) {
 		dev_err(dev, "invalid channel: %d / %d\n", chan, max_channel);
@@ -159,10 +195,37 @@ static int lp55xx_init_led(struct lp55xx_led *led,
 	if (pdata->led_config[chan].led_current == 0)
 		return 0;
 
+	if (pdata->led_config[chan].name) {
+		led->cdev.name = pdata->led_config[chan].name;
+	} else {
+		snprintf(name, sizeof(name), "%s:channel%d",
+			pdata->label ? : chip->cl->name, chan);
+		led->cdev.name = name;
+	}
+
+	if (pdata->led_config[chan].num_colors > 1) {
+		led->mc_cdev.led_cdev = &led->cdev;
+		led->cdev.brightness_set_blocking = lp55xx_set_brightness;
+		led->cdev.groups = lp55xx_led_groups;
+		led->mc_cdev.num_leds = pdata->led_config[chan].num_colors;
+		led->mc_cdev.available_colors =
+			pdata->led_config[chan].available_colors;
+		memcpy(led->channel_color,
+		       pdata->led_config[chan].channel_color,
+		       sizeof(led->channel_color));
+		memcpy(led->grouped_channels,
+		       pdata->led_config[chan].grouped_channels,
+		       sizeof(led->grouped_channels));
+	} else {
+
+		led->cdev.default_trigger =
+			pdata->led_config[chan].default_trigger;
+		led->cdev.brightness_set_blocking = lp55xx_set_brightness;
+	}	led->cdev.groups = lp55xx_led_groups;
+
 	led->led_current = pdata->led_config[chan].led_current;
 	led->max_current = pdata->led_config[chan].max_current;
 	led->chan_nr = pdata->led_config[chan].chan_nr;
-	led->cdev.default_trigger = pdata->led_config[chan].default_trigger;
 
 	if (led->chan_nr >= max_channel) {
 		dev_err(dev, "Use channel numbers between 0 and %d\n",
@@ -170,18 +233,11 @@ static int lp55xx_init_led(struct lp55xx_led *led,
 		return -EINVAL;
 	}
 
-	led->cdev.brightness_set_blocking = lp55xx_set_brightness;
-	led->cdev.groups = lp55xx_led_groups;
+	if (pdata->led_config[chan].num_colors > 1)
+		ret = led_classdev_multicolor_register(dev, &led->mc_cdev);
+	else
+		ret = led_classdev_register(dev, &led->cdev);
 
-	if (pdata->led_config[chan].name) {
-		led->cdev.name = pdata->led_config[chan].name;
-	} else {
-		snprintf(name, sizeof(name), "%s:channel%d",
-			pdata->label ? : chip->cl->name, chan);
-		led->cdev.name = name;
-	}
-
-	ret = led_classdev_register(dev, &led->cdev);
 	if (ret) {
 		dev_err(dev, "led register err: %d\n", ret);
 		return ret;
@@ -466,7 +522,6 @@ int lp55xx_register_leds(struct lp55xx_led *led, struct lp55xx_chip *chip)
 		dev_err(&chip->cl->dev, "empty brightness configuration\n");
 		return -EINVAL;
 	}
-
 	for (i = 0; i < num_channels; i++) {
 
 		/* do not initialize channels that are not connected */
@@ -538,6 +593,76 @@ void lp55xx_unregister_sysfs(struct lp55xx_chip *chip)
 }
 EXPORT_SYMBOL_GPL(lp55xx_unregister_sysfs);
 
+static int lp5xx_parse_common_child(struct device_node *np,
+				     struct lp55xx_led_config *cfg,
+				     int chan_num, bool is_multicolor)
+{
+	u32 led_number;
+	int ret;
+
+	of_property_read_string(np, "chan-name",
+				&cfg[chan_num].name);
+	of_property_read_u8(np, "led-cur",
+			    &cfg[chan_num].led_current);
+	of_property_read_u8(np, "max-cur",
+			    &cfg[chan_num].max_current);

drivers/leds/leds-lp55xx-common.c void lp55xx_unregister_sysfs(struct lp55xx_chip *chip) · line 618

Quoted 10 lines
drivers/leds/leds-lp55xx-common.c +10 -0
+
+	ret = of_property_read_u32(np, "reg", &led_number);
+	if (ret)
+		return ret;
+
+	if (led_number < 0 || led_number > 6)
+		return -EINVAL;
+
+	if (is_multicolor)
+		cfg[chan_num].grouped_channels[cfg[chan_num].num_colors]

Please pass the index for grouped channels as an argument to this function. Referring here directly to a temporary state of num_colors that is incremented in the loop from which this function is called is ugly IMO.

Quoted 102 lines
drivers/leds/leds-lp55xx-common.c +51 -8
+				= led_number;
+	else
+		cfg[chan_num].chan_nr = led_number;
+
+	return 0;
+}
+
+static int lp5xx_parse_channel_child(struct device_node *np,
+				     struct lp55xx_led_config *cfg,
+				     int child_number)
+{
+	struct device_node *child;
+	int channel_color;
+	u32 color_id;
+	int ret;
+
+	cfg[child_number].default_trigger =
+			of_get_property(np, "linux,default-trigger", NULL);
+
+	ret = of_property_read_u32(np, "color", &channel_color);
+	if (ret)
+		channel_color = ret;
+
+
+	if (channel_color == LED_COLOR_ID_MULTI) {
+		for_each_child_of_node(np, child) {
+			ret = lp5xx_parse_common_child(child, cfg,
+						       child_number, true);
+			if (ret)
+				return ret;
+			ret = of_property_read_u32(child, "color", &color_id);
+			if (ret)
+				return ret;
+
+			cfg[child_number].channel_color[cfg[child_number].num_colors] =
+				color_id;
+			set_bit(color_id, &cfg[child_number].available_colors);
+
+			cfg[child_number].num_colors++;
+		}
+	} else {
+		return lp5xx_parse_common_child(np, cfg, child_number, false);
+	}
+
+	return 0;
+}
+
 struct lp55xx_platform_data *lp55xx_of_populate_pdata(struct device *dev,
 						      struct device_node *np)
 {
@@ -546,6 +671,7 @@ struct lp55xx_platform_data *lp55xx_of_populate_pdata(struct device *dev,
 	struct lp55xx_led_config *cfg;
 	int num_channels;
 	int i = 0;
+	int ret;
 
 	pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
 	if (!pdata)
@@ -565,14 +691,9 @@ struct lp55xx_platform_data *lp55xx_of_populate_pdata(struct device *dev,
 	pdata->num_channels = num_channels;
 
 	for_each_child_of_node(np, child) {
-		cfg[i].chan_nr = i;
-
-		of_property_read_string(child, "chan-name", &cfg[i].name);
-		of_property_read_u8(child, "led-cur", &cfg[i].led_current);
-		of_property_read_u8(child, "max-cur", &cfg[i].max_current);
-		cfg[i].default_trigger =
-			of_get_property(child, "linux,default-trigger", NULL);
-
+		ret = lp5xx_parse_channel_child(child, cfg, i);
+		if (ret)
+			return ERR_PTR(-EINVAL);
 		i++;
 	}
 
drivers/leds/leds-lp55xx-common.h +7 -0
index 783ed5103ce5..5ea2a292a97e 100644
@@ -12,6 +12,10 @@
 #ifndef _LEDS_LP55XX_COMMON_H
 #define _LEDS_LP55XX_COMMON_H
 
+#include <linux/led-class-multicolor.h>
+
+#define LP55XX_MAX_GROUPED_CHAN	4
+
 enum lp55xx_engine_index {
 	LP55XX_ENGINE_INVALID,
 	LP55XX_ENGINE_1,
@@ -109,6 +113,9 @@ struct lp55xx_device_config {
 	/* access brightness register */
 	int (*brightness_fn)(struct lp55xx_led *led);
 
+	/* access specific brightness register */
+	int (*color_intensity_fn)(struct lp55xx_led *led, int chan_num, int brightness);
+
 	/* current setting function */
 	void (*set_led_current) (struct lp55xx_led *led, u8 led_current);
 

drivers/leds/leds-lp55xx-common.h struct lp55xx_chip { · line 172

Quoted 7 lines
drivers/leds/leds-lp55xx-common.h +1 -0
@@ -159,6 +166,7 @@ struct lp55xx_chip {
  * struct lp55xx_led
  * @chan_nr         : Channel number
  * @cdev            : LED class device
+ * @mc_cdev	    : Multi color class device
  * @led_current     : Current setting at each led channel
  * @max_current     : Maximun current at each led channel
  * @brightness      : Brightness value

Documentation for channel_color and grouped_channels is missing.

drivers/leds/leds-lp55xx-common.h struct lp55xx_chip { · line 183

Quoted 10 lines
drivers/leds/leds-lp55xx-common.h +3 -0
@@ -167,9 +175,12 @@ struct lp55xx_chip {
 struct lp55xx_led {
 	int chan_nr;
 	struct led_classdev cdev;
+	struct led_classdev_mc mc_cdev;
 	u8 led_current;
 	u8 max_current;
 	u8 brightness;
+	int channel_color[LP55XX_MAX_GROUPED_CHAN];
+	int grouped_channels[LP55XX_MAX_GROUPED_CHAN];

I propose to create structure:

struct lp55xx_mc_cluster {
	int channel_color;
	int channel_id;
};

and instead of the above two arrays create one

struct lp55xx_mc_cluster mc_cluster[LP55XX_MAX_GROUPED_CHAN];

Quoted 17 lines
drivers/leds/leds-lp55xx-common.h +0 -0
 	struct lp55xx_chip *chip;
 };
 
include/linux/platform_data/leds-lp55xx.h +2 -0
index 96a787100fda..0ac29f537ab6 100644
@@ -12,6 +12,8 @@
 #ifndef _LEDS_LP55XX_H
 #define _LEDS_LP55XX_H
 
+#include <linux/led-class-multicolor.h>
+
 /* Clock configuration */
 #define LP55XX_CLOCK_AUTO	0
 #define LP55XX_CLOCK_INT	1

include/linux/platform_data/leds-lp55xx.h struct lp55xx_led_config { · line 30

Quoted 6 lines
include/linux/platform_data/leds-lp55xx.h +3 -0
@@ -23,6 +25,10 @@ struct lp55xx_led_config {
 	u8 chan_nr;
 	u8 led_current; /* mA x10, 0 if led is not connected */
 	u8 max_current;
+	int num_colors;
+	unsigned long available_colors;
+	u32 channel_color[LED_COLOR_ID_MAX];

channel_color array is redundant if you have available_colors flags.

Quoted 5 lines
include/linux/platform_data/leds-lp55xx.h +1 -0
+	int grouped_channels[LED_COLOR_ID_MAX];
 };
 
 struct lp55xx_predef_pattern {
Signature · 2 lines
Best regards,
Jacek Anaszewski
author
#6 lore raw

Re: [PATCH v10 04/16] leds: multicolor: Introduce a multicolor class definition

In reply to Jacek Anaszewski

Jacek

Thanks for the review

Quoted 122 lines · Jacek Anaszewski

Dan,

Thank you for the update.

Quoted 117 lines · Dan Murphy

Introduce a multicolor class that groups colored LEDs within a LED node.

The multi color class groups monochrome LEDs and allows controlling two aspects of the final combined color: hue and lightness. The former is controlled via <color>_intensity files and the latter is controlled via brightness file.

---
  .../ABI/testing/sysfs-class-led-multicolor    |  35 +++
  Documentation/leds/index.rst                  |   1 +
  Documentation/leds/leds-class-multicolor.rst  |  96 +++++++
  drivers/leds/Kconfig                          |  10 +
  drivers/leds/Makefile                         |   1 +
  drivers/leds/led-class-multicolor.c           | 268 ++++++++++++++++++
  include/linux/led-class-multicolor.h          |  88 ++++++
  7 files changed, 499 insertions(+)

create mode 100644 Documentation/ABI/testing/sysfs-class-led-multicolor create mode 100644 Documentation/leds/leds-class-multicolor.rst create mode 100644 drivers/leds/led-class-multicolor.c create mode 100644 include/linux/led-class-multicolor.h

Documentation/ABI/testing/sysfs-class-led-multicolor new file +35 -0
new file mode 100644
index 000000000000..65cb43de26e6
@@ -0,0 +1,35 @@
+What:		/sys/class/leds/<led>/brightness
+Date:		Sept 2019
+KernelVersion:	5.5
+Contact:	Dan Murphy <[email protected]>
+Description:	read/write
+		Writing to this file will update all LEDs within the group to a
+		calculated percentage of what each color LED intensity is set
+		to. The percentage is calculated via the equation below:
+
+		led_brightness = brightness * <color>_intensity/<color>_max_intensity
+
+		For additional details please refer to
+		Documentation/leds/leds-class-multicolor.rst.
+
+		The value of the color is from 0 to
+		/sys/class/leds/<led>/max_brightness.
+
+What:		/sys/class/leds/<led>/colors/<color>_intensity
+Date:		Sept 2019
+KernelVersion:	5.5
+Contact:	Dan Murphy <[email protected]>
+Description:	read/write
+		The <color>_intensity file is created based on the color
+		defined by the registrar of the class.
+		There is one file per color presented.
+
+		The value of the color is from 0 to
+		/sys/class/leds/<led>/colors/<color>_max_intensity.
+
+What:		/sys/class/leds/<led>/colors/<color>_max_intensity
+Date:		Sept 2019
+KernelVersion:	5.5
+Contact:	Dan Murphy <[email protected]>
+Description:	read only
+		Maximum intensity level for the LED color.
Documentation/leds/index.rst +1 -0
index 060f4e485897..bc70c6aa7138 100644
@@ -9,6 +9,7 @@ LEDs
 
     leds-class
     leds-class-flash
+   leds-class-multicolor
     ledtrig-oneshot
     ledtrig-transient
     ledtrig-usbport
Documentation/leds/leds-class-multicolor.rst new file +35 -0
new file mode 100644
index 000000000000..87a1588d7619
@@ -0,0 +1,96 @@
+====================================
+Multi Color LED handling under Linux
+====================================
+
+Description
+===========
+The multi color class groups monochrome LEDs and allows controlling two
+aspects of the final combined color: hue and lightness. The former is
+controlled via <color>_intensity files and the latter is controlled
+via brightness file.
+
+For more details on hue and lightness notions please refer to
+https://en.wikipedia.org/wiki/CIECAM02.
+
+Note that intensity files only cache the written value and the actual
+change of hardware state occurs upon writing brightness file. This
+allows for changing many factors of the perceived color in a virtually
+unnoticeable way for the human observer.
+
+Multicolor Class Control
+========================
+The multicolor class presents the LED groups under a directory called "colors".
+This directory is a child under the LED parent node created by the led_class
+framework.  The led_class framework is documented in led-class.rst within this
+documentation directory.
+
+Each colored LED will have two files created under the colors directory
+<color>_intensity and <color>_max_intensity. These files will contain
+one of LED_COLOR_ID_* definitions from the header
+include/dt-bindings/leds/common.h.
+
+Directory Layout Example
+========================
+root:/sys/class/leds/rgb:grouped_leds# ls -lR colors/
+-rw-rwxr-- 1 root root 4096 Jul 7 03:10 red_max_intensity
Quoted 8 lines

Documentation/leds/leds-class-multicolor.rst line 40

Quoted 5 lines
Documentation/leds/leds-class-multicolor.rst new file +5 -0
+--w--wx-w- 1 root root 4096 Jul 7 03:10 red_intensity
+-rw-rwxr-- 1 root root 4096 Jul 7 03:10 green_max_intensity
+--w--wx-w- 1 root root 4096 Jul 7 03:10 green_intensity
+-rw-rwxr-- 1 root root 4096 Jul 7 03:10 blue_max_intensity
+--w--wx-w- 1 root root 4096 Jul 7 03:10 blue_intensity

Now when you have fixed file permissions in LED mc core the 'ls -l' should report them correctly, so this needs to be updated.

ACK

Quoted 22 lines

[...]

Quoted 21 lines
Documentation/leds/leds-class-multicolor.rst new file +21 -0
+int devm_led_classdev_multicolor_register(struct device *parent,
+					  struct led_classdev_mc *mcled_cdev)
+{
+	struct led_classdev_mc **dr;
+	int ret;
+
+	dr = devres_alloc(devm_led_classdev_multicolor_release,
+			  sizeof(*dr), GFP_KERNEL);
+	if (!dr)
+		return -ENOMEM;
+
+	ret = led_classdev_multicolor_register(parent, mcled_cdev);
+	if (ret) {
+		devres_free(dr);
+		return ret;
+	}
+
+	*dr = mcled_cdev;
+	devres_add(parent, dr);
+
+	return 0;
Quoted 8 lines

Documentation/leds/leds-class-multicolor.rst

Quoted 7 lines
Documentation/leds/leds-class-multicolor.rst new file +7 -0
+}
+EXPORT_SYMBOL_GPL(devm_led_classdev_multicolor_register);
+
+static int devm_led_classdev_multicolor_match(struct device *dev,
+					      void *res, void *data)
+{
+	struct mcled_cdev **p = res;

s/mcled_cdev/led_classdev_mc/

ACK.  Fixed in v11

Dan

Quoted 8 lines
Quoted 7 lines
Documentation/leds/leds-class-multicolor.rst new file +7 -0
+
+	if (WARN_ON(!p || !*p))
+		return 0;
+
+	return *p == data;
+}
+

[...]

author
#11 lore raw

Re: [PATCH v10 06/16] leds: lp50xx: Add the LP50XX family of the RGB LED driver

In reply to Jacek Anaszewski

Jacek

Quoted 91 lines · Jacek Anaszewski

Dan,

Quoted 58 lines · Dan Murphy

Introduce the LP5036/30/24/18/12/9 RGB LED driver. The difference in these parts are the number of LED outputs where the:

LP5036 can control 36 LEDs
LP5030 can control 30 LEDs
LP5024 can control 24 LEDs
LP5018 can control 18 LEDs
LP5012 can control 12 LEDs
LP5009 can control 9 LEDs

The device has the ability to group LED output into control banks so that multiple LED banks can be controlled with the same mixing and brightness. Inversely the LEDs can also be controlled independently.

---
  drivers/leds/Kconfig       |  11 +
  drivers/leds/Makefile      |   1 +
  drivers/leds/leds-lp50xx.c | 784 +++++++++++++++++++++++++++++++++++++
  3 files changed, 796 insertions(+)

create mode 100644 drivers/leds/leds-lp50xx.c

drivers/leds/Kconfig +11 -0
index cfb1ebb6517f..84f60e35c5ee 100644
@@ -363,6 +363,17 @@ config LEDS_LP3952
  	  To compile this driver as a module, choose M here: the
  	  module will be called leds-lp3952.
 
+config LEDS_LP50XX
+	tristate "LED Support for TI LP5036/30/24/18/12/9 LED driver chip"
+	depends on LEDS_CLASS && REGMAP_I2C
+	depends on LEDS_CLASS_MULTI_COLOR
+	help
+	  If you say yes here you get support for the Texas Instruments
+	  LP5036, LP5030, LP5024, LP5018, LP5012 and LP5009 LED driver.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called leds-lp50xx.
+
  config LEDS_LP55XX_COMMON
  	tristate "Common Driver for TI/National LP5521/5523/55231/5562/8501"
  	depends on LEDS_LP5521 || LEDS_LP5523 || LEDS_LP5562 || LEDS_LP8501
drivers/leds/Makefile +1 -0
index 841038cfe35b..7a208a0f7b84 100644
@@ -34,6 +34,7 @@ obj-$(CONFIG_LEDS_GPIO_REGISTER)	+= leds-gpio-register.o
  obj-$(CONFIG_LEDS_GPIO)			+= leds-gpio.o
  obj-$(CONFIG_LEDS_LP3944)		+= leds-lp3944.o
  obj-$(CONFIG_LEDS_LP3952)		+= leds-lp3952.o
+obj-$(CONFIG_LEDS_LP50XX)		+= leds-lp50xx.o
  obj-$(CONFIG_LEDS_LP55XX_COMMON)	+= leds-lp55xx-common.o
  obj-$(CONFIG_LEDS_LP5521)		+= leds-lp5521.o
  obj-$(CONFIG_LEDS_LP5523)		+= leds-lp5523.o
drivers/leds/leds-lp50xx.c +0 -0

[...]

Quoted 29 lines
drivers/leds/leds-lp50xx.c +29 -0
+static int lp50xx_probe_dt(struct lp50xx *priv)
+{
+	u32 led_banks[LP5036_MAX_LED_MODULES];
+	struct fwnode_handle *child = NULL;
+	struct fwnode_handle *led_node = NULL;
+	struct led_init_data init_data;
+	struct lp50xx_led *led;
+	int num_colors;
+	u32 color_id;
+	int led_number;
+	size_t i = 0;
+	int ret;
+
+	priv->enable_gpio = devm_gpiod_get_optional(&priv->client->dev,
+						   "enable", GPIOD_OUT_LOW);
+	if (IS_ERR(priv->enable_gpio)) {
+		ret = PTR_ERR(priv->enable_gpio);
+		dev_err(&priv->client->dev, "Failed to get enable gpio: %d\n",
+			ret);
+		return ret;
+	}
+
+	priv->regulator = devm_regulator_get(&priv->client->dev, "vled");
+	if (IS_ERR(priv->regulator))
+		priv->regulator = NULL;
+
+	device_for_each_child_node(&priv->client->dev, child) {
+		led = &priv->leds[i];
+		if (fwnode_property_present(child, "ti,led-bank")) {
Quoted 8 lines

drivers/leds/leds-lp50xx.c line 601

Quoted 7 lines
drivers/leds/leds-lp50xx.c +7 -0
+			ret = fwnode_property_read_u32_array(child,
+							     "ti,led-bank",
+							     NULL, 0);
+			ret = fwnode_property_read_u32_array(child,
+							     "ti,led-bank",
+							     led_banks,
+							     ret);

You could check if bank numbers are within a range.

Ack

Quoted 15 lines
Quoted 15 lines
drivers/leds/leds-lp50xx.c +14 -0
+			if (ret) {
+				dev_err(&priv->client->dev,
+					"led-bank property is missing\n");
+				fwnode_handle_put(child);
+				goto child_out;
+			}
+
+			priv->num_of_banked_leds = ARRAY_SIZE(led_banks);
+
+			ret = lp50xx_set_banks(priv, led_banks);
+			if (ret) {
+				dev_err(&priv->client->dev,
+					"Cannot setup banked LEDs\n");
+				fwnode_handle_put(child);
Quoted 8 lines

drivers/leds/leds-lp50xx.c line 622

Quoted 7 lines
drivers/leds/leds-lp50xx.c +7 -0
+				goto child_out;
+			}
+			led->ctrl_bank_enabled = 1;
+
+		} else {
+			ret = fwnode_property_read_u32(child, "reg",
+					       &led_number);

The same applies to the led_number.

NACK to this.  This is checked below.  But I should probably move that check up into the else case.

Dan

Quoted 10 lines
Quoted 10 lines
drivers/leds/leds-lp50xx.c +9 -0
+			if (ret) {
+				dev_err(&priv->client->dev,
+					"led reg property missing\n");
+				fwnode_handle_put(child);
+				goto child_out;
+			}
+
+			led->led_number = led_number;
+		}
author
#22 lore raw

Re: [PATCH v10 12/16] leds: lp55xx: Add multicolor framework support to lp55xx

In reply to Jacek Anaszewski

Jacek

Quoted 33 lines · Jacek Anaszewski

Dan,

Quoted 30 lines · Dan Murphy

Add multicolor framework support for the lp55xx family.

---
  drivers/leds/Kconfig                      |   1 +
  drivers/leds/leds-lp55xx-common.c         | 169 +++++++++++++++++++---
  drivers/leds/leds-lp55xx-common.h         |  11 ++
  include/linux/platform_data/leds-lp55xx.h |   6 +
  4 files changed, 163 insertions(+), 24 deletions(-)
drivers/leds/Kconfig +1 -0
index 84f60e35c5ee..dc3d9f2194cd 100644
@@ -377,6 +377,7 @@ config LEDS_LP50XX
  config LEDS_LP55XX_COMMON
  	tristate "Common Driver for TI/National LP5521/5523/55231/5562/8501"
  	depends on LEDS_LP5521 || LEDS_LP5523 || LEDS_LP5562 || LEDS_LP8501
+	depends on LEDS_CLASS_MULTI_COLOR && OF
  	select FW_LOADER
  	select FW_LOADER_USER_HELPER
  	help
drivers/leds/leds-lp55xx-common.c +0 -0
index 44ced02b49f9..5de4f1789a44 100644
@@ -131,14 +131,50 @@ static struct attribute *lp55xx_led_attrs[] = {
  };
  ATTRIBUTE_GROUPS(lp55xx_led);
 
Quoted 2 lines

drivers/leds/leds-lp55xx-common.c static struct attribute *lp55xx_led_attrs[] = { · line 134

Quoted 1 line
drivers/leds/leds-lp55xx-common.c +1 -0
+struct led_mc_color_conversion color_component[LP55XX_MAX_GROUPED_CHAN];

Why is this global? Please move it to lp55xx_set_brightness().

ACK

Quoted 23 lines
Quoted 23 lines
drivers/leds/leds-lp55xx-common.c +16 -0
+
+static int lp55xx_get_channel(struct lp55xx_led *led, int color_id)
+{
+	int i;
+
+	for (i = 0; i < led->mc_cdev.num_leds; i++) {
+		if (led->channel_color[i] == color_id)
+			return led->grouped_channels[i];
+	}
+
+	return -EINVAL;
+}
+
  static int lp55xx_set_brightness(struct led_classdev *cdev,
  			     enum led_brightness brightness)
  {
  	struct lp55xx_led *led = cdev_to_lp55xx_led(cdev);
  	struct lp55xx_device_config *cfg = led->chip->cfg;
+	int channel_num;
+	int ret;
+	int i;
 
Quoted 6 lines

drivers/leds/leds-lp55xx-common.c static struct attribute *lp55xx_led_attrs[] = { · line 159

Quoted 5 lines
drivers/leds/leds-lp55xx-common.c +3 -2
-	led->brightness = (u8)brightness;
-	return cfg->brightness_fn(led);
+	if (led->mc_cdev.num_leds > 1) {
+		led_mc_calc_brightness(&led->mc_cdev, brightness,
+				       &color_component[0]);

s/&color_component[0]/color_component/

ACK

Quoted 5 lines
Quoted 5 lines
drivers/leds/leds-lp55xx-common.c +5 -0
+
+		for (i = 0; i < led->mc_cdev.num_leds; i++) {
+			channel_num = lp55xx_get_channel(led,
+						color_component[i].color_id);
+			if (channel_num < 0)
Quoted 8 lines

drivers/leds/leds-lp55xx-common.c static struct attribute *lp55xx_led_attrs[] = { · line 168

Quoted 4 lines
drivers/leds/leds-lp55xx-common.c +4 -0
+				return channel_num;
+
+			ret = cfg->color_intensity_fn(led, channel_num,
+						 color_component[i].brightness);

If you passed struct led_mc_color_conversion instead of brightness, then in the color_intensity_fn op you could obtain channel numbers by calling lp55xx_get_channel in a loop. And you could setup the whole cluster in a single call.

Hmm.  How would that be an improvement?  Maybe the answer lies down below in my response and we will not have to get the channel_num as we can make the output part of the mc_color_conversion struct.

As I pointed out in v9 "Beyond that in coding this and thinking about the design it is better to have the lp55xx_common code to do all the heavy lifting and the children to just perform the action on the device itself"

https://lore.kernel.org/linux-leds/[email protected]/T/#u

The children should not have to know if the LED is registered to the LED class, MC Class or Flash class only the common code should know this information.  Just need to keep the child code simple. This is why I pass in the values as opposed to having the child figure it out.

Quoted 116 lines
Quoted 116 lines
drivers/leds/leds-lp55xx-common.c +61 -14
+			if (ret)
+				return ret;
+		}
+	} else {
+		led->brightness = (u8)brightness;
+		ret = cfg->brightness_fn(led);
+	}
+
+	return ret;
  }
 
  static int lp55xx_init_led(struct lp55xx_led *led,
@@ -147,9 +183,9 @@ static int lp55xx_init_led(struct lp55xx_led *led,
  	struct lp55xx_platform_data *pdata = chip->pdata;
  	struct lp55xx_device_config *cfg = chip->cfg;
  	struct device *dev = &chip->cl->dev;
+	int max_channel = cfg->max_channel;
  	char name[32];
  	int ret;
-	int max_channel = cfg->max_channel;
 
  	if (chan >= max_channel) {
  		dev_err(dev, "invalid channel: %d / %d\n", chan, max_channel);
@@ -159,10 +195,37 @@ static int lp55xx_init_led(struct lp55xx_led *led,
  	if (pdata->led_config[chan].led_current == 0)
  		return 0;
 
+	if (pdata->led_config[chan].name) {
+		led->cdev.name = pdata->led_config[chan].name;
+	} else {
+		snprintf(name, sizeof(name), "%s:channel%d",
+			pdata->label ? : chip->cl->name, chan);
+		led->cdev.name = name;
+	}
+
+	if (pdata->led_config[chan].num_colors > 1) {
+		led->mc_cdev.led_cdev = &led->cdev;
+		led->cdev.brightness_set_blocking = lp55xx_set_brightness;
+		led->cdev.groups = lp55xx_led_groups;
+		led->mc_cdev.num_leds = pdata->led_config[chan].num_colors;
+		led->mc_cdev.available_colors =
+			pdata->led_config[chan].available_colors;
+		memcpy(led->channel_color,
+		       pdata->led_config[chan].channel_color,
+		       sizeof(led->channel_color));
+		memcpy(led->grouped_channels,
+		       pdata->led_config[chan].grouped_channels,
+		       sizeof(led->grouped_channels));
+	} else {
+
+		led->cdev.default_trigger =
+			pdata->led_config[chan].default_trigger;
+		led->cdev.brightness_set_blocking = lp55xx_set_brightness;
+	}	led->cdev.groups = lp55xx_led_groups;
+
  	led->led_current = pdata->led_config[chan].led_current;
  	led->max_current = pdata->led_config[chan].max_current;
  	led->chan_nr = pdata->led_config[chan].chan_nr;
-	led->cdev.default_trigger = pdata->led_config[chan].default_trigger;
 
  	if (led->chan_nr >= max_channel) {
  		dev_err(dev, "Use channel numbers between 0 and %d\n",
@@ -170,18 +233,11 @@ static int lp55xx_init_led(struct lp55xx_led *led,
  		return -EINVAL;
  	}
 
-	led->cdev.brightness_set_blocking = lp55xx_set_brightness;
-	led->cdev.groups = lp55xx_led_groups;
+	if (pdata->led_config[chan].num_colors > 1)
+		ret = led_classdev_multicolor_register(dev, &led->mc_cdev);
+	else
+		ret = led_classdev_register(dev, &led->cdev);
 
-	if (pdata->led_config[chan].name) {
-		led->cdev.name = pdata->led_config[chan].name;
-	} else {
-		snprintf(name, sizeof(name), "%s:channel%d",
-			pdata->label ? : chip->cl->name, chan);
-		led->cdev.name = name;
-	}
-
-	ret = led_classdev_register(dev, &led->cdev);
  	if (ret) {
  		dev_err(dev, "led register err: %d\n", ret);
  		return ret;
@@ -466,7 +522,6 @@ int lp55xx_register_leds(struct lp55xx_led *led, struct lp55xx_chip *chip)
  		dev_err(&chip->cl->dev, "empty brightness configuration\n");
  		return -EINVAL;
  	}
-
  	for (i = 0; i < num_channels; i++) {
 
  		/* do not initialize channels that are not connected */
@@ -538,6 +593,76 @@ void lp55xx_unregister_sysfs(struct lp55xx_chip *chip)
  }
  EXPORT_SYMBOL_GPL(lp55xx_unregister_sysfs);
 
+static int lp5xx_parse_common_child(struct device_node *np,
+				     struct lp55xx_led_config *cfg,
+				     int chan_num, bool is_multicolor)
+{
+	u32 led_number;
+	int ret;
+
+	of_property_read_string(np, "chan-name",
+				&cfg[chan_num].name);
+	of_property_read_u8(np, "led-cur",
+			    &cfg[chan_num].led_current);
+	of_property_read_u8(np, "max-cur",
+			    &cfg[chan_num].max_current);
+
+	ret = of_property_read_u32(np, "reg", &led_number);
+	if (ret)
+		return ret;
+
+	if (led_number < 0 || led_number > 6)
Quoted 8 lines

drivers/leds/leds-lp55xx-common.c void lp55xx_unregister_sysfs(struct lp55xx_chip *chip) · line 618

Quoted 4 lines
drivers/leds/leds-lp55xx-common.c +4 -0
+		return -EINVAL;
+
+	if (is_multicolor)
+		cfg[chan_num].grouped_channels[cfg[chan_num].num_colors]

Please pass the index for grouped channels as an argument to this function. Referring here directly to a temporary state of num_colors that is incremented in the loop from which this function is called is ugly IMO.

Ack

Quoted 101 lines
Quoted 101 lines
drivers/leds/leds-lp55xx-common.c +51 -8
+				= led_number;
+	else
+		cfg[chan_num].chan_nr = led_number;
+
+	return 0;
+}
+
+static int lp5xx_parse_channel_child(struct device_node *np,
+				     struct lp55xx_led_config *cfg,
+				     int child_number)
+{
+	struct device_node *child;
+	int channel_color;
+	u32 color_id;
+	int ret;
+
+	cfg[child_number].default_trigger =
+			of_get_property(np, "linux,default-trigger", NULL);
+
+	ret = of_property_read_u32(np, "color", &channel_color);
+	if (ret)
+		channel_color = ret;
+
+
+	if (channel_color == LED_COLOR_ID_MULTI) {
+		for_each_child_of_node(np, child) {
+			ret = lp5xx_parse_common_child(child, cfg,
+						       child_number, true);
+			if (ret)
+				return ret;
+			ret = of_property_read_u32(child, "color", &color_id);
+			if (ret)
+				return ret;
+
+			cfg[child_number].channel_color[cfg[child_number].num_colors] =
+				color_id;
+			set_bit(color_id, &cfg[child_number].available_colors);
+
+			cfg[child_number].num_colors++;
+		}
+	} else {
+		return lp5xx_parse_common_child(np, cfg, child_number, false);
+	}
+
+	return 0;
+}
+
  struct lp55xx_platform_data *lp55xx_of_populate_pdata(struct device *dev,
  						      struct device_node *np)
  {
@@ -546,6 +671,7 @@ struct lp55xx_platform_data *lp55xx_of_populate_pdata(struct device *dev,
  	struct lp55xx_led_config *cfg;
  	int num_channels;
  	int i = 0;
+	int ret;
 
  	pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
  	if (!pdata)
@@ -565,14 +691,9 @@ struct lp55xx_platform_data *lp55xx_of_populate_pdata(struct device *dev,
  	pdata->num_channels = num_channels;
 
  	for_each_child_of_node(np, child) {
-		cfg[i].chan_nr = i;
-
-		of_property_read_string(child, "chan-name", &cfg[i].name);
-		of_property_read_u8(child, "led-cur", &cfg[i].led_current);
-		of_property_read_u8(child, "max-cur", &cfg[i].max_current);
-		cfg[i].default_trigger =
-			of_get_property(child, "linux,default-trigger", NULL);
-
+		ret = lp5xx_parse_channel_child(child, cfg, i);
+		if (ret)
+			return ERR_PTR(-EINVAL);
  		i++;
  	}
 
drivers/leds/leds-lp55xx-common.h +7 -0
index 783ed5103ce5..5ea2a292a97e 100644
@@ -12,6 +12,10 @@
  #ifndef _LEDS_LP55XX_COMMON_H
  #define _LEDS_LP55XX_COMMON_H
 
+#include <linux/led-class-multicolor.h>
+
+#define LP55XX_MAX_GROUPED_CHAN	4
+
  enum lp55xx_engine_index {
  	LP55XX_ENGINE_INVALID,
  	LP55XX_ENGINE_1,
@@ -109,6 +113,9 @@ struct lp55xx_device_config {
  	/* access brightness register */
  	int (*brightness_fn)(struct lp55xx_led *led);
 
+	/* access specific brightness register */
+	int (*color_intensity_fn)(struct lp55xx_led *led, int chan_num, int brightness);
+
  	/* current setting function */
  	void (*set_led_current) (struct lp55xx_led *led, u8 led_current);
 
Quoted 10 lines

drivers/leds/leds-lp55xx-common.h struct lp55xx_chip { · line 172

Quoted 8 lines
drivers/leds/leds-lp55xx-common.h +1 -0
@@ -159,6 +166,7 @@ struct lp55xx_chip {
   * struct lp55xx_led
   * @chan_nr         : Channel number
   * @cdev            : LED class device
+ * @mc_cdev	    : Multi color class device
   * @led_current     : Current setting at each led channel
   * @max_current     : Maximun current at each led channel
   * @brightness      : Brightness value

Documentation for channel_color and grouped_channels is missing.

ACK

Quoted 12 lines

drivers/leds/leds-lp55xx-common.h struct lp55xx_chip { · line 183

Quoted 10 lines
drivers/leds/leds-lp55xx-common.h +3 -0
@@ -167,9 +175,12 @@ struct lp55xx_chip {
  struct lp55xx_led {
  	int chan_nr;
  	struct led_classdev cdev;
+	struct led_classdev_mc mc_cdev;
  	u8 led_current;
  	u8 max_current;
  	u8 brightness;
+	int channel_color[LP55XX_MAX_GROUPED_CHAN];
+	int grouped_channels[LP55XX_MAX_GROUPED_CHAN];

I propose to create structure:

Quoted 8 lines
struct lp55xx_mc_cluster {
	int channel_color;
	int channel_id;
};

and instead of the above two arrays create one

struct lp55xx_mc_cluster mc_cluster[LP55XX_MAX_GROUPED_CHAN];

Maybe we can extend the mc_color_converion struct to add output_num.

Now I did try to do this but the design of the code made it a bit wonky.  I will look at it again.

If the output_num information is contain in a single struct as opposed to having each driver create their own struct.

struct led_mc_color_conversion {
    int color_id;
    int brightness;

    int output_num;

};

struct led_mc_color_conversion mc_cluster[LP55XX_MAX_GROUPED_CHAN];

If other drivers do not need that information then they do not need to populate it

Quoted 12 lines
Quoted 12 lines
drivers/leds/leds-lp55xx-common.h +0 -0
  	struct lp55xx_chip *chip;
  };
 
include/linux/platform_data/leds-lp55xx.h +0 -0
index 96a787100fda..0ac29f537ab6 100644
@@ -12,6 +12,8 @@
  #ifndef _LEDS_LP55XX_H
  #define _LEDS_LP55XX_H
 
Quoted 13 lines

include/linux/platform_data/leds-lp55xx.h struct lp55xx_led_config { · line 30

Quoted 12 lines
include/linux/platform_data/leds-lp55xx.h +5 -0
+#include <linux/led-class-multicolor.h>
+
  /* Clock configuration */
  #define LP55XX_CLOCK_AUTO	0
  #define LP55XX_CLOCK_INT	1
@@ -23,6 +25,10 @@ struct lp55xx_led_config {
  	u8 chan_nr;
  	u8 led_current; /* mA x10, 0 if led is not connected */
  	u8 max_current;
+	int num_colors;
+	unsigned long available_colors;
+	u32 channel_color[LED_COLOR_ID_MAX];

channel_color array is redundant if you have available_colors flags.

I will look this again.

Quoted 5 lines
Quoted 5 lines
include/linux/platform_data/leds-lp55xx.h +1 -0
+	int grouped_channels[LED_COLOR_ID_MAX];
  };
 
  struct lp55xx_predef_pattern {
#23 lore raw

Re: [PATCH v10 12/16] leds: lp55xx: Add multicolor framework support to lp55xx

Dan,

Quoted 88 lines · Dan Murphy

Jacek

Quoted 30 lines · Jacek Anaszewski

Dan,

Quoted 27 lines · Dan Murphy

Add multicolor framework support for the lp55xx family.

---
  drivers/leds/Kconfig                      |   1 + drivers/leds/leds-lp55xx-common.c         | 169 +++++++++++++++++++--- drivers/leds/leds-lp55xx-common.h         |  11 ++ include/linux/platform_data/leds-lp55xx.h |   6 +

  4 files changed, 163 insertions(+), 24 deletions(-)
drivers/leds/Kconfig +0 -0
index 84f60e35c5ee..dc3d9f2194cd 100644
@@ -377,6 +377,7 @@ config LEDS_LP50XX

  config LEDS_LP55XX_COMMON
      tristate "Common Driver for TI/National LP5521/5523/55231/5562/8501"
      depends on LEDS_LP5521 || LEDS_LP5523 || LEDS_LP5562 || LEDS_LP8501
+    depends on LEDS_CLASS_MULTI_COLOR && OF
      select FW_LOADER
      select FW_LOADER_USER_HELPER
      help

drivers/leds/leds-lp55xx-common.c +0 -0
index 44ced02b49f9..5de4f1789a44 100644
Quoted 8 lines
Quoted 7 lines
drivers/leds/leds-lp55xx-common.c +0 -0
@@ -131,14 +131,50 @@ static struct attribute *lp55xx_led_attrs[] = {
   };
   ATTRIBUTE_GROUPS(lp55xx_led);

  +struct led_mc_color_conversion
color_component[LP55XX_MAX_GROUPED_CHAN];

Why is this global? Please move it to lp55xx_set_brightness().

ACK

Quoted 20 lines
Quoted 20 lines
drivers/leds/leds-lp55xx-common.c +13 -0
+
+static int lp55xx_get_channel(struct lp55xx_led *led, int color_id)
+{
+    int i;
+
+    for (i = 0; i < led->mc_cdev.num_leds; i++) {
+        if (led->channel_color[i] == color_id)
+            return led->grouped_channels[i];
+    }
+
+    return -EINVAL;
+}
+

  static int lp55xx_set_brightness(struct led_classdev *cdev, enum led_brightness brightness) {
      struct lp55xx_led *led = cdev_to_lp55xx_led(cdev); struct lp55xx_device_config *cfg = led->chip->cfg; +    int channel_num;

Quoted 8 lines
Quoted 7 lines

+    int ret;
+    int i;
  -    led->brightness = (u8)brightness;
-    return cfg->brightness_fn(led);
+    if (led->mc_cdev.num_leds > 1) {
+        led_mc_calc_brightness(&led->mc_cdev, brightness, +                       &color_component[0]);

s/&color_component[0]/color_component/

ACK

Quoted 5 lines
Quoted 5 lines

+
+        for (i = 0; i < led->mc_cdev.num_leds; i++) { +            channel_num = lp55xx_get_channel(led, +                        color_component[i].color_id); +            if (channel_num < 0)

Quoted 8 lines
Quoted 4 lines

+                return channel_num;
+
+            ret = cfg->color_intensity_fn(led, channel_num, +                         color_component[i].brightness);

If you passed struct led_mc_color_conversion instead of brightness, then in the color_intensity_fn op you could obtain channel numbers by calling lp55xx_get_channel in a loop. And you could setup the whole cluster in a single call.

Quoted 1 line

Hmm.  How would that be an improvement?  Maybe the answer lies down

I mentioned that before - think of sleeping on mutex on contention (keep it mind that brightness will be also set from triggers and from the workqueue in effect, and userspace can interfere that).

That could add unpleasant delays between setting color components. It could be worked around by executing the for loop here under mutex, but would be non-uniform with regard to handling monochrome brightness setting via cfg->brightness_fn, which relies on chip->lock taken by it.

You need one of two options: either the whole for loop here under mutex or on the driver side.

Quoted 8 lines

below in my response and we will not have to get the channel_num as we can make the output part of the mc_color_conversion struct.

As I pointed out in v9 "Beyond that in coding this and thinking about the design it is better to have the lp55xx_common code to do all the heavy lifting and the children to just perform the action on the device itself"

Quoted 7 lines

https://lore.kernel.org/linux-leds/[email protected]/T/#u

The children should not have to know if the LED is registered to the LED class, MC Class or Flash class only the common code should know this information.  Just need to keep the child code simple. This is why I pass in the values as opposed to having the child figure it out.

With mc class we have a bit different perspective - the children are not standalone LED class devices. Of course it can be modeled this way as well, but it can result in a misleading impression that the LEDs are independent. If we set the all colors in one op for mc class case then it would nicely highlight that use case on the driver side.

Quoted 271 lines
Quoted 112 lines
Quoted 112 lines

+            if (ret)
+                return ret;
+        }
+    } else {
+        led->brightness = (u8)brightness;
+        ret = cfg->brightness_fn(led);
+    }
+
+    return ret;
  }
    static int lp55xx_init_led(struct lp55xx_led *led,

drivers/leds/leds-lp55xx-common.c +50 -12
@@ -147,9 +183,9 @@ static int lp55xx_init_led(struct lp55xx_led *led,
       struct lp55xx_platform_data *pdata = chip->pdata;
       struct lp55xx_device_config *cfg = chip->cfg;
       struct device *dev = &chip->cl->dev;
+    int max_channel = cfg->max_channel;
       char name[32];
       int ret;
-    int max_channel = cfg->max_channel;
         if (chan >= max_channel) {
           dev_err(dev, "invalid channel: %d / %d\n", chan, max_channel);
@@ -159,10 +195,37 @@ static int lp55xx_init_led(struct lp55xx_led *led,
       if (pdata->led_config[chan].led_current == 0)
           return 0;
   +    if (pdata->led_config[chan].name) {
+        led->cdev.name = pdata->led_config[chan].name;
+    } else {
+        snprintf(name, sizeof(name), "%s:channel%d",
+            pdata->label ? : chip->cl->name, chan);
+        led->cdev.name = name;
+    }
+
+    if (pdata->led_config[chan].num_colors > 1) {
+        led->mc_cdev.led_cdev = &led->cdev;
+        led->cdev.brightness_set_blocking = lp55xx_set_brightness;
+        led->cdev.groups = lp55xx_led_groups;
+        led->mc_cdev.num_leds = pdata->led_config[chan].num_colors;
+        led->mc_cdev.available_colors =
+            pdata->led_config[chan].available_colors;
+        memcpy(led->channel_color,
+               pdata->led_config[chan].channel_color,
+               sizeof(led->channel_color));
+        memcpy(led->grouped_channels,
+               pdata->led_config[chan].grouped_channels,
+               sizeof(led->grouped_channels));
+    } else {
+
+        led->cdev.default_trigger =
+            pdata->led_config[chan].default_trigger;
+        led->cdev.brightness_set_blocking = lp55xx_set_brightness;
+    }    led->cdev.groups = lp55xx_led_groups;
+
       led->led_current = pdata->led_config[chan].led_current;
       led->max_current = pdata->led_config[chan].max_current;
       led->chan_nr = pdata->led_config[chan].chan_nr;
-    led->cdev.default_trigger =
 pdata->led_config[chan].default_trigger;
         if (led->chan_nr >= max_channel) {
           dev_err(dev, "Use channel numbers between 0 and %d\n",
@@ -170,18 +233,11 @@ static int lp55xx_init_led(struct lp55xx_led *led,
           return -EINVAL;
       }
   -    led->cdev.brightness_set_blocking = lp55xx_set_brightness;
-    led->cdev.groups = lp55xx_led_groups;
+    if (pdata->led_config[chan].num_colors > 1)
+        ret = led_classdev_multicolor_register(dev, &led->mc_cdev);
+    else
+        ret = led_classdev_register(dev, &led->cdev);
   -    if (pdata->led_config[chan].name) {
-        led->cdev.name = pdata->led_config[chan].name;
-    } else {
-        snprintf(name, sizeof(name), "%s:channel%d",
-            pdata->label ? : chip->cl->name, chan);
-        led->cdev.name = name;
-    }
-
-    ret = led_classdev_register(dev, &led->cdev);
       if (ret) {
           dev_err(dev, "led register err: %d\n", ret);
           return ret;
@@ -466,7 +522,6 @@ int lp55xx_register_leds(struct lp55xx_led *led,
 struct lp55xx_chip *chip)
           dev_err(&chip->cl->dev, "empty brightness configuration\n");
           return -EINVAL;
       }
-
       for (i = 0; i < num_channels; i++) {
             /* do not initialize channels that are not connected */
@@ -538,6 +593,76 @@ void lp55xx_unregister_sysfs(struct lp55xx_chip
 *chip)
   }
   EXPORT_SYMBOL_GPL(lp55xx_unregister_sysfs);
   +static int lp5xx_parse_common_child(struct device_node *np,
+                     struct lp55xx_led_config *cfg,
+                     int chan_num, bool is_multicolor)
+{
+    u32 led_number;
+    int ret;
+
+    of_property_read_string(np, "chan-name",
+                &cfg[chan_num].name);
+    of_property_read_u8(np, "led-cur",
+                &cfg[chan_num].led_current);
+    of_property_read_u8(np, "max-cur",
+                &cfg[chan_num].max_current);
+
+    ret = of_property_read_u32(np, "reg", &led_number);
+    if (ret)
+        return ret;
+
+    if (led_number < 0 || led_number > 6)
Quoted 8 lines

drivers/leds/leds-lp55xx-common.c void lp55xx_unregister_sysfs(struct lp55xx_chip *chip) · line 618

Quoted 4 lines
drivers/leds/leds-lp55xx-common.c +4 -0
+        return -EINVAL;
+
+    if (is_multicolor)
+        cfg[chan_num].grouped_channels[cfg[chan_num].num_colors]

Please pass the index for grouped channels as an argument to this function. Referring here directly to a temporary state of num_colors that is incremented in the loop from which this function is called is ugly IMO.

Ack

Quoted 102 lines
Quoted 102 lines
drivers/leds/leds-lp55xx-common.c +35 -0
+                = led_number;
+    else
+        cfg[chan_num].chan_nr = led_number;
+
+    return 0;
+}
+
+static int lp5xx_parse_channel_child(struct device_node *np,
+                     struct lp55xx_led_config *cfg,
+                     int child_number)
+{
+    struct device_node *child;
+    int channel_color;
+    u32 color_id;
+    int ret;
+
+    cfg[child_number].default_trigger =
+            of_get_property(np, "linux,default-trigger", NULL);
+
+    ret = of_property_read_u32(np, "color", &channel_color);
+    if (ret)
+        channel_color = ret;
+
+
+    if (channel_color == LED_COLOR_ID_MULTI) {
+        for_each_child_of_node(np, child) {
+            ret = lp5xx_parse_common_child(child, cfg,
+                               child_number, true);
+            if (ret)
+                return ret;
+            ret = of_property_read_u32(child, "color", &color_id);
+            if (ret)
+                return ret;
+
+           

cfg[child_number].channel_color[cfg[child_number].num_colors] = +                color_id;
+            set_bit(color_id, &cfg[child_number].available_colors);

drivers/leds/leds-lp55xx-common.c +10 -0
+
+            cfg[child_number].num_colors++;
+        }
+    } else {
+        return lp5xx_parse_common_child(np, cfg, child_number, false);
+    }
+
+    return 0;
+}
+

  struct lp55xx_platform_data *lp55xx_of_populate_pdata(struct device *dev,
                                struct device_node *np)
  {

drivers/leds/leds-lp55xx-common.c +4 -8
@@ -546,6 +671,7 @@ struct lp55xx_platform_data
 *lp55xx_of_populate_pdata(struct device *dev,
       struct lp55xx_led_config *cfg;
       int num_channels;
       int i = 0;
+    int ret;
         pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
       if (!pdata)
@@ -565,14 +691,9 @@ struct lp55xx_platform_data
 *lp55xx_of_populate_pdata(struct device *dev,
       pdata->num_channels = num_channels;
         for_each_child_of_node(np, child) {
-        cfg[i].chan_nr = i;
-
-        of_property_read_string(child, "chan-name", &cfg[i].name);
-        of_property_read_u8(child, "led-cur", &cfg[i].led_current);
-        of_property_read_u8(child, "max-cur", &cfg[i].max_current);
-        cfg[i].default_trigger =
-            of_get_property(child, "linux,default-trigger", NULL);
-
+        ret = lp5xx_parse_channel_child(child, cfg, i);
+        if (ret)
+            return ERR_PTR(-EINVAL);
           i++;
       }

  diff --git a/drivers/leds/leds-lp55xx-common.h
b/drivers/leds/leds-lp55xx-common.h
index 783ed5103ce5..5ea2a292a97e 100644

drivers/leds/leds-lp55xx-common.h +0 -0
@@ -12,6 +12,10 @@
   #ifndef _LEDS_LP55XX_COMMON_H
   #define _LEDS_LP55XX_COMMON_H

  +#include <linux/led-class-multicolor.h>

drivers/leds/leds-lp55xx-common.h +3 -0
+
+#define LP55XX_MAX_GROUPED_CHAN    4
+

  enum lp55xx_engine_index {
      LP55XX_ENGINE_INVALID,
      LP55XX_ENGINE_1,

drivers/leds/leds-lp55xx-common.h +0 -0
@@ -109,6 +113,9 @@ struct lp55xx_device_config {
       /* access brightness register */
       int (*brightness_fn)(struct lp55xx_led *led);

  +    /* access specific brightness register */
+    int (*color_intensity_fn)(struct lp55xx_led *led, int chan_num, int brightness);
+
      /* current setting function */
      void (*set_led_current) (struct lp55xx_led *led, u8 led_current); @@ -159,6 +166,7 @@ struct lp55xx_chip {

Quoted 9 lines
Quoted 7 lines

   * struct lp55xx_led
   * @chan_nr         : Channel number
   * @cdev            : LED class device
+ * @mc_cdev        : Multi color class device
   * @led_current     : Current setting at each led channel
   * @max_current     : Maximun current at each led channel
   * @brightness      : Brightness value

Documentation for channel_color and grouped_channels is missing.

ACK

Quoted 12 lines

drivers/leds/leds-lp55xx-common.h struct lp55xx_chip { · line 183

Quoted 10 lines
drivers/leds/leds-lp55xx-common.h +3 -0
@@ -167,9 +175,12 @@ struct lp55xx_chip {
   struct lp55xx_led {
       int chan_nr;
       struct led_classdev cdev;
+    struct led_classdev_mc mc_cdev;
       u8 led_current;
       u8 max_current;
       u8 brightness;
+    int channel_color[LP55XX_MAX_GROUPED_CHAN];
+    int grouped_channels[LP55XX_MAX_GROUPED_CHAN];

I propose to create structure:

Quoted 8 lines

struct lp55xx_mc_cluster {
    int channel_color;
    int channel_id;
};

and instead of the above two arrays create one

struct lp55xx_mc_cluster mc_cluster[LP55XX_MAX_GROUPED_CHAN];

Maybe we can extend the mc_color_converion struct to add output_num.

Now I did try to do this but the design of the code made it a bit wonky.  I will look at it again.

If the output_num information is contain in a single struct as opposed to having each driver create their own struct.

struct led_mc_color_conversion {
    int color_id;
    int brightness;

Quoted 8 lines

    int output_num;

};

struct led_mc_color_conversion mc_cluster[LP55XX_MAX_GROUPED_CHAN];

If other drivers do not need that information then they do not need to populate it

Maybe, feel free to give it a try.

      struct lp55xx_chip *chip;

Quoted 31 lines
Quoted 14 lines
Quoted 14 lines
drivers/leds/leds-lp55xx-common.h +0 -0
   };

  diff --git a/include/linux/platform_data/leds-lp55xx.h b/include/linux/platform_data/leds-lp55xx.h index 96a787100fda..0ac29f537ab6 100644

include/linux/platform_data/leds-lp55xx.h +0 -0
@@ -12,6 +12,8 @@
   #ifndef _LEDS_LP55XX_H
   #define _LEDS_LP55XX_H

  +#include <linux/led-class-multicolor.h>
+
  /* Clock configuration */
  #define LP55XX_CLOCK_AUTO    0
  #define LP55XX_CLOCK_INT    1

Quoted 8 lines
Quoted 7 lines
include/linux/platform_data/leds-lp55xx.h +0 -0
@@ -23,6 +25,10 @@ struct lp55xx_led_config {
       u8 chan_nr;

      u8 led_current; /* mA x10, 0 if led is not connected */ u8 max_current;
+    int num_colors;
+    unsigned long available_colors;
+    u32 channel_color[LED_COLOR_ID_MAX];

channel_color array is redundant if you have available_colors flags.

I will look this again.

Quoted 4 lines
Quoted 4 lines

+    int grouped_channels[LED_COLOR_ID_MAX];
  };
    struct lp55xx_predef_pattern {

Signature · 2 lines
Best regards,
Jacek Anaszewski