Multicolor FW update
Subsystems (3)
v5 cover Multicolor FW update
Hello
Lots of changes went into this update. The main change was that when writing to the colors/intensity or colors/color_mix file for a specific color the LED intensity will not change until the brightness file is written.
Added the LP5012/9 LED devices to the LP50xx code. Converted the class doc to rst format.
Dan
Dan Murphy (9):
leds: multicolor: Add sysfs interface definition
documention: leds: Add multicolor class documentation
dt: bindings: Add multicolor class dt bindings documention
dt-bindings: leds: Add multicolor ID to the color ID list
leds: Add multicolor ID to the color ID list
leds: multicolor: Introduce a multicolor class definition
dt: bindings: lp50xx: Introduce the lp50xx family of RGB drivers
leds: lp50xx: Add the LP50XX family of the RGB LED driver
leds: Update the lp55xx to use the multi color framework
.../ABI/testing/sysfs-class-led-multicolor | 73 ++ .../bindings/leds/leds-class-multicolor.txt | 96 +++ .../devicetree/bindings/leds/leds-lp50xx.txt | 148 ++++ Documentation/leds/index.rst | 1 + Documentation/leds/leds-class-multicolor.rst | 149 ++++ drivers/leds/Kconfig | 17 + drivers/leds/Makefile | 2 + drivers/leds/led-class-multicolor.c | 387 +++++++++ drivers/leds/led-core.c | 1 + drivers/leds/leds-lp50xx.c | 807 ++++++++++++++++++ drivers/leds/leds-lp5523.c | 13 + drivers/leds/leds-lp55xx-common.c | 131 ++- drivers/leds/leds-lp55xx-common.h | 9 + include/dt-bindings/leds/common.h | 3 +- include/linux/led-class-multicolor.h | 96 +++ include/linux/platform_data/leds-lp55xx.h | 6 + modules.builtin.modinfo | Bin 0 -> 43550 bytes 17 files changed, 1916 insertions(+), 23 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-class-led-multicolor create mode 100644 Documentation/devicetree/bindings/leds/leds-class-multicolor.txt create mode 100644 Documentation/devicetree/bindings/leds/leds-lp50xx.txt create mode 100644 Documentation/leds/leds-class-multicolor.rst create mode 100644 drivers/leds/led-class-multicolor.c create mode 100644 drivers/leds/leds-lp50xx.c create mode 100644 include/linux/led-class-multicolor.h create mode 100644 modules.builtin.modinfo
Signature · 1 line
2.22.0.214.g8dca754b1e
PATCH v5 1/9 leds: multicolor: Add sysfs interface definition
Add a documentation of LED Multicolor LED class specific sysfs attributes.
--- .../ABI/testing/sysfs-class-led-multicolor | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-class-led-multicolor
Documentation/ABI/testing/sysfs-class-led-multicolor new file +73 -0
@@ -0,0 +1,73 @@ +What: /sys/class/leds/<led>/brightness +Date: Sept 2019 +KernelVersion: 5.5 +Contact: Dan Murphy <[email protected]> +Description: read/write + The multicolor class will redirect the device drivers call back + function for brightness control to the multicolor class + brightness control function. + + Writing to this file will update all LEDs within the group to a + calculated percentage of what each color LED in the group 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/color_mix +Date: Sept 2019 +KernelVersion: 5.5 +Contact: Dan Murphy <[email protected]> +Description: read/write + The values written to this file should contain the intensity + values of each multicolor LED within the colors directory. The + index of given color is reported by the color_id file present in + colors/<color> directory. The index determines the position in + the sequence of intensities on which the related intensity + should be passed to this file. + + For additional details please refer to + Documentation/leds/leds-class-multicolor.rst. + +What: /sys/class/leds/<led>/colors/<led_color>/color_id +Date: Sept 2019 +KernelVersion: 5.5 +Contact: Dan Murphy <[email protected]> +Description: read only + This file when read will return the index of the color in the + color_mix. + + For additional details please refer to + Documentation/leds/leds-class-multicolor.rst. + +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 led_color can be but not limited to red, green, blue, + white, amber, yellow and violet. There is one directory per color + presented. The brightness 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
Re: [PATCH v5 1/9] leds: multicolor: Add sysfs interface definition
Hi Dan,
Quoted 40 lines · Dan Murphy
Add a documentation of LED Multicolor LED class specific sysfs attributes.
Signed-off-by Dan Murphy <[email protected]>--- .../ABI/testing/sysfs-class-led-multicolor | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-class-led-multicolorDocumentation/ABI/testing/sysfs-class-led-multicolor new file +25
-0@@ -0,0 +1,73 @@ +What: /sys/class/leds/<led>/brightness +Date: Sept 2019 +KernelVersion: 5.5 +Contact: Dan Murphy <[email protected]> +Description: read/write + The multicolor class will redirect the device drivers call back + function for brightness control to the multicolor class + brightness control function. + + Writing to this file will update all LEDs within the group to a + calculated percentage of what each color LED in the group 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/color_mix +Date: Sept 2019 +KernelVersion: 5.5 +Contact: Dan Murphy <[email protected]>
Documentation/ABI/testing/sysfs-class-led-multicolor line 35
Quoted 10 lines
Documentation/ABI/testing/sysfs-class-led-multicolor new file +10
-0+Description: read/write + The values written to this file should contain the intensity + values of each multicolor LED within the colors directory. The + index of given color is reported by the color_id file present in + colors/<color> directory. The index determines the position in + the sequence of intensities on which the related intensity + should be passed to this file. + + For additional details please refer to + Documentation/leds/leds-class-multicolor.rst.
As already mentioned in the reply to Pavel - let's avoid the introduction of another sysfs file with multiple values.
Color intensity files will only cache the value and actual write will be performed upon writing brightness file.
Quoted 39 lines
Documentation/ABI/testing/sysfs-class-led-multicolor new file +38
-0+ +What: /sys/class/leds/<led>/colors/<led_color>/color_id +Date: Sept 2019 +KernelVersion: 5.5 +Contact: Dan Murphy <[email protected]> +Description: read only + This file when read will return the index of the color in the + color_mix. + + For additional details please refer to + Documentation/leds/leds-class-multicolor.rst. + +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 led_color can be but not limited to red, green, blue, + white, amber, yellow and violet. There is one directory per color + presented. The brightness 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 · 2 lines
Best regards, Jacek Anaszewski
Re: [PATCH v5 1/9] leds: multicolor: Add sysfs interface definition
Hello
Quoted 47 lines · Jacek Anaszewski
Hi Dan,
Quoted 44 lines · Dan Murphy
Add a documentation of LED Multicolor LED class specific sysfs attributes.
Signed-off-by Dan Murphy <[email protected]>--- .../ABI/testing/sysfs-class-led-multicolor | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+)create mode 100644
Documentation/ABI/testing/sysfs-class-led-multicolorDocumentation/ABI/testing/sysfs-class-led-multicolor new file +29
-0@@ -0,0 +1,73 @@ +What: /sys/class/leds/<led>/brightness +Date: Sept 2019 +KernelVersion: 5.5 +Contact: Dan Murphy <[email protected]> +Description: read/write + The multicolor class will redirect the device drivers call back + function for brightness control to the multicolor class + brightness control function. + + Writing to this file will update all LEDs within the group to a + calculated percentage of what each color LED in the group 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/color_mix +Date: Sept 2019 +KernelVersion: 5.5 +Contact: Dan Murphy <[email protected]> +Description: read/write + The values written to this file should contain the intensity + values of each multicolor LED within the colors directory. The + index of given color is reported by the color_id file present in
Quoted 8 lines
Documentation/ABI/testing/sysfs-class-led-multicolor line 35
Quoted 6 lines
Documentation/ABI/testing/sysfs-class-led-multicolor new file +6
-0+ colors/<color> directory. The index determines the position in + the sequence of intensities on which the related intensity + should be passed to this file. + + For additional details please refer to + Documentation/leds/leds-class-multicolor.rst.As already mentioned in the reply to Pavel - let's avoid the introduction of another sysfs file with multiple values.
OK for clarification remove the color_mix and color_id files and keep the intensity files?
Dan
Re: [PATCH v5 1/9] leds: multicolor: Add sysfs interface definition
Dan,
Quoted 64 lines · Dan Murphy
Hello
Quoted 52 lines · Jacek Anaszewski
Hi Dan,
Quoted 49 lines · Dan Murphy
Add a documentation of LED Multicolor LED class specific sysfs attributes.
Signed-off-by Dan Murphy <[email protected]>---
.../ABI/testing/sysfs-class-led-multicolor | 73 +++++++++++++++++++1 file changed, 73 insertions(+)create mode 100644
Documentation/ABI/testing/sysfs-class-led-multicolorDocumentation/ABI/testing/sysfs-class-led-multicolor new file +11
-0@@ -0,0 +1,73 @@ +What: /sys/class/leds/<led>/brightness +Date: Sept 2019 +KernelVersion: 5.5 +Contact: Dan Murphy <[email protected]> +Description: read/write + The multicolor class will redirect the device drivers call back + function for brightness control to the multicolor class + brightness control function. + + Writing to this file will update all LEDs within the group to a + calculated percentage of what each color LED in the group isset
+ to. The percentage is calculated via the equation below:
+
+led_brightness=requested_value* led_color_intensity/led_color_max_intensityDocumentation/ABI/testing/sysfs-class-led-multicolor new file +15
-0+ + For additional details please refer to + Documentation/leds/leds-class-multicolor.rst. + + The value of the color is from 0 to + /sys/class/leds/<led>/max_brightness. + +What: /sys/class/leds/<led>/colors/color_mix +Date: Sept 2019 +KernelVersion: 5.5 +Contact: Dan Murphy <[email protected]> +Description: read/write + The values written to this file should contain the intensity + values of each multicolor LED within the colors directory. The + index of given color is reported by the color_id filepresent in
Quoted 8 lines
Quoted 6 lines
+ colors/<color> directory. The index determines the position in + the sequence of intensities on which the related intensity + should be passed to this file.
+
+ For additional details please refer to
+Documentation/leds/leds-class-multicolor.rst.As already mentioned in the reply to Pavel - let's avoid the introduction of another sysfs file with multiple values.
Quoted 2 lines
OK for clarification remove the
color_mixandcolor_idfiles and keep the intensity files?
Exactly.
Signature · 2 lines
Best regards, Jacek Anaszewski
PATCH v5 2/9 documention: leds: Add multicolor class documentation
In reply to Dan MurphyAdd 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/index.rst | 1 + Documentation/leds/leds-class-multicolor.rst | 149 +++++++++++++++++++ 2 files changed, 150 insertions(+) create mode 100644 Documentation/leds/leds-class-multicolor.rst
Documentation/leds/index.rst +1 -0
@@ -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 +149 -0
149 lines not on this page · raw message
Signature · 1 line
2.22.0.214.g8dca754b1e
Re: [PATCH v5 2/9] documention: leds: Add multicolor class documentation
Hi!
Documentation/leds/leds-class-multicolor.rst line 39
Quoted 13 lines
Documentation/leds/leds-class-multicolor.rst new file +13
-0+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 +-rw------- 1 root root 4096 Jun 28 20:21 color_mix + +colors/blue: +-rw------- 1 root root 4096 Jun 28 20:21 intensity +-r-------- 1 root root 4096 Jun 28 20:27 max_intensity +-r-------- 1 root root 4096 Jun 28 20:21 color_id
I don't really like the directories... A bit too much complexity, and it will have a memory footprint, too.
I'd expect max_intensity to be same for all the leds in rgb:grouped_leds... Could we simply rely on max_brightness file?
[If not, would one "max_intensity" file in rgb:grouped_leds be enough?]
Best regards,
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PATCH v5 2/9] documention: leds: Add multicolor class documentation
Hello Pavel
Thanks for looking at this again
Quoted 17 lines · Pavel Machek
Hi!
Documentation/leds/leds-class-multicolor.rst line 39
Quoted 13 lines
Documentation/leds/leds-class-multicolor.rst new file +13
-0+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 +-rw------- 1 root root 4096 Jun 28 20:21 color_mix + +colors/blue: +-rw------- 1 root root 4096 Jun 28 20:21 intensity +-r-------- 1 root root 4096 Jun 28 20:27 max_intensity +-r-------- 1 root root 4096 Jun 28 20:21 color_idI don't really like the directories... A bit too much complexity, and it will have a memory footprint, too.
The directories should be fine to have I am not seeing the complexity. Is memory footprint really an issue? Maybe in the IoT space but this is small and memory footprint should be able to handle this for IoT and larger systems.
Having dedicated directories and files clears up issues for user space to know about the parameters for each LED especially with the color_mix file which I still am not a fan of, but conceded and implemented anyway. It also gives the user space flexibility to call the monochrome LEDs specific intensity file. The user space can either use the color intensity file or the color_mix file it is a choice for them to make.
This code was modeled off the LP50xx device which has individual LED intensity controls as well as a overall brightness control. Since we have no feedback from user space folks I feel we have to give some options not very many but some.
Quoted 3 lines
I'd expect
max_intensityto be same for all the leds in rgb:grouped_leds... Could we simply rely onmax_brightnessfile?
I went under the assumption that not all grouped LEDs would have the same max_intensity.
I don't have specific use cases but wanted this as an option.
Dan
Quoted 6 lines
[If not, would one "
max_intensity" file in rgb:grouped_leds be enough?]Best regards,
Pavel
Re: [PATCH v5 2/9] documention: leds: Add multicolor class documentation
In reply to Pavel MachekQuoted 18 lines · Pavel Machek
Hi!
Documentation/leds/leds-class-multicolor.rst line 39
Quoted 13 lines
Documentation/leds/leds-class-multicolor.rst new file +13
-0+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 +-rw------- 1 root root 4096 Jun 28 20:21 color_mix + +colors/blue: +-rw------- 1 root root 4096 Jun 28 20:21 intensity +-r-------- 1 root root 4096 Jun 28 20:27 max_intensity +-r-------- 1 root root 4096 Jun 28 20:21 color_idI don't really like the directories... A bit too much complexity, and it will have a memory footprint, too.
We will need separate intensity files for each color anyway so separate max_brightness can go along in the sub-dir - it will be cleaner this way and will leave some flexibility regarding max intensity supported by the LED.
And I'm saying about the need for separate intensity files because I've changed my mind regarding color_mix file, basing on the recent experience with trigger file PAGE_SIZE limit rework. That said, I am no longer eager to accept any exception for one-value-per-file rule.
This of course render color_mix file format unacceptable. In a new approach intensity files will only cache the values and actual write to registers will occur on write to the brightness file.
Quoted 2 lines
I'd expect
max_intensityto be same for all the leds in rgb:grouped_leds... Could we simply rely onmax_brightnessfile?
This may not be necessarily true if one will add gpio LED to the cluster of PWM LEDs.
Quoted 7 lines
[If not, would one "
max_intensity" file in rgb:grouped_leds be enough?]Best regards,
Pavel
Signature · 2 lines
Best regards, Jacek Anaszewski
PATCH v5 3/9 dt: bindings: Add multicolor class dt bindings documention
In reply to Dan MurphyAdd DT bindings for the LEDs multicolor class framework.
--- .../bindings/leds/leds-class-multicolor.txt | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/leds-class-multicolor.txt
Documentation/devicetree/bindings/leds/leds-class-multicolor.txt new file +96 -0
@@ -0,0 +1,96 @@ +* 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 : 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_; + + + 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
Re: [PATCH v5 3/9] dt: bindings: Add multicolor class dt bindings documention
Dan,
This patch has the same issues I mentioned in the v4 review [0].
Quoted 101 lines · Dan Murphy
Add DT bindings for the LEDs multicolor class framework.
Signed-off-by Dan Murphy <[email protected]>--- .../bindings/leds/leds-class-multicolor.txt | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/leds-class-multicolor.txtDocumentation/devicetree/bindings/leds/leds-class-multicolor.txt new file +86
-0@@ -0,0 +1,96 @@ +* 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 : 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_; + + + 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>;
Documentation/devicetree/bindings/leds/leds-class-multicolor.txt line 96
Quoted 10 lines
Documentation/devicetree/bindings/leds/leds-class-multicolor.txt new file +10
-0+ color = <LED_COLOR_ID_GREEN>; + }; + + led@14 { + reg = <14>; + color = <LED_COLOR_ID_BLUE>; + }; + }; + +};
[0]
https://lore.kernel.org/linux-leds/[email protected]/
Signature · 2 lines
Best regards, Jacek Anaszewski
Re: [PATCH v5 3/9] dt: bindings: Add multicolor class dt bindings documention
Hello
Quoted 3 lines · Jacek Anaszewski
Dan,
This patch has the same issues I mentioned in the v4 review [0].
Sorry for that with all the rework done to this again the changes may have been lost.
I will update per v4 comments
Dan
Quoted 2 lines
PATCH v5 4/9 dt-bindings: leds: Add multicolor ID to the color ID list
In reply to Dan MurphyAdd a new color ID that is declared as MULTICOLOR as with the multicolor framework declaring a definitive color is not accurate as the node can contain multiple colors.
--- include/dt-bindings/leds/common.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
include/dt-bindings/leds/common.h +2 -1
@@ -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
PATCH v5 5/9 leds: Add multicolor ID to the color ID list
In reply to Dan MurphyAdd a new color ID that is declared as MULTICOLOR as with the multicolor framework declaring a definitive color is not accurate as the node can contain multiple colors.
--- drivers/leds/led-core.c | 1 + 1 file changed, 1 insertion(+)
drivers/leds/led-core.c +1 -0
@@ -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
PATCH v5 6/9 leds: multicolor: Introduce a multicolor class definition
In reply to Dan MurphyIntroduce 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 | 387 +++++++++++++++++++++++++++ include/linux/led-class-multicolor.h | 96 +++++++ 4 files changed, 494 insertions(+) create mode 100644 drivers/leds/led-class-multicolor.c create mode 100644 include/linux/led-class-multicolor.h
drivers/leds/Kconfig +10 -0
@@ -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
@@ -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 +387 -0
387 lines not on this page · raw message
include/linux/led-class-multicolor.h new file +96 -0
96 lines not on this page · raw message
Signature · 1 line
2.22.0.214.g8dca754b1e
Re: [PATCH v5 6/9] leds: multicolor: Introduce a multicolor class definition
Dan,
Quoted 60 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.
Signed-off-by Dan Murphy <[email protected]>--- drivers/leds/Kconfig | 10 + drivers/leds/Makefile | 1 + drivers/leds/led-class-multicolor.c | 387 +++++++++++++++++++++++++++ include/linux/led-class-multicolor.h | 96 +++++++ 4 files changed, 494 insertions(+) create mode 100644 drivers/leds/led-class-multicolor.c create mode 100644 include/linux/led-class-multicolor.hdrivers/leds/Kconfig +10
-0@@ -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_CLASSdrivers/leds/Makefile +1
-0@@ -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 Driversdrivers/leds/led-class-multicolor.c new file +4
-0@@ -0,0 +1,387 @@ +// SPDX-License-Identifier: GPL-2.0 +// LED Multi Color class interface +// Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/ +
drivers/leds/led-class-multicolor.c line 14
Quoted 10 lines
drivers/leds/led-class-multicolor.c new file +10
-0+#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_classdev_mc_priv {
I'd go for some more informative struct name here. And also this is not going to be main classdev struct so we can drop that from the name.
struct led_mc_color_entry ?
Quoted 9 lines
drivers/leds/led-class-multicolor.c new file +9
-0+struct led_classdev_mc *mcled_cdev; + +struct device_attribute max_intensity_attr; +struct device_attribute intensity_attr; +struct device_attribute color_index_attr; + +enum led_brightness max_intensity; +enum led_brightness intensity; +
drivers/leds/led-class-multicolor.c line 33
Quoted 10 lines
drivers/leds/led-class-multicolor.c new file +10
-0+struct list_head list; + +int led_color_id; +int color_seq_pos; +}; + +static int led_mc_calculate_brightness (int brightness,int intensity, +int max_intensity) +{ +if (brightness && intensity && max_intensity)
This check looks odd. I'd drop it entirely. One thing we could worry about would be max_intensity == 0 but this should be secured by the core on registration. Effectively I don't see the need for wrapping below calculation in a function at all.
drivers/leds/led-class-multicolor.c line 39
Quoted 6 lines
drivers/leds/led-class-multicolor.c new file +6
-0+return brightness * intensity / max_intensity; + +return LED_OFF ; +} + +void led_mc_set_cluster_brightness(struct led_classdev_mc *mcled_cdev,
We really don't set cluster brightness but calculate it only here (we can skip "cluster" as well):
s/led_mc_set_cluster_brightness/led_mc_calc_brightness/
drivers/leds/led-class-multicolor.c line 40
Quoted 1 line
drivers/leds/led-class-multicolor.c new file +1
-0+ enum led_brightness brightness, int adj_value[])
s/adj_value/brightness_val/
drivers/leds/led-class-multicolor.c line 49
Quoted 9 lines
drivers/leds/led-class-multicolor.c new file +9
-0+{ +struct led_classdev_mc_data *data = mcled_cdev->data; +struct led_classdev_mc_priv *priv; +int i =0 ; + +list_for_each_entry (priv, &data->color_list, list) { + adj_value[i] =led_mc_calculate_brightness (brightness, + priv->intensity, + priv->max_intensity);
brightness_val[i] = brightness * priv->intensity / priv->max_intensity;
drivers/leds/led-class-multicolor.c line 53
Quoted 4 lines
drivers/leds/led-class-multicolor.c new file +4
-0+ i++; + } + + data->cluster_brightness = brightness;
Why can't we use led_classdev_mc->led_cdev->brightness for storing cluster brightness?
Quoted 148 lines
drivers/leds/led-class-multicolor.c new file +148
-0+} + +void led_mc_get_cluster_brightness (struct led_classdev_mc *mcled_cdev, +int brightness_val[]) +{ +struct led_classdev_mc_data *data = mcled_cdev->data; +struct led_classdev_mc_priv *priv; +int i =0 ; + +list_for_each_entry (priv, &data->color_list, list) { + brightness_val[i] = priv->intensity; + i++; + } +} + +static ssize_t color_index_show (struct device *dev, +struct device_attribute *color_index_attr, +char *buf) +{ +struct led_classdev_mc_priv *priv =container_of (color_index_attr, + struct led_classdev_mc_priv, + color_index_attr); + +return sprintf (buf,"%d\n" , priv->led_color_id); +} + +static ssize_t color_mix_store (struct device *dev, +struct device_attribute *color_mix_attr, +const char *buf,size_t size) +{ +struct led_classdev_mc_data *data =container_of (color_mix_attr, + struct led_classdev_mc_data, + color_mix_attr); +struct led_classdev_mc *mcled_cdev = data->mcled_cdev; +struct led_classdev_mc_priv *priv; +unsigned int value[LED_COLOR_ID_MAX ]; +int nrchars, offset =0 ; +unsigned int i; +int ret; + +for (i =0 ; i < mcled_cdev->num_leds; i++) { + ret =sscanf (buf + offset,"%i%n" , &value[i], &nrchars); +if (ret !=1 ) +break ; + + offset += nrchars; + } + +if (i != mcled_cdev->num_leds) { +dev_err (dev,"Wrong number of LEDs defined %i, need %i\n" , + i, mcled_cdev->num_leds); +return -EINVAL ; + } + +list_for_each_entry (priv, &data->color_list, list) { + priv->intensity = value[priv->color_seq_pos]; +if (mcled_cdev->ops) { + ret = mcled_cdev->ops->set_color_brightness (mcled_cdev, + priv->led_color_id, + priv->intensity); +if (ret) + goto out; + } + } +out: +return size; +} + +static ssize_t intensity_store (struct device *dev, +struct device_attribute *intensity_attr, +const char *buf,size_t size) +{ +struct led_classdev_mc_priv *priv =container_of (intensity_attr, + struct led_classdev_mc_priv, + 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) { + 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); +if (ret) + goto unlock; + } + + ret = size; + +unlock: +mutex_unlock (&led_cdev->led_access); +return ret; +} + +static ssize_t intensity_show (struct device *dev, +struct device_attribute *intensity_attr, +char *buf) +{ +struct led_classdev_mc_priv *priv =container_of (intensity_attr, + struct led_classdev_mc_priv, + intensity_attr); +const struct led_multicolor_ops *ops = priv->mcled_cdev->ops; +int value =0 ; + +if (ops->get_color_brightness) { + value = ops->get_color_brightness (priv->mcled_cdev, + priv->led_color_id); + priv->intensity = value; + }else { + value = priv->intensity; + } + +return sprintf (buf,"%d\n" , value); +} + +static ssize_t max_intensity_show (struct device *dev, +struct device_attribute *max_intensity_attr, +char *buf) +{ +struct led_classdev_mc_priv *priv =container_of (max_intensity_attr, + struct led_classdev_mc_priv, + max_intensity_attr); + +return sprintf (buf,"%d\n" , priv->max_intensity); +} + +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_classdev_mc_priv *mc_priv; +int ret;
drivers/leds/led-class-multicolor.c line 211
Quoted 10 lines
drivers/leds/led-class-multicolor.c new file +10
-0+ + 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; + + data->led_kobj =kobject_create_and_add (led_colors[color_id], + data->color_kobj);
No change here since previous version? What prevents you from following what has been done for drivers/usb/core/ledtrig-usbport.c?
Use sysfs_create_group() for creating color dir and sysfs_add_file_to_group() for adding files to it.
Quoted 39 lines
drivers/leds/led-class-multicolor.c new file +39
-0+if (!data->led_kobj) +return -EINVAL ; + +sysfs_attr_init (&mc_priv->intensity_attr.attr); + mc_priv->intensity_attr.attr.name ="intensity" ; + mc_priv->intensity_attr.attr.mode =S_IRUGO |S_IWUGO ; + mc_priv->intensity_attr.store = intensity_store; + mc_priv->intensity_attr.show = intensity_show; + ret =sysfs_create_file (data->led_kobj, + &mc_priv->intensity_attr.attr); +if (ret) + goto err_out; + +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 =S_IRUGO ; + mc_priv->max_intensity_attr.show = max_intensity_show; + ret =sysfs_create_file (data->led_kobj, + &mc_priv->max_intensity_attr.attr); +if (ret) + goto err_out; + +sysfs_attr_init (&mc_priv->color_index_attr.attr); + mc_priv->color_index_attr.attr.name ="color_id" ; + mc_priv->color_index_attr.attr.mode =S_IRUGO ; + mc_priv->color_index_attr.show = color_index_show; + ret =sysfs_create_file (data->led_kobj, + &mc_priv->color_index_attr.attr); +if (ret) + goto err_out; + + mc_priv->max_intensity =LED_FULL ; + mc_priv->color_seq_pos = color_index; +list_add_tail (&mc_priv->list, &data->color_list); + +err_out: +return ret; +} +
drivers/leds/led-class-multicolor.c line 260
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);
Again: use sysfs_create_group().
Quoted 230 lines
drivers/leds/led-class-multicolor.c new file +127
-0+if (!data->color_kobj) +return -EINVAL ; + + data->mcled_cdev = mcled_cdev; + +for (i =0 ; i <LED_COLOR_ID_MAX ; i++) { + color_id = (mcled_cdev->available_colors & (1 << i)); +if (color_id) { + ret =led_multicolor_init_color (data, mcled_cdev, i, j); +if (ret) +break ; + + j++; + } + } + +sysfs_attr_init (&data->color_mix_attr.attr); + data->color_mix_attr.attr.name ="color_mix" ; + data->color_mix_attr.attr.mode =S_IRUGO |S_IWUGO ; + data->color_mix_attr.store = color_mix_store; + ret =sysfs_create_file (data->color_kobj, + &data->color_mix_attr.attr); + +return ret; +} + +int led_classdev_multicolor_register_ext (struct device *parent, +struct led_classdev_mc *mcled_cdev, +struct led_init_data *init_data) +{ +struct led_classdev *led_cdev; +struct led_classdev_mc_data *data; +int ret; + +if (!mcled_cdev) +return -EINVAL ; + + data =kzalloc (sizeof (*data),GFP_KERNEL ); +if (!data) +return -ENOMEM ; + + mcled_cdev->data = data; + led_cdev = mcled_cdev->led_cdev; +INIT_LIST_HEAD (&data->color_list); + +/* Register led class device */ + ret =led_classdev_register_ext (parent, led_cdev, init_data); +if (ret) +return ret; + +return led_multicolor_init_color_dir (data, mcled_cdev); +} +EXPORT_SYMBOL_GPL (led_classdev_multicolor_register_ext); + +void led_classdev_multicolor_unregister (struct led_classdev_mc *mcled_cdev) +{ +if (!mcled_cdev) +return ; + +led_classdev_unregister (mcled_cdev->led_cdev); +} +EXPORT_SYMBOL_GPL (led_classdev_multicolor_unregister); + +static void devm_led_classdev_multicolor_release (struct device *dev,void *res) +{ +led_classdev_multicolor_unregister (*(struct led_classdev_mc **)res); +} + +/** +* devm_of_led_classdev_register - resource managed led_classdev_register() +* +* @parent: parent of LED device +* @led_cdev: the led_classdev structure for this device. +*/ +int devm_led_classdev_multicolor_register (struct device *parent, +struct led_classdev_mc *mcled_cdev) +{ +struct led_classdev_mc **dr; +int ret; + + dr =devres_alloc (devm_led_classdev_multicolor_release, +sizeof (*dr),GFP_KERNEL ); +if (!dr) +return -ENOMEM ; + + ret =led_classdev_multicolor_register (parent, mcled_cdev); +if (ret) { +devres_free (dr); +return ret; + } + + *dr = mcled_cdev; +devres_add (parent, dr); + +return 0 ; +} +EXPORT_SYMBOL_GPL (devm_led_classdev_multicolor_register); + +static int devm_led_classdev_multicolor_match (struct device *dev, +void *res,void *data) +{ +struct mcled_cdev **p = res; + +if (WARN_ON (!p || !*p)) +return 0 ; + +return *p == data; +} + +/** +* devm_led_classdev_multicolor_unregister() - resource managed +* led_classdev_multicolor_unregister() +* @parent: The device to unregister. +* @mcled_cdev: the led_classdev_mc structure for this device. +*/ +void devm_led_classdev_multicolor_unregister (struct device *dev, +struct led_classdev_mc *mcled_cdev) +{ +WARN_ON (devres_release (dev, + devm_led_classdev_multicolor_release, + devm_led_classdev_multicolor_match, mcled_cdev)); +} +EXPORT_SYMBOL_GPL (devm_led_classdev_multicolor_unregister); + +MODULE_AUTHOR ("Dan Murphy <[email protected]>" ); +MODULE_DESCRIPTION ("Multi Color LED class interface" ); +MODULE_LICENSE ("GPL v2" );include/linux/led-class-multicolor.h new file +96
-0@@ -0,0 +1,96 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* LED Multicolor class interface +* Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/ +*/ + +#ifndef __LINUX_MULTICOLOR_LEDS_H_INCLUDED +#define __LINUX_MULTICOLOR_LEDS_H_INCLUDED + +#include <linux/leds.h> +#include <dt-bindings/leds/common.h> + +struct led_classdev_mc ; + +struct led_classdev_mc_data { +struct led_classdev_mc *mcled_cdev; + +struct kobject *color_kobj; +struct kobject *led_kobj; + +struct device_attribute color_mix_attr; + +struct list_head color_list; + +enum led_brightness cluster_brightness; +}; + +struct led_multicolor_ops { +/* Set brightness for a specific color id */ +int (*set_color_brightness)(struct led_classdev_mc *mcled_cdev, +int color_id,int value); +/* Read current color setting */ +int (*get_color_brightness)(struct led_classdev_mc *mcled_cdev, +int color_id); +}; + +struct led_classdev_mc { +/* led class device */ +struct led_classdev *led_cdev; + +/* multicolor led specific ops */ +struct led_multicolor_ops *ops; + +struct led_classdev_mc_data *data; + +unsigned long available_colors; +int num_leds; +}; + +static inline struct led_classdev_mc *lcdev_to_mccdev ( +struct led_classdev *lcdev) +{ + return container_of(lcdev, struct led_classdev_mc, led_cdev); +} + +/** +* led_classdev_multicolor_register_ext - register a new object of led_classdev +* class with support for multicolor LEDs +* @parent: the multicolor LED to register +* @mcled_cdev: the led_classdev_mc structure for this device +* @init_data: the LED class Multi color device initialization data +* +* Returns: 0 on success or negative error value on failure +*/ +extern int led_classdev_multicolor_register_ext (struct device *parent, +struct led_classdev_mc *mcled_cdev, +struct led_init_data *init_data); + +#define led_classdev_multicolor_register (parent, mcled_cdev) \ + led_classdev_multicolor_register_ext(parent, mcled_cdev, NULL) + +/** +* led_classdev_multicolor_unregister - unregisters an object of led_classdev +* class with support for multicolor LEDs +* @mcled_cdev: the multicolor LED to unregister +* +* Unregister a previously registered via led_classdev_multicolor_register +* object +*/ +extern void led_classdev_multicolor_unregister (struct led_classdev_mc *mcled_cdev); + +extern int devm_led_classdev_multicolor_register (struct device *parent, +struct led_classdev_mc *mcled_cdev); + +extern void devm_led_classdev_multicolor_unregister (struct device *parent, +struct led_classdev_mc *mcled_cdev); + +/* Set brightness for the monochrome LED cluster */ +extern void led_mc_set_cluster_brightness (struct led_classdev_mc *mcled_cdev, +enum led_brightness brightness, +int adj_value[]); + +/* Read current cluster brightness */ +extern void led_mc_get_cluster_brightness (struct led_classdev_mc *mcled_cdev, +int brightness_val[]); + +#endif /* __LINUX_MULTICOLOR_LEDS_H_INCLUDED */
Signature · 2 lines
Best regards, Jacek Anaszewski
Re: [PATCH v5 6/9] leds: multicolor: Introduce a multicolor class definition
Jacek
Quoted 77 lines · Jacek Anaszewski
Dan,
Quoted 60 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.
Signed-off-by Dan Murphy <[email protected]>--- drivers/leds/Kconfig | 10 + drivers/leds/Makefile | 1 + drivers/leds/led-class-multicolor.c | 387 +++++++++++++++++++++++++++ include/linux/led-class-multicolor.h | 96 +++++++ 4 files changed, 494 insertions(+)create mode 100644
drivers/leds/led-class-multicolor.ccreate mode 100644include/linux/led-class-multicolor.hdrivers/leds/Kconfig +10
-0@@ -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_CLASSdrivers/leds/Makefile +1
-0@@ -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 Driversdrivers/leds/led-class-multicolor.c new file +4
-0@@ -0,0 +1,387 @@ +// SPDX-License-Identifier: GPL-2.0 +// LED Multi Color class interface +// Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/ +drivers/leds/led-class-multicolor.c line 14
Quoted 10 lines
drivers/leds/led-class-multicolor.c new file +10
-0+#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_classdev_mc_priv {I'd go for some more informative struct name here. And also this is not going to be main classdev struct so we can drop that from the name.
Quoted 1 line
struct
led_mc_color_entry?
That would probably be better as a name.
Quoted 16 lines
Quoted 16 lines
drivers/leds/led-class-multicolor.c new file +15
-0+struct led_classdev_mc *mcled_cdev; + +struct device_attribute max_intensity_attr; +struct device_attribute intensity_attr; +struct device_attribute color_index_attr; + +enum led_brightness max_intensity; +enum led_brightness intensity; + +struct list_head list; + +int led_color_id; +int color_seq_pos; +}; +
Quoted 8 lines
drivers/leds/led-class-multicolor.c line 33
Quoted 4 lines
drivers/leds/led-class-multicolor.c new file +4
-0+static int led_mc_calculate_brightness (int brightness,int intensity, +int max_intensity) +{ +if (brightness && intensity && max_intensity)This check looks odd. I'd drop it entirely. One thing we could worry about would be
max_intensity== 0 but this should be secured by the core on registration. Effectively I don't see the need for wrapping below calculation in a function at all.
This was made into a function when I had the intensity and color_mix
files writing the values. This is no longer needed as a function.
Quoted 11 lines
drivers/leds/led-class-multicolor.c line 39
Quoted 7 lines
drivers/leds/led-class-multicolor.c new file +6
-0+return brightness * intensity / max_intensity; + +return LED_OFF ; +} + +void led_mc_set_cluster_brightness(struct led_classdev_mc *mcled_cdev,We really don't set cluster brightness but calculate it only here (we can skip "cluster" as well):
Quoted 1 line
s/led_mc_set_cluster_brightness/led_mc_calc_brightness/
Ack
Quoted 3 lines
drivers/leds/led-class-multicolor.c line 40
Quoted 2 lines
drivers/leds/led-class-multicolor.c new file +1
-0+ enum led_brightness brightness, int adj_value[])s/adj_value/brightness_val/
Ack
Quoted 11 lines
drivers/leds/led-class-multicolor.c line 49
Quoted 10 lines
drivers/leds/led-class-multicolor.c new file +9
-0+{ +struct led_classdev_mc_data *data = mcled_cdev->data; +struct led_classdev_mc_priv *priv; +int i =0 ; + +list_for_each_entry (priv, &data->color_list, list) { + adj_value[i] =led_mc_calculate_brightness (brightness, + priv->intensity, + priv->max_intensity);brightness_val[i] = brightness *
priv->intensity/priv->max_intensity;
Ack
Quoted 7 lines
drivers/leds/led-class-multicolor.c line 53
Quoted 5 lines
drivers/leds/led-class-multicolor.c new file +4
-0+ i++; + } + + data->cluster_brightness = brightness;Why can't we use
led_classdev_mc->led_cdev->brightnessfor storing cluster brightness?
We could probably drop this altogether as I think you pointed out before.
Quoted 162 lines
Quoted 149 lines
drivers/leds/led-class-multicolor.c new file +148
-0+} + +void led_mc_get_cluster_brightness (struct led_classdev_mc *mcled_cdev, +int brightness_val[]) +{ +struct led_classdev_mc_data *data = mcled_cdev->data; +struct led_classdev_mc_priv *priv; +int i =0 ; + +list_for_each_entry (priv, &data->color_list, list) { + brightness_val[i] = priv->intensity; + i++; + } +} + +static ssize_t color_index_show (struct device *dev, +struct device_attribute *color_index_attr, +char *buf) +{ +struct led_classdev_mc_priv *priv =container_of (color_index_attr, + struct led_classdev_mc_priv, + color_index_attr); + +return sprintf (buf,"%d\n" , priv->led_color_id); +} + +static ssize_t color_mix_store (struct device *dev, +struct device_attribute *color_mix_attr, +const char *buf,size_t size) +{ +struct led_classdev_mc_data *data =container_of (color_mix_attr, + struct led_classdev_mc_data, + color_mix_attr); +struct led_classdev_mc *mcled_cdev = data->mcled_cdev; +struct led_classdev_mc_priv *priv; +unsigned int value[LED_COLOR_ID_MAX ]; +int nrchars, offset =0 ; +unsigned int i; +int ret; + +for (i =0 ; i < mcled_cdev->num_leds; i++) { + ret =sscanf (buf + offset,"%i%n" , &value[i], &nrchars); +if (ret !=1 ) +break ; + + offset += nrchars; + } + +if (i != mcled_cdev->num_leds) { +dev_err (dev,"Wrong number of LEDs defined %i, need %i\n" , + i, mcled_cdev->num_leds); +return -EINVAL ; + } + +list_for_each_entry (priv, &data->color_list, list) { + priv->intensity = value[priv->color_seq_pos]; +if (mcled_cdev->ops) { + ret = mcled_cdev->ops->set_color_brightness (mcled_cdev, + priv->led_color_id, + priv->intensity); +if (ret) + goto out; + } + } +out: +return size; +} + +static ssize_t intensity_store (struct device *dev, +struct device_attribute *intensity_attr, +const char *buf,size_t size) +{ +struct led_classdev_mc_priv *priv =container_of (intensity_attr, + struct led_classdev_mc_priv, + 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) { + 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); +if (ret) + goto unlock; + } + + ret = size; + +unlock: +mutex_unlock (&led_cdev->led_access); +return ret; +} + +static ssize_t intensity_show (struct device *dev, +struct device_attribute *intensity_attr, +char *buf) +{ +struct led_classdev_mc_priv *priv =container_of (intensity_attr, + struct led_classdev_mc_priv, + intensity_attr); +const struct led_multicolor_ops *ops = priv->mcled_cdev->ops; +int value =0 ; + +if (ops->get_color_brightness) { + value = ops->get_color_brightness (priv->mcled_cdev, + priv->led_color_id); + priv->intensity = value; + }else { + value = priv->intensity; + } + +return sprintf (buf,"%d\n" , value); +} + +static ssize_t max_intensity_show (struct device *dev, +struct device_attribute *max_intensity_attr, +char *buf) +{ +struct led_classdev_mc_priv *priv =container_of (max_intensity_attr, + struct led_classdev_mc_priv, + max_intensity_attr); + +return sprintf (buf,"%d\n" , priv->max_intensity); +} + +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_classdev_mc_priv *mc_priv; +int ret;drivers/leds/led-class-multicolor.c line 211
Quoted 10 lines
drivers/leds/led-class-multicolor.c new file +10
-0+ + 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; + + data->led_kobj =kobject_create_and_add (led_colors[color_id], + data->color_kobj);No change here since previous version? What prevents you from following what has been done for
drivers/usb/core/ledtrig-usbport.c?
Quoted 2 lines
Use
sysfs_create_group()for creating color dir andsysfs_add_file_to_group()for adding files to it.
Yet another change I missed.
I am hoping we can actually nail this down for 5.5. So many changes and versions to this.
Dan
Quoted 283 lines
Quoted 41 lines
drivers/leds/led-class-multicolor.c new file +39
-0+if (!data->led_kobj) +return -EINVAL ; + +sysfs_attr_init (&mc_priv->intensity_attr.attr); + mc_priv->intensity_attr.attr.name ="intensity" ; + mc_priv->intensity_attr.attr.mode =S_IRUGO |S_IWUGO ; + mc_priv->intensity_attr.store = intensity_store; + mc_priv->intensity_attr.show = intensity_show; + ret =sysfs_create_file (data->led_kobj, + &mc_priv->intensity_attr.attr); +if (ret) + goto err_out; + +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 =S_IRUGO ; + mc_priv->max_intensity_attr.show = max_intensity_show; + ret =sysfs_create_file (data->led_kobj, + &mc_priv->max_intensity_attr.attr); +if (ret) + goto err_out; + +sysfs_attr_init (&mc_priv->color_index_attr.attr); + mc_priv->color_index_attr.attr.name ="color_id" ; + mc_priv->color_index_attr.attr.mode =S_IRUGO ; + mc_priv->color_index_attr.show = color_index_show; + ret =sysfs_create_file (data->led_kobj, + &mc_priv->color_index_attr.attr); +if (ret) + goto err_out; + + mc_priv->max_intensity =LED_FULL ; + mc_priv->color_seq_pos = color_index; +list_add_tail (&mc_priv->list, &data->color_list); + +err_out: +return ret; +} +drivers/leds/led-class-multicolor.c line 260
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);Again: use
sysfs_create_group().Quoted 230 lines
drivers/leds/led-class-multicolor.c new file +127
-0+if (!data->color_kobj) +return -EINVAL ; + + data->mcled_cdev = mcled_cdev; + +for (i =0 ; i <LED_COLOR_ID_MAX ; i++) { + color_id = (mcled_cdev->available_colors & (1 << i)); +if (color_id) { + ret =led_multicolor_init_color (data, mcled_cdev, i, j); +if (ret) +break ; + + j++; + } + } + +sysfs_attr_init (&data->color_mix_attr.attr); + data->color_mix_attr.attr.name ="color_mix" ; + data->color_mix_attr.attr.mode =S_IRUGO |S_IWUGO ; + data->color_mix_attr.store = color_mix_store; + ret =sysfs_create_file (data->color_kobj, + &data->color_mix_attr.attr); + +return ret; +} + +int led_classdev_multicolor_register_ext (struct device *parent, +struct led_classdev_mc *mcled_cdev, +struct led_init_data *init_data) +{ +struct led_classdev *led_cdev; +struct led_classdev_mc_data *data; +int ret; + +if (!mcled_cdev) +return -EINVAL ; + + data =kzalloc (sizeof (*data),GFP_KERNEL ); +if (!data) +return -ENOMEM ; + + mcled_cdev->data = data; + led_cdev = mcled_cdev->led_cdev; +INIT_LIST_HEAD (&data->color_list); + +/* Register led class device */ + ret =led_classdev_register_ext (parent, led_cdev, init_data); +if (ret) +return ret; + +return led_multicolor_init_color_dir (data, mcled_cdev); +} +EXPORT_SYMBOL_GPL (led_classdev_multicolor_register_ext); + +void led_classdev_multicolor_unregister (struct led_classdev_mc *mcled_cdev) +{ +if (!mcled_cdev) +return ; + +led_classdev_unregister (mcled_cdev->led_cdev); +} +EXPORT_SYMBOL_GPL (led_classdev_multicolor_unregister); + +static void devm_led_classdev_multicolor_release (struct device *dev,void *res) +{ +led_classdev_multicolor_unregister (*(struct led_classdev_mc **)res); +} + +/** +* devm_of_led_classdev_register - resource managed led_classdev_register() +* +* @parent: parent of LED device +* @led_cdev: the led_classdev structure for this device. +*/ +int devm_led_classdev_multicolor_register (struct device *parent, +struct led_classdev_mc *mcled_cdev) +{ +struct led_classdev_mc **dr; +int ret; + + dr =devres_alloc (devm_led_classdev_multicolor_release, +sizeof (*dr),GFP_KERNEL ); +if (!dr) +return -ENOMEM ; + + ret =led_classdev_multicolor_register (parent, mcled_cdev); +if (ret) { +devres_free (dr); +return ret; + } + + *dr = mcled_cdev; +devres_add (parent, dr); + +return 0 ; +} +EXPORT_SYMBOL_GPL (devm_led_classdev_multicolor_register); + +static int devm_led_classdev_multicolor_match (struct device *dev, +void *res,void *data) +{ +struct mcled_cdev **p = res; + +if (WARN_ON (!p || !*p)) +return 0 ; + +return *p == data; +} + +/** +* devm_led_classdev_multicolor_unregister() - resource managed +* led_classdev_multicolor_unregister() +* @parent: The device to unregister. +* @mcled_cdev: the led_classdev_mc structure for this device. +*/ +void devm_led_classdev_multicolor_unregister (struct device *dev, +struct led_classdev_mc *mcled_cdev) +{ +WARN_ON (devres_release (dev, + devm_led_classdev_multicolor_release, + devm_led_classdev_multicolor_match, mcled_cdev)); +} +EXPORT_SYMBOL_GPL (devm_led_classdev_multicolor_unregister); + +MODULE_AUTHOR ("Dan Murphy <[email protected]>" ); +MODULE_DESCRIPTION ("Multi Color LED class interface" ); +MODULE_LICENSE ("GPL v2" );include/linux/led-class-multicolor.h new file +96
-0@@ -0,0 +1,96 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* LED Multicolor class interface +* Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/ +*/ + +#ifndef __LINUX_MULTICOLOR_LEDS_H_INCLUDED +#define __LINUX_MULTICOLOR_LEDS_H_INCLUDED + +#include <linux/leds.h> +#include <dt-bindings/leds/common.h> + +struct led_classdev_mc ; + +struct led_classdev_mc_data { +struct led_classdev_mc *mcled_cdev; + +struct kobject *color_kobj; +struct kobject *led_kobj; + +struct device_attribute color_mix_attr; + +struct list_head color_list; + +enum led_brightness cluster_brightness; +}; + +struct led_multicolor_ops { +/* Set brightness for a specific color id */ +int (*set_color_brightness)(struct led_classdev_mc *mcled_cdev, +int color_id,int value); +/* Read current color setting */ +int (*get_color_brightness)(struct led_classdev_mc *mcled_cdev, +int color_id); +}; + +struct led_classdev_mc { +/* led class device */ +struct led_classdev *led_cdev; + +/* multicolor led specific ops */ +struct led_multicolor_ops *ops; + +struct led_classdev_mc_data *data; + +unsigned long available_colors; +int num_leds; +}; + +static inline struct led_classdev_mc *lcdev_to_mccdev ( +struct led_classdev *lcdev) +{ + return container_of(lcdev, struct led_classdev_mc, led_cdev); +} + +/** +* led_classdev_multicolor_register_ext - register a new object of led_classdev +* class with support for multicolor LEDs +* @parent: the multicolor LED to register +* @mcled_cdev: the led_classdev_mc structure for this device +* @init_data: the LED class Multi color device initialization data +* +* Returns: 0 on success or negative error value on failure +*/ +extern int led_classdev_multicolor_register_ext (struct device *parent, +struct led_classdev_mc *mcled_cdev, +struct led_init_data *init_data); + +#define led_classdev_multicolor_register (parent, mcled_cdev) \ + led_classdev_multicolor_register_ext(parent, mcled_cdev, NULL) + +/** +* led_classdev_multicolor_unregister - unregisters an object of led_classdev +* class with support for multicolor LEDs +* @mcled_cdev: the multicolor LED to unregister +* +* Unregister a previously registered via led_classdev_multicolor_register +* object +*/ +extern void led_classdev_multicolor_unregister (struct led_classdev_mc *mcled_cdev); + +extern int devm_led_classdev_multicolor_register (struct device *parent, +struct led_classdev_mc *mcled_cdev); + +extern void devm_led_classdev_multicolor_unregister (struct device *parent, +struct led_classdev_mc *mcled_cdev); + +/* Set brightness for the monochrome LED cluster */ +extern void led_mc_set_cluster_brightness (struct led_classdev_mc *mcled_cdev, +enum led_brightness brightness, +int adj_value[]); + +/* Read current cluster brightness */ +extern void led_mc_get_cluster_brightness (struct led_classdev_mc *mcled_cdev, +int brightness_val[]); + +#endif /* __LINUX_MULTICOLOR_LEDS_H_INCLUDED */
Re: [PATCH v5 6/9] leds: multicolor: Introduce a multicolor class definition
In reply to Jacek AnaszewskiJacek
Quoted 22 lines · Jacek Anaszewski
Quoted 9 lines
drivers/leds/led-class-multicolor.c new file +8
-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_classdev_mc_priv *mc_priv; +int ret;drivers/leds/led-class-multicolor.c line 211
Quoted 10 lines
drivers/leds/led-class-multicolor.c new file +10
-0+ + 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; + + data->led_kobj =kobject_create_and_add (led_colors[color_id], + data->color_kobj);No change here since previous version? What prevents you from following what has been done for
drivers/usb/core/ledtrig-usbport.c?
Quoted 2 lines
Use
sysfs_create_group()for creating color dir andsysfs_add_file_to_group()for adding files to it.
We have nested directories here. colors is a directory and then the LED color is a directory.
So I am not sure how to create a group under another group without the colors directory kobj.
Wondering if you know of any examples?
Dan
Re: [PATCH v5 6/9] leds: multicolor: Introduce a multicolor class definition
Quoted 29 lines · Dan Murphy
Jacek
Quoted 23 lines · Jacek Anaszewski
Quoted 14 lines
drivers/leds/led-class-multicolor.c new file +10
-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_classdev_mc_priv *mc_priv; + int ret; + + mc_priv = devm_kzalloc(led_cdev->dev, sizeof(*mc_priv),
GFP_KERNEL);
+ if (!mc_priv)
+ return-ENOMEM;drivers/leds/led-class-multicolor.c line 211
Quoted 6 lines
drivers/leds/led-class-multicolor.c new file +6
-0+ + mc_priv->led_color_id = color_id; + mc_priv->mcled_cdev = mcled_cdev; + + data->led_kobj = kobject_create_and_add(led_colors[color_id], + data->color_kobj);No change here since previous version? What prevents you from following what has been done for
drivers/usb/core/ledtrig-usbport.c?Quoted 2 lines
Use
sysfs_create_group()for creating color dir andsysfs_add_file_to_group()for adding files to it.
Quoted 7 lines
We have nested directories here. colors is a directory and then the LED color is a directory.
So I am not sure how to create a group under another group without the colors directory kobj.
Wondering if you know of any examples?
Hmm, that indeed seems not to be allowed. kobject_create_and_add() seems to be the only solution to achieve nested directories. Nonetheless we will have to first justify the need for that to Greg.
Signature · 2 lines
Best regards, Jacek Anaszewski
PATCH v5 7/9 dt: bindings: lp50xx: Introduce the lp50xx family of RGB drivers
In reply to Dan MurphyIntroduce the bindings for the Texas Instruments LP5036, LP5030, LP5024, LP5018, LP5012 and LP5009 RGB LED device driver. The LP5036/30/24/18/12/9 can control RGB LEDs individually or as part of a control bank group. These devices have the ability to adjust the mixing control for the RGB LEDs to obtain different colors independent of the overall brightness of the LED grouping.
Datasheet:
http://www.ti.com/lit/ds/symlink/lp5012.pdf
http://www.ti.com/lit/ds/symlink/lp5024.pdf
http://www.ti.com/lit/ds/symlink/lp5036.pdf
--- .../devicetree/bindings/leds/leds-lp50xx.txt | 148 ++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/leds-lp50xx.txt
Documentation/devicetree/bindings/leds/leds-lp50xx.txt new file +148 -0
@@ -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
PATCH v5 8/9 leds: lp50xx: Add the LP50XX family of the RGB LED driver
In reply to Dan MurphyIntroduce 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.
--- 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
@@ -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
@@ -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
PATCH v5 9/9 leds: Update the lp55xx to use the multi color framework
In reply to Dan MurphyUpdate the lp5523 to use the multi color framework.
--- 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 + modules.builtin.modinfo | Bin 0 -> 43550 bytes 5 files changed, 137 insertions(+), 22 deletions(-) create mode 100644 modules.builtin.modinfo
drivers/leds/leds-lp5523.c +13 -0
@@ -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
@@ -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
@@ -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 {
modules.builtin.modinfo new file binary +0 -0
Signature · 1 line
2.22.0.214.g8dca754b1e
Re: [PATCH v5 9/9] leds: Update the lp55xx to use the multi color framework
Hi Dan,
Quoted 19 lines · Dan Murphy
Update the lp5523 to use the multi color framework.
Signed-off-by Dan Murphy <[email protected]>--- 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 + modules.builtin.modinfo | Bin 0 -> 43550 bytes 5 files changed, 137 insertions(+), 22 deletions(-) create mode 100644 modules.builtin.modinfodrivers/leds/leds-lp5523.c +0
-0@@ -791,6 +791,18 @@ static ssize_t store_master_fader_leds(struct device *dev,return ret; }
[...]
Quoted 1 line
struct
lp55xx_predef_pattern{
Below file seems to have been added to the index by mistake.
Quoted 9 lines
modules.builtin.modinfo new file binary +0
-0
[...]
Signature · 2 lines
Best regards, Jacek Anaszewski
Re: [PATCH v5 9/9] leds: Update the lp55xx to use the multi color framework
Quoted 23 lines · Jacek Anaszewski
Hi Dan,
Quoted 19 lines · Dan Murphy
Update the lp5523 to use the multi color framework.
Signed-off-by Dan Murphy <[email protected]>--- 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 + modules.builtin.modinfo | Bin 0 -> 43550 bytes 5 files changed, 137 insertions(+), 22 deletions(-)create mode 100644 modules.builtin.modinfo
drivers/leds/leds-lp5523.c +0
-0@@ -791,6 +791,18 @@ static ssize_t store_master_fader_leds(struct device *dev,return ret; }[...]
Quoted 3 lines
Quoted 1 line
struct lp55xx_predef_pattern {Below file seems to have been added to the index by mistake.
I will remove it
Dan
Quoted 11 lines
Quoted 9 lines
modules.builtin.modinfo new file binary +0
-0[...]