Skip to contentSkip to conversation

MultiColor LED framework Documentation

RFC PATCH Superseded Dan Murphy 5 participants 21 messages Apr 1, 2019 – Apr 2, 2019

Subsystems (3)

v1 of 17 Superseded Latest is v17 →

lore
Share & tools
lore

Dan Murphy

author
#0 lore raw

cover MultiColor LED framework Documentation

I am RFCing these patches to start this Multicolor framework as it appears we have a few devices that need to leverage a framework like this.

I have attempted to create as much documentation as possible and have no issue in combining documents into a single document but I think this patchset is logical.

I have also added the dt-bindings patch that include the COLOR_ID and COLOR_NAME and documented the existing patch on the mail list. I have added this only for demonstration purposes.

Finally the code itself is a work in progress that at the very least will create a colors directory as well as the associated colors. The code works in principle but I need to scrub it for issues. The framework code also does not contain the available brightness support as this seems to be a sticky point.

Dan

Dan Murphy (5):
leds: multicolor: Add sysfs interface definition
dt: bindings: Add multicolor class dt bindings documention
documention: leds: Add multicolor class documentation
dt-bindings: leds: Add LED_COLOR_ID and COLOR_NAME definitions
leds: multicolor: Introduce a multicolor class definition

 .../ABI/testing/sysfs-class-led-multicolor    |  91 ++++
 .../bindings/leds/leds-class-multicolor.txt   | 140 ++++++
 Documentation/leds/leds-class-multicolor.txt  |  99 +++++
 drivers/leds/Kconfig                          |  10 +
 drivers/leds/Makefile                         |   1 +
 drivers/leds/led-class-multicolor.c           | 411 ++++++++++++++++++
 include/dt-bindings/leds/common.h             |  19 +
 include/linux/led-class-multicolor.h          |  69 +++
 8 files changed, 840 insertions(+)
 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/leds/leds-class-multicolor.txt
 create mode 100644 drivers/leds/led-class-multicolor.c
 create mode 100644 include/linux/led-class-multicolor.h
Signature · 1 line
2.19.0
author
#1 lore raw

RFC PATCH 1/5 leds: multicolor: Add sysfs interface definition

Add a documentation of LED Multicolor LED class specific sysfs attributes.

---
 .../ABI/testing/sysfs-class-led-multicolor    | 91 +++++++++++++++++++
 1 file changed, 91 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-class-led-multicolor
Documentation/ABI/testing/sysfs-class-led-multicolor new file +91 -0
new file mode 100644
index 000000000000..5583ecaa3170
@@ -0,0 +1,91 @@
+What:		/sys/class/leds/<led>/colors/sync_enable
+Date:		April 2019
+KernelVersion:	5.2
+Contact:	Dan Murphy <[email protected]>
+Description:	read/write
+		Writing a 1 to this file will enable the synchronization of all
+		the defined color LEDs within the LED node.  Brightness values
+		for each LED will be stored and written when sync is set to 1.
+		Writing a 0 to this file will disable syncing and allow
+		individual control of the LEDs brightness settings.
+
+What:		/sys/class/leds/<led>/colors/sync
+Date:		April 2019
+KernelVersion:	5.2
+Contact:	Dan Murphy <[email protected]>
+Description:	write only
+		Writing a 1 to this file while sync_enable is set to 1 will
+		write the current brightness values to all defined LEDs within
+		the LED node.  All LEDs defined will be configured based
+		on the brightness that has been requested.
+
+		If sync_enable is set to 0 then writing a 1 to sync has no
+		affect on the LEDs.
+
+What:		/sys/class/leds/<led>/colors/<led_color>/brightness
+Date:		April 2019
+KernelVersion:	5.2
+Contact:	Dan Murphy <[email protected]>
+Description:	read/write
+		The led_color directory is dynamically created based on the
+		colors defined by the registrar of the class.
+		The led_color can be but not limited to red, green, blue,
+		white, amber, yellow and violet.  Drivers can also declare a
+		LED color for presentation.  There is one directory per color
+		presented.  The brightness file is created under each
+		led_color directory and controls the individual LED color
+		setting.
+
+		If sync is enabled then	writing the brightness value of the LED
+		is deferred until a 1 is written to
+		/sys/class/leds/<led>/color/sync.  If syncing is
+		disabled then the LED brightness value will be written
+		immediately to the LED driver.
+
+		The value of the color is from 0 to
+		/sys/class/leds/<led>/colors/<led_color>/max_brightness.
+
+What:		/sys/class/leds/<led>/colors/<led_color>/max_brightness
+Date:		April 2019
+KernelVersion:	5.2
+Contact:	Dan Murphy <[email protected]>
+Description:	read only
+		Maximum brightness level for the LED color, default is
+		255 (LED_FULL).
+
+		If the LED does not support different brightness levels, this
+		should be 1.
+
+What:		/sys/class/leds/<led>/brightness_model/<model_color>
+Date:		April 2019
+KernelVersion:	5.2
+Contact:	Jacek Anaszewski <[email protected]>
+Description:	read/write
+		This directory contains the defined color models that are read
+		from the firmware node.  The model color will be the read from
+		the firmware node.  The model names should be a color that the
+		LED cluster can produce.
+
+What:		/sys/class/leds/<led>/brightness_model/<model_color>/brightness
+Date:		April 2019
+KernelVersion:	5.2
+Contact:	Jacek Anaszewski <[email protected]>
+Description:	read/write
+		Writing this file will initiate a synchronized write to the LED
+		cluster to produce the color output defined in the firmware node.
+
+		This value cannot exceed <model_color>/max_brightness.
+		Writing a 0 to this file will cause the LED cluster to turn off.
+
+		The sync and sync_enable files do not have an affect on this as
+		this is a real time update of the LED cluster.
+
+What:		/sys/class/leds/<led>/brightness_model/<model_color>/max_brightness
+Date:		April 2019
+KernelVersion:	5.2
+Contact:	Jacek Anaszewski <[email protected]>
+Description:	read
+		Reading this file will return the maximum number of brightness
+		levels that are defined in the firmware node for the model color.
+		It should be assumed that the levels are from 1 -> max_brightness
+		and the LED cluster brightness is increasing.
Signature · 1 line
2.19.0
author
#2 lore raw

