From 095bad7f310809a951735d03be9d06938524a6bc Mon Sep 17 00:00:00 2001 From: Assaf Gordon Date: Fri, 12 Mar 2021 00:13:07 -0700 Subject: [PATCH] overlays: gpio-led: new overlay Add generic connection between the kernel's LED framework and RPI's GPIO pins. Signed-off-by: Assaf Gordon --- arch/arm/boot/dts/overlays/Makefile | 1 + arch/arm/boot/dts/overlays/README | 56 +++++++++++ .../boot/dts/overlays/gpio-led-overlay.dts | 97 +++++++++++++++++++ 3 files changed, 154 insertions(+) create mode 100755 arch/arm/boot/dts/overlays/gpio-led-overlay.dts --- a/arch/arm/boot/dts/overlays/Makefile +++ b/arch/arm/boot/dts/overlays/Makefile @@ -54,6 +54,7 @@ dtbo-$(CONFIG_ARCH_BCM2835) += \ gpio-ir.dtbo \ gpio-ir-tx.dtbo \ gpio-key.dtbo \ + gpio-led.dtbo \ gpio-no-bank0-irq.dtbo \ gpio-no-irq.dtbo \ gpio-poweroff.dtbo \ --- a/arch/arm/boot/dts/overlays/README +++ b/arch/arm/boot/dts/overlays/README @@ -914,6 +914,62 @@ Params: gpio GPIO pin keycode Set the key code for the button + +Name: gpio-led +Info: This is a generic overlay for activating LEDs (or any other component) + by a GPIO pin. Multiple LEDs can be set up using multiple calls to the + overlay. While there are many existing methods to activate LEDs on the + RPi, this method offers some advantages: + 1) Does not require any userspace programs. + 2) LEDs can be connected to the kernel's led-trigger framework, + and drive the LED based on triggers such as cpu load, heartbeat, + kernel panic, key input, timers and others. + 3) LED can be tied to the input state of another GPIO pin. + 4) The LED is setup early during the kernel boot process (useful + for cpu/heartbeat/panic triggers). + + Typical electrical connection is: + RPI-GPIO.19 -> LED -> 300ohm resister -> RPI-GND + The GPIO pin number can be changed with the 'gpio=' parameter. + + To control an LED from userspace, write a 0 or 1 value: + echo 1 > /sys/class/leds/myled1/brightness + The 'myled1' name can be changed with the 'label=' parameter. + + To connect the LED to a kernel trigger from userspace: + echo cpu > /sys/class/leds/myled1/trigger + echo heartbeat > /sys/class/leds/myled1/trigger + echo none > /sys/class/leds/myled1/trigger + To connect the LED to GPIO.26 pin (physical pin 37): + echo gpio > /sys/class/leds/myled1/trigger + echo 26 > /sys/class/leds/myled1/gpio + Available triggers: + cat /sys/class/leds/myled1/trigger + + More information about the Linux kernel LED/Trigger system: + https://www.kernel.org/doc/Documentation/leds/leds-class.rst + https://www.kernel.org/doc/Documentation/leds/ledtrig-oneshot.rst +Load: dtoverlay=gpio-led,= +Params: gpio GPIO pin connected to the LED (default 19) + label The label for this LED. It will appear under + /sys/class/leds/