Skip to content

base-files: support parse DT LED color and function - #13837

Closed
DragonBluep wants to merge 2 commits into
openwrt:mainfrom
DragonBluep:dt-led
Closed

DragonBluep wants to merge 2 commits into
openwrt:mainfrom
DragonBluep:dt-led

Conversation

@DragonBluep

Copy link
Copy Markdown
Contributor

The 'label' property in led node has been deprecated and we'd better to avoid using it. This patch allows us to extract DT OF LED name from the newly introduced LED properties "color", "function" and "function-enumerator".

@github-actions github-actions Bot added kernel pull request/issue with Linux kernel related changes core packages pull request/issue for core (in-tree) packages labels Oct 31, 2023
@DragonBluep

Copy link
Copy Markdown
Contributor Author

Hi! @csharper2005 Perhaps you are interested in these patches. I think we can finally remove all LED labels from the device tree (include those referenced in aliases node).

#define LED_FUNCTION_FLASH "flash"
#define LED_FUNCTION_HEARTBEAT "heartbeat"
#define LED_FUNCTION_INDICATOR "indicator"
+#define LED_FUNCTION_INTERNET "internet"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another function that makes sense IMHO to have is cellular connectivity (LTE, 5G, etc).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The patch has already been sent to the mailing list so we need another patch to add it. I think it can be later.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice also get mesh function.

+#define LED_FUNCTION_MESH "mesh"

@DragonBluep

Copy link
Copy Markdown
Contributor Author

The pending patch should not be difficult to accept, although it may take some time.
https://lore.kernel.org/all/CAL_JsqKxi1KiieGzmY4emQ0DRc5eXtHmQJBrre6mr6pAm6NFjA@mail.gmail.com/

This PR can be reviewed now.

@raenye

raenye commented Nov 6, 2023 •

Copy link
Copy Markdown
Contributor

(edited the entire message, mostly reordering sentences)

These are two unrelated commits. Why have a combined PR for both?

The main commit is specific to OpenWrt, and is required to drop the label property from several (all?) DTS LEDs.
I think it should be merged ASAP (and I have no comments about it).

The other commit is an upstream patch, and should address IMHO the other missing function (cellular/modem/LTE/5g) too, so I sent a message to the kernel mailing list about these.
Also, I fail to see the difference between amber and orange, as well as violet and purple (despite upstream accepting these changes long ago).

@DragonBluep

Copy link
Copy Markdown
Contributor Author

(edited the entire message, mostly reordering sentences)

These are two unrelated commits. Why have a combined PR for both?

We have to sync the LED colors with the upstream to ensure that we don't need to edit this script again. It unlikely to add any new colors.

The main commit is specific to OpenWrt, and is required to drop the label property from several (all?) DTS LEDs. I think it should be merged ASAP (and I have no comments about it).

The other commit is an upstream patch, and should address IMHO the other missing function (cellular/modem/LTE/5g) too, so I sent a message to the kernel mailing list about these.

If reviewers say it's okay, I'd like to extend the patch to include more functions.

Also, I fail to see the difference between amber and orange, as well as violet and purple (despite upstream accepting these changes long ago).

If red > yellow, It's amber, else orange. Purple is the mixture of the blue and red. Violet is the pure 'purple'. All monochrome LEDs are violet. Anyway, they are not very different.

@raenye

raenye commented Nov 7, 2023 •

Copy link
Copy Markdown
Contributor

We have to sync the LED colors with the upstream to ensure that we don't need to edit this script again. It unlikely to add any new colors.

This PR is fine by me then.

If reviewers say it's okay, I'd like to extend the patch to include more functions.

I messed up with the email (responded to an earlier version of the patch, and used gmail so did not respect the thread order) so it will probably be ignored :/

If red > yellow, It's amber, else orange. Purple is the mixture of the blue and red. Violet is the pure 'purple'. All monochrome LEDs are violet. Anyway, they are not very different.

This is defined anywhere? I'm just thinking of people adding support for LEDs in the future, and picking a color at random.

drivers/leds/led-core.c | 5 +++++
1 file changed, 5 insertions(+)

(limited to 'drivers/leds/led-core.c')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please generate this from the full commit

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. The diff parts are the same. torvalds/linux@a067943

Openwrt supports hundreds of devices. These newly added LED colors
and functions can help developers better describe LED indicators.

