Skip to contentSkip to conversation

leds: multicolor: Add sysfs interface definition

PATCH Superseded Dan Murphy 3 participants 15 messages Sep 17, 2019 – Sep 20, 2019

Subsystems (3)

v6 of 17 Superseded Latest is v17 →

lore
Share & tools
lore
author
#3 lore raw

PATCH v6 4/9 dt-bindings: 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.

---

v6 - no change

 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
author
#5 lore raw

PATCH v6 6/9 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.

---

v6 removed color_id and color_mix files, used sysfs_create_groups instead of kobject call for LED color directory, kept kobject_create for the "colors" directory, removed the calculate function, updated the export for the intensity calculations.

 drivers/leds/Kconfig                 |  10 +
 drivers/leds/Makefile                |   1 +
 drivers/leds/led-class-multicolor.c  | 306 +++++++++++++++++++++++++++
 include/linux/led-class-multicolor.h |  90 ++++++++
 4 files changed, 407 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 1988de1d64c0..71e7fd4f6f15 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 41fb073a39c1..897b810257dd 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 +306 -0

306 lines not on this page · raw message

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

90 lines not on this page · raw message

Signature · 1 line
2.22.0.214.g8dca754b1e

Dan Murphy

author
#0 lore raw

PATCH v6 1/9 leds: multicolor: Add sysfs interface definition

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

---

v6 - Removed color_mix and color_id files

 .../ABI/testing/sysfs-class-led-multicolor    | 43 +++++++++++++++++++
 1 file changed, 43 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-class-led-multicolor
Documentation/ABI/testing/sysfs-class-led-multicolor new file +43 -0
new file mode 100644
index 000000000000..b8f459f97919
@@ -0,0 +1,43 @@
+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 = requested_value * led_color_intensity/led_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/<led_color>/intensity
+Date:		Sept 2019
+KernelVersion:	5.5
+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 value for the led_color is defined in the
+		include/dt-bindings/leds/common.h. There is one directory per
+		color presented.  The intensity file is created under each
+		led_color directory and controls the individual LED color
+		setting.
+
+		The value of the color is from 0 to
+		/sys/class/leds/<led>/colors/<led_color>/max_intensity.
+
+What:		/sys/class/leds/<led>/colors/<led_color>/max_intensity
+Date:		Sept 2019
+KernelVersion:	5.5
+Contact:	Dan Murphy <[email protected]>
+Description:	read only
+		Maximum intensity level for the LED color, default is
+		255 (LED_FULL).
+
+		If the LED does not support different intensity levels, this
+		should be 1.
Signature · 1 line
2.22.0.214.g8dca754b1e
author
#1 lore raw

PATCH v6 2/9 documention: leds: Add multicolor class documentation

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.

---
v6 - Removed color_mix and color_id files

 Documentation/leds/index.rst                 |   1 +
 Documentation/leds/leds-class-multicolor.rst | 101 +++++++++++++++++++
 2 files changed, 102 insertions(+)
 create mode 100644 Documentation/leds/leds-class-multicolor.rst
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 +101 -0

101 lines not on this page · raw message

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

PATCH v6 5/9 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.

---

v6 - no change

 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
#14 lore raw

PATCH v6 9/9 leds: Update the lp55xx to use the multi color framework

In reply to Dan Murphy

Update the lp5523 to use the multi color framework.

---

v6 - Updated call to calculate LED intensity, removed extra module binary

 drivers/leds/leds-lp5523.c                |  13 +++
 drivers/leds/leds-lp55xx-common.c         | 131 ++++++++++++++++++----
 drivers/leds/leds-lp55xx-common.h         |   9 ++
 include/linux/platform_data/leds-lp55xx.h |   6 +
 4 files changed, 137 insertions(+), 22 deletions(-)
drivers/leds/leds-lp5523.c +13 -0
index d0b931a136b9..8b2cdb98fed6 100644
@@ -791,6 +791,18 @@ static ssize_t store_master_fader_leds(struct device *dev,
 	return ret;
 }
 
+static int lp5523_led_intensity(struct lp55xx_led *led, int chan_num)
+{
+	struct lp55xx_chip *chip = led->chip;
+	int ret;
+
+	mutex_lock(&chip->lock);
+	ret = lp55xx_write(chip, LP5523_REG_LED_PWM_BASE + chan_num,
+		     led->brightness);
+	mutex_unlock(&chip->lock);
+	return ret;
+}
+
 static int lp5523_led_brightness(struct lp55xx_led *led)
 {
 	struct lp55xx_chip *chip = led->chip;
@@ -857,6 +869,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,
drivers/leds/leds-lp55xx-common.c +109 -22

188 lines not on this page · raw message

drivers/leds/leds-lp55xx-common.h +9 -0
index 783ed5103ce5..d9c114259dcb 100644
@@ -12,6 +12,8 @@
 #ifndef _LEDS_LP55XX_COMMON_H
 #define _LEDS_LP55XX_COMMON_H
 
+#include <linux/led-class-multicolor.h>
+
 enum lp55xx_engine_index {
 	LP55XX_ENGINE_INVALID,
 	LP55XX_ENGINE_1,
@@ -109,6 +111,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);
+
 	/* current setting function */
 	void (*set_led_current) (struct lp55xx_led *led, u8 led_current);
 
@@ -159,6 +164,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 +173,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[LED_COLOR_ID_MAX];
+	int grouped_channels[LED_COLOR_ID_MAX];
 	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
#13 lore raw

PATCH v6 8/9 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
LP509 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.

---

v6 - no changes

 drivers/leds/Kconfig       |   7 +
 drivers/leds/Makefile      |   1 +
 drivers/leds/leds-lp50xx.c | 807 +++++++++++++++++++++++++++++++++++++
 3 files changed, 815 insertions(+)
 create mode 100644 drivers/leds/leds-lp50xx.c
drivers/leds/Kconfig +7 -0
index 71e7fd4f6f15..1041dfe8e354 100644
@@ -350,6 +350,13 @@ 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 LED driver chip"
+	depends on LEDS_CLASS && REGMAP_I2C
+	help
+	  If you say yes here you get support for the Texas Instruments
+	  LP5036, LP5030, LP5024 and LP5018 LED driver.
+
 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 897b810257dd..438a5499f3ee 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 +807 -0

807 lines not on this page · raw message

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

PATCH v6 7/9 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

---

v6 - no changes

 .../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..9d05f43042e0
@@ -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 - 0x28
+		lp5018/24 - 0x28
+		lp5030/36 - 0x30
+	- #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 : see Documentation/devicetree/bindings/leds/common.txt
+	- 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 module that controls
+		the RGB cluster.
+	- color : see Documentation/devicetree/bindings/leds/leds-multicolor.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 - 2 Total RGB cluster LED outputs 0-1
+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
author
#2 lore raw

PATCH v6 3/9 dt: bindings: Add multicolor class dt bindings documention

In reply to Dan Murphy

Add DT bindings for the LEDs multicolor class framework.

---

v6 - Fixed description and added suffix for function

 .../bindings/leds/leds-class-multicolor.txt   | 95 +++++++++++++++++++
 1 file changed, 95 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/leds/leds-class-multicolor.txt
Documentation/devicetree/bindings/leds/leds-class-multicolor.txt new file +95 -0
new file mode 100644
index 000000000000..215d3c90f351
@@ -0,0 +1,95 @@
+* Multicolor LED properties
+
+Monochrome LEDs can grouped into LED clusters.  These clusters can provide a
+visible output that have a wide range of colors and intensities.
+
+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
#6 lore raw

Re: [PATCH v6 6/9] leds: multicolor: Introduce a multicolor class definition

In reply to Dan Murphy

Greg

<snip>

Quoted 48 lines
drivers/leds/led-class-multicolor.c new file +48 -0
+static int led_multicolor_init_color(struct led_classdev_mc_data *data,
+				     struct led_classdev_mc *mcled_cdev,
+				     int color_id, int color_index)
+{
+	struct led_classdev *led_cdev = mcled_cdev->led_cdev;
+	struct led_mc_color_entry *mc_priv;
+	int ret;
+
+	mc_priv = devm_kzalloc(led_cdev->dev, sizeof(*mc_priv), GFP_KERNEL);
+	if (!mc_priv)
+		return -ENOMEM;
+
+	mc_priv->led_color_id = color_id;
+	mc_priv->mcled_cdev = mcled_cdev;
+
+	led_color_group.name = led_colors[color_id];
+	ret = sysfs_create_group(data->color_kobj, &led_color_group);
+	if (ret)
+		return ret;
+
+	sysfs_attr_init(&mc_priv->intensity_attr.attr);
+	mc_priv->intensity_attr.attr.name = "intensity";
+	mc_priv->intensity_attr.attr.mode = 666;
+	mc_priv->intensity_attr.store = intensity_store;
+	mc_priv->intensity_attr.show = intensity_show;
+	ret = sysfs_add_file_to_group(data->color_kobj,
+				      &mc_priv->intensity_attr.attr,
+				      led_color_group.name);
+	if (ret)
+		return ret;
+
+	sysfs_attr_init(&mc_priv->max_intensity_attr.attr);
+	mc_priv->max_intensity_attr.attr.name = "max_intensity";
+	mc_priv->max_intensity_attr.attr.mode = 444;
+	mc_priv->max_intensity_attr.show = max_intensity_show;
+	ret = sysfs_add_file_to_group(data->color_kobj,
+				      &mc_priv->max_intensity_attr.attr,
+				      led_color_group.name);
+	if (ret)
+		goto err_out;
+
+	mc_priv->max_intensity = LED_FULL;
+	list_add_tail(&mc_priv->list, &data->color_list);
+
+err_out:
+	return ret;
+}
+

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

Quoted 10 lines
drivers/leds/led-class-multicolor.c new file +10 -0
+static int led_multicolor_init_color_dir(struct led_classdev_mc_data *data,
+					 struct led_classdev_mc *mcled_cdev)
+{
+	struct led_classdev *led_cdev = mcled_cdev->led_cdev;
+	u32 color_id;
+	int ret;
+	int i, j = 0;
+
+	data->color_kobj = kobject_create_and_add("colors",
+						  &led_cdev->dev->kobj);

We need some guidance here on how to properly create sub directories more then 1 level deep.

In short under the LED class device parent directory we want to create a directory called "colors".

Under that directory we want to create a directory corresponding to the monochrome LED color. Under that directory we have the files to for intensity and max_intensity for the monochrome LED.

We can use the LED class kobject to create the colors directory using the sysfs calls but the issue comes when creating the LED color directory.  We don't have a kobj for colors to associate those directories to.  The only API we see to use the kobject_create_and_add which then gives us the colors directory kobj.

So the directory structure would look like this which is explained in this patch https://lore.kernel.org/patchwork/patch/1128444/

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
rwxr-xr-x    2 root     root             0 Jun 28 20:21 green
drwxr-xr-x    2 root     root             0 Jun 28 20:21 red

colors/blue:
-rw-------    1 root     root          4096 Jun 28 20:21 intensity -r--------    1 root     root          4096 Jun 28 20:27 max_intensity +colors/green:
-rw-------    1 root     root          4096 Jun 28 20:22 intensity -r--------    1 root     root          4096 Jun 28 20:27 max_intensity

colors/red:
-rw-------    1 root     root          4096 Jun 28 20:21 intensity -r--------    1 root     root          4096 Jun 28 20:27 max_intensity

I have reviewed your example code and read your blogs and papers on the subject but nothing really talks about sub-sub directories.

Now if this is a no-no in the kernel that is fine we can adjust but Jacek wanted to get your opinon/guidance on this topic.

Dan

<snip>

#7 lore raw

Re: [PATCH v6 6/9] leds: multicolor: Introduce a multicolor class definition

Quoted 57 lines · Dan Murphy

Greg

<snip>

Quoted 53 lines
drivers/leds/led-class-multicolor.c new file +53 -0
+static int led_multicolor_init_color(struct led_classdev_mc_data *data,
+				     struct led_classdev_mc *mcled_cdev,
+				     int color_id, int color_index)
+{
+	struct led_classdev *led_cdev = mcled_cdev->led_cdev;
+	struct led_mc_color_entry *mc_priv;
+	int ret;
+
+	mc_priv = devm_kzalloc(led_cdev->dev, sizeof(*mc_priv), GFP_KERNEL);
+	if (!mc_priv)
+		return -ENOMEM;
+
+	mc_priv->led_color_id = color_id;
+	mc_priv->mcled_cdev = mcled_cdev;
+
+	led_color_group.name = led_colors[color_id];
+	ret = sysfs_create_group(data->color_kobj, &led_color_group);
+	if (ret)
+		return ret;
+
+	sysfs_attr_init(&mc_priv->intensity_attr.attr);
+	mc_priv->intensity_attr.attr.name = "intensity";
+	mc_priv->intensity_attr.attr.mode = 666;
+	mc_priv->intensity_attr.store = intensity_store;
+	mc_priv->intensity_attr.show = intensity_show;
+	ret = sysfs_add_file_to_group(data->color_kobj,
+				      &mc_priv->intensity_attr.attr,
+				      led_color_group.name);
+	if (ret)
+		return ret;
+
+	sysfs_attr_init(&mc_priv->max_intensity_attr.attr);
+	mc_priv->max_intensity_attr.attr.name = "max_intensity";
+	mc_priv->max_intensity_attr.attr.mode = 444;
+	mc_priv->max_intensity_attr.show = max_intensity_show;
+	ret = sysfs_add_file_to_group(data->color_kobj,
+				      &mc_priv->max_intensity_attr.attr,
+				      led_color_group.name);
+	if (ret)
+		goto err_out;
+
+	mc_priv->max_intensity = LED_FULL;
+	list_add_tail(&mc_priv->list, &data->color_list);
+
+err_out:
+	return ret;
+}
+
+static int led_multicolor_init_color_dir(struct led_classdev_mc_data *data,
+					 struct led_classdev_mc *mcled_cdev)
+{
+	struct led_classdev *led_cdev = mcled_cdev->led_cdev;
+	u32 color_id;
Quoted 8 lines

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

Quoted 5 lines
drivers/leds/led-class-multicolor.c new file +5 -0
+	int ret;
+	int i, j = 0;
+
+	data->color_kobj = kobject_create_and_add("colors",
+						  &led_cdev->dev->kobj);

We need some guidance here on how to properly create sub directories more then 1 level deep.

Short answer, don't.

Long answer, use a 'struct device' but ONLY IF YOU KNOW WHAT YOU ARE DOING!

Follow the short answer please.

Quoted 2 lines

In short under the LED class device parent directory we want to create a directory called "colors".

Ok, that's simple.

Quoted 2 lines

Under that directory we want to create a directory corresponding to the monochrome LED color.

Why?

Quoted 2 lines

Under that directory we have the files to for intensity and max_intensity for the monochrome LED.

Why not just have colors/monochrome_intensity and colors/monochrome_max_intensity as your files in the colors/ directory?

Quoted 2 lines

We can use the LED class kobject to create the colors directory using the sysfs calls but the issue comes when creating the LED color directory.

Yes.

Quoted 1 line

We don't have a kobj for colors to associate those directories to.

And you shouldn't :)

Quoted 2 lines

The only API we see to use the kobject_create_and_add which then gives us the colors directory kobj.

Don't do that, you will break userspace code hard if you do that.

NEVER put a raw kobject after a 'struct device' in the sysfs tree if you expect normal userspace libraries to be able to understand what is going on. That's why this is "hard", you are not supposed to be doing it.

Quoted 19 lines

So the directory structure would look like this which is explained in this patch https://lore.kernel.org/patchwork/patch/1128444/

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
rwxr-xr-x    2 root     root             0 Jun 28 20:21 green
drwxr-xr-x    2 root     root             0 Jun 28 20:21 red

colors/blue:

(quoted diff) +1 -4
-rw-------    1 root     root          4096 Jun 28 20:21 intensity
-r--------    1 root     root          4096 Jun 28 20:27 max_intensity
+colors/green:
-rw-------    1 root     root          4096 Jun 28 20:22 intensity
-r--------    1 root     root          4096 Jun 28 20:27 max_intensity

colors/red:

Review

Quoted 2 lines
(quoted diff) +0 -2
-rw-------    1 root     root          4096 Jun 28 20:21 intensity
-r--------    1 root     root          4096 Jun 28 20:27 max_intensity

No, just add blue, green, red to the prefix of those files and all should be fine. Don't try to get fancy and use subdirs, that way lies madness.

Quoted 2 lines

I have reviewed your example code and read your blogs and papers on the subject but nothing really talks about sub-sub directories.

Because you shouldn't do it, I didn't think I had to describe everything you should not do :)

Quoted 2 lines

Now if this is a no-no in the kernel that is fine we can adjust but Jacek wanted to get your opinon/guidance on this topic.

Yes, don't do it.

did I say it enough times? :)

thanks,

greg k-h

#8 lore raw

Re: [PATCH v6 6/9] leds: multicolor: Introduce a multicolor class definition

In reply to Dan Murphy

Hi Dan,

I think Greg's guidance clarified everything nicely - we will avoid <color> sub-dirs in favour of prefixes to *intensity and *max_intensity.

Before you will send an update I have some improvement ideas regarding the remnants after the previous approach, where single color intensity update resulted in updating hardware state. Now the update will happen only on write to brightness file, so we will not need color_set/color_get ops anymore.

Quoted 125 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.

---

v6 removed color_id and color_mix files, used sysfs_create_groups instead of kobject call for LED color directory, kept kobject_create for the "colors" directory, removed the calculate function, updated the export for the intensity calculations.

 drivers/leds/Kconfig                 |  10 +
 drivers/leds/Makefile                |   1 +
 drivers/leds/led-class-multicolor.c  | 306 +++++++++++++++++++++++++++
 include/linux/led-class-multicolor.h |  90 ++++++++
 4 files changed, 407 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 1988de1d64c0..71e7fd4f6f15 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 41fb073a39c1..897b810257dd 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 +63 -0
new file mode 100644
index 000000000000..d43bd344ed4c
@@ -0,0 +1,306 @@
+// SPDX-License-Identifier: GPL-2.0
+// LED Multi Color class interface
+// Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/
+
+#include <linux/device.h>
+#include <linux/init.h>
+#include <linux/led-class-multicolor.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/uaccess.h>
+
+#include "leds.h"
+
+struct led_mc_color_entry {
+	struct led_classdev_mc *mcled_cdev;
+
+	struct device_attribute max_intensity_attr;
+	struct device_attribute intensity_attr;
+
+	enum led_brightness max_intensity;
+	enum led_brightness intensity;
+
+	struct list_head list;
+
+	int led_color_id;
+};
+
+void led_mc_calc_brightness(struct led_classdev_mc *mcled_cdev,
+			    enum led_brightness brightness,
+			    int brightness_val[])
+{
+	struct led_classdev_mc_data *data = mcled_cdev->data;
+	struct led_mc_color_entry *priv;
+	int i = 0;
+
+	list_for_each_entry(priv, &data->color_list, list) {
+		brightness_val[i] = brightness *
+				    priv->intensity / priv->max_intensity;
+		i++;
+	}
+}
+EXPORT_SYMBOL_GPL(led_mc_calc_brightness);
+
+static ssize_t intensity_store(struct device *dev,
+				struct device_attribute *intensity_attr,
+				const char *buf, size_t size)
+{
+	struct led_mc_color_entry *priv = container_of(intensity_attr,
+						    struct led_mc_color_entry,
+						      intensity_attr);
+	struct led_classdev_mc_data *data = priv->mcled_cdev->data;
+	struct led_classdev_mc *mcled_cdev = data->mcled_cdev;
+	struct led_classdev *led_cdev = priv->mcled_cdev->led_cdev;
+	unsigned long value;
+	ssize_t ret;
+
+	mutex_lock(&led_cdev->led_access);
+
+	ret = kstrtoul(buf, 10, &value);
+	if (ret)
+		goto unlock;
+
+	if (value > priv->max_intensity) {

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

Quoted 10 lines
drivers/leds/led-class-multicolor.c new file +10 -0
+		ret = -EINVAL;
+		goto unlock;
+	}
+
+	priv->intensity = value;
+
+	if (mcled_cdev->ops) {
+		ret = mcled_cdev->ops->set_color_brightness(mcled_cdev,
+							    priv->led_color_id,
+							    priv->intensity);

I don't think this is a good idea to update hw here now.
As I proposed before - let's do the write only in brightness set. Otherwise any change of hue requiring alteration of more than one color component will be non-atomic w.r.t. hw state change. Just cache the intensity in the entry here.

[...]

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

Re: [PATCH v6 6/9] leds: multicolor: Introduce a multicolor class definition

Jacek

Quoted 5 lines · Jacek Anaszewski

Hi Dan,

I think Greg's guidance clarified everything nicely - we will avoid <color> sub-dirs in favour of prefixes to *intensity and *max_intensity.

Yes I will make the change accordingly.  It will simplify the code.

Quoted 7 lines

Before you will send an update I have some improvement ideas regarding the remnants after the previous approach, where single color intensity update resulted in updating hardware state. Now the update will happen only on write to brightness file, so we will not need color_set/color_get ops anymore.

I left those call backs in specifically for the LP50xx. Otherwise the LEDs are only updated when the brightness file is written.

The LP50xx has an engine that performs the intensity computation for the specific LED.  So there is no call back to the MC FW for calculating the intensity.

The brightness and intensity are written directly to the device and the MCU in the device does all the computations so you have real time update.

For the LP55xx device the LEDs are only updated when the brightness file is written.

I think we can leave those call backs in if device driver or product development teams would like to use them.

Dan

Quoted 144 lines · Dan Murphy
Quoted 125 lines

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.

---

v6 removed color_id and color_mix files, used sysfs_create_groups instead of kobject call for LED color directory, kept kobject_create for the "colors" directory, removed the calculate function, updated the export for the intensity calculations.

  drivers/leds/Kconfig                 |  10 +
  drivers/leds/Makefile                |   1 +
  drivers/leds/led-class-multicolor.c  | 306 +++++++++++++++++++++++++++
  include/linux/led-class-multicolor.h |  90 ++++++++
  4 files changed, 407 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 1988de1d64c0..71e7fd4f6f15 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 41fb073a39c1..897b810257dd 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 +63 -0
new file mode 100644
index 000000000000..d43bd344ed4c
@@ -0,0 +1,306 @@
+// SPDX-License-Identifier: GPL-2.0
+// LED Multi Color class interface
+// Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/
+
+#include <linux/device.h>
+#include <linux/init.h>
+#include <linux/led-class-multicolor.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/uaccess.h>
+
+#include "leds.h"
+
+struct led_mc_color_entry {
+	struct led_classdev_mc *mcled_cdev;
+
+	struct device_attribute max_intensity_attr;
+	struct device_attribute intensity_attr;
+
+	enum led_brightness max_intensity;
+	enum led_brightness intensity;
+
+	struct list_head list;
+
+	int led_color_id;
+};
+
+void led_mc_calc_brightness(struct led_classdev_mc *mcled_cdev,
+			    enum led_brightness brightness,
+			    int brightness_val[])
+{
+	struct led_classdev_mc_data *data = mcled_cdev->data;
+	struct led_mc_color_entry *priv;
+	int i = 0;
+
+	list_for_each_entry(priv, &data->color_list, list) {
+		brightness_val[i] = brightness *
+				    priv->intensity / priv->max_intensity;
+		i++;
+	}
+}
+EXPORT_SYMBOL_GPL(led_mc_calc_brightness);
+
+static ssize_t intensity_store(struct device *dev,
+				struct device_attribute *intensity_attr,
+				const char *buf, size_t size)
+{
+	struct led_mc_color_entry *priv = container_of(intensity_attr,
+						    struct led_mc_color_entry,
+						      intensity_attr);
+	struct led_classdev_mc_data *data = priv->mcled_cdev->data;
+	struct led_classdev_mc *mcled_cdev = data->mcled_cdev;
+	struct led_classdev *led_cdev = priv->mcled_cdev->led_cdev;
+	unsigned long value;
+	ssize_t ret;
+
+	mutex_lock(&led_cdev->led_access);
+
+	ret = kstrtoul(buf, 10, &value);
+	if (ret)
+		goto unlock;
+
+	if (value > priv->max_intensity) {

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

Quoted 10 lines
drivers/leds/led-class-multicolor.c new file +10 -0
+		ret = -EINVAL;
+		goto unlock;
+	}
+
+	priv->intensity = value;
+
+	if (mcled_cdev->ops) {
+		ret = mcled_cdev->ops->set_color_brightness(mcled_cdev,
+							    priv->led_color_id,
+							    priv->intensity);

I don't think this is a good idea to update hw here now.
As I proposed before - let's do the write only in brightness set. Otherwise any change of hue requiring alteration of more than one color component will be non-atomic w.r.t. hw state change. Just cache the intensity in the entry here.

[...]

#10 lore raw

Re: [PATCH v6 6/9] leds: multicolor: Introduce a multicolor class definition

Dan,

Quoted 20 lines · Dan Murphy

Jacek

Quoted 5 lines · Jacek Anaszewski

Hi Dan,

I think Greg's guidance clarified everything nicely - we will avoid <color> sub-dirs in favour of prefixes to *intensity and *max_intensity.

Yes I will make the change accordingly.  It will simplify the code.

Quoted 7 lines

Before you will send an update I have some improvement ideas regarding the remnants after the previous approach, where single color intensity update resulted in updating hardware state. Now the update will happen only on write to brightness file, so we will not need color_set/color_get ops anymore.

I left those call backs in specifically for the LP50xx. Otherwise the LEDs are only updated when the brightness file is written.

Quoted 6 lines

The LP50xx has an engine that performs the intensity computation for the specific LED.  So there is no call back to the MC FW for calculating the intensity.

The brightness and intensity are written directly to the device and the MCU in the device does all the computations so you have real time update.

You can still handle that in brightness_set op. You need to compare which color channels have changed and update them in hardware in addition to setting LEDn_BRIGHTNESS register.

And yes - even updating a single color will need two operations:

echo 231 > colors/red_intensity // only cache the color in MC core echo 100 > brightness // do the actual hw update

Note that brightness value doesn't have to be necessarily different from the previous one here, but writing brightness file will be needed to trigger the hw update.

Quoted 5 lines

For the LP55xx device the LEDs are only updated when the brightness file is written.

I think we can leave those call backs in if device driver or product development teams would like to use them.

I'd not do that - it will be confusing. We can accomplish everything in brightness_set{_blocking} op. It will have also the advantage of same ABI semantics across all devices. Otherwise we would need separate documentation for devices like LP50xx.

I have also another question - what with linear vs logarithmic LP50xx brightness scale? I think we should make both options available to the userspace.

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

Re: [PATCH v6 6/9] leds: multicolor: Introduce a multicolor class definition

Jacek

Quoted 24 lines · Jacek Anaszewski

Dan,

Quoted 21 lines · Dan Murphy

Jacek

Quoted 5 lines · Jacek Anaszewski

Hi Dan,

I think Greg's guidance clarified everything nicely - we will avoid <color> sub-dirs in favour of prefixes to *intensity and *max_intensity.

Yes I will make the change accordingly.  It will simplify the code.

Quoted 6 lines

Before you will send an update I have some improvement ideas regarding the remnants after the previous approach, where single color intensity update resulted in updating hardware state. Now the update will happen only on write to brightness file, so we will not need color_set/color_get ops anymore.

I left those call backs in specifically for the LP50xx. Otherwise the LEDs are only updated when the brightness file is written. The LP50xx has an engine that performs the intensity computation for the specific LED.  So there is no call back to the MC FW for calculating the intensity.

Quoted 7 lines
Quoted 2 lines

The brightness and intensity are written directly to the device and the MCU in the device does all the computations so you have real time update.

You can still handle that in brightness_set op. You need to compare which color channels have changed and update them in hardware in addition to setting LEDn_BRIGHTNESS register.

And yes - even updating a single color will need two operations:

If we kept the ops then the LP50xx device would only need one operation to the led intensity file to update the color.

Quoted 2 lines

echo 231 > colors/red_intensity // only cache the color in MC core echo 100 > brightness // do the actual hw update

And this is the way the LP55xx device works now.

Quoted 8 lines

Note that brightness value doesn't have to be necessarily different from the previous one here, but writing brightness file will be needed to trigger the hw update.

Quoted 3 lines

For the LP55xx device the LEDs are only updated when the brightness file is written.

Quoted 6 lines
Quoted 2 lines

I think we can leave those call backs in if device driver or product development teams would like to use them.

I'd not do that - it will be confusing. We can accomplish everything in brightness_set{_blocking} op. It will have also the advantage of same ABI semantics across all devices. Otherwise we would need separate documentation for devices like LP50xx.

OK I am not going to argue this I will just remove the ops even though I don't agree.

Removing the ops will just make the LP50xx driver more complex then what it needs to be.

I will post v8 later today.

Quoted 4 lines

I have also another question - what with linear vs logarithmic LP50xx brightness scale? I think we should make both options available to the userspace.

I have no requirements from customers to provide this scaling.

It can be an enhancement to the driver later if we get the request.

Dan