2 * drivers/base/power/common.c - Common device power management code.
4 * Copyright (C) 2011 Rafael J. Wysocki <rjw@sisk.pl>, Renesas Electronics Corp.
6 * This file is released under the GPLv2.
9 #include <linux/init.h>
10 #include <linux/kernel.h>
11 #include <linux/device.h>
12 #include <linux/export.h>
13 #include <linux/slab.h>
14 #include <linux/pm_clock.h>
17 * dev_pm_get_subsys_data - Create or refcount power.subsys_data for device.
18 * @dev: Device to handle.
20 * If power.subsys_data is NULL, point it to a new object, otherwise increment
21 * its reference counter. Return 1 if a new object has been created, otherwise
22 * return 0 or error code.
24 int dev_pm_get_subsys_data(struct device
*dev
)
26 struct pm_subsys_data
*psd
;
28 psd
= kzalloc(sizeof(*psd
), GFP_KERNEL
);
32 spin_lock_irq(&dev
->power
.lock
);
34 if (dev
->power
.subsys_data
) {
35 dev
->power
.subsys_data
->refcount
++;
37 spin_lock_init(&psd
->lock
);
39 dev
->power
.subsys_data
= psd
;
44 spin_unlock_irq(&dev
->power
.lock
);
46 /* kfree() verifies that its argument is nonzero. */
51 EXPORT_SYMBOL_GPL(dev_pm_get_subsys_data
);
54 * dev_pm_put_subsys_data - Drop reference to power.subsys_data.
55 * @dev: Device to handle.
57 * If the reference counter of power.subsys_data is zero after dropping the
58 * reference, power.subsys_data is removed. Return 1 if that happens or 0
61 int dev_pm_put_subsys_data(struct device
*dev
)
63 struct pm_subsys_data
*psd
;
66 spin_lock_irq(&dev
->power
.lock
);
68 psd
= dev_to_psd(dev
);
72 if (--psd
->refcount
== 0) {
73 dev
->power
.subsys_data
= NULL
;
80 spin_unlock_irq(&dev
->power
.lock
);
85 EXPORT_SYMBOL_GPL(dev_pm_put_subsys_data
);