Signed-off-by: Shiji Yang <[email protected]>
"purple" "orange" "pink" "cyan" "lime"
do
[ $idx -eq 0 ] && label="$color" && break
idx=$(($idx-1))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shellchecker found this.

idx=$(($idx-1))
       ^-- [SC2004](https://www.shellcheck.net/wiki/SC2004) (style): $/${} is unnecessary on arithmetic variables.
``

[ -e "$1/function-enumerator" ] && \
enum=$((0x$(hexdump -n 4 -e '4/1 "%02x"' "$1/function-enumerator")))

[ -z "$idx" -o -z "$func" ] && return 2

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shellchecker:

[ -z "$idx" -o -z "$func" ] && return 2
            ^-- [SC2166](https://www.shellcheck.net/wiki/SC2166) (warning): Prefer [ p ] || [ q ] as [ p -o q ] is not well defined.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your review. I searched the Linux led code and found that one of function and color property could be missing. So I changed some logic to match this behavior. I haven't tested the new changes yet, but it shouldn't have introduced any other errors.

The ref:
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/drivers/leds/led-core.c?h=next-20231201#n501

The git force-push diff:
https://github.com/openwrt/openwrt/compare/9d2262c4fc44fa253b7f65da12d5fee5168c1476..ac049e3ab5adc5ff025d466c382da931846745e3

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test result shows all LEDs still work.

dts:
	aliases {
		led-boot = &led_status_red;
		led-failsafe = &led_status_blue;
		led-running = &led_status_yellow;
		led-upgrade = &led_status_blue;
	};

	leds {
		compatible = "gpio-leds";

		led_status_blue: led-blue {
			color = <LED_COLOR_ID_BLUE>;
			gpios = <&gpio0 10 GPIO_ACTIVE_LOW>;
		};

		led_status_red: led-red {
			function = LED_FUNCTION_STATUS;
			function-enumerator = <0>;
			gpios = <&gpio0 8 GPIO_ACTIVE_HIGH>;
		};

		led_status_yellow: led-yellow {
			color = <LED_COLOR_ID_YELLOW>;
			function = LED_FUNCTION_STATUS;
			function-enumerator = <100>;
			gpios = <&gpio0 11 GPIO_ACTIVE_LOW>;
		};
	};


root@OpenWrt:~# ls /sys/class/leds/
:status-0                mt76-phy0                rt2800soc-phy1::quality  yellow:status-100
blue:                    rt2800soc-phy1::assoc    rt2800soc-phy1::radio
root@OpenWrt:~# ls /sys/firmware/devicetree/base/leds/led-blue/
color  gpios  name
root@OpenWrt:~# ls /sys/firmware/devicetree/base/leds/led-red/
function             function-enumerator  gpios                name
root@OpenWrt:~# ls /sys/firmware/devicetree/base/leds/led-yellow/
color                function             function-enumerator  gpios                name

@chunkeey chunkeey left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Tested it, it works.

@raenye

raenye commented Dec 1, 2023

Copy link
Copy Markdown
Contributor

@chunkeey once the shellchecker comments are fixed, who's allowed to merge this? are responsibilities somehow partitioned between the different devs with commit access?

@csharper2005

Copy link
Copy Markdown
Contributor

@chunkeey once the shellchecker comments are fixed, who's allowed to merge this? are responsibilities somehow partitioned between the different devs with commit access?

According to the rules https://openwrt.org/rules all committers have such rights. Other factors may be at play: e.g. lack of time, information to fully assess the changes.

The 'label' property in led node has been deprecated and we'd better
to avoid using it. This patch allows us to extract DT OF LED name
from the newly introduced LED properties "color", "function" and
"function-enumerator".

Signed-off-by: Shiji Yang <[email protected]>
@chunkeey

chunkeey commented Dec 2, 2023

Copy link
Copy Markdown
Member

Merged. Thanks!

@rmilecki

rmilecki commented Dec 4, 2023

Copy link
Copy Markdown
Contributor

Thanks a lot for working on this solution. I was looking for a way of matching color + function to generated label but I wasn't sure how to handle that.

FWIW I sent an e-mail to DT and LEDs developers asking if there is an option for upstream binding describing LED's function. No answer so far but I'm keep an eye on that
Describing LEDs roles in device tree?

@DragonBluep
DragonBluep deleted the dt-led branch December 11, 2023 01:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core packages pull request/issue for core (in-tree) packages kernel pull request/issue with Linux kernel related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants