xref: /openbmc/linux/Documentation/leds/uleds.rst (revision 0898782247ae533d1f4e47a06bc5d4870931b284)
1*8dab9197SMauro Carvalho Chehab==============
2*8dab9197SMauro Carvalho ChehabUserspace LEDs
3*8dab9197SMauro Carvalho Chehab==============
4*8dab9197SMauro Carvalho Chehab
5*8dab9197SMauro Carvalho ChehabThe uleds driver supports userspace LEDs. This can be useful for testing
6*8dab9197SMauro Carvalho Chehabtriggers and can also be used to implement virtual LEDs.
7*8dab9197SMauro Carvalho Chehab
8*8dab9197SMauro Carvalho Chehab
9*8dab9197SMauro Carvalho ChehabUsage
10*8dab9197SMauro Carvalho Chehab=====
11*8dab9197SMauro Carvalho Chehab
12*8dab9197SMauro Carvalho ChehabWhen the driver is loaded, a character device is created at /dev/uleds. To
13*8dab9197SMauro Carvalho Chehabcreate a new LED class device, open /dev/uleds and write a uleds_user_dev
14*8dab9197SMauro Carvalho Chehabstructure to it (found in kernel public header file linux/uleds.h)::
15*8dab9197SMauro Carvalho Chehab
16*8dab9197SMauro Carvalho Chehab    #define LED_MAX_NAME_SIZE 64
17*8dab9197SMauro Carvalho Chehab
18*8dab9197SMauro Carvalho Chehab    struct uleds_user_dev {
19*8dab9197SMauro Carvalho Chehab	char name[LED_MAX_NAME_SIZE];
20*8dab9197SMauro Carvalho Chehab    };
21*8dab9197SMauro Carvalho Chehab
22*8dab9197SMauro Carvalho ChehabA new LED class device will be created with the name given. The name can be
23*8dab9197SMauro Carvalho Chehabany valid sysfs device node name, but consider using the LED class naming
24*8dab9197SMauro Carvalho Chehabconvention of "devicename:color:function".
25*8dab9197SMauro Carvalho Chehab
26*8dab9197SMauro Carvalho ChehabThe current brightness is found by reading a single byte from the character
27*8dab9197SMauro Carvalho Chehabdevice. Values are unsigned: 0 to 255. Reading will block until the brightness
28*8dab9197SMauro Carvalho Chehabchanges. The device node can also be polled to notify when the brightness value
29*8dab9197SMauro Carvalho Chehabchanges.
30*8dab9197SMauro Carvalho Chehab
31*8dab9197SMauro Carvalho ChehabThe LED class device will be removed when the open file handle to /dev/uleds
32*8dab9197SMauro Carvalho Chehabis closed.
33*8dab9197SMauro Carvalho Chehab
34*8dab9197SMauro Carvalho ChehabMultiple LED class devices are created by opening additional file handles to
35*8dab9197SMauro Carvalho Chehab/dev/uleds.
36*8dab9197SMauro Carvalho Chehab
37*8dab9197SMauro Carvalho ChehabSee tools/leds/uledmon.c for an example userspace program.
38