2019-06-04 02:11:33 -06:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2012-12-28 05:25:11 -07:00
|
|
|
/*
|
|
|
|
* Power off by restarting and let u-boot keep hold of the machine
|
|
|
|
* until the user presses a button for example.
|
|
|
|
*
|
|
|
|
* Andrew Lunn <andrew@lunn.ch>
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Andrew Lunn
|
|
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/of_platform.h>
|
|
|
|
#include <linux/module.h>
|
2013-07-08 17:01:40 -06:00
|
|
|
#include <linux/reboot.h>
|
2012-12-28 05:25:11 -07:00
|
|
|
|
|
|
|
static void restart_poweroff_do_poweroff(void)
|
|
|
|
{
|
2014-09-25 18:03:16 -06:00
|
|
|
reboot_mode = REBOOT_HARD;
|
|
|
|
machine_restart(NULL);
|
2012-12-28 05:25:11 -07:00
|
|
|
}
|
|
|
|
|
2013-01-30 04:28:13 -07:00
|
|
|
static int restart_poweroff_probe(struct platform_device *pdev)
|
2012-12-28 05:25:11 -07:00
|
|
|
{
|
|
|
|
/* If a pm_power_off function has already been added, leave it alone */
|
|
|
|
if (pm_power_off != NULL) {
|
|
|
|
dev_err(&pdev->dev,
|
|
|
|
"pm_power_off function already registered");
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
pm_power_off = &restart_poweroff_do_poweroff;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-01-30 04:28:13 -07:00
|
|
|
static int restart_poweroff_remove(struct platform_device *pdev)
|
2012-12-28 05:25:11 -07:00
|
|
|
{
|
|
|
|
if (pm_power_off == &restart_poweroff_do_poweroff)
|
|
|
|
pm_power_off = NULL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct of_device_id of_restart_poweroff_match[] = {
|
|
|
|
{ .compatible = "restart-poweroff", },
|
|
|
|
{},
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct platform_driver restart_poweroff_driver = {
|
|
|
|
.probe = restart_poweroff_probe,
|
2013-01-30 04:28:13 -07:00
|
|
|
.remove = restart_poweroff_remove,
|
2012-12-28 05:25:11 -07:00
|
|
|
.driver = {
|
|
|
|
.name = "poweroff-restart",
|
|
|
|
.of_match_table = of_restart_poweroff_match,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
module_platform_driver(restart_poweroff_driver);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Andrew Lunn <andrew@lunn.ch");
|
|
|
|
MODULE_DESCRIPTION("restart poweroff driver");
|
2014-07-15 17:24:50 -06:00
|
|
|
MODULE_LICENSE("GPL v2");
|
2012-12-28 05:25:11 -07:00
|
|
|
MODULE_ALIAS("platform:poweroff-restart");
|