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 
21 #ifndef _LINUX_PM_H
22 #define _LINUX_PM_H
23 
24 #ifdef __KERNEL__
25 
26 #include <linux/config.h>
27 #include <linux/list.h>
28 
29 /*
30  * Power management requests
31  */
32 enum
33 {
34 	PM_SUSPEND, /* enter D1-D3 */
35 	PM_RESUME,  /* enter D0 */
36 
37 	PM_SAVE_STATE,  /* save device's state */
38 
39 	/* enable wake-on */
40 	PM_SET_WAKEUP,
41 
42 	/* bus resource management */
43 	PM_GET_RESOURCES,
44 	PM_SET_RESOURCES,
45 
46 	/* base station management */
47 	PM_EJECT,
48 	PM_LOCK,
49 };
50 
51 typedef int pm_request_t;
52 
53 /*
54  * Device types
55  */
56 enum
57 {
58 	PM_UNKNOWN_DEV = 0, /* generic */
59 	PM_SYS_DEV,	    /* system device (fan, KB controller, ...) */
60 	PM_PCI_DEV,	    /* PCI device */
61 	PM_USB_DEV,	    /* USB device */
62 	PM_SCSI_DEV,	    /* SCSI device */
63 	PM_ISA_DEV,	    /* ISA device */
64 	PM_MTD_DEV,	    /* Memory Technology Device */
65 };
66 
67 typedef int pm_dev_t;
68 
69 /*
70  * System device hardware ID (PnP) values
71  */
72 enum
73 {
74 	PM_SYS_UNKNOWN = 0x00000000, /* generic */
75 	PM_SYS_KBC =	 0x41d00303, /* keyboard controller */
76 	PM_SYS_COM =	 0x41d00500, /* serial port */
77 	PM_SYS_IRDA =	 0x41d00510, /* IRDA controller */
78 	PM_SYS_FDC =	 0x41d00700, /* floppy controller */
79 	PM_SYS_VGA =	 0x41d00900, /* VGA controller */
80 	PM_SYS_PCMCIA =	 0x41d00e00, /* PCMCIA controller */
81 };
82 
83 /*
84  * Device identifier
85  */
86 #define PM_PCI_ID(dev) ((dev)->bus->number << 16 | (dev)->devfn)
87 
88 /*
89  * Request handler callback
90  */
91 struct pm_dev;
92 
93 typedef int (*pm_callback)(struct pm_dev *dev, pm_request_t rqst, void *data);
94 
95 /*
96  * Dynamic device information
97  */
98 struct pm_dev
99 {
100 	pm_dev_t	 type;
101 	unsigned long	 id;
102 	pm_callback	 callback;
103 	void		*data;
104 
105 	unsigned long	 flags;
106 	unsigned long	 state;
107 	unsigned long	 prev_state;
108 
109 	struct list_head entry;
110 };
111 
112 #ifdef CONFIG_PM
113 
114 extern int pm_active;
115 
116 #define PM_IS_ACTIVE() (pm_active != 0)
117 
118 /*
119  * Register a device with power management
120  */
121 struct pm_dev *pm_register(pm_dev_t type,
122 			   unsigned long id,
123 			   pm_callback callback);
124 
125 /*
126  * Unregister a device with power management
127  */
128 void pm_unregister(struct pm_dev *dev);
129 
130 /*
131  * Unregister all devices with matching callback
132  */
133 void pm_unregister_all(pm_callback callback);
134 
135 /*
136  * Send a request to a single device
137  */
138 int pm_send(struct pm_dev *dev, pm_request_t rqst, void *data);
139 
140 /*
141  * Send a request to all devices
142  */
143 int pm_send_all(pm_request_t rqst, void *data);
144 
145 /*
146  * Find a device
147  */
148 struct pm_dev *pm_find(pm_dev_t type, struct pm_dev *from);
149 
pm_access(struct pm_dev * dev)150 static inline void pm_access(struct pm_dev *dev) {}
pm_dev_idle(struct pm_dev * dev)151 static inline void pm_dev_idle(struct pm_dev *dev) {}
152 
153 #else /* CONFIG_PM */
154 
155 #define PM_IS_ACTIVE() 0
156 
pm_register(pm_dev_t type,unsigned long id,pm_callback callback)157 static inline struct pm_dev *pm_register(pm_dev_t type,
158 					 unsigned long id,
159 					 pm_callback callback)
160 {
161 	return 0;
162 }
163 
pm_unregister(struct pm_dev * dev)164 static inline void pm_unregister(struct pm_dev *dev) {}
165 
pm_unregister_all(pm_callback callback)166 static inline void pm_unregister_all(pm_callback callback) {}
167 
pm_send(struct pm_dev * dev,pm_request_t rqst,void * data)168 static inline int pm_send(struct pm_dev *dev, pm_request_t rqst, void *data)
169 {
170 	return 0;
171 }
172 
pm_send_all(pm_request_t rqst,void * data)173 static inline int pm_send_all(pm_request_t rqst, void *data)
174 {
175 	return 0;
176 }
177 
pm_find(pm_dev_t type,struct pm_dev * from)178 static inline struct pm_dev *pm_find(pm_dev_t type, struct pm_dev *from)
179 {
180 	return 0;
181 }
182 
pm_access(struct pm_dev * dev)183 static inline void pm_access(struct pm_dev *dev) {}
pm_dev_idle(struct pm_dev * dev)184 static inline void pm_dev_idle(struct pm_dev *dev) {}
185 
186 #endif /* CONFIG_PM */
187 
188 extern void (*pm_idle)(void);
189 extern void (*pm_power_off)(void);
190 
191 #endif /* __KERNEL__ */
192 
193 #endif /* _LINUX_PM_H */
194