2 * shutdown.c - power management functions for the device tree.
4 * Copyright (c) 2002-3 Patrick Mochel
5 * 2002-3 Open Source Development Lab
7 * This file is released under the GPLv2
11 #include <linux/config.h>
12 #include <linux/device.h>
13 #include <asm/semaphore.h>
17 #define to_dev(node) container_of(node, struct device, kobj.entry)
19 extern struct subsystem devices_subsys;
22 int device_detach_shutdown(struct device * dev)
24 if (!dev->detach_state)
27 if (dev->detach_state == DEVICE_PM_OFF) {
28 if (dev->driver && dev->driver->shutdown) {
29 dev_dbg(dev, "shutdown\n");
30 dev->driver->shutdown(dev);
34 return dpm_runtime_suspend(dev, dev->detach_state);
39 * We handle system devices differently - we suspend and shut them
40 * down last and resume them first. That way, we don't do anything stupid like
41 * shutting down the interrupt controller before any devices..
43 * Note that there are not different stages for power management calls -
44 * they only get one called once when interrupts are disabled.
47 extern int sysdev_shutdown(void);
50 * device_shutdown - call ->shutdown() on each device to shutdown.
52 void device_shutdown(void)
56 down_write(&devices_subsys.rwsem);
57 list_for_each_entry_reverse(dev, &devices_subsys.kset.list,
59 if (dev->driver && dev->driver->shutdown) {
60 dev_dbg(dev, "shutdown\n");
61 dev->driver->shutdown(dev);
64 up_write(&devices_subsys.rwsem);