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)  * Reset driver for Axxia devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5)  * Copyright (C) 2014 LSI
^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/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9) #include <linux/io.h>
^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/mfd/syscon.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/notifier.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/reboot.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define SC_CRIT_WRITE_KEY	0x1000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define SC_LATCH_ON_RESET	0x1004
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define SC_RESET_CONTROL	0x1008
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define   RSTCTL_RST_ZERO	(1<<3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define   RSTCTL_RST_FAB	(1<<2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define   RSTCTL_RST_CHIP	(1<<1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define   RSTCTL_RST_SYS	(1<<0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define SC_EFUSE_INT_STATUS	0x180c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define   EFUSE_READ_DONE	(1<<31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) static struct regmap *syscon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) static int axxia_restart_handler(struct notifier_block *this,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 				 unsigned long mode, void *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 	/* Access Key (0xab) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) 	regmap_write(syscon, SC_CRIT_WRITE_KEY, 0xab);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 	/* Select internal boot from 0xffff0000 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 	regmap_write(syscon, SC_LATCH_ON_RESET, 0x00000040);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 	/* Assert ResetReadDone (to avoid hanging in boot ROM) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 	regmap_write(syscon, SC_EFUSE_INT_STATUS, EFUSE_READ_DONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 	/* Assert chip reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 	regmap_update_bits(syscon, SC_RESET_CONTROL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 			   RSTCTL_RST_CHIP, RSTCTL_RST_CHIP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 	return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) static struct notifier_block axxia_restart_nb = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 	.notifier_call = axxia_restart_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 	.priority = 128,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) static int axxia_reset_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 	struct device *dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 	syscon = syscon_regmap_lookup_by_phandle(dev->of_node, "syscon");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) 	if (IS_ERR(syscon)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 		pr_err("%pOFn: syscon lookup failed\n", dev->of_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) 		return PTR_ERR(syscon);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) 	err = register_restart_handler(&axxia_restart_nb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) 		dev_err(dev, "cannot register restart handler (err=%d)\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) 	return err;
^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) static const struct of_device_id of_axxia_reset_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) 	{ .compatible = "lsi,axm55xx-reset", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) 	{},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) MODULE_DEVICE_TABLE(of, of_axxia_reset_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) static struct platform_driver axxia_reset_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) 	.probe = axxia_reset_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) 		.name = "axxia-reset",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) 		.of_match_table = of_match_ptr(of_axxia_reset_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) static int __init axxia_reset_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) 	return platform_driver_register(&axxia_reset_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) device_initcall(axxia_reset_init);