blob: 58b6f77a1b340f3bfc70527758c501be18ed6f52 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/device.h>
12#include <asm/semaphore.h>
13
Adrian Bunkf67d1152006-01-19 17:30:17 +010014#include "../base.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include "power.h"
16
17#define to_dev(node) container_of(node, struct device, kobj.entry)
18
19extern struct subsystem devices_subsys;
20
21
Linus Torvalds1da177e2005-04-16 15:20:36 -070022/**
23 * We handle system devices differently - we suspend and shut them
24 * down last and resume them first. That way, we don't do anything stupid like
25 * shutting down the interrupt controller before any devices..
26 *
27 * Note that there are not different stages for power management calls -
28 * they only get one called once when interrupts are disabled.
29 */
30
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32/**
33 * device_shutdown - call ->shutdown() on each device to shutdown.
34 */
35void device_shutdown(void)
36{
Michael Richardson9c08a932006-01-09 01:04:51 -080037 struct device * dev, *devn;
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Michael Richardson9c08a932006-01-09 01:04:51 -080039 list_for_each_entry_safe_reverse(dev, devn, &devices_subsys.kset.list,
David Brownell82428b62005-05-09 08:07:00 -070040 kobj.entry) {
Russell King594c8282006-01-05 14:29:51 +000041 if (dev->bus && dev->bus->shutdown) {
42 dev_dbg(dev, "shutdown\n");
43 dev->bus->shutdown(dev);
44 } else if (dev->driver && dev->driver->shutdown) {
David Brownell82428b62005-05-09 08:07:00 -070045 dev_dbg(dev, "shutdown\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 dev->driver->shutdown(dev);
David Brownell82428b62005-05-09 08:07:00 -070047 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50 sysdev_shutdown();
51}
52