FreeBSD supports GPIOLED(4).
Here is a description how to work with it on the Raspberry Pi (for example).
GPIOLED(4) is a special driver attaches a led(4) device to a GPIO pin.
After describing physical led as a gpioled(4) we control it through a led(4) device.
Raspberry Pi has one gpioled by default. This is a led «ACT» near audio output.
This led described in the file rpi.dts:
314 leds { 315 compatible = "gpio-leds"; 316 317 ok { 318 label = "ok"; 319 gpios = <&gpio 16 1>; 320 321 /* Don't change this - it configures 322 * how the led driver determines if 323 * the led is on or off when it loads. 324 */ 325 default-state = "keep"; 326 327 /* This is the real default state. */ 328 linux,default-trigger = "default-on"; 329 }; 330 };
This led has name «ok». Default state for this led is «keep». This mean that it is «on» in normal state.
To work with this led we can use device /dev/led/ok.
To turn it off we can use this command:
# echo 1 > /dev/led/ok
And to turn it on we can use this command:
# echo 0 > /dev/led/ok
We can use symbols «*», «-«, «0», «1», «f», «f1» … «f9» and so on as described in the manual page led(4).
Let’s connect usual LED to GPIO pin 25:
To describe it as GPIOLED we need to add this four strings to the file /usr/src/sys/boot/fdt/dts/arm/rpi.dts:
led25 { label = "led25"; gpios = <&gpio 25 0>; };
After changing the rpi.dts file, we need to compile it:
# cd /usr/src/sys/tools/fdt
# setenv MACHINE arm
# ./make_dtb.sh /usr/src/sys /usr/src/sys/boot/fdt/dts/arm/rpi.dts rpi.dtb
Then we need to copy the result to the directory /boot/msdos:
# cp /boot/msdos/rpi.dtb /boot/msdos/rpidtb.old
# cp rpi.dtb /boot/msdos
The new rpi.dtb less than the old one but it works.
Let’s play with our leds:
FreeBSD rpi 11.0-CURRENT FreeBSD 11.0-CURRENT #0 r278908: Tue Feb 17 23:25:47 UTC 2015
RPi Model B+
dmesg shows: gpioled0: at pin(s) 16 on gpiobus0
# echo 1 > /dev/led/ok
# echo 0 > /dev/led/ok
has no effect on the ACT LED, no does:
# gpioctl 16 0
# gpioctl 16 1
gpioctl -lv shows the state as changing but the ACT LED does not light at all (it lights when rebooting for a second so the LED does work).
Model B+ has pin 16 on the 40-pin header (http://elinux.org/RPi_Low-level_peripherals).
I don’t know what pin is for ACT LED on Model B+
Try to use pin 47 for the ACT LED and pin 35 for the PWR LED
http://www.raspberrypi.org/forums/viewtopic.php?f=29&t=83700
No luck with pin 47 :
#gpioctl -f /dev/gpioc0 -t 47
gpio_pin_toggle: Invalid argument
#gpioctl 47 1
gpio_pin_set: Invalid argument
I suspect the FreeBSD tweaks for the Model B+ were simply to get FreeBSD running with the new USB/LAN chip and that my dmesg entry of:
gpioled0: at pin(s) 16 on gpiobus0
indicates that the rpi.dts file was not updated for the B+. I’ll see if I can find the dts file used in the FreeBSD svn.
Yes, I see.
Both files rpi.dts and bcm2835.dtsi was not updated for the B+
Pin 47 marked as ‘read-only’ in the file bcm2835.dtsi
(Line 155 here: https://svnweb.freebsd.org/base/head/sys/boot/fdt/dts/arm/bcm2835.dtsi?revision=278915&view=markup)
You can try to update this files by yourself 🙂
Yep, found those. No model B+ updates as I suspected. I’ll try fixing and submitting a PR. Cheers.