Skip to content

Commit

Permalink
gpio-poweroff: Remember the old poweroff handler
Browse files Browse the repository at this point in the history
Keeping a copy of the old poweroff handler allows it to be restored
should this module be unloaded, but also provides a fallback if the
power hasn't been removed when the timeout elapses.

See: raspberrypi/rpi-eeprom#330

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
  • Loading branch information
pelwell authored and popcornmix committed Jul 11, 2023
1 parent 7ea5c83 commit 627cf12
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion drivers/power/reset/gpio-poweroff.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ static struct gpio_desc *reset_gpio;
static u32 timeout = DEFAULT_TIMEOUT_MS;
static u32 active_delay = 100;
static u32 inactive_delay = 100;
static void (*old_power_off)(void);

static void gpio_poweroff_do_poweroff(void)
{
Expand All @@ -43,6 +44,9 @@ static void gpio_poweroff_do_poweroff(void)
/* give it some time */
mdelay(timeout);

if (old_power_off)
old_power_off();

WARN_ON(1);
}

Expand Down Expand Up @@ -83,14 +87,15 @@ static int gpio_poweroff_probe(struct platform_device *pdev)
gpiod_export_link(&pdev->dev, "poweroff-gpio", reset_gpio);
}

old_power_off = pm_power_off;
pm_power_off = &gpio_poweroff_do_poweroff;
return 0;
}

static int gpio_poweroff_remove(struct platform_device *pdev)
{
if (pm_power_off == &gpio_poweroff_do_poweroff)
pm_power_off = NULL;
pm_power_off = old_power_off;

gpiod_unexport(reset_gpio);

Expand Down

0 comments on commit 627cf12

Please sign in to comment.