2010-03-07 04:28:37 +08:00
|
|
|
/*
|
|
|
|
* drivers/base/power/generic_ops.c - Generic PM callbacks for subsystems
|
|
|
|
*
|
|
|
|
* Copyright (c) 2010 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc.
|
|
|
|
*
|
|
|
|
* This file is released under the GPLv2.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/pm.h>
|
|
|
|
#include <linux/pm_runtime.h>
|
2011-05-27 19:12:15 +08:00
|
|
|
#include <linux/export.h>
|
2010-03-07 04:28:37 +08:00
|
|
|
|
2013-12-10 21:37:41 +08:00
|
|
|
#ifdef CONFIG_PM
|
2010-03-07 04:28:37 +08:00
|
|
|
/**
|
|
|
|
* pm_generic_runtime_suspend - Generic runtime suspend callback for subsystems.
|
|
|
|
* @dev: Device to suspend.
|
|
|
|
*
|
|
|
|
* If PM operations are defined for the @dev's driver and they include
|
|
|
|
* ->runtime_suspend(), execute it and return its error code. Otherwise,
|
2010-11-26 06:41:19 +08:00
|
|
|
* return 0.
|
2010-03-07 04:28:37 +08:00
|
|
|
*/
|
|
|
|
int pm_generic_runtime_suspend(struct device *dev)
|
|
|
|
{
|
|
|
|
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
|
|
|
|
int ret;
|
|
|
|
|
2010-09-09 06:46:16 +08:00
|
|
|
ret = pm && pm->runtime_suspend ? pm->runtime_suspend(dev) : 0;
|
2010-03-07 04:28:37 +08:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(pm_generic_runtime_suspend);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* pm_generic_runtime_resume - Generic runtime resume callback for subsystems.
|
|
|
|
* @dev: Device to resume.
|
|
|
|
*
|
|
|
|
* If PM operations are defined for the @dev's driver and they include
|
|
|
|
* ->runtime_resume(), execute it and return its error code. Otherwise,
|
2010-11-26 06:41:19 +08:00
|
|
|
* return 0.
|
2010-03-07 04:28:37 +08:00
|
|
|
*/
|
|
|
|
int pm_generic_runtime_resume(struct device *dev)
|
|
|
|
{
|
|
|
|
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
|
|
|
|
int ret;
|
|
|
|
|
2010-09-09 06:46:16 +08:00
|
|
|
ret = pm && pm->runtime_resume ? pm->runtime_resume(dev) : 0;
|
2010-03-07 04:28:37 +08:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(pm_generic_runtime_resume);
|
2013-12-10 21:37:41 +08:00
|
|
|
#endif /* CONFIG_PM */
|
2010-03-07 04:28:37 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_PM_SLEEP
|
2011-05-18 05:26:21 +08:00
|
|
|
/**
|
|
|
|
* pm_generic_prepare - Generic routine preparing a device for power transition.
|
|
|
|
* @dev: Device to prepare.
|
|
|
|
*
|
|
|
|
* Prepare a device for a system-wide power transition.
|
|
|
|
*/
|
|
|
|
int pm_generic_prepare(struct device *dev)
|
|
|
|
{
|
|
|
|
struct device_driver *drv = dev->driver;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (drv && drv->pm && drv->pm->prepare)
|
|
|
|
ret = drv->pm->prepare(dev);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-03-07 04:28:37 +08:00
|
|
|
/**
|
2012-01-30 03:38:41 +08:00
|
|
|
* pm_generic_suspend_noirq - Generic suspend_noirq callback for subsystems.
|
|
|
|
* @dev: Device to suspend.
|
2010-03-07 04:28:37 +08:00
|
|
|
*/
|
2012-01-30 03:38:41 +08:00
|
|
|
int pm_generic_suspend_noirq(struct device *dev)
|
2010-03-07 04:28:37 +08:00
|
|
|
{
|
|
|
|
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
|
|
|
|
|
2012-01-30 03:38:41 +08:00
|
|
|
return pm && pm->suspend_noirq ? pm->suspend_noirq(dev) : 0;
|
2010-03-07 04:28:37 +08:00
|
|
|
}
|
2012-01-30 03:38:41 +08:00
|
|
|
EXPORT_SYMBOL_GPL(pm_generic_suspend_noirq);
|
2010-03-07 04:28:37 +08:00
|
|
|
|
2011-07-02 04:12:59 +08:00
|
|
|
/**
|
2012-01-30 03:38:41 +08:00
|
|
|
* pm_generic_suspend_late - Generic suspend_late callback for subsystems.
|
2011-07-02 04:12:59 +08:00
|
|
|
* @dev: Device to suspend.
|
|
|
|
*/
|
2012-01-30 03:38:41 +08:00
|
|
|
int pm_generic_suspend_late(struct device *dev)
|
2011-07-02 04:12:59 +08:00
|
|
|
{
|
2012-01-30 03:38:41 +08:00
|
|
|
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
|
|
|
|
|
|
|
|
return pm && pm->suspend_late ? pm->suspend_late(dev) : 0;
|
2011-07-02 04:12:59 +08:00
|
|
|
}
|
2012-01-30 03:38:41 +08:00
|
|
|
EXPORT_SYMBOL_GPL(pm_generic_suspend_late);
|
2011-07-02 04:12:59 +08:00
|
|
|
|
2010-03-07 04:28:37 +08:00
|
|
|
/**
|
|
|
|
* pm_generic_suspend - Generic suspend callback for subsystems.
|
|
|
|
* @dev: Device to suspend.
|
|
|
|
*/
|
|
|
|
int pm_generic_suspend(struct device *dev)
|
|
|
|
{
|
2012-01-30 03:38:41 +08:00
|
|
|
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
|
|
|
|
|
|
|
|
return pm && pm->suspend ? pm->suspend(dev) : 0;
|
2010-03-07 04:28:37 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(pm_generic_suspend);
|
|
|
|
|
2011-07-02 04:12:59 +08:00
|
|
|
/**
|
|
|
|
* pm_generic_freeze_noirq - Generic freeze_noirq callback for subsystems.
|
|
|
|
* @dev: Device to freeze.
|
|
|
|
*/
|
|
|
|
int pm_generic_freeze_noirq(struct device *dev)
|
|
|
|
{
|
2012-01-30 03:38:41 +08:00
|
|
|
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
|
|
|
|
|
|
|
|
return pm && pm->freeze_noirq ? pm->freeze_noirq(dev) : 0;
|
2011-07-02 04:12:59 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(pm_generic_freeze_noirq);
|
|
|
|
|
2012-01-30 03:38:41 +08:00
|
|
|
/**
|
|
|
|
* pm_generic_freeze_late - Generic freeze_late callback for subsystems.
|
|
|
|
* @dev: Device to freeze.
|
|
|
|
*/
|
|
|
|
int pm_generic_freeze_late(struct device *dev)
|
|
|
|
{
|
|
|
|
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
|
|
|
|
|
|
|
|
return pm && pm->freeze_late ? pm->freeze_late(dev) : 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(pm_generic_freeze_late);
|
|
|
|
|
2010-03-07 04:28:37 +08:00
|
|
|
/**
|
|
|
|
* pm_generic_freeze - Generic freeze callback for subsystems.
|
|
|
|
* @dev: Device to freeze.
|
|
|
|
*/
|
|
|
|
int pm_generic_freeze(struct device *dev)
|
|
|
|
{
|
2012-01-30 03:38:41 +08:00
|
|
|
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
|
|
|
|
|
|
|
|
return pm && pm->freeze ? pm->freeze(dev) : 0;
|
2010-03-07 04:28:37 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(pm_generic_freeze);
|
|
|
|
|
2011-07-02 04:12:59 +08:00
|
|
|
/**
|
|
|
|
* pm_generic_poweroff_noirq - Generic poweroff_noirq callback for subsystems.
|
|
|
|
* @dev: Device to handle.
|
|
|
|
*/
|
|
|
|
int pm_generic_poweroff_noirq(struct device *dev)
|
|
|
|
{
|
2012-01-30 03:38:41 +08:00
|
|
|
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
|
|
|
|
|
|
|
|
return pm && pm->poweroff_noirq ? pm->poweroff_noirq(dev) : 0;
|
2011-07-02 04:12:59 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(pm_generic_poweroff_noirq);
|
|
|
|
|
2012-01-30 03:38:41 +08:00
|
|
|
/**
|
|
|
|
* pm_generic_poweroff_late - Generic poweroff_late callback for subsystems.
|
|
|
|
* @dev: Device to handle.
|
|
|
|
*/
|
|
|
|
int pm_generic_poweroff_late(struct device *dev)
|
|
|
|
{
|
|
|
|
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
|
|
|
|
|
|
|
|
return pm && pm->poweroff_late ? pm->poweroff_late(dev) : 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(pm_generic_poweroff_late);
|
|
|
|
|
2010-03-07 04:28:37 +08:00
|
|
|
/**
|
|
|
|
* pm_generic_poweroff - Generic poweroff callback for subsystems.
|
|
|
|
* @dev: Device to handle.
|
|
|
|
*/
|
|
|
|
int pm_generic_poweroff(struct device *dev)
|
|
|
|
{
|
2012-01-30 03:38:41 +08:00
|
|
|
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
|
|
|
|
|
|
|
|
return pm && pm->poweroff ? pm->poweroff(dev) : 0;
|
2010-03-07 04:28:37 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(pm_generic_poweroff);
|
|
|
|
|
2011-07-02 04:12:59 +08:00
|
|
|
/**
|
|
|
|
* pm_generic_thaw_noirq - Generic thaw_noirq callback for subsystems.
|
|
|
|
* @dev: Device to thaw.
|
|
|
|
*/
|
|
|
|
int pm_generic_thaw_noirq(struct device *dev)
|
|
|
|
{
|
2012-01-30 03:38:41 +08:00
|
|
|
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
|
|
|
|
|
|
|
|
return pm && pm->thaw_noirq ? pm->thaw_noirq(dev) : 0;
|
2011-07-02 04:12:59 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(pm_generic_thaw_noirq);
|
|
|
|
|
2012-01-30 03:38:41 +08:00
|
|
|
/**
|
|
|
|
* pm_generic_thaw_early - Generic thaw_early callback for subsystems.
|
|
|
|
* @dev: Device to thaw.
|
|
|
|
*/
|
|
|
|
int pm_generic_thaw_early(struct device *dev)
|
|
|
|
{
|
|
|
|
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
|
|
|
|
|
|
|
|
return pm && pm->thaw_early ? pm->thaw_early(dev) : 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(pm_generic_thaw_early);
|
|
|
|
|
2010-03-07 04:28:37 +08:00
|
|
|
/**
|
|
|
|
* pm_generic_thaw - Generic thaw callback for subsystems.
|
|
|
|
* @dev: Device to thaw.
|
|
|
|
*/
|
|
|
|
int pm_generic_thaw(struct device *dev)
|
|
|
|
{
|
2012-01-30 03:38:41 +08:00
|
|
|
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
|
|
|
|
|
|
|
|
return pm && pm->thaw ? pm->thaw(dev) : 0;
|
2010-03-07 04:28:37 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(pm_generic_thaw);
|
|
|
|
|
2011-07-02 04:12:59 +08:00
|
|
|
/**
|
|
|
|
* pm_generic_resume_noirq - Generic resume_noirq callback for subsystems.
|
|
|
|
* @dev: Device to resume.
|
|
|
|
*/
|
|
|
|
int pm_generic_resume_noirq(struct device *dev)
|
|
|
|
{
|
2012-01-30 03:38:41 +08:00
|
|
|
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
|
|
|
|
|
|
|
|
return pm && pm->resume_noirq ? pm->resume_noirq(dev) : 0;
|
2011-07-02 04:12:59 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(pm_generic_resume_noirq);
|
|
|
|
|
2012-01-30 03:38:41 +08:00
|
|
|
/**
|
|
|
|
* pm_generic_resume_early - Generic resume_early callback for subsystems.
|
|
|
|
* @dev: Device to resume.
|
|
|
|
*/
|
|
|
|
int pm_generic_resume_early(struct device *dev)
|
|
|
|
{
|
|
|
|
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
|
|
|
|
|
|
|
|
return pm && pm->resume_early ? pm->resume_early(dev) : 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(pm_generic_resume_early);
|
|
|
|
|
2010-03-07 04:28:37 +08:00
|
|
|
/**
|
|
|
|
* pm_generic_resume - Generic resume callback for subsystems.
|
|
|
|
* @dev: Device to resume.
|
|
|
|
*/
|
|
|
|
int pm_generic_resume(struct device *dev)
|
|
|
|
{
|
2012-01-30 03:38:41 +08:00
|
|
|
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
|
|
|
|
|
|
|
|
return pm && pm->resume ? pm->resume(dev) : 0;
|
2010-03-07 04:28:37 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(pm_generic_resume);
|
|
|
|
|
2011-07-02 04:12:59 +08:00
|
|
|
/**
|
|
|
|
* pm_generic_restore_noirq - Generic restore_noirq callback for subsystems.
|
|
|
|
* @dev: Device to restore.
|
|
|
|
*/
|
|
|
|
int pm_generic_restore_noirq(struct device *dev)
|
|
|
|
{
|
2012-01-30 03:38:41 +08:00
|
|
|
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
|
|
|
|
|
|
|
|
return pm && pm->restore_noirq ? pm->restore_noirq(dev) : 0;
|
2011-07-02 04:12:59 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(pm_generic_restore_noirq);
|
|
|
|
|
2012-01-30 03:38:41 +08:00
|
|
|
/**
|
|
|
|
* pm_generic_restore_early - Generic restore_early callback for subsystems.
|
|
|
|
* @dev: Device to resume.
|
|
|
|
*/
|
|
|
|
int pm_generic_restore_early(struct device *dev)
|
|
|
|
{
|
|
|
|
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
|
|
|
|
|
|
|
|
return pm && pm->restore_early ? pm->restore_early(dev) : 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(pm_generic_restore_early);
|
|
|
|
|
2010-03-07 04:28:37 +08:00
|
|
|
/**
|
|
|
|
* pm_generic_restore - Generic restore callback for subsystems.
|
|
|
|
* @dev: Device to restore.
|
|
|
|
*/
|
|
|
|
int pm_generic_restore(struct device *dev)
|
|
|
|
{
|
2012-01-30 03:38:41 +08:00
|
|
|
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
|
|
|
|
|
|
|
|
return pm && pm->restore ? pm->restore(dev) : 0;
|
2010-03-07 04:28:37 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(pm_generic_restore);
|
2011-05-18 05:26:21 +08:00
|
|
|
|
|
|
|
/**
|
2014-03-25 04:37:03 +08:00
|
|
|
* pm_generic_complete - Generic routine completing a device power transition.
|
2011-05-18 05:26:21 +08:00
|
|
|
* @dev: Device to handle.
|
|
|
|
*
|
|
|
|
* Complete a device power transition during a system-wide power transition.
|
|
|
|
*/
|
|
|
|
void pm_generic_complete(struct device *dev)
|
|
|
|
{
|
|
|
|
struct device_driver *drv = dev->driver;
|
|
|
|
|
|
|
|
if (drv && drv->pm && drv->pm->complete)
|
|
|
|
drv->pm->complete(dev);
|
|
|
|
}
|
2010-03-07 04:28:37 +08:00
|
|
|
#endif /* CONFIG_PM_SLEEP */
|