diff options
-rw-r--r-- | drivers/acpi/ac.c | 163 | ||||
-rw-r--r-- | drivers/acpi/acpi_platform.c | 1 |
2 files changed, 81 insertions, 83 deletions
diff --git a/drivers/acpi/ac.c b/drivers/acpi/ac.c index f37beaa32750..324b5a096eff 100644 --- a/drivers/acpi/ac.c +++ b/drivers/acpi/ac.c | |||
@@ -34,6 +34,7 @@ | |||
34 | #include <linux/proc_fs.h> | 34 | #include <linux/proc_fs.h> |
35 | #include <linux/seq_file.h> | 35 | #include <linux/seq_file.h> |
36 | #endif | 36 | #endif |
37 | #include <linux/platform_device.h> | ||
37 | #include <linux/power_supply.h> | 38 | #include <linux/power_supply.h> |
38 | #include <acpi/acpi_bus.h> | 39 | #include <acpi/acpi_bus.h> |
39 | #include <acpi/acpi_drivers.h> | 40 | #include <acpi/acpi_drivers.h> |
@@ -61,39 +62,12 @@ extern void *acpi_unlock_ac_dir(struct proc_dir_entry *acpi_ac_dir); | |||
61 | static int acpi_ac_open_fs(struct inode *inode, struct file *file); | 62 | static int acpi_ac_open_fs(struct inode *inode, struct file *file); |
62 | #endif | 63 | #endif |
63 | 64 | ||
64 | static int acpi_ac_add(struct acpi_device *device); | ||
65 | static int acpi_ac_remove(struct acpi_device *device); | ||
66 | static void acpi_ac_notify(struct acpi_device *device, u32 event); | ||
67 | |||
68 | static const struct acpi_device_id ac_device_ids[] = { | ||
69 | {"ACPI0003", 0}, | ||
70 | {"", 0}, | ||
71 | }; | ||
72 | MODULE_DEVICE_TABLE(acpi, ac_device_ids); | ||
73 | |||
74 | #ifdef CONFIG_PM_SLEEP | ||
75 | static int acpi_ac_resume(struct device *dev); | ||
76 | #endif | ||
77 | static SIMPLE_DEV_PM_OPS(acpi_ac_pm, NULL, acpi_ac_resume); | ||
78 | |||
79 | static int ac_sleep_before_get_state_ms; | 65 | static int ac_sleep_before_get_state_ms; |
80 | 66 | ||
81 | static struct acpi_driver acpi_ac_driver = { | ||
82 | .name = "ac", | ||
83 | .class = ACPI_AC_CLASS, | ||
84 | .ids = ac_device_ids, | ||
85 | .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS, | ||
86 | .ops = { | ||
87 | .add = acpi_ac_add, | ||
88 | .remove = acpi_ac_remove, | ||
89 | .notify = acpi_ac_notify, | ||
90 | }, | ||
91 | .drv.pm = &acpi_ac_pm, | ||
92 | }; | ||
93 | |||
94 | struct acpi_ac { | 67 | struct acpi_ac { |
95 | struct power_supply charger; | 68 | struct power_supply charger; |
96 | struct acpi_device * device; | 69 | struct acpi_device *adev; |
70 | struct platform_device *pdev; | ||
97 | unsigned long long state; | 71 | unsigned long long state; |
98 | }; | 72 | }; |
99 | 73 | ||
@@ -115,15 +89,13 @@ static const struct file_operations acpi_ac_fops = { | |||
115 | 89 | ||
116 | static int acpi_ac_get_state(struct acpi_ac *ac) | 90 | static int acpi_ac_get_state(struct acpi_ac *ac) |
117 | { | 91 | { |
118 | acpi_status status = AE_OK; | 92 | acpi_status status; |
119 | |||
120 | 93 | ||
121 | if (!ac) | 94 | status = acpi_evaluate_integer(ac->adev->handle, "_PSR", NULL, |
122 | return -EINVAL; | 95 | &ac->state); |
123 | |||
124 | status = acpi_evaluate_integer(ac->device->handle, "_PSR", NULL, &ac->state); | ||
125 | if (ACPI_FAILURE(status)) { | 96 | if (ACPI_FAILURE(status)) { |
126 | ACPI_EXCEPTION((AE_INFO, status, "Error reading AC Adapter state")); | 97 | ACPI_EXCEPTION((AE_INFO, status, |
98 | "Error reading AC Adapter state")); | ||
127 | ac->state = ACPI_AC_STATUS_UNKNOWN; | 99 | ac->state = ACPI_AC_STATUS_UNKNOWN; |
128 | return -ENODEV; | 100 | return -ENODEV; |
129 | } | 101 | } |
@@ -201,36 +173,36 @@ static int acpi_ac_open_fs(struct inode *inode, struct file *file) | |||
201 | return single_open(file, acpi_ac_seq_show, PDE_DATA(inode)); | 173 | return single_open(file, acpi_ac_seq_show, PDE_DATA(inode)); |
202 | } | 174 | } |
203 | 175 | ||
204 | static int acpi_ac_add_fs(struct acpi_device *device) | 176 | static int acpi_ac_add_fs(struct acpi_ac *ac) |
205 | { | 177 | { |
206 | struct proc_dir_entry *entry = NULL; | 178 | struct proc_dir_entry *entry = NULL; |
207 | 179 | ||
208 | printk(KERN_WARNING PREFIX "Deprecated procfs I/F for AC is loaded," | 180 | printk(KERN_WARNING PREFIX "Deprecated procfs I/F for AC is loaded," |
209 | " please retry with CONFIG_ACPI_PROCFS_POWER cleared\n"); | 181 | " please retry with CONFIG_ACPI_PROCFS_POWER cleared\n"); |
210 | if (!acpi_device_dir(device)) { | 182 | if (!acpi_device_dir(ac->adev)) { |
211 | acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), | 183 | acpi_device_dir(ac->adev) = |
212 | acpi_ac_dir); | 184 | proc_mkdir(acpi_device_bid(ac->adev), acpi_ac_dir); |
213 | if (!acpi_device_dir(device)) | 185 | if (!acpi_device_dir(ac->adev)) |
214 | return -ENODEV; | 186 | return -ENODEV; |
215 | } | 187 | } |
216 | 188 | ||
217 | /* 'state' [R] */ | 189 | /* 'state' [R] */ |
218 | entry = proc_create_data(ACPI_AC_FILE_STATE, | 190 | entry = proc_create_data(ACPI_AC_FILE_STATE, |
219 | S_IRUGO, acpi_device_dir(device), | 191 | S_IRUGO, acpi_device_dir(ac->adev), |
220 | &acpi_ac_fops, acpi_driver_data(device)); | 192 | &acpi_ac_fops, ac); |
221 | if (!entry) | 193 | if (!entry) |
222 | return -ENODEV; | 194 | return -ENODEV; |
223 | return 0; | 195 | return 0; |
224 | } | 196 | } |
225 | 197 | ||
226 | static int acpi_ac_remove_fs(struct acpi_device *device) | 198 | static int acpi_ac_remove_fs(struct acpi_ac *ac) |
227 | { | 199 | { |
228 | 200 | ||
229 | if (acpi_device_dir(device)) { | 201 | if (acpi_device_dir(ac->adev)) { |
230 | remove_proc_entry(ACPI_AC_FILE_STATE, acpi_device_dir(device)); | 202 | remove_proc_entry(ACPI_AC_FILE_STATE, |
231 | 203 | acpi_device_dir(ac->adev)); | |
232 | remove_proc_entry(acpi_device_bid(device), acpi_ac_dir); | 204 | remove_proc_entry(acpi_device_bid(ac->adev), acpi_ac_dir); |
233 | acpi_device_dir(device) = NULL; | 205 | acpi_device_dir(ac->adev) = NULL; |
234 | } | 206 | } |
235 | 207 | ||
236 | return 0; | 208 | return 0; |
@@ -241,10 +213,9 @@ static int acpi_ac_remove_fs(struct acpi_device *device) | |||
241 | Driver Model | 213 | Driver Model |
242 | -------------------------------------------------------------------------- */ | 214 | -------------------------------------------------------------------------- */ |
243 | 215 | ||
244 | static void acpi_ac_notify(struct acpi_device *device, u32 event) | 216 | static void acpi_ac_notify_handler(acpi_handle handle, u32 event, void *data) |
245 | { | 217 | { |
246 | struct acpi_ac *ac = acpi_driver_data(device); | 218 | struct acpi_ac *ac = data; |
247 | |||
248 | 219 | ||
249 | if (!ac) | 220 | if (!ac) |
250 | return; | 221 | return; |
@@ -267,10 +238,10 @@ static void acpi_ac_notify(struct acpi_device *device, u32 event) | |||
267 | msleep(ac_sleep_before_get_state_ms); | 238 | msleep(ac_sleep_before_get_state_ms); |
268 | 239 | ||
269 | acpi_ac_get_state(ac); | 240 | acpi_ac_get_state(ac); |
270 | acpi_bus_generate_netlink_event(device->pnp.device_class, | 241 | acpi_bus_generate_netlink_event(ac->adev->pnp.device_class, |
271 | dev_name(&device->dev), event, | 242 | dev_name(&ac->pdev->dev), |
272 | (u32) ac->state); | 243 | event, (u32) ac->state); |
273 | acpi_notifier_call_chain(device, event, (u32) ac->state); | 244 | acpi_notifier_call_chain(ac->adev, event, (u32) ac->state); |
274 | kobject_uevent(&ac->charger.dev->kobj, KOBJ_CHANGE); | 245 | kobject_uevent(&ac->charger.dev->kobj, KOBJ_CHANGE); |
275 | } | 246 | } |
276 | 247 | ||
@@ -295,50 +266,61 @@ static struct dmi_system_id ac_dmi_table[] = { | |||
295 | {}, | 266 | {}, |
296 | }; | 267 | }; |
297 | 268 | ||
298 | static int acpi_ac_add(struct acpi_device *device) | 269 | static int acpi_ac_probe(struct platform_device *pdev) |
299 | { | 270 | { |
300 | int result = 0; | 271 | int result = 0; |
301 | struct acpi_ac *ac = NULL; | 272 | struct acpi_ac *ac = NULL; |
273 | struct acpi_device *adev; | ||
302 | 274 | ||
303 | 275 | if (!pdev) | |
304 | if (!device) | ||
305 | return -EINVAL; | 276 | return -EINVAL; |
306 | 277 | ||
278 | result = acpi_bus_get_device(ACPI_HANDLE(&pdev->dev), &adev); | ||
279 | if (result) | ||
280 | return -ENODEV; | ||
281 | |||
307 | ac = kzalloc(sizeof(struct acpi_ac), GFP_KERNEL); | 282 | ac = kzalloc(sizeof(struct acpi_ac), GFP_KERNEL); |
308 | if (!ac) | 283 | if (!ac) |
309 | return -ENOMEM; | 284 | return -ENOMEM; |
310 | 285 | ||
311 | ac->device = device; | 286 | strcpy(acpi_device_name(adev), ACPI_AC_DEVICE_NAME); |
312 | strcpy(acpi_device_name(device), ACPI_AC_DEVICE_NAME); | 287 | strcpy(acpi_device_class(adev), ACPI_AC_CLASS); |
313 | strcpy(acpi_device_class(device), ACPI_AC_CLASS); | 288 | ac->adev = adev; |
314 | device->driver_data = ac; | 289 | ac->pdev = pdev; |
290 | platform_set_drvdata(pdev, ac); | ||
315 | 291 | ||
316 | result = acpi_ac_get_state(ac); | 292 | result = acpi_ac_get_state(ac); |
317 | if (result) | 293 | if (result) |
318 | goto end; | 294 | goto end; |
319 | 295 | ||
320 | #ifdef CONFIG_ACPI_PROCFS_POWER | 296 | #ifdef CONFIG_ACPI_PROCFS_POWER |
321 | result = acpi_ac_add_fs(device); | 297 | result = acpi_ac_add_fs(ac); |
322 | #endif | ||
323 | if (result) | 298 | if (result) |
324 | goto end; | 299 | goto end; |
325 | ac->charger.name = acpi_device_bid(device); | 300 | #endif |
301 | ac->charger.name = acpi_device_bid(adev); | ||
326 | ac->charger.type = POWER_SUPPLY_TYPE_MAINS; | 302 | ac->charger.type = POWER_SUPPLY_TYPE_MAINS; |
327 | ac->charger.properties = ac_props; | 303 | ac->charger.properties = ac_props; |
328 | ac->charger.num_properties = ARRAY_SIZE(ac_props); | 304 | ac->charger.num_properties = ARRAY_SIZE(ac_props); |
329 | ac->charger.get_property = get_ac_property; | 305 | ac->charger.get_property = get_ac_property; |
330 | result = power_supply_register(&ac->device->dev, &ac->charger); | 306 | result = power_supply_register(&pdev->dev, &ac->charger); |
331 | if (result) | 307 | if (result) |
332 | goto end; | 308 | goto end; |
333 | 309 | ||
310 | result = acpi_install_notify_handler(ACPI_HANDLE(&pdev->dev), | ||
311 | ACPI_DEVICE_NOTIFY, acpi_ac_notify_handler, ac); | ||
312 | if (result) { | ||
313 | power_supply_unregister(&ac->charger); | ||
314 | goto end; | ||
315 | } | ||
334 | printk(KERN_INFO PREFIX "%s [%s] (%s)\n", | 316 | printk(KERN_INFO PREFIX "%s [%s] (%s)\n", |
335 | acpi_device_name(device), acpi_device_bid(device), | 317 | acpi_device_name(adev), acpi_device_bid(adev), |
336 | ac->state ? "on-line" : "off-line"); | 318 | ac->state ? "on-line" : "off-line"); |
337 | 319 | ||
338 | end: | 320 | end: |
339 | if (result) { | 321 | if (result) { |
340 | #ifdef CONFIG_ACPI_PROCFS_POWER | 322 | #ifdef CONFIG_ACPI_PROCFS_POWER |
341 | acpi_ac_remove_fs(device); | 323 | acpi_ac_remove_fs(ac); |
342 | #endif | 324 | #endif |
343 | kfree(ac); | 325 | kfree(ac); |
344 | } | 326 | } |
@@ -356,7 +338,7 @@ static int acpi_ac_resume(struct device *dev) | |||
356 | if (!dev) | 338 | if (!dev) |
357 | return -EINVAL; | 339 | return -EINVAL; |
358 | 340 | ||
359 | ac = acpi_driver_data(to_acpi_device(dev)); | 341 | ac = platform_get_drvdata(to_platform_device(dev)); |
360 | if (!ac) | 342 | if (!ac) |
361 | return -EINVAL; | 343 | return -EINVAL; |
362 | 344 | ||
@@ -368,21 +350,24 @@ static int acpi_ac_resume(struct device *dev) | |||
368 | return 0; | 350 | return 0; |
369 | } | 351 | } |
370 | #endif | 352 | #endif |
353 | static SIMPLE_DEV_PM_OPS(acpi_ac_pm_ops, NULL, acpi_ac_resume); | ||
371 | 354 | ||
372 | static int acpi_ac_remove(struct acpi_device *device) | 355 | static int acpi_ac_remove(struct platform_device *pdev) |
373 | { | 356 | { |
374 | struct acpi_ac *ac = NULL; | 357 | struct acpi_ac *ac; |
375 | |||
376 | 358 | ||
377 | if (!device || !acpi_driver_data(device)) | 359 | if (!pdev) |
378 | return -EINVAL; | 360 | return -EINVAL; |
379 | 361 | ||
380 | ac = acpi_driver_data(device); | 362 | acpi_remove_notify_handler(ACPI_HANDLE(&pdev->dev), |
363 | ACPI_DEVICE_NOTIFY, acpi_ac_notify_handler); | ||
381 | 364 | ||
365 | ac = platform_get_drvdata(pdev); | ||
382 | if (ac->charger.dev) | 366 | if (ac->charger.dev) |
383 | power_supply_unregister(&ac->charger); | 367 | power_supply_unregister(&ac->charger); |
368 | |||
384 | #ifdef CONFIG_ACPI_PROCFS_POWER | 369 | #ifdef CONFIG_ACPI_PROCFS_POWER |
385 | acpi_ac_remove_fs(device); | 370 | acpi_ac_remove_fs(ac); |
386 | #endif | 371 | #endif |
387 | 372 | ||
388 | kfree(ac); | 373 | kfree(ac); |
@@ -390,6 +375,23 @@ static int acpi_ac_remove(struct acpi_device *device) | |||
390 | return 0; | 375 | return 0; |
391 | } | 376 | } |
392 | 377 | ||
378 | static const struct acpi_device_id acpi_ac_match[] = { | ||
379 | { "ACPI0003", 0 }, | ||
380 | { } | ||
381 | }; | ||
382 | MODULE_DEVICE_TABLE(acpi, acpi_ac_match); | ||
383 | |||
384 | static struct platform_driver acpi_ac_driver = { | ||
385 | .probe = acpi_ac_probe, | ||
386 | .remove = acpi_ac_remove, | ||
387 | .driver = { | ||
388 | .name = "acpi-ac", | ||
389 | .owner = THIS_MODULE, | ||
390 | .pm = &acpi_ac_pm_ops, | ||
391 | .acpi_match_table = ACPI_PTR(acpi_ac_match), | ||
392 | }, | ||
393 | }; | ||
394 | |||
393 | static int __init acpi_ac_init(void) | 395 | static int __init acpi_ac_init(void) |
394 | { | 396 | { |
395 | int result; | 397 | int result; |
@@ -403,7 +405,7 @@ static int __init acpi_ac_init(void) | |||
403 | return -ENODEV; | 405 | return -ENODEV; |
404 | #endif | 406 | #endif |
405 | 407 | ||
406 | result = acpi_bus_register_driver(&acpi_ac_driver); | 408 | result = platform_driver_register(&acpi_ac_driver); |
407 | if (result < 0) { | 409 | if (result < 0) { |
408 | #ifdef CONFIG_ACPI_PROCFS_POWER | 410 | #ifdef CONFIG_ACPI_PROCFS_POWER |
409 | acpi_unlock_ac_dir(acpi_ac_dir); | 411 | acpi_unlock_ac_dir(acpi_ac_dir); |
@@ -416,15 +418,10 @@ static int __init acpi_ac_init(void) | |||
416 | 418 | ||
417 | static void __exit acpi_ac_exit(void) | 419 | static void __exit acpi_ac_exit(void) |
418 | { | 420 | { |
419 | 421 | platform_driver_unregister(&acpi_ac_driver); | |
420 | acpi_bus_unregister_driver(&acpi_ac_driver); | ||
421 | |||
422 | #ifdef CONFIG_ACPI_PROCFS_POWER | 422 | #ifdef CONFIG_ACPI_PROCFS_POWER |
423 | acpi_unlock_ac_dir(acpi_ac_dir); | 423 | acpi_unlock_ac_dir(acpi_ac_dir); |
424 | #endif | 424 | #endif |
425 | |||
426 | return; | ||
427 | } | 425 | } |
428 | |||
429 | module_init(acpi_ac_init); | 426 | module_init(acpi_ac_init); |
430 | module_exit(acpi_ac_exit); | 427 | module_exit(acpi_ac_exit); |
diff --git a/drivers/acpi/acpi_platform.c b/drivers/acpi/acpi_platform.c index 1bde12708f9e..6259bc28ef18 100644 --- a/drivers/acpi/acpi_platform.c +++ b/drivers/acpi/acpi_platform.c | |||
@@ -29,6 +29,7 @@ ACPI_MODULE_NAME("platform"); | |||
29 | static const struct acpi_device_id acpi_platform_device_ids[] = { | 29 | static const struct acpi_device_id acpi_platform_device_ids[] = { |
30 | 30 | ||
31 | { "PNP0D40" }, | 31 | { "PNP0D40" }, |
32 | { "ACPI0003" }, | ||
32 | 33 | ||
33 | { } | 34 | { } |
34 | }; | 35 | }; |