xref: /OK3568_Linux_fs/u-boot/include/sysreset.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright (c) 2015 Google, Inc
3*4882a593Smuzhiyun  * Written by Simon Glass <sjg@chromium.org>
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * SPDX-License-Identifier:	GPL-2.0+
6*4882a593Smuzhiyun  */
7*4882a593Smuzhiyun 
8*4882a593Smuzhiyun #ifndef __SYSRESET_H
9*4882a593Smuzhiyun #define __SYSRESET_H
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun enum sysreset_t {
12*4882a593Smuzhiyun 	SYSRESET_WARM,	/* Reset CPU, keep GPIOs active */
13*4882a593Smuzhiyun 	SYSRESET_COLD,	/* Reset CPU and GPIOs */
14*4882a593Smuzhiyun 	SYSRESET_POWER,	/* Reset PMIC (remove and restore power) */
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun 	SYSRESET_COUNT,
17*4882a593Smuzhiyun };
18*4882a593Smuzhiyun 
19*4882a593Smuzhiyun struct sysreset_ops {
20*4882a593Smuzhiyun 	/**
21*4882a593Smuzhiyun 	 * request() - request a sysreset of the given type
22*4882a593Smuzhiyun 	 *
23*4882a593Smuzhiyun 	 * Note that this function may return before the reset takes effect.
24*4882a593Smuzhiyun 	 *
25*4882a593Smuzhiyun 	 * @type:	Reset type to request
26*4882a593Smuzhiyun 	 * @return -EINPROGRESS if the reset has been started and
27*4882a593Smuzhiyun 	 *		will complete soon, -EPROTONOSUPPORT if not supported
28*4882a593Smuzhiyun 	 *		by this device, 0 if the reset has already happened
29*4882a593Smuzhiyun 	 *		(in which case this method will not actually return)
30*4882a593Smuzhiyun 	 */
31*4882a593Smuzhiyun 	int (*request)(struct udevice *dev, enum sysreset_t type);
32*4882a593Smuzhiyun 
33*4882a593Smuzhiyun 	/**
34*4882a593Smuzhiyun 	 * request_by_mode() - request a sysreset of the given mode
35*4882a593Smuzhiyun 	 *
36*4882a593Smuzhiyun 	 * Note that this function may return before the reset takes effect.
37*4882a593Smuzhiyun 	 *
38*4882a593Smuzhiyun 	 * @mode:	mode to request
39*4882a593Smuzhiyun 	 * @return -EINPROGRESS if the reset has been started and
40*4882a593Smuzhiyun 	 *		will complete soon, -EPROTONOSUPPORT if not supported
41*4882a593Smuzhiyun 	 *		by this device, 0 if the reset has already happened
42*4882a593Smuzhiyun 	 *		(in which case this method will not actually return)
43*4882a593Smuzhiyun 	 */
44*4882a593Smuzhiyun 	int (*request_by_mode)(struct udevice *dev, const char *mode);
45*4882a593Smuzhiyun };
46*4882a593Smuzhiyun 
47*4882a593Smuzhiyun #define sysreset_get_ops(dev)        ((struct sysreset_ops *)(dev)->driver->ops)
48*4882a593Smuzhiyun 
49*4882a593Smuzhiyun #ifdef CONFIG_SYSRESET
50*4882a593Smuzhiyun /**
51*4882a593Smuzhiyun  * sysreset_request() - request a sysreset
52*4882a593Smuzhiyun  *
53*4882a593Smuzhiyun  * @type:	Reset type to request
54*4882a593Smuzhiyun  * @return 0 if OK, -EPROTONOSUPPORT if not supported by this device
55*4882a593Smuzhiyun  */
56*4882a593Smuzhiyun int sysreset_request(struct udevice *dev, enum sysreset_t type);
57*4882a593Smuzhiyun 
58*4882a593Smuzhiyun /**
59*4882a593Smuzhiyun  * sysreset_walk() - cause a system reset
60*4882a593Smuzhiyun  *
61*4882a593Smuzhiyun  * This works through the available sysreset devices until it finds one that can
62*4882a593Smuzhiyun  * perform a reset. If the provided sysreset type is not available, the next one
63*4882a593Smuzhiyun  * will be tried.
64*4882a593Smuzhiyun  *
65*4882a593Smuzhiyun  * If this function fails to reset, it will display a message and halt
66*4882a593Smuzhiyun  *
67*4882a593Smuzhiyun  * @type:	Reset type to request
68*4882a593Smuzhiyun  * @return -EINPROGRESS if a reset is in progress, -ENOSYS if not available
69*4882a593Smuzhiyun  */
70*4882a593Smuzhiyun int sysreset_walk(enum sysreset_t type);
71*4882a593Smuzhiyun 
72*4882a593Smuzhiyun /**
73*4882a593Smuzhiyun  * sysreset_walk_halt() - try to reset, otherwise halt
74*4882a593Smuzhiyun  *
75*4882a593Smuzhiyun  * This calls sysreset_walk(). If it returns, indicating that reset is not
76*4882a593Smuzhiyun  * supported, it prints a message and halts.
77*4882a593Smuzhiyun  */
78*4882a593Smuzhiyun void sysreset_walk_halt(enum sysreset_t type);
79*4882a593Smuzhiyun 
80*4882a593Smuzhiyun /**
81*4882a593Smuzhiyun  * reset_cpu() - calls sysreset_walk(SYSRESET_WARM)
82*4882a593Smuzhiyun  */
83*4882a593Smuzhiyun void reset_cpu(ulong addr);
84*4882a593Smuzhiyun 
85*4882a593Smuzhiyun /**
86*4882a593Smuzhiyun  * reboot() - calls sysreset_walk(SYSRESET_WARM)
87*4882a593Smuzhiyun  *
88*4882a593Smuzhiyun  * Support the command like: reboot loader/bootloader/recovery, etc.
89*4882a593Smuzhiyun  */
90*4882a593Smuzhiyun void reboot(const char *mode);
91*4882a593Smuzhiyun 
92*4882a593Smuzhiyun #else
93*4882a593Smuzhiyun #include <asm/io.h>
94*4882a593Smuzhiyun 
reset_cpu(ulong addr)95*4882a593Smuzhiyun inline void reset_cpu(ulong addr)
96*4882a593Smuzhiyun {
97*4882a593Smuzhiyun 	writel(CONFIG_SYSRESET_VAL, CONFIG_SYSRESET_REG);
98*4882a593Smuzhiyun 	dsb();
99*4882a593Smuzhiyun 	isb();
100*4882a593Smuzhiyun 
101*4882a593Smuzhiyun 	while (1)
102*4882a593Smuzhiyun 		;
103*4882a593Smuzhiyun }
104*4882a593Smuzhiyun #endif
105*4882a593Smuzhiyun 
106*4882a593Smuzhiyun #endif
107