Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Stephen Warren | 859f256 | 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 | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #ifndef __SYSRESET_H |
| 8 | #define __SYSRESET_H |
| 9 | |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 10 | struct udevice; |
| 11 | |
Heinrich Schuchardt | ca52380 | 2021-09-23 11:06:16 +0200 | [diff] [blame] | 12 | /** |
| 13 | * enum sysreset_t - system reset types |
| 14 | */ |
Stephen Warren | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 15 | enum sysreset_t { |
Heinrich Schuchardt | ca52380 | 2021-09-23 11:06:16 +0200 | [diff] [blame] | 16 | /** @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 Warren | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 25 | SYSRESET_COUNT, |
| 26 | }; |
| 27 | |
Heinrich Schuchardt | ca52380 | 2021-09-23 11:06:16 +0200 | [diff] [blame] | 28 | /** |
| 29 | * struct sysreset_ops - operations of system reset drivers |
| 30 | */ |
Stephen Warren | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 31 | struct sysreset_ops { |
| 32 | /** |
Heinrich Schuchardt | ca52380 | 2021-09-23 11:06:16 +0200 | [diff] [blame] | 33 | * @request: request a sysreset of the given type |
Stephen Warren | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 34 | * |
| 35 | * Note that this function may return before the reset takes effect. |
| 36 | * |
Heinrich Schuchardt | ca52380 | 2021-09-23 11:06:16 +0200 | [diff] [blame] | 37 | * @dev: Device to be used for system reset |
Stephen Warren | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 38 | * @type: Reset type to request |
Heinrich Schuchardt | ca52380 | 2021-09-23 11:06:16 +0200 | [diff] [blame] | 39 | * 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 Warren | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 44 | */ |
| 45 | int (*request)(struct udevice *dev, enum sysreset_t type); |
Mario Six | 265f82a | 2018-08-06 10:23:32 +0200 | [diff] [blame] | 46 | /** |
Heinrich Schuchardt | ca52380 | 2021-09-23 11:06:16 +0200 | [diff] [blame] | 47 | * @get_status: get printable reset status information |
Mario Six | 265f82a | 2018-08-06 10:23:32 +0200 | [diff] [blame] | 48 | * |
Simon Glass | b8b4d2a | 2018-10-01 12:22:45 -0600 | [diff] [blame] | 49 | * @dev: Device to check |
Mario Six | 265f82a | 2018-08-06 10:23:32 +0200 | [diff] [blame] | 50 | * @buf: Buffer to receive the textual reset information |
| 51 | * @size: Size of the passed buffer |
Heinrich Schuchardt | ca52380 | 2021-09-23 11:06:16 +0200 | [diff] [blame] | 52 | * Return: 0 if OK, -ve on error |
Mario Six | 265f82a | 2018-08-06 10:23:32 +0200 | [diff] [blame] | 53 | */ |
| 54 | int (*get_status)(struct udevice *dev, char *buf, int size); |
Simon Glass | 07fbba5 | 2018-10-01 12:22:46 -0600 | [diff] [blame] | 55 | |
| 56 | /** |
Heinrich Schuchardt | ca52380 | 2021-09-23 11:06:16 +0200 | [diff] [blame] | 57 | * @get_last: get information on the last reset |
Simon Glass | 07fbba5 | 2018-10-01 12:22:46 -0600 | [diff] [blame] | 58 | * |
| 59 | * @dev: Device to check |
Heinrich Schuchardt | ca52380 | 2021-09-23 11:06:16 +0200 | [diff] [blame] | 60 | * Return: last reset state (enum :enum:`sysreset_t`) or -ve error |
Simon Glass | 07fbba5 | 2018-10-01 12:22:46 -0600 | [diff] [blame] | 61 | */ |
| 62 | int (*get_last)(struct udevice *dev); |
Stephen Warren | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | #define sysreset_get_ops(dev) ((struct sysreset_ops *)(dev)->driver->ops) |
| 66 | |
| 67 | /** |
| 68 | * sysreset_request() - request a sysreset |
| 69 | * |
Heinrich Schuchardt | ca52380 | 2021-09-23 11:06:16 +0200 | [diff] [blame] | 70 | * @dev: Device to be used for system reset |
Stephen Warren | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 71 | * @type: Reset type to request |
Heinrich Schuchardt | ca52380 | 2021-09-23 11:06:16 +0200 | [diff] [blame] | 72 | * Return: 0 if OK, -EPROTONOSUPPORT if not supported by this device |
Stephen Warren | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 73 | */ |
| 74 | int sysreset_request(struct udevice *dev, enum sysreset_t type); |
| 75 | |
| 76 | /** |
Simon Glass | b8b4d2a | 2018-10-01 12:22:45 -0600 | [diff] [blame] | 77 | * sysreset_get_status() - get printable reset status information |
Mario Six | 265f82a | 2018-08-06 10:23:32 +0200 | [diff] [blame] | 78 | * |
Simon Glass | b8b4d2a | 2018-10-01 12:22:45 -0600 | [diff] [blame] | 79 | * @dev: Device to check |
Mario Six | 265f82a | 2018-08-06 10:23:32 +0200 | [diff] [blame] | 80 | * @buf: Buffer to receive the textual reset information |
| 81 | * @size: Size of the passed buffer |
Heinrich Schuchardt | ca52380 | 2021-09-23 11:06:16 +0200 | [diff] [blame] | 82 | * Return: 0 if OK, -ve on error |
Mario Six | 265f82a | 2018-08-06 10:23:32 +0200 | [diff] [blame] | 83 | */ |
| 84 | int sysreset_get_status(struct udevice *dev, char *buf, int size); |
| 85 | |
| 86 | /** |
Simon Glass | 07fbba5 | 2018-10-01 12:22:46 -0600 | [diff] [blame] | 87 | * sysreset_get_last() - get information on the last reset |
| 88 | * |
| 89 | * @dev: Device to check |
Heinrich Schuchardt | ca52380 | 2021-09-23 11:06:16 +0200 | [diff] [blame] | 90 | * Return: last reset state (enum sysreset_t) or -ve error |
Simon Glass | 07fbba5 | 2018-10-01 12:22:46 -0600 | [diff] [blame] | 91 | */ |
| 92 | int sysreset_get_last(struct udevice *dev); |
| 93 | |
| 94 | /** |
Stephen Warren | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 95 | * 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 Schuchardt | ca52380 | 2021-09-23 11:06:16 +0200 | [diff] [blame] | 104 | * Return: -EINPROGRESS if a reset is in progress, -ENOSYS if not available |
Stephen Warren | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 105 | */ |
| 106 | int sysreset_walk(enum sysreset_t type); |
| 107 | |
| 108 | /** |
Simon Glass | 07fbba5 | 2018-10-01 12:22:46 -0600 | [diff] [blame] | 109 | * 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 Schuchardt | ca52380 | 2021-09-23 11:06:16 +0200 | [diff] [blame] | 117 | * Return: last reset state (enum sysreset_t) or -ve error |
Simon Glass | 07fbba5 | 2018-10-01 12:22:46 -0600 | [diff] [blame] | 118 | */ |
| 119 | int sysreset_get_last_walk(void); |
| 120 | |
| 121 | /** |
Stephen Warren | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 122 | * 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 Schuchardt | ca52380 | 2021-09-23 11:06:16 +0200 | [diff] [blame] | 126 | * |
| 127 | * @type: Reset type to request |
Stephen Warren | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 128 | */ |
| 129 | void sysreset_walk_halt(enum sysreset_t type); |
| 130 | |
| 131 | /** |
| 132 | * reset_cpu() - calls sysreset_walk(SYSRESET_WARM) |
| 133 | */ |
Harald Seiler | 6f14d5f | 2020-12-15 16:47:52 +0100 | [diff] [blame] | 134 | void reset_cpu(void); |
Stephen Warren | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 135 | |
Samuel Holland | 3a8713a | 2021-11-03 22:55:14 -0500 | [diff] [blame^] | 136 | /** |
| 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 | */ |
| 144 | int sysreset_register_wdt(struct udevice *dev); |
| 145 | |
Stephen Warren | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 146 | #endif |