GPIO poweroff in Linux?

Following @RadxaYuntian’s advices, I come up with the following overlay :

/dts-v1/;
/plugin/;

/ {
	compatible = "radxa,zero", "amlogic,g12a";

	fragment@0 {
		target-path = "/";
		__overlay__ {
			gpio-poweroff {
				compatible = "gpio-poweroff";
				/* gpios = <&gpio_ao GPIOAO_3 GPIO_ACTIVE_HIGH>; */
				gpios = <&gpio_ao 3 1>;
				status = "okay";
			};
		};
	};
};

I’ve removed the includes from w1-gpioao-3.dts, giving the raw pin number as found in the included file, so that it’s easier to compile.

The overlay compiles and loads successfully. From the latest @theophile’s comments, I believe it should perform as intended. I cannot confirm sin ce I can’t monitor the voltage on GPIOAO_3 (physical pin 7). I’ll report here if I get updates on this. Anyone able to test this overlay before me would be welcome to tell !

The sample overlay is already merged: https://github.com/radxa/kernel/commit/8989d6dd5cbb47e3a0dcb49abe0c9299051e798f#diff-f46cbf8dc1d5be28611a9274ede3f9324e3207af63c9b61533146cfbeef9612c

1 Like

How would one adapt this to work with a Rock Pi E or similar rk3328 based device?

My current failed attempt is this:

/dts-v1/;
/plugin/;

/ {
	compatible = "rockchip,rk3328";

	fragment@0 {
		target-path = "/";
		__overlay__ {
			gpio-poweroff {
				compatible = "gpio-poweroff";
				gpios = <&gpio1 24 0>;
				timeout-ms = <20000>;
				force;
			};
		};
	};
};

dtc -I dts -O dtb -f rk3328-poweroff-gpio1-24.dts -o /boot/dtb/rockchip/overlay/rk3328-poweroff-gpio1-24.dtbo

/boot/armbianEnv.txt:
overlays=rk3328-poweroff-gpio1-24

No output on gpio24 on shutdown complete.

Couple things. First, the overlay isn’t enough. You also need a kernel that has CONFIG_POWER_RESET_GPIO enabled, and depending on what kernel you’re using, you may need to either modify /drivers/firmware/psci/psci.c to comment out the ‘pm_power_off = psci_sys_poweroff’ line, or adapt these patches.

Second, it might be worth checking to see if the rk3328 can run a Hardkernel odroid kernel, as Hardkernel has a similar implementation of this already built in. I think the odroid go has an rk3326. I’m not sure how similar they are so maybe this is a non-starter, but probably worth a look just in case.

1 Like