Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Stephen Warren | 1163625 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2015 Google, Inc |
| 4 | * Written by Simon Glass <sjg@chromium.org> |
Stephen Warren | 1163625 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #ifndef __SYSRESET_H |
| 8 | #define __SYSRESET_H |
| 9 | |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 10 | struct udevice; |
| 11 | |
Stephen Warren | 1163625 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 12 | enum sysreset_t { |
| 13 | SYSRESET_WARM, /* Reset CPU, keep GPIOs active */ |
| 14 | SYSRESET_COLD, /* Reset CPU and GPIOs */ |
| 15 | SYSRESET_POWER, /* Reset PMIC (remove and restore power) */ |
Simon Glass | 751fed4 | 2018-10-01 12:22:46 -0600 | [diff] [blame] | 16 | SYSRESET_POWER_OFF, /* Turn off power */ |
Stephen Warren | 1163625 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 17 | |
| 18 | SYSRESET_COUNT, |
| 19 | }; |
| 20 | |
| 21 | struct sysreset_ops { |
| 22 | /** |
| 23 | * request() - request a sysreset of the given type |
| 24 | * |
| 25 | * Note that this function may return before the reset takes effect. |
| 26 | * |
| 27 | * @type: Reset type to request |
| 28 | * @return -EINPROGRESS if the reset has been started and |
| 29 | * will complete soon, -EPROTONOSUPPORT if not supported |
| 30 | * by this device, 0 if the reset has already happened |
| 31 | * (in which case this method will not actually return) |
| 32 | */ |
| 33 | int (*request)(struct udevice *dev, enum sysreset_t type); |
Mario Six | 245f5cd | 2018-08-06 10:23:32 +0200 | [diff] [blame] | 34 | /** |
| 35 | * get_status() - get printable reset status information |
| 36 | * |
Simon Glass | eb51731 | 2018-10-01 12:22:45 -0600 | [diff] [blame] | 37 | * @dev: Device to check |
Mario Six | 245f5cd | 2018-08-06 10:23:32 +0200 | [diff] [blame] | 38 | * @buf: Buffer to receive the textual reset information |
| 39 | * @size: Size of the passed buffer |
| 40 | * @return 0 if OK, -ve on error |
| 41 | */ |
| 42 | int (*get_status)(struct udevice *dev, char *buf, int size); |
Simon Glass | 751fed4 | 2018-10-01 12:22:46 -0600 | [diff] [blame] | 43 | |
| 44 | /** |
| 45 | * get_last() - get information on the last reset |
| 46 | * |
| 47 | * @dev: Device to check |
| 48 | * @return last reset state (enum sysreset_t) or -ve error |
| 49 | */ |
| 50 | int (*get_last)(struct udevice *dev); |
Stephen Warren | 1163625 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | #define sysreset_get_ops(dev) ((struct sysreset_ops *)(dev)->driver->ops) |
| 54 | |
| 55 | /** |
| 56 | * sysreset_request() - request a sysreset |
| 57 | * |
| 58 | * @type: Reset type to request |
| 59 | * @return 0 if OK, -EPROTONOSUPPORT if not supported by this device |
| 60 | */ |
| 61 | int sysreset_request(struct udevice *dev, enum sysreset_t type); |
| 62 | |
| 63 | /** |
Simon Glass | eb51731 | 2018-10-01 12:22:45 -0600 | [diff] [blame] | 64 | * sysreset_get_status() - get printable reset status information |
Mario Six | 245f5cd | 2018-08-06 10:23:32 +0200 | [diff] [blame] | 65 | * |
Simon Glass | eb51731 | 2018-10-01 12:22:45 -0600 | [diff] [blame] | 66 | * @dev: Device to check |
Mario Six | 245f5cd | 2018-08-06 10:23:32 +0200 | [diff] [blame] | 67 | * @buf: Buffer to receive the textual reset information |
| 68 | * @size: Size of the passed buffer |
| 69 | * @return 0 if OK, -ve on error |
| 70 | */ |
| 71 | int sysreset_get_status(struct udevice *dev, char *buf, int size); |
| 72 | |
| 73 | /** |
Simon Glass | 751fed4 | 2018-10-01 12:22:46 -0600 | [diff] [blame] | 74 | * sysreset_get_last() - get information on the last reset |
| 75 | * |
| 76 | * @dev: Device to check |
| 77 | * @return last reset state (enum sysreset_t) or -ve error |
| 78 | */ |
| 79 | int sysreset_get_last(struct udevice *dev); |
| 80 | |
| 81 | /** |
Stephen Warren | 1163625 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 82 | * sysreset_walk() - cause a system reset |
| 83 | * |
| 84 | * This works through the available sysreset devices until it finds one that can |
| 85 | * perform a reset. If the provided sysreset type is not available, the next one |
| 86 | * will be tried. |
| 87 | * |
| 88 | * If this function fails to reset, it will display a message and halt |
| 89 | * |
| 90 | * @type: Reset type to request |
| 91 | * @return -EINPROGRESS if a reset is in progress, -ENOSYS if not available |
| 92 | */ |
| 93 | int sysreset_walk(enum sysreset_t type); |
| 94 | |
| 95 | /** |
Simon Glass | 751fed4 | 2018-10-01 12:22:46 -0600 | [diff] [blame] | 96 | * sysreset_get_last_walk() - get information on the last reset |
| 97 | * |
| 98 | * This works through the available sysreset devices until it finds one that can |
| 99 | * perform a reset. If the provided sysreset type is not available, the next one |
| 100 | * will be tried. |
| 101 | * |
| 102 | * If no device prives the information, this function returns -ENOENT |
| 103 | * |
| 104 | * @return last reset state (enum sysreset_t) or -ve error |
| 105 | */ |
| 106 | int sysreset_get_last_walk(void); |
| 107 | |
| 108 | /** |
Stephen Warren | 1163625 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 109 | * sysreset_walk_halt() - try to reset, otherwise halt |
| 110 | * |
| 111 | * This calls sysreset_walk(). If it returns, indicating that reset is not |
| 112 | * supported, it prints a message and halts. |
| 113 | */ |
| 114 | void sysreset_walk_halt(enum sysreset_t type); |
| 115 | |
| 116 | /** |
| 117 | * reset_cpu() - calls sysreset_walk(SYSRESET_WARM) |
| 118 | */ |
Harald Seiler | 35b65dd | 2020-12-15 16:47:52 +0100 | [diff] [blame] | 119 | void reset_cpu(void); |
Stephen Warren | 1163625 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 120 | |
| 121 | #endif |