main.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * drivers/base/power/main.c - Where the driver meets power management.
  3. *
  4. * Copyright (c) 2003 Patrick Mochel
  5. * Copyright (c) 2003 Open Source Development Lab
  6. *
  7. * This file is released under the GPLv2
  8. *
  9. *
  10. * The driver model core calls device_pm_add() when a device is registered.
  11. * This will intialize the embedded device_pm_info object in the device
  12. * and add it to the list of power-controlled devices. sysfs entries for
  13. * controlling device power management will also be added.
  14. *
  15. * A different set of lists than the global subsystem list are used to
  16. * keep track of power info because we use different lists to hold
  17. * devices based on what stage of the power management process they
  18. * are in. The power domain dependencies may also differ from the
  19. * ancestral dependencies that the subsystem list maintains.
  20. */
  21. #include <linux/device.h>
  22. #include <linux/mutex.h>
  23. #include "power.h"
  24. LIST_HEAD(dpm_active);
  25. LIST_HEAD(dpm_off);
  26. LIST_HEAD(dpm_off_irq);
  27. DEFINE_MUTEX(dpm_mtx);
  28. DEFINE_MUTEX(dpm_list_mtx);
  29. int (*platform_enable_wakeup)(struct device *dev, int is_on);
  30. int device_pm_add(struct device *dev)
  31. {
  32. int error;
  33. pr_debug("PM: Adding info for %s:%s\n",
  34. dev->bus ? dev->bus->name : "No Bus",
  35. kobject_name(&dev->kobj));
  36. mutex_lock(&dpm_list_mtx);
  37. list_add_tail(&dev->power.entry, &dpm_active);
  38. error = dpm_sysfs_add(dev);
  39. if (error)
  40. list_del(&dev->power.entry);
  41. mutex_unlock(&dpm_list_mtx);
  42. return error;
  43. }
  44. void device_pm_remove(struct device *dev)
  45. {
  46. pr_debug("PM: Removing info for %s:%s\n",
  47. dev->bus ? dev->bus->name : "No Bus",
  48. kobject_name(&dev->kobj));
  49. mutex_lock(&dpm_list_mtx);
  50. dpm_sysfs_remove(dev);
  51. list_del_init(&dev->power.entry);
  52. mutex_unlock(&dpm_list_mtx);
  53. }