blob: d233daa5835b5b05af18f83ac5653d9cc4f45cf5 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Andrew Lunnffd8f9a2012-12-28 13:25:11 +01002/*
3 * Power off by restarting and let u-boot keep hold of the machine
4 * until the user presses a button for example.
5 *
6 * Andrew Lunn <andrew@lunn.ch>
7 *
8 * Copyright (C) 2012 Andrew Lunn
Andrew Lunnffd8f9a2012-12-28 13:25:11 +01009 */
10#include <linux/kernel.h>
11#include <linux/init.h>
12#include <linux/platform_device.h>
13#include <linux/of_platform.h>
14#include <linux/module.h>
Robin Holt7b6d8642013-07-08 16:01:40 -070015#include <linux/reboot.h>
Andrew Lunnffd8f9a2012-12-28 13:25:11 +010016
17static void restart_poweroff_do_poweroff(void)
18{
Guenter Roeck0713e142014-09-26 00:03:16 +000019 reboot_mode = REBOOT_HARD;
20 machine_restart(NULL);
Andrew Lunnffd8f9a2012-12-28 13:25:11 +010021}
22
Thierry Reding60a1c4d2013-01-30 12:28:13 +010023static int restart_poweroff_probe(struct platform_device *pdev)
Andrew Lunnffd8f9a2012-12-28 13:25:11 +010024{
25 /* If a pm_power_off function has already been added, leave it alone */
26 if (pm_power_off != NULL) {
27 dev_err(&pdev->dev,
28 "pm_power_off function already registered");
29 return -EBUSY;
30 }
31
32 pm_power_off = &restart_poweroff_do_poweroff;
33 return 0;
34}
35
Thierry Reding60a1c4d2013-01-30 12:28:13 +010036static int restart_poweroff_remove(struct platform_device *pdev)
Andrew Lunnffd8f9a2012-12-28 13:25:11 +010037{
38 if (pm_power_off == &restart_poweroff_do_poweroff)
39 pm_power_off = NULL;
40
41 return 0;
42}
43
44static const struct of_device_id of_restart_poweroff_match[] = {
45 { .compatible = "restart-poweroff", },
46 {},
47};
48
49static struct platform_driver restart_poweroff_driver = {
50 .probe = restart_poweroff_probe,
Thierry Reding60a1c4d2013-01-30 12:28:13 +010051 .remove = restart_poweroff_remove,
Andrew Lunnffd8f9a2012-12-28 13:25:11 +010052 .driver = {
53 .name = "poweroff-restart",
Andrew Lunnffd8f9a2012-12-28 13:25:11 +010054 .of_match_table = of_restart_poweroff_match,
55 },
56};
57module_platform_driver(restart_poweroff_driver);
58
59MODULE_AUTHOR("Andrew Lunn <andrew@lunn.ch");
60MODULE_DESCRIPTION("restart poweroff driver");
Bjorn Helgaas661468b2014-07-15 17:24:50 -060061MODULE_LICENSE("GPL v2");
Andrew Lunnffd8f9a2012-12-28 13:25:11 +010062MODULE_ALIAS("platform:poweroff-restart");