Skip to content

Commit

Permalink
gpio-poweroff: Remember the old poweroff handler
Browse files Browse the repository at this point in the history
commit a102c479c898390bf71200e4e1897f53700e7928 from
https://github.com/raspberrypi/linux.git rpi-6.6.y

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>
Signed-off-by: Rajeshkumar Ramasamy <rajeshkumar.ramasamy@windriver.com>
  • Loading branch information
pelwell authored and rajeshkumarwr committed Aug 10, 2024
1 parent 5feeed9 commit f860164
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 @@ -26,6 +26,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 @@ -45,6 +46,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 @@ -85,14 +89,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 f860164

Please sign in to comment.