Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / drivers / base / power / shutdown.c
1 /*
2  * shutdown.c - power management functions for the device tree.
3  *
4  * Copyright (c) 2002-3 Patrick Mochel
5  *               2002-3 Open Source Development Lab
6  *
7  * This file is released under the GPLv2
8  *
9  */
10
11 #include <linux/config.h>
12 #include <linux/device.h>
13 #include <asm/semaphore.h>
14
15 #include "../base.h"
16 #include "power.h"
17
18 #define to_dev(node) container_of(node, struct device, kobj.entry)
19
20 extern struct subsystem devices_subsys;
21
22
23 /**
24  * We handle system devices differently - we suspend and shut them
25  * down last and resume them first. That way, we don't do anything stupid like
26  * shutting down the interrupt controller before any devices..
27  *
28  * Note that there are not different stages for power management calls -
29  * they only get one called once when interrupts are disabled.
30  */
31
32
33 /**
34  * device_shutdown - call ->shutdown() on each device to shutdown.
35  */
36 void device_shutdown(void)
37 {
38         struct device * dev, *devn;
39
40         down_write(&devices_subsys.rwsem);
41         list_for_each_entry_safe_reverse(dev, devn, &devices_subsys.kset.list,
42                                 kobj.entry) {
43                 if (dev->bus && dev->bus->shutdown) {
44                         dev_dbg(dev, "shutdown\n");
45                         dev->bus->shutdown(dev);
46                 } else if (dev->driver && dev->driver->shutdown) {
47                         dev_dbg(dev, "shutdown\n");
48                         dev->driver->shutdown(dev);
49                 }
50         }
51         up_write(&devices_subsys.rwsem);
52
53         sysdev_shutdown();
54 }
55