RFC PATCH 2/5 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   | 140 ++++++++++++++++++
 1 file changed, 140 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/leds/leds-class-multicolor.txt
Documentation/devicetree/bindings/leds/leds-class-multicolor.txt new file +140 -0
new file mode 100644
index 000000000000..4b1a26104c79
@@ -0,0 +1,140 @@
+* Multicolor LED properties
+
+Multicolor LEDs can consist of a RGB, RGBW or a RGBA LED clusters.  These devices
+can be grouped together and also provide a modeling mechanism so that the
+cluster LEDs can vary in hue and intensity to produce a wide range of colors.
+
+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 : This is the color ID of the LED.  Definitions can be found
+		  in include/linux/leds/common.txt
+
+Optional LED Child properties:
+	- available-brightness-models : This is the phandle to the brightness-model
+					node(s) that this LED cluster can support.
+
+Required Brightness model properties
+	- led-brightness-model : This flag alerts the device driver and class
+				 code that this node is a brightness model node
+				 and to process the properties differently.
+
+Required Brightness model child properties
+	- model_name : This is the name of the model presented to the user.  This
+		       should be a color that the LED cluster can produce for
+		       the device it is attached to.
+	- layout : This is the LED layout for the levels.  This layout will
+		   determine the color order of the levels.  The layout and
+		   level-x properties array should be the same size.
+	- level-x : These are the values for the LEDs to produce the color that
+		    is defined.  These values are placed in the array according
+		    to the layout property.
+
+led-controller@30 {
+	#address-cells = <1>;
+	#size-cells = <0>;
+	compatible = "ti,lp5024";
+	reg = <0x29>;
+
+	lp5024_model_yellow: brightness-models {
+		led-brightness-model;
+		model@0 {
+			model_name = "yellow";
+			layout = <LED_COLOR_ID_RED
+				  LED_COLOR_ID_GREEN
+				  LED_COLOR_ID_BLUE>;
+			level-1 = <255 227 40>;
+			level-2 = <255 240 136>;
+			level-3 = <255 247 196>;
+		};
+	};
+
+	lp5024_model_orange: brightness-models {
+		led-brightness-model;
+		model@1 {
+			model_name = "orange";
+			layout = <LED_COLOR_ID_RED
+				  LED_COLOR_ID_GREEN
+				  LED_COLOR_ID_BLUE>;
+			level-1 = <236 140 16>;
+			level-2 = <236 157 55>;
+			level-3 = <236 183 115>;
+		};
+	}; 
+
+	multi-led@4 {
+		#address-cells = <1>;
+		#size-cells = <0>;
+		reg = <4>;
+		label = "rgb:led_mod4";
+		available-brightness-models = <&lp5024_model_yellow>;
+		
+		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>;
+		};
+	};
+
+	/* Only support RGB no model defined */
+	multi-led@1 {
+		#address-cells = <1>;
+		#size-cells = <0>;
+		reg = <1>;
+		label = "rgb:led_mod1";
+		
+		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>;
+		label = "rgb:banks";
+		reg = <2>;
+		ti,led-bank = <2 3 5>;
+		available-brightness-models = <&lp5024_model_orange>;
+
+		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>;
+		};
+	};
+
+};
Signature · 1 line
2.19.0
author
#9 lore raw

RFC PATCH 3/5 documention: leds: Add multicolor class documentation

In reply to Dan Murphy

Add the support documentation on the multicolor LED framework. This document defines the directores and file generated by the multicolor framework. It also documents usage.

---
 Documentation/leds/leds-class-multicolor.txt | 99 ++++++++++++++++++++
 1 file changed, 99 insertions(+)
 create mode 100644 Documentation/leds/leds-class-multicolor.txt
Documentation/leds/leds-class-multicolor.txt new file +99 -0
new file mode 100644
index 000000000000..8112b99a7668
@@ -0,0 +1,99 @@
+
+Multi Color LED handling under Linux
+=================================================
+
+Authors: Dan Murphy <[email protected]>
+
+Description
+-----------
+There are varying monochrome LED colors available for application.  These
+LEDs can be used as a single use case LED or can be mixed with other color
+LEDs to produce the full spectrum of color.  Color LEDs that are grouped
+can be presented under a single LED node with individual color control.
+The multicolor class groups these LEDs and allows dynamically setting the value
+of a single LED or setting the brightness values of the LEDs in the group and
+updating the LEDs virtually simultaneously.
+
+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 but the led_class
+framework.  The led_class framework is documented in led-class.txt within this
+documentation directory. 
+
+Each colored LED is given it's own directory.  These directories can be but not
+limited to red, green, blue, white, amber, yellow and violet.  Under these
+directories the brightness and max_brightness files are presented for each LED.
+
+Under the "colors" directory there are two files created "sync" and
+"sync_enable". The sync_enable file controls whether the LED brightness
+value is set real time or if the LED brightness value setting is deferred until
+the "sync" file is written.  If sync_enable is set then writing to each LED
+"brightness" file will store the brightness value.  Once the "sync" file is
+written then each LED color defined in the node will write the brightness of
+the LED in the device driver.
+
+If "sync_enable" is not set then writing the brightness value of the LED to the
+device driver is done immediately.  Writing the "sync" file has no affect.
+
+Directory Layout Example
+------------------------
+root:/sys/class/leds/rgb:grouped_leds# ls -lR colors/
+colors/:
+drwxr-xr-x    2 root     root             0 Jun 28 20:21 blue
+drwxr-xr-x    2 root     root             0 Jun 28 20:21 green
+drwxr-xr-x    2 root     root             0 Jun 28 20:21 red
+--w-------    1 root     root          4096 Jun 28 20:21 sync
+-rw-------    1 root     root          4096 Jun 28 20:22 sync_enable
+
+colors/blue:
+-rw-------    1 root     root          4096 Jun 28 20:21 brightness
+-r--------    1 root     root          4096 Jun 28 20:27 max_brightness
+
+colors/green:
+-rw-------    1 root     root          4096 Jun 28 20:22 brightness
+-r--------    1 root     root          4096 Jun 28 20:27 max_brightness
+
+colors/red:
+-rw-------    1 root     root          4096 Jun 28 20:21 brightness
+-r--------    1 root     root          4096 Jun 28 20:27 max_brightness
+
+Example of Writing LEDs with Sync Enabled
+-----------------------------------------
+Below the red, green and blue LEDs are set to corresponding values.  These
+values are stored and not written until the sync file is written.
+
+cd /sys/class/leds/rgb:grouped_leds/colors
+
+echo 1 > sync_enable
+
+echo 100 > red/brightness
+echo 80 > green/brightness
+echo 180 > blue/brightness
+
+* LED device driver has not been updated and the LED states have not changed.
+* Writing the LED brightness files again will only change the stored value and
+* not the device driver value.
+
+echo 1 > sync
+
+* LED device driver has been updated the LEDs should present the brightness
+* levels that have been set.  Since sync_enable is still enabled writing to the
+* LED brightness files will not change the current brightnesses.
+
+Example of Writing LEDs with Sync Disabled
+------------------------------------------
+Below the values of each LED are written to the device driver immediately upon
+request.
+
+cd /sys/class/leds/rgb:grouped_leds/colors
+
+echo 0 > sync_enable
+
+echo 100 > red/brightness // Red LED should be on with the current brightness
+echo 80 > green/brightness // Green LED should be on with the current brightness
+echo 180 > blue/brightness // Blue LED should be on with the current brightness
+.
+.
+.
+echo 0 > green/brightness // Green LED should be off
Signature · 1 line
2.19.0
author
#15 lore raw

