Skip to content

Commit 0fcb4ee

Browse files
AlanSternrjwysocki
authored andcommitted
PM / Runtime: Make runtime_status attribute not debug-only (v. 2)
This patch (as1404b) makes the runtime_status sysfs attribute available even in the absence of CONFIG_PM_ADVANCED_DEBUG, and it changes the routine to display "unsupported" when runtime PM is disabled for a device. Although not strictly 100% accurate, this will almost always be correct. Signed-off-by: Alan Stern <stern@rowland.harvard.edu> Acked-by: Dominik Brodowski <linux@dominikbrodowski.net> Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
1 parent 4eb241e commit 0fcb4ee

1 file changed

Lines changed: 33 additions & 20 deletions

File tree

‎drivers/base/power/sysfs.c‎

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,38 @@ static ssize_t control_store(struct device * dev, struct device_attribute *attr,
110110
}
111111

112112
static DEVICE_ATTR(control, 0644, control_show, control_store);
113+
114+
static ssize_t rtpm_status_show(struct device *dev,
115+
struct device_attribute *attr, char *buf)
116+
{
117+
const char *p;
118+
119+
if (dev->power.runtime_error) {
120+
p = "error\n";
121+
} else if (dev->power.disable_depth) {
122+
p = "unsupported\n";
123+
} else {
124+
switch (dev->power.runtime_status) {
125+
case RPM_SUSPENDED:
126+
p = "suspended\n";
127+
break;
128+
case RPM_SUSPENDING:
129+
p = "suspending\n";
130+
break;
131+
case RPM_RESUMING:
132+
p = "resuming\n";
133+
break;
134+
case RPM_ACTIVE:
135+
p = "active\n";
136+
break;
137+
default:
138+
return -EIO;
139+
}
140+
}
141+
return sprintf(buf, p);
142+
}
143+
144+
static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
113145
#endif
114146

115147
static ssize_t
@@ -184,27 +216,8 @@ static ssize_t rtpm_enabled_show(struct device *dev,
184216
return sprintf(buf, "enabled\n");
185217
}
186218

187-
static ssize_t rtpm_status_show(struct device *dev,
188-
struct device_attribute *attr, char *buf)
189-
{
190-
if (dev->power.runtime_error)
191-
return sprintf(buf, "error\n");
192-
switch (dev->power.runtime_status) {
193-
case RPM_SUSPENDED:
194-
return sprintf(buf, "suspended\n");
195-
case RPM_SUSPENDING:
196-
return sprintf(buf, "suspending\n");
197-
case RPM_RESUMING:
198-
return sprintf(buf, "resuming\n");
199-
case RPM_ACTIVE:
200-
return sprintf(buf, "active\n");
201-
}
202-
return -EIO;
203-
}
204-
205219
static DEVICE_ATTR(runtime_usage, 0444, rtpm_usagecount_show, NULL);
206220
static DEVICE_ATTR(runtime_active_kids, 0444, rtpm_children_show, NULL);
207-
static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
208221
static DEVICE_ATTR(runtime_enabled, 0444, rtpm_enabled_show, NULL);
209222

210223
#endif
@@ -240,6 +253,7 @@ static DEVICE_ATTR(async, 0644, async_show, async_store);
240253
static struct attribute * power_attrs[] = {
241254
#ifdef CONFIG_PM_RUNTIME
242255
&dev_attr_control.attr,
256+
&dev_attr_runtime_status.attr,
243257
#endif
244258
&dev_attr_wakeup.attr,
245259
#ifdef CONFIG_PM_SLEEP
@@ -250,7 +264,6 @@ static struct attribute * power_attrs[] = {
250264
#ifdef CONFIG_PM_RUNTIME
251265
&dev_attr_runtime_usage.attr,
252266
&dev_attr_runtime_active_kids.attr,
253-
&dev_attr_runtime_status.attr,
254267
&dev_attr_runtime_enabled.attr,
255268
#endif
256269
#endif

0 commit comments

Comments
 (0)