Andrew Lunn | ffd8f9a | 2012-12-28 13:25:11 +0100 | [diff] [blame] | 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> |
Robin Holt | 7b6d864 | 2013-07-08 16:01:40 -0700 | [diff] [blame] | 18 | #include <linux/reboot.h> |
Andrew Lunn | ffd8f9a | 2012-12-28 13:25:11 +0100 | [diff] [blame] | 19 | |
| 20 | static void restart_poweroff_do_poweroff(void) |
| 21 | { |
Guenter Roeck | 0713e14 | 2014-09-26 00:03:16 +0000 | [diff] [blame] | 22 | reboot_mode = REBOOT_HARD; |
| 23 | machine_restart(NULL); |
Andrew Lunn | ffd8f9a | 2012-12-28 13:25:11 +0100 | [diff] [blame] | 24 | } |
| 25 | |
Thierry Reding | 60a1c4d | 2013-01-30 12:28:13 +0100 | [diff] [blame] | 26 | static int restart_poweroff_probe(struct platform_device *pdev) |
Andrew Lunn | ffd8f9a | 2012-12-28 13:25:11 +0100 | [diff] [blame] | 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 | |
Thierry Reding | 60a1c4d | 2013-01-30 12:28:13 +0100 | [diff] [blame] | 39 | static int restart_poweroff_remove(struct platform_device *pdev) |
Andrew Lunn | ffd8f9a | 2012-12-28 13:25:11 +0100 | [diff] [blame] | 40 | { |
| 41 | if (pm_power_off == &restart_poweroff_do_poweroff) |
| 42 | pm_power_off = NULL; |
| 43 | |
| 44 | return 0; |
| 45 | } |
| 46 | |
| 47 | static const struct of_device_id of_restart_poweroff_match[] = { |
| 48 | { .compatible = "restart-poweroff", }, |
| 49 | {}, |
| 50 | }; |
| 51 | |
| 52 | static struct platform_driver restart_poweroff_driver = { |
| 53 | .probe = restart_poweroff_probe, |
Thierry Reding | 60a1c4d | 2013-01-30 12:28:13 +0100 | [diff] [blame] | 54 | .remove = restart_poweroff_remove, |
Andrew Lunn | ffd8f9a | 2012-12-28 13:25:11 +0100 | [diff] [blame] | 55 | .driver = { |
| 56 | .name = "poweroff-restart", |
Andrew Lunn | ffd8f9a | 2012-12-28 13:25:11 +0100 | [diff] [blame] | 57 | .of_match_table = of_restart_poweroff_match, |
| 58 | }, |
| 59 | }; |
| 60 | module_platform_driver(restart_poweroff_driver); |
| 61 | |
| 62 | MODULE_AUTHOR("Andrew Lunn <andrew@lunn.ch"); |
| 63 | MODULE_DESCRIPTION("restart poweroff driver"); |
Bjorn Helgaas | 661468b | 2014-07-15 17:24:50 -0600 | [diff] [blame] | 64 | MODULE_LICENSE("GPL v2"); |
Andrew Lunn | ffd8f9a | 2012-12-28 13:25:11 +0100 | [diff] [blame] | 65 | MODULE_ALIAS("platform:poweroff-restart"); |