smaclennan
Posts: 12
Joined: Sat Nov 25, 2023 6:10 pm

RPi5 power button

Sat Feb 17, 2024 8:26 pm

The RPi5 boots much faster than the RPi4... but I have to hold the power button down for 5 seconds to halt.

I noticed that Linux seems to halt as soon as you hit the button. But I do not know even where to begin looking for how they do that.

Anybody have any hints?

trejan
Posts: 7204
Joined: Tue Jul 02, 2019 2:28 pm

Re: RPi5 power button

Sat Feb 17, 2024 8:39 pm

The power button is connected to one of the SoC GPIOs. Linux monitors that and starts the shutdown process.

Holding for 5 seconds is a hard power off.

smaclennan
Posts: 12
Joined: Sat Nov 25, 2023 6:10 pm

Re: RPi5 power button

Sun Feb 18, 2024 12:31 am

trejan wrote:
Sat Feb 17, 2024 8:39 pm
The power button is connected to one of the SoC GPIOs. Linux monitors that and starts the shutdown process.

Holding for 5 seconds is a hard power off.
Thank you! That gives me a great start. I think I grepped for "power" and got nothing.

And I suspected that the 5 seconds was a hard power off. Nice to know for sure.

smaclennan
Posts: 12
Joined: Sat Nov 25, 2023 6:10 pm

Re: RPi5 power button

Mon Feb 19, 2024 4:16 pm

I have the power button working in polling mode, but not with an interrupt. Today is a holiday in Canada, so probably wait till tomorrow for a reply to my email.

But a second question, how to I actually power off the board? I thought I could just hit the same GPIO 20 since it seems to become an output when the button is pressed, but that doesn't seem to work.

Once we get the network running, I might use the power button as a reset, but for now I want it to power off. Or maybe push for reset, hold 2 seconds for power off.

User avatar
GTR2Fan
Posts: 2078
Joined: Sun Feb 23, 2014 9:20 pm
Location: South East UK

Re: RPi5 power button

Mon Feb 19, 2024 5:22 pm

I don't know whether this is of any use to you...

https://www.raspberrypi.com/documentati ... turned-off

That's as close as you'll get to powered down without disconnecting the power supply.

Note: This may make some HATs misbehave.
Pi5 8GB Mini-PC/Media Centre @3GHz in custom 3D-printed case running Raspberry Pi OS with KODI, 1TB Lexar NM790 SSD on Pimoroni NVMe Base at Gen 3 (870MB/s read), 60mm Gelid Solutions Silent 6 12V fan @5V and GeeekPi C-0048 aluminium heatsink case top.

smaclennan
Posts: 12
Joined: Sat Nov 25, 2023 6:10 pm

Re: RPi5 power button

Mon Feb 19, 2024 5:42 pm

I know there has to be a way to power off the board with no HW changes, since Linux can do it. I just don't know how they do it.

Once you boot Linux, hitting the power button immediately turns the board off. I know how to reset using the WDT, but not how to turn it off.

trejan
Posts: 7204
Joined: Tue Jul 02, 2019 2:28 pm

Re: RPi5 power button

Mon Feb 19, 2024 5:45 pm

I assume it uses the VC mailbox to send a message to the firmware to power down.
Last edited by trejan on Mon Feb 19, 2024 7:04 pm, edited 1 time in total.

smaclennan
Posts: 12
Joined: Sat Nov 25, 2023 6:10 pm

Re: RPi5 power button

Mon Feb 19, 2024 6:35 pm

trejan wrote:
Mon Feb 19, 2024 5:45 pm
I assume it uses the VC mailbox to send a message to the firmware to power down.
This looks promising. As part of bcm2835-firmware:

Code: Select all

		reset: reset {
			compatible = "raspberrypi,firmware-reset";
			#reset-cells = <1>;
		};

trejan
Posts: 7204
Joined: Tue Jul 02, 2019 2:28 pm

Re: RPi5 power button

Mon Feb 19, 2024 6:51 pm

trejan wrote:
Mon Feb 19, 2024 5:45 pm
I assume it uses the VC mailbox to send a message to the firmware to power down.
I found the code. It isn't a mailbox. The kernel puts a magic number for halt into the RSTS register and triggers the WDT.

smaclennan
Posts: 12
Joined: Sat Nov 25, 2023 6:10 pm

Re: RPi5 power button

Mon Feb 19, 2024 6:58 pm

Perfect! Thanks!

cleverca22
Posts: 8824
Joined: Sat Aug 18, 2012 2:33 pm

Re: RPi5 power button

Mon Feb 19, 2024 9:04 pm

trejan wrote:
Mon Feb 19, 2024 6:51 pm
trejan wrote:
Mon Feb 19, 2024 5:45 pm
I assume it uses the VC mailbox to send a message to the firmware to power down.
I found the code. It isn't a mailbox. The kernel puts a magic number for halt into the RSTS register and triggers the WDT.
the number its putting in there, is the noobs partition#

so a number from 0-62, tells the firmware to use that partition number as the fat when booting
a value of 63 is a magic number to tell the firmware that you wanted a shutdown
so when the watchdog triggers and things are rebooting, it notices the 63, and then does what POWER_OFF_ON_HALT and WAKE_ON_GPIO said to do

rst
Posts: 559
Joined: Sat Apr 20, 2013 6:42 pm
Location: Germany

Re: RPi5 power button

Tue Feb 20, 2024 11:42 am

Another possibility to switch off the Raspberry Pi 5 is this call to the PCSI interface, provided by the Trusted Firmware module:

Code: Select all

asm volatile
(
	"mov	x0, %0\n"
	"smc	#0\n"

	:: "r" (0x84000008U)	// function code SYSTEM_OFF
);

smaclennan
Posts: 12
Joined: Sat Nov 25, 2023 6:10 pm

Re: RPi5 power button

Tue Feb 20, 2024 10:06 pm

Tired that. It does work if I raise my privilege (I am running as a normal user process). So it is an alternative.

Return to “Bare metal, Assembly language”