In the course of my little EPIA MII project, I have to interface four custom LEDs which I connected to the MII’s internal parallel port connector. The LEDs are tri-state LEDs, that is, they can not be just turned on or off but can show three different colors, hence the name tri-state LEDs. The particular ones I bought can be either off or light in either green, orange or yellow. Naturally, green would be a good choice to indicate a “ready/everything’s right” condition, orange could indicate ongoing activity und yellow is a good candidate in case of errors. Each LED requires two pins plus a Ground connection, thus the eight data lines on the parallel port can drive four LEDs just fine.
Driving the LEDs could be done from within a userspace program. This would work just fine with the parallel port. However the code’s not just about driving the LEDs but also about detecting when to drive which LED (plus, in my case, in what colour). What can one do with four tri-state LEDs? I decided to go with the following:
- The first LED is considered a “System” LED. It is initialized to orange by the Linux kernel as soon as the driver is loaded and switched to green by a boot script, when the system has finished booting. The LED however also indicates the RAID array status: the description given so far applies only when the md code determines that all software RAID arrays are in a healthy state. If at least one array is undergoing reconstruction, the LED will blink at a slow speed, retaining the previous colour. If an array loses a disk or is detected as degraded at bootup, the System LED will instead blink yellow at a high speed until a new drive is added. This way I don’t forget replacing failed hard disk drives.
- The second LED is supposed to show the status of local network interfaces, that is, LAN and WLAN. It shows yellow if only one interface is up, green if both interfaces are up and orange if both interfaces are up and at least one client has associated to the system’s access point interface. A green or orange LED blinks to indicate traffic from or to either local interface.
- The third LED reflects the “uplink” status. This could be DSL, cable modem or an upstream WLAN network. Orange would indicate that a connection is being established, green would indicate that a connection has been made and yellow represents connection failures. A blinking green LED indicates uplink traffic.
- The fourth LED is called a “Media” LED. It is supposed to indicate whenever audio streaming is ready for connections (green LED) or in progress (orange LED). Yellow could indicate errors again, but the question is what error conditions that could be.
- In case of a kernel panic, all four LEDs will blink yellow at a fast speed. This replaces blinking keyboard lights which I wouldn’t see in my project anyways, since there is no keyboard connected.
It should become obvious that safe for the last LED’s function, all functions require help from kernel space. Having the functionality in userspace might be technically possible, but it would probably be a lot harder. Therefore, I decided to realize the desired functionality in kernelspace by means of a loadable or statically compiled-in module.
While in theory this means a lot of custom design decisions, the Linux kernel already has a LEDs driver API which alleviates my task. I will go into details on this API and its shortcomings in an upcoming post.