diff options
author | Alexey Starikovskiy <astarikovskiy@suse.de> | 2007-09-26 11:44:06 -0400 |
---|---|---|
committer | Len Brown <len.brown@intel.com> | 2007-09-27 15:50:23 -0400 |
commit | d5b4a3d0efa36de31b86d5677dad6c36cb8735d7 (patch) | |
tree | fc7029b7c7fbab943b1e226b955d974710948126 | |
parent | 8bd955320661cfd03ab8d5574d96aa684acd38f6 (diff) |
ACPI: AC: Add sysfs interface
Refer to Documentation/power_supply_class.txt for interface description.
Signed-off-by: Alexey Starikovskiy <astarikovskiy@suse.de>
Signed-off-by: Len Brown <len.brown@intel.com>
-rw-r--r-- | drivers/acpi/Kconfig | 2 | ||||
-rw-r--r-- | drivers/acpi/ac.c | 33 |
2 files changed, 32 insertions, 3 deletions
diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig index ba6a61f7aae7..a858bc528ec3 100644 --- a/drivers/acpi/Kconfig +++ b/drivers/acpi/Kconfig | |||
@@ -88,7 +88,7 @@ config ACPI_PROC_EVENT | |||
88 | 88 | ||
89 | config ACPI_AC | 89 | config ACPI_AC |
90 | tristate "AC Adapter" | 90 | tristate "AC Adapter" |
91 | depends on X86 | 91 | depends on X86 && POWER_SUPPLY |
92 | default y | 92 | default y |
93 | help | 93 | help |
94 | This driver adds support for the AC Adapter object, which indicates | 94 | This driver adds support for the AC Adapter object, which indicates |
diff --git a/drivers/acpi/ac.c b/drivers/acpi/ac.c index 26d70702b313..e03de37a750d 100644 --- a/drivers/acpi/ac.c +++ b/drivers/acpi/ac.c | |||
@@ -29,6 +29,7 @@ | |||
29 | #include <linux/types.h> | 29 | #include <linux/types.h> |
30 | #include <linux/proc_fs.h> | 30 | #include <linux/proc_fs.h> |
31 | #include <linux/seq_file.h> | 31 | #include <linux/seq_file.h> |
32 | #include <linux/power_supply.h> | ||
32 | #include <acpi/acpi_bus.h> | 33 | #include <acpi/acpi_bus.h> |
33 | #include <acpi/acpi_drivers.h> | 34 | #include <acpi/acpi_drivers.h> |
34 | 35 | ||
@@ -72,16 +73,37 @@ static struct acpi_driver acpi_ac_driver = { | |||
72 | }; | 73 | }; |
73 | 74 | ||
74 | struct acpi_ac { | 75 | struct acpi_ac { |
76 | struct power_supply charger; | ||
75 | struct acpi_device * device; | 77 | struct acpi_device * device; |
76 | unsigned long state; | 78 | unsigned long state; |
77 | }; | 79 | }; |
78 | 80 | ||
81 | #define to_acpi_ac(x) container_of(x, struct acpi_ac, charger); | ||
82 | |||
79 | static const struct file_operations acpi_ac_fops = { | 83 | static const struct file_operations acpi_ac_fops = { |
80 | .open = acpi_ac_open_fs, | 84 | .open = acpi_ac_open_fs, |
81 | .read = seq_read, | 85 | .read = seq_read, |
82 | .llseek = seq_lseek, | 86 | .llseek = seq_lseek, |
83 | .release = single_release, | 87 | .release = single_release, |
84 | }; | 88 | }; |
89 | static int get_ac_property(struct power_supply *psy, | ||
90 | enum power_supply_property psp, | ||
91 | union power_supply_propval *val) | ||
92 | { | ||
93 | struct acpi_ac *ac = to_acpi_ac(psy); | ||
94 | switch (psp) { | ||
95 | case POWER_SUPPLY_PROP_ONLINE: | ||
96 | val->intval = ac->state; | ||
97 | break; | ||
98 | default: | ||
99 | return -EINVAL; | ||
100 | } | ||
101 | return 0; | ||
102 | } | ||
103 | |||
104 | static enum power_supply_property ac_props[] = { | ||
105 | POWER_SUPPLY_PROP_ONLINE, | ||
106 | }; | ||
85 | 107 | ||
86 | /* -------------------------------------------------------------------------- | 108 | /* -------------------------------------------------------------------------- |
87 | AC Adapter Management | 109 | AC Adapter Management |
@@ -208,6 +230,7 @@ static void acpi_ac_notify(acpi_handle handle, u32 event, void *data) | |||
208 | acpi_bus_generate_netlink_event(device->pnp.device_class, | 230 | acpi_bus_generate_netlink_event(device->pnp.device_class, |
209 | device->dev.bus_id, event, | 231 | device->dev.bus_id, event, |
210 | (u32) ac->state); | 232 | (u32) ac->state); |
233 | kobject_uevent(&ac->charger.dev->kobj, KOBJ_CHANGE); | ||
211 | break; | 234 | break; |
212 | default: | 235 | default: |
213 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 236 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
@@ -244,7 +267,12 @@ static int acpi_ac_add(struct acpi_device *device) | |||
244 | result = acpi_ac_add_fs(device); | 267 | result = acpi_ac_add_fs(device); |
245 | if (result) | 268 | if (result) |
246 | goto end; | 269 | goto end; |
247 | 270 | ac->charger.name = acpi_device_bid(device); | |
271 | ac->charger.type = POWER_SUPPLY_TYPE_MAINS; | ||
272 | ac->charger.properties = ac_props; | ||
273 | ac->charger.num_properties = ARRAY_SIZE(ac_props); | ||
274 | ac->charger.get_property = get_ac_property; | ||
275 | power_supply_register(&ac->device->dev, &ac->charger); | ||
248 | status = acpi_install_notify_handler(device->handle, | 276 | status = acpi_install_notify_handler(device->handle, |
249 | ACPI_ALL_NOTIFY, acpi_ac_notify, | 277 | ACPI_ALL_NOTIFY, acpi_ac_notify, |
250 | ac); | 278 | ac); |
@@ -279,7 +307,8 @@ static int acpi_ac_remove(struct acpi_device *device, int type) | |||
279 | 307 | ||
280 | status = acpi_remove_notify_handler(device->handle, | 308 | status = acpi_remove_notify_handler(device->handle, |
281 | ACPI_ALL_NOTIFY, acpi_ac_notify); | 309 | ACPI_ALL_NOTIFY, acpi_ac_notify); |
282 | 310 | if (ac->charger.dev) | |
311 | power_supply_unregister(&ac->charger); | ||
283 | acpi_ac_remove_fs(device); | 312 | acpi_ac_remove_fs(device); |
284 | 313 | ||
285 | kfree(ac); | 314 | kfree(ac); |