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)  * Hisilicon SoC reset code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5)  * Copyright (c) 2014 Hisilicon Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6)  * Copyright (c) 2014 Linaro Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8)  * Author: Haojian Zhuang <haojian.zhuang@linaro.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/notifier.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/of_address.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/reboot.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <asm/proc-fns.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) static void __iomem *base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) static u32 reboot_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) static int hisi_restart_handler(struct notifier_block *this,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) 				unsigned long mode, void *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) 	writel_relaxed(0xdeadbeef, base + reboot_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) 	while (1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 		cpu_do_idle();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 	return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) static struct notifier_block hisi_restart_nb = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 	.notifier_call = hisi_restart_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 	.priority = 128,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) static int hisi_reboot_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 	struct device_node *np = pdev->dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 	base = of_iomap(np, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 	if (!base) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) 		WARN(1, "failed to map base address");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 	if (of_property_read_u32(np, "reboot-offset", &reboot_offset) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 		pr_err("failed to find reboot-offset property\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 		iounmap(base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 		return -EINVAL;
^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) 	err = register_restart_handler(&hisi_restart_nb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 		dev_err(&pdev->dev, "cannot register restart handler (err=%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) 			err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 		iounmap(base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) static const struct of_device_id hisi_reboot_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) 	{ .compatible = "hisilicon,sysctrl" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) 	{}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) static struct platform_driver hisi_reboot_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) 	.probe = hisi_reboot_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) 		.name = "hisi-reboot",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) 		.of_match_table = hisi_reboot_of_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) module_platform_driver(hisi_reboot_driver);