Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support gpio-poweroff driver to allow switching off power #1031

Closed
brycewilkins opened this issue Jun 22, 2015 · 20 comments
Closed

Support gpio-poweroff driver to allow switching off power #1031

brycewilkins opened this issue Jun 22, 2015 · 20 comments

Comments

@brycewilkins
Copy link

I tried to use the device tree GPIO binding gpio-poweroff to switch off power to the Raspberry Pi (via an on/off push-button controller) once the system reaches 'halt' state. Please see these links for info:
https://github.com/raspberrypi/linux/blob/rpi-4.0.y/Documentation/devicetree/bindings/gpio/gpio-poweroff.txt
and
https://www.raspberrypi.org/forums/viewtopic.php?f=107&t=113789.

It did not work because the standard Raspberry Pi configurations do not include the gpio-poweroff driver which must be enabled using the POWER_RESET and POWER_RESET_GPIO flags. I would like to request these additions.

I believe this would be an excellent feature to have support for as it will allow the RPi to actually switch off the power to a system it is controlling once it reaches a shutdown state. Currently the RPi enters a low-power shutdown state, but circuitry controlling the power (and anything connected to it) remains on.

As the gpio-poweroff driver would only be enabled by a device tree overlay it will not cause any conflict/incompatibility with existing systems.

Thank you!

@popcornmix
Copy link
Collaborator

Looks okay. Will add in next update.

@brycewilkins
Copy link
Author

Fantastic! Thank you so much :) I'll be happy to test and report back when something is ready.

popcornmix added a commit to Hexxeh/rpi-firmware that referenced this issue Jun 23, 2015
kernel: Add rpi-ft5406 overlay Add rpi-ft5406 driver as module

kernel: config: Enable 8250 serial port
See: raspberrypi/linux#1008

kernel: config: Enable POWER_RESET_GPIO
See: raspberrypi/linux#1031

firmware: arm_display: Fix fb_base alias returned from mailbox property interface
See: raspberrypi/linux#1026

firmware: mem_unlock - prevent decrementing lock count below 0

firmware: camera: Support multi-channel raw image capture
firmware: camera: write_raw copies input frame if HDR is enabled
firmware: camera: Write correct camera mode from write_raw_md_stage
firmware: AGC tuner: Correction to setting default digital gain to x1.0
popcornmix added a commit to raspberrypi/firmware that referenced this issue Jun 23, 2015
kernel: Add rpi-ft5406 overlay Add rpi-ft5406 driver as module

kernel: config: Enable 8250 serial port
See: raspberrypi/linux#1008

kernel: config: Enable POWER_RESET_GPIO
See: raspberrypi/linux#1031

firmware: arm_display: Fix fb_base alias returned from mailbox property interface
See: raspberrypi/linux#1026

firmware: mem_unlock - prevent decrementing lock count below 0

firmware: camera: Support multi-channel raw image capture
firmware: camera: write_raw copies input frame if HDR is enabled
firmware: camera: Write correct camera mode from write_raw_md_stage
firmware: AGC tuner: Correction to setting default digital gain to x1.0
@popcornmix
Copy link
Collaborator

Can you try rpi-update. The options should be in.

@brycewilkins
Copy link
Author

@popcornmix Unfortunately no success yet, here is what I did.

  • Ran rpi-update and got the 4.0.6 kernel
  • Recompile dt-blob.dts to /boot/dt-blob.bin
  • Recompile my power-off DT overlay and put in /boot/overlays/

Please see my thread in raspberrypi.org forum for details (link in original post above).

I put an oscilloscope on GPIO 26 which I'm using as the power-off control signal. The pin goes high during boot when dt-blob.bin is loaded, but when I execute "shutdown -h now" or "poweroff" the pin remains high after the 'halt' state. (At the end of shutdown the Raspberry Pi green "disk activity" LED blinks a few times then stays off, while the red "power" LED stays on.)

The overlay seems to be loaded as I have directory /proc/device-tree/soc/gpio/power_ctrl/ and files within, but I wonder if the fragment@0 is correct.

