usb: otg: mv_otg: Add dependence
[zen-stable.git] / drivers / base / power / domain_governor.c
blob66a265bf5867d1b516a03f34e8e50946db4c1e3e
1 /*
2 * drivers/base/power/domain_governor.c - Governors for device PM domains.
4 * Copyright (C) 2011 Rafael J. Wysocki <rjw@sisk.pl>, Renesas Electronics Corp.
6 * This file is released under the GPLv2.
7 */
9 #include <linux/init.h>
10 #include <linux/kernel.h>
11 #include <linux/pm_domain.h>
12 #include <linux/pm_qos.h>
13 #include <linux/hrtimer.h>
15 #ifdef CONFIG_PM_RUNTIME
17 /**
18 * default_stop_ok - Default PM domain governor routine for stopping devices.
19 * @dev: Device to check.
21 bool default_stop_ok(struct device *dev)
23 struct gpd_timing_data *td = &dev_gpd_data(dev)->td;
25 dev_dbg(dev, "%s()\n", __func__);
27 if (dev->power.max_time_suspended_ns < 0 || td->break_even_ns == 0)
28 return true;
30 return td->stop_latency_ns + td->start_latency_ns < td->break_even_ns
31 && td->break_even_ns < dev->power.max_time_suspended_ns;
34 /**
35 * default_power_down_ok - Default generic PM domain power off governor routine.
36 * @pd: PM domain to check.
38 * This routine must be executed under the PM domain's lock.
40 static bool default_power_down_ok(struct dev_pm_domain *pd)
42 struct generic_pm_domain *genpd = pd_to_genpd(pd);
43 struct gpd_link *link;
44 struct pm_domain_data *pdd;
45 s64 min_dev_off_time_ns;
46 s64 off_on_time_ns;
47 ktime_t time_now = ktime_get();
49 off_on_time_ns = genpd->power_off_latency_ns +
50 genpd->power_on_latency_ns;
52 * It doesn't make sense to remove power from the domain if saving
53 * the state of all devices in it and the power off/power on operations
54 * take too much time.
56 * All devices in this domain have been stopped already at this point.
58 list_for_each_entry(pdd, &genpd->dev_list, list_node) {
59 if (pdd->dev->driver)
60 off_on_time_ns +=
61 to_gpd_data(pdd)->td.save_state_latency_ns;
65 * Check if subdomains can be off for enough time.
67 * All subdomains have been powered off already at this point.
69 list_for_each_entry(link, &genpd->master_links, master_node) {
70 struct generic_pm_domain *sd = link->slave;
71 s64 sd_max_off_ns = sd->max_off_time_ns;
73 if (sd_max_off_ns < 0)
74 continue;
76 sd_max_off_ns -= ktime_to_ns(ktime_sub(time_now,
77 sd->power_off_time));
79 * Check if the subdomain is allowed to be off long enough for
80 * the current domain to turn off and on (that's how much time
81 * it will have to wait worst case).
83 if (sd_max_off_ns <= off_on_time_ns)
84 return false;
88 * Check if the devices in the domain can be off enough time.
90 min_dev_off_time_ns = -1;
91 list_for_each_entry(pdd, &genpd->dev_list, list_node) {
92 struct gpd_timing_data *td;
93 struct device *dev = pdd->dev;
94 s64 dev_off_time_ns;
96 if (!dev->driver || dev->power.max_time_suspended_ns < 0)
97 continue;
99 td = &to_gpd_data(pdd)->td;
100 dev_off_time_ns = dev->power.max_time_suspended_ns -
101 (td->start_latency_ns + td->restore_state_latency_ns +
102 ktime_to_ns(ktime_sub(time_now,
103 dev->power.suspend_time)));
104 if (dev_off_time_ns <= off_on_time_ns)
105 return false;
107 if (min_dev_off_time_ns > dev_off_time_ns
108 || min_dev_off_time_ns < 0)
109 min_dev_off_time_ns = dev_off_time_ns;
112 if (min_dev_off_time_ns < 0) {
114 * There are no latency constraints, so the domain can spend
115 * arbitrary time in the "off" state.
117 genpd->max_off_time_ns = -1;
118 return true;
122 * The difference between the computed minimum delta and the time needed
123 * to turn the domain on is the maximum theoretical time this domain can
124 * spend in the "off" state.
126 min_dev_off_time_ns -= genpd->power_on_latency_ns;
129 * If the difference between the computed minimum delta and the time
130 * needed to turn the domain off and back on on is smaller than the
131 * domain's power break even time, removing power from the domain is not
132 * worth it.
134 if (genpd->break_even_ns >
135 min_dev_off_time_ns - genpd->power_off_latency_ns)
136 return false;
138 genpd->max_off_time_ns = min_dev_off_time_ns;
139 return true;
142 static bool always_on_power_down_ok(struct dev_pm_domain *domain)
144 return false;
147 #else /* !CONFIG_PM_RUNTIME */
149 bool default_stop_ok(struct device *dev)
151 return false;
154 #define default_power_down_ok NULL
155 #define always_on_power_down_ok NULL
157 #endif /* !CONFIG_PM_RUNTIME */
159 struct dev_power_governor simple_qos_governor = {
160 .stop_ok = default_stop_ok,
161 .power_down_ok = default_power_down_ok,
165 * pm_genpd_gov_always_on - A governor implementing an always-on policy
167 struct dev_power_governor pm_domain_always_on_gov = {
168 .power_down_ok = always_on_power_down_ok,
169 .stop_ok = default_stop_ok,