26 #include <linux/kernel.h>
27 #include <linux/module.h>
28 #include <linux/slab.h>
30 #include <linux/types.h>
31 #ifdef CONFIG_ACPI_PROCFS_POWER
39 #define PREFIX "ACPI: "
41 #define ACPI_AC_CLASS "ac_adapter"
42 #define ACPI_AC_DEVICE_NAME "AC Adapter"
43 #define ACPI_AC_FILE_STATE "state"
44 #define ACPI_AC_NOTIFY_STATUS 0x80
45 #define ACPI_AC_STATUS_OFFLINE 0x00
46 #define ACPI_AC_STATUS_ONLINE 0x01
47 #define ACPI_AC_STATUS_UNKNOWN 0xFF
49 #define _COMPONENT ACPI_AC_COMPONENT
56 #ifdef CONFIG_ACPI_PROCFS_POWER
62 static int acpi_ac_add(
struct acpi_device *
device);
63 static int acpi_ac_remove(
struct acpi_device *
device,
int type);
72 #ifdef CONFIG_PM_SLEEP
73 static int acpi_ac_resume(
struct device *
dev);
77 static struct acpi_driver acpi_ac_driver = {
81 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
84 .remove = acpi_ac_remove,
85 .notify = acpi_ac_notify,
87 .drv.pm = &acpi_ac_pm,
96 #define to_acpi_ac(x) container_of(x, struct acpi_ac, charger)
98 #ifdef CONFIG_ACPI_PROCFS_POWER
101 .open = acpi_ac_open_fs,
112 static int acpi_ac_get_state(
struct acpi_ac *
ac)
142 if (acpi_ac_get_state(ac))
159 #ifdef CONFIG_ACPI_PROCFS_POWER
174 if (acpi_ac_get_state(ac)) {
175 seq_puts(seq,
"ERROR: Unable to read AC Adapter state\n");
200 static int acpi_ac_add_fs(
struct acpi_device *
device)
205 " please retry with CONFIG_ACPI_PROCFS_POWER cleared\n");
206 if (!acpi_device_dir(device)) {
207 acpi_device_dir(device) =
proc_mkdir(acpi_device_bid(device),
209 if (!acpi_device_dir(device))
215 S_IRUGO, acpi_device_dir(device),
216 &acpi_ac_fops, acpi_driver_data(device));
222 static int acpi_ac_remove_fs(
struct acpi_device *device)
225 if (acpi_device_dir(device)) {
229 acpi_device_dir(device) =
NULL;
240 static void acpi_ac_notify(
struct acpi_device *device,
u32 event)
242 struct acpi_ac *ac = acpi_driver_data(device);
251 "Unsupported event [0x%x]\n", event));
255 acpi_ac_get_state(ac);
256 acpi_bus_generate_proc_event(device, event, (
u32) ac->
state);
258 dev_name(&device->dev), event,
267 static int acpi_ac_add(
struct acpi_device *device)
283 device->driver_data =
ac;
285 result = acpi_ac_get_state(ac);
289 #ifdef CONFIG_ACPI_PROCFS_POWER
290 result = acpi_ac_add_fs(device);
294 ac->
charger.name = acpi_device_bid(device);
296 ac->
charger.properties = ac_props;
298 ac->
charger.get_property = get_ac_property;
304 acpi_device_name(device), acpi_device_bid(device),
305 ac->
state ?
"on-line" :
"off-line");
309 #ifdef CONFIG_ACPI_PROCFS_POWER
310 acpi_ac_remove_fs(device);
318 #ifdef CONFIG_PM_SLEEP
319 static int acpi_ac_resume(
struct device *
dev)
327 ac = acpi_driver_data(to_acpi_device(dev));
331 old_state = ac->
state;
332 if (acpi_ac_get_state(ac))
334 if (old_state != ac->
state)
340 static int acpi_ac_remove(
struct acpi_device *device,
int type)
345 if (!device || !acpi_driver_data(device))
348 ac = acpi_driver_data(device);
352 #ifdef CONFIG_ACPI_PROCFS_POWER
353 acpi_ac_remove_fs(device);
361 static int __init acpi_ac_init(
void)
368 #ifdef CONFIG_ACPI_PROCFS_POWER
376 #ifdef CONFIG_ACPI_PROCFS_POWER
385 static void __exit acpi_ac_exit(
void)
390 #ifdef CONFIG_ACPI_PROCFS_POWER