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