runtime.c 1.8 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * drivers/base/power/runtime.c - Handling dynamic device power management.
 *
 * Copyright (c) 2003 Patrick Mochel
 * Copyright (c) 2003 Open Source Development Lab
 *
 */

#include <linux/device.h>
#include "power.h"


static void runtime_resume(struct device * dev)
{
	dev_dbg(dev, "resuming\n");
16
	if (!dev->power.power_state.event)
L
Linus Torvalds 已提交
17 18
		return;
	if (!resume_device(dev))
19
		dev->power.power_state = PMSG_ON;
L
Linus Torvalds 已提交
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
}


/**
 *	dpm_runtime_resume - Power one device back on.
 *	@dev:	Device.
 *
 *	Bring one device back to the on state by first powering it
 *	on, then restoring state. We only operate on devices that aren't
 *	already on.
 *	FIXME: We need to handle devices that are in an unknown state.
 */

void dpm_runtime_resume(struct device * dev)
{
35
	mutex_lock(&dpm_mtx);
L
Linus Torvalds 已提交
36
	runtime_resume(dev);
37
	mutex_unlock(&dpm_mtx);
L
Linus Torvalds 已提交
38
}
39
EXPORT_SYMBOL(dpm_runtime_resume);
L
Linus Torvalds 已提交
40 41 42 43 44 45 46 47 48 49 50 51


/**
 *	dpm_runtime_suspend - Put one device in low-power state.
 *	@dev:	Device.
 *	@state:	State to enter.
 */

int dpm_runtime_suspend(struct device * dev, pm_message_t state)
{
	int error = 0;

52
	mutex_lock(&dpm_mtx);
53
	if (dev->power.power_state.event == state.event)
L
Linus Torvalds 已提交
54 55
		goto Done;

56
	if (dev->power.power_state.event)
L
Linus Torvalds 已提交
57 58 59 60 61
		runtime_resume(dev);

	if (!(error = suspend_device(dev, state)))
		dev->power.power_state = state;
 Done:
62
	mutex_unlock(&dpm_mtx);
L
Linus Torvalds 已提交
63 64
	return error;
}
65
EXPORT_SYMBOL(dpm_runtime_suspend);
L
Linus Torvalds 已提交
66 67


68
#if 0
L
Linus Torvalds 已提交
69 70 71 72 73 74 75 76 77 78 79 80
/**
 *	dpm_set_power_state - Update power_state field.
 *	@dev:	Device.
 *	@state:	Power state device is in.
 *
 *	This is an update mechanism for drivers to notify the core
 *	what power state a device is in. Device probing code may not
 *	always be able to tell, but we need accurate information to
 *	work reliably.
 */
void dpm_set_power_state(struct device * dev, pm_message_t state)
{
81
	mutex_lock(&dpm_mtx);
L
Linus Torvalds 已提交
82
	dev->power.power_state = state;
83
	mutex_unlock(&dpm_mtx);
L
Linus Torvalds 已提交
84
}
85
#endif  /*  0  */