RFC PATCH 4/5 dt-bindings: leds: Add LED_COLOR_ID and COLOR_NAME definitions

In reply to Dan Murphy

This patch is being added to demonstrate reuse of Jacek's patch
https://lore.kernel.org/patchwork/patch/1056726/

I have added color name definitions to the above patch. I do not claim authorship and the intent of this patch to strictly for demonstration.

---
 include/dt-bindings/leds/common.h | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
include/dt-bindings/leds/common.h +19 -0
index e171d0a6beb2..7e1279d761e4 100644
@@ -19,4 +19,23 @@
 #define LEDS_BOOST_ADAPTIVE	1
 #define LEDS_BOOST_FIXED	2
 
+#define LED_COLOR_ID_WHITE	 0
+#define LED_COLOR_ID_RED	 1
+#define LED_COLOR_ID_GREEN	 2
+#define LED_COLOR_ID_BLUE	 3
+#define LED_COLOR_ID_AMBER	 4
+#define LED_COLOR_ID_VIOLET	 5
+#define LED_COLOR_ID_YELLOW	 6
+#define LED_COLOR_ID_MAX	 LED_COLOR_ID_YELLOW
+
+#define LED_COLOR_NAME_WHITE	"white"
+#define LED_COLOR_NAME_RED	"red"
+#define LED_COLOR_NAME_GREEN	"green"
+#define LED_COLOR_NAME_BLUE	"blue"
+#define LED_COLOR_NAME_AMBER	"amber"
+#define LED_COLOR_NAME_VIOLET	"violet"
+#define LED_COLOR_NAME_YELLOW	"yellow"
+
+#define LED_COLOR_NAME_MAX_SZ	6
+
 #endif /* __DT_BINDINGS_LEDS_H */
Signature · 1 line
2.19.0
author
#16 lore raw

RFC PATCH 5/5 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 framework allows for dynamically setting individual LEDs or setting brightness levels of LEDs and updating them virtually simultaneously.

---
 drivers/leds/Kconfig                 |  10 +
 drivers/leds/Makefile                |   1 +
 drivers/leds/led-class-multicolor.c  | 411 +++++++++++++++++++++++++++
 include/linux/led-class-multicolor.h |  69 +++++
 4 files changed, 491 insertions(+)
 create mode 100644 drivers/leds/led-class-multicolor.c
 create mode 100644 include/linux/led-class-multicolor.h
drivers/leds/Kconfig +10 -0
index a72f97fca57b..477e108fd2a7 100644
@@ -29,6 +29,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 flash led sysfs class in /sys/class/leds.
+	  It wrapps LED Class and adds flash LEDs specific sysfs attributes
+	  and kernel internal API to it. You'll need this to provide support
+	  for the flash related features of a LED device. 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 4c1b0054f379..c57c2aec9510 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 +411 -0

411 lines not on this page · raw message

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

69 lines not on this page · raw message

Signature · 1 line
2.19.0
reviewer
#17 lore raw

Re: [RFC PATCH 5/5] leds: multicolor: Introduce a multicolor class definition

Hi,

Quoted 22 lines · Dan Murphy

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

The framework allows for dynamically setting individual LEDs or setting brightness levels of LEDs and updating them virtually simultaneously.

---
 drivers/leds/Kconfig                 |  10 +
 drivers/leds/Makefile                |   1 +
 drivers/leds/led-class-multicolor.c  | 411 +++++++++++++++++++++++++++
 include/linux/led-class-multicolor.h |  69 +++++
 4 files changed, 491 insertions(+)
 create mode 100644 drivers/leds/led-class-multicolor.c
 create mode 100644 include/linux/led-class-multicolor.h
drivers/leds/Kconfig +0 -0
index a72f97fca57b..477e108fd2a7 100644

drivers/leds/Kconfig config LEDS_CLASS_FLASH · line 33

Quoted 5 lines
drivers/leds/Kconfig +2 -0
@@ -29,6 +29,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"

Multi

drivers/leds/Kconfig config LEDS_CLASS_FLASH · line 36

Quoted 3 lines
drivers/leds/Kconfig +3 -0
+	depends on LEDS_CLASS
+	help
+	  This option enables the flash led sysfs class in /sys/class/leds.
	                                LED (?)

drivers/leds/Kconfig config LEDS_CLASS_FLASH · line 37

Quoted 1 line
drivers/leds/Kconfig +1 -0
+	  It wrapps LED Class and adds flash LEDs specific sysfs attributes

wraps

drivers/leds/Kconfig config LEDS_CLASS_FLASH · line 39

Quoted 2 lines
drivers/leds/Kconfig +2 -0
+	  and kernel internal API to it. You'll need this to provide support
+	  for the flash related features of a LED device. It can be built

of an LED device.

drivers/leds/Kconfig config LEDS_CLASS_FLASH · line 44

Quoted 5 lines
drivers/leds/Kconfig +2 -0
+	  as a module.
+
 config LEDS_BRIGHTNESS_HW_CHANGED
 	bool "LED Class brightness_hw_changed attribute support"
 	depends on LEDS_CLASS

