aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base/power/sysfs.c
diff options
context:
space:
mode:
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>2012-10-23 20:08:18 -0400
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2012-10-23 20:08:18 -0400
commite39473d0b9448e770f49b0b15e514be884264438 (patch)
treea6fbf50c1fcd8e7cfd176425384a82fe06d3cadd /drivers/base/power/sysfs.c
parentae0fb4b72c8db7e6c4ef32bc58a43a759ad414b9 (diff)
PM / QoS: Make it possible to expose PM QoS device flags to user space
Define two device PM QoS flags, PM_QOS_FLAG_NO_POWER_OFF and PM_QOS_FLAG_REMOTE_WAKEUP, and introduce routines dev_pm_qos_expose_flags() and dev_pm_qos_hide_flags() allowing the caller to expose those two flags to user space or to hide them from it, respectively. After the flags have been exposed, user space will see two additional sysfs attributes, pm_qos_no_power_off and pm_qos_remote_wakeup, under the device's /sys/devices/.../power/ directory. Then, writing 1 to one of them will update the PM QoS flags request owned by user space so that the corresponding flag is requested to be set. In turn, writing 0 to one of them will cause the corresponding flag in the user space's request to be cleared (however, the owners of the other PM QoS flags requests for the same device may still request the flag to be set and it may be effectively set even if user space doesn't request that). Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Reviewed-by: Jean Pihet <j-pihet@ti.com> Acked-by: mark gross <markgross@thegnar.org>
Diffstat (limited to 'drivers/base/power/sysfs.c')
-rw-r--r--drivers/base/power/sysfs.c94
1 files changed, 85 insertions, 9 deletions
diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
index 54c61ffa2044..50d16e3cb0a9 100644
--- a/drivers/base/power/sysfs.c
+++ b/drivers/base/power/sysfs.c
@@ -221,7 +221,7 @@ static DEVICE_ATTR(autosuspend_delay_ms, 0644, autosuspend_delay_ms_show,
221static ssize_t pm_qos_latency_show(struct device *dev, 221static ssize_t pm_qos_latency_show(struct device *dev,
222 struct device_attribute *attr, char *buf) 222 struct device_attribute *attr, char *buf)
223{ 223{
224 return sprintf(buf, "%d\n", dev->power.pq_req->data.pnode.prio); 224 return sprintf(buf, "%d\n", dev_pm_qos_requested_latency(dev));
225} 225}
226 226
227static ssize_t pm_qos_latency_store(struct device *dev, 227static ssize_t pm_qos_latency_store(struct device *dev,
@@ -237,12 +237,66 @@ static ssize_t pm_qos_latency_store(struct device *dev,
237 if (value < 0) 237 if (value < 0)
238 return -EINVAL; 238 return -EINVAL;
239 239
240 ret = dev_pm_qos_update_request(dev->power.pq_req, value); 240 ret = dev_pm_qos_update_request(dev->power.qos->latency_req, value);
241 return ret < 0 ? ret : n; 241 return ret < 0 ? ret : n;
242} 242}
243 243
244static DEVICE_ATTR(pm_qos_resume_latency_us, 0644, 244static DEVICE_ATTR(pm_qos_resume_latency_us, 0644,
245 pm_qos_latency_show, pm_qos_latency_store); 245 pm_qos_latency_show, pm_qos_latency_store);
246
247static ssize_t pm_qos_no_power_off_show(struct device *dev,
248 struct device_attribute *attr,
249 char *buf)
250{
251 return sprintf(buf, "%d\n", !!(dev_pm_qos_requested_flags(dev)
252 & PM_QOS_FLAG_NO_POWER_OFF));
253}
254
255static ssize_t pm_qos_no_power_off_store(struct device *dev,
256 struct device_attribute *attr,
257 const char *buf, size_t n)
258{
259 int ret;
260
261 if (kstrtoint(buf, 0, &ret))
262 return -EINVAL;
263
264 if (ret != 0 && ret != 1)
265 return -EINVAL;
266
267 ret = dev_pm_qos_update_flags(dev, PM_QOS_FLAG_NO_POWER_OFF, ret);
268 return ret < 0 ? ret : n;
269}
270
271static DEVICE_ATTR(pm_qos_no_power_off, 0644,
272 pm_qos_no_power_off_show, pm_qos_no_power_off_store);
273
274static ssize_t pm_qos_remote_wakeup_show(struct device *dev,
275 struct device_attribute *attr,
276 char *buf)
277{
278 return sprintf(buf, "%d\n", !!(dev_pm_qos_requested_flags(dev)
279 & PM_QOS_FLAG_REMOTE_WAKEUP));
280}
281
282static ssize_t pm_qos_remote_wakeup_store(struct device *dev,
283 struct device_attribute *attr,
284 const char *buf, size_t n)
285{
286 int ret;
287
288 if (kstrtoint(buf, 0, &ret))
289 return -EINVAL;
290
291 if (ret != 0 && ret != 1)
292 return -EINVAL;
293
294 ret = dev_pm_qos_update_flags(dev, PM_QOS_FLAG_REMOTE_WAKEUP, ret);
295 return ret < 0 ? ret : n;
296}
297
298static DEVICE_ATTR(pm_qos_remote_wakeup, 0644,
299 pm_qos_remote_wakeup_show, pm_qos_remote_wakeup_store);
246#endif /* CONFIG_PM_RUNTIME */ 300#endif /* CONFIG_PM_RUNTIME */
247 301
248#ifdef CONFIG_PM_SLEEP 302#ifdef CONFIG_PM_SLEEP
@@ -564,15 +618,27 @@ static struct attribute_group pm_runtime_attr_group = {
564 .attrs = runtime_attrs, 618 .attrs = runtime_attrs,
565}; 619};
566 620
567static struct attribute *pm_qos_attrs[] = { 621static struct attribute *pm_qos_latency_attrs[] = {
568#ifdef CONFIG_PM_RUNTIME 622#ifdef CONFIG_PM_RUNTIME
569 &dev_attr_pm_qos_resume_latency_us.attr, 623 &dev_attr_pm_qos_resume_latency_us.attr,
570#endif /* CONFIG_PM_RUNTIME */ 624#endif /* CONFIG_PM_RUNTIME */
571 NULL, 625 NULL,
572}; 626};
573static struct attribute_group pm_qos_attr_group = { 627static struct attribute_group pm_qos_latency_attr_group = {
574 .name = power_group_name, 628 .name = power_group_name,
575 .attrs = pm_qos_attrs, 629 .attrs = pm_qos_latency_attrs,
630};
631
632static struct attribute *pm_qos_flags_attrs[] = {
633#ifdef CONFIG_PM_RUNTIME
634 &dev_attr_pm_qos_no_power_off.attr,
635 &dev_attr_pm_qos_remote_wakeup.attr,
636#endif /* CONFIG_PM_RUNTIME */
637 NULL,
638};
639static struct attribute_group pm_qos_flags_attr_group = {
640 .name = power_group_name,
641 .attrs = pm_qos_flags_attrs,
576}; 642};
577 643
578int dpm_sysfs_add(struct device *dev) 644int dpm_sysfs_add(struct device *dev)
@@ -615,14 +681,24 @@ void wakeup_sysfs_remove(struct device *dev)
615 sysfs_unmerge_group(&dev->kobj, &pm_wakeup_attr_group); 681 sysfs_unmerge_group(&dev->kobj, &pm_wakeup_attr_group);
616} 682}
617 683
618int pm_qos_sysfs_add(struct device *dev) 684int pm_qos_sysfs_add_latency(struct device *dev)
685{
686 return sysfs_merge_group(&dev->kobj, &pm_qos_latency_attr_group);
687}
688
689void pm_qos_sysfs_remove_latency(struct device *dev)
690{
691 sysfs_unmerge_group(&dev->kobj, &pm_qos_latency_attr_group);
692}
693
694int pm_qos_sysfs_add_flags(struct device *dev)
619{ 695{
620 return sysfs_merge_group(&dev->kobj, &pm_qos_attr_group); 696 return sysfs_merge_group(&dev->kobj, &pm_qos_flags_attr_group);
621} 697}
622 698
623void pm_qos_sysfs_remove(struct device *dev) 699void pm_qos_sysfs_remove_flags(struct device *dev)
624{ 700{
625 sysfs_unmerge_group(&dev->kobj, &pm_qos_attr_group); 701 sysfs_unmerge_group(&dev->kobj, &pm_qos_flags_attr_group);
626} 702}
627 703
628void rpm_sysfs_remove(struct device *dev) 704void rpm_sysfs_remove(struct device *dev)