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 STMicroelectronics
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Power off Restart driver, used in STMicroelectronics devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Author: Christophe Kerello <christophe.kerello@st.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/module.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) #include <linux/of_platform.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/mfd/syscon.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) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) struct reset_syscfg {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 	struct regmap *regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	/* syscfg used for reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	unsigned int offset_rst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	unsigned int mask_rst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	/* syscfg used for unmask the reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	unsigned int offset_rst_msk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	unsigned int mask_rst_msk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) /* STiH407 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define STIH407_SYSCFG_4000	0x0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #define STIH407_SYSCFG_4008	0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) static struct reset_syscfg stih407_reset = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	.offset_rst = STIH407_SYSCFG_4000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	.mask_rst = BIT(0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	.offset_rst_msk = STIH407_SYSCFG_4008,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	.mask_rst_msk = BIT(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) };
^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 struct reset_syscfg *st_restart_syscfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) static int st_restart(struct notifier_block *this, unsigned long mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		      void *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	/* reset syscfg updated */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	regmap_update_bits(st_restart_syscfg->regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 			   st_restart_syscfg->offset_rst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 			   st_restart_syscfg->mask_rst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 			   0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	/* unmask the reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	regmap_update_bits(st_restart_syscfg->regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 			   st_restart_syscfg->offset_rst_msk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 			   st_restart_syscfg->mask_rst_msk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 			   0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) static struct notifier_block st_restart_nb = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	.notifier_call = st_restart,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	.priority = 192,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) static const struct of_device_id st_reset_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		.compatible = "st,stih407-restart",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		.data = (void *)&stih407_reset,
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) static int st_reset_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	struct device_node *np = pdev->dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	const struct of_device_id *match;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	struct device *dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	match = of_match_device(st_reset_of_match, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	if (!match)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	st_restart_syscfg = (struct reset_syscfg *)match->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	st_restart_syscfg->regmap =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		syscon_regmap_lookup_by_phandle(np, "st,syscfg");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	if (IS_ERR(st_restart_syscfg->regmap)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		dev_err(dev, "No syscfg phandle specified\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		return PTR_ERR(st_restart_syscfg->regmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	return register_restart_handler(&st_restart_nb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) static struct platform_driver st_reset_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	.probe = st_reset_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		.name = "st_reset",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		.of_match_table = st_reset_of_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) static int __init st_reset_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	return platform_driver_register(&st_reset_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) device_initcall(st_reset_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) MODULE_AUTHOR("Christophe Kerello <christophe.kerello@st.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) MODULE_DESCRIPTION("STMicroelectronics Power off Restart driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) MODULE_LICENSE("GPL v2");