Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/device.h> |
| 12 | #include <asm/semaphore.h> |
| 13 | |
Adrian Bunk | f67d115 | 2006-01-19 17:30:17 +0100 | [diff] [blame] | 14 | #include "../base.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include "power.h" |
| 16 | |
| 17 | #define to_dev(node) container_of(node, struct device, kobj.entry) |
| 18 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | /** |
| 21 | * We handle system devices differently - we suspend and shut them |
| 22 | * down last and resume them first. That way, we don't do anything stupid like |
| 23 | * shutting down the interrupt controller before any devices.. |
| 24 | * |
| 25 | * Note that there are not different stages for power management calls - |
| 26 | * they only get one called once when interrupts are disabled. |
| 27 | */ |
| 28 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
| 30 | /** |
| 31 | * device_shutdown - call ->shutdown() on each device to shutdown. |
| 32 | */ |
| 33 | void device_shutdown(void) |
| 34 | { |
Michael Richardson | 9c08a93 | 2006-01-09 01:04:51 -0800 | [diff] [blame] | 35 | struct device * dev, *devn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame^] | 37 | list_for_each_entry_safe_reverse(dev, devn, &devices_subsys.list, |
David Brownell | 82428b6 | 2005-05-09 08:07:00 -0700 | [diff] [blame] | 38 | kobj.entry) { |
Russell King | 594c828 | 2006-01-05 14:29:51 +0000 | [diff] [blame] | 39 | if (dev->bus && dev->bus->shutdown) { |
| 40 | dev_dbg(dev, "shutdown\n"); |
| 41 | dev->bus->shutdown(dev); |
| 42 | } else if (dev->driver && dev->driver->shutdown) { |
David Brownell | 82428b6 | 2005-05-09 08:07:00 -0700 | [diff] [blame] | 43 | dev_dbg(dev, "shutdown\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | dev->driver->shutdown(dev); |
David Brownell | 82428b6 | 2005-05-09 08:07:00 -0700 | [diff] [blame] | 45 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
| 48 | sysdev_shutdown(); |
| 49 | } |
| 50 | |