ciao.

Signature · 1 line
~Randy
reviewer
#10 lore raw

Re: [RFC PATCH 3/5] documention: leds: Add multicolor class documentation

In reply to Dan Murphy

Hi,

Quoted 2 lines · Dan Murphy

Add the support documentation on the multicolor LED framework. This document defines the directores and file generated by the

directories and files

Quoted 14 lines

multicolor framework. It also documents usage.

---
 Documentation/leds/leds-class-multicolor.txt | 99 ++++++++++++++++++++
 1 file changed, 99 insertions(+)
 create mode 100644 Documentation/leds/leds-class-multicolor.txt
Documentation/leds/leds-class-multicolor.txt new file +0 -0
new file mode 100644
index 000000000000..8112b99a7668

Documentation/leds/leds-class-multicolor.txt line 5

Quoted 5 lines
Documentation/leds/leds-class-multicolor.txt new file +5 -0
@@ -0,0 +1,99 @@
+
+Multi Color LED handling under Linux
+=================================================
+
+Authors: Dan Murphy <[email protected]>

or Author:

Quoted 5 lines
Documentation/leds/leds-class-multicolor.txt new file +5 -0
+
+Description
+-----------
+There are varying monochrome LED colors available for application.  These
+LEDs can be used as a single use case LED or can be mixed with other color

Documentation/leds/leds-class-multicolor.txt line 20

Quoted 10 lines
Documentation/leds/leds-class-multicolor.txt new file +10 -0
+LEDs to produce the full spectrum of color.  Color LEDs that are grouped
+can be presented under a single LED node with individual color control.
+The multicolor class groups these LEDs and allows dynamically setting the value
+of a single LED or setting the brightness values of the LEDs in the group and
+updating the LEDs virtually simultaneously.
+
+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 but the led_class

created by

Documentation/leds/leds-class-multicolor.txt line 24

Quoted 4 lines
Documentation/leds/leds-class-multicolor.txt new file +4 -0
+framework.  The led_class framework is documented in led-class.txt within this
+documentation directory. 
+
+Each colored LED is given it's own directory.  These directories can be but not

its huh???????????

Documentation/leds/leds-class-multicolor.txt line 28

Quoted 4 lines
Documentation/leds/leds-class-multicolor.txt new file +4 -0
+limited to red, green, blue, white, amber, yellow and violet.  Under these
+directories the brightness and max_brightness files are presented for each LED.
+
+Under the "colors" directory there are two files created "sync" and

created:

Quoted 42 lines
Documentation/leds/leds-class-multicolor.txt new file +42 -0
+"sync_enable". The sync_enable file controls whether the LED brightness
+value is set real time or if the LED brightness value setting is deferred until
+the "sync" file is written.  If sync_enable is set then writing to each LED
+"brightness" file will store the brightness value.  Once the "sync" file is
+written then each LED color defined in the node will write the brightness of
+the LED in the device driver.
+
+If "sync_enable" is not set then writing the brightness value of the LED to the
+device driver is done immediately.  Writing the "sync" file has no affect.
+
+Directory Layout Example
+------------------------
+root:/sys/class/leds/rgb:grouped_leds# ls -lR colors/
+colors/:
+drwxr-xr-x    2 root     root             0 Jun 28 20:21 blue
+drwxr-xr-x    2 root     root             0 Jun 28 20:21 green
+drwxr-xr-x    2 root     root             0 Jun 28 20:21 red
+--w-------    1 root     root          4096 Jun 28 20:21 sync
+-rw-------    1 root     root          4096 Jun 28 20:22 sync_enable
+
+colors/blue:
+-rw-------    1 root     root          4096 Jun 28 20:21 brightness
+-r--------    1 root     root          4096 Jun 28 20:27 max_brightness
+
+colors/green:
+-rw-------    1 root     root          4096 Jun 28 20:22 brightness
+-r--------    1 root     root          4096 Jun 28 20:27 max_brightness
+
+colors/red:
+-rw-------    1 root     root          4096 Jun 28 20:21 brightness
+-r--------    1 root     root          4096 Jun 28 20:27 max_brightness
+
+Example of Writing LEDs with Sync Enabled
+-----------------------------------------
+Below the red, green and blue LEDs are set to corresponding values.  These
+values are stored and not written until the sync file is written.
+
+cd /sys/class/leds/rgb:grouped_leds/colors
+
+echo 1 > sync_enable
+
+echo 100 > red/brightness

Documentation/leds/leds-class-multicolor.txt line 80

Quoted 10 lines
Documentation/leds/leds-class-multicolor.txt new file +10 -0
+echo 80 > green/brightness
+echo 180 > blue/brightness
+
+* LED device driver has not been updated and the LED states have not changed.
+* Writing the LED brightness files again will only change the stored value and
+* not the device driver value.
+
+echo 1 > sync
+
+* LED device driver has been updated the LEDs should present the brightness

updated; the LEDs

Quoted 10 lines
Documentation/leds/leds-class-multicolor.txt new file +9 -0
+* levels that have been set.  Since sync_enable is still enabled writing to the
+* LED brightness files will not change the current brightnesses.
+
+Example of Writing LEDs with Sync Disabled
+------------------------------------------
+Below the values of each LED are written to the device driver immediately upon
+request.
+
+cd /sys/class/leds/rgb:grouped_leds/colors

Documentation/leds/leds-class-multicolor.txt line 99

Quoted 10 lines
Documentation/leds/leds-class-multicolor.txt new file +10 -0
+
+echo 0 > sync_enable
+
+echo 100 > red/brightness // Red LED should be on with the current brightness
+echo 80 > green/brightness // Green LED should be on with the current brightness
+echo 180 > blue/brightness // Blue LED should be on with the current brightness
+.
+.
+.
+echo 0 > green/brightness // Green LED should be off

cheers.

Signature · 1 line
~Randy
#11 lore raw

Re: [RFC PATCH 3/5] documention: leds: Add multicolor class documentation

In reply to Dan Murphy

Hi!

