Re: [PATCH v19 04/18] leds: multicolor: Introduce a multicolor class definition

From: Dan Murphy
Date: Wed Apr 08 2020 - 12:39:10 EST


Jacek

On 4/7/20 4:08 PM, Jacek Anaszewski wrote:
Dan,

One more nit below.

On 4/2/20 10:42 PM, Dan Murphy wrote:
Introduce a multicolor class that groups colored LEDs
within a LED node.

The multi color class groups monochrome LEDs and allows controlling two
aspects of the final combined color: hue and lightness. The former is
controlled via <color>_intensity files and the latter is controlled
via brightness file.
[...]
# LED Platform Drivers
diff --git a/drivers/leds/led-class-multicolor.c b/drivers/leds/led-class-multicolor.c
new file mode 100644
index 000000000000..838b1d679647
--- /dev/null
+++ b/drivers/leds/led-class-multicolor.c
@@ -0,0 +1,206 @@
+// SPDX-License-Identifier: GPL-2.0
+// LED Multi Color class interface
+// Copyright (C) 2019-20 Texas Instruments Incorporated - http://www.ti.com/
+// Author: Dan Murphy <dmurphy@xxxxxx>
+
+#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"
+
+int led_mc_calc_color_components(struct led_classdev_mc *mcled_cdev,
+ enum led_brightness brightness)
+{
+ struct led_classdev *led_cdev = &mcled_cdev->led_cdev;
+ int i;
+
+ for (i = 0; i < mcled_cdev->num_colors; i++)
+ mcled_cdev->multicolor_info[i].color_brightness = (brightness *
If you passed temporary array for collecting calculated brightness
items to this function then you could remove this color_brightness
field from struct multicolor_info.

I thought about doing it that way but I liked how each LEDs properties were stored in a single element in the array.

There would be no issues with referencing the array element and knowing everything about the specific LED like the

intensity, brightness, output channel and ID.ÂÂ This eliminates any need for a channel map or mapping brightness to IDs or channels.

Dan