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)  * Copyright (C) 2014 Linaro Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Author: Linus Walleij <linus.walleij@linaro.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/mfd/syscon.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/reboot.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #define INTEGRATOR_HDR_CTRL_OFFSET	0x0C
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #define INTEGRATOR_HDR_LOCK_OFFSET	0x14
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #define INTEGRATOR_CM_CTRL_RESET	(1 << 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #define VERSATILE_SYS_LOCK_OFFSET	0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #define VERSATILE_SYS_RESETCTL_OFFSET	0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) /* Magic unlocking token used on all Versatile boards */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define VERSATILE_LOCK_VAL		0xA05F
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * We detect the different syscon types from the compatible strings.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) enum versatile_reboot {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	INTEGRATOR_REBOOT_CM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	VERSATILE_REBOOT_CM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	REALVIEW_REBOOT_EB,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	REALVIEW_REBOOT_PB1176,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	REALVIEW_REBOOT_PB11MP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	REALVIEW_REBOOT_PBA8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	REALVIEW_REBOOT_PBX,
^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) /* Pointer to the system controller */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) static struct regmap *syscon_regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) static enum versatile_reboot versatile_reboot_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) static const struct of_device_id versatile_reboot_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		.compatible = "arm,core-module-integrator",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		.data = (void *)INTEGRATOR_REBOOT_CM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		.compatible = "arm,core-module-versatile",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		.data = (void *)VERSATILE_REBOOT_CM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		.compatible = "arm,realview-eb-syscon",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		.data = (void *)REALVIEW_REBOOT_EB,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		.compatible = "arm,realview-pb1176-syscon",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		.data = (void *)REALVIEW_REBOOT_PB1176,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		.compatible = "arm,realview-pb11mp-syscon",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		.data = (void *)REALVIEW_REBOOT_PB11MP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		.compatible = "arm,realview-pba8-syscon",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		.data = (void *)REALVIEW_REBOOT_PBA8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		.compatible = "arm,realview-pbx-syscon",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		.data = (void *)REALVIEW_REBOOT_PBX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	},
^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 int versatile_reboot(struct notifier_block *this, unsigned long mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 			    void *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	/* Unlock the reset register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	/* Then hit reset on the different machines */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	switch (versatile_reboot_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	case INTEGRATOR_REBOOT_CM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		regmap_write(syscon_regmap, INTEGRATOR_HDR_LOCK_OFFSET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 			     VERSATILE_LOCK_VAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		regmap_update_bits(syscon_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 				   INTEGRATOR_HDR_CTRL_OFFSET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 				   INTEGRATOR_CM_CTRL_RESET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 				   INTEGRATOR_CM_CTRL_RESET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	case VERSATILE_REBOOT_CM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		regmap_write(syscon_regmap, VERSATILE_SYS_LOCK_OFFSET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 			     VERSATILE_LOCK_VAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		regmap_update_bits(syscon_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 				   VERSATILE_SYS_RESETCTL_OFFSET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 				   0x0107,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 				   0x0105);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		regmap_write(syscon_regmap, VERSATILE_SYS_LOCK_OFFSET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 			     0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	case REALVIEW_REBOOT_EB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		regmap_write(syscon_regmap, VERSATILE_SYS_LOCK_OFFSET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 			     VERSATILE_LOCK_VAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		regmap_write(syscon_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 			     VERSATILE_SYS_RESETCTL_OFFSET, 0x0008);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	case REALVIEW_REBOOT_PB1176:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		regmap_write(syscon_regmap, VERSATILE_SYS_LOCK_OFFSET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 			     VERSATILE_LOCK_VAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		regmap_write(syscon_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 			     VERSATILE_SYS_RESETCTL_OFFSET, 0x0100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	case REALVIEW_REBOOT_PB11MP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	case REALVIEW_REBOOT_PBA8:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		regmap_write(syscon_regmap, VERSATILE_SYS_LOCK_OFFSET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 			     VERSATILE_LOCK_VAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		regmap_write(syscon_regmap, VERSATILE_SYS_RESETCTL_OFFSET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 			     0x0000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		regmap_write(syscon_regmap, VERSATILE_SYS_RESETCTL_OFFSET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 			     0x0004);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	case REALVIEW_REBOOT_PBX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		regmap_write(syscon_regmap, VERSATILE_SYS_LOCK_OFFSET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 			     VERSATILE_LOCK_VAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		regmap_write(syscon_regmap, VERSATILE_SYS_RESETCTL_OFFSET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 			     0x00f0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		regmap_write(syscon_regmap, VERSATILE_SYS_RESETCTL_OFFSET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 			     0x00f4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	dsb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) static struct notifier_block versatile_reboot_nb = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	.notifier_call = versatile_reboot,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	.priority = 192,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) static int __init versatile_reboot_probe(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	const struct of_device_id *reboot_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	struct device_node *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	np = of_find_matching_node_and_match(NULL, versatile_reboot_of_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 						 &reboot_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	if (!np)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	versatile_reboot_type = (enum versatile_reboot)reboot_id->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	syscon_regmap = syscon_node_to_regmap(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	if (IS_ERR(syscon_regmap))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		return PTR_ERR(syscon_regmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	err = register_restart_handler(&versatile_reboot_nb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	pr_info("versatile reboot driver registered\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) device_initcall(versatile_reboot_probe);