Quoted 11 lines
Documentation/leds/leds-class-multicolor.txt new file +10 -0
+Under the "colors" directory there are two files created "sync" and
+"sync_enable". The sync_enable file controls whether the LED brightness
+value is set real time or if the LED brightness value setting is deferred until
+the "sync" file is written.  If sync_enable is set then writing to each LED
+"brightness" file will store the brightness value.  Once the "sync" file is
+written then each LED color defined in the node will write the brightness of
+the LED in the device driver.
+
+If "sync_enable" is not set then writing the brightness value of the LED to the
+device driver is done immediately.  Writing the "sync" file has no

affect.

I believe better solutions exists for this problem.

One was discussed before -- have single file which contains coefficients for r/g/b channels.

Or at least... you should not really need separate sync and sync_enable files. One should do.

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#3 lore raw

Re: [RFC PATCH 2/5] dt: bindings: Add multicolor class dt bindings documention

In reply to Dan Murphy

Hi!

Quoted 52 lines
 .../bindings/leds/leds-class-multicolor.txt   | 140 ++++++++++++++++++
 1 file changed, 140 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/leds/leds-class-multicolor.txt
Documentation/devicetree/bindings/leds/leds-class-multicolor.txt new file +41 -0
new file mode 100644
index 000000000000..4b1a26104c79
@@ -0,0 +1,140 @@
+* Multicolor LED properties
+
+Multicolor LEDs can consist of a RGB, RGBW or a RGBA LED clusters.  These devices
+can be grouped together and also provide a modeling mechanism so that the
+cluster LEDs can vary in hue and intensity to produce a wide range of colors.
+
+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 : This is the color ID of the LED.  Definitions can be found
+		  in include/linux/leds/common.txt
+
+Optional LED Child properties:
+	- available-brightness-models : This is the phandle to the brightness-model
+					node(s) that this LED cluster can support.
+
+Required Brightness model properties
+	- led-brightness-model : This flag alerts the device driver and class
+				 code that this node is a brightness model node
+				 and to process the properties differently.
+
+Required Brightness model child properties
+	- model_name : This is the name of the model presented to the user.  This
+		       should be a color that the LED cluster can produce for
+		       the device it is attached to.
+	- layout : This is the LED layout for the levels.  This layout will
+		   determine the color order of the levels.  The layout and
+		   level-x properties array should be the same size.
+	- level-x : These are the values for the LEDs to produce the color that
+		    is defined.  These values are placed in the array according
+		    to the layout property.
 
