blob: 343e46f1aa55081ec76b642b335686e011748987 [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) */
14
15 SYSRESET_COUNT,
16};
17
18struct 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);
Mario Six245f5cd2018-08-06 10:23:32 +020031 /**
32 * get_status() - get printable reset status information
33 *
Simon Glasseb517312018-10-01 12:22:45 -060034 * @dev: Device to check
Mario Six245f5cd2018-08-06 10:23:32 +020035 * @buf: Buffer to receive the textual reset information
36 * @size: Size of the passed buffer
37 * @return 0 if OK, -ve on error
38 */
39 int (*get_status)(struct udevice *dev, char *buf, int size);
Stephen Warren11636252016-05-12 12:03:35 -060040};
41
42#define sysreset_get_ops(dev) ((struct sysreset_ops *)(dev)->driver->ops)
43
44/**
45 * sysreset_request() - request a sysreset
46 *
47 * @type: Reset type to request
48 * @return 0 if OK, -EPROTONOSUPPORT if not supported by this device
49 */
50int sysreset_request(struct udevice *dev, enum sysreset_t type);
51
52/**
Simon Glasseb517312018-10-01 12:22:45 -060053 * sysreset_get_status() - get printable reset status information
Mario Six245f5cd2018-08-06 10:23:32 +020054 *
Simon Glasseb517312018-10-01 12:22:45 -060055 * @dev: Device to check
Mario Six245f5cd2018-08-06 10:23:32 +020056 * @buf: Buffer to receive the textual reset information
57 * @size: Size of the passed buffer
58 * @return 0 if OK, -ve on error
59 */
60int sysreset_get_status(struct udevice *dev, char *buf, int size);
61
62/**
Stephen Warren11636252016-05-12 12:03:35 -060063 * sysreset_walk() - cause a system reset
64 *
65 * This works through the available sysreset devices until it finds one that can
66 * perform a reset. If the provided sysreset type is not available, the next one
67 * will be tried.
68 *
69 * If this function fails to reset, it will display a message and halt
70 *
71 * @type: Reset type to request
72 * @return -EINPROGRESS if a reset is in progress, -ENOSYS if not available
73 */
74int sysreset_walk(enum sysreset_t type);
75
76/**
77 * sysreset_walk_halt() - try to reset, otherwise halt
78 *
79 * This calls sysreset_walk(). If it returns, indicating that reset is not
80 * supported, it prints a message and halts.
81 */
82void sysreset_walk_halt(enum sysreset_t type);
83
84/**
85 * reset_cpu() - calls sysreset_walk(SYSRESET_WARM)
86 */
87void reset_cpu(ulong addr);
88
89#endif