Blame view

include/power-domain.h 6.76 KB
83d290c56   Tom Rini   SPDX: Convert all...
1
  /* SPDX-License-Identifier: GPL-2.0 */
61f5ddcb7   Stephen Warren   Add a power domai...
2
3
  /*
   * Copyright (c) 2016, NVIDIA CORPORATION.
e99add1a0   Ye Li   MLK-16118-2 power...
4
5
   * Copyright 2017 NXP
   *
61f5ddcb7   Stephen Warren   Add a power domai...
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
   */
  
  #ifndef _POWER_DOMAIN_H
  #define _POWER_DOMAIN_H
  
  /**
   * A power domain is a portion of an SoC or chip that is powered by a
   * switchable source of power. In many cases, software has control over the
   * power domain, and can turn the power source on or off. This is typically
   * done to save power by powering off unused devices, or to enable software
   * sequencing of initial powerup at boot. This API provides a means for
   * drivers to turn power domains on and off.
   *
   * A driver that implements UCLASS_POWER_DOMAIN is a power domain controller or
   * provider. A controller will often implement multiple separate power domains,
   * since the hardware it manages often has this capability.
   * power-domain-uclass.h describes the interface which power domain controllers
   * must implement.
   *
   * Depending on the power domain controller hardware, changing the state of a
   * power domain may require performing related operations on other resources.
   * For example, some power domains may require certain clocks to be enabled
   * whenever the power domain is powered on, or during the time when the power
   * domain is transitioning state. These details are implementation-specific
   * and should ideally be encapsulated entirely within the provider driver, or
   * configured through mechanisms (e.g. device tree) that do not require client
   * drivers to provide extra configuration information.
   *
   * Power domain consumers/clients are the drivers for HW modules within the
   * power domain. This header file describes the API used by those drivers.
   *
   * In many cases, a single complex IO controller (e.g. a PCIe controller) will
   * be the sole logic contained within a power domain. In such cases, it is
   * logical for the relevant device driver to directly control that power
   * domain. In other cases, multiple controllers, each with their own driver,
   * may be contained in a single power domain. Any logic require to co-ordinate
   * between drivers for these multiple controllers is beyond the scope of this
   * API at present. Equally, this API does not define or implement any policy
   * by which power domains are managed.
   */
  
  struct udevice;
  
  /**
   * struct power_domain - A handle to (allowing control of) a single power domain.
   *
   * Clients provide storage for power domain handles. The content of the
   * structure is managed solely by the power domain API and power domain
   * drivers. A power domain struct is initialized by "get"ing the power domain
   * struct. The power domain struct is passed to all other power domain APIs to
   * identify which power domain to operate upon.
   *
   * @dev: The device which implements the power domain.
   * @id: The power domain ID within the provider.
fd4e7be5f   Lokesh Vutla   power-domain: Add...
60
   * @priv: Private data corresponding to each power domain.
61f5ddcb7   Stephen Warren   Add a power domai...
61
62
63
   */
  struct power_domain {
  	struct udevice *dev;
61f5ddcb7   Stephen Warren   Add a power domai...
64
  	unsigned long id;
fd4e7be5f   Lokesh Vutla   power-domain: Add...
65
  	void *priv;
61f5ddcb7   Stephen Warren   Add a power domai...
66
67
68
  };
  
  /**
e99add1a0   Ye Li   MLK-16118-2 power...
69
70
71
72
73
74
75
76
77
78
79
80
81
   * power_domain_lookup_name - Lookup the power domain device by name and request it.
   *
   * This looks up and requests a provider power domain by using its device name. This
   * skip the associated client device, but directly get the power domain device.
   *
   * @name:        The power domain device's name.
   * @power_domain        A pointer to a power domain struct to initialize.
   * @return 0 if OK, or a negative error code.
   */
  
  int power_domain_lookup_name(const char *name, struct power_domain *power_domain);
  
  /**
61f5ddcb7   Stephen Warren   Add a power domai...
82
83
84
85
86
87
88
89
90
91
92
93
   * power_domain_get - Get/request the power domain for a device.
   *
   * This looks up and requests a power domain. Each device is assumed to have
   * a single (or, at least one) power domain associated with it somehow, and
   * that domain, or the first/default domain. The mapping of client device to
   * provider power domain may be via device-tree properties, board-provided
   * mapping tables, or some other mechanism.
   *
   * @dev:	The client device.
   * @power_domain	A pointer to a power domain struct to initialize.
   * @return 0 if OK, or a negative error code.
   */
58d3de19b   Peng Fan   power-domain: add...
94
  #if CONFIG_IS_ENABLED(POWER_DOMAIN)
61f5ddcb7   Stephen Warren   Add a power domai...
95
  int power_domain_get(struct udevice *dev, struct power_domain *power_domain);
