blob: e8f0519f5dfa88566e3e49d34d0e637180793a7c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * drivers/base/power/runtime.c - Handling dynamic device power management.
3 *
4 * Copyright (c) 2003 Patrick Mochel
5 * Copyright (c) 2003 Open Source Development Lab
6 *
7 */
8
9#include <linux/device.h>
10#include "power.h"
11
12
13static void runtime_resume(struct device * dev)
14{
15 dev_dbg(dev, "resuming\n");
Pavel Machekca078ba2005-09-03 15:56:57 -070016 if (!dev->power.power_state.event)
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 return;
18 if (!resume_device(dev))
Pavel Machekca078ba2005-09-03 15:56:57 -070019 dev->power.power_state = PMSG_ON;
Linus Torvalds1da177e2005-04-16 15:20:36 -070020}
21
22
23/**
24 * dpm_runtime_resume - Power one device back on.
25 * @dev: Device.
26 *
27 * Bring one device back to the on state by first powering it
28 * on, then restoring state. We only operate on devices that aren't
29 * already on.
30 * FIXME: We need to handle devices that are in an unknown state.
31 */
32
33void dpm_runtime_resume(struct device * dev)
34{
35 down(&dpm_sem);
36 runtime_resume(dev);
37 up(&dpm_sem);
38}
39
40
41/**
42 * dpm_runtime_suspend - Put one device in low-power state.
43 * @dev: Device.
44 * @state: State to enter.
45 */
46
47int dpm_runtime_suspend(struct device * dev, pm_message_t state)
48{
49 int error = 0;
50
51 down(&dpm_sem);
Pavel Machekca078ba2005-09-03 15:56:57 -070052 if (dev->power.power_state.event == state.event)
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 goto Done;
54
Pavel Machekca078ba2005-09-03 15:56:57 -070055 if (dev->power.power_state.event)
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 runtime_resume(dev);
57
58 if (!(error = suspend_device(dev, state)))
59 dev->power.power_state = state;
60 Done:
61 up(&dpm_sem);
62 return error;
63}
64
65
66/**
67 * dpm_set_power_state - Update power_state field.
68 * @dev: Device.
69 * @state: Power state device is in.
70 *
71 * This is an update mechanism for drivers to notify the core
72 * what power state a device is in. Device probing code may not
73 * always be able to tell, but we need accurate information to
74 * work reliably.
75 */
76void dpm_set_power_state(struct device * dev, pm_message_t state)
77{
78 down(&dpm_sem);
79 dev->power.power_state = state;
80 up(&dpm_sem);
81}