summaryrefslogtreecommitdiffstats
path: root/drivers/power/reset/gpio-poweroff.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 17:40:19 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 17:40:19 +0000
commit9f0fc191371843c4fc000a226b0a26b6c059aacd (patch)
tree35f8be3ef04506ac891ad001e8c41e535ae8d01d /drivers/power/reset/gpio-poweroff.c
parentReleasing progress-linux version 6.6.15-2~progress7.99u1. (diff)
downloadlinux-9f0fc191371843c4fc000a226b0a26b6c059aacd.tar.xz
linux-9f0fc191371843c4fc000a226b0a26b6c059aacd.zip
Merging upstream version 6.7.7.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'drivers/power/reset/gpio-poweroff.c')
-rw-r--r--drivers/power/reset/gpio-poweroff.c82
1 files changed, 44 insertions, 38 deletions
diff --git a/drivers/power/reset/gpio-poweroff.c b/drivers/power/reset/gpio-poweroff.c
index b28f24da1b..52cfeee2cb 100644
--- a/drivers/power/reset/gpio-poweroff.c
+++ b/drivers/power/reset/gpio-poweroff.c
@@ -15,50 +15,51 @@
#include <linux/gpio/consumer.h>
#include <linux/mod_devicetable.h>
#include <linux/module.h>
+#include <linux/reboot.h>
#define DEFAULT_TIMEOUT_MS 3000
-/*
- * Hold configuration here, cannot be more than one instance of the driver
- * since pm_power_off itself is global.
- */
-static struct gpio_desc *reset_gpio;
-static u32 timeout = DEFAULT_TIMEOUT_MS;
-static u32 active_delay = 100;
-static u32 inactive_delay = 100;
-static void gpio_poweroff_do_poweroff(void)
+struct gpio_poweroff {
+ struct gpio_desc *reset_gpio;
+ u32 timeout_ms;
+ u32 active_delay_ms;
+ u32 inactive_delay_ms;
+};
+
+static int gpio_poweroff_do_poweroff(struct sys_off_data *data)
{
- BUG_ON(!reset_gpio);
+ struct gpio_poweroff *gpio_poweroff = data->cb_data;
/* drive it active, also inactive->active edge */
- gpiod_direction_output(reset_gpio, 1);
- mdelay(active_delay);
+ gpiod_direction_output(gpio_poweroff->reset_gpio, 1);
+ mdelay(gpio_poweroff->active_delay_ms);
/* drive inactive, also active->inactive edge */
- gpiod_set_value_cansleep(reset_gpio, 0);
- mdelay(inactive_delay);
+ gpiod_set_value_cansleep(gpio_poweroff->reset_gpio, 0);
+ mdelay(gpio_poweroff->inactive_delay_ms);
/* drive it active, also inactive->active edge */
- gpiod_set_value_cansleep(reset_gpio, 1);
+ gpiod_set_value_cansleep(gpio_poweroff->reset_gpio, 1);
/* give it some time */
- mdelay(timeout);
+ mdelay(gpio_poweroff->timeout_ms);
WARN_ON(1);
+
+ return NOTIFY_DONE;
}
static int gpio_poweroff_probe(struct platform_device *pdev)
{
+ struct gpio_poweroff *gpio_poweroff;
bool input = false;
enum gpiod_flags flags;
+ int priority = SYS_OFF_PRIO_DEFAULT;
+ int ret;
- /* 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\n",
- __func__);
- return -EBUSY;
- }
+ gpio_poweroff = devm_kzalloc(&pdev->dev, sizeof(*gpio_poweroff), GFP_KERNEL);
+ if (!gpio_poweroff)
+ return -ENOMEM;
input = device_property_read_bool(&pdev->dev, "input");
if (input)
@@ -66,23 +67,29 @@ static int gpio_poweroff_probe(struct platform_device *pdev)
else
flags = GPIOD_OUT_LOW;
- device_property_read_u32(&pdev->dev, "active-delay-ms", &active_delay);
- device_property_read_u32(&pdev->dev, "inactive-delay-ms",
- &inactive_delay);
- device_property_read_u32(&pdev->dev, "timeout-ms", &timeout);
- reset_gpio = devm_gpiod_get(&pdev->dev, NULL, flags);
- if (IS_ERR(reset_gpio))
- return PTR_ERR(reset_gpio);
+ gpio_poweroff->active_delay_ms = 100;
+ gpio_poweroff->inactive_delay_ms = 100;
+ gpio_poweroff->timeout_ms = DEFAULT_TIMEOUT_MS;
- pm_power_off = &gpio_poweroff_do_poweroff;
- return 0;
-}
+ device_property_read_u32(&pdev->dev, "active-delay-ms", &gpio_poweroff->active_delay_ms);
+ device_property_read_u32(&pdev->dev, "inactive-delay-ms",
+ &gpio_poweroff->inactive_delay_ms);
+ device_property_read_u32(&pdev->dev, "timeout-ms", &gpio_poweroff->timeout_ms);
+ device_property_read_u32(&pdev->dev, "priority", &priority);
+ if (priority > 255) {
+ dev_err(&pdev->dev, "Invalid priority property: %u\n", priority);
+ return -EINVAL;
+ }
-static int gpio_poweroff_remove(struct platform_device *pdev)
-{
- if (pm_power_off == &gpio_poweroff_do_poweroff)
- pm_power_off = NULL;
+ gpio_poweroff->reset_gpio = devm_gpiod_get(&pdev->dev, NULL, flags);
+ if (IS_ERR(gpio_poweroff->reset_gpio))
+ return PTR_ERR(gpio_poweroff->reset_gpio);
+
+ ret = devm_register_sys_off_handler(&pdev->dev, SYS_OFF_MODE_POWER_OFF,
+ priority, gpio_poweroff_do_poweroff, gpio_poweroff);
+ if (ret)
+ return dev_err_probe(&pdev->dev, ret, "Cannot register poweroff handler\n");
return 0;
}
@@ -95,7 +102,6 @@ MODULE_DEVICE_TABLE(of, of_gpio_poweroff_match);
static struct platform_driver gpio_poweroff_driver = {
.probe = gpio_poweroff_probe,
- .remove = gpio_poweroff_remove,
.driver = {
.name = "poweroff-gpio",
.of_match_table = of_gpio_poweroff_match,