I am trying to write a device tree overlay (using GPIO device tree binding for "power off", see here) for a push-button on/off controller (Linear Technology LTC2951-1). I attached an image showing the schematic of LTC2951 and Raspberry Pi GPIOs. Unfortunately I've not been able to get it to work as I expect. Here is a little info about the setup to explain my process and where I'm at.
The LTC2951 has an active-low interrupt output (/INT) which it drives low when a normally-open push-button is pressed. When the Raspberry Pi detects /INT going low, the system starts its shutdown procedure. I accomplish this step with the following Python script (which is started at boot in /etc/rc.local):
Code: Select all
import os import time import RPi.GPIO as GPIO # This script runs at boot and listens on /INT for shutdown request by LTC2951. # When /INT = 0 is detected by interrupt the system initiates shutdown and will end in 'halt' state. # Define input/output pins connected to LTC2951 pushbutton controller nINT = 20 # LTC2951 /INT output connected to RPi input # Configure pins used by on/off pushbutton controller GPIO.setmode(GPIO.BCM) # Use Broadcom (BCM) pin numbering GPIO.setup(nINT, GPIO.IN) # Input : listen for /INT from on/off controller # Function to run when on/off button press detected def isr_shutdown(self): print("Calibration Box - LTC2951 shutdown request received") os.system("sudo shutdown -h now") # Software system shutdown (commence immediately) # Configure interrupt detection and assign callback function GPIO.add_event_detect(nINT, GPIO.FALLING, callback=isr_shutdown, bouncetime=2000) while(True): time.sleep(1)
To do this the active-low /KILL input of LTC2951 needs to be driven low. I am trying to accomplish it using the device tree GPIO binding that seems specifically for this purpose.
As shown in the schematic I have GPIO 26 of the Raspberry Pi connected to the /KILL input, but the RPi is not driving this pin low when the system reaches 'halt'. Following is the device tree configuration I have followed to try and get it to work.
First, I used information from here and here to edit dt-blob.dts and compile my own /boot/dt-blob.bin. Here is relevant snippet of dt-blob.dts which shows configuring GPIO 26 as an active-low output defaulting to inactive state at boot:
Code: Select all
<snip> pins_2b2 { // Pi 2 Model B rev 1.1 pin_config { [email protected] { polarity = "active_high"; termination = "pull_down"; startup_state = "inactive"; function = "input"; }; // pin [email protected] { function = "output"; termination = "no_pulling"; polarity = "active_low"; startup_state = "inactive"; }; // Power off signal // Continues as original file... [email protected] { function = "uart0"; termination = "no_pulling"; drive_strength_mA = < 8 >; }; // TX uart0 <snip>
Now I used information about device tree overlay from here to add the power-off function which should result in GPIO 26 going low once the system reaches 'halt', and consequently cutting power. Here is what I have written for the DT overlay:
Code: Select all
/dts-v1/; /plugin/; / { compatible = "brcm,bcm2709"; [email protected] { target = <&gpio>; __overlay__ { power_ctrl: power_ctrl { compatible = "gpio-poweroff"; gpios = <&gpio 26 0>; }; }; }; };
Despite all this "power off" is not working --- specifically GPIO 26 does not go low when the system reaches 'halt', therefore the power stays on after the system is shutdown.
Compared to other overlay examples, mine looks rather simple. I wonder if I am missing something, like setting the GPIO to use in one fragment and then configure the pin as a "power controller" in a second fragment...similar to this example.
Or, is there a difference in how the system is shutdown? For example, I call "shutdown -h now" from my Python script, but what about "poweroff", "halt", or "init 0". Are all these expected to equivalently result in the pm_power_off handler being called?
Thanks for any and all help, folks. The device tree stuff is fascinating for configuring custom hardware, but seems tricky to get the overlay stuff right.
Cheers,
sparkyPi