blob: 5758033e0c161470c60831d470ebfd9946d7d3e3 [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{
Robin Holt7b6d8642013-07-08 16:01:40 -070023 arm_pm_restart(REBOOT_HARD, NULL);
Andrew Lunnffd8f9a2012-12-28 13:25:11 +010024}
25
Thierry Reding60a1c4d2013-01-30 12:28:13 +010026static int restart_poweroff_probe(struct platform_device *pdev)
Andrew Lunnffd8f9a2012-12-28 13:25:11 +010027{
28 /* If a pm_power_off function has already been added, leave it alone */
29 if (pm_power_off != NULL) {
30 dev_err(&pdev->dev,
31 "pm_power_off function already registered");
32 return -EBUSY;
33 }
34
35 pm_power_off = &restart_poweroff_do_poweroff;
36 return 0;
37}
38
Thierry Reding60a1c4d2013-01-30 12:28:13 +010039static int restart_poweroff_remove(struct platform_device *pdev)
Andrew Lunnffd8f9a2012-12-28 13:25:11 +010040{
41 if (pm_power_off == &restart_poweroff_do_poweroff)
42 pm_power_off = NULL;
43
44 return 0;
45}
46
47static const struct of_device_id of_restart_poweroff_match[] = {
48 { .compatible = "restart-poweroff", },
49 {},
50};
51
52static struct platform_driver restart_poweroff_driver = {
53 .probe = restart_poweroff_probe,
Thierry Reding60a1c4d2013-01-30 12:28:13 +010054 .remove = restart_poweroff_remove,
Andrew Lunnffd8f9a2012-12-28 13:25:11 +010055 .driver = {
56 .name = "poweroff-restart",
57 .owner = THIS_MODULE,
58 .of_match_table = of_restart_poweroff_match,
59 },
60};
61module_platform_driver(restart_poweroff_driver);
62
63MODULE_AUTHOR("Andrew Lunn <andrew@lunn.ch");
64MODULE_DESCRIPTION("restart poweroff driver");
65MODULE_LICENSE("GPLv2");
66MODULE_ALIAS("platform:poweroff-restart");