1 From 6fe800dee9b24ef1d75a0acd5b067a1e84f2a5da Mon Sep 17 00:00:00 2001
2 From: Phil Elwell <phil@raspberrypi.com>
3 Date: Tue, 27 Apr 2021 08:59:01 +0100
4 Subject: [PATCH] gpio-poweroff: Remember the old poweroff handler
6 Keeping a copy of the old poweroff handler allows it to be restored
7 should this module be unloaded, but also provides a fallback if the
8 power hasn't been removed when the timeout elapses.
10 See: https://github.com/raspberrypi/rpi-eeprom/issues/330
12 Signed-off-by: Phil Elwell <phil@raspberrypi.com>
14 drivers/power/reset/gpio-poweroff.c | 7 ++++++-
15 1 file changed, 6 insertions(+), 1 deletion(-)
17 --- a/drivers/power/reset/gpio-poweroff.c
18 +++ b/drivers/power/reset/gpio-poweroff.c
19 @@ -24,6 +24,7 @@ static struct gpio_desc *reset_gpio;
20 static u32 timeout = DEFAULT_TIMEOUT_MS;
21 static u32 active_delay = 100;
22 static u32 inactive_delay = 100;
23 +static void (*old_power_off)(void);
25 static void gpio_poweroff_do_poweroff(void)
27 @@ -43,6 +44,9 @@ static void gpio_poweroff_do_poweroff(vo
28 /* give it some time */
37 @@ -83,6 +87,7 @@ static int gpio_poweroff_probe(struct pl
38 gpiod_export_link(&pdev->dev, "poweroff-gpio", reset_gpio);
41 + old_power_off = pm_power_off;
42 pm_power_off = &gpio_poweroff_do_poweroff;
45 @@ -90,7 +95,7 @@ static int gpio_poweroff_probe(struct pl
46 static int gpio_poweroff_remove(struct platform_device *pdev)
48 if (pm_power_off == &gpio_poweroff_do_poweroff)
49 - pm_power_off = NULL;
50 + pm_power_off = old_power_off;
52 gpiod_unexport(reset_gpio);