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