LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 06-01-2016, 02:30 AM   #1
vinoth57
LQ Newbie
 
Registered: Jun 2016
Posts: 1

Rep: Reputation: Disabled
how sysfs based LED control works?


When we do the fwrite to the file /sys/class/leds/LED1/brightness , how it turns on/off the LED.Can any one give me some brief details about this..i meant from the user space to Driver how the flow is happening,and what are the modules involved in this.

Thanks in advance!

Last edited by vinoth57; 06-01-2016 at 02:32 AM. Reason: spelling mistakes
 
Old 06-02-2016, 08:27 PM   #2
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
/sys, like /proc, is a virtual filesystem. Actually, it is a very sophisticated API, since none of the "files" and "directories" in it actually exist.

Here's a good foundation paper on the subject: https://www.kernel.org/pub/linux/ker...005/mochel.pdf.

Of course, since it was written many years ago now, the implementation details will have changed. But it is an excellent overview of how this interface works, and how it was implemented.

Everything that hooks into this API emulates one or more files, directories, symlinks, and so on. (Refer to the PDF, especially starting in Section 6 and beyond.) In this regard, /sys is a bit more-ambitious than /proc, but the essential concepts and facilities are very similar.

At some point, there will be a software object that corresponds to that LED-control, and it will be expecting (probably ...) a sysctl() call. Linux will direct the call to this object when it comes in, and the code, executing in kernel-mode, must do the right thing.

Last edited by sundialsvcs; 06-02-2016 at 08:46 PM.
 
2 members found this post helpful.
Old 06-27-2016, 03:27 PM   #3
Ratamahatta
Member
 
Registered: Feb 2012
Location: Germany
Distribution: siduction
Posts: 134

Rep: Reputation: 17
How I did it...

On my laptop, the brightness is adjustable via writing to /sys/class/backlight/radeon_bl0/brightness. Only Root is allowed to write, the rest can only read the value. 0 is off, 1 is minimum, 255 is maximum brightness.

So I wrote a little C program that takes one number as a parameter and writes the value to that file. The compiled binary needs to belong to root and have the suid bit set in order to allow everyone to change the backlight brightness.

There are some brightness symbols on the keyboard, so I used xev to find the keycodes. Then I wrote a shell script that reads the value from /sys/class/backlight/radeon_bl0/brightness and increases/decreases it according to the given parameter. Then the script writes that value out by using the program I mentioned before. And finally I added two keyboard shortcuts to the openbox rc.xml. So now I can use Fn+F6/Fn+F7 to adjust the brightness. (And I could use the program on it's own to set the brightness to a specific value during startup or when the power supply is connected/disconnected.)

Would you like to see the code or would you like to figure out the rest on your own?
 
Old 06-28-2016, 01:48 PM   #4
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
... and, if you want to learn how such things work, you should grab a copy of the Kernel source-code and look at how this brightness-control pseudo-file was implemented.

All of the pseudo- file-systems work in basically the same way, and all of the source code is available for your amusement and amazement . . .

Remember that egrep is your best friend. For instance, look for \bbrightness\b ...

Last edited by sundialsvcs; 06-28-2016 at 01:50 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Simple LED control with the Raspberry Pi LXer Syndicated Linux News 0 03-17-2016 11:51 AM
Attribute Based Access Control (ABAC): NIST Guide Aims to Ease Access Control tronayne Linux - Security 0 03-09-2014 06:44 PM
Raspberry pi red LED on solidly with flashing green led. darkstarbyte Linux - Hardware 19 01-05-2013 06:54 PM
Foxconn nt435: control LLS Led state (on/off) Angel2953 Linux - Hardware 0 03-05-2012 09:40 AM
How to write Device Driver to control LED? mcp_achindra Programming 1 04-01-2004 06:33 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 09:04 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration