blob: 61295e3fcbb7850bc289dd4349ccda38d7410e22 [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
10enum 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) */
Simon Glass751fed42018-10-01 12:22:46 -060014 SYSRESET_POWER_OFF, /* Turn off power */
Stephen Warren11636252016-05-12 12:03:35 -060015
16 SYSRESET_COUNT,
17};
18
19struct 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);
Mario Six245f5cd2018-08-06 10:23:32 +020032 /**
33 * get_status() - get printable reset status information
34 *
Simon Glasseb517312018-10-01 12:22:45 -060035 * @dev: Device to check
Mario Six245f5cd2018-08-06 10:23:32 +020036 * @buf: Buffer to receive the textual reset information
37 * @size: Size of the passed buffer
38 * @return 0 if OK, -ve on error
39 */
40 int (*get_status)(struct udevice *dev, char *buf, int size);
Simon Glass751fed42018-10-01 12:22:46 -060041
42 /**
43 * get_last() - get information on the last reset
44 *
45 * @dev: Device to check
46 * @return last reset state (enum sysreset_t) or -ve error
47 */
48 int (*get_last)(struct udevice *dev);
Stephen Warren11636252016-05-12 12:03:35 -060049};
50
51#define sysreset_get_ops(dev) ((struct sysreset_ops *)(dev)->driver->ops)
52
53/**
54 * sysreset_request() - request a sysreset
55 *
56 * @type: Reset type to request
57 * @return 0 if OK, -EPROTONOSUPPORT if not supported by this device
58 */
59int sysreset_request(struct udevice *dev, enum sysreset_t type);
60
61/**
Simon Glasseb517312018-10-01 12:22:45 -060062 * sysreset_get_status() - get printable reset status information
Mario Six245f5cd2018-08-06 10:23:32 +020063 *
Simon Glasseb517312018-10-01 12:22:45 -060064 * @dev: Device to check
Mario Six245f5cd2018-08-06 10:23:32 +020065 * @buf: Buffer to receive the textual reset information
66 * @size: Size of the passed buffer
67 * @return 0 if OK, -ve on error
68 */
69int sysreset_get_status(struct udevice *dev, char *buf, int size);
70
71/**
Simon Glass751fed42018-10-01 12:22:46 -060072 * sysreset_get_last() - get information on the last reset
73 *
74 * @dev: Device to check
75 * @return last reset state (enum sysreset_t) or -ve error
76 */
77int sysreset_get_last(struct udevice *dev);
78
79/**
Stephen Warren11636252016-05-12 12:03:35 -060080 * sysreset_walk() - cause a system reset
81 *
82 * This works through the available sysreset devices until it finds one that can
83 * perform a reset. If the provided sysreset type is not available, the next one
84 * will be tried.
85 *
86 * If this function fails to reset, it will display a message and halt
87 *
88 * @type: Reset type to request
89 * @return -EINPROGRESS if a reset is in progress, -ENOSYS if not available
90 */
91int sysreset_walk(enum sysreset_t type);
92
93/**
Simon Glass751fed42018-10-01 12:22:46 -060094 * sysreset_get_last_walk() - get information on the last reset
95 *
96 * This works through the available sysreset devices until it finds one that can
97 * perform a reset. If the provided sysreset type is not available, the next one
98 * will be tried.
99 *
100 * If no device prives the information, this function returns -ENOENT
101 *
102 * @return last reset state (enum sysreset_t) or -ve error
103 */
104int sysreset_get_last_walk(void);
105
106/**
Stephen Warren11636252016-05-12 12:03:35 -0600107 * sysreset_walk_halt() - try to reset, otherwise halt
108 *
109 * This calls sysreset_walk(). If it returns, indicating that reset is not
110 * supported, it prints a message and halts.
111 */
112void sysreset_walk_halt(enum sysreset_t type);
113
114/**
115 * reset_cpu() - calls sysreset_walk(SYSRESET_WARM)
116 */
117void reset_cpu(ulong addr);
118
119#endif