I built a handheld around a Raspberry Pi Zero W, and now I am working on migrating it to the Radxa Zero to take advantage of the additional power. There are a couple of RPI-specific aspects that I need to figure out how to implement in EmuELEC with this board, and one of them is the power switch with safe shutdown.
(Side note: The forum won’t let me include more than 2 links because I’m a new user, so I’ve collected all my hyperlink references in this Pastebin and will use Wikipedia-style bracketed reference numbers in my post. Apologies for the inconvenience.)
I am using an external battery/charge/boost controller that has a GPIO-controlled enable (EN) pin. I am using this safe shutdown circuit [1] and a simple SPDT switch. When the switch is “on,” the battery is connected to the EN pin, which enables the power controller and supplies power to the Pi and other peripherals. When the switch is turned “off,” the Pi is triggered via GPIO to initiate a shutdown. After shutdown is complete, a second GPIO on the Pi is driven high to indicate it’s safe to power off. The power controller EN pin is then driven low and the power is shut off.
The Pi implementation relies on the gpio-shutdown [2] and gpio-poweroff [3] device tree overlays. I understand these overlays are specific to the Raspberry Pi, so I’m trying to figure out whether something similar is available on the Amlogic devices/Radxa Zero.
Looking at the code for gpio-shutdown [4], it looks like the kernel just monitors the specified GPIO and fires a KEY_POWER when the state changes. gpio-poweroff is actually a kernel module [5], and the gpio-poweroff overlay [6] looks like it just provides configurable parameters for the kernel module through a boot overlay.
Looking at the EmuELEC Github repo, I noticed that Radxa_Zero_boot.ini [7] contains a line:
if test "${gpiopower}" != ""; then setenv gpiopower "gpiopower=${gpiopower}"; fi
From my Google research, it looks like “gpiopower” is indeed something similar to gpio-shutdown that is specific to the Amlogic vendor kernel, but does not exist in the mainline kernel.
Am I correct to assume from this that EmuELEC uses an Amlogic kernel that has support for this gpiopower parameter? If so, should I expect this to work in the same manner as gpio-shutdown when I supply the correct pin in boot.ini?
If not (and just in case this is helpful to anyone else), here’s some more info I found in my research:
I found a Github issue thread on the Home Assistant project [8] where a user was unable to use gpiopower because that project uses mainline kernel, so the developer implemented the feature by patching the dtsi [9].
I found a similar block of code [10] in the EmuELEC Github repo, which looks like it works by polling a specific GPIO pin and then firing KEY_POWER if it changes state, but that block looks like it’s specific to the Beelink GS_King X device.
However, I did find a patch [11] that adds support for the Radxa Zero, which seems to be adding meson-g12a-radxa-zero.dts from the Radxa-maintained kernel [12]. That .dts doesn’t seem to have anything related to GPIO power, but the meson-g12b-radxa-zero2.dts from the same Radxa repo does have a block that looks like it’s implementing a GPIO power-off sequence [13].
Maybe I can just copy that into the Radxa Zero patch?
I also can’t tell from the Github repo whether the kernel has CONFIG_POWER_RESET_GPIO enabled, built as a module, or not set. As I understand it, this is the part that changes state of a second GPIO pin after the system shutdown has completed. This is what the shutdown circuit needs in order to tell the battery/power controller to shut off the power.
Overall, I am hoping a dev or someone who is more familiar with this project can tell me whether it’s already possible to accomplish what I’m trying to do, or if not, whether any of the pieces are already in place and what would still need to be done to get it to work. Thank you in advance!