55#include <linux/device.h>
66#include <linux/string.h>
77#include <linux/pm_runtime.h>
8+ #include <asm/atomic.h>
89#include "power.h"
910
1011/*
@@ -143,7 +144,59 @@ wake_store(struct device * dev, struct device_attribute *attr,
143144
144145static DEVICE_ATTR (wakeup , 0644 , wake_show , wake_store ) ;
145146
146- #ifdef CONFIG_PM_SLEEP_ADVANCED_DEBUG
147+ #ifdef CONFIG_PM_ADVANCED_DEBUG
148+ #ifdef CONFIG_PM_RUNTIME
149+
150+ static ssize_t rtpm_usagecount_show (struct device * dev ,
151+ struct device_attribute * attr , char * buf )
152+ {
153+ return sprintf (buf , "%d\n" , atomic_read (& dev -> power .usage_count ));
154+ }
155+
156+ static ssize_t rtpm_children_show (struct device * dev ,
157+ struct device_attribute * attr , char * buf )
158+ {
159+ return sprintf (buf , "%d\n" , dev -> power .ignore_children ?
160+ 0 : atomic_read (& dev -> power .child_count ));
161+ }
162+
163+ static ssize_t rtpm_enabled_show (struct device * dev ,
164+ struct device_attribute * attr , char * buf )
165+ {
166+ if ((dev -> power .disable_depth ) && (dev -> power .runtime_auto == false))
167+ return sprintf (buf , "disabled & forbidden\n" );
168+ else if (dev -> power .disable_depth )
169+ return sprintf (buf , "disabled\n" );
170+ else if (dev -> power .runtime_auto == false)
171+ return sprintf (buf , "forbidden\n" );
172+ return sprintf (buf , "enabled\n" );
173+ }
174+
175+ static ssize_t rtpm_status_show (struct device * dev ,
176+ struct device_attribute * attr , char * buf )
177+ {
178+ if (dev -> power .runtime_error )
179+ return sprintf (buf , "error\n" );
180+ switch (dev -> power .runtime_status ) {
181+ case RPM_SUSPENDED :
182+ return sprintf (buf , "suspended\n" );
183+ case RPM_SUSPENDING :
184+ return sprintf (buf , "suspending\n" );
185+ case RPM_RESUMING :
186+ return sprintf (buf , "resuming\n" );
187+ case RPM_ACTIVE :
188+ return sprintf (buf , "active\n" );
189+ }
190+ return - EIO ;
191+ }
192+
193+ static DEVICE_ATTR (runtime_usage , 0444 , rtpm_usagecount_show , NULL );
194+ static DEVICE_ATTR (runtime_active_kids , 0444 , rtpm_children_show , NULL );
195+ static DEVICE_ATTR (runtime_status , 0444 , rtpm_status_show , NULL );
196+ static DEVICE_ATTR (runtime_enabled , 0444 , rtpm_enabled_show , NULL );
197+
198+ #endif
199+
147200static ssize_t async_show (struct device * dev , struct device_attribute * attr ,
148201 char * buf )
149202{
@@ -170,15 +223,21 @@ static ssize_t async_store(struct device *dev, struct device_attribute *attr,
170223}
171224
172225static DEVICE_ATTR (async , 0644 , async_show , async_store );
173- #endif /* CONFIG_PM_SLEEP_ADVANCED_DEBUG */
226+ #endif /* CONFIG_PM_ADVANCED_DEBUG */
174227
175228static struct attribute * power_attrs [] = {
176229#ifdef CONFIG_PM_RUNTIME
177230 & dev_attr_control .attr ,
178231#endif
179232 & dev_attr_wakeup .attr ,
180- #ifdef CONFIG_PM_SLEEP_ADVANCED_DEBUG
233+ #ifdef CONFIG_PM_ADVANCED_DEBUG
181234 & dev_attr_async .attr ,
235+ #ifdef CONFIG_PM_RUNTIME
236+ & dev_attr_runtime_usage .attr ,
237+ & dev_attr_runtime_active_kids .attr ,
238+ & dev_attr_runtime_status .attr ,
239+ & dev_attr_runtime_enabled .attr ,
240+ #endif
182241#endif
183242 NULL ,
184243};
0 commit comments