pm.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /*
  2. * pm.h - Power management interface
  3. *
  4. * Copyright (C) 2000 Andrew Henroid
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #ifndef _LINUX_PM_H
  21. #define _LINUX_PM_H
  22. #ifdef __KERNEL__
  23. #include <linux/config.h>
  24. #include <linux/list.h>
  25. #include <asm/atomic.h>
  26. /*
  27. * Power management requests... these are passed to pm_send_all() and friends.
  28. *
  29. * these functions are old and deprecated, see below.
  30. */
  31. typedef int __bitwise pm_request_t;
  32. #define PM_SUSPEND ((__force pm_request_t) 1) /* enter D1-D3 */
  33. #define PM_RESUME ((__force pm_request_t) 2) /* enter D0 */
  34. /*
  35. * Device types... these are passed to pm_register
  36. */
  37. typedef int __bitwise pm_dev_t;
  38. #define PM_UNKNOWN_DEV ((__force pm_dev_t) 0) /* generic */
  39. #define PM_SYS_DEV ((__force pm_dev_t) 1) /* system device (fan, KB controller, ...) */
  40. #define PM_PCI_DEV ((__force pm_dev_t) 2) /* PCI device */
  41. #define PM_USB_DEV ((__force pm_dev_t) 3) /* USB device */
  42. #define PM_SCSI_DEV ((__force pm_dev_t) 4) /* SCSI device */
  43. #define PM_ISA_DEV ((__force pm_dev_t) 5) /* ISA device */
  44. #define PM_MTD_DEV ((__force pm_dev_t) 6) /* Memory Technology Device */
  45. /*
  46. * System device hardware ID (PnP) values
  47. */
  48. enum
  49. {
  50. PM_SYS_UNKNOWN = 0x00000000, /* generic */
  51. PM_SYS_KBC = 0x41d00303, /* keyboard controller */
  52. PM_SYS_COM = 0x41d00500, /* serial port */
  53. PM_SYS_IRDA = 0x41d00510, /* IRDA controller */
  54. PM_SYS_FDC = 0x41d00700, /* floppy controller */
  55. PM_SYS_VGA = 0x41d00900, /* VGA controller */
  56. PM_SYS_PCMCIA = 0x41d00e00, /* PCMCIA controller */
  57. };
  58. /*
  59. * Device identifier
  60. */
  61. #define PM_PCI_ID(dev) ((dev)->bus->number << 16 | (dev)->devfn)
  62. /*
  63. * Request handler callback
  64. */
  65. struct pm_dev;
  66. typedef int (*pm_callback)(struct pm_dev *dev, pm_request_t rqst, void *data);
  67. /*
  68. * Dynamic device information
  69. */
  70. struct pm_dev
  71. {
  72. pm_dev_t type;
  73. unsigned long id;
  74. pm_callback callback;
  75. void *data;
  76. unsigned long flags;
  77. unsigned long state;
  78. unsigned long prev_state;
  79. struct list_head entry;
  80. };
  81. /* Functions above this comment are list-based old-style power
  82. * managment. Please avoid using them. */
  83. /*
  84. * Callbacks for platform drivers to implement.
  85. */
  86. extern void (*pm_idle)(void);
  87. extern void (*pm_power_off)(void);
  88. typedef int __bitwise suspend_state_t;
  89. #define PM_SUSPEND_ON ((__force suspend_state_t) 0)
  90. #define PM_SUSPEND_STANDBY ((__force suspend_state_t) 1)
  91. #define PM_SUSPEND_MEM ((__force suspend_state_t) 3)
  92. #define PM_SUSPEND_DISK ((__force suspend_state_t) 4)
  93. #define PM_SUSPEND_MAX ((__force suspend_state_t) 5)
  94. typedef int __bitwise suspend_disk_method_t;
  95. #define PM_DISK_FIRMWARE ((__force suspend_disk_method_t) 1)
  96. #define PM_DISK_PLATFORM ((__force suspend_disk_method_t) 2)
  97. #define PM_DISK_SHUTDOWN ((__force suspend_disk_method_t) 3)
  98. #define PM_DISK_REBOOT ((__force suspend_disk_method_t) 4)
  99. #define PM_DISK_MAX ((__force suspend_disk_method_t) 5)
  100. struct pm_ops {
  101. suspend_disk_method_t pm_disk_mode;
  102. int (*valid)(suspend_state_t state);
  103. int (*prepare)(suspend_state_t state);
  104. int (*enter)(suspend_state_t state);
  105. int (*finish)(suspend_state_t state);
  106. };
  107. extern void pm_set_ops(struct pm_ops *);
  108. extern struct pm_ops *pm_ops;
  109. extern int pm_suspend(suspend_state_t state);
  110. /*
  111. * Device power management
  112. */
  113. struct device;
  114. typedef struct pm_message {
  115. int event;
  116. } pm_message_t;
  117. /*
  118. * There are 4 important states driver can be in:
  119. * ON -- driver is working
  120. * FREEZE -- stop operations and apply whatever policy is applicable to a
  121. * suspended driver of that class, freeze queues for block like IDE
  122. * does, drop packets for ethernet, etc... stop DMA engine too etc...
  123. * so a consistent image can be saved; but do not power any hardware
  124. * down.
  125. * SUSPEND - like FREEZE, but hardware is doing as much powersaving as
  126. * possible. Roughly pci D3.
  127. *
  128. * Unfortunately, current drivers only recognize numeric values 0 (ON) and 3
  129. * (SUSPEND). We'll need to fix the drivers. So yes, putting 3 to all different
  130. * defines is intentional, and will go away as soon as drivers are fixed. Also
  131. * note that typedef is neccessary, we'll probably want to switch to
  132. * typedef struct pm_message_t { int event; int flags; } pm_message_t
  133. * or something similar soon.
  134. */
  135. #define PM_EVENT_ON 0
  136. #define PM_EVENT_FREEZE 1
  137. #define PM_EVENT_SUSPEND 2
  138. #define PMSG_FREEZE ((struct pm_message){ .event = PM_EVENT_FREEZE, })
  139. #define PMSG_SUSPEND ((struct pm_message){ .event = PM_EVENT_SUSPEND, })
  140. #define PMSG_ON ((struct pm_message){ .event = PM_EVENT_ON, })
  141. struct dev_pm_info {
  142. pm_message_t power_state;
  143. unsigned can_wakeup:1;
  144. #ifdef CONFIG_PM
  145. unsigned should_wakeup:1;
  146. pm_message_t prev_state;
  147. void * saved_state;
  148. struct device * pm_parent;
  149. struct list_head entry;
  150. #endif
  151. };
  152. extern void device_pm_set_parent(struct device * dev, struct device * parent);
  153. extern int device_power_down(pm_message_t state);
  154. extern void device_power_up(void);
  155. extern void device_resume(void);
  156. #ifdef CONFIG_PM
  157. extern int device_suspend(pm_message_t state);
  158. #define device_set_wakeup_enable(dev,val) \
  159. ((dev)->power.should_wakeup = !!(val))
  160. #define device_may_wakeup(dev) \
  161. (device_can_wakeup(dev) && (dev)->power.should_wakeup)
  162. extern int dpm_runtime_suspend(struct device *, pm_message_t);
  163. extern void dpm_runtime_resume(struct device *);
  164. #else /* !CONFIG_PM */
  165. static inline int device_suspend(pm_message_t state)
  166. {
  167. return 0;
  168. }
  169. #define device_set_wakeup_enable(dev,val) do{}while(0)
  170. #define device_may_wakeup(dev) (0)
  171. static inline int dpm_runtime_suspend(struct device * dev, pm_message_t state)
  172. {
  173. return 0;
  174. }
  175. static inline void dpm_runtime_resume(struct device * dev)
  176. {
  177. }
  178. #endif
  179. /* changes to device_may_wakeup take effect on the next pm state change.
  180. * by default, devices should wakeup if they can.
  181. */
  182. #define device_can_wakeup(dev) \
  183. ((dev)->power.can_wakeup)
  184. #define device_init_wakeup(dev,val) \
  185. do { \
  186. device_can_wakeup(dev) = !!(val); \
  187. device_set_wakeup_enable(dev,val); \
  188. } while(0)
  189. #endif /* __KERNEL__ */
  190. #endif /* _LINUX_PM_H */