Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Stephen Warren | 61f5ddc | 2016-07-13 13:45:31 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2016, NVIDIA CORPORATION. |
Stephen Warren | 61f5ddc | 2016-07-13 13:45:31 -0600 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #ifndef _POWER_DOMAIN_H |
| 7 | #define _POWER_DOMAIN_H |
| 8 | |
Max Krummenacher | e2e6929 | 2024-01-18 19:10:47 +0100 | [diff] [blame] | 9 | #include <linux/errno.h> |
| 10 | |
Stephen Warren | 61f5ddc | 2016-07-13 13:45:31 -0600 | [diff] [blame] | 11 | /** |
| 12 | * A power domain is a portion of an SoC or chip that is powered by a |
| 13 | * switchable source of power. In many cases, software has control over the |
| 14 | * power domain, and can turn the power source on or off. This is typically |
| 15 | * done to save power by powering off unused devices, or to enable software |
| 16 | * sequencing of initial powerup at boot. This API provides a means for |
| 17 | * drivers to turn power domains on and off. |
| 18 | * |
| 19 | * A driver that implements UCLASS_POWER_DOMAIN is a power domain controller or |
| 20 | * provider. A controller will often implement multiple separate power domains, |
| 21 | * since the hardware it manages often has this capability. |
| 22 | * power-domain-uclass.h describes the interface which power domain controllers |
| 23 | * must implement. |
| 24 | * |
| 25 | * Depending on the power domain controller hardware, changing the state of a |
| 26 | * power domain may require performing related operations on other resources. |
| 27 | * For example, some power domains may require certain clocks to be enabled |
| 28 | * whenever the power domain is powered on, or during the time when the power |
| 29 | * domain is transitioning state. These details are implementation-specific |
| 30 | * and should ideally be encapsulated entirely within the provider driver, or |
| 31 | * configured through mechanisms (e.g. device tree) that do not require client |
| 32 | * drivers to provide extra configuration information. |
| 33 | * |
| 34 | * Power domain consumers/clients are the drivers for HW modules within the |
| 35 | * power domain. This header file describes the API used by those drivers. |
| 36 | * |
| 37 | * In many cases, a single complex IO controller (e.g. a PCIe controller) will |
| 38 | * be the sole logic contained within a power domain. In such cases, it is |
| 39 | * logical for the relevant device driver to directly control that power |
| 40 | * domain. In other cases, multiple controllers, each with their own driver, |
| 41 | * may be contained in a single power domain. Any logic require to co-ordinate |
| 42 | * between drivers for these multiple controllers is beyond the scope of this |
| 43 | * API at present. Equally, this API does not define or implement any policy |
| 44 | * by which power domains are managed. |
| 45 | */ |
| 46 | |
| 47 | struct udevice; |
| 48 | |
| 49 | /** |
| 50 | * struct power_domain - A handle to (allowing control of) a single power domain. |
| 51 | * |
| 52 | * Clients provide storage for power domain handles. The content of the |
| 53 | * structure is managed solely by the power domain API and power domain |
| 54 | * drivers. A power domain struct is initialized by "get"ing the power domain |
| 55 | * struct. The power domain struct is passed to all other power domain APIs to |
| 56 | * identify which power domain to operate upon. |
| 57 | * |
| 58 | * @dev: The device which implements the power domain. |
| 59 | * @id: The power domain ID within the provider. |
Lokesh Vutla | fd4e7be | 2019-06-07 19:24:44 +0530 | [diff] [blame] | 60 | * @priv: Private data corresponding to each power domain. |
Stephen Warren | 61f5ddc | 2016-07-13 13:45:31 -0600 | [diff] [blame] | 61 | */ |
| 62 | struct power_domain { |
| 63 | struct udevice *dev; |
Stephen Warren | 61f5ddc | 2016-07-13 13:45:31 -0600 | [diff] [blame] | 64 | unsigned long id; |
Lokesh Vutla | fd4e7be | 2019-06-07 19:24:44 +0530 | [diff] [blame] | 65 | void *priv; |
Stephen Warren | 61f5ddc | 2016-07-13 13:45:31 -0600 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | /** |
| 69 | * power_domain_get - Get/request the power domain for a device. |
| 70 | * |
| 71 | * This looks up and requests a power domain. Each device is assumed to have |
| 72 | * a single (or, at least one) power domain associated with it somehow, and |
| 73 | * that domain, or the first/default domain. The mapping of client device to |
| 74 | * provider power domain may be via device-tree properties, board-provided |
| 75 | * mapping tables, or some other mechanism. |
| 76 | * |
| 77 | * @dev: The client device. |
| 78 | * @power_domain A pointer to a power domain struct to initialize. |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 79 | * Return: 0 if OK, or a negative error code. |
Stephen Warren | 61f5ddc | 2016-07-13 13:45:31 -0600 | [diff] [blame] | 80 | */ |
Peng Fan | 58d3de1 | 2018-07-27 10:20:36 +0800 | [diff] [blame] | 81 | #if CONFIG_IS_ENABLED(POWER_DOMAIN) |
Stephen Warren | 61f5ddc | 2016-07-13 13:45:31 -0600 | [diff] [blame] | 82 | int power_domain_get(struct udevice *dev, struct power_domain *power_domain); |
Peng Fan | 58d3de1 | 2018-07-27 10:20:36 +0800 | [diff] [blame] | 83 | #else |
| 84 | static inline |
| 85 | int power_domain_get(struct udevice *dev, struct power_domain *power_domain) |
| 86 | { |
| 87 | return -ENOSYS; |
| 88 | } |
| 89 | #endif |
Stephen Warren | 61f5ddc | 2016-07-13 13:45:31 -0600 | [diff] [blame] | 90 | |
| 91 | /** |
Lokesh Vutla | 2618cf3 | 2018-08-27 15:57:44 +0530 | [diff] [blame] | 92 | * power_domain_get_by_index - Get the indexed power domain for a device. |
| 93 | * |
| 94 | * @dev: The client device. |
| 95 | * @power_domain: A pointer to a power domain struct to initialize. |
| 96 | * @index: Power domain index to be powered on. |
| 97 | * |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 98 | * Return: 0 if OK, or a negative error code. |
Lokesh Vutla | 2618cf3 | 2018-08-27 15:57:44 +0530 | [diff] [blame] | 99 | */ |
| 100 | #if CONFIG_IS_ENABLED(POWER_DOMAIN) |
| 101 | int power_domain_get_by_index(struct udevice *dev, |
| 102 | struct power_domain *power_domain, int index); |
| 103 | #else |
| 104 | static inline |
| 105 | int power_domain_get_by_index(struct udevice *dev, |
| 106 | struct power_domain *power_domain, int index) |
| 107 | { |
| 108 | return -ENOSYS; |
| 109 | } |
| 110 | #endif |
| 111 | |
| 112 | /** |
Marek Vasut | 63c390a | 2022-04-13 00:42:52 +0200 | [diff] [blame] | 113 | * power_domain_get_by_name - Get the named power domain for a device. |
| 114 | * |
| 115 | * @dev: The client device. |
| 116 | * @power_domain: A pointer to a power domain struct to initialize. |
| 117 | * @name: Power domain name to be powered on. |
| 118 | * |
| 119 | * Return: 0 if OK, or a negative error code. |
| 120 | */ |
| 121 | #if CONFIG_IS_ENABLED(POWER_DOMAIN) |
| 122 | int power_domain_get_by_name(struct udevice *dev, |
| 123 | struct power_domain *power_domain, const char *name); |
| 124 | #else |
| 125 | static inline |
| 126 | int power_domain_get_by_name(struct udevice *dev, |
| 127 | struct power_domain *power_domain, const char *name) |
| 128 | { |
| 129 | return -ENOSYS; |
| 130 | } |
| 131 | #endif |
| 132 | |
| 133 | /** |
Stephen Warren | 61f5ddc | 2016-07-13 13:45:31 -0600 | [diff] [blame] | 134 | * power_domain_free - Free a previously requested power domain. |
| 135 | * |
| 136 | * @power_domain: A power domain struct that was previously successfully |
| 137 | * requested by power_domain_get(). |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 138 | * Return: 0 if OK, or a negative error code. |
Stephen Warren | 61f5ddc | 2016-07-13 13:45:31 -0600 | [diff] [blame] | 139 | */ |
Peng Fan | 58d3de1 | 2018-07-27 10:20:36 +0800 | [diff] [blame] | 140 | #if CONFIG_IS_ENABLED(POWER_DOMAIN) |
Stephen Warren | 61f5ddc | 2016-07-13 13:45:31 -0600 | [diff] [blame] | 141 | int power_domain_free(struct power_domain *power_domain); |
Peng Fan | 58d3de1 | 2018-07-27 10:20:36 +0800 | [diff] [blame] | 142 | #else |
| 143 | static inline int power_domain_free(struct power_domain *power_domain) |
| 144 | { |
| 145 | return -ENOSYS; |
| 146 | } |
| 147 | #endif |
Stephen Warren | 61f5ddc | 2016-07-13 13:45:31 -0600 | [diff] [blame] | 148 | |
| 149 | /** |
| 150 | * power_domain_on - Enable power to a power domain. |
| 151 | * |
| 152 | * @power_domain: A power domain struct that was previously successfully |
| 153 | * requested by power_domain_get(). |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 154 | * Return: 0 if OK, or a negative error code. |
Stephen Warren | 61f5ddc | 2016-07-13 13:45:31 -0600 | [diff] [blame] | 155 | */ |
Peng Fan | 58d3de1 | 2018-07-27 10:20:36 +0800 | [diff] [blame] | 156 | #if CONFIG_IS_ENABLED(POWER_DOMAIN) |
Stephen Warren | 61f5ddc | 2016-07-13 13:45:31 -0600 | [diff] [blame] | 157 | int power_domain_on(struct power_domain *power_domain); |
Peng Fan | 58d3de1 | 2018-07-27 10:20:36 +0800 | [diff] [blame] | 158 | #else |
| 159 | static inline int power_domain_on(struct power_domain *power_domain) |
| 160 | { |
| 161 | return -ENOSYS; |
| 162 | } |
| 163 | #endif |
Stephen Warren | 61f5ddc | 2016-07-13 13:45:31 -0600 | [diff] [blame] | 164 | |
| 165 | /** |
Anatolij Gustschin | f752e57 | 2019-07-10 10:03:13 +0200 | [diff] [blame] | 166 | * power_domain_off - Disable power to a power domain. |
Stephen Warren | 61f5ddc | 2016-07-13 13:45:31 -0600 | [diff] [blame] | 167 | * |
| 168 | * @power_domain: A power domain struct that was previously successfully |
| 169 | * requested by power_domain_get(). |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 170 | * Return: 0 if OK, or a negative error code. |
Stephen Warren | 61f5ddc | 2016-07-13 13:45:31 -0600 | [diff] [blame] | 171 | */ |
Peng Fan | 58d3de1 | 2018-07-27 10:20:36 +0800 | [diff] [blame] | 172 | #if CONFIG_IS_ENABLED(POWER_DOMAIN) |
Stephen Warren | 61f5ddc | 2016-07-13 13:45:31 -0600 | [diff] [blame] | 173 | int power_domain_off(struct power_domain *power_domain); |
Peng Fan | 58d3de1 | 2018-07-27 10:20:36 +0800 | [diff] [blame] | 174 | #else |
| 175 | static inline int power_domain_off(struct power_domain *power_domain) |
| 176 | { |
| 177 | return -ENOSYS; |
| 178 | } |
| 179 | #endif |
Stephen Warren | 61f5ddc | 2016-07-13 13:45:31 -0600 | [diff] [blame] | 180 | |
Peng Fan | 9c1e982 | 2019-09-17 09:29:19 +0000 | [diff] [blame] | 181 | /** |
| 182 | * dev_power_domain_on - Enable power domains for a device . |
| 183 | * |
| 184 | * @dev: The client device. |
| 185 | * |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 186 | * Return: 0 if OK, or a negative error code. |
Peng Fan | 9c1e982 | 2019-09-17 09:29:19 +0000 | [diff] [blame] | 187 | */ |
Simon Glass | 414cc15 | 2021-08-07 07:24:03 -0600 | [diff] [blame] | 188 | #if CONFIG_IS_ENABLED(OF_REAL) && CONFIG_IS_ENABLED(POWER_DOMAIN) |
Peng Fan | 9c1e982 | 2019-09-17 09:29:19 +0000 | [diff] [blame] | 189 | int dev_power_domain_on(struct udevice *dev); |
| 190 | #else |
| 191 | static inline int dev_power_domain_on(struct udevice *dev) |
| 192 | { |
| 193 | return 0; |
| 194 | } |
| 195 | #endif |
| 196 | |
Lokesh Vutla | 0cf795a | 2019-09-27 13:48:14 +0530 | [diff] [blame] | 197 | /** |
| 198 | * dev_power_domain_off - Disable power domains for a device . |
| 199 | * |
| 200 | * @dev: The client device. |
| 201 | * |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 202 | * Return: 0 if OK, or a negative error code. |
Lokesh Vutla | 0cf795a | 2019-09-27 13:48:14 +0530 | [diff] [blame] | 203 | */ |
Simon Glass | 414cc15 | 2021-08-07 07:24:03 -0600 | [diff] [blame] | 204 | #if CONFIG_IS_ENABLED(OF_REAL) && CONFIG_IS_ENABLED(POWER_DOMAIN) |
Lokesh Vutla | 0cf795a | 2019-09-27 13:48:14 +0530 | [diff] [blame] | 205 | int dev_power_domain_off(struct udevice *dev); |
| 206 | #else |
| 207 | static inline int dev_power_domain_off(struct udevice *dev) |
| 208 | { |
| 209 | return 0; |
| 210 | } |
| 211 | #endif |
| 212 | |
Stephen Warren | 61f5ddc | 2016-07-13 13:45:31 -0600 | [diff] [blame] | 213 | #endif |