shutdown.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. #include <linux/device.h>
  11. #include <asm/semaphore.h>
  12. #include "../base.h"
  13. #include "power.h"
  14. #define to_dev(node) container_of(node, struct device, kobj.entry)
  15. extern struct subsystem devices_subsys;
  16. /**
  17. * We handle system devices differently - we suspend and shut them
  18. * down last and resume them first. That way, we don't do anything stupid like
  19. * shutting down the interrupt controller before any devices..
  20. *
  21. * Note that there are not different stages for power management calls -
  22. * they only get one called once when interrupts are disabled.
  23. */
  24. /**
  25. * device_shutdown - call ->shutdown() on each device to shutdown.
  26. */
  27. void device_shutdown(void)
  28. {
  29. struct device * dev, *devn;
  30. down_write(&devices_subsys.rwsem);
  31. list_for_each_entry_safe_reverse(dev, devn, &devices_subsys.kset.list,
  32. kobj.entry) {
  33. if (dev->bus && dev->bus->shutdown) {
  34. dev_dbg(dev, "shutdown\n");
  35. dev->bus->shutdown(dev);
  36. } else if (dev->driver && dev->driver->shutdown) {
  37. dev_dbg(dev, "shutdown\n");
  38. dev->driver->shutdown(dev);
  39. }
  40. }
  41. up_write(&devices_subsys.rwsem);
  42. sysdev_shutdown();
  43. }