How can I help to get it working? Thank you!

@popcornmix
Copy link
Collaborator

The options you requested appear to be present:

pi@raspberrypi:~ $ sudo modprobe configs 
pi@raspberrypi:~ $ zcat /proc/config.gz |grep POWER_RESET
CONFIG_POWER_RESET=y
# CONFIG_POWER_RESET_BRCMSTB is not set
CONFIG_POWER_RESET_GPIO=y
# CONFIG_POWER_RESET_GPIO_RESTART is not set
# CONFIG_POWER_RESET_LTC2952 is not set
# CONFIG_POWER_RESET_RESTART is not set
# CONFIG_POWER_RESET_SYSCON is not set

@pelwell may have some ideas.

@brycewilkins
Copy link
Author

Thanks. I have the same output on my system.

Interesting that there is a config for LTC2952 which has some extra features compared to LTC2951 I am using. Seems like this should work.

@pelwell
Copy link
Contributor

pelwell commented Jun 24, 2015

but I wonder if the fragment@0 is correct.

Good guess. I've commented on the thread.

@notro
Copy link
Contributor

notro commented Jun 24, 2015

If I read this correctly, gpio-poweroff won't work because pm_power_off is already set in the platform file.

arch/arm/mach-bcm2708/bcm2708.c

void __init bcm2708_init(void)
{
...
    pm_power_off = bcm2708_power_off;

drivers/power/reset/gpio-poweroff.c

static int gpio_poweroff_probe(struct platform_device *pdev)
{
        bool input = false;

        /* If a pm_power_off function has already been added, leave it alone */
        if (pm_power_off != NULL) {
                dev_err(&pdev->dev,
                        "%s: pm_power_off function already registered",
                       __func__);
                return -EBUSY;
        }

@brycewilkins
Copy link
Author

@notro : @pelwell noted that it should replace the standard pm_power_off handler - please see here

But as I've commented over in the thread, it's still not working...

@notro
Copy link
Contributor

notro commented Jun 25, 2015

What does this return:

$ dmesg | grep poweroff

@pelwell
Copy link
Contributor

pelwell commented Jun 25, 2015

I've got it working (with caveats) - I'm writing a response for the Forum.

@pelwell
Copy link
Contributor

pelwell commented Jun 25, 2015

And you were correct (of course) about the existing pm_power_off handler.

@pelwell
Copy link
Contributor

pelwell commented Jun 25, 2015

Thread updated. Gist here: https://gist.github.com/pelwell/e4c5662c331fcae1e707

@notro
Copy link
Contributor

notro commented Jun 25, 2015

You could do:

if (!force && pm_power_off != NULL) {

@notro
Copy link
Contributor

notro commented Jun 25, 2015

Or just remove the whole if clause, since pm_power_off will always be set in our repo.

@brycewilkins
Copy link
Author

Thanks @pelwell @notro for getting to the root of the problem! I'd give it a try but not sure how to apply the patch...

@pelwell
Copy link
Contributor

pelwell commented Jun 25, 2015

I've pushed the patch to the rpi-4.0.y branch. It will be in the next firmware release.

@brycewilkins
Copy link
Author

That's really excellent news. I will post a message here when I test it. Thank you!

popcornmix added a commit to raspberrypi/firmware that referenced this issue Jun 26, 2015
kernel: bcm2708-spi: Don't use static pin configuration with DT

kernel: bcm2708-i2s: Don't use static pin configuration with DT

kernel: gpio-poweroff: Allow it to work on Raspberry Pi
See: raspberrypi/linux#1031

kernel: BCM270X_DT: Create a core clock, use it for SPI and sdhost

kernel: BCM270X_DT: Add overlay to enable uart1
See: raspberrypi/linux#1008

kernel: config: Enable ZSMALLOC, ZRAM and PGTABLE_MAPPING
See: Hexxeh/rpi-firmware#85

firmware: arm_loader: Support initialising vchiq through mailbox property interface
See: raspberrypi/linux#1026

firmware: drivers/usb: Reduce busy-wait to sensible timeout
See: raspberrypi/linux#1026

firmware: video_encode: Initialise headers for video_bitrate
See: #163

firmware: arm_loader: Use the new core_freq DT parameter if present

firmware: arm_loader: Set the uart1_clkrate DT property from core_freq

firmware: arm_cursor: Better handling of a second app requesting a cursor

firmware: arm: Tidy up setting of arm_control and arm_bash
popcornmix added a commit to Hexxeh/rpi-firmware that referenced this issue Jun 26, 2015
kernel: bcm2708-spi: Don't use static pin configuration with DT

kernel: bcm2708-i2s: Don't use static pin configuration with DT

kernel: gpio-poweroff: Allow it to work on Raspberry Pi
See: raspberrypi/linux#1031

kernel: BCM270X_DT: Create a core clock, use it for SPI and sdhost

kernel: BCM270X_DT: Add overlay to enable uart1
See: raspberrypi/linux#1008

kernel: config: Enable ZSMALLOC, ZRAM and PGTABLE_MAPPING
See: #85

firmware: arm_loader: Support initialising vchiq through mailbox property interface
See: raspberrypi/linux#1026

firmware: drivers/usb: Reduce busy-wait to sensible timeout
See: raspberrypi/linux#1026

firmware: video_encode: Initialise headers for video_bitrate
See: raspberrypi/firmware#163

firmware: arm_loader: Use the new core_freq DT parameter if present

firmware: arm_loader: Set the uart1_clkrate DT property from core_freq

firmware: arm_cursor: Better handling of a second app requesting a cursor

firmware: arm: Tidy up setting of arm_control and arm_bash
@popcornmix
Copy link
Collaborator

rpi-update firmware should contain @pelwell's patch

@brycewilkins
Copy link
Author

It works perfectly! Thank you @popcornmix @pelwell @notro for all your help in adding this feature. No doubt a lot of people can make use of it. You guys are awesome!

I think this issue can be marked closed.

neuschaefer pushed a commit to neuschaefer/raspi-binary-firmware that referenced this issue Feb 27, 2017
kernel: Add rpi-ft5406 overlay Add rpi-ft5406 driver as module

kernel: config: Enable 8250 serial port
See: raspberrypi/linux#1008

kernel: config: Enable POWER_RESET_GPIO
See: raspberrypi/linux#1031

firmware: arm_display: Fix fb_base alias returned from mailbox property interface
See: raspberrypi/linux#1026

firmware: mem_unlock - prevent decrementing lock count below 0

firmware: camera: Support multi-channel raw image capture
firmware: camera: write_raw copies input frame if HDR is enabled
firmware: camera: Write correct camera mode from write_raw_md_stage
firmware: AGC tuner: Correction to setting default digital gain to x1.0
neuschaefer pushed a commit to neuschaefer/raspi-binary-firmware that referenced this issue Feb 27, 2017
kernel: bcm2708-spi: Don't use static pin configuration with DT

kernel: bcm2708-i2s: Don't use static pin configuration with DT

kernel: gpio-poweroff: Allow it to work on Raspberry Pi
See: raspberrypi/linux#1031

kernel: BCM270X_DT: Create a core clock, use it for SPI and sdhost

kernel: BCM270X_DT: Add overlay to enable uart1
See: raspberrypi/linux#1008

kernel: config: Enable ZSMALLOC, ZRAM and PGTABLE_MAPPING
See: Hexxeh/rpi-firmware#85

firmware: arm_loader: Support initialising vchiq through mailbox property interface
See: raspberrypi/linux#1026

firmware: drivers/usb: Reduce busy-wait to sensible timeout
See: raspberrypi/linux#1026

firmware: video_encode: Initialise headers for video_bitrate
See: raspberrypi#163

firmware: arm_loader: Use the new core_freq DT parameter if present

firmware: arm_loader: Set the uart1_clkrate DT property from core_freq

firmware: arm_cursor: Better handling of a second app requesting a cursor

firmware: arm: Tidy up setting of arm_control and arm_bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants