restart-poweroff.c 1.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * 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
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/platform_device.h>
#include <linux/of_platform.h>
#include <linux/module.h>
18
#include <linux/reboot.h>
19 20 21 22
#include <asm/system_misc.h>

static void restart_poweroff_do_poweroff(void)
{
23
	arm_pm_restart(REBOOT_HARD, NULL);
24 25
}

26
static int restart_poweroff_probe(struct platform_device *pdev)
27 28 29 30 31 32 33 34 35 36 37 38
{
	/* 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;
}

39
static int restart_poweroff_remove(struct platform_device *pdev)
40 41 42 43 44 45 46 47 48 49 50 51 52 53
{
	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,
54
	.remove = restart_poweroff_remove,
55 56 57 58 59 60 61 62 63 64 65 66
	.driver = {
		.name = "poweroff-restart",
		.owner = THIS_MODULE,
		.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");
MODULE_LICENSE("GPLv2");
MODULE_ALIAS("platform:poweroff-restart");