mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-08-28 18:05:00 -04:00
Some multicolor LEDs support global brightness control in hardware, meaning that the maximum intensity of the color components is not connected to the maximum global brightness. Such LEDs cannot be described properly by the current multicolor LED class interface, because it assumes that the maximum intensity of each color component is described by the maximum global brightness of the LED. Fix this by introducing a new sysfs attribute called "multi_max_intensity" holding the maximum intensity values for the color components of a multicolor LED class device. Drivers can use the new max_intensity field inside struct mc_subled to tell the multicolor LED class code about those values. Intensity values written by userspace applications will be limited to this maximum value. Drivers for multicolor LEDs that do not support global brightness control in hardware might still want to use the maximum global LED brightness supplied via devicetree as the maximum intensity of each individual color component. Such drivers should set max_intensity to 0 so that the multicolor LED core can act accordingly. The lp50xx and ncp5623 LED drivers already use hardware-based control for the global LED brightness. Modify those drivers to correctly initalize .max_intensity to avoid being limited to the maximum global brightness supplied via devicetree. Reviewed-by: Werner Sembach <wse@tuxedocomputers.com> Reviewed-by: Jacek Anaszewski <jacek.anaszewski@gmail.com> Signed-off-by: Armin Wolf <W_Armin@gmx.de> Link: https://patch.msgid.link/20260509214603.262368-2-W_Armin@gmx.de Signed-off-by: Lee Jones <lee@kernel.org>
126 lines
4.0 KiB
ReStructuredText
126 lines
4.0 KiB
ReStructuredText
.. SPDX-License-Identifier: GPL-2.0
|
|
|
|
====================================
|
|
Multicolor LED handling under Linux
|
|
====================================
|
|
|
|
Description
|
|
===========
|
|
The multicolor class groups monochrome LEDs and allows controlling two
|
|
aspects of the final combined color: hue and lightness. The former is
|
|
controlled via the multi_intensity array file and the latter is controlled
|
|
via brightness file.
|
|
|
|
Multicolor Class Control
|
|
========================
|
|
The multicolor class presents files that groups the colors as indexes in an
|
|
array. These files are children under the LED parent node created by the
|
|
led_class framework. The led_class framework is documented in led-class.rst
|
|
within this documentation directory.
|
|
|
|
Each colored LED will be indexed under the ``multi_*`` files. The order of the
|
|
colors will be arbitrary. The ``multi_index`` file can be read to determine the
|
|
color name to indexed value.
|
|
|
|
The ``multi_index`` file is an array that contains the string list of the colors as
|
|
they are defined in each ``multi_*`` array file.
|
|
|
|
The ``multi_intensity`` file is an array that can be read or written to for the
|
|
individual color intensities. All elements within this array must be written in
|
|
order for the color LED intensities to be updated.
|
|
|
|
The ``multi_max_intensity`` file is an array that contains the maximum intensity
|
|
value supported by each color intensity. Intensity values above this will be
|
|
automatically clamped into the supported range.
|
|
|
|
Directory Layout Example
|
|
========================
|
|
.. code-block:: console
|
|
|
|
root:/sys/class/leds/multicolor:status# ls -lR
|
|
-rw-r--r-- 1 root root 4096 Oct 19 16:16 brightness
|
|
-r--r--r-- 1 root root 4096 Oct 19 16:16 max_brightness
|
|
-r--r--r-- 1 root root 4096 Oct 19 16:16 multi_index
|
|
-rw-r--r-- 1 root root 4096 Oct 19 16:16 multi_intensity
|
|
-r--r--r-- 1 root root 4096 Oct 19 16:16 multi_max_intensity
|
|
|
|
..
|
|
|
|
Multicolor Class Brightness Control
|
|
===================================
|
|
The brightness level for each LED is calculated based on the color LED
|
|
intensity setting divided by the global max_brightness setting multiplied by
|
|
the requested brightness.
|
|
|
|
``led_brightness = brightness * multi_intensity/max_brightness``
|
|
|
|
Example:
|
|
A user first writes the multi_intensity file with the brightness levels
|
|
for each LED that are necessary to achieve a certain color output from a
|
|
multicolor LED group.
|
|
|
|
.. code-block:: console
|
|
|
|
# cat /sys/class/leds/multicolor:status/multi_index
|
|
green blue red
|
|
|
|
# echo 43 226 138 > /sys/class/leds/multicolor:status/multi_intensity
|
|
|
|
red -
|
|
intensity = 138
|
|
max_brightness = 255
|
|
green -
|
|
intensity = 43
|
|
max_brightness = 255
|
|
blue -
|
|
intensity = 226
|
|
max_brightness = 255
|
|
|
|
..
|
|
|
|
The user can control the brightness of that multicolor LED group by writing the
|
|
global 'brightness' control. Assuming a max_brightness of 255 the user
|
|
may want to dim the LED color group to half. The user would write a value of
|
|
128 to the global brightness file then the values written to each LED will be
|
|
adjusted base on this value.
|
|
|
|
.. code-block:: console
|
|
|
|
# cat /sys/class/leds/multicolor:status/max_brightness
|
|
255
|
|
# echo 128 > /sys/class/leds/multicolor:status/brightness
|
|
|
|
..
|
|
|
|
.. code-block:: none
|
|
|
|
adjusted_red_value = 128 * 138/255 = 69
|
|
adjusted_green_value = 128 * 43/255 = 21
|
|
adjusted_blue_value = 128 * 226/255 = 113
|
|
|
|
..
|
|
|
|
Reading the global brightness file will return the current brightness value of
|
|
the color LED group.
|
|
|
|
.. code-block:: console
|
|
|
|
# cat /sys/class/leds/multicolor:status/brightness
|
|
128
|
|
|
|
..
|
|
|
|
Writing intensity values larger than the maximum specified in ``multi_max_intensity``
|
|
will result in those values being clamped into the supported range.
|
|
|
|
.. code-block:: console
|
|
|
|
# cat /sys/class/leds/multicolor:status/multi_max_intensity
|
|
255 255 255
|
|
|
|
# echo 512 512 512 > /sys/class/leds/multicolor:status/multi_intensity
|
|
# cat /sys/class/leds/multicolor:status/multi_intensity
|
|
255 255 255
|
|
|
|
..
|