Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3)  * Power off by restarting and let u-boot keep hold of the machine
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  * until the user presses a button for example.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6)  * Andrew Lunn <andrew@lunn.ch>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8)  * Copyright (C) 2012 Andrew Lunn
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/of_platform.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/reboot.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) static void restart_poweroff_do_poweroff(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) 	reboot_mode = REBOOT_HARD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) 	machine_restart(NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) static int restart_poweroff_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) 	/* If a pm_power_off function has already been added, leave it alone */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) 	if (pm_power_off != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) 		dev_err(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) 			"pm_power_off function already registered");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 	pm_power_off = &restart_poweroff_do_poweroff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) static int restart_poweroff_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 	if (pm_power_off == &restart_poweroff_do_poweroff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 		pm_power_off = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) static const struct of_device_id of_restart_poweroff_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 	{ .compatible = "restart-poweroff", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 	{},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) static struct platform_driver restart_poweroff_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 	.probe = restart_poweroff_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 	.remove = restart_poweroff_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 		.name = "poweroff-restart",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 		.of_match_table = of_restart_poweroff_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) module_platform_driver(restart_poweroff_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) MODULE_AUTHOR("Andrew Lunn <andrew@lunn.ch");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) MODULE_DESCRIPTION("restart poweroff driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) MODULE_LICENSE("GPL v2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) MODULE_ALIAS("platform:poweroff-restart");