2008-03-20 05:39:13 +08:00
|
|
|
/*
|
|
|
|
* pm_wakeup.h - Power management wakeup interface
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008 Alan Stern
|
2010-09-23 04:09:10 +08:00
|
|
|
* Copyright (C) 2010 Rafael J. Wysocki, Novell Inc.
|
2008-03-20 05:39:13 +08:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _LINUX_PM_WAKEUP_H
|
|
|
|
#define _LINUX_PM_WAKEUP_H
|
|
|
|
|
|
|
|
#ifndef _DEVICE_H_
|
|
|
|
# error "please don't include this file directly"
|
|
|
|
#endif
|
|
|
|
|
2010-03-16 04:44:41 +08:00
|
|
|
#include <linux/types.h>
|
|
|
|
|
PM / Wakeirq: Add automated device wake IRQ handling
Turns out we can automate the handling for the device_may_wakeup()
quite a bit by using the kernel wakeup source list as suggested
by Rafael J. Wysocki <rjw@rjwysocki.net>.
And as some hardware has separate dedicated wake-up interrupt
in addition to the IO interrupt, we can automate the handling by
adding a generic threaded interrupt handler that just calls the
device PM runtime to wake up the device.
This allows dropping code from device drivers as we currently
are doing it in multiple ways, and often wrong.
For most drivers, we should be able to drop the following
boilerplate code from runtime_suspend and runtime_resume
functions:
...
device_init_wakeup(dev, true);
...
if (device_may_wakeup(dev))
enable_irq_wake(irq);
...
if (device_may_wakeup(dev))
disable_irq_wake(irq);
...
device_init_wakeup(dev, false);
...
We can replace it with just the following init and exit
time code:
...
device_init_wakeup(dev, true);
dev_pm_set_wake_irq(dev, irq);
...
dev_pm_clear_wake_irq(dev);
device_init_wakeup(dev, false);
...
And for hardware with dedicated wake-up interrupts:
...
device_init_wakeup(dev, true);
dev_pm_set_dedicated_wake_irq(dev, irq);
...
dev_pm_clear_wake_irq(dev);
device_init_wakeup(dev, false);
...
Signed-off-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2015-05-19 06:40:29 +08:00
|
|
|
struct wake_irq;
|
|
|
|
|
2010-09-23 04:09:10 +08:00
|
|
|
/**
|
|
|
|
* struct wakeup_source - Representation of wakeup sources
|
2010-06-13 06:36:52 +08:00
|
|
|
*
|
PM / Wakeirq: Add automated device wake IRQ handling
Turns out we can automate the handling for the device_may_wakeup()
quite a bit by using the kernel wakeup source list as suggested
by Rafael J. Wysocki <rjw@rjwysocki.net>.
And as some hardware has separate dedicated wake-up interrupt
in addition to the IO interrupt, we can automate the handling by
adding a generic threaded interrupt handler that just calls the
device PM runtime to wake up the device.
This allows dropping code from device drivers as we currently
are doing it in multiple ways, and often wrong.
For most drivers, we should be able to drop the following
boilerplate code from runtime_suspend and runtime_resume
functions:
...
device_init_wakeup(dev, true);
...
if (device_may_wakeup(dev))
enable_irq_wake(irq);
...
if (device_may_wakeup(dev))
disable_irq_wake(irq);
...
device_init_wakeup(dev, false);
...
We can replace it with just the following init and exit
time code:
...
device_init_wakeup(dev, true);
dev_pm_set_wake_irq(dev, irq);
...
dev_pm_clear_wake_irq(dev);
device_init_wakeup(dev, false);
...
And for hardware with dedicated wake-up interrupts:
...
device_init_wakeup(dev, true);
dev_pm_set_dedicated_wake_irq(dev, irq);
...
dev_pm_clear_wake_irq(dev);
device_init_wakeup(dev, false);
...
Signed-off-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2015-05-19 06:40:29 +08:00
|
|
|
* @name: Name of the wakeup source
|
|
|
|
* @entry: Wakeup source list entry
|
|
|
|
* @lock: Wakeup source lock
|
|
|
|
* @wakeirq: Optional device specific wakeirq
|
|
|
|
* @timer: Wakeup timer list
|
|
|
|
* @timer_expires: Wakeup timer expiration
|
2010-09-23 04:09:10 +08:00
|
|
|
* @total_time: Total time this wakeup source has been active.
|
|
|
|
* @max_time: Maximum time this wakeup source has been continuously active.
|
2012-04-30 04:52:52 +08:00
|
|
|
* @last_time: Monotonic clock when the wakeup source's was touched last time.
|
2012-04-30 04:53:32 +08:00
|
|
|
* @prevent_sleep_time: Total time this source has been preventing autosleep.
|
2010-09-23 04:09:10 +08:00
|
|
|
* @event_count: Number of signaled wakeup events.
|
2013-07-11 12:55:58 +08:00
|
|
|
* @active_count: Number of times the wakeup source was activated.
|
|
|
|
* @relax_count: Number of times the wakeup source was deactivated.
|
2012-04-30 04:52:52 +08:00
|
|
|
* @expire_count: Number of times the wakeup source's timeout has expired.
|
|
|
|
* @wakeup_count: Number of times the wakeup source might abort suspend.
|
2010-09-23 04:09:10 +08:00
|
|
|
* @active: Status of the wakeup source.
|
2012-04-30 04:52:52 +08:00
|
|
|
* @has_timeout: The wakeup source has been activated with a timeout.
|
2008-03-20 05:39:13 +08:00
|
|
|
*/
|
2010-09-23 04:09:10 +08:00
|
|
|
struct wakeup_source {
|
2012-02-22 06:47:56 +08:00
|
|
|
const char *name;
|
2010-09-23 04:09:10 +08:00
|
|
|
struct list_head entry;
|
|
|
|
spinlock_t lock;
|
PM / Wakeirq: Add automated device wake IRQ handling
Turns out we can automate the handling for the device_may_wakeup()
quite a bit by using the kernel wakeup source list as suggested
by Rafael J. Wysocki <rjw@rjwysocki.net>.
And as some hardware has separate dedicated wake-up interrupt
in addition to the IO interrupt, we can automate the handling by
adding a generic threaded interrupt handler that just calls the
device PM runtime to wake up the device.
This allows dropping code from device drivers as we currently
are doing it in multiple ways, and often wrong.
For most drivers, we should be able to drop the following
boilerplate code from runtime_suspend and runtime_resume
functions:
...
device_init_wakeup(dev, true);
...
if (device_may_wakeup(dev))
enable_irq_wake(irq);
...
if (device_may_wakeup(dev))
disable_irq_wake(irq);
...
device_init_wakeup(dev, false);
...
We can replace it with just the following init and exit
time code:
...
device_init_wakeup(dev, true);
dev_pm_set_wake_irq(dev, irq);
...
dev_pm_clear_wake_irq(dev);
device_init_wakeup(dev, false);
...
And for hardware with dedicated wake-up interrupts:
...
device_init_wakeup(dev, true);
dev_pm_set_dedicated_wake_irq(dev, irq);
...
dev_pm_clear_wake_irq(dev);
device_init_wakeup(dev, false);
...
Signed-off-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2015-05-19 06:40:29 +08:00
|
|
|
struct wake_irq *wakeirq;
|
2010-09-23 04:09:10 +08:00
|
|
|
struct timer_list timer;
|
|
|
|
unsigned long timer_expires;
|
|
|
|
ktime_t total_time;
|
|
|
|
ktime_t max_time;
|
|
|
|
ktime_t last_time;
|
2012-04-30 04:53:32 +08:00
|
|
|
ktime_t start_prevent_time;
|
|
|
|
ktime_t prevent_sleep_time;
|
2010-09-23 04:09:10 +08:00
|
|
|
unsigned long event_count;
|
|
|
|
unsigned long active_count;
|
|
|
|
unsigned long relax_count;
|
2012-04-30 04:52:52 +08:00
|
|
|
unsigned long expire_count;
|
|
|
|
unsigned long wakeup_count;
|
|
|
|
bool active:1;
|
2012-04-30 04:53:32 +08:00
|
|
|
bool autosleep_enabled:1;
|
2010-09-23 04:09:10 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef CONFIG_PM_SLEEP
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Changes to device_may_wakeup take effect on the next pm state change.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static inline bool device_can_wakeup(struct device *dev)
|
|
|
|
{
|
|
|
|
return dev->power.can_wakeup;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool device_may_wakeup(struct device *dev)
|
2008-03-20 05:39:13 +08:00
|
|
|
{
|
2010-09-23 04:09:10 +08:00
|
|
|
return dev->power.can_wakeup && !!dev->power.wakeup;
|
2008-03-20 05:39:13 +08:00
|
|
|
}
|
|
|
|
|
2010-09-23 04:09:10 +08:00
|
|
|
/* drivers/base/power/wakeup.c */
|
2012-02-22 06:47:56 +08:00
|
|
|
extern void wakeup_source_prepare(struct wakeup_source *ws, const char *name);
|
2010-09-23 04:09:10 +08:00
|
|
|
extern struct wakeup_source *wakeup_source_create(const char *name);
|
2012-02-22 06:47:56 +08:00
|
|
|
extern void wakeup_source_drop(struct wakeup_source *ws);
|
2010-09-23 04:09:10 +08:00
|
|
|
extern void wakeup_source_destroy(struct wakeup_source *ws);
|
|
|
|
extern void wakeup_source_add(struct wakeup_source *ws);
|
|
|
|
extern void wakeup_source_remove(struct wakeup_source *ws);
|
|
|
|
extern struct wakeup_source *wakeup_source_register(const char *name);
|
|
|
|
extern void wakeup_source_unregister(struct wakeup_source *ws);
|
|
|
|
extern int device_wakeup_enable(struct device *dev);
|
|
|
|
extern int device_wakeup_disable(struct device *dev);
|
2011-02-09 06:26:02 +08:00
|
|
|
extern void device_set_wakeup_capable(struct device *dev, bool capable);
|
2010-09-23 04:09:10 +08:00
|
|
|
extern int device_init_wakeup(struct device *dev, bool val);
|
|
|
|
extern int device_set_wakeup_enable(struct device *dev, bool enable);
|
|
|
|
extern void __pm_stay_awake(struct wakeup_source *ws);
|
|
|
|
extern void pm_stay_awake(struct device *dev);
|
|
|
|
extern void __pm_relax(struct wakeup_source *ws);
|
|
|
|
extern void pm_relax(struct device *dev);
|
|
|
|
extern void __pm_wakeup_event(struct wakeup_source *ws, unsigned int msec);
|
|
|
|
extern void pm_wakeup_event(struct device *dev, unsigned int msec);
|
|
|
|
|
|
|
|
#else /* !CONFIG_PM_SLEEP */
|
|
|
|
|
2010-03-16 04:44:41 +08:00
|
|
|
static inline void device_set_wakeup_capable(struct device *dev, bool capable)
|
2008-07-07 09:34:48 +08:00
|
|
|
{
|
2010-03-16 04:44:41 +08:00
|
|
|
dev->power.can_wakeup = capable;
|
2008-07-07 09:34:48 +08:00
|
|
|
}
|
|
|
|
|
2010-03-16 04:44:41 +08:00
|
|
|
static inline bool device_can_wakeup(struct device *dev)
|
2008-03-20 05:39:13 +08:00
|
|
|
{
|
|
|
|
return dev->power.can_wakeup;
|
|
|
|
}
|
|
|
|
|
2012-02-22 06:47:56 +08:00
|
|
|
static inline void wakeup_source_prepare(struct wakeup_source *ws,
|
|
|
|
const char *name) {}
|
|
|
|
|
2010-09-23 04:09:10 +08:00
|
|
|
static inline struct wakeup_source *wakeup_source_create(const char *name)
|
2008-03-20 05:39:13 +08:00
|
|
|
{
|
2010-09-23 04:09:10 +08:00
|
|
|
return NULL;
|
2008-03-20 05:39:13 +08:00
|
|
|
}
|
|
|
|
|
2012-02-22 06:47:56 +08:00
|
|
|
static inline void wakeup_source_drop(struct wakeup_source *ws) {}
|
|
|
|
|
2010-09-23 04:09:10 +08:00
|
|
|
static inline void wakeup_source_destroy(struct wakeup_source *ws) {}
|
|
|
|
|
|
|
|
static inline void wakeup_source_add(struct wakeup_source *ws) {}
|
2008-03-20 05:39:13 +08:00
|
|
|
|
2010-09-23 04:09:10 +08:00
|
|
|
static inline void wakeup_source_remove(struct wakeup_source *ws) {}
|
|
|
|
|
|
|
|
static inline struct wakeup_source *wakeup_source_register(const char *name)
|
2008-03-20 05:39:13 +08:00
|
|
|
{
|
2010-09-23 04:09:10 +08:00
|
|
|
return NULL;
|
2008-03-20 05:39:13 +08:00
|
|
|
}
|
|
|
|
|
2010-09-23 04:09:10 +08:00
|
|
|
static inline void wakeup_source_unregister(struct wakeup_source *ws) {}
|
|
|
|
|
|
|
|
static inline int device_wakeup_enable(struct device *dev)
|
2010-03-16 04:44:41 +08:00
|
|
|
{
|
2011-02-24 18:10:01 +08:00
|
|
|
dev->power.should_wakeup = true;
|
|
|
|
return 0;
|
2010-03-16 04:44:41 +08:00
|
|
|
}
|
2008-07-10 08:16:44 +08:00
|
|
|
|
2010-09-23 04:09:10 +08:00
|
|
|
static inline int device_wakeup_disable(struct device *dev)
|
2008-03-20 05:39:13 +08:00
|
|
|
{
|
2011-02-24 18:10:01 +08:00
|
|
|
dev->power.should_wakeup = false;
|
2010-09-23 04:09:10 +08:00
|
|
|
return 0;
|
2008-03-20 05:39:13 +08:00
|
|
|
}
|
|
|
|
|
2011-02-24 18:10:01 +08:00
|
|
|
static inline int device_set_wakeup_enable(struct device *dev, bool enable)
|
2010-03-16 04:44:41 +08:00
|
|
|
{
|
2011-02-24 18:10:01 +08:00
|
|
|
dev->power.should_wakeup = enable;
|
|
|
|
return 0;
|
2010-03-16 04:44:41 +08:00
|
|
|
}
|
|
|
|
|
2011-02-24 18:10:01 +08:00
|
|
|
static inline int device_init_wakeup(struct device *dev, bool val)
|
|
|
|
{
|
|
|
|
device_set_wakeup_capable(dev, val);
|
|
|
|
device_set_wakeup_enable(dev, val);
|
|
|
|
return 0;
|
|
|
|
}
|
2010-09-23 04:09:10 +08:00
|
|
|
|
2011-02-24 18:10:01 +08:00
|
|
|
static inline bool device_may_wakeup(struct device *dev)
|
2010-03-16 04:44:41 +08:00
|
|
|
{
|
2011-02-24 18:10:01 +08:00
|
|
|
return dev->power.can_wakeup && dev->power.should_wakeup;
|
2010-03-16 04:44:41 +08:00
|
|
|
}
|
2008-03-20 05:39:13 +08:00
|
|
|
|
2010-09-23 04:09:10 +08:00
|
|
|
static inline void __pm_stay_awake(struct wakeup_source *ws) {}
|
|
|
|
|
|
|
|
static inline void pm_stay_awake(struct device *dev) {}
|
|
|
|
|
|
|
|
static inline void __pm_relax(struct wakeup_source *ws) {}
|
|
|
|
|
|
|
|
static inline void pm_relax(struct device *dev) {}
|
|
|
|
|
|
|
|
static inline void __pm_wakeup_event(struct wakeup_source *ws, unsigned int msec) {}
|
|
|
|
|
|
|
|
static inline void pm_wakeup_event(struct device *dev, unsigned int msec) {}
|
|
|
|
|
|
|
|
#endif /* !CONFIG_PM_SLEEP */
|
2008-03-20 05:39:13 +08:00
|
|
|
|
2012-02-22 06:47:56 +08:00
|
|
|
static inline void wakeup_source_init(struct wakeup_source *ws,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
wakeup_source_prepare(ws, name);
|
|
|
|
wakeup_source_add(ws);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void wakeup_source_trash(struct wakeup_source *ws)
|
|
|
|
{
|
|
|
|
wakeup_source_remove(ws);
|
|
|
|
wakeup_source_drop(ws);
|
|
|
|
}
|
|
|
|
|
2008-03-20 05:39:13 +08:00
|
|
|
#endif /* _LINUX_PM_WAKEUP_H */
|