2005-04-16 15:20:36 -07:00
/*
* drivers / base / power / main . c - Where the driver meets power management .
*
* Copyright ( c ) 2003 Patrick Mochel
* Copyright ( c ) 2003 Open Source Development Lab
*
* This file is released under the GPLv2
*
*
* The driver model core calls device_pm_add ( ) when a device is registered .
* This will intialize the embedded device_pm_info object in the device
* and add it to the list of power - controlled devices . sysfs entries for
* controlling device power management will also be added .
*
* A different set of lists than the global subsystem list are used to
* keep track of power info because we use different lists to hold
* devices based on what stage of the power management process they
* are in . The power domain dependencies may also differ from the
* ancestral dependencies that the subsystem list maintains .
*/
# include <linux/device.h>
2007-05-23 14:19:41 -07:00
# include <linux/mutex.h>
2005-04-16 15:20:36 -07:00
# include "power.h"
LIST_HEAD ( dpm_active ) ;
LIST_HEAD ( dpm_off ) ;
LIST_HEAD ( dpm_off_irq ) ;
2007-05-23 14:19:41 -07:00
DEFINE_MUTEX ( dpm_mtx ) ;
DEFINE_MUTEX ( dpm_list_mtx ) ;
2005-04-16 15:20:36 -07:00
2007-04-26 00:12:06 -07:00
int ( * platform_enable_wakeup ) ( struct device * dev , int is_on ) ;
2007-06-13 15:53:34 +02:00
int device_pm_add ( struct device * dev )
2005-04-16 15:20:36 -07:00
{
int error ;
pr_debug ( " PM: Adding info for %s:%s \n " ,
2007-04-11 01:37:18 -04:00
dev - > bus ? dev - > bus - > name : " No Bus " ,
kobject_name ( & dev - > kobj ) ) ;
2007-05-23 14:19:41 -07:00
mutex_lock ( & dpm_list_mtx ) ;
2005-04-16 15:20:36 -07:00
list_add_tail ( & dev - > power . entry , & dpm_active ) ;
2007-06-13 15:53:34 +02:00
error = dpm_sysfs_add ( dev ) ;
if ( error )
2005-04-16 15:20:36 -07:00
list_del ( & dev - > power . entry ) ;
2007-05-23 14:19:41 -07:00
mutex_unlock ( & dpm_list_mtx ) ;
2005-04-16 15:20:36 -07:00
return error ;
}
2007-06-13 15:53:34 +02:00
void device_pm_remove ( struct device * dev )
2005-04-16 15:20:36 -07:00
{
pr_debug ( " PM: Removing info for %s:%s \n " ,
2007-04-11 01:37:18 -04:00
dev - > bus ? dev - > bus - > name : " No Bus " ,
kobject_name ( & dev - > kobj ) ) ;
2007-05-23 14:19:41 -07:00
mutex_lock ( & dpm_list_mtx ) ;
2005-04-16 15:20:36 -07:00
dpm_sysfs_remove ( dev ) ;
list_del_init ( & dev - > power . entry ) ;
2007-05-23 14:19:41 -07:00
mutex_unlock ( & dpm_list_mtx ) ;
2005-04-16 15:20:36 -07:00
}