Le Potato gpio-poweroff replacement

The Raspberry Pi has a kernel overlay gpio-poweroff that allows you to have a GPIO pin set a state early in the boot process and maintain that state until safe to poweroff the device. What would be the best way to mimic this with a Le Potato?

I’m not sure, it must be possible though because the blue and green LEDs at the front of the board do just that, if only coincidentally. I’m new to writing overlays, but I think searching the full device tree for “LED” might shed some light on how it’s done. You can also fool around with the LED triggers by messing with the files in /sys/class/leds/ to see how the work.

Device Tree:
https://boot.libre.computer/ci/aml-s905x-cc.dts

We are currently working to fix the reboot on shutdown issue permanently.

1 Like

@librecomputer Cool, is this coming in the new images?

@Joshua_Dye In the mean time this overlay lights up an LED connected to pin 3 at the same time the blue heartbeat starts and kills it when it is safe to power off:

/*
 * Overlay aimed create a safe power off LED on pin 3 :
 */

/dts-v1/;
/plugin/;

#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/gpio/meson-gxl-gpio.h>

/ {
	compatible = "libretech,aml-s905x-cc\0amlogic,s905x\0amlogic,meson-gxl";
	
	fragment@0 {
	target-path = "/leds";
	
	__overlay__ {
		led-off {
			label = "green:status";
			color = <0x02>;
			gpios = <&gpio_ao GPIOAO_5 GPIO_ACTIVE_HIGH>;
			linux,default-trigger = "default-on";
			};
		};
	};
};

Notes:

  1. You can modify the “gpios” property to change the pin.
  2. I have no idea if the color property actually matters, or the color in the name, but this said to do like so, so I did: LED handling under Linux — The Linux Kernel documentation
  3. It seems this cannot be enabled during runtime, it must be merged for the next reboot.
  4. As stated above, I don’t have much experience, and this was a learning exercise for me. I don’t 100% understand this, so use with caution.
  5. You could probably copy the proprieties from the green LED to get it to light earlier in the boot process, but I didn’t understand this route as well, so I did it this way.

Yes, we are adding shutdown and suspend support to AML family and adding support for RK3328 video at startup and fixing RK3399 PD issues.

1 Like

Thanks for the overlay. I need this for a car power switch that drops power when a GPIO pin is brought low, so changing the shutdown behavior won’t affect the need. I’ll try to test it out in the next couple of days.

@librecomputer, I hope the change will still leave at least the option of having the restart watchdog. It’s rather handy when the only way to recover a hung system otherwise is to turn your car off and back on.

watchdog is supported on Le Potato if you flash the latest firmware. You can setup the watchdog using standard Linux interfaces.

Hey all, just a caution about this overlay: a few seconds after power is applied Pin 3 drops to 0V for about 100 us. I’m guessing this is actually when the overlay is loaded and the application of the overlay causes this transient. This pulse would be bad if one were controlling system power circuitry with this pin, but not so important if driving an LED. [I’m running Debian 12 on an AML-s905x-cc-v1 Potato]

It is important to note the interaction of u-boot and Linux. There’s no magic here. The Linux device tree is loaded by u-boot. Prior to Linux starting up, there’s no guarantees as to the state of the board. After Linux has loaded the device tree, pins are set to the configuration as defined in the DT.