blob: edd707ee7281154ae11995fcfc196c63120a927f [file] [log] [blame]
Andrew Lunnffd8f9a2012-12-28 13:25:11 +01001/*
2 * Power off by restarting and let u-boot keep hold of the machine
3 * until the user presses a button for example.
4 *
5 * Andrew Lunn <andrew@lunn.ch>
6 *
7 * Copyright (C) 2012 Andrew Lunn
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13#include <linux/kernel.h>
14#include <linux/init.h>
15#include <linux/platform_device.h>
16#include <linux/of_platform.h>
17#include <linux/module.h>
Robin Holt7b6d8642013-07-08 16:01:40 -070018#include <linux/reboot.h>
Andrew Lunnffd8f9a2012-12-28 13:25:11 +010019#include <asm/system_misc.h>
20
21static void restart_poweroff_do_poweroff(void)
22{
Guenter Roeck0713e142014-09-26 00:03:16 +000023 reboot_mode = REBOOT_HARD;
24 machine_restart(NULL);
Andrew Lunnffd8f9a2012-12-28 13:25:11 +010025}
26
Thierry Reding60a1c4d2013-01-30 12:28:13 +010027static int restart_poweroff_probe(struct platform_device *pdev)
Andrew Lunnffd8f9a2012-12-28 13:25:11 +010028{
29 /* If a pm_power_off function has already been added, leave it alone */
30 if (pm_power_off != NULL) {
31 dev_err(&pdev->dev,
32 "pm_power_off function already registered");
33 return -EBUSY;
34 }
35
36 pm_power_off = &restart_poweroff_do_poweroff;
37 return 0;
38}
39
Thierry Reding60a1c4d2013-01-30 12:28:13 +010040static int restart_poweroff_remove(struct platform_device *pdev)
Andrew Lunnffd8f9a2012-12-28 13:25:11 +010041{
42 if (pm_power_off == &restart_poweroff_do_poweroff)
43 pm_power_off = NULL;
44
45 return 0;
46}
47
48static const struct of_device_id of_restart_poweroff_match[] = {
49 { .compatible = "restart-poweroff", },
50 {},
51};
52
53static struct platform_driver restart_poweroff_driver = {
54 .probe = restart_poweroff_probe,
Thierry Reding60a1c4d2013-01-30 12:28:13 +010055 .remove = restart_poweroff_remove,
Andrew Lunnffd8f9a2012-12-28 13:25:11 +010056 .driver = {
57 .name = "poweroff-restart",
58 .owner = THIS_MODULE,
59 .of_match_table = of_restart_poweroff_match,
60 },
61};
62module_platform_driver(restart_poweroff_driver);
63
64MODULE_AUTHOR("Andrew Lunn <andrew@lunn.ch");
65MODULE_DESCRIPTION("restart poweroff driver");
Bjorn Helgaas661468b2014-07-15 17:24:50 -060066MODULE_LICENSE("GPL v2");
Andrew Lunnffd8f9a2012-12-28 13:25:11 +010067MODULE_ALIAS("platform:poweroff-restart");