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