1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Copyright (c) 2015 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
13 * enum sysreset_t - system reset types
16 /** @SYSRESET_WARM: reset CPU, keep GPIOs active */
18 /** @SYSRESET_COLD: reset CPU and GPIOs */
20 /** @SYSRESET_POWER: reset PMIC (remove and restore power) */
22 /** @SYSRESET_POWER_OFF: turn off power */
24 /** @SYSRESET_COUNT: number of available reset types */
29 * struct sysreset_ops - operations of system reset drivers
33 * @request: request a sysreset of the given type
35 * Note that this function may return before the reset takes effect.
37 * @dev: Device to be used for system reset
38 * @type: Reset type to request
40 * -EINPROGRESS if the reset has been started and
41 * will complete soon, -EPROTONOSUPPORT if not supported
42 * by this device, 0 if the reset has already happened
43 * (in which case this method will not actually return)
45 int (*request)(struct udevice *dev, enum sysreset_t type);
47 * @get_status: get printable reset status information
49 * @dev: Device to check
50 * @buf: Buffer to receive the textual reset information
51 * @size: Size of the passed buffer
52 * Return: 0 if OK, -ve on error
54 int (*get_status)(struct udevice *dev, char *buf, int size);
57 * @get_last: get information on the last reset
59 * @dev: Device to check
60 * Return: last reset state (enum :enum:`sysreset_t`) or -ve error
62 int (*get_last)(struct udevice *dev);
65 #define sysreset_get_ops(dev) ((struct sysreset_ops *)(dev)->driver->ops)
68 * sysreset_request() - request a sysreset
70 * @dev: Device to be used for system reset
71 * @type: Reset type to request
72 * Return: 0 if OK, -EPROTONOSUPPORT if not supported by this device
74 int sysreset_request(struct udevice *dev, enum sysreset_t type);
77 * sysreset_get_status() - get printable reset status information
79 * @dev: Device to check
80 * @buf: Buffer to receive the textual reset information
81 * @size: Size of the passed buffer
82 * Return: 0 if OK, -ve on error
84 int sysreset_get_status(struct udevice *dev, char *buf, int size);
87 * sysreset_get_last() - get information on the last reset
89 * @dev: Device to check
90 * Return: last reset state (enum sysreset_t) or -ve error
92 int sysreset_get_last(struct udevice *dev);
95 * sysreset_walk() - cause a system reset
97 * This works through the available sysreset devices until it finds one that can
98 * perform a reset. If the provided sysreset type is not available, the next one
101 * If this function fails to reset, it will display a message and halt
103 * @type: Reset type to request
104 * Return: -EINPROGRESS if a reset is in progress, -ENOSYS if not available
106 int sysreset_walk(enum sysreset_t type);
109 * sysreset_get_last_walk() - get information on the last reset
111 * This works through the available sysreset devices until it finds one that can
112 * perform a reset. If the provided sysreset type is not available, the next one
115 * If no device prives the information, this function returns -ENOENT
117 * Return: last reset state (enum sysreset_t) or -ve error
119 int sysreset_get_last_walk(void);
122 * sysreset_walk_halt() - try to reset, otherwise halt
124 * This calls sysreset_walk(). If it returns, indicating that reset is not
125 * supported, it prints a message and halts.
127 * @type: Reset type to request
129 void sysreset_walk_halt(enum sysreset_t type);
132 * reset_cpu() - calls sysreset_walk(SYSRESET_WARM)
134 void reset_cpu(void);
137 * sysreset_register_wdt() - register a watchdog for use with sysreset
139 * This registers the given watchdog timer to be used to reset the system.
142 * @return: 0 if OK, -errno if error
144 int sysreset_register_wdt(struct udevice *dev);