diff options
Diffstat (limited to 'drivers/acpi')
-rw-r--r-- | drivers/acpi/Kconfig | 18 | ||||
-rw-r--r-- | drivers/acpi/Makefile | 1 | ||||
-rw-r--r-- | drivers/acpi/ac.c | 73 | ||||
-rw-r--r-- | drivers/acpi/battery.c | 1060 | ||||
-rw-r--r-- | drivers/acpi/bus.c | 37 | ||||
-rw-r--r-- | drivers/acpi/button.c | 43 | ||||
-rw-r--r-- | drivers/acpi/ec.c | 260 | ||||
-rw-r--r-- | drivers/acpi/events/evevent.c | 6 | ||||
-rw-r--r-- | drivers/acpi/fan.c | 72 | ||||
-rw-r--r-- | drivers/acpi/hardware/hwregs.c | 89 | ||||
-rw-r--r-- | drivers/acpi/hardware/hwsleep.c | 40 | ||||
-rw-r--r-- | drivers/acpi/osl.c | 2 | ||||
-rw-r--r-- | drivers/acpi/power.c | 63 | ||||
-rw-r--r-- | drivers/acpi/processor_core.c | 8 | ||||
-rw-r--r-- | drivers/acpi/processor_idle.c | 14 | ||||
-rw-r--r-- | drivers/acpi/sbs.c | 1870 | ||||
-rw-r--r-- | drivers/acpi/sbshc.c | 309 | ||||
-rw-r--r-- | drivers/acpi/sbshc.h | 27 | ||||
-rw-r--r-- | drivers/acpi/scan.c | 16 | ||||
-rw-r--r-- | drivers/acpi/sleep/main.c | 50 | ||||
-rw-r--r-- | drivers/acpi/sleep/proc.c | 66 | ||||
-rw-r--r-- | drivers/acpi/sleep/sleep.h | 1 | ||||
-rw-r--r-- | drivers/acpi/sleep/wakeup.c | 117 | ||||
-rw-r--r-- | drivers/acpi/tables/tbutils.c | 2 | ||||
-rw-r--r-- | drivers/acpi/thermal.c | 36 | ||||
-rw-r--r-- | drivers/acpi/toshiba_acpi.c | 5 | ||||
-rw-r--r-- | drivers/acpi/video.c | 34 |
27 files changed, 1857 insertions, 2462 deletions
diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig index 4875f0149eb4..087a7028ae84 100644 --- a/drivers/acpi/Kconfig +++ b/drivers/acpi/Kconfig | |||
@@ -3,7 +3,7 @@ | |||
3 | # | 3 | # |
4 | 4 | ||
5 | menuconfig ACPI | 5 | menuconfig ACPI |
6 | bool "ACPI Support (Advanced Configuration and Power Interface) Support" | 6 | bool "ACPI (Advanced Configuration and Power Interface) Support" |
7 | depends on !X86_NUMAQ | 7 | depends on !X86_NUMAQ |
8 | depends on !X86_VISWS | 8 | depends on !X86_VISWS |
9 | depends on !IA64_HP_SIM | 9 | depends on !IA64_HP_SIM |
@@ -50,9 +50,10 @@ config ACPI_SLEEP | |||
50 | config ACPI_PROCFS | 50 | config ACPI_PROCFS |
51 | bool "Deprecated /proc/acpi files" | 51 | bool "Deprecated /proc/acpi files" |
52 | depends on PROC_FS | 52 | depends on PROC_FS |
53 | default y | ||
53 | ---help--- | 54 | ---help--- |
54 | For backwards compatibility, this option allows | 55 | For backwards compatibility, this option allows |
55 | depricated /proc/acpi/ files to exist, even when | 56 | deprecated /proc/acpi/ files to exist, even when |
56 | they have been replaced by functions in /sys. | 57 | they have been replaced by functions in /sys. |
57 | The deprecated files (and their replacements) include: | 58 | The deprecated files (and their replacements) include: |
58 | 59 | ||
@@ -60,6 +61,7 @@ config ACPI_PROCFS | |||
60 | /proc/acpi/info (/sys/modules/acpi/parameters/acpica_version) | 61 | /proc/acpi/info (/sys/modules/acpi/parameters/acpica_version) |
61 | /proc/acpi/dsdt (/sys/firmware/acpi/tables/DSDT) | 62 | /proc/acpi/dsdt (/sys/firmware/acpi/tables/DSDT) |
62 | /proc/acpi/fadt (/sys/firmware/acpi/tables/FACP) | 63 | /proc/acpi/fadt (/sys/firmware/acpi/tables/FACP) |
64 | /proc/acpi/battery (/sys/class/power_supply) | ||
63 | /proc/acpi/debug_layer (/sys/module/acpi/parameters/debug_layer) | 65 | /proc/acpi/debug_layer (/sys/module/acpi/parameters/debug_layer) |
64 | /proc/acpi/debug_level (/sys/module/acpi/parameters/debug_level) | 66 | /proc/acpi/debug_level (/sys/module/acpi/parameters/debug_level) |
65 | 67 | ||
@@ -89,6 +91,7 @@ config ACPI_PROC_EVENT | |||
89 | config ACPI_AC | 91 | config ACPI_AC |
90 | tristate "AC Adapter" | 92 | tristate "AC Adapter" |
91 | depends on X86 | 93 | depends on X86 |
94 | select POWER_SUPPLY | ||
92 | default y | 95 | default y |
93 | help | 96 | help |
94 | This driver adds support for the AC Adapter object, which indicates | 97 | This driver adds support for the AC Adapter object, which indicates |
@@ -98,6 +101,7 @@ config ACPI_AC | |||
98 | config ACPI_BATTERY | 101 | config ACPI_BATTERY |
99 | tristate "Battery" | 102 | tristate "Battery" |
100 | depends on X86 | 103 | depends on X86 |
104 | select POWER_SUPPLY | ||
101 | default y | 105 | default y |
102 | help | 106 | help |
103 | This driver adds support for battery information through | 107 | This driver adds support for battery information through |
@@ -117,6 +121,7 @@ config ACPI_BUTTON | |||
117 | config ACPI_VIDEO | 121 | config ACPI_VIDEO |
118 | tristate "Video" | 122 | tristate "Video" |
119 | depends on X86 && BACKLIGHT_CLASS_DEVICE && VIDEO_OUTPUT_CONTROL | 123 | depends on X86 && BACKLIGHT_CLASS_DEVICE && VIDEO_OUTPUT_CONTROL |
124 | depends on INPUT | ||
120 | help | 125 | help |
121 | This driver implement the ACPI Extensions For Display Adapters | 126 | This driver implement the ACPI Extensions For Display Adapters |
122 | for integrated graphics devices on motherboard, as specified in | 127 | for integrated graphics devices on motherboard, as specified in |
@@ -349,12 +354,11 @@ config ACPI_HOTPLUG_MEMORY | |||
349 | $>modprobe acpi_memhotplug | 354 | $>modprobe acpi_memhotplug |
350 | 355 | ||
351 | config ACPI_SBS | 356 | config ACPI_SBS |
352 | tristate "Smart Battery System (EXPERIMENTAL)" | 357 | tristate "Smart Battery System" |
353 | depends on X86 | 358 | depends on X86 |
354 | depends on EXPERIMENTAL | 359 | select POWER_SUPPLY |
355 | help | 360 | help |
356 | This driver adds support for the Smart Battery System. | 361 | This driver adds support for the Smart Battery System, another |
357 | A "Smart Battery" is quite old and quite rare compared | 362 | type of access to battery information, found on some laptops. |
358 | to today's ACPI "Control Method" battery. | ||
359 | 363 | ||
360 | endif # ACPI | 364 | endif # ACPI |
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile index d4336f1730e9..54e3ab0e5fc0 100644 --- a/drivers/acpi/Makefile +++ b/drivers/acpi/Makefile | |||
@@ -60,3 +60,4 @@ obj-$(CONFIG_ACPI_TOSHIBA) += toshiba_acpi.o | |||
60 | obj-$(CONFIG_ACPI_HOTPLUG_MEMORY) += acpi_memhotplug.o | 60 | obj-$(CONFIG_ACPI_HOTPLUG_MEMORY) += acpi_memhotplug.o |
61 | obj-y += cm_sbs.o | 61 | obj-y += cm_sbs.o |
62 | obj-$(CONFIG_ACPI_SBS) += sbs.o | 62 | obj-$(CONFIG_ACPI_SBS) += sbs.o |
63 | obj-$(CONFIG_ACPI_SBS) += sbshc.o | ||
diff --git a/drivers/acpi/ac.c b/drivers/acpi/ac.c index 26d70702b313..30238f6ff232 100644 --- a/drivers/acpi/ac.c +++ b/drivers/acpi/ac.c | |||
@@ -27,8 +27,11 @@ | |||
27 | #include <linux/module.h> | 27 | #include <linux/module.h> |
28 | #include <linux/init.h> | 28 | #include <linux/init.h> |
29 | #include <linux/types.h> | 29 | #include <linux/types.h> |
30 | #ifdef CONFIG_ACPI_PROCFS | ||
30 | #include <linux/proc_fs.h> | 31 | #include <linux/proc_fs.h> |
31 | #include <linux/seq_file.h> | 32 | #include <linux/seq_file.h> |
33 | #endif | ||
34 | #include <linux/power_supply.h> | ||
32 | #include <acpi/acpi_bus.h> | 35 | #include <acpi/acpi_bus.h> |
33 | #include <acpi/acpi_drivers.h> | 36 | #include <acpi/acpi_drivers.h> |
34 | 37 | ||
@@ -48,12 +51,15 @@ MODULE_AUTHOR("Paul Diefenbaugh"); | |||
48 | MODULE_DESCRIPTION("ACPI AC Adapter Driver"); | 51 | MODULE_DESCRIPTION("ACPI AC Adapter Driver"); |
49 | MODULE_LICENSE("GPL"); | 52 | MODULE_LICENSE("GPL"); |
50 | 53 | ||
54 | #ifdef CONFIG_ACPI_PROCFS | ||
51 | extern struct proc_dir_entry *acpi_lock_ac_dir(void); | 55 | extern struct proc_dir_entry *acpi_lock_ac_dir(void); |
52 | extern void *acpi_unlock_ac_dir(struct proc_dir_entry *acpi_ac_dir); | 56 | extern void *acpi_unlock_ac_dir(struct proc_dir_entry *acpi_ac_dir); |
57 | static int acpi_ac_open_fs(struct inode *inode, struct file *file); | ||
58 | #endif | ||
53 | 59 | ||
54 | static int acpi_ac_add(struct acpi_device *device); | 60 | static int acpi_ac_add(struct acpi_device *device); |
55 | static int acpi_ac_remove(struct acpi_device *device, int type); | 61 | static int acpi_ac_remove(struct acpi_device *device, int type); |
56 | static int acpi_ac_open_fs(struct inode *inode, struct file *file); | 62 | static int acpi_ac_resume(struct acpi_device *device); |
57 | 63 | ||
58 | const static struct acpi_device_id ac_device_ids[] = { | 64 | const static struct acpi_device_id ac_device_ids[] = { |
59 | {"ACPI0003", 0}, | 65 | {"ACPI0003", 0}, |
@@ -68,20 +74,45 @@ static struct acpi_driver acpi_ac_driver = { | |||
68 | .ops = { | 74 | .ops = { |
69 | .add = acpi_ac_add, | 75 | .add = acpi_ac_add, |
70 | .remove = acpi_ac_remove, | 76 | .remove = acpi_ac_remove, |
77 | .resume = acpi_ac_resume, | ||
71 | }, | 78 | }, |
72 | }; | 79 | }; |
73 | 80 | ||
74 | struct acpi_ac { | 81 | struct acpi_ac { |
82 | struct power_supply charger; | ||
75 | struct acpi_device * device; | 83 | struct acpi_device * device; |
76 | unsigned long state; | 84 | unsigned long state; |
77 | }; | 85 | }; |
78 | 86 | ||
87 | #define to_acpi_ac(x) container_of(x, struct acpi_ac, charger); | ||
88 | |||
89 | #ifdef CONFIG_ACPI_PROCFS | ||
79 | static const struct file_operations acpi_ac_fops = { | 90 | static const struct file_operations acpi_ac_fops = { |
80 | .open = acpi_ac_open_fs, | 91 | .open = acpi_ac_open_fs, |
81 | .read = seq_read, | 92 | .read = seq_read, |
82 | .llseek = seq_lseek, | 93 | .llseek = seq_lseek, |
83 | .release = single_release, | 94 | .release = single_release, |
84 | }; | 95 | }; |
96 | #endif | ||
97 | |||
98 | static int get_ac_property(struct power_supply *psy, | ||
99 | enum power_supply_property psp, | ||
100 | union power_supply_propval *val) | ||
101 | { | ||
102 | struct acpi_ac *ac = to_acpi_ac(psy); | ||
103 | switch (psp) { | ||
104 | case POWER_SUPPLY_PROP_ONLINE: | ||
105 | val->intval = ac->state; | ||
106 | break; | ||
107 | default: | ||
108 | return -EINVAL; | ||
109 | } | ||
110 | return 0; | ||
111 | } | ||
112 | |||
113 | static enum power_supply_property ac_props[] = { | ||
114 | POWER_SUPPLY_PROP_ONLINE, | ||
115 | }; | ||
85 | 116 | ||
86 | /* -------------------------------------------------------------------------- | 117 | /* -------------------------------------------------------------------------- |
87 | AC Adapter Management | 118 | AC Adapter Management |
@@ -105,6 +136,7 @@ static int acpi_ac_get_state(struct acpi_ac *ac) | |||
105 | return 0; | 136 | return 0; |
106 | } | 137 | } |
107 | 138 | ||
139 | #ifdef CONFIG_ACPI_PROCFS | ||
108 | /* -------------------------------------------------------------------------- | 140 | /* -------------------------------------------------------------------------- |
109 | FS Interface (/proc) | 141 | FS Interface (/proc) |
110 | -------------------------------------------------------------------------- */ | 142 | -------------------------------------------------------------------------- */ |
@@ -184,6 +216,7 @@ static int acpi_ac_remove_fs(struct acpi_device *device) | |||
184 | 216 | ||
185 | return 0; | 217 | return 0; |
186 | } | 218 | } |
219 | #endif | ||
187 | 220 | ||
188 | /* -------------------------------------------------------------------------- | 221 | /* -------------------------------------------------------------------------- |
189 | Driver Model | 222 | Driver Model |
@@ -208,6 +241,7 @@ static void acpi_ac_notify(acpi_handle handle, u32 event, void *data) | |||
208 | acpi_bus_generate_netlink_event(device->pnp.device_class, | 241 | acpi_bus_generate_netlink_event(device->pnp.device_class, |
209 | device->dev.bus_id, event, | 242 | device->dev.bus_id, event, |
210 | (u32) ac->state); | 243 | (u32) ac->state); |
244 | kobject_uevent(&ac->charger.dev->kobj, KOBJ_CHANGE); | ||
211 | break; | 245 | break; |
212 | default: | 246 | default: |
213 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 247 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
@@ -241,10 +275,17 @@ static int acpi_ac_add(struct acpi_device *device) | |||
241 | if (result) | 275 | if (result) |
242 | goto end; | 276 | goto end; |
243 | 277 | ||
278 | #ifdef CONFIG_ACPI_PROCFS | ||
244 | result = acpi_ac_add_fs(device); | 279 | result = acpi_ac_add_fs(device); |
280 | #endif | ||
245 | if (result) | 281 | if (result) |
246 | goto end; | 282 | goto end; |
247 | 283 | ac->charger.name = acpi_device_bid(device); | |
284 | ac->charger.type = POWER_SUPPLY_TYPE_MAINS; | ||
285 | ac->charger.properties = ac_props; | ||
286 | ac->charger.num_properties = ARRAY_SIZE(ac_props); | ||
287 | ac->charger.get_property = get_ac_property; | ||
288 | power_supply_register(&ac->device->dev, &ac->charger); | ||
248 | status = acpi_install_notify_handler(device->handle, | 289 | status = acpi_install_notify_handler(device->handle, |
249 | ACPI_ALL_NOTIFY, acpi_ac_notify, | 290 | ACPI_ALL_NOTIFY, acpi_ac_notify, |
250 | ac); | 291 | ac); |
@@ -259,13 +300,30 @@ static int acpi_ac_add(struct acpi_device *device) | |||
259 | 300 | ||
260 | end: | 301 | end: |
261 | if (result) { | 302 | if (result) { |
303 | #ifdef CONFIG_ACPI_PROCFS | ||
262 | acpi_ac_remove_fs(device); | 304 | acpi_ac_remove_fs(device); |
305 | #endif | ||
263 | kfree(ac); | 306 | kfree(ac); |
264 | } | 307 | } |
265 | 308 | ||
266 | return result; | 309 | return result; |
267 | } | 310 | } |
268 | 311 | ||
312 | static int acpi_ac_resume(struct acpi_device *device) | ||
313 | { | ||
314 | struct acpi_ac *ac; | ||
315 | unsigned old_state; | ||
316 | if (!device || !acpi_driver_data(device)) | ||
317 | return -EINVAL; | ||
318 | ac = acpi_driver_data(device); | ||
319 | old_state = ac->state; | ||
320 | if (acpi_ac_get_state(ac)) | ||
321 | return 0; | ||
322 | if (old_state != ac->state) | ||
323 | kobject_uevent(&ac->charger.dev->kobj, KOBJ_CHANGE); | ||
324 | return 0; | ||
325 | } | ||
326 | |||
269 | static int acpi_ac_remove(struct acpi_device *device, int type) | 327 | static int acpi_ac_remove(struct acpi_device *device, int type) |
270 | { | 328 | { |
271 | acpi_status status = AE_OK; | 329 | acpi_status status = AE_OK; |
@@ -279,8 +337,11 @@ static int acpi_ac_remove(struct acpi_device *device, int type) | |||
279 | 337 | ||
280 | status = acpi_remove_notify_handler(device->handle, | 338 | status = acpi_remove_notify_handler(device->handle, |
281 | ACPI_ALL_NOTIFY, acpi_ac_notify); | 339 | ACPI_ALL_NOTIFY, acpi_ac_notify); |
282 | 340 | if (ac->charger.dev) | |
341 | power_supply_unregister(&ac->charger); | ||
342 | #ifdef CONFIG_ACPI_PROCFS | ||
283 | acpi_ac_remove_fs(device); | 343 | acpi_ac_remove_fs(device); |
344 | #endif | ||
284 | 345 | ||
285 | kfree(ac); | 346 | kfree(ac); |
286 | 347 | ||
@@ -294,13 +355,17 @@ static int __init acpi_ac_init(void) | |||
294 | if (acpi_disabled) | 355 | if (acpi_disabled) |
295 | return -ENODEV; | 356 | return -ENODEV; |
296 | 357 | ||
358 | #ifdef CONFIG_ACPI_PROCFS | ||
297 | acpi_ac_dir = acpi_lock_ac_dir(); | 359 | acpi_ac_dir = acpi_lock_ac_dir(); |
298 | if (!acpi_ac_dir) | 360 | if (!acpi_ac_dir) |
299 | return -ENODEV; | 361 | return -ENODEV; |
362 | #endif | ||
300 | 363 | ||
301 | result = acpi_bus_register_driver(&acpi_ac_driver); | 364 | result = acpi_bus_register_driver(&acpi_ac_driver); |
302 | if (result < 0) { | 365 | if (result < 0) { |
366 | #ifdef CONFIG_ACPI_PROCFS | ||
303 | acpi_unlock_ac_dir(acpi_ac_dir); | 367 | acpi_unlock_ac_dir(acpi_ac_dir); |
368 | #endif | ||
304 | return -ENODEV; | 369 | return -ENODEV; |
305 | } | 370 | } |
306 | 371 | ||
@@ -312,7 +377,9 @@ static void __exit acpi_ac_exit(void) | |||
312 | 377 | ||
313 | acpi_bus_unregister_driver(&acpi_ac_driver); | 378 | acpi_bus_unregister_driver(&acpi_ac_driver); |
314 | 379 | ||
380 | #ifdef CONFIG_ACPI_PROCFS | ||
315 | acpi_unlock_ac_dir(acpi_ac_dir); | 381 | acpi_unlock_ac_dir(acpi_ac_dir); |
382 | #endif | ||
316 | 383 | ||
317 | return; | 384 | return; |
318 | } | 385 | } |
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index 9b2c0f74f869..2e8e790c1180 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c | |||
@@ -1,6 +1,8 @@ | |||
1 | /* | 1 | /* |
2 | * acpi_battery.c - ACPI Battery Driver ($Revision: 37 $) | 2 | * battery.c - ACPI Battery Driver (Revision: 2.0) |
3 | * | 3 | * |
4 | * Copyright (C) 2007 Alexey Starikovskiy <astarikovskiy@suse.de> | ||
5 | * Copyright (C) 2004-2007 Vladimir Lebedev <vladimir.p.lebedev@intel.com> | ||
4 | * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com> | 6 | * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com> |
5 | * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com> | 7 | * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com> |
6 | * | 8 | * |
@@ -27,244 +29,301 @@ | |||
27 | #include <linux/module.h> | 29 | #include <linux/module.h> |
28 | #include <linux/init.h> | 30 | #include <linux/init.h> |
29 | #include <linux/types.h> | 31 | #include <linux/types.h> |
32 | #include <linux/jiffies.h> | ||
33 | |||
34 | #ifdef CONFIG_ACPI_PROCFS | ||
30 | #include <linux/proc_fs.h> | 35 | #include <linux/proc_fs.h> |
31 | #include <linux/seq_file.h> | 36 | #include <linux/seq_file.h> |
32 | #include <asm/uaccess.h> | 37 | #include <asm/uaccess.h> |
38 | #endif | ||
33 | 39 | ||
34 | #include <acpi/acpi_bus.h> | 40 | #include <acpi/acpi_bus.h> |
35 | #include <acpi/acpi_drivers.h> | 41 | #include <acpi/acpi_drivers.h> |
36 | 42 | ||
37 | #define ACPI_BATTERY_VALUE_UNKNOWN 0xFFFFFFFF | 43 | #include <linux/power_supply.h> |
38 | 44 | ||
39 | #define ACPI_BATTERY_FORMAT_BIF "NNNNNNNNNSSSS" | 45 | #define ACPI_BATTERY_VALUE_UNKNOWN 0xFFFFFFFF |
40 | #define ACPI_BATTERY_FORMAT_BST "NNNN" | ||
41 | 46 | ||
42 | #define ACPI_BATTERY_COMPONENT 0x00040000 | 47 | #define ACPI_BATTERY_COMPONENT 0x00040000 |
43 | #define ACPI_BATTERY_CLASS "battery" | 48 | #define ACPI_BATTERY_CLASS "battery" |
44 | #define ACPI_BATTERY_DEVICE_NAME "Battery" | 49 | #define ACPI_BATTERY_DEVICE_NAME "Battery" |
45 | #define ACPI_BATTERY_NOTIFY_STATUS 0x80 | 50 | #define ACPI_BATTERY_NOTIFY_STATUS 0x80 |
46 | #define ACPI_BATTERY_NOTIFY_INFO 0x81 | 51 | #define ACPI_BATTERY_NOTIFY_INFO 0x81 |
47 | #define ACPI_BATTERY_UNITS_WATTS "mW" | ||
48 | #define ACPI_BATTERY_UNITS_AMPS "mA" | ||
49 | 52 | ||
50 | #define _COMPONENT ACPI_BATTERY_COMPONENT | 53 | #define _COMPONENT ACPI_BATTERY_COMPONENT |
51 | 54 | ||
52 | #define ACPI_BATTERY_UPDATE_TIME 0 | ||
53 | |||
54 | #define ACPI_BATTERY_NONE_UPDATE 0 | ||
55 | #define ACPI_BATTERY_EASY_UPDATE 1 | ||
56 | #define ACPI_BATTERY_INIT_UPDATE 2 | ||
57 | |||
58 | ACPI_MODULE_NAME("battery"); | 55 | ACPI_MODULE_NAME("battery"); |
59 | 56 | ||
60 | MODULE_AUTHOR("Paul Diefenbaugh"); | 57 | MODULE_AUTHOR("Paul Diefenbaugh"); |
58 | MODULE_AUTHOR("Alexey Starikovskiy <astarikovskiy@suse.de>"); | ||
61 | MODULE_DESCRIPTION("ACPI Battery Driver"); | 59 | MODULE_DESCRIPTION("ACPI Battery Driver"); |
62 | MODULE_LICENSE("GPL"); | 60 | MODULE_LICENSE("GPL"); |
63 | 61 | ||
64 | static unsigned int update_time = ACPI_BATTERY_UPDATE_TIME; | 62 | static unsigned int cache_time = 1000; |
65 | 63 | module_param(cache_time, uint, 0644); | |
66 | /* 0 - every time, > 0 - by update_time */ | 64 | MODULE_PARM_DESC(cache_time, "cache time in milliseconds"); |
67 | module_param(update_time, uint, 0644); | ||
68 | 65 | ||
66 | #ifdef CONFIG_ACPI_PROCFS | ||
69 | extern struct proc_dir_entry *acpi_lock_battery_dir(void); | 67 | extern struct proc_dir_entry *acpi_lock_battery_dir(void); |
70 | extern void *acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir); | 68 | extern void *acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir); |
71 | 69 | ||
72 | static int acpi_battery_add(struct acpi_device *device); | 70 | enum acpi_battery_files { |
73 | static int acpi_battery_remove(struct acpi_device *device, int type); | 71 | info_tag = 0, |
74 | static int acpi_battery_resume(struct acpi_device *device); | 72 | state_tag, |
73 | alarm_tag, | ||
74 | ACPI_BATTERY_NUMFILES, | ||
75 | }; | ||
76 | |||
77 | #endif | ||
75 | 78 | ||
76 | static const struct acpi_device_id battery_device_ids[] = { | 79 | static const struct acpi_device_id battery_device_ids[] = { |
77 | {"PNP0C0A", 0}, | 80 | {"PNP0C0A", 0}, |
78 | {"", 0}, | 81 | {"", 0}, |
79 | }; | 82 | }; |
80 | MODULE_DEVICE_TABLE(acpi, battery_device_ids); | ||
81 | |||
82 | static struct acpi_driver acpi_battery_driver = { | ||
83 | .name = "battery", | ||
84 | .class = ACPI_BATTERY_CLASS, | ||
85 | .ids = battery_device_ids, | ||
86 | .ops = { | ||
87 | .add = acpi_battery_add, | ||
88 | .resume = acpi_battery_resume, | ||
89 | .remove = acpi_battery_remove, | ||
90 | }, | ||
91 | }; | ||
92 | 83 | ||
93 | struct acpi_battery_state { | 84 | MODULE_DEVICE_TABLE(acpi, battery_device_ids); |
94 | acpi_integer state; | ||
95 | acpi_integer present_rate; | ||
96 | acpi_integer remaining_capacity; | ||
97 | acpi_integer present_voltage; | ||
98 | }; | ||
99 | |||
100 | struct acpi_battery_info { | ||
101 | acpi_integer power_unit; | ||
102 | acpi_integer design_capacity; | ||
103 | acpi_integer last_full_capacity; | ||
104 | acpi_integer battery_technology; | ||
105 | acpi_integer design_voltage; | ||
106 | acpi_integer design_capacity_warning; | ||
107 | acpi_integer design_capacity_low; | ||
108 | acpi_integer battery_capacity_granularity_1; | ||
109 | acpi_integer battery_capacity_granularity_2; | ||
110 | acpi_string model_number; | ||
111 | acpi_string serial_number; | ||
112 | acpi_string battery_type; | ||
113 | acpi_string oem_info; | ||
114 | }; | ||
115 | |||
116 | enum acpi_battery_files{ | ||
117 | ACPI_BATTERY_INFO = 0, | ||
118 | ACPI_BATTERY_STATE, | ||
119 | ACPI_BATTERY_ALARM, | ||
120 | ACPI_BATTERY_NUMFILES, | ||
121 | }; | ||
122 | 85 | ||
123 | struct acpi_battery_flags { | ||
124 | u8 battery_present_prev; | ||
125 | u8 alarm_present; | ||
126 | u8 init_update; | ||
127 | u8 update[ACPI_BATTERY_NUMFILES]; | ||
128 | u8 power_unit; | ||
129 | }; | ||
130 | 86 | ||
131 | struct acpi_battery { | 87 | struct acpi_battery { |
132 | struct mutex mutex; | 88 | struct mutex lock; |
89 | struct power_supply bat; | ||
133 | struct acpi_device *device; | 90 | struct acpi_device *device; |
134 | struct acpi_battery_flags flags; | 91 | unsigned long update_time; |
135 | struct acpi_buffer bif_data; | 92 | int current_now; |
136 | struct acpi_buffer bst_data; | 93 | int capacity_now; |
137 | unsigned long alarm; | 94 | int voltage_now; |
138 | unsigned long update_time[ACPI_BATTERY_NUMFILES]; | 95 | int design_capacity; |
96 | int full_charge_capacity; | ||
97 | int technology; | ||
98 | int design_voltage; | ||
99 | int design_capacity_warning; | ||
100 | int design_capacity_low; | ||
101 | int capacity_granularity_1; | ||
102 | int capacity_granularity_2; | ||
103 | int alarm; | ||
104 | char model_number[32]; | ||
105 | char serial_number[32]; | ||
106 | char type[32]; | ||
107 | char oem_info[32]; | ||
108 | int state; | ||
109 | int power_unit; | ||
110 | u8 alarm_present; | ||
139 | }; | 111 | }; |
140 | 112 | ||
113 | #define to_acpi_battery(x) container_of(x, struct acpi_battery, bat); | ||
114 | |||
141 | inline int acpi_battery_present(struct acpi_battery *battery) | 115 | inline int acpi_battery_present(struct acpi_battery *battery) |
142 | { | 116 | { |
143 | return battery->device->status.battery_present; | 117 | return battery->device->status.battery_present; |
144 | } | 118 | } |
145 | inline char *acpi_battery_power_units(struct acpi_battery *battery) | ||
146 | { | ||
147 | if (battery->flags.power_unit) | ||
148 | return ACPI_BATTERY_UNITS_AMPS; | ||
149 | else | ||
150 | return ACPI_BATTERY_UNITS_WATTS; | ||
151 | } | ||
152 | 119 | ||
153 | inline acpi_handle acpi_battery_handle(struct acpi_battery *battery) | 120 | static int acpi_battery_technology(struct acpi_battery *battery) |
154 | { | 121 | { |
155 | return battery->device->handle; | 122 | if (!strcasecmp("NiCd", battery->type)) |
123 | return POWER_SUPPLY_TECHNOLOGY_NiCd; | ||
124 | if (!strcasecmp("NiMH", battery->type)) | ||
125 | return POWER_SUPPLY_TECHNOLOGY_NiMH; | ||
126 | if (!strcasecmp("LION", battery->type)) | ||
127 | return POWER_SUPPLY_TECHNOLOGY_LION; | ||
128 | if (!strcasecmp("LI-ION", battery->type)) | ||
129 | return POWER_SUPPLY_TECHNOLOGY_LION; | ||
130 | if (!strcasecmp("LiP", battery->type)) | ||
131 | return POWER_SUPPLY_TECHNOLOGY_LIPO; | ||
132 | return POWER_SUPPLY_TECHNOLOGY_UNKNOWN; | ||
156 | } | 133 | } |
157 | 134 | ||
158 | /* -------------------------------------------------------------------------- | 135 | static int acpi_battery_get_state(struct acpi_battery *battery); |
159 | Battery Management | ||
160 | -------------------------------------------------------------------------- */ | ||
161 | 136 | ||
162 | static void acpi_battery_check_result(struct acpi_battery *battery, int result) | 137 | static int acpi_battery_get_property(struct power_supply *psy, |
138 | enum power_supply_property psp, | ||
139 | union power_supply_propval *val) | ||
163 | { | 140 | { |
164 | if (!battery) | 141 | struct acpi_battery *battery = to_acpi_battery(psy); |
165 | return; | ||
166 | 142 | ||
167 | if (result) { | 143 | if (acpi_battery_present(battery)) { |
168 | battery->flags.init_update = 1; | 144 | /* run battery update only if it is present */ |
145 | acpi_battery_get_state(battery); | ||
146 | } else if (psp != POWER_SUPPLY_PROP_PRESENT) | ||
147 | return -ENODEV; | ||
148 | switch (psp) { | ||
149 | case POWER_SUPPLY_PROP_STATUS: | ||
150 | if (battery->state & 0x01) | ||
151 | val->intval = POWER_SUPPLY_STATUS_DISCHARGING; | ||
152 | else if (battery->state & 0x02) | ||
153 | val->intval = POWER_SUPPLY_STATUS_CHARGING; | ||
154 | else if (battery->state == 0) | ||
155 | val->intval = POWER_SUPPLY_STATUS_FULL; | ||
156 | else | ||
157 | val->intval = POWER_SUPPLY_STATUS_UNKNOWN; | ||
158 | break; | ||
159 | case POWER_SUPPLY_PROP_PRESENT: | ||
160 | val->intval = acpi_battery_present(battery); | ||
161 | break; | ||
162 | case POWER_SUPPLY_PROP_TECHNOLOGY: | ||
163 | val->intval = acpi_battery_technology(battery); | ||
164 | break; | ||
165 | case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN: | ||
166 | val->intval = battery->design_voltage * 1000; | ||
167 | break; | ||
168 | case POWER_SUPPLY_PROP_VOLTAGE_NOW: | ||
169 | val->intval = battery->voltage_now * 1000; | ||
170 | break; | ||
171 | case POWER_SUPPLY_PROP_CURRENT_NOW: | ||
172 | val->intval = battery->current_now * 1000; | ||
173 | break; | ||
174 | case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: | ||
175 | case POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN: | ||
176 | val->intval = battery->design_capacity * 1000; | ||
177 | break; | ||
178 | case POWER_SUPPLY_PROP_CHARGE_FULL: | ||
179 | case POWER_SUPPLY_PROP_ENERGY_FULL: | ||
180 | val->intval = battery->full_charge_capacity * 1000; | ||
181 | break; | ||
182 | case POWER_SUPPLY_PROP_CHARGE_NOW: | ||
183 | case POWER_SUPPLY_PROP_ENERGY_NOW: | ||
184 | val->intval = battery->capacity_now * 1000; | ||
185 | break; | ||
186 | case POWER_SUPPLY_PROP_MODEL_NAME: | ||
187 | val->strval = battery->model_number; | ||
188 | break; | ||
189 | case POWER_SUPPLY_PROP_MANUFACTURER: | ||
190 | val->strval = battery->oem_info; | ||
191 | break; | ||
192 | default: | ||
193 | return -EINVAL; | ||
169 | } | 194 | } |
195 | return 0; | ||
170 | } | 196 | } |
171 | 197 | ||
172 | static int acpi_battery_extract_package(struct acpi_battery *battery, | 198 | static enum power_supply_property charge_battery_props[] = { |
173 | union acpi_object *package, | 199 | POWER_SUPPLY_PROP_STATUS, |
174 | struct acpi_buffer *format, | 200 | POWER_SUPPLY_PROP_PRESENT, |
175 | struct acpi_buffer *data, | 201 | POWER_SUPPLY_PROP_TECHNOLOGY, |
176 | char *package_name) | 202 | POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN, |
203 | POWER_SUPPLY_PROP_VOLTAGE_NOW, | ||
204 | POWER_SUPPLY_PROP_CURRENT_NOW, | ||
205 | POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, | ||
206 | POWER_SUPPLY_PROP_CHARGE_FULL, | ||
207 | POWER_SUPPLY_PROP_CHARGE_NOW, | ||
208 | POWER_SUPPLY_PROP_MODEL_NAME, | ||
209 | POWER_SUPPLY_PROP_MANUFACTURER, | ||
210 | }; | ||
211 | |||
212 | static enum power_supply_property energy_battery_props[] = { | ||
213 | POWER_SUPPLY_PROP_STATUS, | ||
214 | POWER_SUPPLY_PROP_PRESENT, | ||
215 | POWER_SUPPLY_PROP_TECHNOLOGY, | ||
216 | POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN, | ||
217 | POWER_SUPPLY_PROP_VOLTAGE_NOW, | ||
218 | POWER_SUPPLY_PROP_CURRENT_NOW, | ||
219 | POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN, | ||
220 | POWER_SUPPLY_PROP_ENERGY_FULL, | ||
221 | POWER_SUPPLY_PROP_ENERGY_NOW, | ||
222 | POWER_SUPPLY_PROP_MODEL_NAME, | ||
223 | POWER_SUPPLY_PROP_MANUFACTURER, | ||
224 | }; | ||
225 | |||
226 | #ifdef CONFIG_ACPI_PROCFS | ||
227 | inline char *acpi_battery_units(struct acpi_battery *battery) | ||
177 | { | 228 | { |
178 | acpi_status status = AE_OK; | 229 | return (battery->power_unit)?"mA":"mW"; |
179 | struct acpi_buffer data_null = { 0, NULL }; | 230 | } |
231 | #endif | ||
180 | 232 | ||
181 | status = acpi_extract_package(package, format, &data_null); | 233 | /* -------------------------------------------------------------------------- |
182 | if (status != AE_BUFFER_OVERFLOW) { | 234 | Battery Management |
183 | ACPI_EXCEPTION((AE_INFO, status, "Extracting size %s", | 235 | -------------------------------------------------------------------------- */ |
184 | package_name)); | 236 | struct acpi_offsets { |
185 | return -ENODEV; | 237 | size_t offset; /* offset inside struct acpi_sbs_battery */ |
186 | } | 238 | u8 mode; /* int or string? */ |
239 | }; | ||
187 | 240 | ||
188 | if (data_null.length != data->length) { | 241 | static struct acpi_offsets state_offsets[] = { |
189 | kfree(data->pointer); | 242 | {offsetof(struct acpi_battery, state), 0}, |
190 | data->pointer = kzalloc(data_null.length, GFP_KERNEL); | 243 | {offsetof(struct acpi_battery, current_now), 0}, |
191 | if (!data->pointer) { | 244 | {offsetof(struct acpi_battery, capacity_now), 0}, |
192 | ACPI_EXCEPTION((AE_INFO, AE_NO_MEMORY, "kzalloc()")); | 245 | {offsetof(struct acpi_battery, voltage_now), 0}, |
193 | return -ENOMEM; | 246 | }; |
194 | } | ||
195 | data->length = data_null.length; | ||
196 | } | ||
197 | 247 | ||
198 | status = acpi_extract_package(package, format, data); | 248 | static struct acpi_offsets info_offsets[] = { |
199 | if (ACPI_FAILURE(status)) { | 249 | {offsetof(struct acpi_battery, power_unit), 0}, |
200 | ACPI_EXCEPTION((AE_INFO, status, "Extracting %s", | 250 | {offsetof(struct acpi_battery, design_capacity), 0}, |
201 | package_name)); | 251 | {offsetof(struct acpi_battery, full_charge_capacity), 0}, |
202 | return -ENODEV; | 252 | {offsetof(struct acpi_battery, technology), 0}, |
203 | } | 253 | {offsetof(struct acpi_battery, design_voltage), 0}, |
254 | {offsetof(struct acpi_battery, design_capacity_warning), 0}, | ||
255 | {offsetof(struct acpi_battery, design_capacity_low), 0}, | ||
256 | {offsetof(struct acpi_battery, capacity_granularity_1), 0}, | ||
257 | {offsetof(struct acpi_battery, capacity_granularity_2), 0}, | ||
258 | {offsetof(struct acpi_battery, model_number), 1}, | ||
259 | {offsetof(struct acpi_battery, serial_number), 1}, | ||
260 | {offsetof(struct acpi_battery, type), 1}, | ||
261 | {offsetof(struct acpi_battery, oem_info), 1}, | ||
262 | }; | ||
204 | 263 | ||
264 | static int extract_package(struct acpi_battery *battery, | ||
265 | union acpi_object *package, | ||
266 | struct acpi_offsets *offsets, int num) | ||
267 | { | ||
268 | int i; | ||
269 | union acpi_object *element; | ||
270 | if (package->type != ACPI_TYPE_PACKAGE) | ||
271 | return -EFAULT; | ||
272 | for (i = 0; i < num; ++i) { | ||
273 | if (package->package.count <= i) | ||
274 | return -EFAULT; | ||
275 | element = &package->package.elements[i]; | ||
276 | if (offsets[i].mode) { | ||
277 | u8 *ptr = (u8 *)battery + offsets[i].offset; | ||
278 | if (element->type == ACPI_TYPE_STRING || | ||
279 | element->type == ACPI_TYPE_BUFFER) | ||
280 | strncpy(ptr, element->string.pointer, 32); | ||
281 | else if (element->type == ACPI_TYPE_INTEGER) { | ||
282 | strncpy(ptr, (u8 *)&element->integer.value, | ||
283 | sizeof(acpi_integer)); | ||
284 | ptr[sizeof(acpi_integer)] = 0; | ||
285 | } else return -EFAULT; | ||
286 | } else { | ||
287 | if (element->type == ACPI_TYPE_INTEGER) { | ||
288 | int *x = (int *)((u8 *)battery + | ||
289 | offsets[i].offset); | ||
290 | *x = element->integer.value; | ||
291 | } else return -EFAULT; | ||
292 | } | ||
293 | } | ||
205 | return 0; | 294 | return 0; |
206 | } | 295 | } |
207 | 296 | ||
208 | static int acpi_battery_get_status(struct acpi_battery *battery) | 297 | static int acpi_battery_get_status(struct acpi_battery *battery) |
209 | { | 298 | { |
210 | int result = 0; | 299 | if (acpi_bus_get_status(battery->device)) { |
211 | |||
212 | result = acpi_bus_get_status(battery->device); | ||
213 | if (result) { | ||
214 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, "Evaluating _STA")); | 300 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, "Evaluating _STA")); |
215 | return -ENODEV; | 301 | return -ENODEV; |
216 | } | 302 | } |
217 | return result; | 303 | return 0; |
218 | } | 304 | } |
219 | 305 | ||
220 | static int acpi_battery_get_info(struct acpi_battery *battery) | 306 | static int acpi_battery_get_info(struct acpi_battery *battery) |
221 | { | 307 | { |
222 | int result = 0; | 308 | int result = -EFAULT; |
223 | acpi_status status = 0; | 309 | acpi_status status = 0; |
224 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; | 310 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
225 | struct acpi_buffer format = { sizeof(ACPI_BATTERY_FORMAT_BIF), | ||
226 | ACPI_BATTERY_FORMAT_BIF | ||
227 | }; | ||
228 | union acpi_object *package = NULL; | ||
229 | struct acpi_buffer *data = NULL; | ||
230 | struct acpi_battery_info *bif = NULL; | ||
231 | |||
232 | battery->update_time[ACPI_BATTERY_INFO] = get_seconds(); | ||
233 | 311 | ||
234 | if (!acpi_battery_present(battery)) | 312 | if (!acpi_battery_present(battery)) |
235 | return 0; | 313 | return 0; |
314 | mutex_lock(&battery->lock); | ||
315 | status = acpi_evaluate_object(battery->device->handle, "_BIF", | ||
316 | NULL, &buffer); | ||
317 | mutex_unlock(&battery->lock); | ||
236 | 318 | ||
237 | /* Evaluate _BIF */ | ||
238 | |||
239 | status = | ||
240 | acpi_evaluate_object(acpi_battery_handle(battery), "_BIF", NULL, | ||
241 | &buffer); | ||
242 | if (ACPI_FAILURE(status)) { | 319 | if (ACPI_FAILURE(status)) { |
243 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _BIF")); | 320 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _BIF")); |
244 | return -ENODEV; | 321 | return -ENODEV; |
245 | } | 322 | } |
246 | 323 | ||
247 | package = buffer.pointer; | 324 | result = extract_package(battery, buffer.pointer, |
248 | 325 | info_offsets, ARRAY_SIZE(info_offsets)); | |
249 | data = &battery->bif_data; | ||
250 | |||
251 | /* Extract Package Data */ | ||
252 | |||
253 | result = | ||
254 | acpi_battery_extract_package(battery, package, &format, data, | ||
255 | "_BIF"); | ||
256 | if (result) | ||
257 | goto end; | ||
258 | |||
259 | end: | ||
260 | |||
261 | kfree(buffer.pointer); | 326 | kfree(buffer.pointer); |
262 | |||
263 | if (!result) { | ||
264 | bif = data->pointer; | ||
265 | battery->flags.power_unit = bif->power_unit; | ||
266 | } | ||
267 | |||
268 | return result; | 327 | return result; |
269 | } | 328 | } |
270 | 329 | ||
@@ -273,342 +332,256 @@ static int acpi_battery_get_state(struct acpi_battery *battery) | |||
273 | int result = 0; | 332 | int result = 0; |
274 | acpi_status status = 0; | 333 | acpi_status status = 0; |
275 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; | 334 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
276 | struct acpi_buffer format = { sizeof(ACPI_BATTERY_FORMAT_BST), | ||
277 | ACPI_BATTERY_FORMAT_BST | ||
278 | }; | ||
279 | union acpi_object *package = NULL; | ||
280 | struct acpi_buffer *data = NULL; | ||
281 | |||
282 | battery->update_time[ACPI_BATTERY_STATE] = get_seconds(); | ||
283 | 335 | ||
284 | if (!acpi_battery_present(battery)) | 336 | if (!acpi_battery_present(battery)) |
285 | return 0; | 337 | return 0; |
286 | 338 | ||
287 | /* Evaluate _BST */ | 339 | if (battery->update_time && |
340 | time_before(jiffies, battery->update_time + | ||
341 | msecs_to_jiffies(cache_time))) | ||
342 | return 0; | ||
343 | |||
344 | mutex_lock(&battery->lock); | ||
345 | status = acpi_evaluate_object(battery->device->handle, "_BST", | ||
346 | NULL, &buffer); | ||
347 | mutex_unlock(&battery->lock); | ||
288 | 348 | ||
289 | status = | ||
290 | acpi_evaluate_object(acpi_battery_handle(battery), "_BST", NULL, | ||
291 | &buffer); | ||
292 | if (ACPI_FAILURE(status)) { | 349 | if (ACPI_FAILURE(status)) { |
293 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _BST")); | 350 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _BST")); |
294 | return -ENODEV; | 351 | return -ENODEV; |
295 | } | 352 | } |
296 | 353 | ||
297 | package = buffer.pointer; | 354 | result = extract_package(battery, buffer.pointer, |
298 | 355 | state_offsets, ARRAY_SIZE(state_offsets)); | |
299 | data = &battery->bst_data; | 356 | battery->update_time = jiffies; |
300 | |||
301 | /* Extract Package Data */ | ||
302 | |||
303 | result = | ||
304 | acpi_battery_extract_package(battery, package, &format, data, | ||
305 | "_BST"); | ||
306 | if (result) | ||
307 | goto end; | ||
308 | |||
309 | end: | ||
310 | kfree(buffer.pointer); | 357 | kfree(buffer.pointer); |
311 | |||
312 | return result; | 358 | return result; |
313 | } | 359 | } |
314 | 360 | ||
315 | static int acpi_battery_get_alarm(struct acpi_battery *battery) | 361 | static int acpi_battery_set_alarm(struct acpi_battery *battery) |
316 | { | ||
317 | battery->update_time[ACPI_BATTERY_ALARM] = get_seconds(); | ||
318 | |||
319 | return 0; | ||
320 | } | ||
321 | |||
322 | static int acpi_battery_set_alarm(struct acpi_battery *battery, | ||
323 | unsigned long alarm) | ||
324 | { | 362 | { |
325 | acpi_status status = 0; | 363 | acpi_status status = 0; |
326 | union acpi_object arg0 = { ACPI_TYPE_INTEGER }; | 364 | union acpi_object arg0 = { .type = ACPI_TYPE_INTEGER }; |
327 | struct acpi_object_list arg_list = { 1, &arg0 }; | 365 | struct acpi_object_list arg_list = { 1, &arg0 }; |
328 | 366 | ||
329 | battery->update_time[ACPI_BATTERY_ALARM] = get_seconds(); | 367 | if (!acpi_battery_present(battery)|| !battery->alarm_present) |
330 | |||
331 | if (!acpi_battery_present(battery)) | ||
332 | return -ENODEV; | 368 | return -ENODEV; |
333 | 369 | ||
334 | if (!battery->flags.alarm_present) | 370 | arg0.integer.value = battery->alarm; |
335 | return -ENODEV; | ||
336 | 371 | ||
337 | arg0.integer.value = alarm; | 372 | mutex_lock(&battery->lock); |
338 | 373 | status = acpi_evaluate_object(battery->device->handle, "_BTP", | |
339 | status = | ||
340 | acpi_evaluate_object(acpi_battery_handle(battery), "_BTP", | ||
341 | &arg_list, NULL); | 374 | &arg_list, NULL); |
375 | mutex_unlock(&battery->lock); | ||
376 | |||
342 | if (ACPI_FAILURE(status)) | 377 | if (ACPI_FAILURE(status)) |
343 | return -ENODEV; | 378 | return -ENODEV; |
344 | 379 | ||
345 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Alarm set to %d\n", (u32) alarm)); | 380 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Alarm set to %d\n", battery->alarm)); |
346 | |||
347 | battery->alarm = alarm; | ||
348 | |||
349 | return 0; | 381 | return 0; |
350 | } | 382 | } |
351 | 383 | ||
352 | static int acpi_battery_init_alarm(struct acpi_battery *battery) | 384 | static int acpi_battery_init_alarm(struct acpi_battery *battery) |
353 | { | 385 | { |
354 | int result = 0; | ||
355 | acpi_status status = AE_OK; | 386 | acpi_status status = AE_OK; |
356 | acpi_handle handle = NULL; | 387 | acpi_handle handle = NULL; |
357 | struct acpi_battery_info *bif = battery->bif_data.pointer; | ||
358 | unsigned long alarm = battery->alarm; | ||
359 | 388 | ||
360 | /* See if alarms are supported, and if so, set default */ | 389 | /* See if alarms are supported, and if so, set default */ |
361 | 390 | status = acpi_get_handle(battery->device->handle, "_BTP", &handle); | |
362 | status = acpi_get_handle(acpi_battery_handle(battery), "_BTP", &handle); | 391 | if (ACPI_FAILURE(status)) { |
363 | if (ACPI_SUCCESS(status)) { | 392 | battery->alarm_present = 0; |
364 | battery->flags.alarm_present = 1; | 393 | return 0; |
365 | if (!alarm && bif) { | ||
366 | alarm = bif->design_capacity_warning; | ||
367 | } | ||
368 | result = acpi_battery_set_alarm(battery, alarm); | ||
369 | if (result) | ||
370 | goto end; | ||
371 | } else { | ||
372 | battery->flags.alarm_present = 0; | ||
373 | } | 394 | } |
374 | 395 | battery->alarm_present = 1; | |
375 | end: | 396 | if (!battery->alarm) |
376 | 397 | battery->alarm = battery->design_capacity_warning; | |
377 | return result; | 398 | return acpi_battery_set_alarm(battery); |
378 | } | 399 | } |
379 | 400 | ||
380 | static int acpi_battery_init_update(struct acpi_battery *battery) | 401 | static ssize_t acpi_battery_alarm_show(struct device *dev, |
402 | struct device_attribute *attr, | ||
403 | char *buf) | ||
381 | { | 404 | { |
382 | int result = 0; | 405 | struct acpi_battery *battery = to_acpi_battery(dev_get_drvdata(dev)); |
383 | 406 | return sprintf(buf, "%d\n", battery->alarm * 1000); | |
384 | result = acpi_battery_get_status(battery); | ||
385 | if (result) | ||
386 | return result; | ||
387 | |||
388 | battery->flags.battery_present_prev = acpi_battery_present(battery); | ||
389 | |||
390 | if (acpi_battery_present(battery)) { | ||
391 | result = acpi_battery_get_info(battery); | ||
392 | if (result) | ||
393 | return result; | ||
394 | result = acpi_battery_get_state(battery); | ||
395 | if (result) | ||
396 | return result; | ||
397 | |||
398 | acpi_battery_init_alarm(battery); | ||
399 | } | ||
400 | |||
401 | return result; | ||
402 | } | 407 | } |
403 | 408 | ||
404 | static int acpi_battery_update(struct acpi_battery *battery, | 409 | static ssize_t acpi_battery_alarm_store(struct device *dev, |
405 | int update, int *update_result_ptr) | 410 | struct device_attribute *attr, |
411 | const char *buf, size_t count) | ||
406 | { | 412 | { |
407 | int result = 0; | 413 | unsigned long x; |
408 | int update_result = ACPI_BATTERY_NONE_UPDATE; | 414 | struct acpi_battery *battery = to_acpi_battery(dev_get_drvdata(dev)); |
409 | 415 | if (sscanf(buf, "%ld\n", &x) == 1) | |
410 | if (!acpi_battery_present(battery)) { | 416 | battery->alarm = x/1000; |
411 | update = 1; | 417 | if (acpi_battery_present(battery)) |
412 | } | 418 | acpi_battery_set_alarm(battery); |
419 | return count; | ||
420 | } | ||
413 | 421 | ||
414 | if (battery->flags.init_update) { | 422 | static struct device_attribute alarm_attr = { |
415 | result = acpi_battery_init_update(battery); | 423 | .attr = {.name = "alarm", .mode = 0644, .owner = THIS_MODULE}, |
416 | if (result) | 424 | .show = acpi_battery_alarm_show, |
417 | goto end; | 425 | .store = acpi_battery_alarm_store, |
418 | update_result = ACPI_BATTERY_INIT_UPDATE; | 426 | }; |
419 | } else if (update) { | ||
420 | result = acpi_battery_get_status(battery); | ||
421 | if (result) | ||
422 | goto end; | ||
423 | if ((!battery->flags.battery_present_prev & acpi_battery_present(battery)) | ||
424 | || (battery->flags.battery_present_prev & !acpi_battery_present(battery))) { | ||
425 | result = acpi_battery_init_update(battery); | ||
426 | if (result) | ||
427 | goto end; | ||
428 | update_result = ACPI_BATTERY_INIT_UPDATE; | ||
429 | } else { | ||
430 | update_result = ACPI_BATTERY_EASY_UPDATE; | ||
431 | } | ||
432 | } | ||
433 | 427 | ||
434 | end: | 428 | static int sysfs_add_battery(struct acpi_battery *battery) |
429 | { | ||
430 | int result; | ||
435 | 431 | ||
436 | battery->flags.init_update = (result != 0); | 432 | battery->update_time = 0; |
433 | result = acpi_battery_get_info(battery); | ||
434 | acpi_battery_init_alarm(battery); | ||
435 | if (result) | ||
436 | return result; | ||
437 | if (battery->power_unit) { | ||
438 | battery->bat.properties = charge_battery_props; | ||
439 | battery->bat.num_properties = | ||
440 | ARRAY_SIZE(charge_battery_props); | ||
441 | } else { | ||
442 | battery->bat.properties = energy_battery_props; | ||
443 | battery->bat.num_properties = | ||
444 | ARRAY_SIZE(energy_battery_props); | ||
445 | } | ||
437 | 446 | ||
438 | *update_result_ptr = update_result; | 447 | battery->bat.name = acpi_device_bid(battery->device); |
448 | battery->bat.type = POWER_SUPPLY_TYPE_BATTERY; | ||
449 | battery->bat.get_property = acpi_battery_get_property; | ||
439 | 450 | ||
440 | return result; | 451 | result = power_supply_register(&battery->device->dev, &battery->bat); |
452 | if (result) | ||
453 | return result; | ||
454 | return device_create_file(battery->bat.dev, &alarm_attr); | ||
441 | } | 455 | } |
442 | 456 | ||
443 | static void acpi_battery_notify_update(struct acpi_battery *battery) | 457 | static void sysfs_remove_battery(struct acpi_battery *battery) |
444 | { | 458 | { |
445 | acpi_battery_get_status(battery); | 459 | if (!battery->bat.dev) |
446 | |||
447 | if (battery->flags.init_update) { | ||
448 | return; | 460 | return; |
449 | } | 461 | device_remove_file(battery->bat.dev, &alarm_attr); |
462 | power_supply_unregister(&battery->bat); | ||
463 | battery->bat.dev = NULL; | ||
464 | } | ||
450 | 465 | ||
451 | if ((!battery->flags.battery_present_prev & | 466 | static int acpi_battery_update(struct acpi_battery *battery) |
452 | acpi_battery_present(battery)) || | 467 | { |
453 | (battery->flags.battery_present_prev & | 468 | int result = acpi_battery_get_status(battery); |
454 | !acpi_battery_present(battery))) { | 469 | if (result) |
455 | battery->flags.init_update = 1; | 470 | return result; |
456 | } else { | 471 | if (!acpi_battery_present(battery)) { |
457 | battery->flags.update[ACPI_BATTERY_INFO] = 1; | 472 | sysfs_remove_battery(battery); |
458 | battery->flags.update[ACPI_BATTERY_STATE] = 1; | 473 | return 0; |
459 | battery->flags.update[ACPI_BATTERY_ALARM] = 1; | ||
460 | } | 474 | } |
475 | if (!battery->bat.dev) | ||
476 | sysfs_add_battery(battery); | ||
477 | return acpi_battery_get_state(battery); | ||
461 | } | 478 | } |
462 | 479 | ||
463 | /* -------------------------------------------------------------------------- | 480 | /* -------------------------------------------------------------------------- |
464 | FS Interface (/proc) | 481 | FS Interface (/proc) |
465 | -------------------------------------------------------------------------- */ | 482 | -------------------------------------------------------------------------- */ |
466 | 483 | ||
484 | #ifdef CONFIG_ACPI_PROCFS | ||
467 | static struct proc_dir_entry *acpi_battery_dir; | 485 | static struct proc_dir_entry *acpi_battery_dir; |
468 | 486 | ||
469 | static int acpi_battery_print_info(struct seq_file *seq, int result) | 487 | static int acpi_battery_print_info(struct seq_file *seq, int result) |
470 | { | 488 | { |
471 | struct acpi_battery *battery = seq->private; | 489 | struct acpi_battery *battery = seq->private; |
472 | struct acpi_battery_info *bif = NULL; | ||
473 | char *units = "?"; | ||
474 | 490 | ||
475 | if (result) | 491 | if (result) |
476 | goto end; | 492 | goto end; |
477 | 493 | ||
478 | if (acpi_battery_present(battery)) | 494 | seq_printf(seq, "present: %s\n", |
479 | seq_printf(seq, "present: yes\n"); | 495 | acpi_battery_present(battery)?"yes":"no"); |
480 | else { | 496 | if (!acpi_battery_present(battery)) |
481 | seq_printf(seq, "present: no\n"); | ||
482 | goto end; | ||
483 | } | ||
484 | |||
485 | bif = battery->bif_data.pointer; | ||
486 | if (!bif) { | ||
487 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, "BIF buffer is NULL")); | ||
488 | result = -ENODEV; | ||
489 | goto end; | 497 | goto end; |
490 | } | 498 | if (battery->design_capacity == ACPI_BATTERY_VALUE_UNKNOWN) |
491 | |||
492 | /* Battery Units */ | ||
493 | |||
494 | units = acpi_battery_power_units(battery); | ||
495 | |||
496 | if (bif->design_capacity == ACPI_BATTERY_VALUE_UNKNOWN) | ||
497 | seq_printf(seq, "design capacity: unknown\n"); | 499 | seq_printf(seq, "design capacity: unknown\n"); |
498 | else | 500 | else |
499 | seq_printf(seq, "design capacity: %d %sh\n", | 501 | seq_printf(seq, "design capacity: %d %sh\n", |
500 | (u32) bif->design_capacity, units); | 502 | battery->design_capacity, |
503 | acpi_battery_units(battery)); | ||
501 | 504 | ||
502 | if (bif->last_full_capacity == ACPI_BATTERY_VALUE_UNKNOWN) | 505 | if (battery->full_charge_capacity == ACPI_BATTERY_VALUE_UNKNOWN) |
503 | seq_printf(seq, "last full capacity: unknown\n"); | 506 | seq_printf(seq, "last full capacity: unknown\n"); |
504 | else | 507 | else |
505 | seq_printf(seq, "last full capacity: %d %sh\n", | 508 | seq_printf(seq, "last full capacity: %d %sh\n", |
506 | (u32) bif->last_full_capacity, units); | 509 | battery->full_charge_capacity, |
510 | acpi_battery_units(battery)); | ||
507 | 511 | ||
508 | switch ((u32) bif->battery_technology) { | 512 | seq_printf(seq, "battery technology: %srechargeable\n", |
509 | case 0: | 513 | (!battery->technology)?"non-":""); |
510 | seq_printf(seq, "battery technology: non-rechargeable\n"); | ||
511 | break; | ||
512 | case 1: | ||
513 | seq_printf(seq, "battery technology: rechargeable\n"); | ||
514 | break; | ||
515 | default: | ||
516 | seq_printf(seq, "battery technology: unknown\n"); | ||
517 | break; | ||
518 | } | ||
519 | 514 | ||
520 | if (bif->design_voltage == ACPI_BATTERY_VALUE_UNKNOWN) | 515 | if (battery->design_voltage == ACPI_BATTERY_VALUE_UNKNOWN) |
521 | seq_printf(seq, "design voltage: unknown\n"); | 516 | seq_printf(seq, "design voltage: unknown\n"); |
522 | else | 517 | else |
523 | seq_printf(seq, "design voltage: %d mV\n", | 518 | seq_printf(seq, "design voltage: %d mV\n", |
524 | (u32) bif->design_voltage); | 519 | battery->design_voltage); |
525 | seq_printf(seq, "design capacity warning: %d %sh\n", | 520 | seq_printf(seq, "design capacity warning: %d %sh\n", |
526 | (u32) bif->design_capacity_warning, units); | 521 | battery->design_capacity_warning, |
522 | acpi_battery_units(battery)); | ||
527 | seq_printf(seq, "design capacity low: %d %sh\n", | 523 | seq_printf(seq, "design capacity low: %d %sh\n", |
528 | (u32) bif->design_capacity_low, units); | 524 | battery->design_capacity_low, |
525 | acpi_battery_units(battery)); | ||
529 | seq_printf(seq, "capacity granularity 1: %d %sh\n", | 526 | seq_printf(seq, "capacity granularity 1: %d %sh\n", |
530 | (u32) bif->battery_capacity_granularity_1, units); | 527 | battery->capacity_granularity_1, |
528 | acpi_battery_units(battery)); | ||
531 | seq_printf(seq, "capacity granularity 2: %d %sh\n", | 529 | seq_printf(seq, "capacity granularity 2: %d %sh\n", |
532 | (u32) bif->battery_capacity_granularity_2, units); | 530 | battery->capacity_granularity_2, |
533 | seq_printf(seq, "model number: %s\n", bif->model_number); | 531 | acpi_battery_units(battery)); |
534 | seq_printf(seq, "serial number: %s\n", bif->serial_number); | 532 | seq_printf(seq, "model number: %s\n", battery->model_number); |
535 | seq_printf(seq, "battery type: %s\n", bif->battery_type); | 533 | seq_printf(seq, "serial number: %s\n", battery->serial_number); |
536 | seq_printf(seq, "OEM info: %s\n", bif->oem_info); | 534 | seq_printf(seq, "battery type: %s\n", battery->type); |
537 | 535 | seq_printf(seq, "OEM info: %s\n", battery->oem_info); | |
538 | end: | 536 | end: |
539 | |||
540 | if (result) | 537 | if (result) |
541 | seq_printf(seq, "ERROR: Unable to read battery info\n"); | 538 | seq_printf(seq, "ERROR: Unable to read battery info\n"); |
542 | |||
543 | return result; | 539 | return result; |
544 | } | 540 | } |
545 | 541 | ||
546 | static int acpi_battery_print_state(struct seq_file *seq, int result) | 542 | static int acpi_battery_print_state(struct seq_file *seq, int result) |
547 | { | 543 | { |
548 | struct acpi_battery *battery = seq->private; | 544 | struct acpi_battery *battery = seq->private; |
549 | struct acpi_battery_state *bst = NULL; | ||
550 | char *units = "?"; | ||
551 | 545 | ||
552 | if (result) | 546 | if (result) |
553 | goto end; | 547 | goto end; |
554 | 548 | ||
555 | if (acpi_battery_present(battery)) | 549 | seq_printf(seq, "present: %s\n", |
556 | seq_printf(seq, "present: yes\n"); | 550 | acpi_battery_present(battery)?"yes":"no"); |
557 | else { | 551 | if (!acpi_battery_present(battery)) |
558 | seq_printf(seq, "present: no\n"); | ||
559 | goto end; | 552 | goto end; |
560 | } | ||
561 | 553 | ||
562 | bst = battery->bst_data.pointer; | 554 | seq_printf(seq, "capacity state: %s\n", |
563 | if (!bst) { | 555 | (battery->state & 0x04)?"critical":"ok"); |
564 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, "BST buffer is NULL")); | 556 | if ((battery->state & 0x01) && (battery->state & 0x02)) |
565 | result = -ENODEV; | ||
566 | goto end; | ||
567 | } | ||
568 | |||
569 | /* Battery Units */ | ||
570 | |||
571 | units = acpi_battery_power_units(battery); | ||
572 | |||
573 | if (!(bst->state & 0x04)) | ||
574 | seq_printf(seq, "capacity state: ok\n"); | ||
575 | else | ||
576 | seq_printf(seq, "capacity state: critical\n"); | ||
577 | |||
578 | if ((bst->state & 0x01) && (bst->state & 0x02)) { | ||
579 | seq_printf(seq, | 557 | seq_printf(seq, |
580 | "charging state: charging/discharging\n"); | 558 | "charging state: charging/discharging\n"); |
581 | } else if (bst->state & 0x01) | 559 | else if (battery->state & 0x01) |
582 | seq_printf(seq, "charging state: discharging\n"); | 560 | seq_printf(seq, "charging state: discharging\n"); |
583 | else if (bst->state & 0x02) | 561 | else if (battery->state & 0x02) |
584 | seq_printf(seq, "charging state: charging\n"); | 562 | seq_printf(seq, "charging state: charging\n"); |
585 | else { | 563 | else |
586 | seq_printf(seq, "charging state: charged\n"); | 564 | seq_printf(seq, "charging state: charged\n"); |
587 | } | ||
588 | 565 | ||
589 | if (bst->present_rate == ACPI_BATTERY_VALUE_UNKNOWN) | 566 | if (battery->current_now == ACPI_BATTERY_VALUE_UNKNOWN) |
590 | seq_printf(seq, "present rate: unknown\n"); | 567 | seq_printf(seq, "present rate: unknown\n"); |
591 | else | 568 | else |
592 | seq_printf(seq, "present rate: %d %s\n", | 569 | seq_printf(seq, "present rate: %d %s\n", |
593 | (u32) bst->present_rate, units); | 570 | battery->current_now, acpi_battery_units(battery)); |
594 | 571 | ||
595 | if (bst->remaining_capacity == ACPI_BATTERY_VALUE_UNKNOWN) | 572 | if (battery->capacity_now == ACPI_BATTERY_VALUE_UNKNOWN) |
596 | seq_printf(seq, "remaining capacity: unknown\n"); | 573 | seq_printf(seq, "remaining capacity: unknown\n"); |
597 | else | 574 | else |
598 | seq_printf(seq, "remaining capacity: %d %sh\n", | 575 | seq_printf(seq, "remaining capacity: %d %sh\n", |
599 | (u32) bst->remaining_capacity, units); | 576 | battery->capacity_now, acpi_battery_units(battery)); |
600 | 577 | if (battery->voltage_now == ACPI_BATTERY_VALUE_UNKNOWN) | |
601 | if (bst->present_voltage == ACPI_BATTERY_VALUE_UNKNOWN) | ||
602 | seq_printf(seq, "present voltage: unknown\n"); | 578 | seq_printf(seq, "present voltage: unknown\n"); |
603 | else | 579 | else |
604 | seq_printf(seq, "present voltage: %d mV\n", | 580 | seq_printf(seq, "present voltage: %d mV\n", |
605 | (u32) bst->present_voltage); | 581 | battery->voltage_now); |
606 | |||
607 | end: | 582 | end: |
608 | 583 | if (result) | |
609 | if (result) { | ||
610 | seq_printf(seq, "ERROR: Unable to read battery state\n"); | 584 | seq_printf(seq, "ERROR: Unable to read battery state\n"); |
611 | } | ||
612 | 585 | ||
613 | return result; | 586 | return result; |
614 | } | 587 | } |
@@ -616,7 +589,6 @@ static int acpi_battery_print_state(struct seq_file *seq, int result) | |||
616 | static int acpi_battery_print_alarm(struct seq_file *seq, int result) | 589 | static int acpi_battery_print_alarm(struct seq_file *seq, int result) |
617 | { | 590 | { |
618 | struct acpi_battery *battery = seq->private; | 591 | struct acpi_battery *battery = seq->private; |
619 | char *units = "?"; | ||
620 | 592 | ||
621 | if (result) | 593 | if (result) |
622 | goto end; | 594 | goto end; |
@@ -625,189 +597,117 @@ static int acpi_battery_print_alarm(struct seq_file *seq, int result) | |||
625 | seq_printf(seq, "present: no\n"); | 597 | seq_printf(seq, "present: no\n"); |
626 | goto end; | 598 | goto end; |
627 | } | 599 | } |
628 | |||
629 | /* Battery Units */ | ||
630 | |||
631 | units = acpi_battery_power_units(battery); | ||
632 | |||
633 | seq_printf(seq, "alarm: "); | 600 | seq_printf(seq, "alarm: "); |
634 | if (!battery->alarm) | 601 | if (!battery->alarm) |
635 | seq_printf(seq, "unsupported\n"); | 602 | seq_printf(seq, "unsupported\n"); |
636 | else | 603 | else |
637 | seq_printf(seq, "%lu %sh\n", battery->alarm, units); | 604 | seq_printf(seq, "%u %sh\n", battery->alarm, |
638 | 605 | acpi_battery_units(battery)); | |
639 | end: | 606 | end: |
640 | |||
641 | if (result) | 607 | if (result) |
642 | seq_printf(seq, "ERROR: Unable to read battery alarm\n"); | 608 | seq_printf(seq, "ERROR: Unable to read battery alarm\n"); |
643 | |||
644 | return result; | 609 | return result; |
645 | } | 610 | } |
646 | 611 | ||
647 | static ssize_t | 612 | static ssize_t acpi_battery_write_alarm(struct file *file, |
648 | acpi_battery_write_alarm(struct file *file, | 613 | const char __user * buffer, |
649 | const char __user * buffer, | 614 | size_t count, loff_t * ppos) |
650 | size_t count, loff_t * ppos) | ||
651 | { | 615 | { |
652 | int result = 0; | 616 | int result = 0; |
653 | char alarm_string[12] = { '\0' }; | 617 | char alarm_string[12] = { '\0' }; |
654 | struct seq_file *m = file->private_data; | 618 | struct seq_file *m = file->private_data; |
655 | struct acpi_battery *battery = m->private; | 619 | struct acpi_battery *battery = m->private; |
656 | int update_result = ACPI_BATTERY_NONE_UPDATE; | ||
657 | 620 | ||
658 | if (!battery || (count > sizeof(alarm_string) - 1)) | 621 | if (!battery || (count > sizeof(alarm_string) - 1)) |
659 | return -EINVAL; | 622 | return -EINVAL; |
660 | |||
661 | mutex_lock(&battery->mutex); | ||
662 | |||
663 | result = acpi_battery_update(battery, 1, &update_result); | ||
664 | if (result) { | ||
665 | result = -ENODEV; | ||
666 | goto end; | ||
667 | } | ||
668 | |||
669 | if (!acpi_battery_present(battery)) { | 623 | if (!acpi_battery_present(battery)) { |
670 | result = -ENODEV; | 624 | result = -ENODEV; |
671 | goto end; | 625 | goto end; |
672 | } | 626 | } |
673 | |||
674 | if (copy_from_user(alarm_string, buffer, count)) { | 627 | if (copy_from_user(alarm_string, buffer, count)) { |
675 | result = -EFAULT; | 628 | result = -EFAULT; |
676 | goto end; | 629 | goto end; |
677 | } | 630 | } |
678 | |||
679 | alarm_string[count] = '\0'; | 631 | alarm_string[count] = '\0'; |
680 | 632 | battery->alarm = simple_strtol(alarm_string, NULL, 0); | |
681 | result = acpi_battery_set_alarm(battery, | 633 | result = acpi_battery_set_alarm(battery); |
682 | simple_strtoul(alarm_string, NULL, 0)); | ||
683 | if (result) | ||
684 | goto end; | ||
685 | |||
686 | end: | 634 | end: |
687 | |||
688 | acpi_battery_check_result(battery, result); | ||
689 | |||
690 | if (!result) | 635 | if (!result) |
691 | result = count; | 636 | return count; |
692 | |||
693 | mutex_unlock(&battery->mutex); | ||
694 | |||
695 | return result; | 637 | return result; |
696 | } | 638 | } |
697 | 639 | ||
698 | typedef int(*print_func)(struct seq_file *seq, int result); | 640 | typedef int(*print_func)(struct seq_file *seq, int result); |
699 | typedef int(*get_func)(struct acpi_battery *battery); | 641 | |
700 | 642 | static print_func acpi_print_funcs[ACPI_BATTERY_NUMFILES] = { | |
701 | static struct acpi_read_mux { | 643 | acpi_battery_print_info, |
702 | print_func print; | 644 | acpi_battery_print_state, |
703 | get_func get; | 645 | acpi_battery_print_alarm, |
704 | } acpi_read_funcs[ACPI_BATTERY_NUMFILES] = { | ||
705 | {.get = acpi_battery_get_info, .print = acpi_battery_print_info}, | ||
706 | {.get = acpi_battery_get_state, .print = acpi_battery_print_state}, | ||
707 | {.get = acpi_battery_get_alarm, .print = acpi_battery_print_alarm}, | ||
708 | }; | 646 | }; |
709 | 647 | ||
710 | static int acpi_battery_read(int fid, struct seq_file *seq) | 648 | static int acpi_battery_read(int fid, struct seq_file *seq) |
711 | { | 649 | { |
712 | struct acpi_battery *battery = seq->private; | 650 | struct acpi_battery *battery = seq->private; |
713 | int result = 0; | 651 | int result = acpi_battery_update(battery); |
714 | int update_result = ACPI_BATTERY_NONE_UPDATE; | 652 | return acpi_print_funcs[fid](seq, result); |
715 | int update = 0; | 653 | } |
716 | 654 | ||
717 | mutex_lock(&battery->mutex); | 655 | #define DECLARE_FILE_FUNCTIONS(_name) \ |
718 | 656 | static int acpi_battery_read_##_name(struct seq_file *seq, void *offset) \ | |
719 | update = (get_seconds() - battery->update_time[fid] >= update_time); | 657 | { \ |
720 | update = (update | battery->flags.update[fid]); | 658 | return acpi_battery_read(_name##_tag, seq); \ |
721 | 659 | } \ | |
722 | result = acpi_battery_update(battery, update, &update_result); | 660 | static int acpi_battery_##_name##_open_fs(struct inode *inode, struct file *file) \ |
723 | if (result) | 661 | { \ |
724 | goto end; | 662 | return single_open(file, acpi_battery_read_##_name, PDE(inode)->data); \ |
725 | 663 | } | |
726 | if (update_result == ACPI_BATTERY_EASY_UPDATE) { | 664 | |
727 | result = acpi_read_funcs[fid].get(battery); | 665 | DECLARE_FILE_FUNCTIONS(info); |
728 | if (result) | 666 | DECLARE_FILE_FUNCTIONS(state); |
729 | goto end; | 667 | DECLARE_FILE_FUNCTIONS(alarm); |
668 | |||
669 | #undef DECLARE_FILE_FUNCTIONS | ||
670 | |||
671 | #define FILE_DESCRIPTION_RO(_name) \ | ||
672 | { \ | ||
673 | .name = __stringify(_name), \ | ||
674 | .mode = S_IRUGO, \ | ||
675 | .ops = { \ | ||
676 | .open = acpi_battery_##_name##_open_fs, \ | ||
677 | .read = seq_read, \ | ||
678 | .llseek = seq_lseek, \ | ||
679 | .release = single_release, \ | ||
680 | .owner = THIS_MODULE, \ | ||
681 | }, \ | ||
682 | } | ||
683 | |||
684 | #define FILE_DESCRIPTION_RW(_name) \ | ||
685 | { \ | ||
686 | .name = __stringify(_name), \ | ||
687 | .mode = S_IFREG | S_IRUGO | S_IWUSR, \ | ||
688 | .ops = { \ | ||
689 | .open = acpi_battery_##_name##_open_fs, \ | ||
690 | .read = seq_read, \ | ||
691 | .llseek = seq_lseek, \ | ||
692 | .write = acpi_battery_write_##_name, \ | ||
693 | .release = single_release, \ | ||
694 | .owner = THIS_MODULE, \ | ||
695 | }, \ | ||
730 | } | 696 | } |
731 | 697 | ||
732 | end: | ||
733 | result = acpi_read_funcs[fid].print(seq, result); | ||
734 | acpi_battery_check_result(battery, result); | ||
735 | battery->flags.update[fid] = result; | ||
736 | mutex_unlock(&battery->mutex); | ||
737 | return result; | ||
738 | } | ||
739 | |||
740 | static int acpi_battery_read_info(struct seq_file *seq, void *offset) | ||
741 | { | ||
742 | return acpi_battery_read(ACPI_BATTERY_INFO, seq); | ||
743 | } | ||
744 | |||
745 | static int acpi_battery_read_state(struct seq_file *seq, void *offset) | ||
746 | { | ||
747 | return acpi_battery_read(ACPI_BATTERY_STATE, seq); | ||
748 | } | ||
749 | |||
750 | static int acpi_battery_read_alarm(struct seq_file *seq, void *offset) | ||
751 | { | ||
752 | return acpi_battery_read(ACPI_BATTERY_ALARM, seq); | ||
753 | } | ||
754 | |||
755 | static int acpi_battery_info_open_fs(struct inode *inode, struct file *file) | ||
756 | { | ||
757 | return single_open(file, acpi_battery_read_info, PDE(inode)->data); | ||
758 | } | ||
759 | |||
760 | static int acpi_battery_state_open_fs(struct inode *inode, struct file *file) | ||
761 | { | ||
762 | return single_open(file, acpi_battery_read_state, PDE(inode)->data); | ||
763 | } | ||
764 | |||
765 | static int acpi_battery_alarm_open_fs(struct inode *inode, struct file *file) | ||
766 | { | ||
767 | return single_open(file, acpi_battery_read_alarm, PDE(inode)->data); | ||
768 | } | ||
769 | |||
770 | static struct battery_file { | 698 | static struct battery_file { |
771 | struct file_operations ops; | 699 | struct file_operations ops; |
772 | mode_t mode; | 700 | mode_t mode; |
773 | char *name; | 701 | char *name; |
774 | } acpi_battery_file[] = { | 702 | } acpi_battery_file[] = { |
775 | { | 703 | FILE_DESCRIPTION_RO(info), |
776 | .name = "info", | 704 | FILE_DESCRIPTION_RO(state), |
777 | .mode = S_IRUGO, | 705 | FILE_DESCRIPTION_RW(alarm), |
778 | .ops = { | ||
779 | .open = acpi_battery_info_open_fs, | ||
780 | .read = seq_read, | ||
781 | .llseek = seq_lseek, | ||
782 | .release = single_release, | ||
783 | .owner = THIS_MODULE, | ||
784 | }, | ||
785 | }, | ||
786 | { | ||
787 | .name = "state", | ||
788 | .mode = S_IRUGO, | ||
789 | .ops = { | ||
790 | .open = acpi_battery_state_open_fs, | ||
791 | .read = seq_read, | ||
792 | .llseek = seq_lseek, | ||
793 | .release = single_release, | ||
794 | .owner = THIS_MODULE, | ||
795 | }, | ||
796 | }, | ||
797 | { | ||
798 | .name = "alarm", | ||
799 | .mode = S_IFREG | S_IRUGO | S_IWUSR, | ||
800 | .ops = { | ||
801 | .open = acpi_battery_alarm_open_fs, | ||
802 | .read = seq_read, | ||
803 | .write = acpi_battery_write_alarm, | ||
804 | .llseek = seq_lseek, | ||
805 | .release = single_release, | ||
806 | .owner = THIS_MODULE, | ||
807 | }, | ||
808 | }, | ||
809 | }; | 706 | }; |
810 | 707 | ||
708 | #undef FILE_DESCRIPTION_RO | ||
709 | #undef FILE_DESCRIPTION_RW | ||
710 | |||
811 | static int acpi_battery_add_fs(struct acpi_device *device) | 711 | static int acpi_battery_add_fs(struct acpi_device *device) |
812 | { | 712 | { |
813 | struct proc_dir_entry *entry = NULL; | 713 | struct proc_dir_entry *entry = NULL; |
@@ -832,25 +732,24 @@ static int acpi_battery_add_fs(struct acpi_device *device) | |||
832 | entry->owner = THIS_MODULE; | 732 | entry->owner = THIS_MODULE; |
833 | } | 733 | } |
834 | } | 734 | } |
835 | |||
836 | return 0; | 735 | return 0; |
837 | } | 736 | } |
838 | 737 | ||
839 | static int acpi_battery_remove_fs(struct acpi_device *device) | 738 | static void acpi_battery_remove_fs(struct acpi_device *device) |
840 | { | 739 | { |
841 | int i; | 740 | int i; |
842 | if (acpi_device_dir(device)) { | 741 | if (!acpi_device_dir(device)) |
843 | for (i = 0; i < ACPI_BATTERY_NUMFILES; ++i) { | 742 | return; |
844 | remove_proc_entry(acpi_battery_file[i].name, | 743 | for (i = 0; i < ACPI_BATTERY_NUMFILES; ++i) |
744 | remove_proc_entry(acpi_battery_file[i].name, | ||
845 | acpi_device_dir(device)); | 745 | acpi_device_dir(device)); |
846 | } | ||
847 | remove_proc_entry(acpi_device_bid(device), acpi_battery_dir); | ||
848 | acpi_device_dir(device) = NULL; | ||
849 | } | ||
850 | 746 | ||
851 | return 0; | 747 | remove_proc_entry(acpi_device_bid(device), acpi_battery_dir); |
748 | acpi_device_dir(device) = NULL; | ||
852 | } | 749 | } |
853 | 750 | ||
751 | #endif | ||
752 | |||
854 | /* -------------------------------------------------------------------------- | 753 | /* -------------------------------------------------------------------------- |
855 | Driver Interface | 754 | Driver Interface |
856 | -------------------------------------------------------------------------- */ | 755 | -------------------------------------------------------------------------- */ |
@@ -858,33 +757,19 @@ static int acpi_battery_remove_fs(struct acpi_device *device) | |||
858 | static void acpi_battery_notify(acpi_handle handle, u32 event, void *data) | 757 | static void acpi_battery_notify(acpi_handle handle, u32 event, void *data) |
859 | { | 758 | { |
860 | struct acpi_battery *battery = data; | 759 | struct acpi_battery *battery = data; |
861 | struct acpi_device *device = NULL; | 760 | struct acpi_device *device; |
862 | |||
863 | if (!battery) | 761 | if (!battery) |
864 | return; | 762 | return; |
865 | |||
866 | device = battery->device; | 763 | device = battery->device; |
867 | 764 | acpi_battery_update(battery); | |
868 | switch (event) { | 765 | acpi_bus_generate_proc_event(device, event, |
869 | case ACPI_BATTERY_NOTIFY_STATUS: | 766 | acpi_battery_present(battery)); |
870 | case ACPI_BATTERY_NOTIFY_INFO: | 767 | acpi_bus_generate_netlink_event(device->pnp.device_class, |
871 | case ACPI_NOTIFY_BUS_CHECK: | 768 | device->dev.bus_id, event, |
872 | case ACPI_NOTIFY_DEVICE_CHECK: | ||
873 | device = battery->device; | ||
874 | acpi_battery_notify_update(battery); | ||
875 | acpi_bus_generate_proc_event(device, event, | ||
876 | acpi_battery_present(battery)); | 769 | acpi_battery_present(battery)); |
877 | acpi_bus_generate_netlink_event(device->pnp.device_class, | 770 | /* acpi_batter_update could remove power_supply object */ |
878 | device->dev.bus_id, event, | 771 | if (battery->bat.dev) |
879 | acpi_battery_present(battery)); | 772 | kobject_uevent(&battery->bat.dev->kobj, KOBJ_CHANGE); |
880 | break; | ||
881 | default: | ||
882 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | ||
883 | "Unsupported event [0x%x]\n", event)); | ||
884 | break; | ||
885 | } | ||
886 | |||
887 | return; | ||
888 | } | 773 | } |
889 | 774 | ||
890 | static int acpi_battery_add(struct acpi_device *device) | 775 | static int acpi_battery_add(struct acpi_device *device) |
@@ -892,33 +777,22 @@ static int acpi_battery_add(struct acpi_device *device) | |||
892 | int result = 0; | 777 | int result = 0; |
893 | acpi_status status = 0; | 778 | acpi_status status = 0; |
894 | struct acpi_battery *battery = NULL; | 779 | struct acpi_battery *battery = NULL; |
895 | |||
896 | if (!device) | 780 | if (!device) |
897 | return -EINVAL; | 781 | return -EINVAL; |
898 | |||
899 | battery = kzalloc(sizeof(struct acpi_battery), GFP_KERNEL); | 782 | battery = kzalloc(sizeof(struct acpi_battery), GFP_KERNEL); |
900 | if (!battery) | 783 | if (!battery) |
901 | return -ENOMEM; | 784 | return -ENOMEM; |
902 | |||
903 | mutex_init(&battery->mutex); | ||
904 | |||
905 | mutex_lock(&battery->mutex); | ||
906 | |||
907 | battery->device = device; | 785 | battery->device = device; |
908 | strcpy(acpi_device_name(device), ACPI_BATTERY_DEVICE_NAME); | 786 | strcpy(acpi_device_name(device), ACPI_BATTERY_DEVICE_NAME); |
909 | strcpy(acpi_device_class(device), ACPI_BATTERY_CLASS); | 787 | strcpy(acpi_device_class(device), ACPI_BATTERY_CLASS); |
910 | acpi_driver_data(device) = battery; | 788 | acpi_driver_data(device) = battery; |
911 | 789 | mutex_init(&battery->lock); | |
912 | result = acpi_battery_get_status(battery); | 790 | acpi_battery_update(battery); |
913 | if (result) | 791 | #ifdef CONFIG_ACPI_PROCFS |
914 | goto end; | ||
915 | |||
916 | battery->flags.init_update = 1; | ||
917 | |||
918 | result = acpi_battery_add_fs(device); | 792 | result = acpi_battery_add_fs(device); |
919 | if (result) | 793 | if (result) |
920 | goto end; | 794 | goto end; |
921 | 795 | #endif | |
922 | status = acpi_install_notify_handler(device->handle, | 796 | status = acpi_install_notify_handler(device->handle, |
923 | ACPI_ALL_NOTIFY, | 797 | ACPI_ALL_NOTIFY, |
924 | acpi_battery_notify, battery); | 798 | acpi_battery_notify, battery); |
@@ -927,20 +801,16 @@ static int acpi_battery_add(struct acpi_device *device) | |||
927 | result = -ENODEV; | 801 | result = -ENODEV; |
928 | goto end; | 802 | goto end; |
929 | } | 803 | } |
930 | |||
931 | printk(KERN_INFO PREFIX "%s Slot [%s] (battery %s)\n", | 804 | printk(KERN_INFO PREFIX "%s Slot [%s] (battery %s)\n", |
932 | ACPI_BATTERY_DEVICE_NAME, acpi_device_bid(device), | 805 | ACPI_BATTERY_DEVICE_NAME, acpi_device_bid(device), |
933 | device->status.battery_present ? "present" : "absent"); | 806 | device->status.battery_present ? "present" : "absent"); |
934 | |||
935 | end: | 807 | end: |
936 | |||
937 | if (result) { | 808 | if (result) { |
809 | #ifdef CONFIG_ACPI_PROCFS | ||
938 | acpi_battery_remove_fs(device); | 810 | acpi_battery_remove_fs(device); |
811 | #endif | ||
939 | kfree(battery); | 812 | kfree(battery); |
940 | } | 813 | } |
941 | |||
942 | mutex_unlock(&battery->mutex); | ||
943 | |||
944 | return result; | 814 | return result; |
945 | } | 815 | } |
946 | 816 | ||
@@ -951,27 +821,16 @@ static int acpi_battery_remove(struct acpi_device *device, int type) | |||
951 | 821 | ||
952 | if (!device || !acpi_driver_data(device)) | 822 | if (!device || !acpi_driver_data(device)) |
953 | return -EINVAL; | 823 | return -EINVAL; |
954 | |||
955 | battery = acpi_driver_data(device); | 824 | battery = acpi_driver_data(device); |
956 | |||
957 | mutex_lock(&battery->mutex); | ||
958 | |||
959 | status = acpi_remove_notify_handler(device->handle, | 825 | status = acpi_remove_notify_handler(device->handle, |
960 | ACPI_ALL_NOTIFY, | 826 | ACPI_ALL_NOTIFY, |
961 | acpi_battery_notify); | 827 | acpi_battery_notify); |
962 | 828 | #ifdef CONFIG_ACPI_PROCFS | |
963 | acpi_battery_remove_fs(device); | 829 | acpi_battery_remove_fs(device); |
964 | 830 | #endif | |
965 | kfree(battery->bif_data.pointer); | 831 | sysfs_remove_battery(battery); |
966 | 832 | mutex_destroy(&battery->lock); | |
967 | kfree(battery->bst_data.pointer); | ||
968 | |||
969 | mutex_unlock(&battery->mutex); | ||
970 | |||
971 | mutex_destroy(&battery->mutex); | ||
972 | |||
973 | kfree(battery); | 833 | kfree(battery); |
974 | |||
975 | return 0; | 834 | return 0; |
976 | } | 835 | } |
977 | 836 | ||
@@ -979,44 +838,49 @@ static int acpi_battery_remove(struct acpi_device *device, int type) | |||
979 | static int acpi_battery_resume(struct acpi_device *device) | 838 | static int acpi_battery_resume(struct acpi_device *device) |
980 | { | 839 | { |
981 | struct acpi_battery *battery; | 840 | struct acpi_battery *battery; |
982 | |||
983 | if (!device) | 841 | if (!device) |
984 | return -EINVAL; | 842 | return -EINVAL; |
985 | 843 | battery = acpi_driver_data(device); | |
986 | battery = device->driver_data; | 844 | battery->update_time = 0; |
987 | 845 | acpi_battery_update(battery); | |
988 | battery->flags.init_update = 1; | ||
989 | |||
990 | return 0; | 846 | return 0; |
991 | } | 847 | } |
992 | 848 | ||
849 | static struct acpi_driver acpi_battery_driver = { | ||
850 | .name = "battery", | ||
851 | .class = ACPI_BATTERY_CLASS, | ||
852 | .ids = battery_device_ids, | ||
853 | .ops = { | ||
854 | .add = acpi_battery_add, | ||
855 | .resume = acpi_battery_resume, | ||
856 | .remove = acpi_battery_remove, | ||
857 | }, | ||
858 | }; | ||
859 | |||
993 | static int __init acpi_battery_init(void) | 860 | static int __init acpi_battery_init(void) |
994 | { | 861 | { |
995 | int result; | ||
996 | |||
997 | if (acpi_disabled) | 862 | if (acpi_disabled) |
998 | return -ENODEV; | 863 | return -ENODEV; |
999 | 864 | #ifdef CONFIG_ACPI_PROCFS | |
1000 | acpi_battery_dir = acpi_lock_battery_dir(); | 865 | acpi_battery_dir = acpi_lock_battery_dir(); |
1001 | if (!acpi_battery_dir) | 866 | if (!acpi_battery_dir) |
1002 | return -ENODEV; | 867 | return -ENODEV; |
1003 | 868 | #endif | |
1004 | result = acpi_bus_register_driver(&acpi_battery_driver); | 869 | if (acpi_bus_register_driver(&acpi_battery_driver) < 0) { |
1005 | if (result < 0) { | 870 | #ifdef CONFIG_ACPI_PROCFS |
1006 | acpi_unlock_battery_dir(acpi_battery_dir); | 871 | acpi_unlock_battery_dir(acpi_battery_dir); |
872 | #endif | ||
1007 | return -ENODEV; | 873 | return -ENODEV; |
1008 | } | 874 | } |
1009 | |||
1010 | return 0; | 875 | return 0; |
1011 | } | 876 | } |
1012 | 877 | ||
1013 | static void __exit acpi_battery_exit(void) | 878 | static void __exit acpi_battery_exit(void) |
1014 | { | 879 | { |
1015 | acpi_bus_unregister_driver(&acpi_battery_driver); | 880 | acpi_bus_unregister_driver(&acpi_battery_driver); |
1016 | 881 | #ifdef CONFIG_ACPI_PROCFS | |
1017 | acpi_unlock_battery_dir(acpi_battery_dir); | 882 | acpi_unlock_battery_dir(acpi_battery_dir); |
1018 | 883 | #endif | |
1019 | return; | ||
1020 | } | 884 | } |
1021 | 885 | ||
1022 | module_init(acpi_battery_init); | 886 | module_init(acpi_battery_init); |
diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c index 9ba778a2b484..49d432d0a12c 100644 --- a/drivers/acpi/bus.c +++ b/drivers/acpi/bus.c | |||
@@ -194,16 +194,14 @@ int acpi_bus_set_power(acpi_handle handle, int state) | |||
194 | 194 | ||
195 | if (!device->flags.power_manageable) { | 195 | if (!device->flags.power_manageable) { |
196 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device `[%s]' is not power manageable\n", | 196 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device `[%s]' is not power manageable\n", |
197 | device->dev.kobj.name)); | 197 | kobject_name(&device->dev.kobj))); |
198 | return -ENODEV; | 198 | return -ENODEV; |
199 | } | 199 | } |
200 | /* | 200 | /* |
201 | * Get device's current power state if it's unknown | 201 | * Get device's current power state |
202 | * This means device power state isn't initialized or previous setting failed | ||
203 | */ | 202 | */ |
204 | if ((device->power.state == ACPI_STATE_UNKNOWN) || device->flags.force_power_state) | 203 | acpi_bus_get_power(device->handle, &device->power.state); |
205 | acpi_bus_get_power(device->handle, &device->power.state); | 204 | if (state == device->power.state) { |
206 | if ((state == device->power.state) && !device->flags.force_power_state) { | ||
207 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at D%d\n", | 205 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at D%d\n", |
208 | state)); | 206 | state)); |
209 | return 0; | 207 | return 0; |
@@ -262,10 +260,12 @@ int acpi_bus_set_power(acpi_handle handle, int state) | |||
262 | printk(KERN_WARNING PREFIX | 260 | printk(KERN_WARNING PREFIX |
263 | "Transitioning device [%s] to D%d\n", | 261 | "Transitioning device [%s] to D%d\n", |
264 | device->pnp.bus_id, state); | 262 | device->pnp.bus_id, state); |
265 | else | 263 | else { |
264 | device->power.state = state; | ||
266 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 265 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
267 | "Device [%s] transitioned to D%d\n", | 266 | "Device [%s] transitioned to D%d\n", |
268 | device->pnp.bus_id, state)); | 267 | device->pnp.bus_id, state)); |
268 | } | ||
269 | 269 | ||
270 | return result; | 270 | return result; |
271 | } | 271 | } |
@@ -284,15 +284,11 @@ DECLARE_WAIT_QUEUE_HEAD(acpi_bus_event_queue); | |||
284 | 284 | ||
285 | extern int event_is_open; | 285 | extern int event_is_open; |
286 | 286 | ||
287 | int acpi_bus_generate_proc_event(struct acpi_device *device, u8 type, int data) | 287 | int acpi_bus_generate_proc_event4(const char *device_class, const char *bus_id, u8 type, int data) |
288 | { | 288 | { |
289 | struct acpi_bus_event *event = NULL; | 289 | struct acpi_bus_event *event; |
290 | unsigned long flags = 0; | 290 | unsigned long flags = 0; |
291 | 291 | ||
292 | |||
293 | if (!device) | ||
294 | return -EINVAL; | ||
295 | |||
296 | /* drop event on the floor if no one's listening */ | 292 | /* drop event on the floor if no one's listening */ |
297 | if (!event_is_open) | 293 | if (!event_is_open) |
298 | return 0; | 294 | return 0; |
@@ -301,8 +297,8 @@ int acpi_bus_generate_proc_event(struct acpi_device *device, u8 type, int data) | |||
301 | if (!event) | 297 | if (!event) |
302 | return -ENOMEM; | 298 | return -ENOMEM; |
303 | 299 | ||
304 | strcpy(event->device_class, device->pnp.device_class); | 300 | strcpy(event->device_class, device_class); |
305 | strcpy(event->bus_id, device->pnp.bus_id); | 301 | strcpy(event->bus_id, bus_id); |
306 | event->type = type; | 302 | event->type = type; |
307 | event->data = data; | 303 | event->data = data; |
308 | 304 | ||
@@ -313,6 +309,17 @@ int acpi_bus_generate_proc_event(struct acpi_device *device, u8 type, int data) | |||
313 | wake_up_interruptible(&acpi_bus_event_queue); | 309 | wake_up_interruptible(&acpi_bus_event_queue); |
314 | 310 | ||
315 | return 0; | 311 | return 0; |
312 | |||
313 | } | ||
314 | |||
315 | EXPORT_SYMBOL_GPL(acpi_bus_generate_proc_event4); | ||
316 | |||
317 | int acpi_bus_generate_proc_event(struct acpi_device *device, u8 type, int data) | ||
318 | { | ||
319 | if (!device) | ||
320 | return -EINVAL; | ||
321 | return acpi_bus_generate_proc_event4(device->pnp.device_class, | ||
322 | device->pnp.bus_id, type, data); | ||
316 | } | 323 | } |
317 | 324 | ||
318 | EXPORT_SYMBOL(acpi_bus_generate_proc_event); | 325 | EXPORT_SYMBOL(acpi_bus_generate_proc_event); |
diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c index 2e79a3395ecf..24a7865a57cb 100644 --- a/drivers/acpi/button.c +++ b/drivers/acpi/button.c | |||
@@ -78,6 +78,7 @@ MODULE_DEVICE_TABLE(acpi, button_device_ids); | |||
78 | 78 | ||
79 | static int acpi_button_add(struct acpi_device *device); | 79 | static int acpi_button_add(struct acpi_device *device); |
80 | static int acpi_button_remove(struct acpi_device *device, int type); | 80 | static int acpi_button_remove(struct acpi_device *device, int type); |
81 | static int acpi_button_resume(struct acpi_device *device); | ||
81 | static int acpi_button_info_open_fs(struct inode *inode, struct file *file); | 82 | static int acpi_button_info_open_fs(struct inode *inode, struct file *file); |
82 | static int acpi_button_state_open_fs(struct inode *inode, struct file *file); | 83 | static int acpi_button_state_open_fs(struct inode *inode, struct file *file); |
83 | 84 | ||
@@ -87,6 +88,7 @@ static struct acpi_driver acpi_button_driver = { | |||
87 | .ids = button_device_ids, | 88 | .ids = button_device_ids, |
88 | .ops = { | 89 | .ops = { |
89 | .add = acpi_button_add, | 90 | .add = acpi_button_add, |
91 | .resume = acpi_button_resume, | ||
90 | .remove = acpi_button_remove, | 92 | .remove = acpi_button_remove, |
91 | }, | 93 | }, |
92 | }; | 94 | }; |
@@ -253,6 +255,19 @@ static int acpi_button_remove_fs(struct acpi_device *device) | |||
253 | /* -------------------------------------------------------------------------- | 255 | /* -------------------------------------------------------------------------- |
254 | Driver Interface | 256 | Driver Interface |
255 | -------------------------------------------------------------------------- */ | 257 | -------------------------------------------------------------------------- */ |
258 | static int acpi_lid_send_state(struct acpi_button *button) | ||
259 | { | ||
260 | unsigned long state; | ||
261 | acpi_status status; | ||
262 | |||
263 | status = acpi_evaluate_integer(button->device->handle, "_LID", NULL, | ||
264 | &state); | ||
265 | if (ACPI_FAILURE(status)) | ||
266 | return -ENODEV; | ||
267 | /* input layer checks if event is redundant */ | ||
268 | input_report_switch(button->input, SW_LID, !state); | ||
269 | return 0; | ||
270 | } | ||
256 | 271 | ||
257 | static void acpi_button_notify(acpi_handle handle, u32 event, void *data) | 272 | static void acpi_button_notify(acpi_handle handle, u32 event, void *data) |
258 | { | 273 | { |
@@ -265,15 +280,8 @@ static void acpi_button_notify(acpi_handle handle, u32 event, void *data) | |||
265 | switch (event) { | 280 | switch (event) { |
266 | case ACPI_BUTTON_NOTIFY_STATUS: | 281 | case ACPI_BUTTON_NOTIFY_STATUS: |
267 | input = button->input; | 282 | input = button->input; |
268 | |||
269 | if (button->type == ACPI_BUTTON_TYPE_LID) { | 283 | if (button->type == ACPI_BUTTON_TYPE_LID) { |
270 | struct acpi_handle *handle = button->device->handle; | 284 | acpi_lid_send_state(button); |
271 | unsigned long state; | ||
272 | |||
273 | if (!ACPI_FAILURE(acpi_evaluate_integer(handle, "_LID", | ||
274 | NULL, &state))) | ||
275 | input_report_switch(input, SW_LID, !state); | ||
276 | |||
277 | } else { | 285 | } else { |
278 | int keycode = test_bit(KEY_SLEEP, input->keybit) ? | 286 | int keycode = test_bit(KEY_SLEEP, input->keybit) ? |
279 | KEY_SLEEP : KEY_POWER; | 287 | KEY_SLEEP : KEY_POWER; |
@@ -336,6 +344,17 @@ static int acpi_button_install_notify_handlers(struct acpi_button *button) | |||
336 | return ACPI_FAILURE(status) ? -ENODEV : 0; | 344 | return ACPI_FAILURE(status) ? -ENODEV : 0; |
337 | } | 345 | } |
338 | 346 | ||
347 | static int acpi_button_resume(struct acpi_device *device) | ||
348 | { | ||
349 | struct acpi_button *button; | ||
350 | if (!device) | ||
351 | return -EINVAL; | ||
352 | button = acpi_driver_data(device); | ||
353 | if (button && button->type == ACPI_BUTTON_TYPE_LID) | ||
354 | return acpi_lid_send_state(button); | ||
355 | return 0; | ||
356 | } | ||
357 | |||
339 | static void acpi_button_remove_notify_handlers(struct acpi_button *button) | 358 | static void acpi_button_remove_notify_handlers(struct acpi_button *button) |
340 | { | 359 | { |
341 | switch (button->type) { | 360 | switch (button->type) { |
@@ -434,18 +453,18 @@ static int acpi_button_add(struct acpi_device *device) | |||
434 | switch (button->type) { | 453 | switch (button->type) { |
435 | case ACPI_BUTTON_TYPE_POWER: | 454 | case ACPI_BUTTON_TYPE_POWER: |
436 | case ACPI_BUTTON_TYPE_POWERF: | 455 | case ACPI_BUTTON_TYPE_POWERF: |
437 | input->evbit[0] = BIT(EV_KEY); | 456 | input->evbit[0] = BIT_MASK(EV_KEY); |
438 | set_bit(KEY_POWER, input->keybit); | 457 | set_bit(KEY_POWER, input->keybit); |
439 | break; | 458 | break; |
440 | 459 | ||
441 | case ACPI_BUTTON_TYPE_SLEEP: | 460 | case ACPI_BUTTON_TYPE_SLEEP: |
442 | case ACPI_BUTTON_TYPE_SLEEPF: | 461 | case ACPI_BUTTON_TYPE_SLEEPF: |
443 | input->evbit[0] = BIT(EV_KEY); | 462 | input->evbit[0] = BIT_MASK(EV_KEY); |
444 | set_bit(KEY_SLEEP, input->keybit); | 463 | set_bit(KEY_SLEEP, input->keybit); |
445 | break; | 464 | break; |
446 | 465 | ||
447 | case ACPI_BUTTON_TYPE_LID: | 466 | case ACPI_BUTTON_TYPE_LID: |
448 | input->evbit[0] = BIT(EV_SW); | 467 | input->evbit[0] = BIT_MASK(EV_SW); |
449 | set_bit(SW_LID, input->swbit); | 468 | set_bit(SW_LID, input->swbit); |
450 | break; | 469 | break; |
451 | } | 470 | } |
@@ -453,6 +472,8 @@ static int acpi_button_add(struct acpi_device *device) | |||
453 | error = input_register_device(input); | 472 | error = input_register_device(input); |
454 | if (error) | 473 | if (error) |
455 | goto err_remove_handlers; | 474 | goto err_remove_handlers; |
475 | if (button->type == ACPI_BUTTON_TYPE_LID) | ||
476 | acpi_lid_send_state(button); | ||
456 | 477 | ||
457 | if (device->wakeup.flags.valid) { | 478 | if (device->wakeup.flags.valid) { |
458 | /* Button's GPE is run-wake GPE */ | 479 | /* Button's GPE is run-wake GPE */ |
diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c index 3f7935ab0cf5..d6ddb547f2d9 100644 --- a/drivers/acpi/ec.c +++ b/drivers/acpi/ec.c | |||
@@ -65,16 +65,19 @@ enum ec_command { | |||
65 | /* EC events */ | 65 | /* EC events */ |
66 | enum ec_event { | 66 | enum ec_event { |
67 | ACPI_EC_EVENT_OBF_1 = 1, /* Output buffer full */ | 67 | ACPI_EC_EVENT_OBF_1 = 1, /* Output buffer full */ |
68 | ACPI_EC_EVENT_IBF_0, /* Input buffer empty */ | 68 | ACPI_EC_EVENT_IBF_0, /* Input buffer empty */ |
69 | }; | 69 | }; |
70 | 70 | ||
71 | #define ACPI_EC_DELAY 500 /* Wait 500ms max. during EC ops */ | 71 | #define ACPI_EC_DELAY 500 /* Wait 500ms max. during EC ops */ |
72 | #define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */ | 72 | #define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */ |
73 | 73 | ||
74 | static enum ec_mode { | 74 | enum { |
75 | EC_INTR = 1, /* Output buffer full */ | 75 | EC_FLAGS_WAIT_GPE = 0, /* Don't check status until GPE arrives */ |
76 | EC_POLL, /* Input buffer empty */ | 76 | EC_FLAGS_QUERY_PENDING, /* Query is pending */ |
77 | } acpi_ec_mode = EC_INTR; | 77 | EC_FLAGS_GPE_MODE, /* Expect GPE to be sent for status change */ |
78 | EC_FLAGS_NO_ADDRESS_GPE, /* Expect GPE only for non-address event */ | ||
79 | EC_FLAGS_ADDRESS, /* Address is being written */ | ||
80 | }; | ||
78 | 81 | ||
79 | static int acpi_ec_remove(struct acpi_device *device, int type); | 82 | static int acpi_ec_remove(struct acpi_device *device, int type); |
80 | static int acpi_ec_start(struct acpi_device *device); | 83 | static int acpi_ec_start(struct acpi_device *device); |
@@ -116,11 +119,11 @@ static struct acpi_ec { | |||
116 | unsigned long command_addr; | 119 | unsigned long command_addr; |
117 | unsigned long data_addr; | 120 | unsigned long data_addr; |
118 | unsigned long global_lock; | 121 | unsigned long global_lock; |
122 | unsigned long flags; | ||
119 | struct mutex lock; | 123 | struct mutex lock; |
120 | atomic_t query_pending; | ||
121 | atomic_t event_count; | ||
122 | wait_queue_head_t wait; | 124 | wait_queue_head_t wait; |
123 | struct list_head list; | 125 | struct list_head list; |
126 | u8 handlers_installed; | ||
124 | } *boot_ec, *first_ec; | 127 | } *boot_ec, *first_ec; |
125 | 128 | ||
126 | /* -------------------------------------------------------------------------- | 129 | /* -------------------------------------------------------------------------- |
@@ -147,46 +150,62 @@ static inline void acpi_ec_write_data(struct acpi_ec *ec, u8 data) | |||
147 | outb(data, ec->data_addr); | 150 | outb(data, ec->data_addr); |
148 | } | 151 | } |
149 | 152 | ||
150 | static inline int acpi_ec_check_status(struct acpi_ec *ec, enum ec_event event, | 153 | static inline int acpi_ec_check_status(struct acpi_ec *ec, enum ec_event event) |
151 | unsigned old_count) | ||
152 | { | 154 | { |
153 | u8 status = acpi_ec_read_status(ec); | 155 | if (test_bit(EC_FLAGS_WAIT_GPE, &ec->flags)) |
154 | if (old_count == atomic_read(&ec->event_count)) | ||
155 | return 0; | 156 | return 0; |
156 | if (event == ACPI_EC_EVENT_OBF_1) { | 157 | if (event == ACPI_EC_EVENT_OBF_1) { |
157 | if (status & ACPI_EC_FLAG_OBF) | 158 | if (acpi_ec_read_status(ec) & ACPI_EC_FLAG_OBF) |
158 | return 1; | 159 | return 1; |
159 | } else if (event == ACPI_EC_EVENT_IBF_0) { | 160 | } else if (event == ACPI_EC_EVENT_IBF_0) { |
160 | if (!(status & ACPI_EC_FLAG_IBF)) | 161 | if (!(acpi_ec_read_status(ec) & ACPI_EC_FLAG_IBF)) |
161 | return 1; | 162 | return 1; |
162 | } | 163 | } |
163 | 164 | ||
164 | return 0; | 165 | return 0; |
165 | } | 166 | } |
166 | 167 | ||
167 | static int acpi_ec_wait(struct acpi_ec *ec, enum ec_event event, | 168 | static int acpi_ec_wait(struct acpi_ec *ec, enum ec_event event, int force_poll) |
168 | unsigned count, int force_poll) | ||
169 | { | 169 | { |
170 | if (unlikely(force_poll) || acpi_ec_mode == EC_POLL) { | 170 | int ret = 0; |
171 | if (unlikely(test_bit(EC_FLAGS_ADDRESS, &ec->flags) && | ||
172 | test_bit(EC_FLAGS_NO_ADDRESS_GPE, &ec->flags))) | ||
173 | force_poll = 1; | ||
174 | if (likely(test_bit(EC_FLAGS_GPE_MODE, &ec->flags)) && | ||
175 | likely(!force_poll)) { | ||
176 | if (wait_event_timeout(ec->wait, acpi_ec_check_status(ec, event), | ||
177 | msecs_to_jiffies(ACPI_EC_DELAY))) | ||
178 | goto end; | ||
179 | clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags); | ||
180 | if (acpi_ec_check_status(ec, event)) { | ||
181 | if (test_bit(EC_FLAGS_ADDRESS, &ec->flags)) { | ||
182 | /* miss address GPE, don't expect it anymore */ | ||
183 | printk(KERN_INFO PREFIX "missing address confirmation," | ||
184 | "don't expect it any longer.\n"); | ||
185 | set_bit(EC_FLAGS_NO_ADDRESS_GPE, &ec->flags); | ||
186 | } else { | ||
187 | /* missing GPEs, switch back to poll mode */ | ||
188 | printk(KERN_INFO PREFIX "missing confirmations," | ||
189 | "switch off interrupt mode.\n"); | ||
190 | clear_bit(EC_FLAGS_GPE_MODE, &ec->flags); | ||
191 | } | ||
192 | goto end; | ||
193 | } | ||
194 | } else { | ||
171 | unsigned long delay = jiffies + msecs_to_jiffies(ACPI_EC_DELAY); | 195 | unsigned long delay = jiffies + msecs_to_jiffies(ACPI_EC_DELAY); |
196 | clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags); | ||
172 | while (time_before(jiffies, delay)) { | 197 | while (time_before(jiffies, delay)) { |
173 | if (acpi_ec_check_status(ec, event, 0)) | 198 | if (acpi_ec_check_status(ec, event)) |
174 | return 0; | 199 | goto end; |
175 | } | 200 | } |
176 | } else { | 201 | } |
177 | if (wait_event_timeout(ec->wait, | 202 | printk(KERN_ERR PREFIX "acpi_ec_wait timeout," |
178 | acpi_ec_check_status(ec, event, count), | ||
179 | msecs_to_jiffies(ACPI_EC_DELAY)) || | ||
180 | acpi_ec_check_status(ec, event, 0)) { | ||
181 | return 0; | ||
182 | } else { | ||
183 | printk(KERN_ERR PREFIX "acpi_ec_wait timeout," | ||
184 | " status = %d, expect_event = %d\n", | 203 | " status = %d, expect_event = %d\n", |
185 | acpi_ec_read_status(ec), event); | 204 | acpi_ec_read_status(ec), event); |
186 | } | 205 | ret = -ETIME; |
187 | } | 206 | end: |
188 | 207 | clear_bit(EC_FLAGS_ADDRESS, &ec->flags); | |
189 | return -ETIME; | 208 | return ret; |
190 | } | 209 | } |
191 | 210 | ||
192 | static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command, | 211 | static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command, |
@@ -195,39 +214,43 @@ static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command, | |||
195 | int force_poll) | 214 | int force_poll) |
196 | { | 215 | { |
197 | int result = 0; | 216 | int result = 0; |
198 | unsigned count = atomic_read(&ec->event_count); | 217 | set_bit(EC_FLAGS_WAIT_GPE, &ec->flags); |
199 | acpi_ec_write_cmd(ec, command); | 218 | acpi_ec_write_cmd(ec, command); |
200 | 219 | ||
201 | for (; wdata_len > 0; --wdata_len) { | 220 | for (; wdata_len > 0; --wdata_len) { |
202 | result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, count, force_poll); | 221 | result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, force_poll); |
203 | if (result) { | 222 | if (result) { |
204 | printk(KERN_ERR PREFIX | 223 | printk(KERN_ERR PREFIX |
205 | "write_cmd timeout, command = %d\n", command); | 224 | "write_cmd timeout, command = %d\n", command); |
206 | goto end; | 225 | goto end; |
207 | } | 226 | } |
208 | count = atomic_read(&ec->event_count); | 227 | /* mark the address byte written to EC */ |
228 | if (rdata_len + wdata_len > 1) | ||
229 | set_bit(EC_FLAGS_ADDRESS, &ec->flags); | ||
230 | set_bit(EC_FLAGS_WAIT_GPE, &ec->flags); | ||
209 | acpi_ec_write_data(ec, *(wdata++)); | 231 | acpi_ec_write_data(ec, *(wdata++)); |
210 | } | 232 | } |
211 | 233 | ||
212 | if (!rdata_len) { | 234 | if (!rdata_len) { |
213 | result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, count, force_poll); | 235 | result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, force_poll); |
214 | if (result) { | 236 | if (result) { |
215 | printk(KERN_ERR PREFIX | 237 | printk(KERN_ERR PREFIX |
216 | "finish-write timeout, command = %d\n", command); | 238 | "finish-write timeout, command = %d\n", command); |
217 | goto end; | 239 | goto end; |
218 | } | 240 | } |
219 | } else if (command == ACPI_EC_COMMAND_QUERY) { | 241 | } else if (command == ACPI_EC_COMMAND_QUERY) |
220 | atomic_set(&ec->query_pending, 0); | 242 | clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags); |
221 | } | ||
222 | 243 | ||
223 | for (; rdata_len > 0; --rdata_len) { | 244 | for (; rdata_len > 0; --rdata_len) { |
224 | result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF_1, count, force_poll); | 245 | result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF_1, force_poll); |
225 | if (result) { | 246 | if (result) { |
226 | printk(KERN_ERR PREFIX "read timeout, command = %d\n", | 247 | printk(KERN_ERR PREFIX "read timeout, command = %d\n", |
227 | command); | 248 | command); |
228 | goto end; | 249 | goto end; |
229 | } | 250 | } |
230 | count = atomic_read(&ec->event_count); | 251 | /* Don't expect GPE after last read */ |
252 | if (rdata_len > 1) | ||
253 | set_bit(EC_FLAGS_WAIT_GPE, &ec->flags); | ||
231 | *(rdata++) = acpi_ec_read_data(ec); | 254 | *(rdata++) = acpi_ec_read_data(ec); |
232 | } | 255 | } |
233 | end: | 256 | end: |
@@ -257,10 +280,7 @@ static int acpi_ec_transaction(struct acpi_ec *ec, u8 command, | |||
257 | } | 280 | } |
258 | } | 281 | } |
259 | 282 | ||
260 | /* Make sure GPE is enabled before doing transaction */ | 283 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, 0); |
261 | acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR); | ||
262 | |||
263 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, 0, 0); | ||
264 | if (status) { | 284 | if (status) { |
265 | printk(KERN_ERR PREFIX | 285 | printk(KERN_ERR PREFIX |
266 | "input buffer is not empty, aborting transaction\n"); | 286 | "input buffer is not empty, aborting transaction\n"); |
@@ -425,7 +445,7 @@ int acpi_ec_add_query_handler(struct acpi_ec *ec, u8 query_bit, | |||
425 | handler->func = func; | 445 | handler->func = func; |
426 | handler->data = data; | 446 | handler->data = data; |
427 | mutex_lock(&ec->lock); | 447 | mutex_lock(&ec->lock); |
428 | list_add_tail(&handler->node, &ec->list); | 448 | list_add(&handler->node, &ec->list); |
429 | mutex_unlock(&ec->lock); | 449 | mutex_unlock(&ec->lock); |
430 | return 0; | 450 | return 0; |
431 | } | 451 | } |
@@ -434,13 +454,12 @@ EXPORT_SYMBOL_GPL(acpi_ec_add_query_handler); | |||
434 | 454 | ||
435 | void acpi_ec_remove_query_handler(struct acpi_ec *ec, u8 query_bit) | 455 | void acpi_ec_remove_query_handler(struct acpi_ec *ec, u8 query_bit) |
436 | { | 456 | { |
437 | struct acpi_ec_query_handler *handler; | 457 | struct acpi_ec_query_handler *handler, *tmp; |
438 | mutex_lock(&ec->lock); | 458 | mutex_lock(&ec->lock); |
439 | list_for_each_entry(handler, &ec->list, node) { | 459 | list_for_each_entry_safe(handler, tmp, &ec->list, node) { |
440 | if (query_bit == handler->query_bit) { | 460 | if (query_bit == handler->query_bit) { |
441 | list_del(&handler->node); | 461 | list_del(&handler->node); |
442 | kfree(handler); | 462 | kfree(handler); |
443 | break; | ||
444 | } | 463 | } |
445 | } | 464 | } |
446 | mutex_unlock(&ec->lock); | 465 | mutex_unlock(&ec->lock); |
@@ -476,23 +495,24 @@ static void acpi_ec_gpe_query(void *ec_cxt) | |||
476 | static u32 acpi_ec_gpe_handler(void *data) | 495 | static u32 acpi_ec_gpe_handler(void *data) |
477 | { | 496 | { |
478 | acpi_status status = AE_OK; | 497 | acpi_status status = AE_OK; |
479 | u8 value; | ||
480 | struct acpi_ec *ec = data; | 498 | struct acpi_ec *ec = data; |
481 | 499 | ||
482 | atomic_inc(&ec->event_count); | 500 | clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags); |
483 | 501 | if (test_bit(EC_FLAGS_GPE_MODE, &ec->flags)) | |
484 | if (acpi_ec_mode == EC_INTR) { | ||
485 | wake_up(&ec->wait); | 502 | wake_up(&ec->wait); |
486 | } | ||
487 | 503 | ||
488 | value = acpi_ec_read_status(ec); | 504 | if (acpi_ec_read_status(ec) & ACPI_EC_FLAG_SCI) { |
489 | if ((value & ACPI_EC_FLAG_SCI) && !atomic_read(&ec->query_pending)) { | 505 | if (!test_and_set_bit(EC_FLAGS_QUERY_PENDING, &ec->flags)) |
490 | atomic_set(&ec->query_pending, 1); | 506 | status = acpi_os_execute(OSL_EC_BURST_HANDLER, |
491 | status = | 507 | acpi_ec_gpe_query, ec); |
492 | acpi_os_execute(OSL_EC_BURST_HANDLER, acpi_ec_gpe_query, ec); | 508 | } else if (unlikely(!test_bit(EC_FLAGS_GPE_MODE, &ec->flags))) { |
509 | /* this is non-query, must be confirmation */ | ||
510 | printk(KERN_INFO PREFIX "non-query interrupt received," | ||
511 | " switching to interrupt mode\n"); | ||
512 | set_bit(EC_FLAGS_GPE_MODE, &ec->flags); | ||
493 | } | 513 | } |
494 | 514 | ||
495 | return status == AE_OK ? | 515 | return ACPI_SUCCESS(status) ? |
496 | ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED; | 516 | ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED; |
497 | } | 517 | } |
498 | 518 | ||
@@ -641,13 +661,10 @@ static struct acpi_ec *make_acpi_ec(void) | |||
641 | struct acpi_ec *ec = kzalloc(sizeof(struct acpi_ec), GFP_KERNEL); | 661 | struct acpi_ec *ec = kzalloc(sizeof(struct acpi_ec), GFP_KERNEL); |
642 | if (!ec) | 662 | if (!ec) |
643 | return NULL; | 663 | return NULL; |
644 | 664 | ec->flags = 1 << EC_FLAGS_QUERY_PENDING; | |
645 | atomic_set(&ec->query_pending, 1); | ||
646 | atomic_set(&ec->event_count, 1); | ||
647 | mutex_init(&ec->lock); | 665 | mutex_init(&ec->lock); |
648 | init_waitqueue_head(&ec->wait); | 666 | init_waitqueue_head(&ec->wait); |
649 | INIT_LIST_HEAD(&ec->list); | 667 | INIT_LIST_HEAD(&ec->list); |
650 | |||
651 | return ec; | 668 | return ec; |
652 | } | 669 | } |
653 | 670 | ||
@@ -680,32 +697,50 @@ ec_parse_device(acpi_handle handle, u32 Level, void *context, void **retval) | |||
680 | status = acpi_evaluate_integer(handle, "_GPE", NULL, &ec->gpe); | 697 | status = acpi_evaluate_integer(handle, "_GPE", NULL, &ec->gpe); |
681 | if (ACPI_FAILURE(status)) | 698 | if (ACPI_FAILURE(status)) |
682 | return status; | 699 | return status; |
683 | |||
684 | /* Find and register all query methods */ | 700 | /* Find and register all query methods */ |
685 | acpi_walk_namespace(ACPI_TYPE_METHOD, handle, 1, | 701 | acpi_walk_namespace(ACPI_TYPE_METHOD, handle, 1, |
686 | acpi_ec_register_query_methods, ec, NULL); | 702 | acpi_ec_register_query_methods, ec, NULL); |
687 | |||
688 | /* Use the global lock for all EC transactions? */ | 703 | /* Use the global lock for all EC transactions? */ |
689 | acpi_evaluate_integer(handle, "_GLK", NULL, &ec->global_lock); | 704 | acpi_evaluate_integer(handle, "_GLK", NULL, &ec->global_lock); |
690 | |||
691 | ec->handle = handle; | 705 | ec->handle = handle; |
692 | |||
693 | printk(KERN_INFO PREFIX "GPE = 0x%lx, I/O: command/status = 0x%lx, data = 0x%lx\n", | ||
694 | ec->gpe, ec->command_addr, ec->data_addr); | ||
695 | |||
696 | return AE_CTRL_TERMINATE; | 706 | return AE_CTRL_TERMINATE; |
697 | } | 707 | } |
698 | 708 | ||
709 | static void ec_remove_handlers(struct acpi_ec *ec) | ||
710 | { | ||
711 | if (ACPI_FAILURE(acpi_remove_address_space_handler(ec->handle, | ||
712 | ACPI_ADR_SPACE_EC, &acpi_ec_space_handler))) | ||
713 | printk(KERN_ERR PREFIX "failed to remove space handler\n"); | ||
714 | if (ACPI_FAILURE(acpi_remove_gpe_handler(NULL, ec->gpe, | ||
715 | &acpi_ec_gpe_handler))) | ||
716 | printk(KERN_ERR PREFIX "failed to remove gpe handler\n"); | ||
717 | ec->handlers_installed = 0; | ||
718 | } | ||
719 | |||
699 | static int acpi_ec_add(struct acpi_device *device) | 720 | static int acpi_ec_add(struct acpi_device *device) |
700 | { | 721 | { |
701 | struct acpi_ec *ec = NULL; | 722 | struct acpi_ec *ec = NULL; |
702 | 723 | ||
703 | if (!device) | 724 | if (!device) |
704 | return -EINVAL; | 725 | return -EINVAL; |
705 | |||
706 | strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME); | 726 | strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME); |
707 | strcpy(acpi_device_class(device), ACPI_EC_CLASS); | 727 | strcpy(acpi_device_class(device), ACPI_EC_CLASS); |
708 | 728 | ||
729 | /* Check for boot EC */ | ||
730 | if (boot_ec) { | ||
731 | if (boot_ec->handle == device->handle) { | ||
732 | /* Pre-loaded EC from DSDT, just move pointer */ | ||
733 | ec = boot_ec; | ||
734 | boot_ec = NULL; | ||
735 | goto end; | ||
736 | } else if (boot_ec->handle == ACPI_ROOT_OBJECT) { | ||
737 | /* ECDT-based EC, time to shut it down */ | ||
738 | ec_remove_handlers(boot_ec); | ||
739 | kfree(boot_ec); | ||
740 | first_ec = boot_ec = NULL; | ||
741 | } | ||
742 | } | ||
743 | |||
709 | ec = make_acpi_ec(); | 744 | ec = make_acpi_ec(); |
710 | if (!ec) | 745 | if (!ec) |
711 | return -ENOMEM; | 746 | return -ENOMEM; |
@@ -715,25 +750,16 @@ static int acpi_ec_add(struct acpi_device *device) | |||
715 | kfree(ec); | 750 | kfree(ec); |
716 | return -EINVAL; | 751 | return -EINVAL; |
717 | } | 752 | } |
718 | |||
719 | /* Check if we found the boot EC */ | ||
720 | if (boot_ec) { | ||
721 | if (boot_ec->gpe == ec->gpe) { | ||
722 | /* We might have incorrect info for GL at boot time */ | ||
723 | mutex_lock(&boot_ec->lock); | ||
724 | boot_ec->global_lock = ec->global_lock; | ||
725 | /* Copy handlers from new ec into boot ec */ | ||
726 | list_splice(&ec->list, &boot_ec->list); | ||
727 | mutex_unlock(&boot_ec->lock); | ||
728 | kfree(ec); | ||
729 | ec = boot_ec; | ||
730 | } | ||
731 | } else | ||
732 | first_ec = ec; | ||
733 | ec->handle = device->handle; | 753 | ec->handle = device->handle; |
754 | end: | ||
755 | if (!first_ec) | ||
756 | first_ec = ec; | ||
734 | acpi_driver_data(device) = ec; | 757 | acpi_driver_data(device) = ec; |
735 | |||
736 | acpi_ec_add_fs(device); | 758 | acpi_ec_add_fs(device); |
759 | printk(KERN_INFO PREFIX "GPE = 0x%lx, I/O: command/status = 0x%lx, data = 0x%lx\n", | ||
760 | ec->gpe, ec->command_addr, ec->data_addr); | ||
761 | printk(KERN_INFO PREFIX "driver started in %s mode\n", | ||
762 | (test_bit(EC_FLAGS_GPE_MODE, &ec->flags))?"interrupt":"poll"); | ||
737 | return 0; | 763 | return 0; |
738 | } | 764 | } |
739 | 765 | ||
@@ -756,10 +782,7 @@ static int acpi_ec_remove(struct acpi_device *device, int type) | |||
756 | acpi_driver_data(device) = NULL; | 782 | acpi_driver_data(device) = NULL; |
757 | if (ec == first_ec) | 783 | if (ec == first_ec) |
758 | first_ec = NULL; | 784 | first_ec = NULL; |
759 | 785 | kfree(ec); | |
760 | /* Don't touch boot EC */ | ||
761 | if (boot_ec != ec) | ||
762 | kfree(ec); | ||
763 | return 0; | 786 | return 0; |
764 | } | 787 | } |
765 | 788 | ||
@@ -789,6 +812,8 @@ ec_parse_io_ports(struct acpi_resource *resource, void *context) | |||
789 | static int ec_install_handlers(struct acpi_ec *ec) | 812 | static int ec_install_handlers(struct acpi_ec *ec) |
790 | { | 813 | { |
791 | acpi_status status; | 814 | acpi_status status; |
815 | if (ec->handlers_installed) | ||
816 | return 0; | ||
792 | status = acpi_install_gpe_handler(NULL, ec->gpe, | 817 | status = acpi_install_gpe_handler(NULL, ec->gpe, |
793 | ACPI_GPE_EDGE_TRIGGERED, | 818 | ACPI_GPE_EDGE_TRIGGERED, |
794 | &acpi_ec_gpe_handler, ec); | 819 | &acpi_ec_gpe_handler, ec); |
@@ -807,6 +832,7 @@ static int ec_install_handlers(struct acpi_ec *ec) | |||
807 | return -ENODEV; | 832 | return -ENODEV; |
808 | } | 833 | } |
809 | 834 | ||
835 | ec->handlers_installed = 1; | ||
810 | return 0; | 836 | return 0; |
811 | } | 837 | } |
812 | 838 | ||
@@ -823,41 +849,22 @@ static int acpi_ec_start(struct acpi_device *device) | |||
823 | if (!ec) | 849 | if (!ec) |
824 | return -EINVAL; | 850 | return -EINVAL; |
825 | 851 | ||
826 | /* Boot EC is already working */ | 852 | ret = ec_install_handlers(ec); |
827 | if (ec != boot_ec) | ||
828 | ret = ec_install_handlers(ec); | ||
829 | 853 | ||
830 | /* EC is fully operational, allow queries */ | 854 | /* EC is fully operational, allow queries */ |
831 | atomic_set(&ec->query_pending, 0); | 855 | clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags); |
832 | |||
833 | return ret; | 856 | return ret; |
834 | } | 857 | } |
835 | 858 | ||
836 | static int acpi_ec_stop(struct acpi_device *device, int type) | 859 | static int acpi_ec_stop(struct acpi_device *device, int type) |
837 | { | 860 | { |
838 | acpi_status status; | ||
839 | struct acpi_ec *ec; | 861 | struct acpi_ec *ec; |
840 | |||
841 | if (!device) | 862 | if (!device) |
842 | return -EINVAL; | 863 | return -EINVAL; |
843 | |||
844 | ec = acpi_driver_data(device); | 864 | ec = acpi_driver_data(device); |
845 | if (!ec) | 865 | if (!ec) |
846 | return -EINVAL; | 866 | return -EINVAL; |
847 | 867 | ec_remove_handlers(ec); | |
848 | /* Don't touch boot EC */ | ||
849 | if (ec == boot_ec) | ||
850 | return 0; | ||
851 | |||
852 | status = acpi_remove_address_space_handler(ec->handle, | ||
853 | ACPI_ADR_SPACE_EC, | ||
854 | &acpi_ec_space_handler); | ||
855 | if (ACPI_FAILURE(status)) | ||
856 | return -ENODEV; | ||
857 | |||
858 | status = acpi_remove_gpe_handler(NULL, ec->gpe, &acpi_ec_gpe_handler); | ||
859 | if (ACPI_FAILURE(status)) | ||
860 | return -ENODEV; | ||
861 | 868 | ||
862 | return 0; | 869 | return 0; |
863 | } | 870 | } |
@@ -877,18 +884,26 @@ int __init acpi_ec_ecdt_probe(void) | |||
877 | status = acpi_get_table(ACPI_SIG_ECDT, 1, | 884 | status = acpi_get_table(ACPI_SIG_ECDT, 1, |
878 | (struct acpi_table_header **)&ecdt_ptr); | 885 | (struct acpi_table_header **)&ecdt_ptr); |
879 | if (ACPI_SUCCESS(status)) { | 886 | if (ACPI_SUCCESS(status)) { |
880 | printk(KERN_INFO PREFIX "EC description table is found, configuring boot EC\n\n"); | 887 | printk(KERN_INFO PREFIX "EC description table is found, configuring boot EC\n"); |
881 | boot_ec->command_addr = ecdt_ptr->control.address; | 888 | boot_ec->command_addr = ecdt_ptr->control.address; |
882 | boot_ec->data_addr = ecdt_ptr->data.address; | 889 | boot_ec->data_addr = ecdt_ptr->data.address; |
883 | boot_ec->gpe = ecdt_ptr->gpe; | 890 | boot_ec->gpe = ecdt_ptr->gpe; |
884 | boot_ec->handle = ACPI_ROOT_OBJECT; | 891 | boot_ec->handle = ACPI_ROOT_OBJECT; |
885 | } else { | 892 | } else { |
893 | /* This workaround is needed only on some broken machines, | ||
894 | * which require early EC, but fail to provide ECDT */ | ||
895 | acpi_handle x; | ||
886 | printk(KERN_DEBUG PREFIX "Look up EC in DSDT\n"); | 896 | printk(KERN_DEBUG PREFIX "Look up EC in DSDT\n"); |
887 | status = acpi_get_devices(ec_device_ids[0].id, ec_parse_device, | 897 | status = acpi_get_devices(ec_device_ids[0].id, ec_parse_device, |
888 | boot_ec, NULL); | 898 | boot_ec, NULL); |
889 | /* Check that acpi_get_devices actually find something */ | 899 | /* Check that acpi_get_devices actually find something */ |
890 | if (ACPI_FAILURE(status) || !boot_ec->handle) | 900 | if (ACPI_FAILURE(status) || !boot_ec->handle) |
891 | goto error; | 901 | goto error; |
902 | /* We really need to limit this workaround, the only ASUS, | ||
903 | * which needs it, has fake EC._INI method, so use it as flag. | ||
904 | */ | ||
905 | if (ACPI_FAILURE(acpi_get_handle(boot_ec->handle, "_INI", &x))) | ||
906 | goto error; | ||
892 | } | 907 | } |
893 | 908 | ||
894 | ret = ec_install_handlers(boot_ec); | 909 | ret = ec_install_handlers(boot_ec); |
@@ -899,7 +914,6 @@ int __init acpi_ec_ecdt_probe(void) | |||
899 | error: | 914 | error: |
900 | kfree(boot_ec); | 915 | kfree(boot_ec); |
901 | boot_ec = NULL; | 916 | boot_ec = NULL; |
902 | |||
903 | return -ENODEV; | 917 | return -ENODEV; |
904 | } | 918 | } |
905 | 919 | ||
@@ -937,20 +951,4 @@ static void __exit acpi_ec_exit(void) | |||
937 | 951 | ||
938 | return; | 952 | return; |
939 | } | 953 | } |
940 | #endif /* 0 */ | 954 | #endif /* 0 */ |
941 | |||
942 | static int __init acpi_ec_set_intr_mode(char *str) | ||
943 | { | ||
944 | int intr; | ||
945 | |||
946 | if (!get_option(&str, &intr)) | ||
947 | return 0; | ||
948 | |||
949 | acpi_ec_mode = (intr) ? EC_INTR : EC_POLL; | ||
950 | |||
951 | printk(KERN_NOTICE PREFIX "%s mode.\n", intr ? "interrupt" : "polling"); | ||
952 | |||
953 | return 1; | ||
954 | } | ||
955 | |||
956 | __setup("ec_intr=", acpi_ec_set_intr_mode); | ||
diff --git a/drivers/acpi/events/evevent.c b/drivers/acpi/events/evevent.c index a1f87b5def2a..e41287815ea1 100644 --- a/drivers/acpi/events/evevent.c +++ b/drivers/acpi/events/evevent.c | |||
@@ -239,10 +239,8 @@ u32 acpi_ev_fixed_event_detect(void) | |||
239 | * Read the fixed feature status and enable registers, as all the cases | 239 | * Read the fixed feature status and enable registers, as all the cases |
240 | * depend on their values. Ignore errors here. | 240 | * depend on their values. Ignore errors here. |
241 | */ | 241 | */ |
242 | (void)acpi_hw_register_read(ACPI_MTX_DO_NOT_LOCK, | 242 | (void)acpi_hw_register_read(ACPI_REGISTER_PM1_STATUS, &fixed_status); |
243 | ACPI_REGISTER_PM1_STATUS, &fixed_status); | 243 | (void)acpi_hw_register_read(ACPI_REGISTER_PM1_ENABLE, &fixed_enable); |
244 | (void)acpi_hw_register_read(ACPI_MTX_DO_NOT_LOCK, | ||
245 | ACPI_REGISTER_PM1_ENABLE, &fixed_enable); | ||
246 | 244 | ||
247 | ACPI_DEBUG_PRINT((ACPI_DB_INTERRUPTS, | 245 | ACPI_DEBUG_PRINT((ACPI_DB_INTERRUPTS, |
248 | "Fixed Event Block: Enable %08X Status %08X\n", | 246 | "Fixed Event Block: Enable %08X Status %08X\n", |
diff --git a/drivers/acpi/fan.c b/drivers/acpi/fan.c index c81f6bdb68b8..a5a5532db268 100644 --- a/drivers/acpi/fan.c +++ b/drivers/acpi/fan.c | |||
@@ -47,8 +47,6 @@ MODULE_LICENSE("GPL"); | |||
47 | 47 | ||
48 | static int acpi_fan_add(struct acpi_device *device); | 48 | static int acpi_fan_add(struct acpi_device *device); |
49 | static int acpi_fan_remove(struct acpi_device *device, int type); | 49 | static int acpi_fan_remove(struct acpi_device *device, int type); |
50 | static int acpi_fan_suspend(struct acpi_device *device, pm_message_t state); | ||
51 | static int acpi_fan_resume(struct acpi_device *device); | ||
52 | 50 | ||
53 | static const struct acpi_device_id fan_device_ids[] = { | 51 | static const struct acpi_device_id fan_device_ids[] = { |
54 | {"PNP0C0B", 0}, | 52 | {"PNP0C0B", 0}, |
@@ -63,15 +61,9 @@ static struct acpi_driver acpi_fan_driver = { | |||
63 | .ops = { | 61 | .ops = { |
64 | .add = acpi_fan_add, | 62 | .add = acpi_fan_add, |
65 | .remove = acpi_fan_remove, | 63 | .remove = acpi_fan_remove, |
66 | .suspend = acpi_fan_suspend, | ||
67 | .resume = acpi_fan_resume, | ||
68 | }, | 64 | }, |
69 | }; | 65 | }; |
70 | 66 | ||
71 | struct acpi_fan { | ||
72 | struct acpi_device * device; | ||
73 | }; | ||
74 | |||
75 | /* -------------------------------------------------------------------------- | 67 | /* -------------------------------------------------------------------------- |
76 | FS Interface (/proc) | 68 | FS Interface (/proc) |
77 | -------------------------------------------------------------------------- */ | 69 | -------------------------------------------------------------------------- */ |
@@ -80,12 +72,12 @@ static struct proc_dir_entry *acpi_fan_dir; | |||
80 | 72 | ||
81 | static int acpi_fan_read_state(struct seq_file *seq, void *offset) | 73 | static int acpi_fan_read_state(struct seq_file *seq, void *offset) |
82 | { | 74 | { |
83 | struct acpi_fan *fan = seq->private; | 75 | struct acpi_device *device = seq->private; |
84 | int state = 0; | 76 | int state = 0; |
85 | 77 | ||
86 | 78 | ||
87 | if (fan) { | 79 | if (device) { |
88 | if (acpi_bus_get_power(fan->device->handle, &state)) | 80 | if (acpi_bus_get_power(device->handle, &state)) |
89 | seq_printf(seq, "status: ERROR\n"); | 81 | seq_printf(seq, "status: ERROR\n"); |
90 | else | 82 | else |
91 | seq_printf(seq, "status: %s\n", | 83 | seq_printf(seq, "status: %s\n", |
@@ -105,11 +97,10 @@ acpi_fan_write_state(struct file *file, const char __user * buffer, | |||
105 | { | 97 | { |
106 | int result = 0; | 98 | int result = 0; |
107 | struct seq_file *m = file->private_data; | 99 | struct seq_file *m = file->private_data; |
108 | struct acpi_fan *fan = m->private; | 100 | struct acpi_device *device = m->private; |
109 | char state_string[12] = { '\0' }; | 101 | char state_string[12] = { '\0' }; |
110 | 102 | ||
111 | 103 | if (count > sizeof(state_string) - 1) | |
112 | if (!fan || (count > sizeof(state_string) - 1)) | ||
113 | return -EINVAL; | 104 | return -EINVAL; |
114 | 105 | ||
115 | if (copy_from_user(state_string, buffer, count)) | 106 | if (copy_from_user(state_string, buffer, count)) |
@@ -117,7 +108,7 @@ acpi_fan_write_state(struct file *file, const char __user * buffer, | |||
117 | 108 | ||
118 | state_string[count] = '\0'; | 109 | state_string[count] = '\0'; |
119 | 110 | ||
120 | result = acpi_bus_set_power(fan->device->handle, | 111 | result = acpi_bus_set_power(device->handle, |
121 | simple_strtoul(state_string, NULL, 0)); | 112 | simple_strtoul(state_string, NULL, 0)); |
122 | if (result) | 113 | if (result) |
123 | return result; | 114 | return result; |
@@ -158,7 +149,7 @@ static int acpi_fan_add_fs(struct acpi_device *device) | |||
158 | return -ENODEV; | 149 | return -ENODEV; |
159 | else { | 150 | else { |
160 | entry->proc_fops = &acpi_fan_state_ops; | 151 | entry->proc_fops = &acpi_fan_state_ops; |
161 | entry->data = acpi_driver_data(device); | 152 | entry->data = device; |
162 | entry->owner = THIS_MODULE; | 153 | entry->owner = THIS_MODULE; |
163 | } | 154 | } |
164 | 155 | ||
@@ -191,14 +182,8 @@ static int acpi_fan_add(struct acpi_device *device) | |||
191 | if (!device) | 182 | if (!device) |
192 | return -EINVAL; | 183 | return -EINVAL; |
193 | 184 | ||
194 | fan = kzalloc(sizeof(struct acpi_fan), GFP_KERNEL); | ||
195 | if (!fan) | ||
196 | return -ENOMEM; | ||
197 | |||
198 | fan->device = device; | ||
199 | strcpy(acpi_device_name(device), "Fan"); | 185 | strcpy(acpi_device_name(device), "Fan"); |
200 | strcpy(acpi_device_class(device), ACPI_FAN_CLASS); | 186 | strcpy(acpi_device_class(device), ACPI_FAN_CLASS); |
201 | acpi_driver_data(device) = fan; | ||
202 | 187 | ||
203 | result = acpi_bus_get_power(device->handle, &state); | 188 | result = acpi_bus_get_power(device->handle, &state); |
204 | if (result) { | 189 | if (result) { |
@@ -206,10 +191,6 @@ static int acpi_fan_add(struct acpi_device *device) | |||
206 | goto end; | 191 | goto end; |
207 | } | 192 | } |
208 | 193 | ||
209 | device->flags.force_power_state = 1; | ||
210 | acpi_bus_set_power(device->handle, state); | ||
211 | device->flags.force_power_state = 0; | ||
212 | |||
213 | result = acpi_fan_add_fs(device); | 194 | result = acpi_fan_add_fs(device); |
214 | if (result) | 195 | if (result) |
215 | goto end; | 196 | goto end; |
@@ -227,53 +208,14 @@ static int acpi_fan_add(struct acpi_device *device) | |||
227 | 208 | ||
228 | static int acpi_fan_remove(struct acpi_device *device, int type) | 209 | static int acpi_fan_remove(struct acpi_device *device, int type) |
229 | { | 210 | { |
230 | struct acpi_fan *fan = NULL; | ||
231 | |||
232 | |||
233 | if (!device || !acpi_driver_data(device)) | 211 | if (!device || !acpi_driver_data(device)) |
234 | return -EINVAL; | 212 | return -EINVAL; |
235 | 213 | ||
236 | fan = acpi_driver_data(device); | ||
237 | |||
238 | acpi_fan_remove_fs(device); | 214 | acpi_fan_remove_fs(device); |
239 | 215 | ||
240 | kfree(fan); | ||
241 | |||
242 | return 0; | 216 | return 0; |
243 | } | 217 | } |
244 | 218 | ||
245 | static int acpi_fan_suspend(struct acpi_device *device, pm_message_t state) | ||
246 | { | ||
247 | if (!device) | ||
248 | return -EINVAL; | ||
249 | |||
250 | acpi_bus_set_power(device->handle, ACPI_STATE_D0); | ||
251 | |||
252 | return AE_OK; | ||
253 | } | ||
254 | |||
255 | static int acpi_fan_resume(struct acpi_device *device) | ||
256 | { | ||
257 | int result = 0; | ||
258 | int power_state = 0; | ||
259 | |||
260 | if (!device) | ||
261 | return -EINVAL; | ||
262 | |||
263 | result = acpi_bus_get_power(device->handle, &power_state); | ||
264 | if (result) { | ||
265 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | ||
266 | "Error reading fan power state\n")); | ||
267 | return result; | ||
268 | } | ||
269 | |||
270 | device->flags.force_power_state = 1; | ||
271 | acpi_bus_set_power(device->handle, power_state); | ||
272 | device->flags.force_power_state = 0; | ||
273 | |||
274 | return result; | ||
275 | } | ||
276 | |||
277 | static int __init acpi_fan_init(void) | 219 | static int __init acpi_fan_init(void) |
278 | { | 220 | { |
279 | int result = 0; | 221 | int result = 0; |
diff --git a/drivers/acpi/hardware/hwregs.c b/drivers/acpi/hardware/hwregs.c index 1d371fa663f2..73f9c5fb1ba7 100644 --- a/drivers/acpi/hardware/hwregs.c +++ b/drivers/acpi/hardware/hwregs.c | |||
@@ -75,8 +75,7 @@ acpi_status acpi_hw_clear_acpi_status(void) | |||
75 | 75 | ||
76 | lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock); | 76 | lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock); |
77 | 77 | ||
78 | status = acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK, | 78 | status = acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS, |
79 | ACPI_REGISTER_PM1_STATUS, | ||
80 | ACPI_BITMASK_ALL_FIXED_STATUS); | 79 | ACPI_BITMASK_ALL_FIXED_STATUS); |
81 | if (ACPI_FAILURE(status)) { | 80 | if (ACPI_FAILURE(status)) { |
82 | goto unlock_and_exit; | 81 | goto unlock_and_exit; |
@@ -259,7 +258,7 @@ struct acpi_bit_register_info *acpi_hw_get_bit_register_info(u32 register_id) | |||
259 | * | 258 | * |
260 | ******************************************************************************/ | 259 | ******************************************************************************/ |
261 | 260 | ||
262 | acpi_status acpi_get_register(u32 register_id, u32 * return_value) | 261 | acpi_status acpi_get_register_unlocked(u32 register_id, u32 * return_value) |
263 | { | 262 | { |
264 | u32 register_value = 0; | 263 | u32 register_value = 0; |
265 | struct acpi_bit_register_info *bit_reg_info; | 264 | struct acpi_bit_register_info *bit_reg_info; |
@@ -276,8 +275,7 @@ acpi_status acpi_get_register(u32 register_id, u32 * return_value) | |||
276 | 275 | ||
277 | /* Read from the register */ | 276 | /* Read from the register */ |
278 | 277 | ||
279 | status = acpi_hw_register_read(ACPI_MTX_LOCK, | 278 | status = acpi_hw_register_read(bit_reg_info->parent_register, |
280 | bit_reg_info->parent_register, | ||
281 | ®ister_value); | 279 | ®ister_value); |
282 | 280 | ||
283 | if (ACPI_SUCCESS(status)) { | 281 | if (ACPI_SUCCESS(status)) { |
@@ -298,6 +296,16 @@ acpi_status acpi_get_register(u32 register_id, u32 * return_value) | |||
298 | return_ACPI_STATUS(status); | 296 | return_ACPI_STATUS(status); |
299 | } | 297 | } |
300 | 298 | ||
299 | acpi_status acpi_get_register(u32 register_id, u32 * return_value) | ||
300 | { | ||
301 | acpi_status status; | ||
302 | acpi_cpu_flags flags; | ||
303 | flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock); | ||
304 | status = acpi_get_register_unlocked(register_id, return_value); | ||
305 | acpi_os_release_lock(acpi_gbl_hardware_lock, flags); | ||
306 | return status; | ||
307 | } | ||
308 | |||
301 | ACPI_EXPORT_SYMBOL(acpi_get_register) | 309 | ACPI_EXPORT_SYMBOL(acpi_get_register) |
302 | 310 | ||
303 | /******************************************************************************* | 311 | /******************************************************************************* |
@@ -335,8 +343,7 @@ acpi_status acpi_set_register(u32 register_id, u32 value) | |||
335 | 343 | ||
336 | /* Always do a register read first so we can insert the new bits */ | 344 | /* Always do a register read first so we can insert the new bits */ |
337 | 345 | ||
338 | status = acpi_hw_register_read(ACPI_MTX_DO_NOT_LOCK, | 346 | status = acpi_hw_register_read(bit_reg_info->parent_register, |
339 | bit_reg_info->parent_register, | ||
340 | ®ister_value); | 347 | ®ister_value); |
341 | if (ACPI_FAILURE(status)) { | 348 | if (ACPI_FAILURE(status)) { |
342 | goto unlock_and_exit; | 349 | goto unlock_and_exit; |
@@ -363,8 +370,7 @@ acpi_status acpi_set_register(u32 register_id, u32 value) | |||
363 | bit_reg_info-> | 370 | bit_reg_info-> |
364 | access_bit_mask); | 371 | access_bit_mask); |
365 | if (value) { | 372 | if (value) { |
366 | status = acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK, | 373 | status = acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS, |
367 | ACPI_REGISTER_PM1_STATUS, | ||
368 | (u16) value); | 374 | (u16) value); |
369 | register_value = 0; | 375 | register_value = 0; |
370 | } | 376 | } |
@@ -377,8 +383,7 @@ acpi_status acpi_set_register(u32 register_id, u32 value) | |||
377 | bit_reg_info->access_bit_mask, | 383 | bit_reg_info->access_bit_mask, |
378 | value); | 384 | value); |
379 | 385 | ||
380 | status = acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK, | 386 | status = acpi_hw_register_write(ACPI_REGISTER_PM1_ENABLE, |
381 | ACPI_REGISTER_PM1_ENABLE, | ||
382 | (u16) register_value); | 387 | (u16) register_value); |
383 | break; | 388 | break; |
384 | 389 | ||
@@ -397,15 +402,13 @@ acpi_status acpi_set_register(u32 register_id, u32 value) | |||
397 | bit_reg_info->access_bit_mask, | 402 | bit_reg_info->access_bit_mask, |
398 | value); | 403 | value); |
399 | 404 | ||
400 | status = acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK, | 405 | status = acpi_hw_register_write(ACPI_REGISTER_PM1_CONTROL, |
401 | ACPI_REGISTER_PM1_CONTROL, | ||
402 | (u16) register_value); | 406 | (u16) register_value); |
403 | break; | 407 | break; |
404 | 408 | ||
405 | case ACPI_REGISTER_PM2_CONTROL: | 409 | case ACPI_REGISTER_PM2_CONTROL: |
406 | 410 | ||
407 | status = acpi_hw_register_read(ACPI_MTX_DO_NOT_LOCK, | 411 | status = acpi_hw_register_read(ACPI_REGISTER_PM2_CONTROL, |
408 | ACPI_REGISTER_PM2_CONTROL, | ||
409 | ®ister_value); | 412 | ®ister_value); |
410 | if (ACPI_FAILURE(status)) { | 413 | if (ACPI_FAILURE(status)) { |
411 | goto unlock_and_exit; | 414 | goto unlock_and_exit; |
@@ -430,8 +433,7 @@ acpi_status acpi_set_register(u32 register_id, u32 value) | |||
430 | xpm2_control_block. | 433 | xpm2_control_block. |
431 | address))); | 434 | address))); |
432 | 435 | ||
433 | status = acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK, | 436 | status = acpi_hw_register_write(ACPI_REGISTER_PM2_CONTROL, |
434 | ACPI_REGISTER_PM2_CONTROL, | ||
435 | (u8) (register_value)); | 437 | (u8) (register_value)); |
436 | break; | 438 | break; |
437 | 439 | ||
@@ -461,8 +463,7 @@ ACPI_EXPORT_SYMBOL(acpi_set_register) | |||
461 | * | 463 | * |
462 | * FUNCTION: acpi_hw_register_read | 464 | * FUNCTION: acpi_hw_register_read |
463 | * | 465 | * |
464 | * PARAMETERS: use_lock - Lock hardware? True/False | 466 | * PARAMETERS: register_id - ACPI Register ID |
465 | * register_id - ACPI Register ID | ||
466 | * return_value - Where the register value is returned | 467 | * return_value - Where the register value is returned |
467 | * | 468 | * |
468 | * RETURN: Status and the value read. | 469 | * RETURN: Status and the value read. |
@@ -471,19 +472,14 @@ ACPI_EXPORT_SYMBOL(acpi_set_register) | |||
471 | * | 472 | * |
472 | ******************************************************************************/ | 473 | ******************************************************************************/ |
473 | acpi_status | 474 | acpi_status |
474 | acpi_hw_register_read(u8 use_lock, u32 register_id, u32 * return_value) | 475 | acpi_hw_register_read(u32 register_id, u32 * return_value) |
475 | { | 476 | { |
476 | u32 value1 = 0; | 477 | u32 value1 = 0; |
477 | u32 value2 = 0; | 478 | u32 value2 = 0; |
478 | acpi_status status; | 479 | acpi_status status; |
479 | acpi_cpu_flags lock_flags = 0; | ||
480 | 480 | ||
481 | ACPI_FUNCTION_TRACE(hw_register_read); | 481 | ACPI_FUNCTION_TRACE(hw_register_read); |
482 | 482 | ||
483 | if (ACPI_MTX_LOCK == use_lock) { | ||
484 | lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock); | ||
485 | } | ||
486 | |||
487 | switch (register_id) { | 483 | switch (register_id) { |
488 | case ACPI_REGISTER_PM1_STATUS: /* 16-bit access */ | 484 | case ACPI_REGISTER_PM1_STATUS: /* 16-bit access */ |
489 | 485 | ||
@@ -491,7 +487,7 @@ acpi_hw_register_read(u8 use_lock, u32 register_id, u32 * return_value) | |||
491 | acpi_hw_low_level_read(16, &value1, | 487 | acpi_hw_low_level_read(16, &value1, |
492 | &acpi_gbl_FADT.xpm1a_event_block); | 488 | &acpi_gbl_FADT.xpm1a_event_block); |
493 | if (ACPI_FAILURE(status)) { | 489 | if (ACPI_FAILURE(status)) { |
494 | goto unlock_and_exit; | 490 | goto exit; |
495 | } | 491 | } |
496 | 492 | ||
497 | /* PM1B is optional */ | 493 | /* PM1B is optional */ |
@@ -507,7 +503,7 @@ acpi_hw_register_read(u8 use_lock, u32 register_id, u32 * return_value) | |||
507 | status = | 503 | status = |
508 | acpi_hw_low_level_read(16, &value1, &acpi_gbl_xpm1a_enable); | 504 | acpi_hw_low_level_read(16, &value1, &acpi_gbl_xpm1a_enable); |
509 | if (ACPI_FAILURE(status)) { | 505 | if (ACPI_FAILURE(status)) { |
510 | goto unlock_and_exit; | 506 | goto exit; |
511 | } | 507 | } |
512 | 508 | ||
513 | /* PM1B is optional */ | 509 | /* PM1B is optional */ |
@@ -523,7 +519,7 @@ acpi_hw_register_read(u8 use_lock, u32 register_id, u32 * return_value) | |||
523 | acpi_hw_low_level_read(16, &value1, | 519 | acpi_hw_low_level_read(16, &value1, |
524 | &acpi_gbl_FADT.xpm1a_control_block); | 520 | &acpi_gbl_FADT.xpm1a_control_block); |
525 | if (ACPI_FAILURE(status)) { | 521 | if (ACPI_FAILURE(status)) { |
526 | goto unlock_and_exit; | 522 | goto exit; |
527 | } | 523 | } |
528 | 524 | ||
529 | status = | 525 | status = |
@@ -558,10 +554,7 @@ acpi_hw_register_read(u8 use_lock, u32 register_id, u32 * return_value) | |||
558 | break; | 554 | break; |
559 | } | 555 | } |
560 | 556 | ||
561 | unlock_and_exit: | 557 | exit: |
562 | if (ACPI_MTX_LOCK == use_lock) { | ||
563 | acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags); | ||
564 | } | ||
565 | 558 | ||
566 | if (ACPI_SUCCESS(status)) { | 559 | if (ACPI_SUCCESS(status)) { |
567 | *return_value = value1; | 560 | *return_value = value1; |
@@ -574,8 +567,7 @@ acpi_hw_register_read(u8 use_lock, u32 register_id, u32 * return_value) | |||
574 | * | 567 | * |
575 | * FUNCTION: acpi_hw_register_write | 568 | * FUNCTION: acpi_hw_register_write |
576 | * | 569 | * |
577 | * PARAMETERS: use_lock - Lock hardware? True/False | 570 | * PARAMETERS: register_id - ACPI Register ID |
578 | * register_id - ACPI Register ID | ||
579 | * Value - The value to write | 571 | * Value - The value to write |
580 | * | 572 | * |
581 | * RETURN: Status | 573 | * RETURN: Status |
@@ -597,28 +589,22 @@ acpi_hw_register_read(u8 use_lock, u32 register_id, u32 * return_value) | |||
597 | * | 589 | * |
598 | ******************************************************************************/ | 590 | ******************************************************************************/ |
599 | 591 | ||
600 | acpi_status acpi_hw_register_write(u8 use_lock, u32 register_id, u32 value) | 592 | acpi_status acpi_hw_register_write(u32 register_id, u32 value) |
601 | { | 593 | { |
602 | acpi_status status; | 594 | acpi_status status; |
603 | acpi_cpu_flags lock_flags = 0; | ||
604 | u32 read_value; | 595 | u32 read_value; |
605 | 596 | ||
606 | ACPI_FUNCTION_TRACE(hw_register_write); | 597 | ACPI_FUNCTION_TRACE(hw_register_write); |
607 | 598 | ||
608 | if (ACPI_MTX_LOCK == use_lock) { | ||
609 | lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock); | ||
610 | } | ||
611 | |||
612 | switch (register_id) { | 599 | switch (register_id) { |
613 | case ACPI_REGISTER_PM1_STATUS: /* 16-bit access */ | 600 | case ACPI_REGISTER_PM1_STATUS: /* 16-bit access */ |
614 | 601 | ||
615 | /* Perform a read first to preserve certain bits (per ACPI spec) */ | 602 | /* Perform a read first to preserve certain bits (per ACPI spec) */ |
616 | 603 | ||
617 | status = acpi_hw_register_read(ACPI_MTX_DO_NOT_LOCK, | 604 | status = acpi_hw_register_read(ACPI_REGISTER_PM1_STATUS, |
618 | ACPI_REGISTER_PM1_STATUS, | ||
619 | &read_value); | 605 | &read_value); |
620 | if (ACPI_FAILURE(status)) { | 606 | if (ACPI_FAILURE(status)) { |
621 | goto unlock_and_exit; | 607 | goto exit; |
622 | } | 608 | } |
623 | 609 | ||
624 | /* Insert the bits to be preserved */ | 610 | /* Insert the bits to be preserved */ |
@@ -632,7 +618,7 @@ acpi_status acpi_hw_register_write(u8 use_lock, u32 register_id, u32 value) | |||
632 | acpi_hw_low_level_write(16, value, | 618 | acpi_hw_low_level_write(16, value, |
633 | &acpi_gbl_FADT.xpm1a_event_block); | 619 | &acpi_gbl_FADT.xpm1a_event_block); |
634 | if (ACPI_FAILURE(status)) { | 620 | if (ACPI_FAILURE(status)) { |
635 | goto unlock_and_exit; | 621 | goto exit; |
636 | } | 622 | } |
637 | 623 | ||
638 | /* PM1B is optional */ | 624 | /* PM1B is optional */ |
@@ -647,7 +633,7 @@ acpi_status acpi_hw_register_write(u8 use_lock, u32 register_id, u32 value) | |||
647 | status = | 633 | status = |
648 | acpi_hw_low_level_write(16, value, &acpi_gbl_xpm1a_enable); | 634 | acpi_hw_low_level_write(16, value, &acpi_gbl_xpm1a_enable); |
649 | if (ACPI_FAILURE(status)) { | 635 | if (ACPI_FAILURE(status)) { |
650 | goto unlock_and_exit; | 636 | goto exit; |
651 | } | 637 | } |
652 | 638 | ||
653 | /* PM1B is optional */ | 639 | /* PM1B is optional */ |
@@ -661,11 +647,10 @@ acpi_status acpi_hw_register_write(u8 use_lock, u32 register_id, u32 value) | |||
661 | /* | 647 | /* |
662 | * Perform a read first to preserve certain bits (per ACPI spec) | 648 | * Perform a read first to preserve certain bits (per ACPI spec) |
663 | */ | 649 | */ |
664 | status = acpi_hw_register_read(ACPI_MTX_DO_NOT_LOCK, | 650 | status = acpi_hw_register_read(ACPI_REGISTER_PM1_CONTROL, |
665 | ACPI_REGISTER_PM1_CONTROL, | ||
666 | &read_value); | 651 | &read_value); |
667 | if (ACPI_FAILURE(status)) { | 652 | if (ACPI_FAILURE(status)) { |
668 | goto unlock_and_exit; | 653 | goto exit; |
669 | } | 654 | } |
670 | 655 | ||
671 | /* Insert the bits to be preserved */ | 656 | /* Insert the bits to be preserved */ |
@@ -679,7 +664,7 @@ acpi_status acpi_hw_register_write(u8 use_lock, u32 register_id, u32 value) | |||
679 | acpi_hw_low_level_write(16, value, | 664 | acpi_hw_low_level_write(16, value, |
680 | &acpi_gbl_FADT.xpm1a_control_block); | 665 | &acpi_gbl_FADT.xpm1a_control_block); |
681 | if (ACPI_FAILURE(status)) { | 666 | if (ACPI_FAILURE(status)) { |
682 | goto unlock_and_exit; | 667 | goto exit; |
683 | } | 668 | } |
684 | 669 | ||
685 | status = | 670 | status = |
@@ -728,11 +713,7 @@ acpi_status acpi_hw_register_write(u8 use_lock, u32 register_id, u32 value) | |||
728 | break; | 713 | break; |
729 | } | 714 | } |
730 | 715 | ||
731 | unlock_and_exit: | 716 | exit: |
732 | if (ACPI_MTX_LOCK == use_lock) { | ||
733 | acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags); | ||
734 | } | ||
735 | |||
736 | return_ACPI_STATUS(status); | 717 | return_ACPI_STATUS(status); |
737 | } | 718 | } |
738 | 719 | ||
diff --git a/drivers/acpi/hardware/hwsleep.c b/drivers/acpi/hardware/hwsleep.c index cf69c0040a39..81b248429703 100644 --- a/drivers/acpi/hardware/hwsleep.c +++ b/drivers/acpi/hardware/hwsleep.c | |||
@@ -234,15 +234,11 @@ acpi_status acpi_enter_sleep_state_prep(u8 sleep_state) | |||
234 | "While executing method _SST")); | 234 | "While executing method _SST")); |
235 | } | 235 | } |
236 | 236 | ||
237 | /* | 237 | /* Disable/Clear all GPEs */ |
238 | * 1) Disable/Clear all GPEs | 238 | |
239 | */ | ||
240 | status = acpi_hw_disable_all_gpes(); | 239 | status = acpi_hw_disable_all_gpes(); |
241 | if (ACPI_FAILURE(status)) { | ||
242 | return_ACPI_STATUS(status); | ||
243 | } | ||
244 | 240 | ||
245 | return_ACPI_STATUS(AE_OK); | 241 | return_ACPI_STATUS(status); |
246 | } | 242 | } |
247 | 243 | ||
248 | ACPI_EXPORT_SYMBOL(acpi_enter_sleep_state_prep) | 244 | ACPI_EXPORT_SYMBOL(acpi_enter_sleep_state_prep) |
@@ -313,8 +309,7 @@ acpi_status asmlinkage acpi_enter_sleep_state(u8 sleep_state) | |||
313 | 309 | ||
314 | /* Get current value of PM1A control */ | 310 | /* Get current value of PM1A control */ |
315 | 311 | ||
316 | status = acpi_hw_register_read(ACPI_MTX_DO_NOT_LOCK, | 312 | status = acpi_hw_register_read(ACPI_REGISTER_PM1_CONTROL, &PM1Acontrol); |
317 | ACPI_REGISTER_PM1_CONTROL, &PM1Acontrol); | ||
318 | if (ACPI_FAILURE(status)) { | 313 | if (ACPI_FAILURE(status)) { |
319 | return_ACPI_STATUS(status); | 314 | return_ACPI_STATUS(status); |
320 | } | 315 | } |
@@ -341,15 +336,13 @@ acpi_status asmlinkage acpi_enter_sleep_state(u8 sleep_state) | |||
341 | 336 | ||
342 | /* Write #1: fill in SLP_TYP data */ | 337 | /* Write #1: fill in SLP_TYP data */ |
343 | 338 | ||
344 | status = acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK, | 339 | status = acpi_hw_register_write(ACPI_REGISTER_PM1A_CONTROL, |
345 | ACPI_REGISTER_PM1A_CONTROL, | ||
346 | PM1Acontrol); | 340 | PM1Acontrol); |
347 | if (ACPI_FAILURE(status)) { | 341 | if (ACPI_FAILURE(status)) { |
348 | return_ACPI_STATUS(status); | 342 | return_ACPI_STATUS(status); |
349 | } | 343 | } |
350 | 344 | ||
351 | status = acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK, | 345 | status = acpi_hw_register_write(ACPI_REGISTER_PM1B_CONTROL, |
352 | ACPI_REGISTER_PM1B_CONTROL, | ||
353 | PM1Bcontrol); | 346 | PM1Bcontrol); |
354 | if (ACPI_FAILURE(status)) { | 347 | if (ACPI_FAILURE(status)) { |
355 | return_ACPI_STATUS(status); | 348 | return_ACPI_STATUS(status); |
@@ -364,15 +357,13 @@ acpi_status asmlinkage acpi_enter_sleep_state(u8 sleep_state) | |||
364 | 357 | ||
365 | ACPI_FLUSH_CPU_CACHE(); | 358 | ACPI_FLUSH_CPU_CACHE(); |
366 | 359 | ||
367 | status = acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK, | 360 | status = acpi_hw_register_write(ACPI_REGISTER_PM1A_CONTROL, |
368 | ACPI_REGISTER_PM1A_CONTROL, | ||
369 | PM1Acontrol); | 361 | PM1Acontrol); |
370 | if (ACPI_FAILURE(status)) { | 362 | if (ACPI_FAILURE(status)) { |
371 | return_ACPI_STATUS(status); | 363 | return_ACPI_STATUS(status); |
372 | } | 364 | } |
373 | 365 | ||
374 | status = acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK, | 366 | status = acpi_hw_register_write(ACPI_REGISTER_PM1B_CONTROL, |
375 | ACPI_REGISTER_PM1B_CONTROL, | ||
376 | PM1Bcontrol); | 367 | PM1Bcontrol); |
377 | if (ACPI_FAILURE(status)) { | 368 | if (ACPI_FAILURE(status)) { |
378 | return_ACPI_STATUS(status); | 369 | return_ACPI_STATUS(status); |
@@ -392,8 +383,7 @@ acpi_status asmlinkage acpi_enter_sleep_state(u8 sleep_state) | |||
392 | */ | 383 | */ |
393 | acpi_os_stall(10000000); | 384 | acpi_os_stall(10000000); |
394 | 385 | ||
395 | status = acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK, | 386 | status = acpi_hw_register_write(ACPI_REGISTER_PM1_CONTROL, |
396 | ACPI_REGISTER_PM1_CONTROL, | ||
397 | sleep_enable_reg_info-> | 387 | sleep_enable_reg_info-> |
398 | access_bit_mask); | 388 | access_bit_mask); |
399 | if (ACPI_FAILURE(status)) { | 389 | if (ACPI_FAILURE(status)) { |
@@ -404,7 +394,8 @@ acpi_status asmlinkage acpi_enter_sleep_state(u8 sleep_state) | |||
404 | /* Wait until we enter sleep state */ | 394 | /* Wait until we enter sleep state */ |
405 | 395 | ||
406 | do { | 396 | do { |
407 | status = acpi_get_register(ACPI_BITREG_WAKE_STATUS, &in_value); | 397 | status = acpi_get_register_unlocked(ACPI_BITREG_WAKE_STATUS, |
398 | &in_value); | ||
408 | if (ACPI_FAILURE(status)) { | 399 | if (ACPI_FAILURE(status)) { |
409 | return_ACPI_STATUS(status); | 400 | return_ACPI_STATUS(status); |
410 | } | 401 | } |
@@ -520,8 +511,7 @@ acpi_status acpi_leave_sleep_state(u8 sleep_state) | |||
520 | 511 | ||
521 | /* Get current value of PM1A control */ | 512 | /* Get current value of PM1A control */ |
522 | 513 | ||
523 | status = acpi_hw_register_read(ACPI_MTX_DO_NOT_LOCK, | 514 | status = acpi_hw_register_read(ACPI_REGISTER_PM1_CONTROL, |
524 | ACPI_REGISTER_PM1_CONTROL, | ||
525 | &PM1Acontrol); | 515 | &PM1Acontrol); |
526 | if (ACPI_SUCCESS(status)) { | 516 | if (ACPI_SUCCESS(status)) { |
527 | 517 | ||
@@ -543,11 +533,9 @@ acpi_status acpi_leave_sleep_state(u8 sleep_state) | |||
543 | 533 | ||
544 | /* Just ignore any errors */ | 534 | /* Just ignore any errors */ |
545 | 535 | ||
546 | (void)acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK, | 536 | (void)acpi_hw_register_write(ACPI_REGISTER_PM1A_CONTROL, |
547 | ACPI_REGISTER_PM1A_CONTROL, | ||
548 | PM1Acontrol); | 537 | PM1Acontrol); |
549 | (void)acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK, | 538 | (void)acpi_hw_register_write(ACPI_REGISTER_PM1B_CONTROL, |
550 | ACPI_REGISTER_PM1B_CONTROL, | ||
551 | PM1Bcontrol); | 539 | PM1Bcontrol); |
552 | } | 540 | } |
553 | } | 541 | } |
diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c index 5d14d4f10b12..aabc6ca4a81c 100644 --- a/drivers/acpi/osl.c +++ b/drivers/acpi/osl.c | |||
@@ -1206,7 +1206,7 @@ acpi_os_validate_address ( | |||
1206 | } | 1206 | } |
1207 | 1207 | ||
1208 | #ifdef CONFIG_DMI | 1208 | #ifdef CONFIG_DMI |
1209 | static int dmi_osi_linux(struct dmi_system_id *d) | 1209 | static int dmi_osi_linux(const struct dmi_system_id *d) |
1210 | { | 1210 | { |
1211 | printk(KERN_NOTICE "%s detected: enabling _OSI(Linux)\n", d->ident); | 1211 | printk(KERN_NOTICE "%s detected: enabling _OSI(Linux)\n", d->ident); |
1212 | enable_osi_linux(1); | 1212 | enable_osi_linux(1); |
diff --git a/drivers/acpi/power.c b/drivers/acpi/power.c index 57b9a2998fd0..af1769a20c7a 100644 --- a/drivers/acpi/power.c +++ b/drivers/acpi/power.c | |||
@@ -86,7 +86,6 @@ struct acpi_power_resource { | |||
86 | acpi_bus_id name; | 86 | acpi_bus_id name; |
87 | u32 system_level; | 87 | u32 system_level; |
88 | u32 order; | 88 | u32 order; |
89 | int state; | ||
90 | struct mutex resource_lock; | 89 | struct mutex resource_lock; |
91 | struct list_head reference; | 90 | struct list_head reference; |
92 | }; | 91 | }; |
@@ -128,33 +127,31 @@ acpi_power_get_context(acpi_handle handle, | |||
128 | return 0; | 127 | return 0; |
129 | } | 128 | } |
130 | 129 | ||
131 | static int acpi_power_get_state(struct acpi_power_resource *resource) | 130 | static int acpi_power_get_state(struct acpi_power_resource *resource, int *state) |
132 | { | 131 | { |
133 | acpi_status status = AE_OK; | 132 | acpi_status status = AE_OK; |
134 | unsigned long sta = 0; | 133 | unsigned long sta = 0; |
135 | 134 | ||
136 | 135 | ||
137 | if (!resource) | 136 | if (!resource || !state) |
138 | return -EINVAL; | 137 | return -EINVAL; |
139 | 138 | ||
140 | status = acpi_evaluate_integer(resource->device->handle, "_STA", NULL, &sta); | 139 | status = acpi_evaluate_integer(resource->device->handle, "_STA", NULL, &sta); |
141 | if (ACPI_FAILURE(status)) | 140 | if (ACPI_FAILURE(status)) |
142 | return -ENODEV; | 141 | return -ENODEV; |
143 | 142 | ||
144 | if (sta & 0x01) | 143 | *state = (sta & 0x01)?ACPI_POWER_RESOURCE_STATE_ON: |
145 | resource->state = ACPI_POWER_RESOURCE_STATE_ON; | 144 | ACPI_POWER_RESOURCE_STATE_OFF; |
146 | else | ||
147 | resource->state = ACPI_POWER_RESOURCE_STATE_OFF; | ||
148 | 145 | ||
149 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] is %s\n", | 146 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] is %s\n", |
150 | resource->name, resource->state ? "on" : "off")); | 147 | resource->name, state ? "on" : "off")); |
151 | 148 | ||
152 | return 0; | 149 | return 0; |
153 | } | 150 | } |
154 | 151 | ||
155 | static int acpi_power_get_list_state(struct acpi_handle_list *list, int *state) | 152 | static int acpi_power_get_list_state(struct acpi_handle_list *list, int *state) |
156 | { | 153 | { |
157 | int result = 0; | 154 | int result = 0, state1; |
158 | struct acpi_power_resource *resource = NULL; | 155 | struct acpi_power_resource *resource = NULL; |
159 | u32 i = 0; | 156 | u32 i = 0; |
160 | 157 | ||
@@ -168,11 +165,11 @@ static int acpi_power_get_list_state(struct acpi_handle_list *list, int *state) | |||
168 | result = acpi_power_get_context(list->handles[i], &resource); | 165 | result = acpi_power_get_context(list->handles[i], &resource); |
169 | if (result) | 166 | if (result) |
170 | return result; | 167 | return result; |
171 | result = acpi_power_get_state(resource); | 168 | result = acpi_power_get_state(resource, &state1); |
172 | if (result) | 169 | if (result) |
173 | return result; | 170 | return result; |
174 | 171 | ||
175 | *state = resource->state; | 172 | *state = state1; |
176 | 173 | ||
177 | if (*state != ACPI_POWER_RESOURCE_STATE_ON) | 174 | if (*state != ACPI_POWER_RESOURCE_STATE_ON) |
178 | break; | 175 | break; |
@@ -186,7 +183,7 @@ static int acpi_power_get_list_state(struct acpi_handle_list *list, int *state) | |||
186 | 183 | ||
187 | static int acpi_power_on(acpi_handle handle, struct acpi_device *dev) | 184 | static int acpi_power_on(acpi_handle handle, struct acpi_device *dev) |
188 | { | 185 | { |
189 | int result = 0; | 186 | int result = 0, state; |
190 | int found = 0; | 187 | int found = 0; |
191 | acpi_status status = AE_OK; | 188 | acpi_status status = AE_OK; |
192 | struct acpi_power_resource *resource = NULL; | 189 | struct acpi_power_resource *resource = NULL; |
@@ -224,20 +221,14 @@ static int acpi_power_on(acpi_handle handle, struct acpi_device *dev) | |||
224 | } | 221 | } |
225 | mutex_unlock(&resource->resource_lock); | 222 | mutex_unlock(&resource->resource_lock); |
226 | 223 | ||
227 | if (resource->state == ACPI_POWER_RESOURCE_STATE_ON) { | ||
228 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] already on\n", | ||
229 | resource->name)); | ||
230 | return 0; | ||
231 | } | ||
232 | |||
233 | status = acpi_evaluate_object(resource->device->handle, "_ON", NULL, NULL); | 224 | status = acpi_evaluate_object(resource->device->handle, "_ON", NULL, NULL); |
234 | if (ACPI_FAILURE(status)) | 225 | if (ACPI_FAILURE(status)) |
235 | return -ENODEV; | 226 | return -ENODEV; |
236 | 227 | ||
237 | result = acpi_power_get_state(resource); | 228 | result = acpi_power_get_state(resource, &state); |
238 | if (result) | 229 | if (result) |
239 | return result; | 230 | return result; |
240 | if (resource->state != ACPI_POWER_RESOURCE_STATE_ON) | 231 | if (state != ACPI_POWER_RESOURCE_STATE_ON) |
241 | return -ENOEXEC; | 232 | return -ENOEXEC; |
242 | 233 | ||
243 | /* Update the power resource's _device_ power state */ | 234 | /* Update the power resource's _device_ power state */ |
@@ -250,7 +241,7 @@ static int acpi_power_on(acpi_handle handle, struct acpi_device *dev) | |||
250 | 241 | ||
251 | static int acpi_power_off_device(acpi_handle handle, struct acpi_device *dev) | 242 | static int acpi_power_off_device(acpi_handle handle, struct acpi_device *dev) |
252 | { | 243 | { |
253 | int result = 0; | 244 | int result = 0, state; |
254 | acpi_status status = AE_OK; | 245 | acpi_status status = AE_OK; |
255 | struct acpi_power_resource *resource = NULL; | 246 | struct acpi_power_resource *resource = NULL; |
256 | struct list_head *node, *next; | 247 | struct list_head *node, *next; |
@@ -281,20 +272,14 @@ static int acpi_power_off_device(acpi_handle handle, struct acpi_device *dev) | |||
281 | } | 272 | } |
282 | mutex_unlock(&resource->resource_lock); | 273 | mutex_unlock(&resource->resource_lock); |
283 | 274 | ||
284 | if (resource->state == ACPI_POWER_RESOURCE_STATE_OFF) { | ||
285 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] already off\n", | ||
286 | resource->name)); | ||
287 | return 0; | ||
288 | } | ||
289 | |||
290 | status = acpi_evaluate_object(resource->device->handle, "_OFF", NULL, NULL); | 275 | status = acpi_evaluate_object(resource->device->handle, "_OFF", NULL, NULL); |
291 | if (ACPI_FAILURE(status)) | 276 | if (ACPI_FAILURE(status)) |
292 | return -ENODEV; | 277 | return -ENODEV; |
293 | 278 | ||
294 | result = acpi_power_get_state(resource); | 279 | result = acpi_power_get_state(resource, &state); |
295 | if (result) | 280 | if (result) |
296 | return result; | 281 | return result; |
297 | if (resource->state != ACPI_POWER_RESOURCE_STATE_OFF) | 282 | if (state != ACPI_POWER_RESOURCE_STATE_OFF) |
298 | return -ENOEXEC; | 283 | return -ENOEXEC; |
299 | 284 | ||
300 | /* Update the power resource's _device_ power state */ | 285 | /* Update the power resource's _device_ power state */ |
@@ -494,7 +479,7 @@ static struct proc_dir_entry *acpi_power_dir; | |||
494 | static int acpi_power_seq_show(struct seq_file *seq, void *offset) | 479 | static int acpi_power_seq_show(struct seq_file *seq, void *offset) |
495 | { | 480 | { |
496 | int count = 0; | 481 | int count = 0; |
497 | int result = 0; | 482 | int result = 0, state; |
498 | struct acpi_power_resource *resource = NULL; | 483 | struct acpi_power_resource *resource = NULL; |
499 | struct list_head *node, *next; | 484 | struct list_head *node, *next; |
500 | struct acpi_power_reference *ref; | 485 | struct acpi_power_reference *ref; |
@@ -505,12 +490,12 @@ static int acpi_power_seq_show(struct seq_file *seq, void *offset) | |||
505 | if (!resource) | 490 | if (!resource) |
506 | goto end; | 491 | goto end; |
507 | 492 | ||
508 | result = acpi_power_get_state(resource); | 493 | result = acpi_power_get_state(resource, &state); |
509 | if (result) | 494 | if (result) |
510 | goto end; | 495 | goto end; |
511 | 496 | ||
512 | seq_puts(seq, "state: "); | 497 | seq_puts(seq, "state: "); |
513 | switch (resource->state) { | 498 | switch (state) { |
514 | case ACPI_POWER_RESOURCE_STATE_ON: | 499 | case ACPI_POWER_RESOURCE_STATE_ON: |
515 | seq_puts(seq, "on\n"); | 500 | seq_puts(seq, "on\n"); |
516 | break; | 501 | break; |
@@ -591,7 +576,7 @@ static int acpi_power_remove_fs(struct acpi_device *device) | |||
591 | 576 | ||
592 | static int acpi_power_add(struct acpi_device *device) | 577 | static int acpi_power_add(struct acpi_device *device) |
593 | { | 578 | { |
594 | int result = 0; | 579 | int result = 0, state; |
595 | acpi_status status = AE_OK; | 580 | acpi_status status = AE_OK; |
596 | struct acpi_power_resource *resource = NULL; | 581 | struct acpi_power_resource *resource = NULL; |
597 | union acpi_object acpi_object; | 582 | union acpi_object acpi_object; |
@@ -622,11 +607,11 @@ static int acpi_power_add(struct acpi_device *device) | |||
622 | resource->system_level = acpi_object.power_resource.system_level; | 607 | resource->system_level = acpi_object.power_resource.system_level; |
623 | resource->order = acpi_object.power_resource.resource_order; | 608 | resource->order = acpi_object.power_resource.resource_order; |
624 | 609 | ||
625 | result = acpi_power_get_state(resource); | 610 | result = acpi_power_get_state(resource, &state); |
626 | if (result) | 611 | if (result) |
627 | goto end; | 612 | goto end; |
628 | 613 | ||
629 | switch (resource->state) { | 614 | switch (state) { |
630 | case ACPI_POWER_RESOURCE_STATE_ON: | 615 | case ACPI_POWER_RESOURCE_STATE_ON: |
631 | device->power.state = ACPI_STATE_D0; | 616 | device->power.state = ACPI_STATE_D0; |
632 | break; | 617 | break; |
@@ -643,7 +628,7 @@ static int acpi_power_add(struct acpi_device *device) | |||
643 | goto end; | 628 | goto end; |
644 | 629 | ||
645 | printk(KERN_INFO PREFIX "%s [%s] (%s)\n", acpi_device_name(device), | 630 | printk(KERN_INFO PREFIX "%s [%s] (%s)\n", acpi_device_name(device), |
646 | acpi_device_bid(device), resource->state ? "on" : "off"); | 631 | acpi_device_bid(device), state ? "on" : "off"); |
647 | 632 | ||
648 | end: | 633 | end: |
649 | if (result) | 634 | if (result) |
@@ -680,7 +665,7 @@ static int acpi_power_remove(struct acpi_device *device, int type) | |||
680 | 665 | ||
681 | static int acpi_power_resume(struct acpi_device *device) | 666 | static int acpi_power_resume(struct acpi_device *device) |
682 | { | 667 | { |
683 | int result = 0; | 668 | int result = 0, state; |
684 | struct acpi_power_resource *resource = NULL; | 669 | struct acpi_power_resource *resource = NULL; |
685 | struct acpi_power_reference *ref; | 670 | struct acpi_power_reference *ref; |
686 | 671 | ||
@@ -689,12 +674,12 @@ static int acpi_power_resume(struct acpi_device *device) | |||
689 | 674 | ||
690 | resource = (struct acpi_power_resource *)acpi_driver_data(device); | 675 | resource = (struct acpi_power_resource *)acpi_driver_data(device); |
691 | 676 | ||
692 | result = acpi_power_get_state(resource); | 677 | result = acpi_power_get_state(resource, &state); |
693 | if (result) | 678 | if (result) |
694 | return result; | 679 | return result; |
695 | 680 | ||
696 | mutex_lock(&resource->resource_lock); | 681 | mutex_lock(&resource->resource_lock); |
697 | if ((resource->state == ACPI_POWER_RESOURCE_STATE_OFF) && | 682 | if (state == ACPI_POWER_RESOURCE_STATE_OFF && |
698 | !list_empty(&resource->reference)) { | 683 | !list_empty(&resource->reference)) { |
699 | ref = container_of(resource->reference.next, struct acpi_power_reference, node); | 684 | ref = container_of(resource->reference.next, struct acpi_power_reference, node); |
700 | mutex_unlock(&resource->resource_lock); | 685 | mutex_unlock(&resource->resource_lock); |
diff --git a/drivers/acpi/processor_core.c b/drivers/acpi/processor_core.c index a7351084f2f8..235a51e328c3 100644 --- a/drivers/acpi/processor_core.c +++ b/drivers/acpi/processor_core.c | |||
@@ -422,12 +422,6 @@ static int map_lsapic_id(struct acpi_subtable_header *entry, | |||
422 | return 0; | 422 | return 0; |
423 | } | 423 | } |
424 | 424 | ||
425 | #ifdef CONFIG_IA64 | ||
426 | #define arch_cpu_to_apicid ia64_cpu_to_sapicid | ||
427 | #else | ||
428 | #define arch_cpu_to_apicid x86_cpu_to_apicid | ||
429 | #endif | ||
430 | |||
431 | static int map_madt_entry(u32 acpi_id) | 425 | static int map_madt_entry(u32 acpi_id) |
432 | { | 426 | { |
433 | unsigned long madt_end, entry; | 427 | unsigned long madt_end, entry; |
@@ -501,7 +495,7 @@ static int get_cpu_id(acpi_handle handle, u32 acpi_id) | |||
501 | return apic_id; | 495 | return apic_id; |
502 | 496 | ||
503 | for (i = 0; i < NR_CPUS; ++i) { | 497 | for (i = 0; i < NR_CPUS; ++i) { |
504 | if (arch_cpu_to_apicid[i] == apic_id) | 498 | if (cpu_physical_id(i) == apic_id) |
505 | return i; | 499 | return i; |
506 | } | 500 | } |
507 | return -1; | 501 | return -1; |
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c index 8904f5c82a1c..7b6c20eeeaff 100644 --- a/drivers/acpi/processor_idle.c +++ b/drivers/acpi/processor_idle.c | |||
@@ -102,7 +102,7 @@ static int acpi_processor_set_power_policy(struct acpi_processor *pr); | |||
102 | * | 102 | * |
103 | * To skip this limit, boot/load with a large max_cstate limit. | 103 | * To skip this limit, boot/load with a large max_cstate limit. |
104 | */ | 104 | */ |
105 | static int set_max_cstate(struct dmi_system_id *id) | 105 | static int set_max_cstate(const struct dmi_system_id *id) |
106 | { | 106 | { |
107 | if (max_cstate > ACPI_PROCESSOR_MAX_POWER) | 107 | if (max_cstate > ACPI_PROCESSOR_MAX_POWER) |
108 | return 0; | 108 | return 0; |
@@ -299,21 +299,12 @@ static void acpi_timer_check_state(int state, struct acpi_processor *pr, | |||
299 | 299 | ||
300 | static void acpi_propagate_timer_broadcast(struct acpi_processor *pr) | 300 | static void acpi_propagate_timer_broadcast(struct acpi_processor *pr) |
301 | { | 301 | { |
302 | #ifdef CONFIG_GENERIC_CLOCKEVENTS | ||
303 | unsigned long reason; | 302 | unsigned long reason; |
304 | 303 | ||
305 | reason = pr->power.timer_broadcast_on_state < INT_MAX ? | 304 | reason = pr->power.timer_broadcast_on_state < INT_MAX ? |
306 | CLOCK_EVT_NOTIFY_BROADCAST_ON : CLOCK_EVT_NOTIFY_BROADCAST_OFF; | 305 | CLOCK_EVT_NOTIFY_BROADCAST_ON : CLOCK_EVT_NOTIFY_BROADCAST_OFF; |
307 | 306 | ||
308 | clockevents_notify(reason, &pr->id); | 307 | clockevents_notify(reason, &pr->id); |
309 | #else | ||
310 | cpumask_t mask = cpumask_of_cpu(pr->id); | ||
311 | |||
312 | if (pr->power.timer_broadcast_on_state < INT_MAX) | ||
313 | on_each_cpu(switch_APIC_timer_to_ipi, &mask, 1, 1); | ||
314 | else | ||
315 | on_each_cpu(switch_ipi_to_APIC_timer, &mask, 1, 1); | ||
316 | #endif | ||
317 | } | 308 | } |
318 | 309 | ||
319 | /* Power(C) State timer broadcast control */ | 310 | /* Power(C) State timer broadcast control */ |
@@ -321,8 +312,6 @@ static void acpi_state_timer_broadcast(struct acpi_processor *pr, | |||
321 | struct acpi_processor_cx *cx, | 312 | struct acpi_processor_cx *cx, |
322 | int broadcast) | 313 | int broadcast) |
323 | { | 314 | { |
324 | #ifdef CONFIG_GENERIC_CLOCKEVENTS | ||
325 | |||
326 | int state = cx - pr->power.states; | 315 | int state = cx - pr->power.states; |
327 | 316 | ||
328 | if (state >= pr->power.timer_broadcast_on_state) { | 317 | if (state >= pr->power.timer_broadcast_on_state) { |
@@ -332,7 +321,6 @@ static void acpi_state_timer_broadcast(struct acpi_processor *pr, | |||
332 | CLOCK_EVT_NOTIFY_BROADCAST_EXIT; | 321 | CLOCK_EVT_NOTIFY_BROADCAST_EXIT; |
333 | clockevents_notify(reason, &pr->id); | 322 | clockevents_notify(reason, &pr->id); |
334 | } | 323 | } |
335 | #endif | ||
336 | } | 324 | } |
337 | 325 | ||
338 | #else | 326 | #else |
diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c index a578986e3214..73c1ba314299 100644 --- a/drivers/acpi/sbs.c +++ b/drivers/acpi/sbs.c | |||
@@ -1,6 +1,8 @@ | |||
1 | /* | 1 | /* |
2 | * acpi_sbs.c - ACPI Smart Battery System Driver ($Revision: 1.16 $) | 2 | * sbs.c - ACPI Smart Battery System Driver ($Revision: 2.0 $) |
3 | * | 3 | * |
4 | * Copyright (c) 2007 Alexey Starikovskiy <astarikovskiy@suse.de> | ||
5 | * Copyright (c) 2005-2007 Vladimir Lebedev <vladimir.p.lebedev@intel.com> | ||
4 | * Copyright (c) 2005 Rich Townsend <rhdt@bartol.udel.edu> | 6 | * Copyright (c) 2005 Rich Townsend <rhdt@bartol.udel.edu> |
5 | * | 7 | * |
6 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 8 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
@@ -26,15 +28,22 @@ | |||
26 | #include <linux/module.h> | 28 | #include <linux/module.h> |
27 | #include <linux/moduleparam.h> | 29 | #include <linux/moduleparam.h> |
28 | #include <linux/kernel.h> | 30 | #include <linux/kernel.h> |
31 | |||
32 | #ifdef CONFIG_ACPI_PROCFS | ||
29 | #include <linux/proc_fs.h> | 33 | #include <linux/proc_fs.h> |
30 | #include <linux/seq_file.h> | 34 | #include <linux/seq_file.h> |
31 | #include <asm/uaccess.h> | 35 | #include <asm/uaccess.h> |
36 | #endif | ||
37 | |||
32 | #include <linux/acpi.h> | 38 | #include <linux/acpi.h> |
33 | #include <linux/timer.h> | 39 | #include <linux/timer.h> |
34 | #include <linux/jiffies.h> | 40 | #include <linux/jiffies.h> |
35 | #include <linux/delay.h> | 41 | #include <linux/delay.h> |
36 | 42 | ||
37 | #define ACPI_SBS_COMPONENT 0x00080000 | 43 | #include <linux/power_supply.h> |
44 | |||
45 | #include "sbshc.h" | ||
46 | |||
38 | #define ACPI_SBS_CLASS "sbs" | 47 | #define ACPI_SBS_CLASS "sbs" |
39 | #define ACPI_AC_CLASS "ac_adapter" | 48 | #define ACPI_AC_CLASS "ac_adapter" |
40 | #define ACPI_BATTERY_CLASS "battery" | 49 | #define ACPI_BATTERY_CLASS "battery" |
@@ -44,836 +53,437 @@ | |||
44 | #define ACPI_SBS_FILE_ALARM "alarm" | 53 | #define ACPI_SBS_FILE_ALARM "alarm" |
45 | #define ACPI_BATTERY_DIR_NAME "BAT%i" | 54 | #define ACPI_BATTERY_DIR_NAME "BAT%i" |
46 | #define ACPI_AC_DIR_NAME "AC0" | 55 | #define ACPI_AC_DIR_NAME "AC0" |
47 | #define ACPI_SBC_SMBUS_ADDR 0x9 | ||
48 | #define ACPI_SBSM_SMBUS_ADDR 0xa | ||
49 | #define ACPI_SB_SMBUS_ADDR 0xb | ||
50 | #define ACPI_SBS_AC_NOTIFY_STATUS 0x80 | ||
51 | #define ACPI_SBS_BATTERY_NOTIFY_STATUS 0x80 | ||
52 | #define ACPI_SBS_BATTERY_NOTIFY_INFO 0x81 | ||
53 | 56 | ||
54 | #define _COMPONENT ACPI_SBS_COMPONENT | 57 | enum acpi_sbs_device_addr { |
58 | ACPI_SBS_CHARGER = 0x9, | ||
59 | ACPI_SBS_MANAGER = 0xa, | ||
60 | ACPI_SBS_BATTERY = 0xb, | ||
61 | }; | ||
55 | 62 | ||
56 | ACPI_MODULE_NAME("sbs"); | 63 | #define ACPI_SBS_NOTIFY_STATUS 0x80 |
64 | #define ACPI_SBS_NOTIFY_INFO 0x81 | ||
57 | 65 | ||
58 | MODULE_AUTHOR("Rich Townsend"); | 66 | MODULE_AUTHOR("Alexey Starikovskiy <astarikovskiy@suse.de>"); |
59 | MODULE_DESCRIPTION("Smart Battery System ACPI interface driver"); | 67 | MODULE_DESCRIPTION("Smart Battery System ACPI interface driver"); |
60 | MODULE_LICENSE("GPL"); | 68 | MODULE_LICENSE("GPL"); |
61 | 69 | ||
62 | #define xmsleep(t) msleep(t) | 70 | static unsigned int cache_time = 1000; |
63 | 71 | module_param(cache_time, uint, 0644); | |
64 | #define ACPI_EC_SMB_PRTCL 0x00 /* protocol, PEC */ | 72 | MODULE_PARM_DESC(cache_time, "cache time in milliseconds"); |
65 | |||
66 | #define ACPI_EC_SMB_STS 0x01 /* status */ | ||
67 | #define ACPI_EC_SMB_ADDR 0x02 /* address */ | ||
68 | #define ACPI_EC_SMB_CMD 0x03 /* command */ | ||
69 | #define ACPI_EC_SMB_DATA 0x04 /* 32 data registers */ | ||
70 | #define ACPI_EC_SMB_BCNT 0x24 /* number of data bytes */ | ||
71 | |||
72 | #define ACPI_EC_SMB_STS_DONE 0x80 | ||
73 | #define ACPI_EC_SMB_STS_STATUS 0x1f | ||
74 | |||
75 | #define ACPI_EC_SMB_PRTCL_WRITE 0x00 | ||
76 | #define ACPI_EC_SMB_PRTCL_READ 0x01 | ||
77 | #define ACPI_EC_SMB_PRTCL_WORD_DATA 0x08 | ||
78 | #define ACPI_EC_SMB_PRTCL_BLOCK_DATA 0x0a | ||
79 | |||
80 | #define ACPI_EC_SMB_TRANSACTION_SLEEP 1 | ||
81 | #define ACPI_EC_SMB_ACCESS_SLEEP1 1 | ||
82 | #define ACPI_EC_SMB_ACCESS_SLEEP2 10 | ||
83 | |||
84 | #define DEF_CAPACITY_UNIT 3 | ||
85 | #define MAH_CAPACITY_UNIT 1 | ||
86 | #define MWH_CAPACITY_UNIT 2 | ||
87 | #define CAPACITY_UNIT DEF_CAPACITY_UNIT | ||
88 | |||
89 | #define REQUEST_UPDATE_MODE 1 | ||
90 | #define QUEUE_UPDATE_MODE 2 | ||
91 | |||
92 | #define DATA_TYPE_COMMON 0 | ||
93 | #define DATA_TYPE_INFO 1 | ||
94 | #define DATA_TYPE_STATE 2 | ||
95 | #define DATA_TYPE_ALARM 3 | ||
96 | #define DATA_TYPE_AC_STATE 4 | ||
97 | 73 | ||
98 | extern struct proc_dir_entry *acpi_lock_ac_dir(void); | 74 | extern struct proc_dir_entry *acpi_lock_ac_dir(void); |
99 | extern struct proc_dir_entry *acpi_lock_battery_dir(void); | 75 | extern struct proc_dir_entry *acpi_lock_battery_dir(void); |
100 | extern void acpi_unlock_ac_dir(struct proc_dir_entry *acpi_ac_dir); | 76 | extern void acpi_unlock_ac_dir(struct proc_dir_entry *acpi_ac_dir); |
101 | extern void acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir); | 77 | extern void acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir); |
102 | 78 | ||
103 | #define MAX_SBS_BAT 4 | 79 | #define MAX_SBS_BAT 4 |
104 | #define ACPI_SBS_BLOCK_MAX 32 | 80 | #define ACPI_SBS_BLOCK_MAX 32 |
105 | 81 | ||
106 | #define ACPI_SBS_SMBUS_READ 1 | ||
107 | #define ACPI_SBS_SMBUS_WRITE 2 | ||
108 | |||
109 | #define ACPI_SBS_WORD_DATA 1 | ||
110 | #define ACPI_SBS_BLOCK_DATA 2 | ||
111 | |||
112 | #define UPDATE_DELAY 10 | ||
113 | |||
114 | /* 0 - every time, > 0 - by update_time */ | ||
115 | static unsigned int update_time = 120; | ||
116 | |||
117 | static unsigned int capacity_mode = CAPACITY_UNIT; | ||
118 | |||
119 | module_param(update_time, uint, 0644); | ||
120 | module_param(capacity_mode, uint, 0444); | ||
121 | |||
122 | static int acpi_sbs_add(struct acpi_device *device); | ||
123 | static int acpi_sbs_remove(struct acpi_device *device, int type); | ||
124 | static int acpi_sbs_resume(struct acpi_device *device); | ||
125 | |||
126 | static const struct acpi_device_id sbs_device_ids[] = { | 82 | static const struct acpi_device_id sbs_device_ids[] = { |
127 | {"ACPI0001", 0}, | 83 | {"ACPI0002", 0}, |
128 | {"ACPI0005", 0}, | ||
129 | {"", 0}, | 84 | {"", 0}, |
130 | }; | 85 | }; |
131 | MODULE_DEVICE_TABLE(acpi, sbs_device_ids); | 86 | MODULE_DEVICE_TABLE(acpi, sbs_device_ids); |
132 | 87 | ||
133 | static struct acpi_driver acpi_sbs_driver = { | ||
134 | .name = "sbs", | ||
135 | .class = ACPI_SBS_CLASS, | ||
136 | .ids = sbs_device_ids, | ||
137 | .ops = { | ||
138 | .add = acpi_sbs_add, | ||
139 | .remove = acpi_sbs_remove, | ||
140 | .resume = acpi_sbs_resume, | ||
141 | }, | ||
142 | }; | ||
143 | |||
144 | struct acpi_ac { | ||
145 | int ac_present; | ||
146 | }; | ||
147 | |||
148 | struct acpi_battery_info { | ||
149 | int capacity_mode; | ||
150 | s16 full_charge_capacity; | ||
151 | s16 design_capacity; | ||
152 | s16 design_voltage; | ||
153 | int vscale; | ||
154 | int ipscale; | ||
155 | s16 serial_number; | ||
156 | char manufacturer_name[ACPI_SBS_BLOCK_MAX + 3]; | ||
157 | char device_name[ACPI_SBS_BLOCK_MAX + 3]; | ||
158 | char device_chemistry[ACPI_SBS_BLOCK_MAX + 3]; | ||
159 | }; | ||
160 | |||
161 | struct acpi_battery_state { | ||
162 | s16 voltage; | ||
163 | s16 amperage; | ||
164 | s16 remaining_capacity; | ||
165 | s16 battery_state; | ||
166 | }; | ||
167 | |||
168 | struct acpi_battery_alarm { | ||
169 | s16 remaining_capacity; | ||
170 | }; | ||
171 | |||
172 | struct acpi_battery { | 88 | struct acpi_battery { |
173 | int alive; | 89 | struct power_supply bat; |
174 | int id; | ||
175 | int init_state; | ||
176 | int battery_present; | ||
177 | struct acpi_sbs *sbs; | 90 | struct acpi_sbs *sbs; |
178 | struct acpi_battery_info info; | 91 | #ifdef CONFIG_ACPI_PROCFS |
179 | struct acpi_battery_state state; | 92 | struct proc_dir_entry *proc_entry; |
180 | struct acpi_battery_alarm alarm; | 93 | #endif |
181 | struct proc_dir_entry *battery_entry; | 94 | unsigned long update_time; |
95 | char name[8]; | ||
96 | char manufacturer_name[ACPI_SBS_BLOCK_MAX]; | ||
97 | char device_name[ACPI_SBS_BLOCK_MAX]; | ||
98 | char device_chemistry[ACPI_SBS_BLOCK_MAX]; | ||
99 | u16 alarm_capacity; | ||
100 | u16 full_charge_capacity; | ||
101 | u16 design_capacity; | ||
102 | u16 design_voltage; | ||
103 | u16 serial_number; | ||
104 | u16 cycle_count; | ||
105 | u16 temp_now; | ||
106 | u16 voltage_now; | ||
107 | s16 current_now; | ||
108 | s16 current_avg; | ||
109 | u16 capacity_now; | ||
110 | u16 state_of_charge; | ||
111 | u16 state; | ||
112 | u16 mode; | ||
113 | u16 spec; | ||
114 | u8 id; | ||
115 | u8 present:1; | ||
116 | u8 have_sysfs_alarm:1; | ||
182 | }; | 117 | }; |
183 | 118 | ||
119 | #define to_acpi_battery(x) container_of(x, struct acpi_battery, bat); | ||
120 | |||
184 | struct acpi_sbs { | 121 | struct acpi_sbs { |
185 | int base; | 122 | struct power_supply charger; |
186 | struct acpi_device *device; | 123 | struct acpi_device *device; |
187 | struct mutex mutex; | 124 | struct acpi_smb_hc *hc; |
188 | int sbsm_present; | 125 | struct mutex lock; |
189 | int sbsm_batteries_supported; | 126 | #ifdef CONFIG_ACPI_PROCFS |
190 | struct proc_dir_entry *ac_entry; | 127 | struct proc_dir_entry *charger_entry; |
191 | struct acpi_ac ac; | 128 | #endif |
192 | struct acpi_battery battery[MAX_SBS_BAT]; | 129 | struct acpi_battery battery[MAX_SBS_BAT]; |
193 | int zombie; | 130 | u8 batteries_supported:4; |
194 | struct timer_list update_timer; | 131 | u8 manager_present:1; |
195 | int run_cnt; | 132 | u8 charger_present:1; |
196 | int update_proc_flg; | ||
197 | }; | 133 | }; |
198 | 134 | ||
199 | static int acpi_sbs_update_run(struct acpi_sbs *sbs, int id, int data_type); | 135 | #define to_acpi_sbs(x) container_of(x, struct acpi_sbs, charger) |
200 | static void acpi_sbs_update_time(void *data); | ||
201 | 136 | ||
202 | union sbs_rw_data { | 137 | static inline int battery_scale(int log) |
203 | u16 word; | ||
204 | u8 block[ACPI_SBS_BLOCK_MAX + 2]; | ||
205 | }; | ||
206 | |||
207 | static int acpi_ec_sbs_access(struct acpi_sbs *sbs, u16 addr, | ||
208 | char read_write, u8 command, int size, | ||
209 | union sbs_rw_data *data); | ||
210 | |||
211 | /* -------------------------------------------------------------------------- | ||
212 | SMBus Communication | ||
213 | -------------------------------------------------------------------------- */ | ||
214 | |||
215 | static int acpi_ec_sbs_read(struct acpi_sbs *sbs, u8 address, u8 * data) | ||
216 | { | 138 | { |
217 | u8 val; | 139 | int scale = 1; |
218 | int err; | 140 | while (log--) |
219 | 141 | scale *= 10; | |
220 | err = ec_read(sbs->base + address, &val); | 142 | return scale; |
221 | if (!err) { | ||
222 | *data = val; | ||
223 | } | ||
224 | xmsleep(ACPI_EC_SMB_TRANSACTION_SLEEP); | ||
225 | return (err); | ||
226 | } | ||
227 | |||
228 | static int acpi_ec_sbs_write(struct acpi_sbs *sbs, u8 address, u8 data) | ||
229 | { | ||
230 | int err; | ||
231 | |||
232 | err = ec_write(sbs->base + address, data); | ||
233 | return (err); | ||
234 | } | ||
235 | |||
236 | static int | ||
237 | acpi_ec_sbs_access(struct acpi_sbs *sbs, u16 addr, | ||
238 | char read_write, u8 command, int size, | ||
239 | union sbs_rw_data *data) | ||
240 | { | ||
241 | unsigned char protocol, len = 0, temp[2] = { 0, 0 }; | ||
242 | int i; | ||
243 | |||
244 | if (read_write == ACPI_SBS_SMBUS_READ) { | ||
245 | protocol = ACPI_EC_SMB_PRTCL_READ; | ||
246 | } else { | ||
247 | protocol = ACPI_EC_SMB_PRTCL_WRITE; | ||
248 | } | ||
249 | |||
250 | switch (size) { | ||
251 | |||
252 | case ACPI_SBS_WORD_DATA: | ||
253 | acpi_ec_sbs_write(sbs, ACPI_EC_SMB_CMD, command); | ||
254 | if (read_write == ACPI_SBS_SMBUS_WRITE) { | ||
255 | acpi_ec_sbs_write(sbs, ACPI_EC_SMB_DATA, data->word); | ||
256 | acpi_ec_sbs_write(sbs, ACPI_EC_SMB_DATA + 1, | ||
257 | data->word >> 8); | ||
258 | } | ||
259 | protocol |= ACPI_EC_SMB_PRTCL_WORD_DATA; | ||
260 | break; | ||
261 | case ACPI_SBS_BLOCK_DATA: | ||
262 | acpi_ec_sbs_write(sbs, ACPI_EC_SMB_CMD, command); | ||
263 | if (read_write == ACPI_SBS_SMBUS_WRITE) { | ||
264 | len = min_t(u8, data->block[0], 32); | ||
265 | acpi_ec_sbs_write(sbs, ACPI_EC_SMB_BCNT, len); | ||
266 | for (i = 0; i < len; i++) | ||
267 | acpi_ec_sbs_write(sbs, ACPI_EC_SMB_DATA + i, | ||
268 | data->block[i + 1]); | ||
269 | } | ||
270 | protocol |= ACPI_EC_SMB_PRTCL_BLOCK_DATA; | ||
271 | break; | ||
272 | default: | ||
273 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
274 | "unsupported transaction %d", size)); | ||
275 | return (-1); | ||
276 | } | ||
277 | |||
278 | acpi_ec_sbs_write(sbs, ACPI_EC_SMB_ADDR, addr << 1); | ||
279 | acpi_ec_sbs_write(sbs, ACPI_EC_SMB_PRTCL, protocol); | ||
280 | |||
281 | acpi_ec_sbs_read(sbs, ACPI_EC_SMB_STS, temp); | ||
282 | |||
283 | if (~temp[0] & ACPI_EC_SMB_STS_DONE) { | ||
284 | xmsleep(ACPI_EC_SMB_ACCESS_SLEEP1); | ||
285 | acpi_ec_sbs_read(sbs, ACPI_EC_SMB_STS, temp); | ||
286 | } | ||
287 | if (~temp[0] & ACPI_EC_SMB_STS_DONE) { | ||
288 | xmsleep(ACPI_EC_SMB_ACCESS_SLEEP2); | ||
289 | acpi_ec_sbs_read(sbs, ACPI_EC_SMB_STS, temp); | ||
290 | } | ||
291 | if ((~temp[0] & ACPI_EC_SMB_STS_DONE) | ||
292 | || (temp[0] & ACPI_EC_SMB_STS_STATUS)) { | ||
293 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
294 | "transaction %d error", size)); | ||
295 | return (-1); | ||
296 | } | ||
297 | |||
298 | if (read_write == ACPI_SBS_SMBUS_WRITE) { | ||
299 | return (0); | ||
300 | } | ||
301 | |||
302 | switch (size) { | ||
303 | |||
304 | case ACPI_SBS_WORD_DATA: | ||
305 | acpi_ec_sbs_read(sbs, ACPI_EC_SMB_DATA, temp); | ||
306 | acpi_ec_sbs_read(sbs, ACPI_EC_SMB_DATA + 1, temp + 1); | ||
307 | data->word = (temp[1] << 8) | temp[0]; | ||
308 | break; | ||
309 | |||
310 | case ACPI_SBS_BLOCK_DATA: | ||
311 | len = 0; | ||
312 | acpi_ec_sbs_read(sbs, ACPI_EC_SMB_BCNT, &len); | ||
313 | len = min_t(u8, len, 32); | ||
314 | for (i = 0; i < len; i++) | ||
315 | acpi_ec_sbs_read(sbs, ACPI_EC_SMB_DATA + i, | ||
316 | data->block + i + 1); | ||
317 | data->block[0] = len; | ||
318 | break; | ||
319 | default: | ||
320 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
321 | "unsupported transaction %d", size)); | ||
322 | return (-1); | ||
323 | } | ||
324 | |||
325 | return (0); | ||
326 | } | 143 | } |
327 | 144 | ||
328 | static int | 145 | static inline int acpi_battery_vscale(struct acpi_battery *battery) |
329 | acpi_sbs_read_word(struct acpi_sbs *sbs, int addr, int func, u16 * word) | ||
330 | { | 146 | { |
331 | union sbs_rw_data data; | 147 | return battery_scale((battery->spec & 0x0f00) >> 8); |
332 | int result = 0; | ||
333 | |||
334 | result = acpi_ec_sbs_access(sbs, addr, | ||
335 | ACPI_SBS_SMBUS_READ, func, | ||
336 | ACPI_SBS_WORD_DATA, &data); | ||
337 | if (result) { | ||
338 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
339 | "acpi_ec_sbs_access() failed")); | ||
340 | } else { | ||
341 | *word = data.word; | ||
342 | } | ||
343 | |||
344 | return result; | ||
345 | } | 148 | } |
346 | 149 | ||
347 | static int | 150 | static inline int acpi_battery_ipscale(struct acpi_battery *battery) |
348 | acpi_sbs_read_str(struct acpi_sbs *sbs, int addr, int func, char *str) | ||
349 | { | 151 | { |
350 | union sbs_rw_data data; | 152 | return battery_scale((battery->spec & 0xf000) >> 12); |
351 | int result = 0; | ||
352 | |||
353 | result = acpi_ec_sbs_access(sbs, addr, | ||
354 | ACPI_SBS_SMBUS_READ, func, | ||
355 | ACPI_SBS_BLOCK_DATA, &data); | ||
356 | if (result) { | ||
357 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
358 | "acpi_ec_sbs_access() failed")); | ||
359 | } else { | ||
360 | strncpy(str, (const char *)data.block + 1, data.block[0]); | ||
361 | str[data.block[0]] = 0; | ||
362 | } | ||
363 | |||
364 | return result; | ||
365 | } | 153 | } |
366 | 154 | ||
367 | static int | 155 | static inline int acpi_battery_mode(struct acpi_battery *battery) |
368 | acpi_sbs_write_word(struct acpi_sbs *sbs, int addr, int func, int word) | ||
369 | { | 156 | { |
370 | union sbs_rw_data data; | 157 | return (battery->mode & 0x8000); |
371 | int result = 0; | ||
372 | |||
373 | data.word = word; | ||
374 | |||
375 | result = acpi_ec_sbs_access(sbs, addr, | ||
376 | ACPI_SBS_SMBUS_WRITE, func, | ||
377 | ACPI_SBS_WORD_DATA, &data); | ||
378 | if (result) { | ||
379 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
380 | "acpi_ec_sbs_access() failed")); | ||
381 | } | ||
382 | |||
383 | return result; | ||
384 | } | 158 | } |
385 | 159 | ||
386 | static int sbs_zombie(struct acpi_sbs *sbs) | 160 | static inline int acpi_battery_scale(struct acpi_battery *battery) |
387 | { | 161 | { |
388 | return (sbs->zombie); | 162 | return (acpi_battery_mode(battery) ? 10 : 1) * |
163 | acpi_battery_ipscale(battery); | ||
389 | } | 164 | } |
390 | 165 | ||
391 | static int sbs_mutex_lock(struct acpi_sbs *sbs) | 166 | static int sbs_get_ac_property(struct power_supply *psy, |
167 | enum power_supply_property psp, | ||
168 | union power_supply_propval *val) | ||
392 | { | 169 | { |
393 | if (sbs_zombie(sbs)) { | 170 | struct acpi_sbs *sbs = to_acpi_sbs(psy); |
394 | return -ENODEV; | 171 | switch (psp) { |
172 | case POWER_SUPPLY_PROP_ONLINE: | ||
173 | val->intval = sbs->charger_present; | ||
174 | break; | ||
175 | default: | ||
176 | return -EINVAL; | ||
395 | } | 177 | } |
396 | mutex_lock(&sbs->mutex); | ||
397 | return 0; | 178 | return 0; |
398 | } | 179 | } |
399 | 180 | ||
400 | static void sbs_mutex_unlock(struct acpi_sbs *sbs) | 181 | static int acpi_battery_technology(struct acpi_battery *battery) |
401 | { | 182 | { |
402 | mutex_unlock(&sbs->mutex); | 183 | if (!strcasecmp("NiCd", battery->device_chemistry)) |
184 | return POWER_SUPPLY_TECHNOLOGY_NiCd; | ||
185 | if (!strcasecmp("NiMH", battery->device_chemistry)) | ||
186 | return POWER_SUPPLY_TECHNOLOGY_NiMH; | ||
187 | if (!strcasecmp("LION", battery->device_chemistry)) | ||
188 | return POWER_SUPPLY_TECHNOLOGY_LION; | ||
189 | if (!strcasecmp("LiP", battery->device_chemistry)) | ||
190 | return POWER_SUPPLY_TECHNOLOGY_LIPO; | ||
191 | return POWER_SUPPLY_TECHNOLOGY_UNKNOWN; | ||
403 | } | 192 | } |
404 | 193 | ||
405 | /* -------------------------------------------------------------------------- | 194 | static int acpi_sbs_battery_get_property(struct power_supply *psy, |
406 | Smart Battery System Management | 195 | enum power_supply_property psp, |
407 | -------------------------------------------------------------------------- */ | 196 | union power_supply_propval *val) |
408 | |||
409 | static int acpi_check_update_proc(struct acpi_sbs *sbs) | ||
410 | { | 197 | { |
411 | acpi_status status = AE_OK; | 198 | struct acpi_battery *battery = to_acpi_battery(psy); |
412 | 199 | ||
413 | if (update_time == 0) { | 200 | if ((!battery->present) && psp != POWER_SUPPLY_PROP_PRESENT) |
414 | sbs->update_proc_flg = 0; | 201 | return -ENODEV; |
415 | return 0; | 202 | switch (psp) { |
416 | } | 203 | case POWER_SUPPLY_PROP_STATUS: |
417 | if (sbs->update_proc_flg == 0) { | 204 | if (battery->current_now < 0) |
418 | status = acpi_os_execute(OSL_GPE_HANDLER, | 205 | val->intval = POWER_SUPPLY_STATUS_DISCHARGING; |
419 | acpi_sbs_update_time, sbs); | 206 | else if (battery->current_now > 0) |
420 | if (status != AE_OK) { | 207 | val->intval = POWER_SUPPLY_STATUS_CHARGING; |
421 | ACPI_EXCEPTION((AE_INFO, status, | 208 | else |
422 | "acpi_os_execute() failed")); | 209 | val->intval = POWER_SUPPLY_STATUS_FULL; |
423 | return 1; | 210 | break; |
424 | } | 211 | case POWER_SUPPLY_PROP_PRESENT: |
425 | sbs->update_proc_flg = 1; | 212 | val->intval = battery->present; |
213 | break; | ||
214 | case POWER_SUPPLY_PROP_TECHNOLOGY: | ||
215 | val->intval = acpi_battery_technology(battery); | ||
216 | break; | ||
217 | case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN: | ||
218 | val->intval = battery->design_voltage * | ||
219 | acpi_battery_vscale(battery) * 1000; | ||
220 | break; | ||
221 | case POWER_SUPPLY_PROP_VOLTAGE_NOW: | ||
222 | val->intval = battery->voltage_now * | ||
223 | acpi_battery_vscale(battery) * 1000; | ||
224 | break; | ||
225 | case POWER_SUPPLY_PROP_CURRENT_NOW: | ||
226 | val->intval = abs(battery->current_now) * | ||
227 | acpi_battery_ipscale(battery) * 1000; | ||
228 | break; | ||
229 | case POWER_SUPPLY_PROP_CURRENT_AVG: | ||
230 | val->intval = abs(battery->current_avg) * | ||
231 | acpi_battery_ipscale(battery) * 1000; | ||
232 | break; | ||
233 | case POWER_SUPPLY_PROP_CAPACITY: | ||
234 | val->intval = battery->state_of_charge; | ||
235 | break; | ||
236 | case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: | ||
237 | case POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN: | ||
238 | val->intval = battery->design_capacity * | ||
239 | acpi_battery_scale(battery) * 1000; | ||
240 | break; | ||
241 | case POWER_SUPPLY_PROP_CHARGE_FULL: | ||
242 | case POWER_SUPPLY_PROP_ENERGY_FULL: | ||
243 | val->intval = battery->full_charge_capacity * | ||
244 | acpi_battery_scale(battery) * 1000; | ||
245 | break; | ||
246 | case POWER_SUPPLY_PROP_CHARGE_NOW: | ||
247 | case POWER_SUPPLY_PROP_ENERGY_NOW: | ||
248 | val->intval = battery->capacity_now * | ||
249 | acpi_battery_scale(battery) * 1000; | ||
250 | break; | ||
251 | case POWER_SUPPLY_PROP_TEMP: | ||
252 | val->intval = battery->temp_now - 2730; // dK -> dC | ||
253 | break; | ||
254 | case POWER_SUPPLY_PROP_MODEL_NAME: | ||
255 | val->strval = battery->device_name; | ||
256 | break; | ||
257 | case POWER_SUPPLY_PROP_MANUFACTURER: | ||
258 | val->strval = battery->manufacturer_name; | ||
259 | break; | ||
260 | default: | ||
261 | return -EINVAL; | ||
426 | } | 262 | } |
427 | return 0; | 263 | return 0; |
428 | } | 264 | } |
429 | 265 | ||
430 | static int acpi_sbs_generate_event(struct acpi_device *device, | 266 | static enum power_supply_property sbs_ac_props[] = { |
431 | int event, int state, char *bid, char *class) | 267 | POWER_SUPPLY_PROP_ONLINE, |
432 | { | 268 | }; |
433 | char bid_saved[5]; | ||
434 | char class_saved[20]; | ||
435 | int result = 0; | ||
436 | |||
437 | strcpy(bid_saved, acpi_device_bid(device)); | ||
438 | strcpy(class_saved, acpi_device_class(device)); | ||
439 | |||
440 | strcpy(acpi_device_bid(device), bid); | ||
441 | strcpy(acpi_device_class(device), class); | ||
442 | |||
443 | result = acpi_bus_generate_proc_event(device, event, state); | ||
444 | |||
445 | strcpy(acpi_device_bid(device), bid_saved); | ||
446 | strcpy(acpi_device_class(device), class_saved); | ||
447 | |||
448 | acpi_bus_generate_netlink_event(class, bid, event, state); | ||
449 | return result; | ||
450 | } | ||
451 | |||
452 | static int acpi_battery_get_present(struct acpi_battery *battery) | ||
453 | { | ||
454 | s16 state; | ||
455 | int result = 0; | ||
456 | int is_present = 0; | ||
457 | |||
458 | result = acpi_sbs_read_word(battery->sbs, | ||
459 | ACPI_SBSM_SMBUS_ADDR, 0x01, &state); | ||
460 | if (result) { | ||
461 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
462 | "acpi_sbs_read_word() failed")); | ||
463 | } | ||
464 | if (!result) { | ||
465 | is_present = (state & 0x000f) & (1 << battery->id); | ||
466 | } | ||
467 | battery->battery_present = is_present; | ||
468 | |||
469 | return result; | ||
470 | } | ||
471 | 269 | ||
472 | static int acpi_battery_select(struct acpi_battery *battery) | 270 | static enum power_supply_property sbs_charge_battery_props[] = { |
473 | { | 271 | POWER_SUPPLY_PROP_STATUS, |
474 | struct acpi_sbs *sbs = battery->sbs; | 272 | POWER_SUPPLY_PROP_PRESENT, |
475 | int result = 0; | 273 | POWER_SUPPLY_PROP_TECHNOLOGY, |
476 | s16 state; | 274 | POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN, |
477 | int foo; | 275 | POWER_SUPPLY_PROP_VOLTAGE_NOW, |
276 | POWER_SUPPLY_PROP_CURRENT_NOW, | ||
277 | POWER_SUPPLY_PROP_CURRENT_AVG, | ||
278 | POWER_SUPPLY_PROP_CAPACITY, | ||
279 | POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, | ||
280 | POWER_SUPPLY_PROP_CHARGE_FULL, | ||
281 | POWER_SUPPLY_PROP_CHARGE_NOW, | ||
282 | POWER_SUPPLY_PROP_TEMP, | ||
283 | POWER_SUPPLY_PROP_MODEL_NAME, | ||
284 | POWER_SUPPLY_PROP_MANUFACTURER, | ||
285 | }; | ||
478 | 286 | ||
479 | if (sbs->sbsm_present) { | 287 | static enum power_supply_property sbs_energy_battery_props[] = { |
288 | POWER_SUPPLY_PROP_STATUS, | ||
289 | POWER_SUPPLY_PROP_PRESENT, | ||
290 | POWER_SUPPLY_PROP_TECHNOLOGY, | ||
291 | POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN, | ||
292 | POWER_SUPPLY_PROP_VOLTAGE_NOW, | ||
293 | POWER_SUPPLY_PROP_CURRENT_NOW, | ||
294 | POWER_SUPPLY_PROP_CURRENT_AVG, | ||
295 | POWER_SUPPLY_PROP_CAPACITY, | ||
296 | POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN, | ||
297 | POWER_SUPPLY_PROP_ENERGY_FULL, | ||
298 | POWER_SUPPLY_PROP_ENERGY_NOW, | ||
299 | POWER_SUPPLY_PROP_TEMP, | ||
300 | POWER_SUPPLY_PROP_MODEL_NAME, | ||
301 | POWER_SUPPLY_PROP_MANUFACTURER, | ||
302 | }; | ||
480 | 303 | ||
481 | /* Take special care not to knobble other nibbles of | 304 | /* -------------------------------------------------------------------------- |
482 | * state (aka selector_state), since | 305 | Smart Battery System Management |
483 | * it causes charging to halt on SBSELs */ | 306 | -------------------------------------------------------------------------- */ |
484 | 307 | ||
485 | result = | 308 | struct acpi_battery_reader { |
486 | acpi_sbs_read_word(sbs, ACPI_SBSM_SMBUS_ADDR, 0x01, &state); | 309 | u8 command; /* command for battery */ |
487 | if (result) { | 310 | u8 mode; /* word or block? */ |
488 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | 311 | size_t offset; /* offset inside struct acpi_sbs_battery */ |
489 | "acpi_sbs_read_word() failed")); | 312 | }; |
490 | goto end; | ||
491 | } | ||
492 | 313 | ||
493 | foo = (state & 0x0fff) | (1 << (battery->id + 12)); | 314 | static struct acpi_battery_reader info_readers[] = { |
494 | result = | 315 | {0x01, SMBUS_READ_WORD, offsetof(struct acpi_battery, alarm_capacity)}, |
495 | acpi_sbs_write_word(sbs, ACPI_SBSM_SMBUS_ADDR, 0x01, foo); | 316 | {0x03, SMBUS_READ_WORD, offsetof(struct acpi_battery, mode)}, |
496 | if (result) { | 317 | {0x10, SMBUS_READ_WORD, offsetof(struct acpi_battery, full_charge_capacity)}, |
497 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | 318 | {0x17, SMBUS_READ_WORD, offsetof(struct acpi_battery, cycle_count)}, |
498 | "acpi_sbs_write_word() failed")); | 319 | {0x18, SMBUS_READ_WORD, offsetof(struct acpi_battery, design_capacity)}, |
499 | goto end; | 320 | {0x19, SMBUS_READ_WORD, offsetof(struct acpi_battery, design_voltage)}, |
500 | } | 321 | {0x1a, SMBUS_READ_WORD, offsetof(struct acpi_battery, spec)}, |
501 | } | 322 | {0x1c, SMBUS_READ_WORD, offsetof(struct acpi_battery, serial_number)}, |
323 | {0x20, SMBUS_READ_BLOCK, offsetof(struct acpi_battery, manufacturer_name)}, | ||
324 | {0x21, SMBUS_READ_BLOCK, offsetof(struct acpi_battery, device_name)}, | ||
325 | {0x22, SMBUS_READ_BLOCK, offsetof(struct acpi_battery, device_chemistry)}, | ||
326 | }; | ||
502 | 327 | ||
503 | end: | 328 | static struct acpi_battery_reader state_readers[] = { |
504 | return result; | 329 | {0x08, SMBUS_READ_WORD, offsetof(struct acpi_battery, temp_now)}, |
505 | } | 330 | {0x09, SMBUS_READ_WORD, offsetof(struct acpi_battery, voltage_now)}, |
331 | {0x0a, SMBUS_READ_WORD, offsetof(struct acpi_battery, current_now)}, | ||
332 | {0x0b, SMBUS_READ_WORD, offsetof(struct acpi_battery, current_avg)}, | ||
333 | {0x0f, SMBUS_READ_WORD, offsetof(struct acpi_battery, capacity_now)}, | ||
334 | {0x0e, SMBUS_READ_WORD, offsetof(struct acpi_battery, state_of_charge)}, | ||
335 | {0x16, SMBUS_READ_WORD, offsetof(struct acpi_battery, state)}, | ||
336 | }; | ||
506 | 337 | ||
507 | static int acpi_sbsm_get_info(struct acpi_sbs *sbs) | 338 | static int acpi_manager_get_info(struct acpi_sbs *sbs) |
508 | { | 339 | { |
509 | int result = 0; | 340 | int result = 0; |
510 | s16 battery_system_info; | 341 | u16 battery_system_info; |
511 | |||
512 | result = acpi_sbs_read_word(sbs, ACPI_SBSM_SMBUS_ADDR, 0x04, | ||
513 | &battery_system_info); | ||
514 | if (result) { | ||
515 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
516 | "acpi_sbs_read_word() failed")); | ||
517 | goto end; | ||
518 | } | ||
519 | sbs->sbsm_present = 1; | ||
520 | sbs->sbsm_batteries_supported = battery_system_info & 0x000f; | ||
521 | |||
522 | end: | ||
523 | 342 | ||
343 | result = acpi_smbus_read(sbs->hc, SMBUS_READ_WORD, ACPI_SBS_MANAGER, | ||
344 | 0x04, (u8 *)&battery_system_info); | ||
345 | if (!result) | ||
346 | sbs->batteries_supported = battery_system_info & 0x000f; | ||
524 | return result; | 347 | return result; |
525 | } | 348 | } |
526 | 349 | ||
527 | static int acpi_battery_get_info(struct acpi_battery *battery) | 350 | static int acpi_battery_get_info(struct acpi_battery *battery) |
528 | { | 351 | { |
529 | struct acpi_sbs *sbs = battery->sbs; | 352 | int i, result = 0; |
530 | int result = 0; | 353 | |
531 | s16 battery_mode; | 354 | for (i = 0; i < ARRAY_SIZE(info_readers); ++i) { |
532 | s16 specification_info; | 355 | result = acpi_smbus_read(battery->sbs->hc, |
533 | 356 | info_readers[i].mode, | |
534 | result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x03, | 357 | ACPI_SBS_BATTERY, |
535 | &battery_mode); | 358 | info_readers[i].command, |
536 | if (result) { | 359 | (u8 *) battery + |
537 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | 360 | info_readers[i].offset); |
538 | "acpi_sbs_read_word() failed")); | 361 | if (result) |
539 | goto end; | 362 | break; |
540 | } | ||
541 | battery->info.capacity_mode = (battery_mode & 0x8000) >> 15; | ||
542 | |||
543 | result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x10, | ||
544 | &battery->info.full_charge_capacity); | ||
545 | if (result) { | ||
546 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
547 | "acpi_sbs_read_word() failed")); | ||
548 | goto end; | ||
549 | } | ||
550 | |||
551 | result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x18, | ||
552 | &battery->info.design_capacity); | ||
553 | |||
554 | if (result) { | ||
555 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
556 | "acpi_sbs_read_word() failed")); | ||
557 | goto end; | ||
558 | } | ||
559 | |||
560 | result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x19, | ||
561 | &battery->info.design_voltage); | ||
562 | if (result) { | ||
563 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
564 | "acpi_sbs_read_word() failed")); | ||
565 | goto end; | ||
566 | } | 363 | } |
567 | |||
568 | result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x1a, | ||
569 | &specification_info); | ||
570 | if (result) { | ||
571 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
572 | "acpi_sbs_read_word() failed")); | ||
573 | goto end; | ||
574 | } | ||
575 | |||
576 | switch ((specification_info & 0x0f00) >> 8) { | ||
577 | case 1: | ||
578 | battery->info.vscale = 10; | ||
579 | break; | ||
580 | case 2: | ||
581 | battery->info.vscale = 100; | ||
582 | break; | ||
583 | case 3: | ||
584 | battery->info.vscale = 1000; | ||
585 | break; | ||
586 | default: | ||
587 | battery->info.vscale = 1; | ||
588 | } | ||
589 | |||
590 | switch ((specification_info & 0xf000) >> 12) { | ||
591 | case 1: | ||
592 | battery->info.ipscale = 10; | ||
593 | break; | ||
594 | case 2: | ||
595 | battery->info.ipscale = 100; | ||
596 | break; | ||
597 | case 3: | ||
598 | battery->info.ipscale = 1000; | ||
599 | break; | ||
600 | default: | ||
601 | battery->info.ipscale = 1; | ||
602 | } | ||
603 | |||
604 | result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x1c, | ||
605 | &battery->info.serial_number); | ||
606 | if (result) { | ||
607 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
608 | "acpi_sbs_read_word() failed")); | ||
609 | goto end; | ||
610 | } | ||
611 | |||
612 | result = acpi_sbs_read_str(sbs, ACPI_SB_SMBUS_ADDR, 0x20, | ||
613 | battery->info.manufacturer_name); | ||
614 | if (result) { | ||
615 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
616 | "acpi_sbs_read_str() failed")); | ||
617 | goto end; | ||
618 | } | ||
619 | |||
620 | result = acpi_sbs_read_str(sbs, ACPI_SB_SMBUS_ADDR, 0x21, | ||
621 | battery->info.device_name); | ||
622 | if (result) { | ||
623 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
624 | "acpi_sbs_read_str() failed")); | ||
625 | goto end; | ||
626 | } | ||
627 | |||
628 | result = acpi_sbs_read_str(sbs, ACPI_SB_SMBUS_ADDR, 0x22, | ||
629 | battery->info.device_chemistry); | ||
630 | if (result) { | ||
631 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
632 | "acpi_sbs_read_str() failed")); | ||
633 | goto end; | ||
634 | } | ||
635 | |||
636 | end: | ||
637 | return result; | 364 | return result; |
638 | } | 365 | } |
639 | 366 | ||
640 | static int acpi_battery_get_state(struct acpi_battery *battery) | 367 | static int acpi_battery_get_state(struct acpi_battery *battery) |
641 | { | 368 | { |
642 | struct acpi_sbs *sbs = battery->sbs; | 369 | int i, result = 0; |
643 | int result = 0; | ||
644 | 370 | ||
645 | result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x09, | 371 | if (battery->update_time && |
646 | &battery->state.voltage); | 372 | time_before(jiffies, battery->update_time + |
647 | if (result) { | 373 | msecs_to_jiffies(cache_time))) |
648 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | 374 | return 0; |
649 | "acpi_sbs_read_word() failed")); | 375 | for (i = 0; i < ARRAY_SIZE(state_readers); ++i) { |
650 | goto end; | 376 | result = acpi_smbus_read(battery->sbs->hc, |
651 | } | 377 | state_readers[i].mode, |
652 | 378 | ACPI_SBS_BATTERY, | |
653 | result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x0a, | 379 | state_readers[i].command, |
654 | &battery->state.amperage); | 380 | (u8 *)battery + |
655 | if (result) { | 381 | state_readers[i].offset); |
656 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | 382 | if (result) |
657 | "acpi_sbs_read_word() failed")); | 383 | goto end; |
658 | goto end; | ||
659 | } | ||
660 | |||
661 | result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x0f, | ||
662 | &battery->state.remaining_capacity); | ||
663 | if (result) { | ||
664 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
665 | "acpi_sbs_read_word() failed")); | ||
666 | goto end; | ||
667 | } | ||
668 | |||
669 | result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x16, | ||
670 | &battery->state.battery_state); | ||
671 | if (result) { | ||
672 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
673 | "acpi_sbs_read_word() failed")); | ||
674 | goto end; | ||
675 | } | 384 | } |
676 | |||
677 | end: | 385 | end: |
386 | battery->update_time = jiffies; | ||
678 | return result; | 387 | return result; |
679 | } | 388 | } |
680 | 389 | ||
681 | static int acpi_battery_get_alarm(struct acpi_battery *battery) | 390 | static int acpi_battery_get_alarm(struct acpi_battery *battery) |
682 | { | 391 | { |
683 | struct acpi_sbs *sbs = battery->sbs; | 392 | return acpi_smbus_read(battery->sbs->hc, SMBUS_READ_WORD, |
684 | int result = 0; | 393 | ACPI_SBS_BATTERY, 0x01, |
685 | 394 | (u8 *)&battery->alarm_capacity); | |
686 | result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x01, | ||
687 | &battery->alarm.remaining_capacity); | ||
688 | if (result) { | ||
689 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
690 | "acpi_sbs_read_word() failed")); | ||
691 | goto end; | ||
692 | } | ||
693 | |||
694 | end: | ||
695 | |||
696 | return result; | ||
697 | } | 395 | } |
698 | 396 | ||
699 | static int acpi_battery_set_alarm(struct acpi_battery *battery, | 397 | static int acpi_battery_set_alarm(struct acpi_battery *battery) |
700 | unsigned long alarm) | ||
701 | { | 398 | { |
702 | struct acpi_sbs *sbs = battery->sbs; | 399 | struct acpi_sbs *sbs = battery->sbs; |
703 | int result = 0; | 400 | u16 value, sel = 1 << (battery->id + 12); |
704 | s16 battery_mode; | ||
705 | int foo; | ||
706 | 401 | ||
707 | result = acpi_battery_select(battery); | 402 | int ret; |
708 | if (result) { | ||
709 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
710 | "acpi_battery_select() failed")); | ||
711 | goto end; | ||
712 | } | ||
713 | 403 | ||
714 | /* If necessary, enable the alarm */ | ||
715 | 404 | ||
716 | if (alarm > 0) { | 405 | if (sbs->manager_present) { |
717 | result = | 406 | ret = acpi_smbus_read(sbs->hc, SMBUS_READ_WORD, ACPI_SBS_MANAGER, |
718 | acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x03, | 407 | 0x01, (u8 *)&value); |
719 | &battery_mode); | 408 | if (ret) |
720 | if (result) { | ||
721 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
722 | "acpi_sbs_read_word() failed")); | ||
723 | goto end; | 409 | goto end; |
724 | } | 410 | if ((value & 0xf000) != sel) { |
725 | 411 | value &= 0x0fff; | |
726 | result = | 412 | value |= sel; |
727 | acpi_sbs_write_word(sbs, ACPI_SB_SMBUS_ADDR, 0x01, | 413 | ret = acpi_smbus_write(sbs->hc, SMBUS_WRITE_WORD, |
728 | battery_mode & 0xbfff); | 414 | ACPI_SBS_MANAGER, |
729 | if (result) { | 415 | 0x01, (u8 *)&value, 2); |
730 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | 416 | if (ret) |
731 | "acpi_sbs_write_word() failed")); | ||
732 | goto end; | 417 | goto end; |
733 | } | 418 | } |
734 | } | 419 | } |
735 | 420 | ret = acpi_smbus_write(sbs->hc, SMBUS_WRITE_WORD, ACPI_SBS_BATTERY, | |
736 | foo = alarm / (battery->info.capacity_mode ? 10 : 1); | 421 | 0x01, (u8 *)&battery->alarm_capacity, 2); |
737 | result = acpi_sbs_write_word(sbs, ACPI_SB_SMBUS_ADDR, 0x01, foo); | ||
738 | if (result) { | ||
739 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
740 | "acpi_sbs_write_word() failed")); | ||
741 | goto end; | ||
742 | } | ||
743 | |||
744 | end: | 422 | end: |
745 | 423 | return ret; | |
746 | return result; | ||
747 | } | 424 | } |
748 | 425 | ||
749 | static int acpi_battery_set_mode(struct acpi_battery *battery) | 426 | static int acpi_ac_get_present(struct acpi_sbs *sbs) |
750 | { | 427 | { |
751 | struct acpi_sbs *sbs = battery->sbs; | 428 | int result; |
752 | int result = 0; | 429 | u16 status; |
753 | s16 battery_mode; | ||
754 | |||
755 | if (capacity_mode == DEF_CAPACITY_UNIT) { | ||
756 | goto end; | ||
757 | } | ||
758 | |||
759 | result = acpi_sbs_read_word(sbs, | ||
760 | ACPI_SB_SMBUS_ADDR, 0x03, &battery_mode); | ||
761 | if (result) { | ||
762 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
763 | "acpi_sbs_read_word() failed")); | ||
764 | goto end; | ||
765 | } | ||
766 | |||
767 | if (capacity_mode == MAH_CAPACITY_UNIT) { | ||
768 | battery_mode &= 0x7fff; | ||
769 | } else { | ||
770 | battery_mode |= 0x8000; | ||
771 | } | ||
772 | result = acpi_sbs_write_word(sbs, | ||
773 | ACPI_SB_SMBUS_ADDR, 0x03, battery_mode); | ||
774 | if (result) { | ||
775 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
776 | "acpi_sbs_write_word() failed")); | ||
777 | goto end; | ||
778 | } | ||
779 | |||
780 | result = acpi_sbs_read_word(sbs, | ||
781 | ACPI_SB_SMBUS_ADDR, 0x03, &battery_mode); | ||
782 | if (result) { | ||
783 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
784 | "acpi_sbs_read_word() failed")); | ||
785 | goto end; | ||
786 | } | ||
787 | 430 | ||
788 | end: | 431 | result = acpi_smbus_read(sbs->hc, SMBUS_READ_WORD, ACPI_SBS_CHARGER, |
432 | 0x13, (u8 *) & status); | ||
433 | if (!result) | ||
434 | sbs->charger_present = (status >> 15) & 0x1; | ||
789 | return result; | 435 | return result; |
790 | } | 436 | } |
791 | 437 | ||
792 | static int acpi_battery_init(struct acpi_battery *battery) | 438 | static ssize_t acpi_battery_alarm_show(struct device *dev, |
439 | struct device_attribute *attr, | ||
440 | char *buf) | ||
793 | { | 441 | { |
794 | int result = 0; | 442 | struct acpi_battery *battery = to_acpi_battery(dev_get_drvdata(dev)); |
795 | 443 | acpi_battery_get_alarm(battery); | |
796 | result = acpi_battery_select(battery); | 444 | return sprintf(buf, "%d\n", battery->alarm_capacity * |
797 | if (result) { | 445 | acpi_battery_scale(battery) * 1000); |
798 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
799 | "acpi_battery_select() failed")); | ||
800 | goto end; | ||
801 | } | ||
802 | |||
803 | result = acpi_battery_set_mode(battery); | ||
804 | if (result) { | ||
805 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
806 | "acpi_battery_set_mode() failed")); | ||
807 | goto end; | ||
808 | } | ||
809 | |||
810 | result = acpi_battery_get_info(battery); | ||
811 | if (result) { | ||
812 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
813 | "acpi_battery_get_info() failed")); | ||
814 | goto end; | ||
815 | } | ||
816 | |||
817 | result = acpi_battery_get_state(battery); | ||
818 | if (result) { | ||
819 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
820 | "acpi_battery_get_state() failed")); | ||
821 | goto end; | ||
822 | } | ||
823 | |||
824 | result = acpi_battery_get_alarm(battery); | ||
825 | if (result) { | ||
826 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
827 | "acpi_battery_get_alarm() failed")); | ||
828 | goto end; | ||
829 | } | ||
830 | |||
831 | end: | ||
832 | return result; | ||
833 | } | 446 | } |
834 | 447 | ||
835 | static int acpi_ac_get_present(struct acpi_sbs *sbs) | 448 | static ssize_t acpi_battery_alarm_store(struct device *dev, |
449 | struct device_attribute *attr, | ||
450 | const char *buf, size_t count) | ||
836 | { | 451 | { |
837 | int result = 0; | 452 | unsigned long x; |
838 | s16 charger_status; | 453 | struct acpi_battery *battery = to_acpi_battery(dev_get_drvdata(dev)); |
839 | 454 | if (sscanf(buf, "%ld\n", &x) == 1) | |
840 | result = acpi_sbs_read_word(sbs, ACPI_SBC_SMBUS_ADDR, 0x13, | 455 | battery->alarm_capacity = x / |
841 | &charger_status); | 456 | (1000 * acpi_battery_scale(battery)); |
842 | 457 | if (battery->present) | |
843 | if (result) { | 458 | acpi_battery_set_alarm(battery); |
844 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | 459 | return count; |
845 | "acpi_sbs_read_word() failed")); | ||
846 | goto end; | ||
847 | } | ||
848 | |||
849 | sbs->ac.ac_present = (charger_status & 0x8000) >> 15; | ||
850 | |||
851 | end: | ||
852 | |||
853 | return result; | ||
854 | } | 460 | } |
855 | 461 | ||
462 | static struct device_attribute alarm_attr = { | ||
463 | .attr = {.name = "alarm", .mode = 0644, .owner = THIS_MODULE}, | ||
464 | .show = acpi_battery_alarm_show, | ||
465 | .store = acpi_battery_alarm_store, | ||
466 | }; | ||
467 | |||
856 | /* -------------------------------------------------------------------------- | 468 | /* -------------------------------------------------------------------------- |
857 | FS Interface (/proc/acpi) | 469 | FS Interface (/proc/acpi) |
858 | -------------------------------------------------------------------------- */ | 470 | -------------------------------------------------------------------------- */ |
859 | 471 | ||
472 | #ifdef CONFIG_ACPI_PROCFS | ||
860 | /* Generic Routines */ | 473 | /* Generic Routines */ |
861 | |||
862 | static int | 474 | static int |
863 | acpi_sbs_generic_add_fs(struct proc_dir_entry **dir, | 475 | acpi_sbs_add_fs(struct proc_dir_entry **dir, |
864 | struct proc_dir_entry *parent_dir, | 476 | struct proc_dir_entry *parent_dir, |
865 | char *dir_name, | 477 | char *dir_name, |
866 | struct file_operations *info_fops, | 478 | struct file_operations *info_fops, |
867 | struct file_operations *state_fops, | 479 | struct file_operations *state_fops, |
868 | struct file_operations *alarm_fops, void *data) | 480 | struct file_operations *alarm_fops, void *data) |
869 | { | 481 | { |
870 | struct proc_dir_entry *entry = NULL; | 482 | struct proc_dir_entry *entry = NULL; |
871 | 483 | ||
872 | if (!*dir) { | 484 | if (!*dir) { |
873 | *dir = proc_mkdir(dir_name, parent_dir); | 485 | *dir = proc_mkdir(dir_name, parent_dir); |
874 | if (!*dir) { | 486 | if (!*dir) { |
875 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
876 | "proc_mkdir() failed")); | ||
877 | return -ENODEV; | 487 | return -ENODEV; |
878 | } | 488 | } |
879 | (*dir)->owner = THIS_MODULE; | 489 | (*dir)->owner = THIS_MODULE; |
@@ -882,10 +492,7 @@ acpi_sbs_generic_add_fs(struct proc_dir_entry **dir, | |||
882 | /* 'info' [R] */ | 492 | /* 'info' [R] */ |
883 | if (info_fops) { | 493 | if (info_fops) { |
884 | entry = create_proc_entry(ACPI_SBS_FILE_INFO, S_IRUGO, *dir); | 494 | entry = create_proc_entry(ACPI_SBS_FILE_INFO, S_IRUGO, *dir); |
885 | if (!entry) { | 495 | if (entry) { |
886 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
887 | "create_proc_entry() failed")); | ||
888 | } else { | ||
889 | entry->proc_fops = info_fops; | 496 | entry->proc_fops = info_fops; |
890 | entry->data = data; | 497 | entry->data = data; |
891 | entry->owner = THIS_MODULE; | 498 | entry->owner = THIS_MODULE; |
@@ -895,10 +502,7 @@ acpi_sbs_generic_add_fs(struct proc_dir_entry **dir, | |||
895 | /* 'state' [R] */ | 502 | /* 'state' [R] */ |
896 | if (state_fops) { | 503 | if (state_fops) { |
897 | entry = create_proc_entry(ACPI_SBS_FILE_STATE, S_IRUGO, *dir); | 504 | entry = create_proc_entry(ACPI_SBS_FILE_STATE, S_IRUGO, *dir); |
898 | if (!entry) { | 505 | if (entry) { |
899 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
900 | "create_proc_entry() failed")); | ||
901 | } else { | ||
902 | entry->proc_fops = state_fops; | 506 | entry->proc_fops = state_fops; |
903 | entry->data = data; | 507 | entry->data = data; |
904 | entry->owner = THIS_MODULE; | 508 | entry->owner = THIS_MODULE; |
@@ -908,24 +512,19 @@ acpi_sbs_generic_add_fs(struct proc_dir_entry **dir, | |||
908 | /* 'alarm' [R/W] */ | 512 | /* 'alarm' [R/W] */ |
909 | if (alarm_fops) { | 513 | if (alarm_fops) { |
910 | entry = create_proc_entry(ACPI_SBS_FILE_ALARM, S_IRUGO, *dir); | 514 | entry = create_proc_entry(ACPI_SBS_FILE_ALARM, S_IRUGO, *dir); |
911 | if (!entry) { | 515 | if (entry) { |
912 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
913 | "create_proc_entry() failed")); | ||
914 | } else { | ||
915 | entry->proc_fops = alarm_fops; | 516 | entry->proc_fops = alarm_fops; |
916 | entry->data = data; | 517 | entry->data = data; |
917 | entry->owner = THIS_MODULE; | 518 | entry->owner = THIS_MODULE; |
918 | } | 519 | } |
919 | } | 520 | } |
920 | |||
921 | return 0; | 521 | return 0; |
922 | } | 522 | } |
923 | 523 | ||
924 | static void | 524 | static void |
925 | acpi_sbs_generic_remove_fs(struct proc_dir_entry **dir, | 525 | acpi_sbs_remove_fs(struct proc_dir_entry **dir, |
926 | struct proc_dir_entry *parent_dir) | 526 | struct proc_dir_entry *parent_dir) |
927 | { | 527 | { |
928 | |||
929 | if (*dir) { | 528 | if (*dir) { |
930 | remove_proc_entry(ACPI_SBS_FILE_INFO, *dir); | 529 | remove_proc_entry(ACPI_SBS_FILE_INFO, *dir); |
931 | remove_proc_entry(ACPI_SBS_FILE_STATE, *dir); | 530 | remove_proc_entry(ACPI_SBS_FILE_STATE, *dir); |
@@ -933,82 +532,52 @@ acpi_sbs_generic_remove_fs(struct proc_dir_entry **dir, | |||
933 | remove_proc_entry((*dir)->name, parent_dir); | 532 | remove_proc_entry((*dir)->name, parent_dir); |
934 | *dir = NULL; | 533 | *dir = NULL; |
935 | } | 534 | } |
936 | |||
937 | } | 535 | } |
938 | 536 | ||
939 | /* Smart Battery Interface */ | 537 | /* Smart Battery Interface */ |
940 | |||
941 | static struct proc_dir_entry *acpi_battery_dir = NULL; | 538 | static struct proc_dir_entry *acpi_battery_dir = NULL; |
942 | 539 | ||
540 | static inline char *acpi_battery_units(struct acpi_battery *battery) | ||
541 | { | ||
542 | return acpi_battery_mode(battery) ? " mWh" : " mAh"; | ||
543 | } | ||
544 | |||
545 | |||
943 | static int acpi_battery_read_info(struct seq_file *seq, void *offset) | 546 | static int acpi_battery_read_info(struct seq_file *seq, void *offset) |
944 | { | 547 | { |
945 | struct acpi_battery *battery = seq->private; | 548 | struct acpi_battery *battery = seq->private; |
946 | struct acpi_sbs *sbs = battery->sbs; | 549 | struct acpi_sbs *sbs = battery->sbs; |
947 | int cscale; | ||
948 | int result = 0; | 550 | int result = 0; |
949 | 551 | ||
950 | if (sbs_mutex_lock(sbs)) { | 552 | mutex_lock(&sbs->lock); |
951 | return -ENODEV; | ||
952 | } | ||
953 | |||
954 | result = acpi_check_update_proc(sbs); | ||
955 | if (result) | ||
956 | goto end; | ||
957 | |||
958 | if (update_time == 0) { | ||
959 | result = acpi_sbs_update_run(sbs, battery->id, DATA_TYPE_INFO); | ||
960 | if (result) { | ||
961 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
962 | "acpi_sbs_update_run() failed")); | ||
963 | } | ||
964 | } | ||
965 | 553 | ||
966 | if (battery->battery_present) { | 554 | seq_printf(seq, "present: %s\n", |
967 | seq_printf(seq, "present: yes\n"); | 555 | (battery->present) ? "yes" : "no"); |
968 | } else { | 556 | if (!battery->present) |
969 | seq_printf(seq, "present: no\n"); | ||
970 | goto end; | 557 | goto end; |
971 | } | ||
972 | 558 | ||
973 | if (battery->info.capacity_mode) { | ||
974 | cscale = battery->info.vscale * battery->info.ipscale; | ||
975 | } else { | ||
976 | cscale = battery->info.ipscale; | ||
977 | } | ||
978 | seq_printf(seq, "design capacity: %i%s\n", | 559 | seq_printf(seq, "design capacity: %i%s\n", |
979 | battery->info.design_capacity * cscale, | 560 | battery->design_capacity * acpi_battery_scale(battery), |
980 | battery->info.capacity_mode ? "0 mWh" : " mAh"); | 561 | acpi_battery_units(battery)); |
981 | |||
982 | seq_printf(seq, "last full capacity: %i%s\n", | 562 | seq_printf(seq, "last full capacity: %i%s\n", |
983 | battery->info.full_charge_capacity * cscale, | 563 | battery->full_charge_capacity * acpi_battery_scale(battery), |
984 | battery->info.capacity_mode ? "0 mWh" : " mAh"); | 564 | acpi_battery_units(battery)); |
985 | |||
986 | seq_printf(seq, "battery technology: rechargeable\n"); | 565 | seq_printf(seq, "battery technology: rechargeable\n"); |
987 | |||
988 | seq_printf(seq, "design voltage: %i mV\n", | 566 | seq_printf(seq, "design voltage: %i mV\n", |
989 | battery->info.design_voltage * battery->info.vscale); | 567 | battery->design_voltage * acpi_battery_vscale(battery)); |
990 | |||
991 | seq_printf(seq, "design capacity warning: unknown\n"); | 568 | seq_printf(seq, "design capacity warning: unknown\n"); |
992 | seq_printf(seq, "design capacity low: unknown\n"); | 569 | seq_printf(seq, "design capacity low: unknown\n"); |
993 | seq_printf(seq, "capacity granularity 1: unknown\n"); | 570 | seq_printf(seq, "capacity granularity 1: unknown\n"); |
994 | seq_printf(seq, "capacity granularity 2: unknown\n"); | 571 | seq_printf(seq, "capacity granularity 2: unknown\n"); |
995 | 572 | seq_printf(seq, "model number: %s\n", battery->device_name); | |
996 | seq_printf(seq, "model number: %s\n", | ||
997 | battery->info.device_name); | ||
998 | |||
999 | seq_printf(seq, "serial number: %i\n", | 573 | seq_printf(seq, "serial number: %i\n", |
1000 | battery->info.serial_number); | 574 | battery->serial_number); |
1001 | |||
1002 | seq_printf(seq, "battery type: %s\n", | 575 | seq_printf(seq, "battery type: %s\n", |
1003 | battery->info.device_chemistry); | 576 | battery->device_chemistry); |
1004 | |||
1005 | seq_printf(seq, "OEM info: %s\n", | 577 | seq_printf(seq, "OEM info: %s\n", |
1006 | battery->info.manufacturer_name); | 578 | battery->manufacturer_name); |
1007 | |||
1008 | end: | 579 | end: |
1009 | 580 | mutex_unlock(&sbs->lock); | |
1010 | sbs_mutex_unlock(sbs); | ||
1011 | |||
1012 | return result; | 581 | return result; |
1013 | } | 582 | } |
1014 | 583 | ||
@@ -1022,73 +591,29 @@ static int acpi_battery_read_state(struct seq_file *seq, void *offset) | |||
1022 | struct acpi_battery *battery = seq->private; | 591 | struct acpi_battery *battery = seq->private; |
1023 | struct acpi_sbs *sbs = battery->sbs; | 592 | struct acpi_sbs *sbs = battery->sbs; |
1024 | int result = 0; | 593 | int result = 0; |
1025 | int cscale; | ||
1026 | int foo; | ||
1027 | |||
1028 | if (sbs_mutex_lock(sbs)) { | ||
1029 | return -ENODEV; | ||
1030 | } | ||
1031 | 594 | ||
1032 | result = acpi_check_update_proc(sbs); | 595 | mutex_lock(&sbs->lock); |
1033 | if (result) | 596 | seq_printf(seq, "present: %s\n", |
597 | (battery->present) ? "yes" : "no"); | ||
598 | if (!battery->present) | ||
1034 | goto end; | 599 | goto end; |
1035 | 600 | ||
1036 | if (update_time == 0) { | 601 | acpi_battery_get_state(battery); |
1037 | result = acpi_sbs_update_run(sbs, battery->id, DATA_TYPE_STATE); | 602 | seq_printf(seq, "capacity state: %s\n", |
1038 | if (result) { | 603 | (battery->state & 0x0010) ? "critical" : "ok"); |
1039 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | 604 | seq_printf(seq, "charging state: %s\n", |
1040 | "acpi_sbs_update_run() failed")); | 605 | (battery->current_now < 0) ? "discharging" : |
1041 | } | 606 | ((battery->current_now > 0) ? "charging" : "charged")); |
1042 | } | 607 | seq_printf(seq, "present rate: %d mA\n", |
1043 | 608 | abs(battery->current_now) * acpi_battery_ipscale(battery)); | |
1044 | if (battery->battery_present) { | ||
1045 | seq_printf(seq, "present: yes\n"); | ||
1046 | } else { | ||
1047 | seq_printf(seq, "present: no\n"); | ||
1048 | goto end; | ||
1049 | } | ||
1050 | |||
1051 | if (battery->info.capacity_mode) { | ||
1052 | cscale = battery->info.vscale * battery->info.ipscale; | ||
1053 | } else { | ||
1054 | cscale = battery->info.ipscale; | ||
1055 | } | ||
1056 | |||
1057 | if (battery->state.battery_state & 0x0010) { | ||
1058 | seq_printf(seq, "capacity state: critical\n"); | ||
1059 | } else { | ||
1060 | seq_printf(seq, "capacity state: ok\n"); | ||
1061 | } | ||
1062 | |||
1063 | foo = (s16) battery->state.amperage * battery->info.ipscale; | ||
1064 | if (battery->info.capacity_mode) { | ||
1065 | foo = foo * battery->info.design_voltage / 1000; | ||
1066 | } | ||
1067 | if (battery->state.amperage < 0) { | ||
1068 | seq_printf(seq, "charging state: discharging\n"); | ||
1069 | seq_printf(seq, "present rate: %d %s\n", | ||
1070 | -foo, battery->info.capacity_mode ? "mW" : "mA"); | ||
1071 | } else if (battery->state.amperage > 0) { | ||
1072 | seq_printf(seq, "charging state: charging\n"); | ||
1073 | seq_printf(seq, "present rate: %d %s\n", | ||
1074 | foo, battery->info.capacity_mode ? "mW" : "mA"); | ||
1075 | } else { | ||
1076 | seq_printf(seq, "charging state: charged\n"); | ||
1077 | seq_printf(seq, "present rate: 0 %s\n", | ||
1078 | battery->info.capacity_mode ? "mW" : "mA"); | ||
1079 | } | ||
1080 | |||
1081 | seq_printf(seq, "remaining capacity: %i%s\n", | 609 | seq_printf(seq, "remaining capacity: %i%s\n", |
1082 | battery->state.remaining_capacity * cscale, | 610 | battery->capacity_now * acpi_battery_scale(battery), |
1083 | battery->info.capacity_mode ? "0 mWh" : " mAh"); | 611 | acpi_battery_units(battery)); |
1084 | |||
1085 | seq_printf(seq, "present voltage: %i mV\n", | 612 | seq_printf(seq, "present voltage: %i mV\n", |
1086 | battery->state.voltage * battery->info.vscale); | 613 | battery->voltage_now * acpi_battery_vscale(battery)); |
1087 | 614 | ||
1088 | end: | 615 | end: |
1089 | 616 | mutex_unlock(&sbs->lock); | |
1090 | sbs_mutex_unlock(sbs); | ||
1091 | |||
1092 | return result; | 617 | return result; |
1093 | } | 618 | } |
1094 | 619 | ||
@@ -1102,48 +627,25 @@ static int acpi_battery_read_alarm(struct seq_file *seq, void *offset) | |||
1102 | struct acpi_battery *battery = seq->private; | 627 | struct acpi_battery *battery = seq->private; |
1103 | struct acpi_sbs *sbs = battery->sbs; | 628 | struct acpi_sbs *sbs = battery->sbs; |
1104 | int result = 0; | 629 | int result = 0; |
1105 | int cscale; | ||
1106 | |||
1107 | if (sbs_mutex_lock(sbs)) { | ||
1108 | return -ENODEV; | ||
1109 | } | ||
1110 | |||
1111 | result = acpi_check_update_proc(sbs); | ||
1112 | if (result) | ||
1113 | goto end; | ||
1114 | 630 | ||
1115 | if (update_time == 0) { | 631 | mutex_lock(&sbs->lock); |
1116 | result = acpi_sbs_update_run(sbs, battery->id, DATA_TYPE_ALARM); | ||
1117 | if (result) { | ||
1118 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
1119 | "acpi_sbs_update_run() failed")); | ||
1120 | } | ||
1121 | } | ||
1122 | 632 | ||
1123 | if (!battery->battery_present) { | 633 | if (!battery->present) { |
1124 | seq_printf(seq, "present: no\n"); | 634 | seq_printf(seq, "present: no\n"); |
1125 | goto end; | 635 | goto end; |
1126 | } | 636 | } |
1127 | 637 | ||
1128 | if (battery->info.capacity_mode) { | 638 | acpi_battery_get_alarm(battery); |
1129 | cscale = battery->info.vscale * battery->info.ipscale; | ||
1130 | } else { | ||
1131 | cscale = battery->info.ipscale; | ||
1132 | } | ||
1133 | |||
1134 | seq_printf(seq, "alarm: "); | 639 | seq_printf(seq, "alarm: "); |
1135 | if (battery->alarm.remaining_capacity) { | 640 | if (battery->alarm_capacity) |
1136 | seq_printf(seq, "%i%s\n", | 641 | seq_printf(seq, "%i%s\n", |
1137 | battery->alarm.remaining_capacity * cscale, | 642 | battery->alarm_capacity * |
1138 | battery->info.capacity_mode ? "0 mWh" : " mAh"); | 643 | acpi_battery_scale(battery), |
1139 | } else { | 644 | acpi_battery_units(battery)); |
645 | else | ||
1140 | seq_printf(seq, "disabled\n"); | 646 | seq_printf(seq, "disabled\n"); |
1141 | } | ||
1142 | |||
1143 | end: | 647 | end: |
1144 | 648 | mutex_unlock(&sbs->lock); | |
1145 | sbs_mutex_unlock(sbs); | ||
1146 | |||
1147 | return result; | 649 | return result; |
1148 | } | 650 | } |
1149 | 651 | ||
@@ -1155,59 +657,29 @@ acpi_battery_write_alarm(struct file *file, const char __user * buffer, | |||
1155 | struct acpi_battery *battery = seq->private; | 657 | struct acpi_battery *battery = seq->private; |
1156 | struct acpi_sbs *sbs = battery->sbs; | 658 | struct acpi_sbs *sbs = battery->sbs; |
1157 | char alarm_string[12] = { '\0' }; | 659 | char alarm_string[12] = { '\0' }; |
1158 | int result, old_alarm, new_alarm; | 660 | int result = 0; |
1159 | 661 | mutex_lock(&sbs->lock); | |
1160 | if (sbs_mutex_lock(sbs)) { | 662 | if (!battery->present) { |
1161 | return -ENODEV; | ||
1162 | } | ||
1163 | |||
1164 | result = acpi_check_update_proc(sbs); | ||
1165 | if (result) | ||
1166 | goto end; | ||
1167 | |||
1168 | if (!battery->battery_present) { | ||
1169 | result = -ENODEV; | 663 | result = -ENODEV; |
1170 | goto end; | 664 | goto end; |
1171 | } | 665 | } |
1172 | |||
1173 | if (count > sizeof(alarm_string) - 1) { | 666 | if (count > sizeof(alarm_string) - 1) { |
1174 | result = -EINVAL; | 667 | result = -EINVAL; |
1175 | goto end; | 668 | goto end; |
1176 | } | 669 | } |
1177 | |||
1178 | if (copy_from_user(alarm_string, buffer, count)) { | 670 | if (copy_from_user(alarm_string, buffer, count)) { |
1179 | result = -EFAULT; | 671 | result = -EFAULT; |
1180 | goto end; | 672 | goto end; |
1181 | } | 673 | } |
1182 | |||
1183 | alarm_string[count] = 0; | 674 | alarm_string[count] = 0; |
1184 | 675 | battery->alarm_capacity = simple_strtoul(alarm_string, NULL, 0) / | |
1185 | old_alarm = battery->alarm.remaining_capacity; | 676 | acpi_battery_scale(battery); |
1186 | new_alarm = simple_strtoul(alarm_string, NULL, 0); | 677 | acpi_battery_set_alarm(battery); |
1187 | |||
1188 | result = acpi_battery_set_alarm(battery, new_alarm); | ||
1189 | if (result) { | ||
1190 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
1191 | "acpi_battery_set_alarm() failed")); | ||
1192 | acpi_battery_set_alarm(battery, old_alarm); | ||
1193 | goto end; | ||
1194 | } | ||
1195 | result = acpi_battery_get_alarm(battery); | ||
1196 | if (result) { | ||
1197 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
1198 | "acpi_battery_get_alarm() failed")); | ||
1199 | acpi_battery_set_alarm(battery, old_alarm); | ||
1200 | goto end; | ||
1201 | } | ||
1202 | |||
1203 | end: | 678 | end: |
1204 | sbs_mutex_unlock(sbs); | 679 | mutex_unlock(&sbs->lock); |
1205 | 680 | if (result) | |
1206 | if (result) { | ||
1207 | return result; | 681 | return result; |
1208 | } else { | 682 | return count; |
1209 | return count; | ||
1210 | } | ||
1211 | } | 683 | } |
1212 | 684 | ||
1213 | static int acpi_battery_alarm_open_fs(struct inode *inode, struct file *file) | 685 | static int acpi_battery_alarm_open_fs(struct inode *inode, struct file *file) |
@@ -1246,26 +718,15 @@ static struct proc_dir_entry *acpi_ac_dir = NULL; | |||
1246 | 718 | ||
1247 | static int acpi_ac_read_state(struct seq_file *seq, void *offset) | 719 | static int acpi_ac_read_state(struct seq_file *seq, void *offset) |
1248 | { | 720 | { |
1249 | struct acpi_sbs *sbs = seq->private; | ||
1250 | int result; | ||
1251 | 721 | ||
1252 | if (sbs_mutex_lock(sbs)) { | 722 | struct acpi_sbs *sbs = seq->private; |
1253 | return -ENODEV; | ||
1254 | } | ||
1255 | 723 | ||
1256 | if (update_time == 0) { | 724 | mutex_lock(&sbs->lock); |
1257 | result = acpi_sbs_update_run(sbs, -1, DATA_TYPE_AC_STATE); | ||
1258 | if (result) { | ||
1259 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
1260 | "acpi_sbs_update_run() failed")); | ||
1261 | } | ||
1262 | } | ||
1263 | 725 | ||
1264 | seq_printf(seq, "state: %s\n", | 726 | seq_printf(seq, "state: %s\n", |
1265 | sbs->ac.ac_present ? "on-line" : "off-line"); | 727 | sbs->charger_present ? "on-line" : "off-line"); |
1266 | |||
1267 | sbs_mutex_unlock(sbs); | ||
1268 | 728 | ||
729 | mutex_unlock(&sbs->lock); | ||
1269 | return 0; | 730 | return 0; |
1270 | } | 731 | } |
1271 | 732 | ||
@@ -1282,429 +743,211 @@ static struct file_operations acpi_ac_state_fops = { | |||
1282 | .owner = THIS_MODULE, | 743 | .owner = THIS_MODULE, |
1283 | }; | 744 | }; |
1284 | 745 | ||
746 | #endif | ||
747 | |||
1285 | /* -------------------------------------------------------------------------- | 748 | /* -------------------------------------------------------------------------- |
1286 | Driver Interface | 749 | Driver Interface |
1287 | -------------------------------------------------------------------------- */ | 750 | -------------------------------------------------------------------------- */ |
751 | static int acpi_battery_read(struct acpi_battery *battery) | ||
752 | { | ||
753 | int result = 0, saved_present = battery->present; | ||
754 | u16 state; | ||
755 | |||
756 | if (battery->sbs->manager_present) { | ||
757 | result = acpi_smbus_read(battery->sbs->hc, SMBUS_READ_WORD, | ||
758 | ACPI_SBS_MANAGER, 0x01, (u8 *)&state); | ||
759 | if (!result) | ||
760 | battery->present = state & (1 << battery->id); | ||
761 | state &= 0x0fff; | ||
762 | state |= 1 << (battery->id + 12); | ||
763 | acpi_smbus_write(battery->sbs->hc, SMBUS_WRITE_WORD, | ||
764 | ACPI_SBS_MANAGER, 0x01, (u8 *)&state, 2); | ||
765 | } else if (battery->id == 0) | ||
766 | battery->present = 1; | ||
767 | if (result || !battery->present) | ||
768 | return result; | ||
1288 | 769 | ||
1289 | /* Smart Battery */ | 770 | if (saved_present != battery->present) { |
771 | battery->update_time = 0; | ||
772 | result = acpi_battery_get_info(battery); | ||
773 | if (result) | ||
774 | return result; | ||
775 | } | ||
776 | result = acpi_battery_get_state(battery); | ||
777 | return result; | ||
778 | } | ||
1290 | 779 | ||
780 | /* Smart Battery */ | ||
1291 | static int acpi_battery_add(struct acpi_sbs *sbs, int id) | 781 | static int acpi_battery_add(struct acpi_sbs *sbs, int id) |
1292 | { | 782 | { |
1293 | int is_present; | 783 | struct acpi_battery *battery = &sbs->battery[id]; |
1294 | int result; | 784 | int result; |
1295 | char dir_name[32]; | ||
1296 | struct acpi_battery *battery; | ||
1297 | |||
1298 | battery = &sbs->battery[id]; | ||
1299 | |||
1300 | battery->alive = 0; | ||
1301 | 785 | ||
1302 | battery->init_state = 0; | ||
1303 | battery->id = id; | 786 | battery->id = id; |
1304 | battery->sbs = sbs; | 787 | battery->sbs = sbs; |
788 | result = acpi_battery_read(battery); | ||
789 | if (result) | ||
790 | return result; | ||
1305 | 791 | ||
1306 | result = acpi_battery_select(battery); | 792 | sprintf(battery->name, ACPI_BATTERY_DIR_NAME, id); |
1307 | if (result) { | 793 | #ifdef CONFIG_ACPI_PROCFS |
1308 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | 794 | acpi_sbs_add_fs(&battery->proc_entry, acpi_battery_dir, |
1309 | "acpi_battery_select() failed")); | 795 | battery->name, &acpi_battery_info_fops, |
1310 | goto end; | 796 | &acpi_battery_state_fops, &acpi_battery_alarm_fops, |
797 | battery); | ||
798 | #endif | ||
799 | battery->bat.name = battery->name; | ||
800 | battery->bat.type = POWER_SUPPLY_TYPE_BATTERY; | ||
801 | if (!acpi_battery_mode(battery)) { | ||
802 | battery->bat.properties = sbs_charge_battery_props; | ||
803 | battery->bat.num_properties = | ||
804 | ARRAY_SIZE(sbs_charge_battery_props); | ||
805 | } else { | ||
806 | battery->bat.properties = sbs_energy_battery_props; | ||
807 | battery->bat.num_properties = | ||
808 | ARRAY_SIZE(sbs_energy_battery_props); | ||
1311 | } | 809 | } |
1312 | 810 | battery->bat.get_property = acpi_sbs_battery_get_property; | |
1313 | result = acpi_battery_get_present(battery); | 811 | result = power_supply_register(&sbs->device->dev, &battery->bat); |
1314 | if (result) { | 812 | if (result) |
1315 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
1316 | "acpi_battery_get_present() failed")); | ||
1317 | goto end; | 813 | goto end; |
1318 | } | 814 | result = device_create_file(battery->bat.dev, &alarm_attr); |
1319 | 815 | if (result) | |
1320 | is_present = battery->battery_present; | ||
1321 | |||
1322 | if (is_present) { | ||
1323 | result = acpi_battery_init(battery); | ||
1324 | if (result) { | ||
1325 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
1326 | "acpi_battery_init() failed")); | ||
1327 | goto end; | ||
1328 | } | ||
1329 | battery->init_state = 1; | ||
1330 | } | ||
1331 | |||
1332 | sprintf(dir_name, ACPI_BATTERY_DIR_NAME, id); | ||
1333 | |||
1334 | result = acpi_sbs_generic_add_fs(&battery->battery_entry, | ||
1335 | acpi_battery_dir, | ||
1336 | dir_name, | ||
1337 | &acpi_battery_info_fops, | ||
1338 | &acpi_battery_state_fops, | ||
1339 | &acpi_battery_alarm_fops, battery); | ||
1340 | if (result) { | ||
1341 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
1342 | "acpi_sbs_generic_add_fs() failed")); | ||
1343 | goto end; | 816 | goto end; |
1344 | } | 817 | battery->have_sysfs_alarm = 1; |
1345 | battery->alive = 1; | ||
1346 | |||
1347 | printk(KERN_INFO PREFIX "%s [%s]: Battery Slot [%s] (battery %s)\n", | ||
1348 | ACPI_SBS_DEVICE_NAME, acpi_device_bid(sbs->device), dir_name, | ||
1349 | sbs->battery->battery_present ? "present" : "absent"); | ||
1350 | |||
1351 | end: | 818 | end: |
819 | printk(KERN_INFO PREFIX "%s [%s]: Battery Slot [%s] (battery %s)\n", | ||
820 | ACPI_SBS_DEVICE_NAME, acpi_device_bid(sbs->device), | ||
821 | battery->name, sbs->battery->present ? "present" : "absent"); | ||
1352 | return result; | 822 | return result; |
1353 | } | 823 | } |
1354 | 824 | ||
1355 | static void acpi_battery_remove(struct acpi_sbs *sbs, int id) | 825 | static void acpi_battery_remove(struct acpi_sbs *sbs, int id) |
1356 | { | 826 | { |
827 | struct acpi_battery *battery = &sbs->battery[id]; | ||
1357 | 828 | ||
1358 | if (sbs->battery[id].battery_entry) { | 829 | if (battery->bat.dev) { |
1359 | acpi_sbs_generic_remove_fs(&(sbs->battery[id].battery_entry), | 830 | if (battery->have_sysfs_alarm) |
1360 | acpi_battery_dir); | 831 | device_remove_file(battery->bat.dev, &alarm_attr); |
832 | power_supply_unregister(&battery->bat); | ||
1361 | } | 833 | } |
834 | #ifdef CONFIG_ACPI_PROCFS | ||
835 | if (battery->proc_entry) | ||
836 | acpi_sbs_remove_fs(&battery->proc_entry, acpi_battery_dir); | ||
837 | #endif | ||
1362 | } | 838 | } |
1363 | 839 | ||
1364 | static int acpi_ac_add(struct acpi_sbs *sbs) | 840 | static int acpi_charger_add(struct acpi_sbs *sbs) |
1365 | { | 841 | { |
1366 | int result; | 842 | int result; |
1367 | 843 | ||
1368 | result = acpi_ac_get_present(sbs); | 844 | result = acpi_ac_get_present(sbs); |
1369 | if (result) { | 845 | if (result) |
1370 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
1371 | "acpi_ac_get_present() failed")); | ||
1372 | goto end; | 846 | goto end; |
1373 | } | 847 | #ifdef CONFIG_ACPI_PROCFS |
1374 | 848 | result = acpi_sbs_add_fs(&sbs->charger_entry, acpi_ac_dir, | |
1375 | result = acpi_sbs_generic_add_fs(&sbs->ac_entry, | 849 | ACPI_AC_DIR_NAME, NULL, |
1376 | acpi_ac_dir, | 850 | &acpi_ac_state_fops, NULL, sbs); |
1377 | ACPI_AC_DIR_NAME, | 851 | if (result) |
1378 | NULL, &acpi_ac_state_fops, NULL, sbs); | ||
1379 | if (result) { | ||
1380 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
1381 | "acpi_sbs_generic_add_fs() failed")); | ||
1382 | goto end; | 852 | goto end; |
1383 | } | 853 | #endif |
1384 | 854 | sbs->charger.name = "sbs-charger"; | |
855 | sbs->charger.type = POWER_SUPPLY_TYPE_MAINS; | ||
856 | sbs->charger.properties = sbs_ac_props; | ||
857 | sbs->charger.num_properties = ARRAY_SIZE(sbs_ac_props); | ||
858 | sbs->charger.get_property = sbs_get_ac_property; | ||
859 | power_supply_register(&sbs->device->dev, &sbs->charger); | ||
1385 | printk(KERN_INFO PREFIX "%s [%s]: AC Adapter [%s] (%s)\n", | 860 | printk(KERN_INFO PREFIX "%s [%s]: AC Adapter [%s] (%s)\n", |
1386 | ACPI_SBS_DEVICE_NAME, acpi_device_bid(sbs->device), | 861 | ACPI_SBS_DEVICE_NAME, acpi_device_bid(sbs->device), |
1387 | ACPI_AC_DIR_NAME, sbs->ac.ac_present ? "on-line" : "off-line"); | 862 | ACPI_AC_DIR_NAME, sbs->charger_present ? "on-line" : "off-line"); |
1388 | |||
1389 | end: | 863 | end: |
1390 | |||
1391 | return result; | 864 | return result; |
1392 | } | 865 | } |
1393 | 866 | ||
1394 | static void acpi_ac_remove(struct acpi_sbs *sbs) | 867 | static void acpi_charger_remove(struct acpi_sbs *sbs) |
1395 | { | 868 | { |
1396 | 869 | if (sbs->charger.dev) | |
1397 | if (sbs->ac_entry) { | 870 | power_supply_unregister(&sbs->charger); |
1398 | acpi_sbs_generic_remove_fs(&sbs->ac_entry, acpi_ac_dir); | 871 | #ifdef CONFIG_ACPI_PROCFS |
1399 | } | 872 | if (sbs->charger_entry) |
873 | acpi_sbs_remove_fs(&sbs->charger_entry, acpi_ac_dir); | ||
874 | #endif | ||
1400 | } | 875 | } |
1401 | 876 | ||
1402 | static void acpi_sbs_update_time_run(unsigned long data) | 877 | void acpi_sbs_callback(void *context) |
1403 | { | 878 | { |
1404 | acpi_os_execute(OSL_GPE_HANDLER, acpi_sbs_update_time, (void *)data); | 879 | int id; |
1405 | } | 880 | struct acpi_sbs *sbs = context; |
1406 | 881 | struct acpi_battery *bat; | |
1407 | static int acpi_sbs_update_run(struct acpi_sbs *sbs, int id, int data_type) | 882 | u8 saved_charger_state = sbs->charger_present; |
1408 | { | 883 | u8 saved_battery_state; |
1409 | struct acpi_battery *battery; | 884 | acpi_ac_get_present(sbs); |
1410 | int result = 0, cnt; | 885 | if (sbs->charger_present != saved_charger_state) { |
1411 | int old_ac_present = -1; | 886 | #ifdef CONFIG_ACPI_PROC_EVENT |
1412 | int old_battery_present = -1; | 887 | acpi_bus_generate_proc_event4(ACPI_AC_CLASS, ACPI_AC_DIR_NAME, |
1413 | int new_ac_present = -1; | 888 | ACPI_SBS_NOTIFY_STATUS, |
1414 | int new_battery_present = -1; | 889 | sbs->charger_present); |
1415 | int id_min = 0, id_max = MAX_SBS_BAT - 1; | 890 | #endif |
1416 | char dir_name[32]; | 891 | kobject_uevent(&sbs->charger.dev->kobj, KOBJ_CHANGE); |
1417 | int do_battery_init = 0, do_ac_init = 0; | 892 | } |
1418 | int old_remaining_capacity = 0; | 893 | if (sbs->manager_present) { |
1419 | int update_battery = 1; | 894 | for (id = 0; id < MAX_SBS_BAT; ++id) { |
1420 | int up_tm = update_time; | 895 | if (!(sbs->batteries_supported & (1 << id))) |
1421 | 896 | continue; | |
1422 | if (sbs_zombie(sbs)) { | 897 | bat = &sbs->battery[id]; |
1423 | goto end; | 898 | saved_battery_state = bat->present; |
1424 | } | 899 | acpi_battery_read(bat); |
1425 | 900 | if (saved_battery_state == bat->present) | |
1426 | if (id >= 0) { | 901 | continue; |
1427 | id_min = id_max = id; | 902 | #ifdef CONFIG_ACPI_PROC_EVENT |
1428 | } | 903 | acpi_bus_generate_proc_event4(ACPI_BATTERY_CLASS, |
1429 | 904 | bat->name, | |
1430 | if (data_type == DATA_TYPE_COMMON && up_tm > 0) { | 905 | ACPI_SBS_NOTIFY_STATUS, |
1431 | cnt = up_tm / (up_tm > UPDATE_DELAY ? UPDATE_DELAY : up_tm); | 906 | bat->present); |
1432 | if (sbs->run_cnt % cnt != 0) { | 907 | #endif |
1433 | update_battery = 0; | 908 | kobject_uevent(&bat->bat.dev->kobj, KOBJ_CHANGE); |
1434 | } | ||
1435 | } | ||
1436 | |||
1437 | sbs->run_cnt++; | ||
1438 | |||
1439 | old_ac_present = sbs->ac.ac_present; | ||
1440 | |||
1441 | result = acpi_ac_get_present(sbs); | ||
1442 | if (result) { | ||
1443 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
1444 | "acpi_ac_get_present() failed")); | ||
1445 | } | ||
1446 | |||
1447 | new_ac_present = sbs->ac.ac_present; | ||
1448 | |||
1449 | do_ac_init = (old_ac_present != new_ac_present); | ||
1450 | if (sbs->run_cnt == 1 && data_type == DATA_TYPE_COMMON) { | ||
1451 | do_ac_init = 1; | ||
1452 | } | ||
1453 | |||
1454 | if (do_ac_init) { | ||
1455 | result = acpi_sbs_generate_event(sbs->device, | ||
1456 | ACPI_SBS_AC_NOTIFY_STATUS, | ||
1457 | new_ac_present, | ||
1458 | ACPI_AC_DIR_NAME, | ||
1459 | ACPI_AC_CLASS); | ||
1460 | if (result) { | ||
1461 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
1462 | "acpi_sbs_generate_event() failed")); | ||
1463 | } | ||
1464 | } | ||
1465 | |||
1466 | if (data_type == DATA_TYPE_COMMON) { | ||
1467 | if (!do_ac_init && !update_battery) { | ||
1468 | goto end; | ||
1469 | } | ||
1470 | } | ||
1471 | |||
1472 | if (data_type == DATA_TYPE_AC_STATE && !do_ac_init) { | ||
1473 | goto end; | ||
1474 | } | ||
1475 | |||
1476 | for (id = id_min; id <= id_max; id++) { | ||
1477 | battery = &sbs->battery[id]; | ||
1478 | if (battery->alive == 0) { | ||
1479 | continue; | ||
1480 | } | ||
1481 | |||
1482 | old_remaining_capacity = battery->state.remaining_capacity; | ||
1483 | |||
1484 | old_battery_present = battery->battery_present; | ||
1485 | |||
1486 | result = acpi_battery_select(battery); | ||
1487 | if (result) { | ||
1488 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
1489 | "acpi_battery_select() failed")); | ||
1490 | } | ||
1491 | |||
1492 | result = acpi_battery_get_present(battery); | ||
1493 | if (result) { | ||
1494 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
1495 | "acpi_battery_get_present() failed")); | ||
1496 | } | ||
1497 | |||
1498 | new_battery_present = battery->battery_present; | ||
1499 | |||
1500 | do_battery_init = ((old_battery_present != new_battery_present) | ||
1501 | && new_battery_present); | ||
1502 | if (!new_battery_present) | ||
1503 | goto event; | ||
1504 | if (do_ac_init || do_battery_init) { | ||
1505 | result = acpi_battery_init(battery); | ||
1506 | if (result) { | ||
1507 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
1508 | "acpi_battery_init() " | ||
1509 | "failed")); | ||
1510 | } | ||
1511 | } | ||
1512 | if (sbs_zombie(sbs)) { | ||
1513 | goto end; | ||
1514 | } | ||
1515 | |||
1516 | if ((data_type == DATA_TYPE_COMMON | ||
1517 | || data_type == DATA_TYPE_INFO) | ||
1518 | && new_battery_present) { | ||
1519 | result = acpi_battery_get_info(battery); | ||
1520 | if (result) { | ||
1521 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
1522 | "acpi_battery_get_info() failed")); | ||
1523 | } | ||
1524 | } | ||
1525 | if (data_type == DATA_TYPE_INFO) { | ||
1526 | continue; | ||
1527 | } | ||
1528 | if (sbs_zombie(sbs)) { | ||
1529 | goto end; | ||
1530 | } | ||
1531 | |||
1532 | if ((data_type == DATA_TYPE_COMMON | ||
1533 | || data_type == DATA_TYPE_STATE) | ||
1534 | && new_battery_present) { | ||
1535 | result = acpi_battery_get_state(battery); | ||
1536 | if (result) { | ||
1537 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
1538 | "acpi_battery_get_state() failed")); | ||
1539 | } | ||
1540 | } | ||
1541 | if (data_type == DATA_TYPE_STATE) { | ||
1542 | goto event; | ||
1543 | } | ||
1544 | if (sbs_zombie(sbs)) { | ||
1545 | goto end; | ||
1546 | } | ||
1547 | |||
1548 | if ((data_type == DATA_TYPE_COMMON | ||
1549 | || data_type == DATA_TYPE_ALARM) | ||
1550 | && new_battery_present) { | ||
1551 | result = acpi_battery_get_alarm(battery); | ||
1552 | if (result) { | ||
1553 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
1554 | "acpi_battery_get_alarm() " | ||
1555 | "failed")); | ||
1556 | } | ||
1557 | } | ||
1558 | if (data_type == DATA_TYPE_ALARM) { | ||
1559 | continue; | ||
1560 | } | ||
1561 | if (sbs_zombie(sbs)) { | ||
1562 | goto end; | ||
1563 | } | ||
1564 | |||
1565 | event: | ||
1566 | |||
1567 | if (old_battery_present != new_battery_present || do_ac_init || | ||
1568 | old_remaining_capacity != | ||
1569 | battery->state.remaining_capacity) { | ||
1570 | sprintf(dir_name, ACPI_BATTERY_DIR_NAME, id); | ||
1571 | result = acpi_sbs_generate_event(sbs->device, | ||
1572 | ACPI_SBS_BATTERY_NOTIFY_STATUS, | ||
1573 | new_battery_present, | ||
1574 | dir_name, | ||
1575 | ACPI_BATTERY_CLASS); | ||
1576 | if (result) { | ||
1577 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
1578 | "acpi_sbs_generate_event() " | ||
1579 | "failed")); | ||
1580 | } | ||
1581 | } | 909 | } |
1582 | } | 910 | } |
1583 | |||
1584 | end: | ||
1585 | |||
1586 | return result; | ||
1587 | } | 911 | } |
1588 | 912 | ||
1589 | static void acpi_sbs_update_time(void *data) | 913 | static int acpi_sbs_remove(struct acpi_device *device, int type); |
1590 | { | ||
1591 | struct acpi_sbs *sbs = data; | ||
1592 | unsigned long delay = -1; | ||
1593 | int result; | ||
1594 | unsigned int up_tm = update_time; | ||
1595 | |||
1596 | if (sbs_mutex_lock(sbs)) | ||
1597 | return; | ||
1598 | |||
1599 | result = acpi_sbs_update_run(sbs, -1, DATA_TYPE_COMMON); | ||
1600 | if (result) { | ||
1601 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
1602 | "acpi_sbs_update_run() failed")); | ||
1603 | } | ||
1604 | |||
1605 | if (sbs_zombie(sbs)) { | ||
1606 | goto end; | ||
1607 | } | ||
1608 | |||
1609 | if (!up_tm) { | ||
1610 | if (timer_pending(&sbs->update_timer)) | ||
1611 | del_timer(&sbs->update_timer); | ||
1612 | } else { | ||
1613 | delay = (up_tm > UPDATE_DELAY ? UPDATE_DELAY : up_tm); | ||
1614 | delay = jiffies + HZ * delay; | ||
1615 | if (timer_pending(&sbs->update_timer)) { | ||
1616 | mod_timer(&sbs->update_timer, delay); | ||
1617 | } else { | ||
1618 | sbs->update_timer.data = (unsigned long)data; | ||
1619 | sbs->update_timer.function = acpi_sbs_update_time_run; | ||
1620 | sbs->update_timer.expires = delay; | ||
1621 | add_timer(&sbs->update_timer); | ||
1622 | } | ||
1623 | } | ||
1624 | |||
1625 | end: | ||
1626 | |||
1627 | sbs_mutex_unlock(sbs); | ||
1628 | } | ||
1629 | 914 | ||
1630 | static int acpi_sbs_add(struct acpi_device *device) | 915 | static int acpi_sbs_add(struct acpi_device *device) |
1631 | { | 916 | { |
1632 | struct acpi_sbs *sbs = NULL; | 917 | struct acpi_sbs *sbs; |
1633 | int result = 0, remove_result = 0; | 918 | int result = 0; |
1634 | int id; | 919 | int id; |
1635 | acpi_status status = AE_OK; | ||
1636 | unsigned long val; | ||
1637 | |||
1638 | status = | ||
1639 | acpi_evaluate_integer(device->handle, "_EC", NULL, &val); | ||
1640 | if (ACPI_FAILURE(status)) { | ||
1641 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, "Error obtaining _EC")); | ||
1642 | return -EIO; | ||
1643 | } | ||
1644 | 920 | ||
1645 | sbs = kzalloc(sizeof(struct acpi_sbs), GFP_KERNEL); | 921 | sbs = kzalloc(sizeof(struct acpi_sbs), GFP_KERNEL); |
1646 | if (!sbs) { | 922 | if (!sbs) { |
1647 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, "kzalloc() failed")); | ||
1648 | result = -ENOMEM; | 923 | result = -ENOMEM; |
1649 | goto end; | 924 | goto end; |
1650 | } | 925 | } |
1651 | 926 | ||
1652 | mutex_init(&sbs->mutex); | 927 | mutex_init(&sbs->lock); |
1653 | 928 | ||
1654 | sbs_mutex_lock(sbs); | 929 | sbs->hc = acpi_driver_data(device->parent); |
1655 | |||
1656 | sbs->base = 0xff & (val >> 8); | ||
1657 | sbs->device = device; | 930 | sbs->device = device; |
1658 | |||
1659 | strcpy(acpi_device_name(device), ACPI_SBS_DEVICE_NAME); | 931 | strcpy(acpi_device_name(device), ACPI_SBS_DEVICE_NAME); |
1660 | strcpy(acpi_device_class(device), ACPI_SBS_CLASS); | 932 | strcpy(acpi_device_class(device), ACPI_SBS_CLASS); |
1661 | acpi_driver_data(device) = sbs; | 933 | acpi_driver_data(device) = sbs; |
1662 | 934 | ||
1663 | result = acpi_ac_add(sbs); | 935 | result = acpi_charger_add(sbs); |
1664 | if (result) { | ||
1665 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, "acpi_ac_add() failed")); | ||
1666 | goto end; | ||
1667 | } | ||
1668 | |||
1669 | acpi_sbsm_get_info(sbs); | ||
1670 | |||
1671 | if (!sbs->sbsm_present) { | ||
1672 | result = acpi_battery_add(sbs, 0); | ||
1673 | if (result) { | ||
1674 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
1675 | "acpi_battery_add() failed")); | ||
1676 | goto end; | ||
1677 | } | ||
1678 | } else { | ||
1679 | for (id = 0; id < MAX_SBS_BAT; id++) { | ||
1680 | if ((sbs->sbsm_batteries_supported & (1 << id))) { | ||
1681 | result = acpi_battery_add(sbs, id); | ||
1682 | if (result) { | ||
1683 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
1684 | "acpi_battery_add() failed")); | ||
1685 | goto end; | ||
1686 | } | ||
1687 | } | ||
1688 | } | ||
1689 | } | ||
1690 | |||
1691 | init_timer(&sbs->update_timer); | ||
1692 | result = acpi_check_update_proc(sbs); | ||
1693 | if (result) | 936 | if (result) |
1694 | goto end; | 937 | goto end; |
1695 | 938 | ||
939 | result = acpi_manager_get_info(sbs); | ||
940 | if (!result) { | ||
941 | sbs->manager_present = 1; | ||
942 | for (id = 0; id < MAX_SBS_BAT; ++id) | ||
943 | if ((sbs->batteries_supported & (1 << id))) | ||
944 | acpi_battery_add(sbs, id); | ||
945 | } else | ||
946 | acpi_battery_add(sbs, 0); | ||
947 | acpi_smbus_register_callback(sbs->hc, acpi_sbs_callback, sbs); | ||
1696 | end: | 948 | end: |
1697 | 949 | if (result) | |
1698 | sbs_mutex_unlock(sbs); | 950 | acpi_sbs_remove(device, 0); |
1699 | |||
1700 | if (result) { | ||
1701 | remove_result = acpi_sbs_remove(device, 0); | ||
1702 | if (remove_result) { | ||
1703 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
1704 | "acpi_sbs_remove() failed")); | ||
1705 | } | ||
1706 | } | ||
1707 | |||
1708 | return result; | 951 | return result; |
1709 | } | 952 | } |
1710 | 953 | ||
@@ -1713,39 +956,25 @@ static int acpi_sbs_remove(struct acpi_device *device, int type) | |||
1713 | struct acpi_sbs *sbs; | 956 | struct acpi_sbs *sbs; |
1714 | int id; | 957 | int id; |
1715 | 958 | ||
1716 | if (!device) { | 959 | if (!device) |
1717 | return -EINVAL; | 960 | return -EINVAL; |
1718 | } | ||
1719 | |||
1720 | sbs = acpi_driver_data(device); | 961 | sbs = acpi_driver_data(device); |
1721 | if (!sbs) { | 962 | if (!sbs) |
1722 | return -EINVAL; | 963 | return -EINVAL; |
1723 | } | 964 | mutex_lock(&sbs->lock); |
1724 | 965 | acpi_smbus_unregister_callback(sbs->hc); | |
1725 | sbs_mutex_lock(sbs); | 966 | for (id = 0; id < MAX_SBS_BAT; ++id) |
1726 | |||
1727 | sbs->zombie = 1; | ||
1728 | del_timer_sync(&sbs->update_timer); | ||
1729 | acpi_os_wait_events_complete(NULL); | ||
1730 | del_timer_sync(&sbs->update_timer); | ||
1731 | |||
1732 | for (id = 0; id < MAX_SBS_BAT; id++) { | ||
1733 | acpi_battery_remove(sbs, id); | 967 | acpi_battery_remove(sbs, id); |
1734 | } | 968 | acpi_charger_remove(sbs); |
1735 | 969 | mutex_unlock(&sbs->lock); | |
1736 | acpi_ac_remove(sbs); | 970 | mutex_destroy(&sbs->lock); |
1737 | |||
1738 | sbs_mutex_unlock(sbs); | ||
1739 | |||
1740 | mutex_destroy(&sbs->mutex); | ||
1741 | |||
1742 | kfree(sbs); | 971 | kfree(sbs); |
1743 | |||
1744 | return 0; | 972 | return 0; |
1745 | } | 973 | } |
1746 | 974 | ||
1747 | static void acpi_sbs_rmdirs(void) | 975 | static void acpi_sbs_rmdirs(void) |
1748 | { | 976 | { |
977 | #ifdef CONFIG_ACPI_PROCFS | ||
1749 | if (acpi_ac_dir) { | 978 | if (acpi_ac_dir) { |
1750 | acpi_unlock_ac_dir(acpi_ac_dir); | 979 | acpi_unlock_ac_dir(acpi_ac_dir); |
1751 | acpi_ac_dir = NULL; | 980 | acpi_ac_dir = NULL; |
@@ -1754,69 +983,58 @@ static void acpi_sbs_rmdirs(void) | |||
1754 | acpi_unlock_battery_dir(acpi_battery_dir); | 983 | acpi_unlock_battery_dir(acpi_battery_dir); |
1755 | acpi_battery_dir = NULL; | 984 | acpi_battery_dir = NULL; |
1756 | } | 985 | } |
986 | #endif | ||
1757 | } | 987 | } |
1758 | 988 | ||
1759 | static int acpi_sbs_resume(struct acpi_device *device) | 989 | static int acpi_sbs_resume(struct acpi_device *device) |
1760 | { | 990 | { |
1761 | struct acpi_sbs *sbs; | 991 | struct acpi_sbs *sbs; |
1762 | |||
1763 | if (!device) | 992 | if (!device) |
1764 | return -EINVAL; | 993 | return -EINVAL; |
1765 | |||
1766 | sbs = device->driver_data; | 994 | sbs = device->driver_data; |
1767 | 995 | acpi_sbs_callback(sbs); | |
1768 | sbs->run_cnt = 0; | ||
1769 | |||
1770 | return 0; | 996 | return 0; |
1771 | } | 997 | } |
1772 | 998 | ||
999 | static struct acpi_driver acpi_sbs_driver = { | ||
1000 | .name = "sbs", | ||
1001 | .class = ACPI_SBS_CLASS, | ||
1002 | .ids = sbs_device_ids, | ||
1003 | .ops = { | ||
1004 | .add = acpi_sbs_add, | ||
1005 | .remove = acpi_sbs_remove, | ||
1006 | .resume = acpi_sbs_resume, | ||
1007 | }, | ||
1008 | }; | ||
1009 | |||
1773 | static int __init acpi_sbs_init(void) | 1010 | static int __init acpi_sbs_init(void) |
1774 | { | 1011 | { |
1775 | int result = 0; | 1012 | int result = 0; |
1776 | 1013 | ||
1777 | if (acpi_disabled) | 1014 | if (acpi_disabled) |
1778 | return -ENODEV; | 1015 | return -ENODEV; |
1779 | 1016 | #ifdef CONFIG_ACPI_PROCFS | |
1780 | if (capacity_mode != DEF_CAPACITY_UNIT | ||
1781 | && capacity_mode != MAH_CAPACITY_UNIT | ||
1782 | && capacity_mode != MWH_CAPACITY_UNIT) { | ||
1783 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
1784 | "invalid capacity_mode = %d", capacity_mode)); | ||
1785 | return -EINVAL; | ||
1786 | } | ||
1787 | |||
1788 | acpi_ac_dir = acpi_lock_ac_dir(); | 1017 | acpi_ac_dir = acpi_lock_ac_dir(); |
1789 | if (!acpi_ac_dir) { | 1018 | if (!acpi_ac_dir) |
1790 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
1791 | "acpi_lock_ac_dir() failed")); | ||
1792 | return -ENODEV; | 1019 | return -ENODEV; |
1793 | } | ||
1794 | |||
1795 | acpi_battery_dir = acpi_lock_battery_dir(); | 1020 | acpi_battery_dir = acpi_lock_battery_dir(); |
1796 | if (!acpi_battery_dir) { | 1021 | if (!acpi_battery_dir) { |
1797 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
1798 | "acpi_lock_battery_dir() failed")); | ||
1799 | acpi_sbs_rmdirs(); | 1022 | acpi_sbs_rmdirs(); |
1800 | return -ENODEV; | 1023 | return -ENODEV; |
1801 | } | 1024 | } |
1802 | 1025 | #endif | |
1803 | result = acpi_bus_register_driver(&acpi_sbs_driver); | 1026 | result = acpi_bus_register_driver(&acpi_sbs_driver); |
1804 | if (result < 0) { | 1027 | if (result < 0) { |
1805 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
1806 | "acpi_bus_register_driver() failed")); | ||
1807 | acpi_sbs_rmdirs(); | 1028 | acpi_sbs_rmdirs(); |
1808 | return -ENODEV; | 1029 | return -ENODEV; |
1809 | } | 1030 | } |
1810 | |||
1811 | return 0; | 1031 | return 0; |
1812 | } | 1032 | } |
1813 | 1033 | ||
1814 | static void __exit acpi_sbs_exit(void) | 1034 | static void __exit acpi_sbs_exit(void) |
1815 | { | 1035 | { |
1816 | acpi_bus_unregister_driver(&acpi_sbs_driver); | 1036 | acpi_bus_unregister_driver(&acpi_sbs_driver); |
1817 | |||
1818 | acpi_sbs_rmdirs(); | 1037 | acpi_sbs_rmdirs(); |
1819 | |||
1820 | return; | 1038 | return; |
1821 | } | 1039 | } |
1822 | 1040 | ||
diff --git a/drivers/acpi/sbshc.c b/drivers/acpi/sbshc.c new file mode 100644 index 000000000000..046d7c3ed356 --- /dev/null +++ b/drivers/acpi/sbshc.c | |||
@@ -0,0 +1,309 @@ | |||
1 | /* | ||
2 | * SMBus driver for ACPI Embedded Controller (v0.1) | ||
3 | * | ||
4 | * Copyright (c) 2007 Alexey Starikovskiy | ||
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 version 2. | ||
9 | */ | ||
10 | |||
11 | #include <acpi/acpi_bus.h> | ||
12 | #include <acpi/acpi_drivers.h> | ||
13 | #include <acpi/actypes.h> | ||
14 | #include <linux/wait.h> | ||
15 | #include <linux/delay.h> | ||
16 | #include <linux/interrupt.h> | ||
17 | #include "sbshc.h" | ||
18 | |||
19 | #define ACPI_SMB_HC_CLASS "smbus_host_controller" | ||
20 | #define ACPI_SMB_HC_DEVICE_NAME "ACPI SMBus HC" | ||
21 | |||
22 | struct acpi_smb_hc { | ||
23 | struct acpi_ec *ec; | ||
24 | struct mutex lock; | ||
25 | wait_queue_head_t wait; | ||
26 | u8 offset; | ||
27 | u8 query_bit; | ||
28 | smbus_alarm_callback callback; | ||
29 | void *context; | ||
30 | }; | ||
31 | |||
32 | static int acpi_smbus_hc_add(struct acpi_device *device); | ||
33 | static int acpi_smbus_hc_remove(struct acpi_device *device, int type); | ||
34 | |||
35 | static const struct acpi_device_id sbs_device_ids[] = { | ||
36 | {"ACPI0001", 0}, | ||
37 | {"ACPI0005", 0}, | ||
38 | {"", 0}, | ||
39 | }; | ||
40 | |||
41 | MODULE_DEVICE_TABLE(acpi, sbs_device_ids); | ||
42 | |||
43 | static struct acpi_driver acpi_smb_hc_driver = { | ||
44 | .name = "smbus_hc", | ||
45 | .class = ACPI_SMB_HC_CLASS, | ||
46 | .ids = sbs_device_ids, | ||
47 | .ops = { | ||
48 | .add = acpi_smbus_hc_add, | ||
49 | .remove = acpi_smbus_hc_remove, | ||
50 | }, | ||
51 | }; | ||
52 | |||
53 | union acpi_smb_status { | ||
54 | u8 raw; | ||
55 | struct { | ||
56 | u8 status:5; | ||
57 | u8 reserved:1; | ||
58 | u8 alarm:1; | ||
59 | u8 done:1; | ||
60 | } fields; | ||
61 | }; | ||
62 | |||
63 | enum acpi_smb_status_codes { | ||
64 | SMBUS_OK = 0, | ||
65 | SMBUS_UNKNOWN_FAILURE = 0x07, | ||
66 | SMBUS_DEVICE_ADDRESS_NACK = 0x10, | ||
67 | SMBUS_DEVICE_ERROR = 0x11, | ||
68 | SMBUS_DEVICE_COMMAND_ACCESS_DENIED = 0x12, | ||
69 | SMBUS_UNKNOWN_ERROR = 0x13, | ||
70 | SMBUS_DEVICE_ACCESS_DENIED = 0x17, | ||
71 | SMBUS_TIMEOUT = 0x18, | ||
72 | SMBUS_HOST_UNSUPPORTED_PROTOCOL = 0x19, | ||
73 | SMBUS_BUSY = 0x1a, | ||
74 | SMBUS_PEC_ERROR = 0x1f, | ||
75 | }; | ||
76 | |||
77 | enum acpi_smb_offset { | ||
78 | ACPI_SMB_PROTOCOL = 0, /* protocol, PEC */ | ||
79 | ACPI_SMB_STATUS = 1, /* status */ | ||
80 | ACPI_SMB_ADDRESS = 2, /* address */ | ||
81 | ACPI_SMB_COMMAND = 3, /* command */ | ||
82 | ACPI_SMB_DATA = 4, /* 32 data registers */ | ||
83 | ACPI_SMB_BLOCK_COUNT = 0x24, /* number of data bytes */ | ||
84 | ACPI_SMB_ALARM_ADDRESS = 0x25, /* alarm address */ | ||
85 | ACPI_SMB_ALARM_DATA = 0x26, /* 2 bytes alarm data */ | ||
86 | }; | ||
87 | |||
88 | static inline int smb_hc_read(struct acpi_smb_hc *hc, u8 address, u8 *data) | ||
89 | { | ||
90 | return ec_read(hc->offset + address, data); | ||
91 | } | ||
92 | |||
93 | static inline int smb_hc_write(struct acpi_smb_hc *hc, u8 address, u8 data) | ||
94 | { | ||
95 | return ec_write(hc->offset + address, data); | ||
96 | } | ||
97 | |||
98 | static inline int smb_check_done(struct acpi_smb_hc *hc) | ||
99 | { | ||
100 | union acpi_smb_status status = {.raw = 0}; | ||
101 | smb_hc_read(hc, ACPI_SMB_STATUS, &status.raw); | ||
102 | return status.fields.done && (status.fields.status == SMBUS_OK); | ||
103 | } | ||
104 | |||
105 | static int wait_transaction_complete(struct acpi_smb_hc *hc, int timeout) | ||
106 | { | ||
107 | if (wait_event_timeout(hc->wait, smb_check_done(hc), | ||
108 | msecs_to_jiffies(timeout))) | ||
109 | return 0; | ||
110 | else | ||
111 | return -ETIME; | ||
112 | } | ||
113 | |||
114 | int acpi_smbus_transaction(struct acpi_smb_hc *hc, u8 protocol, u8 address, | ||
115 | u8 command, u8 *data, u8 length) | ||
116 | { | ||
117 | int ret = -EFAULT, i; | ||
118 | u8 temp, sz = 0; | ||
119 | |||
120 | mutex_lock(&hc->lock); | ||
121 | if (smb_hc_read(hc, ACPI_SMB_PROTOCOL, &temp)) | ||
122 | goto end; | ||
123 | if (temp) { | ||
124 | ret = -EBUSY; | ||
125 | goto end; | ||
126 | } | ||
127 | smb_hc_write(hc, ACPI_SMB_COMMAND, command); | ||
128 | smb_hc_write(hc, ACPI_SMB_COMMAND, command); | ||
129 | if (!(protocol & 0x01)) { | ||
130 | smb_hc_write(hc, ACPI_SMB_BLOCK_COUNT, length); | ||
131 | for (i = 0; i < length; ++i) | ||
132 | smb_hc_write(hc, ACPI_SMB_DATA + i, data[i]); | ||
133 | } | ||
134 | smb_hc_write(hc, ACPI_SMB_ADDRESS, address << 1); | ||
135 | smb_hc_write(hc, ACPI_SMB_PROTOCOL, protocol); | ||
136 | /* | ||
137 | * Wait for completion. Save the status code, data size, | ||
138 | * and data into the return package (if required by the protocol). | ||
139 | */ | ||
140 | ret = wait_transaction_complete(hc, 1000); | ||
141 | if (ret || !(protocol & 0x01)) | ||
142 | goto end; | ||
143 | switch (protocol) { | ||
144 | case SMBUS_RECEIVE_BYTE: | ||
145 | case SMBUS_READ_BYTE: | ||
146 | sz = 1; | ||
147 | break; | ||
148 | case SMBUS_READ_WORD: | ||
149 | sz = 2; | ||
150 | break; | ||
151 | case SMBUS_READ_BLOCK: | ||
152 | if (smb_hc_read(hc, ACPI_SMB_BLOCK_COUNT, &sz)) { | ||
153 | ret = -EFAULT; | ||
154 | goto end; | ||
155 | } | ||
156 | sz &= 0x1f; | ||
157 | break; | ||
158 | } | ||
159 | for (i = 0; i < sz; ++i) | ||
160 | smb_hc_read(hc, ACPI_SMB_DATA + i, &data[i]); | ||
161 | end: | ||
162 | mutex_unlock(&hc->lock); | ||
163 | return ret; | ||
164 | } | ||
165 | |||
166 | int acpi_smbus_read(struct acpi_smb_hc *hc, u8 protocol, u8 address, | ||
167 | u8 command, u8 *data) | ||
168 | { | ||
169 | return acpi_smbus_transaction(hc, protocol, address, command, data, 0); | ||
170 | } | ||
171 | |||
172 | EXPORT_SYMBOL_GPL(acpi_smbus_read); | ||
173 | |||
174 | int acpi_smbus_write(struct acpi_smb_hc *hc, u8 protocol, u8 address, | ||
175 | u8 command, u8 *data, u8 length) | ||
176 | { | ||
177 | return acpi_smbus_transaction(hc, protocol, address, command, data, length); | ||
178 | } | ||
179 | |||
180 | EXPORT_SYMBOL_GPL(acpi_smbus_write); | ||
181 | |||
182 | int acpi_smbus_register_callback(struct acpi_smb_hc *hc, | ||
183 | smbus_alarm_callback callback, void *context) | ||
184 | { | ||
185 | mutex_lock(&hc->lock); | ||
186 | hc->callback = callback; | ||
187 | hc->context = context; | ||
188 | mutex_unlock(&hc->lock); | ||
189 | return 0; | ||
190 | } | ||
191 | |||
192 | EXPORT_SYMBOL_GPL(acpi_smbus_register_callback); | ||
193 | |||
194 | int acpi_smbus_unregister_callback(struct acpi_smb_hc *hc) | ||
195 | { | ||
196 | mutex_lock(&hc->lock); | ||
197 | hc->callback = NULL; | ||
198 | hc->context = NULL; | ||
199 | mutex_unlock(&hc->lock); | ||
200 | return 0; | ||
201 | } | ||
202 | |||
203 | EXPORT_SYMBOL_GPL(acpi_smbus_unregister_callback); | ||
204 | |||
205 | static void acpi_smbus_callback(void *context) | ||
206 | { | ||
207 | struct acpi_smb_hc *hc = context; | ||
208 | |||
209 | if (hc->callback) | ||
210 | hc->callback(hc->context); | ||
211 | } | ||
212 | |||
213 | static int smbus_alarm(void *context) | ||
214 | { | ||
215 | struct acpi_smb_hc *hc = context; | ||
216 | union acpi_smb_status status; | ||
217 | if (smb_hc_read(hc, ACPI_SMB_STATUS, &status.raw)) | ||
218 | return 0; | ||
219 | /* Check if it is only a completion notify */ | ||
220 | if (status.fields.done) | ||
221 | wake_up(&hc->wait); | ||
222 | if (!status.fields.alarm) | ||
223 | return 0; | ||
224 | mutex_lock(&hc->lock); | ||
225 | smb_hc_write(hc, ACPI_SMB_STATUS, status.raw); | ||
226 | if (hc->callback) | ||
227 | acpi_os_execute(OSL_GPE_HANDLER, acpi_smbus_callback, hc); | ||
228 | mutex_unlock(&hc->lock); | ||
229 | return 0; | ||
230 | } | ||
231 | |||
232 | typedef int (*acpi_ec_query_func) (void *data); | ||
233 | |||
234 | extern int acpi_ec_add_query_handler(struct acpi_ec *ec, u8 query_bit, | ||
235 | acpi_handle handle, acpi_ec_query_func func, | ||
236 | void *data); | ||
237 | |||
238 | static int acpi_smbus_hc_add(struct acpi_device *device) | ||
239 | { | ||
240 | int status; | ||
241 | unsigned long val; | ||
242 | struct acpi_smb_hc *hc; | ||
243 | |||
244 | if (!device) | ||
245 | return -EINVAL; | ||
246 | |||
247 | status = acpi_evaluate_integer(device->handle, "_EC", NULL, &val); | ||
248 | if (ACPI_FAILURE(status)) { | ||
249 | printk(KERN_ERR PREFIX "error obtaining _EC.\n"); | ||
250 | return -EIO; | ||
251 | } | ||
252 | |||
253 | strcpy(acpi_device_name(device), ACPI_SMB_HC_DEVICE_NAME); | ||
254 | strcpy(acpi_device_class(device), ACPI_SMB_HC_CLASS); | ||
255 | |||
256 | hc = kzalloc(sizeof(struct acpi_smb_hc), GFP_KERNEL); | ||
257 | if (!hc) | ||
258 | return -ENOMEM; | ||
259 | mutex_init(&hc->lock); | ||
260 | init_waitqueue_head(&hc->wait); | ||
261 | |||
262 | hc->ec = acpi_driver_data(device->parent); | ||
263 | hc->offset = (val >> 8) & 0xff; | ||
264 | hc->query_bit = val & 0xff; | ||
265 | acpi_driver_data(device) = hc; | ||
266 | |||
267 | acpi_ec_add_query_handler(hc->ec, hc->query_bit, NULL, smbus_alarm, hc); | ||
268 | printk(KERN_INFO PREFIX "SBS HC: EC = 0x%p, offset = 0x%0x, query_bit = 0x%0x\n", | ||
269 | hc->ec, hc->offset, hc->query_bit); | ||
270 | |||
271 | return 0; | ||
272 | } | ||
273 | |||
274 | extern void acpi_ec_remove_query_handler(struct acpi_ec *ec, u8 query_bit); | ||
275 | |||
276 | static int acpi_smbus_hc_remove(struct acpi_device *device, int type) | ||
277 | { | ||
278 | struct acpi_smb_hc *hc; | ||
279 | |||
280 | if (!device) | ||
281 | return -EINVAL; | ||
282 | |||
283 | hc = acpi_driver_data(device); | ||
284 | acpi_ec_remove_query_handler(hc->ec, hc->query_bit); | ||
285 | kfree(hc); | ||
286 | return 0; | ||
287 | } | ||
288 | |||
289 | static int __init acpi_smb_hc_init(void) | ||
290 | { | ||
291 | int result; | ||
292 | |||
293 | result = acpi_bus_register_driver(&acpi_smb_hc_driver); | ||
294 | if (result < 0) | ||
295 | return -ENODEV; | ||
296 | return 0; | ||
297 | } | ||
298 | |||
299 | static void __exit acpi_smb_hc_exit(void) | ||
300 | { | ||
301 | acpi_bus_unregister_driver(&acpi_smb_hc_driver); | ||
302 | } | ||
303 | |||
304 | module_init(acpi_smb_hc_init); | ||
305 | module_exit(acpi_smb_hc_exit); | ||
306 | |||
307 | MODULE_LICENSE("GPL"); | ||
308 | MODULE_AUTHOR("Alexey Starikovskiy"); | ||
309 | MODULE_DESCRIPTION("ACPI SMBus HC driver"); | ||
diff --git a/drivers/acpi/sbshc.h b/drivers/acpi/sbshc.h new file mode 100644 index 000000000000..3bda3491a97b --- /dev/null +++ b/drivers/acpi/sbshc.h | |||
@@ -0,0 +1,27 @@ | |||
1 | struct acpi_smb_hc; | ||
2 | enum acpi_smb_protocol { | ||
3 | SMBUS_WRITE_QUICK = 2, | ||
4 | SMBUS_READ_QUICK = 3, | ||
5 | SMBUS_SEND_BYTE = 4, | ||
6 | SMBUS_RECEIVE_BYTE = 5, | ||
7 | SMBUS_WRITE_BYTE = 6, | ||
8 | SMBUS_READ_BYTE = 7, | ||
9 | SMBUS_WRITE_WORD = 8, | ||
10 | SMBUS_READ_WORD = 9, | ||
11 | SMBUS_WRITE_BLOCK = 0xa, | ||
12 | SMBUS_READ_BLOCK = 0xb, | ||
13 | SMBUS_PROCESS_CALL = 0xc, | ||
14 | SMBUS_BLOCK_PROCESS_CALL = 0xd, | ||
15 | }; | ||
16 | |||
17 | static const u8 SMBUS_PEC = 0x80; | ||
18 | |||
19 | typedef void (*smbus_alarm_callback)(void *context); | ||
20 | |||
21 | extern int acpi_smbus_read(struct acpi_smb_hc *hc, u8 protocol, u8 address, | ||
22 | u8 command, u8 * data); | ||
23 | extern int acpi_smbus_write(struct acpi_smb_hc *hc, u8 protocol, u8 slave_address, | ||
24 | u8 command, u8 * data, u8 length); | ||
25 | extern int acpi_smbus_register_callback(struct acpi_smb_hc *hc, | ||
26 | smbus_alarm_callback callback, void *context); | ||
27 | extern int acpi_smbus_unregister_callback(struct acpi_smb_hc *hc); | ||
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index 64620d668742..5b4d462117cf 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c | |||
@@ -319,16 +319,18 @@ static int acpi_bus_match(struct device *dev, struct device_driver *drv) | |||
319 | return !acpi_match_device_ids(acpi_dev, acpi_drv->ids); | 319 | return !acpi_match_device_ids(acpi_dev, acpi_drv->ids); |
320 | } | 320 | } |
321 | 321 | ||
322 | static int acpi_device_uevent(struct device *dev, char **envp, int num_envp, | 322 | static int acpi_device_uevent(struct device *dev, struct kobj_uevent_env *env) |
323 | char *buffer, int buffer_size) | ||
324 | { | 323 | { |
325 | struct acpi_device *acpi_dev = to_acpi_device(dev); | 324 | struct acpi_device *acpi_dev = to_acpi_device(dev); |
325 | int len; | ||
326 | 326 | ||
327 | strcpy(buffer, "MODALIAS="); | 327 | if (add_uevent_var(env, "MODALIAS=")) |
328 | if (create_modalias(acpi_dev, buffer + 9, buffer_size - 9) > 0) { | 328 | return -ENOMEM; |
329 | envp[0] = buffer; | 329 | len = create_modalias(acpi_dev, &env->buf[env->buflen - 1], |
330 | envp[1] = NULL; | 330 | sizeof(env->buf) - env->buflen); |
331 | } | 331 | if (len >= (sizeof(env->buf) - env->buflen)) |
332 | return -ENOMEM; | ||
333 | env->buflen += len; | ||
332 | return 0; | 334 | return 0; |
333 | } | 335 | } |
334 | 336 | ||
diff --git a/drivers/acpi/sleep/main.c b/drivers/acpi/sleep/main.c index 2cbb9aabd00e..2c0b6630f8ba 100644 --- a/drivers/acpi/sleep/main.c +++ b/drivers/acpi/sleep/main.c | |||
@@ -44,13 +44,12 @@ int acpi_sleep_prepare(u32 acpi_state) | |||
44 | ACPI_FLUSH_CPU_CACHE(); | 44 | ACPI_FLUSH_CPU_CACHE(); |
45 | acpi_enable_wakeup_device_prep(acpi_state); | 45 | acpi_enable_wakeup_device_prep(acpi_state); |
46 | #endif | 46 | #endif |
47 | acpi_gpe_sleep_prepare(acpi_state); | ||
48 | acpi_enter_sleep_state_prep(acpi_state); | 47 | acpi_enter_sleep_state_prep(acpi_state); |
49 | return 0; | 48 | return 0; |
50 | } | 49 | } |
51 | 50 | ||
52 | #ifdef CONFIG_SUSPEND | 51 | #ifdef CONFIG_SUSPEND |
53 | static struct pm_ops acpi_pm_ops; | 52 | static struct platform_suspend_ops acpi_pm_ops; |
54 | 53 | ||
55 | extern void do_suspend_lowlevel(void); | 54 | extern void do_suspend_lowlevel(void); |
56 | 55 | ||
@@ -85,13 +84,12 @@ static int acpi_pm_set_target(suspend_state_t pm_state) | |||
85 | 84 | ||
86 | /** | 85 | /** |
87 | * acpi_pm_prepare - Do preliminary suspend work. | 86 | * acpi_pm_prepare - Do preliminary suspend work. |
88 | * @pm_state: ignored | ||
89 | * | 87 | * |
90 | * If necessary, set the firmware waking vector and do arch-specific | 88 | * If necessary, set the firmware waking vector and do arch-specific |
91 | * nastiness to get the wakeup code to the waking vector. | 89 | * nastiness to get the wakeup code to the waking vector. |
92 | */ | 90 | */ |
93 | 91 | ||
94 | static int acpi_pm_prepare(suspend_state_t pm_state) | 92 | static int acpi_pm_prepare(void) |
95 | { | 93 | { |
96 | int error = acpi_sleep_prepare(acpi_target_sleep_state); | 94 | int error = acpi_sleep_prepare(acpi_target_sleep_state); |
97 | 95 | ||
@@ -160,18 +158,17 @@ static int acpi_pm_enter(suspend_state_t pm_state) | |||
160 | 158 | ||
161 | /** | 159 | /** |
162 | * acpi_pm_finish - Finish up suspend sequence. | 160 | * acpi_pm_finish - Finish up suspend sequence. |
163 | * @pm_state: ignored | ||
164 | * | 161 | * |
165 | * This is called after we wake back up (or if entering the sleep state | 162 | * This is called after we wake back up (or if entering the sleep state |
166 | * failed). | 163 | * failed). |
167 | */ | 164 | */ |
168 | 165 | ||
169 | static int acpi_pm_finish(suspend_state_t pm_state) | 166 | static void acpi_pm_finish(void) |
170 | { | 167 | { |
171 | u32 acpi_state = acpi_target_sleep_state; | 168 | u32 acpi_state = acpi_target_sleep_state; |
172 | 169 | ||
173 | acpi_leave_sleep_state(acpi_state); | ||
174 | acpi_disable_wakeup_device(acpi_state); | 170 | acpi_disable_wakeup_device(acpi_state); |
171 | acpi_leave_sleep_state(acpi_state); | ||
175 | 172 | ||
176 | /* reset firmware waking vector */ | 173 | /* reset firmware waking vector */ |
177 | acpi_set_firmware_waking_vector((acpi_physical_address) 0); | 174 | acpi_set_firmware_waking_vector((acpi_physical_address) 0); |
@@ -184,7 +181,6 @@ static int acpi_pm_finish(suspend_state_t pm_state) | |||
184 | init_8259A(0); | 181 | init_8259A(0); |
185 | } | 182 | } |
186 | #endif | 183 | #endif |
187 | return 0; | ||
188 | } | 184 | } |
189 | 185 | ||
190 | static int acpi_pm_state_valid(suspend_state_t pm_state) | 186 | static int acpi_pm_state_valid(suspend_state_t pm_state) |
@@ -203,7 +199,7 @@ static int acpi_pm_state_valid(suspend_state_t pm_state) | |||
203 | } | 199 | } |
204 | } | 200 | } |
205 | 201 | ||
206 | static struct pm_ops acpi_pm_ops = { | 202 | static struct platform_suspend_ops acpi_pm_ops = { |
207 | .valid = acpi_pm_state_valid, | 203 | .valid = acpi_pm_state_valid, |
208 | .set_target = acpi_pm_set_target, | 204 | .set_target = acpi_pm_set_target, |
209 | .prepare = acpi_pm_prepare, | 205 | .prepare = acpi_pm_prepare, |
@@ -215,7 +211,7 @@ static struct pm_ops acpi_pm_ops = { | |||
215 | * Toshiba fails to preserve interrupts over S1, reinitialization | 211 | * Toshiba fails to preserve interrupts over S1, reinitialization |
216 | * of 8259 is needed after S1 resume. | 212 | * of 8259 is needed after S1 resume. |
217 | */ | 213 | */ |
218 | static int __init init_ints_after_s1(struct dmi_system_id *d) | 214 | static int __init init_ints_after_s1(const struct dmi_system_id *d) |
219 | { | 215 | { |
220 | printk(KERN_WARNING "%s with broken S1 detected.\n", d->ident); | 216 | printk(KERN_WARNING "%s with broken S1 detected.\n", d->ident); |
221 | init_8259A_after_S1 = 1; | 217 | init_8259A_after_S1 = 1; |
@@ -233,6 +229,12 @@ static struct dmi_system_id __initdata acpisleep_dmi_table[] = { | |||
233 | #endif /* CONFIG_SUSPEND */ | 229 | #endif /* CONFIG_SUSPEND */ |
234 | 230 | ||
235 | #ifdef CONFIG_HIBERNATION | 231 | #ifdef CONFIG_HIBERNATION |
232 | static int acpi_hibernation_start(void) | ||
233 | { | ||
234 | acpi_target_sleep_state = ACPI_STATE_S4; | ||
235 | return 0; | ||
236 | } | ||
237 | |||
236 | static int acpi_hibernation_prepare(void) | 238 | static int acpi_hibernation_prepare(void) |
237 | { | 239 | { |
238 | return acpi_sleep_prepare(ACPI_STATE_S4); | 240 | return acpi_sleep_prepare(ACPI_STATE_S4); |
@@ -254,13 +256,29 @@ static int acpi_hibernation_enter(void) | |||
254 | return ACPI_SUCCESS(status) ? 0 : -EFAULT; | 256 | return ACPI_SUCCESS(status) ? 0 : -EFAULT; |
255 | } | 257 | } |
256 | 258 | ||
259 | static void acpi_hibernation_leave(void) | ||
260 | { | ||
261 | /* | ||
262 | * If ACPI is not enabled by the BIOS and the boot kernel, we need to | ||
263 | * enable it here. | ||
264 | */ | ||
265 | acpi_enable(); | ||
266 | } | ||
267 | |||
257 | static void acpi_hibernation_finish(void) | 268 | static void acpi_hibernation_finish(void) |
258 | { | 269 | { |
259 | acpi_leave_sleep_state(ACPI_STATE_S4); | 270 | /* |
271 | * If ACPI is not enabled by the BIOS and the boot kernel, we need to | ||
272 | * enable it here. | ||
273 | */ | ||
274 | acpi_enable(); | ||
260 | acpi_disable_wakeup_device(ACPI_STATE_S4); | 275 | acpi_disable_wakeup_device(ACPI_STATE_S4); |
276 | acpi_leave_sleep_state(ACPI_STATE_S4); | ||
261 | 277 | ||
262 | /* reset firmware waking vector */ | 278 | /* reset firmware waking vector */ |
263 | acpi_set_firmware_waking_vector((acpi_physical_address) 0); | 279 | acpi_set_firmware_waking_vector((acpi_physical_address) 0); |
280 | |||
281 | acpi_target_sleep_state = ACPI_STATE_S0; | ||
264 | } | 282 | } |
265 | 283 | ||
266 | static int acpi_hibernation_pre_restore(void) | 284 | static int acpi_hibernation_pre_restore(void) |
@@ -277,10 +295,13 @@ static void acpi_hibernation_restore_cleanup(void) | |||
277 | acpi_hw_enable_all_runtime_gpes(); | 295 | acpi_hw_enable_all_runtime_gpes(); |
278 | } | 296 | } |
279 | 297 | ||
280 | static struct hibernation_ops acpi_hibernation_ops = { | 298 | static struct platform_hibernation_ops acpi_hibernation_ops = { |
299 | .start = acpi_hibernation_start, | ||
300 | .pre_snapshot = acpi_hibernation_prepare, | ||
301 | .finish = acpi_hibernation_finish, | ||
281 | .prepare = acpi_hibernation_prepare, | 302 | .prepare = acpi_hibernation_prepare, |
282 | .enter = acpi_hibernation_enter, | 303 | .enter = acpi_hibernation_enter, |
283 | .finish = acpi_hibernation_finish, | 304 | .leave = acpi_hibernation_leave, |
284 | .pre_restore = acpi_hibernation_pre_restore, | 305 | .pre_restore = acpi_hibernation_pre_restore, |
285 | .restore_cleanup = acpi_hibernation_restore_cleanup, | 306 | .restore_cleanup = acpi_hibernation_restore_cleanup, |
286 | }; | 307 | }; |
@@ -389,6 +410,7 @@ static void acpi_power_off(void) | |||
389 | /* acpi_sleep_prepare(ACPI_STATE_S5) should have already been called */ | 410 | /* acpi_sleep_prepare(ACPI_STATE_S5) should have already been called */ |
390 | printk("%s called\n", __FUNCTION__); | 411 | printk("%s called\n", __FUNCTION__); |
391 | local_irq_disable(); | 412 | local_irq_disable(); |
413 | acpi_enable_wakeup_device(ACPI_STATE_S5); | ||
392 | acpi_enter_sleep_state(ACPI_STATE_S5); | 414 | acpi_enter_sleep_state(ACPI_STATE_S5); |
393 | } | 415 | } |
394 | 416 | ||
@@ -417,7 +439,7 @@ int __init acpi_sleep_init(void) | |||
417 | } | 439 | } |
418 | } | 440 | } |
419 | 441 | ||
420 | pm_set_ops(&acpi_pm_ops); | 442 | suspend_set_ops(&acpi_pm_ops); |
421 | #endif | 443 | #endif |
422 | 444 | ||
423 | #ifdef CONFIG_HIBERNATION | 445 | #ifdef CONFIG_HIBERNATION |
diff --git a/drivers/acpi/sleep/proc.c b/drivers/acpi/sleep/proc.c index 3839efd5eaea..1538355c266b 100644 --- a/drivers/acpi/sleep/proc.c +++ b/drivers/acpi/sleep/proc.c | |||
@@ -194,6 +194,23 @@ static int get_date_field(char **p, u32 * value) | |||
194 | return result; | 194 | return result; |
195 | } | 195 | } |
196 | 196 | ||
197 | /* Read a possibly BCD register, always return binary */ | ||
198 | static u32 cmos_bcd_read(int offset, int rtc_control) | ||
199 | { | ||
200 | u32 val = CMOS_READ(offset); | ||
201 | if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) | ||
202 | BCD_TO_BIN(val); | ||
203 | return val; | ||
204 | } | ||
205 | |||
206 | /* Write binary value into possibly BCD register */ | ||
207 | static void cmos_bcd_write(u32 val, int offset, int rtc_control) | ||
208 | { | ||
209 | if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) | ||
210 | BIN_TO_BCD(val); | ||
211 | CMOS_WRITE(val, offset); | ||
212 | } | ||
213 | |||
197 | static ssize_t | 214 | static ssize_t |
198 | acpi_system_write_alarm(struct file *file, | 215 | acpi_system_write_alarm(struct file *file, |
199 | const char __user * buffer, size_t count, loff_t * ppos) | 216 | const char __user * buffer, size_t count, loff_t * ppos) |
@@ -258,35 +275,18 @@ acpi_system_write_alarm(struct file *file, | |||
258 | spin_lock_irq(&rtc_lock); | 275 | spin_lock_irq(&rtc_lock); |
259 | 276 | ||
260 | rtc_control = CMOS_READ(RTC_CONTROL); | 277 | rtc_control = CMOS_READ(RTC_CONTROL); |
261 | if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) { | ||
262 | BIN_TO_BCD(yr); | ||
263 | BIN_TO_BCD(mo); | ||
264 | BIN_TO_BCD(day); | ||
265 | BIN_TO_BCD(hr); | ||
266 | BIN_TO_BCD(min); | ||
267 | BIN_TO_BCD(sec); | ||
268 | } | ||
269 | 278 | ||
270 | if (adjust) { | 279 | if (adjust) { |
271 | yr += CMOS_READ(RTC_YEAR); | 280 | yr += cmos_bcd_read(RTC_YEAR, rtc_control); |
272 | mo += CMOS_READ(RTC_MONTH); | 281 | mo += cmos_bcd_read(RTC_MONTH, rtc_control); |
273 | day += CMOS_READ(RTC_DAY_OF_MONTH); | 282 | day += cmos_bcd_read(RTC_DAY_OF_MONTH, rtc_control); |
274 | hr += CMOS_READ(RTC_HOURS); | 283 | hr += cmos_bcd_read(RTC_HOURS, rtc_control); |
275 | min += CMOS_READ(RTC_MINUTES); | 284 | min += cmos_bcd_read(RTC_MINUTES, rtc_control); |
276 | sec += CMOS_READ(RTC_SECONDS); | 285 | sec += cmos_bcd_read(RTC_SECONDS, rtc_control); |
277 | } | 286 | } |
278 | 287 | ||
279 | spin_unlock_irq(&rtc_lock); | 288 | spin_unlock_irq(&rtc_lock); |
280 | 289 | ||
281 | if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) { | ||
282 | BCD_TO_BIN(yr); | ||
283 | BCD_TO_BIN(mo); | ||
284 | BCD_TO_BIN(day); | ||
285 | BCD_TO_BIN(hr); | ||
286 | BCD_TO_BIN(min); | ||
287 | BCD_TO_BIN(sec); | ||
288 | } | ||
289 | |||
290 | if (sec > 59) { | 290 | if (sec > 59) { |
291 | min++; | 291 | min++; |
292 | sec -= 60; | 292 | sec -= 60; |
@@ -307,14 +307,6 @@ acpi_system_write_alarm(struct file *file, | |||
307 | yr++; | 307 | yr++; |
308 | mo -= 12; | 308 | mo -= 12; |
309 | } | 309 | } |
310 | if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) { | ||
311 | BIN_TO_BCD(yr); | ||
312 | BIN_TO_BCD(mo); | ||
313 | BIN_TO_BCD(day); | ||
314 | BIN_TO_BCD(hr); | ||
315 | BIN_TO_BCD(min); | ||
316 | BIN_TO_BCD(sec); | ||
317 | } | ||
318 | 310 | ||
319 | spin_lock_irq(&rtc_lock); | 311 | spin_lock_irq(&rtc_lock); |
320 | /* | 312 | /* |
@@ -326,9 +318,9 @@ acpi_system_write_alarm(struct file *file, | |||
326 | CMOS_READ(RTC_INTR_FLAGS); | 318 | CMOS_READ(RTC_INTR_FLAGS); |
327 | 319 | ||
328 | /* write the fields the rtc knows about */ | 320 | /* write the fields the rtc knows about */ |
329 | CMOS_WRITE(hr, RTC_HOURS_ALARM); | 321 | cmos_bcd_write(hr, RTC_HOURS_ALARM, rtc_control); |
330 | CMOS_WRITE(min, RTC_MINUTES_ALARM); | 322 | cmos_bcd_write(min, RTC_MINUTES_ALARM, rtc_control); |
331 | CMOS_WRITE(sec, RTC_SECONDS_ALARM); | 323 | cmos_bcd_write(sec, RTC_SECONDS_ALARM, rtc_control); |
332 | 324 | ||
333 | /* | 325 | /* |
334 | * If the system supports an enhanced alarm it will have non-zero | 326 | * If the system supports an enhanced alarm it will have non-zero |
@@ -336,11 +328,11 @@ acpi_system_write_alarm(struct file *file, | |||
336 | * to the RTC area of memory. | 328 | * to the RTC area of memory. |
337 | */ | 329 | */ |
338 | if (acpi_gbl_FADT.day_alarm) | 330 | if (acpi_gbl_FADT.day_alarm) |
339 | CMOS_WRITE(day, acpi_gbl_FADT.day_alarm); | 331 | cmos_bcd_write(day, acpi_gbl_FADT.day_alarm, rtc_control); |
340 | if (acpi_gbl_FADT.month_alarm) | 332 | if (acpi_gbl_FADT.month_alarm) |
341 | CMOS_WRITE(mo, acpi_gbl_FADT.month_alarm); | 333 | cmos_bcd_write(mo, acpi_gbl_FADT.month_alarm, rtc_control); |
342 | if (acpi_gbl_FADT.century) | 334 | if (acpi_gbl_FADT.century) |
343 | CMOS_WRITE(yr / 100, acpi_gbl_FADT.century); | 335 | cmos_bcd_write(yr / 100, acpi_gbl_FADT.century, rtc_control); |
344 | /* enable the rtc alarm interrupt */ | 336 | /* enable the rtc alarm interrupt */ |
345 | rtc_control |= RTC_AIE; | 337 | rtc_control |= RTC_AIE; |
346 | CMOS_WRITE(rtc_control, RTC_CONTROL); | 338 | CMOS_WRITE(rtc_control, RTC_CONTROL); |
diff --git a/drivers/acpi/sleep/sleep.h b/drivers/acpi/sleep/sleep.h index ff1f8504f497..a2ea125ae2d0 100644 --- a/drivers/acpi/sleep/sleep.h +++ b/drivers/acpi/sleep/sleep.h | |||
@@ -5,6 +5,5 @@ extern int acpi_suspend (u32 state); | |||
5 | extern void acpi_enable_wakeup_device_prep(u8 sleep_state); | 5 | extern void acpi_enable_wakeup_device_prep(u8 sleep_state); |
6 | extern void acpi_enable_wakeup_device(u8 sleep_state); | 6 | extern void acpi_enable_wakeup_device(u8 sleep_state); |
7 | extern void acpi_disable_wakeup_device(u8 sleep_state); | 7 | extern void acpi_disable_wakeup_device(u8 sleep_state); |
8 | extern void acpi_gpe_sleep_prepare(u32 sleep_state); | ||
9 | 8 | ||
10 | extern int acpi_sleep_prepare(u32 acpi_state); | 9 | extern int acpi_sleep_prepare(u32 acpi_state); |
diff --git a/drivers/acpi/sleep/wakeup.c b/drivers/acpi/sleep/wakeup.c index 97c27ddb144d..ed8e41becf0c 100644 --- a/drivers/acpi/sleep/wakeup.c +++ b/drivers/acpi/sleep/wakeup.c | |||
@@ -64,36 +64,29 @@ void acpi_enable_wakeup_device(u8 sleep_state) | |||
64 | ACPI_FUNCTION_TRACE("acpi_enable_wakeup_device"); | 64 | ACPI_FUNCTION_TRACE("acpi_enable_wakeup_device"); |
65 | spin_lock(&acpi_device_lock); | 65 | spin_lock(&acpi_device_lock); |
66 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { | 66 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { |
67 | struct acpi_device *dev = container_of(node, | 67 | struct acpi_device *dev = |
68 | struct acpi_device, | 68 | container_of(node, struct acpi_device, wakeup_list); |
69 | wakeup_list); | 69 | if (!dev->wakeup.flags.valid) |
70 | 70 | continue; | |
71 | /* If users want to disable run-wake GPE, | 71 | /* If users want to disable run-wake GPE, |
72 | * we only disable it for wake and leave it for runtime | 72 | * we only disable it for wake and leave it for runtime |
73 | */ | 73 | */ |
74 | if (dev->wakeup.flags.run_wake && !dev->wakeup.state.enabled) { | 74 | if (!dev->wakeup.state.enabled || |
75 | spin_unlock(&acpi_device_lock); | 75 | sleep_state > (u32) dev->wakeup.sleep_state) { |
76 | acpi_set_gpe_type(dev->wakeup.gpe_device, | 76 | if (dev->wakeup.flags.run_wake) { |
77 | dev->wakeup.gpe_number, | 77 | spin_unlock(&acpi_device_lock); |
78 | ACPI_GPE_TYPE_RUNTIME); | 78 | /* set_gpe_type will disable GPE, leave it like that */ |
79 | /* Re-enable it, since set_gpe_type will disable it */ | 79 | acpi_set_gpe_type(dev->wakeup.gpe_device, |
80 | acpi_enable_gpe(dev->wakeup.gpe_device, | 80 | dev->wakeup.gpe_number, |
81 | dev->wakeup.gpe_number, ACPI_ISR); | 81 | ACPI_GPE_TYPE_RUNTIME); |
82 | spin_lock(&acpi_device_lock); | 82 | spin_lock(&acpi_device_lock); |
83 | } | ||
83 | continue; | 84 | continue; |
84 | } | 85 | } |
85 | |||
86 | if (!dev->wakeup.flags.valid || | ||
87 | !dev->wakeup.state.enabled || | ||
88 | (sleep_state > (u32) dev->wakeup.sleep_state)) | ||
89 | continue; | ||
90 | |||
91 | spin_unlock(&acpi_device_lock); | 86 | spin_unlock(&acpi_device_lock); |
92 | /* run-wake GPE has been enabled */ | ||
93 | if (!dev->wakeup.flags.run_wake) | 87 | if (!dev->wakeup.flags.run_wake) |
94 | acpi_enable_gpe(dev->wakeup.gpe_device, | 88 | acpi_enable_gpe(dev->wakeup.gpe_device, |
95 | dev->wakeup.gpe_number, ACPI_ISR); | 89 | dev->wakeup.gpe_number, ACPI_ISR); |
96 | dev->wakeup.state.active = 1; | ||
97 | spin_lock(&acpi_device_lock); | 90 | spin_lock(&acpi_device_lock); |
98 | } | 91 | } |
99 | spin_unlock(&acpi_device_lock); | 92 | spin_unlock(&acpi_device_lock); |
@@ -112,26 +105,25 @@ void acpi_disable_wakeup_device(u8 sleep_state) | |||
112 | 105 | ||
113 | spin_lock(&acpi_device_lock); | 106 | spin_lock(&acpi_device_lock); |
114 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { | 107 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { |
115 | struct acpi_device *dev = container_of(node, | 108 | struct acpi_device *dev = |
116 | struct acpi_device, | 109 | container_of(node, struct acpi_device, wakeup_list); |
117 | wakeup_list); | ||
118 | 110 | ||
119 | if (dev->wakeup.flags.run_wake && !dev->wakeup.state.enabled) { | 111 | if (!dev->wakeup.flags.valid) |
120 | spin_unlock(&acpi_device_lock); | ||
121 | acpi_set_gpe_type(dev->wakeup.gpe_device, | ||
122 | dev->wakeup.gpe_number, | ||
123 | ACPI_GPE_TYPE_WAKE_RUN); | ||
124 | /* Re-enable it, since set_gpe_type will disable it */ | ||
125 | acpi_enable_gpe(dev->wakeup.gpe_device, | ||
126 | dev->wakeup.gpe_number, ACPI_NOT_ISR); | ||
127 | spin_lock(&acpi_device_lock); | ||
128 | continue; | 112 | continue; |
129 | } | 113 | if (!dev->wakeup.state.enabled || |
130 | 114 | sleep_state > (u32) dev->wakeup.sleep_state) { | |
131 | if (!dev->wakeup.flags.valid || | 115 | if (dev->wakeup.flags.run_wake) { |
132 | !dev->wakeup.state.active || | 116 | spin_unlock(&acpi_device_lock); |
133 | (sleep_state > (u32) dev->wakeup.sleep_state)) | 117 | acpi_set_gpe_type(dev->wakeup.gpe_device, |
118 | dev->wakeup.gpe_number, | ||
119 | ACPI_GPE_TYPE_WAKE_RUN); | ||
120 | /* Re-enable it, since set_gpe_type will disable it */ | ||
121 | acpi_enable_gpe(dev->wakeup.gpe_device, | ||
122 | dev->wakeup.gpe_number, ACPI_NOT_ISR); | ||
123 | spin_lock(&acpi_device_lock); | ||
124 | } | ||
134 | continue; | 125 | continue; |
126 | } | ||
135 | 127 | ||
136 | spin_unlock(&acpi_device_lock); | 128 | spin_unlock(&acpi_device_lock); |
137 | acpi_disable_wakeup_device_power(dev); | 129 | acpi_disable_wakeup_device_power(dev); |
@@ -142,7 +134,6 @@ void acpi_disable_wakeup_device(u8 sleep_state) | |||
142 | acpi_clear_gpe(dev->wakeup.gpe_device, | 134 | acpi_clear_gpe(dev->wakeup.gpe_device, |
143 | dev->wakeup.gpe_number, ACPI_NOT_ISR); | 135 | dev->wakeup.gpe_number, ACPI_NOT_ISR); |
144 | } | 136 | } |
145 | dev->wakeup.state.active = 0; | ||
146 | spin_lock(&acpi_device_lock); | 137 | spin_lock(&acpi_device_lock); |
147 | } | 138 | } |
148 | spin_unlock(&acpi_device_lock); | 139 | spin_unlock(&acpi_device_lock); |
@@ -160,48 +151,20 @@ static int __init acpi_wakeup_device_init(void) | |||
160 | struct acpi_device *dev = container_of(node, | 151 | struct acpi_device *dev = container_of(node, |
161 | struct acpi_device, | 152 | struct acpi_device, |
162 | wakeup_list); | 153 | wakeup_list); |
163 | |||
164 | /* In case user doesn't load button driver */ | 154 | /* In case user doesn't load button driver */ |
165 | if (dev->wakeup.flags.run_wake && !dev->wakeup.state.enabled) { | 155 | if (!dev->wakeup.flags.run_wake || dev->wakeup.state.enabled) |
166 | spin_unlock(&acpi_device_lock); | 156 | continue; |
167 | acpi_set_gpe_type(dev->wakeup.gpe_device, | 157 | spin_unlock(&acpi_device_lock); |
168 | dev->wakeup.gpe_number, | 158 | acpi_set_gpe_type(dev->wakeup.gpe_device, |
169 | ACPI_GPE_TYPE_WAKE_RUN); | 159 | dev->wakeup.gpe_number, |
170 | acpi_enable_gpe(dev->wakeup.gpe_device, | 160 | ACPI_GPE_TYPE_WAKE_RUN); |
171 | dev->wakeup.gpe_number, ACPI_NOT_ISR); | 161 | acpi_enable_gpe(dev->wakeup.gpe_device, |
172 | dev->wakeup.state.enabled = 1; | 162 | dev->wakeup.gpe_number, ACPI_NOT_ISR); |
173 | spin_lock(&acpi_device_lock); | 163 | dev->wakeup.state.enabled = 1; |
174 | } | 164 | spin_lock(&acpi_device_lock); |
175 | } | 165 | } |
176 | spin_unlock(&acpi_device_lock); | 166 | spin_unlock(&acpi_device_lock); |
177 | |||
178 | return 0; | 167 | return 0; |
179 | } | 168 | } |
180 | 169 | ||
181 | late_initcall(acpi_wakeup_device_init); | 170 | late_initcall(acpi_wakeup_device_init); |
182 | |||
183 | /* | ||
184 | * Disable all wakeup GPEs before entering requested sleep state. | ||
185 | * @sleep_state: ACPI state | ||
186 | * Since acpi_enter_sleep_state() will disable all | ||
187 | * RUNTIME GPEs, we simply mark all GPES that | ||
188 | * are not enabled for wakeup from requested state as RUNTIME. | ||
189 | */ | ||
190 | void acpi_gpe_sleep_prepare(u32 sleep_state) | ||
191 | { | ||
192 | struct list_head *node, *next; | ||
193 | |||
194 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { | ||
195 | struct acpi_device *dev = container_of(node, | ||
196 | struct acpi_device, | ||
197 | wakeup_list); | ||
198 | |||
199 | /* The GPE can wakeup system from this state, don't touch it */ | ||
200 | if ((u32) dev->wakeup.sleep_state >= sleep_state) | ||
201 | continue; | ||
202 | /* acpi_set_gpe_type will automatically disable GPE */ | ||
203 | acpi_set_gpe_type(dev->wakeup.gpe_device, | ||
204 | dev->wakeup.gpe_number, | ||
205 | ACPI_GPE_TYPE_RUNTIME); | ||
206 | } | ||
207 | } | ||
diff --git a/drivers/acpi/tables/tbutils.c b/drivers/acpi/tables/tbutils.c index 8cc9492ffbf2..5f1d85f2ffe4 100644 --- a/drivers/acpi/tables/tbutils.c +++ b/drivers/acpi/tables/tbutils.c | |||
@@ -400,7 +400,7 @@ acpi_tb_parse_root_table(acpi_physical_address rsdp_address, u8 flags) | |||
400 | u32 table_count; | 400 | u32 table_count; |
401 | struct acpi_table_header *table; | 401 | struct acpi_table_header *table; |
402 | acpi_physical_address address; | 402 | acpi_physical_address address; |
403 | acpi_physical_address rsdt_address; | 403 | acpi_physical_address uninitialized_var(rsdt_address); |
404 | u32 length; | 404 | u32 length; |
405 | u8 *table_entry; | 405 | u8 *table_entry; |
406 | acpi_status status; | 406 | acpi_status status; |
diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index bc6d5866ef98..5f79b4451212 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c | |||
@@ -195,6 +195,7 @@ struct acpi_thermal { | |||
195 | struct acpi_thermal_trips trips; | 195 | struct acpi_thermal_trips trips; |
196 | struct acpi_handle_list devices; | 196 | struct acpi_handle_list devices; |
197 | struct timer_list timer; | 197 | struct timer_list timer; |
198 | struct mutex lock; | ||
198 | }; | 199 | }; |
199 | 200 | ||
200 | static const struct file_operations acpi_thermal_state_fops = { | 201 | static const struct file_operations acpi_thermal_state_fops = { |
@@ -711,6 +712,7 @@ static void acpi_thermal_check(void *data) | |||
711 | int result = 0; | 712 | int result = 0; |
712 | struct acpi_thermal *tz = data; | 713 | struct acpi_thermal *tz = data; |
713 | unsigned long sleep_time = 0; | 714 | unsigned long sleep_time = 0; |
715 | unsigned long timeout_jiffies = 0; | ||
714 | int i = 0; | 716 | int i = 0; |
715 | struct acpi_thermal_state state; | 717 | struct acpi_thermal_state state; |
716 | 718 | ||
@@ -720,11 +722,15 @@ static void acpi_thermal_check(void *data) | |||
720 | return; | 722 | return; |
721 | } | 723 | } |
722 | 724 | ||
725 | /* Check if someone else is already running */ | ||
726 | if (!mutex_trylock(&tz->lock)) | ||
727 | return; | ||
728 | |||
723 | state = tz->state; | 729 | state = tz->state; |
724 | 730 | ||
725 | result = acpi_thermal_get_temperature(tz); | 731 | result = acpi_thermal_get_temperature(tz); |
726 | if (result) | 732 | if (result) |
727 | return; | 733 | goto unlock; |
728 | 734 | ||
729 | memset(&tz->state, 0, sizeof(tz->state)); | 735 | memset(&tz->state, 0, sizeof(tz->state)); |
730 | 736 | ||
@@ -787,10 +793,13 @@ static void acpi_thermal_check(void *data) | |||
787 | * a thermal event occurs). Note that _TSP and _TZD values are | 793 | * a thermal event occurs). Note that _TSP and _TZD values are |
788 | * given in 1/10th seconds (we must covert to milliseconds). | 794 | * given in 1/10th seconds (we must covert to milliseconds). |
789 | */ | 795 | */ |
790 | if (tz->state.passive) | 796 | if (tz->state.passive) { |
791 | sleep_time = tz->trips.passive.tsp * 100; | 797 | sleep_time = tz->trips.passive.tsp * 100; |
792 | else if (tz->polling_frequency > 0) | 798 | timeout_jiffies = jiffies + (HZ * sleep_time) / 1000; |
799 | } else if (tz->polling_frequency > 0) { | ||
793 | sleep_time = tz->polling_frequency * 100; | 800 | sleep_time = tz->polling_frequency * 100; |
801 | timeout_jiffies = round_jiffies(jiffies + (HZ * sleep_time) / 1000); | ||
802 | } | ||
794 | 803 | ||
795 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s: temperature[%lu] sleep[%lu]\n", | 804 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s: temperature[%lu] sleep[%lu]\n", |
796 | tz->name, tz->temperature, sleep_time)); | 805 | tz->name, tz->temperature, sleep_time)); |
@@ -804,17 +813,16 @@ static void acpi_thermal_check(void *data) | |||
804 | del_timer(&(tz->timer)); | 813 | del_timer(&(tz->timer)); |
805 | } else { | 814 | } else { |
806 | if (timer_pending(&(tz->timer))) | 815 | if (timer_pending(&(tz->timer))) |
807 | mod_timer(&(tz->timer), | 816 | mod_timer(&(tz->timer), timeout_jiffies); |
808 | jiffies + (HZ * sleep_time) / 1000); | ||
809 | else { | 817 | else { |
810 | tz->timer.data = (unsigned long)tz; | 818 | tz->timer.data = (unsigned long)tz; |
811 | tz->timer.function = acpi_thermal_run; | 819 | tz->timer.function = acpi_thermal_run; |
812 | tz->timer.expires = jiffies + (HZ * sleep_time) / 1000; | 820 | tz->timer.expires = timeout_jiffies; |
813 | add_timer(&(tz->timer)); | 821 | add_timer(&(tz->timer)); |
814 | } | 822 | } |
815 | } | 823 | } |
816 | 824 | unlock: | |
817 | return; | 825 | mutex_unlock(&tz->lock); |
818 | } | 826 | } |
819 | 827 | ||
820 | /* -------------------------------------------------------------------------- | 828 | /* -------------------------------------------------------------------------- |
@@ -1251,7 +1259,7 @@ static int acpi_thermal_add(struct acpi_device *device) | |||
1251 | strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME); | 1259 | strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME); |
1252 | strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS); | 1260 | strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS); |
1253 | acpi_driver_data(device) = tz; | 1261 | acpi_driver_data(device) = tz; |
1254 | 1262 | mutex_init(&tz->lock); | |
1255 | result = acpi_thermal_get_info(tz); | 1263 | result = acpi_thermal_get_info(tz); |
1256 | if (result) | 1264 | if (result) |
1257 | goto end; | 1265 | goto end; |
@@ -1321,7 +1329,7 @@ static int acpi_thermal_remove(struct acpi_device *device, int type) | |||
1321 | } | 1329 | } |
1322 | 1330 | ||
1323 | acpi_thermal_remove_fs(device); | 1331 | acpi_thermal_remove_fs(device); |
1324 | 1332 | mutex_destroy(&tz->lock); | |
1325 | kfree(tz); | 1333 | kfree(tz); |
1326 | return 0; | 1334 | return 0; |
1327 | } | 1335 | } |
@@ -1360,7 +1368,7 @@ static int acpi_thermal_resume(struct acpi_device *device) | |||
1360 | } | 1368 | } |
1361 | 1369 | ||
1362 | #ifdef CONFIG_DMI | 1370 | #ifdef CONFIG_DMI |
1363 | static int thermal_act(struct dmi_system_id *d) { | 1371 | static int thermal_act(const struct dmi_system_id *d) { |
1364 | 1372 | ||
1365 | if (act == 0) { | 1373 | if (act == 0) { |
1366 | printk(KERN_NOTICE "ACPI: %s detected: " | 1374 | printk(KERN_NOTICE "ACPI: %s detected: " |
@@ -1369,14 +1377,14 @@ static int thermal_act(struct dmi_system_id *d) { | |||
1369 | } | 1377 | } |
1370 | return 0; | 1378 | return 0; |
1371 | } | 1379 | } |
1372 | static int thermal_nocrt(struct dmi_system_id *d) { | 1380 | static int thermal_nocrt(const struct dmi_system_id *d) { |
1373 | 1381 | ||
1374 | printk(KERN_NOTICE "ACPI: %s detected: " | 1382 | printk(KERN_NOTICE "ACPI: %s detected: " |
1375 | "disabling all critical thermal trip point actions.\n", d->ident); | 1383 | "disabling all critical thermal trip point actions.\n", d->ident); |
1376 | nocrt = 1; | 1384 | nocrt = 1; |
1377 | return 0; | 1385 | return 0; |
1378 | } | 1386 | } |
1379 | static int thermal_tzp(struct dmi_system_id *d) { | 1387 | static int thermal_tzp(const struct dmi_system_id *d) { |
1380 | 1388 | ||
1381 | if (tzp == 0) { | 1389 | if (tzp == 0) { |
1382 | printk(KERN_NOTICE "ACPI: %s detected: " | 1390 | printk(KERN_NOTICE "ACPI: %s detected: " |
@@ -1385,7 +1393,7 @@ static int thermal_tzp(struct dmi_system_id *d) { | |||
1385 | } | 1393 | } |
1386 | return 0; | 1394 | return 0; |
1387 | } | 1395 | } |
1388 | static int thermal_psv(struct dmi_system_id *d) { | 1396 | static int thermal_psv(const struct dmi_system_id *d) { |
1389 | 1397 | ||
1390 | if (psv == 0) { | 1398 | if (psv == 0) { |
1391 | printk(KERN_NOTICE "ACPI: %s detected: " | 1399 | printk(KERN_NOTICE "ACPI: %s detected: " |
diff --git a/drivers/acpi/toshiba_acpi.c b/drivers/acpi/toshiba_acpi.c index 13369b45563f..9e8c20c6a0b7 100644 --- a/drivers/acpi/toshiba_acpi.c +++ b/drivers/acpi/toshiba_acpi.c | |||
@@ -362,7 +362,7 @@ static unsigned long write_video(const char *buffer, unsigned long count) | |||
362 | int crt_out = -1; | 362 | int crt_out = -1; |
363 | int tv_out = -1; | 363 | int tv_out = -1; |
364 | u32 hci_result; | 364 | u32 hci_result; |
365 | int video_out; | 365 | u32 video_out; |
366 | 366 | ||
367 | /* scan expression. Multiple expressions may be delimited with ; | 367 | /* scan expression. Multiple expressions may be delimited with ; |
368 | * | 368 | * |
@@ -591,9 +591,12 @@ static int __init toshiba_acpi_init(void) | |||
591 | NULL, | 591 | NULL, |
592 | &toshiba_backlight_data); | 592 | &toshiba_backlight_data); |
593 | if (IS_ERR(toshiba_backlight_device)) { | 593 | if (IS_ERR(toshiba_backlight_device)) { |
594 | int ret = PTR_ERR(toshiba_backlight_device); | ||
595 | |||
594 | printk(KERN_ERR "Could not register toshiba backlight device\n"); | 596 | printk(KERN_ERR "Could not register toshiba backlight device\n"); |
595 | toshiba_backlight_device = NULL; | 597 | toshiba_backlight_device = NULL; |
596 | toshiba_acpi_exit(); | 598 | toshiba_acpi_exit(); |
599 | return ret; | ||
597 | } | 600 | } |
598 | toshiba_backlight_device->props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1; | 601 | toshiba_backlight_device->props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1; |
599 | 602 | ||
diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c index d05891f16282..bac956b30c57 100644 --- a/drivers/acpi/video.c +++ b/drivers/acpi/video.c | |||
@@ -316,7 +316,7 @@ static int acpi_video_output_get(struct output_device *od) | |||
316 | { | 316 | { |
317 | unsigned long state; | 317 | unsigned long state; |
318 | struct acpi_video_device *vd = | 318 | struct acpi_video_device *vd = |
319 | (struct acpi_video_device *)class_get_devdata(&od->class_dev); | 319 | (struct acpi_video_device *)dev_get_drvdata(&od->dev); |
320 | acpi_video_device_get_state(vd, &state); | 320 | acpi_video_device_get_state(vd, &state); |
321 | return (int)state; | 321 | return (int)state; |
322 | } | 322 | } |
@@ -325,7 +325,7 @@ static int acpi_video_output_set(struct output_device *od) | |||
325 | { | 325 | { |
326 | unsigned long state = od->request_state; | 326 | unsigned long state = od->request_state; |
327 | struct acpi_video_device *vd= | 327 | struct acpi_video_device *vd= |
328 | (struct acpi_video_device *)class_get_devdata(&od->class_dev); | 328 | (struct acpi_video_device *)dev_get_drvdata(&od->dev); |
329 | return acpi_video_device_set_state(vd, state); | 329 | return acpi_video_device_set_state(vd, state); |
330 | } | 330 | } |
331 | 331 | ||
@@ -409,14 +409,17 @@ acpi_video_device_lcd_query_levels(struct acpi_video_device *device, | |||
409 | static int | 409 | static int |
410 | acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level) | 410 | acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level) |
411 | { | 411 | { |
412 | int status; | 412 | int status = AE_OK; |
413 | union acpi_object arg0 = { ACPI_TYPE_INTEGER }; | 413 | union acpi_object arg0 = { ACPI_TYPE_INTEGER }; |
414 | struct acpi_object_list args = { 1, &arg0 }; | 414 | struct acpi_object_list args = { 1, &arg0 }; |
415 | 415 | ||
416 | 416 | ||
417 | arg0.integer.value = level; | 417 | arg0.integer.value = level; |
418 | status = acpi_evaluate_object(device->dev->handle, "_BCM", &args, NULL); | ||
419 | 418 | ||
419 | if (device->cap._BCM) | ||
420 | status = acpi_evaluate_object(device->dev->handle, "_BCM", | ||
421 | &args, NULL); | ||
422 | device->brightness->curr = level; | ||
420 | return status; | 423 | return status; |
421 | } | 424 | } |
422 | 425 | ||
@@ -424,11 +427,11 @@ static int | |||
424 | acpi_video_device_lcd_get_level_current(struct acpi_video_device *device, | 427 | acpi_video_device_lcd_get_level_current(struct acpi_video_device *device, |
425 | unsigned long *level) | 428 | unsigned long *level) |
426 | { | 429 | { |
427 | int status; | 430 | if (device->cap._BQC) |
428 | 431 | return acpi_evaluate_integer(device->dev->handle, "_BQC", NULL, | |
429 | status = acpi_evaluate_integer(device->dev->handle, "_BQC", NULL, level); | 432 | level); |
430 | 433 | *level = device->brightness->curr; | |
431 | return status; | 434 | return AE_OK; |
432 | } | 435 | } |
433 | 436 | ||
434 | static int | 437 | static int |
@@ -1633,9 +1636,20 @@ static int | |||
1633 | acpi_video_get_next_level(struct acpi_video_device *device, | 1636 | acpi_video_get_next_level(struct acpi_video_device *device, |
1634 | u32 level_current, u32 event) | 1637 | u32 level_current, u32 event) |
1635 | { | 1638 | { |
1636 | int min, max, min_above, max_below, i, l; | 1639 | int min, max, min_above, max_below, i, l, delta = 255; |
1637 | max = max_below = 0; | 1640 | max = max_below = 0; |
1638 | min = min_above = 255; | 1641 | min = min_above = 255; |
1642 | /* Find closest level to level_current */ | ||
1643 | for (i = 0; i < device->brightness->count; i++) { | ||
1644 | l = device->brightness->levels[i]; | ||
1645 | if (abs(l - level_current) < abs(delta)) { | ||
1646 | delta = l - level_current; | ||
1647 | if (!delta) | ||
1648 | break; | ||
1649 | } | ||
1650 | } | ||
1651 | /* Ajust level_current to closest available level */ | ||
1652 | level_current += delta; | ||
1639 | for (i = 0; i < device->brightness->count; i++) { | 1653 | for (i = 0; i < device->brightness->count; i++) { |
1640 | l = device->brightness->levels[i]; | 1654 | l = device->brightness->levels[i]; |
1641 | if (l < min) | 1655 | if (l < min) |