Linux Audio

Check our new training course

Loading...
v6.13.7
 1// SPDX-License-Identifier: GPL-2.0-only
 2/*
 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
 
 
 
 
 9 */
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>
15#include <linux/reboot.h>
16
17static int restart_poweroff_do_poweroff(struct sys_off_data *data)
18{
19	reboot_mode = REBOOT_HARD;
20	machine_restart(NULL);
21	return NOTIFY_DONE;
22}
23
24static int restart_poweroff_probe(struct platform_device *pdev)
25{
26	/* Set this handler to low priority to not override an existing handler */
27	return devm_register_sys_off_handler(&pdev->dev,
28					     SYS_OFF_MODE_POWER_OFF,
29					     SYS_OFF_PRIO_LOW,
30					     restart_poweroff_do_poweroff,
31					     NULL);
 
 
 
 
 
 
 
 
 
 
 
32}
33
34static const struct of_device_id of_restart_poweroff_match[] = {
35	{ .compatible = "restart-poweroff", },
36	{},
37};
38MODULE_DEVICE_TABLE(of, of_restart_poweroff_match);
39
40static struct platform_driver restart_poweroff_driver = {
41	.probe = restart_poweroff_probe,
 
42	.driver = {
43		.name = "poweroff-restart",
44		.of_match_table = of_restart_poweroff_match,
45	},
46};
47module_platform_driver(restart_poweroff_driver);
48
49MODULE_AUTHOR("Andrew Lunn <andrew@lunn.ch");
50MODULE_DESCRIPTION("restart poweroff driver");
 
51MODULE_ALIAS("platform:poweroff-restart");
v4.6
 
 1/*
 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>
18#include <linux/reboot.h>
19
20static void restart_poweroff_do_poweroff(void)
21{
22	reboot_mode = REBOOT_HARD;
23	machine_restart(NULL);
 
24}
25
26static int restart_poweroff_probe(struct platform_device *pdev)
27{
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
39static int restart_poweroff_remove(struct platform_device *pdev)
40{
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,
54	.remove = restart_poweroff_remove,
55	.driver = {
56		.name = "poweroff-restart",
57		.of_match_table = of_restart_poweroff_match,
58	},
59};
60module_platform_driver(restart_poweroff_driver);
61
62MODULE_AUTHOR("Andrew Lunn <andrew@lunn.ch");
63MODULE_DESCRIPTION("restart poweroff driver");
64MODULE_LICENSE("GPL v2");
65MODULE_ALIAS("platform:poweroff-restart");