shutdown.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. int device_detach_shutdown(struct device * dev)
  17. {
  18. if (!dev->detach_state)
  19. return 0;
  20. if (dev->detach_state == DEVICE_PM_OFF) {
  21. if (dev->driver && dev->driver->shutdown)
  22. dev->driver->shutdown(dev);
  23. return 0;
  24. }
  25. return dpm_runtime_suspend(dev, dev->detach_state);
  26. }
  27. /**
  28. * We handle system devices differently - we suspend and shut them
  29. * down last and resume them first. That way, we don't do anything stupid like
  30. * shutting down the interrupt controller before any devices..
  31. *
  32. * Note that there are not different stages for power management calls -
  33. * they only get one called once when interrupts are disabled.
  34. */
  35. extern int sysdev_shutdown(void);
  36. /**
  37. * device_shutdown - call ->shutdown() on each device to shutdown.
  38. */
  39. void device_shutdown(void)
  40. {
  41. struct device * dev;
  42. down_write(&devices_subsys.rwsem);
  43. list_for_each_entry_reverse(dev, &devices_subsys.kset.list, kobj.entry) {
  44. pr_debug("shutting down %s: ", dev->bus_id);
  45. if (dev->driver && dev->driver->shutdown) {
  46. pr_debug("Ok\n");
  47. dev->driver->shutdown(dev);
  48. } else
  49. pr_debug("Ignored.\n");
  50. }
  51. up_write(&devices_subsys.rwsem);
  52. sysdev_shutdown();
  53. }