+led-controller@30 {
+	#address-cells = <1>;
+	#size-cells = <0>;
+	compatible = "ti,lp5024";
+	reg = <0x29>;
+
+	lp5024_model_yellow: brightness-models {
+		led-brightness-model;

Documentation/devicetree/bindings/leds/leds-class-multicolor.txt line 52

Quoted 10 lines
Documentation/devicetree/bindings/leds/leds-class-multicolor.txt new file +10 -0
+		model@0 {
+			model_name = "yellow";
+			layout = <LED_COLOR_ID_RED
+				  LED_COLOR_ID_GREEN
+				  LED_COLOR_ID_BLUE>;
+			level-1 = <255 227 40>;
+			level-2 = <255 240 136>;
+			level-3 = <255 247 196>;
+		};
+	};

I don't think this works. RGB LED can show millions of colors. Do you propose to have millions of entries in dts?
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#19 lore raw

Re: [RFC PATCH 5/5] leds: multicolor: Introduce a multicolor class definition

In reply to Dan Murphy

Hi Dan,

Quoted 8 lines · On Mon, 1 Apr 2019 12:34:00 -0500 Dan Murphy <[email protected]> wrote:
drivers/leds/led-class-multicolor.c new file +8 -0
+static ssize_t sync_store(struct device *dev,
+			  struct device_attribute *sync_attr,
+			  const char *buf, size_t size)
+{
+	struct led_classdev_mc_data *data = container_of(sync_attr,
+						      struct led_classdev_mc_data,
+						      sync_attr);
+	struct led_classdev_mc *mcled_cdev = data->mcled_cdev;

drivers/leds/led-class-multicolor.c line 64

Quoted 10 lines
drivers/leds/led-class-multicolor.c new file +10 -0
+	struct led_classdev *led_cdev = &mcled_cdev->led_cdev;
+	const struct led_multicolor_ops *ops = mcled_cdev->ops;
+	struct led_classdev_mc_priv *priv;
+	unsigned long sync_value;
+	ssize_t ret = -EINVAL;
+
+	mutex_lock(&led_cdev->led_access);
+
+	if (!mcled_cdev->sync_enabled)
+		goto unlock;

This lock is redundant, you could just put
if (mcled_cdev->sync_enabled)

    return ret;

before the lock.

#12 lore raw

Re: [RFC PATCH 3/5] documention: leds: Add multicolor class documentation

In reply to Pavel Machek
Quoted 2 lines · On Mon, 1 Apr 2019 23:27:10 +0200 Pavel Machek <[email protected]> wrote:

One was discussed before -- have single file which contains coefficients for r/g/b channels.

That would somehow break the rule one file/one value. Although you could consider the whole color one value, that way it would not be broken...

author
#4 lore raw

Re: [RFC PATCH 2/5] dt: bindings: Add multicolor class dt bindings documention

In reply to Pavel Machek

Pavel

Quoted 61 lines · Pavel Machek

Hi!

Quoted 58 lines
 .../bindings/leds/leds-class-multicolor.txt   | 140 ++++++++++++++++++
 1 file changed, 140 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/leds/leds-class-multicolor.txt
Documentation/devicetree/bindings/leds/leds-class-multicolor.txt new file +47 -0
new file mode 100644
index 000000000000..4b1a26104c79
@@ -0,0 +1,140 @@
+* Multicolor LED properties
+
+Multicolor LEDs can consist of a RGB, RGBW or a RGBA LED clusters.  These devices
+can be grouped together and also provide a modeling mechanism so that the
+cluster LEDs can vary in hue and intensity to produce a wide range of colors.
+
+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 : This is the color ID of the LED.  Definitions can be found
+		  in include/linux/leds/common.txt
+
+Optional LED Child properties:
+	- available-brightness-models : This is the phandle to the brightness-model
+					node(s) that this LED cluster can support.
+
+Required Brightness model properties
+	- led-brightness-model : This flag alerts the device driver and class
+				 code that this node is a brightness model node
+				 and to process the properties differently.
+
+Required Brightness model child properties
+	- model_name : This is the name of the model presented to the user.  This
+		       should be a color that the LED cluster can produce for
+		       the device it is attached to.
+	- layout : This is the LED layout for the levels.  This layout will
+		   determine the color order of the levels.  The layout and
+		   level-x properties array should be the same size.
+	- level-x : These are the values for the LEDs to produce the color that
+		    is defined.  These values are placed in the array according
+		    to the layout property.
 
+led-controller@30 {
+	#address-cells = <1>;
+	#size-cells = <0>;
+	compatible = "ti,lp5024";
+	reg = <0x29>;
+
+	lp5024_model_yellow: brightness-models {
+		led-brightness-model;
+		model@0 {
+			model_name = "yellow";
+			layout = <LED_COLOR_ID_RED
+				  LED_COLOR_ID_GREEN
+				  LED_COLOR_ID_BLUE>;
+			level-1 = <255 227 40>;
Quoted 9 lines

Documentation/devicetree/bindings/leds/leds-class-multicolor.txt line 52

Quoted 4 lines
Documentation/devicetree/bindings/leds/leds-class-multicolor.txt new file +4 -0
+			level-2 = <255 240 136>;
+			level-3 = <255 247 196>;
+		};
+	};

I don't think this works. RGB LED can show millions of colors. Do you propose to have millions of entries in dts?
Pavel

I have had off line conversations with Jacek about this brightness model node.

Your concern was actually one of my concerns as well. Not only millions of entries but also having a huge DT binary.

We wanted to RFC this to get feedback. And this is why I have not added any support for this in the framework code.

Dan

Signature · 2 lines
------------------
Dan Murphy
author
#13 lore raw

Re: [RFC PATCH 3/5] documention: leds: Add multicolor class documentation

In reply to Pavel Machek

Pavel

Thanks for the comments

Quoted 16 lines · Pavel Machek

Hi!

Quoted 11 lines
Documentation/leds/leds-class-multicolor.txt new file +10 -0
+Under the "colors" directory there are two files created "sync" and
+"sync_enable". The sync_enable file controls whether the LED brightness
+value is set real time or if the LED brightness value setting is deferred until
+the "sync" file is written.  If sync_enable is set then writing to each LED
+"brightness" file will store the brightness value.  Once the "sync" file is
+written then each LED color defined in the node will write the brightness of
+the LED in the device driver.
+
+If "sync_enable" is not set then writing the brightness value of the LED to the
+device driver is done immediately.  Writing the "sync" file has no

affect.

I believe better solutions exists for this problem.

I agree there are other solutions. Better not so sure.
We keep kicking a solution down the road we have been talking about adding something to the kernel for almost 5 months now, but no one can decide what to do.

How do we move a solution forward?
Should we just forget the whole idea and keep developing against the current framework?

Quoted 3 lines

One was discussed before -- have single file which contains coefficients for r/g/b channels.

That has been presented as well and the concept was not well received either.

Quoted 3 lines

Or at least... you should not really need separate sync and sync_enable files. One should do.

The idea here was to be able to set the LED brightness immediately on a single LED with a single brightness write or setup the color brightness on all the LEDs and then sync the LED brightnesses.

If you wanted to control a single LED for notifications the user space may have to do

echo 0 > blue/brightness
echo 0 > green/brightness
echo 255 > red/brightness
echo 1 > sync

As opposed to just
echo 255 > red/brightness

But if that is not a concern then removing the sync_enable is fine with me from a code standpoint but not from a user space side.

Dan

Quoted 2 lines

Pavel

Signature · 2 lines
------------------
Dan Murphy
author
#20 lore raw

Re: [RFC PATCH 5/5] leds: multicolor: Introduce a multicolor class definition

In reply to Marek Behun

Marek

Quoted 26 lines · Marek Behun

Hi Dan,

Quoted 8 lines · On Mon, 1 Apr 2019 12:34:00 -0500 Dan Murphy <[email protected]> wrote:
drivers/leds/led-class-multicolor.c new file +8 -0
+static ssize_t sync_store(struct device *dev,
+			  struct device_attribute *sync_attr,
+			  const char *buf, size_t size)
+{
+	struct led_classdev_mc_data *data = container_of(sync_attr,
+						      struct led_classdev_mc_data,
+						      sync_attr);
+	struct led_classdev_mc *mcled_cdev = data->mcled_cdev;

drivers/leds/led-class-multicolor.c line 64

Quoted 10 lines
drivers/leds/led-class-multicolor.c new file +10 -0
+	struct led_classdev *led_cdev = &mcled_cdev->led_cdev;
+	const struct led_multicolor_ops *ops = mcled_cdev->ops;
+	struct led_classdev_mc_priv *priv;
+	unsigned long sync_value;
+	ssize_t ret = -EINVAL;
+
+	mutex_lock(&led_cdev->led_access);
+
+	if (!mcled_cdev->sync_enabled)
+		goto unlock;

This lock is redundant, you could just put
if (mcled_cdev->sync_enabled)

Quoted 3 lines
    return ret;

before the lock.

Ack

Thanks the code is just proof of concept code. But I will make this change as well.

Dan

Signature · 2 lines
------------------
Dan Murphy
#14 lore raw

Re: [RFC PATCH 3/5] documention: leds: Add multicolor class documentation

In reply to Dan Murphy

Hi

Quoted 23 lines · On Tue, 2 Apr 2019 06:53:30 -0500 Dan Murphy <[email protected]> wrote:

I agree there are other solutions. Better not so sure.
We keep kicking a solution down the road we have been talking about adding something to the kernel for almost 5 months now, but no one can decide what to do.

How do we move a solution forward?
Should we just forget the whole idea and keep developing against the current framework?

Quoted 3 lines

One was discussed before -- have single file which contains coefficients for r/g/b channels.

That has been presented as well and the concept was not well received either.

Quoted 3 lines

Or at least... you should not really need separate sync and sync_enable files. One should do.

The idea here was to be able to set the LED brightness immediately on a single LED with a single brightness write or setup the color brightness on all the LEDs and then sync the LED brightnesses.

If you wanted to control a single LED for notifications the user space may have to do

Quoted 8 lines

echo 0 > blue/brightness
echo 0 > green/brightness
echo 255 > red/brightness
echo 1 > sync

As opposed to just
echo 255 > red/brightness

Maybe other kernel developers, or sysfs maintainers like Greg, schould also have a word about this.

Another solution, although not usable from shell, could be this:
if a process opens all brightness files of a singled multicolor LED and then does a special SYNC_ON_THIS ioctl on one of them, then the sync is done when this color is written.
But that would also require ioctl for sysfs files, and I don't think Greg would like that.

Dan's sync_enable API looks right to me from the one file/one value sysfs rule as well - you can enable this setting (sync_enable) via one file.

What is the main reason you guys are concerned about this? That users will complain that they are writing to red/brightness and the LED does not change color (because they did not disable sync_enable)?

Marek

#5 lore raw

Re: [RFC PATCH 2/5] dt: bindings: Add multicolor class dt bindings documention

In reply to Dan Murphy
Quoted 9 lines · On Tue, 2 Apr 2019 06:40:53 -0500 Dan Murphy <[email protected]> wrote:

I have had off line conversations with Jacek about this brightness model node.

Your concern was actually one of my concerns as well. Not only millions of entries but also having a huge DT binary.

We wanted to RFC this to get feedback. And this is why I have not added any support for this in the framework code.

Dan

What if we just stuck to color spaces and defined channel curves in the device tree?

The curve could then be defined via an array of integer pairs, which would be interpreted as points via which the curve passes and the curve would be approximated by linear segemts...

  led@0 {
    colorspace = <COLOR_SPACE_ID_RGB>;
    red-curve = <0 0>, <255 255>;
    green-curve = <0 0>, <255 128>;
    blue-curve = <0 0>, <255 128>;
  };
author
#6 lore raw

Re: [RFC PATCH 2/5] dt: bindings: Add multicolor class dt bindings documention

Marek

Quoted 8 lines · Marek Behun
Quoted 5 lines · On Tue, 2 Apr 2019 06:40:53 -0500 Dan Murphy <[email protected]> wrote:

I have had off line conversations with Jacek about this brightness model node.

Your concern was actually one of my concerns as well. Not only millions of entries but also having a huge DT binary.

Quoted 8 lines
Quoted 4 lines

We wanted to RFC this to get feedback. And this is why I have not added any support for this in the framework code.

Dan

What if we just stuck to color spaces and defined channel curves in the device tree?

Vesa did a good summary of the current MC framework implementations that are being proposed The thread also documents Pavel's requirements

https://lore.kernel.org/patchwork/patch/1037147/

And here is the series with a single brightness file and passing in multiple integers. I did not document this code as I was pretty certain it was not the way to go.

https://patches.linaro.org/project/linux-leds/list/?series=18022

Dan

Quoted 11 lines

The curve could then be defined via an array of integer pairs, which would be interpreted as points via which the curve passes and the curve would be approximated by linear segemts...

  led@0 {
    colorspace = <COLOR_SPACE_ID_RGB>;
    red-curve = <0 0>, <255 255>;
    green-curve = <0 0>, <255 128>;
    blue-curve = <0 0>, <255 128>;
  };
Signature · 2 lines
------------------
Dan Murphy
author
#18 lore raw

Re: [RFC PATCH 5/5] leds: multicolor: Introduce a multicolor class definition

In reply to Randy Dunlap

Randy

Thank you.

Quoted 28 lines · Randy Dunlap

Hi,

Quoted 25 lines · Dan Murphy

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

The framework allows for dynamically setting individual LEDs or setting brightness levels of LEDs and updating them virtually simultaneously.

---
 drivers/leds/Kconfig                 |  10 +
 drivers/leds/Makefile                |   1 +
 drivers/leds/led-class-multicolor.c  | 411 +++++++++++++++++++++++++++
 include/linux/led-class-multicolor.h |  69 +++++
 4 files changed, 491 insertions(+)
 create mode 100644 drivers/leds/led-class-multicolor.c
 create mode 100644 include/linux/led-class-multicolor.h
drivers/leds/Kconfig +0 -0
index a72f97fca57b..477e108fd2a7 100644
@@ -29,6 +29,16 @@ config LEDS_CLASS_FLASH
 	  for the flash related features of a LED device. It can be built
 	  as a module.
 
Quoted 4 lines

drivers/leds/Kconfig config LEDS_CLASS_FLASH · line 33

Quoted 2 lines
drivers/leds/Kconfig +2 -0
+config LEDS_CLASS_MULTI_COLOR
+	tristate "LED Mulit Color LED Class Support"

Multi

Ack

Quoted 7 lines

drivers/leds/Kconfig config LEDS_CLASS_FLASH · line 36

Quoted 4 lines
drivers/leds/Kconfig +3 -0
+	depends on LEDS_CLASS
+	help
+	  This option enables the flash led sysfs class in /sys/class/leds.
	                                LED (?)

HA! This was a copy paste from the Flash class kconfig. I need to re-write the description anyway.

So your comments actually will turn into a bug fix for the Kconfig on that flag.

Dan
<snip>

Signature · 2 lines
------------------
Dan Murphy
#8 lore raw

Re: [RFC PATCH 2/5] dt: bindings: Add multicolor class dt bindings documention

In reply to Pavel Machek
Quoted 60 lines · Pavel Machek

Hi!

Quoted 57 lines
  .../bindings/leds/leds-class-multicolor.txt   | 140 ++++++++++++++++++
  1 file changed, 140 insertions(+)

create mode 100644 Documentation/devicetree/bindings/leds/leds-class-multicolor.txt

Documentation/devicetree/bindings/leds/leds-class-multicolor.txt new file +46 -0
new file mode 100644
index 000000000000..4b1a26104c79
@@ -0,0 +1,140 @@
+* Multicolor LED properties
+
+Multicolor LEDs can consist of a RGB, RGBW or a RGBA LED clusters.  These devices
+can be grouped together and also provide a modeling mechanism so that the
+cluster LEDs can vary in hue and intensity to produce a wide range of colors.
+
+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 : This is the color ID of the LED.  Definitions can be found
+		  in include/linux/leds/common.txt
+
+Optional LED Child properties:
+	- available-brightness-models : This is the phandle to the brightness-model
+					node(s) that this LED cluster can support.
+
+Required Brightness model properties
+	- led-brightness-model : This flag alerts the device driver and class
+				 code that this node is a brightness model node
+				 and to process the properties differently.
+
+Required Brightness model child properties
+	- model_name : This is the name of the model presented to the user.  This
+		       should be a color that the LED cluster can produce for
+		       the device it is attached to.
+	- layout : This is the LED layout for the levels.  This layout will
+		   determine the color order of the levels.  The layout and
+		   level-x properties array should be the same size.
+	- level-x : These are the values for the LEDs to produce the color that
+		    is defined.  These values are placed in the array according
+		    to the layout property.
 
+led-controller@30 {
+	#address-cells = <1>;
+	#size-cells = <0>;
+	compatible = "ti,lp5024";
+	reg = <0x29>;
+
+	lp5024_model_yellow: brightness-models {
+		led-brightness-model;
+		model@0 {
+			model_name = "yellow";
+			layout = <LED_COLOR_ID_RED
+				  LED_COLOR_ID_GREEN
+				  LED_COLOR_ID_BLUE>;
Quoted 8 lines

Documentation/devicetree/bindings/leds/leds-class-multicolor.txt line 52

Quoted 5 lines
Documentation/devicetree/bindings/leds/leds-class-multicolor.txt new file +5 -0
+			level-1 = <255 227 40>;
+			level-2 = <255 240 136>;
+			level-3 = <255 247 196>;
+		};
+	};

I don't think this works. RGB LED can show millions of colors. Do you propose to have millions of entries in dts?

Pavel, you know very well what is going on here and what is the background of this design. I suppose you've just entered your trolling mode - you lately admitted that it sometimes happens :-) [0]

This aims at solving the problem with multi color LED support in a backward compatible way, which is especially important in relation to existing triggers.

This is our attempt of addressing that problem in a color space agnostic way. It was inspired by out-of-tree approach presented by Vesa few months ago.

[0] https://www.spinics.net/lists/linux-leds/msg11388.html

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

Re: [RFC PATCH 2/5] dt: bindings: Add multicolor class dt bindings documention

In reply to Dan Murphy
Quoted 74 lines · Dan Murphy

Pavel

Quoted 61 lines · Pavel Machek

Hi!

Quoted 58 lines
  .../bindings/leds/leds-class-multicolor.txt   | 140 ++++++++++++++++++
  1 file changed, 140 insertions(+)

create mode 100644 Documentation/devicetree/bindings/leds/leds-class-multicolor.txt

Documentation/devicetree/bindings/leds/leds-class-multicolor.txt new file +47 -0
new file mode 100644
index 000000000000..4b1a26104c79
@@ -0,0 +1,140 @@
+* Multicolor LED properties
+
+Multicolor LEDs can consist of a RGB, RGBW or a RGBA LED clusters.  These devices
+can be grouped together and also provide a modeling mechanism so that the
+cluster LEDs can vary in hue and intensity to produce a wide range of colors.
+
+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 : This is the color ID of the LED.  Definitions can be found
+		  in include/linux/leds/common.txt
+
+Optional LED Child properties:
+	- available-brightness-models : This is the phandle to the brightness-model
+					node(s) that this LED cluster can support.
+
+Required Brightness model properties
+	- led-brightness-model : This flag alerts the device driver and class
+				 code that this node is a brightness model node
+				 and to process the properties differently.
+
+Required Brightness model child properties
+	- model_name : This is the name of the model presented to the user.  This
+		       should be a color that the LED cluster can produce for
+		       the device it is attached to.
+	- layout : This is the LED layout for the levels.  This layout will
+		   determine the color order of the levels.  The layout and
+		   level-x properties array should be the same size.
+	- level-x : These are the values for the LEDs to produce the color that
+		    is defined.  These values are placed in the array according
+		    to the layout property.
 
+led-controller@30 {
+	#address-cells = <1>;
+	#size-cells = <0>;
+	compatible = "ti,lp5024";
+	reg = <0x29>;
+
+	lp5024_model_yellow: brightness-models {
+		led-brightness-model;
+		model@0 {
+			model_name = "yellow";
+			layout = <LED_COLOR_ID_RED
+				  LED_COLOR_ID_GREEN
+				  LED_COLOR_ID_BLUE>;
+			level-1 = <255 227 40>;
Quoted 9 lines

Documentation/devicetree/bindings/leds/leds-class-multicolor.txt line 52

Quoted 4 lines
Documentation/devicetree/bindings/leds/leds-class-multicolor.txt new file +4 -0
+			level-2 = <255 240 136>;
+			level-3 = <255 247 196>;
+		};
+	};

I don't think this works. RGB LED can show millions of colors. Do you propose to have millions of entries in dts?
Pavel

Quoted 6 lines

I have had off line conversations with Jacek about this brightness model node.

Your concern was actually one of my concerns as well. Not only millions of entries but also having a huge DT binary.

We wanted to RFC this to get feedback. And this is why I have not added any support for this in the framework code.

We all know that nobody sane is going to add millions of color entries. It is just a holistic solution to the problem, without the need to worry about different colors being produced by different LED elements, either due to their inherent properties, due to different parameters of LED controllers and board designs, or due to aging. Of course the last case will be possible to fix only by update of DTB blob.

Regarding the possible size of DTB blob, I made some calculations and even compiled sample dts. Here is my reasoning from one of the replies to Dan during our private discussion:

-------------------------------------------------------------------------

Brightness models will be reusable between modules. There could be arbitrary number of brightness models, limited only by maximum dtb blob size.

In uboot it can be configured with "setenv fdt_high". For the dtbs appended to zImage for ARM the limit is 2MB AFAIK. Brightness models will be what consumes the most of memory with this proposed DT design.

Let's calculate.

4 bytes for single brightness value (we allow for values > 255).

I think quite exaggerated exemplary quantities:

number of colors in the mcled_dev: 10
number of levels per model: 256
number of models: 100

bytes required = 4 * 10 * 256 * 100 = 1024000, i.e. less than 1MB

And average mainline dtbs usually don't exceed 100kB, so I think we are safe. I've even just tried it out by adding such 10 models of 255 levels * 10 values * 4-byte to versatile-pb.dts and I got dtb size ~150kB.

But to be sure it would be good to get early ack from DT guys.

-------------------------------------------------------------------------

And now is this moment - we'd like to hear the feedback from DT guys.

Signature · 2 lines
Best regards,
Jacek Anaszewski