blob: ff20abdeed3cfd7d7dde8a3891ca156f04beb8b8 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Stephen Warren11636252016-05-12 12:03:35 -06002/*
3 * Copyright (c) 2015 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
Stephen Warren11636252016-05-12 12:03:35 -06005 */
6
7#ifndef __SYSRESET_H
8#define __SYSRESET_H
9
Simon Glass401d1c42020-10-30 21:38:53 -060010struct udevice;
11
Heinrich Schuchardt1da0b6a2021-09-23 11:06:16 +020012/**
13 * enum sysreset_t - system reset types
14 */
Stephen Warren11636252016-05-12 12:03:35 -060015enum sysreset_t {
Heinrich Schuchardt1da0b6a2021-09-23 11:06:16 +020016 /** @SYSRESET_WARM: reset CPU, keep GPIOs active */
17 SYSRESET_WARM,
18 /** @SYSRESET_COLD: reset CPU and GPIOs */
19 SYSRESET_COLD,
20 /** @SYSRESET_POWER: reset PMIC (remove and restore power) */
21 SYSRESET_POWER,
22 /** @SYSRESET_POWER_OFF: turn off power */
23 SYSRESET_POWER_OFF,
24 /** @SYSRESET_COUNT: number of available reset types */
Stephen Warren11636252016-05-12 12:03:35 -060025 SYSRESET_COUNT,
26};
27
Heinrich Schuchardt1da0b6a2021-09-23 11:06:16 +020028/**
29 * struct sysreset_ops - operations of system reset drivers
30 */
Stephen Warren11636252016-05-12 12:03:35 -060031struct sysreset_ops {
32 /**
Heinrich Schuchardt1da0b6a2021-09-23 11:06:16 +020033 * @request: request a sysreset of the given type
Stephen Warren11636252016-05-12 12:03:35 -060034 *
35 * Note that this function may return before the reset takes effect.
36 *
Heinrich Schuchardt1da0b6a2021-09-23 11:06:16 +020037 * @dev: Device to be used for system reset
Stephen Warren11636252016-05-12 12:03:35 -060038 * @type: Reset type to request
Heinrich Schuchardt1da0b6a2021-09-23 11:06:16 +020039 * Return:
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)
Stephen Warren11636252016-05-12 12:03:35 -060044 */
45 int (*request)(struct udevice *dev, enum sysreset_t type);
Mario Six245f5cd2018-08-06 10:23:32 +020046 /**
Heinrich Schuchardt1da0b6a2021-09-23 11:06:16 +020047 * @get_status: get printable reset status information
Mario Six245f5cd2018-08-06 10:23:32 +020048 *
Simon Glasseb517312018-10-01 12:22:45 -060049 * @dev: Device to check
Mario Six245f5cd2018-08-06 10:23:32 +020050 * @buf: Buffer to receive the textual reset information
51 * @size: Size of the passed buffer
Heinrich Schuchardt1da0b6a2021-09-23 11:06:16 +020052 * Return: 0 if OK, -ve on error
Mario Six245f5cd2018-08-06 10:23:32 +020053 */
54 int (*get_status)(struct udevice *dev, char *buf, int size);
Simon Glass751fed42018-10-01 12:22:46 -060055
56 /**
Heinrich Schuchardt1da0b6a2021-09-23 11:06:16 +020057 * @get_last: get information on the last reset
Simon Glass751fed42018-10-01 12:22:46 -060058 *
59 * @dev: Device to check
Heinrich Schuchardt1da0b6a2021-09-23 11:06:16 +020060 * Return: last reset state (enum :enum:`sysreset_t`) or -ve error
Simon Glass751fed42018-10-01 12:22:46 -060061 */
62 int (*get_last)(struct udevice *dev);
Stephen Warren11636252016-05-12 12:03:35 -060063};
64
65#define sysreset_get_ops(dev) ((struct sysreset_ops *)(dev)->driver->ops)
66
67/**
68 * sysreset_request() - request a sysreset
69 *
Heinrich Schuchardt1da0b6a2021-09-23 11:06:16 +020070 * @dev: Device to be used for system reset
Stephen Warren11636252016-05-12 12:03:35 -060071 * @type: Reset type to request
Heinrich Schuchardt1da0b6a2021-09-23 11:06:16 +020072 * Return: 0 if OK, -EPROTONOSUPPORT if not supported by this device
Stephen Warren11636252016-05-12 12:03:35 -060073 */
74int sysreset_request(struct udevice *dev, enum sysreset_t type);
75
76/**
Simon Glasseb517312018-10-01 12:22:45 -060077 * sysreset_get_status() - get printable reset status information
Mario Six245f5cd2018-08-06 10:23:32 +020078 *
Simon Glasseb517312018-10-01 12:22:45 -060079 * @dev: Device to check
Mario Six245f5cd2018-08-06 10:23:32 +020080 * @buf: Buffer to receive the textual reset information
81 * @size: Size of the passed buffer
Heinrich Schuchardt1da0b6a2021-09-23 11:06:16 +020082 * Return: 0 if OK, -ve on error
Mario Six245f5cd2018-08-06 10:23:32 +020083 */
84int sysreset_get_status(struct udevice *dev, char *buf, int size);
85
86/**
Simon Glass751fed42018-10-01 12:22:46 -060087 * sysreset_get_last() - get information on the last reset
88 *
89 * @dev: Device to check
Heinrich Schuchardt1da0b6a2021-09-23 11:06:16 +020090 * Return: last reset state (enum sysreset_t) or -ve error
Simon Glass751fed42018-10-01 12:22:46 -060091 */
92int sysreset_get_last(struct udevice *dev);
93
94/**
Stephen Warren11636252016-05-12 12:03:35 -060095 * sysreset_walk() - cause a system reset
96 *
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
99 * will be tried.
100 *
101 * If this function fails to reset, it will display a message and halt
102 *
103 * @type: Reset type to request
Heinrich Schuchardt1da0b6a2021-09-23 11:06:16 +0200104 * Return: -EINPROGRESS if a reset is in progress, -ENOSYS if not available
Stephen Warren11636252016-05-12 12:03:35 -0600105 */
106int sysreset_walk(enum sysreset_t type);
107
108/**
Simon Glass751fed42018-10-01 12:22:46 -0600109 * sysreset_get_last_walk() - get information on the last reset
110 *
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
113 * will be tried.
114 *
115 * If no device prives the information, this function returns -ENOENT
116 *
Heinrich Schuchardt1da0b6a2021-09-23 11:06:16 +0200117 * Return: last reset state (enum sysreset_t) or -ve error
Simon Glass751fed42018-10-01 12:22:46 -0600118 */
119int sysreset_get_last_walk(void);
120
121/**
Stephen Warren11636252016-05-12 12:03:35 -0600122 * sysreset_walk_halt() - try to reset, otherwise halt
123 *
124 * This calls sysreset_walk(). If it returns, indicating that reset is not
125 * supported, it prints a message and halts.
Heinrich Schuchardt1da0b6a2021-09-23 11:06:16 +0200126 *
127 * @type: Reset type to request
Stephen Warren11636252016-05-12 12:03:35 -0600128 */
129void sysreset_walk_halt(enum sysreset_t type);
130
131/**
132 * reset_cpu() - calls sysreset_walk(SYSRESET_WARM)
133 */
Harald Seiler35b65dd2020-12-15 16:47:52 +0100134void reset_cpu(void);
Stephen Warren11636252016-05-12 12:03:35 -0600135
Samuel Hollanda8f63d12021-11-03 22:55:14 -0500136/**
137 * sysreset_register_wdt() - register a watchdog for use with sysreset
138 *
139 * This registers the given watchdog timer to be used to reset the system.
140 *
141 * @dev: WDT device
142 * @return: 0 if OK, -errno if error
143 */
144int sysreset_register_wdt(struct udevice *dev);
145
Stephen Warren11636252016-05-12 12:03:35 -0600146#endif