shutdown.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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/config.h>
  11. #include <linux/device.h>
  12. #include <asm/semaphore.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. extern int sysdev_shutdown(void);
  25. /**
  26. * device_shutdown - call ->shutdown() on each device to shutdown.
  27. */
  28. void device_shutdown(void)
  29. {
  30. struct device * dev;
  31. down_write(&devices_subsys.rwsem);
  32. list_for_each_entry_reverse(dev, &devices_subsys.kset.list,
  33. kobj.entry) {
  34. if (dev->driver && dev->driver->shutdown) {
  35. dev_dbg(dev, "shutdown\n");
  36. dev->driver->shutdown(dev);
  37. }
  38. }
  39. up_write(&devices_subsys.rwsem);
  40. sysdev_shutdown();
  41. }