]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blame - include/linux/pm_domain.h
OPP: Don't return 0 on error from of_get_required_opp_performance_state()
[mirror_ubuntu-focal-kernel.git] / include / linux / pm_domain.h
CommitLineData
f721889f
RW
1/*
2 * pm_domain.h - Definitions and headers related to device power domains.
3 *
4 * Copyright (C) 2011 Rafael J. Wysocki <rjw@sisk.pl>, Renesas Electronics Corp.
5 *
6 * This file is released under the GPLv2.
7 */
8
9#ifndef _LINUX_PM_DOMAIN_H
10#define _LINUX_PM_DOMAIN_H
11
12#include <linux/device.h>
313162d0
PG
13#include <linux/mutex.h>
14#include <linux/pm.h>
4f042cda 15#include <linux/err.h>
c8aa130b 16#include <linux/of.h>
6ff7bb0d 17#include <linux/notifier.h>
d716f479 18#include <linux/spinlock.h>
f721889f 19
e5089c2c
UH
20/*
21 * Flags to control the behaviour of a genpd.
22 *
23 * These flags may be set in the struct generic_pm_domain's flags field by a
24 * genpd backend driver. The flags must be set before it calls pm_genpd_init(),
25 * which initializes a genpd.
26 *
27 * GENPD_FLAG_PM_CLK: Instructs genpd to use the PM clk framework,
28 * while powering on/off attached devices.
29 *
30 * GENPD_FLAG_IRQ_SAFE: This informs genpd that its backend callbacks,
31 * ->power_on|off(), doesn't sleep. Hence, these
32 * can be invoked from within atomic context, which
33 * enables genpd to power on/off the PM domain,
34 * even when pm_runtime_is_irq_safe() returns true,
35 * for any of its attached devices. Note that, a
36 * genpd having this flag set, requires its
37 * masterdomains to also have it set.
38 *
39 * GENPD_FLAG_ALWAYS_ON: Instructs genpd to always keep the PM domain
40 * powered on.
41 *
42 * GENPD_FLAG_ACTIVE_WAKEUP: Instructs genpd to keep the PM domain powered
43 * on, in case any of its attached devices is used
44 * in the wakeup path to serve system wakeups.
45 */
46#define GENPD_FLAG_PM_CLK (1U << 0)
47#define GENPD_FLAG_IRQ_SAFE (1U << 1)
48#define GENPD_FLAG_ALWAYS_ON (1U << 2)
49#define GENPD_FLAG_ACTIVE_WAKEUP (1U << 3)
c11f6f5b 50
17b75eca
RW
51enum gpd_status {
52 GPD_STATE_ACTIVE = 0, /* PM domain is active */
17b75eca
RW
53 GPD_STATE_POWER_OFF, /* PM domain is off */
54};
596ba34b 55
f721889f
RW
56struct dev_power_governor {
57 bool (*power_down_ok)(struct dev_pm_domain *domain);
9df3921e 58 bool (*suspend_ok)(struct device *dev);
f721889f
RW
59};
60
d5e4cbfe
RW
61struct gpd_dev_ops {
62 int (*start)(struct device *dev);
63 int (*stop)(struct device *dev);
d5e4cbfe
RW
64};
65
fc5cbf0c
AH
66struct genpd_power_state {
67 s64 power_off_latency_ns;
68 s64 power_on_latency_ns;
405f7226 69 s64 residency_ns;
0c9b694a 70 struct fwnode_handle *fwnode;
afece3ab 71 ktime_t idle_time;
fc5cbf0c
AH
72};
73
35241d12 74struct genpd_lock_ops;
6e41766a 75struct dev_pm_opp;
35241d12 76
f721889f 77struct generic_pm_domain {
401ea157 78 struct device dev;
f721889f 79 struct dev_pm_domain domain; /* PM domain operations */
5125bbf3 80 struct list_head gpd_list_node; /* Node in the global PM domains list */
5063ce15
RW
81 struct list_head master_links; /* Links with PM domain as a master */
82 struct list_head slave_links; /* Links with PM domain as a slave */
f721889f 83 struct list_head dev_list; /* List of devices */
f721889f
RW
84 struct dev_power_governor *gov;
85 struct work_struct power_off_work;
de0aa06d
JH
86 struct fwnode_handle *provider; /* Identity of the domain provider */
87 bool has_provider;
d07e9c17 88 const char *name;
c4bb3160 89 atomic_t sd_count; /* Number of subdomains with power "on" */
17b75eca 90 enum gpd_status status; /* Current state of the domain */
596ba34b
RW
91 unsigned int device_count; /* Number of devices */
92 unsigned int suspended_count; /* System suspend device counter */
93 unsigned int prepared_count; /* Suspend counter of prepared devices */
42f6284a 94 unsigned int performance_state; /* Aggregated max performance state */
f721889f
RW
95 int (*power_off)(struct generic_pm_domain *domain);
96 int (*power_on)(struct generic_pm_domain *domain);
6e41766a
VK
97 unsigned int (*opp_to_performance_state)(struct generic_pm_domain *genpd,
98 struct dev_pm_opp *opp);
42f6284a
VK
99 int (*set_performance_state)(struct generic_pm_domain *genpd,
100 unsigned int state);
d5e4cbfe 101 struct gpd_dev_ops dev_ops;
221e9b58 102 s64 max_off_time_ns; /* Maximum allowed "suspended" time. */
6ff7bb0d
RW
103 bool max_off_time_changed;
104 bool cached_power_down_ok;
c16561e8
UH
105 int (*attach_dev)(struct generic_pm_domain *domain,
106 struct device *dev);
107 void (*detach_dev)(struct generic_pm_domain *domain,
108 struct device *dev);
c11f6f5b 109 unsigned int flags; /* Bit field of configs for genpd */
59d65b73 110 struct genpd_power_state *states;
fc5cbf0c
AH
111 unsigned int state_count; /* number of states */
112 unsigned int state_idx; /* state that genpd will go to when off */
59d65b73 113 void *free; /* Free the state that was allocated for default */
afece3ab
TG
114 ktime_t on_time;
115 ktime_t accounting_time;
35241d12 116 const struct genpd_lock_ops *lock_ops;
d716f479
LI
117 union {
118 struct mutex mlock;
119 struct {
120 spinlock_t slock;
121 unsigned long lock_flags;
122 };
123 };
fc5cbf0c 124
f721889f
RW
125};
126
596ba34b
RW
127static inline struct generic_pm_domain *pd_to_genpd(struct dev_pm_domain *pd)
128{
129 return container_of(pd, struct generic_pm_domain, domain);
130}
131
5063ce15
RW
132struct gpd_link {
133 struct generic_pm_domain *master;
134 struct list_head master_node;
135 struct generic_pm_domain *slave;
136 struct list_head slave_node;
137};
138
b02c999a 139struct gpd_timing_data {
2b1d88cd
UH
140 s64 suspend_latency_ns;
141 s64 resume_latency_ns;
a5bef810 142 s64 effective_constraint_ns;
6ff7bb0d 143 bool constraint_changed;
9df3921e 144 bool cached_suspend_ok;
b02c999a
RW
145};
146
00e7c295
UH
147struct pm_domain_data {
148 struct list_head list_node;
149 struct device *dev;
150};
151
cd0ea672
RW
152struct generic_pm_domain_data {
153 struct pm_domain_data base;
b02c999a 154 struct gpd_timing_data td;
6ff7bb0d 155 struct notifier_block nb;
42f6284a 156 unsigned int performance_state;
a5ea7a0f 157 void *data;
cd0ea672
RW
158};
159
9b4f617b 160#ifdef CONFIG_PM_GENERIC_DOMAINS
cd0ea672
RW
161static inline struct generic_pm_domain_data *to_gpd_data(struct pm_domain_data *pdd)
162{
163 return container_of(pdd, struct generic_pm_domain_data, base);
164}
165
d5e4cbfe
RW
166static inline struct generic_pm_domain_data *dev_gpd_data(struct device *dev)
167{
168 return to_gpd_data(dev->power.subsys_data->domain_data);
169}
170
1a7a6707 171int pm_genpd_add_device(struct generic_pm_domain *genpd, struct device *dev);
924f4486 172int pm_genpd_remove_device(struct device *dev);
781b9d6b
UH
173int pm_genpd_add_subdomain(struct generic_pm_domain *genpd,
174 struct generic_pm_domain *new_subdomain);
175int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
176 struct generic_pm_domain *target);
177int pm_genpd_init(struct generic_pm_domain *genpd,
178 struct dev_power_governor *gov, bool is_off);
179int pm_genpd_remove(struct generic_pm_domain *genpd);
180int dev_pm_genpd_set_performance_state(struct device *dev, unsigned int state);
b02c999a 181
ae3c511c 182extern struct dev_power_governor simple_qos_governor;
925b44a2 183extern struct dev_power_governor pm_domain_always_on_gov;
f721889f 184#else
b02c999a 185
b642631d
MD
186static inline struct generic_pm_domain_data *dev_gpd_data(struct device *dev)
187{
188 return ERR_PTR(-ENOSYS);
189}
1a7a6707
UH
190static inline int pm_genpd_add_device(struct generic_pm_domain *genpd,
191 struct device *dev)
b02c999a
RW
192{
193 return -ENOSYS;
194}
924f4486 195static inline int pm_genpd_remove_device(struct device *dev)
f721889f
RW
196{
197 return -ENOSYS;
198}
199static inline int pm_genpd_add_subdomain(struct generic_pm_domain *genpd,
200 struct generic_pm_domain *new_sd)
201{
202 return -ENOSYS;
203}
204static inline int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
205 struct generic_pm_domain *target)
206{
207 return -ENOSYS;
208}
7eb231c3
UH
209static inline int pm_genpd_init(struct generic_pm_domain *genpd,
210 struct dev_power_governor *gov, bool is_off)
b02c999a 211{
7eb231c3 212 return -ENOSYS;
b02c999a 213}
3fe57710
JH
214static inline int pm_genpd_remove(struct generic_pm_domain *genpd)
215{
216 return -ENOTSUPP;
217}
16d0bf18 218
42f6284a
VK
219static inline int dev_pm_genpd_set_performance_state(struct device *dev,
220 unsigned int state)
221{
222 return -ENOTSUPP;
223}
224
16d0bf18
GU
225#define simple_qos_governor (*(struct dev_power_governor *)(NULL))
226#define pm_domain_always_on_gov (*(struct dev_power_governor *)(NULL))
17f2ae7f
RW
227#endif
228
77f827de 229#ifdef CONFIG_PM_GENERIC_DOMAINS_SLEEP
781b9d6b
UH
230void pm_genpd_syscore_poweroff(struct device *dev);
231void pm_genpd_syscore_poweron(struct device *dev);
77f827de 232#else
d47e6464
UH
233static inline void pm_genpd_syscore_poweroff(struct device *dev) {}
234static inline void pm_genpd_syscore_poweron(struct device *dev) {}
77f827de
RW
235#endif
236
aa42240a
TF
237/* OF PM domain providers */
238struct of_device_id;
239
40845524
TR
240typedef struct generic_pm_domain *(*genpd_xlate_t)(struct of_phandle_args *args,
241 void *data);
242
aa42240a
TF
243struct genpd_onecell_data {
244 struct generic_pm_domain **domains;
245 unsigned int num_domains;
40845524 246 genpd_xlate_t xlate;
aa42240a
TF
247};
248
aa42240a 249#ifdef CONFIG_PM_GENERIC_DOMAINS_OF
892ebdcc
JH
250int of_genpd_add_provider_simple(struct device_node *np,
251 struct generic_pm_domain *genpd);
252int of_genpd_add_provider_onecell(struct device_node *np,
253 struct genpd_onecell_data *data);
aa42240a 254void of_genpd_del_provider(struct device_node *np);
781b9d6b
UH
255int of_genpd_add_device(struct of_phandle_args *args, struct device *dev);
256int of_genpd_add_subdomain(struct of_phandle_args *parent,
257 struct of_phandle_args *new_subdomain);
258struct generic_pm_domain *of_genpd_remove_last(struct device_node *np);
259int of_genpd_parse_idle_states(struct device_node *dn,
260 struct genpd_power_state **states, int *n);
e38f89d3
VK
261unsigned int pm_genpd_opp_to_performance_state(struct device *genpd_dev,
262 struct dev_pm_opp *opp);
aa42240a
TF
263
264int genpd_dev_pm_attach(struct device *dev);
3c095f32
UH
265struct device *genpd_dev_pm_attach_by_id(struct device *dev,
266 unsigned int index);
5d6be70a
UH
267struct device *genpd_dev_pm_attach_by_name(struct device *dev,
268 char *name);
aa42240a 269#else /* !CONFIG_PM_GENERIC_DOMAINS_OF */
892ebdcc
JH
270static inline int of_genpd_add_provider_simple(struct device_node *np,
271 struct generic_pm_domain *genpd)
aa42240a 272{
892ebdcc
JH
273 return -ENOTSUPP;
274}
275
276static inline int of_genpd_add_provider_onecell(struct device_node *np,
277 struct genpd_onecell_data *data)
278{
279 return -ENOTSUPP;
aa42240a 280}
aa42240a 281
892ebdcc 282static inline void of_genpd_del_provider(struct device_node *np) {}
aa42240a 283
ec69572b
JH
284static inline int of_genpd_add_device(struct of_phandle_args *args,
285 struct device *dev)
286{
287 return -ENODEV;
288}
289
290static inline int of_genpd_add_subdomain(struct of_phandle_args *parent,
291 struct of_phandle_args *new_subdomain)
292{
293 return -ENODEV;
294}
295
30f60428
LI
296static inline int of_genpd_parse_idle_states(struct device_node *dn,
297 struct genpd_power_state **states, int *n)
298{
299 return -ENODEV;
300}
301
e38f89d3
VK
302static inline unsigned int
303pm_genpd_opp_to_performance_state(struct device *genpd_dev,
304 struct dev_pm_opp *opp)
305{
306 return 0;
307}
308
aa42240a
TF
309static inline int genpd_dev_pm_attach(struct device *dev)
310{
919b7308 311 return 0;
aa42240a 312}
17926551 313
3c095f32
UH
314static inline struct device *genpd_dev_pm_attach_by_id(struct device *dev,
315 unsigned int index)
316{
317 return NULL;
318}
319
5d6be70a
UH
320static inline struct device *genpd_dev_pm_attach_by_name(struct device *dev,
321 char *name)
322{
323 return NULL;
324}
325
17926551
JH
326static inline
327struct generic_pm_domain *of_genpd_remove_last(struct device_node *np)
328{
329 return ERR_PTR(-ENOTSUPP);
330}
aa42240a
TF
331#endif /* CONFIG_PM_GENERIC_DOMAINS_OF */
332
f48c767c 333#ifdef CONFIG_PM
781b9d6b 334int dev_pm_domain_attach(struct device *dev, bool power_on);
82e12d9e
UH
335struct device *dev_pm_domain_attach_by_id(struct device *dev,
336 unsigned int index);
27dceb81
UH
337struct device *dev_pm_domain_attach_by_name(struct device *dev,
338 char *name);
781b9d6b
UH
339void dev_pm_domain_detach(struct device *dev, bool power_off);
340void dev_pm_domain_set(struct device *dev, struct dev_pm_domain *pd);
f48c767c
UH
341#else
342static inline int dev_pm_domain_attach(struct device *dev, bool power_on)
343{
919b7308 344 return 0;
f48c767c 345}
82e12d9e
UH
346static inline struct device *dev_pm_domain_attach_by_id(struct device *dev,
347 unsigned int index)
348{
349 return NULL;
350}
27dceb81
UH
351static inline struct device *dev_pm_domain_attach_by_name(struct device *dev,
352 char *name)
353{
354 return NULL;
355}
f48c767c 356static inline void dev_pm_domain_detach(struct device *dev, bool power_off) {}
989561de
TV
357static inline void dev_pm_domain_set(struct device *dev,
358 struct dev_pm_domain *pd) {}
f48c767c
UH
359#endif
360
f721889f 361#endif /* _LINUX_PM_DOMAIN_H */