bcm27xx: switch to 5.15
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-5.10 / 950-0591-gpio-poweroff-Remember-the-old-poweroff-handler.patch
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
5
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.
9
10 See: https://github.com/raspberrypi/rpi-eeprom/issues/330
11
12 Signed-off-by: Phil Elwell <phil@raspberrypi.com>
13 ---
14 drivers/power/reset/gpio-poweroff.c | 7 ++++++-
15 1 file changed, 6 insertions(+), 1 deletion(-)
16
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);
24
25 static void gpio_poweroff_do_poweroff(void)
26 {
27 @@ -43,6 +44,9 @@ static void gpio_poweroff_do_poweroff(vo
28 /* give it some time */
29 mdelay(timeout);
30
31 + if (old_power_off)
32 + old_power_off();
33 +
34 WARN_ON(1);
35 }
36
37 @@ -83,6 +87,7 @@ static int gpio_poweroff_probe(struct pl
38 gpiod_export_link(&pdev->dev, "poweroff-gpio", reset_gpio);
39 }
40
41 + old_power_off = pm_power_off;
42 pm_power_off = &gpio_poweroff_do_poweroff;
43 return 0;
44 }
45 @@ -90,7 +95,7 @@ static int gpio_poweroff_probe(struct pl
46 static int gpio_poweroff_remove(struct platform_device *pdev)
47 {
48 if (pm_power_off == &gpio_poweroff_do_poweroff)
49 - pm_power_off = NULL;
50 + pm_power_off = old_power_off;
51
52 gpiod_unexport(reset_gpio);
53