1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (c) 2016, NVIDIA CORPORATION.
6 #ifndef _POWER_DOMAIN_H
7 #define _POWER_DOMAIN_H
9 #include <linux/errno.h>
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.
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
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.
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.
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.
50 * struct power_domain - A handle to (allowing control of) a single power domain.
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.
58 * @dev: The device which implements the power domain.
59 * @id: The power domain ID within the provider.
60 * @priv: Private data corresponding to each power domain.
69 * power_domain_get - Get/request the power domain for a device.
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.
77 * @dev: The client device.
78 * @power_domain A pointer to a power domain struct to initialize.
79 * Return: 0 if OK, or a negative error code.
81 #if CONFIG_IS_ENABLED(POWER_DOMAIN)
82 int power_domain_get(struct udevice *dev, struct power_domain *power_domain);
85 int power_domain_get(struct udevice *dev, struct power_domain *power_domain)
92 * power_domain_get_by_index - Get the indexed power domain for a device.
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.
98 * Return: 0 if OK, or a negative error code.
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);
105 int power_domain_get_by_index(struct udevice *dev,
106 struct power_domain *power_domain, int index)
113 * power_domain_get_by_name - Get the named power domain for a device.
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.
119 * Return: 0 if OK, or a negative error code.
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);
126 int power_domain_get_by_name(struct udevice *dev,
127 struct power_domain *power_domain, const char *name)
134 * power_domain_free - Free a previously requested power domain.
136 * @power_domain: A power domain struct that was previously successfully
137 * requested by power_domain_get().
138 * Return: 0 if OK, or a negative error code.
140 #if CONFIG_IS_ENABLED(POWER_DOMAIN)
141 int power_domain_free(struct power_domain *power_domain);
143 static inline int power_domain_free(struct power_domain *power_domain)
150 * power_domain_on - Enable power to a power domain.
152 * @power_domain: A power domain struct that was previously successfully
153 * requested by power_domain_get().
154 * Return: 0 if OK, or a negative error code.
156 #if CONFIG_IS_ENABLED(POWER_DOMAIN)
157 int power_domain_on(struct power_domain *power_domain);
159 static inline int power_domain_on(struct power_domain *power_domain)
166 * power_domain_off - Disable power to a power domain.
168 * @power_domain: A power domain struct that was previously successfully
169 * requested by power_domain_get().
170 * Return: 0 if OK, or a negative error code.
172 #if CONFIG_IS_ENABLED(POWER_DOMAIN)
173 int power_domain_off(struct power_domain *power_domain);
175 static inline int power_domain_off(struct power_domain *power_domain)
182 * dev_power_domain_on - Enable power domains for a device .
184 * @dev: The client device.
186 * Return: 0 if OK, or a negative error code.
188 #if CONFIG_IS_ENABLED(OF_REAL) && CONFIG_IS_ENABLED(POWER_DOMAIN)
189 int dev_power_domain_on(struct udevice *dev);
191 static inline int dev_power_domain_on(struct udevice *dev)
198 * dev_power_domain_off - Disable power domains for a device .
200 * @dev: The client device.
202 * Return: 0 if OK, or a negative error code.
204 #if CONFIG_IS_ENABLED(OF_REAL) && CONFIG_IS_ENABLED(POWER_DOMAIN)
205 int dev_power_domain_off(struct udevice *dev);
207 static inline int dev_power_domain_off(struct udevice *dev)