diff options
Diffstat (limited to 'drivers/acpi/ac.c')
-rw-r--r-- | drivers/acpi/ac.c | 138 |
1 files changed, 56 insertions, 82 deletions
diff --git a/drivers/acpi/ac.c b/drivers/acpi/ac.c index 23ab761dd721..7839b831df94 100644 --- a/drivers/acpi/ac.c +++ b/drivers/acpi/ac.c | |||
@@ -32,7 +32,6 @@ | |||
32 | #include <acpi/acpi_bus.h> | 32 | #include <acpi/acpi_bus.h> |
33 | #include <acpi/acpi_drivers.h> | 33 | #include <acpi/acpi_drivers.h> |
34 | 34 | ||
35 | |||
36 | #define ACPI_AC_COMPONENT 0x00020000 | 35 | #define ACPI_AC_COMPONENT 0x00020000 |
37 | #define ACPI_AC_CLASS "ac_adapter" | 36 | #define ACPI_AC_CLASS "ac_adapter" |
38 | #define ACPI_AC_HID "ACPI0003" | 37 | #define ACPI_AC_HID "ACPI0003" |
@@ -45,47 +44,45 @@ | |||
45 | #define ACPI_AC_STATUS_UNKNOWN 0xFF | 44 | #define ACPI_AC_STATUS_UNKNOWN 0xFF |
46 | 45 | ||
47 | #define _COMPONENT ACPI_AC_COMPONENT | 46 | #define _COMPONENT ACPI_AC_COMPONENT |
48 | ACPI_MODULE_NAME ("acpi_ac") | 47 | ACPI_MODULE_NAME("acpi_ac") |
49 | 48 | ||
50 | MODULE_AUTHOR("Paul Diefenbaugh"); | 49 | MODULE_AUTHOR("Paul Diefenbaugh"); |
51 | MODULE_DESCRIPTION(ACPI_AC_DRIVER_NAME); | 50 | MODULE_DESCRIPTION(ACPI_AC_DRIVER_NAME); |
52 | MODULE_LICENSE("GPL"); | 51 | MODULE_LICENSE("GPL"); |
53 | 52 | ||
54 | static int acpi_ac_add (struct acpi_device *device); | 53 | static int acpi_ac_add(struct acpi_device *device); |
55 | static int acpi_ac_remove (struct acpi_device *device, int type); | 54 | static int acpi_ac_remove(struct acpi_device *device, int type); |
56 | static int acpi_ac_open_fs(struct inode *inode, struct file *file); | 55 | static int acpi_ac_open_fs(struct inode *inode, struct file *file); |
57 | 56 | ||
58 | static struct acpi_driver acpi_ac_driver = { | 57 | static struct acpi_driver acpi_ac_driver = { |
59 | .name = ACPI_AC_DRIVER_NAME, | 58 | .name = ACPI_AC_DRIVER_NAME, |
60 | .class = ACPI_AC_CLASS, | 59 | .class = ACPI_AC_CLASS, |
61 | .ids = ACPI_AC_HID, | 60 | .ids = ACPI_AC_HID, |
62 | .ops = { | 61 | .ops = { |
63 | .add = acpi_ac_add, | 62 | .add = acpi_ac_add, |
64 | .remove = acpi_ac_remove, | 63 | .remove = acpi_ac_remove, |
65 | }, | 64 | }, |
66 | }; | 65 | }; |
67 | 66 | ||
68 | struct acpi_ac { | 67 | struct acpi_ac { |
69 | acpi_handle handle; | 68 | acpi_handle handle; |
70 | unsigned long state; | 69 | unsigned long state; |
71 | }; | 70 | }; |
72 | 71 | ||
73 | static struct file_operations acpi_ac_fops = { | 72 | static struct file_operations acpi_ac_fops = { |
74 | .open = acpi_ac_open_fs, | 73 | .open = acpi_ac_open_fs, |
75 | .read = seq_read, | 74 | .read = seq_read, |
76 | .llseek = seq_lseek, | 75 | .llseek = seq_lseek, |
77 | .release = single_release, | 76 | .release = single_release, |
78 | }; | 77 | }; |
79 | 78 | ||
80 | /* -------------------------------------------------------------------------- | 79 | /* -------------------------------------------------------------------------- |
81 | AC Adapter Management | 80 | AC Adapter Management |
82 | -------------------------------------------------------------------------- */ | 81 | -------------------------------------------------------------------------- */ |
83 | 82 | ||
84 | static int | 83 | static int acpi_ac_get_state(struct acpi_ac *ac) |
85 | acpi_ac_get_state ( | ||
86 | struct acpi_ac *ac) | ||
87 | { | 84 | { |
88 | acpi_status status = AE_OK; | 85 | acpi_status status = AE_OK; |
89 | 86 | ||
90 | ACPI_FUNCTION_TRACE("acpi_ac_get_state"); | 87 | ACPI_FUNCTION_TRACE("acpi_ac_get_state"); |
91 | 88 | ||
@@ -95,24 +92,23 @@ acpi_ac_get_state ( | |||
95 | status = acpi_evaluate_integer(ac->handle, "_PSR", NULL, &ac->state); | 92 | status = acpi_evaluate_integer(ac->handle, "_PSR", NULL, &ac->state); |
96 | if (ACPI_FAILURE(status)) { | 93 | if (ACPI_FAILURE(status)) { |
97 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 94 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
98 | "Error reading AC Adapter state\n")); | 95 | "Error reading AC Adapter state\n")); |
99 | ac->state = ACPI_AC_STATUS_UNKNOWN; | 96 | ac->state = ACPI_AC_STATUS_UNKNOWN; |
100 | return_VALUE(-ENODEV); | 97 | return_VALUE(-ENODEV); |
101 | } | 98 | } |
102 | 99 | ||
103 | return_VALUE(0); | 100 | return_VALUE(0); |
104 | } | 101 | } |
105 | 102 | ||
106 | |||
107 | /* -------------------------------------------------------------------------- | 103 | /* -------------------------------------------------------------------------- |
108 | FS Interface (/proc) | 104 | FS Interface (/proc) |
109 | -------------------------------------------------------------------------- */ | 105 | -------------------------------------------------------------------------- */ |
110 | 106 | ||
111 | static struct proc_dir_entry *acpi_ac_dir; | 107 | static struct proc_dir_entry *acpi_ac_dir; |
112 | 108 | ||
113 | static int acpi_ac_seq_show(struct seq_file *seq, void *offset) | 109 | static int acpi_ac_seq_show(struct seq_file *seq, void *offset) |
114 | { | 110 | { |
115 | struct acpi_ac *ac = (struct acpi_ac *) seq->private; | 111 | struct acpi_ac *ac = (struct acpi_ac *)seq->private; |
116 | 112 | ||
117 | ACPI_FUNCTION_TRACE("acpi_ac_seq_show"); | 113 | ACPI_FUNCTION_TRACE("acpi_ac_seq_show"); |
118 | 114 | ||
@@ -139,23 +135,21 @@ static int acpi_ac_seq_show(struct seq_file *seq, void *offset) | |||
139 | 135 | ||
140 | return_VALUE(0); | 136 | return_VALUE(0); |
141 | } | 137 | } |
142 | 138 | ||
143 | static int acpi_ac_open_fs(struct inode *inode, struct file *file) | 139 | static int acpi_ac_open_fs(struct inode *inode, struct file *file) |
144 | { | 140 | { |
145 | return single_open(file, acpi_ac_seq_show, PDE(inode)->data); | 141 | return single_open(file, acpi_ac_seq_show, PDE(inode)->data); |
146 | } | 142 | } |
147 | 143 | ||
148 | static int | 144 | static int acpi_ac_add_fs(struct acpi_device *device) |
149 | acpi_ac_add_fs ( | ||
150 | struct acpi_device *device) | ||
151 | { | 145 | { |
152 | struct proc_dir_entry *entry = NULL; | 146 | struct proc_dir_entry *entry = NULL; |
153 | 147 | ||
154 | ACPI_FUNCTION_TRACE("acpi_ac_add_fs"); | 148 | ACPI_FUNCTION_TRACE("acpi_ac_add_fs"); |
155 | 149 | ||
156 | if (!acpi_device_dir(device)) { | 150 | if (!acpi_device_dir(device)) { |
157 | acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), | 151 | acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), |
158 | acpi_ac_dir); | 152 | acpi_ac_dir); |
159 | if (!acpi_device_dir(device)) | 153 | if (!acpi_device_dir(device)) |
160 | return_VALUE(-ENODEV); | 154 | return_VALUE(-ENODEV); |
161 | acpi_device_dir(device)->owner = THIS_MODULE; | 155 | acpi_device_dir(device)->owner = THIS_MODULE; |
@@ -163,11 +157,11 @@ acpi_ac_add_fs ( | |||
163 | 157 | ||
164 | /* 'state' [R] */ | 158 | /* 'state' [R] */ |
165 | entry = create_proc_entry(ACPI_AC_FILE_STATE, | 159 | entry = create_proc_entry(ACPI_AC_FILE_STATE, |
166 | S_IRUGO, acpi_device_dir(device)); | 160 | S_IRUGO, acpi_device_dir(device)); |
167 | if (!entry) | 161 | if (!entry) |
168 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 162 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
169 | "Unable to create '%s' fs entry\n", | 163 | "Unable to create '%s' fs entry\n", |
170 | ACPI_AC_FILE_STATE)); | 164 | ACPI_AC_FILE_STATE)); |
171 | else { | 165 | else { |
172 | entry->proc_fops = &acpi_ac_fops; | 166 | entry->proc_fops = &acpi_ac_fops; |
173 | entry->data = acpi_driver_data(device); | 167 | entry->data = acpi_driver_data(device); |
@@ -177,16 +171,12 @@ acpi_ac_add_fs ( | |||
177 | return_VALUE(0); | 171 | return_VALUE(0); |
178 | } | 172 | } |
179 | 173 | ||
180 | 174 | static int acpi_ac_remove_fs(struct acpi_device *device) | |
181 | static int | ||
182 | acpi_ac_remove_fs ( | ||
183 | struct acpi_device *device) | ||
184 | { | 175 | { |
185 | ACPI_FUNCTION_TRACE("acpi_ac_remove_fs"); | 176 | ACPI_FUNCTION_TRACE("acpi_ac_remove_fs"); |
186 | 177 | ||
187 | if (acpi_device_dir(device)) { | 178 | if (acpi_device_dir(device)) { |
188 | remove_proc_entry(ACPI_AC_FILE_STATE, | 179 | remove_proc_entry(ACPI_AC_FILE_STATE, acpi_device_dir(device)); |
189 | acpi_device_dir(device)); | ||
190 | 180 | ||
191 | remove_proc_entry(acpi_device_bid(device), acpi_ac_dir); | 181 | remove_proc_entry(acpi_device_bid(device), acpi_ac_dir); |
192 | acpi_device_dir(device) = NULL; | 182 | acpi_device_dir(device) = NULL; |
@@ -195,19 +185,14 @@ acpi_ac_remove_fs ( | |||
195 | return_VALUE(0); | 185 | return_VALUE(0); |
196 | } | 186 | } |
197 | 187 | ||
198 | |||
199 | /* -------------------------------------------------------------------------- | 188 | /* -------------------------------------------------------------------------- |
200 | Driver Model | 189 | Driver Model |
201 | -------------------------------------------------------------------------- */ | 190 | -------------------------------------------------------------------------- */ |
202 | 191 | ||
203 | static void | 192 | static void acpi_ac_notify(acpi_handle handle, u32 event, void *data) |
204 | acpi_ac_notify ( | ||
205 | acpi_handle handle, | ||
206 | u32 event, | ||
207 | void *data) | ||
208 | { | 193 | { |
209 | struct acpi_ac *ac = (struct acpi_ac *) data; | 194 | struct acpi_ac *ac = (struct acpi_ac *)data; |
210 | struct acpi_device *device = NULL; | 195 | struct acpi_device *device = NULL; |
211 | 196 | ||
212 | ACPI_FUNCTION_TRACE("acpi_ac_notify"); | 197 | ACPI_FUNCTION_TRACE("acpi_ac_notify"); |
213 | 198 | ||
@@ -224,21 +209,18 @@ acpi_ac_notify ( | |||
224 | break; | 209 | break; |
225 | default: | 210 | default: |
226 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 211 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
227 | "Unsupported event [0x%x]\n", event)); | 212 | "Unsupported event [0x%x]\n", event)); |
228 | break; | 213 | break; |
229 | } | 214 | } |
230 | 215 | ||
231 | return_VOID; | 216 | return_VOID; |
232 | } | 217 | } |
233 | 218 | ||
234 | 219 | static int acpi_ac_add(struct acpi_device *device) | |
235 | static int | ||
236 | acpi_ac_add ( | ||
237 | struct acpi_device *device) | ||
238 | { | 220 | { |
239 | int result = 0; | 221 | int result = 0; |
240 | acpi_status status = AE_OK; | 222 | acpi_status status = AE_OK; |
241 | struct acpi_ac *ac = NULL; | 223 | struct acpi_ac *ac = NULL; |
242 | 224 | ||
243 | ACPI_FUNCTION_TRACE("acpi_ac_add"); | 225 | ACPI_FUNCTION_TRACE("acpi_ac_add"); |
244 | 226 | ||
@@ -264,19 +246,20 @@ acpi_ac_add ( | |||
264 | goto end; | 246 | goto end; |
265 | 247 | ||
266 | status = acpi_install_notify_handler(ac->handle, | 248 | status = acpi_install_notify_handler(ac->handle, |
267 | ACPI_DEVICE_NOTIFY, acpi_ac_notify, ac); | 249 | ACPI_DEVICE_NOTIFY, acpi_ac_notify, |
250 | ac); | ||
268 | if (ACPI_FAILURE(status)) { | 251 | if (ACPI_FAILURE(status)) { |
269 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 252 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
270 | "Error installing notify handler\n")); | 253 | "Error installing notify handler\n")); |
271 | result = -ENODEV; | 254 | result = -ENODEV; |
272 | goto end; | 255 | goto end; |
273 | } | 256 | } |
274 | 257 | ||
275 | printk(KERN_INFO PREFIX "%s [%s] (%s)\n", | 258 | printk(KERN_INFO PREFIX "%s [%s] (%s)\n", |
276 | acpi_device_name(device), acpi_device_bid(device), | 259 | acpi_device_name(device), acpi_device_bid(device), |
277 | ac->state?"on-line":"off-line"); | 260 | ac->state ? "on-line" : "off-line"); |
278 | 261 | ||
279 | end: | 262 | end: |
280 | if (result) { | 263 | if (result) { |
281 | acpi_ac_remove_fs(device); | 264 | acpi_ac_remove_fs(device); |
282 | kfree(ac); | 265 | kfree(ac); |
@@ -285,27 +268,23 @@ end: | |||
285 | return_VALUE(result); | 268 | return_VALUE(result); |
286 | } | 269 | } |
287 | 270 | ||
288 | 271 | static int acpi_ac_remove(struct acpi_device *device, int type) | |
289 | static int | ||
290 | acpi_ac_remove ( | ||
291 | struct acpi_device *device, | ||
292 | int type) | ||
293 | { | 272 | { |
294 | acpi_status status = AE_OK; | 273 | acpi_status status = AE_OK; |
295 | struct acpi_ac *ac = NULL; | 274 | struct acpi_ac *ac = NULL; |
296 | 275 | ||
297 | ACPI_FUNCTION_TRACE("acpi_ac_remove"); | 276 | ACPI_FUNCTION_TRACE("acpi_ac_remove"); |
298 | 277 | ||
299 | if (!device || !acpi_driver_data(device)) | 278 | if (!device || !acpi_driver_data(device)) |
300 | return_VALUE(-EINVAL); | 279 | return_VALUE(-EINVAL); |
301 | 280 | ||
302 | ac = (struct acpi_ac *) acpi_driver_data(device); | 281 | ac = (struct acpi_ac *)acpi_driver_data(device); |
303 | 282 | ||
304 | status = acpi_remove_notify_handler(ac->handle, | 283 | status = acpi_remove_notify_handler(ac->handle, |
305 | ACPI_DEVICE_NOTIFY, acpi_ac_notify); | 284 | ACPI_DEVICE_NOTIFY, acpi_ac_notify); |
306 | if (ACPI_FAILURE(status)) | 285 | if (ACPI_FAILURE(status)) |
307 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 286 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
308 | "Error removing notify handler\n")); | 287 | "Error removing notify handler\n")); |
309 | 288 | ||
310 | acpi_ac_remove_fs(device); | 289 | acpi_ac_remove_fs(device); |
311 | 290 | ||
@@ -314,11 +293,9 @@ acpi_ac_remove ( | |||
314 | return_VALUE(0); | 293 | return_VALUE(0); |
315 | } | 294 | } |
316 | 295 | ||
317 | 296 | static int __init acpi_ac_init(void) | |
318 | static int __init | ||
319 | acpi_ac_init (void) | ||
320 | { | 297 | { |
321 | int result = 0; | 298 | int result = 0; |
322 | 299 | ||
323 | ACPI_FUNCTION_TRACE("acpi_ac_init"); | 300 | ACPI_FUNCTION_TRACE("acpi_ac_init"); |
324 | 301 | ||
@@ -336,9 +313,7 @@ acpi_ac_init (void) | |||
336 | return_VALUE(0); | 313 | return_VALUE(0); |
337 | } | 314 | } |
338 | 315 | ||
339 | 316 | static void __exit acpi_ac_exit(void) | |
340 | static void __exit | ||
341 | acpi_ac_exit (void) | ||
342 | { | 317 | { |
343 | ACPI_FUNCTION_TRACE("acpi_ac_exit"); | 318 | ACPI_FUNCTION_TRACE("acpi_ac_exit"); |
344 | 319 | ||
@@ -349,6 +324,5 @@ acpi_ac_exit (void) | |||
349 | return_VOID; | 324 | return_VOID; |
350 | } | 325 | } |
351 | 326 | ||
352 | |||
353 | module_init(acpi_ac_init); | 327 | module_init(acpi_ac_init); |
354 | module_exit(acpi_ac_exit); | 328 | module_exit(acpi_ac_exit); |