summaryrefslogtreecommitdiff
path: root/drivers/base/power/runtime.c
blob: 4bafef83e79fabe93f2253bb5680a34c4aead0f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
 * 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");
	if (!dev->power.power_state.event)
		return;
	if (!resume_device(dev))
		dev->power.power_state = PMSG_ON;
}


/**
 *	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)
{
	down(&dpm_sem);
	runtime_resume(dev);
	up(&dpm_sem);
}
EXPORT_SYMBOL(dpm_runtime_resume);


/**
 *	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;

	down(&dpm_sem);
	if (dev->power.power_state.event == state.event)
		goto Done;

	if (dev->power.power_state.event)
		runtime_resume(dev);

	if (!(error = suspend_device(dev, state)))
		dev->power.power_state = state;
 Done:
	up(&dpm_sem);
	return error;
}


#if 0
/**
 *	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)
{
	down(&dpm_sem);
	dev->power.power_state = state;
	up(&dpm_sem);
}
#endif  /*  0  */