58d3de19b   Peng Fan   power-domain: add...
96
97
98
99
100
101
102
  #else
  static inline
  int power_domain_get(struct udevice *dev, struct power_domain *power_domain)
  {
  	return -ENOSYS;
  }
  #endif
61f5ddcb7   Stephen Warren   Add a power domai...
103
104
  
  /**
2618cf365   Lokesh Vutla   power domain: Add...
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
   * power_domain_get_by_index - Get the indexed power domain for a device.
   *
   * @dev:		The client device.
   * @power_domain:	A pointer to a power domain struct to initialize.
   * @index:		Power domain index to be powered on.
   *
   * @return 0 if OK, or a negative error code.
   */
  #if CONFIG_IS_ENABLED(POWER_DOMAIN)
  int power_domain_get_by_index(struct udevice *dev,
  			      struct power_domain *power_domain, int index);
  #else
  static inline
  int power_domain_get_by_index(struct udevice *dev,
  			      struct power_domain *power_domain, int index)
  {
  	return -ENOSYS;
  }
  #endif
  
  /**
61f5ddcb7   Stephen Warren   Add a power domai...
126
127
128
129
130
131
   * power_domain_free - Free a previously requested power domain.
   *
   * @power_domain:	A power domain struct that was previously successfully
   *		requested by power_domain_get().
   * @return 0 if OK, or a negative error code.
   */
58d3de19b   Peng Fan   power-domain: add...
132
  #if CONFIG_IS_ENABLED(POWER_DOMAIN)
61f5ddcb7   Stephen Warren   Add a power domai...
133
  int power_domain_free(struct power_domain *power_domain);
58d3de19b   Peng Fan   power-domain: add...
134
135
136
137
138
139
  #else
  static inline int power_domain_free(struct power_domain *power_domain)
  {
  	return -ENOSYS;
  }
  #endif
61f5ddcb7   Stephen Warren   Add a power domai...
140
141
142
143
144
145
146
147
  
  /**
   * power_domain_on - Enable power to a power domain.
   *
   * @power_domain:	A power domain struct that was previously successfully
   *		requested by power_domain_get().
   * @return 0 if OK, or a negative error code.
   */
58d3de19b   Peng Fan   power-domain: add...
148
  #if CONFIG_IS_ENABLED(POWER_DOMAIN)
61f5ddcb7   Stephen Warren   Add a power domai...
149
  int power_domain_on(struct power_domain *power_domain);
58d3de19b   Peng Fan   power-domain: add...
150
151
152
153
154
155
  #else
  static inline int power_domain_on(struct power_domain *power_domain)
  {
  	return -ENOSYS;
  }
  #endif
61f5ddcb7   Stephen Warren   Add a power domai...
156
157
  
  /**
f752e5783   Anatolij Gustschin   power-domain.h: F...
158
   * power_domain_off - Disable power to a power domain.
61f5ddcb7   Stephen Warren   Add a power domai...
159
160
161
162
163
   *
   * @power_domain:	A power domain struct that was previously successfully
   *		requested by power_domain_get().
   * @return 0 if OK, or a negative error code.
   */
58d3de19b   Peng Fan   power-domain: add...
164
  #if CONFIG_IS_ENABLED(POWER_DOMAIN)
61f5ddcb7   Stephen Warren   Add a power domai...
165
  int power_domain_off(struct power_domain *power_domain);
58d3de19b   Peng Fan   power-domain: add...
166
167
168
169
170
171
  #else
  static inline int power_domain_off(struct power_domain *power_domain)
  {
  	return -ENOSYS;
  }
  #endif
61f5ddcb7   Stephen Warren   Add a power domai...
172

9c1e98221   Peng Fan   power: domain: ad...
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
  /**
   * dev_power_domain_on - Enable power domains for a device .
   *
   * @dev:		The client device.
   *
   * @return 0 if OK, or a negative error code.
   */
  #if (CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)) && \
  	CONFIG_IS_ENABLED(POWER_DOMAIN)
  int dev_power_domain_on(struct udevice *dev);
  #else
  static inline int dev_power_domain_on(struct udevice *dev)
  {
  	return 0;
  }
  #endif
0cf795a80   Lokesh Vutla   power: domain: In...
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
  /**
   * dev_power_domain_off - Disable power domains for a device .
   *
   * @dev:		The client device.
   *
   * @return 0 if OK, or a negative error code.
   */
  #if (CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)) && \
  	CONFIG_IS_ENABLED(POWER_DOMAIN)
  int dev_power_domain_off(struct udevice *dev);
  #else
  static inline int dev_power_domain_off(struct udevice *dev)
  {
  	return 0;
  }
  #endif
61f5ddcb7   Stephen Warren   Add a power domai...
205
  #endif