简体   繁体   中英

How to blink leds in a linux kernel module?


I have a laptop with Linux Mint and 4.4.0-78-generic kernel.
Also, I have some leds there in the /sys/class/leds directory, and i can turn them on and off in the userspace by executing "echo 255 > brightness" in the bash.

However I want to switch them in my kernel module.
Lets say, that this module will listen a udp socket and switch led based on incoming packet data.
I have googled and found kernel source files called "leds-base.c","leds-class.c" which contains functions to control leds. However this functions require "struct led_classdev" to be passed, and I don't know where do I should get it.

So, the question is: How to set led brightness using it's name from /sys/class/leds directory in a kernel module?

PS. I have seen a similar question, but it's about KEYBOARD leds only, the led I want to control is not a keyboard one, and can not be controlled by code in question mentioned before.

Implement an led_trigger class and call

led_trigger_event(led, LED_FULL);

and friends in your driver. You can bind your trigger to any led by

echo my-trigger-name > /sys/class/leds/.../trigger

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM