diff options
Diffstat (limited to 'drivers/acpi')
-rw-r--r-- | drivers/acpi/Kconfig | 44 | ||||
-rw-r--r-- | drivers/acpi/Makefile | 10 | ||||
-rw-r--r-- | drivers/acpi/acpi_memhotplug.c | 13 | ||||
-rw-r--r-- | drivers/acpi/bus.c | 4 | ||||
-rw-r--r-- | drivers/acpi/container.c | 6 | ||||
-rw-r--r-- | drivers/acpi/dock.c | 25 | ||||
-rw-r--r-- | drivers/acpi/ec.c | 495 | ||||
-rw-r--r-- | drivers/acpi/i2c_ec.c | 403 | ||||
-rw-r--r-- | drivers/acpi/i2c_ec.h | 23 | ||||
-rw-r--r-- | drivers/acpi/ibm_acpi.c | 2798 | ||||
-rw-r--r-- | drivers/acpi/processor_core.c | 4 | ||||
-rw-r--r-- | drivers/acpi/processor_idle.c | 8 | ||||
-rw-r--r-- | drivers/acpi/sbs.c | 1291 | ||||
-rw-r--r-- | drivers/acpi/scan.c | 4 | ||||
-rw-r--r-- | drivers/acpi/sleep/proc.c | 16 | ||||
-rw-r--r-- | drivers/acpi/tables/tbfadt.c | 12 |
16 files changed, 928 insertions, 4228 deletions
diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig index e2ce4a9c1c92..139f41f033d8 100644 --- a/drivers/acpi/Kconfig +++ b/drivers/acpi/Kconfig | |||
@@ -85,8 +85,8 @@ config ACPI_PROCFS | |||
85 | depends on ACPI | 85 | depends on ACPI |
86 | default y | 86 | default y |
87 | ---help--- | 87 | ---help--- |
88 | Procfs interface for ACPI is made optional for back-compatible. | 88 | The Procfs interface for ACPI is made optional for backward compatibility. |
89 | As the same functions are duplicated in sysfs interface | 89 | As the same functions are duplicated in the sysfs interface |
90 | and this proc interface will be removed some time later, | 90 | and this proc interface will be removed some time later, |
91 | it's marked as deprecated. | 91 | it's marked as deprecated. |
92 | ( /proc/acpi/debug_layer && debug_level are deprecated by | 92 | ( /proc/acpi/debug_layer && debug_level are deprecated by |
@@ -218,43 +218,6 @@ config ACPI_ASUS | |||
218 | NOTE: This driver is deprecated and will probably be removed soon, | 218 | NOTE: This driver is deprecated and will probably be removed soon, |
219 | use asus-laptop instead. | 219 | use asus-laptop instead. |
220 | 220 | ||
221 | config ACPI_IBM | ||
222 | tristate "IBM ThinkPad Laptop Extras" | ||
223 | depends on X86 | ||
224 | select BACKLIGHT_CLASS_DEVICE | ||
225 | ---help--- | ||
226 | This is a Linux ACPI driver for the IBM ThinkPad laptops. It adds | ||
227 | support for Fn-Fx key combinations, Bluetooth control, video | ||
228 | output switching, ThinkLight control, UltraBay eject and more. | ||
229 | For more information about this driver see <file:Documentation/ibm-acpi.txt> | ||
230 | and <http://ibm-acpi.sf.net/> . | ||
231 | |||
232 | If you have an IBM ThinkPad laptop, say Y or M here. | ||
233 | |||
234 | config ACPI_IBM_DOCK | ||
235 | bool "Legacy Docking Station Support" | ||
236 | depends on ACPI_IBM | ||
237 | depends on ACPI_DOCK=n | ||
238 | default n | ||
239 | ---help--- | ||
240 | Allows the ibm_acpi driver to handle docking station events. | ||
241 | This support is obsoleted by CONFIG_HOTPLUG_PCI_ACPI. It will | ||
242 | allow locking and removing the laptop from the docking station, | ||
243 | but will not properly connect PCI devices. | ||
244 | |||
245 | If you are not sure, say N here. | ||
246 | |||
247 | config ACPI_IBM_BAY | ||
248 | bool "Legacy Removable Bay Support" | ||
249 | depends on ACPI_IBM | ||
250 | default y | ||
251 | ---help--- | ||
252 | Allows the ibm_acpi driver to handle removable bays. It will allow | ||
253 | disabling the device in the bay, and also generate notifications when | ||
254 | the bay lever is ejected or inserted. | ||
255 | |||
256 | If you are not sure, say Y here. | ||
257 | |||
258 | config ACPI_TOSHIBA | 221 | config ACPI_TOSHIBA |
259 | tristate "Toshiba Laptop Extras" | 222 | tristate "Toshiba Laptop Extras" |
260 | depends on X86 | 223 | depends on X86 |
@@ -388,11 +351,10 @@ config ACPI_HOTPLUG_MEMORY | |||
388 | 351 | ||
389 | config ACPI_SBS | 352 | config ACPI_SBS |
390 | tristate "Smart Battery System (EXPERIMENTAL)" | 353 | tristate "Smart Battery System (EXPERIMENTAL)" |
391 | depends on X86 && I2C | 354 | depends on X86 |
392 | depends on EXPERIMENTAL | 355 | depends on EXPERIMENTAL |
393 | help | 356 | help |
394 | This driver adds support for the Smart Battery System. | 357 | This driver adds support for the Smart Battery System. |
395 | Depends on I2C (Device Drivers ---> I2C support) | ||
396 | A "Smart Battery" is quite old and quite rare compared | 358 | A "Smart Battery" is quite old and quite rare compared |
397 | to today's ACPI "Control Method" battery. | 359 | to today's ACPI "Control Method" battery. |
398 | 360 | ||
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile index 5956e9f64a8b..d4336f1730e9 100644 --- a/drivers/acpi/Makefile +++ b/drivers/acpi/Makefile | |||
@@ -1,6 +1,6 @@ | |||
1 | # | 1 | # |
2 | # Makefile for the Linux ACPI interpreter | 2 | # Makefile for the Linux ACPI interpreter |
3 | # | 3 | # |
4 | 4 | ||
5 | export ACPI_CFLAGS | 5 | export ACPI_CFLAGS |
6 | 6 | ||
@@ -32,16 +32,17 @@ obj-y += osl.o utils.o \ | |||
32 | processor-objs += processor_core.o processor_throttling.o \ | 32 | processor-objs += processor_core.o processor_throttling.o \ |
33 | processor_idle.o processor_thermal.o | 33 | processor_idle.o processor_thermal.o |
34 | ifdef CONFIG_CPU_FREQ | 34 | ifdef CONFIG_CPU_FREQ |
35 | processor-objs += processor_perflib.o | 35 | processor-objs += processor_perflib.o |
36 | endif | 36 | endif |
37 | 37 | ||
38 | obj-y += sleep/ | 38 | obj-y += sleep/ |
39 | obj-y += bus.o glue.o | 39 | obj-y += bus.o glue.o |
40 | obj-y += scan.o | 40 | obj-y += scan.o |
41 | # Keep EC driver first. Initialization of others depend on it. | ||
42 | obj-$(CONFIG_ACPI_EC) += ec.o | ||
41 | obj-$(CONFIG_ACPI_AC) += ac.o | 43 | obj-$(CONFIG_ACPI_AC) += ac.o |
42 | obj-$(CONFIG_ACPI_BATTERY) += battery.o | 44 | obj-$(CONFIG_ACPI_BATTERY) += battery.o |
43 | obj-$(CONFIG_ACPI_BUTTON) += button.o | 45 | obj-$(CONFIG_ACPI_BUTTON) += button.o |
44 | obj-$(CONFIG_ACPI_EC) += ec.o | ||
45 | obj-$(CONFIG_ACPI_FAN) += fan.o | 46 | obj-$(CONFIG_ACPI_FAN) += fan.o |
46 | obj-$(CONFIG_ACPI_DOCK) += dock.o | 47 | obj-$(CONFIG_ACPI_DOCK) += dock.o |
47 | obj-$(CONFIG_ACPI_BAY) += bay.o | 48 | obj-$(CONFIG_ACPI_BAY) += bay.o |
@@ -55,8 +56,7 @@ obj-$(CONFIG_ACPI_SYSTEM) += system.o event.o | |||
55 | obj-$(CONFIG_ACPI_DEBUG) += debug.o | 56 | obj-$(CONFIG_ACPI_DEBUG) += debug.o |
56 | obj-$(CONFIG_ACPI_NUMA) += numa.o | 57 | obj-$(CONFIG_ACPI_NUMA) += numa.o |
57 | obj-$(CONFIG_ACPI_ASUS) += asus_acpi.o | 58 | obj-$(CONFIG_ACPI_ASUS) += asus_acpi.o |
58 | obj-$(CONFIG_ACPI_IBM) += ibm_acpi.o | ||
59 | obj-$(CONFIG_ACPI_TOSHIBA) += toshiba_acpi.o | 59 | 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) += i2c_ec.o sbs.o | 62 | obj-$(CONFIG_ACPI_SBS) += sbs.o |
diff --git a/drivers/acpi/acpi_memhotplug.c b/drivers/acpi/acpi_memhotplug.c index c26172671fd8..e65628a03085 100644 --- a/drivers/acpi/acpi_memhotplug.c +++ b/drivers/acpi/acpi_memhotplug.c | |||
@@ -44,11 +44,6 @@ MODULE_AUTHOR("Naveen B S <naveen.b.s@intel.com>"); | |||
44 | MODULE_DESCRIPTION("Hotplug Mem Driver"); | 44 | MODULE_DESCRIPTION("Hotplug Mem Driver"); |
45 | MODULE_LICENSE("GPL"); | 45 | MODULE_LICENSE("GPL"); |
46 | 46 | ||
47 | /* ACPI _STA method values */ | ||
48 | #define ACPI_MEMORY_STA_PRESENT (0x00000001UL) | ||
49 | #define ACPI_MEMORY_STA_ENABLED (0x00000002UL) | ||
50 | #define ACPI_MEMORY_STA_FUNCTIONAL (0x00000008UL) | ||
51 | |||
52 | /* Memory Device States */ | 47 | /* Memory Device States */ |
53 | #define MEMORY_INVALID_STATE 0 | 48 | #define MEMORY_INVALID_STATE 0 |
54 | #define MEMORY_POWER_ON_STATE 1 | 49 | #define MEMORY_POWER_ON_STATE 1 |
@@ -204,9 +199,9 @@ static int acpi_memory_check_device(struct acpi_memory_device *mem_device) | |||
204 | * Check for device status. Device should be | 199 | * Check for device status. Device should be |
205 | * present/enabled/functioning. | 200 | * present/enabled/functioning. |
206 | */ | 201 | */ |
207 | if (!((current_status & ACPI_MEMORY_STA_PRESENT) | 202 | if (!((current_status & ACPI_STA_DEVICE_PRESENT) |
208 | && (current_status & ACPI_MEMORY_STA_ENABLED) | 203 | && (current_status & ACPI_STA_DEVICE_ENABLED) |
209 | && (current_status & ACPI_MEMORY_STA_FUNCTIONAL))) | 204 | && (current_status & ACPI_STA_DEVICE_FUNCTIONING))) |
210 | return -ENODEV; | 205 | return -ENODEV; |
211 | 206 | ||
212 | return 0; | 207 | return 0; |
@@ -286,7 +281,7 @@ static int acpi_memory_powerdown_device(struct acpi_memory_device *mem_device) | |||
286 | return -ENODEV; | 281 | return -ENODEV; |
287 | 282 | ||
288 | /* Check for device status. Device should be disabled */ | 283 | /* Check for device status. Device should be disabled */ |
289 | if (current_status & ACPI_MEMORY_STA_ENABLED) | 284 | if (current_status & ACPI_STA_DEVICE_ENABLED) |
290 | return -EINVAL; | 285 | return -EINVAL; |
291 | 286 | ||
292 | return 0; | 287 | return 0; |
diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c index dd49ea0d0ed3..e5084ececb6f 100644 --- a/drivers/acpi/bus.c +++ b/drivers/acpi/bus.c | |||
@@ -103,7 +103,9 @@ int acpi_bus_get_status(struct acpi_device *device) | |||
103 | else if (device->parent) | 103 | else if (device->parent) |
104 | device->status = device->parent->status; | 104 | device->status = device->parent->status; |
105 | else | 105 | else |
106 | STRUCT_TO_INT(device->status) = 0x0F; | 106 | STRUCT_TO_INT(device->status) = |
107 | ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED | | ||
108 | ACPI_STA_DEVICE_UI | ACPI_STA_DEVICE_FUNCTIONING; | ||
107 | 109 | ||
108 | if (device->status.functional && !device->status.present) { | 110 | if (device->status.functional && !device->status.present) { |
109 | printk(KERN_WARNING PREFIX "Device [%s] status [%08x]: " | 111 | printk(KERN_WARNING PREFIX "Device [%s] status [%08x]: " |
diff --git a/drivers/acpi/container.c b/drivers/acpi/container.c index 0930d9413dfa..0dd3bf7c0ed1 100644 --- a/drivers/acpi/container.c +++ b/drivers/acpi/container.c | |||
@@ -49,8 +49,6 @@ MODULE_AUTHOR("Anil S Keshavamurthy"); | |||
49 | MODULE_DESCRIPTION("ACPI container driver"); | 49 | MODULE_DESCRIPTION("ACPI container driver"); |
50 | MODULE_LICENSE("GPL"); | 50 | MODULE_LICENSE("GPL"); |
51 | 51 | ||
52 | #define ACPI_STA_PRESENT (0x00000001) | ||
53 | |||
54 | static int acpi_container_add(struct acpi_device *device); | 52 | static int acpi_container_add(struct acpi_device *device); |
55 | static int acpi_container_remove(struct acpi_device *device, int type); | 53 | static int acpi_container_remove(struct acpi_device *device, int type); |
56 | 54 | ||
@@ -75,13 +73,13 @@ static int is_device_present(acpi_handle handle) | |||
75 | 73 | ||
76 | status = acpi_get_handle(handle, "_STA", &temp); | 74 | status = acpi_get_handle(handle, "_STA", &temp); |
77 | if (ACPI_FAILURE(status)) | 75 | if (ACPI_FAILURE(status)) |
78 | return 1; /* _STA not found, assmue device present */ | 76 | return 1; /* _STA not found, assume device present */ |
79 | 77 | ||
80 | status = acpi_evaluate_integer(handle, "_STA", NULL, &sta); | 78 | status = acpi_evaluate_integer(handle, "_STA", NULL, &sta); |
81 | if (ACPI_FAILURE(status)) | 79 | if (ACPI_FAILURE(status)) |
82 | return 0; /* Firmware error */ | 80 | return 0; /* Firmware error */ |
83 | 81 | ||
84 | return ((sta & ACPI_STA_PRESENT) == ACPI_STA_PRESENT); | 82 | return ((sta & ACPI_STA_DEVICE_PRESENT) == ACPI_STA_DEVICE_PRESENT); |
85 | } | 83 | } |
86 | 84 | ||
87 | /*******************************************************************/ | 85 | /*******************************************************************/ |
diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c index 54a697f9aa18..4546bf873aea 100644 --- a/drivers/acpi/dock.c +++ b/drivers/acpi/dock.c | |||
@@ -29,6 +29,7 @@ | |||
29 | #include <linux/notifier.h> | 29 | #include <linux/notifier.h> |
30 | #include <linux/platform_device.h> | 30 | #include <linux/platform_device.h> |
31 | #include <linux/jiffies.h> | 31 | #include <linux/jiffies.h> |
32 | #include <linux/stddef.h> | ||
32 | #include <acpi/acpi_bus.h> | 33 | #include <acpi/acpi_bus.h> |
33 | #include <acpi/acpi_drivers.h> | 34 | #include <acpi/acpi_drivers.h> |
34 | 35 | ||
@@ -667,6 +668,23 @@ static ssize_t write_undock(struct device *dev, struct device_attribute *attr, | |||
667 | } | 668 | } |
668 | DEVICE_ATTR(undock, S_IWUSR, NULL, write_undock); | 669 | DEVICE_ATTR(undock, S_IWUSR, NULL, write_undock); |
669 | 670 | ||
671 | /* | ||
672 | * show_dock_uid - read method for "uid" file in sysfs | ||
673 | */ | ||
674 | static ssize_t show_dock_uid(struct device *dev, | ||
675 | struct device_attribute *attr, char *buf) | ||
676 | { | ||
677 | unsigned long lbuf; | ||
678 | acpi_status status = acpi_evaluate_integer(dock_station->handle, "_UID", NULL, &lbuf); | ||
679 | if(ACPI_FAILURE(status)) { | ||
680 | return 0; | ||
681 | } | ||
682 | return snprintf(buf, PAGE_SIZE, "%lx\n", lbuf); | ||
683 | } | ||
684 | DEVICE_ATTR(uid, S_IRUGO, show_dock_uid, NULL); | ||
685 | |||
686 | |||
687 | |||
670 | /** | 688 | /** |
671 | * dock_add - add a new dock station | 689 | * dock_add - add a new dock station |
672 | * @handle: the dock station handle | 690 | * @handle: the dock station handle |
@@ -715,6 +733,13 @@ static int dock_add(acpi_handle handle) | |||
715 | kfree(dock_station); | 733 | kfree(dock_station); |
716 | return ret; | 734 | return ret; |
717 | } | 735 | } |
736 | ret = device_create_file(&dock_device.dev, &dev_attr_uid); | ||
737 | if (ret) { | ||
738 | printk("Error %d adding sysfs file\n", ret); | ||
739 | platform_device_unregister(&dock_device); | ||
740 | kfree(dock_station); | ||
741 | return ret; | ||
742 | } | ||
718 | 743 | ||
719 | /* Find dependent devices */ | 744 | /* Find dependent devices */ |
720 | acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, | 745 | acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, |
diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c index a802962ff2b4..e08cf98f504f 100644 --- a/drivers/acpi/ec.c +++ b/drivers/acpi/ec.c | |||
@@ -1,6 +1,8 @@ | |||
1 | /* | 1 | /* |
2 | * acpi_ec.c - ACPI Embedded Controller Driver ($Revision: 38 $) | 2 | * ec.c - ACPI Embedded Controller Driver (v2.0) |
3 | * | 3 | * |
4 | * Copyright (C) 2006, 2007 Alexey Starikovskiy <alexey.y.starikovskiy@intel.com> | ||
5 | * Copyright (C) 2006 Denis Sadykov <denis.m.sadykov@intel.com> | ||
4 | * Copyright (C) 2004 Luming Yu <luming.yu@intel.com> | 6 | * Copyright (C) 2004 Luming Yu <luming.yu@intel.com> |
5 | * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com> | 7 | * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com> |
6 | * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com> | 8 | * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com> |
@@ -91,9 +93,9 @@ static struct acpi_driver acpi_ec_driver = { | |||
91 | }; | 93 | }; |
92 | 94 | ||
93 | /* If we find an EC via the ECDT, we need to keep a ptr to its context */ | 95 | /* If we find an EC via the ECDT, we need to keep a ptr to its context */ |
96 | /* External interfaces use first EC only, so remember */ | ||
94 | static struct acpi_ec { | 97 | static struct acpi_ec { |
95 | acpi_handle handle; | 98 | acpi_handle handle; |
96 | unsigned long uid; | ||
97 | unsigned long gpe; | 99 | unsigned long gpe; |
98 | unsigned long command_addr; | 100 | unsigned long command_addr; |
99 | unsigned long data_addr; | 101 | unsigned long data_addr; |
@@ -101,12 +103,8 @@ static struct acpi_ec { | |||
101 | struct mutex lock; | 103 | struct mutex lock; |
102 | atomic_t query_pending; | 104 | atomic_t query_pending; |
103 | atomic_t event_count; | 105 | atomic_t event_count; |
104 | atomic_t leaving_burst; /* 0 : No, 1 : Yes, 2: abort */ | ||
105 | wait_queue_head_t wait; | 106 | wait_queue_head_t wait; |
106 | } *ec_ecdt; | 107 | } *boot_ec, *first_ec; |
107 | |||
108 | /* External interfaces use first EC only, so remember */ | ||
109 | static struct acpi_device *first_ec; | ||
110 | 108 | ||
111 | /* -------------------------------------------------------------------------- | 109 | /* -------------------------------------------------------------------------- |
112 | Transaction Management | 110 | Transaction Management |
@@ -173,56 +171,6 @@ static int acpi_ec_wait(struct acpi_ec *ec, enum ec_event event, unsigned count) | |||
173 | return -ETIME; | 171 | return -ETIME; |
174 | } | 172 | } |
175 | 173 | ||
176 | #ifdef ACPI_FUTURE_USAGE | ||
177 | /* | ||
178 | * Note: samsung nv5000 doesn't work with ec burst mode. | ||
179 | * http://bugzilla.kernel.org/show_bug.cgi?id=4980 | ||
180 | */ | ||
181 | int acpi_ec_enter_burst_mode(struct acpi_ec *ec) | ||
182 | { | ||
183 | u8 tmp = 0; | ||
184 | u8 status = 0; | ||
185 | |||
186 | status = acpi_ec_read_status(ec); | ||
187 | if (status != -EINVAL && !(status & ACPI_EC_FLAG_BURST)) { | ||
188 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0); | ||
189 | if (status) | ||
190 | goto end; | ||
191 | acpi_ec_write_cmd(ec, ACPI_EC_BURST_ENABLE); | ||
192 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF_1); | ||
193 | tmp = acpi_ec_read_data(ec); | ||
194 | if (tmp != 0x90) { /* Burst ACK byte */ | ||
195 | return -EINVAL; | ||
196 | } | ||
197 | } | ||
198 | |||
199 | atomic_set(&ec->leaving_burst, 0); | ||
200 | return 0; | ||
201 | end: | ||
202 | ACPI_EXCEPTION((AE_INFO, status, "EC wait, burst mode")); | ||
203 | return -1; | ||
204 | } | ||
205 | |||
206 | int acpi_ec_leave_burst_mode(struct acpi_ec *ec) | ||
207 | { | ||
208 | u8 status = 0; | ||
209 | |||
210 | status = acpi_ec_read_status(ec); | ||
211 | if (status != -EINVAL && (status & ACPI_EC_FLAG_BURST)) { | ||
212 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0); | ||
213 | if (status) | ||
214 | goto end; | ||
215 | acpi_ec_write_cmd(ec, ACPI_EC_BURST_DISABLE); | ||
216 | acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0); | ||
217 | } | ||
218 | atomic_set(&ec->leaving_burst, 1); | ||
219 | return 0; | ||
220 | end: | ||
221 | ACPI_EXCEPTION((AE_INFO, status, "EC leave burst mode")); | ||
222 | return -1; | ||
223 | } | ||
224 | #endif /* ACPI_FUTURE_USAGE */ | ||
225 | |||
226 | static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command, | 174 | static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command, |
227 | const u8 * wdata, unsigned wdata_len, | 175 | const u8 * wdata, unsigned wdata_len, |
228 | u8 * rdata, unsigned rdata_len) | 176 | u8 * rdata, unsigned rdata_len) |
@@ -312,6 +260,21 @@ static int acpi_ec_transaction(struct acpi_ec *ec, u8 command, | |||
312 | return status; | 260 | return status; |
313 | } | 261 | } |
314 | 262 | ||
263 | /* | ||
264 | * Note: samsung nv5000 doesn't work with ec burst mode. | ||
265 | * http://bugzilla.kernel.org/show_bug.cgi?id=4980 | ||
266 | */ | ||
267 | int acpi_ec_burst_enable(struct acpi_ec *ec) | ||
268 | { | ||
269 | u8 d; | ||
270 | return acpi_ec_transaction(ec, ACPI_EC_BURST_ENABLE, NULL, 0, &d, 1); | ||
271 | } | ||
272 | |||
273 | int acpi_ec_burst_disable(struct acpi_ec *ec) | ||
274 | { | ||
275 | return acpi_ec_transaction(ec, ACPI_EC_BURST_DISABLE, NULL, 0, NULL, 0); | ||
276 | } | ||
277 | |||
315 | static int acpi_ec_read(struct acpi_ec *ec, u8 address, u8 * data) | 278 | static int acpi_ec_read(struct acpi_ec *ec, u8 address, u8 * data) |
316 | { | 279 | { |
317 | int result; | 280 | int result; |
@@ -333,18 +296,33 @@ static int acpi_ec_write(struct acpi_ec *ec, u8 address, u8 data) | |||
333 | /* | 296 | /* |
334 | * Externally callable EC access functions. For now, assume 1 EC only | 297 | * Externally callable EC access functions. For now, assume 1 EC only |
335 | */ | 298 | */ |
299 | int ec_burst_enable(void) | ||
300 | { | ||
301 | if (!first_ec) | ||
302 | return -ENODEV; | ||
303 | return acpi_ec_burst_enable(first_ec); | ||
304 | } | ||
305 | |||
306 | EXPORT_SYMBOL(ec_burst_enable); | ||
307 | |||
308 | int ec_burst_disable(void) | ||
309 | { | ||
310 | if (!first_ec) | ||
311 | return -ENODEV; | ||
312 | return acpi_ec_burst_disable(first_ec); | ||
313 | } | ||
314 | |||
315 | EXPORT_SYMBOL(ec_burst_disable); | ||
316 | |||
336 | int ec_read(u8 addr, u8 * val) | 317 | int ec_read(u8 addr, u8 * val) |
337 | { | 318 | { |
338 | struct acpi_ec *ec; | ||
339 | int err; | 319 | int err; |
340 | u8 temp_data; | 320 | u8 temp_data; |
341 | 321 | ||
342 | if (!first_ec) | 322 | if (!first_ec) |
343 | return -ENODEV; | 323 | return -ENODEV; |
344 | 324 | ||
345 | ec = acpi_driver_data(first_ec); | 325 | err = acpi_ec_read(first_ec, addr, &temp_data); |
346 | |||
347 | err = acpi_ec_read(ec, addr, &temp_data); | ||
348 | 326 | ||
349 | if (!err) { | 327 | if (!err) { |
350 | *val = temp_data; | 328 | *val = temp_data; |
@@ -357,15 +335,12 @@ EXPORT_SYMBOL(ec_read); | |||
357 | 335 | ||
358 | int ec_write(u8 addr, u8 val) | 336 | int ec_write(u8 addr, u8 val) |
359 | { | 337 | { |
360 | struct acpi_ec *ec; | ||
361 | int err; | 338 | int err; |
362 | 339 | ||
363 | if (!first_ec) | 340 | if (!first_ec) |
364 | return -ENODEV; | 341 | return -ENODEV; |
365 | 342 | ||
366 | ec = acpi_driver_data(first_ec); | 343 | err = acpi_ec_write(first_ec, addr, val); |
367 | |||
368 | err = acpi_ec_write(ec, addr, val); | ||
369 | 344 | ||
370 | return err; | 345 | return err; |
371 | } | 346 | } |
@@ -376,14 +351,10 @@ int ec_transaction(u8 command, | |||
376 | const u8 * wdata, unsigned wdata_len, | 351 | const u8 * wdata, unsigned wdata_len, |
377 | u8 * rdata, unsigned rdata_len) | 352 | u8 * rdata, unsigned rdata_len) |
378 | { | 353 | { |
379 | struct acpi_ec *ec; | ||
380 | |||
381 | if (!first_ec) | 354 | if (!first_ec) |
382 | return -ENODEV; | 355 | return -ENODEV; |
383 | 356 | ||
384 | ec = acpi_driver_data(first_ec); | 357 | return acpi_ec_transaction(first_ec, command, wdata, |
385 | |||
386 | return acpi_ec_transaction(ec, command, wdata, | ||
387 | wdata_len, rdata, rdata_len); | 358 | wdata_len, rdata, rdata_len); |
388 | } | 359 | } |
389 | 360 | ||
@@ -420,7 +391,7 @@ static int acpi_ec_query(struct acpi_ec *ec, u8 * data) | |||
420 | 391 | ||
421 | static void acpi_ec_gpe_query(void *ec_cxt) | 392 | static void acpi_ec_gpe_query(void *ec_cxt) |
422 | { | 393 | { |
423 | struct acpi_ec *ec = (struct acpi_ec *)ec_cxt; | 394 | struct acpi_ec *ec = ec_cxt; |
424 | u8 value = 0; | 395 | u8 value = 0; |
425 | char object_name[8]; | 396 | char object_name[8]; |
426 | 397 | ||
@@ -438,8 +409,9 @@ static u32 acpi_ec_gpe_handler(void *data) | |||
438 | { | 409 | { |
439 | acpi_status status = AE_OK; | 410 | acpi_status status = AE_OK; |
440 | u8 value; | 411 | u8 value; |
441 | struct acpi_ec *ec = (struct acpi_ec *)data; | 412 | struct acpi_ec *ec = data; |
442 | atomic_inc(&ec->event_count); | 413 | atomic_inc(&ec->event_count); |
414 | |||
443 | if (acpi_ec_mode == EC_INTR) { | 415 | if (acpi_ec_mode == EC_INTR) { |
444 | wake_up(&ec->wait); | 416 | wake_up(&ec->wait); |
445 | } | 417 | } |
@@ -482,7 +454,7 @@ acpi_ec_space_handler(u32 function, | |||
482 | void *handler_context, void *region_context) | 454 | void *handler_context, void *region_context) |
483 | { | 455 | { |
484 | int result = 0; | 456 | int result = 0; |
485 | struct acpi_ec *ec = NULL; | 457 | struct acpi_ec *ec = handler_context; |
486 | u64 temp = *value; | 458 | u64 temp = *value; |
487 | acpi_integer f_v = 0; | 459 | acpi_integer f_v = 0; |
488 | int i = 0; | 460 | int i = 0; |
@@ -494,8 +466,6 @@ acpi_ec_space_handler(u32 function, | |||
494 | return AE_BAD_PARAMETER; | 466 | return AE_BAD_PARAMETER; |
495 | } | 467 | } |
496 | 468 | ||
497 | ec = (struct acpi_ec *)handler_context; | ||
498 | |||
499 | next_byte: | 469 | next_byte: |
500 | switch (function) { | 470 | switch (function) { |
501 | case ACPI_READ: | 471 | case ACPI_READ: |
@@ -551,18 +521,16 @@ static struct proc_dir_entry *acpi_ec_dir; | |||
551 | 521 | ||
552 | static int acpi_ec_read_info(struct seq_file *seq, void *offset) | 522 | static int acpi_ec_read_info(struct seq_file *seq, void *offset) |
553 | { | 523 | { |
554 | struct acpi_ec *ec = (struct acpi_ec *)seq->private; | 524 | struct acpi_ec *ec = seq->private; |
555 | 525 | ||
556 | if (!ec) | 526 | if (!ec) |
557 | goto end; | 527 | goto end; |
558 | 528 | ||
559 | seq_printf(seq, "gpe: 0x%02x\n", (u32) ec->gpe); | 529 | seq_printf(seq, "gpe:\t\t\t0x%02x\n", (u32) ec->gpe); |
560 | seq_printf(seq, "ports: 0x%02x, 0x%02x\n", | 530 | seq_printf(seq, "ports:\t\t\t0x%02x, 0x%02x\n", |
561 | (u32) ec->command_addr, (u32) ec->data_addr); | 531 | (unsigned)ec->command_addr, (unsigned)ec->data_addr); |
562 | seq_printf(seq, "use global lock: %s\n", | 532 | seq_printf(seq, "use global lock:\t%s\n", |
563 | ec->global_lock ? "yes" : "no"); | 533 | ec->global_lock ? "yes" : "no"); |
564 | acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR); | ||
565 | |||
566 | end: | 534 | end: |
567 | return 0; | 535 | return 0; |
568 | } | 536 | } |
@@ -619,154 +587,122 @@ static int acpi_ec_remove_fs(struct acpi_device *device) | |||
619 | /* -------------------------------------------------------------------------- | 587 | /* -------------------------------------------------------------------------- |
620 | Driver Interface | 588 | Driver Interface |
621 | -------------------------------------------------------------------------- */ | 589 | -------------------------------------------------------------------------- */ |
590 | static acpi_status | ||
591 | ec_parse_io_ports(struct acpi_resource *resource, void *context); | ||
592 | |||
593 | static acpi_status | ||
594 | ec_parse_device(acpi_handle handle, u32 Level, void *context, void **retval); | ||
595 | |||
596 | static struct acpi_ec *make_acpi_ec(void) | ||
597 | { | ||
598 | struct acpi_ec *ec = kzalloc(sizeof(struct acpi_ec), GFP_KERNEL); | ||
599 | if (!ec) | ||
600 | return NULL; | ||
601 | |||
602 | atomic_set(&ec->query_pending, 1); | ||
603 | atomic_set(&ec->event_count, 1); | ||
604 | mutex_init(&ec->lock); | ||
605 | init_waitqueue_head(&ec->wait); | ||
606 | |||
607 | return ec; | ||
608 | } | ||
622 | 609 | ||
623 | static int acpi_ec_add(struct acpi_device *device) | 610 | static int acpi_ec_add(struct acpi_device *device) |
624 | { | 611 | { |
625 | int result = 0; | ||
626 | acpi_status status = AE_OK; | 612 | acpi_status status = AE_OK; |
627 | struct acpi_ec *ec = NULL; | 613 | struct acpi_ec *ec = NULL; |
628 | 614 | ||
629 | if (!device) | 615 | if (!device) |
630 | return -EINVAL; | 616 | return -EINVAL; |
631 | 617 | ||
632 | ec = kzalloc(sizeof(struct acpi_ec), GFP_KERNEL); | ||
633 | if (!ec) | ||
634 | return -ENOMEM; | ||
635 | |||
636 | ec->handle = device->handle; | ||
637 | ec->uid = -1; | ||
638 | mutex_init(&ec->lock); | ||
639 | atomic_set(&ec->query_pending, 0); | ||
640 | atomic_set(&ec->event_count, 1); | ||
641 | if (acpi_ec_mode == EC_INTR) { | ||
642 | atomic_set(&ec->leaving_burst, 1); | ||
643 | init_waitqueue_head(&ec->wait); | ||
644 | } | ||
645 | strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME); | 618 | strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME); |
646 | strcpy(acpi_device_class(device), ACPI_EC_CLASS); | 619 | strcpy(acpi_device_class(device), ACPI_EC_CLASS); |
647 | acpi_driver_data(device) = ec; | ||
648 | |||
649 | /* Use the global lock for all EC transactions? */ | ||
650 | acpi_evaluate_integer(ec->handle, "_GLK", NULL, &ec->global_lock); | ||
651 | |||
652 | /* XXX we don't test uids, because on some boxes ecdt uid = 0, see: | ||
653 | http://bugzilla.kernel.org/show_bug.cgi?id=6111 */ | ||
654 | if (ec_ecdt) { | ||
655 | acpi_remove_address_space_handler(ACPI_ROOT_OBJECT, | ||
656 | ACPI_ADR_SPACE_EC, | ||
657 | &acpi_ec_space_handler); | ||
658 | 620 | ||
659 | acpi_remove_gpe_handler(NULL, ec_ecdt->gpe, | 621 | ec = make_acpi_ec(); |
660 | &acpi_ec_gpe_handler); | 622 | if (!ec) |
623 | return -ENOMEM; | ||
661 | 624 | ||
662 | kfree(ec_ecdt); | 625 | status = ec_parse_device(device->handle, 0, ec, NULL); |
626 | if (status != AE_CTRL_TERMINATE) { | ||
627 | kfree(ec); | ||
628 | return -EINVAL; | ||
663 | } | 629 | } |
664 | 630 | ||
665 | /* Get GPE bit assignment (EC events). */ | 631 | /* Check if we found the boot EC */ |
666 | /* TODO: Add support for _GPE returning a package */ | 632 | if (boot_ec) { |
667 | status = acpi_evaluate_integer(ec->handle, "_GPE", NULL, &ec->gpe); | 633 | if (boot_ec->gpe == ec->gpe) { |
668 | if (ACPI_FAILURE(status)) { | 634 | /* We might have incorrect info for GL at boot time */ |
669 | ACPI_EXCEPTION((AE_INFO, status, | 635 | mutex_lock(&boot_ec->lock); |
670 | "Obtaining GPE bit assignment")); | 636 | boot_ec->global_lock = ec->global_lock; |
671 | result = -ENODEV; | 637 | mutex_unlock(&boot_ec->lock); |
672 | goto end; | 638 | kfree(ec); |
673 | } | 639 | ec = boot_ec; |
640 | } | ||
641 | } else | ||
642 | first_ec = ec; | ||
643 | ec->handle = device->handle; | ||
644 | acpi_driver_data(device) = ec; | ||
674 | 645 | ||
675 | result = acpi_ec_add_fs(device); | 646 | acpi_ec_add_fs(device); |
676 | if (result) | ||
677 | goto end; | ||
678 | 647 | ||
679 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s [%s] (gpe %d) interrupt mode.", | 648 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s [%s] (gpe %d) interrupt mode.", |
680 | acpi_device_name(device), acpi_device_bid(device), | 649 | acpi_device_name(device), acpi_device_bid(device), |
681 | (u32) ec->gpe)); | 650 | (u32) ec->gpe)); |
682 | 651 | ||
683 | if (!first_ec) | 652 | return 0; |
684 | first_ec = device; | ||
685 | |||
686 | end: | ||
687 | if (result) | ||
688 | kfree(ec); | ||
689 | |||
690 | return result; | ||
691 | } | 653 | } |
692 | 654 | ||
693 | static int acpi_ec_remove(struct acpi_device *device, int type) | 655 | static int acpi_ec_remove(struct acpi_device *device, int type) |
694 | { | 656 | { |
695 | struct acpi_ec *ec = NULL; | 657 | struct acpi_ec *ec; |
696 | 658 | ||
697 | if (!device) | 659 | if (!device) |
698 | return -EINVAL; | 660 | return -EINVAL; |
699 | 661 | ||
700 | ec = acpi_driver_data(device); | 662 | ec = acpi_driver_data(device); |
701 | |||
702 | acpi_ec_remove_fs(device); | 663 | acpi_ec_remove_fs(device); |
664 | acpi_driver_data(device) = NULL; | ||
665 | if (ec == first_ec) | ||
666 | first_ec = NULL; | ||
703 | 667 | ||
704 | kfree(ec); | 668 | /* Don't touch boot EC */ |
705 | 669 | if (boot_ec != ec) | |
670 | kfree(ec); | ||
706 | return 0; | 671 | return 0; |
707 | } | 672 | } |
708 | 673 | ||
709 | static acpi_status | 674 | static acpi_status |
710 | acpi_ec_io_ports(struct acpi_resource *resource, void *context) | 675 | ec_parse_io_ports(struct acpi_resource *resource, void *context) |
711 | { | 676 | { |
712 | struct acpi_ec *ec = (struct acpi_ec *)context; | 677 | struct acpi_ec *ec = context; |
713 | 678 | ||
714 | if (resource->type != ACPI_RESOURCE_TYPE_IO) { | 679 | if (resource->type != ACPI_RESOURCE_TYPE_IO) |
715 | return AE_OK; | 680 | return AE_OK; |
716 | } | ||
717 | 681 | ||
718 | /* | 682 | /* |
719 | * The first address region returned is the data port, and | 683 | * The first address region returned is the data port, and |
720 | * the second address region returned is the status/command | 684 | * the second address region returned is the status/command |
721 | * port. | 685 | * port. |
722 | */ | 686 | */ |
723 | if (ec->data_addr == 0) { | 687 | if (ec->data_addr == 0) |
724 | ec->data_addr = resource->data.io.minimum; | 688 | ec->data_addr = resource->data.io.minimum; |
725 | } else if (ec->command_addr == 0) { | 689 | else if (ec->command_addr == 0) |
726 | ec->command_addr = resource->data.io.minimum; | 690 | ec->command_addr = resource->data.io.minimum; |
727 | } else { | 691 | else |
728 | return AE_CTRL_TERMINATE; | 692 | return AE_CTRL_TERMINATE; |
729 | } | ||
730 | 693 | ||
731 | return AE_OK; | 694 | return AE_OK; |
732 | } | 695 | } |
733 | 696 | ||
734 | static int acpi_ec_start(struct acpi_device *device) | 697 | static int ec_install_handlers(struct acpi_ec *ec) |
735 | { | 698 | { |
736 | acpi_status status = AE_OK; | 699 | acpi_status status; |
737 | struct acpi_ec *ec = NULL; | ||
738 | |||
739 | if (!device) | ||
740 | return -EINVAL; | ||
741 | |||
742 | ec = acpi_driver_data(device); | ||
743 | |||
744 | if (!ec) | ||
745 | return -EINVAL; | ||
746 | |||
747 | /* | ||
748 | * Get I/O port addresses. Convert to GAS format. | ||
749 | */ | ||
750 | status = acpi_walk_resources(ec->handle, METHOD_NAME__CRS, | ||
751 | acpi_ec_io_ports, ec); | ||
752 | if (ACPI_FAILURE(status) || ec->command_addr == 0) { | ||
753 | ACPI_EXCEPTION((AE_INFO, status, | ||
754 | "Error getting I/O port addresses")); | ||
755 | return -ENODEV; | ||
756 | } | ||
757 | |||
758 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "gpe=0x%02lx, ports=0x%2lx,0x%2lx", | ||
759 | ec->gpe, ec->command_addr, ec->data_addr)); | ||
760 | |||
761 | /* | ||
762 | * Install GPE handler | ||
763 | */ | ||
764 | status = acpi_install_gpe_handler(NULL, ec->gpe, | 700 | status = acpi_install_gpe_handler(NULL, ec->gpe, |
765 | ACPI_GPE_EDGE_TRIGGERED, | 701 | ACPI_GPE_EDGE_TRIGGERED, |
766 | &acpi_ec_gpe_handler, ec); | 702 | &acpi_ec_gpe_handler, ec); |
767 | if (ACPI_FAILURE(status)) { | 703 | if (ACPI_FAILURE(status)) |
768 | return -ENODEV; | 704 | return -ENODEV; |
769 | } | 705 | |
770 | acpi_set_gpe_type(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME); | 706 | acpi_set_gpe_type(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME); |
771 | acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR); | 707 | acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR); |
772 | 708 | ||
@@ -779,18 +715,49 @@ static int acpi_ec_start(struct acpi_device *device) | |||
779 | return -ENODEV; | 715 | return -ENODEV; |
780 | } | 716 | } |
781 | 717 | ||
782 | return AE_OK; | 718 | /* EC is fully operational, allow queries */ |
719 | atomic_set(&ec->query_pending, 0); | ||
720 | |||
721 | return 0; | ||
722 | } | ||
723 | |||
724 | static int acpi_ec_start(struct acpi_device *device) | ||
725 | { | ||
726 | struct acpi_ec *ec; | ||
727 | |||
728 | if (!device) | ||
729 | return -EINVAL; | ||
730 | |||
731 | ec = acpi_driver_data(device); | ||
732 | |||
733 | if (!ec) | ||
734 | return -EINVAL; | ||
735 | |||
736 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "gpe=0x%02lx, ports=0x%2lx,0x%2lx", | ||
737 | ec->gpe, ec->command_addr, ec->data_addr)); | ||
738 | |||
739 | /* Boot EC is already working */ | ||
740 | if (ec == boot_ec) | ||
741 | return 0; | ||
742 | |||
743 | return ec_install_handlers(ec); | ||
783 | } | 744 | } |
784 | 745 | ||
785 | static int acpi_ec_stop(struct acpi_device *device, int type) | 746 | static int acpi_ec_stop(struct acpi_device *device, int type) |
786 | { | 747 | { |
787 | acpi_status status = AE_OK; | 748 | acpi_status status; |
788 | struct acpi_ec *ec = NULL; | 749 | struct acpi_ec *ec; |
789 | 750 | ||
790 | if (!device) | 751 | if (!device) |
791 | return -EINVAL; | 752 | return -EINVAL; |
792 | 753 | ||
793 | ec = acpi_driver_data(device); | 754 | ec = acpi_driver_data(device); |
755 | if (!ec) | ||
756 | return -EINVAL; | ||
757 | |||
758 | /* Don't touch boot EC */ | ||
759 | if (ec == boot_ec) | ||
760 | return 0; | ||
794 | 761 | ||
795 | status = acpi_remove_address_space_handler(ec->handle, | 762 | status = acpi_remove_address_space_handler(ec->handle, |
796 | ACPI_ADR_SPACE_EC, | 763 | ACPI_ADR_SPACE_EC, |
@@ -805,164 +772,67 @@ static int acpi_ec_stop(struct acpi_device *device, int type) | |||
805 | return 0; | 772 | return 0; |
806 | } | 773 | } |
807 | 774 | ||
808 | static acpi_status __init | 775 | static acpi_status |
809 | acpi_fake_ecdt_callback(acpi_handle handle, | 776 | ec_parse_device(acpi_handle handle, u32 Level, void *context, void **retval) |
810 | u32 Level, void *context, void **retval) | ||
811 | { | 777 | { |
812 | acpi_status status; | 778 | acpi_status status; |
813 | 779 | ||
814 | mutex_init(&ec_ecdt->lock); | 780 | struct acpi_ec *ec = context; |
815 | atomic_set(&ec_ecdt->event_count, 1); | ||
816 | if (acpi_ec_mode == EC_INTR) { | ||
817 | init_waitqueue_head(&ec_ecdt->wait); | ||
818 | } | ||
819 | status = acpi_walk_resources(handle, METHOD_NAME__CRS, | 781 | status = acpi_walk_resources(handle, METHOD_NAME__CRS, |
820 | acpi_ec_io_ports, ec_ecdt); | 782 | ec_parse_io_ports, ec); |
821 | if (ACPI_FAILURE(status)) | 783 | if (ACPI_FAILURE(status)) |
822 | return status; | 784 | return status; |
823 | 785 | ||
824 | ec_ecdt->uid = -1; | 786 | /* Get GPE bit assignment (EC events). */ |
825 | acpi_evaluate_integer(handle, "_UID", NULL, &ec_ecdt->uid); | 787 | /* TODO: Add support for _GPE returning a package */ |
826 | 788 | status = acpi_evaluate_integer(handle, "_GPE", NULL, &ec->gpe); | |
827 | status = acpi_evaluate_integer(handle, "_GPE", NULL, &ec_ecdt->gpe); | ||
828 | if (ACPI_FAILURE(status)) | 789 | if (ACPI_FAILURE(status)) |
829 | return status; | 790 | return status; |
830 | ec_ecdt->global_lock = TRUE; | ||
831 | ec_ecdt->handle = handle; | ||
832 | |||
833 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "GPE=0x%02lx, ports=0x%2lx, 0x%2lx", | ||
834 | ec_ecdt->gpe, ec_ecdt->command_addr, | ||
835 | ec_ecdt->data_addr)); | ||
836 | 791 | ||
837 | return AE_CTRL_TERMINATE; | 792 | /* Use the global lock for all EC transactions? */ |
838 | } | 793 | acpi_evaluate_integer(handle, "_GLK", NULL, &ec->global_lock); |
839 | |||
840 | /* | ||
841 | * Some BIOS (such as some from Gateway laptops) access EC region very early | ||
842 | * such as in BAT0._INI or EC._INI before an EC device is found and | ||
843 | * do not provide an ECDT. According to ACPI spec, ECDT isn't mandatorily | ||
844 | * required, but if EC regison is accessed early, it is required. | ||
845 | * The routine tries to workaround the BIOS bug by pre-scan EC device | ||
846 | * It assumes that _CRS, _HID, _GPE, _UID methods of EC don't touch any | ||
847 | * op region (since _REG isn't invoked yet). The assumption is true for | ||
848 | * all systems found. | ||
849 | */ | ||
850 | static int __init acpi_ec_fake_ecdt(void) | ||
851 | { | ||
852 | acpi_status status; | ||
853 | int ret = 0; | ||
854 | 794 | ||
855 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Try to make an fake ECDT")); | 795 | ec->handle = handle; |
856 | 796 | ||
857 | ec_ecdt = kzalloc(sizeof(struct acpi_ec), GFP_KERNEL); | 797 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "GPE=0x%02lx, ports=0x%2lx, 0x%2lx", |
858 | if (!ec_ecdt) { | 798 | ec->gpe, ec->command_addr, ec->data_addr)); |
859 | ret = -ENOMEM; | ||
860 | goto error; | ||
861 | } | ||
862 | 799 | ||
863 | status = acpi_get_devices(ACPI_EC_HID, | 800 | return AE_CTRL_TERMINATE; |
864 | acpi_fake_ecdt_callback, NULL, NULL); | ||
865 | if (ACPI_FAILURE(status)) { | ||
866 | kfree(ec_ecdt); | ||
867 | ec_ecdt = NULL; | ||
868 | ret = -ENODEV; | ||
869 | ACPI_EXCEPTION((AE_INFO, status, "Can't make an fake ECDT")); | ||
870 | goto error; | ||
871 | } | ||
872 | return 0; | ||
873 | error: | ||
874 | return ret; | ||
875 | } | 801 | } |
876 | 802 | ||
877 | static int __init acpi_ec_get_real_ecdt(void) | 803 | int __init acpi_ec_ecdt_probe(void) |
878 | { | 804 | { |
805 | int ret; | ||
879 | acpi_status status; | 806 | acpi_status status; |
880 | struct acpi_table_ecdt *ecdt_ptr; | 807 | struct acpi_table_ecdt *ecdt_ptr; |
881 | 808 | ||
882 | status = acpi_get_table(ACPI_SIG_ECDT, 1, | 809 | boot_ec = make_acpi_ec(); |
883 | (struct acpi_table_header **)&ecdt_ptr); | 810 | if (!boot_ec) |
884 | if (ACPI_FAILURE(status)) | 811 | return -ENOMEM; |
885 | return -ENODEV; | ||
886 | |||
887 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found ECDT")); | ||
888 | |||
889 | /* | 812 | /* |
890 | * Generate a temporary ec context to use until the namespace is scanned | 813 | * Generate a boot ec context |
891 | */ | 814 | */ |
892 | ec_ecdt = kzalloc(sizeof(struct acpi_ec), GFP_KERNEL); | ||
893 | if (!ec_ecdt) | ||
894 | return -ENOMEM; | ||
895 | 815 | ||
896 | mutex_init(&ec_ecdt->lock); | 816 | status = acpi_get_table(ACPI_SIG_ECDT, 1, |
897 | atomic_set(&ec_ecdt->event_count, 1); | 817 | (struct acpi_table_header **)&ecdt_ptr); |
898 | if (acpi_ec_mode == EC_INTR) { | 818 | if (ACPI_FAILURE(status)) |
899 | init_waitqueue_head(&ec_ecdt->wait); | ||
900 | } | ||
901 | ec_ecdt->command_addr = ecdt_ptr->control.address; | ||
902 | ec_ecdt->data_addr = ecdt_ptr->data.address; | ||
903 | ec_ecdt->gpe = ecdt_ptr->gpe; | ||
904 | /* use the GL just to be safe */ | ||
905 | ec_ecdt->global_lock = TRUE; | ||
906 | ec_ecdt->uid = ecdt_ptr->uid; | ||
907 | |||
908 | status = acpi_get_handle(NULL, ecdt_ptr->id, &ec_ecdt->handle); | ||
909 | if (ACPI_FAILURE(status)) { | ||
910 | goto error; | 819 | goto error; |
911 | } | ||
912 | |||
913 | return 0; | ||
914 | error: | ||
915 | ACPI_EXCEPTION((AE_INFO, status, "Could not use ECDT")); | ||
916 | kfree(ec_ecdt); | ||
917 | ec_ecdt = NULL; | ||
918 | 820 | ||
919 | return -ENODEV; | 821 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found ECDT")); |
920 | } | ||
921 | |||
922 | static int __initdata acpi_fake_ecdt_enabled; | ||
923 | int __init acpi_ec_ecdt_probe(void) | ||
924 | { | ||
925 | acpi_status status; | ||
926 | int ret; | ||
927 | 822 | ||
928 | ret = acpi_ec_get_real_ecdt(); | 823 | boot_ec->command_addr = ecdt_ptr->control.address; |
929 | /* Try to make a fake ECDT */ | 824 | boot_ec->data_addr = ecdt_ptr->data.address; |
930 | if (ret && acpi_fake_ecdt_enabled) { | 825 | boot_ec->gpe = ecdt_ptr->gpe; |
931 | ret = acpi_ec_fake_ecdt(); | 826 | boot_ec->handle = ACPI_ROOT_OBJECT; |
932 | } | ||
933 | 827 | ||
934 | if (ret) | 828 | ret = ec_install_handlers(boot_ec); |
829 | if (!ret) { | ||
830 | first_ec = boot_ec; | ||
935 | return 0; | 831 | return 0; |
936 | |||
937 | /* | ||
938 | * Install GPE handler | ||
939 | */ | ||
940 | status = acpi_install_gpe_handler(NULL, ec_ecdt->gpe, | ||
941 | ACPI_GPE_EDGE_TRIGGERED, | ||
942 | &acpi_ec_gpe_handler, ec_ecdt); | ||
943 | if (ACPI_FAILURE(status)) { | ||
944 | goto error; | ||
945 | } | 832 | } |
946 | acpi_set_gpe_type(NULL, ec_ecdt->gpe, ACPI_GPE_TYPE_RUNTIME); | ||
947 | acpi_enable_gpe(NULL, ec_ecdt->gpe, ACPI_NOT_ISR); | ||
948 | |||
949 | status = acpi_install_address_space_handler(ACPI_ROOT_OBJECT, | ||
950 | ACPI_ADR_SPACE_EC, | ||
951 | &acpi_ec_space_handler, | ||
952 | &acpi_ec_space_setup, | ||
953 | ec_ecdt); | ||
954 | if (ACPI_FAILURE(status)) { | ||
955 | acpi_remove_gpe_handler(NULL, ec_ecdt->gpe, | ||
956 | &acpi_ec_gpe_handler); | ||
957 | goto error; | ||
958 | } | ||
959 | |||
960 | return 0; | ||
961 | |||
962 | error: | 833 | error: |
963 | ACPI_EXCEPTION((AE_INFO, status, "Could not use ECDT")); | 834 | kfree(boot_ec); |
964 | kfree(ec_ecdt); | 835 | boot_ec = NULL; |
965 | ec_ecdt = NULL; | ||
966 | 836 | ||
967 | return -ENODEV; | 837 | return -ENODEV; |
968 | } | 838 | } |
@@ -1003,13 +873,6 @@ static void __exit acpi_ec_exit(void) | |||
1003 | } | 873 | } |
1004 | #endif /* 0 */ | 874 | #endif /* 0 */ |
1005 | 875 | ||
1006 | static int __init acpi_fake_ecdt_setup(char *str) | ||
1007 | { | ||
1008 | acpi_fake_ecdt_enabled = 1; | ||
1009 | return 1; | ||
1010 | } | ||
1011 | |||
1012 | __setup("acpi_fake_ecdt", acpi_fake_ecdt_setup); | ||
1013 | static int __init acpi_ec_set_intr_mode(char *str) | 876 | static int __init acpi_ec_set_intr_mode(char *str) |
1014 | { | 877 | { |
1015 | int intr; | 878 | int intr; |
@@ -1017,12 +880,8 @@ static int __init acpi_ec_set_intr_mode(char *str) | |||
1017 | if (!get_option(&str, &intr)) | 880 | if (!get_option(&str, &intr)) |
1018 | return 0; | 881 | return 0; |
1019 | 882 | ||
1020 | if (intr) { | 883 | acpi_ec_mode = (intr) ? EC_INTR : EC_POLL; |
1021 | acpi_ec_mode = EC_INTR; | 884 | |
1022 | } else { | ||
1023 | acpi_ec_mode = EC_POLL; | ||
1024 | } | ||
1025 | acpi_ec_driver.ops.add = acpi_ec_add; | ||
1026 | printk(KERN_NOTICE PREFIX "%s mode.\n", intr ? "interrupt" : "polling"); | 885 | printk(KERN_NOTICE PREFIX "%s mode.\n", intr ? "interrupt" : "polling"); |
1027 | 886 | ||
1028 | return 1; | 887 | return 1; |
diff --git a/drivers/acpi/i2c_ec.c b/drivers/acpi/i2c_ec.c deleted file mode 100644 index acab4a481897..000000000000 --- a/drivers/acpi/i2c_ec.c +++ /dev/null | |||
@@ -1,403 +0,0 @@ | |||
1 | /* | ||
2 | * SMBus driver for ACPI Embedded Controller ($Revision: 1.3 $) | ||
3 | * | ||
4 | * Copyright (c) 2002, 2005 Ducrot Bruno | ||
5 | * Copyright (c) 2005 Rich Townsend (tiny hacks & tweaks) | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation version 2. | ||
10 | */ | ||
11 | |||
12 | #include <linux/version.h> | ||
13 | #include <linux/module.h> | ||
14 | #include <linux/slab.h> | ||
15 | #include <linux/kernel.h> | ||
16 | #include <linux/stddef.h> | ||
17 | #include <linux/init.h> | ||
18 | #include <linux/i2c.h> | ||
19 | #include <linux/acpi.h> | ||
20 | #include <linux/delay.h> | ||
21 | |||
22 | #include "i2c_ec.h" | ||
23 | |||
24 | #define xudelay(t) udelay(t) | ||
25 | #define xmsleep(t) msleep(t) | ||
26 | |||
27 | #define ACPI_EC_HC_COMPONENT 0x00080000 | ||
28 | #define ACPI_EC_HC_CLASS "ec_hc_smbus" | ||
29 | #define ACPI_EC_HC_HID "ACPI0001" | ||
30 | #define ACPI_EC_HC_DEVICE_NAME "EC HC smbus" | ||
31 | |||
32 | #define _COMPONENT ACPI_EC_HC_COMPONENT | ||
33 | |||
34 | ACPI_MODULE_NAME("i2c_ec"); | ||
35 | |||
36 | static int acpi_ec_hc_add(struct acpi_device *device); | ||
37 | static int acpi_ec_hc_remove(struct acpi_device *device, int type); | ||
38 | |||
39 | static struct acpi_driver acpi_ec_hc_driver = { | ||
40 | .name = "i2c_ec", | ||
41 | .class = ACPI_EC_HC_CLASS, | ||
42 | .ids = ACPI_EC_HC_HID, | ||
43 | .ops = { | ||
44 | .add = acpi_ec_hc_add, | ||
45 | .remove = acpi_ec_hc_remove, | ||
46 | }, | ||
47 | }; | ||
48 | |||
49 | /* Various bit mask for EC_SC (R) */ | ||
50 | #define OBF 0x01 | ||
51 | #define IBF 0x02 | ||
52 | #define CMD 0x08 | ||
53 | #define BURST 0x10 | ||
54 | #define SCI_EVT 0x20 | ||
55 | #define SMI_EVT 0x40 | ||
56 | |||
57 | /* Commands for EC_SC (W) */ | ||
58 | #define RD_EC 0x80 | ||
59 | #define WR_EC 0x81 | ||
60 | #define BE_EC 0x82 | ||
61 | #define BD_EC 0x83 | ||
62 | #define QR_EC 0x84 | ||
63 | |||
64 | /* | ||
65 | * ACPI 2.0 chapter 13 SMBus 2.0 EC register model | ||
66 | */ | ||
67 | |||
68 | #define ACPI_EC_SMB_PRTCL 0x00 /* protocol, PEC */ | ||
69 | #define ACPI_EC_SMB_STS 0x01 /* status */ | ||
70 | #define ACPI_EC_SMB_ADDR 0x02 /* address */ | ||
71 | #define ACPI_EC_SMB_CMD 0x03 /* command */ | ||
72 | #define ACPI_EC_SMB_DATA 0x04 /* 32 data registers */ | ||
73 | #define ACPI_EC_SMB_BCNT 0x24 /* number of data bytes */ | ||
74 | #define ACPI_EC_SMB_ALRM_A 0x25 /* alarm address */ | ||
75 | #define ACPI_EC_SMB_ALRM_D 0x26 /* 2 bytes alarm data */ | ||
76 | |||
77 | #define ACPI_EC_SMB_STS_DONE 0x80 | ||
78 | #define ACPI_EC_SMB_STS_ALRM 0x40 | ||
79 | #define ACPI_EC_SMB_STS_RES 0x20 | ||
80 | #define ACPI_EC_SMB_STS_STATUS 0x1f | ||
81 | |||
82 | #define ACPI_EC_SMB_STATUS_OK 0x00 | ||
83 | #define ACPI_EC_SMB_STATUS_FAIL 0x07 | ||
84 | #define ACPI_EC_SMB_STATUS_DNAK 0x10 | ||
85 | #define ACPI_EC_SMB_STATUS_DERR 0x11 | ||
86 | #define ACPI_EC_SMB_STATUS_CMD_DENY 0x12 | ||
87 | #define ACPI_EC_SMB_STATUS_UNKNOWN 0x13 | ||
88 | #define ACPI_EC_SMB_STATUS_ACC_DENY 0x17 | ||
89 | #define ACPI_EC_SMB_STATUS_TIMEOUT 0x18 | ||
90 | #define ACPI_EC_SMB_STATUS_NOTSUP 0x19 | ||
91 | #define ACPI_EC_SMB_STATUS_BUSY 0x1A | ||
92 | #define ACPI_EC_SMB_STATUS_PEC 0x1F | ||
93 | |||
94 | #define ACPI_EC_SMB_PRTCL_WRITE 0x00 | ||
95 | #define ACPI_EC_SMB_PRTCL_READ 0x01 | ||
96 | #define ACPI_EC_SMB_PRTCL_QUICK 0x02 | ||
97 | #define ACPI_EC_SMB_PRTCL_BYTE 0x04 | ||
98 | #define ACPI_EC_SMB_PRTCL_BYTE_DATA 0x06 | ||
99 | #define ACPI_EC_SMB_PRTCL_WORD_DATA 0x08 | ||
100 | #define ACPI_EC_SMB_PRTCL_BLOCK_DATA 0x0a | ||
101 | #define ACPI_EC_SMB_PRTCL_PROC_CALL 0x0c | ||
102 | #define ACPI_EC_SMB_PRTCL_BLOCK_PROC_CALL 0x0d | ||
103 | #define ACPI_EC_SMB_PRTCL_I2C_BLOCK_DATA 0x4a | ||
104 | #define ACPI_EC_SMB_PRTCL_PEC 0x80 | ||
105 | |||
106 | /* Length of pre/post transaction sleep (msec) */ | ||
107 | #define ACPI_EC_SMB_TRANSACTION_SLEEP 1 | ||
108 | #define ACPI_EC_SMB_ACCESS_SLEEP1 1 | ||
109 | #define ACPI_EC_SMB_ACCESS_SLEEP2 10 | ||
110 | |||
111 | static int acpi_ec_smb_read(struct acpi_ec_smbus *smbus, u8 address, u8 * data) | ||
112 | { | ||
113 | u8 val; | ||
114 | int err; | ||
115 | |||
116 | err = ec_read(smbus->base + address, &val); | ||
117 | if (!err) { | ||
118 | *data = val; | ||
119 | } | ||
120 | xmsleep(ACPI_EC_SMB_TRANSACTION_SLEEP); | ||
121 | return (err); | ||
122 | } | ||
123 | |||
124 | static int acpi_ec_smb_write(struct acpi_ec_smbus *smbus, u8 address, u8 data) | ||
125 | { | ||
126 | int err; | ||
127 | |||
128 | err = ec_write(smbus->base + address, data); | ||
129 | return (err); | ||
130 | } | ||
131 | |||
132 | static int | ||
133 | acpi_ec_smb_access(struct i2c_adapter *adap, u16 addr, unsigned short flags, | ||
134 | char read_write, u8 command, int size, | ||
135 | union i2c_smbus_data *data) | ||
136 | { | ||
137 | struct acpi_ec_smbus *smbus = adap->algo_data; | ||
138 | unsigned char protocol, len = 0, pec, temp[2] = { 0, 0 }; | ||
139 | int i; | ||
140 | |||
141 | if (read_write == I2C_SMBUS_READ) { | ||
142 | protocol = ACPI_EC_SMB_PRTCL_READ; | ||
143 | } else { | ||
144 | protocol = ACPI_EC_SMB_PRTCL_WRITE; | ||
145 | } | ||
146 | pec = (flags & I2C_CLIENT_PEC) ? ACPI_EC_SMB_PRTCL_PEC : 0; | ||
147 | |||
148 | switch (size) { | ||
149 | |||
150 | case I2C_SMBUS_QUICK: | ||
151 | protocol |= ACPI_EC_SMB_PRTCL_QUICK; | ||
152 | read_write = I2C_SMBUS_WRITE; | ||
153 | break; | ||
154 | |||
155 | case I2C_SMBUS_BYTE: | ||
156 | if (read_write == I2C_SMBUS_WRITE) { | ||
157 | acpi_ec_smb_write(smbus, ACPI_EC_SMB_DATA, data->byte); | ||
158 | } | ||
159 | protocol |= ACPI_EC_SMB_PRTCL_BYTE; | ||
160 | break; | ||
161 | |||
162 | case I2C_SMBUS_BYTE_DATA: | ||
163 | acpi_ec_smb_write(smbus, ACPI_EC_SMB_CMD, command); | ||
164 | if (read_write == I2C_SMBUS_WRITE) { | ||
165 | acpi_ec_smb_write(smbus, ACPI_EC_SMB_DATA, data->byte); | ||
166 | } | ||
167 | protocol |= ACPI_EC_SMB_PRTCL_BYTE_DATA; | ||
168 | break; | ||
169 | |||
170 | case I2C_SMBUS_WORD_DATA: | ||
171 | acpi_ec_smb_write(smbus, ACPI_EC_SMB_CMD, command); | ||
172 | if (read_write == I2C_SMBUS_WRITE) { | ||
173 | acpi_ec_smb_write(smbus, ACPI_EC_SMB_DATA, data->word); | ||
174 | acpi_ec_smb_write(smbus, ACPI_EC_SMB_DATA + 1, | ||
175 | data->word >> 8); | ||
176 | } | ||
177 | protocol |= ACPI_EC_SMB_PRTCL_WORD_DATA | pec; | ||
178 | break; | ||
179 | |||
180 | case I2C_SMBUS_BLOCK_DATA: | ||
181 | acpi_ec_smb_write(smbus, ACPI_EC_SMB_CMD, command); | ||
182 | if (read_write == I2C_SMBUS_WRITE) { | ||
183 | len = min_t(u8, data->block[0], 32); | ||
184 | acpi_ec_smb_write(smbus, ACPI_EC_SMB_BCNT, len); | ||
185 | for (i = 0; i < len; i++) | ||
186 | acpi_ec_smb_write(smbus, ACPI_EC_SMB_DATA + i, | ||
187 | data->block[i + 1]); | ||
188 | } | ||
189 | protocol |= ACPI_EC_SMB_PRTCL_BLOCK_DATA | pec; | ||
190 | break; | ||
191 | |||
192 | case I2C_SMBUS_I2C_BLOCK_DATA: | ||
193 | len = min_t(u8, data->block[0], 32); | ||
194 | acpi_ec_smb_write(smbus, ACPI_EC_SMB_CMD, command); | ||
195 | acpi_ec_smb_write(smbus, ACPI_EC_SMB_BCNT, len); | ||
196 | if (read_write == I2C_SMBUS_WRITE) { | ||
197 | for (i = 0; i < len; i++) { | ||
198 | acpi_ec_smb_write(smbus, ACPI_EC_SMB_DATA + i, | ||
199 | data->block[i + 1]); | ||
200 | } | ||
201 | } | ||
202 | protocol |= ACPI_EC_SMB_PRTCL_I2C_BLOCK_DATA; | ||
203 | break; | ||
204 | |||
205 | case I2C_SMBUS_PROC_CALL: | ||
206 | acpi_ec_smb_write(smbus, ACPI_EC_SMB_CMD, command); | ||
207 | acpi_ec_smb_write(smbus, ACPI_EC_SMB_DATA, data->word); | ||
208 | acpi_ec_smb_write(smbus, ACPI_EC_SMB_DATA + 1, data->word >> 8); | ||
209 | protocol = ACPI_EC_SMB_PRTCL_PROC_CALL | pec; | ||
210 | read_write = I2C_SMBUS_READ; | ||
211 | break; | ||
212 | |||
213 | case I2C_SMBUS_BLOCK_PROC_CALL: | ||
214 | protocol |= pec; | ||
215 | len = min_t(u8, data->block[0], 31); | ||
216 | acpi_ec_smb_write(smbus, ACPI_EC_SMB_CMD, command); | ||
217 | acpi_ec_smb_write(smbus, ACPI_EC_SMB_BCNT, len); | ||
218 | for (i = 0; i < len; i++) | ||
219 | acpi_ec_smb_write(smbus, ACPI_EC_SMB_DATA + i, | ||
220 | data->block[i + 1]); | ||
221 | protocol = ACPI_EC_SMB_PRTCL_BLOCK_PROC_CALL | pec; | ||
222 | read_write = I2C_SMBUS_READ; | ||
223 | break; | ||
224 | |||
225 | default: | ||
226 | ACPI_DEBUG_PRINT((ACPI_DB_WARN, "EC SMBus adapter: " | ||
227 | "Unsupported transaction %d\n", size)); | ||
228 | return (-1); | ||
229 | } | ||
230 | |||
231 | acpi_ec_smb_write(smbus, ACPI_EC_SMB_ADDR, addr << 1); | ||
232 | acpi_ec_smb_write(smbus, ACPI_EC_SMB_PRTCL, protocol); | ||
233 | |||
234 | acpi_ec_smb_read(smbus, ACPI_EC_SMB_STS, temp + 0); | ||
235 | |||
236 | if (~temp[0] & ACPI_EC_SMB_STS_DONE) { | ||
237 | xudelay(500); | ||
238 | acpi_ec_smb_read(smbus, ACPI_EC_SMB_STS, temp + 0); | ||
239 | } | ||
240 | if (~temp[0] & ACPI_EC_SMB_STS_DONE) { | ||
241 | xmsleep(ACPI_EC_SMB_ACCESS_SLEEP2); | ||
242 | acpi_ec_smb_read(smbus, ACPI_EC_SMB_STS, temp + 0); | ||
243 | } | ||
244 | if ((~temp[0] & ACPI_EC_SMB_STS_DONE) | ||
245 | || (temp[0] & ACPI_EC_SMB_STS_STATUS)) { | ||
246 | return (-1); | ||
247 | } | ||
248 | |||
249 | if (read_write == I2C_SMBUS_WRITE) { | ||
250 | return (0); | ||
251 | } | ||
252 | |||
253 | switch (size) { | ||
254 | |||
255 | case I2C_SMBUS_BYTE: | ||
256 | case I2C_SMBUS_BYTE_DATA: | ||
257 | acpi_ec_smb_read(smbus, ACPI_EC_SMB_DATA, &data->byte); | ||
258 | break; | ||
259 | |||
260 | case I2C_SMBUS_WORD_DATA: | ||
261 | case I2C_SMBUS_PROC_CALL: | ||
262 | acpi_ec_smb_read(smbus, ACPI_EC_SMB_DATA, temp + 0); | ||
263 | acpi_ec_smb_read(smbus, ACPI_EC_SMB_DATA + 1, temp + 1); | ||
264 | data->word = (temp[1] << 8) | temp[0]; | ||
265 | break; | ||
266 | |||
267 | case I2C_SMBUS_BLOCK_DATA: | ||
268 | case I2C_SMBUS_BLOCK_PROC_CALL: | ||
269 | len = 0; | ||
270 | acpi_ec_smb_read(smbus, ACPI_EC_SMB_BCNT, &len); | ||
271 | len = min_t(u8, len, 32); | ||
272 | case I2C_SMBUS_I2C_BLOCK_DATA: | ||
273 | for (i = 0; i < len; i++) | ||
274 | acpi_ec_smb_read(smbus, ACPI_EC_SMB_DATA + i, | ||
275 | data->block + i + 1); | ||
276 | data->block[0] = len; | ||
277 | break; | ||
278 | } | ||
279 | |||
280 | return (0); | ||
281 | } | ||
282 | |||
283 | static u32 acpi_ec_smb_func(struct i2c_adapter *adapter) | ||
284 | { | ||
285 | |||
286 | return (I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | | ||
287 | I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | | ||
288 | I2C_FUNC_SMBUS_BLOCK_DATA | | ||
289 | I2C_FUNC_SMBUS_PROC_CALL | | ||
290 | I2C_FUNC_SMBUS_BLOCK_PROC_CALL | | ||
291 | I2C_FUNC_SMBUS_I2C_BLOCK | I2C_FUNC_SMBUS_HWPEC_CALC); | ||
292 | } | ||
293 | |||
294 | static const struct i2c_algorithm acpi_ec_smbus_algorithm = { | ||
295 | .smbus_xfer = acpi_ec_smb_access, | ||
296 | .functionality = acpi_ec_smb_func, | ||
297 | }; | ||
298 | |||
299 | static int acpi_ec_hc_add(struct acpi_device *device) | ||
300 | { | ||
301 | int status; | ||
302 | unsigned long val; | ||
303 | struct acpi_ec_hc *ec_hc; | ||
304 | struct acpi_ec_smbus *smbus; | ||
305 | |||
306 | if (!device) { | ||
307 | return -EINVAL; | ||
308 | } | ||
309 | |||
310 | ec_hc = kzalloc(sizeof(struct acpi_ec_hc), GFP_KERNEL); | ||
311 | if (!ec_hc) { | ||
312 | return -ENOMEM; | ||
313 | } | ||
314 | |||
315 | smbus = kzalloc(sizeof(struct acpi_ec_smbus), GFP_KERNEL); | ||
316 | if (!smbus) { | ||
317 | kfree(ec_hc); | ||
318 | return -ENOMEM; | ||
319 | } | ||
320 | |||
321 | ec_hc->handle = device->handle; | ||
322 | strcpy(acpi_device_name(device), ACPI_EC_HC_DEVICE_NAME); | ||
323 | strcpy(acpi_device_class(device), ACPI_EC_HC_CLASS); | ||
324 | acpi_driver_data(device) = ec_hc; | ||
325 | |||
326 | status = acpi_evaluate_integer(ec_hc->handle, "_EC", NULL, &val); | ||
327 | if (ACPI_FAILURE(status)) { | ||
328 | ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Error obtaining _EC\n")); | ||
329 | kfree(ec_hc); | ||
330 | kfree(smbus); | ||
331 | return -EIO; | ||
332 | } | ||
333 | |||
334 | smbus->ec = acpi_driver_data(device->parent); | ||
335 | smbus->base = (val & 0xff00ull) >> 8; | ||
336 | smbus->alert = val & 0xffull; | ||
337 | |||
338 | smbus->adapter.owner = THIS_MODULE; | ||
339 | smbus->adapter.algo = &acpi_ec_smbus_algorithm; | ||
340 | smbus->adapter.algo_data = smbus; | ||
341 | smbus->adapter.dev.parent = &device->dev; | ||
342 | |||
343 | if (i2c_add_adapter(&smbus->adapter)) { | ||
344 | ACPI_DEBUG_PRINT((ACPI_DB_WARN, | ||
345 | "EC SMBus adapter: Failed to register adapter\n")); | ||
346 | kfree(smbus); | ||
347 | kfree(ec_hc); | ||
348 | return -EIO; | ||
349 | } | ||
350 | |||
351 | ec_hc->smbus = smbus; | ||
352 | |||
353 | printk(KERN_INFO PREFIX "%s [%s]\n", | ||
354 | acpi_device_name(device), acpi_device_bid(device)); | ||
355 | |||
356 | return AE_OK; | ||
357 | } | ||
358 | |||
359 | static int acpi_ec_hc_remove(struct acpi_device *device, int type) | ||
360 | { | ||
361 | struct acpi_ec_hc *ec_hc; | ||
362 | |||
363 | if (!device) { | ||
364 | return -EINVAL; | ||
365 | } | ||
366 | ec_hc = acpi_driver_data(device); | ||
367 | |||
368 | i2c_del_adapter(&ec_hc->smbus->adapter); | ||
369 | kfree(ec_hc->smbus); | ||
370 | kfree(ec_hc); | ||
371 | |||
372 | return AE_OK; | ||
373 | } | ||
374 | |||
375 | static int __init acpi_ec_hc_init(void) | ||
376 | { | ||
377 | int result; | ||
378 | |||
379 | result = acpi_bus_register_driver(&acpi_ec_hc_driver); | ||
380 | if (result < 0) { | ||
381 | return -ENODEV; | ||
382 | } | ||
383 | return 0; | ||
384 | } | ||
385 | |||
386 | static void __exit acpi_ec_hc_exit(void) | ||
387 | { | ||
388 | acpi_bus_unregister_driver(&acpi_ec_hc_driver); | ||
389 | } | ||
390 | |||
391 | struct acpi_ec_hc *acpi_get_ec_hc(struct acpi_device *device) | ||
392 | { | ||
393 | return acpi_driver_data(device->parent); | ||
394 | } | ||
395 | |||
396 | EXPORT_SYMBOL(acpi_get_ec_hc); | ||
397 | |||
398 | module_init(acpi_ec_hc_init); | ||
399 | module_exit(acpi_ec_hc_exit); | ||
400 | |||
401 | MODULE_LICENSE("GPL"); | ||
402 | MODULE_AUTHOR("Ducrot Bruno"); | ||
403 | MODULE_DESCRIPTION("ACPI EC SMBus driver"); | ||
diff --git a/drivers/acpi/i2c_ec.h b/drivers/acpi/i2c_ec.h deleted file mode 100644 index 7c53fb732d61..000000000000 --- a/drivers/acpi/i2c_ec.h +++ /dev/null | |||
@@ -1,23 +0,0 @@ | |||
1 | /* | ||
2 | * SMBus driver for ACPI Embedded Controller ($Revision: 1.2 $) | ||
3 | * | ||
4 | * Copyright (c) 2002, 2005 Ducrot Bruno | ||
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 | struct acpi_ec_smbus { | ||
12 | struct i2c_adapter adapter; | ||
13 | union acpi_ec *ec; | ||
14 | int base; | ||
15 | int alert; | ||
16 | }; | ||
17 | |||
18 | struct acpi_ec_hc { | ||
19 | acpi_handle handle; | ||
20 | struct acpi_ec_smbus *smbus; | ||
21 | }; | ||
22 | |||
23 | struct acpi_ec_hc *acpi_get_ec_hc(struct acpi_device *device); | ||
diff --git a/drivers/acpi/ibm_acpi.c b/drivers/acpi/ibm_acpi.c deleted file mode 100644 index dc1096608f43..000000000000 --- a/drivers/acpi/ibm_acpi.c +++ /dev/null | |||
@@ -1,2798 +0,0 @@ | |||
1 | /* | ||
2 | * ibm_acpi.c - IBM ThinkPad ACPI Extras | ||
3 | * | ||
4 | * | ||
5 | * Copyright (C) 2004-2005 Borislav Deianov <borislav@users.sf.net> | ||
6 | * Copyright (C) 2006 Henrique de Moraes Holschuh <hmh@hmh.eng.br> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License as published by | ||
10 | * the Free Software Foundation; either version 2 of the License, or | ||
11 | * (at your option) any later version. | ||
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | * GNU General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
21 | */ | ||
22 | |||
23 | #define IBM_VERSION "0.13" | ||
24 | |||
25 | /* | ||
26 | * Changelog: | ||
27 | * | ||
28 | * 2006-11-22 0.13 new maintainer | ||
29 | * changelog now lives in git commit history, and will | ||
30 | * not be updated further in-file. | ||
31 | * | ||
32 | * 2005-08-17 0.12 fix compilation on 2.6.13-rc kernels | ||
33 | * 2005-03-17 0.11 support for 600e, 770x | ||
34 | * thanks to Jamie Lentin <lentinj@dial.pipex.com> | ||
35 | * support for 770e, G41 | ||
36 | * G40 and G41 don't have a thinklight | ||
37 | * temperatures no longer experimental | ||
38 | * experimental brightness control | ||
39 | * experimental volume control | ||
40 | * experimental fan enable/disable | ||
41 | * 2005-01-16 0.10 fix module loading on R30, R31 | ||
42 | * 2005-01-16 0.9 support for 570, R30, R31 | ||
43 | * ultrabay support on A22p, A3x | ||
44 | * limit arg for cmos, led, beep, drop experimental status | ||
45 | * more capable led control on A21e, A22p, T20-22, X20 | ||
46 | * experimental temperatures and fan speed | ||
47 | * experimental embedded controller register dump | ||
48 | * mark more functions as __init, drop incorrect __exit | ||
49 | * use MODULE_VERSION | ||
50 | * thanks to Henrik Brix Andersen <brix@gentoo.org> | ||
51 | * fix parameter passing on module loading | ||
52 | * thanks to Rusty Russell <rusty@rustcorp.com.au> | ||
53 | * thanks to Jim Radford <radford@blackbean.org> | ||
54 | * 2004-11-08 0.8 fix init error case, don't return from a macro | ||
55 | * thanks to Chris Wright <chrisw@osdl.org> | ||
56 | * 2004-10-23 0.7 fix module loading on A21e, A22p, T20, T21, X20 | ||
57 | * fix led control on A21e | ||
58 | * 2004-10-19 0.6 use acpi_bus_register_driver() to claim HKEY device | ||
59 | * 2004-10-18 0.5 thinklight support on A21e, G40, R32, T20, T21, X20 | ||
60 | * proc file format changed | ||
61 | * video_switch command | ||
62 | * experimental cmos control | ||
63 | * experimental led control | ||
64 | * experimental acpi sounds | ||
65 | * 2004-09-16 0.4 support for module parameters | ||
66 | * hotkey mask can be prefixed by 0x | ||
67 | * video output switching | ||
68 | * video expansion control | ||
69 | * ultrabay eject support | ||
70 | * removed lcd brightness/on/off control, didn't work | ||
71 | * 2004-08-17 0.3 support for R40 | ||
72 | * lcd off, brightness control | ||
73 | * thinklight on/off | ||
74 | * 2004-08-14 0.2 support for T series, X20 | ||
75 | * bluetooth enable/disable | ||
76 | * hotkey events disabled by default | ||
77 | * removed fan control, currently useless | ||
78 | * 2004-08-09 0.1 initial release, support for X series | ||
79 | */ | ||
80 | |||
81 | #include <linux/kernel.h> | ||
82 | #include <linux/module.h> | ||
83 | #include <linux/init.h> | ||
84 | #include <linux/types.h> | ||
85 | #include <linux/string.h> | ||
86 | |||
87 | #include <linux/proc_fs.h> | ||
88 | #include <linux/backlight.h> | ||
89 | #include <linux/fb.h> | ||
90 | #include <asm/uaccess.h> | ||
91 | |||
92 | #include <linux/dmi.h> | ||
93 | #include <linux/jiffies.h> | ||
94 | #include <linux/workqueue.h> | ||
95 | |||
96 | #include <acpi/acpi_drivers.h> | ||
97 | #include <acpi/acnamesp.h> | ||
98 | |||
99 | #define IBM_NAME "ibm" | ||
100 | #define IBM_DESC "IBM ThinkPad ACPI Extras" | ||
101 | #define IBM_FILE "ibm_acpi" | ||
102 | #define IBM_URL "http://ibm-acpi.sf.net/" | ||
103 | |||
104 | MODULE_AUTHOR("Borislav Deianov, Henrique de Moraes Holschuh"); | ||
105 | MODULE_DESCRIPTION(IBM_DESC); | ||
106 | MODULE_VERSION(IBM_VERSION); | ||
107 | MODULE_LICENSE("GPL"); | ||
108 | |||
109 | #define IBM_DIR IBM_NAME | ||
110 | |||
111 | #define IBM_LOG IBM_FILE ": " | ||
112 | #define IBM_ERR KERN_ERR IBM_LOG | ||
113 | #define IBM_NOTICE KERN_NOTICE IBM_LOG | ||
114 | #define IBM_INFO KERN_INFO IBM_LOG | ||
115 | #define IBM_DEBUG KERN_DEBUG IBM_LOG | ||
116 | |||
117 | #define IBM_MAX_ACPI_ARGS 3 | ||
118 | |||
119 | #define __unused __attribute__ ((unused)) | ||
120 | |||
121 | static int experimental; | ||
122 | module_param(experimental, int, 0); | ||
123 | |||
124 | static acpi_handle root_handle = NULL; | ||
125 | |||
126 | #define IBM_HANDLE(object, parent, paths...) \ | ||
127 | static acpi_handle object##_handle; \ | ||
128 | static acpi_handle *object##_parent = &parent##_handle; \ | ||
129 | static char *object##_path; \ | ||
130 | static char *object##_paths[] = { paths } | ||
131 | |||
132 | IBM_HANDLE(ec, root, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */ | ||
133 | "\\_SB.PCI.ISA.EC", /* 570 */ | ||
134 | "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */ | ||
135 | "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */ | ||
136 | "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */ | ||
137 | "\\_SB.PCI0.ICH3.EC0", /* R31 */ | ||
138 | "\\_SB.PCI0.LPC.EC", /* all others */ | ||
139 | ); | ||
140 | |||
141 | IBM_HANDLE(vid, root, "\\_SB.PCI.AGP.VGA", /* 570 */ | ||
142 | "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */ | ||
143 | "\\_SB.PCI0.VID0", /* 770e */ | ||
144 | "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */ | ||
145 | "\\_SB.PCI0.AGP.VID", /* all others */ | ||
146 | ); /* R30, R31 */ | ||
147 | |||
148 | IBM_HANDLE(vid2, root, "\\_SB.PCI0.AGPB.VID"); /* G41 */ | ||
149 | |||
150 | IBM_HANDLE(cmos, root, "\\UCMS", /* R50, R50e, R50p, R51, T4x, X31, X40 */ | ||
151 | "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */ | ||
152 | "\\CMS", /* R40, R40e */ | ||
153 | ); /* all others */ | ||
154 | #ifdef CONFIG_ACPI_IBM_DOCK | ||
155 | IBM_HANDLE(dock, root, "\\_SB.GDCK", /* X30, X31, X40 */ | ||
156 | "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */ | ||
157 | "\\_SB.PCI0.PCI1.DOCK", /* all others */ | ||
158 | "\\_SB.PCI.ISA.SLCE", /* 570 */ | ||
159 | ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */ | ||
160 | #endif | ||
161 | #ifdef CONFIG_ACPI_IBM_BAY | ||
162 | IBM_HANDLE(bay, root, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */ | ||
163 | "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */ | ||
164 | "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */ | ||
165 | "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */ | ||
166 | ); /* A21e, R30, R31 */ | ||
167 | |||
168 | IBM_HANDLE(bay_ej, bay, "_EJ3", /* 600e/x, A2xm/p, A3x */ | ||
169 | "_EJ0", /* all others */ | ||
170 | ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */ | ||
171 | |||
172 | IBM_HANDLE(bay2, root, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */ | ||
173 | "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */ | ||
174 | ); /* all others */ | ||
175 | |||
176 | IBM_HANDLE(bay2_ej, bay2, "_EJ3", /* 600e/x, 770e, A3x */ | ||
177 | "_EJ0", /* 770x */ | ||
178 | ); /* all others */ | ||
179 | #endif /* CONFIG_ACPI_IBM_BAY */ | ||
180 | |||
181 | /* don't list other alternatives as we install a notify handler on the 570 */ | ||
182 | IBM_HANDLE(pci, root, "\\_SB.PCI"); /* 570 */ | ||
183 | |||
184 | IBM_HANDLE(hkey, ec, "\\_SB.HKEY", /* 600e/x, 770e, 770x */ | ||
185 | "^HKEY", /* R30, R31 */ | ||
186 | "HKEY", /* all others */ | ||
187 | ); /* 570 */ | ||
188 | |||
189 | IBM_HANDLE(lght, root, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */ | ||
190 | IBM_HANDLE(ledb, ec, "LEDB"); /* G4x */ | ||
191 | |||
192 | IBM_HANDLE(led, ec, "SLED", /* 570 */ | ||
193 | "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */ | ||
194 | "LED", /* all others */ | ||
195 | ); /* R30, R31 */ | ||
196 | |||
197 | IBM_HANDLE(beep, ec, "BEEP"); /* all except R30, R31 */ | ||
198 | IBM_HANDLE(ecrd, ec, "ECRD"); /* 570 */ | ||
199 | IBM_HANDLE(ecwr, ec, "ECWR"); /* 570 */ | ||
200 | IBM_HANDLE(fans, ec, "FANS"); /* X31, X40, X41 */ | ||
201 | |||
202 | IBM_HANDLE(gfan, ec, "GFAN", /* 570 */ | ||
203 | "\\FSPD", /* 600e/x, 770e, 770x */ | ||
204 | ); /* all others */ | ||
205 | |||
206 | IBM_HANDLE(sfan, ec, "SFAN", /* 570 */ | ||
207 | "JFNS", /* 770x-JL */ | ||
208 | ); /* all others */ | ||
209 | |||
210 | #define IBM_HKEY_HID "IBM0068" | ||
211 | #define IBM_PCI_HID "PNP0A03" | ||
212 | |||
213 | enum thermal_access_mode { | ||
214 | IBMACPI_THERMAL_NONE = 0, /* No thermal support */ | ||
215 | IBMACPI_THERMAL_ACPI_TMP07, /* Use ACPI TMP0-7 */ | ||
216 | IBMACPI_THERMAL_ACPI_UPDT, /* Use ACPI TMP0-7 with UPDT */ | ||
217 | IBMACPI_THERMAL_TPEC_8, /* Use ACPI EC regs, 8 sensors */ | ||
218 | IBMACPI_THERMAL_TPEC_16, /* Use ACPI EC regs, 16 sensors */ | ||
219 | }; | ||
220 | |||
221 | #define IBMACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */ | ||
222 | struct ibm_thermal_sensors_struct { | ||
223 | s32 temp[IBMACPI_MAX_THERMAL_SENSORS]; | ||
224 | }; | ||
225 | |||
226 | /* | ||
227 | * FAN ACCESS MODES | ||
228 | * | ||
229 | * IBMACPI_FAN_RD_ACPI_GFAN: | ||
230 | * ACPI GFAN method: returns fan level | ||
231 | * | ||
232 | * see IBMACPI_FAN_WR_ACPI_SFAN | ||
233 | * EC 0x2f not available if GFAN exists | ||
234 | * | ||
235 | * IBMACPI_FAN_WR_ACPI_SFAN: | ||
236 | * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max) | ||
237 | * | ||
238 | * EC 0x2f might be available *for reading*, but never for writing. | ||
239 | * | ||
240 | * IBMACPI_FAN_WR_TPEC: | ||
241 | * ThinkPad EC register 0x2f (HFSP): fan control loop mode Supported | ||
242 | * on almost all ThinkPads | ||
243 | * | ||
244 | * Fan speed changes of any sort (including those caused by the | ||
245 | * disengaged mode) are usually done slowly by the firmware as the | ||
246 | * maximum ammount of fan duty cycle change per second seems to be | ||
247 | * limited. | ||
248 | * | ||
249 | * Reading is not available if GFAN exists. | ||
250 | * Writing is not available if SFAN exists. | ||
251 | * | ||
252 | * Bits | ||
253 | * 7 automatic mode engaged; | ||
254 | * (default operation mode of the ThinkPad) | ||
255 | * fan level is ignored in this mode. | ||
256 | * 6 disengage mode (takes precedence over bit 7); | ||
257 | * not available on all thinkpads. May disable | ||
258 | * the tachometer, and speeds up fan to 100% duty-cycle, | ||
259 | * which speeds it up far above the standard RPM | ||
260 | * levels. It is not impossible that it could cause | ||
261 | * hardware damage. | ||
262 | * 5-3 unused in some models. Extra bits for fan level | ||
263 | * in others, but still useless as all values above | ||
264 | * 7 map to the same speed as level 7 in these models. | ||
265 | * 2-0 fan level (0..7 usually) | ||
266 | * 0x00 = stop | ||
267 | * 0x07 = max (set when temperatures critical) | ||
268 | * Some ThinkPads may have other levels, see | ||
269 | * IBMACPI_FAN_WR_ACPI_FANS (X31/X40/X41) | ||
270 | * | ||
271 | * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at | ||
272 | * boot. Apparently the EC does not intialize it, so unless ACPI DSDT | ||
273 | * does so, its initial value is meaningless (0x07). | ||
274 | * | ||
275 | * For firmware bugs, refer to: | ||
276 | * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues | ||
277 | * | ||
278 | * ---- | ||
279 | * | ||
280 | * ThinkPad EC register 0x84 (LSB), 0x85 (MSB): | ||
281 | * Main fan tachometer reading (in RPM) | ||
282 | * | ||
283 | * This register is present on all ThinkPads with a new-style EC, and | ||
284 | * it is known not to be present on the A21m/e, and T22, as there is | ||
285 | * something else in offset 0x84 according to the ACPI DSDT. Other | ||
286 | * ThinkPads from this same time period (and earlier) probably lack the | ||
287 | * tachometer as well. | ||
288 | * | ||
289 | * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare | ||
290 | * was never fixed by IBM to report the EC firmware version string | ||
291 | * probably support the tachometer (like the early X models), so | ||
292 | * detecting it is quite hard. We need more data to know for sure. | ||
293 | * | ||
294 | * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings | ||
295 | * might result. | ||
296 | * | ||
297 | * FIRMWARE BUG: when EC 0x2f bit 6 is set (disengaged mode), this | ||
298 | * register is not invalidated in ThinkPads that disable tachometer | ||
299 | * readings. Thus, the tachometer readings go stale. | ||
300 | * | ||
301 | * For firmware bugs, refer to: | ||
302 | * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues | ||
303 | * | ||
304 | * IBMACPI_FAN_WR_ACPI_FANS: | ||
305 | * ThinkPad X31, X40, X41. Not available in the X60. | ||
306 | * | ||
307 | * FANS ACPI handle: takes three arguments: low speed, medium speed, | ||
308 | * high speed. ACPI DSDT seems to map these three speeds to levels | ||
309 | * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH | ||
310 | * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3") | ||
311 | * | ||
312 | * The speeds are stored on handles | ||
313 | * (FANA:FAN9), (FANC:FANB), (FANE:FAND). | ||
314 | * | ||
315 | * There are three default speed sets, acessible as handles: | ||
316 | * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H | ||
317 | * | ||
318 | * ACPI DSDT switches which set is in use depending on various | ||
319 | * factors. | ||
320 | * | ||
321 | * IBMACPI_FAN_WR_TPEC is also available and should be used to | ||
322 | * command the fan. The X31/X40/X41 seems to have 8 fan levels, | ||
323 | * but the ACPI tables just mention level 7. | ||
324 | */ | ||
325 | |||
326 | enum fan_status_access_mode { | ||
327 | IBMACPI_FAN_NONE = 0, /* No fan status or control */ | ||
328 | IBMACPI_FAN_RD_ACPI_GFAN, /* Use ACPI GFAN */ | ||
329 | IBMACPI_FAN_RD_TPEC, /* Use ACPI EC regs 0x2f, 0x84-0x85 */ | ||
330 | }; | ||
331 | |||
332 | enum fan_control_access_mode { | ||
333 | IBMACPI_FAN_WR_NONE = 0, /* No fan control */ | ||
334 | IBMACPI_FAN_WR_ACPI_SFAN, /* Use ACPI SFAN */ | ||
335 | IBMACPI_FAN_WR_TPEC, /* Use ACPI EC reg 0x2f */ | ||
336 | IBMACPI_FAN_WR_ACPI_FANS, /* Use ACPI FANS and EC reg 0x2f */ | ||
337 | }; | ||
338 | |||
339 | enum fan_control_commands { | ||
340 | IBMACPI_FAN_CMD_SPEED = 0x0001, /* speed command */ | ||
341 | IBMACPI_FAN_CMD_LEVEL = 0x0002, /* level command */ | ||
342 | IBMACPI_FAN_CMD_ENABLE = 0x0004, /* enable/disable cmd, | ||
343 | * and also watchdog cmd */ | ||
344 | }; | ||
345 | |||
346 | enum { /* Fan control constants */ | ||
347 | fan_status_offset = 0x2f, /* EC register 0x2f */ | ||
348 | fan_rpm_offset = 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM) | ||
349 | * 0x84 must be read before 0x85 */ | ||
350 | |||
351 | IBMACPI_FAN_EC_DISENGAGED = 0x40, /* EC mode: tachometer | ||
352 | * disengaged */ | ||
353 | IBMACPI_FAN_EC_AUTO = 0x80, /* EC mode: auto fan | ||
354 | * control */ | ||
355 | }; | ||
356 | |||
357 | static char *ibm_thinkpad_ec_found = NULL; | ||
358 | |||
359 | struct ibm_struct { | ||
360 | char *name; | ||
361 | char param[32]; | ||
362 | |||
363 | char *hid; | ||
364 | struct acpi_driver *driver; | ||
365 | |||
366 | int (*init) (void); | ||
367 | int (*read) (char *); | ||
368 | int (*write) (char *); | ||
369 | void (*exit) (void); | ||
370 | |||
371 | void (*notify) (struct ibm_struct *, u32); | ||
372 | acpi_handle *handle; | ||
373 | int type; | ||
374 | struct acpi_device *device; | ||
375 | |||
376 | int driver_registered; | ||
377 | int proc_created; | ||
378 | int init_called; | ||
379 | int notify_installed; | ||
380 | |||
381 | int experimental; | ||
382 | }; | ||
383 | |||
384 | static struct proc_dir_entry *proc_dir = NULL; | ||
385 | |||
386 | static struct backlight_device *ibm_backlight_device = NULL; | ||
387 | |||
388 | #define onoff(status,bit) ((status) & (1 << (bit)) ? "on" : "off") | ||
389 | #define enabled(status,bit) ((status) & (1 << (bit)) ? "enabled" : "disabled") | ||
390 | #define strlencmp(a,b) (strncmp((a), (b), strlen(b))) | ||
391 | |||
392 | static int acpi_evalf(acpi_handle handle, | ||
393 | void *res, char *method, char *fmt, ...) | ||
394 | { | ||
395 | char *fmt0 = fmt; | ||
396 | struct acpi_object_list params; | ||
397 | union acpi_object in_objs[IBM_MAX_ACPI_ARGS]; | ||
398 | struct acpi_buffer result, *resultp; | ||
399 | union acpi_object out_obj; | ||
400 | acpi_status status; | ||
401 | va_list ap; | ||
402 | char res_type; | ||
403 | int success; | ||
404 | int quiet; | ||
405 | |||
406 | if (!*fmt) { | ||
407 | printk(IBM_ERR "acpi_evalf() called with empty format\n"); | ||
408 | return 0; | ||
409 | } | ||
410 | |||
411 | if (*fmt == 'q') { | ||
412 | quiet = 1; | ||
413 | fmt++; | ||
414 | } else | ||
415 | quiet = 0; | ||
416 | |||
417 | res_type = *(fmt++); | ||
418 | |||
419 | params.count = 0; | ||
420 | params.pointer = &in_objs[0]; | ||
421 | |||
422 | va_start(ap, fmt); | ||
423 | while (*fmt) { | ||
424 | char c = *(fmt++); | ||
425 | switch (c) { | ||
426 | case 'd': /* int */ | ||
427 | in_objs[params.count].integer.value = va_arg(ap, int); | ||
428 | in_objs[params.count++].type = ACPI_TYPE_INTEGER; | ||
429 | break; | ||
430 | /* add more types as needed */ | ||
431 | default: | ||
432 | printk(IBM_ERR "acpi_evalf() called " | ||
433 | "with invalid format character '%c'\n", c); | ||
434 | return 0; | ||
435 | } | ||
436 | } | ||
437 | va_end(ap); | ||
438 | |||
439 | if (res_type != 'v') { | ||
440 | result.length = sizeof(out_obj); | ||
441 | result.pointer = &out_obj; | ||
442 | resultp = &result; | ||
443 | } else | ||
444 | resultp = NULL; | ||
445 | |||
446 | status = acpi_evaluate_object(handle, method, ¶ms, resultp); | ||
447 | |||
448 | switch (res_type) { | ||
449 | case 'd': /* int */ | ||
450 | if (res) | ||
451 | *(int *)res = out_obj.integer.value; | ||
452 | success = status == AE_OK && out_obj.type == ACPI_TYPE_INTEGER; | ||
453 | break; | ||
454 | case 'v': /* void */ | ||
455 | success = status == AE_OK; | ||
456 | break; | ||
457 | /* add more types as needed */ | ||
458 | default: | ||
459 | printk(IBM_ERR "acpi_evalf() called " | ||
460 | "with invalid format character '%c'\n", res_type); | ||
461 | return 0; | ||
462 | } | ||
463 | |||
464 | if (!success && !quiet) | ||
465 | printk(IBM_ERR "acpi_evalf(%s, %s, ...) failed: %d\n", | ||
466 | method, fmt0, status); | ||
467 | |||
468 | return success; | ||
469 | } | ||
470 | |||
471 | static void __unused acpi_print_int(acpi_handle handle, char *method) | ||
472 | { | ||
473 | int i; | ||
474 | |||
475 | if (acpi_evalf(handle, &i, method, "d")) | ||
476 | printk(IBM_INFO "%s = 0x%x\n", method, i); | ||
477 | else | ||
478 | printk(IBM_ERR "error calling %s\n", method); | ||
479 | } | ||
480 | |||
481 | static char *next_cmd(char **cmds) | ||
482 | { | ||
483 | char *start = *cmds; | ||
484 | char *end; | ||
485 | |||
486 | while ((end = strchr(start, ',')) && end == start) | ||
487 | start = end + 1; | ||
488 | |||
489 | if (!end) | ||
490 | return NULL; | ||
491 | |||
492 | *end = 0; | ||
493 | *cmds = end + 1; | ||
494 | return start; | ||
495 | } | ||
496 | |||
497 | static int ibm_acpi_driver_init(void) | ||
498 | { | ||
499 | printk(IBM_INFO "%s v%s\n", IBM_DESC, IBM_VERSION); | ||
500 | printk(IBM_INFO "%s\n", IBM_URL); | ||
501 | |||
502 | if (ibm_thinkpad_ec_found) | ||
503 | printk(IBM_INFO "ThinkPad EC firmware %s\n", | ||
504 | ibm_thinkpad_ec_found); | ||
505 | |||
506 | return 0; | ||
507 | } | ||
508 | |||
509 | static int driver_read(char *p) | ||
510 | { | ||
511 | int len = 0; | ||
512 | |||
513 | len += sprintf(p + len, "driver:\t\t%s\n", IBM_DESC); | ||
514 | len += sprintf(p + len, "version:\t%s\n", IBM_VERSION); | ||
515 | |||
516 | return len; | ||
517 | } | ||
518 | |||
519 | static int hotkey_supported; | ||
520 | static int hotkey_mask_supported; | ||
521 | static int hotkey_orig_status; | ||
522 | static int hotkey_orig_mask; | ||
523 | |||
524 | static int hotkey_get(int *status, int *mask) | ||
525 | { | ||
526 | if (!acpi_evalf(hkey_handle, status, "DHKC", "d")) | ||
527 | return 0; | ||
528 | |||
529 | if (hotkey_mask_supported) | ||
530 | if (!acpi_evalf(hkey_handle, mask, "DHKN", "d")) | ||
531 | return 0; | ||
532 | |||
533 | return 1; | ||
534 | } | ||
535 | |||
536 | static int hotkey_set(int status, int mask) | ||
537 | { | ||
538 | int i; | ||
539 | |||
540 | if (!acpi_evalf(hkey_handle, NULL, "MHKC", "vd", status)) | ||
541 | return 0; | ||
542 | |||
543 | if (hotkey_mask_supported) | ||
544 | for (i = 0; i < 32; i++) { | ||
545 | int bit = ((1 << i) & mask) != 0; | ||
546 | if (!acpi_evalf(hkey_handle, | ||
547 | NULL, "MHKM", "vdd", i + 1, bit)) | ||
548 | return 0; | ||
549 | } | ||
550 | |||
551 | return 1; | ||
552 | } | ||
553 | |||
554 | static int hotkey_init(void) | ||
555 | { | ||
556 | /* hotkey not supported on 570 */ | ||
557 | hotkey_supported = hkey_handle != NULL; | ||
558 | |||
559 | if (hotkey_supported) { | ||
560 | /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, | ||
561 | A30, R30, R31, T20-22, X20-21, X22-24 */ | ||
562 | hotkey_mask_supported = | ||
563 | acpi_evalf(hkey_handle, NULL, "DHKN", "qv"); | ||
564 | |||
565 | if (!hotkey_get(&hotkey_orig_status, &hotkey_orig_mask)) | ||
566 | return -ENODEV; | ||
567 | } | ||
568 | |||
569 | return 0; | ||
570 | } | ||
571 | |||
572 | static int hotkey_read(char *p) | ||
573 | { | ||
574 | int status, mask; | ||
575 | int len = 0; | ||
576 | |||
577 | if (!hotkey_supported) { | ||
578 | len += sprintf(p + len, "status:\t\tnot supported\n"); | ||
579 | return len; | ||
580 | } | ||
581 | |||
582 | if (!hotkey_get(&status, &mask)) | ||
583 | return -EIO; | ||
584 | |||
585 | len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 0)); | ||
586 | if (hotkey_mask_supported) { | ||
587 | len += sprintf(p + len, "mask:\t\t0x%04x\n", mask); | ||
588 | len += sprintf(p + len, | ||
589 | "commands:\tenable, disable, reset, <mask>\n"); | ||
590 | } else { | ||
591 | len += sprintf(p + len, "mask:\t\tnot supported\n"); | ||
592 | len += sprintf(p + len, "commands:\tenable, disable, reset\n"); | ||
593 | } | ||
594 | |||
595 | return len; | ||
596 | } | ||
597 | |||
598 | static int hotkey_write(char *buf) | ||
599 | { | ||
600 | int status, mask; | ||
601 | char *cmd; | ||
602 | int do_cmd = 0; | ||
603 | |||
604 | if (!hotkey_supported) | ||
605 | return -ENODEV; | ||
606 | |||
607 | if (!hotkey_get(&status, &mask)) | ||
608 | return -EIO; | ||
609 | |||
610 | while ((cmd = next_cmd(&buf))) { | ||
611 | if (strlencmp(cmd, "enable") == 0) { | ||
612 | status = 1; | ||
613 | } else if (strlencmp(cmd, "disable") == 0) { | ||
614 | status = 0; | ||
615 | } else if (strlencmp(cmd, "reset") == 0) { | ||
616 | status = hotkey_orig_status; | ||
617 | mask = hotkey_orig_mask; | ||
618 | } else if (sscanf(cmd, "0x%x", &mask) == 1) { | ||
619 | /* mask set */ | ||
620 | } else if (sscanf(cmd, "%x", &mask) == 1) { | ||
621 | /* mask set */ | ||
622 | } else | ||
623 | return -EINVAL; | ||
624 | do_cmd = 1; | ||
625 | } | ||
626 | |||
627 | if (do_cmd && !hotkey_set(status, mask)) | ||
628 | return -EIO; | ||
629 | |||
630 | return 0; | ||
631 | } | ||
632 | |||
633 | static void hotkey_exit(void) | ||
634 | { | ||
635 | if (hotkey_supported) | ||
636 | hotkey_set(hotkey_orig_status, hotkey_orig_mask); | ||
637 | } | ||
638 | |||
639 | static void hotkey_notify(struct ibm_struct *ibm, u32 event) | ||
640 | { | ||
641 | int hkey; | ||
642 | |||
643 | if (acpi_evalf(hkey_handle, &hkey, "MHKP", "d")) | ||
644 | acpi_bus_generate_event(ibm->device, event, hkey); | ||
645 | else { | ||
646 | printk(IBM_ERR "unknown hotkey event %d\n", event); | ||
647 | acpi_bus_generate_event(ibm->device, event, 0); | ||
648 | } | ||
649 | } | ||
650 | |||
651 | static int bluetooth_supported; | ||
652 | |||
653 | static int bluetooth_init(void) | ||
654 | { | ||
655 | /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, | ||
656 | G4x, R30, R31, R40e, R50e, T20-22, X20-21 */ | ||
657 | bluetooth_supported = hkey_handle && | ||
658 | acpi_evalf(hkey_handle, NULL, "GBDC", "qv"); | ||
659 | |||
660 | return 0; | ||
661 | } | ||
662 | |||
663 | static int bluetooth_status(void) | ||
664 | { | ||
665 | int status; | ||
666 | |||
667 | if (!bluetooth_supported || | ||
668 | !acpi_evalf(hkey_handle, &status, "GBDC", "d")) | ||
669 | status = 0; | ||
670 | |||
671 | return status; | ||
672 | } | ||
673 | |||
674 | static int bluetooth_read(char *p) | ||
675 | { | ||
676 | int len = 0; | ||
677 | int status = bluetooth_status(); | ||
678 | |||
679 | if (!bluetooth_supported) | ||
680 | len += sprintf(p + len, "status:\t\tnot supported\n"); | ||
681 | else if (!(status & 1)) | ||
682 | len += sprintf(p + len, "status:\t\tnot installed\n"); | ||
683 | else { | ||
684 | len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 1)); | ||
685 | len += sprintf(p + len, "commands:\tenable, disable\n"); | ||
686 | } | ||
687 | |||
688 | return len; | ||
689 | } | ||
690 | |||
691 | static int bluetooth_write(char *buf) | ||
692 | { | ||
693 | int status = bluetooth_status(); | ||
694 | char *cmd; | ||
695 | int do_cmd = 0; | ||
696 | |||
697 | if (!bluetooth_supported) | ||
698 | return -ENODEV; | ||
699 | |||
700 | while ((cmd = next_cmd(&buf))) { | ||
701 | if (strlencmp(cmd, "enable") == 0) { | ||
702 | status |= 2; | ||
703 | } else if (strlencmp(cmd, "disable") == 0) { | ||
704 | status &= ~2; | ||
705 | } else | ||
706 | return -EINVAL; | ||
707 | do_cmd = 1; | ||
708 | } | ||
709 | |||
710 | if (do_cmd && !acpi_evalf(hkey_handle, NULL, "SBDC", "vd", status)) | ||
711 | return -EIO; | ||
712 | |||
713 | return 0; | ||
714 | } | ||
715 | |||
716 | static int wan_supported; | ||
717 | |||
718 | static int wan_init(void) | ||
719 | { | ||
720 | wan_supported = hkey_handle && | ||
721 | acpi_evalf(hkey_handle, NULL, "GWAN", "qv"); | ||
722 | |||
723 | return 0; | ||
724 | } | ||
725 | |||
726 | static int wan_status(void) | ||
727 | { | ||
728 | int status; | ||
729 | |||
730 | if (!wan_supported || !acpi_evalf(hkey_handle, &status, "GWAN", "d")) | ||
731 | status = 0; | ||
732 | |||
733 | return status; | ||
734 | } | ||
735 | |||
736 | static int wan_read(char *p) | ||
737 | { | ||
738 | int len = 0; | ||
739 | int status = wan_status(); | ||
740 | |||
741 | if (!wan_supported) | ||
742 | len += sprintf(p + len, "status:\t\tnot supported\n"); | ||
743 | else if (!(status & 1)) | ||
744 | len += sprintf(p + len, "status:\t\tnot installed\n"); | ||
745 | else { | ||
746 | len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 1)); | ||
747 | len += sprintf(p + len, "commands:\tenable, disable\n"); | ||
748 | } | ||
749 | |||
750 | return len; | ||
751 | } | ||
752 | |||
753 | static int wan_write(char *buf) | ||
754 | { | ||
755 | int status = wan_status(); | ||
756 | char *cmd; | ||
757 | int do_cmd = 0; | ||
758 | |||
759 | if (!wan_supported) | ||
760 | return -ENODEV; | ||
761 | |||
762 | while ((cmd = next_cmd(&buf))) { | ||
763 | if (strlencmp(cmd, "enable") == 0) { | ||
764 | status |= 2; | ||
765 | } else if (strlencmp(cmd, "disable") == 0) { | ||
766 | status &= ~2; | ||
767 | } else | ||
768 | return -EINVAL; | ||
769 | do_cmd = 1; | ||
770 | } | ||
771 | |||
772 | if (do_cmd && !acpi_evalf(hkey_handle, NULL, "SWAN", "vd", status)) | ||
773 | return -EIO; | ||
774 | |||
775 | return 0; | ||
776 | } | ||
777 | |||
778 | enum video_access_mode { | ||
779 | IBMACPI_VIDEO_NONE = 0, | ||
780 | IBMACPI_VIDEO_570, /* 570 */ | ||
781 | IBMACPI_VIDEO_770, /* 600e/x, 770e, 770x */ | ||
782 | IBMACPI_VIDEO_NEW, /* all others */ | ||
783 | }; | ||
784 | |||
785 | static enum video_access_mode video_supported; | ||
786 | static int video_orig_autosw; | ||
787 | |||
788 | static int video_init(void) | ||
789 | { | ||
790 | int ivga; | ||
791 | |||
792 | if (vid2_handle && acpi_evalf(NULL, &ivga, "\\IVGA", "d") && ivga) | ||
793 | /* G41, assume IVGA doesn't change */ | ||
794 | vid_handle = vid2_handle; | ||
795 | |||
796 | if (!vid_handle) | ||
797 | /* video switching not supported on R30, R31 */ | ||
798 | video_supported = IBMACPI_VIDEO_NONE; | ||
799 | else if (acpi_evalf(vid_handle, &video_orig_autosw, "SWIT", "qd")) | ||
800 | /* 570 */ | ||
801 | video_supported = IBMACPI_VIDEO_570; | ||
802 | else if (acpi_evalf(vid_handle, &video_orig_autosw, "^VADL", "qd")) | ||
803 | /* 600e/x, 770e, 770x */ | ||
804 | video_supported = IBMACPI_VIDEO_770; | ||
805 | else | ||
806 | /* all others */ | ||
807 | video_supported = IBMACPI_VIDEO_NEW; | ||
808 | |||
809 | return 0; | ||
810 | } | ||
811 | |||
812 | static int video_status(void) | ||
813 | { | ||
814 | int status = 0; | ||
815 | int i; | ||
816 | |||
817 | if (video_supported == IBMACPI_VIDEO_570) { | ||
818 | if (acpi_evalf(NULL, &i, "\\_SB.PHS", "dd", 0x87)) | ||
819 | status = i & 3; | ||
820 | } else if (video_supported == IBMACPI_VIDEO_770) { | ||
821 | if (acpi_evalf(NULL, &i, "\\VCDL", "d")) | ||
822 | status |= 0x01 * i; | ||
823 | if (acpi_evalf(NULL, &i, "\\VCDC", "d")) | ||
824 | status |= 0x02 * i; | ||
825 | } else if (video_supported == IBMACPI_VIDEO_NEW) { | ||
826 | acpi_evalf(NULL, NULL, "\\VUPS", "vd", 1); | ||
827 | if (acpi_evalf(NULL, &i, "\\VCDC", "d")) | ||
828 | status |= 0x02 * i; | ||
829 | |||
830 | acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0); | ||
831 | if (acpi_evalf(NULL, &i, "\\VCDL", "d")) | ||
832 | status |= 0x01 * i; | ||
833 | if (acpi_evalf(NULL, &i, "\\VCDD", "d")) | ||
834 | status |= 0x08 * i; | ||
835 | } | ||
836 | |||
837 | return status; | ||
838 | } | ||
839 | |||
840 | static int video_autosw(void) | ||
841 | { | ||
842 | int autosw = 0; | ||
843 | |||
844 | if (video_supported == IBMACPI_VIDEO_570) | ||
845 | acpi_evalf(vid_handle, &autosw, "SWIT", "d"); | ||
846 | else if (video_supported == IBMACPI_VIDEO_770 || | ||
847 | video_supported == IBMACPI_VIDEO_NEW) | ||
848 | acpi_evalf(vid_handle, &autosw, "^VDEE", "d"); | ||
849 | |||
850 | return autosw & 1; | ||
851 | } | ||
852 | |||
853 | static int video_read(char *p) | ||
854 | { | ||
855 | int status = video_status(); | ||
856 | int autosw = video_autosw(); | ||
857 | int len = 0; | ||
858 | |||
859 | if (!video_supported) { | ||
860 | len += sprintf(p + len, "status:\t\tnot supported\n"); | ||
861 | return len; | ||
862 | } | ||
863 | |||
864 | len += sprintf(p + len, "status:\t\tsupported\n"); | ||
865 | len += sprintf(p + len, "lcd:\t\t%s\n", enabled(status, 0)); | ||
866 | len += sprintf(p + len, "crt:\t\t%s\n", enabled(status, 1)); | ||
867 | if (video_supported == IBMACPI_VIDEO_NEW) | ||
868 | len += sprintf(p + len, "dvi:\t\t%s\n", enabled(status, 3)); | ||
869 | len += sprintf(p + len, "auto:\t\t%s\n", enabled(autosw, 0)); | ||
870 | len += sprintf(p + len, "commands:\tlcd_enable, lcd_disable\n"); | ||
871 | len += sprintf(p + len, "commands:\tcrt_enable, crt_disable\n"); | ||
872 | if (video_supported == IBMACPI_VIDEO_NEW) | ||
873 | len += sprintf(p + len, "commands:\tdvi_enable, dvi_disable\n"); | ||
874 | len += sprintf(p + len, "commands:\tauto_enable, auto_disable\n"); | ||
875 | len += sprintf(p + len, "commands:\tvideo_switch, expand_toggle\n"); | ||
876 | |||
877 | return len; | ||
878 | } | ||
879 | |||
880 | static int video_switch(void) | ||
881 | { | ||
882 | int autosw = video_autosw(); | ||
883 | int ret; | ||
884 | |||
885 | if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 1)) | ||
886 | return -EIO; | ||
887 | ret = video_supported == IBMACPI_VIDEO_570 ? | ||
888 | acpi_evalf(ec_handle, NULL, "_Q16", "v") : | ||
889 | acpi_evalf(vid_handle, NULL, "VSWT", "v"); | ||
890 | acpi_evalf(vid_handle, NULL, "_DOS", "vd", autosw); | ||
891 | |||
892 | return ret; | ||
893 | } | ||
894 | |||
895 | static int video_expand(void) | ||
896 | { | ||
897 | if (video_supported == IBMACPI_VIDEO_570) | ||
898 | return acpi_evalf(ec_handle, NULL, "_Q17", "v"); | ||
899 | else if (video_supported == IBMACPI_VIDEO_770) | ||
900 | return acpi_evalf(vid_handle, NULL, "VEXP", "v"); | ||
901 | else | ||
902 | return acpi_evalf(NULL, NULL, "\\VEXP", "v"); | ||
903 | } | ||
904 | |||
905 | static int video_switch2(int status) | ||
906 | { | ||
907 | int ret; | ||
908 | |||
909 | if (video_supported == IBMACPI_VIDEO_570) { | ||
910 | ret = acpi_evalf(NULL, NULL, | ||
911 | "\\_SB.PHS2", "vdd", 0x8b, status | 0x80); | ||
912 | } else if (video_supported == IBMACPI_VIDEO_770) { | ||
913 | int autosw = video_autosw(); | ||
914 | if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 1)) | ||
915 | return -EIO; | ||
916 | |||
917 | ret = acpi_evalf(vid_handle, NULL, | ||
918 | "ASWT", "vdd", status * 0x100, 0); | ||
919 | |||
920 | acpi_evalf(vid_handle, NULL, "_DOS", "vd", autosw); | ||
921 | } else { | ||
922 | ret = acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0x80) && | ||
923 | acpi_evalf(NULL, NULL, "\\VSDS", "vdd", status, 1); | ||
924 | } | ||
925 | |||
926 | return ret; | ||
927 | } | ||
928 | |||
929 | static int video_write(char *buf) | ||
930 | { | ||
931 | char *cmd; | ||
932 | int enable, disable, status; | ||
933 | |||
934 | if (!video_supported) | ||
935 | return -ENODEV; | ||
936 | |||
937 | enable = disable = 0; | ||
938 | |||
939 | while ((cmd = next_cmd(&buf))) { | ||
940 | if (strlencmp(cmd, "lcd_enable") == 0) { | ||
941 | enable |= 0x01; | ||
942 | } else if (strlencmp(cmd, "lcd_disable") == 0) { | ||
943 | disable |= 0x01; | ||
944 | } else if (strlencmp(cmd, "crt_enable") == 0) { | ||
945 | enable |= 0x02; | ||
946 | } else if (strlencmp(cmd, "crt_disable") == 0) { | ||
947 | disable |= 0x02; | ||
948 | } else if (video_supported == IBMACPI_VIDEO_NEW && | ||
949 | strlencmp(cmd, "dvi_enable") == 0) { | ||
950 | enable |= 0x08; | ||
951 | } else if (video_supported == IBMACPI_VIDEO_NEW && | ||
952 | strlencmp(cmd, "dvi_disable") == 0) { | ||
953 | disable |= 0x08; | ||
954 | } else if (strlencmp(cmd, "auto_enable") == 0) { | ||
955 | if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 1)) | ||
956 | return -EIO; | ||
957 | } else if (strlencmp(cmd, "auto_disable") == 0) { | ||
958 | if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 0)) | ||
959 | return -EIO; | ||
960 | } else if (strlencmp(cmd, "video_switch") == 0) { | ||
961 | if (!video_switch()) | ||
962 | return -EIO; | ||
963 | } else if (strlencmp(cmd, "expand_toggle") == 0) { | ||
964 | if (!video_expand()) | ||
965 | return -EIO; | ||
966 | } else | ||
967 | return -EINVAL; | ||
968 | } | ||
969 | |||
970 | if (enable || disable) { | ||
971 | status = (video_status() & 0x0f & ~disable) | enable; | ||
972 | if (!video_switch2(status)) | ||
973 | return -EIO; | ||
974 | } | ||
975 | |||
976 | return 0; | ||
977 | } | ||
978 | |||
979 | static void video_exit(void) | ||
980 | { | ||
981 | acpi_evalf(vid_handle, NULL, "_DOS", "vd", video_orig_autosw); | ||
982 | } | ||
983 | |||
984 | static int light_supported; | ||
985 | static int light_status_supported; | ||
986 | |||
987 | static int light_init(void) | ||
988 | { | ||
989 | /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */ | ||
990 | light_supported = (cmos_handle || lght_handle) && !ledb_handle; | ||
991 | |||
992 | if (light_supported) | ||
993 | /* light status not supported on | ||
994 | 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */ | ||
995 | light_status_supported = acpi_evalf(ec_handle, NULL, | ||
996 | "KBLT", "qv"); | ||
997 | |||
998 | return 0; | ||
999 | } | ||
1000 | |||
1001 | static int light_read(char *p) | ||
1002 | { | ||
1003 | int len = 0; | ||
1004 | int status = 0; | ||
1005 | |||
1006 | if (!light_supported) { | ||
1007 | len += sprintf(p + len, "status:\t\tnot supported\n"); | ||
1008 | } else if (!light_status_supported) { | ||
1009 | len += sprintf(p + len, "status:\t\tunknown\n"); | ||
1010 | len += sprintf(p + len, "commands:\ton, off\n"); | ||
1011 | } else { | ||
1012 | if (!acpi_evalf(ec_handle, &status, "KBLT", "d")) | ||
1013 | return -EIO; | ||
1014 | len += sprintf(p + len, "status:\t\t%s\n", onoff(status, 0)); | ||
1015 | len += sprintf(p + len, "commands:\ton, off\n"); | ||
1016 | } | ||
1017 | |||
1018 | return len; | ||
1019 | } | ||
1020 | |||
1021 | static int light_write(char *buf) | ||
1022 | { | ||
1023 | int cmos_cmd, lght_cmd; | ||
1024 | char *cmd; | ||
1025 | int success; | ||
1026 | |||
1027 | if (!light_supported) | ||
1028 | return -ENODEV; | ||
1029 | |||
1030 | while ((cmd = next_cmd(&buf))) { | ||
1031 | if (strlencmp(cmd, "on") == 0) { | ||
1032 | cmos_cmd = 0x0c; | ||
1033 | lght_cmd = 1; | ||
1034 | } else if (strlencmp(cmd, "off") == 0) { | ||
1035 | cmos_cmd = 0x0d; | ||
1036 | lght_cmd = 0; | ||
1037 | } else | ||
1038 | return -EINVAL; | ||
1039 | |||
1040 | success = cmos_handle ? | ||
1041 | acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd) : | ||
1042 | acpi_evalf(lght_handle, NULL, NULL, "vd", lght_cmd); | ||
1043 | if (!success) | ||
1044 | return -EIO; | ||
1045 | } | ||
1046 | |||
1047 | return 0; | ||
1048 | } | ||
1049 | |||
1050 | #if defined(CONFIG_ACPI_IBM_DOCK) || defined(CONFIG_ACPI_IBM_BAY) | ||
1051 | static int _sta(acpi_handle handle) | ||
1052 | { | ||
1053 | int status; | ||
1054 | |||
1055 | if (!handle || !acpi_evalf(handle, &status, "_STA", "d")) | ||
1056 | status = 0; | ||
1057 | |||
1058 | return status; | ||
1059 | } | ||
1060 | #endif | ||
1061 | |||
1062 | #ifdef CONFIG_ACPI_IBM_DOCK | ||
1063 | #define dock_docked() (_sta(dock_handle) & 1) | ||
1064 | |||
1065 | static int dock_read(char *p) | ||
1066 | { | ||
1067 | int len = 0; | ||
1068 | int docked = dock_docked(); | ||
1069 | |||
1070 | if (!dock_handle) | ||
1071 | len += sprintf(p + len, "status:\t\tnot supported\n"); | ||
1072 | else if (!docked) | ||
1073 | len += sprintf(p + len, "status:\t\tundocked\n"); | ||
1074 | else { | ||
1075 | len += sprintf(p + len, "status:\t\tdocked\n"); | ||
1076 | len += sprintf(p + len, "commands:\tdock, undock\n"); | ||
1077 | } | ||
1078 | |||
1079 | return len; | ||
1080 | } | ||
1081 | |||
1082 | static int dock_write(char *buf) | ||
1083 | { | ||
1084 | char *cmd; | ||
1085 | |||
1086 | if (!dock_docked()) | ||
1087 | return -ENODEV; | ||
1088 | |||
1089 | while ((cmd = next_cmd(&buf))) { | ||
1090 | if (strlencmp(cmd, "undock") == 0) { | ||
1091 | if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 0) || | ||
1092 | !acpi_evalf(dock_handle, NULL, "_EJ0", "vd", 1)) | ||
1093 | return -EIO; | ||
1094 | } else if (strlencmp(cmd, "dock") == 0) { | ||
1095 | if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 1)) | ||
1096 | return -EIO; | ||
1097 | } else | ||
1098 | return -EINVAL; | ||
1099 | } | ||
1100 | |||
1101 | return 0; | ||
1102 | } | ||
1103 | |||
1104 | static void dock_notify(struct ibm_struct *ibm, u32 event) | ||
1105 | { | ||
1106 | int docked = dock_docked(); | ||
1107 | int pci = ibm->hid && strstr(ibm->hid, IBM_PCI_HID); | ||
1108 | |||
1109 | if (event == 1 && !pci) /* 570 */ | ||
1110 | acpi_bus_generate_event(ibm->device, event, 1); /* button */ | ||
1111 | else if (event == 1 && pci) /* 570 */ | ||
1112 | acpi_bus_generate_event(ibm->device, event, 3); /* dock */ | ||
1113 | else if (event == 3 && docked) | ||
1114 | acpi_bus_generate_event(ibm->device, event, 1); /* button */ | ||
1115 | else if (event == 3 && !docked) | ||
1116 | acpi_bus_generate_event(ibm->device, event, 2); /* undock */ | ||
1117 | else if (event == 0 && docked) | ||
1118 | acpi_bus_generate_event(ibm->device, event, 3); /* dock */ | ||
1119 | else { | ||
1120 | printk(IBM_ERR "unknown dock event %d, status %d\n", | ||
1121 | event, _sta(dock_handle)); | ||
1122 | acpi_bus_generate_event(ibm->device, event, 0); /* unknown */ | ||
1123 | } | ||
1124 | } | ||
1125 | #endif | ||
1126 | |||
1127 | #ifdef CONFIG_ACPI_IBM_BAY | ||
1128 | static int bay_status_supported; | ||
1129 | static int bay_status2_supported; | ||
1130 | static int bay_eject_supported; | ||
1131 | static int bay_eject2_supported; | ||
1132 | |||
1133 | static int bay_init(void) | ||
1134 | { | ||
1135 | bay_status_supported = bay_handle && | ||
1136 | acpi_evalf(bay_handle, NULL, "_STA", "qv"); | ||
1137 | bay_status2_supported = bay2_handle && | ||
1138 | acpi_evalf(bay2_handle, NULL, "_STA", "qv"); | ||
1139 | |||
1140 | bay_eject_supported = bay_handle && bay_ej_handle && | ||
1141 | (strlencmp(bay_ej_path, "_EJ0") == 0 || experimental); | ||
1142 | bay_eject2_supported = bay2_handle && bay2_ej_handle && | ||
1143 | (strlencmp(bay2_ej_path, "_EJ0") == 0 || experimental); | ||
1144 | |||
1145 | return 0; | ||
1146 | } | ||
1147 | |||
1148 | #define bay_occupied(b) (_sta(b##_handle) & 1) | ||
1149 | |||
1150 | static int bay_read(char *p) | ||
1151 | { | ||
1152 | int len = 0; | ||
1153 | int occupied = bay_occupied(bay); | ||
1154 | int occupied2 = bay_occupied(bay2); | ||
1155 | int eject, eject2; | ||
1156 | |||
1157 | len += sprintf(p + len, "status:\t\t%s\n", bay_status_supported ? | ||
1158 | (occupied ? "occupied" : "unoccupied") : | ||
1159 | "not supported"); | ||
1160 | if (bay_status2_supported) | ||
1161 | len += sprintf(p + len, "status2:\t%s\n", occupied2 ? | ||
1162 | "occupied" : "unoccupied"); | ||
1163 | |||
1164 | eject = bay_eject_supported && occupied; | ||
1165 | eject2 = bay_eject2_supported && occupied2; | ||
1166 | |||
1167 | if (eject && eject2) | ||
1168 | len += sprintf(p + len, "commands:\teject, eject2\n"); | ||
1169 | else if (eject) | ||
1170 | len += sprintf(p + len, "commands:\teject\n"); | ||
1171 | else if (eject2) | ||
1172 | len += sprintf(p + len, "commands:\teject2\n"); | ||
1173 | |||
1174 | return len; | ||
1175 | } | ||
1176 | |||
1177 | static int bay_write(char *buf) | ||
1178 | { | ||
1179 | char *cmd; | ||
1180 | |||
1181 | if (!bay_eject_supported && !bay_eject2_supported) | ||
1182 | return -ENODEV; | ||
1183 | |||
1184 | while ((cmd = next_cmd(&buf))) { | ||
1185 | if (bay_eject_supported && strlencmp(cmd, "eject") == 0) { | ||
1186 | if (!acpi_evalf(bay_ej_handle, NULL, NULL, "vd", 1)) | ||
1187 | return -EIO; | ||
1188 | } else if (bay_eject2_supported && | ||
1189 | strlencmp(cmd, "eject2") == 0) { | ||
1190 | if (!acpi_evalf(bay2_ej_handle, NULL, NULL, "vd", 1)) | ||
1191 | return -EIO; | ||
1192 | } else | ||
1193 | return -EINVAL; | ||
1194 | } | ||
1195 | |||
1196 | return 0; | ||
1197 | } | ||
1198 | |||
1199 | static void bay_notify(struct ibm_struct *ibm, u32 event) | ||
1200 | { | ||
1201 | acpi_bus_generate_event(ibm->device, event, 0); | ||
1202 | } | ||
1203 | #endif /* CONFIG_ACPI_IBM_BAY */ | ||
1204 | |||
1205 | static int cmos_read(char *p) | ||
1206 | { | ||
1207 | int len = 0; | ||
1208 | |||
1209 | /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, | ||
1210 | R30, R31, T20-22, X20-21 */ | ||
1211 | if (!cmos_handle) | ||
1212 | len += sprintf(p + len, "status:\t\tnot supported\n"); | ||
1213 | else { | ||
1214 | len += sprintf(p + len, "status:\t\tsupported\n"); | ||
1215 | len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-21)\n"); | ||
1216 | } | ||
1217 | |||
1218 | return len; | ||
1219 | } | ||
1220 | |||
1221 | static int cmos_eval(int cmos_cmd) | ||
1222 | { | ||
1223 | if (cmos_handle) | ||
1224 | return acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd); | ||
1225 | else | ||
1226 | return 1; | ||
1227 | } | ||
1228 | |||
1229 | static int cmos_write(char *buf) | ||
1230 | { | ||
1231 | char *cmd; | ||
1232 | int cmos_cmd; | ||
1233 | |||
1234 | if (!cmos_handle) | ||
1235 | return -EINVAL; | ||
1236 | |||
1237 | while ((cmd = next_cmd(&buf))) { | ||
1238 | if (sscanf(cmd, "%u", &cmos_cmd) == 1 && | ||
1239 | cmos_cmd >= 0 && cmos_cmd <= 21) { | ||
1240 | /* cmos_cmd set */ | ||
1241 | } else | ||
1242 | return -EINVAL; | ||
1243 | |||
1244 | if (!cmos_eval(cmos_cmd)) | ||
1245 | return -EIO; | ||
1246 | } | ||
1247 | |||
1248 | return 0; | ||
1249 | } | ||
1250 | |||
1251 | enum led_access_mode { | ||
1252 | IBMACPI_LED_NONE = 0, | ||
1253 | IBMACPI_LED_570, /* 570 */ | ||
1254 | IBMACPI_LED_OLD, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */ | ||
1255 | IBMACPI_LED_NEW, /* all others */ | ||
1256 | }; | ||
1257 | static enum led_access_mode led_supported; | ||
1258 | |||
1259 | static int led_init(void) | ||
1260 | { | ||
1261 | if (!led_handle) | ||
1262 | /* led not supported on R30, R31 */ | ||
1263 | led_supported = IBMACPI_LED_NONE; | ||
1264 | else if (strlencmp(led_path, "SLED") == 0) | ||
1265 | /* 570 */ | ||
1266 | led_supported = IBMACPI_LED_570; | ||
1267 | else if (strlencmp(led_path, "SYSL") == 0) | ||
1268 | /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */ | ||
1269 | led_supported = IBMACPI_LED_OLD; | ||
1270 | else | ||
1271 | /* all others */ | ||
1272 | led_supported = IBMACPI_LED_NEW; | ||
1273 | |||
1274 | return 0; | ||
1275 | } | ||
1276 | |||
1277 | #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking")) | ||
1278 | |||
1279 | static int led_read(char *p) | ||
1280 | { | ||
1281 | int len = 0; | ||
1282 | |||
1283 | if (!led_supported) { | ||
1284 | len += sprintf(p + len, "status:\t\tnot supported\n"); | ||
1285 | return len; | ||
1286 | } | ||
1287 | len += sprintf(p + len, "status:\t\tsupported\n"); | ||
1288 | |||
1289 | if (led_supported == IBMACPI_LED_570) { | ||
1290 | /* 570 */ | ||
1291 | int i, status; | ||
1292 | for (i = 0; i < 8; i++) { | ||
1293 | if (!acpi_evalf(ec_handle, | ||
1294 | &status, "GLED", "dd", 1 << i)) | ||
1295 | return -EIO; | ||
1296 | len += sprintf(p + len, "%d:\t\t%s\n", | ||
1297 | i, led_status(status)); | ||
1298 | } | ||
1299 | } | ||
1300 | |||
1301 | len += sprintf(p + len, "commands:\t" | ||
1302 | "<led> on, <led> off, <led> blink (<led> is 0-7)\n"); | ||
1303 | |||
1304 | return len; | ||
1305 | } | ||
1306 | |||
1307 | /* off, on, blink */ | ||
1308 | static const int led_sled_arg1[] = { 0, 1, 3 }; | ||
1309 | static const int led_exp_hlbl[] = { 0, 0, 1 }; /* led# * */ | ||
1310 | static const int led_exp_hlcl[] = { 0, 1, 1 }; /* led# * */ | ||
1311 | static const int led_led_arg1[] = { 0, 0x80, 0xc0 }; | ||
1312 | |||
1313 | #define EC_HLCL 0x0c | ||
1314 | #define EC_HLBL 0x0d | ||
1315 | #define EC_HLMS 0x0e | ||
1316 | |||
1317 | static int led_write(char *buf) | ||
1318 | { | ||
1319 | char *cmd; | ||
1320 | int led, ind, ret; | ||
1321 | |||
1322 | if (!led_supported) | ||
1323 | return -ENODEV; | ||
1324 | |||
1325 | while ((cmd = next_cmd(&buf))) { | ||
1326 | if (sscanf(cmd, "%d", &led) != 1 || led < 0 || led > 7) | ||
1327 | return -EINVAL; | ||
1328 | |||
1329 | if (strstr(cmd, "off")) { | ||
1330 | ind = 0; | ||
1331 | } else if (strstr(cmd, "on")) { | ||
1332 | ind = 1; | ||
1333 | } else if (strstr(cmd, "blink")) { | ||
1334 | ind = 2; | ||
1335 | } else | ||
1336 | return -EINVAL; | ||
1337 | |||
1338 | if (led_supported == IBMACPI_LED_570) { | ||
1339 | /* 570 */ | ||
1340 | led = 1 << led; | ||
1341 | if (!acpi_evalf(led_handle, NULL, NULL, "vdd", | ||
1342 | led, led_sled_arg1[ind])) | ||
1343 | return -EIO; | ||
1344 | } else if (led_supported == IBMACPI_LED_OLD) { | ||
1345 | /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */ | ||
1346 | led = 1 << led; | ||
1347 | ret = ec_write(EC_HLMS, led); | ||
1348 | if (ret >= 0) | ||
1349 | ret = | ||
1350 | ec_write(EC_HLBL, led * led_exp_hlbl[ind]); | ||
1351 | if (ret >= 0) | ||
1352 | ret = | ||
1353 | ec_write(EC_HLCL, led * led_exp_hlcl[ind]); | ||
1354 | if (ret < 0) | ||
1355 | return ret; | ||
1356 | } else { | ||
1357 | /* all others */ | ||
1358 | if (!acpi_evalf(led_handle, NULL, NULL, "vdd", | ||
1359 | led, led_led_arg1[ind])) | ||
1360 | return -EIO; | ||
1361 | } | ||
1362 | } | ||
1363 | |||
1364 | return 0; | ||
1365 | } | ||
1366 | |||
1367 | static int beep_read(char *p) | ||
1368 | { | ||
1369 | int len = 0; | ||
1370 | |||
1371 | if (!beep_handle) | ||
1372 | len += sprintf(p + len, "status:\t\tnot supported\n"); | ||
1373 | else { | ||
1374 | len += sprintf(p + len, "status:\t\tsupported\n"); | ||
1375 | len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-17)\n"); | ||
1376 | } | ||
1377 | |||
1378 | return len; | ||
1379 | } | ||
1380 | |||
1381 | static int beep_write(char *buf) | ||
1382 | { | ||
1383 | char *cmd; | ||
1384 | int beep_cmd; | ||
1385 | |||
1386 | if (!beep_handle) | ||
1387 | return -ENODEV; | ||
1388 | |||
1389 | while ((cmd = next_cmd(&buf))) { | ||
1390 | if (sscanf(cmd, "%u", &beep_cmd) == 1 && | ||
1391 | beep_cmd >= 0 && beep_cmd <= 17) { | ||
1392 | /* beep_cmd set */ | ||
1393 | } else | ||
1394 | return -EINVAL; | ||
1395 | if (!acpi_evalf(beep_handle, NULL, NULL, "vdd", beep_cmd, 0)) | ||
1396 | return -EIO; | ||
1397 | } | ||
1398 | |||
1399 | return 0; | ||
1400 | } | ||
1401 | |||
1402 | static int acpi_ec_read(int i, u8 * p) | ||
1403 | { | ||
1404 | int v; | ||
1405 | |||
1406 | if (ecrd_handle) { | ||
1407 | if (!acpi_evalf(ecrd_handle, &v, NULL, "dd", i)) | ||
1408 | return 0; | ||
1409 | *p = v; | ||
1410 | } else { | ||
1411 | if (ec_read(i, p) < 0) | ||
1412 | return 0; | ||
1413 | } | ||
1414 | |||
1415 | return 1; | ||
1416 | } | ||
1417 | |||
1418 | static int acpi_ec_write(int i, u8 v) | ||
1419 | { | ||
1420 | if (ecwr_handle) { | ||
1421 | if (!acpi_evalf(ecwr_handle, NULL, NULL, "vdd", i, v)) | ||
1422 | return 0; | ||
1423 | } else { | ||
1424 | if (ec_write(i, v) < 0) | ||
1425 | return 0; | ||
1426 | } | ||
1427 | |||
1428 | return 1; | ||
1429 | } | ||
1430 | |||
1431 | static enum thermal_access_mode thermal_read_mode; | ||
1432 | |||
1433 | static int thermal_init(void) | ||
1434 | { | ||
1435 | u8 t, ta1, ta2; | ||
1436 | int i; | ||
1437 | int acpi_tmp7 = acpi_evalf(ec_handle, NULL, "TMP7", "qv"); | ||
1438 | |||
1439 | if (ibm_thinkpad_ec_found && experimental) { | ||
1440 | /* | ||
1441 | * Direct EC access mode: sensors at registers | ||
1442 | * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for | ||
1443 | * non-implemented, thermal sensors return 0x80 when | ||
1444 | * not available | ||
1445 | */ | ||
1446 | |||
1447 | ta1 = ta2 = 0; | ||
1448 | for (i = 0; i < 8; i++) { | ||
1449 | if (likely(acpi_ec_read(0x78 + i, &t))) { | ||
1450 | ta1 |= t; | ||
1451 | } else { | ||
1452 | ta1 = 0; | ||
1453 | break; | ||
1454 | } | ||
1455 | if (likely(acpi_ec_read(0xC0 + i, &t))) { | ||
1456 | ta2 |= t; | ||
1457 | } else { | ||
1458 | ta1 = 0; | ||
1459 | break; | ||
1460 | } | ||
1461 | } | ||
1462 | if (ta1 == 0) { | ||
1463 | /* This is sheer paranoia, but we handle it anyway */ | ||
1464 | if (acpi_tmp7) { | ||
1465 | printk(IBM_ERR | ||
1466 | "ThinkPad ACPI EC access misbehaving, " | ||
1467 | "falling back to ACPI TMPx access mode\n"); | ||
1468 | thermal_read_mode = IBMACPI_THERMAL_ACPI_TMP07; | ||
1469 | } else { | ||
1470 | printk(IBM_ERR | ||
1471 | "ThinkPad ACPI EC access misbehaving, " | ||
1472 | "disabling thermal sensors access\n"); | ||
1473 | thermal_read_mode = IBMACPI_THERMAL_NONE; | ||
1474 | } | ||
1475 | } else { | ||
1476 | thermal_read_mode = | ||
1477 | (ta2 != 0) ? | ||
1478 | IBMACPI_THERMAL_TPEC_16 : IBMACPI_THERMAL_TPEC_8; | ||
1479 | } | ||
1480 | } else if (acpi_tmp7) { | ||
1481 | if (acpi_evalf(ec_handle, NULL, "UPDT", "qv")) { | ||
1482 | /* 600e/x, 770e, 770x */ | ||
1483 | thermal_read_mode = IBMACPI_THERMAL_ACPI_UPDT; | ||
1484 | } else { | ||
1485 | /* Standard ACPI TMPx access, max 8 sensors */ | ||
1486 | thermal_read_mode = IBMACPI_THERMAL_ACPI_TMP07; | ||
1487 | } | ||
1488 | } else { | ||
1489 | /* temperatures not supported on 570, G4x, R30, R31, R32 */ | ||
1490 | thermal_read_mode = IBMACPI_THERMAL_NONE; | ||
1491 | } | ||
1492 | |||
1493 | return 0; | ||
1494 | } | ||
1495 | |||
1496 | static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s) | ||
1497 | { | ||
1498 | int i, t; | ||
1499 | s8 tmp; | ||
1500 | char tmpi[] = "TMPi"; | ||
1501 | |||
1502 | if (!s) | ||
1503 | return -EINVAL; | ||
1504 | |||
1505 | switch (thermal_read_mode) { | ||
1506 | #if IBMACPI_MAX_THERMAL_SENSORS >= 16 | ||
1507 | case IBMACPI_THERMAL_TPEC_16: | ||
1508 | for (i = 0; i < 8; i++) { | ||
1509 | if (!acpi_ec_read(0xC0 + i, &tmp)) | ||
1510 | return -EIO; | ||
1511 | s->temp[i + 8] = tmp * 1000; | ||
1512 | } | ||
1513 | /* fallthrough */ | ||
1514 | #endif | ||
1515 | case IBMACPI_THERMAL_TPEC_8: | ||
1516 | for (i = 0; i < 8; i++) { | ||
1517 | if (!acpi_ec_read(0x78 + i, &tmp)) | ||
1518 | return -EIO; | ||
1519 | s->temp[i] = tmp * 1000; | ||
1520 | } | ||
1521 | return (thermal_read_mode == IBMACPI_THERMAL_TPEC_16) ? 16 : 8; | ||
1522 | |||
1523 | case IBMACPI_THERMAL_ACPI_UPDT: | ||
1524 | if (!acpi_evalf(ec_handle, NULL, "UPDT", "v")) | ||
1525 | return -EIO; | ||
1526 | for (i = 0; i < 8; i++) { | ||
1527 | tmpi[3] = '0' + i; | ||
1528 | if (!acpi_evalf(ec_handle, &t, tmpi, "d")) | ||
1529 | return -EIO; | ||
1530 | s->temp[i] = (t - 2732) * 100; | ||
1531 | } | ||
1532 | return 8; | ||
1533 | |||
1534 | case IBMACPI_THERMAL_ACPI_TMP07: | ||
1535 | for (i = 0; i < 8; i++) { | ||
1536 | tmpi[3] = '0' + i; | ||
1537 | if (!acpi_evalf(ec_handle, &t, tmpi, "d")) | ||
1538 | return -EIO; | ||
1539 | s->temp[i] = t * 1000; | ||
1540 | } | ||
1541 | return 8; | ||
1542 | |||
1543 | case IBMACPI_THERMAL_NONE: | ||
1544 | default: | ||
1545 | return 0; | ||
1546 | } | ||
1547 | } | ||
1548 | |||
1549 | static int thermal_read(char *p) | ||
1550 | { | ||
1551 | int len = 0; | ||
1552 | int n, i; | ||
1553 | struct ibm_thermal_sensors_struct t; | ||
1554 | |||
1555 | n = thermal_get_sensors(&t); | ||
1556 | if (unlikely(n < 0)) | ||
1557 | return n; | ||
1558 | |||
1559 | len += sprintf(p + len, "temperatures:\t"); | ||
1560 | |||
1561 | if (n > 0) { | ||
1562 | for (i = 0; i < (n - 1); i++) | ||
1563 | len += sprintf(p + len, "%d ", t.temp[i] / 1000); | ||
1564 | len += sprintf(p + len, "%d\n", t.temp[i] / 1000); | ||
1565 | } else | ||
1566 | len += sprintf(p + len, "not supported\n"); | ||
1567 | |||
1568 | return len; | ||
1569 | } | ||
1570 | |||
1571 | static u8 ecdump_regs[256]; | ||
1572 | |||
1573 | static int ecdump_read(char *p) | ||
1574 | { | ||
1575 | int len = 0; | ||
1576 | int i, j; | ||
1577 | u8 v; | ||
1578 | |||
1579 | len += sprintf(p + len, "EC " | ||
1580 | " +00 +01 +02 +03 +04 +05 +06 +07" | ||
1581 | " +08 +09 +0a +0b +0c +0d +0e +0f\n"); | ||
1582 | for (i = 0; i < 256; i += 16) { | ||
1583 | len += sprintf(p + len, "EC 0x%02x:", i); | ||
1584 | for (j = 0; j < 16; j++) { | ||
1585 | if (!acpi_ec_read(i + j, &v)) | ||
1586 | break; | ||
1587 | if (v != ecdump_regs[i + j]) | ||
1588 | len += sprintf(p + len, " *%02x", v); | ||
1589 | else | ||
1590 | len += sprintf(p + len, " %02x", v); | ||
1591 | ecdump_regs[i + j] = v; | ||
1592 | } | ||
1593 | len += sprintf(p + len, "\n"); | ||
1594 | if (j != 16) | ||
1595 | break; | ||
1596 | } | ||
1597 | |||
1598 | /* These are way too dangerous to advertise openly... */ | ||
1599 | #if 0 | ||
1600 | len += sprintf(p + len, "commands:\t0x<offset> 0x<value>" | ||
1601 | " (<offset> is 00-ff, <value> is 00-ff)\n"); | ||
1602 | len += sprintf(p + len, "commands:\t0x<offset> <value> " | ||
1603 | " (<offset> is 00-ff, <value> is 0-255)\n"); | ||
1604 | #endif | ||
1605 | return len; | ||
1606 | } | ||
1607 | |||
1608 | static int ecdump_write(char *buf) | ||
1609 | { | ||
1610 | char *cmd; | ||
1611 | int i, v; | ||
1612 | |||
1613 | while ((cmd = next_cmd(&buf))) { | ||
1614 | if (sscanf(cmd, "0x%x 0x%x", &i, &v) == 2) { | ||
1615 | /* i and v set */ | ||
1616 | } else if (sscanf(cmd, "0x%x %u", &i, &v) == 2) { | ||
1617 | /* i and v set */ | ||
1618 | } else | ||
1619 | return -EINVAL; | ||
1620 | if (i >= 0 && i < 256 && v >= 0 && v < 256) { | ||
1621 | if (!acpi_ec_write(i, v)) | ||
1622 | return -EIO; | ||
1623 | } else | ||
1624 | return -EINVAL; | ||
1625 | } | ||
1626 | |||
1627 | return 0; | ||
1628 | } | ||
1629 | |||
1630 | static int brightness_offset = 0x31; | ||
1631 | |||
1632 | static int brightness_get(struct backlight_device *bd) | ||
1633 | { | ||
1634 | u8 level; | ||
1635 | if (!acpi_ec_read(brightness_offset, &level)) | ||
1636 | return -EIO; | ||
1637 | |||
1638 | level &= 0x7; | ||
1639 | |||
1640 | return level; | ||
1641 | } | ||
1642 | |||
1643 | static int brightness_read(char *p) | ||
1644 | { | ||
1645 | int len = 0; | ||
1646 | int level; | ||
1647 | |||
1648 | if ((level = brightness_get(NULL)) < 0) { | ||
1649 | len += sprintf(p + len, "level:\t\tunreadable\n"); | ||
1650 | } else { | ||
1651 | len += sprintf(p + len, "level:\t\t%d\n", level & 0x7); | ||
1652 | len += sprintf(p + len, "commands:\tup, down\n"); | ||
1653 | len += sprintf(p + len, "commands:\tlevel <level>" | ||
1654 | " (<level> is 0-7)\n"); | ||
1655 | } | ||
1656 | |||
1657 | return len; | ||
1658 | } | ||
1659 | |||
1660 | #define BRIGHTNESS_UP 4 | ||
1661 | #define BRIGHTNESS_DOWN 5 | ||
1662 | |||
1663 | static int brightness_set(int value) | ||
1664 | { | ||
1665 | int cmos_cmd, inc, i; | ||
1666 | int current_value = brightness_get(NULL); | ||
1667 | |||
1668 | value &= 7; | ||
1669 | |||
1670 | cmos_cmd = value > current_value ? BRIGHTNESS_UP : BRIGHTNESS_DOWN; | ||
1671 | inc = value > current_value ? 1 : -1; | ||
1672 | for (i = current_value; i != value; i += inc) { | ||
1673 | if (!cmos_eval(cmos_cmd)) | ||
1674 | return -EIO; | ||
1675 | if (!acpi_ec_write(brightness_offset, i + inc)) | ||
1676 | return -EIO; | ||
1677 | } | ||
1678 | |||
1679 | return 0; | ||
1680 | } | ||
1681 | |||
1682 | static int brightness_write(char *buf) | ||
1683 | { | ||
1684 | int level; | ||
1685 | int new_level; | ||
1686 | char *cmd; | ||
1687 | |||
1688 | while ((cmd = next_cmd(&buf))) { | ||
1689 | if ((level = brightness_get(NULL)) < 0) | ||
1690 | return level; | ||
1691 | level &= 7; | ||
1692 | |||
1693 | if (strlencmp(cmd, "up") == 0) { | ||
1694 | new_level = level == 7 ? 7 : level + 1; | ||
1695 | } else if (strlencmp(cmd, "down") == 0) { | ||
1696 | new_level = level == 0 ? 0 : level - 1; | ||
1697 | } else if (sscanf(cmd, "level %d", &new_level) == 1 && | ||
1698 | new_level >= 0 && new_level <= 7) { | ||
1699 | /* new_level set */ | ||
1700 | } else | ||
1701 | return -EINVAL; | ||
1702 | |||
1703 | brightness_set(new_level); | ||
1704 | } | ||
1705 | |||
1706 | return 0; | ||
1707 | } | ||
1708 | |||
1709 | static int brightness_update_status(struct backlight_device *bd) | ||
1710 | { | ||
1711 | return brightness_set( | ||
1712 | (bd->props.fb_blank == FB_BLANK_UNBLANK && | ||
1713 | bd->props.power == FB_BLANK_UNBLANK) ? | ||
1714 | bd->props.brightness : 0); | ||
1715 | } | ||
1716 | |||
1717 | static struct backlight_ops ibm_backlight_data = { | ||
1718 | .get_brightness = brightness_get, | ||
1719 | .update_status = brightness_update_status, | ||
1720 | }; | ||
1721 | |||
1722 | static int brightness_init(void) | ||
1723 | { | ||
1724 | int b; | ||
1725 | |||
1726 | b = brightness_get(NULL); | ||
1727 | if (b < 0) | ||
1728 | return b; | ||
1729 | |||
1730 | ibm_backlight_device = backlight_device_register("ibm", NULL, NULL, | ||
1731 | &ibm_backlight_data); | ||
1732 | if (IS_ERR(ibm_backlight_device)) { | ||
1733 | printk(IBM_ERR "Could not register backlight device\n"); | ||
1734 | return PTR_ERR(ibm_backlight_device); | ||
1735 | } | ||
1736 | |||
1737 | ibm_backlight_device->props.max_brightness = 7; | ||
1738 | ibm_backlight_device->props.brightness = b; | ||
1739 | backlight_update_status(ibm_backlight_device); | ||
1740 | |||
1741 | return 0; | ||
1742 | } | ||
1743 | |||
1744 | static void brightness_exit(void) | ||
1745 | { | ||
1746 | if (ibm_backlight_device) { | ||
1747 | backlight_device_unregister(ibm_backlight_device); | ||
1748 | ibm_backlight_device = NULL; | ||
1749 | } | ||
1750 | } | ||
1751 | |||
1752 | static int volume_offset = 0x30; | ||
1753 | |||
1754 | static int volume_read(char *p) | ||
1755 | { | ||
1756 | int len = 0; | ||
1757 | u8 level; | ||
1758 | |||
1759 | if (!acpi_ec_read(volume_offset, &level)) { | ||
1760 | len += sprintf(p + len, "level:\t\tunreadable\n"); | ||
1761 | } else { | ||
1762 | len += sprintf(p + len, "level:\t\t%d\n", level & 0xf); | ||
1763 | len += sprintf(p + len, "mute:\t\t%s\n", onoff(level, 6)); | ||
1764 | len += sprintf(p + len, "commands:\tup, down, mute\n"); | ||
1765 | len += sprintf(p + len, "commands:\tlevel <level>" | ||
1766 | " (<level> is 0-15)\n"); | ||
1767 | } | ||
1768 | |||
1769 | return len; | ||
1770 | } | ||
1771 | |||
1772 | #define VOLUME_DOWN 0 | ||
1773 | #define VOLUME_UP 1 | ||
1774 | #define VOLUME_MUTE 2 | ||
1775 | |||
1776 | static int volume_write(char *buf) | ||
1777 | { | ||
1778 | int cmos_cmd, inc, i; | ||
1779 | u8 level, mute; | ||
1780 | int new_level, new_mute; | ||
1781 | char *cmd; | ||
1782 | |||
1783 | while ((cmd = next_cmd(&buf))) { | ||
1784 | if (!acpi_ec_read(volume_offset, &level)) | ||
1785 | return -EIO; | ||
1786 | new_mute = mute = level & 0x40; | ||
1787 | new_level = level = level & 0xf; | ||
1788 | |||
1789 | if (strlencmp(cmd, "up") == 0) { | ||
1790 | if (mute) | ||
1791 | new_mute = 0; | ||
1792 | else | ||
1793 | new_level = level == 15 ? 15 : level + 1; | ||
1794 | } else if (strlencmp(cmd, "down") == 0) { | ||
1795 | if (mute) | ||
1796 | new_mute = 0; | ||
1797 | else | ||
1798 | new_level = level == 0 ? 0 : level - 1; | ||
1799 | } else if (sscanf(cmd, "level %d", &new_level) == 1 && | ||
1800 | new_level >= 0 && new_level <= 15) { | ||
1801 | /* new_level set */ | ||
1802 | } else if (strlencmp(cmd, "mute") == 0) { | ||
1803 | new_mute = 0x40; | ||
1804 | } else | ||
1805 | return -EINVAL; | ||
1806 | |||
1807 | if (new_level != level) { /* mute doesn't change */ | ||
1808 | cmos_cmd = new_level > level ? VOLUME_UP : VOLUME_DOWN; | ||
1809 | inc = new_level > level ? 1 : -1; | ||
1810 | |||
1811 | if (mute && (!cmos_eval(cmos_cmd) || | ||
1812 | !acpi_ec_write(volume_offset, level))) | ||
1813 | return -EIO; | ||
1814 | |||
1815 | for (i = level; i != new_level; i += inc) | ||
1816 | if (!cmos_eval(cmos_cmd) || | ||
1817 | !acpi_ec_write(volume_offset, i + inc)) | ||
1818 | return -EIO; | ||
1819 | |||
1820 | if (mute && (!cmos_eval(VOLUME_MUTE) || | ||
1821 | !acpi_ec_write(volume_offset, | ||
1822 | new_level + mute))) | ||
1823 | return -EIO; | ||
1824 | } | ||
1825 | |||
1826 | if (new_mute != mute) { /* level doesn't change */ | ||
1827 | cmos_cmd = new_mute ? VOLUME_MUTE : VOLUME_UP; | ||
1828 | |||
1829 | if (!cmos_eval(cmos_cmd) || | ||
1830 | !acpi_ec_write(volume_offset, level + new_mute)) | ||
1831 | return -EIO; | ||
1832 | } | ||
1833 | } | ||
1834 | |||
1835 | return 0; | ||
1836 | } | ||
1837 | |||
1838 | static enum fan_status_access_mode fan_status_access_mode; | ||
1839 | static enum fan_control_access_mode fan_control_access_mode; | ||
1840 | static enum fan_control_commands fan_control_commands; | ||
1841 | |||
1842 | static int fan_control_status_known; | ||
1843 | static u8 fan_control_initial_status; | ||
1844 | |||
1845 | static void fan_watchdog_fire(struct work_struct *ignored); | ||
1846 | static int fan_watchdog_maxinterval; | ||
1847 | static DECLARE_DELAYED_WORK(fan_watchdog_task, fan_watchdog_fire); | ||
1848 | |||
1849 | static int fan_init(void) | ||
1850 | { | ||
1851 | fan_status_access_mode = IBMACPI_FAN_NONE; | ||
1852 | fan_control_access_mode = IBMACPI_FAN_WR_NONE; | ||
1853 | fan_control_commands = 0; | ||
1854 | fan_control_status_known = 1; | ||
1855 | fan_watchdog_maxinterval = 0; | ||
1856 | |||
1857 | if (gfan_handle) { | ||
1858 | /* 570, 600e/x, 770e, 770x */ | ||
1859 | fan_status_access_mode = IBMACPI_FAN_RD_ACPI_GFAN; | ||
1860 | } else { | ||
1861 | /* all other ThinkPads: note that even old-style | ||
1862 | * ThinkPad ECs supports the fan control register */ | ||
1863 | if (likely(acpi_ec_read(fan_status_offset, | ||
1864 | &fan_control_initial_status))) { | ||
1865 | fan_status_access_mode = IBMACPI_FAN_RD_TPEC; | ||
1866 | |||
1867 | /* In some ThinkPads, neither the EC nor the ACPI | ||
1868 | * DSDT initialize the fan status, and it ends up | ||
1869 | * being set to 0x07 when it *could* be either | ||
1870 | * 0x07 or 0x80. | ||
1871 | * | ||
1872 | * Enable for TP-1Y (T43), TP-78 (R51e), | ||
1873 | * TP-76 (R52), TP-70 (T43, R52), which are known | ||
1874 | * to be buggy. */ | ||
1875 | if (fan_control_initial_status == 0x07 && | ||
1876 | ibm_thinkpad_ec_found && | ||
1877 | ((ibm_thinkpad_ec_found[0] == '1' && | ||
1878 | ibm_thinkpad_ec_found[1] == 'Y') || | ||
1879 | (ibm_thinkpad_ec_found[0] == '7' && | ||
1880 | (ibm_thinkpad_ec_found[1] == '6' || | ||
1881 | ibm_thinkpad_ec_found[1] == '8' || | ||
1882 | ibm_thinkpad_ec_found[1] == '0')) | ||
1883 | )) { | ||
1884 | printk(IBM_NOTICE | ||
1885 | "fan_init: initial fan status is " | ||
1886 | "unknown, assuming it is in auto " | ||
1887 | "mode\n"); | ||
1888 | fan_control_status_known = 0; | ||
1889 | } | ||
1890 | } else { | ||
1891 | printk(IBM_ERR | ||
1892 | "ThinkPad ACPI EC access misbehaving, " | ||
1893 | "fan status and control unavailable\n"); | ||
1894 | return 0; | ||
1895 | } | ||
1896 | } | ||
1897 | |||
1898 | if (sfan_handle) { | ||
1899 | /* 570, 770x-JL */ | ||
1900 | fan_control_access_mode = IBMACPI_FAN_WR_ACPI_SFAN; | ||
1901 | fan_control_commands |= | ||
1902 | IBMACPI_FAN_CMD_LEVEL | IBMACPI_FAN_CMD_ENABLE; | ||
1903 | } else { | ||
1904 | if (!gfan_handle) { | ||
1905 | /* gfan without sfan means no fan control */ | ||
1906 | /* all other models implement TP EC 0x2f control */ | ||
1907 | |||
1908 | if (fans_handle) { | ||
1909 | /* X31, X40, X41 */ | ||
1910 | fan_control_access_mode = | ||
1911 | IBMACPI_FAN_WR_ACPI_FANS; | ||
1912 | fan_control_commands |= | ||
1913 | IBMACPI_FAN_CMD_SPEED | | ||
1914 | IBMACPI_FAN_CMD_LEVEL | | ||
1915 | IBMACPI_FAN_CMD_ENABLE; | ||
1916 | } else { | ||
1917 | fan_control_access_mode = IBMACPI_FAN_WR_TPEC; | ||
1918 | fan_control_commands |= | ||
1919 | IBMACPI_FAN_CMD_LEVEL | | ||
1920 | IBMACPI_FAN_CMD_ENABLE; | ||
1921 | } | ||
1922 | } | ||
1923 | } | ||
1924 | |||
1925 | return 0; | ||
1926 | } | ||
1927 | |||
1928 | static int fan_get_status(u8 *status) | ||
1929 | { | ||
1930 | u8 s; | ||
1931 | |||
1932 | /* TODO: | ||
1933 | * Add IBMACPI_FAN_RD_ACPI_FANS ? */ | ||
1934 | |||
1935 | switch (fan_status_access_mode) { | ||
1936 | case IBMACPI_FAN_RD_ACPI_GFAN: | ||
1937 | /* 570, 600e/x, 770e, 770x */ | ||
1938 | |||
1939 | if (unlikely(!acpi_evalf(gfan_handle, &s, NULL, "d"))) | ||
1940 | return -EIO; | ||
1941 | |||
1942 | if (likely(status)) | ||
1943 | *status = s & 0x07; | ||
1944 | |||
1945 | break; | ||
1946 | |||
1947 | case IBMACPI_FAN_RD_TPEC: | ||
1948 | /* all except 570, 600e/x, 770e, 770x */ | ||
1949 | if (unlikely(!acpi_ec_read(fan_status_offset, &s))) | ||
1950 | return -EIO; | ||
1951 | |||
1952 | if (likely(status)) | ||
1953 | *status = s; | ||
1954 | |||
1955 | break; | ||
1956 | |||
1957 | default: | ||
1958 | return -ENXIO; | ||
1959 | } | ||
1960 | |||
1961 | return 0; | ||
1962 | } | ||
1963 | |||
1964 | static int fan_get_speed(unsigned int *speed) | ||
1965 | { | ||
1966 | u8 hi, lo; | ||
1967 | |||
1968 | switch (fan_status_access_mode) { | ||
1969 | case IBMACPI_FAN_RD_TPEC: | ||
1970 | /* all except 570, 600e/x, 770e, 770x */ | ||
1971 | if (unlikely(!acpi_ec_read(fan_rpm_offset, &lo) || | ||
1972 | !acpi_ec_read(fan_rpm_offset + 1, &hi))) | ||
1973 | return -EIO; | ||
1974 | |||
1975 | if (likely(speed)) | ||
1976 | *speed = (hi << 8) | lo; | ||
1977 | |||
1978 | break; | ||
1979 | |||
1980 | default: | ||
1981 | return -ENXIO; | ||
1982 | } | ||
1983 | |||
1984 | return 0; | ||
1985 | } | ||
1986 | |||
1987 | static void fan_exit(void) | ||
1988 | { | ||
1989 | cancel_delayed_work(&fan_watchdog_task); | ||
1990 | flush_scheduled_work(); | ||
1991 | } | ||
1992 | |||
1993 | static void fan_watchdog_reset(void) | ||
1994 | { | ||
1995 | static int fan_watchdog_active = 0; | ||
1996 | |||
1997 | if (fan_watchdog_active) | ||
1998 | cancel_delayed_work(&fan_watchdog_task); | ||
1999 | |||
2000 | if (fan_watchdog_maxinterval > 0) { | ||
2001 | fan_watchdog_active = 1; | ||
2002 | if (!schedule_delayed_work(&fan_watchdog_task, | ||
2003 | msecs_to_jiffies(fan_watchdog_maxinterval | ||
2004 | * 1000))) { | ||
2005 | printk(IBM_ERR "failed to schedule the fan watchdog, " | ||
2006 | "watchdog will not trigger\n"); | ||
2007 | } | ||
2008 | } else | ||
2009 | fan_watchdog_active = 0; | ||
2010 | } | ||
2011 | |||
2012 | static int fan_read(char *p) | ||
2013 | { | ||
2014 | int len = 0; | ||
2015 | int rc; | ||
2016 | u8 status; | ||
2017 | unsigned int speed = 0; | ||
2018 | |||
2019 | switch (fan_status_access_mode) { | ||
2020 | case IBMACPI_FAN_RD_ACPI_GFAN: | ||
2021 | /* 570, 600e/x, 770e, 770x */ | ||
2022 | if ((rc = fan_get_status(&status)) < 0) | ||
2023 | return rc; | ||
2024 | |||
2025 | len += sprintf(p + len, "status:\t\t%s\n" | ||
2026 | "level:\t\t%d\n", | ||
2027 | (status != 0) ? "enabled" : "disabled", status); | ||
2028 | break; | ||
2029 | |||
2030 | case IBMACPI_FAN_RD_TPEC: | ||
2031 | /* all except 570, 600e/x, 770e, 770x */ | ||
2032 | if ((rc = fan_get_status(&status)) < 0) | ||
2033 | return rc; | ||
2034 | |||
2035 | if (unlikely(!fan_control_status_known)) { | ||
2036 | if (status != fan_control_initial_status) | ||
2037 | fan_control_status_known = 1; | ||
2038 | else | ||
2039 | /* Return most likely status. In fact, it | ||
2040 | * might be the only possible status */ | ||
2041 | status = IBMACPI_FAN_EC_AUTO; | ||
2042 | } | ||
2043 | |||
2044 | len += sprintf(p + len, "status:\t\t%s\n", | ||
2045 | (status != 0) ? "enabled" : "disabled"); | ||
2046 | |||
2047 | /* No ThinkPad boots on disengaged mode, we can safely | ||
2048 | * assume the tachometer is online if fan control status | ||
2049 | * was unknown */ | ||
2050 | if ((rc = fan_get_speed(&speed)) < 0) | ||
2051 | return rc; | ||
2052 | |||
2053 | len += sprintf(p + len, "speed:\t\t%d\n", speed); | ||
2054 | |||
2055 | if (status & IBMACPI_FAN_EC_DISENGAGED) | ||
2056 | /* Disengaged mode takes precedence */ | ||
2057 | len += sprintf(p + len, "level:\t\tdisengaged\n"); | ||
2058 | else if (status & IBMACPI_FAN_EC_AUTO) | ||
2059 | len += sprintf(p + len, "level:\t\tauto\n"); | ||
2060 | else | ||
2061 | len += sprintf(p + len, "level:\t\t%d\n", status); | ||
2062 | break; | ||
2063 | |||
2064 | case IBMACPI_FAN_NONE: | ||
2065 | default: | ||
2066 | len += sprintf(p + len, "status:\t\tnot supported\n"); | ||
2067 | } | ||
2068 | |||
2069 | if (fan_control_commands & IBMACPI_FAN_CMD_LEVEL) { | ||
2070 | len += sprintf(p + len, "commands:\tlevel <level>"); | ||
2071 | |||
2072 | switch (fan_control_access_mode) { | ||
2073 | case IBMACPI_FAN_WR_ACPI_SFAN: | ||
2074 | len += sprintf(p + len, " (<level> is 0-7)\n"); | ||
2075 | break; | ||
2076 | |||
2077 | default: | ||
2078 | len += sprintf(p + len, " (<level> is 0-7, " | ||
2079 | "auto, disengaged)\n"); | ||
2080 | break; | ||
2081 | } | ||
2082 | } | ||
2083 | |||
2084 | if (fan_control_commands & IBMACPI_FAN_CMD_ENABLE) | ||
2085 | len += sprintf(p + len, "commands:\tenable, disable\n" | ||
2086 | "commands:\twatchdog <timeout> (<timeout> is 0 (off), " | ||
2087 | "1-120 (seconds))\n"); | ||
2088 | |||
2089 | if (fan_control_commands & IBMACPI_FAN_CMD_SPEED) | ||
2090 | len += sprintf(p + len, "commands:\tspeed <speed>" | ||
2091 | " (<speed> is 0-65535)\n"); | ||
2092 | |||
2093 | return len; | ||
2094 | } | ||
2095 | |||
2096 | static int fan_set_level(int level) | ||
2097 | { | ||
2098 | switch (fan_control_access_mode) { | ||
2099 | case IBMACPI_FAN_WR_ACPI_SFAN: | ||
2100 | if (level >= 0 && level <= 7) { | ||
2101 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level)) | ||
2102 | return -EIO; | ||
2103 | } else | ||
2104 | return -EINVAL; | ||
2105 | break; | ||
2106 | |||
2107 | case IBMACPI_FAN_WR_ACPI_FANS: | ||
2108 | case IBMACPI_FAN_WR_TPEC: | ||
2109 | if ((level != IBMACPI_FAN_EC_AUTO) && | ||
2110 | (level != IBMACPI_FAN_EC_DISENGAGED) && | ||
2111 | ((level < 0) || (level > 7))) | ||
2112 | return -EINVAL; | ||
2113 | |||
2114 | if (!acpi_ec_write(fan_status_offset, level)) | ||
2115 | return -EIO; | ||
2116 | else | ||
2117 | fan_control_status_known = 1; | ||
2118 | break; | ||
2119 | |||
2120 | default: | ||
2121 | return -ENXIO; | ||
2122 | } | ||
2123 | return 0; | ||
2124 | } | ||
2125 | |||
2126 | static int fan_set_enable(void) | ||
2127 | { | ||
2128 | u8 s; | ||
2129 | int rc; | ||
2130 | |||
2131 | switch (fan_control_access_mode) { | ||
2132 | case IBMACPI_FAN_WR_ACPI_FANS: | ||
2133 | case IBMACPI_FAN_WR_TPEC: | ||
2134 | if ((rc = fan_get_status(&s)) < 0) | ||
2135 | return rc; | ||
2136 | |||
2137 | /* Don't go out of emergency fan mode */ | ||
2138 | if (s != 7) | ||
2139 | s = IBMACPI_FAN_EC_AUTO; | ||
2140 | |||
2141 | if (!acpi_ec_write(fan_status_offset, s)) | ||
2142 | return -EIO; | ||
2143 | else | ||
2144 | fan_control_status_known = 1; | ||
2145 | break; | ||
2146 | |||
2147 | case IBMACPI_FAN_WR_ACPI_SFAN: | ||
2148 | if ((rc = fan_get_status(&s)) < 0) | ||
2149 | return rc; | ||
2150 | |||
2151 | s &= 0x07; | ||
2152 | |||
2153 | /* Set fan to at least level 4 */ | ||
2154 | if (s < 4) | ||
2155 | s = 4; | ||
2156 | |||
2157 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", s)) | ||
2158 | return -EIO; | ||
2159 | break; | ||
2160 | |||
2161 | default: | ||
2162 | return -ENXIO; | ||
2163 | } | ||
2164 | return 0; | ||
2165 | } | ||
2166 | |||
2167 | static int fan_set_disable(void) | ||
2168 | { | ||
2169 | switch (fan_control_access_mode) { | ||
2170 | case IBMACPI_FAN_WR_ACPI_FANS: | ||
2171 | case IBMACPI_FAN_WR_TPEC: | ||
2172 | if (!acpi_ec_write(fan_status_offset, 0x00)) | ||
2173 | return -EIO; | ||
2174 | else | ||
2175 | fan_control_status_known = 1; | ||
2176 | break; | ||
2177 | |||
2178 | case IBMACPI_FAN_WR_ACPI_SFAN: | ||
2179 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", 0x00)) | ||
2180 | return -EIO; | ||
2181 | break; | ||
2182 | |||
2183 | default: | ||
2184 | return -ENXIO; | ||
2185 | } | ||
2186 | return 0; | ||
2187 | } | ||
2188 | |||
2189 | static int fan_set_speed(int speed) | ||
2190 | { | ||
2191 | switch (fan_control_access_mode) { | ||
2192 | case IBMACPI_FAN_WR_ACPI_FANS: | ||
2193 | if (speed >= 0 && speed <= 65535) { | ||
2194 | if (!acpi_evalf(fans_handle, NULL, NULL, "vddd", | ||
2195 | speed, speed, speed)) | ||
2196 | return -EIO; | ||
2197 | } else | ||
2198 | return -EINVAL; | ||
2199 | break; | ||
2200 | |||
2201 | default: | ||
2202 | return -ENXIO; | ||
2203 | } | ||
2204 | return 0; | ||
2205 | } | ||
2206 | |||
2207 | static int fan_write_cmd_level(const char *cmd, int *rc) | ||
2208 | { | ||
2209 | int level; | ||
2210 | |||
2211 | if (strlencmp(cmd, "level auto") == 0) | ||
2212 | level = IBMACPI_FAN_EC_AUTO; | ||
2213 | else if (strlencmp(cmd, "level disengaged") == 0) | ||
2214 | level = IBMACPI_FAN_EC_DISENGAGED; | ||
2215 | else if (sscanf(cmd, "level %d", &level) != 1) | ||
2216 | return 0; | ||
2217 | |||
2218 | if ((*rc = fan_set_level(level)) == -ENXIO) | ||
2219 | printk(IBM_ERR "level command accepted for unsupported " | ||
2220 | "access mode %d", fan_control_access_mode); | ||
2221 | |||
2222 | return 1; | ||
2223 | } | ||
2224 | |||
2225 | static int fan_write_cmd_enable(const char *cmd, int *rc) | ||
2226 | { | ||
2227 | if (strlencmp(cmd, "enable") != 0) | ||
2228 | return 0; | ||
2229 | |||
2230 | if ((*rc = fan_set_enable()) == -ENXIO) | ||
2231 | printk(IBM_ERR "enable command accepted for unsupported " | ||
2232 | "access mode %d", fan_control_access_mode); | ||
2233 | |||
2234 | return 1; | ||
2235 | } | ||
2236 | |||
2237 | static int fan_write_cmd_disable(const char *cmd, int *rc) | ||
2238 | { | ||
2239 | if (strlencmp(cmd, "disable") != 0) | ||
2240 | return 0; | ||
2241 | |||
2242 | if ((*rc = fan_set_disable()) == -ENXIO) | ||
2243 | printk(IBM_ERR "disable command accepted for unsupported " | ||
2244 | "access mode %d", fan_control_access_mode); | ||
2245 | |||
2246 | return 1; | ||
2247 | } | ||
2248 | |||
2249 | static int fan_write_cmd_speed(const char *cmd, int *rc) | ||
2250 | { | ||
2251 | int speed; | ||
2252 | |||
2253 | /* TODO: | ||
2254 | * Support speed <low> <medium> <high> ? */ | ||
2255 | |||
2256 | if (sscanf(cmd, "speed %d", &speed) != 1) | ||
2257 | return 0; | ||
2258 | |||
2259 | if ((*rc = fan_set_speed(speed)) == -ENXIO) | ||
2260 | printk(IBM_ERR "speed command accepted for unsupported " | ||
2261 | "access mode %d", fan_control_access_mode); | ||
2262 | |||
2263 | return 1; | ||
2264 | } | ||
2265 | |||
2266 | static int fan_write_cmd_watchdog(const char *cmd, int *rc) | ||
2267 | { | ||
2268 | int interval; | ||
2269 | |||
2270 | if (sscanf(cmd, "watchdog %d", &interval) != 1) | ||
2271 | return 0; | ||
2272 | |||
2273 | if (interval < 0 || interval > 120) | ||
2274 | *rc = -EINVAL; | ||
2275 | else | ||
2276 | fan_watchdog_maxinterval = interval; | ||
2277 | |||
2278 | return 1; | ||
2279 | } | ||
2280 | |||
2281 | static int fan_write(char *buf) | ||
2282 | { | ||
2283 | char *cmd; | ||
2284 | int rc = 0; | ||
2285 | |||
2286 | while (!rc && (cmd = next_cmd(&buf))) { | ||
2287 | if (!((fan_control_commands & IBMACPI_FAN_CMD_LEVEL) && | ||
2288 | fan_write_cmd_level(cmd, &rc)) && | ||
2289 | !((fan_control_commands & IBMACPI_FAN_CMD_ENABLE) && | ||
2290 | (fan_write_cmd_enable(cmd, &rc) || | ||
2291 | fan_write_cmd_disable(cmd, &rc) || | ||
2292 | fan_write_cmd_watchdog(cmd, &rc))) && | ||
2293 | !((fan_control_commands & IBMACPI_FAN_CMD_SPEED) && | ||
2294 | fan_write_cmd_speed(cmd, &rc)) | ||
2295 | ) | ||
2296 | rc = -EINVAL; | ||
2297 | else if (!rc) | ||
2298 | fan_watchdog_reset(); | ||
2299 | } | ||
2300 | |||
2301 | return rc; | ||
2302 | } | ||
2303 | |||
2304 | static void fan_watchdog_fire(struct work_struct *ignored) | ||
2305 | { | ||
2306 | printk(IBM_NOTICE "fan watchdog: enabling fan\n"); | ||
2307 | if (fan_set_enable()) { | ||
2308 | printk(IBM_ERR "fan watchdog: error while enabling fan\n"); | ||
2309 | /* reschedule for later */ | ||
2310 | fan_watchdog_reset(); | ||
2311 | } | ||
2312 | } | ||
2313 | |||
2314 | static struct ibm_struct ibms[] = { | ||
2315 | { | ||
2316 | .name = "driver", | ||
2317 | .init = ibm_acpi_driver_init, | ||
2318 | .read = driver_read, | ||
2319 | }, | ||
2320 | { | ||
2321 | .name = "hotkey", | ||
2322 | .hid = IBM_HKEY_HID, | ||
2323 | .init = hotkey_init, | ||
2324 | .read = hotkey_read, | ||
2325 | .write = hotkey_write, | ||
2326 | .exit = hotkey_exit, | ||
2327 | .notify = hotkey_notify, | ||
2328 | .handle = &hkey_handle, | ||
2329 | .type = ACPI_DEVICE_NOTIFY, | ||
2330 | }, | ||
2331 | { | ||
2332 | .name = "bluetooth", | ||
2333 | .init = bluetooth_init, | ||
2334 | .read = bluetooth_read, | ||
2335 | .write = bluetooth_write, | ||
2336 | }, | ||
2337 | { | ||
2338 | .name = "wan", | ||
2339 | .init = wan_init, | ||
2340 | .read = wan_read, | ||
2341 | .write = wan_write, | ||
2342 | .experimental = 1, | ||
2343 | }, | ||
2344 | { | ||
2345 | .name = "video", | ||
2346 | .init = video_init, | ||
2347 | .read = video_read, | ||
2348 | .write = video_write, | ||
2349 | .exit = video_exit, | ||
2350 | }, | ||
2351 | { | ||
2352 | .name = "light", | ||
2353 | .init = light_init, | ||
2354 | .read = light_read, | ||
2355 | .write = light_write, | ||
2356 | }, | ||
2357 | #ifdef CONFIG_ACPI_IBM_DOCK | ||
2358 | { | ||
2359 | .name = "dock", | ||
2360 | .read = dock_read, | ||
2361 | .write = dock_write, | ||
2362 | .notify = dock_notify, | ||
2363 | .handle = &dock_handle, | ||
2364 | .type = ACPI_SYSTEM_NOTIFY, | ||
2365 | }, | ||
2366 | { | ||
2367 | .name = "dock", | ||
2368 | .hid = IBM_PCI_HID, | ||
2369 | .notify = dock_notify, | ||
2370 | .handle = &pci_handle, | ||
2371 | .type = ACPI_SYSTEM_NOTIFY, | ||
2372 | }, | ||
2373 | #endif | ||
2374 | #ifdef CONFIG_ACPI_IBM_BAY | ||
2375 | { | ||
2376 | .name = "bay", | ||
2377 | .init = bay_init, | ||
2378 | .read = bay_read, | ||
2379 | .write = bay_write, | ||
2380 | .notify = bay_notify, | ||
2381 | .handle = &bay_handle, | ||
2382 | .type = ACPI_SYSTEM_NOTIFY, | ||
2383 | }, | ||
2384 | #endif /* CONFIG_ACPI_IBM_BAY */ | ||
2385 | { | ||
2386 | .name = "cmos", | ||
2387 | .read = cmos_read, | ||
2388 | .write = cmos_write, | ||
2389 | }, | ||
2390 | { | ||
2391 | .name = "led", | ||
2392 | .init = led_init, | ||
2393 | .read = led_read, | ||
2394 | .write = led_write, | ||
2395 | }, | ||
2396 | { | ||
2397 | .name = "beep", | ||
2398 | .read = beep_read, | ||
2399 | .write = beep_write, | ||
2400 | }, | ||
2401 | { | ||
2402 | .name = "thermal", | ||
2403 | .init = thermal_init, | ||
2404 | .read = thermal_read, | ||
2405 | }, | ||
2406 | { | ||
2407 | .name = "ecdump", | ||
2408 | .read = ecdump_read, | ||
2409 | .write = ecdump_write, | ||
2410 | .experimental = 1, | ||
2411 | }, | ||
2412 | { | ||
2413 | .name = "brightness", | ||
2414 | .read = brightness_read, | ||
2415 | .write = brightness_write, | ||
2416 | .init = brightness_init, | ||
2417 | .exit = brightness_exit, | ||
2418 | }, | ||
2419 | { | ||
2420 | .name = "volume", | ||
2421 | .read = volume_read, | ||
2422 | .write = volume_write, | ||
2423 | }, | ||
2424 | { | ||
2425 | .name = "fan", | ||
2426 | .read = fan_read, | ||
2427 | .write = fan_write, | ||
2428 | .init = fan_init, | ||
2429 | .exit = fan_exit, | ||
2430 | .experimental = 1, | ||
2431 | }, | ||
2432 | }; | ||
2433 | |||
2434 | static int dispatch_read(char *page, char **start, off_t off, int count, | ||
2435 | int *eof, void *data) | ||
2436 | { | ||
2437 | struct ibm_struct *ibm = data; | ||
2438 | int len; | ||
2439 | |||
2440 | if (!ibm || !ibm->read) | ||
2441 | return -EINVAL; | ||
2442 | |||
2443 | len = ibm->read(page); | ||
2444 | if (len < 0) | ||
2445 | return len; | ||
2446 | |||
2447 | if (len <= off + count) | ||
2448 | *eof = 1; | ||
2449 | *start = page + off; | ||
2450 | len -= off; | ||
2451 | if (len > count) | ||
2452 | len = count; | ||
2453 | if (len < 0) | ||
2454 | len = 0; | ||
2455 | |||
2456 | return len; | ||
2457 | } | ||
2458 | |||
2459 | static int dispatch_write(struct file *file, const char __user * userbuf, | ||
2460 | unsigned long count, void *data) | ||
2461 | { | ||
2462 | struct ibm_struct *ibm = data; | ||
2463 | char *kernbuf; | ||
2464 | int ret; | ||
2465 | |||
2466 | if (!ibm || !ibm->write) | ||
2467 | return -EINVAL; | ||
2468 | |||
2469 | kernbuf = kmalloc(count + 2, GFP_KERNEL); | ||
2470 | if (!kernbuf) | ||
2471 | return -ENOMEM; | ||
2472 | |||
2473 | if (copy_from_user(kernbuf, userbuf, count)) { | ||
2474 | kfree(kernbuf); | ||
2475 | return -EFAULT; | ||
2476 | } | ||
2477 | |||
2478 | kernbuf[count] = 0; | ||
2479 | strcat(kernbuf, ","); | ||
2480 | ret = ibm->write(kernbuf); | ||
2481 | if (ret == 0) | ||
2482 | ret = count; | ||
2483 | |||
2484 | kfree(kernbuf); | ||
2485 | |||
2486 | return ret; | ||
2487 | } | ||
2488 | |||
2489 | static void dispatch_notify(acpi_handle handle, u32 event, void *data) | ||
2490 | { | ||
2491 | struct ibm_struct *ibm = data; | ||
2492 | |||
2493 | if (!ibm || !ibm->notify) | ||
2494 | return; | ||
2495 | |||
2496 | ibm->notify(ibm, event); | ||
2497 | } | ||
2498 | |||
2499 | static int __init setup_notify(struct ibm_struct *ibm) | ||
2500 | { | ||
2501 | acpi_status status; | ||
2502 | int ret; | ||
2503 | |||
2504 | if (!*ibm->handle) | ||
2505 | return 0; | ||
2506 | |||
2507 | ret = acpi_bus_get_device(*ibm->handle, &ibm->device); | ||
2508 | if (ret < 0) { | ||
2509 | printk(IBM_ERR "%s device not present\n", ibm->name); | ||
2510 | return -ENODEV; | ||
2511 | } | ||
2512 | |||
2513 | acpi_driver_data(ibm->device) = ibm; | ||
2514 | sprintf(acpi_device_class(ibm->device), "%s/%s", IBM_NAME, ibm->name); | ||
2515 | |||
2516 | status = acpi_install_notify_handler(*ibm->handle, ibm->type, | ||
2517 | dispatch_notify, ibm); | ||
2518 | if (ACPI_FAILURE(status)) { | ||
2519 | if (status == AE_ALREADY_EXISTS) { | ||
2520 | printk(IBM_NOTICE "another device driver is already handling %s events\n", | ||
2521 | ibm->name); | ||
2522 | } else { | ||
2523 | printk(IBM_ERR "acpi_install_notify_handler(%s) failed: %d\n", | ||
2524 | ibm->name, status); | ||
2525 | } | ||
2526 | return -ENODEV; | ||
2527 | } | ||
2528 | ibm->notify_installed = 1; | ||
2529 | return 0; | ||
2530 | } | ||
2531 | |||
2532 | static int __init ibm_device_add(struct acpi_device *device) | ||
2533 | { | ||
2534 | return 0; | ||
2535 | } | ||
2536 | |||
2537 | static int __init register_driver(struct ibm_struct *ibm) | ||
2538 | { | ||
2539 | int ret; | ||
2540 | |||
2541 | ibm->driver = kzalloc(sizeof(struct acpi_driver), GFP_KERNEL); | ||
2542 | if (!ibm->driver) { | ||
2543 | printk(IBM_ERR "kmalloc(ibm->driver) failed\n"); | ||
2544 | return -1; | ||
2545 | } | ||
2546 | |||
2547 | sprintf(ibm->driver->name, "%s_%s", IBM_NAME, ibm->name); | ||
2548 | ibm->driver->ids = ibm->hid; | ||
2549 | ibm->driver->ops.add = &ibm_device_add; | ||
2550 | |||
2551 | ret = acpi_bus_register_driver(ibm->driver); | ||
2552 | if (ret < 0) { | ||
2553 | printk(IBM_ERR "acpi_bus_register_driver(%s) failed: %d\n", | ||
2554 | ibm->hid, ret); | ||
2555 | kfree(ibm->driver); | ||
2556 | } | ||
2557 | |||
2558 | return ret; | ||
2559 | } | ||
2560 | |||
2561 | static void ibm_exit(struct ibm_struct *ibm); | ||
2562 | |||
2563 | static int __init ibm_init(struct ibm_struct *ibm) | ||
2564 | { | ||
2565 | int ret; | ||
2566 | struct proc_dir_entry *entry; | ||
2567 | |||
2568 | if (ibm->experimental && !experimental) | ||
2569 | return 0; | ||
2570 | |||
2571 | if (ibm->hid) { | ||
2572 | ret = register_driver(ibm); | ||
2573 | if (ret < 0) | ||
2574 | return ret; | ||
2575 | ibm->driver_registered = 1; | ||
2576 | } | ||
2577 | |||
2578 | if (ibm->init) { | ||
2579 | ret = ibm->init(); | ||
2580 | if (ret != 0) | ||
2581 | return ret; | ||
2582 | ibm->init_called = 1; | ||
2583 | } | ||
2584 | |||
2585 | if (ibm->read) { | ||
2586 | entry = create_proc_entry(ibm->name, | ||
2587 | S_IFREG | S_IRUGO | S_IWUSR, | ||
2588 | proc_dir); | ||
2589 | if (!entry) { | ||
2590 | printk(IBM_ERR "unable to create proc entry %s\n", | ||
2591 | ibm->name); | ||
2592 | return -ENODEV; | ||
2593 | } | ||
2594 | entry->owner = THIS_MODULE; | ||
2595 | entry->data = ibm; | ||
2596 | entry->read_proc = &dispatch_read; | ||
2597 | if (ibm->write) | ||
2598 | entry->write_proc = &dispatch_write; | ||
2599 | ibm->proc_created = 1; | ||
2600 | } | ||
2601 | |||
2602 | if (ibm->notify) { | ||
2603 | ret = setup_notify(ibm); | ||
2604 | if (ret == -ENODEV) { | ||
2605 | printk(IBM_NOTICE "disabling subdriver %s\n", | ||
2606 | ibm->name); | ||
2607 | ibm_exit(ibm); | ||
2608 | return 0; | ||
2609 | } | ||
2610 | if (ret < 0) | ||
2611 | return ret; | ||
2612 | } | ||
2613 | |||
2614 | return 0; | ||
2615 | } | ||
2616 | |||
2617 | static void ibm_exit(struct ibm_struct *ibm) | ||
2618 | { | ||
2619 | if (ibm->notify_installed) | ||
2620 | acpi_remove_notify_handler(*ibm->handle, ibm->type, | ||
2621 | dispatch_notify); | ||
2622 | |||
2623 | if (ibm->proc_created) | ||
2624 | remove_proc_entry(ibm->name, proc_dir); | ||
2625 | |||
2626 | if (ibm->init_called && ibm->exit) | ||
2627 | ibm->exit(); | ||
2628 | |||
2629 | if (ibm->driver_registered) { | ||
2630 | acpi_bus_unregister_driver(ibm->driver); | ||
2631 | kfree(ibm->driver); | ||
2632 | } | ||
2633 | } | ||
2634 | |||
2635 | static void __init ibm_handle_init(char *name, | ||
2636 | acpi_handle * handle, acpi_handle parent, | ||
2637 | char **paths, int num_paths, char **path) | ||
2638 | { | ||
2639 | int i; | ||
2640 | acpi_status status; | ||
2641 | |||
2642 | for (i = 0; i < num_paths; i++) { | ||
2643 | status = acpi_get_handle(parent, paths[i], handle); | ||
2644 | if (ACPI_SUCCESS(status)) { | ||
2645 | *path = paths[i]; | ||
2646 | return; | ||
2647 | } | ||
2648 | } | ||
2649 | |||
2650 | *handle = NULL; | ||
2651 | } | ||
2652 | |||
2653 | #define IBM_HANDLE_INIT(object) \ | ||
2654 | ibm_handle_init(#object, &object##_handle, *object##_parent, \ | ||
2655 | object##_paths, ARRAY_SIZE(object##_paths), &object##_path) | ||
2656 | |||
2657 | static int __init set_ibm_param(const char *val, struct kernel_param *kp) | ||
2658 | { | ||
2659 | unsigned int i; | ||
2660 | |||
2661 | for (i = 0; i < ARRAY_SIZE(ibms); i++) | ||
2662 | if (strcmp(ibms[i].name, kp->name) == 0 && ibms[i].write) { | ||
2663 | if (strlen(val) > sizeof(ibms[i].param) - 2) | ||
2664 | return -ENOSPC; | ||
2665 | strcpy(ibms[i].param, val); | ||
2666 | strcat(ibms[i].param, ","); | ||
2667 | return 0; | ||
2668 | } | ||
2669 | |||
2670 | return -EINVAL; | ||
2671 | } | ||
2672 | |||
2673 | #define IBM_PARAM(feature) \ | ||
2674 | module_param_call(feature, set_ibm_param, NULL, NULL, 0) | ||
2675 | |||
2676 | IBM_PARAM(hotkey); | ||
2677 | IBM_PARAM(bluetooth); | ||
2678 | IBM_PARAM(video); | ||
2679 | IBM_PARAM(light); | ||
2680 | #ifdef CONFIG_ACPI_IBM_DOCK | ||
2681 | IBM_PARAM(dock); | ||
2682 | #endif | ||
2683 | #ifdef CONFIG_ACPI_IBM_BAY | ||
2684 | IBM_PARAM(bay); | ||
2685 | #endif /* CONFIG_ACPI_IBM_BAY */ | ||
2686 | IBM_PARAM(cmos); | ||
2687 | IBM_PARAM(led); | ||
2688 | IBM_PARAM(beep); | ||
2689 | IBM_PARAM(ecdump); | ||
2690 | IBM_PARAM(brightness); | ||
2691 | IBM_PARAM(volume); | ||
2692 | IBM_PARAM(fan); | ||
2693 | |||
2694 | static void acpi_ibm_exit(void) | ||
2695 | { | ||
2696 | int i; | ||
2697 | |||
2698 | for (i = ARRAY_SIZE(ibms) - 1; i >= 0; i--) | ||
2699 | ibm_exit(&ibms[i]); | ||
2700 | |||
2701 | if (proc_dir) | ||
2702 | remove_proc_entry(IBM_DIR, acpi_root_dir); | ||
2703 | |||
2704 | if (ibm_thinkpad_ec_found) | ||
2705 | kfree(ibm_thinkpad_ec_found); | ||
2706 | } | ||
2707 | |||
2708 | static char* __init check_dmi_for_ec(void) | ||
2709 | { | ||
2710 | struct dmi_device *dev = NULL; | ||
2711 | char ec_fw_string[18]; | ||
2712 | |||
2713 | /* | ||
2714 | * ThinkPad T23 or newer, A31 or newer, R50e or newer, | ||
2715 | * X32 or newer, all Z series; Some models must have an | ||
2716 | * up-to-date BIOS or they will not be detected. | ||
2717 | * | ||
2718 | * See http://thinkwiki.org/wiki/List_of_DMI_IDs | ||
2719 | */ | ||
2720 | while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, NULL, dev))) { | ||
2721 | if (sscanf(dev->name, | ||
2722 | "IBM ThinkPad Embedded Controller -[%17c", | ||
2723 | ec_fw_string) == 1) { | ||
2724 | ec_fw_string[sizeof(ec_fw_string) - 1] = 0; | ||
2725 | ec_fw_string[strcspn(ec_fw_string, " ]")] = 0; | ||
2726 | return kstrdup(ec_fw_string, GFP_KERNEL); | ||
2727 | } | ||
2728 | } | ||
2729 | return NULL; | ||
2730 | } | ||
2731 | |||
2732 | static int __init acpi_ibm_init(void) | ||
2733 | { | ||
2734 | int ret, i; | ||
2735 | |||
2736 | if (acpi_disabled) | ||
2737 | return -ENODEV; | ||
2738 | |||
2739 | /* ec is required because many other handles are relative to it */ | ||
2740 | IBM_HANDLE_INIT(ec); | ||
2741 | if (!ec_handle) { | ||
2742 | printk(IBM_ERR "ec object not found\n"); | ||
2743 | return -ENODEV; | ||
2744 | } | ||
2745 | |||
2746 | /* Models with newer firmware report the EC in DMI */ | ||
2747 | ibm_thinkpad_ec_found = check_dmi_for_ec(); | ||
2748 | |||
2749 | /* these handles are not required */ | ||
2750 | IBM_HANDLE_INIT(vid); | ||
2751 | IBM_HANDLE_INIT(vid2); | ||
2752 | IBM_HANDLE_INIT(ledb); | ||
2753 | IBM_HANDLE_INIT(led); | ||
2754 | IBM_HANDLE_INIT(hkey); | ||
2755 | IBM_HANDLE_INIT(lght); | ||
2756 | IBM_HANDLE_INIT(cmos); | ||
2757 | #ifdef CONFIG_ACPI_IBM_DOCK | ||
2758 | IBM_HANDLE_INIT(dock); | ||
2759 | #endif | ||
2760 | IBM_HANDLE_INIT(pci); | ||
2761 | #ifdef CONFIG_ACPI_IBM_BAY | ||
2762 | IBM_HANDLE_INIT(bay); | ||
2763 | if (bay_handle) | ||
2764 | IBM_HANDLE_INIT(bay_ej); | ||
2765 | IBM_HANDLE_INIT(bay2); | ||
2766 | if (bay2_handle) | ||
2767 | IBM_HANDLE_INIT(bay2_ej); | ||
2768 | #endif /* CONFIG_ACPI_IBM_BAY */ | ||
2769 | IBM_HANDLE_INIT(beep); | ||
2770 | IBM_HANDLE_INIT(ecrd); | ||
2771 | IBM_HANDLE_INIT(ecwr); | ||
2772 | IBM_HANDLE_INIT(fans); | ||
2773 | IBM_HANDLE_INIT(gfan); | ||
2774 | IBM_HANDLE_INIT(sfan); | ||
2775 | |||
2776 | proc_dir = proc_mkdir(IBM_DIR, acpi_root_dir); | ||
2777 | if (!proc_dir) { | ||
2778 | printk(IBM_ERR "unable to create proc dir %s", IBM_DIR); | ||
2779 | acpi_ibm_exit(); | ||
2780 | return -ENODEV; | ||
2781 | } | ||
2782 | proc_dir->owner = THIS_MODULE; | ||
2783 | |||
2784 | for (i = 0; i < ARRAY_SIZE(ibms); i++) { | ||
2785 | ret = ibm_init(&ibms[i]); | ||
2786 | if (ret >= 0 && *ibms[i].param) | ||
2787 | ret = ibms[i].write(ibms[i].param); | ||
2788 | if (ret < 0) { | ||
2789 | acpi_ibm_exit(); | ||
2790 | return ret; | ||
2791 | } | ||
2792 | } | ||
2793 | |||
2794 | return 0; | ||
2795 | } | ||
2796 | |||
2797 | module_init(acpi_ibm_init); | ||
2798 | module_exit(acpi_ibm_exit); | ||
diff --git a/drivers/acpi/processor_core.c b/drivers/acpi/processor_core.c index 99d1516d1e70..f7de02a6f497 100644 --- a/drivers/acpi/processor_core.c +++ b/drivers/acpi/processor_core.c | |||
@@ -70,8 +70,6 @@ | |||
70 | #define ACPI_PROCESSOR_LIMIT_USER 0 | 70 | #define ACPI_PROCESSOR_LIMIT_USER 0 |
71 | #define ACPI_PROCESSOR_LIMIT_THERMAL 1 | 71 | #define ACPI_PROCESSOR_LIMIT_THERMAL 1 |
72 | 72 | ||
73 | #define ACPI_STA_PRESENT 0x00000001 | ||
74 | |||
75 | #define _COMPONENT ACPI_PROCESSOR_COMPONENT | 73 | #define _COMPONENT ACPI_PROCESSOR_COMPONENT |
76 | ACPI_MODULE_NAME("processor_core"); | 74 | ACPI_MODULE_NAME("processor_core"); |
77 | 75 | ||
@@ -779,7 +777,7 @@ static int is_processor_present(acpi_handle handle) | |||
779 | 777 | ||
780 | 778 | ||
781 | status = acpi_evaluate_integer(handle, "_STA", NULL, &sta); | 779 | status = acpi_evaluate_integer(handle, "_STA", NULL, &sta); |
782 | if (ACPI_FAILURE(status) || !(sta & ACPI_STA_PRESENT)) { | 780 | if (ACPI_FAILURE(status) || !(sta & ACPI_STA_DEVICE_PRESENT)) { |
783 | ACPI_EXCEPTION((AE_INFO, status, "Processor Device is not present")); | 781 | ACPI_EXCEPTION((AE_INFO, status, "Processor Device is not present")); |
784 | return 0; | 782 | return 0; |
785 | } | 783 | } |
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c index cdf78943af4d..ae0654cd11ea 100644 --- a/drivers/acpi/processor_idle.c +++ b/drivers/acpi/processor_idle.c | |||
@@ -51,14 +51,6 @@ | |||
51 | #include <asm/apic.h> | 51 | #include <asm/apic.h> |
52 | #endif | 52 | #endif |
53 | 53 | ||
54 | /* | ||
55 | * Include the apic definitions for x86 to have the APIC timer related defines | ||
56 | * available also for UP (on SMP it gets magically included via linux/smp.h). | ||
57 | */ | ||
58 | #ifdef CONFIG_X86 | ||
59 | #include <asm/apic.h> | ||
60 | #endif | ||
61 | |||
62 | #include <asm/io.h> | 54 | #include <asm/io.h> |
63 | #include <asm/uaccess.h> | 55 | #include <asm/uaccess.h> |
64 | 56 | ||
diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c index 59640d9a0acc..c1bae106833c 100644 --- a/drivers/acpi/sbs.c +++ b/drivers/acpi/sbs.c | |||
@@ -30,30 +30,10 @@ | |||
30 | #include <linux/seq_file.h> | 30 | #include <linux/seq_file.h> |
31 | #include <asm/uaccess.h> | 31 | #include <asm/uaccess.h> |
32 | #include <linux/acpi.h> | 32 | #include <linux/acpi.h> |
33 | #include <linux/i2c.h> | 33 | #include <linux/timer.h> |
34 | #include <linux/jiffies.h> | ||
34 | #include <linux/delay.h> | 35 | #include <linux/delay.h> |
35 | 36 | ||
36 | #include "i2c_ec.h" | ||
37 | |||
38 | #define DEF_CAPACITY_UNIT 3 | ||
39 | #define MAH_CAPACITY_UNIT 1 | ||
40 | #define MWH_CAPACITY_UNIT 2 | ||
41 | #define CAPACITY_UNIT DEF_CAPACITY_UNIT | ||
42 | |||
43 | #define REQUEST_UPDATE_MODE 1 | ||
44 | #define QUEUE_UPDATE_MODE 2 | ||
45 | |||
46 | #define DATA_TYPE_COMMON 0 | ||
47 | #define DATA_TYPE_INFO 1 | ||
48 | #define DATA_TYPE_STATE 2 | ||
49 | #define DATA_TYPE_ALARM 3 | ||
50 | #define DATA_TYPE_AC_STATE 4 | ||
51 | |||
52 | extern struct proc_dir_entry *acpi_lock_ac_dir(void); | ||
53 | extern struct proc_dir_entry *acpi_lock_battery_dir(void); | ||
54 | extern void acpi_unlock_ac_dir(struct proc_dir_entry *acpi_ac_dir); | ||
55 | extern void acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir); | ||
56 | |||
57 | #define ACPI_SBS_COMPONENT 0x00080000 | 37 | #define ACPI_SBS_COMPONENT 0x00080000 |
58 | #define ACPI_SBS_CLASS "sbs" | 38 | #define ACPI_SBS_CLASS "sbs" |
59 | #define ACPI_AC_CLASS "ac_adapter" | 39 | #define ACPI_AC_CLASS "ac_adapter" |
@@ -74,39 +54,75 @@ extern void acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir); | |||
74 | 54 | ||
75 | #define _COMPONENT ACPI_SBS_COMPONENT | 55 | #define _COMPONENT ACPI_SBS_COMPONENT |
76 | 56 | ||
77 | #define MAX_SBS_BAT 4 | ||
78 | #define MAX_SMBUS_ERR 1 | ||
79 | |||
80 | ACPI_MODULE_NAME("sbs"); | 57 | ACPI_MODULE_NAME("sbs"); |
81 | 58 | ||
82 | MODULE_AUTHOR("Rich Townsend"); | 59 | MODULE_AUTHOR("Rich Townsend"); |
83 | MODULE_DESCRIPTION("Smart Battery System ACPI interface driver"); | 60 | MODULE_DESCRIPTION("Smart Battery System ACPI interface driver"); |
84 | MODULE_LICENSE("GPL"); | 61 | MODULE_LICENSE("GPL"); |
85 | 62 | ||
86 | static struct semaphore sbs_sem; | 63 | #define xmsleep(t) msleep(t) |
64 | |||
65 | #define ACPI_EC_SMB_PRTCL 0x00 /* protocol, PEC */ | ||
66 | |||
67 | #define ACPI_EC_SMB_STS 0x01 /* status */ | ||
68 | #define ACPI_EC_SMB_ADDR 0x02 /* address */ | ||
69 | #define ACPI_EC_SMB_CMD 0x03 /* command */ | ||
70 | #define ACPI_EC_SMB_DATA 0x04 /* 32 data registers */ | ||
71 | #define ACPI_EC_SMB_BCNT 0x24 /* number of data bytes */ | ||
87 | 72 | ||
88 | #define UPDATE_MODE QUEUE_UPDATE_MODE | 73 | #define ACPI_EC_SMB_STS_DONE 0x80 |
89 | /* REQUEST_UPDATE_MODE QUEUE_UPDATE_MODE */ | 74 | #define ACPI_EC_SMB_STS_STATUS 0x1f |
90 | #define UPDATE_INFO_MODE 0 | ||
91 | #define UPDATE_TIME 60 | ||
92 | #define UPDATE_TIME2 0 | ||
93 | 75 | ||
94 | static int capacity_mode = CAPACITY_UNIT; | 76 | #define ACPI_EC_SMB_PRTCL_WRITE 0x00 |
95 | static int update_mode = UPDATE_MODE; | 77 | #define ACPI_EC_SMB_PRTCL_READ 0x01 |
96 | static int update_info_mode = UPDATE_INFO_MODE; | 78 | #define ACPI_EC_SMB_PRTCL_WORD_DATA 0x08 |
97 | static int update_time = UPDATE_TIME; | 79 | #define ACPI_EC_SMB_PRTCL_BLOCK_DATA 0x0a |
98 | static int update_time2 = UPDATE_TIME2; | ||
99 | 80 | ||
100 | module_param(capacity_mode, int, 0); | 81 | #define ACPI_EC_SMB_TRANSACTION_SLEEP 1 |
101 | module_param(update_mode, int, 0); | 82 | #define ACPI_EC_SMB_ACCESS_SLEEP1 1 |
102 | module_param(update_info_mode, int, 0); | 83 | #define ACPI_EC_SMB_ACCESS_SLEEP2 10 |
103 | module_param(update_time, int, 0); | 84 | |
104 | module_param(update_time2, int, 0); | 85 | #define DEF_CAPACITY_UNIT 3 |
86 | #define MAH_CAPACITY_UNIT 1 | ||
87 | #define MWH_CAPACITY_UNIT 2 | ||
88 | #define CAPACITY_UNIT DEF_CAPACITY_UNIT | ||
89 | |||
90 | #define REQUEST_UPDATE_MODE 1 | ||
91 | #define QUEUE_UPDATE_MODE 2 | ||
92 | |||
93 | #define DATA_TYPE_COMMON 0 | ||
94 | #define DATA_TYPE_INFO 1 | ||
95 | #define DATA_TYPE_STATE 2 | ||
96 | #define DATA_TYPE_ALARM 3 | ||
97 | #define DATA_TYPE_AC_STATE 4 | ||
98 | |||
99 | extern struct proc_dir_entry *acpi_lock_ac_dir(void); | ||
100 | extern struct proc_dir_entry *acpi_lock_battery_dir(void); | ||
101 | extern void acpi_unlock_ac_dir(struct proc_dir_entry *acpi_ac_dir); | ||
102 | extern void acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir); | ||
103 | |||
104 | #define MAX_SBS_BAT 4 | ||
105 | #define ACPI_SBS_BLOCK_MAX 32 | ||
106 | |||
107 | #define ACPI_SBS_SMBUS_READ 1 | ||
108 | #define ACPI_SBS_SMBUS_WRITE 2 | ||
109 | |||
110 | #define ACPI_SBS_WORD_DATA 1 | ||
111 | #define ACPI_SBS_BLOCK_DATA 2 | ||
112 | |||
113 | #define UPDATE_DELAY 10 | ||
114 | |||
115 | /* 0 - every time, > 0 - by update_time */ | ||
116 | static unsigned int update_time = 120; | ||
117 | |||
118 | static unsigned int capacity_mode = CAPACITY_UNIT; | ||
119 | |||
120 | module_param(update_time, uint, 0644); | ||
121 | module_param(capacity_mode, uint, 0444); | ||
105 | 122 | ||
106 | static int acpi_sbs_add(struct acpi_device *device); | 123 | static int acpi_sbs_add(struct acpi_device *device); |
107 | static int acpi_sbs_remove(struct acpi_device *device, int type); | 124 | static int acpi_sbs_remove(struct acpi_device *device, int type); |
108 | static void acpi_battery_smbus_err_handler(struct acpi_ec_smbus *smbus); | 125 | static int acpi_sbs_resume(struct acpi_device *device); |
109 | static void acpi_sbs_update_queue(void *data); | ||
110 | 126 | ||
111 | static struct acpi_driver acpi_sbs_driver = { | 127 | static struct acpi_driver acpi_sbs_driver = { |
112 | .name = "sbs", | 128 | .name = "sbs", |
@@ -115,9 +131,14 @@ static struct acpi_driver acpi_sbs_driver = { | |||
115 | .ops = { | 131 | .ops = { |
116 | .add = acpi_sbs_add, | 132 | .add = acpi_sbs_add, |
117 | .remove = acpi_sbs_remove, | 133 | .remove = acpi_sbs_remove, |
134 | .resume = acpi_sbs_resume, | ||
118 | }, | 135 | }, |
119 | }; | 136 | }; |
120 | 137 | ||
138 | struct acpi_ac { | ||
139 | int ac_present; | ||
140 | }; | ||
141 | |||
121 | struct acpi_battery_info { | 142 | struct acpi_battery_info { |
122 | int capacity_mode; | 143 | int capacity_mode; |
123 | s16 full_charge_capacity; | 144 | s16 full_charge_capacity; |
@@ -126,18 +147,16 @@ struct acpi_battery_info { | |||
126 | int vscale; | 147 | int vscale; |
127 | int ipscale; | 148 | int ipscale; |
128 | s16 serial_number; | 149 | s16 serial_number; |
129 | char manufacturer_name[I2C_SMBUS_BLOCK_MAX + 3]; | 150 | char manufacturer_name[ACPI_SBS_BLOCK_MAX + 3]; |
130 | char device_name[I2C_SMBUS_BLOCK_MAX + 3]; | 151 | char device_name[ACPI_SBS_BLOCK_MAX + 3]; |
131 | char device_chemistry[I2C_SMBUS_BLOCK_MAX + 3]; | 152 | char device_chemistry[ACPI_SBS_BLOCK_MAX + 3]; |
132 | }; | 153 | }; |
133 | 154 | ||
134 | struct acpi_battery_state { | 155 | struct acpi_battery_state { |
135 | s16 voltage; | 156 | s16 voltage; |
136 | s16 amperage; | 157 | s16 amperage; |
137 | s16 remaining_capacity; | 158 | s16 remaining_capacity; |
138 | s16 average_time_to_empty; | 159 | s16 battery_state; |
139 | s16 average_time_to_full; | ||
140 | s16 battery_status; | ||
141 | }; | 160 | }; |
142 | 161 | ||
143 | struct acpi_battery_alarm { | 162 | struct acpi_battery_alarm { |
@@ -146,9 +165,9 @@ struct acpi_battery_alarm { | |||
146 | 165 | ||
147 | struct acpi_battery { | 166 | struct acpi_battery { |
148 | int alive; | 167 | int alive; |
149 | int battery_present; | ||
150 | int id; | 168 | int id; |
151 | int init_state; | 169 | int init_state; |
170 | int battery_present; | ||
152 | struct acpi_sbs *sbs; | 171 | struct acpi_sbs *sbs; |
153 | struct acpi_battery_info info; | 172 | struct acpi_battery_info info; |
154 | struct acpi_battery_state state; | 173 | struct acpi_battery_state state; |
@@ -158,186 +177,251 @@ struct acpi_battery { | |||
158 | 177 | ||
159 | struct acpi_sbs { | 178 | struct acpi_sbs { |
160 | acpi_handle handle; | 179 | acpi_handle handle; |
180 | int base; | ||
161 | struct acpi_device *device; | 181 | struct acpi_device *device; |
162 | struct acpi_ec_smbus *smbus; | 182 | struct acpi_ec_smbus *smbus; |
183 | struct mutex mutex; | ||
163 | int sbsm_present; | 184 | int sbsm_present; |
164 | int sbsm_batteries_supported; | 185 | int sbsm_batteries_supported; |
165 | int ac_present; | ||
166 | struct proc_dir_entry *ac_entry; | 186 | struct proc_dir_entry *ac_entry; |
187 | struct acpi_ac ac; | ||
167 | struct acpi_battery battery[MAX_SBS_BAT]; | 188 | struct acpi_battery battery[MAX_SBS_BAT]; |
168 | int update_info_mode; | ||
169 | int zombie; | 189 | int zombie; |
170 | int update_time; | ||
171 | int update_time2; | ||
172 | struct timer_list update_timer; | 190 | struct timer_list update_timer; |
191 | int run_cnt; | ||
192 | int update_proc_flg; | ||
173 | }; | 193 | }; |
174 | 194 | ||
175 | static void acpi_update_delay(struct acpi_sbs *sbs); | 195 | static int acpi_sbs_update_run(struct acpi_sbs *sbs, int id, int data_type); |
176 | static int acpi_sbs_update_run(struct acpi_sbs *sbs, int data_type); | 196 | static void acpi_sbs_update_time(void *data); |
197 | |||
198 | union sbs_rw_data { | ||
199 | u16 word; | ||
200 | u8 block[ACPI_SBS_BLOCK_MAX + 2]; | ||
201 | }; | ||
202 | |||
203 | static int acpi_ec_sbs_access(struct acpi_sbs *sbs, u16 addr, | ||
204 | char read_write, u8 command, int size, | ||
205 | union sbs_rw_data *data); | ||
177 | 206 | ||
178 | /* -------------------------------------------------------------------------- | 207 | /* -------------------------------------------------------------------------- |
179 | SMBus Communication | 208 | SMBus Communication |
180 | -------------------------------------------------------------------------- */ | 209 | -------------------------------------------------------------------------- */ |
181 | 210 | ||
182 | static void acpi_battery_smbus_err_handler(struct acpi_ec_smbus *smbus) | 211 | static int acpi_ec_sbs_read(struct acpi_sbs *sbs, u8 address, u8 * data) |
183 | { | 212 | { |
184 | union i2c_smbus_data data; | 213 | u8 val; |
185 | int result = 0; | 214 | int err; |
186 | char *err_str; | ||
187 | int err_number; | ||
188 | 215 | ||
189 | data.word = 0; | 216 | err = ec_read(sbs->base + address, &val); |
217 | if (!err) { | ||
218 | *data = val; | ||
219 | } | ||
220 | xmsleep(ACPI_EC_SMB_TRANSACTION_SLEEP); | ||
221 | return (err); | ||
222 | } | ||
190 | 223 | ||
191 | result = smbus->adapter.algo-> | 224 | static int acpi_ec_sbs_write(struct acpi_sbs *sbs, u8 address, u8 data) |
192 | smbus_xfer(&smbus->adapter, | 225 | { |
193 | ACPI_SB_SMBUS_ADDR, | 226 | int err; |
194 | 0, I2C_SMBUS_READ, 0x16, I2C_SMBUS_BLOCK_DATA, &data); | ||
195 | 227 | ||
196 | err_number = (data.word & 0x000f); | 228 | err = ec_write(sbs->base + address, data); |
229 | return (err); | ||
230 | } | ||
197 | 231 | ||
198 | switch (data.word & 0x000f) { | 232 | static int |
199 | case 0x0000: | 233 | acpi_ec_sbs_access(struct acpi_sbs *sbs, u16 addr, |
200 | err_str = "unexpected bus error"; | 234 | char read_write, u8 command, int size, |
201 | break; | 235 | union sbs_rw_data *data) |
202 | case 0x0001: | 236 | { |
203 | err_str = "busy"; | 237 | unsigned char protocol, len = 0, temp[2] = { 0, 0 }; |
204 | break; | 238 | int i; |
205 | case 0x0002: | 239 | |
206 | err_str = "reserved command"; | 240 | if (read_write == ACPI_SBS_SMBUS_READ) { |
207 | break; | 241 | protocol = ACPI_EC_SMB_PRTCL_READ; |
208 | case 0x0003: | 242 | } else { |
209 | err_str = "unsupported command"; | 243 | protocol = ACPI_EC_SMB_PRTCL_WRITE; |
210 | break; | 244 | } |
211 | case 0x0004: | 245 | |
212 | err_str = "access denied"; | 246 | switch (size) { |
247 | |||
248 | case ACPI_SBS_WORD_DATA: | ||
249 | acpi_ec_sbs_write(sbs, ACPI_EC_SMB_CMD, command); | ||
250 | if (read_write == ACPI_SBS_SMBUS_WRITE) { | ||
251 | acpi_ec_sbs_write(sbs, ACPI_EC_SMB_DATA, data->word); | ||
252 | acpi_ec_sbs_write(sbs, ACPI_EC_SMB_DATA + 1, | ||
253 | data->word >> 8); | ||
254 | } | ||
255 | protocol |= ACPI_EC_SMB_PRTCL_WORD_DATA; | ||
213 | break; | 256 | break; |
214 | case 0x0005: | 257 | case ACPI_SBS_BLOCK_DATA: |
215 | err_str = "overflow/underflow"; | 258 | acpi_ec_sbs_write(sbs, ACPI_EC_SMB_CMD, command); |
259 | if (read_write == ACPI_SBS_SMBUS_WRITE) { | ||
260 | len = min_t(u8, data->block[0], 32); | ||
261 | acpi_ec_sbs_write(sbs, ACPI_EC_SMB_BCNT, len); | ||
262 | for (i = 0; i < len; i++) | ||
263 | acpi_ec_sbs_write(sbs, ACPI_EC_SMB_DATA + i, | ||
264 | data->block[i + 1]); | ||
265 | } | ||
266 | protocol |= ACPI_EC_SMB_PRTCL_BLOCK_DATA; | ||
216 | break; | 267 | break; |
217 | case 0x0006: | 268 | default: |
218 | err_str = "bad size"; | 269 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
270 | "unsupported transaction %d", size)); | ||
271 | return (-1); | ||
272 | } | ||
273 | |||
274 | acpi_ec_sbs_write(sbs, ACPI_EC_SMB_ADDR, addr << 1); | ||
275 | acpi_ec_sbs_write(sbs, ACPI_EC_SMB_PRTCL, protocol); | ||
276 | |||
277 | acpi_ec_sbs_read(sbs, ACPI_EC_SMB_STS, temp); | ||
278 | |||
279 | if (~temp[0] & ACPI_EC_SMB_STS_DONE) { | ||
280 | xmsleep(ACPI_EC_SMB_ACCESS_SLEEP1); | ||
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_SLEEP2); | ||
285 | acpi_ec_sbs_read(sbs, ACPI_EC_SMB_STS, temp); | ||
286 | } | ||
287 | if ((~temp[0] & ACPI_EC_SMB_STS_DONE) | ||
288 | || (temp[0] & ACPI_EC_SMB_STS_STATUS)) { | ||
289 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
290 | "transaction %d error", size)); | ||
291 | return (-1); | ||
292 | } | ||
293 | |||
294 | if (read_write == ACPI_SBS_SMBUS_WRITE) { | ||
295 | return (0); | ||
296 | } | ||
297 | |||
298 | switch (size) { | ||
299 | |||
300 | case ACPI_SBS_WORD_DATA: | ||
301 | acpi_ec_sbs_read(sbs, ACPI_EC_SMB_DATA, temp); | ||
302 | acpi_ec_sbs_read(sbs, ACPI_EC_SMB_DATA + 1, temp + 1); | ||
303 | data->word = (temp[1] << 8) | temp[0]; | ||
219 | break; | 304 | break; |
220 | case 0x0007: | 305 | |
221 | err_str = "unknown error"; | 306 | case ACPI_SBS_BLOCK_DATA: |
307 | len = 0; | ||
308 | acpi_ec_sbs_read(sbs, ACPI_EC_SMB_BCNT, &len); | ||
309 | len = min_t(u8, len, 32); | ||
310 | for (i = 0; i < len; i++) | ||
311 | acpi_ec_sbs_read(sbs, ACPI_EC_SMB_DATA + i, | ||
312 | data->block + i + 1); | ||
313 | data->block[0] = len; | ||
222 | break; | 314 | break; |
223 | default: | 315 | default: |
224 | err_str = "unrecognized error"; | 316 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
317 | "unsupported transaction %d", size)); | ||
318 | return (-1); | ||
225 | } | 319 | } |
226 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 320 | |
227 | "%s: ret %i, err %i\n", err_str, result, err_number)); | 321 | return (0); |
228 | } | 322 | } |
229 | 323 | ||
230 | static int | 324 | static int |
231 | acpi_sbs_smbus_read_word(struct acpi_ec_smbus *smbus, int addr, int func, | 325 | acpi_sbs_read_word(struct acpi_sbs *sbs, int addr, int func, u16 * word) |
232 | u16 * word, | ||
233 | void (*err_handler) (struct acpi_ec_smbus * smbus)) | ||
234 | { | 326 | { |
235 | union i2c_smbus_data data; | 327 | union sbs_rw_data data; |
236 | int result = 0; | 328 | int result = 0; |
237 | int i; | ||
238 | 329 | ||
239 | if (err_handler == NULL) { | 330 | result = acpi_ec_sbs_access(sbs, addr, |
240 | err_handler = acpi_battery_smbus_err_handler; | 331 | ACPI_SBS_SMBUS_READ, func, |
241 | } | 332 | ACPI_SBS_WORD_DATA, &data); |
242 | 333 | if (result) { | |
243 | for (i = 0; i < MAX_SMBUS_ERR; i++) { | 334 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
244 | result = | 335 | "acpi_ec_sbs_access() failed")); |
245 | smbus->adapter.algo->smbus_xfer(&smbus->adapter, addr, 0, | 336 | } else { |
246 | I2C_SMBUS_READ, func, | 337 | *word = data.word; |
247 | I2C_SMBUS_WORD_DATA, &data); | ||
248 | if (result) { | ||
249 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | ||
250 | "try %i: smbus->adapter.algo->smbus_xfer() failed\n", | ||
251 | i)); | ||
252 | if (err_handler) { | ||
253 | err_handler(smbus); | ||
254 | } | ||
255 | } else { | ||
256 | *word = data.word; | ||
257 | break; | ||
258 | } | ||
259 | } | 338 | } |
260 | 339 | ||
261 | return result; | 340 | return result; |
262 | } | 341 | } |
263 | 342 | ||
264 | static int | 343 | static int |
265 | acpi_sbs_smbus_read_str(struct acpi_ec_smbus *smbus, int addr, int func, | 344 | acpi_sbs_read_str(struct acpi_sbs *sbs, int addr, int func, char *str) |
266 | char *str, | ||
267 | void (*err_handler) (struct acpi_ec_smbus * smbus)) | ||
268 | { | 345 | { |
269 | union i2c_smbus_data data; | 346 | union sbs_rw_data data; |
270 | int result = 0; | 347 | int result = 0; |
271 | int i; | ||
272 | |||
273 | if (err_handler == NULL) { | ||
274 | err_handler = acpi_battery_smbus_err_handler; | ||
275 | } | ||
276 | 348 | ||
277 | for (i = 0; i < MAX_SMBUS_ERR; i++) { | 349 | result = acpi_ec_sbs_access(sbs, addr, |
278 | result = | 350 | ACPI_SBS_SMBUS_READ, func, |
279 | smbus->adapter.algo->smbus_xfer(&smbus->adapter, addr, 0, | 351 | ACPI_SBS_BLOCK_DATA, &data); |
280 | I2C_SMBUS_READ, func, | 352 | if (result) { |
281 | I2C_SMBUS_BLOCK_DATA, | 353 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
282 | &data); | 354 | "acpi_ec_sbs_access() failed")); |
283 | if (result) { | 355 | } else { |
284 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 356 | strncpy(str, (const char *)data.block + 1, data.block[0]); |
285 | "try %i: smbus->adapter.algo->smbus_xfer() failed\n", | 357 | str[data.block[0]] = 0; |
286 | i)); | ||
287 | if (err_handler) { | ||
288 | err_handler(smbus); | ||
289 | } | ||
290 | } else { | ||
291 | strncpy(str, (const char *)data.block + 1, | ||
292 | data.block[0]); | ||
293 | str[data.block[0]] = 0; | ||
294 | break; | ||
295 | } | ||
296 | } | 358 | } |
297 | 359 | ||
298 | return result; | 360 | return result; |
299 | } | 361 | } |
300 | 362 | ||
301 | static int | 363 | static int |
302 | acpi_sbs_smbus_write_word(struct acpi_ec_smbus *smbus, int addr, int func, | 364 | acpi_sbs_write_word(struct acpi_sbs *sbs, int addr, int func, int word) |
303 | int word, | ||
304 | void (*err_handler) (struct acpi_ec_smbus * smbus)) | ||
305 | { | 365 | { |
306 | union i2c_smbus_data data; | 366 | union sbs_rw_data data; |
307 | int result = 0; | 367 | int result = 0; |
308 | int i; | ||
309 | |||
310 | if (err_handler == NULL) { | ||
311 | err_handler = acpi_battery_smbus_err_handler; | ||
312 | } | ||
313 | 368 | ||
314 | data.word = word; | 369 | data.word = word; |
315 | 370 | ||
316 | for (i = 0; i < MAX_SMBUS_ERR; i++) { | 371 | result = acpi_ec_sbs_access(sbs, addr, |
317 | result = | 372 | ACPI_SBS_SMBUS_WRITE, func, |
318 | smbus->adapter.algo->smbus_xfer(&smbus->adapter, addr, 0, | 373 | ACPI_SBS_WORD_DATA, &data); |
319 | I2C_SMBUS_WRITE, func, | 374 | if (result) { |
320 | I2C_SMBUS_WORD_DATA, &data); | 375 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
321 | if (result) { | 376 | "acpi_ec_sbs_access() failed")); |
322 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | ||
323 | "try %i: smbus->adapter.algo" | ||
324 | "->smbus_xfer() failed\n", i)); | ||
325 | if (err_handler) { | ||
326 | err_handler(smbus); | ||
327 | } | ||
328 | } else { | ||
329 | break; | ||
330 | } | ||
331 | } | 377 | } |
332 | 378 | ||
333 | return result; | 379 | return result; |
334 | } | 380 | } |
335 | 381 | ||
382 | static int sbs_zombie(struct acpi_sbs *sbs) | ||
383 | { | ||
384 | return (sbs->zombie); | ||
385 | } | ||
386 | |||
387 | static int sbs_mutex_lock(struct acpi_sbs *sbs) | ||
388 | { | ||
389 | if (sbs_zombie(sbs)) { | ||
390 | return -ENODEV; | ||
391 | } | ||
392 | mutex_lock(&sbs->mutex); | ||
393 | return 0; | ||
394 | } | ||
395 | |||
396 | static void sbs_mutex_unlock(struct acpi_sbs *sbs) | ||
397 | { | ||
398 | mutex_unlock(&sbs->mutex); | ||
399 | } | ||
400 | |||
336 | /* -------------------------------------------------------------------------- | 401 | /* -------------------------------------------------------------------------- |
337 | Smart Battery System Management | 402 | Smart Battery System Management |
338 | -------------------------------------------------------------------------- */ | 403 | -------------------------------------------------------------------------- */ |
339 | 404 | ||
340 | /* Smart Battery */ | 405 | static int acpi_check_update_proc(struct acpi_sbs *sbs) |
406 | { | ||
407 | acpi_status status = AE_OK; | ||
408 | |||
409 | if (update_time == 0) { | ||
410 | sbs->update_proc_flg = 0; | ||
411 | return 0; | ||
412 | } | ||
413 | if (sbs->update_proc_flg == 0) { | ||
414 | status = acpi_os_execute(OSL_GPE_HANDLER, | ||
415 | acpi_sbs_update_time, sbs); | ||
416 | if (status != AE_OK) { | ||
417 | ACPI_EXCEPTION((AE_INFO, status, | ||
418 | "acpi_os_execute() failed")); | ||
419 | return 1; | ||
420 | } | ||
421 | sbs->update_proc_flg = 1; | ||
422 | } | ||
423 | return 0; | ||
424 | } | ||
341 | 425 | ||
342 | static int acpi_sbs_generate_event(struct acpi_device *device, | 426 | static int acpi_sbs_generate_event(struct acpi_device *device, |
343 | int event, int state, char *bid, char *class) | 427 | int event, int state, char *bid, char *class) |
@@ -366,12 +450,11 @@ static int acpi_battery_get_present(struct acpi_battery *battery) | |||
366 | int result = 0; | 450 | int result = 0; |
367 | int is_present = 0; | 451 | int is_present = 0; |
368 | 452 | ||
369 | result = acpi_sbs_smbus_read_word(battery->sbs->smbus, | 453 | result = acpi_sbs_read_word(battery->sbs, |
370 | ACPI_SBSM_SMBUS_ADDR, 0x01, | 454 | ACPI_SBSM_SMBUS_ADDR, 0x01, &state); |
371 | &state, NULL); | ||
372 | if (result) { | 455 | if (result) { |
373 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 456 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
374 | "acpi_sbs_smbus_read_word() failed")); | 457 | "acpi_sbs_read_word() failed")); |
375 | } | 458 | } |
376 | if (!result) { | 459 | if (!result) { |
377 | is_present = (state & 0x000f) & (1 << battery->id); | 460 | is_present = (state & 0x000f) & (1 << battery->id); |
@@ -381,45 +464,33 @@ static int acpi_battery_get_present(struct acpi_battery *battery) | |||
381 | return result; | 464 | return result; |
382 | } | 465 | } |
383 | 466 | ||
384 | static int acpi_battery_is_present(struct acpi_battery *battery) | ||
385 | { | ||
386 | return (battery->battery_present); | ||
387 | } | ||
388 | |||
389 | static int acpi_ac_is_present(struct acpi_sbs *sbs) | ||
390 | { | ||
391 | return (sbs->ac_present); | ||
392 | } | ||
393 | |||
394 | static int acpi_battery_select(struct acpi_battery *battery) | 467 | static int acpi_battery_select(struct acpi_battery *battery) |
395 | { | 468 | { |
396 | struct acpi_ec_smbus *smbus = battery->sbs->smbus; | 469 | struct acpi_sbs *sbs = battery->sbs; |
397 | int result = 0; | 470 | int result = 0; |
398 | s16 state; | 471 | s16 state; |
399 | int foo; | 472 | int foo; |
400 | 473 | ||
401 | if (battery->sbs->sbsm_present) { | 474 | if (sbs->sbsm_present) { |
402 | 475 | ||
403 | /* Take special care not to knobble other nibbles of | 476 | /* Take special care not to knobble other nibbles of |
404 | * state (aka selector_state), since | 477 | * state (aka selector_state), since |
405 | * it causes charging to halt on SBSELs */ | 478 | * it causes charging to halt on SBSELs */ |
406 | 479 | ||
407 | result = | 480 | result = |
408 | acpi_sbs_smbus_read_word(smbus, ACPI_SBSM_SMBUS_ADDR, 0x01, | 481 | acpi_sbs_read_word(sbs, ACPI_SBSM_SMBUS_ADDR, 0x01, &state); |
409 | &state, NULL); | ||
410 | if (result) { | 482 | if (result) { |
411 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 483 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
412 | "acpi_sbs_smbus_read_word() failed\n")); | 484 | "acpi_sbs_read_word() failed")); |
413 | goto end; | 485 | goto end; |
414 | } | 486 | } |
415 | 487 | ||
416 | foo = (state & 0x0fff) | (1 << (battery->id + 12)); | 488 | foo = (state & 0x0fff) | (1 << (battery->id + 12)); |
417 | result = | 489 | result = |
418 | acpi_sbs_smbus_write_word(smbus, ACPI_SBSM_SMBUS_ADDR, 0x01, | 490 | acpi_sbs_write_word(sbs, ACPI_SBSM_SMBUS_ADDR, 0x01, foo); |
419 | foo, NULL); | ||
420 | if (result) { | 491 | if (result) { |
421 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 492 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
422 | "acpi_sbs_smbus_write_word() failed\n")); | 493 | "acpi_sbs_write_word() failed")); |
423 | goto end; | 494 | goto end; |
424 | } | 495 | } |
425 | } | 496 | } |
@@ -430,15 +501,14 @@ static int acpi_battery_select(struct acpi_battery *battery) | |||
430 | 501 | ||
431 | static int acpi_sbsm_get_info(struct acpi_sbs *sbs) | 502 | static int acpi_sbsm_get_info(struct acpi_sbs *sbs) |
432 | { | 503 | { |
433 | struct acpi_ec_smbus *smbus = sbs->smbus; | ||
434 | int result = 0; | 504 | int result = 0; |
435 | s16 battery_system_info; | 505 | s16 battery_system_info; |
436 | 506 | ||
437 | result = acpi_sbs_smbus_read_word(smbus, ACPI_SBSM_SMBUS_ADDR, 0x04, | 507 | result = acpi_sbs_read_word(sbs, ACPI_SBSM_SMBUS_ADDR, 0x04, |
438 | &battery_system_info, NULL); | 508 | &battery_system_info); |
439 | if (result) { | 509 | if (result) { |
440 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 510 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
441 | "acpi_sbs_smbus_read_word() failed\n")); | 511 | "acpi_sbs_read_word() failed")); |
442 | goto end; | 512 | goto end; |
443 | } | 513 | } |
444 | 514 | ||
@@ -451,53 +521,50 @@ static int acpi_sbsm_get_info(struct acpi_sbs *sbs) | |||
451 | 521 | ||
452 | static int acpi_battery_get_info(struct acpi_battery *battery) | 522 | static int acpi_battery_get_info(struct acpi_battery *battery) |
453 | { | 523 | { |
454 | struct acpi_ec_smbus *smbus = battery->sbs->smbus; | 524 | struct acpi_sbs *sbs = battery->sbs; |
455 | int result = 0; | 525 | int result = 0; |
456 | s16 battery_mode; | 526 | s16 battery_mode; |
457 | s16 specification_info; | 527 | s16 specification_info; |
458 | 528 | ||
459 | result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x03, | 529 | result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x03, |
460 | &battery_mode, | 530 | &battery_mode); |
461 | &acpi_battery_smbus_err_handler); | ||
462 | if (result) { | 531 | if (result) { |
463 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 532 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
464 | "acpi_sbs_smbus_read_word() failed\n")); | 533 | "acpi_sbs_read_word() failed")); |
465 | goto end; | 534 | goto end; |
466 | } | 535 | } |
467 | battery->info.capacity_mode = (battery_mode & 0x8000) >> 15; | 536 | battery->info.capacity_mode = (battery_mode & 0x8000) >> 15; |
468 | 537 | ||
469 | result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x10, | 538 | result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x10, |
470 | &battery->info.full_charge_capacity, | 539 | &battery->info.full_charge_capacity); |
471 | &acpi_battery_smbus_err_handler); | ||
472 | if (result) { | 540 | if (result) { |
473 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 541 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
474 | "acpi_sbs_smbus_read_word() failed\n")); | 542 | "acpi_sbs_read_word() failed")); |
475 | goto end; | 543 | goto end; |
476 | } | 544 | } |
477 | 545 | ||
478 | result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x18, | 546 | result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x18, |
479 | &battery->info.design_capacity, | 547 | &battery->info.design_capacity); |
480 | &acpi_battery_smbus_err_handler); | ||
481 | 548 | ||
482 | if (result) { | 549 | if (result) { |
550 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
551 | "acpi_sbs_read_word() failed")); | ||
483 | goto end; | 552 | goto end; |
484 | } | 553 | } |
485 | 554 | ||
486 | result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x19, | 555 | result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x19, |
487 | &battery->info.design_voltage, | 556 | &battery->info.design_voltage); |
488 | &acpi_battery_smbus_err_handler); | ||
489 | if (result) { | 557 | if (result) { |
490 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 558 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
491 | "acpi_sbs_smbus_read_word() failed\n")); | 559 | "acpi_sbs_read_word() failed")); |
492 | goto end; | 560 | goto end; |
493 | } | 561 | } |
494 | 562 | ||
495 | result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x1a, | 563 | result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x1a, |
496 | &specification_info, | 564 | &specification_info); |
497 | &acpi_battery_smbus_err_handler); | ||
498 | if (result) { | 565 | if (result) { |
499 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 566 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
500 | "acpi_sbs_smbus_read_word() failed\n")); | 567 | "acpi_sbs_read_word() failed")); |
501 | goto end; | 568 | goto end; |
502 | } | 569 | } |
503 | 570 | ||
@@ -529,37 +596,35 @@ static int acpi_battery_get_info(struct acpi_battery *battery) | |||
529 | battery->info.ipscale = 1; | 596 | battery->info.ipscale = 1; |
530 | } | 597 | } |
531 | 598 | ||
532 | result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x1c, | 599 | result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x1c, |
533 | &battery->info.serial_number, | 600 | &battery->info.serial_number); |
534 | &acpi_battery_smbus_err_handler); | ||
535 | if (result) { | 601 | if (result) { |
602 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
603 | "acpi_sbs_read_word() failed")); | ||
536 | goto end; | 604 | goto end; |
537 | } | 605 | } |
538 | 606 | ||
539 | result = acpi_sbs_smbus_read_str(smbus, ACPI_SB_SMBUS_ADDR, 0x20, | 607 | result = acpi_sbs_read_str(sbs, ACPI_SB_SMBUS_ADDR, 0x20, |
540 | battery->info.manufacturer_name, | 608 | battery->info.manufacturer_name); |
541 | &acpi_battery_smbus_err_handler); | ||
542 | if (result) { | 609 | if (result) { |
543 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 610 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
544 | "acpi_sbs_smbus_read_str() failed\n")); | 611 | "acpi_sbs_read_str() failed")); |
545 | goto end; | 612 | goto end; |
546 | } | 613 | } |
547 | 614 | ||
548 | result = acpi_sbs_smbus_read_str(smbus, ACPI_SB_SMBUS_ADDR, 0x21, | 615 | result = acpi_sbs_read_str(sbs, ACPI_SB_SMBUS_ADDR, 0x21, |
549 | battery->info.device_name, | 616 | battery->info.device_name); |
550 | &acpi_battery_smbus_err_handler); | ||
551 | if (result) { | 617 | if (result) { |
552 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 618 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
553 | "acpi_sbs_smbus_read_str() failed\n")); | 619 | "acpi_sbs_read_str() failed")); |
554 | goto end; | 620 | goto end; |
555 | } | 621 | } |
556 | 622 | ||
557 | result = acpi_sbs_smbus_read_str(smbus, ACPI_SB_SMBUS_ADDR, 0x22, | 623 | result = acpi_sbs_read_str(sbs, ACPI_SB_SMBUS_ADDR, 0x22, |
558 | battery->info.device_chemistry, | 624 | battery->info.device_chemistry); |
559 | &acpi_battery_smbus_err_handler); | ||
560 | if (result) { | 625 | if (result) { |
561 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 626 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
562 | "acpi_sbs_smbus_read_str() failed\n")); | 627 | "acpi_sbs_read_str() failed")); |
563 | goto end; | 628 | goto end; |
564 | } | 629 | } |
565 | 630 | ||
@@ -567,103 +632,60 @@ static int acpi_battery_get_info(struct acpi_battery *battery) | |||
567 | return result; | 632 | return result; |
568 | } | 633 | } |
569 | 634 | ||
570 | static void acpi_update_delay(struct acpi_sbs *sbs) | ||
571 | { | ||
572 | if (sbs->zombie) { | ||
573 | return; | ||
574 | } | ||
575 | if (sbs->update_time2 > 0) { | ||
576 | msleep(sbs->update_time2 * 1000); | ||
577 | } | ||
578 | } | ||
579 | |||
580 | static int acpi_battery_get_state(struct acpi_battery *battery) | 635 | static int acpi_battery_get_state(struct acpi_battery *battery) |
581 | { | 636 | { |
582 | struct acpi_ec_smbus *smbus = battery->sbs->smbus; | 637 | struct acpi_sbs *sbs = battery->sbs; |
583 | int result = 0; | 638 | int result = 0; |
584 | 639 | ||
585 | acpi_update_delay(battery->sbs); | 640 | result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x09, |
586 | result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x09, | 641 | &battery->state.voltage); |
587 | &battery->state.voltage, | ||
588 | &acpi_battery_smbus_err_handler); | ||
589 | if (result) { | 642 | if (result) { |
590 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 643 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
591 | "acpi_sbs_smbus_read_word() failed\n")); | 644 | "acpi_sbs_read_word() failed")); |
592 | goto end; | 645 | goto end; |
593 | } | 646 | } |
594 | 647 | ||
595 | acpi_update_delay(battery->sbs); | 648 | result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x0a, |
596 | result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x0a, | 649 | &battery->state.amperage); |
597 | &battery->state.amperage, | ||
598 | &acpi_battery_smbus_err_handler); | ||
599 | if (result) { | 650 | if (result) { |
600 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 651 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
601 | "acpi_sbs_smbus_read_word() failed\n")); | 652 | "acpi_sbs_read_word() failed")); |
602 | goto end; | 653 | goto end; |
603 | } | 654 | } |
604 | 655 | ||
605 | acpi_update_delay(battery->sbs); | 656 | result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x0f, |
606 | result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x0f, | 657 | &battery->state.remaining_capacity); |
607 | &battery->state.remaining_capacity, | ||
608 | &acpi_battery_smbus_err_handler); | ||
609 | if (result) { | 658 | if (result) { |
610 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 659 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
611 | "acpi_sbs_smbus_read_word() failed\n")); | 660 | "acpi_sbs_read_word() failed")); |
612 | goto end; | 661 | goto end; |
613 | } | 662 | } |
614 | 663 | ||
615 | acpi_update_delay(battery->sbs); | 664 | result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x16, |
616 | result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x12, | 665 | &battery->state.battery_state); |
617 | &battery->state.average_time_to_empty, | ||
618 | &acpi_battery_smbus_err_handler); | ||
619 | if (result) { | 666 | if (result) { |
620 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 667 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
621 | "acpi_sbs_smbus_read_word() failed\n")); | 668 | "acpi_sbs_read_word() failed")); |
622 | goto end; | 669 | goto end; |
623 | } | 670 | } |
624 | 671 | ||
625 | acpi_update_delay(battery->sbs); | ||
626 | result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x13, | ||
627 | &battery->state.average_time_to_full, | ||
628 | &acpi_battery_smbus_err_handler); | ||
629 | if (result) { | ||
630 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | ||
631 | "acpi_sbs_smbus_read_word() failed\n")); | ||
632 | goto end; | ||
633 | } | ||
634 | |||
635 | acpi_update_delay(battery->sbs); | ||
636 | result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x16, | ||
637 | &battery->state.battery_status, | ||
638 | &acpi_battery_smbus_err_handler); | ||
639 | if (result) { | ||
640 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | ||
641 | "acpi_sbs_smbus_read_word() failed\n")); | ||
642 | goto end; | ||
643 | } | ||
644 | |||
645 | acpi_update_delay(battery->sbs); | ||
646 | |||
647 | end: | 672 | end: |
648 | return result; | 673 | return result; |
649 | } | 674 | } |
650 | 675 | ||
651 | static int acpi_battery_get_alarm(struct acpi_battery *battery) | 676 | static int acpi_battery_get_alarm(struct acpi_battery *battery) |
652 | { | 677 | { |
653 | struct acpi_ec_smbus *smbus = battery->sbs->smbus; | 678 | struct acpi_sbs *sbs = battery->sbs; |
654 | int result = 0; | 679 | int result = 0; |
655 | 680 | ||
656 | result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x01, | 681 | result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x01, |
657 | &battery->alarm.remaining_capacity, | 682 | &battery->alarm.remaining_capacity); |
658 | &acpi_battery_smbus_err_handler); | ||
659 | if (result) { | 683 | if (result) { |
660 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 684 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
661 | "acpi_sbs_smbus_read_word() failed\n")); | 685 | "acpi_sbs_read_word() failed")); |
662 | goto end; | 686 | goto end; |
663 | } | 687 | } |
664 | 688 | ||
665 | acpi_update_delay(battery->sbs); | ||
666 | |||
667 | end: | 689 | end: |
668 | 690 | ||
669 | return result; | 691 | return result; |
@@ -672,15 +694,15 @@ static int acpi_battery_get_alarm(struct acpi_battery *battery) | |||
672 | static int acpi_battery_set_alarm(struct acpi_battery *battery, | 694 | static int acpi_battery_set_alarm(struct acpi_battery *battery, |
673 | unsigned long alarm) | 695 | unsigned long alarm) |
674 | { | 696 | { |
675 | struct acpi_ec_smbus *smbus = battery->sbs->smbus; | 697 | struct acpi_sbs *sbs = battery->sbs; |
676 | int result = 0; | 698 | int result = 0; |
677 | s16 battery_mode; | 699 | s16 battery_mode; |
678 | int foo; | 700 | int foo; |
679 | 701 | ||
680 | result = acpi_battery_select(battery); | 702 | result = acpi_battery_select(battery); |
681 | if (result) { | 703 | if (result) { |
682 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 704 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
683 | "acpi_battery_select() failed\n")); | 705 | "acpi_battery_select() failed")); |
684 | goto end; | 706 | goto end; |
685 | } | 707 | } |
686 | 708 | ||
@@ -688,33 +710,29 @@ static int acpi_battery_set_alarm(struct acpi_battery *battery, | |||
688 | 710 | ||
689 | if (alarm > 0) { | 711 | if (alarm > 0) { |
690 | result = | 712 | result = |
691 | acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x03, | 713 | acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x03, |
692 | &battery_mode, | 714 | &battery_mode); |
693 | &acpi_battery_smbus_err_handler); | ||
694 | if (result) { | 715 | if (result) { |
695 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 716 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
696 | "acpi_sbs_smbus_read_word() failed\n")); | 717 | "acpi_sbs_read_word() failed")); |
697 | goto end; | 718 | goto end; |
698 | } | 719 | } |
699 | 720 | ||
700 | result = | 721 | result = |
701 | acpi_sbs_smbus_write_word(smbus, ACPI_SB_SMBUS_ADDR, 0x01, | 722 | acpi_sbs_write_word(sbs, ACPI_SB_SMBUS_ADDR, 0x01, |
702 | battery_mode & 0xbfff, | 723 | battery_mode & 0xbfff); |
703 | &acpi_battery_smbus_err_handler); | ||
704 | if (result) { | 724 | if (result) { |
705 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 725 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
706 | "acpi_sbs_smbus_write_word() failed\n")); | 726 | "acpi_sbs_write_word() failed")); |
707 | goto end; | 727 | goto end; |
708 | } | 728 | } |
709 | } | 729 | } |
710 | 730 | ||
711 | foo = alarm / (battery->info.capacity_mode ? 10 : 1); | 731 | foo = alarm / (battery->info.capacity_mode ? 10 : 1); |
712 | result = acpi_sbs_smbus_write_word(smbus, ACPI_SB_SMBUS_ADDR, 0x01, | 732 | result = acpi_sbs_write_word(sbs, ACPI_SB_SMBUS_ADDR, 0x01, foo); |
713 | foo, | ||
714 | &acpi_battery_smbus_err_handler); | ||
715 | if (result) { | 733 | if (result) { |
716 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 734 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
717 | "acpi_sbs_smbus_write_word() failed\n")); | 735 | "acpi_sbs_write_word() failed")); |
718 | goto end; | 736 | goto end; |
719 | } | 737 | } |
720 | 738 | ||
@@ -725,6 +743,7 @@ static int acpi_battery_set_alarm(struct acpi_battery *battery, | |||
725 | 743 | ||
726 | static int acpi_battery_set_mode(struct acpi_battery *battery) | 744 | static int acpi_battery_set_mode(struct acpi_battery *battery) |
727 | { | 745 | { |
746 | struct acpi_sbs *sbs = battery->sbs; | ||
728 | int result = 0; | 747 | int result = 0; |
729 | s16 battery_mode; | 748 | s16 battery_mode; |
730 | 749 | ||
@@ -732,12 +751,11 @@ static int acpi_battery_set_mode(struct acpi_battery *battery) | |||
732 | goto end; | 751 | goto end; |
733 | } | 752 | } |
734 | 753 | ||
735 | result = acpi_sbs_smbus_read_word(battery->sbs->smbus, | 754 | result = acpi_sbs_read_word(sbs, |
736 | ACPI_SB_SMBUS_ADDR, 0x03, | 755 | ACPI_SB_SMBUS_ADDR, 0x03, &battery_mode); |
737 | &battery_mode, NULL); | ||
738 | if (result) { | 756 | if (result) { |
739 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 757 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
740 | "acpi_sbs_smbus_read_word() failed\n")); | 758 | "acpi_sbs_read_word() failed")); |
741 | goto end; | 759 | goto end; |
742 | } | 760 | } |
743 | 761 | ||
@@ -746,21 +764,19 @@ static int acpi_battery_set_mode(struct acpi_battery *battery) | |||
746 | } else { | 764 | } else { |
747 | battery_mode |= 0x8000; | 765 | battery_mode |= 0x8000; |
748 | } | 766 | } |
749 | result = acpi_sbs_smbus_write_word(battery->sbs->smbus, | 767 | result = acpi_sbs_write_word(sbs, |
750 | ACPI_SB_SMBUS_ADDR, 0x03, | 768 | ACPI_SB_SMBUS_ADDR, 0x03, battery_mode); |
751 | battery_mode, NULL); | ||
752 | if (result) { | 769 | if (result) { |
753 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 770 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
754 | "acpi_sbs_smbus_write_word() failed\n")); | 771 | "acpi_sbs_write_word() failed")); |
755 | goto end; | 772 | goto end; |
756 | } | 773 | } |
757 | 774 | ||
758 | result = acpi_sbs_smbus_read_word(battery->sbs->smbus, | 775 | result = acpi_sbs_read_word(sbs, |
759 | ACPI_SB_SMBUS_ADDR, 0x03, | 776 | ACPI_SB_SMBUS_ADDR, 0x03, &battery_mode); |
760 | &battery_mode, NULL); | ||
761 | if (result) { | 777 | if (result) { |
762 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 778 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
763 | "acpi_sbs_smbus_read_word() failed\n")); | 779 | "acpi_sbs_read_word() failed")); |
764 | goto end; | 780 | goto end; |
765 | } | 781 | } |
766 | 782 | ||
@@ -774,36 +790,36 @@ static int acpi_battery_init(struct acpi_battery *battery) | |||
774 | 790 | ||
775 | result = acpi_battery_select(battery); | 791 | result = acpi_battery_select(battery); |
776 | if (result) { | 792 | if (result) { |
777 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 793 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
778 | "acpi_battery_init() failed\n")); | 794 | "acpi_battery_select() failed")); |
779 | goto end; | 795 | goto end; |
780 | } | 796 | } |
781 | 797 | ||
782 | result = acpi_battery_set_mode(battery); | 798 | result = acpi_battery_set_mode(battery); |
783 | if (result) { | 799 | if (result) { |
784 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 800 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
785 | "acpi_battery_set_mode() failed\n")); | 801 | "acpi_battery_set_mode() failed")); |
786 | goto end; | 802 | goto end; |
787 | } | 803 | } |
788 | 804 | ||
789 | result = acpi_battery_get_info(battery); | 805 | result = acpi_battery_get_info(battery); |
790 | if (result) { | 806 | if (result) { |
791 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 807 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
792 | "acpi_battery_get_info() failed\n")); | 808 | "acpi_battery_get_info() failed")); |
793 | goto end; | 809 | goto end; |
794 | } | 810 | } |
795 | 811 | ||
796 | result = acpi_battery_get_state(battery); | 812 | result = acpi_battery_get_state(battery); |
797 | if (result) { | 813 | if (result) { |
798 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 814 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
799 | "acpi_battery_get_state() failed\n")); | 815 | "acpi_battery_get_state() failed")); |
800 | goto end; | 816 | goto end; |
801 | } | 817 | } |
802 | 818 | ||
803 | result = acpi_battery_get_alarm(battery); | 819 | result = acpi_battery_get_alarm(battery); |
804 | if (result) { | 820 | if (result) { |
805 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 821 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
806 | "acpi_battery_get_alarm() failed\n")); | 822 | "acpi_battery_get_alarm() failed")); |
807 | goto end; | 823 | goto end; |
808 | } | 824 | } |
809 | 825 | ||
@@ -813,20 +829,19 @@ static int acpi_battery_init(struct acpi_battery *battery) | |||
813 | 829 | ||
814 | static int acpi_ac_get_present(struct acpi_sbs *sbs) | 830 | static int acpi_ac_get_present(struct acpi_sbs *sbs) |
815 | { | 831 | { |
816 | struct acpi_ec_smbus *smbus = sbs->smbus; | ||
817 | int result = 0; | 832 | int result = 0; |
818 | s16 charger_status; | 833 | s16 charger_status; |
819 | 834 | ||
820 | result = acpi_sbs_smbus_read_word(smbus, ACPI_SBC_SMBUS_ADDR, 0x13, | 835 | result = acpi_sbs_read_word(sbs, ACPI_SBC_SMBUS_ADDR, 0x13, |
821 | &charger_status, NULL); | 836 | &charger_status); |
822 | 837 | ||
823 | if (result) { | 838 | if (result) { |
824 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 839 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
825 | "acpi_sbs_smbus_read_word() failed\n")); | 840 | "acpi_sbs_read_word() failed")); |
826 | goto end; | 841 | goto end; |
827 | } | 842 | } |
828 | 843 | ||
829 | sbs->ac_present = (charger_status & 0x8000) >> 15; | 844 | sbs->ac.ac_present = (charger_status & 0x8000) >> 15; |
830 | 845 | ||
831 | end: | 846 | end: |
832 | 847 | ||
@@ -852,8 +867,8 @@ acpi_sbs_generic_add_fs(struct proc_dir_entry **dir, | |||
852 | if (!*dir) { | 867 | if (!*dir) { |
853 | *dir = proc_mkdir(dir_name, parent_dir); | 868 | *dir = proc_mkdir(dir_name, parent_dir); |
854 | if (!*dir) { | 869 | if (!*dir) { |
855 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 870 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
856 | "proc_mkdir() failed\n")); | 871 | "proc_mkdir() failed")); |
857 | return -ENODEV; | 872 | return -ENODEV; |
858 | } | 873 | } |
859 | (*dir)->owner = THIS_MODULE; | 874 | (*dir)->owner = THIS_MODULE; |
@@ -863,8 +878,8 @@ acpi_sbs_generic_add_fs(struct proc_dir_entry **dir, | |||
863 | if (info_fops) { | 878 | if (info_fops) { |
864 | entry = create_proc_entry(ACPI_SBS_FILE_INFO, S_IRUGO, *dir); | 879 | entry = create_proc_entry(ACPI_SBS_FILE_INFO, S_IRUGO, *dir); |
865 | if (!entry) { | 880 | if (!entry) { |
866 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 881 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
867 | "create_proc_entry() failed\n")); | 882 | "create_proc_entry() failed")); |
868 | } else { | 883 | } else { |
869 | entry->proc_fops = info_fops; | 884 | entry->proc_fops = info_fops; |
870 | entry->data = data; | 885 | entry->data = data; |
@@ -876,8 +891,8 @@ acpi_sbs_generic_add_fs(struct proc_dir_entry **dir, | |||
876 | if (state_fops) { | 891 | if (state_fops) { |
877 | entry = create_proc_entry(ACPI_SBS_FILE_STATE, S_IRUGO, *dir); | 892 | entry = create_proc_entry(ACPI_SBS_FILE_STATE, S_IRUGO, *dir); |
878 | if (!entry) { | 893 | if (!entry) { |
879 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 894 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
880 | "create_proc_entry() failed\n")); | 895 | "create_proc_entry() failed")); |
881 | } else { | 896 | } else { |
882 | entry->proc_fops = state_fops; | 897 | entry->proc_fops = state_fops; |
883 | entry->data = data; | 898 | entry->data = data; |
@@ -889,8 +904,8 @@ acpi_sbs_generic_add_fs(struct proc_dir_entry **dir, | |||
889 | if (alarm_fops) { | 904 | if (alarm_fops) { |
890 | entry = create_proc_entry(ACPI_SBS_FILE_ALARM, S_IRUGO, *dir); | 905 | entry = create_proc_entry(ACPI_SBS_FILE_ALARM, S_IRUGO, *dir); |
891 | if (!entry) { | 906 | if (!entry) { |
892 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 907 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
893 | "create_proc_entry() failed\n")); | 908 | "create_proc_entry() failed")); |
894 | } else { | 909 | } else { |
895 | entry->proc_fops = alarm_fops; | 910 | entry->proc_fops = alarm_fops; |
896 | entry->data = data; | 911 | entry->data = data; |
@@ -923,24 +938,27 @@ static struct proc_dir_entry *acpi_battery_dir = NULL; | |||
923 | static int acpi_battery_read_info(struct seq_file *seq, void *offset) | 938 | static int acpi_battery_read_info(struct seq_file *seq, void *offset) |
924 | { | 939 | { |
925 | struct acpi_battery *battery = seq->private; | 940 | struct acpi_battery *battery = seq->private; |
941 | struct acpi_sbs *sbs = battery->sbs; | ||
926 | int cscale; | 942 | int cscale; |
927 | int result = 0; | 943 | int result = 0; |
928 | 944 | ||
929 | if (battery->sbs->zombie) { | 945 | if (sbs_mutex_lock(sbs)) { |
930 | return -ENODEV; | 946 | return -ENODEV; |
931 | } | 947 | } |
932 | 948 | ||
933 | down(&sbs_sem); | 949 | result = acpi_check_update_proc(sbs); |
950 | if (result) | ||
951 | goto end; | ||
934 | 952 | ||
935 | if (update_mode == REQUEST_UPDATE_MODE) { | 953 | if (update_time == 0) { |
936 | result = acpi_sbs_update_run(battery->sbs, DATA_TYPE_INFO); | 954 | result = acpi_sbs_update_run(sbs, battery->id, DATA_TYPE_INFO); |
937 | if (result) { | 955 | if (result) { |
938 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 956 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
939 | "acpi_sbs_update_run() failed\n")); | 957 | "acpi_sbs_update_run() failed")); |
940 | } | 958 | } |
941 | } | 959 | } |
942 | 960 | ||
943 | if (acpi_battery_is_present(battery)) { | 961 | if (battery->battery_present) { |
944 | seq_printf(seq, "present: yes\n"); | 962 | seq_printf(seq, "present: yes\n"); |
945 | } else { | 963 | } else { |
946 | seq_printf(seq, "present: no\n"); | 964 | seq_printf(seq, "present: no\n"); |
@@ -952,13 +970,13 @@ static int acpi_battery_read_info(struct seq_file *seq, void *offset) | |||
952 | } else { | 970 | } else { |
953 | cscale = battery->info.ipscale; | 971 | cscale = battery->info.ipscale; |
954 | } | 972 | } |
955 | seq_printf(seq, "design capacity: %i%s", | 973 | seq_printf(seq, "design capacity: %i%s\n", |
956 | battery->info.design_capacity * cscale, | 974 | battery->info.design_capacity * cscale, |
957 | battery->info.capacity_mode ? "0 mWh\n" : " mAh\n"); | 975 | battery->info.capacity_mode ? "0 mWh" : " mAh"); |
958 | 976 | ||
959 | seq_printf(seq, "last full capacity: %i%s", | 977 | seq_printf(seq, "last full capacity: %i%s\n", |
960 | battery->info.full_charge_capacity * cscale, | 978 | battery->info.full_charge_capacity * cscale, |
961 | battery->info.capacity_mode ? "0 mWh\n" : " mAh\n"); | 979 | battery->info.capacity_mode ? "0 mWh" : " mAh"); |
962 | 980 | ||
963 | seq_printf(seq, "battery technology: rechargeable\n"); | 981 | seq_printf(seq, "battery technology: rechargeable\n"); |
964 | 982 | ||
@@ -984,7 +1002,7 @@ static int acpi_battery_read_info(struct seq_file *seq, void *offset) | |||
984 | 1002 | ||
985 | end: | 1003 | end: |
986 | 1004 | ||
987 | up(&sbs_sem); | 1005 | sbs_mutex_unlock(sbs); |
988 | 1006 | ||
989 | return result; | 1007 | return result; |
990 | } | 1008 | } |
@@ -996,26 +1014,29 @@ static int acpi_battery_info_open_fs(struct inode *inode, struct file *file) | |||
996 | 1014 | ||
997 | static int acpi_battery_read_state(struct seq_file *seq, void *offset) | 1015 | static int acpi_battery_read_state(struct seq_file *seq, void *offset) |
998 | { | 1016 | { |
999 | struct acpi_battery *battery = (struct acpi_battery *)seq->private; | 1017 | struct acpi_battery *battery = seq->private; |
1018 | struct acpi_sbs *sbs = battery->sbs; | ||
1000 | int result = 0; | 1019 | int result = 0; |
1001 | int cscale; | 1020 | int cscale; |
1002 | int foo; | 1021 | int foo; |
1003 | 1022 | ||
1004 | if (battery->sbs->zombie) { | 1023 | if (sbs_mutex_lock(sbs)) { |
1005 | return -ENODEV; | 1024 | return -ENODEV; |
1006 | } | 1025 | } |
1007 | 1026 | ||
1008 | down(&sbs_sem); | 1027 | result = acpi_check_update_proc(sbs); |
1028 | if (result) | ||
1029 | goto end; | ||
1009 | 1030 | ||
1010 | if (update_mode == REQUEST_UPDATE_MODE) { | 1031 | if (update_time == 0) { |
1011 | result = acpi_sbs_update_run(battery->sbs, DATA_TYPE_STATE); | 1032 | result = acpi_sbs_update_run(sbs, battery->id, DATA_TYPE_STATE); |
1012 | if (result) { | 1033 | if (result) { |
1013 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 1034 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
1014 | "acpi_sbs_update_run() failed\n")); | 1035 | "acpi_sbs_update_run() failed")); |
1015 | } | 1036 | } |
1016 | } | 1037 | } |
1017 | 1038 | ||
1018 | if (acpi_battery_is_present(battery)) { | 1039 | if (battery->battery_present) { |
1019 | seq_printf(seq, "present: yes\n"); | 1040 | seq_printf(seq, "present: yes\n"); |
1020 | } else { | 1041 | } else { |
1021 | seq_printf(seq, "present: no\n"); | 1042 | seq_printf(seq, "present: no\n"); |
@@ -1028,7 +1049,7 @@ static int acpi_battery_read_state(struct seq_file *seq, void *offset) | |||
1028 | cscale = battery->info.ipscale; | 1049 | cscale = battery->info.ipscale; |
1029 | } | 1050 | } |
1030 | 1051 | ||
1031 | if (battery->state.battery_status & 0x0010) { | 1052 | if (battery->state.battery_state & 0x0010) { |
1032 | seq_printf(seq, "capacity state: critical\n"); | 1053 | seq_printf(seq, "capacity state: critical\n"); |
1033 | } else { | 1054 | } else { |
1034 | seq_printf(seq, "capacity state: ok\n"); | 1055 | seq_printf(seq, "capacity state: ok\n"); |
@@ -1052,16 +1073,16 @@ static int acpi_battery_read_state(struct seq_file *seq, void *offset) | |||
1052 | battery->info.capacity_mode ? "mW" : "mA"); | 1073 | battery->info.capacity_mode ? "mW" : "mA"); |
1053 | } | 1074 | } |
1054 | 1075 | ||
1055 | seq_printf(seq, "remaining capacity: %i%s", | 1076 | seq_printf(seq, "remaining capacity: %i%s\n", |
1056 | battery->state.remaining_capacity * cscale, | 1077 | battery->state.remaining_capacity * cscale, |
1057 | battery->info.capacity_mode ? "0 mWh\n" : " mAh\n"); | 1078 | battery->info.capacity_mode ? "0 mWh" : " mAh"); |
1058 | 1079 | ||
1059 | seq_printf(seq, "present voltage: %i mV\n", | 1080 | seq_printf(seq, "present voltage: %i mV\n", |
1060 | battery->state.voltage * battery->info.vscale); | 1081 | battery->state.voltage * battery->info.vscale); |
1061 | 1082 | ||
1062 | end: | 1083 | end: |
1063 | 1084 | ||
1064 | up(&sbs_sem); | 1085 | sbs_mutex_unlock(sbs); |
1065 | 1086 | ||
1066 | return result; | 1087 | return result; |
1067 | } | 1088 | } |
@@ -1074,24 +1095,27 @@ static int acpi_battery_state_open_fs(struct inode *inode, struct file *file) | |||
1074 | static int acpi_battery_read_alarm(struct seq_file *seq, void *offset) | 1095 | static int acpi_battery_read_alarm(struct seq_file *seq, void *offset) |
1075 | { | 1096 | { |
1076 | struct acpi_battery *battery = seq->private; | 1097 | struct acpi_battery *battery = seq->private; |
1098 | struct acpi_sbs *sbs = battery->sbs; | ||
1077 | int result = 0; | 1099 | int result = 0; |
1078 | int cscale; | 1100 | int cscale; |
1079 | 1101 | ||
1080 | if (battery->sbs->zombie) { | 1102 | if (sbs_mutex_lock(sbs)) { |
1081 | return -ENODEV; | 1103 | return -ENODEV; |
1082 | } | 1104 | } |
1083 | 1105 | ||
1084 | down(&sbs_sem); | 1106 | result = acpi_check_update_proc(sbs); |
1107 | if (result) | ||
1108 | goto end; | ||
1085 | 1109 | ||
1086 | if (update_mode == REQUEST_UPDATE_MODE) { | 1110 | if (update_time == 0) { |
1087 | result = acpi_sbs_update_run(battery->sbs, DATA_TYPE_ALARM); | 1111 | result = acpi_sbs_update_run(sbs, battery->id, DATA_TYPE_ALARM); |
1088 | if (result) { | 1112 | if (result) { |
1089 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 1113 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
1090 | "acpi_sbs_update_run() failed\n")); | 1114 | "acpi_sbs_update_run() failed")); |
1091 | } | 1115 | } |
1092 | } | 1116 | } |
1093 | 1117 | ||
1094 | if (!acpi_battery_is_present(battery)) { | 1118 | if (!battery->battery_present) { |
1095 | seq_printf(seq, "present: no\n"); | 1119 | seq_printf(seq, "present: no\n"); |
1096 | goto end; | 1120 | goto end; |
1097 | } | 1121 | } |
@@ -1104,16 +1128,16 @@ static int acpi_battery_read_alarm(struct seq_file *seq, void *offset) | |||
1104 | 1128 | ||
1105 | seq_printf(seq, "alarm: "); | 1129 | seq_printf(seq, "alarm: "); |
1106 | if (battery->alarm.remaining_capacity) { | 1130 | if (battery->alarm.remaining_capacity) { |
1107 | seq_printf(seq, "%i%s", | 1131 | seq_printf(seq, "%i%s\n", |
1108 | battery->alarm.remaining_capacity * cscale, | 1132 | battery->alarm.remaining_capacity * cscale, |
1109 | battery->info.capacity_mode ? "0 mWh\n" : " mAh\n"); | 1133 | battery->info.capacity_mode ? "0 mWh" : " mAh"); |
1110 | } else { | 1134 | } else { |
1111 | seq_printf(seq, "disabled\n"); | 1135 | seq_printf(seq, "disabled\n"); |
1112 | } | 1136 | } |
1113 | 1137 | ||
1114 | end: | 1138 | end: |
1115 | 1139 | ||
1116 | up(&sbs_sem); | 1140 | sbs_mutex_unlock(sbs); |
1117 | 1141 | ||
1118 | return result; | 1142 | return result; |
1119 | } | 1143 | } |
@@ -1124,16 +1148,19 @@ acpi_battery_write_alarm(struct file *file, const char __user * buffer, | |||
1124 | { | 1148 | { |
1125 | struct seq_file *seq = file->private_data; | 1149 | struct seq_file *seq = file->private_data; |
1126 | struct acpi_battery *battery = seq->private; | 1150 | struct acpi_battery *battery = seq->private; |
1151 | struct acpi_sbs *sbs = battery->sbs; | ||
1127 | char alarm_string[12] = { '\0' }; | 1152 | char alarm_string[12] = { '\0' }; |
1128 | int result, old_alarm, new_alarm; | 1153 | int result, old_alarm, new_alarm; |
1129 | 1154 | ||
1130 | if (battery->sbs->zombie) { | 1155 | if (sbs_mutex_lock(sbs)) { |
1131 | return -ENODEV; | 1156 | return -ENODEV; |
1132 | } | 1157 | } |
1133 | 1158 | ||
1134 | down(&sbs_sem); | 1159 | result = acpi_check_update_proc(sbs); |
1160 | if (result) | ||
1161 | goto end; | ||
1135 | 1162 | ||
1136 | if (!acpi_battery_is_present(battery)) { | 1163 | if (!battery->battery_present) { |
1137 | result = -ENODEV; | 1164 | result = -ENODEV; |
1138 | goto end; | 1165 | goto end; |
1139 | } | 1166 | } |
@@ -1155,21 +1182,21 @@ acpi_battery_write_alarm(struct file *file, const char __user * buffer, | |||
1155 | 1182 | ||
1156 | result = acpi_battery_set_alarm(battery, new_alarm); | 1183 | result = acpi_battery_set_alarm(battery, new_alarm); |
1157 | if (result) { | 1184 | if (result) { |
1158 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 1185 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
1159 | "acpi_battery_set_alarm() failed\n")); | 1186 | "acpi_battery_set_alarm() failed")); |
1160 | acpi_battery_set_alarm(battery, old_alarm); | 1187 | acpi_battery_set_alarm(battery, old_alarm); |
1161 | goto end; | 1188 | goto end; |
1162 | } | 1189 | } |
1163 | result = acpi_battery_get_alarm(battery); | 1190 | result = acpi_battery_get_alarm(battery); |
1164 | if (result) { | 1191 | if (result) { |
1165 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 1192 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
1166 | "acpi_battery_get_alarm() failed\n")); | 1193 | "acpi_battery_get_alarm() failed")); |
1167 | acpi_battery_set_alarm(battery, old_alarm); | 1194 | acpi_battery_set_alarm(battery, old_alarm); |
1168 | goto end; | 1195 | goto end; |
1169 | } | 1196 | } |
1170 | 1197 | ||
1171 | end: | 1198 | end: |
1172 | up(&sbs_sem); | 1199 | sbs_mutex_unlock(sbs); |
1173 | 1200 | ||
1174 | if (result) { | 1201 | if (result) { |
1175 | return result; | 1202 | return result; |
@@ -1217,24 +1244,22 @@ static int acpi_ac_read_state(struct seq_file *seq, void *offset) | |||
1217 | struct acpi_sbs *sbs = seq->private; | 1244 | struct acpi_sbs *sbs = seq->private; |
1218 | int result; | 1245 | int result; |
1219 | 1246 | ||
1220 | if (sbs->zombie) { | 1247 | if (sbs_mutex_lock(sbs)) { |
1221 | return -ENODEV; | 1248 | return -ENODEV; |
1222 | } | 1249 | } |
1223 | 1250 | ||
1224 | down(&sbs_sem); | 1251 | if (update_time == 0) { |
1225 | 1252 | result = acpi_sbs_update_run(sbs, -1, DATA_TYPE_AC_STATE); | |
1226 | if (update_mode == REQUEST_UPDATE_MODE) { | ||
1227 | result = acpi_sbs_update_run(sbs, DATA_TYPE_AC_STATE); | ||
1228 | if (result) { | 1253 | if (result) { |
1229 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 1254 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
1230 | "acpi_sbs_update_run() failed\n")); | 1255 | "acpi_sbs_update_run() failed")); |
1231 | } | 1256 | } |
1232 | } | 1257 | } |
1233 | 1258 | ||
1234 | seq_printf(seq, "state: %s\n", | 1259 | seq_printf(seq, "state: %s\n", |
1235 | sbs->ac_present ? "on-line" : "off-line"); | 1260 | sbs->ac.ac_present ? "on-line" : "off-line"); |
1236 | 1261 | ||
1237 | up(&sbs_sem); | 1262 | sbs_mutex_unlock(sbs); |
1238 | 1263 | ||
1239 | return 0; | 1264 | return 0; |
1240 | } | 1265 | } |
@@ -1275,25 +1300,25 @@ static int acpi_battery_add(struct acpi_sbs *sbs, int id) | |||
1275 | 1300 | ||
1276 | result = acpi_battery_select(battery); | 1301 | result = acpi_battery_select(battery); |
1277 | if (result) { | 1302 | if (result) { |
1278 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 1303 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
1279 | "acpi_battery_select() failed\n")); | 1304 | "acpi_battery_select() failed")); |
1280 | goto end; | 1305 | goto end; |
1281 | } | 1306 | } |
1282 | 1307 | ||
1283 | result = acpi_battery_get_present(battery); | 1308 | result = acpi_battery_get_present(battery); |
1284 | if (result) { | 1309 | if (result) { |
1285 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 1310 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
1286 | "acpi_battery_get_present() failed\n")); | 1311 | "acpi_battery_get_present() failed")); |
1287 | goto end; | 1312 | goto end; |
1288 | } | 1313 | } |
1289 | 1314 | ||
1290 | is_present = acpi_battery_is_present(battery); | 1315 | is_present = battery->battery_present; |
1291 | 1316 | ||
1292 | if (is_present) { | 1317 | if (is_present) { |
1293 | result = acpi_battery_init(battery); | 1318 | result = acpi_battery_init(battery); |
1294 | if (result) { | 1319 | if (result) { |
1295 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 1320 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
1296 | "acpi_battery_init() failed\n")); | 1321 | "acpi_battery_init() failed")); |
1297 | goto end; | 1322 | goto end; |
1298 | } | 1323 | } |
1299 | battery->init_state = 1; | 1324 | battery->init_state = 1; |
@@ -1308,12 +1333,16 @@ static int acpi_battery_add(struct acpi_sbs *sbs, int id) | |||
1308 | &acpi_battery_state_fops, | 1333 | &acpi_battery_state_fops, |
1309 | &acpi_battery_alarm_fops, battery); | 1334 | &acpi_battery_alarm_fops, battery); |
1310 | if (result) { | 1335 | if (result) { |
1311 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 1336 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
1312 | "acpi_sbs_generic_add_fs() failed\n")); | 1337 | "acpi_sbs_generic_add_fs() failed")); |
1313 | goto end; | 1338 | goto end; |
1314 | } | 1339 | } |
1315 | battery->alive = 1; | 1340 | battery->alive = 1; |
1316 | 1341 | ||
1342 | printk(KERN_INFO PREFIX "%s [%s]: Battery Slot [%s] (battery %s)\n", | ||
1343 | ACPI_SBS_DEVICE_NAME, acpi_device_bid(sbs->device), dir_name, | ||
1344 | sbs->battery->battery_present ? "present" : "absent"); | ||
1345 | |||
1317 | end: | 1346 | end: |
1318 | return result; | 1347 | return result; |
1319 | } | 1348 | } |
@@ -1333,8 +1362,8 @@ static int acpi_ac_add(struct acpi_sbs *sbs) | |||
1333 | 1362 | ||
1334 | result = acpi_ac_get_present(sbs); | 1363 | result = acpi_ac_get_present(sbs); |
1335 | if (result) { | 1364 | if (result) { |
1336 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 1365 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
1337 | "acpi_ac_get_present() failed\n")); | 1366 | "acpi_ac_get_present() failed")); |
1338 | goto end; | 1367 | goto end; |
1339 | } | 1368 | } |
1340 | 1369 | ||
@@ -1343,11 +1372,15 @@ static int acpi_ac_add(struct acpi_sbs *sbs) | |||
1343 | ACPI_AC_DIR_NAME, | 1372 | ACPI_AC_DIR_NAME, |
1344 | NULL, &acpi_ac_state_fops, NULL, sbs); | 1373 | NULL, &acpi_ac_state_fops, NULL, sbs); |
1345 | if (result) { | 1374 | if (result) { |
1346 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 1375 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
1347 | "acpi_sbs_generic_add_fs() failed\n")); | 1376 | "acpi_sbs_generic_add_fs() failed")); |
1348 | goto end; | 1377 | goto end; |
1349 | } | 1378 | } |
1350 | 1379 | ||
1380 | printk(KERN_INFO PREFIX "%s [%s]: AC Adapter [%s] (%s)\n", | ||
1381 | ACPI_SBS_DEVICE_NAME, acpi_device_bid(sbs->device), | ||
1382 | ACPI_AC_DIR_NAME, sbs->ac.ac_present ? "on-line" : "off-line"); | ||
1383 | |||
1351 | end: | 1384 | end: |
1352 | 1385 | ||
1353 | return result; | 1386 | return result; |
@@ -1361,45 +1394,85 @@ static void acpi_ac_remove(struct acpi_sbs *sbs) | |||
1361 | } | 1394 | } |
1362 | } | 1395 | } |
1363 | 1396 | ||
1364 | static void acpi_sbs_update_queue_run(unsigned long data) | 1397 | static void acpi_sbs_update_time_run(unsigned long data) |
1365 | { | 1398 | { |
1366 | acpi_os_execute(OSL_GPE_HANDLER, acpi_sbs_update_queue, (void *)data); | 1399 | acpi_os_execute(OSL_GPE_HANDLER, acpi_sbs_update_time, (void *)data); |
1367 | } | 1400 | } |
1368 | 1401 | ||
1369 | static int acpi_sbs_update_run(struct acpi_sbs *sbs, int data_type) | 1402 | static int acpi_sbs_update_run(struct acpi_sbs *sbs, int id, int data_type) |
1370 | { | 1403 | { |
1371 | struct acpi_battery *battery; | 1404 | struct acpi_battery *battery; |
1372 | int result = 0; | 1405 | int result = 0, cnt; |
1373 | int old_ac_present; | 1406 | int old_ac_present = -1; |
1374 | int old_battery_present; | 1407 | int old_battery_present = -1; |
1375 | int new_ac_present; | 1408 | int new_ac_present = -1; |
1376 | int new_battery_present; | 1409 | int new_battery_present = -1; |
1377 | int id; | 1410 | int id_min = 0, id_max = MAX_SBS_BAT - 1; |
1378 | char dir_name[32]; | 1411 | char dir_name[32]; |
1379 | int do_battery_init, do_ac_init; | 1412 | int do_battery_init = 0, do_ac_init = 0; |
1380 | s16 old_remaining_capacity; | 1413 | int old_remaining_capacity = 0; |
1414 | int update_ac = 1, update_battery = 1; | ||
1415 | int up_tm = update_time; | ||
1381 | 1416 | ||
1382 | if (sbs->zombie) { | 1417 | if (sbs_zombie(sbs)) { |
1383 | goto end; | 1418 | goto end; |
1384 | } | 1419 | } |
1385 | 1420 | ||
1386 | old_ac_present = acpi_ac_is_present(sbs); | 1421 | if (id >= 0) { |
1422 | id_min = id_max = id; | ||
1423 | } | ||
1424 | |||
1425 | if (data_type == DATA_TYPE_COMMON && up_tm > 0) { | ||
1426 | cnt = up_tm / (up_tm > UPDATE_DELAY ? UPDATE_DELAY : up_tm); | ||
1427 | if (sbs->run_cnt % cnt != 0) { | ||
1428 | update_battery = 0; | ||
1429 | } | ||
1430 | } | ||
1431 | |||
1432 | sbs->run_cnt++; | ||
1433 | |||
1434 | if (!update_ac && !update_battery) { | ||
1435 | goto end; | ||
1436 | } | ||
1437 | |||
1438 | old_ac_present = sbs->ac.ac_present; | ||
1387 | 1439 | ||
1388 | result = acpi_ac_get_present(sbs); | 1440 | result = acpi_ac_get_present(sbs); |
1389 | if (result) { | 1441 | if (result) { |
1390 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 1442 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
1391 | "acpi_ac_get_present() failed\n")); | 1443 | "acpi_ac_get_present() failed")); |
1392 | } | 1444 | } |
1393 | 1445 | ||
1394 | new_ac_present = acpi_ac_is_present(sbs); | 1446 | new_ac_present = sbs->ac.ac_present; |
1395 | 1447 | ||
1396 | do_ac_init = (old_ac_present != new_ac_present); | 1448 | do_ac_init = (old_ac_present != new_ac_present); |
1449 | if (sbs->run_cnt == 1 && data_type == DATA_TYPE_COMMON) { | ||
1450 | do_ac_init = 1; | ||
1451 | } | ||
1397 | 1452 | ||
1398 | if (data_type == DATA_TYPE_AC_STATE) { | 1453 | if (do_ac_init) { |
1454 | result = acpi_sbs_generate_event(sbs->device, | ||
1455 | ACPI_SBS_AC_NOTIFY_STATUS, | ||
1456 | new_ac_present, | ||
1457 | ACPI_AC_DIR_NAME, | ||
1458 | ACPI_AC_CLASS); | ||
1459 | if (result) { | ||
1460 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
1461 | "acpi_sbs_generate_event() failed")); | ||
1462 | } | ||
1463 | } | ||
1464 | |||
1465 | if (data_type == DATA_TYPE_COMMON) { | ||
1466 | if (!do_ac_init && !update_battery) { | ||
1467 | goto end; | ||
1468 | } | ||
1469 | } | ||
1470 | |||
1471 | if (data_type == DATA_TYPE_AC_STATE && !do_ac_init) { | ||
1399 | goto end; | 1472 | goto end; |
1400 | } | 1473 | } |
1401 | 1474 | ||
1402 | for (id = 0; id < MAX_SBS_BAT; id++) { | 1475 | for (id = id_min; id <= id_max; id++) { |
1403 | battery = &sbs->battery[id]; | 1476 | battery = &sbs->battery[id]; |
1404 | if (battery->alive == 0) { | 1477 | if (battery->alive == 0) { |
1405 | continue; | 1478 | continue; |
@@ -1407,94 +1480,92 @@ static int acpi_sbs_update_run(struct acpi_sbs *sbs, int data_type) | |||
1407 | 1480 | ||
1408 | old_remaining_capacity = battery->state.remaining_capacity; | 1481 | old_remaining_capacity = battery->state.remaining_capacity; |
1409 | 1482 | ||
1410 | old_battery_present = acpi_battery_is_present(battery); | 1483 | old_battery_present = battery->battery_present; |
1411 | 1484 | ||
1412 | result = acpi_battery_select(battery); | 1485 | result = acpi_battery_select(battery); |
1413 | if (result) { | 1486 | if (result) { |
1414 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 1487 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
1415 | "acpi_battery_select() failed\n")); | 1488 | "acpi_battery_select() failed")); |
1416 | } | ||
1417 | if (sbs->zombie) { | ||
1418 | goto end; | ||
1419 | } | 1489 | } |
1420 | 1490 | ||
1421 | result = acpi_battery_get_present(battery); | 1491 | result = acpi_battery_get_present(battery); |
1422 | if (result) { | 1492 | if (result) { |
1423 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 1493 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
1424 | "acpi_battery_get_present() failed\n")); | 1494 | "acpi_battery_get_present() failed")); |
1425 | } | ||
1426 | if (sbs->zombie) { | ||
1427 | goto end; | ||
1428 | } | 1495 | } |
1429 | 1496 | ||
1430 | new_battery_present = acpi_battery_is_present(battery); | 1497 | new_battery_present = battery->battery_present; |
1431 | 1498 | ||
1432 | do_battery_init = ((old_battery_present != new_battery_present) | 1499 | do_battery_init = ((old_battery_present != new_battery_present) |
1433 | && new_battery_present); | 1500 | && new_battery_present); |
1434 | 1501 | if (!new_battery_present) | |
1435 | if (sbs->zombie) { | 1502 | goto event; |
1503 | if (do_ac_init || do_battery_init) { | ||
1504 | result = acpi_battery_init(battery); | ||
1505 | if (result) { | ||
1506 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
1507 | "acpi_battery_init() " | ||
1508 | "failed")); | ||
1509 | } | ||
1510 | } | ||
1511 | if (sbs_zombie(sbs)) { | ||
1436 | goto end; | 1512 | goto end; |
1437 | } | 1513 | } |
1438 | if (do_ac_init || do_battery_init || | 1514 | |
1439 | update_info_mode || sbs->update_info_mode) { | 1515 | if ((data_type == DATA_TYPE_COMMON |
1440 | if (sbs->update_info_mode) { | 1516 | || data_type == DATA_TYPE_INFO) |
1441 | sbs->update_info_mode = 0; | 1517 | && new_battery_present) { |
1442 | } else { | 1518 | result = acpi_battery_get_info(battery); |
1443 | sbs->update_info_mode = 1; | ||
1444 | } | ||
1445 | result = acpi_battery_init(battery); | ||
1446 | if (result) { | 1519 | if (result) { |
1447 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 1520 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
1448 | "acpi_battery_init() " | 1521 | "acpi_battery_get_info() failed")); |
1449 | "failed\n")); | ||
1450 | } | 1522 | } |
1451 | } | 1523 | } |
1452 | if (data_type == DATA_TYPE_INFO) { | 1524 | if (data_type == DATA_TYPE_INFO) { |
1453 | continue; | 1525 | continue; |
1454 | } | 1526 | } |
1455 | 1527 | if (sbs_zombie(sbs)) { | |
1456 | if (sbs->zombie) { | ||
1457 | goto end; | 1528 | goto end; |
1458 | } | 1529 | } |
1459 | if (new_battery_present) { | ||
1460 | result = acpi_battery_get_alarm(battery); | ||
1461 | if (result) { | ||
1462 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | ||
1463 | "acpi_battery_get_alarm() " | ||
1464 | "failed\n")); | ||
1465 | } | ||
1466 | if (data_type == DATA_TYPE_ALARM) { | ||
1467 | continue; | ||
1468 | } | ||
1469 | 1530 | ||
1531 | if ((data_type == DATA_TYPE_COMMON | ||
1532 | || data_type == DATA_TYPE_STATE) | ||
1533 | && new_battery_present) { | ||
1470 | result = acpi_battery_get_state(battery); | 1534 | result = acpi_battery_get_state(battery); |
1471 | if (result) { | 1535 | if (result) { |
1472 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 1536 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
1473 | "acpi_battery_get_state() " | 1537 | "acpi_battery_get_state() failed")); |
1474 | "failed\n")); | ||
1475 | } | 1538 | } |
1476 | } | 1539 | } |
1477 | if (sbs->zombie) { | 1540 | if (data_type == DATA_TYPE_STATE) { |
1478 | goto end; | 1541 | goto event; |
1479 | } | 1542 | } |
1480 | if (data_type != DATA_TYPE_COMMON) { | 1543 | if (sbs_zombie(sbs)) { |
1481 | continue; | 1544 | goto end; |
1482 | } | 1545 | } |
1483 | 1546 | ||
1484 | if (old_battery_present != new_battery_present) { | 1547 | if ((data_type == DATA_TYPE_COMMON |
1485 | sprintf(dir_name, ACPI_BATTERY_DIR_NAME, id); | 1548 | || data_type == DATA_TYPE_ALARM) |
1486 | result = acpi_sbs_generate_event(sbs->device, | 1549 | && new_battery_present) { |
1487 | ACPI_SBS_BATTERY_NOTIFY_STATUS, | 1550 | result = acpi_battery_get_alarm(battery); |
1488 | new_battery_present, | ||
1489 | dir_name, | ||
1490 | ACPI_BATTERY_CLASS); | ||
1491 | if (result) { | 1551 | if (result) { |
1492 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 1552 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
1493 | "acpi_sbs_generate_event() " | 1553 | "acpi_battery_get_alarm() " |
1494 | "failed\n")); | 1554 | "failed")); |
1495 | } | 1555 | } |
1496 | } | 1556 | } |
1497 | if (old_remaining_capacity != battery->state.remaining_capacity) { | 1557 | if (data_type == DATA_TYPE_ALARM) { |
1558 | continue; | ||
1559 | } | ||
1560 | if (sbs_zombie(sbs)) { | ||
1561 | goto end; | ||
1562 | } | ||
1563 | |||
1564 | event: | ||
1565 | |||
1566 | if (old_battery_present != new_battery_present || do_ac_init || | ||
1567 | old_remaining_capacity != | ||
1568 | battery->state.remaining_capacity) { | ||
1498 | sprintf(dir_name, ACPI_BATTERY_DIR_NAME, id); | 1569 | sprintf(dir_name, ACPI_BATTERY_DIR_NAME, id); |
1499 | result = acpi_sbs_generate_event(sbs->device, | 1570 | result = acpi_sbs_generate_event(sbs->device, |
1500 | ACPI_SBS_BATTERY_NOTIFY_STATUS, | 1571 | ACPI_SBS_BATTERY_NOTIFY_STATUS, |
@@ -1502,138 +1573,120 @@ static int acpi_sbs_update_run(struct acpi_sbs *sbs, int data_type) | |||
1502 | dir_name, | 1573 | dir_name, |
1503 | ACPI_BATTERY_CLASS); | 1574 | ACPI_BATTERY_CLASS); |
1504 | if (result) { | 1575 | if (result) { |
1505 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 1576 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
1506 | "acpi_sbs_generate_event() failed\n")); | 1577 | "acpi_sbs_generate_event() " |
1578 | "failed")); | ||
1507 | } | 1579 | } |
1508 | } | 1580 | } |
1509 | |||
1510 | } | ||
1511 | if (sbs->zombie) { | ||
1512 | goto end; | ||
1513 | } | ||
1514 | if (data_type != DATA_TYPE_COMMON) { | ||
1515 | goto end; | ||
1516 | } | ||
1517 | |||
1518 | if (old_ac_present != new_ac_present) { | ||
1519 | result = acpi_sbs_generate_event(sbs->device, | ||
1520 | ACPI_SBS_AC_NOTIFY_STATUS, | ||
1521 | new_ac_present, | ||
1522 | ACPI_AC_DIR_NAME, | ||
1523 | ACPI_AC_CLASS); | ||
1524 | if (result) { | ||
1525 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | ||
1526 | "acpi_sbs_generate_event() failed\n")); | ||
1527 | } | ||
1528 | } | 1581 | } |
1529 | 1582 | ||
1530 | end: | 1583 | end: |
1584 | |||
1531 | return result; | 1585 | return result; |
1532 | } | 1586 | } |
1533 | 1587 | ||
1534 | static void acpi_sbs_update_queue(void *data) | 1588 | static void acpi_sbs_update_time(void *data) |
1535 | { | 1589 | { |
1536 | struct acpi_sbs *sbs = data; | 1590 | struct acpi_sbs *sbs = data; |
1537 | unsigned long delay = -1; | 1591 | unsigned long delay = -1; |
1538 | int result; | 1592 | int result; |
1593 | unsigned int up_tm = update_time; | ||
1539 | 1594 | ||
1540 | if (sbs->zombie) { | 1595 | if (sbs_mutex_lock(sbs)) |
1541 | goto end; | 1596 | return; |
1542 | } | ||
1543 | 1597 | ||
1544 | result = acpi_sbs_update_run(sbs, DATA_TYPE_COMMON); | 1598 | result = acpi_sbs_update_run(sbs, -1, DATA_TYPE_COMMON); |
1545 | if (result) { | 1599 | if (result) { |
1546 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 1600 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
1547 | "acpi_sbs_update_run() failed\n")); | 1601 | "acpi_sbs_update_run() failed")); |
1548 | } | 1602 | } |
1549 | 1603 | ||
1550 | if (sbs->zombie) { | 1604 | if (sbs_zombie(sbs)) { |
1551 | goto end; | 1605 | goto end; |
1552 | } | 1606 | } |
1553 | 1607 | ||
1554 | if (update_mode == REQUEST_UPDATE_MODE) { | 1608 | if (!up_tm) { |
1555 | goto end; | 1609 | if (timer_pending(&sbs->update_timer)) |
1610 | del_timer(&sbs->update_timer); | ||
1611 | } else { | ||
1612 | delay = (up_tm > UPDATE_DELAY ? UPDATE_DELAY : up_tm); | ||
1613 | delay = jiffies + HZ * delay; | ||
1614 | if (timer_pending(&sbs->update_timer)) { | ||
1615 | mod_timer(&sbs->update_timer, delay); | ||
1616 | } else { | ||
1617 | sbs->update_timer.data = (unsigned long)data; | ||
1618 | sbs->update_timer.function = acpi_sbs_update_time_run; | ||
1619 | sbs->update_timer.expires = delay; | ||
1620 | add_timer(&sbs->update_timer); | ||
1621 | } | ||
1556 | } | 1622 | } |
1557 | 1623 | ||
1558 | delay = jiffies + HZ * update_time; | ||
1559 | sbs->update_timer.data = (unsigned long)data; | ||
1560 | sbs->update_timer.function = acpi_sbs_update_queue_run; | ||
1561 | sbs->update_timer.expires = delay; | ||
1562 | add_timer(&sbs->update_timer); | ||
1563 | end: | 1624 | end: |
1564 | ; | 1625 | |
1626 | sbs_mutex_unlock(sbs); | ||
1565 | } | 1627 | } |
1566 | 1628 | ||
1567 | static int acpi_sbs_add(struct acpi_device *device) | 1629 | static int acpi_sbs_add(struct acpi_device *device) |
1568 | { | 1630 | { |
1569 | struct acpi_sbs *sbs = NULL; | 1631 | struct acpi_sbs *sbs = NULL; |
1570 | struct acpi_ec_hc *ec_hc = NULL; | 1632 | int result = 0, remove_result = 0; |
1571 | int result, remove_result = 0; | ||
1572 | unsigned long sbs_obj; | 1633 | unsigned long sbs_obj; |
1573 | int id, cnt; | 1634 | int id; |
1574 | acpi_status status = AE_OK; | 1635 | acpi_status status = AE_OK; |
1636 | unsigned long val; | ||
1637 | |||
1638 | status = | ||
1639 | acpi_evaluate_integer(device->parent->handle, "_EC", NULL, &val); | ||
1640 | if (ACPI_FAILURE(status)) { | ||
1641 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, "Error obtaining _EC")); | ||
1642 | return -EIO; | ||
1643 | } | ||
1575 | 1644 | ||
1576 | sbs = kzalloc(sizeof(struct acpi_sbs), GFP_KERNEL); | 1645 | sbs = kzalloc(sizeof(struct acpi_sbs), GFP_KERNEL); |
1577 | if (!sbs) { | 1646 | if (!sbs) { |
1578 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "kmalloc() failed\n")); | 1647 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, "kzalloc() failed")); |
1579 | return -ENOMEM; | 1648 | result = -ENOMEM; |
1649 | goto end; | ||
1580 | } | 1650 | } |
1581 | 1651 | ||
1582 | cnt = 0; | 1652 | mutex_init(&sbs->mutex); |
1583 | while (cnt < 10) { | ||
1584 | cnt++; | ||
1585 | ec_hc = acpi_get_ec_hc(device); | ||
1586 | if (ec_hc) { | ||
1587 | break; | ||
1588 | } | ||
1589 | msleep(1000); | ||
1590 | } | ||
1591 | 1653 | ||
1592 | if (!ec_hc) { | 1654 | sbs_mutex_lock(sbs); |
1593 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | ||
1594 | "acpi_get_ec_hc() failed: " | ||
1595 | "NO driver found for EC HC SMBus\n")); | ||
1596 | result = -ENODEV; | ||
1597 | goto end; | ||
1598 | } | ||
1599 | 1655 | ||
1656 | sbs->base = (val & 0xff00ull) >> 8; | ||
1600 | sbs->device = device; | 1657 | sbs->device = device; |
1601 | sbs->smbus = ec_hc->smbus; | ||
1602 | 1658 | ||
1603 | strcpy(acpi_device_name(device), ACPI_SBS_DEVICE_NAME); | 1659 | strcpy(acpi_device_name(device), ACPI_SBS_DEVICE_NAME); |
1604 | strcpy(acpi_device_class(device), ACPI_SBS_CLASS); | 1660 | strcpy(acpi_device_class(device), ACPI_SBS_CLASS); |
1605 | acpi_driver_data(device) = sbs; | 1661 | acpi_driver_data(device) = sbs; |
1606 | 1662 | ||
1607 | sbs->update_time = 0; | ||
1608 | sbs->update_time2 = 0; | ||
1609 | |||
1610 | result = acpi_ac_add(sbs); | 1663 | result = acpi_ac_add(sbs); |
1611 | if (result) { | 1664 | if (result) { |
1612 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "acpi_ac_add() failed\n")); | 1665 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, "acpi_ac_add() failed")); |
1613 | goto end; | 1666 | goto end; |
1614 | } | 1667 | } |
1615 | result = acpi_evaluate_integer(device->handle, "_SBS", NULL, &sbs_obj); | 1668 | status = acpi_evaluate_integer(device->handle, "_SBS", NULL, &sbs_obj); |
1616 | if (ACPI_FAILURE(result)) { | 1669 | if (status) { |
1617 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 1670 | ACPI_EXCEPTION((AE_INFO, status, |
1618 | "acpi_evaluate_integer() failed\n")); | 1671 | "acpi_evaluate_integer() failed")); |
1619 | result = -EIO; | 1672 | result = -EIO; |
1620 | goto end; | 1673 | goto end; |
1621 | } | 1674 | } |
1622 | |||
1623 | if (sbs_obj > 0) { | 1675 | if (sbs_obj > 0) { |
1624 | result = acpi_sbsm_get_info(sbs); | 1676 | result = acpi_sbsm_get_info(sbs); |
1625 | if (result) { | 1677 | if (result) { |
1626 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 1678 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
1627 | "acpi_sbsm_get_info() failed\n")); | 1679 | "acpi_sbsm_get_info() failed")); |
1628 | goto end; | 1680 | goto end; |
1629 | } | 1681 | } |
1630 | sbs->sbsm_present = 1; | 1682 | sbs->sbsm_present = 1; |
1631 | } | 1683 | } |
1684 | |||
1632 | if (sbs->sbsm_present == 0) { | 1685 | if (sbs->sbsm_present == 0) { |
1633 | result = acpi_battery_add(sbs, 0); | 1686 | result = acpi_battery_add(sbs, 0); |
1634 | if (result) { | 1687 | if (result) { |
1635 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 1688 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
1636 | "acpi_battery_add() failed\n")); | 1689 | "acpi_battery_add() failed")); |
1637 | goto end; | 1690 | goto end; |
1638 | } | 1691 | } |
1639 | } else { | 1692 | } else { |
@@ -1641,9 +1694,8 @@ static int acpi_sbs_add(struct acpi_device *device) | |||
1641 | if ((sbs->sbsm_batteries_supported & (1 << id))) { | 1694 | if ((sbs->sbsm_batteries_supported & (1 << id))) { |
1642 | result = acpi_battery_add(sbs, id); | 1695 | result = acpi_battery_add(sbs, id); |
1643 | if (result) { | 1696 | if (result) { |
1644 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 1697 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
1645 | "acpi_battery_add() " | 1698 | "acpi_battery_add() failed")); |
1646 | "failed\n")); | ||
1647 | goto end; | 1699 | goto end; |
1648 | } | 1700 | } |
1649 | } | 1701 | } |
@@ -1653,33 +1705,26 @@ static int acpi_sbs_add(struct acpi_device *device) | |||
1653 | sbs->handle = device->handle; | 1705 | sbs->handle = device->handle; |
1654 | 1706 | ||
1655 | init_timer(&sbs->update_timer); | 1707 | init_timer(&sbs->update_timer); |
1656 | if (update_mode == QUEUE_UPDATE_MODE) { | 1708 | result = acpi_check_update_proc(sbs); |
1657 | status = acpi_os_execute(OSL_GPE_HANDLER, | 1709 | if (result) |
1658 | acpi_sbs_update_queue, sbs); | 1710 | goto end; |
1659 | if (status != AE_OK) { | ||
1660 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | ||
1661 | "acpi_os_execute() failed\n")); | ||
1662 | } | ||
1663 | } | ||
1664 | sbs->update_time = update_time; | ||
1665 | sbs->update_time2 = update_time2; | ||
1666 | |||
1667 | printk(KERN_INFO PREFIX "%s [%s]\n", | ||
1668 | acpi_device_name(device), acpi_device_bid(device)); | ||
1669 | 1711 | ||
1670 | end: | 1712 | end: |
1713 | |||
1714 | sbs_mutex_unlock(sbs); | ||
1715 | |||
1671 | if (result) { | 1716 | if (result) { |
1672 | remove_result = acpi_sbs_remove(device, 0); | 1717 | remove_result = acpi_sbs_remove(device, 0); |
1673 | if (remove_result) { | 1718 | if (remove_result) { |
1674 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 1719 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
1675 | "acpi_sbs_remove() failed\n")); | 1720 | "acpi_sbs_remove() failed")); |
1676 | } | 1721 | } |
1677 | } | 1722 | } |
1678 | 1723 | ||
1679 | return result; | 1724 | return result; |
1680 | } | 1725 | } |
1681 | 1726 | ||
1682 | int acpi_sbs_remove(struct acpi_device *device, int type) | 1727 | static int acpi_sbs_remove(struct acpi_device *device, int type) |
1683 | { | 1728 | { |
1684 | struct acpi_sbs *sbs; | 1729 | struct acpi_sbs *sbs; |
1685 | int id; | 1730 | int id; |
@@ -1688,15 +1733,14 @@ int acpi_sbs_remove(struct acpi_device *device, int type) | |||
1688 | return -EINVAL; | 1733 | return -EINVAL; |
1689 | } | 1734 | } |
1690 | 1735 | ||
1691 | sbs = (struct acpi_sbs *)acpi_driver_data(device); | 1736 | sbs = acpi_driver_data(device); |
1692 | |||
1693 | if (!sbs) { | 1737 | if (!sbs) { |
1694 | return -EINVAL; | 1738 | return -EINVAL; |
1695 | } | 1739 | } |
1696 | 1740 | ||
1741 | sbs_mutex_lock(sbs); | ||
1742 | |||
1697 | sbs->zombie = 1; | 1743 | sbs->zombie = 1; |
1698 | sbs->update_time = 0; | ||
1699 | sbs->update_time2 = 0; | ||
1700 | del_timer_sync(&sbs->update_timer); | 1744 | del_timer_sync(&sbs->update_timer); |
1701 | acpi_os_wait_events_complete(NULL); | 1745 | acpi_os_wait_events_complete(NULL); |
1702 | del_timer_sync(&sbs->update_timer); | 1746 | del_timer_sync(&sbs->update_timer); |
@@ -1707,11 +1751,41 @@ int acpi_sbs_remove(struct acpi_device *device, int type) | |||
1707 | 1751 | ||
1708 | acpi_ac_remove(sbs); | 1752 | acpi_ac_remove(sbs); |
1709 | 1753 | ||
1754 | sbs_mutex_unlock(sbs); | ||
1755 | |||
1756 | mutex_destroy(&sbs->mutex); | ||
1757 | |||
1710 | kfree(sbs); | 1758 | kfree(sbs); |
1711 | 1759 | ||
1712 | return 0; | 1760 | return 0; |
1713 | } | 1761 | } |
1714 | 1762 | ||
1763 | static void acpi_sbs_rmdirs(void) | ||
1764 | { | ||
1765 | if (acpi_ac_dir) { | ||
1766 | acpi_unlock_ac_dir(acpi_ac_dir); | ||
1767 | acpi_ac_dir = NULL; | ||
1768 | } | ||
1769 | if (acpi_battery_dir) { | ||
1770 | acpi_unlock_battery_dir(acpi_battery_dir); | ||
1771 | acpi_battery_dir = NULL; | ||
1772 | } | ||
1773 | } | ||
1774 | |||
1775 | static int acpi_sbs_resume(struct acpi_device *device) | ||
1776 | { | ||
1777 | struct acpi_sbs *sbs; | ||
1778 | |||
1779 | if (!device) | ||
1780 | return -EINVAL; | ||
1781 | |||
1782 | sbs = device->driver_data; | ||
1783 | |||
1784 | sbs->run_cnt = 0; | ||
1785 | |||
1786 | return 0; | ||
1787 | } | ||
1788 | |||
1715 | static int __init acpi_sbs_init(void) | 1789 | static int __init acpi_sbs_init(void) |
1716 | { | 1790 | { |
1717 | int result = 0; | 1791 | int result = 0; |
@@ -1719,35 +1793,34 @@ static int __init acpi_sbs_init(void) | |||
1719 | if (acpi_disabled) | 1793 | if (acpi_disabled) |
1720 | return -ENODEV; | 1794 | return -ENODEV; |
1721 | 1795 | ||
1722 | init_MUTEX(&sbs_sem); | ||
1723 | |||
1724 | if (capacity_mode != DEF_CAPACITY_UNIT | 1796 | if (capacity_mode != DEF_CAPACITY_UNIT |
1725 | && capacity_mode != MAH_CAPACITY_UNIT | 1797 | && capacity_mode != MAH_CAPACITY_UNIT |
1726 | && capacity_mode != MWH_CAPACITY_UNIT) { | 1798 | && capacity_mode != MWH_CAPACITY_UNIT) { |
1727 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "acpi_sbs_init: " | 1799 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
1728 | "invalid capacity_mode = %d\n", | 1800 | "invalid capacity_mode = %d", capacity_mode)); |
1729 | capacity_mode)); | ||
1730 | return -EINVAL; | 1801 | return -EINVAL; |
1731 | } | 1802 | } |
1732 | 1803 | ||
1733 | acpi_ac_dir = acpi_lock_ac_dir(); | 1804 | acpi_ac_dir = acpi_lock_ac_dir(); |
1734 | if (!acpi_ac_dir) { | 1805 | if (!acpi_ac_dir) { |
1735 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 1806 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
1736 | "acpi_lock_ac_dir() failed\n")); | 1807 | "acpi_lock_ac_dir() failed")); |
1737 | return -ENODEV; | 1808 | return -ENODEV; |
1738 | } | 1809 | } |
1739 | 1810 | ||
1740 | acpi_battery_dir = acpi_lock_battery_dir(); | 1811 | acpi_battery_dir = acpi_lock_battery_dir(); |
1741 | if (!acpi_battery_dir) { | 1812 | if (!acpi_battery_dir) { |
1742 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 1813 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
1743 | "acpi_lock_battery_dir() failed\n")); | 1814 | "acpi_lock_battery_dir() failed")); |
1815 | acpi_sbs_rmdirs(); | ||
1744 | return -ENODEV; | 1816 | return -ENODEV; |
1745 | } | 1817 | } |
1746 | 1818 | ||
1747 | result = acpi_bus_register_driver(&acpi_sbs_driver); | 1819 | result = acpi_bus_register_driver(&acpi_sbs_driver); |
1748 | if (result < 0) { | 1820 | if (result < 0) { |
1749 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 1821 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
1750 | "acpi_bus_register_driver() failed\n")); | 1822 | "acpi_bus_register_driver() failed")); |
1823 | acpi_sbs_rmdirs(); | ||
1751 | return -ENODEV; | 1824 | return -ENODEV; |
1752 | } | 1825 | } |
1753 | 1826 | ||
@@ -1756,13 +1829,9 @@ static int __init acpi_sbs_init(void) | |||
1756 | 1829 | ||
1757 | static void __exit acpi_sbs_exit(void) | 1830 | static void __exit acpi_sbs_exit(void) |
1758 | { | 1831 | { |
1759 | |||
1760 | acpi_bus_unregister_driver(&acpi_sbs_driver); | 1832 | acpi_bus_unregister_driver(&acpi_sbs_driver); |
1761 | 1833 | ||
1762 | acpi_unlock_ac_dir(acpi_ac_dir); | 1834 | acpi_sbs_rmdirs(); |
1763 | acpi_ac_dir = NULL; | ||
1764 | acpi_unlock_battery_dir(acpi_battery_dir); | ||
1765 | acpi_battery_dir = NULL; | ||
1766 | 1835 | ||
1767 | return; | 1836 | return; |
1768 | } | 1837 | } |
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index bb0e0da39fb1..d80dd84e5bfd 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c | |||
@@ -1068,7 +1068,9 @@ acpi_add_single_object(struct acpi_device **child, | |||
1068 | } | 1068 | } |
1069 | break; | 1069 | break; |
1070 | default: | 1070 | default: |
1071 | STRUCT_TO_INT(device->status) = 0x0F; | 1071 | STRUCT_TO_INT(device->status) = |
1072 | ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED | | ||
1073 | ACPI_STA_DEVICE_UI | ACPI_STA_DEVICE_FUNCTIONING; | ||
1072 | break; | 1074 | break; |
1073 | } | 1075 | } |
1074 | 1076 | ||
diff --git a/drivers/acpi/sleep/proc.c b/drivers/acpi/sleep/proc.c index ccc11b33d89c..2d912b71e543 100644 --- a/drivers/acpi/sleep/proc.c +++ b/drivers/acpi/sleep/proc.c | |||
@@ -350,21 +350,31 @@ acpi_system_wakeup_device_seq_show(struct seq_file *seq, void *offset) | |||
350 | { | 350 | { |
351 | struct list_head *node, *next; | 351 | struct list_head *node, *next; |
352 | 352 | ||
353 | seq_printf(seq, "Device Sleep state Status\n"); | 353 | seq_printf(seq, "Device\tS-state\t Status Sysfs node\n"); |
354 | 354 | ||
355 | spin_lock(&acpi_device_lock); | 355 | spin_lock(&acpi_device_lock); |
356 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { | 356 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { |
357 | struct acpi_device *dev = | 357 | struct acpi_device *dev = |
358 | container_of(node, struct acpi_device, wakeup_list); | 358 | container_of(node, struct acpi_device, wakeup_list); |
359 | struct device *ldev; | ||
359 | 360 | ||
360 | if (!dev->wakeup.flags.valid) | 361 | if (!dev->wakeup.flags.valid) |
361 | continue; | 362 | continue; |
362 | spin_unlock(&acpi_device_lock); | 363 | spin_unlock(&acpi_device_lock); |
363 | seq_printf(seq, "%4s %4d %s%8s\n", | 364 | |
365 | ldev = acpi_get_physical_device(dev->handle); | ||
366 | seq_printf(seq, "%s\t S%d\t%c%-8s ", | ||
364 | dev->pnp.bus_id, | 367 | dev->pnp.bus_id, |
365 | (u32) dev->wakeup.sleep_state, | 368 | (u32) dev->wakeup.sleep_state, |
366 | dev->wakeup.flags.run_wake ? "*" : "", | 369 | dev->wakeup.flags.run_wake ? '*' : ' ', |
367 | dev->wakeup.state.enabled ? "enabled" : "disabled"); | 370 | dev->wakeup.state.enabled ? "enabled" : "disabled"); |
371 | if (ldev) | ||
372 | seq_printf(seq, "%s:%s", | ||
373 | ldev->bus ? ldev->bus->name : "no-bus", | ||
374 | ldev->bus_id); | ||
375 | seq_printf(seq, "\n"); | ||
376 | put_device(ldev); | ||
377 | |||
368 | spin_lock(&acpi_device_lock); | 378 | spin_lock(&acpi_device_lock); |
369 | } | 379 | } |
370 | spin_unlock(&acpi_device_lock); | 380 | spin_unlock(&acpi_device_lock); |
diff --git a/drivers/acpi/tables/tbfadt.c b/drivers/acpi/tables/tbfadt.c index 807c7116e94b..1db833eb2417 100644 --- a/drivers/acpi/tables/tbfadt.c +++ b/drivers/acpi/tables/tbfadt.c | |||
@@ -347,6 +347,18 @@ static void acpi_tb_convert_fadt(void) | |||
347 | acpi_gbl_xpm1b_enable.space_id = acpi_gbl_FADT.xpm1a_event_block.space_id; | 347 | acpi_gbl_xpm1b_enable.space_id = acpi_gbl_FADT.xpm1a_event_block.space_id; |
348 | 348 | ||
349 | } | 349 | } |
350 | |||
351 | /* | ||
352 | * For ACPI 1.0 FADTs, ensure that reserved fields (which should be zero) | ||
353 | * are indeed zero. This will workaround BIOSs that inadvertently placed | ||
354 | * values in these fields. | ||
355 | */ | ||
356 | if (acpi_gbl_FADT.header.revision < 3) { | ||
357 | acpi_gbl_FADT.preferred_profile = 0; | ||
358 | acpi_gbl_FADT.pstate_control = 0; | ||
359 | acpi_gbl_FADT.cst_control = 0; | ||
360 | acpi_gbl_FADT.boot_flags = 0; | ||
361 | } | ||
350 | } | 362 | } |
351 | 363 | ||
352 | /****************************************************************************** | 364 | /****************************************************************************** |